[C++-sig] Re: Parameter translation python, C++

David Abrahams dave at boost-consulting.com
Wed Aug 13 16:14:57 CEST 2003


Stefan Fleiter <sf.lists at web.de> writes:

> Hi,
>
> when I call a boost::python method from python
> with a parameter of type float and there is only
> a C++ Method with a parameter of type double
> I get an "unidentifiable C++ exception".
>
> C++-Code:
> --------------------------------------------------------
> void pybind(db::ExtCursor& cur, int column, float value)
                                              ^^^^^
> {
>    // do something
> }
>
> BOOST_PYTHON_MODULE(_dblib)
> {
>
>      void (*bind4)(db::ExtCursor&, int, double) = &pybind;
                                          ^^^^^^
I can't believe your compiler lets you get away with this.

>      py::class_< db::ExtCursor, boost::noncopyable >("ExtCursor",
>      py::init< db::Connection& >())
>          .def("bind", bind4, "bind value to query")
> }
>
> Python-Code:
> --------------------------------------------------------
> self._cCursor.bind(0, 2.3) // _cCursor is db::ExtCursor
>
>
> PS: I am using boost::python 1.30.

Your example is missing the definition of ExtCursor.

Anyway, the exception is either:

1. Actually a crash (most likely in your code), if you're running on
   windows.  Try #including libs/python/test/module_tail.cpp in your
   module

2. A regular C++ exception thrown by your code for which you've not
   installed a translator.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list