mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
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.
This commit is contained in:
parent
0cc71bde00
commit
993c3cca16
18 changed files with 2015 additions and 421 deletions
|
@ -583,6 +583,8 @@ free_interpreter(PyInterpreterState *interp)
|
|||
}
|
||||
}
|
||||
|
||||
static inline int check_interpreter_whence(long);
|
||||
|
||||
/* Get the interpreter state to a minimal consistent state.
|
||||
Further init happens in pylifecycle.c before it can be used.
|
||||
All fields not initialized here are expected to be zeroed out,
|
||||
|
@ -605,12 +607,17 @@ free_interpreter(PyInterpreterState *interp)
|
|||
static PyStatus
|
||||
init_interpreter(PyInterpreterState *interp,
|
||||
_PyRuntimeState *runtime, int64_t id,
|
||||
PyInterpreterState *next)
|
||||
PyInterpreterState *next,
|
||||
long whence)
|
||||
{
|
||||
if (interp->_initialized) {
|
||||
return _PyStatus_ERR("interpreter already initialized");
|
||||
}
|
||||
|
||||
assert(interp->_whence == _PyInterpreterState_WHENCE_NOTSET);
|
||||
assert(check_interpreter_whence(whence) == 0);
|
||||
interp->_whence = whence;
|
||||
|
||||
assert(runtime != NULL);
|
||||
interp->runtime = runtime;
|
||||
|
||||
|
@ -718,8 +725,9 @@ _PyInterpreterState_New(PyThreadState *tstate, PyInterpreterState **pinterp)
|
|||
}
|
||||
interpreters->head = interp;
|
||||
|
||||
long whence = _PyInterpreterState_WHENCE_UNKNOWN;
|
||||
status = init_interpreter(interp, runtime,
|
||||
id, old_head);
|
||||
id, old_head, whence);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -1103,6 +1111,34 @@ _PyInterpreterState_ReinitRunningMain(PyThreadState *tstate)
|
|||
// accessors
|
||||
//----------
|
||||
|
||||
static inline int
|
||||
check_interpreter_whence(long whence)
|
||||
{
|
||||
if(whence < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (whence > _PyInterpreterState_WHENCE_MAX) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long
|
||||
_PyInterpreterState_GetWhence(PyInterpreterState *interp)
|
||||
{
|
||||
assert(check_interpreter_whence(interp->_whence) == 0);
|
||||
return interp->_whence;
|
||||
}
|
||||
|
||||
void
|
||||
_PyInterpreterState_SetWhence(PyInterpreterState *interp, long whence)
|
||||
{
|
||||
assert(interp->_whence != _PyInterpreterState_WHENCE_NOTSET);
|
||||
assert(check_interpreter_whence(whence) == 0);
|
||||
interp->_whence = whence;
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *interp)
|
||||
{
|
||||
|
@ -1114,6 +1150,7 @@ PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *interp)
|
|||
return PyMapping_GetItemString(modules, "__main__");
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyInterpreterState_GetDict(PyInterpreterState *interp)
|
||||
{
|
||||
|
@ -1176,6 +1213,20 @@ PyInterpreterState_GetID(PyInterpreterState *interp)
|
|||
return interp->id;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyInterpreterState_GetIDObject(PyInterpreterState *interp)
|
||||
{
|
||||
if (_PyInterpreterState_IDInitref(interp) != 0) {
|
||||
return NULL;
|
||||
};
|
||||
int64_t interpid = interp->id;
|
||||
if (interpid < 0) {
|
||||
return NULL;
|
||||
}
|
||||
assert(interpid < LLONG_MAX);
|
||||
return PyLong_FromLongLong(interpid);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_PyInterpreterState_IDInitref(PyInterpreterState *interp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue