diff Objects/object.c @ 19846:662e22f99639 legacy-trunk

More on SF bug [#460020] bug or feature: unicode() and subclasses. Repaired str(i) to return a genuine string when i is an instance of a str subclass. New PyString_CheckExact() macro.
author Tim Peters <tim.peters@gmail.com>
date Tue, 11 Sep 2001 01:41:59 +0000
parents f44606b242c5
children f39a9be7c9af
line wrap: on
line diff
--- a/Objects/object.c	Mon Sep 10 23:53:53 2001 +0000
+++ b/Objects/object.c	Tue Sep 11 01:41:59 2001 +0000
@@ -250,10 +250,16 @@
 	
 	if (v == NULL)
 		return PyString_FromString("<NULL>");
-	if (PyString_Check(v)) {
+	if (PyString_CheckExact(v)) {
 		Py_INCREF(v);
 		return v;
 	}
+	if (PyString_Check(v)) {
+		/* For a string subtype that's not a string, return a true
+		   string with the same string data. */
+		PyStringObject *s = (PyStringObject *)v;
+		return PyString_FromStringAndSize(s->ob_sval, s->ob_size);
+	}
 	if (v->ob_type->tp_str == NULL)
 		return PyObject_Repr(v);