Skip to content

Commit 1ebff0b

Browse files
committed
fix(c): fix warnings about APIENTRY redefinition and implicit int-to-char conversion
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
1 parent 243e32a commit 1ebff0b

2 files changed

Lines changed: 30 additions & 28 deletions

File tree

src/generator/c/templates/header.h.j2

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@
6969
#include <gloam/gl.h>
7070
{% elif fs.spec_name == "wgl" %}
7171
#ifdef GLOAM_PLATFORM_WINDOWS
72+
7273
#ifndef WIN32_LEAN_AND_MEAN
7374
#define WIN32_LEAN_AND_MEAN
7475
#endif
7576
#include <windows.h>
7677

7778
#include <gloam/gl.h>
79+
7880
/* These are defined in wingdi.h and we're redefining them. */
7981
#undef wglUseFontBitmaps
8082
#undef wglUseFontOutlines
@@ -84,20 +86,19 @@
8486

8587
{% for hdr in fs.required_headers -%}
8688
#include "{{ hdr }}"
87-
{% endfor -%}
88-
89+
{% endfor %}
8990
{# Platform / WSI system headers: include-category types whose protection
9091
guards were inferred at generation time from which extensions require them.
9192
An empty protect list means the include is unconditional.
9293
Consecutive types sharing the same guard are coalesced into a single
93-
#ifdef/#endif block by the resolver. #}
94-
{%- for group in fs.include_type_groups -%}
94+
#ifdef/#endif block by the resolver. -#}
95+
{% for group in fs.include_type_groups -%}
9596
{{ u.protect_begin(group.protect) -}}
9697
{% for type in group.items -%}
9798
{{ type.raw_c }}
9899
{% endfor -%}
99100
{{ u.protect_end(group.protect) -}}
100-
{% endfor %}
101+
{% endfor -%}
101102
#ifdef __cplusplus
102103
extern "C" {
103104
#endif

src/generator/c/templates/source.c.j2

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
{{ preamble }}
33
{% if fs.spec_name == "wgl" %}
44
#include <gloam/gl.h>
5-
{% endif %}
5+
{%- endif %}
66
#include <gloam/{{ stem }}.h>
77
{% if fs.spec_name == "glx" %}
88
#ifdef GLOAM_PLATFORM_LINUX
9-
{% elif fs.spec_name == "wgl" %}
10-
#ifdef GLOAM_PLATFORM_WINDOWS
11-
{% endif %}
12-
13-
#include <stdlib.h> /* calloc, free */
14-
#include <stddef.h>
15-
#include <stdio.h> /* sscanf */
16-
#include <string.h> /* strlen, strncmp */
17-
{% if loader -%}
9+
{%- elif fs.spec_name == "wgl" %}
1810
#ifdef GLOAM_PLATFORM_WINDOWS
11+
{%- endif %}
12+
{%- if loader and fs.spec_name != "wgl" %}
13+
#if defined(__CYGWIN__) || defined(_WIN32)
1914
# ifndef WIN32_LEAN_AND_MEAN
2015
# define WIN32_LEAN_AND_MEAN
2116
# endif
17+
# undef APIENTRY /* fix macro redefinition warning */
2218
# include <windows.h> /* LoadLibrary, GetProcAddress */
2319
#else
2420
# include <dlfcn.h> /* dlopen, dlsym, dlclose */
2521
#endif
2622
{%- endif %}
2723

24+
#include <stdlib.h> /* calloc, free */
25+
#include <stddef.h>
26+
#include <stdio.h> /* sscanf */
27+
#include <string.h> /* strlen, strncmp */
28+
2829
{% if fs.extensions | length > 0 -%}
2930
#if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64)
3031
# define XXH_VECTOR XXH_SSE2
@@ -190,7 +191,7 @@ static void gloam_vk_apply_version({{ u.ctx_arg(', ') }}uint32_t api_version) {
190191
const uint16_t version_value = (uint16_t)(
191192
(((api_version >> 22) & 0x7fu) << 8) | ((api_version >> 12) & 0x3ffu));
192193
{% for feat in fs.features %}
193-
context->{{ feat.short_name }} = (version_value >= {{ feat.packed | hex4 }});
194+
context->{{ feat.short_name }} = (unsigned char)(version_value >= {{ feat.packed | hex4 }});
194195
{%- endfor %}
195196
}
196197

@@ -502,7 +503,7 @@ static int gloam_{{ fs.spec_name }}_find_extensions_{{ api }}({{ u.ctx_arg(', ')
502503
when this call adds device extensions. */
503504
for (i = 0; i < GLOAM_ARRAYSIZE(kExtIdx_{{ api }}); ++i) {
504505
const uint16_t extIdx = kExtIdx_{{ api }}[i];
505-
context->extArray[extIdx] |= gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
506+
context->extArray[extIdx] |= (unsigned char)gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
506507
}
507508

508509
free(exts);
@@ -518,7 +519,7 @@ static int gloam_{{ fs.spec_name }}_find_extensions_{{ api }}({{ u.ctx_arg() }}{
518519

519520
for (i = 0; i < GLOAM_ARRAYSIZE(kExtIdx_{{ api }}); ++i) {
520521
const uint16_t extIdx = kExtIdx_{{ api }}[i];
521-
context->extArray[extIdx] = gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
522+
context->extArray[extIdx] = (unsigned char)gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
522523
}
523524

524525
free(exts);
@@ -549,7 +550,7 @@ static int gloam_{{ fs.spec_name }}_find_core_{{ api }}({{ u.ctx_arg() }}) {
549550
GLOAM_IMPL_UTIL_SSCANF(version, "%d.%d", &major, &minor);
550551
version_value = (unsigned short)((major << 8) | minor);
551552
{% for feat in fs.features | selectattr("api", "equalto", api) %}
552-
context->{{ feat.short_name }} = (version_value >= {{ feat.packed | hex4 }});
553+
context->{{ feat.short_name }} = (unsigned char)(version_value >= {{ feat.packed | hex4 }});
553554
{%- endfor %}
554555

555556
return (int)version_value;
@@ -570,11 +571,11 @@ static int gloam_{{ fs.spec_name }}_find_core_{{ api }}({{ u.ctx_arg(', ') }}Dis
570571
}
571572
context->QueryVersion(*display, &major, &minor);
572573
version_value = (major << 8U) | minor;
573-
context->VERSION_1_0 = version_value >= 0x0100;
574-
context->VERSION_1_1 = version_value >= 0x0101;
575-
context->VERSION_1_2 = version_value >= 0x0102;
576-
context->VERSION_1_3 = version_value >= 0x0103;
577-
context->VERSION_1_4 = version_value >= 0x0104;
574+
context->VERSION_1_0 = (unsigned char)(version_value >= 0x0100);
575+
context->VERSION_1_1 = (unsigned char)(version_value >= 0x0101);
576+
context->VERSION_1_2 = (unsigned char)(version_value >= 0x0102);
577+
context->VERSION_1_3 = (unsigned char)(version_value >= 0x0103);
578+
context->VERSION_1_4 = (unsigned char)(version_value >= 0x0104);
578579
return version_value;
579580
}
580581
{%- elif fs.spec_name == "vk" -%}
@@ -629,7 +630,7 @@ static int gloam_vk_find_core({{ u.ctx_arg(', ') }}VkPhysicalDevice physical_dev
629630

630631
version_value = (uint16_t)((major << 8) | minor);
631632
{% for feat in fs.features %}
632-
context->{{ feat.short_name }} = (version_value >= {{ feat.packed | hex4 }});
633+
context->{{ feat.short_name }} = (unsigned char)(version_value >= {{ feat.packed | hex4 }});
633634
{%- endfor %}
634635

635636
return (int)version_value;
@@ -642,7 +643,7 @@ static int gloam_{{ fs.spec_name }}_find_core_{{ api }}({{ u.ctx_arg() }}) {
642643
unsigned short version_value;
643644
version_value = (unsigned short)((major << 8) | minor);
644645
{% for feat in fs.features | selectattr("api", "equalto", api) %}
645-
context->{{ feat.short_name }} = (version_value >= {{ feat.packed | hex4 }});
646+
context->{{ feat.short_name }} = (unsigned char)(version_value >= {{ feat.packed | hex4 }});
646647
{%- endfor %}
647648

648649
return (int)version_value;
@@ -662,7 +663,7 @@ static int gloam_{{ fs.spec_name }}_find_core_{{ api }}({{ u.ctx_arg(', ') }}EGL
662663
GLOAM_IMPL_UTIL_SSCANF(version, "%d.%d", &major, &minor);
663664
version_value = (unsigned short)((major << 8) | minor);
664665
{% for feat in fs.features | selectattr("api", "equalto", api) %}
665-
context->{{ feat.short_name }} = (version_value >= {{ feat.packed | hex4 }});
666+
context->{{ feat.short_name }} = (unsigned char)(version_value >= {{ feat.packed | hex4 }});
666667
{%- endfor %}
667668

668669
return (int)version_value;
@@ -876,7 +877,7 @@ static int gloam_vk_apply_extensions_{{ api }}({{ u.ctx_arg(', ') }}
876877

877878
for (i = 0; i < GLOAM_ARRAYSIZE(kExtIdx_{{ api }}); ++i) {
878879
const uint16_t extIdx = kExtIdx_{{ api }}[i];
879-
context->extArray[extIdx] |= gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
880+
context->extArray[extIdx] |= (unsigned char)gloam_hash_search(exts, num_exts, kExtHashes_{{ fs.spec_name | spec_display }}[extIdx]);
880881
}
881882

882883
free(exts);

0 commit comments

Comments
 (0)