@@ -7,7 +7,17 @@ from godot.classes cimport BaseGDObject
77
88
99# LibGodot API
10- cdef extern from " *" :
10+ cdef extern from * :
11+ """
12+ typedef struct {
13+ const char* key;
14+ void* val;
15+ } LibGodotExtensionParameter;
16+
17+ GDExtensionObjectPtr libgodot_create_godot_instance(int p_argc, char *p_argv[], GDExtensionInitializationFunction p_init_func, LibGodotExtensionParameter *p_params);
18+ void libgodot_destroy_godot_instance(GDExtensionObjectPtr p_godot_instance);
19+ """
20+
1121 ctypedef struct LibGodotExtensionParameter:
1222 const char * key
1323 void * val
@@ -34,9 +44,10 @@ def create_godot_instance(argv: list[str]):
3444 if gd_instance == NULL :
3545 raise RuntimeError (" Failed to create Godot instance" )
3646
47+ cdef BaseGDObject instance
3748 try :
3849 from godot.classes import GodotInstance
39- cdef BaseGDObject instance = GodotInstance.__new__ (GodotInstance)
50+ instance = GodotInstance.__new__ (GodotInstance)
4051 _libgodot_instance = instance
4152
4253 _libgodot_init_lock.release()
@@ -45,7 +56,7 @@ def create_godot_instance(argv: list[str]):
4556
4657 finally :
4758 with _libgodot_init_lock:
48- libgodot_destroy_godot_instance(instance._gd_instance )
59+ libgodot_destroy_godot_instance(instance._gd_ptr )
4960 _libgodot_instance = None
5061
5162
@@ -59,13 +70,13 @@ cdef GDExtensionObjectPtr _create_godot_instance(argv: list[str]):
5970 assert c_argv != NULL
6071 try :
6172 for i in range (length):
62- c_argv[i] = < const char * > pybytes_argv
73+ c_argv[i] = < char * > pybytes_argv
6374
6475 # `c_argv` is ready, now we can initialize Godot instance !
6576 return libgodot_create_godot_instance(
6677 len (argv),
6778 c_argv,
68- pythonscript_init ,
79+ _pythonscript_init ,
6980 NULL
7081 )
7182
@@ -80,17 +91,21 @@ cdef GDExtensionObjectPtr _create_godot_instance(argv: list[str]):
8091
8192# Those symbols are defined in `pythonscript_gdextension_ptrs.c` which is
8293# going to be compiled together with this file into a single shared library.
83- cdef extern from " *" :
94+ cdef extern from * :
95+ """
96+ void init_pythonscript_gdextension();
97+ """
98+
8499 const GDExtensionInterfaceGetProcAddress pythonscript_gdptr_get_proc_address
85100 const GDExtensionClassLibraryPtr pythonscript_gdptr_library
86101 void init_pythonscript_gdextension()
87102
88103
89- cdef public GDExtensionBool pythonscript_init (
90- const GDExtensionInterfaceGetProcAddress p_get_proc_address,
91- const GDExtensionClassLibraryPtr p_library,
104+ cdef GDExtensionBool _pythonscript_init (
105+ GDExtensionInterfaceGetProcAddress p_get_proc_address,
106+ GDExtensionClassLibraryPtr p_library,
92107 GDExtensionInitialization * r_initialization
93- ):
108+ ) noexcept with gil :
94109 print (' [libgodot] pythonscript_init()' , flush= True )
95110
96111 # `pythonscript_gdptr_*` must be set as early as possible given it is never
@@ -107,22 +122,22 @@ cdef public GDExtensionBool pythonscript_init(
107122 # Initialize as early as possible, this way we can have 3rd party plugins written
108123 # in Python/Cython that can do things at this level
109124 r_initialization.minimum_initialization_level = GDEXTENSION_INITIALIZATION_CORE
110- r_initialization.userdata = NULL
125+ r_initialization.userdata = NULL
111126 r_initialization.initialize = _initialize
112127 r_initialization.deinitialize = _deinitialize
113128
114129
115- cdef void _initialize(void * userdata, GDExtensionInitializationLevel p_level):
130+ cdef void _initialize(void * userdata, GDExtensionInitializationLevel p_level) noexcept with gil :
116131 print (f' [libgodot] _initialize({p_level})' , flush= True )
117132
118133 import godot._lang
119- pythonscript_initialize = < void (* )(int )> godot._lang.pythonscript_initialize_function_ptr
134+ pythonscript_initialize = < void (* )(int )>< size_t > godot._lang.pythonscript_initialize_function_ptr
120135 pythonscript_initialize(p_level);
121136
122137
123- cdef void _deinitialize(void * userdata, GDExtensionInitializationLevel p_level):
138+ cdef void _deinitialize(void * userdata, GDExtensionInitializationLevel p_level) noexcept with gil :
124139 print (f' [libgodot] _deinitialize({p_level})' , flush= True )
125140
126141 import godot._lang
127- pythonscript_deinitialize = < void (* )(int )> godot._lang.pythonscript_deinitialize_function_ptr
142+ pythonscript_deinitialize = < void (* )(int )>< size_t > godot._lang.pythonscript_deinitialize_function_ptr
128143 pythonscript_deinitialize(p_level);
0 commit comments