[C++-sig] Assert's in boost.python when instanciating class

Sean Dunn sean_dunn1 at yahoo.com
Tue May 6 08:38:40 CEST 2003


I've been having troubles getting a very simple class to work in Python
after extending C++ code using boost.python.

system:
Win2k
VC6 sp5
boost.python 1.30.0 built using bjam, using pydebug dynamic link
library
python 2.2.2 debug shell

// C++ code
#include <boost/python.hpp>
using namespace boost::python;
struct SimpleTest
{
	int val;
};
class_<SimpleTest>("SimpleTest")
	.def_readwrite("val",  &SimpleTest::val)
;


Upon loading this in python, I hit a failed assert in class.cpp:
# Python output
Adding parser accelerators ...
Done.
Python 2.2.2 (#37, Apr 29 2003, 17:46:46) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import payamodule
[8162 refs]
>>> t = payamodule.SimpleTest()
Assertion failed: self_->ob_type->ob_type == &class_metatype_object,
file ../src
/object\class.cpp, line 481

// from the debugger
self_->ob_type->ob_type == 0x1e194858
&class_metatype_object == 0x00895b80

So, the problem here seems to be that this maybe should be
assert(self_->ob_type->ob_type == class_metatype_object.ob_type);

Is this a manifestation of using the debug libraries? There is an
instance of actual running code in the non-debug case inside
class.cpp:264,find_instance_impl(). I had previously tracked down a bug
to this line in a previous test where I was calling a simple method
that would return an integer constant. It gave me a 
TypeError: bad argument type for built-in operation.

I made the above change, and although it passes the asserts, and I can
read "val", it crashes when I try to set "val". An expected PyObject*
seems to be garbage (a value of 0x00000002 instead of a sane pointer).

I'll give the normal disclaimer that I've been using boost.python for
about 24 hours now, and I really do know nothing.

Sean


=====
--

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com




More information about the Cplusplus-sig mailing list