Skip to content

Commit d67bd45

Browse files
committed
Issue python#19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions
1 parent b44562b commit d67bd45

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Include/sysmodule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ extern "C" {
88
#endif
99

1010
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
11+
PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key);
1112
PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
13+
PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *);
14+
1215
PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
1316
PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
1417
PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);

Python/sysmodule.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ extern const char *PyWin_DLLVersionString;
4141
#include <langinfo.h>
4242
#endif
4343

44+
PyObject *
45+
_PySys_GetObjectId(_Py_Identifier *key)
46+
{
47+
PyThreadState *tstate = PyThreadState_GET();
48+
PyObject *sd = tstate->interp->sysdict;
49+
if (sd == NULL)
50+
return NULL;
51+
return _PyDict_GetItemId(sd, key);
52+
}
53+
4454
PyObject *
4555
PySys_GetObject(const char *name)
4656
{
@@ -51,6 +61,21 @@ PySys_GetObject(const char *name)
5161
return PyDict_GetItemString(sd, name);
5262
}
5363

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);
77+
}
78+
5479
int
5580
PySys_SetObject(const char *name, PyObject *v)
5681
{

0 commit comments

Comments
 (0)