summaryrefslogtreecommitdiff
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1a29621473..b512c05a3f 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4306,6 +4306,61 @@ py_w_stopcode(PyObject *self, PyObject *args)
#endif
+static PyObject *
+test_pythread_tss_key_state(PyObject *self, PyObject *args)
+{
+ Py_tss_t tss_key = Py_tss_NEEDS_INIT;
+ if (PyThread_tss_is_created(&tss_key)) {
+ return raiseTestError("test_pythread_tss_key_state",
+ "TSS key not in an uninitialized state at "
+ "creation time");
+ }
+ if (PyThread_tss_create(&tss_key) != 0) {
+ PyErr_SetString(PyExc_RuntimeError, "PyThread_tss_create failed");
+ return NULL;
+ }
+ if (!PyThread_tss_is_created(&tss_key)) {
+ return raiseTestError("test_pythread_tss_key_state",
+ "PyThread_tss_create succeeded, "
+ "but with TSS key in an uninitialized state");
+ }
+ if (PyThread_tss_create(&tss_key) != 0) {
+ return raiseTestError("test_pythread_tss_key_state",
+ "PyThread_tss_create unsuccessful with "
+ "an already initialized key");
+ }
+#define CHECK_TSS_API(expr) \
+ (void)(expr); \
+ if (!PyThread_tss_is_created(&tss_key)) { \
+ return raiseTestError("test_pythread_tss_key_state", \
+ "TSS key initialization state was not " \
+ "preserved after calling " #expr); }
+ CHECK_TSS_API(PyThread_tss_set(&tss_key, NULL));
+ CHECK_TSS_API(PyThread_tss_get(&tss_key));
+#undef CHECK_TSS_API
+ PyThread_tss_delete(&tss_key);
+ if (PyThread_tss_is_created(&tss_key)) {
+ return raiseTestError("test_pythread_tss_key_state",
+ "PyThread_tss_delete called, but did not "
+ "set the key state to uninitialized");
+ }
+
+ Py_tss_t *ptr_key = PyThread_tss_alloc();
+ if (ptr_key == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "PyThread_tss_alloc failed");
+ return NULL;
+ }
+ if (PyThread_tss_is_created(ptr_key)) {
+ return raiseTestError("test_pythread_tss_key_state",
+ "TSS key not in an uninitialized state at "
+ "allocation time");
+ }
+ PyThread_tss_free(ptr_key);
+ ptr_key = NULL;
+ Py_RETURN_NONE;
+}
+
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
@@ -4518,6 +4573,7 @@ static PyMethodDef TestMethods[] = {
#ifdef W_STOPCODE
{"W_STOPCODE", py_w_stopcode, METH_VARARGS},
#endif
+ {"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS},
{NULL, NULL} /* sentinel */
};