diff Objects/stringlib/string_format.h @ 45391:3fc586307d66 legacy-trunk

Added code to correct combining str and unicode in ''.format(). Added test case.
author Eric Smith <eric@trueblade.com>
date Mon, 18 Feb 2008 18:02:34 +0000
parents b7231bf6bfb7
children a77e1cf7ed25
line wrap: on
line diff
--- a/Objects/stringlib/string_format.h	Mon Feb 18 17:40:47 2008 +0000
+++ b/Objects/stringlib/string_format.h	Mon Feb 18 18:02:34 2008 +0000
@@ -493,6 +493,22 @@
     if (result == NULL)
         goto done;
 
+#if PY_VERSION_HEX >= 0x03000000
+    assert(PyString_Check(result));
+#else
+    assert(PyString_Check(result) || PyUnicode_Check(result));
+
+    /* Convert result to our type.  We could be str, and result could
+       be unicode */
+    {
+	PyObject *tmp = STRINGLIB_TOSTR(result);
+	if (tmp == NULL)
+	    goto done;
+	Py_DECREF(result);
+	result = tmp;
+    }
+#endif
+
     ok = output_data(output,
                      STRINGLIB_STR(result), STRINGLIB_LEN(result));
 done: