summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-06-05 20:22:04 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-06-05 20:22:04 (GMT)
commit2a0c081470cc652c35d3bf60f77734d407832136 (patch)
treeafb0545d68679c9c3f96840f8ccbbe2b3142dda8 /Python
parent360b01a6630e0d129ef0f00ddae1a9d054f9d8d5 (diff)
downloadcpython-2a0c081470cc652c35d3bf60f77734d407832136.zip
cpython-2a0c081470cc652c35d3bf60f77734d407832136.tar.gz
cpython-2a0c081470cc652c35d3bf60f77734d407832136.tar.bz2
Change sys.intern() so that unicode strings can be
interned too. Add a test for this.
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 1756834..a8bb918 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -266,14 +266,21 @@ sys_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");
+ if (PyString_CheckExact(s)) {
+ Py_INCREF(s);
+ PyString_InternInPlace(&s);
+ return s;
+ }
+ else if (PyUnicode_CheckExact(s)) {
+ Py_INCREF(s);
+ PyUnicode_InternInPlace(&s);
+ return s;
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "can't intern %.400s", s->ob_type->tp_name);
return NULL;
}
- Py_INCREF(s);
- PyString_InternInPlace(&s);
- return s;
}
PyDoc_STRVAR(intern_doc,