I believe I have found my problem.  

I was allowing the GIL to be released (essentially letting multiple
threads run concurrently) but the " const boost::python::list & disks"
argument was not protected at this point.

I can either move the Py_BEGIN_ALLOW_THREADS call to after I am finished
accessing the "disks" arg, or use Py_BLOCK_THREADS and
Py_UNBLOCK_THREADS to protect access calls.

John
 
John McLaughlin
iStor Networks, Inc.
-----Original Message-----
From: John McLaughlin 
Sent: Friday, April 23, 2010 8:01 PM
To: 'cplusplus-...@python.org.'
Subject: boost::python::len( list_object) throws "Access violation"
(MSDev v9/Boost 1.41)

I have a strange crash in my C++ method when called from Python.  I have
a method that has one of the arguments a Python List.  The symptoms are
the same with an empty list and a non-empty one.

In one method, early in the code I call;
       boost::python::len( var )
and it returns properly.

HOWEVER, in another method, I am passing the *same value* from Python,
but the "boost::python::len( var )" aborts when "PyErr_Occurred()" is
called.  It causes an access violation (like a bad pointer dereference).

What is strange is that the line before (calling
PyObject_Length(obj.ptr() ) returns a proper size.

Any ideas?

------------------------------------------------------

namespace boost { namespace python {

    inline ssize_t len(object const& obj)
    {
        ssize_t result = PyObject_Length(obj.ptr());
        if (PyErr_Occurred()) throw_error_already_set();
        return result;
    }

}} // namespace boost::python

------------------------------------------------------

void PyService_Volume::Reconfigure(
                        const PyStorageSize & sizeInBytes,
                        const
iStor::UserAgent::UAEnums::VolumeCompositionName & compositionName,
                        const boost::python::list & disks,
                        int stripeWidth,
                        const iStor::UserAgent::UAEnums::StripeDepth &
stripeDepth)
{
        Py_BEGIN_ALLOW_THREADS
.
.
.

        if (boost::python::len(disks) > 0)
        {
                ...

------------------------------------------------------

John McLaughlin
iStor Networks, Inc.

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to