[Python-Dev] The Trick

Alex Martelli aleaxit at yahoo.com
Sat Oct 18 16:15:28 EDT 2003


On Saturday 18 October 2003 08:00 pm, Kevin Jacobs wrote:
> On Sat, 18 Oct 2003, Guido van Rossum wrote:
> > I don't like the trick of avoiding the copy if the refcount is one;
> > AFAIK it can't be done in Jython.
>
> There is also a problem with the strategy if if gets called by a C
> extension.  It is perfectly feasible for a C extension to hold the only
> reference to an object, call the copying sort (directly or indirectly), and
> then be very surprised that the copy did not take place.

Alas, I fear you're right.  Darn -- so much for a possible little but
cheap optimization (which might have been neat in PySequence_List
even if copysort never happens and the optimization is only for
CPython -- I don't see why an optimization being impossible in
Jython should stop CPython from making it, as long as semantics
remain compatible).  It's certainly possible for C code to call
PySequence_List or whatever while holding the only reference,
and count on the returned and argument objects being distinct:-(.


Alex




More information about the Python-Dev mailing list