File: sample.py

package info (click to toggle)
pypy 2.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 86,992 kB
  • ctags: 170,715
  • sloc: python: 1,030,417; ansic: 43,437; cpp: 5,241; asm: 5,169; sh: 458; makefile: 408; xml: 231; lisp: 45
file content (72 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

from ctypes_configure import configure
import ctypes

class CConfigure:
    _compilation_info_ = configure.ExternalCompilationInfo(
        
        # all lines landing in C header before includes
        pre_include_lines = [],

        # list of .h files to include
        includes = ['time.h', 'sys/time.h', 'unistd.h'],

        # list of directories to search for include files
        include_dirs = [],

        # all lines landing in C header after includes
        post_include_lines = [],

        # libraries to link with
        libraries = [],

        # library directories
        library_dirs = [],

        # additional C sources to compile with (that go to
        # created .c files)
        separate_module_sources = [],

        # additional existing C source file names
        separate_module_files = [],
        )

    # get real int type out of hint and name
    size_t = configure.SimpleType('size_t', ctypes.c_int)

    # grab value of numerical #define
    NULL = configure.ConstantInteger('NULL')

    # grab #define, whether it's defined or not
    EXISTANT = configure.Defined('NULL')
    NOT_EXISTANT = configure.Defined('XXXNOTNULL')

    # check for existance of C functions
    has_write = configure.Has('write')
    no_xxxwrite = configure.Has('xxxwrite')

    # check for size of type
    sizeof_size_t = configure.SizeOf('size_t')

    # structure, with given hints for interesting fields,
    # types does not need to be too specific.
    # all interesting fields would end up with right offset
    # size and order
    struct_timeval = configure.Struct('struct timeval',[
        ('tv_sec', ctypes.c_int),
        ('tv_usec', ctypes.c_int)])

info = configure.configure(CConfigure)

assert info['has_write']
assert not info['no_xxxwrite']
assert info['NULL'] == 0
size_t = info['size_t']
print "size_t in ctypes is ", size_t
assert ctypes.sizeof(size_t) == info['sizeof_size_t']
assert info['EXISTANT']
assert not info['NOT_EXISTANT']
print
print "fields of struct timeval are "
for name, value in info['struct_timeval']._fields_:
    print "  ", name, " ", value