Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 40472:9548ca0e6560 | 40484:8565e3fea9b6 |
|---|---|
| 261 Return the encoding used to convert Unicode filenames in\n\ | 261 Return the encoding used to convert Unicode filenames in\n\ |
| 262 operating system filenames." | 262 operating system filenames." |
| 263 ); | 263 ); |
| 264 | 264 |
| 265 #endif | 265 #endif |
| 266 | |
| 267 | |
| 268 static PyObject * | |
| 269 sys_intern(PyObject *self, PyObject *args) | |
| 270 { | |
| 271 PyObject *s; | |
| 272 if (!PyArg_ParseTuple(args, "S:intern", &s)) | |
| 273 return NULL; | |
| 274 if (!PyString_CheckExact(s)) { | |
| 275 PyErr_SetString(PyExc_TypeError, | |
| 276 "can't intern subclass of string"); | |
| 277 return NULL; | |
| 278 } | |
| 279 Py_INCREF(s); | |
| 280 PyString_InternInPlace(&s); | |
| 281 return s; | |
| 282 } | |
| 283 | |
| 284 PyDoc_STRVAR(intern_doc, | |
| 285 "intern(string) -> string\n\ | |
| 286 \n\ | |
| 287 ``Intern'' the given string. This enters the string in the (global)\n\ | |
| 288 table of interned strings whose purpose is to speed up dictionary lookups.\n\ | |
| 289 Return the string itself or the previously interned string object with the\n\ | |
| 290 same value."); | |
| 291 | |
| 266 | 292 |
| 267 /* | 293 /* |
| 268 * Cached interned string objects used for calling the profile and | 294 * Cached interned string objects used for calling the profile and |
| 269 * trace functions. Initialized by trace_init(). | 295 * trace functions. Initialized by trace_init(). |
| 270 */ | 296 */ |
| 770 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, | 796 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, |
| 771 #ifdef MS_WINDOWS | 797 #ifdef MS_WINDOWS |
| 772 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, | 798 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, |
| 773 getwindowsversion_doc}, | 799 getwindowsversion_doc}, |
| 774 #endif /* MS_WINDOWS */ | 800 #endif /* MS_WINDOWS */ |
| 801 {"intern", sys_intern, METH_VARARGS, intern_doc}, | |
| 775 #ifdef USE_MALLOPT | 802 #ifdef USE_MALLOPT |
| 776 {"mdebug", sys_mdebug, METH_VARARGS}, | 803 {"mdebug", sys_mdebug, METH_VARARGS}, |
| 777 #endif | 804 #endif |
| 778 #ifdef Py_USING_UNICODE | 805 #ifdef Py_USING_UNICODE |
| 779 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS, | 806 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS, |
