annotate python/pydc/examples/atoi.py @ 48:a2125195b052

added callconv switching to one example
author Tassilo Philipp
date Fri, 13 Nov 2020 18:27:09 +0100
parents edbbd467f50a
children
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")
48
a2125195b052 added callconv switching to one example
Tassilo Philipp
parents: 28
diff changeset
19 fp_printf = find(libc,"printf")
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
21
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
22
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
23 def atoi(s): return call(fp_atoi,"Z)i",s)
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
24 def atod(s): return call(fp_atof,"Z)d",s)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
26 print(atoi("3".join(["12","45"])))
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
27 print(atod("3".join(["12","45"])))
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
48
a2125195b052 added callconv switching to one example
Tassilo Philipp
parents: 28
diff changeset
29 # w/ some text - tests vararg callconv switch
a2125195b052 added callconv switching to one example
Tassilo Philipp
parents: 28
diff changeset
30 call(fp_printf,"_eZ_.id)i", "and again: %d %f\n", atoi("31245"), atod("31245"))
a2125195b052 added callconv switching to one example
Tassilo Philipp
parents: 28
diff changeset
31