Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Do not use PyInterpreterState_GetIDObject() in _xxinterpchannels module.
  • Loading branch information
ericsnowcurrently committed Mar 21, 2024
commit 2370c160178f51b753466cfe82038156d8d364b6
17 changes: 17 additions & 0 deletions Modules/_interpreters_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ clear_xid_class(PyTypeObject *cls)
return _PyCrossInterpreterData_UnregisterClass(cls);
}
#endif


#ifdef RETURNS_INTERPID_OBJECT
static PyObject *
get_interpid_obj(PyInterpreterState *interp)
{
if (_PyInterpreterState_IDInitref(interp) != 0) {
return NULL;
};
int64_t id = PyInterpreterState_GetID(interp);
if (id < 0) {
return NULL;
}
assert(id < LLONG_MAX);
return PyLong_FromLongLong(id);
}
#endif
5 changes: 3 additions & 2 deletions Modules/_xxinterpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#endif

#include "Python.h"
#include "interpreteridobject.h"
#include "pycore_crossinterp.h" // struct _xid
#include "pycore_interp.h" // _PyInterpreterState_LookUpID()

Expand All @@ -18,7 +17,9 @@
#endif

#define REGISTERS_HEAP_TYPES
#define RETURNS_INTERPID_OBJECT
#include "_interpreters_common.h"
#undef RETURNS_INTERPID_OBJECT
#undef REGISTERS_HEAP_TYPES


Expand Down Expand Up @@ -2908,7 +2909,7 @@ channelsmod_list_interpreters(PyObject *self, PyObject *args, PyObject *kwds)
goto except;
}
if (res) {
interpid_obj = PyInterpreterState_GetIDObject(interp);
interpid_obj = get_interpid_obj(interp);
if (interpid_obj == NULL) {
goto except;
}
Expand Down
17 changes: 2 additions & 15 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
#include "pycore_pyerrors.h" // _Py_excinfo
#include "pycore_pystate.h" // _PyInterpreterState_SetRunningMain()

#include "interpreteridobject.h"
#include "marshal.h" // PyMarshal_ReadObjectFromString()

#define RETURNS_INTERPID_OBJECT
#include "_interpreters_common.h"
#undef RETURNS_INTERPID_OBJECT


#define MODULE_NAME _xxsubinterpreters
Expand All @@ -38,20 +39,6 @@ _get_current_interp(void)
#define look_up_interp _PyInterpreterState_LookUpIDObject


static PyObject *
get_interpid_obj(PyInterpreterState *interp)
{
if (_PyInterpreterState_IDInitref(interp) != 0) {
return NULL;
};
int64_t id = PyInterpreterState_GetID(interp);
if (id < 0) {
return NULL;
}
assert(id < LLONG_MAX);
return PyLong_FromLongLong(id);
}

static PyObject *
_get_current_module(void)
{
Expand Down