diff Python/bltinmodule.c @ 33019:5218bff56449 legacy-trunk

Subclasses of string can no longer be interned. The semantics of interning were not clear here -- a subclass could be mutable, for example -- and had bugs. Explicitly interning a subclass of string via intern() will raise a TypeError. Internal operations that attempt to intern a string subclass will have no effect. Added a few tests to test_builtin that includes the old buggy code and verifies that calls like PyObject_SetAttr() don't fail. Perhaps these tests should have gone in test_string.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Sat, 07 Aug 2004 19:20:05 +0000
parents a75815e31545
children ce016d0ec701
line wrap: on
line diff
--- a/Python/bltinmodule.c	Sat Aug 07 19:16:32 2004 +0000
+++ b/Python/bltinmodule.c	Sat Aug 07 19:20:05 2004 +0000
@@ -1035,6 +1035,11 @@
 	PyObject *s;
 	if (!PyArg_ParseTuple(args, "S:intern", &s))
 		return NULL;
+	if (!PyString_CheckExact(s)) {
+		PyErr_SetString(PyExc_TypeError,
+				"can't intern subclass of string");
+		return NULL;
+	}
 	Py_INCREF(s);
 	PyString_InternInPlace(&s);
 	return s;