diff --git a/src/_pythonscript_editor.pxi b/src/_pythonscript_editor.pxi index e0248678..1714961e 100644 --- a/src/_pythonscript_editor.pxi +++ b/src/_pythonscript_editor.pxi @@ -46,7 +46,7 @@ cdef public void _pythonscript_get_reserved_words( "yield", ] for keyword in keywords: - string = gd_string_from_utf8(keyword, keyword.len()) + string = gd_string_from_utf8_and_len(keyword, keyword.len()) gd_packed_string_array_append(&arr, &string) gd_string_del(&string) @@ -66,7 +66,7 @@ cdef public void _pythonscript_get_recognized_extensions( "py", ] for keyword in keywords: - string = gd_string_from_utf8(keyword, keyword.len()) + string = gd_string_from_utf8_and_len(keyword, keyword.len()) gd_packed_string_array_append(&arr, &string) gd_string_del(&string) @@ -86,7 +86,7 @@ cdef public void _pythonscript_get_string_delimiters( "\"\"\" \"\"\"", ] for keyword in keywords: - string = gd_string_from_utf8(keyword, keyword.len()) + string = gd_string_from_utf8_and_len(keyword, keyword.len()) gd_packed_string_array_append(&arr, &string) gd_string_del(&string) @@ -96,7 +96,7 @@ cdef _register_editor_methods(): pass # cdef GDExtensionClassMethodInfo info - # pythonscript_gdstringname_new(&info.name, "_get_reserved_words") + # info.name = gd_string_name_from_utf8("_get_reserved_words") # info.method_userdata = NULL # info.call_func = NULL # # info.ptrcall_func = &_pythonscript_get_reserved_words @@ -113,9 +113,9 @@ cdef _register_editor_methods(): # "PythonScriptLanguageExtension", # &info, # ) - # pythonscript_gdstringname_delete(&info.name) + # gd_string_name_del(&info.name) - # pythonscript_gdstringname_new(&info.name, "_get_recognized_extensions") + # info.name = gd_string_name_from_utf8("_get_recognized_extensions") # info.method_userdata = NULL # info.call_func = NULL # # info.ptrcall_func = &_pythonscript_get_recognized_extensions @@ -132,9 +132,9 @@ cdef _register_editor_methods(): # "PythonScriptLanguageExtension", # &info, # ) - # pythonscript_gdstringname_delete(&info.name) + # gd_string_name_del(&info.name) - # pythonscript_gdstringname_new(&info.name, "_get_string_delimiters") + # info.name = gd_string_name_from_utf8("_get_string_delimiters") # info.method_userdata = NULL # info.call_func = NULL # # info.ptrcall_func = &_pythonscript_get_string_delimiters @@ -151,4 +151,4 @@ cdef _register_editor_methods(): # "PythonScriptLanguageExtension", # &info, # ) - # pythonscript_gdstringname_delete(&info.name) + # gd_string_name_del(&info.name) diff --git a/src/godot/builtins_pyx/class.pyx.j2 b/src/godot/builtins_pyx/class.pyx.j2 index 14ca2421..174e9d88 100644 --- a/src/godot/builtins_pyx/class.pyx.j2 +++ b/src/godot/builtins_pyx/class.pyx.j2 @@ -10,10 +10,9 @@ def {{ c.name }}(self): cdef gd_variant_t gdvariant # TODO: cache the constant on first fetch ? - cdef gd_string_name_t gdname - pythonscript_gdstringname_new(&gdname, "{{ c.original_name }}") + cdef gd_string_name_t gdname = gd_string_name_from_utf8("{{ c.original_name }}") pythonscript_gdextension.variant_get_constant_value({{ builtin.variant_type_name }}, &gdname, &gdvariant) - pythonscript_gdstringname_delete(&gdname) + gd_string_name_del(&gdname) return gd_variant_steal_into_pyobj(&gdvariant) # No need to destroy gdvariant given the conversion has stolen ownership on data ! {% endif %} diff --git a/src/godot/classes.pyx.j2 b/src/godot/classes.pyx.j2 index bba0ff6a..91d6a340 100644 --- a/src/godot/classes.pyx.j2 +++ b/src/godot/classes.pyx.j2 @@ -87,10 +87,9 @@ cdef class {{ cls.cy_type }} cdef object _load_singleton(str name): cdef object cls = _load_class(name) {# cdef GDExtensionObjectPtr gdobj = pythonscript_gdextension.global_get_singleton(&(cls._gd_name)._gd_data) #} - cdef gd_string_name_t gdname - pythonscript_gdstringname_new(&gdname, name.encode()) + cdef gd_string_name_t gdname = gd_string_name_from_utf8(name.encode()) cdef GDExtensionObjectPtr gdobj = pythonscript_gdextension.global_get_singleton(&gdname) - pythonscript_gdstringname_delete(&gdname) + gd_string_name_del(&gdname) return cls._from_ptr(gdobj) {# {% for singleton in api.singletons %} cdef {{ singleton.type.py_type }} singleton_{{ singleton.name }} = {{ singleton.type.py_type }}.__new__({{ singleton.type.py_type }}) diff --git a/src/godot/hazmat/extension_class.pxd b/src/godot/hazmat/extension_class.pxd index 79e5a4e6..7944d7b9 100644 --- a/src/godot/hazmat/extension_class.pxd +++ b/src/godot/hazmat/extension_class.pxd @@ -29,8 +29,7 @@ cdef inline list _get_extension_gc_protector() noexcept: cdef inline void unregister_extension_class(bytes class_name) noexcept: - cdef gd_string_name_t gd_class_name - pythonscript_gdstringname_new(&gd_class_name, class_name) + cdef gd_string_name_t gd_class_name = gd_string_name_from_utf8(class_name) pythonscript_gdextension.classdb_unregister_extension_class( pythonscript_gdextension_library, &gd_class_name, @@ -80,10 +79,8 @@ cdef inline void register_extension_class_creation( # Don't increment refcount given we rely on gc protector info.class_userdata = spec # void* - cdef gd_string_name_t gdname - cdef gd_string_name_t gdname_parent - pythonscript_gdstringname_new(&gdname, class_name) - pythonscript_gdstringname_new(&gdname_parent, parent_class_name) + cdef gd_string_name_t gdname = gd_string_name_from_utf8(class_name) + cdef gd_string_name_t gdname_parent = gd_string_name_from_utf8(parent_class_name) # TODO: correct me once https://github.com/godotengine/godot/pull/67121 is merged pythonscript_gdextension.classdb_register_extension_class( pythonscript_gdextension_library, diff --git a/src/godot/hazmat/gdapi.pxd.j2 b/src/godot/hazmat/gdapi.pxd.j2 index 272cf191..46526142 100644 --- a/src/godot/hazmat/gdapi.pxd.j2 +++ b/src/godot/hazmat/gdapi.pxd.j2 @@ -46,7 +46,13 @@ cdef extern from "Python.h": object PyUnicode_DecodeUTF32(const char *s, ssize_t size, const char *errors, int *byteorder) -cdef inline gd_string_t gd_string_from_utf8(const char *cstr, ssize_t cstr_size): +cdef inline gd_string_t gd_string_from_utf8(const char *cstr): + cdef gd_string_t gdstr + pythonscript_gdextension.string_new_with_utf8_chars(&gdstr, cstr) + return gdstr + + +cdef inline gd_string_t gd_string_from_utf8_and_len(const char *cstr, ssize_t cstr_size): cdef gd_string_t gdstr pythonscript_gdextension.string_new_with_utf8_chars_and_len(&gdstr, cstr, cstr_size) return gdstr @@ -55,7 +61,7 @@ cdef inline gd_string_t gd_string_from_utf8(const char *cstr, ssize_t cstr_size) cdef inline gd_string_t gd_string_from_unchecked_pystr(object pystr): cdef ssize_t buffsize cdef const char *buff = PyUnicode_AsUTF8AndSize(pystr, &buffsize) - return gd_string_from_utf8(buff, buffsize) + return gd_string_from_utf8_and_len(buff, buffsize) cdef inline object gd_string_to_pystr(gd_string_t *gdstr): @@ -77,6 +83,18 @@ cdef inline gd_string_name_t gd_string_name_from_pybytes(bytes cstr): return gdstrname +cdef inline gd_string_name_t gd_string_name_from_utf8(const char *cstr): + cdef gd_string_name_t gdstr + pythonscript_gdextension.string_name_new_with_utf8_chars(&gdstr, cstr) + return gdstr + + +cdef inline gd_string_name_t gd_string_name_from_utf8_and_len(const char *cstr, ssize_t cstr_size): + cdef gd_string_name_t gdstr + pythonscript_gdextension.string_name_new_with_utf8_chars_and_len(&gdstr, cstr, cstr_size) + return gdstr + + ############################################################################## # Builtins stucts # ############################################################################## diff --git a/src/godot/hazmat/gdnative_ptrs.pxd.j2 b/src/godot/hazmat/gdnative_ptrs.pxd.j2 index d3557e4c..fd1e4bd8 100644 --- a/src/godot/hazmat/gdnative_ptrs.pxd.j2 +++ b/src/godot/hazmat/gdnative_ptrs.pxd.j2 @@ -72,9 +72,9 @@ cdef struct LoadedGDExtensionInterface: void (*string_new_with_wide_chars)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents) void (*string_new_with_latin1_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) void (*string_new_with_utf8_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) - void (*string_new_with_utf16_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_size) - void (*string_new_with_utf32_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_size) - void (*string_new_with_wide_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_size) + void (*string_new_with_utf16_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count) + void (*string_new_with_utf32_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count) + void (*string_new_with_wide_chars_and_len)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count) GDExtensionInt (*string_to_latin1_chars)(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length) GDExtensionInt (*string_to_utf8_chars)(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length) GDExtensionInt (*string_to_utf16_chars)(GDExtensionConstStringPtr p_self, char16_t *r_text, GDExtensionInt p_max_write_length) @@ -87,6 +87,10 @@ cdef struct LoadedGDExtensionInterface: void (*string_operator_plus_eq_cstr)(GDExtensionStringPtr p_self, const char *p_b) void (*string_operator_plus_eq_wcstr)(GDExtensionStringPtr p_self, const wchar_t *p_b) void (*string_operator_plus_eq_c32str)(GDExtensionStringPtr p_self, const char32_t *p_b) + GDExtensionInt (*string_resize)(GDExtensionStringPtr p_self, GDExtensionInt p_resize) + void (*string_name_new_with_latin1_chars)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents, GDExtensionBool p_is_static) + void (*string_name_new_with_utf8_chars)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents) + void (*string_name_new_with_utf8_chars_and_len)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents, GDExtensionInt p_size) GDExtensionInt (*xml_parser_open_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size) void (*file_access_store_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length) uint64_t (*file_access_get_buffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length) @@ -122,6 +126,7 @@ cdef struct LoadedGDExtensionInterface: GDExtensionObjectPtr (*global_get_singleton)(GDExtensionConstStringNamePtr p_name) void *(*object_get_instance_binding)(GDExtensionObjectPtr p_o, void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks) void (*object_set_instance_binding)(GDExtensionObjectPtr p_o, void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks) + void (*object_free_instance_binding)(GDExtensionObjectPtr p_o, void *p_token) void (*object_set_instance)(GDExtensionObjectPtr p_o, GDExtensionConstStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance) GDExtensionBool (*object_get_class_name)(GDExtensionConstObjectPtr p_object, GDExtensionClassLibraryPtr p_library, GDExtensionUninitializedStringNamePtr r_class_name) GDExtensionObjectPtr (*object_cast_to)(GDExtensionConstObjectPtr p_object, void *p_class_tag) @@ -130,13 +135,21 @@ cdef struct LoadedGDExtensionInterface: GDExtensionObjectPtr (*ref_get_object)(GDExtensionConstRefPtr p_ref) void (*ref_set_object)(GDExtensionRefPtr p_ref, GDExtensionObjectPtr p_object) GDExtensionScriptInstancePtr (*script_instance_create)(const GDExtensionScriptInstanceInfo *p_info, GDExtensionScriptInstanceDataPtr p_instance_data) + GDExtensionScriptInstancePtr (*script_instance_create2)(const GDExtensionScriptInstanceInfo2 *p_info, GDExtensionScriptInstanceDataPtr p_instance_data) + GDExtensionScriptInstancePtr (*place_holder_script_instance_create)(GDExtensionObjectPtr p_language, GDExtensionObjectPtr p_script, GDExtensionObjectPtr p_owner) + void (*place_holder_script_instance_update)(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values) + GDExtensionScriptInstanceDataPtr (*object_get_script_instance)(GDExtensionConstObjectPtr p_object, GDExtensionObjectPtr p_language) + void (*callable_custom_create)(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo *p_callable_custom_info) + void *(*callable_custom_get_user_data)(GDExtensionConstTypePtr p_callable, void *p_token) GDExtensionObjectPtr (*classdb_construct_object)(GDExtensionConstStringNamePtr p_classname) GDExtensionMethodBindPtr (*classdb_get_method_bind)(GDExtensionConstStringNamePtr p_classname, GDExtensionConstStringNamePtr p_methodname, GDExtensionInt p_hash) void *(*classdb_get_class_tag)(GDExtensionConstStringNamePtr p_classname) void (*classdb_register_extension_class)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs) + void (*classdb_register_extension_class2)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs) void (*classdb_register_extension_class_method)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info) void (*classdb_register_extension_class_integer_constant)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_enum_name, GDExtensionConstStringNamePtr p_constant_name, GDExtensionInt p_constant_value, GDExtensionBool p_is_bitfield) void (*classdb_register_extension_class_property)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter) + void (*classdb_register_extension_class_property_indexed)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter, GDExtensionInt p_index) void (*classdb_register_extension_class_property_group)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringPtr p_group_name, GDExtensionConstStringPtr p_prefix) void (*classdb_register_extension_class_property_subgroup)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringPtr p_subgroup_name, GDExtensionConstStringPtr p_prefix) void (*classdb_register_extension_class_signal)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_signal_name, const GDExtensionPropertyInfo *p_argument_info, GDExtensionInt p_argument_count) @@ -163,13 +176,9 @@ cdef extern from * nogil: #endif DLL_IMPORT extern GDExtensionInterfaceGetProcAddress pythonscript_gdextension_get_proc_address; DLL_IMPORT extern GDExtensionClassLibraryPtr pythonscript_gdextension_library; - DLL_IMPORT extern void pythonscript_gdstringname_new(GDExtensionStringNamePtr ptr, const char *cstr); - DLL_IMPORT extern void pythonscript_gdstringname_delete(GDExtensionStringNamePtr ptr); """ - cdef const GDExtensionInterfaceGetProcAddress pythonscript_gdextension_get_proc_address; + cdef const GDExtensionInterfaceGetProcAddress pythonscript_gdextension_get_proc_address cdef const GDExtensionClassLibraryPtr pythonscript_gdextension_library - cdef void pythonscript_gdstringname_new(GDExtensionStringNamePtr ptr, const char *cstr) - cdef void pythonscript_gdstringname_delete(GDExtensionStringNamePtr ptr) ############################################################################## diff --git a/src/godot/hazmat/gdnative_ptrs.pyx.j2 b/src/godot/hazmat/gdnative_ptrs.pyx.j2 index 97b02c73..47b7884c 100644 --- a/src/godot/hazmat/gdnative_ptrs.pyx.j2 +++ b/src/godot/hazmat/gdnative_ptrs.pyx.j2 @@ -96,6 +96,10 @@ pythonscript_gdextension.string_operator_plus_eq_char = pythonscript_gdextension_get_proc_address("string_operator_plus_eq_cstr") pythonscript_gdextension.string_operator_plus_eq_wcstr = pythonscript_gdextension_get_proc_address("string_operator_plus_eq_wcstr") pythonscript_gdextension.string_operator_plus_eq_c32str = pythonscript_gdextension_get_proc_address("string_operator_plus_eq_c32str") +pythonscript_gdextension.string_resize = pythonscript_gdextension_get_proc_address("string_resize") +pythonscript_gdextension.string_name_new_with_latin1_chars = pythonscript_gdextension_get_proc_address("string_name_new_with_latin1_chars") +pythonscript_gdextension.string_name_new_with_utf8_chars = pythonscript_gdextension_get_proc_address("string_name_new_with_utf8_chars") +pythonscript_gdextension.string_name_new_with_utf8_chars_and_len = pythonscript_gdextension_get_proc_address("string_name_new_with_utf8_chars_and_len") pythonscript_gdextension.xml_parser_open_buffer = pythonscript_gdextension_get_proc_address("xml_parser_open_buffer") pythonscript_gdextension.file_access_store_buffer = pythonscript_gdextension_get_proc_address("file_access_store_buffer") pythonscript_gdextension.file_access_get_buffer = pythonscript_gdextension_get_proc_address("file_access_get_buffer") @@ -131,6 +135,7 @@ pythonscript_gdextension.object_destroy = python pythonscript_gdextension.global_get_singleton = pythonscript_gdextension_get_proc_address("global_get_singleton") pythonscript_gdextension.object_get_instance_binding = pythonscript_gdextension_get_proc_address("object_get_instance_binding") pythonscript_gdextension.object_set_instance_binding = pythonscript_gdextension_get_proc_address("object_set_instance_binding") +pythonscript_gdextension.object_free_instance_binding = pythonscript_gdextension_get_proc_address("object_free_instance_binding") pythonscript_gdextension.object_set_instance = pythonscript_gdextension_get_proc_address("object_set_instance") pythonscript_gdextension.object_get_class_name = pythonscript_gdextension_get_proc_address("object_get_class_name") pythonscript_gdextension.object_cast_to = pythonscript_gdextension_get_proc_address("object_cast_to") @@ -139,13 +144,21 @@ pythonscript_gdextension.object_get_instance_id = pythonscript_gdextension_get_proc_address("ref_get_object") pythonscript_gdextension.ref_set_object = pythonscript_gdextension_get_proc_address("ref_set_object") pythonscript_gdextension.script_instance_create = pythonscript_gdextension_get_proc_address("script_instance_create") +pythonscript_gdextension.script_instance_create2 = pythonscript_gdextension_get_proc_address("script_instance_create2") +pythonscript_gdextension.place_holder_script_instance_create = pythonscript_gdextension_get_proc_address("place_holder_script_instance_create") +pythonscript_gdextension.place_holder_script_instance_update = pythonscript_gdextension_get_proc_address("place_holder_script_instance_update") +pythonscript_gdextension.object_get_script_instance = pythonscript_gdextension_get_proc_address("object_get_script_instance") +pythonscript_gdextension.callable_custom_create = pythonscript_gdextension_get_proc_address("callable_custom_create") +pythonscript_gdextension.callable_custom_get_user_data = pythonscript_gdextension_get_proc_address("callable_custom_get_user_data") pythonscript_gdextension.classdb_construct_object = pythonscript_gdextension_get_proc_address("classdb_construct_object") pythonscript_gdextension.classdb_get_method_bind = pythonscript_gdextension_get_proc_address("classdb_get_method_bind") pythonscript_gdextension.classdb_get_class_tag = pythonscript_gdextension_get_proc_address("classdb_get_class_tag") pythonscript_gdextension.classdb_register_extension_class = pythonscript_gdextension_get_proc_address("classdb_register_extension_class") +pythonscript_gdextension.classdb_register_extension_class2 = pythonscript_gdextension_get_proc_address("classdb_register_extension_class2") pythonscript_gdextension.classdb_register_extension_class_method = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_method") pythonscript_gdextension.classdb_register_extension_class_integer_constant = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_integer_constant") pythonscript_gdextension.classdb_register_extension_class_property = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_property") +pythonscript_gdextension.classdb_register_extension_class_property_indexed = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_property_indexed") pythonscript_gdextension.classdb_register_extension_class_property_group = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_property_group") pythonscript_gdextension.classdb_register_extension_class_property_subgroup = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_property_subgroup") pythonscript_gdextension.classdb_register_extension_class_signal = pythonscript_gdextension_get_proc_address("classdb_register_extension_class_signal") @@ -160,6 +173,9 @@ pythonscript_gdextension.editor_remove_plugin = minimum_initialization_level = GDEXTENSION_INITIALIZATION_CORE;