|
Boost Users : |
Subject: [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-13 10:25:22
Hello:
I think I am experience a build problem here but not really sure;
nonetheless, below is a simple example that illustrates my problem.
Any idea what I might be doing wrong. I am using boost_1_43_0 built
with gcc 4.2.1 on i686 running darwin. I am linking to the standard
2.5 python that comes with the distro.
Please note that the PyRun_SimpleString("import sys"); does not error
at all. The error comes from when the call to import(). I am not
sure if this is a clue or not but gdb seems not to know what line it
is on. I am guessing it is just confused because of all the inlines. I
suspect this is a linking issues of some sort. However I did check
that they are all linking to the correct location. Why does it
convert the const char * to a str in the first place. 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();
}
// Compiled with 'g++ -I. -I/usr/include -I/usr/local/include
-I../../includes/python2_5_1 -g -L/usr/local/lib
boost_python_issue.cpp -lboost_system -lboost_python -lm
-lpython2.5 -o boost_python_issue'
Output from gdb:
(gdb) break main
Breakpoint 1 at 0x100001319: file boost_python_issue.cpp, line 9.
(gdb) r
Starting program: /Project/zephyr/src/Composer/boost_python_issue
Reading symbols for shared libraries .++++++++..... done
Breakpoint 1, main (argc=1, argv=0x7fff5fbff6d8) at boost_python_issue.cpp:9
9 Py_Initialize();
(gdb) s
11 PyRun_SimpleString("import sys");
(gdb)
13 object sys = import("sys");
(gdb)
boost::python::str::str (this=0x7fff5fbff690, s=0x10000169d "sys") at
str.hpp:150
150 str(const char* s) : base(s) {} // new str
(gdb)
boost::python::detail::str_base::str_base (this=0x7fff5fbff690,
s=0x10000169d "sys") at libs/python/src/str.cpp:39
39 ))
(gdb)
object [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/object_core.hpp:534
Line number 534 out of range; errors.hpp has 55 lines.
(gdb)
expect_non_null<PyObject> [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/errors.hpp:43
44 if (x == 0)
(gdb)
object [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/object_core.hpp:513
534 : object_base(expect_non_null((PyObject*)p))
(gdb)
object_base [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/object_core.hpp:513
513 : m_ptr(p)
(gdb)
boost::python::detail::str_base::str_base (this=0x7fff5fbff690,
s=<value temporarily unavailable, due to optimizations>) at
libs/python/src/str.cpp:40
40 {}
(gdb)
0x000000010000154d in boost::python::str::str (this=0x7fff5fbff690,
s=0x10000169d "sys") at str.hpp:150
150 str(const char* s) : base(s) {} // new str
(gdb)
boost::python::import (name=@0x7fff5fbff690) at libs/python/src/import.cpp:19
19 char *n = python::extract<char *>(name);
(gdb)
extract [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/extract.hpp:156
156 # else
(gdb)
boost::python::api::object_base::ptr () at
/Users/bray/sources/boost_1_43_0/boost/python/object_core.hpp:542
543 return m_ptr;
(gdb)
extract [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/extract.hpp:216
156 : base(o.ptr())
(gdb)
extract_pointer [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/extract.hpp:216
219 )
(gdb)
boost::python::converter::get_lvalue_from_python (source=0x1005cb1e0,
converters=@0x100409500) at
libs/python/src/converter/from_python.cpp:128
128 void* x = objects::find_instance_impl(source,
converters.target_type);
(gdb)
boost::python::objects::find_instance_impl (inst=0x1005cb1e0,
type={<boost::totally_ordered<boost::python::type_info,boost::python::type_info,boost::detail::empty_base<boost::python::type_info>,boost::detail::false_t>>
= {<boost::totally_ordered1<boost::python::type_info,boost::detail::empty_base<boost::python::type_info>
>> = {<boost::less_than_comparable1<boost::python::type_info,boost::equality_comparable1<boost::python::type_info,
boost::detail::empty_base<boost::python::type_info> > >> =
{<boost::equality_comparable1<boost::python::type_info,boost::detail::empty_base<boost::python::type_info>
>> = {<boost::detail::empty_base<boost::python::type_info>> = {<No
data fields>}, <No data fields>}, <No data fields>}, <No data
fields>}, <No data fields>}, m_base_type = 0x7fff885a066c "c"},
null_shared_ptr_only=false) at libs/python/src/object/class.cpp:485
485 if (Py_TYPE(Py_TYPE(inst)) != &class_metatype_object)
(gdb)
490 for (instance_holder* match = self->objects; match != 0;
match = match->next())
(gdb)
497 }
(gdb)
boost::python::converter::get_lvalue_from_python (source=0x1005cb1e0,
converters=@0x100409500) at
libs/python/src/converter/from_python.cpp:129
129 if (x)
(gdb)
132 lvalue_from_python_chain const* chain = converters.lvalue_chain;
(gdb)
133 for (;chain != 0; chain = chain->next)
(gdb)
135 void* r = chain->convert(source);
(gdb)
boost::python::converter::(anonymous namespace)::convert_to_cstring
(obj=0x1005cb1e0) at
libs/python/src/converter/builtin_converters.cpp:46
46 return PyString_Check(obj) ? PyString_AsString(obj) : 0;
(gdb)
47 }
(gdb)
boost::python::converter::get_lvalue_from_python (source=0x1005cb1e0,
converters=<value temporarily unavailable, due to optimizations>) at
libs/python/src/converter/from_python.cpp:136
136 if (r != 0)
(gdb)
132 lvalue_from_python_chain const* chain = converters.lvalue_chain;
(gdb)
133 for (;chain != 0; chain = chain->next)
(gdb)
140 }
(gdb)
0x00000001001a1128 in extract_pointer [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/extract.hpp:219
219 )
(gdb)
boost::python::import (name=<value temporarily unavailable, due to
optimizations>) at libs/python/src/import.cpp:19
19 char *n = python::extract<char *>(name);
(gdb)
boost::python::extract<char*>::operator char* () at
/Users/bray/sources/boost_1_43_0/boost/python/extract.hpp:138
138 return (*this)();
(gdb)
boost::python::converter::extract_pointer<char*>::operator() () at
extract.hpp:231
232 if (m_result == 0 && m_source != Py_None)
(gdb)
boost::python::converter::extract_pointer<char*>::operator() () at
extract.hpp:233
233 (throw_no_pointer_from_python)(m_source,
registered_pointee<Ptr>::converters);
(gdb)
boost::python::converter::throw_no_pointer_from_python
(source=0x1005cb1e0, converters=@0x100409500) at
libs/python/src/converter/from_python.cpp:256
256 (throw_no_lvalue_from_python)(source, converters, "pointer");
(gdb)
257 }
(gdb)
boost::python::converter::throw_no_pointer_from_python
(source=0x1005cb1e0, converters=@0x100409500) at
libs/python/src/converter/from_python.cpp:256
256 (throw_no_lvalue_from_python)(source, converters, "pointer");
(gdb)
boost::python::converter::(anonymous
namespace)::throw_no_lvalue_from_python (source=0x1005cb1e0,
converters=@0x100409500, ref_type=0x1001a8e55 "pointer") at
libs/python/src/converter/from_python.cpp:201
201 void throw_no_lvalue_from_python(PyObject* source,
registration const& converters, char const* ref_type)
(gdb)
215 ));
(gdb)
boost::python::type_info::name () at
/Users/bray/sources/boost_1_43_0/boost/python/type_id.hpp:156
156 {
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:116
116 static mangling_map demangler;
(gdb)
121 , compare_first_cstring());
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::end () at
/usr/include/c++/4.2.1/bits/stl_vector.h:349
349 inline bool
(gdb)
__normal_iterator [inlined] () at /usr/include/c++/4.2.1/bits/stl_iterator.h:654
817 { return __lhs.base() - __rhs.base(); }
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::end () at
/usr/include/c++/4.2.1/bits/stl_vector.h:331
331 { return iterator(this->_M_impl._M_start); }
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:121
121 , compare_first_cstring());
(gdb)
lower_bound<__gnu_cxx::__normal_iterator<std::pair<const char*, const
char*>*, std::vector<std::pair<const char*, const char*>,
std::allocator<std::pair<const char*, const char*> > > >,
std::pair<const char*, const char*>,
boost::python::<unnamed>::compare_first_cstring> [inlined] () at
/usr/include/c++/4.2.1/bits/stl_algo.h:98
98 return __last - __first;
(gdb)
operator-<std::pair<const char*, const char*>*,
std::vector<std::pair<const char*, const char*>,
std::allocator<std::pair<const char*, const char*> > > > [inlined] ()
at /usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:119
119 std::__iterator_category(__first));
(gdb)
__distance<__gnu_cxx::__normal_iterator<std::pair<const char*, const
char*>*, std::vector<std::pair<const char*, const char*>,
std::allocator<std::pair<const char*, const char*> > > > > [inlined]
() at /usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:2948
Line number 2948 out of range; stl_iterator_base_funcs.h has 182 lines.
(gdb)
distance<__gnu_cxx::__normal_iterator<std::pair<const char*, const
char*>*, std::vector<std::pair<const char*, const char*>,
std::allocator<std::pair<const char*, const char*> > > > > [inlined]
() at /usr/include/c++/4.2.1/bits/stl_iterator.h:116
156 __i += __n;
(gdb)
lower_bound<__gnu_cxx::__normal_iterator<std::pair<const char*, const
char*>*, std::vector<std::pair<const char*, const char*>,
std::allocator<std::pair<const char*, const char*> > > >,
std::pair<const char*, const char*>,
boost::python::<unnamed>::compare_first_cstring> [inlined] () at
/usr/include/c++/4.2.1/bits/stl_algo.h:2952
2952 while (__len > 0)
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:121
121 , compare_first_cstring());
(gdb)
123 if (p == demangler.end() || strcmp(p->first, mangled))
(gdb)
128 );
(gdb)
132 if (status == -1)
(gdb)
143 : keeper.p;
(gdb)
152 if (cxxabi_cxa_demangle_is_broken()
(gdb)
cxxabi_cxa_demangle_is_broken [inlined] () at
/Users/bray/sources/boost_1_43_0/libs/python/src/converter/type_id.cpp:94
97 if (!was_tested) {
(gdb)
99 free_mem keeper(cxxabi::__cxa_demangle("b", 0, 0, &status));
(gdb)
100 was_tested = true;
(gdb)
101 if (status == -2 || strcmp(keeper.p, "bool") != 0) {
(gdb)
103 }
(gdb)
~free_mem [inlined] () at
/Users/bray/sources/boost_1_43_0/libs/python/src/converter/type_id.cpp:86
87 std::free(p);
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:152
152 if (cxxabi_cxa_demangle_is_broken()
(gdb)
183 p = demangler.insert(p, std::make_pair(mangled,
demangled));
(gdb)
331 { return iterator(this->_M_impl._M_start); }
(gdb)
183 p = demangler.insert(p, std::make_pair(mangled,
demangled));
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::insert () at
/usr/include/c++/4.2.1/bits/vector.tcc:93
95 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
(gdb)
102 _M_insert_aux(__position, __x);
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_insert_aux
(this=0x1001bfd40, __position={_M_current = 0x0}, __x=@0x7fff5fbff5a0)
at vector.tcc:245
245 _M_insert_aux(iterator __position, const _Tp& __x)
(gdb)
247 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
(gdb)
260 const size_type __old_size = size();
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::size () at
/usr/include/c++/4.2.1/bits/stl_vector.h:400
400 { return size_type(this->_M_impl._M_finish -
this->_M_impl._M_start); }
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_insert_aux
(this=0x1001bfd40, __position={_M_current = 0x0}, __x=@0x7fff5fbff5a0)
at vector.tcc:261
261 if (__old_size == this->max_size())
(gdb)
267 size_type __len = __old_size != 0 ? 2 * __old_size :
1;
(gdb)
88 if (__builtin_expect(__n > this->max_size(), false))
(gdb)
91 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
(gdb)
275 __new_finish =
(gdb)
__uninitialized_copy_a<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*, std::pair<const char*, const
char*> > [inlined] () at
/usr/include/c++/4.2.1/bits/stl_uninitialized.h:114
114 _Is_POD());
(gdb)
__uninitialized_copy_aux<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*> [inlined] () at
stl_uninitialized.h:254
254 { return std::uninitialized_copy(__first, __last, __result); }
(gdb)
uninitialized_copy<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*> [inlined] () at
stl_uninitialized.h:254
254 { return std::uninitialized_copy(__first, __last, __result); }
(gdb)
__gnu_cxx::new_allocator<std::pair<char const*, char const*>
>::construct () at /usr/include/c++/4.2.1/ext/new_allocator.h:107
107 { ::new(__p) _Tp(__val); }
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_insert_aux
(this=0x1001bfd40, __position={_M_current = 0x0}, __x=@0x7fff5fbff5a0)
at vector.tcc:280
280 ++__new_finish;
(gdb)
281 __new_finish =
(gdb)
__uninitialized_copy_a<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*, std::pair<const char*, const
char*> > [inlined] () at
/usr/include/c++/4.2.1/bits/stl_uninitialized.h:114
114 _Is_POD());
(gdb)
__uninitialized_copy_aux<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*> [inlined] () at
stl_uninitialized.h:254
254 { return std::uninitialized_copy(__first, __last, __result); }
(gdb)
uninitialized_copy<std::pair<const char*, const char*>*,
std::pair<const char*, const char*>*> [inlined] () at
stl_uninitialized.h:254
254 { return std::uninitialized_copy(__first, __last, __result); }
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_insert_aux
(this=0x1001bfd40, __position={_M_current = 0x0}, __x=<value
temporarily unavailable, due to optimizations>) at vector.tcc:293
293 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
(gdb)
295 _M_deallocate(this->_M_impl._M_start,
(gdb)
std::_Vector_base<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_deallocate
() at /usr/include/c++/4.2.1/bits/stl_vector.h:135
136 if (__p)
(gdb)
std::vector<std::pair<char const*, char const*>,
std::allocator<std::pair<char const*, char const*> > >::_M_insert_aux
(this=0x1001bfd40, __position={_M_current = 0x0}, __x=<value
temporarily unavailable, due to optimizations>) at vector.tcc:298
298 this->_M_impl._M_start = __new_start;
(gdb)
299 this->_M_impl._M_finish = __new_finish;
(gdb)
300 this->_M_impl._M_end_of_storage = __new_start + __len;
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
vector.tcc:103
103 return iterator(this->_M_impl._M_start + __n);
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:183
183 p = demangler.insert(p, std::make_pair(mangled,
demangled));
(gdb)
185 }
(gdb)
~free_mem [inlined] () at
/Users/bray/sources/boost_1_43_0/libs/python/src/converter/type_id.cpp:86
87 std::free(p);
(gdb)
boost::python::detail::gcc_demangle (mangled=0x7fff885a066c "c") at
libs/python/src/converter/type_id.cpp:189
189 }
(gdb)
boost::python::converter::(anonymous
namespace)::throw_no_lvalue_from_python (source=<value temporarily
unavailable, due to optimizations>, converters=<value temporarily
unavailable, due to optimizations>, ref_type=0x1001a8e55 "pointer") at
libs/python/src/converter/from_python.cpp:215
215 ));
(gdb)
handle<PyObject> [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/handle.hpp:75
75 : m_p(
(gdb)
boost::python::detail::manage_ptr<_object> (p=0x1005ad6b8) at handle.hpp:55
55 inline T* manage_ptr(T* p, ...)
(gdb)
57 return expect_non_null(p);
(gdb)
expect_non_null<PyObject> [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/errors.hpp:43
44 if (x == 0)
(gdb)
0x000000010018a81d in boost::python::converter::(anonymous
namespace)::throw_no_lvalue_from_python (source=<value temporarily
unavailable, due to optimizations>, converters=<value temporarily
unavailable, due to optimizations>, ref_type=0x1001a8e55 "pointer") at
libs/python/src/converter/from_python.cpp:215
215 ));
(gdb)
boost::python::converter::(anonymous
namespace)::throw_no_lvalue_from_python (source=<value temporarily
unavailable, due to optimizations>, converters=<value temporarily
unavailable, due to optimizations>, ref_type=0x1001a8e55 "pointer") at
libs/python/src/converter/from_python.cpp:217
217 PyErr_SetObject(PyExc_TypeError, msg.get());
(gdb)
219 throw_error_already_set();
(gdb)
boost::python::throw_error_already_set () at libs/python/src/errors.cpp:61
61 throw error_already_set();
(gdb)
error_already_set [inlined] () at
/Users/bray/sources/boost_1_43_0/boost/python/errors.hpp:19
19 virtual ~error_already_set();
(gdb)
boost::python::throw_error_already_set () at libs/python/src/errors.cpp:61
61 throw error_already_set();
(gdb)
TypeError: No registered converter was able to extract a C++ pointer
to type char from this Python object of type str
Program exited normally.
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