Fwd: [boost-python] Making a reference to the PyObject* in construct()
I'm trying to figure out an issue that seems to have to do with the construct() method in a from-python conversion. I'm converting from a python string to a custom C++ string class. The c++ string just holds a reference to a python string using a boost::python::object. My construct() function looks like this: struct String_from_python_str { . . . static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { using namespace boost::python; void* storage = ( (converter::rvalue_from_python_storage<String>*) data)->storage.bytes; new (storage) String(object(handle<>(obj_ptr))); // <---- Is this correct? Should it be borrowed? data->convertible = storage; } }; My program has started seeing occasional python reference counting problems and what appear to be memory corruption problems. I find that if I use a borrowed() handle when constructing my string, the problems go away. Is this correct? Or am I doing something totally else wrong here? I can't find any documentation re: the "borrowed" nature of obj_ptr, so I really just assumed that it was a normal, pre-incremented reference. Any help on this would be great. Thanks. Austin Bingham
Austin Bingham wrote:
I can't find any documentation re: the "borrowed" nature of obj_ptr, so I really just assumed that it was a normal, pre-incremented reference. Any help on this would be great. Thanks.
Here's a good thread on this, thanks to Alex Mohr: http://mail.python.org/pipermail/cplusplus-sig/2009-February/014294.html -t
Thanks for the link, but I think I misspoke a bit. I do understand borrowed vs. owned references in general, but I'm not sure about the pointer in the specific context of the construct() call. Is it borrowed or pre-incremented? However, a little poking around the boost.python source seems to indicate that it the pointers in that context are borrowed. The evidence I have is that boost.python's own shared_ptr converter, python/converter/shared_ptr_from_python.hpp, is using 'borrowed' when it forms a reference to the PyObject. So, can anyone verify that this is correct? Austin On Sat, Sep 26, 2009 at 6:07 PM, troy d. straszheim <troy@resophonic.com> wrote:
Austin Bingham wrote:
I can't find any documentation re: the "borrowed" nature of obj_ptr, so I really just assumed that it was a normal, pre-incremented reference. Any help on this would be great. Thanks.
Here's a good thread on this, thanks to Alex Mohr:
http://mail.python.org/pipermail/cplusplus-sig/2009-February/014294.html
-t
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
participants (2)
-
Austin Bingham -
troy d. straszheim