[Patches] [ python-Patches-1007087 ] Return new string for single subclass joins (Bug #1001011)

SourceForge.net noreply at sourceforge.net
Tue Aug 24 01:26:54 CEST 2004


Patches item #1007087, was opened at 2004-08-11 03:03
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1007087&group_id=5470

Category: Core (C code)
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nick Coghlan (ncoghlan)
Assigned to: Nobody/Anonymous (nobody)
Summary: Return new string for single subclass joins (Bug #1001011)

Initial Comment:
At present, str.join contains a shortcut that returns a
reference to the existing string for a sequence that
contains a single item.

This can cause misbehaviour when subclasses of str are
involved (see the bug report for details).

The attached patch removes the shortcut, and adds a
test for the correct behaviour.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-23 18:26

Message:
Logged In: YES 
user_id=80475

Applied as:
   Objects/stringobject.c 2.225
   Lib/test/test_string.py 1.26

Thanks for the perfect patch.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-08-19 17:28

Message:
Logged In: YES 
user_id=31435

Unassigned myself -- can't make time for this now.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-19 17:17

Message:
Logged In: YES 
user_id=80475

The patch looks good, it compiles okay, and the test_suite
passes.

If Tim has no further issues, I will apply it.

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-11 17:53

Message:
Logged In: YES 
user_id=1038590

Oh - the test looks explicitly for the optimised behaviour
for a true string (to make sure this version preserved that
behaviour). Is that a good idea, or not?

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-11 17:52

Message:
Logged In: YES 
user_id=1038590

New version of patch attached which uses PyString_CheckExact
and PyUnicode_CheckExact to determine when the optimisation
is safe, and falls through to the general case when it isn't.

Should this optimisation be applied to the unicode join as well?

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-11 17:17

Message:
Logged In: YES 
user_id=1038590

OK. I think I can do something with PyString_CheckExact that
will do what you'd prefer.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-08-11 07:52

Message:
Logged In: YES 
user_id=31435

This is an important optimization for "true strings".  It was 
indeed the intent that internal optimization for immutable 
types not be applied to subclass instances, so it's good to fix 
that.  It's not good to lose the optimization when it's safe.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1007087&group_id=5470


More information about the Patches mailing list