Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 86970:e5476ecb8b57 | 86971:5e402c16a74c |
|---|---|
| 40 #include <locale.h> | 40 #include <locale.h> |
| 41 #include <langinfo.h> | 41 #include <langinfo.h> |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 PyObject * | 44 PyObject * |
| 45 PySys_GetObject(const char *name) | 45 _PySys_GetObjectId(_Py_Identifier *key) |
| 46 { | 46 { |
| 47 PyThreadState *tstate = PyThreadState_GET(); | 47 PyThreadState *tstate = PyThreadState_GET(); |
| 48 PyObject *sd = tstate->interp->sysdict; | 48 PyObject *sd = tstate->interp->sysdict; |
| 49 if (sd == NULL) | 49 if (sd == NULL) |
| 50 return NULL; | 50 return NULL; |
| 51 return _PyDict_GetItemId(sd, key); | |
| 52 } | |
| 53 | |
| 54 PyObject * | |
| 55 PySys_GetObject(const char *name) | |
| 56 { | |
| 57 PyThreadState *tstate = PyThreadState_GET(); | |
| 58 PyObject *sd = tstate->interp->sysdict; | |
| 59 if (sd == NULL) | |
| 60 return NULL; | |
| 51 return PyDict_GetItemString(sd, name); | 61 return PyDict_GetItemString(sd, name); |
| 62 } | |
| 63 | |
| 64 int | |
| 65 _PySys_SetObjectId(_Py_Identifier *key, PyObject *v) | |
| 66 { | |
| 67 PyThreadState *tstate = PyThreadState_GET(); | |
| 68 PyObject *sd = tstate->interp->sysdict; | |
| 69 if (v == NULL) { | |
| 70 if (_PyDict_GetItemId(sd, key) == NULL) | |
| 71 return 0; | |
| 72 else | |
| 73 return _PyDict_DelItemId(sd, key); | |
| 74 } | |
| 75 else | |
| 76 return _PyDict_SetItemId(sd, key, v); | |
| 52 } | 77 } |
| 53 | 78 |
| 54 int | 79 int |
| 55 PySys_SetObject(const char *name, PyObject *v) | 80 PySys_SetObject(const char *name, PyObject *v) |
| 56 { | 81 { |
