[C++-sig] Re: Problem with Extract conversion

David Abrahams dave at boost-consulting.com
Wed Jun 4 15:19:24 CEST 2003


"Dmitri Mouromtsev" <dimour at mail.ru> writes:

>>> Hello all!
>>> I am embedding Python in my application by using BOOST.PYTHON. I tried
>>> to compile in MSVC 7.0 the example with extract<> conversion:
>>>
>>> boost::python::str test_str("test");
>>> char const* c_str = extract<char const*>(test_str);
>>>
>>>  If I run this code an unhandled exception rise when the function
>>> throw_no_lvalue_from_python compose error message "No registered
> converter
>>> was able to extract a C++...".
>>>
>>>  What I need to do and what is my mistake.
>>
>>Please post a small, complete program which reproduces your problem.
>
> Here is test program reproducing my problem (or bug):
> #include "Python.h"
>
> #include "boost\python.hpp"
>
> #include <iostream>
>
> using namespace boost::python;
>
> int main()
>
> {
>
>     Py_Initialize();
>
>     boost::python::str test_str("test");
>
>     char const* c_str = extract<char const*>(test_str);
>
>     std::cout << c_str << '\n';
>
>     return 0;
>
> }
>
> The exception rise in the same point as I describe blow.
>
> If I use another conversoin:
>
> char const* c_str = PyString_AsString(test_str.ptr());
>
> it's all right.
>
> And when I build this program I've got warning "'argument' : conversion from
> 'size_t' to 'int', possible loss of data" to line
>
> BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string,
> PyString_FromStringAndSize(x.c_str(),x.size()))
>
> in the file builtin_converters.hpp.

Your example works perfectly well for me and builds with no warnings:

bjam -sBUILD=debug-python -sTOOLS="vc7.1" --verbose-test test
...found 2016 targets...
...updating 3 targets...
execute-test c:\build\libs\python\user\bin\test.test\vc7.1\debug-python\runtime-link-dynamic\test.run
1 file(s) copied.
====== BEGIN OUTPUT ======
test
====== END OUTPUT ======
**passed ** c:\build\libs\python\user\bin\test.test\vc7.1\debug-python\runtime-link-dynamic\test.test
...updated 3 targets...

The Jamfile looks like:

subproject libs/python/user ;

# bring in the rules for python
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
# bring in rules for testing
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ;

run test.cpp <dll>../build/boost_python
  : # program args
  : # input files
  : # requirements
  $(PYTHON_PROPERTIES)
    <library-path>$(PYTHON_LIB_PATH)
      <$(gcc-compilers)><debug-python><library-path>$(CYGWIN_PYTHON_DEBUG_DLL_PATH)
        <$(gcc-compilers)><*><library-path>$(CYGWIN_PYTHON_DLL_PATH)
          <find-library>$(PYTHON_EMBEDDED_LIBRARY) ;


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





More information about the Cplusplus-sig mailing list