On Thu, Sep 13, 2012 at 5:27 PM, Rajith Attapattu <[email protected]>wrote:
> On Thu, Sep 13, 2012 at 5:05 PM, Rafael Schloming <[email protected]> > wrote: > > On Thu, Sep 13, 2012 at 4:46 PM, Rajith Attapattu <[email protected] > >wrote: > > > >> On Mon, Sep 10, 2012 at 1:36 PM, Rafael Schloming <[email protected]> > >> wrote: > >> > On Mon, Sep 10, 2012 at 9:26 AM, Darryl L. Pierce <[email protected] > >> >wrote: > >> > methods on Messenger and Message objects and by tying > pn_messenger_free > >> and > >> > pn_message_free into the respective destructors, we could make things > a > >> > whole lot safer, e.g. avoid dangling pointers and the like that a user > >> > could use to segfault the interpreter. > >> > >> Darryl, you could use %typemap(freearg) to ensure the respective free > >> function is called to cleanup. > >> How it gets called is also automatically handled by swig based on the > >> host language. > >> > > > > Maybe I'm missing something, but I don't think %typemap(freearg) helps in > > this case. From what I understand it's used to clean up temporary memory > > allocated for the purpose of argument processing. The situation I'm > talking > > about is when you allocate an object in C and return it to the > interpreter, > > e.g.: > > Sorry I misunderstood. I thought it was for methods. > > It appears Ruby does have support for %newobject > http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn59 > But it maybe simpler to use the strategy Rafi has used for the python > binding. > I'm not trying to discourage use of %newobject and %delobject, I just didn't bother messing with them myself as they seem to be targeted at making the naked swig API more palatable, and IMHO the swig APIs shouldn't ever really be used directly, rather the simplest possible idomatic APIs like the one I posted earlier should be what we support as a public interface. They might well be worth investigating though if they can save us a bit of work inside the idiomatic APIs (aka the buttercream frosting layer). --Rafael
