diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2010-05-22 22:49:47 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2010-05-22 22:49:47 +0000 |
commit | 12cfc251e423a526811b84ccb0f11fd7684cbc56 (patch) | |
tree | 836a89c3c8e781b3d5650c31a6fe2f3ee447daf8 /Source/Modules/typepass.cxx | |
parent | 1fe29bae873b2c389a5bcdbfbc54dae9e7851d1b (diff) | |
download | swig-12cfc251e423a526811b84ccb0f11fd7684cbc56.tar.gz |
Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an inheritance hierarchy. No special treatment is needed for derived classes, the SWIG_SHARED_PTR_DERIVED macro is deprecated.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Source/Modules/typepass.cxx')
-rw-r--r-- | Source/Modules/typepass.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index e63b58a10..57a7663eb 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -231,6 +231,37 @@ class TypePass:private Dispatcher { Node *bclass = n; /* Getattr(n,"class"); */ Hash *scopes = Getattr(bclass, "typescope"); SwigType_inherit(clsname, bname, cast, 0); + String *smartptr = Getattr(first, "feature:smartptr"); + if (smartptr) { + SwigType *smart = 0; + SwigType *spt = Swig_cparse_type(smartptr); + if (spt) { + smart = SwigType_typedef_resolve_all(spt); + Delete(spt); + /* Record a (fake) inheritance relationship between smart pointer + and smart pointer to base class, so that smart pointer upcasts + are automatically generated. */ + SwigType *bsmart = Copy(smart); + SwigType *rclsname = SwigType_typedef_resolve_all(clsname); + SwigType *rbname = SwigType_typedef_resolve_all(bname); + Replaceall(bsmart, rclsname, rbname); + Delete(rclsname); + Delete(rbname); + String *smartnamestr = SwigType_namestr(smart); + String *bsmartnamestr = SwigType_namestr(bsmart); + /* construct casting code */ + String *convcode = NewStringf("\n *newmemory = SWIG_CAST_NEW_MEMORY;\n return (void *) new %s(*(%s *)$from);\n", bsmartnamestr, smartnamestr); + Delete(bsmartnamestr); + Delete(smartnamestr); + /* setup inheritance relationship between smart pointer templates */ + SwigType_inherit(smart, bsmart, 0, convcode); + Delete(convcode); + Delete(bsmart); + Delete(smart); + } else { + Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, clsname); + } + } if (!importmode) { String *btype = Copy(bname); SwigType_add_pointer(btype); |