[Python-checkins] cpython: Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions

victor.stinner python-checkins at python.org
Wed Nov 6 22:46:26 CET 2013


http://hg.python.org/cpython/rev/5e402c16a74c
changeset:   86971:5e402c16a74c
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Nov 06 22:36:40 2013 +0100
summary:
  Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions

files:
  Include/sysmodule.h |   3 +++
  Python/sysmodule.c  |  25 +++++++++++++++++++++++++
  2 files changed, 28 insertions(+), 0 deletions(-)


diff --git a/Include/sysmodule.h b/Include/sysmodule.h
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -8,7 +8,10 @@
 #endif
 
 PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
+PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key);
 PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
+PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *);
+
 PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
 PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
 PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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();

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list