[3.6] bpo-30604: Move co_extra_freefuncs to interpreter state to avoid crashes in threads (#2015)

* Move co_extra_freefuncs to interpreter state to avoid crashes in
multi-threaded scenarios involving deletion of code objects

* Don't require that extra be zero initialized

* Build test list instead of defining empty test class

* Ensure extra is always assigned on success

* Keep the old fields in the thread state object, just don't use them
Add new linked list of code extra objects on a per-interpreter basis
  so that interpreter state size isn't changed

* Rename __PyCodeExtraState_Get and add comment about it going away in 3.7
Fix sort order of import's in test_code.py

* Remove an extraneous space

* Remove docstrings for comments

* Touch up formatting

* Fix casing of coextra local

* Fix casing of another variable

* Prefix PyCodeExtraState with __ to match C API for getting it

* Update NEWS file for bpo-30604
This commit is contained in:
Dino Viehland 2017-06-12 18:46:35 -07:00 committed by Ned Deily
parent f59cac4b64
commit 2997fec01e
6 changed files with 180 additions and 23 deletions

View file

@ -5453,14 +5453,14 @@ _Py_GetDXProfile(PyObject *self, PyObject *args)
Py_ssize_t
_PyEval_RequestCodeExtraIndex(freefunc free)
{
PyThreadState *tstate = PyThreadState_Get();
__PyCodeExtraState *state = __PyCodeExtraState_Get();
Py_ssize_t new_index;
if (tstate->co_extra_user_count == MAX_CO_EXTRA_USERS - 1) {
if (state->co_extra_user_count == MAX_CO_EXTRA_USERS - 1) {
return -1;
}
new_index = tstate->co_extra_user_count++;
tstate->co_extra_freefuncs[new_index] = free;
new_index = state->co_extra_user_count++;
state->co_extra_freefuncs[new_index] = free;
return new_index;
}