Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127945: change _ctypes_test static globals to thread local#132575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kumaraditya303 merged 1 commit intopython:mainfromkumaraditya303:ctypes-fdesc
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletionsLib/test/test_ctypes/test_cfuncs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,10 @@ class CFunctions(unittest.TestCase):
_dll = CDLL(_ctypes_test.__file__)

def S(self):
return c_longlong.in_dll(self._dll, "last_tf_arg_s").value
return _ctypes_test.get_last_tf_arg_s()

def U(self):
returnc_ulonglong.in_dll(self._dll, "last_tf_arg_u").value
return_ctypes_test.get_last_tf_arg_u()

def test_byte(self):
self._dll.tf_b.restype = c_byte
Expand Down
4 changes: 3 additions & 1 deletionLib/test/test_ctypes/test_structures.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -284,7 +284,9 @@ class X(Structure):
func(s)
self.assertEqual(s.first, 0xdeadbeef)
self.assertEqual(s.second, 0xcafebabe)
got = X.in_dll(dll, "last_tfrsuv_arg")
dll.get_last_tfrsuv_arg.argtypes = ()
dll.get_last_tfrsuv_arg.restype = X
got = dll.get_last_tfrsuv_arg()
self.assertEqual(s.first, got.first)
self.assertEqual(s.second, got.second)

Expand Down
34 changes: 29 additions & 5 deletionsModules/_ctypes/_ctypes_test.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,16 @@

#include <Python.h>

#ifdef thread_local
# define _Py_thread_local thread_local
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
# define _Py_thread_local _Thread_local
#elif defined(_MSC_VER) /* AKA NT_THREADS */
# define _Py_thread_local __declspec(thread)
#elif defined(__GNUC__) /* includes clang */
# define _Py_thread_local __thread
#endif

#if defined(Py_HAVE_C_COMPLEX) && defined(Py_FFI_SUPPORT_C_COMPLEX)
# include "../_complex.h" // csqrt()
# undef I // for _ctypes_test_generated.c.h
Expand DownExpand Up@@ -81,7 +91,7 @@ typedef struct {
} TestReg;


EXPORT(TestReg) last_tfrsuv_arg = {0};
_Py_thread_localTestReg last_tfrsuv_arg = {0};


EXPORT(void)
Expand DownExpand Up@@ -741,8 +751,8 @@ EXPORT(void) _py_func(void)
{
}

EXPORT(long long) last_tf_arg_s = 0;
EXPORT(unsigned long long) last_tf_arg_u = 0;
_Py_thread_locallong long last_tf_arg_s = 0;
_Py_thread_localunsigned long long last_tf_arg_u = 0;

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

PyObject *get_last_tf_arg_s(PyObject *self, PyObject *noargs)
{
return PyLong_FromLongLong(last_tf_arg_s);
}

PyObject *get_last_tf_arg_u(PyObject *self, PyObject *noargs)
{
return PyLong_FromUnsignedLongLong(last_tf_arg_u);
}

EXPORT(TestReg) get_last_tfrsuv_arg(void)
{
return last_tfrsuv_arg;
}

static PyMethodDef module_methods[] = {
/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
{"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
{"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
*/
{"func_si", py_func_si, METH_VARARGS},
{"func", py_func, METH_NOARGS},
{"get_generated_test_data", get_generated_test_data, METH_O},
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp