From e12277a4698b2502702e64f18e44613d5b460d3a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 1 Oct 2015 20:27:29 +0100 Subject: [PATCH] Ruby shared_ptr fixes for use with minherit --- Examples/test-suite/ruby/Makefile.in | 1 + .../ruby/ruby_minherit_shared_ptr_runme.rb | 28 +++++++++++++ .../test-suite/ruby_minherit_shared_ptr.i | 39 +++++++++++++++++++ Source/Modules/ruby.cxx | 18 ++++----- 4 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb create mode 100644 Examples/test-suite/ruby_minherit_shared_ptr.i diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in index ed00c6780..69cacaab6 100644 --- a/Examples/test-suite/ruby/Makefile.in +++ b/Examples/test-suite/ruby/Makefile.in @@ -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 \ diff --git a/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb b/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb new file mode 100644 index 000000000..9381fee2b --- /dev/null +++ b/Examples/test-suite/ruby/ruby_minherit_shared_ptr_runme.rb @@ -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 diff --git a/Examples/test-suite/ruby_minherit_shared_ptr.i b/Examples/test-suite/ruby_minherit_shared_ptr.i new file mode 100644 index 000000000..6a0e3f94c --- /dev/null +++ b/Examples/test-suite/ruby_minherit_shared_ptr.i @@ -0,0 +1,39 @@ +// Test ruby_minherit (multiple inheritance support) and shared_ptr +%module(ruby_minherit="1") ruby_minherit_shared_ptr + +%include +%shared_ptr(Interface1) +%shared_ptr(Base1) +%shared_ptr(MultiDerived) + +%inline %{ +#include +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(); +} +%} diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bbb80c959..9dff4276a 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -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);