-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathctypes_cpp.py
More file actions
115 lines (74 loc) · 2.17 KB
/
ctypes_cpp.py
File metadata and controls
115 lines (74 loc) · 2.17 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Expected testing allocators."""
from __future__ import print_function
import ctypes
import logging
import sys
''' insure ctypes basic types are subverted '''
from haystack import model
from haystack.utils import get_pointee_address, array2bytes, bytes2array
from haystack.constraints import LoadableMembers, RangeValue, NotNull, CString
__author__ = "Loic Jaquemet loic.jaquemet+python@gmail.com"
log = logging.getLogger('cpp')
# ============== Internal type defs ==============
class CPP(LoadableMembers):
''' defines classRef '''
pass
class A(CPP):
_fields_ = [
('a', ctypes.c_uint)
]
class B(A):
_fields_ = [
('b', ctypes.c_uint)
]
class C(B):
_fields_ = [
('c', ctypes.c_uint)
]
class D(B):
_fields_ = [
('d', ctypes.c_uint)
]
class E(D, C):
_fields_ = [
('C', C),
#('C', C),
('e', ctypes.c_uint)
]
################ START copy generated classes ##########################
# copy generated classes (gen.*) to this module as wrapper
###model.copy_generated_classes(gen, sys.modules[__name__])
# register all classes (gen.*, locally defines, and local duplicates) to haystack
# create plain old python object from ctypes.Structure's, to picke them
model.registerModule(sys.modules[__name__])
################ END copy generated classes ##########################
############# Start expectedValues and methods overrides #################
# checkks
import sys
import inspect
src = sys.modules[__name__]
def printSizeof(mini=-1):
for (name, klass) in inspect.getmembers(
sys.modules[__name__], inspect.isclass):
# and klass.__module__.endswith('%s_generated'%(__name__) ) :
if isinstance(klass, type(ctypes.Structure)):
if ctypes.sizeof(klass) > mini:
print('%s:' % name, ctypes.sizeof(klass))
e = E()
e.a = 1
e.b = 2
e.c = 3
e.d = 4
e.e = 5
C.__setattr__(e, 'a', 99)
D.__setattr__(e, 'a', 66)
e.C.a = 122
# for f in e.getFields():
# print f[0], getattr(e, f[0])
# print e.C.a
# print dict(e.getFields())
##########
if __name__ == '__main__':
pass # printSizeof()