On Wed, Feb 15, 2006 at 01:38:41PM -0500, Jim Jewett wrote: > On 2/14/06, Neil Schemenauer wrote: > > People could spell it bytes(s.encode('latin-1')) > > Guido wrote: > > At the cost of an extra copying step. > > I asked: > > ... why not just add some smarts to the bytes constructor? > > Guido wrote: > > > ... the VM usually keeps an extra reference > > on the stack so the refcount is never 1. But > > you can't rely on that > > I did miss this, but _PyString_Resize seems to > work around it, and I'm not sure that the bytes > object can't be just as intimate.
No, _PyString_Resize doesn't work around it. _PyString_Resize only works if the refcount is exactly one: only the caller has a reference. And by 'caller', I mean 'the calling C function'. Besides that, the caller takes care to only use _PyString_Resize on strings it created itself. Theoretically it could 'steal' a reference from someplace else, but I haven't seen _PyString_Resize-using code do that, and it would be a recipe for disaster. -- Thomas Wouters <[EMAIL PROTECTED]> Hi! I'm a .signature virus! copy me into your .signature file to help me spread! _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com