From d4f4f14c68d6fea3fc582858ec82af2f8ae36870 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Wed, 19 Apr 2017 13:39:57 +0200 Subject: [PATCH] [GDNative] explicit calling convention --- modules/gdnative/gdnative.cpp | 1 - modules/gdnative/godot.h | 45 +++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index a4c9085f454..09859d95bd0 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -424,7 +424,6 @@ Variant GDNativeScript::_new(const Variant **p_args, int p_argcount, Variant::Ca // @Todo support varargs for constructors. GDNativeInstance *instance = (GDNativeInstance *)instance_create(owner); - owner->set_script(Ref(this).get_ref_ptr()); owner->set_script_instance(instance); if (!instance) { if (ref.is_null()) { diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h index 0d7aece23b4..88d2a9bac21 100644 --- a/modules/gdnative/godot.h +++ b/modules/gdnative/godot.h @@ -38,12 +38,26 @@ extern "C" { #define GDAPI_EXPORT #endif -#if !defined(_WIN32) && !defined(_MSC_VER) -#define GDAPI -#elif defined(GDAPI_EXPORT) -#define GDAPI __declspec(dllexport) +#ifdef _WIN32 +#if defined(GDAPI_EXPORT) +#define GDCALLINGCONV __cdecl +#define GDAPI __declspec(dllexport) GDCALLINGCONV #else -#define GDAPI __declspec(dllimport) +#define GDCALLINGCONV __cdecl +#define GDAPI __declspec(dllimport) GDCALLINGCONV +#endif +#elif defined(__APPLE__) +#include "TargetConditionals.h" +#if TARGET_OS_IPHONE +#define GDCALLINGCONV +#define GDAPI +#elif TARGET_OS_MAC +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif +#else +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV #endif #include @@ -314,16 +328,16 @@ typedef struct godot_property_attributes { typedef struct godot_instance_create_func { // instance pointer, method_data - return user data - void *(*create_func)(godot_object *, void *); + GDCALLINGCONV void *(*create_func)(godot_object *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_create_func; typedef struct godot_instance_destroy_func { // instance pointer, method data, user data - void (*destroy_func)(godot_object *, void *, void *); + GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_destroy_func; void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func); @@ -332,25 +346,25 @@ void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_ba typedef struct godot_instance_method { // instance pointer, method data, user data, num args, args - return result as varaint - godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); + GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_method; void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method); typedef struct godot_property_set_func { // instance pointer, method data, user data, value - void (*set_func)(godot_object *, void *, void *, godot_variant); + GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_set_func; typedef struct godot_property_get_func { // instance pointer, method data, user data, value - godot_variant (*get_func)(godot_object *, void *, void *); + GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_get_func; void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func); @@ -376,6 +390,7 @@ void GDAPI godot_script_register_signal(const char *p_name, const godot_signal * void GDAPI *godot_native_get_userdata(godot_object *p_instance); +// Calling convention? typedef godot_object *(*godot_class_constructor)(); godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname);