Add the co_extra field and accompanying APIs to code objects.

This completes PEP 523.
This commit is contained in:
Brett Cannon 2016-09-07 11:16:41 -07:00
parent a9296e7f3b
commit 5c4de2863b
8 changed files with 139 additions and 3 deletions

View file

@ -5608,3 +5608,17 @@ _Py_GetDXProfile(PyObject *self, PyObject *args)
}
#endif
Py_ssize_t
_PyEval_RequestCodeExtraIndex(freefunc free)
{
PyThreadState *tstate = PyThreadState_Get();
Py_ssize_t new_index;
if (tstate->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;
return new_index;
}