Skip to content

Commit 287d7ad

Browse files
committed
fix(Lib/ctypes): enable ffi on Windows & MacOS
1 parent f6c871d commit 287d7ad

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎tests/Lib/test_ctypes/ctypes_ffi.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import ctypes
22
from math import cos, pi, sin
3-
43
import sys
5-
if sys.platform == 'win32': sys.exit()
64

7-
libc = ctypes.cdll['libc.so.6']
8-
libm = ctypes.cdll['libm.so.6']
5+
from utils import libcname, libmname
6+
7+
libc = ctypes.cdll[libcname]
8+
libm = ctypes.cdll[libmname]
99

1010
libm.sin.argtypes = [ctypes.c_double]
1111
libm.sin.restype = ctypes.c_double
@@ -37,5 +37,7 @@ def increment(value):
3737

3838
identity_type = ctypes.PYFUNCTYPE(ctypes.c_int, ctypes.c_int)
3939
assert identity_type(increment)(4) == 5
40-
#win_identity_type = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_int)
41-
#assert win_identity_type(increment)(4) == 5
40+
41+
if sys.platform == "win32":
42+
win_identity_type = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_int)
43+
assert win_identity_type(increment)(4) == 5

‎tests/Lib/test_ctypes/ctypes_pointers.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010
assert type(p) is char_p
1111
assert p.contents is c
1212

13-
import sys
14-
if sys.platform == 'win32': sys.exit()
15-
16-
libc = ctypes.cdll['libc.so.6']
17-
libc.memset.argtypes = [char_p, ctypes.c_int, ctypes.c_size_t]
18-
libc.memset.restype = char_p
19-
res = libc.memset(p, 66, 1)
20-
assert type(res) is char_p
13+
res = ctypes.memset(ctypes.addressof(c), 66, 1)
14+
assert res == ctypes.addressof(c)
2115
assert c.value == b'B'
2216

23-
libc.memset(c, 67, 1)
17+
ctypes.memset(ctypes.addressof(c), 67, 1)
2418
assert c.value == b'C'

‎tests/Lib/test_ctypes/utils.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import sys
3+
if sys.platform == 'win32':
4+
libcname = 'msvcrt.dll'
5+
libmname = 'msvcrt.dll'
6+
elif sys.platform == 'linux':
7+
libcname = 'libc.so.6'
8+
libmname = 'libm.so.6'
9+
#elif sys.platform == 'darwin':
10+
else:
11+
libcname = 'libc.dylib'
12+
libmname = 'libm.dylib'

0 commit comments

Comments
 (0)