-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathctypes_cpp.py
More file actions
106 lines (69 loc) · 2.02 KB
/
ctypes_cpp.py
File metadata and controls
106 lines (69 loc) · 2.02 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Expected testing structures."""
import ctypes
import logging, sys
''' insure ctypes basic types are subverted '''
from haystack import model
from haystack.model import is_valid_address,is_valid_address_value,getaddress,array2bytes,bytes2array
from haystack.model 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.copyGeneratedClasses(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,inspect
src=sys.modules[__name__]
def printSizeof(mini=-1):
for (name,klass) in inspect.getmembers(sys.modules[__name__], inspect.isclass):
if type(klass) == type(ctypes.Structure):# and klass.__module__.endswith('%s_generated'%(__name__) ) :
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()