File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import ctypes
22from math import cos , pi , sin
3-
43import 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
1010libm .sin .argtypes = [ctypes .c_double ]
1111libm .sin .restype = ctypes .c_double
@@ -37,5 +37,7 @@ def increment(value):
3737
3838identity_type = ctypes .PYFUNCTYPE (ctypes .c_int , ctypes .c_int )
3939assert 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
Original file line number Diff line number Diff line change 1010assert type (p ) is char_p
1111assert 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 )
2115assert c .value == b'B'
2216
23- libc .memset (c , 67 , 1 )
17+ ctypes .memset (ctypes . addressof ( c ) , 67 , 1 )
2418assert c .value == b'C'
Original file line number Diff line number Diff line change 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'
You can’t perform that action at this time.
0 commit comments