diff options
Diffstat (limited to 'parse/sched.py')
-rw-r--r-- | parse/sched.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/parse/sched.py b/parse/sched.py index 6e1fbe6..524f1ed 100644 --- a/parse/sched.py +++ b/parse/sched.py | |||
@@ -98,15 +98,38 @@ record_map = {} | |||
98 | RECORD_SIZE = 24 | 98 | RECORD_SIZE = 24 |
99 | NSEC_PER_MSEC = 1000000 | 99 | NSEC_PER_MSEC = 1000000 |
100 | 100 | ||
101 | def bits_to_bytes(bits): | ||
102 | '''Includes padding''' | ||
103 | return bits / 8 + (1 if bits%8 else 0) | ||
104 | |||
105 | def field_bytes(fields): | ||
106 | fbytes = 0 | ||
107 | fbits = 0 | ||
108 | for f in fields: | ||
109 | flist = list(f) | ||
110 | |||
111 | if len(flist) > 2: | ||
112 | # Specified a bitfield | ||
113 | fbits += flist[2] | ||
114 | else: | ||
115 | # Only specified a type, use types size | ||
116 | fbytes += sizeof(list(f)[1]) | ||
117 | |||
118 | # Bitfields followed by a byte will cause any incomplete | ||
119 | # bytes to be turned into full bytes | ||
120 | fbytes += bits_to_bytes(fbits) | ||
121 | fbits = 0 | ||
122 | |||
123 | fbytes += bits_to_bytes(fbits) | ||
124 | return fbytes + fbits | ||
125 | |||
101 | def register_record(id, clazz): | 126 | def register_record(id, clazz): |
102 | fields = clazz.FIELDS | 127 | fields = clazz.FIELDS |
103 | 128 | diff = RECORD_SIZE - field_bytes(SchedRecord.FIELDS) - field_bytes(fields) | |
104 | fsize = lambda fields : sum([sizeof(list(f)[1]) for f in fields]) | ||
105 | diff = RECORD_SIZE - fsize(SchedRecord.FIELDS) - fsize(fields) | ||
106 | 129 | ||
107 | # Create extra padding fields to make record the proper size | 130 | # Create extra padding fields to make record the proper size |
108 | # Creating one big field of c_uint64 and giving it a size of 8*diff | 131 | # Creating one big field of c_uint64 and giving it a size of 8*diff |
109 | # _shoud_ work, but doesn't. This is an uglier way of accomplishing | 132 | # _should_ work, but doesn't. This is an uglier way of accomplishing |
110 | # the same goal | 133 | # the same goal |
111 | for d in range(diff): | 134 | for d in range(diff): |
112 | fields += [("extra%d" % d, c_char)] | 135 | fields += [("extra%d" % d, c_char)] |