gh-76785: Add More Tests to test_interpreters.test_api (gh-117662) · python/cpython@993c3cc · GitHub
Skip to content

Commit 993c3cc

Browse files
gh-76785: Add More Tests to test_interpreters.test_api (gh-117662)
In addition to the increase test coverage, this is a precursor to sorting out how we handle interpreters created directly via the C-API.
1 parent 0cc71bd commit 993c3cc

18 files changed

Lines changed: 2012 additions & 418 deletions

Include/internal/pycore_crossinterp.h

Lines changed: 20 additions & 0 deletions

Include/internal/pycore_interp.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,22 @@ struct _is {
103103
int requires_idref;
104104
PyThread_type_lock id_mutex;
105105

106+
#define _PyInterpreterState_WHENCE_NOTSET -1
107+
#define _PyInterpreterState_WHENCE_UNKNOWN 0
108+
#define _PyInterpreterState_WHENCE_RUNTIME 1
109+
#define _PyInterpreterState_WHENCE_LEGACY_CAPI 2
110+
#define _PyInterpreterState_WHENCE_CAPI 3
111+
#define _PyInterpreterState_WHENCE_XI 4
112+
#define _PyInterpreterState_WHENCE_MAX 4
113+
long _whence;
114+
106115
/* Has been initialized to a safe state.
107116
108117
In order to be effective, this must be set to 0 during or right
109118
after allocation. */
110119
int _initialized;
120+
/* Has been fully initialized via pylifecycle.c. */
121+
int _ready;
111122
int finalizing;
112123

113124
uintptr_t last_restart_version;
@@ -305,6 +316,11 @@ PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
305316
PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
306317
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
307318

319+
PyAPI_FUNC(long) _PyInterpreterState_GetWhence(PyInterpreterState *interp);
320+
extern void _PyInterpreterState_SetWhence(
321+
PyInterpreterState *interp,
322+
long whence);
323+
308324
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
309325

310326
// Get a copy of the current interpreter configuration.

Include/internal/pycore_pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp)
7777
interp == &_PyRuntime._main_interpreter);
7878
}
7979

80+
// Export for _xxsubinterpreters module.
81+
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
82+
8083
// Export for _xxsubinterpreters module.
8184
PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *);
8285
PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *);

Include/internal/pycore_runtime_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ extern PyTypeObject _PyExc_MemoryError;
162162
#define _PyInterpreterState_INIT(INTERP) \
163163
{ \
164164
.id_refcount = -1, \
165+
._whence = _PyInterpreterState_WHENCE_NOTSET, \
165166
.imports = IMPORTS_INIT, \
166167
.ceval = { \
167168
.recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \

Lib/test/support/interpreters/__init__.py

Lines changed: 4 additions & 3 deletions

0 commit comments

Comments
 (0)