From 9fb217b048aa2fca4c062028e47786f7a24ae563 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Mon, 9 Jan 2006 17:35:04 +0000 Subject: [PATCH] add %delobject, which is the equivalent of %newobject but for functions that delete an element. This allows to properly disown the argument, as the %newobject directive allows to 'own' the object git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8318 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/import_nomodule.i | 2 ++ SWIG/Examples/test-suite/inherit_missing.i | 1 + SWIG/Lib/swig.swg | 6 ++++++ SWIG/Source/Modules/lang.cxx | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/SWIG/Examples/test-suite/import_nomodule.i b/SWIG/Examples/test-suite/import_nomodule.i index a2bc4b9bd..5d5115360 100644 --- a/SWIG/Examples/test-suite/import_nomodule.i +++ b/SWIG/Examples/test-suite/import_nomodule.i @@ -18,6 +18,8 @@ */ %newobject create_Foo; +%delobject delete_Foo; + %inline %{ Foo *create_Foo() { return new Foo(); diff --git a/SWIG/Examples/test-suite/inherit_missing.i b/SWIG/Examples/test-suite/inherit_missing.i index e38a6c8dd..4bd1e2a00 100644 --- a/SWIG/Examples/test-suite/inherit_missing.i +++ b/SWIG/Examples/test-suite/inherit_missing.i @@ -19,6 +19,7 @@ public: class Foo; %newobject new_Foo; +%delobject delete_Foo; %inline %{ class Bar : public Foo { diff --git a/SWIG/Lib/swig.swg b/SWIG/Lib/swig.swg index aa7d59b9b..8f399891d 100644 --- a/SWIG/Lib/swig.swg +++ b/SWIG/Lib/swig.swg @@ -99,6 +99,12 @@ #define %nonewobject %feature("new","0") #define %clearnewobject %feature("new","") +/* the %delobject directive */ + +#define %delobject %feature("del") +#define %nodelobject %feature("del","0") +#define %cleardelobject %feature("del","") + /* the %refobject/%unrefobject directives */ #define %refobject %feature("ref") diff --git a/SWIG/Source/Modules/lang.cxx b/SWIG/Source/Modules/lang.cxx index 2c4bc4fa3..5577c3ef6 100644 --- a/SWIG/Source/Modules/lang.cxx +++ b/SWIG/Source/Modules/lang.cxx @@ -918,6 +918,10 @@ int Language::functionHandler(Node *n) { Parm *p; p = Getattr(n,"parms"); + if (GetFlag(n,"feature:del")) { + /* the method acts like a delete operator, ie, we need to disown the parameter */ + if (p) Setattr(p,"wrap:disown","1"); + } if (!CurrentClass) { globalfunctionHandler(n); } else {