aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-05-02 13:42:17 -0400
committerJonathan Herman <hermanjl@cs.unc.edu>2013-05-02 13:42:17 -0400
commit6f2558b8c4f4e33630b40dfbe20024f7a372a8f0 (patch)
treeeb4351c89079e12d3af9d95d634c2aec5abe05b2
parentcd9f1b026cc5c4526dfbd2f7b1c5f39edb6a7309 (diff)
Modified sched.py field padding calculations to account for bitfields.
-rw-r--r--parse/sched.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/parse/sched.py b/parse/sched.py
index 4933037..a25ec15 100644
--- a/parse/sched.py
+++ b/parse/sched.py
@@ -65,15 +65,38 @@ record_map = {}
65RECORD_SIZE = 24 65RECORD_SIZE = 24
66NSEC_PER_MSEC = 1000000 66NSEC_PER_MSEC = 1000000
67 67
68def bits_to_bytes(bits):
69 '''Includes padding'''
70 return bits / 8 + (1 if bits%8 else 0)
71
72def field_bytes(fields):
73 fbytes = 0
74 fbits = 0
75 for f in fields:
76 flist = list(f)
77
78 if len(flist) > 2:
79 # Specified a bitfield
80 fbits += flist[2]
81 else:
82 # Only specified a type, use types size
83 fbytes += sizeof(list(f)[1])
84
85 # Bitfields followed by a byte will cause any incomplete
86 # bytes to be turned into full bytes
87 fbytes += bits_to_bytes(fbits)
88 fbits = 0
89
90 fbytes += bits_to_bytes(fbits)
91 return fbytes + fbits
92
68def register_record(id, clazz): 93def register_record(id, clazz):
69 fields = clazz.FIELDS 94 fields = clazz.FIELDS
70 95 diff = RECORD_SIZE - field_bytes(SchedRecord.FIELDS) - field_bytes(fields)
71 fsize = lambda fields : sum([sizeof(list(f)[1]) for f in fields])
72 diff = RECORD_SIZE - fsize(SchedRecord.FIELDS) - fsize(fields)
73 96
74 # Create extra padding fields to make record the proper size 97 # Create extra padding fields to make record the proper size
75 # Creating one big field of c_uint64 and giving it a size of 8*diff 98 # Creating one big field of c_uint64 and giving it a size of 8*diff
76 # _shoud_ work, but doesn't. This is an uglier way of accomplishing 99 # _should_ work, but doesn't. This is an uglier way of accomplishing
77 # the same goal 100 # the same goal
78 for d in range(diff): 101 for d in range(diff):
79 fields += [("extra%d" % d, c_char)] 102 fields += [("extra%d" % d, c_char)]