Skip to content

Commit cfc4868

Browse files
committed
Fix string name conversion in src/pythonscript.c
1 parent 3931ed3 commit cfc4868

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/pythonscript.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// is initialized (after that we can use the Python binding), so instead we stick with
3333
// the biggest possible value and accept we will lose a couple of bytes on the stack ;)
3434
#define GD_STRING_MAX_SIZE 8
35+
#define GD_STRING_NAME_MAX_SIZE 8
3536

3637
// Nobody ain't no time to include stdbool.h !
3738
#define bool unsigned int;
@@ -70,16 +71,16 @@ DLL_EXPORT GDExtensionClassLibraryPtr pythonscript_gdextension_library = NULL;
7071

7172
static GDExtensionPtrConstructor gdstring_constructor = NULL;
7273
static GDExtensionPtrDestructor gdstring_destructor = NULL;
73-
static GDExtensionPtrConstructor gdstringname_constructor = NULL;
74+
static GDExtensionPtrConstructor gdstringname_from_gdstring_constructor = NULL;
7475
static GDExtensionPtrDestructor gdstringname_destructor = NULL;
7576

7677
DLL_EXPORT void pythonscript_gdstringname_new(GDExtensionStringNamePtr ptr, const char *cstr) {
7778
// Method name must be passed as a StringName object... which itself has
7879
// to be built from a String object :(
79-
GDExtensionStringPtr as_gdstring;
80+
char as_gdstring[GD_STRING_MAX_SIZE];
8081
const GDExtensionConstTypePtr args[1] = {&as_gdstring};
8182
pythonscript_gdextension->string_new_with_utf8_chars(&as_gdstring, cstr);
82-
gdstringname_constructor(ptr, args);
83+
gdstringname_from_gdstring_constructor(ptr, args);
8384
gdstring_destructor(&as_gdstring);
8485
}
8586

@@ -123,9 +124,13 @@ static void _early_initialize() {
123124
// Set PYTHONHOME from .so path
124125
{
125126
// 0) Retrieve Godot methods
126-
GDExtensionStringNamePtr method_name_as_gdstringname;
127+
char method_name_as_gdstringname[GD_STRING_NAME_MAX_SIZE];
127128
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+
);
129134
pythonscript_gdstringname_delete(&method_name_as_gdstringname);
130135
if (gdstring_get_base_dir == NULL) {
131136
GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `String.get_base_dir` method)");
@@ -336,8 +341,8 @@ DLL_EXPORT GDExtensionBool pythonscript_init(
336341
GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `String` destructor)");
337342
goto error;
338343
}
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) {
341346
GD_PRINT_ERROR("Pythonscript: Initialization error (cannot retrieve `StringName` constructor)");
342347
goto error;
343348
}

0 commit comments

Comments
 (0)