[C++-sig] Overloading & keyword args bug?
Alex Mohr
amohr at pixar.com
Wed Jun 7 22:22:00 CEST 2006
Hi folks,
Can someone tell me what's wrong with this? As is, this code crashes in
the example below (anytime I try to pass keyword arguments to the first
overload). If I reverse the order of the lines marked with ########,
everything seems to work fine.
Thanks!
Alex
#include <boost/python.hpp>
#include <string>
#include <cstdio>
using namespace boost::python;
using std::string;
static void f1(string const &a1, int x, int y) {
printf("f1 with %s, %d, %d\n", a1.c_str(), x, y);
}
static void f2(string const &a1, string const &a2, int x, int y) {
printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y);
}
BOOST_PYTHON_MODULE(overload_kw) {
def("f", f1, (arg("x")=3, arg("y")=4)); // ########
def("f", f2, (arg("x")=5, arg("y")=6)); // ########
}
---------------------------------------
>>> from overload_kw import *
>>> f('hello')
f1 with hello, 3, 4
>>> f('hello', 'goodbye')
f2 with hello, goodbye, 5, 6
>>> f('hello', 1, 2)
f1 with hello, 1, 2
>>> f('hello', x=1)
Segmentation fault
More information about the Cplusplus-sig
mailing list