[C++-sig] BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS default args core dump
Holger Joukl
Holger.Joukl at LBBW.de
Mon May 9 17:14:38 CEST 2011
Hi,
this is basically a re-post of a problem I posted 5 weeks ago, on which
there's
been no echo whatsoever. Now, I'm unsure if this is because I posted on
April 1st,
nobody has ever seen this problem on his platform, nobody ever uses the
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS macro this way or I'm doing s.th.
blatantly
stupid.
What nags me is that I don't think I'm doing something exotic and,
moreover, that
I see different behaviour depending on execution context, i.e. run in a
script with
or without previous method call(s) vs interactive interpreter session.
I'll try to summarize the problem a bit more(see below for a link to the
original post
for reference):
I'm having trouble wrapping a very simple member function with Boost.Python
using the
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS macro, getting a segmentation fault
(sometimes
a bus error).
I run into the problem both with Boost 1.44.0 and 1.46.1, running on
Solaris 10/Sparc
using gcc 4.5.1 and Python 2.7.1.
I can reproducibly avoid the segfault and see an (expected) exception iff
the code is
* not run in an interactive interpreter session and
* if there is a boost-induced exception succesfully raised before the
critical call
(which I don't understand at all).
##### wrapped class
// file default_arguments_class.hpp
class DefaultArgs {
public: // member functions
int foo(int arg1=100, int arg2=10) { return arg1 - arg2; };
};
##### wrapper code
// file default_arguments_wrap.cpp
#include <boost/python.hpp>
#include "default_arguments_class.hpp"
namespace bp = boost::python;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(DefaultArgs_foo_overloads,
DefaultArgs::foo, 0, 2)
BOOST_PYTHON_MODULE(defaultargs)
{
bp::class_<DefaultArgs>("DefaultArgs", "DefaultArgs class docstring")
.def("foo_macro_a2", &DefaultArgs::foo,
DefaultArgs_foo_overloads((bp::arg("arg2"))))
;
};
##### In use in interactive interpreter session:
>>> import defaultargs
>>> d = defaultargs.DefaultArgs()
>>>
>>> try:
... print "d.foo_macro_a2(1, 2, 3):", d.foo_macro_a2(1, 2, 3)
... except Exception, e:
... print e
...
d.foo_macro_a2(1, 2, 3): Python argument types in
DefaultArgs.foo_macro_a2(DefaultArgs, int, int, int)
did not match C++ signature:
foo_macro_a2(DefaultArgs {lvalue})
foo_macro_a2(DefaultArgs {lvalue}, int)
foo_macro_a2(DefaultArgs {lvalue}, int, int arg2)
>>> print "d.foo_macro_a2(arg2=60):", d.foo_macro_a2(arg2=60)
Bus Error (core dumped)
##### In use within a script:
$ cat foo.py
import defaultargs
d = defaultargs.DefaultArgs()
try:
print "d.foo_macro_a2(1, 2, 3):", d.foo_macro_a2(1, 2, 3)
except Exception, e:
print e
print "d.foo_macro_a2(arg2=60):", d.foo_macro_a2(arg2=60)
$
PYTHONPATH=/var/tmp/boost_apps/boost/build/boost_1_46_1/py2.7/minimal/gcc-4.5.1
/debug/ /apps/local/gcc/4.5.1/bin/python2.7 foo.py
d.foo_macro_a2(1, 2, 3): Python argument types in
DefaultArgs.foo_macro_a2(DefaultArgs, int, int, int)
did not match C++ signature:
foo_macro_a2(DefaultArgs {lvalue})
foo_macro_a2(DefaultArgs {lvalue}, int)
foo_macro_a2(DefaultArgs {lvalue}, int, int arg2)
d.foo_macro_a2(arg2=60):
Traceback (most recent call last):
File "/ae/data/tmp/hjoukl/foo.py", line 9, in <module>
print "d.foo_macro_a2(arg2=60):", d.foo_macro_a2(arg2=60)
Boost.Python.ArgumentError: Python argument types in
DefaultArgs.foo_macro_a2(DefaultArgs)
did not match C++ signature:
foo_macro_a2(DefaultArgs {lvalue})
foo_macro_a2(DefaultArgs {lvalue}, int)
foo_macro_a2(DefaultArgs {lvalue}, int, int arg2)
My original post complete with bjam etc. can be found here:
http://article.gmane.org/gmane.comp.python.c%2B%2B/15163
Holger
Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart
More information about the Cplusplus-sig
mailing list