[C++-sig] const char arrays
Niall Douglas
s_sourceforge at nedprod.com
Tue Aug 5 19:16:13 CEST 2003
Are const char arrays supported by boost.python?
eg;
static const char deleteTypeName[];
Obviously we'd prefer them to become python strings. BTW MSVC7.1 here
stops with "reference to a zero-sized array is illegal". BTW a full
list of what boost.python doesn't support in the docs would be
really, really useful - then I can know it's not me misconfiguring
something.
BTW, I've been trying to find docs on how to implement your own
custom converters. Basically I'd like to convert a FXString to a
python one automatically and back again. I've come up with:
namespace boost { namespace python {
BOOST_PYTHON_TO_PYTHON_BY_VALUE(FX::FXString,
PyString_FromStringAndSize(x.text(), x.length()))
}} // namespace
For the other direction I tried:
struct FXString_rvalue_from_python
{
static void init()
{
slot_rvalue_from_python<FX::FXString,
FXString_rvalue_from_python>();
}
static unaryfunc *get_slot(PyObject *obj)
{
return (PyString_Check(obj)) ? &obj->ob_type->tp_str : 0;
}
static FX::FXString extract(PyObject *intermediate)
{
return FX::FXString(PyString_AsString(intermediate),
PyString_Size(intermediate));
}
};
Problem is that slot_rvalue_from_python<> in builtin_converters.hpp
is in an unnamed namespace and so therefore is inaccessible to me :(
Furthermore, string literals in const char * form don't appear to
cast to a FXString first as usual. Instead the compiler treats them
as a const char *, which AFAICS Boost.python doesn't support (it
seems to not to support any pointer to any basic type actually :( ).
This is odd because throughout the header files it /looks/ like it
support const literals to python strings, but it sure ain't working
here (I get a static assertion failure in
make_instance_impl::execute() with is_class<T>::value being value).
Any way of working around this? ie; to get const char * literals to
become python strings? This library I'm making bindings for works
exclusively with C style strings as its lower levels.
Cheers,
Niall
More information about the Cplusplus-sig
mailing list