Re: %newobject and typemap(out)

"Langer, Stephen A. \(Fed\) via Swig-user" <[email protected]> Thu, 7 Jul 2022 19:14:22 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
I understand why what I expected to happen doesn’t happen, so I'll rephrase the question:  Is there a way to write a typemap(out) so that it either deletes its source or doesn't, depending on a flag in the swig file that indicates whether or not the object was newly allocated before being returned?

To be specific, I'm trying to do something like this:

%typemap(out) MyClass * {
  $result = some_operations_on($1);
  if(newly_allocated)  // <<-- how???
    delete $1;
}

so that I can do this:

MyClass *getOldObject();
%newobject getNewObject;
MyClass *getNewObject();

or something along those lines.

I know that I can write two typemaps, one for MyClass and one for NewMyClass, put the delete statement only in the NewMyClass typemap, and typedef NewMyClass to MyClass.  Is there a better way?

Thanks,

 -- Steve



-----Original Message-----
From: "Langer, Stephen A. (Fed) via Swig-user" <[email protected]>
Reply-To: "Langer, Stephen A. (Fed)" <[email protected]>
Date: Thursday, July 7, 2022 at 10:20 AM
To: "[email protected]" <[email protected]>
Subject: [Swig-user] %newobject and typemap(out)

    Hi --

    Is it possible for a typemap to know whether or not it's being invoked in conjunction with %newobject?

    If %newobject is used on a function where the return value has a typemap(newfree) but no typemap(out), the wrapper will correctly delete the return value.  But if there's a typemap(out), newfree doesn't seem to be used.  How can a typemap(out) know whether or not it should delete the return value? 

    Thanks.
     -- Steve



    _______________________________________________
    Swig-user mailing list
    [email protected]
    https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fswig-user&amp;data=05%7C01%7Cstephen.langer%40nist.gov%7C42c220812e33459a2abd08da6023dd74%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637928004412017784%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=Wj6Eq22wc75kWwgbw0Ed6jSUKVkeRam3g5N78T%2B97v0%3D&amp;reserved=0


_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user