Extracting strings from Python beyond the terminating NULL

Phil Muldoon pmuldoon@redhat.com
Tue May 12 09:18:00 GMT 2009


Phil Muldoon wrote:
> And the code in question uses that. So even though we dutifully 
> preserve the embedded null, when the call to Python is made to extract 
> the string, it is terminated on the first null. I'm hoping I missed a 
> length based api call that some python hacker can point me too. 
> PyString_Size(string) actually returns the correct (non null 
> terminated) length btw.
>
And it only took me to write this email to to figure out that:

 PyString_AsStringAndSize(object, &result, &size);


Will fetch the whole string, and report the size as well.

(In the existing code the xstrdup call threw me)

Thanks for reading anyway!

Regards

Phil



More information about the Archer mailing list