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
Prev Previous commit
Next Next commit
Restore PyInterpreterID_*() to the public API.
  • Loading branch information
ericsnowcurrently committed Jul 27, 2023
commit 3c1a0ff72b3f9ad825f03228f59448b64ac85a87
8 changes: 4 additions & 4 deletions Include/cpython/interpreteridobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/* Interpreter ID Object */

PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type;
PyAPI_DATA(PyTypeObject) PyInterpreterID_Type;

PyAPI_FUNC(PyObject *) _PyInterpreterID_New(int64_t);
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterID_LookUp(PyObject *);
PyAPI_FUNC(PyObject *) PyInterpreterID_New(int64_t);
PyAPI_FUNC(PyObject *) PyInterpreterState_GetIDObject(PyInterpreterState *);
PyAPI_FUNC(PyInterpreterState *) PyInterpreterID_LookUp(PyObject *);
4 changes: 2 additions & 2 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "pycore_pystate.h" // _PyThreadState_GET()

#include "frameobject.h"
#include "interpreteridobject.h" // _PyInterpreterID_LookUp()
#include "interpreteridobject.h" // PyInterpreterID_LookUp()
#include "osdefs.h" // MAXPATHLEN

#include "clinic/_testinternalcapi.c.h"
Expand Down Expand Up @@ -1083,7 +1083,7 @@ pending_identify(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O:pending_identify", &interpid)) {
return NULL;
}
PyInterpreterState *interp = _PyInterpreterID_LookUp(interpid);
PyInterpreterState *interp = PyInterpreterID_LookUp(interpid);
if (interp == NULL) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError, "interpreter not found");
Expand Down
2 changes: 1 addition & 1 deletion Modules/_xxinterpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ channel_list_interpreters(PyObject *self, PyObject *args, PyObject *kwds)
goto except;
}
if (res) {
id_obj = _PyInterpreterState_GetIDObject(interp);
id_obj = PyInterpreterState_GetIDObject(interp);
if (id_obj == NULL) {
goto except;
}
Expand Down
16 changes: 8 additions & 8 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
}
assert(tstate != NULL);
PyInterpreterState *interp = PyThreadState_GetInterpreter(tstate);
PyObject *idobj = _PyInterpreterState_GetIDObject(interp);
PyObject *idobj = PyInterpreterState_GetIDObject(interp);
if (idobj == NULL) {
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
Expand Down Expand Up @@ -560,7 +560,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
}

// Look up the interpreter.
PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
PyInterpreterState *interp = PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
Expand Down Expand Up @@ -615,7 +615,7 @@ interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))

interp = PyInterpreterState_Head();
while (interp != NULL) {
id = _PyInterpreterState_GetIDObject(interp);
id = PyInterpreterState_GetIDObject(interp);
if (id == NULL) {
Py_DECREF(ids);
return NULL;
Expand Down Expand Up @@ -647,7 +647,7 @@ interp_get_current(PyObject *self, PyObject *Py_UNUSED(ignored))
if (interp == NULL) {
return NULL;
}
return _PyInterpreterState_GetIDObject(interp);
return PyInterpreterState_GetIDObject(interp);
}

PyDoc_STRVAR(get_current_doc,
Expand All @@ -661,7 +661,7 @@ interp_get_main(PyObject *self, PyObject *Py_UNUSED(ignored))
{
// Currently, 0 is always the main interpreter.
int64_t id = 0;
return _PyInterpreterID_New(id);
return PyInterpreterID_New(id);
}

PyDoc_STRVAR(get_main_doc,
Expand All @@ -683,7 +683,7 @@ interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
}

// Look up the interpreter.
PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
PyInterpreterState *interp = PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
Expand Down Expand Up @@ -749,7 +749,7 @@ interp_is_running(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}

PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
PyInterpreterState *interp = PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
Expand Down Expand Up @@ -807,7 +807,7 @@ module_exec(PyObject *mod)
}

// PyInterpreterID
if (PyModule_AddType(mod, &_PyInterpreterID_Type) < 0) {
if (PyModule_AddType(mod, &PyInterpreterID_Type) < 0) {
goto error;
}

Expand Down
18 changes: 9 additions & 9 deletions Objects/interpreteridobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static int
interp_id_converter(PyObject *arg, void *ptr)
{
int64_t id;
if (PyObject_TypeCheck(arg, &_PyInterpreterID_Type)) {
if (PyObject_TypeCheck(arg, &PyInterpreterID_Type)) {
id = ((interpid *)arg)->id;
}
else if (_PyIndex_Check(arg)) {
Expand Down Expand Up @@ -183,13 +183,13 @@ interpid_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_NOTIMPLEMENTED;
}

if (!PyObject_TypeCheck(self, &_PyInterpreterID_Type)) {
if (!PyObject_TypeCheck(self, &PyInterpreterID_Type)) {
Py_RETURN_NOTIMPLEMENTED;
}

interpid *id = (interpid *)self;
int equal;
if (PyObject_TypeCheck(other, &_PyInterpreterID_Type)) {
if (PyObject_TypeCheck(other, &PyInterpreterID_Type)) {
interpid *otherid = (interpid *)other;
equal = (id->id == otherid->id);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ interpid_richcompare(PyObject *self, PyObject *other, int op)
PyDoc_STRVAR(interpid_doc,
"A interpreter ID identifies a interpreter and may be used as an int.");

PyTypeObject _PyInterpreterID_Type = {
PyTypeObject PyInterpreterID_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"InterpreterID", /* tp_name */
sizeof(interpid), /* tp_basicsize */
Expand Down Expand Up @@ -265,13 +265,13 @@ PyTypeObject _PyInterpreterID_Type = {
interpid_new, /* tp_new */
};

PyObject *_PyInterpreterID_New(int64_t id)
PyObject *PyInterpreterID_New(int64_t id)
{
return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0);
return (PyObject *)newinterpid(&PyInterpreterID_Type, id, 0);
}

PyObject *
_PyInterpreterState_GetIDObject(PyInterpreterState *interp)
PyInterpreterState_GetIDObject(PyInterpreterState *interp)
{
if (_PyInterpreterState_IDInitref(interp) != 0) {
return NULL;
Expand All @@ -280,11 +280,11 @@ _PyInterpreterState_GetIDObject(PyInterpreterState *interp)
if (id < 0) {
return NULL;
}
return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0);
return (PyObject *)newinterpid(&PyInterpreterID_Type, id, 0);
}

PyInterpreterState *
_PyInterpreterID_LookUp(PyObject *requested_id)
PyInterpreterID_LookUp(PyObject *requested_id)
{
int64_t id;
if (!interp_id_converter(requested_id, &id)) {
Expand Down
2 changes: 1 addition & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ static PyTypeObject* static_types[] = {
&PyGen_Type,
&PyGetSetDescr_Type,
&PyInstanceMethod_Type,
&PyInterpreterID_Type,
&PyListIter_Type,
&PyListRevIter_Type,
&PyList_Type,
Expand Down Expand Up @@ -2122,7 +2123,6 @@ static PyTypeObject* static_types[] = {
&_PyHamt_CollisionNode_Type,
&_PyHamt_Type,
&_PyLegacyEventHandler_Type,
&_PyInterpreterID_Type,
&_PyLineIterator,
&_PyManagedBuffer_Type,
&_PyMemoryIter_Type,
Expand Down