]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 6 Nov 2013 21:36:40 +0000 (22:36 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 6 Nov 2013 21:36:40 +0000 (22:36 +0100)
Include/sysmodule.h
Python/sysmodule.c

index 0cabf6fee7fd2af7772e6adc8c8c1f8c94f600a2..925c2a34f47656ce75d48fd99ef761fe6151cbbc 100644 (file)
@@ -8,7 +8,10 @@ extern "C" {
 #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 *);
index b8cf31d435134f0ed39850407b2ecd6859d4e4b9..32136e844f412eb437cf343d917c634979186e97 100644 (file)
@@ -41,6 +41,16 @@ extern const char *PyWin_DLLVersionString;
 #include <langinfo.h>
 #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)
 {
@@ -51,6 +61,21 @@ PySys_GetObject(const char *name)
     return PyDict_GetItemString(sd, name);
 }
 
+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)
 {