mirror of https://github.com/swig/swig
Ruby shared_ptr fixes for use with minherit
This commit is contained in:
parent
04fd4a9c68
commit
e12277a469
|
@ -22,6 +22,7 @@ CPP_TEST_CASES = \
|
|||
li_std_stack \
|
||||
primitive_types \
|
||||
ruby_keywords \
|
||||
ruby_minherit_shared_ptr \
|
||||
ruby_naming \
|
||||
ruby_track_objects \
|
||||
ruby_track_objects_directors \
|
||||
|
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
%}
|
|
@ -2439,25 +2439,23 @@ public:
|
|||
SwigType *btype = NewString(basename);
|
||||
SwigType_add_pointer(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) {
|
||||
String *bmangle = SwigType_manglestr(btype);
|
||||
Insert(bmangle, 0, "((swig_class *) SWIGTYPE");
|
||||
Append(bmangle, "->clientdata)->mImpl");
|
||||
Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL);
|
||||
Delete(bmangle);
|
||||
} 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");
|
||||
Append(bmangle, "->clientdata)->klass");
|
||||
Replaceall(klass->init, "$super", bmangle);
|
||||
Delete(bmangle);
|
||||
Delete(smart);
|
||||
}
|
||||
Delete(bmangle);
|
||||
Delete(smart);
|
||||
Delete(btype);
|
||||
}
|
||||
base = Next(base);
|
||||
|
|
Loading…
Reference in New Issue