[ruby] check whether object is of RTypedData using RTYPEDDATA_P.

This commit is contained in:
Takashi Tamura 2017-04-29 21:55:21 +09:00 committed by William S Fulton
commit ff9e9f9f98
4 changed files with 30 additions and 2 deletions

View file

@ -26,6 +26,7 @@ CPP_TEST_CASES = \
ruby_keywords \
ruby_minherit_shared_ptr \
ruby_naming \
ruby_rdata \
ruby_track_objects \
ruby_track_objects_directors \
std_containers \

View file

@ -0,0 +1,7 @@
require 'swig_assert'
require 'ruby_rdata'
include Ruby_rdata
swig_assert_equal_simple(1, take_proc_or_cpp_obj_and_ret_1(Proc.new{}))
swig_assert_equal_simple(1, take_proc_or_cpp_obj_and_ret_1(C.new))

View file

@ -0,0 +1,20 @@
%module ruby_rdata
%{
class C {};
int take_proc_or_cpp_obj_and_ret_1(VALUE obj) {
return 1;
}
int take_proc_or_cpp_obj_and_ret_1(class C) {
return 1;
}
%}
class C {};
int take_proc_or_cpp_obj_and_ret_1(VALUE);
int take_proc_or_cpp_obj_and_ret_1(C);

View file

@ -247,7 +247,7 @@ typedef struct {
SWIGRUNTIME swig_ruby_owntype
SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) {
swig_ruby_owntype oldown = {0, 0};
if (TYPE(obj) == T_DATA) {
if (TYPE(obj) == T_DATA && !RTYPEDDATA_P(obj)) {
oldown.datafree = RDATA(obj)->dfree;
RDATA(obj)->dfree = own.datafree;
}
@ -268,7 +268,7 @@ SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags,
*ptr = 0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
} else {
if (TYPE(obj) != T_DATA) {
if (TYPE(obj) != T_DATA || (TYPE(obj) == T_DATA && RTYPEDDATA_P(obj))) {
return SWIG_ERROR;
}
Data_Get_Struct(obj, void, vptr);