From 1bb8ef48f4d4335607e8331f803caec12823f91c Mon Sep 17 00:00:00 2001 From: Roza Date: Wed, 26 Feb 2020 11:05:46 -0500 Subject: [PATCH] Build with Ruby 2.7 --- binding/binding-util.h | 18 +++++++++++------- binding/meson.build | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/binding/binding-util.h b/binding/binding-util.h index 00ce00cc..d850ed63 100644 --- a/binding/binding-util.h +++ b/binding/binding-util.h @@ -73,9 +73,15 @@ void raiseRbExc(const Exception &exc); #endif #ifndef OLD_RUBY +#if RUBYCOMPAT < 270 #define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \ rb_data_type_t Klass##Type = { \ Name, {0, Free, 0, {0, 0}}, 0, 0, DEF_TYPE_FLAGS} +#else +#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \ + rb_data_type_t Klass##Type = { \ + Name, {0, Free, 0, 0, 0}, 0, 0, DEF_TYPE_FLAGS} +#endif #define DEF_TYPE_CUSTOMFREE(Klass, Free) \ DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, #Klass, Free) @@ -172,14 +178,13 @@ getPrivateDataCheck(VALUE self, const rb_data_type_t &type) getPrivateDataCheck(VALUE self, const char *type) #endif { -#ifndef OLD_RUBY - void *obj = Check_TypedStruct(self, &type); -#else // RGSS1 works in a more permissive way than the above, - // See the function at ram:10012AB0 in RGSS104E for an example - // This isn't an exact replica, but should have pretty much the same - // result +#ifdef OLD_RUBY rb_check_type(self, T_DATA); VALUE otherObj = rb_const_get(rb_cObject, rb_intern(type)); +#else + Check_TypedStruct(self, &type); + VALUE otherObj = rb_const_get(rb_cObject, rb_intern(type.wrap_struct_name)); +#endif const char *ownname, *othername; if (!rb_obj_is_kind_of(self, otherObj)) { ownname = rb_obj_classname(self); @@ -188,7 +193,6 @@ getPrivateDataCheck(VALUE self, const char *type) } void *obj = DATA_PTR(self); -#endif return static_cast(obj); } diff --git a/binding/meson.build b/binding/meson.build index 3fd203e9..4b277cf0 100644 --- a/binding/meson.build +++ b/binding/meson.build @@ -4,6 +4,9 @@ if get_option('mri_includes') == '' if ver.version_compare('>1.8') == false add_project_arguments('-DOLD_RUBY', language: ['cpp','objc','objcpp']) endif + if ver.version_compare('>=2.7') == true + add_project_arguments('-DRUBYCOMPAT=270', language: ['cpp', 'objc', 'objcpp']) + endif global_dependencies += dependency('ruby-' + ver) else global_args += ('-I' + get_option('mri_includes'))