comparison python/pydc/examples/atoi.py @ 28:edbbd467f50a

python binding: - update to dyncall 1.1 - Python 3 support (supports both, Python 2 and 3) - using the Capsule API over PyCObject, when available - support for python unicode strings (for both, Python 2 and 3) - doc cleanup ruby binding: - doc cleanup
author Tassilo Philipp
date Tue, 07 Apr 2020 21:16:37 +0200
parents bf5625bb6f05
children a2125195b052
comparison
equal deleted inserted replaced
27:18e1f1bb1945 28:edbbd467f50a
5 if sys.platform == "win32": 5 if sys.platform == "win32":
6 libc = load("msvcrt") 6 libc = load("msvcrt")
7 elif sys.platform == "darwin": 7 elif sys.platform == "darwin":
8 libc = load("/usr/lib/libc.dylib") 8 libc = load("/usr/lib/libc.dylib")
9 elif "bsd" in sys.platform: 9 elif "bsd" in sys.platform:
10 libc = load("/usr/lib/libc.so") 10 #libc = load("/usr/lib/libc.so")
11 libc = load("/lib/libc.so.7")
11 elif platform.architecture()[0] == "64bit": 12 elif platform.architecture()[0] == "64bit":
12 libc = load("/lib64/libc.so.6") 13 libc = load("/lib64/libc.so.6")
13 else: 14 else:
14 libc = load("/lib/libc.so.6") 15 libc = load("/lib/libc.so.6")
15 16
16 fp_atoi = find(libc,"atoi") 17 fp_atoi = find(libc,"atoi")
17 fp_atof = find(libc,"atof") 18 fp_atof = find(libc,"atof")
18 19
19 20
20 21
21 def atoi(s): return call(fp_atoi,"p)i",s) 22 def atoi(s): return call(fp_atoi,"Z)i",s)
22 def atod(s): return call(fp_atof,"p)d",s) 23 def atod(s): return call(fp_atof,"Z)d",s)
23 24
24 print atoi( "3".join(["12","45"]) ) 25 print(atoi("3".join(["12","45"])))
25 print atod( "3".join(["12","45"]) ) 26 print(atod("3".join(["12","45"])))
26 27