[C++-sig] strange sideeffect or bug of boost.python
Lutz Paelike
lutz_p at gmx.net
Wed Oct 29 12:33:09 CET 2003
Hi,
i encountered a strange thing when i wanted to create a dictionary object from c++.
The error is after creating the dict with no errors (result!=NULL) a simple PyDict_Check fails with no reason.
I tracked this down through the Python Sources and extracted the essential source of PyDict_Check and inserted
it into the example code below. In the Debugger i see that the ob_type of the new object is somehow screwed up.
And now the strange thing: This error goes away and the code works like expected if i remove the boost include.
Am I missing something or is this a strange side effect ?
I'm using Visual Studio 6 SP5 and a recent boost cvs checkout (about 1-2 weeks old)
Thanks for your help,
Lutz
Here is the code:
///////////////////////////snip//////////////////////////////////////
#include <boost/python.hpp> // comment this out to make it work
#include <string>
#include <iostream>
#include <fstream>
#include <exception>
#include <stdexcept>
#include <Python.h>
#include <compile.h>
#include <eval.h>
#include <dictobject.h>
int main()
{
Py_Initialize();
PyObject *the_dict = PyDict_New ();
if (NULL!=the_dict){
Py_INCREF(the_dict);
_typeobject * dt = &PyDict_Type;
// PyDict_Check does this. Why isn't this working here?
bool isT = ((the_dict)->ob_type == (&PyDict_Type));
bool isST = PyType_IsSubtype((the_dict)->ob_type, (&PyDict_Type));
if (isT) printf("the_dict is of type PyDict_Type\n");
else printf("the_dict is not of type PyDict_Type! Boost.Python Bug?\n");
if (isST) printf("the_dict is of subtype PyDict_Type\n");
else printf("the_dict is not of subtype PyDict_Type! Boost.Python Bug?\n");
Py_DECREF(the_dict);
} else printf("Error creating new dict\n");
Py_Finalize();
return 0;
}
///////////////////////////snip//////////////////////////////////////
More information about the Cplusplus-sig
mailing list