bpo-25658: Implement PEP 539 for Thread Specific Storage (TSS) API by ma8ma · Pull Request #1362 · python/cpython (original) (raw)

To allow for use in the Py_LIMITED_API case, the public APIs that currently accept Py_tss_t by value will need to accept it as a pointer instead.

The alternative would be to make the Py_tss_t struct layout part of the stable ABI, but I'm reluctant to do that due to the NATIVE_TLS_KEY_T field: it would keep us from switching from int to a different native type for platforms that don't currently have a native implementation, but gain one in the future.

Following that chain of thought further, I guess fully supporting Py_LIMITED_API would require an extra pair of memory management functions (PyThread_tss_alloc and PyThread_tss_free), as with the struct definition hidden, API clients won't be able to use static variables.