Skip to content

gh-106320: Remove _PyInterpreterState_Get() alias #106321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,10 @@ Removed

* Remove ``cpython/pytime.h`` header file: it only contained private functions.
(Contributed by Victor Stinner in :gh:`106316`.)

* Remove ``_PyInterpreterState_Get()`` alias to
:c:func:`PyInterpreterState_Get()` which was kept for backward compatibility
with Python 3.8. The `pythoncapi-compat project
<https://github.com/python/pythoncapi-compat/>`__ can be used to get
:c:func:`PyInterpreterState_Get()` on Python 3.8 and older.
(Contributed by Victor Stinner in :gh:`106320`.)
5 changes: 1 addition & 4 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ struct _ts {

/* other API */

// Alias for backward compatibility with Python 3.8
#define _PyInterpreterState_Get PyInterpreterState_Get

/* An alias for the internal _PyThreadState_New(),
kept for stable ABI compatibility. */
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
Expand Down Expand Up @@ -295,7 +292,7 @@ PyAPI_FUNC(int) PyGILState_Check(void);
This function doesn't check for error. Return NULL before _PyGILState_Init()
is called and after _PyGILState_Fini() is called.

See also _PyInterpreterState_Get() and _PyInterpreterState_GET(). */
See also PyInterpreterState_Get() and _PyInterpreterState_GET(). */
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);

/* The implementation of sys._current_frames() Returns a dict mapping
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)

The caller must hold the GIL.

See also _PyInterpreterState_Get()
See also PyInterpreterState_Get()
and _PyGILState_GetInterpreterStateUnsafe(). */
static inline PyInterpreterState* _PyInterpreterState_GET(void) {
PyThreadState *tstate = _PyThreadState_GET();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove ``_PyInterpreterState_Get()`` alias to
:c:func:`PyInterpreterState_Get()` which was kept for backward compatibility
with Python 3.8. Patch by Victor Stinner.
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ thread_run(void *boot_raw)
static PyObject *
thread_daemon_threads_allowed(PyObject *module, PyObject *Py_UNUSED(ignored))
{
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->feature_flags & Py_RTFLAGS_DAEMON_THREADS) {
Py_RETURN_TRUE;
}
Expand Down
4 changes: 2 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6362,7 +6362,7 @@ object___reduce_ex___impl(PyObject *self, int protocol)
/*[clinic end generated code: output=2e157766f6b50094 input=f326b43fb8a4c5ff]*/
{
#define objreduce \
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_Get(), objreduce))
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_GET(), objreduce))
PyObject *reduce, *res;

if (objreduce == NULL) {
Expand Down Expand Up @@ -9688,7 +9688,7 @@ resolve_slotdups(PyTypeObject *type, PyObject *name)
/* XXX Maybe this could be optimized more -- but is it worth it? */

/* pname and ptrs act as a little cache */
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
#define pname _Py_INTERP_CACHED_OBJECT(interp, type_slots_pname)
#define ptrs _Py_INTERP_CACHED_OBJECT(interp, type_slots_ptrs)
pytype_slotdef *p, **pp;
Expand Down
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5831,7 +5831,7 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
_PyUnicode_Name_CAPI *ucnhash_capi;
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();

// so we can remember if we've seen an invalid escape char or not
*first_invalid_escape = NULL;
Expand Down
4 changes: 2 additions & 2 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,15 @@ take_gil(PyThreadState *tstate)

void _PyEval_SetSwitchInterval(unsigned long microseconds)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _gil_runtime_state *gil = interp->ceval.gil;
assert(gil != NULL);
gil->interval = microseconds;
}

unsigned long _PyEval_GetSwitchInterval(void)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _gil_runtime_state *gil = interp->ceval.gil;
assert(gil != NULL);
return gil->interval;
Expand Down
2 changes: 1 addition & 1 deletion Python/hamt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ hamt_alloc(void)
}

#define _empty_hamt \
(&_Py_INTERP_SINGLETON(_PyInterpreterState_Get(), hamt_empty))
(&_Py_INTERP_SINGLETON(_PyInterpreterState_GET(), hamt_empty))

PyHamtObject *
_PyHamt_New(void)
Expand Down
2 changes: 1 addition & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ check_multi_interp_extensions(PyInterpreterState *interp)
int
_PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
{
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (check_multi_interp_extensions(interp)) {
assert(!_Py_IsMainInterpreter(interp));
PyErr_Format(PyExc_ImportError,
Expand Down
18 changes: 9 additions & 9 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ _Py_call_instrumentation_instruction(PyThreadState *tstate, _PyInterpreterFrame*
PyObject *
_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj)
{
PyInterpreterState *is = _PyInterpreterState_Get();
PyInterpreterState *is = _PyInterpreterState_GET();
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
assert(0 <= event_id && event_id < PY_MONITORING_EVENTS);
PyObject *callback = is->monitoring_callables[tool_id][event_id];
Expand Down Expand Up @@ -1678,7 +1678,7 @@ int
_PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
{
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
assert(events < (1 << PY_MONITORING_UNGROUPED_EVENTS));
if (check_tool(interp, tool_id)) {
return -1;
Expand All @@ -1696,7 +1696,7 @@ int
_PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet events)
{
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
assert(events < (1 << PY_MONITORING_UNGROUPED_EVENTS));
if (check_tool(interp, tool_id)) {
return -1;
Expand Down Expand Up @@ -1758,7 +1758,7 @@ monitoring_use_tool_id_impl(PyObject *module, int tool_id, PyObject *name)
PyErr_SetString(PyExc_ValueError, "tool name must be a str");
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->monitoring_tool_names[tool_id] != NULL) {
PyErr_Format(PyExc_ValueError, "tool %d is already in use", tool_id);
return NULL;
Expand All @@ -1782,7 +1782,7 @@ monitoring_free_tool_id_impl(PyObject *module, int tool_id)
if (check_valid_tool(tool_id)) {
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
Py_CLEAR(interp->monitoring_tool_names[tool_id]);
Py_RETURN_NONE;
}
Expand All @@ -1804,7 +1804,7 @@ monitoring_get_tool_impl(PyObject *module, int tool_id)
if (check_valid_tool(tool_id)) {
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *name = interp->monitoring_tool_names[tool_id];
if (name == NULL) {
Py_RETURN_NONE;
Expand Down Expand Up @@ -1865,7 +1865,7 @@ monitoring_get_events_impl(PyObject *module, int tool_id)
if (check_valid_tool(tool_id)) {
return -1;
}
_Py_Monitors *m = &_PyInterpreterState_Get()->monitors;
_Py_Monitors *m = &_PyInterpreterState_GET()->monitors;
_PyMonitoringEventSet event_set = get_events(m, tool_id);
return event_set;
}
Expand Down Expand Up @@ -1990,7 +1990,7 @@ monitoring_restart_events_impl(PyObject *module)
* last restart version > instrumented version for all code objects
* last restart version < current version
*/
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
interp->last_restart_version = interp->monitoring_version + 1;
interp->monitoring_version = interp->last_restart_version + 1;
if (instrument_all_executing_code_objects(interp)) {
Expand Down Expand Up @@ -2038,7 +2038,7 @@ static PyObject *
monitoring__all_events_impl(PyObject *module)
/*[clinic end generated code: output=6b7581e2dbb690f6 input=62ee9672c17b7f0e]*/
{
PyInterpreterState *interp = _PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *res = PyDict_New();
if (res == NULL) {
return NULL;
Expand Down