[Tinyos-devel] Bug/inconsistency in mig python
Rodrigo Fonseca
rfonseca at cs.berkeley.edu
Sat Sep 6 11:25:23 PDT 2008
Hi,
I noticed a couple of things regarding mig generating python classes.
1. First, a bug in the __str__ method of the generated mig class: the mask
for printing array fields is not set properly.
My struct:
typedef nx_struct nx_entry_t {
nx_uint8_t type;
nx_uint8_t res_id;
nx_uint32_t time;
nx_uint32_t ic;
nx_uint16_t arg;
} nx_entry_t;
typedef nx_struct quanto_vlog_msg_t {
nx_uint8_t n;
nx_entry_t entries[N];
} quanto_vlog_msg_t;
The mig command:
mig -o QuantoLogMsgV.py -python-classname=QuantoLogMsgV python \
$(QUANTO_ROOT)/tos/lib/quanto/QuantoLog/QuantoLogStagedMyUART.h \
quanto_vlog_msg_t
The generated __str__ method (exception code omitted):
def __str__(self):
s = "Message <QuantoLogMsgV> \n"
s += " [n=0x%x]\n" % (self.get_n())
s += " [entries.type=";
for i in range(0, 10):
s += "0x%x " % (self.getElement_entries_type(i) & 0xff)
s += "]\n";
s += " [entries.res_id=";
for i in range(0, 10):
s += "0x%x " % (self.getElement_entries_res_id(i) & 0xff)
s += "]\n";
s += " [entries.time=";
for i in range(0, 10):
s += "0x%x " % (self.getElement_entries_time(i) & 0xff)
s += "]\n";
s += " [entries.ic=";
for i in range(0, 10):
s += "0x%x " % (self.getElement_entries_ic(i) & 0xff)
s += "]\n";
s += " [entries.arg=";
for i in range(0, 10):
s += "0x%x " % (self.getElement_entries_arg(i) & 0xff)
s += "]\n";
The masks for time, ic, and arg are wrong, should be respectively
0xffffffff, 0xffffffff, 0xffff.
2. This is an inconsistency between what MIG and nesc are doing with
nx_types.
I defined nx_entry_t as above, and the generated code in app.c is
typedef nx_struct nx_entry_t {
nx_uint8_t type;
nx_uint8_t res_id;
nx_uint32_t time;
nx_uint32_t ic;
nx_uint16_t arg;
} __attribute__((packed))
Then I changed nx_entry_t to include arg inside a union, and nesc added a
filler.
typedef nx_struct nx_entry_t {
nx_uint8_t type;
nx_uint8_t res_id;
nx_uint32_t time;
nx_uint32_t ic;
nx_union {
nx_uint16_t arg;
}
} nx_entry_t;
In app.c, a filler is added by nesc. I don't know if this has to be done,
but, in any case, this is what's in app.c. Of course, sizeof works
correctly, and gives 14 as an answer.
typedef nx_struct nx_entry_t {
nx_uint8_t type;
nx_uint8_t res_id;
nx_uint32_t time;
nx_uint32_t ic;
nx_union {
nx_uint16_t arg;
} __attribute__((packed));
unsigned char __nesc_filler0[2];
} __attribute__((packed))
nx_entry_t;
However, the mig-generated code DOES NOT KNOW ABOUT THE FILLER, and breaks
when trying to parse.
diff QuantoLogMsgV.py.union QuantoLogMsgV.py.no-union returns no difference
between mig-generated python classes for both structs, while the binary
streams are different.
I don't know whether the filler behavior for this case is wrong, but mig is
certainly inconsistent with the binary output.
Thoughts?
Thanks,
Rodrigo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-devel/attachments/20080906/0444d35e/attachment.htm
More information about the Tinyos-devel
mailing list