diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 66b8d5cbdd8..485bf4b9df0 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -49,19 +49,6 @@ def _build_gdnative_api_struct_header(api): 'extern "C" {', '#endif', '', - 'typedef struct godot_gdnative_api_version {', - '\tunsigned int major;', - '\tunsigned int minor;', - '} godot_gdnative_api_version;', - '', - 'typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;', - '', - 'struct godot_gdnative_api_struct {', - '\tunsigned int type;', - '\tgodot_gdnative_api_version version;', - '\tconst godot_gdnative_api_struct *next;', - '};', - '', 'enum GDNATIVE_API_TYPES {', '\tGDNATIVE_' + api['core']['type'] + ',' ] diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 44d6dffc851..7949ca182f5 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -109,6 +109,9 @@ Ref GDNative::get_library() { return library; } +extern "C" void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); +extern "C" void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what); + bool GDNative::initialize() { if (library.is_null()) { ERR_PRINT("No library set, can't initialize GDNative object"); @@ -168,6 +171,8 @@ bool GDNative::initialize() { options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + options.report_version_mismatch = &_gdnative_report_version_mismatch; + options.report_loading_error = &_gdnative_report_loading_error; options.gd_native_library = (godot_object *)(get_library().ptr()); options.active_library_path = (godot_string *)&path; diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 6dfa7ec20bf..34b73558d52 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -36,6 +36,8 @@ #include "os/os.h" #include "variant.h" +#include "modules/gdnative/gdnative.h" + #ifdef __cplusplus extern "C" { #endif @@ -137,6 +139,32 @@ void GDAPI godot_print(const godot_string *p_message) { print_line(*(String *)p_message); } +void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": Extension \"" + p_ext + "\" can't be loaded.\n"; + + Dictionary versions; + versions["have_major"] = p_have.major; + versions["have_minor"] = p_have.minor; + versions["want_major"] = p_want.major; + versions["want_minor"] = p_want.minor; + + message += String("Got version {have_major}.{have_minor} but needs {want_major}.{want_minor}!").format(versions); + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + +void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": " + p_what; + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 781b8754bd5..67a037736c9 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -89,11 +89,6 @@ wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, cons return self->operator[](p_idx); } -const char GDAPI *godot_string_c_str(const godot_string *p_self) { - const String *self = (const String *)p_self; - return self->utf8().get_data(); -} - const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) { const String *self = (const String *)p_self; return self->c_str(); diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 877c65dfb97..0a1c5095d4e 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -4361,13 +4361,6 @@ ["const godot_int", "p_idx"] ] }, - { - "name": "godot_string_c_str", - "return_type": "const char *", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, { "name": "godot_string_unicode_str", "return_type": "const wchar_t *", diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 38a42ab6586..e8d509508e1 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -229,13 +229,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); ////// Script API -struct godot_gdnative_api_struct; // Forward declaration +typedef struct godot_gdnative_api_version { + unsigned int major; + unsigned int minor; +} godot_gdnative_api_version; + +typedef struct godot_gdnative_api_struct godot_gdnative_api_struct; + +struct godot_gdnative_api_struct { + unsigned int type; + godot_gdnative_api_version version; + const godot_gdnative_api_struct *next; +}; + +#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor) typedef struct { godot_bool in_editor; uint64_t core_api_hash; uint64_t editor_api_hash; uint64_t no_api_hash; + void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); + void (*report_loading_error)(const godot_object *p_library, const char *p_what); godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized const struct godot_gdnative_core_api_struct *api_struct; const godot_string *active_library_path; diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index cca3eb26723..10358ceade5 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -68,7 +68,6 @@ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int * wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); -const char GDAPI *godot_string_c_str(const godot_string *p_self); const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b);