diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-03-01 23:50:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-01 23:50:31 (GMT) |
commit | bcfa450f210074e16feb761ae5b3e966a2532fcf (patch) | |
tree | f35f16dc1d0689236065b87ac2a3d65f44c90c91 /Python/pystate.c | |
parent | 1f24a719e7be5e49b876a5dc7daf21d01ee69faa (diff) | |
download | cpython-bcfa450f210074e16feb761ae5b3e966a2532fcf.zip cpython-bcfa450f210074e16feb761ae5b3e966a2532fcf.tar.gz cpython-bcfa450f210074e16feb761ae5b3e966a2532fcf.tar.bz2 |
bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as necessary). (#12003)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index d612d3a..99a01ef 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -403,7 +403,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? @@ -413,6 +413,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) { @@ -425,6 +437,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) @@ -1370,7 +1392,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)) { |