[C++-sig] The "return always existing pointer throws dangling
error" problem
by Niall Douglas other posts by this author
Oct 21 2003 7:53PM messages near this date
[C++-sig] Re: Extension DLLs nonfunctioning with MSVC 7.1 (beta)
|
[C++-sig] Re: The "return always existing pointer throws dangling
error" problem
--PGPMime-Boundary-F123141B
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body
Just run into this one myself whereby when querying a FXObject
subclass for its metadata (a FXMetaClass) it throws "attempt to
return dangling pointer". I've read Dave's comments at
http://mail.python.org/pipermail/c++-sig/2003-August/005288.html &
http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1781761 and I
was wondering, surely it is fairly trivial for BPL to know when a
python object holding a reference to a C++ thing is holding it in a
non-ownership way?
Let me clarify: From what I understand, most return policies destroy
their associated C++ object instance when its python representation
expires. Mostly that's a copy of the C++ object instance and when
this is the case, the throwing of the error is correct.
However, if the object instance was allocated by new (and thus its
policy was manage_new_object), then doesn't that strongly imply that
the receiving object takes ownership of a newed pointer as well
because the return policy setting is an artifact of how the C++ code
works? Therefore in this situation auto_ptr style transference would
be more useful.
return_internal_reference is also different - if you attach lifetime
to self which most do, then when a virtual override in python returns
an internal reference to either C++ or python code invoking that
function, surely BPL is attaching the lifetime of the internal
reference to the "self" instance and not to the temporary object
created during call_method? Therefore surely the error is reporting
the wrong thing dangling?
Lastly looking through the docs I encountered a thing called ptr<>
which while it appears to help me in C++, if I were to subclass
FXObject with my own class in python (whereupon I must provide my own
custom FXMetaClass to describe it) I'd be smack bang right back into
problem-land.
Thoughts? I appreciate that this has been addressed before, and that
Dave who is uber-intelligent has said he's not sure about the correct
solution. But I can't see how BPL doesn't know where one of its own
pointer containers got its pointer from?
If I'm missing something tragically obvious, perhaps some sort of
ownership policy might be needed?
Lastly, while the posts I referred to promise workarounds, I can't
see any which don't involve altering the original C++. Can I
explicitly disable the dangling pointer check? Though, ideally, I'd
still want to always tie any returned FXMetaClass always to its
associated FXObject.
Cheers,
Niall
--PGPMime-Boundary-F123141B
Content-Type: application/pgp-signature
-----BEGIN PGP MESSAGE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2
iQA/AwUBP5WOpMEcvDLFGKbPEQKOrQCfWRvrkndL8hFBMjoJtYXS5JXM+MMAoNJ6
KiApGWgWy1vikZB2+GNUaHpv
=fAtW
-----END PGP MESSAGE-----
--PGPMime-Boundary-F123141B--
Attachments:
unknown1
unknown1
unknown2
unknown3
unknown4
Thread:
Niall Douglas
David Abrahams
Niall Douglas
David Abrahams
Niall Douglas
David Abrahams
David Abrahams
Niall Douglas
Niall Douglas
David Abrahams
Niall Douglas
Nicolas LELONG
Nicolas LELONG
David Abrahams
|