Skip to content

Commit 18b1fde

Browse files
authored
gh-106320: Remove _PyInterpreterState_Get() alias (#106321)
Replace calls to the (removed) slow _PyInterpreterState_Get() with fast inlined _PyInterpreterState_GET() function.
1 parent 0530f4f commit 18b1fde

File tree

11 files changed

+29
-22
lines changed

11 files changed

+29
-22
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,10 @@ Removed
605605

606606
* Remove ``cpython/pytime.h`` header file: it only contained private functions.
607607
(Contributed by Victor Stinner in :gh:`106316`.)
608+
609+
* Remove ``_PyInterpreterState_Get()`` alias to
610+
:c:func:`PyInterpreterState_Get()` which was kept for backward compatibility
611+
with Python 3.8. The `pythoncapi-compat project
612+
<https://github.com/python/pythoncapi-compat/>`__ can be used to get
613+
:c:func:`PyInterpreterState_Get()` on Python 3.8 and older.
614+
(Contributed by Victor Stinner in :gh:`106320`.)

Include/cpython/pystate.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ struct _ts {
261261

262262
/* other API */
263263

264-
// Alias for backward compatibility with Python 3.8
265-
#define _PyInterpreterState_Get PyInterpreterState_Get
266-
267264
/* An alias for the internal _PyThreadState_New(),
268265
kept for stable ABI compatibility. */
269266
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
@@ -295,7 +292,7 @@ PyAPI_FUNC(int) PyGILState_Check(void);
295292
This function doesn't check for error. Return NULL before _PyGILState_Init()
296293
is called and after _PyGILState_Fini() is called.
297294
298-
See also _PyInterpreterState_Get() and _PyInterpreterState_GET(). */
295+
See also PyInterpreterState_Get() and _PyInterpreterState_GET(). */
299296
PyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void);
300297

301298
/* The implementation of sys._current_frames() Returns a dict mapping

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
108108
109109
The caller must hold the GIL.
110110
111-
See also _PyInterpreterState_Get()
111+
See also PyInterpreterState_Get()
112112
and _PyGILState_GetInterpreterStateUnsafe(). */
113113
static inline PyInterpreterState* _PyInterpreterState_GET(void) {
114114
PyThreadState *tstate = _PyThreadState_GET();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove ``_PyInterpreterState_Get()`` alias to
2+
:c:func:`PyInterpreterState_Get()` which was kept for backward compatibility
3+
with Python 3.8. Patch by Victor Stinner.

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ thread_run(void *boot_raw)
11041104
static PyObject *
11051105
thread_daemon_threads_allowed(PyObject *module, PyObject *Py_UNUSED(ignored))
11061106
{
1107-
PyInterpreterState *interp = _PyInterpreterState_Get();
1107+
PyInterpreterState *interp = _PyInterpreterState_GET();
11081108
if (interp->feature_flags & Py_RTFLAGS_DAEMON_THREADS) {
11091109
Py_RETURN_TRUE;
11101110
}

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6362,7 +6362,7 @@ object___reduce_ex___impl(PyObject *self, int protocol)
63626362
/*[clinic end generated code: output=2e157766f6b50094 input=f326b43fb8a4c5ff]*/
63636363
{
63646364
#define objreduce \
6365-
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_Get(), objreduce))
6365+
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_GET(), objreduce))
63666366
PyObject *reduce, *res;
63676367

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

96909690
/* pname and ptrs act as a little cache */
9691-
PyInterpreterState *interp = _PyInterpreterState_Get();
9691+
PyInterpreterState *interp = _PyInterpreterState_GET();
96929692
#define pname _Py_INTERP_CACHED_OBJECT(interp, type_slots_pname)
96939693
#define ptrs _Py_INTERP_CACHED_OBJECT(interp, type_slots_ptrs)
96949694
pytype_slotdef *p, **pp;

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5831,7 +5831,7 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s,
58315831
PyObject *errorHandler = NULL;
58325832
PyObject *exc = NULL;
58335833
_PyUnicode_Name_CAPI *ucnhash_capi;
5834-
PyInterpreterState *interp = _PyInterpreterState_Get();
5834+
PyInterpreterState *interp = _PyInterpreterState_GET();
58355835

58365836
// so we can remember if we've seen an invalid escape char or not
58375837
*first_invalid_escape = NULL;

Python/ceval_gil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,15 @@ take_gil(PyThreadState *tstate)
491491

492492
void _PyEval_SetSwitchInterval(unsigned long microseconds)
493493
{
494-
PyInterpreterState *interp = _PyInterpreterState_Get();
494+
PyInterpreterState *interp = _PyInterpreterState_GET();
495495
struct _gil_runtime_state *gil = interp->ceval.gil;
496496
assert(gil != NULL);
497497
gil->interval = microseconds;
498498
}
499499

500500
unsigned long _PyEval_GetSwitchInterval(void)
501501
{
502-
PyInterpreterState *interp = _PyInterpreterState_Get();
502+
PyInterpreterState *interp = _PyInterpreterState_GET();
503503
struct _gil_runtime_state *gil = interp->ceval.gil;
504504
assert(gil != NULL);
505505
return gil->interval;

Python/hamt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,7 @@ hamt_alloc(void)
24252425
}
24262426

24272427
#define _empty_hamt \
2428-
(&_Py_INTERP_SINGLETON(_PyInterpreterState_Get(), hamt_empty))
2428+
(&_Py_INTERP_SINGLETON(_PyInterpreterState_GET(), hamt_empty))
24292429

24302430
PyHamtObject *
24312431
_PyHamt_New(void)

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ check_multi_interp_extensions(PyInterpreterState *interp)
11231123
int
11241124
_PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
11251125
{
1126-
PyInterpreterState *interp = _PyInterpreterState_Get();
1126+
PyInterpreterState *interp = _PyInterpreterState_GET();
11271127
if (check_multi_interp_extensions(interp)) {
11281128
assert(!_Py_IsMainInterpreter(interp));
11291129
PyErr_Format(PyExc_ImportError,

0 commit comments

Comments
 (0)