On Tue, May 19, 2009 at 9:05 PM, Chris Colbert <[email protected]> wrote:
> I know that Cython does an implicit conversion from char* to Python string,
> but do I need to somehow specify the length of the string?

But then Cython assumes you string is a NULL-terminated one. In other
words, you cannot return this way a char* buffer with embed NULL's.

> I ask because I have a data buffer of known size (7854000 bytes uint8) but
> when i pass the pointer to that buffer into python, my string length is only
> 4617.

Likely your char* buffer has a NULL at index 4617.

>
> this is in python 2.5.
>
> am I missing something?
>

Yes. You should use this core Python C-API call:

http://docs.python.org/c-api/string.html#PyString_FromStringAndSize

This is the way to create Python (byte) strings with embed NULL's.



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to