summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-06-05 20:22:04 +0000
committerWalter Dörwald <walter@livinglogic.de>2007-06-05 20:22:04 +0000
commit446b194d475c6cf010eeb337dba01619d0588c30 (patch)
treebc5d0e6b4e334cfcdc71054076ab52baa440e214 /Python/sysmodule.c
parentcf22627fff4555981400f83d0bd52f3518b524e3 (diff)
downloadcpython-446b194d475c6cf010eeb337dba01619d0588c30.tar.gz
Change sys.intern() so that unicode strings can be
interned too. Add a test for this.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 17568349d5..a8bb918f5a 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,