|
13 | 13 |
|
14 | 14 | #include <Python.h>
|
15 | 15 |
|
| 16 | +#ifdef thread_local |
| 17 | +# define _Py_thread_local thread_local |
| 18 | +#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) |
| 19 | +# define _Py_thread_local _Thread_local |
| 20 | +#elif defined(_MSC_VER) /* AKA NT_THREADS */ |
| 21 | +# define _Py_thread_local __declspec(thread) |
| 22 | +#elif defined(__GNUC__) /* includes clang */ |
| 23 | +# define _Py_thread_local __thread |
| 24 | +#endif |
| 25 | + |
16 | 26 | #if defined(Py_HAVE_C_COMPLEX) && defined(Py_FFI_SUPPORT_C_COMPLEX)
|
17 | 27 | # include "../_complex.h" // csqrt()
|
18 | 28 | # undef I // for _ctypes_test_generated.c.h
|
@@ -81,7 +91,7 @@ typedef struct {
|
81 | 91 | } TestReg;
|
82 | 92 |
|
83 | 93 |
|
84 |
| -EXPORT(TestReg) last_tfrsuv_arg = {0}; |
| 94 | +_Py_thread_local TestReg last_tfrsuv_arg = {0}; |
85 | 95 |
|
86 | 96 |
|
87 | 97 | EXPORT(void)
|
@@ -741,8 +751,8 @@ EXPORT(void) _py_func(void)
|
741 | 751 | {
|
742 | 752 | }
|
743 | 753 |
|
744 |
| -EXPORT(long long) last_tf_arg_s = 0; |
745 |
| -EXPORT(unsigned long long) last_tf_arg_u = 0; |
| 754 | +_Py_thread_local long long last_tf_arg_s = 0; |
| 755 | +_Py_thread_local unsigned long long last_tf_arg_u = 0; |
746 | 756 |
|
747 | 757 | struct BITS {
|
748 | 758 | signed int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
|
@@ -827,10 +837,24 @@ EXPORT(int) unpack_bitfields_msvc(struct BITS_msvc *bits, char name)
|
827 | 837 | }
|
828 | 838 | #endif
|
829 | 839 |
|
| 840 | +PyObject *get_last_tf_arg_s(PyObject *self, PyObject *noargs) |
| 841 | +{ |
| 842 | + return PyLong_FromLongLong(last_tf_arg_s); |
| 843 | +} |
| 844 | + |
| 845 | +PyObject *get_last_tf_arg_u(PyObject *self, PyObject *noargs) |
| 846 | +{ |
| 847 | + return PyLong_FromUnsignedLongLong(last_tf_arg_u); |
| 848 | +} |
| 849 | + |
| 850 | +EXPORT(TestReg) get_last_tfrsuv_arg(void) |
| 851 | +{ |
| 852 | + return last_tfrsuv_arg; |
| 853 | +} |
| 854 | + |
830 | 855 | static PyMethodDef module_methods[] = {
|
831 |
| -/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, |
| 856 | + {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, |
832 | 857 | {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
|
833 |
| -*/ |
834 | 858 | {"func_si", py_func_si, METH_VARARGS},
|
835 | 859 | {"func", py_func, METH_NOARGS},
|
836 | 860 | {"get_generated_test_data", get_generated_test_data, METH_O},
|
|
0 commit comments