annotate python/pydc/examples/atoi.py @ 30:baf087cf5971

- fixed two ref counting problems - minor improvements
author Tassilo Philipp
date Fri, 10 Apr 2020 20:35:19 +0200
parents edbbd467f50a
children a2125195b052
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 from pydc import *
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
2 import sys
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
3 import platform
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
5 if sys.platform == "win32":
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 libc = load("msvcrt")
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
7 elif sys.platform == "darwin":
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 libc = load("/usr/lib/libc.dylib")
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
9 elif "bsd" in sys.platform:
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
10 #libc = load("/usr/lib/libc.so")
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
11 libc = load("/lib/libc.so.7")
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
12 elif platform.architecture()[0] == "64bit":
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
13 libc = load("/lib64/libc.so.6")
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 else:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 libc = load("/lib/libc.so.6")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 fp_atoi = find(libc,"atoi")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 fp_atof = find(libc,"atof")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
20
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
21
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
22 def atoi(s): return call(fp_atoi,"Z)i",s)
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
23 def atod(s): return call(fp_atof,"Z)d",s)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
25 print(atoi("3".join(["12","45"])))
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
26 print(atod("3".join(["12","45"])))
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27