[Python-checkins] r68448 - sandbox/trunk/io-c/_textio.c

antoine.pitrou python-checkins at python.org
Fri Jan 9 13:05:09 CET 2009


Author: antoine.pitrou
Date: Fri Jan  9 13:05:09 2009
New Revision: 68448

Log:
Be sure we really unshare 1-char strings (better safe than sorry)



Modified:
   sandbox/trunk/io-c/_textio.c

Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c	(original)
+++ sandbox/trunk/io-c/_textio.c	Fri Jan  9 13:05:09 2009
@@ -225,7 +225,9 @@
             PyObject *translated = NULL;
             Py_UNICODE *out_str;
             Py_ssize_t out;
-            if (Py_REFCNT(output) != 1) {
+            /* 1-character strings may be shared, and we may be the first
+               to receive a reference (although unlikely). */
+            if (Py_REFCNT(output) != 1 || len < 2) {
                 /* We could try to optimize this so that we only do a copy
                    when there is something to translate. On the other hand,
                    most decoders should only output non-shared strings, i.e.


More information about the Python-checkins mailing list