[C++-sig] Re: passing buffer of bytes from Python to C++

David Abrahams dave at boost-consulting.com
Wed Mar 10 13:45:34 CET 2004


Dan Halbert <halbert at bbn.com> writes:

> One of the C++ methods I've wrapped with BPL has a signature something like
>
>     process_data(unsigned char const* buffer, unsigned long buffer_length)
>
> In other words, it's just taking a buffer of bytes (it's 8-bit audio
> data), which I'll be reading from a file or a network connection in
> Python.
>
> I can make the Python data object whatever I want (string, list,
> tuple), but I see that BPL doesn't convert any of these to a char
> pointer automatically. Is there a way to generate a simple char*
> buffer with Python and BPL?

Python strings will be automatically converted to char const*
                                                       ^^^^^

> Later I'll also want to do the same thing for buffers of 16-bit
> values, so is that also possible?

I'm afraid there's only a conversion from Python unicode strings to
std::wstring, but not to wchar_t const*.


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list