]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Port 60893 to py3k, without unicode test.
authorEric Smith <eric@trueblade.com>
Mon, 18 Feb 2008 18:07:47 +0000 (18:07 +0000)
committerEric Smith <eric@trueblade.com>
Mon, 18 Feb 2008 18:07:47 +0000 (18:07 +0000)
Objects/stringlib/string_format.h

index 70f8f13aea22006236435412dec6b4655a130835..e7762429a772ecf9f557af8928161bedaa703ece 100644 (file)
@@ -493,6 +493,22 @@ render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
     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: