From: Magnus L. H. <ma...@he...> - 2006-04-18 21:08:47
|
On Apr 18, 2006, at 22:27, Marcelo Matus wrote: > Magnus Lie Hetland wrote: [snip] >> The problem isn't that Python does a GC on it -- the problem is >> that the C++ code removes a reference (which *should* be >> removed), and thereby it's deallocated while it's still available >> in Python. > > > well, that is what the DISOWN typemap tells to python, "don't try > to deallocate the object since you don't own it anymore", But... My point is that what I want is exactly the opposite: I *want* Python to own it (i.e., to add a reference to it), because my C++ data structure will be deallocated and therefore will remove *its* references. If Python hasn't added one, the objects will be deallocated by C++, and Python will try to keep using them. I'm curious: Shouldn't the existence of a proxy (and/or a director) object ensure that the refcount is at least 1 (as long as the C++ doesn't mess with it)? > and C++ will take care of it. > > You can also use the %exception trick, ie; > > %exception Result::add() { > AddRef(arg1); // or so > $action > } Hm. Yes. But when are the _wrap_* functions called, then -- i.e. those that call the add_ref stuff? When I return objects? (With or without % newobject?) > or %extend your method as: > > %ignore Result::add; > %extend { > void add(Class *value) { > AddRef(value); > self->add(value); > } > } Sure. Extending the method probably isn't all that hard. I was just hoping it wouldn't be necessary. I guess I don't understand how SWIG handles the reference counting yet (i.e. when the ref-part of the feature is actually used). [snip] >> BTW: Where is the authoritative documentation for the DISOWN >> typemap? I can just find brief mentions of it here and there >> (and, e.g., an explanation in the Chicken section). > > hmm, try Customization.html, if it is not there, we welcome new docs!. Yeah, I've looked there before. All I found was: "This is similar to use the DISOWN typemap in the first method argument, and in fact, it also depends on the target language on implementing the 'disown' mechanism properly." I guess I could contribute some docs -- if/when I understand this stuff ;) -- Magnus Lie Hetland http://hetland.org |