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

Dmitri Mouromtsev dimour at mail.ru
Thu Jun 5 11:01:01 CEST 2003


>>>> 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:


I tested this example in debug and release modes. In release mode it's
really work, but when i tried to run it in debug mode it fail. And warnings
appear every time.



What are your suggestions?





More information about the Cplusplus-sig mailing list