Boost logo

Boost Users :

Subject: Re: [Boost-users] TypeError: No registered converter was able to extract a C++ pointer to type char from this Python object of type str
From: Brian Ray (brianhray_at_[hidden])
Date: 2010-08-16 15:04:48


On Sat, Aug 14, 2010 at 4:51 PM, David Abrahams <dave_at_[hidden]> wrote:
> At Fri, 13 Aug 2010 09:25:22 -0500,
> Brian Ray wrote:
>>>> that they are all linking to the correct location.  Why does it
>> convert the const char * to a str in the first place.
>              ^^^^^
>
> So that it can call Python's import function.
>
>> Seems to be thrashing around a bit.
>>
>> -- Brian
>>
>> ///  contents of boost_python_issue.cpp
>> #include <boost/python.hpp>
>> using namespace boost::python;
>>
>> int main(int argc, char **argv)
>> {
>>  Py_Initialize();
>>  try {
>>     PyRun_SimpleString("import sys");
>>     // This raises exception
>>     object sys = import("sys");
>>  } catch (boost::python::error_already_set) {
>>     PyErr_Print();
>>  }
>>  Py_Finalize();
>> }
>
>
> Hmm, looks simple enough.
>
>> Output from gdb:

>> (gdb)
>> boost::python::import (name=@0x7fff5fbff690) at libs/python/src/import.cpp:19
>> 19        char *n = python::extract<char *>(name);
>
>
> This is where the bug is (in Boost.Python).  One should never try to
> extract a pointer to non-const char from a str.  Could you try the
> enclosed patch and see if your problem is fixed?

Yes, applying this patch to the 1.43 release fixes the problem. Dave,
can this patch be applied to version control head if it has not been
already?

-- Brian Ray


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net