bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as necessary). (gh-12359)

This commit is contained in:
Eric Snow 2019-03-15 16:35:46 -06:00 committed by GitHub
parent 842a2f07f2
commit c11183cdcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 483 additions and 393 deletions

View file

@ -418,7 +418,7 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp)
int64_t refcount = interp->id_refcount;
PyThread_release_lock(interp->id_mutex);
if (refcount == 0) {
if (refcount == 0 && interp->requires_idref) {
// XXX Using the "head" thread isn't strictly correct.
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
// XXX Possible GILState issues?
@ -428,6 +428,18 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp)
}
}
int
_PyInterpreterState_RequiresIDRef(PyInterpreterState *interp)
{
return interp->requires_idref;
}
void
_PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
{
interp->requires_idref = required ? 1 : 0;
}
_PyCoreConfig *
_PyInterpreterState_GetCoreConfig(PyInterpreterState *interp)
{
@ -440,6 +452,16 @@ _PyInterpreterState_GetMainConfig(PyInterpreterState *interp)
return &interp->config;
}
PyObject *
_PyInterpreterState_GetMainModule(PyInterpreterState *interp)
{
if (interp->modules == NULL) {
PyErr_SetString(PyExc_RuntimeError, "interpreter not initialized");
return NULL;
}
return PyMapping_GetItemString(interp->modules, "__main__");
}
/* Default implementation for _PyThreadState_GetFrame */
static struct _frame *
threadstate_getframe(PyThreadState *self)
@ -1392,7 +1414,7 @@ _register_xidata(PyTypeObject *cls, crossinterpdatafunc getdata)
static void _register_builtins_for_crossinterpreter_data(void);
int
_PyCrossInterpreterData_Register_Class(PyTypeObject *cls,
_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
crossinterpdatafunc getdata)
{
if (!PyType_Check(cls)) {