summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 19:20:05 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 19:20:05 +0000
commit68afd55ea92823228709cf9b48795959a01715f9 (patch)
tree1a3e6f4122e9a7d4fc954a5438957ef4f33b4ae8 /Python
parente4262f146805f1373d21dea41f12980294eff9fc (diff)
downloadcpython-68afd55ea92823228709cf9b48795959a01715f9.tar.gz
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 8ff733c4d8..04fcf597b1 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1035,6 +1035,11 @@ builtin_intern(PyObject *self, PyObject *args)
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;