|
32 | 32 | // is initialized (after that we can use the Python binding), so instead we stick with |
33 | 33 | // the biggest possible value and accept we will lose a couple of bytes on the stack ;) |
34 | 34 | #define GD_STRING_MAX_SIZE 8 |
| 35 | +#define GD_STRING_NAME_MAX_SIZE 8 |
35 | 36 |
|
36 | 37 | // Nobody ain't no time to include stdbool.h ! |
37 | 38 | #define bool unsigned int; |
@@ -70,16 +71,16 @@ DLL_EXPORT GDExtensionClassLibraryPtr pythonscript_gdextension_library = NULL; |
70 | 71 |
|
71 | 72 | static GDExtensionPtrConstructor gdstring_constructor = NULL; |
72 | 73 | static GDExtensionPtrDestructor gdstring_destructor = NULL; |
73 | | -static GDExtensionPtrConstructor gdstringname_constructor = NULL; |
| 74 | +static GDExtensionPtrConstructor gdstringname_from_gdstring_constructor = NULL; |
74 | 75 | static GDExtensionPtrDestructor gdstringname_destructor = NULL; |
75 | 76 |
|
76 | 77 | DLL_EXPORT void pythonscript_gdstringname_new(GDExtensionStringNamePtr ptr, const char *cstr) { |
77 | 78 | // Method name must be passed as a StringName object... which itself has |
78 | 79 | // to be built from a String object :( |
79 | | - GDExtensionStringPtr as_gdstring; |
| 80 | + char as_gdstring[GD_STRING_MAX_SIZE]; |
80 | 81 | const GDExtensionConstTypePtr args[1] = {&as_gdstring}; |
81 | 82 | pythonscript_gdextension->string_new_with_utf8_chars(&as_gdstring, cstr); |
82 | | - gdstringname_constructor(ptr, args); |
| 83 | + gdstringname_from_gdstring_constructor(ptr, args); |
83 | 84 | gdstring_destructor(&as_gdstring); |
84 | 85 | } |
85 | 86 |
|
@@ -123,9 +124,13 @@ static void _early_initialize() { |
123 | 124 | // Set PYTHONHOME from .so path |
124 | 125 | { |
125 | 126 | // 0) Retrieve Godot methods |
126 | | - GDExtensionStringNamePtr method_name_as_gdstringname; |
| 127 | + char method_name_as_gdstringname[GD_STRING_NAME_MAX_SIZE]; |
127 | 128 | pythonscript_gdstringname_new(&method_name_as_gdstringname, "get_base_dir"); |
128 | | - GDExtensionPtrBuiltInMethod gdstring_get_base_dir = pythonscript_gdextension->variant_get_ptr_builtin_method(GDEXTENSION_VARIANT_TYPE_STRING, &method_name_as_gdstringname, 3942272618); |
| 129 | + GDExtensionPtrBuiltInMethod gdstring_get_base_dir = pythonscript_gdextension->variant_get_ptr_builtin_method( |
| 130 | + GDEXTENSION_VARIANT_TYPE_STRING, |
| 131 | + &method_name_as_gdstringname, |
| 132 | + 3942272618 |
| 133 | + ); |
129 | 134 | pythonscript_gdstringname_delete(&method_name_as_gdstringname); |
130 | 135 | if (gdstring_get_base_dir == NULL) { |
131 | 136 | GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `String.get_base_dir` method)"); |
@@ -336,8 +341,8 @@ DLL_EXPORT GDExtensionBool pythonscript_init( |
336 | 341 | GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `String` destructor)"); |
337 | 342 | goto error; |
338 | 343 | } |
339 | | - gdstringname_constructor = pythonscript_gdextension->variant_get_ptr_constructor(GDEXTENSION_VARIANT_TYPE_STRING_NAME, 1); |
340 | | - if (gdstringname_constructor == NULL) { |
| 344 | + gdstringname_from_gdstring_constructor = pythonscript_gdextension->variant_get_ptr_constructor(GDEXTENSION_VARIANT_TYPE_STRING_NAME, 2); |
| 345 | + if (gdstringname_from_gdstring_constructor == NULL) { |
341 | 346 | GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `StringName` constructor)"); |
342 | 347 | goto error; |
343 | 348 | } |
|
0 commit comments