Skip to content

Commit 33e16cd

Browse files
change _ctypes_test static globals to thread local
1 parent 4b15d10 commit 33e16cd

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Lib/test/test_ctypes/test_cfuncs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class CFunctions(unittest.TestCase):
1414
_dll = CDLL(_ctypes_test.__file__)
1515

1616
def S(self):
17-
return c_longlong.in_dll(self._dll, "last_tf_arg_s").value
17+
return _ctypes_test.get_last_tf_arg_s()
18+
1819
def U(self):
19-
return c_ulonglong.in_dll(self._dll, "last_tf_arg_u").value
20+
return _ctypes_test.get_last_tf_arg_u()
2021

2122
def test_byte(self):
2223
self._dll.tf_b.restype = c_byte

Lib/test/test_ctypes/test_structures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ class X(Structure):
284284
func(s)
285285
self.assertEqual(s.first, 0xdeadbeef)
286286
self.assertEqual(s.second, 0xcafebabe)
287-
got = X.in_dll(dll, "last_tfrsuv_arg")
287+
dll.get_last_tfrsuv_arg.argtypes = ()
288+
dll.get_last_tfrsuv_arg.restype = X
289+
got = dll.get_last_tfrsuv_arg()
288290
self.assertEqual(s.first, got.first)
289291
self.assertEqual(s.second, got.second)
290292

Modules/_ctypes/_ctypes_test.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef struct {
8181
} TestReg;
8282

8383

84-
EXPORT(TestReg) last_tfrsuv_arg = {0};
84+
_Py_thread_local TestReg last_tfrsuv_arg = {0};
8585

8686

8787
EXPORT(void)
@@ -741,8 +741,8 @@ EXPORT(void) _py_func(void)
741741
{
742742
}
743743

744-
EXPORT(long long) last_tf_arg_s = 0;
745-
EXPORT(unsigned long long) last_tf_arg_u = 0;
744+
_Py_thread_local long long last_tf_arg_s = 0;
745+
_Py_thread_local unsigned long long last_tf_arg_u = 0;
746746

747747
struct BITS {
748748
signed int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
@@ -827,10 +827,24 @@ EXPORT(int) unpack_bitfields_msvc(struct BITS_msvc *bits, char name)
827827
}
828828
#endif
829829

830+
PyObject *get_last_tf_arg_s(PyObject *self, PyObject *noargs)
831+
{
832+
return PyLong_FromLongLong(last_tf_arg_s);
833+
}
834+
835+
PyObject *get_last_tf_arg_u(PyObject *self, PyObject *noargs)
836+
{
837+
return PyLong_FromUnsignedLongLong(last_tf_arg_u);
838+
}
839+
840+
EXPORT(TestReg) get_last_tfrsuv_arg(void)
841+
{
842+
return last_tfrsuv_arg;
843+
}
844+
830845
static PyMethodDef module_methods[] = {
831-
/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
846+
{"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
832847
{"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
833-
*/
834848
{"func_si", py_func_si, METH_VARARGS},
835849
{"func", py_func, METH_NOARGS},
836850
{"get_generated_test_data", get_generated_test_data, METH_O},

0 commit comments

Comments
 (0)