[Python-checkins] python/dist/src/Objects stringobject.c, 2.224, 2.225

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Aug 24 01:23:57 CEST 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20193/Objects

Modified Files:
	stringobject.c 
Log Message:
SF Patch #1007087:  Return new string for single subclass joins (Bug #1001011)
(Patch contributed by Nick Coghlan.)

Now joining string subtypes will always return a string.
Formerly, if there were only one item, it was returned unchanged.



Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.224
retrieving revision 2.225
diff -u -d -r2.224 -r2.225
--- stringobject.c	7 Aug 2004 20:58:32 -0000	2.224
+++ stringobject.c	23 Aug 2004 23:23:54 -0000	2.225
@@ -1618,22 +1618,18 @@
 	}
 	if (seqlen == 1) {
 		item = PySequence_Fast_GET_ITEM(seq, 0);
-		if (!PyString_Check(item) && !PyUnicode_Check(item)) {
-			PyErr_Format(PyExc_TypeError,
-				     "sequence item 0: expected string,"
-				     " %.80s found",
-				     item->ob_type->tp_name);
+		if (PyString_CheckExact(item) || PyUnicode_CheckExact(item)) {
+			Py_INCREF(item);
 			Py_DECREF(seq);
-			return NULL;
+			return item;
 		}
-		Py_INCREF(item);
-		Py_DECREF(seq);
-		return item;
 	}
 
-	/* There are at least two things to join.  Do a pre-pass to figure out
-	 * the total amount of space we'll need (sz), see whether any argument
-	 * is absurd, and defer to the Unicode join if appropriate.
+	/* There are at least two things to join, or else we have a subclass
+	 * of the builtin types in the sequence.  
+	 * Do a pre-pass to figure out the total amount of space we'll
+	 * need (sz), see whether any argument is absurd, and defer to
+	 * the Unicode join if appropriate.
 	 */
 	for (i = 0; i < seqlen; i++) {
 		const size_t old_sz = sz;



More information about the Python-checkins mailing list