Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 86971:5e402c16a74c
Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Wed, 06 Nov 2013 22:36:40 +0100 |
| parents | a2f42d57b91d |
| children | 954167ce92a3 |
line wrap: on
line diff
--- a/Python/sysmodule.c Wed Nov 06 19:03:11 2013 +0100 +++ b/Python/sysmodule.c Wed Nov 06 22:36:40 2013 +0100 @@ -42,6 +42,16 @@ #endif PyObject * +_PySys_GetObjectId(_Py_Identifier *key) +{ + PyThreadState *tstate = PyThreadState_GET(); + PyObject *sd = tstate->interp->sysdict; + if (sd == NULL) + return NULL; + return _PyDict_GetItemId(sd, key); +} + +PyObject * PySys_GetObject(const char *name) { PyThreadState *tstate = PyThreadState_GET(); @@ -52,6 +62,21 @@ } int +_PySys_SetObjectId(_Py_Identifier *key, PyObject *v) +{ + PyThreadState *tstate = PyThreadState_GET(); + PyObject *sd = tstate->interp->sysdict; + if (v == NULL) { + if (_PyDict_GetItemId(sd, key) == NULL) + return 0; + else + return _PyDict_DelItemId(sd, key); + } + else + return _PyDict_SetItemId(sd, key, v); +} + +int PySys_SetObject(const char *name, PyObject *v) { PyThreadState *tstate = PyThreadState_GET();
