|
From: Vladislav G. <the...@ma...> - 2011-01-10 23:13:32
|
Dear Henry,
Sure it was't work the way you wrote
> #define co_offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
But proposed define had member-whatever-it-contains bracket escaping
> #define co_offsetof(TYPE, MEMBER) ((int) (&((TYPE *)0)->MEMBER))
So, with MEMBER == field+const it will be equal to start_of_field +
const*size_of_filed
Anyway, I'd like to see it fixed in svn :)
Btw, there's a lot of places with old style calculations, I mean without
co_offsetof usage, even right several lines below the discussing line.
Best Regards, theMIROn
ICQ: 303357
Skype: the.miron
> -----Original Message-----
> From: Henry Nestler [mailto:hen...@ar...]
> Sent: Tuesday, January 11, 2011 3:41 AM
> To: Vladislav Grishenko
> Cc: col...@li...
> Subject: Re: offset calculation breakage
>
> Hello Vladislav,
>
>
> On 10.01.2011 21:36, Vladislav Grishenko wrote:
> > Dear Henry,
> >
> > My Windows 7 x86 installation goes into BSOD right on/after console
> attach.
> > I've bisected it to recent r1560 changeset introduced co_offsetof macro.
> >
> >> size = (char*)(&message->putcs + 1) - (char*)message +
> >> bytes_per_line;
> > Original construction means the struct length, excluding the member
> > plus size of one member, not its offset actually.
> >
> >> #define co_offsetof(TYPE, MEMBER) ((int)&((TYPE *)0)->MEMBER) size =
> >> co_offsetof(co_console_message_t, putcs) + 1 + bytes_per_line;
> > New one means the struct length excluding the member + one byte,
> > that's seems wrong.
> >
> > So, to keep co_offsetof macro and restore binary compability, I
> > suggest following changes:
> >> #define co_offsetof(TYPE, MEMBER) ((int) (&((TYPE *)0)->MEMBER)) size
> >> = co_offsetof(co_console_message_t, putcs + 1) + bytes_per_line;
>
> many thanks for pointing to that bug!
>
> You are right, that this should give the size for struct without the data
self.
> The +1 was to point directly behind the element "putcs".
> Your changes was not working on my test with gcc 4.4.1:
>
> // Building:
> // DIR=$HOME/colinux/build/devel-gcc412.svn
> // gcc -m32 -I$DIR/linux-2.6.33.5-source/include
> -I$DIR/linux-2.6.33.5-build/include
> -I$DIR/linux-2.6.33.5-source/arch/x86/include foo.c
>
> #include <stdio.h>
> #include <linux/cooperative.h>
>
> #define bytes_per_line 0
> #define co_offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
>
> int main()
> {
> co_console_message_t*<->message;
> int size1 = (char*)(&message->putcs + 1) - (char*)message +
> bytes_per_line; // old
> int size2 = co_offsetof(co_console_message_t, putcs) + 1 +
> bytes_per_line; // Henry
> int size3 = co_offsetof(co_console_message_t, putcs + 1) +
> bytes_per_line; // Vladislav
> int size4 = co_offsetof(co_console_message_t, putcs.data) +
> bytes_per_line; // right
> return printf("%d %d %d %d\n", size1, size2, size3, size4); }
>
> Result:
> 10 5 5 10
>
> So, the right calculation would be:
>
> - size = co_offsetof(co_console_message_t, putcs) + 1 +
> bytes_per_line;
> + size = co_offsetof(co_console_message_t, putcs.data) +
> bytes_per_line;
>
> --
> Henry N.
|