diff --git a/SWIG/Examples/test-suite/python/smart_pointer_extend_runme.py b/SWIG/Examples/test-suite/python/smart_pointer_extend_runme.py index 0b62b9865..969757b4c 100644 --- a/SWIG/Examples/test-suite/python/smart_pointer_extend_runme.py +++ b/SWIG/Examples/test-suite/python/smart_pointer_extend_runme.py @@ -22,3 +22,13 @@ if b.hello() != p.hello(): +d = DFoo() + +dp = DPtrFoo(d) + +if d.SExt(1) != dp.SExt(1): + raise RuntimeError + +if d.Ext(1) != dp.Ext(1): + raise RuntimeError + diff --git a/SWIG/Examples/test-suite/smart_pointer_extend.i b/SWIG/Examples/test-suite/smart_pointer_extend.i index bdffcbf98..6127cb608 100644 --- a/SWIG/Examples/test-suite/smart_pointer_extend.i +++ b/SWIG/Examples/test-suite/smart_pointer_extend.i @@ -97,3 +97,32 @@ public: %} + +%inline %{ + + class DFoo; + + class DPtrFoo + { + DFoo *p; + public: + DPtrFoo(DFoo *ptr) : p(ptr) + { + } + + DFoo* operator->(void) {return p;}; + }; + + class DFoo + { + public: + void F(void) {}; + }; + +%} + + +%extend DFoo { + static int SExt(int i = 1) {return i;}; + int Ext(int i = 2) {return i;}; +} diff --git a/SWIG/Source/Swig/cwrap.c b/SWIG/Source/Swig/cwrap.c index 2978dddac..6ab3ee244 100644 --- a/SWIG/Source/Swig/cwrap.c +++ b/SWIG/Source/Swig/cwrap.c @@ -773,6 +773,7 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) { String *cname = Getattr(n,"classname") ? Getattr(n,"classname") : classname; String *membername = Swig_name_member(cname, name); String *mangled = Swig_name_mangle(membername); + int is_smart_pointer = flags & CWRAP_SMART_POINTER; type = Getattr(n,"type"); @@ -784,11 +785,11 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) { } /* See if there is any code that we need to emit */ - if (!defaultargs && code) { + if (!defaultargs && code &&!is_smart_pointer) { Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus); } - if (flags & CWRAP_SMART_POINTER) { + if (is_smart_pointer) { int i = 0; Parm *pp = p; String *func = NewStringf("%s(", mangled);