Change sys.intern() so that unicode strings can be

interned too. Add a test for this.
This commit is contained in:
Walter Dörwald 2007-06-05 20:22:04 +00:00
parent 360b01a663
commit 2a0c081470
2 changed files with 25 additions and 7 deletions

View file

@ -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,