@@ -47,13 +47,20 @@ cdef inline {{ render_utility_function_signature(builtin) }}:
4747{% if not builtin .return_type .is_stack_only %}
4848 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
4949 __ret = {{ builtin.return_type.c_name_prefix }}_new()
50+ {% else %}
51+ # C compiler doesn't like passing to a function a pointer on uninitialized
52+ # data (see `-Wmaybe-uninitialized`).
53+ # Should be optimized out in the end given the called function end up inlined.
54+ memset(& __ret, 0, sizeof(__ret))
5055{% endif %}
5156{% endif %}
5257 gd_utility_{{ builtin.original_name }}_ptr(
5358 {# GDExtensionTypePtr ret #}
5459 {{ "NULL" if builtin.return_type.is_nil else "&__ret" }},
5560 {# const GDExtensionTypePtr *p_arguments #}
56- {{ "NULL" if (builtin.arguments | length) == 0 else "__args" }},
61+ # Cast on args is required given autopxd2 incorrectly removes the const
62+ # attributes when converting gdextension_interface.c to .pxd
63+ <const void *const* >{{ "NULL" if (builtin.arguments | length) == 0 else "__args" }},
5764 {# int p_argument_count #}
5865 {{ builtin.arguments | length }}
5966 )
@@ -70,12 +77,16 @@ cdef inline {{ render_utility_function_signature(builtin) }}:
7077{# to pass a `gd_variant_t**` as parameter) whose size is passed in the number #}
7178{# of parameters fields... Yes this is very confusing stuff, my brain hurts ! #}
7279{% if builtin .return_type .is_nil %}
73- gd_utility_{{ builtin.original_name }}_ptr(NULL, <GDExtensionTypePtr * >&args, args_count)
80+ # Cast on args is required given autopxd2 incorrectly removes the const
81+ # attributes when converting gdextension_interface.c to .pxd
82+ gd_utility_{{ builtin.original_name }}_ptr(NULL, <const void *const* >&args, args_count)
7483{% else %}
7584 cdef gd_variant_t __ret # TODO: improve return type !
7685 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
7786 __ret = gd_variant_new()
78- gd_utility_{{ builtin.original_name }}_ptr(& __ret, <GDExtensionTypePtr * >&args, args_count)
87+ # Cast on args is required given autopxd2 incorrectly removes the const
88+ # attributes when converting gdextension_interface.c to .pxd
89+ gd_utility_{{ builtin.original_name }}_ptr(& __ret, <const void *const* >&args, args_count)
7990 return __ret
8091{% endif %}
8192{% endmacro %}
@@ -151,7 +162,9 @@ cdef inline {{ render_builtin_constructor_signature(builtin, constructor) }}:
151162{% endif %}
152163 {{ builtin.c_name_prefix }}_constructor_{{ constructor.index }}_ptr(
153164 &obj,
154- {{ "NULL" if (constructor.arguments | length) == 0 else "p_args" }}
165+ # Cast is required given autopxd2 incorrectly removes the const attributes
166+ # when converting gdextension_interface.c to .pxd
167+ <const void * const* >{{ "NULL" if (constructor.arguments | length) == 0 else "p_args" }}
155168 )
156169 return obj
157170{% endmacro %}
@@ -195,13 +208,20 @@ cdef inline {{ render_builtin_method_signature(builtin, meth) }}:
195208{% if not meth .return_type .is_stack_only %}
196209 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
197210 __ret = {{ meth.return_type.c_name_prefix }}_new()
211+ {% else %}
212+ # C compiler doesn't like passing to a function a pointer on uninitialized
213+ # data (see `-Wmaybe-uninitialized`).
214+ # Should be optimized out in the end given the called function end up inlined.
215+ memset(& __ret, 0, sizeof(__ret))
198216{% endif %}
199217{% endif %}
200218 {{ builtin.c_name_prefix }}_meth_{{ meth.name }}_ptr(
201219 {# GDExtensionTypePtr p_base #}
202220 self,
203221 {# const GDExtensionTypePtr *__args #}
204- __args,
222+ # Cast is required given autopxd2 incorrectly removes the const attributes
223+ # when converting gdextension_interface.c to .pxd
224+ <const void * const* >__args,
205225 {# GDExtensionTypePtr __ret #}
206226 {{ "NULL" if meth.return_type.is_nil else "&__ret" }},
207227 {# int p_argument_count #}
@@ -224,6 +244,11 @@ cdef inline {{ m.type.c_type }} {{ builtin.c_name_prefix }}_get_{{ m.name }}({{
224244{% if not m .type .is_stack_only %} 1
225245 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
226246 __ret = {{ m.type.c_name_prefix }}_new()
247+ {% else %}
248+ # C compiler doesn't like passing to a function a pointer on uninitialized
249+ # data (see `-Wmaybe-uninitialized`).
250+ # Should be optimized out in the end given the called function end up inlined.
251+ memset(& __ret, 0, sizeof(__ret))
227252{% endif %}
228253 {{ builtin.c_name_prefix }}_get_{{ m.name }}_ptr(self, & __ret)
229254 return __ret
@@ -250,6 +275,11 @@ cdef inline {{ builtin.indexing_return_type.c_type }} {{ builtin.c_name_prefix }
250275{% if not builtin .indexing_return_type .is_stack_only %}
251276 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
252277 __ret = {{ builtin.indexing_return_type.c_name_prefix }}_new()
278+ {% else %}
279+ # C compiler doesn't like passing to a function a pointer on uninitialized
280+ # data (see `-Wmaybe-uninitialized`).
281+ # Should be optimized out in the end given the called function end up inlined.
282+ memset(& __ret, 0, sizeof(__ret))
253283{% endif %}
254284 {{ builtin.c_name_prefix }}_indexed_getter_ptr(self, index, & __ret)
255285 return __ret
@@ -277,6 +307,11 @@ cdef inline {{ builtin.indexing_return_type.c_type }} {{ builtin.c_name_prefix }
277307{% if not builtin .indexing_return_type .is_stack_only %}
278308 # ptrcall makes us jump right into C++ code (i.e. Godot internals) that expects constructor to be called on each parameter
279309 __ret = {{ builtin.indexing_return_type.c_name_prefix }}_new()
310+ {% else %}
311+ # C compiler doesn't like passing to a function a pointer on uninitialized
312+ # data (see `-Wmaybe-uninitialized`).
313+ # Should be optimized out in the end given the called function end up inlined.
314+ memset(& __ret, 0, sizeof(__ret))
280315{% endif %}
281316 {{ builtin.c_name_prefix }}_keyed_getter_ptr(self, key, & __ret)
282317 return __ret
0 commit comments