Ruby shared_ptr fixes for use with minherit

This commit is contained in:
William S Fulton 2015-10-01 20:27:29 +01:00
parent 04fd4a9c68
commit e12277a469
4 changed files with 76 additions and 10 deletions

View File

@ -22,6 +22,7 @@ CPP_TEST_CASES = \
li_std_stack \ li_std_stack \
primitive_types \ primitive_types \
ruby_keywords \ ruby_keywords \
ruby_minherit_shared_ptr \
ruby_naming \ ruby_naming \
ruby_track_objects \ ruby_track_objects \
ruby_track_objects_directors \ ruby_track_objects_directors \

View File

@ -0,0 +1,28 @@
#!/usr/bin/env ruby
#
# Put description here
#
#
#
#
#
require 'ruby_minherit_shared_ptr'
md = Ruby_minherit_shared_ptr::MultiDerived.new(11, 22)
if md.Base1Func != 11 then
raise RuntimeError
end
if md.Interface1Func != 22 then
raise RuntimeError
end
if Ruby_minherit_shared_ptr.BaseCheck(md) != 11 then
raise RuntimeError
end
if Ruby_minherit_shared_ptr.InterfaceCheck(md) != 22 then
raise RuntimeError
end
if Ruby_minherit_shared_ptr.DerivedCheck(md) != 33 then
raise RuntimeError
end

View File

@ -0,0 +1,39 @@
// Test ruby_minherit (multiple inheritance support) and shared_ptr
%module(ruby_minherit="1") ruby_minherit_shared_ptr
%include <boost_shared_ptr.i>
%shared_ptr(Interface1)
%shared_ptr(Base1)
%shared_ptr(MultiDerived)
%inline %{
#include <boost/shared_ptr.hpp>
class Interface1 {
public:
virtual int Interface1Func() const = 0;
};
class Base1 {
int val;
public:
Base1(int a = 0) : val(a) {}
virtual int Base1Func() const { return val; }
};
class MultiDerived : public Base1, public Interface1 {
int multi;
public:
MultiDerived(int v1, int v2) : Base1(v1), multi(v2) {}
virtual int Interface1Func() const { return multi; }
};
int BaseCheck(const Base1& b) {
return b.Base1Func();
}
int InterfaceCheck(const Interface1& i) {
return i.Interface1Func();
}
int DerivedCheck(const MultiDerived& m) {
return m.Interface1Func() + m.Base1Func();
}
%}

View File

@ -2439,25 +2439,23 @@ public:
SwigType *btype = NewString(basename); SwigType *btype = NewString(basename);
SwigType_add_pointer(btype); SwigType_add_pointer(btype);
SwigType_remember(btype); SwigType_remember(btype);
SwigType *smart = Swig_cparse_smartptr(base.item);
if (smart) {
SwigType_add_pointer(smart);
SwigType_remember(smart);
}
String *bmangle = SwigType_manglestr(smart ? smart : btype);
if (multipleInheritance) { if (multipleInheritance) {
String *bmangle = SwigType_manglestr(btype);
Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); Insert(bmangle, 0, "((swig_class *) SWIGTYPE");
Append(bmangle, "->clientdata)->mImpl"); Append(bmangle, "->clientdata)->mImpl");
Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL); Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL);
Delete(bmangle);
} else { } else {
SwigType *smart = Swig_cparse_smartptr(base.item);
if (smart) {
SwigType_add_pointer(smart);
SwigType_remember(smart);
}
String *bmangle = SwigType_manglestr(smart ? smart : btype);
Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); Insert(bmangle, 0, "((swig_class *) SWIGTYPE");
Append(bmangle, "->clientdata)->klass"); Append(bmangle, "->clientdata)->klass");
Replaceall(klass->init, "$super", bmangle); Replaceall(klass->init, "$super", bmangle);
Delete(bmangle);
Delete(smart);
} }
Delete(bmangle);
Delete(smart);
Delete(btype); Delete(btype);
} }
base = Next(base); base = Next(base);