Re: [Python-Dev] String views

2005-09-06 Thread skip
Greg> If a Python function is clearly wrapping a C function, one doesn't Greg> expect to be able to pass strings with embedded NULs to it. Skip> Isn't that just floating an implementation detail up to the Skip> programmer (who may well not be POSIX- or Unix-aware)? Fredrik> s

Re: [Python-Dev] String views

2005-09-06 Thread Greg Ewing
[EMAIL PROTECTED] wrote: > Greg> If a Python function is clearly wrapping a C function, one doesn't > Greg> expect to be able to pass strings with embedded NULs to it. > > Isn't that just floating an implementation detail up to the programmer (who > may > well not be POSIX- or Unix-aware)

Re: [Python-Dev] String views

2005-09-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: >Greg> If a Python function is clearly wrapping a C function, one doesn't >Greg> expect to be able to pass strings with embedded NULs to it. > > Isn't that just floating an implementation detail up to the programmer (who > may > well not be POSIX- or Unix-aware)?

Re: [Python-Dev] String views

2005-09-05 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Greg> If a Python function is clearly wrapping a C function, one doesn't > Greg> expect to be able to pass strings with embedded NULs to it. > > Isn't that just floating an implementation detail up to the programmer (who > may > well not be POSIX- or Unix-aware)

Re: [Python-Dev] String views

2005-09-05 Thread skip
Greg> If a Python function is clearly wrapping a C function, one doesn't Greg> expect to be able to pass strings with embedded NULs to it. Isn't that just floating an implementation detail up to the programmer (who may well not be POSIX- or Unix-aware)? ___

Re: [Python-Dev] String views

2005-09-04 Thread Greg Ewing
Steve Holden wrote: > 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? If a Python function is clearly wrapping a C function, one doesn't expect to be able to pass strings with embedded NU

Re: [Python-Dev] String views (was: Re: Proof of the pudding:str.partition())

2005-09-01 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: >Fredrik> Python strings are character buffers with a known length, not >Fredrik> null-terminated C strings. the CPython implementation >Fredrik> guarantees that the character buffer has a trailing NULL >Fredrik> character, but that's mostly to make it eas

Re: [Python-Dev] String views

2005-09-01 Thread Stephen J. Turnbull
> "Steve" == Steve Holden <[EMAIL PROTECTED]> writes: Steve> Since Python strings *can* contain embedded NULs, doesn't Steve> that rather poo on the idea of passing pointers to their Steve> data to C functions as things stand? I think it's a "consenting adults" issue. Ie, C progr

Re: [Python-Dev] String views

2005-09-01 Thread Steve Holden
Greg Ewing wrote: > [EMAIL PROTECTED] 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. > > >

Re: [Python-Dev] String views

2005-09-01 Thread Josiah Carlson
[EMAIL PROTECTED] wrote: > >> I'm skeptical about performance as well, but not for that reason. A > >> string object can have a referent field. If not NULL, it refers to > >> another string object which is INCREFed in the usual way. At string > >> deallocation, if the referent i

Re: [Python-Dev] String views

2005-09-01 Thread skip
>> I'm skeptical about performance as well, but not for that reason. A >> string object can have a referent field. If not NULL, it refers to >> another string object which is INCREFed in the usual way. At string >> deallocation, if the referent is not NULL, the referent is DECRE

Re: [Python-Dev] String views (was: Re: Proof of the pudding:str.partition())

2005-09-01 Thread skip
Fredrik> Python strings are character buffers with a known length, not Fredrik> null-terminated C strings. the CPython implementation Fredrik> guarantees that the character buffer has a trailing NULL Fredrik> character, but that's mostly to make it easy to pass Python Fredrik>

[Python-Dev] String views

2005-09-01 Thread Jim Jewett
Tim Delaney writes: > One of the big disadvantages of string views is that they need to keep > the original object around, no matter how big it is. But in the case of > partition, much of the time the original string survives for at least a > similar period to the partitions. Michael Chermside wri

Re: [Python-Dev] String views

2005-09-01 Thread Guido van Rossum
On 8/31/05, Greg Ewing <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > Ah, I forgot the data is part of the PyString object itself, not stored as a > > separate char* array. Without a char* in the object it's kind of hard to do > > views. > > That wouldn't be a problem if substrings

Re: [Python-Dev] String views

2005-09-01 Thread Michael Chermside
Tim Delaney writes: > One of the big disadvantages of string views is that they need to keep > the original object around, no matter how big it is. But in the case of > partition, much of the time the original string survives for at least a > similar period to the partitions. Why do you say that?

Re: [Python-Dev] String views (was: Re: Proof of the pudding:str.partition())

2005-08-31 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > As a Python programmer I'd get back what look like three strings: "http", > ":", and "//www.python.org/". If each of them was a view onto part of the > original string, only the last one would truly refer to a NUL-terminated > sequence of characters. If I then wanted t

Re: [Python-Dev] String views

2005-08-31 Thread Greg Ewing
[EMAIL PROTECTED] wrote: > Ah, I forgot the data is part of the PyString object itself, not stored as a > separate char* array. Without a char* in the object it's kind of hard to do > views. That wouldn't be a problem if substrings were a separate subclass of basestring with their own representa

Re: [Python-Dev] String views

2005-08-31 Thread Greg Ewing
[EMAIL PROTECTED] 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

Re: [Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread skip
James> I suspect this would be a pessimization most of the time, as it James> would require keeping a list of pointers to all the views James> referencing the string object. I'm skeptical about performance as well, but not for that reason. A string object can have a referent field.

Re: [Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread James Y Knight
On Aug 31, 2005, at 10:21 PM, [EMAIL PROTECTED] wrote: > > Tim> One of the big disadvantages of string views is that they > need to > Tim> keep the original object around, no matter how big it is. > But in > Tim> the case of partition, much of the time the original string > Ti

Re: [Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread skip
Tim> One of the big disadvantages of string views is that they need to Tim> keep the original object around, no matter how big it is. But in Tim> the case of partition, much of the time the original string Tim> survives for at least a similar period to the partitions. Not necessar

Re: [Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread Delaney, Timothy (Tim)
[EMAIL PROTECTED] wrote: > How would this work? One of the advantages of the current string is > that the underlying data is NUL-terminated, so when passing strings > to C routines no copying is required. I didn't say it would be easy. Just that it's about the first cases where I've seen there c

Re: [Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread skip
Skip> OTOH, maybe that would work. Perhaps we should try it. Ah, I forgot the data is part of the PyString object itself, not stored as a separate char* array. Without a char* in the object it's kind of hard to do views. Skip ___ Python-Dev maili

[Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

2005-08-31 Thread skip
Tim> I'm actually starting to think that this may be a good use case for Tim> views of strings i.e. rather than create 3 new strings, each Tim> "string" is a view onto the string that was partitioned. How would this work? One of the advantages of the current string is that the underl