[C++-sig] problem with python::dict[]
David Abrahams
dave at boost-consulting.com
Wed Feb 26 20:53:24 CET 2003
harold fellermann <harold at imb-jena.de> writes:
> Hello,
>
> I got your address from
> http://mail.python.org/pipermail/c++-sig/2002-June/001311.html -- so I
> don't know whether you are the right person to ask.
"We" are the right people to ask. You sent it to the appropriate
place: c++-sig at python.org.
> I think I have found an error in the boost.python's dict-interface.
>
> My following code-snippet runs into segmantation fault:
>
> #include <stdlib.h>
> #include <boost/python/dict.hpp>
>
> using namespace boost::python;
>
> int main()
> {
> dict x[750];
>
> return 0;
> }
Do you really mean to construct an array of 750 dicts? I think if
you're going to do that from a program (as opposed to an extension
module) you'll need to call some things like PyInitialize() first.
See libs/python/test/embedding.cpp for an example.
> The problem seems to concern the garbage collector from the
> Python/C-API, as
> my debugger tells me, the program crashes in _PyObject_GC_New():
>
>
> (gdb) run
> Starting program: /home/tsb/harold/c_network/pytest
> [New Thread 1024 (LWP 25905)]
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 1024 (LWP 25905)]
> 0x0809a909 in PyErr_Occurred ()
> (gdb) bt
> #0 0x0809a909 in PyErr_Occurred ()
> #1 0x080addca in _PyObject_GC_New ()
> #2 0x08064edc in PyDict_New ()
> #3 0x4003b1f4 in boost::python::detail::dict_base::dict_base() ()
> from /usr/local/lib/libboost_python.so.1.29.0
> #4 0x080c6c6c in main () at pytest.c:9
> #5 0x401744a2 in __libc_start_main () from /lib/libc.so.6
>
>
> I tried this with a couple of python-objects and all containers (dict,
> list, ...)
> crashed in exactly the same way. Interestingly the program behaves
> normal when
> I reduce the number of objects within my array to approx. 700.
Very interesting, but inconclusive.
> My configuration looks as follows:
> - python 2.2.1 (#1, Sep 10 2002, 17:49:17)
> - gcc 3.2
> - boost version 1.29.0
>
> Do you have any idea what is going on here? Is this a known bug,
> maybe even a nowadays fixed one? Or is it only a question of
> configuration? Any help will be appreciated!
It's hard to imagine any bug in Boost.PYthon that would depend on the
size of the array being small; maybe one in the compiler or in Python
could do that.
This works on my system:
#include <stdlib.h>
#include <boost/python/dict.hpp>
using namespace boost::python;
void test()
{
// Initialize the interpreter
Py_Initialize();
dict d[750];
}
int main()
{
if (handle_exception(test))
{
if (PyErr_Occurred())
PyErr_Print();
return 1;
}
return 0;
}
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list