Bug report
Bug description:
PyUnstable_Code_SetExtra and PyUnstable_Code_GetExtra in Objects/codeobject.c have no free-threaded protections. The co_extra field is read and written with plain loads and stores, and SetExtra calls PyMem_Realloc which can free the old buffer while a concurrent GetExtra is reading from it.
Similarly, PyUnstable_Eval_RequestCodeExtraIndex in Python/ceval.c increments co_extra_user_count and writes to co_extra_freefuncs without any synchronization.
The new tests (#144980) exercise the concurrent paths and a free-threaded TSAN build without the fix crashes/emits warnings.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
PyUnstable_Code_SetExtraandPyUnstable_Code_GetExtrainObjects/codeobject.chave no free-threaded protections. Theco_extrafield is read and written with plain loads and stores, andSetExtracallsPyMem_Reallocwhich can free the old buffer while a concurrentGetExtrais reading from it.Similarly,
PyUnstable_Eval_RequestCodeExtraIndexinPython/ceval.cincrementsco_extra_user_countand writes toco_extra_freefuncswithout any synchronization.The new tests (#144980) exercise the concurrent paths and a free-threaded TSAN build without the fix crashes/emits warnings.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs