[issue31828] Support Py_tss_NEEDS_INIT outside of static initialisation

Nick Coghlan report at bugs.python.org
Sat Oct 21 04:07:56 EDT 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Right, the cases we were aiming to cover were:

- C variable declarations ("static Py_tss_t tss_key = Py_tss_NEEDS_INIT;")
- dynamic allocation with PyThread_tss_alloc
- resetting a key back to the uninitialised state with PyThread_tss_delete

The problem we have is that the second field in Py_tss_t is platform dependent, and not all platforms define a safe "unused" value for their NATIVE_TSS_KEY_T, which means Py_tss_NEEDS_INIT ends up being only a partial initialiser (earlier versions of the PEP used a field initialiser, but we were asked to switch it to a partial initialiser in order to support more compilers).

We *could* offer a `PyThread_tss_reset` (to reset a key back to Py_tss_NEEDS_INIT), but that's confusingly similar to PyThread_tss_delete.

Another option would be to check for typed partial initialiser support in the configure script, and declare Py_tss_NEEDS_INIT accordingly. However, that wouldn't solve the problem for any clients that are themselves also attempting to write cross-platform code.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31828>
_______________________________________


More information about the Python-bugs-list mailing list