@@ -86,7 +86,9 @@ def variant_to_pyobj(p_gdvar):
8686
8787 elif gdtype == lib .GODOT_VARIANT_TYPE_STRING :
8888 raw = lib .godot_variant_as_string (p_gdvar )
89- return godot_string_to_pyobj (ffi .addressof (raw ))
89+ ret = godot_string_to_pyobj (ffi .addressof (raw ))
90+ lib .godot_string_destroy (ffi .addressof (raw ))
91+ return ret
9092
9193 elif gdtype == lib .GODOT_VARIANT_TYPE_VECTOR2 :
9294 raw = lib .godot_variant_as_vector2 (p_gdvar )
@@ -129,8 +131,9 @@ def variant_to_pyobj(p_gdvar):
129131 return godot_bindings_module .Color .build_from_gdobj (raw )
130132
131133 elif gdtype == lib .GODOT_VARIANT_TYPE_NODE_PATH :
132- raw = lib .godot_variant_as_node_path (p_gdvar )
133- return godot_bindings_module .NodePath .build_from_gdobj (raw )
134+ p_raw = godot_node_path_alloc (initialized = False )
135+ p_raw [0 ] = lib .godot_variant_as_node_path (p_gdvar )
136+ return godot_bindings_module .NodePath .build_from_gdobj (p_raw , steal = True )
134137
135138 elif gdtype == lib .GODOT_VARIANT_TYPE_RID :
136139 raw = lib .godot_variant_as_rid (p_gdvar )
@@ -143,40 +146,49 @@ def variant_to_pyobj(p_gdvar):
143146 return getattr (godot_bindings_module , tmpobj .get_class ())(p_raw )
144147
145148 elif gdtype == lib .GODOT_VARIANT_TYPE_DICTIONARY :
146- raw = lib .godot_variant_as_dictionary (p_gdvar )
147- return godot_bindings_module .Dictionary .build_from_gdobj (raw )
149+ p_raw = godot_dictionary_alloc (initialized = False )
150+ p_raw [0 ] = lib .godot_variant_as_dictionary (p_gdvar )
151+ return godot_bindings_module .Dictionary .build_from_gdobj (p_raw , steal = True )
148152
149153 elif gdtype == lib .GODOT_VARIANT_TYPE_ARRAY :
150- raw = lib .godot_variant_as_array (p_gdvar )
151- return godot_bindings_module .Array .build_from_gdobj (raw )
154+ p_raw = godot_array_alloc (initialized = False )
155+ p_raw [0 ] = lib .godot_variant_as_array (p_gdvar )
156+ return godot_bindings_module .Array .build_from_gdobj (p_raw , steal = True )
152157
153158 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY :
154- raw = lib .godot_variant_as_pool_byte_array (p_gdvar )
155- return godot_bindings_module .PoolByteArray .build_from_gdobj (raw )
159+ p_raw = godot_pool_byte_array_alloc (initialized = False )
160+ p_raw [0 ] = lib .godot_variant_as_pool_byte_array (p_gdvar )
161+ return godot_bindings_module .PoolByteArray .build_from_gdobj (p_raw , steal = True )
156162
157163 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_INT_ARRAY :
158- raw = lib .godot_variant_as_pool_int_array (p_gdvar )
159- return godot_bindings_module .PoolIntArray .build_from_gdobj (raw )
164+ p_raw = godot_pool_int_array_alloc (initialized = False )
165+ p_raw [0 ] = lib .godot_variant_as_pool_int_array (p_gdvar )
166+ return godot_bindings_module .PoolIntArray .build_from_gdobj (p_raw , steal = True )
160167
161168 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_REAL_ARRAY :
162- raw = lib .godot_variant_as_pool_real_array (p_gdvar )
163- return godot_bindings_module .PoolRealArray .build_from_gdobj (raw )
169+ p_raw = godot_pool_real_array_alloc (initialized = False )
170+ p_raw [0 ] = lib .godot_variant_as_pool_real_array (p_gdvar )
171+ return godot_bindings_module .PoolRealArray .build_from_gdobj (p_raw , steal = True )
164172
165173 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_STRING_ARRAY :
166- raw = lib .godot_variant_as_pool_string_array (p_gdvar )
167- return godot_bindings_module .PoolStringArray .build_from_gdobj (raw )
174+ p_raw = godot_pool_string_array_alloc (initialized = False )
175+ p_raw [0 ] = lib .godot_variant_as_pool_string_array (p_gdvar )
176+ return godot_bindings_module .PoolStringArray .build_from_gdobj (p_raw , steal = True )
168177
169178 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY :
170- raw = lib .godot_variant_as_pool_vector2_array (p_gdvar )
171- return godot_bindings_module .PoolVector2Array .build_from_gdobj (raw )
179+ p_raw = godot_pool_vector2_array_alloc (initialized = False )
180+ p_raw [0 ] = lib .godot_variant_as_pool_vector2_array (p_gdvar )
181+ return godot_bindings_module .PoolVector2Array .build_from_gdobj (p_raw , steal = True )
172182
173183 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY :
174- raw = lib .godot_variant_as_pool_vector3_array (p_gdvar )
175- return godot_bindings_module .PoolVector3Array .build_from_gdobj (raw )
184+ p_raw = godot_pool_vector3_array_alloc (initialized = False )
185+ p_raw [0 ] = lib .godot_variant_as_pool_vector3_array (p_gdvar )
186+ return godot_bindings_module .PoolVector3Array .build_from_gdobj (p_raw , steal = True )
176187
177188 elif gdtype == lib .GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY :
178- raw = lib .godot_variant_as_pool_color_array (p_gdvar )
179- return godot_bindings_module .PoolColorArray .build_from_gdobj (raw )
189+ p_raw = godot_pool_color_array_alloc (initialized = False )
190+ p_raw [0 ] = lib .godot_variant_as_pool_color_array (p_gdvar )
191+ return godot_bindings_module .PoolColorArray .build_from_gdobj (p_raw , steal = True )
180192
181193 else :
182194 raise TypeError (
@@ -208,7 +220,7 @@ def pyobj_to_variant(pyobj, p_gdvar=None, for_ffi_return=False):
208220 elif (isinstance (pyobj , float )):
209221 lib .godot_variant_new_real (p_gdvar , pyobj )
210222 elif (isinstance (pyobj , str )):
211- gdstr = godot_string_alloc ()
223+ gdstr = godot_string_alloc (initialized = False )
212224 lib .godot_string_new_with_wide_string (gdstr , pyobj , len (pyobj ))
213225 lib .godot_variant_new_string (p_gdvar , gdstr )
214226 elif isinstance (pyobj , BaseBuiltin ):
@@ -486,7 +498,7 @@ def pyobj_to_gdobj(pyobj, steal_gdobj=True):
486498 return godot_real_alloc (pyobj )
487499
488500 elif isinstance (pyobj , str ):
489- gdobj = godot_string_alloc ()
501+ gdobj = godot_string_alloc (initialized = False )
490502 lib .godot_string_new_with_wide_string (gdobj , pyobj , - 1 )
491503 return gdobj
492504
0 commit comments