Re: %newobject and typemap(out)
"Cherry, Josh \(NIH/NLM/NCBI\) \[E\] via Swig-user" <[email protected]> Thu, 7 Jul 2022 20:25:06 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <SA1PR09MB78550C62F3D321BA92023562D1839@SA1PR09MB7855.namprd09.prod.outlook.com> |
Might a "newfree" typemap get you what you want? I would think so from the std::string example here: https://www.swig.org/Doc4.0/Typemaps.html#Typemaps_nn34 ________________________________ From: Langer, Stephen A. (Fed) via Swig-user <[email protected]> Sent: Thursday, July 7, 2022 3:14 PM To: [email protected] <[email protected]> Subject: [EXTERNAL] Re: [Swig-user] %newobject and typemap(out) 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&data=05%7C01%7Cjcherry%40ncbi.nlm.nih.gov%7C7a5f2917d893469ddfba08da604d1cb9%7C14b77578977342d58507251ca2dc2b06%7C0%7C0%7C637928181556625188%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=yJa82ISBB1VHdL2ivrzKCzC2uYWtCTygDdJ4iQt0SAU%3D&reserved=0 _______________________________________________ Swig-user mailing list [email protected] https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fswig-user&data=05%7C01%7Cjcherry%40ncbi.nlm.nih.gov%7C7a5f2917d893469ddfba08da604d1cb9%7C14b77578977342d58507251ca2dc2b06%7C0%7C0%7C637928181556625188%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=yJa82ISBB1VHdL2ivrzKCzC2uYWtCTygDdJ4iQt0SAU%3D&reserved=0 CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and are confident the content is safe. _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user