Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 41957:7015cccf29e3
Change sys.intern() so that unicode strings can be
interned too. Add a test for this.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Tue, 05 Jun 2007 20:22:04 +0000 |
| parents | b30c75d22f34 |
| children | 9d02a4adf574 |
line wrap: on
line diff
--- a/Python/sysmodule.c Tue Jun 05 20:15:52 2007 +0000 +++ b/Python/sysmodule.c Tue Jun 05 20:22:04 2007 +0000 @@ -266,14 +266,21 @@ 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,
