[C++-sig] Re: const char arrays
Niall Douglas
s_sourceforge at nedprod.com
Wed Aug 6 05:03:20 CEST 2003
On 5 Aug 2003 at 15:29, David Abrahams wrote:
> > Is it not better I try to solve problems myself before bothering
> > others?
>
> Absolutely, and thanks for that.
I should add that really I don't know what I'm doing - I'm looking
for stuff which seems associated and plugging in new values. My
problem is that the terse explanation of each template in the docs
doesn't help me see how they all fit together to get the job done. I
know that a database of API's is built and through this the binding
happens partially at compile-time partially at run-time. eg; below I
illustrate a conceptual problem with boost::python::object.
> > I only post here when I really don't know what to do next.
>
> You could make it easier for us to help you by posting small examples
> that demonstrate what you're trying to do and what result you expect,
> and taking care with the precision of what you write, making sure that
> you have supplied enough information. I spent 5 minutes wondering why
> I couldn't find slot_rvalue_from_python in builtin_converters.hpp. If
> you are unable to convert char const* to python a small reproducible
> example and a copy of the error message would help.
My problem here is that I'm binding a large library I didn't write
and so much stuff depends on other stuff. So I can't just cut & paste
the bit I need - I have to alter it which then usually causes a
different error report. Hence to get an isolated example takes hours
of trial & error :(
> > Could not a new section be opened in the docs called "custom rvalue
> > converters"? It seems a waste of time for me to bash my head against
> > a wall and yours to keep answering the same questions over and over.
>
> Sure, we just need a volunteer to write it <wink>.
Ah, but I don't know what I'm doing so that would seem unwise. I'll
firstly say (with some joy) that my test class wrapper finally
compiled today without error and my thanks to this list for helping
me. I've not tried linking yet (bedtime now).
A question (and only because of the atlantic clock difference): in
the example http://mail.python.org/pipermail/c++-sig/2003-
May/004133.html:
struct custom_string_to_python_str
{
static PyObject* convert(custom_string const& s)
{
return
boost::python::incref(boost::python::object(s.value()).ptr());
}
};
Isn't this making use of boost.python's inbuilt std::string
converter? ie; it's not converting to a python string itself.
For some non-std::string based string, would it be more like:
struct custom_string_to_python_str
{
static PyObject* convert(custom_string const& s)
{
return
boost::python::incref(PyString_FromStringAndSize(s.text(),
s.length()));
}
};
I get that boost::python::object encapsulates a python object, and
that ptr() returns that object, but I can't see a conversion path in
the original without going through std::string (which seems
inefficient).
Cheers,
Niall
More information about the Cplusplus-sig
mailing list