[Python-Dev] String views

Steve Holden steve at holdenweb.com
Fri Sep 2 06:50:04 CEST 2005


Greg Ewing wrote:
> skip at pobox.com wrote:
> 
>>If I then wanted to see what scheme's value
>>compared to, the string's comparison method would have to recognize that it
>>wasn't truly NUL-terminated, copy it, call strncmp() or whatever underlying
>>routine is used for string comparisons.
> 
> 
> Python string comparisons can't be using anything that
> relies on nul-termination, because Python strings can
> contain embedded nuls. Possibly it uses memcmp(), but
> that takes a length.
> 
> You have a point when it comes to passing strings to
> other C routines, though. For those that don't have a
> variant which takes a maximum length, the substring type
> might have to keep a cached nul-terminated copy created
> on demand. Then the copying overhead would only be
> incurred if you did happen to pass a substring to such
> a routine.
> 
Since Python strings *can* contain embedded NULs, doesn't that rather 
poo on the idea of passing pointers to their data to C functions as 
things stand?

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/



More information about the Python-Dev mailing list