Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 40484:8565e3fea9b6
Patch #1601678: move intern() to sys.intern().
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 19 Dec 2006 20:50:34 +0000 |
| parents | cc992d75d5b3 |
| children | 6ebad2a6b990 |
line wrap: on
line diff
--- a/Python/sysmodule.c Tue Dec 19 08:30:14 2006 +0000 +++ b/Python/sysmodule.c Tue Dec 19 20:50:34 2006 +0000 @@ -264,6 +264,32 @@ #endif + +static PyObject * +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"); + return NULL; + } + Py_INCREF(s); + PyString_InternInPlace(&s); + return s; +} + +PyDoc_STRVAR(intern_doc, +"intern(string) -> string\n\ +\n\ +``Intern'' the given string. This enters the string in the (global)\n\ +table of interned strings whose purpose is to speed up dictionary lookups.\n\ +Return the string itself or the previously interned string object with the\n\ +same value."); + + /* * Cached interned string objects used for calling the profile and * trace functions. Initialized by trace_init(). @@ -772,6 +798,7 @@ {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, getwindowsversion_doc}, #endif /* MS_WINDOWS */ + {"intern", sys_intern, METH_VARARGS, intern_doc}, #ifdef USE_MALLOPT {"mdebug", sys_mdebug, METH_VARARGS}, #endif
