[C++-sig] boost::python::len( list_object) throws "Access violation" (MSDev v9/Boost 1.41)

John McLaughlin jmclaughlin at istor.com
Sat Apr 24 05:00:59 CEST 2010


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.



More information about the Cplusplus-sig mailing list