@@ -65,7 +65,7 @@ static GDExtensionPtrConstructor gdstring_constructor = NULL;
6565static GDExtensionPtrDestructor gdstring_destructor = NULL ;
6666static GDExtensionPtrConstructor gdstringname_from_gdstring_constructor = NULL ;
6767static GDExtensionPtrDestructor gdstringname_destructor = NULL ;
68- static void ( * gdstring_new_with_utf8_chars )( GDExtensionUninitializedStringPtr , const char * ) = NULL ;
68+ static GDExtensionInterfaceStringNewWithUtf8Chars gdstring_new_with_utf8_chars = NULL ;
6969
7070DLL_EXPORT void pythonscript_gdstringname_new (GDExtensionStringNamePtr ptr , const char * cstr ) {
7171 // Method name must be passed as a StringName object... which itself has
@@ -81,31 +81,9 @@ DLL_EXPORT void pythonscript_gdstringname_delete(GDExtensionStringNamePtr ptr) {
8181 gdstringname_destructor (ptr );
8282}
8383
84- #if __GNUC__ // GCC & Clang
85-
86- #define PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES \
87- _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"");
88-
89- #define PRAGMA_POP \
90- _Pragma("GCC diagnostic pop");
91-
92- #else // MSVC
93-
94- #define PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES \
95- _Pragma("warning( push )"); \
96- _Pragma("warning( disable : 4047 )");
97-
98- #define PRAGMA_POP \
99- _Pragma("warning( pop )");
100-
101- #endif
102-
10384#define GD_PRINT_ERROR (msg ) { \
10485 { \
105- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES; \
106- void (*fn)(const char *, const char *, const char *, int32_t, GDExtensionBool); \
107- fn = pythonscript_gdextension_get_proc_address("print_error"); \
108- PRAGMA_POP; \
86+ GDExtensionInterfacePrintError fn = (GDExtensionInterfacePrintError)(void*)pythonscript_gdextension_get_proc_address("print_error"); \
10987 if (fn) { \
11088 fn(msg, __func__, __FILE__, __LINE__, false); \
11189 } else { \
@@ -116,10 +94,7 @@ DLL_EXPORT void pythonscript_gdstringname_delete(GDExtensionStringNamePtr ptr) {
11694
11795#define GD_PRINT_WARNING (msg ) { \
11896 { \
119- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES; \
120- void (*fn)(const char *, const char *, const char *, int32_t, GDExtensionBool); \
121- fn = pythonscript_gdextension_get_proc_address("print_warning"); \
122- PRAGMA_POP; \
97+ GDExtensionInterfacePrintWarning fn = (GDExtensionInterfacePrintWarning)(void*)pythonscript_gdextension_get_proc_address("print_warning"); \
12398 if (fn) { \
12499 fn(msg, __func__, __FILE__, __LINE__, false); \
125100 } else { \
@@ -148,10 +123,7 @@ static void _initialize_python() {
148123 pythonscript_gdstringname_new (& method_name_as_gdstringname , "get_base_dir" );
149124 GDExtensionPtrBuiltInMethod gdstring_get_base_dir ;
150125 {
151- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
152- GDExtensionPtrBuiltInMethod (* fn )(GDExtensionVariantType , GDExtensionConstStringNamePtr , GDExtensionInt );
153- fn = pythonscript_gdextension_get_proc_address ("variant_get_ptr_builtin_method" );
154- PRAGMA_POP ;
126+ GDExtensionInterfaceVariantGetPtrBuiltinMethod fn = (GDExtensionInterfaceVariantGetPtrBuiltinMethod )(void * )pythonscript_gdextension_get_proc_address ("variant_get_ptr_builtin_method" );
155127 gdstring_get_base_dir = fn (
156128 GDEXTENSION_VARIANT_TYPE_STRING ,
157129 & method_name_as_gdstringname ,
@@ -167,10 +139,7 @@ static void _initialize_python() {
167139 // 1) Retrieve library path
168140 char gd_library_path [GD_STRING_MAX_SIZE ];
169141 {
170- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
171- void (* fn )(GDExtensionClassLibraryPtr , GDExtensionUninitializedStringPtr );
172- fn = pythonscript_gdextension_get_proc_address ("get_library_path" );
173- PRAGMA_POP ;
142+ GDExtensionInterfaceGetLibraryPath fn = (GDExtensionInterfaceGetLibraryPath )(void * )pythonscript_gdextension_get_proc_address ("get_library_path" );
174143 fn (pythonscript_gdextension_library , gd_library_path );
175144 }
176145
@@ -183,10 +152,7 @@ static void _initialize_python() {
183152 // 3) Convert base dir into regular c string
184153 GDExtensionInt basedir_path_size ;
185154 {
186- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
187- GDExtensionInt (* fn )(GDExtensionConstStringPtr , char * , GDExtensionInt );
188- fn = pythonscript_gdextension_get_proc_address ("string_to_utf8_chars" );
189- PRAGMA_POP ;
155+ GDExtensionInterfaceStringToUtf8Chars fn = (GDExtensionInterfaceStringToUtf8Chars )(void * )pythonscript_gdextension_get_proc_address ("string_to_utf8_chars" );
190156 basedir_path_size = fn (gd_basedir_path , NULL , 0 );
191157 }
192158 // Why not using variable length array here ? Glad you asked Timmy !
@@ -196,21 +162,15 @@ static void _initialize_python() {
196162 // like we're about to do two lines down.
197163 char * basedir_path ;
198164 {
199- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
200- void * (* fn )(size_t );
201- fn = pythonscript_gdextension_get_proc_address ("mem_alloc" );
202- PRAGMA_POP ;
165+ GDExtensionInterfaceMemAlloc fn = (GDExtensionInterfaceMemAlloc )(void * )pythonscript_gdextension_get_proc_address ("mem_alloc" );
203166 basedir_path = fn (basedir_path_size + 1 );
204167 }
205168 if (basedir_path == NULL ) {
206169 GD_PRINT_ERROR ("Pythonscript: Initialization error (memory allocation failed)" );
207170 goto error ;
208171 }
209172 {
210- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
211- GDExtensionInt (* fn )(GDExtensionConstStringPtr , char * , GDExtensionInt );
212- fn = pythonscript_gdextension_get_proc_address ("string_to_utf8_chars" );
213- PRAGMA_POP ;
173+ GDExtensionInterfaceStringToUtf8Chars fn = (GDExtensionInterfaceStringToUtf8Chars )(void * )pythonscript_gdextension_get_proc_address ("string_to_utf8_chars" );
214174 fn (gd_basedir_path , basedir_path , basedir_path_size );
215175 }
216176 basedir_path [basedir_path_size ] = '\0' ;
@@ -225,10 +185,7 @@ static void _initialize_python() {
225185 basedir_path
226186 );
227187 {
228- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
229- void (* fn )(void * );
230- fn = pythonscript_gdextension_get_proc_address ("mem_free" );
231- PRAGMA_POP ;
188+ GDExtensionInterfaceMemFree fn = (GDExtensionInterfaceMemFree )(void * )pythonscript_gdextension_get_proc_address ("mem_free" );
232189 fn (basedir_path );
233190 }
234191 if (PyStatus_Exception (status )) {
@@ -394,60 +351,34 @@ DLL_EXPORT GDExtensionBool pythonscript_init(
394351
395352 // Load GDString/GDStringName contructor/destructor needed for pythonscript_gdstringname_new/delete helpers
396353
397- {
398- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
399- GDExtensionPtrConstructor (* fn )(GDExtensionVariantType , int32_t );
400- fn = pythonscript_gdextension_get_proc_address ("variant_get_ptr_constructor" );
401- PRAGMA_POP ;
402- gdstring_constructor = fn (GDEXTENSION_VARIANT_TYPE_STRING , 0 );
403- }
354+ GDExtensionInterfaceVariantGetPtrConstructor variant_get_ptr_constructor = (GDExtensionInterfaceVariantGetPtrConstructor )(void * )p_get_proc_address ("variant_get_ptr_constructor" );
355+ GDExtensionInterfaceVariantGetPtrDestructor variant_get_ptr_destructor = (GDExtensionInterfaceVariantGetPtrDestructor )(void * )p_get_proc_address ("variant_get_ptr_destructor" );
356+
357+ gdstring_constructor = variant_get_ptr_constructor (GDEXTENSION_VARIANT_TYPE_STRING , 0 );
404358 if (gdstring_constructor == NULL ) {
405359 GD_PRINT_ERROR ("Pythonscript: Initialization error (cannot retrieve `String` constructor)" );
406360 goto error ;
407361 }
408362
409- {
410- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
411- GDExtensionPtrDestructor (* fn )(GDExtensionVariantType );
412- fn = pythonscript_gdextension_get_proc_address ("variant_get_ptr_destructor" );
413- PRAGMA_POP ;
414- gdstring_destructor = fn (GDEXTENSION_VARIANT_TYPE_STRING );
415- }
363+ gdstring_destructor = variant_get_ptr_destructor (GDEXTENSION_VARIANT_TYPE_STRING );
416364 if (gdstring_destructor == NULL ) {
417365 GD_PRINT_ERROR ("Pythonscript: Initialization error (cannot retrieve `String` destructor)" );
418366 goto error ;
419367 }
420368
421- {
422- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
423- GDExtensionPtrConstructor (* fn )(GDExtensionVariantType , int32_t );
424- fn = pythonscript_gdextension_get_proc_address ("variant_get_ptr_constructor" );
425- PRAGMA_POP ;
426- gdstringname_from_gdstring_constructor = fn (GDEXTENSION_VARIANT_TYPE_STRING_NAME , 2 );
427- }
369+ gdstringname_from_gdstring_constructor = variant_get_ptr_constructor (GDEXTENSION_VARIANT_TYPE_STRING_NAME , 2 );
428370 if (gdstringname_from_gdstring_constructor == NULL ) {
429371 GD_PRINT_ERROR ("Pythonscript: Initialization error (cannot retrieve `StringName` constructor)" );
430372 goto error ;
431373 }
432374
433- {
434- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
435- GDExtensionPtrDestructor (* fn )(GDExtensionVariantType );
436- fn = pythonscript_gdextension_get_proc_address ("variant_get_ptr_destructor" );
437- PRAGMA_POP ;
438- gdstringname_destructor = fn (GDEXTENSION_VARIANT_TYPE_STRING_NAME );
439- }
375+ gdstringname_destructor = variant_get_ptr_destructor (GDEXTENSION_VARIANT_TYPE_STRING_NAME );
440376 if (gdstringname_destructor == NULL ) {
441377 GD_PRINT_ERROR ("Pythonscript: Initialization error (cannot retrieve `StringName` destructor)" );
442378 goto error ;
443379 }
444380
445- {
446- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
447- gdstring_new_with_utf8_chars = pythonscript_gdextension_get_proc_address ("string_new_with_utf8_chars" );
448- #pragma GCC diagnostic pop
449- PRAGMA_POP ;
450- }
381+ gdstring_new_with_utf8_chars = (GDExtensionInterfaceStringNewWithUtf8Chars )p_get_proc_address ("string_new_with_utf8_chars" );
451382 if (gdstring_new_with_utf8_chars == NULL ) {
452383 GD_PRINT_ERROR ("Pythonscript: Initialization error (cannot retrieve `string_new_with_utf8_chars` destructor)" );
453384 goto error ;
@@ -457,11 +388,8 @@ DLL_EXPORT GDExtensionBool pythonscript_init(
457388 // (i.e. the bindings has been generated against) and the version currently executed.
458389 GDExtensionGodotVersion godot_version ;
459390 {
460- PRAGMA_PUSH_ALLOW_INCOMPATIBLE_POINTER_TYPES ;
461- void (* fn )(GDExtensionGodotVersion * );
462- fn = pythonscript_gdextension_get_proc_address ("get_godot_version" );
463- PRAGMA_POP ;
464- fn (& godot_version );
391+ GDExtensionInterfaceGetGodotVersion get_godot_version = (GDExtensionInterfaceGetGodotVersion )p_get_proc_address ("get_godot_version" );
392+ get_godot_version (& godot_version );
465393 }
466394 if (godot_version .major != GODOT_VERSION_MAJOR ) {
467395 // Don't use GD_PRINT_ERROR here given we don't even know if it is available !
0 commit comments