[aspectc-user] gcc 2.96 vs. ResultBuffer

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Wed Mar 14 02:41:07 CET 2007


Hi Timothy,

could you try replace "&result" with "&result._data" in the generated
code and see if it compiles and works as expected? I don't have a g++
2.96 to test this at the moment, because I am currently attending the
AOSD conference.

It looks for me as if result._data would really be better. I will change
the code generator accordingly.

Best regards,

Olaf

Timothy Stack wrote:
>
> Hi,
>
> I seem to be having some trouble with garbage return values when using
> gcc 2.96.  My test case is a simple method that returns an integer and
> has one advice applied to it.  When I run it, the return value of the
> method (always 1), will come out garbled.  As best as I can figure,
> it's due to the memory layout of the ResultBuffer structure.  I'll
> copy the generated code here for reference:
>
>   struct AnyResultBuffer {};
>   template <typename T> struct ResultBuffer : public AnyResultBuffer {
>     char _data[sizeof (T)];
>     ~ResultBuffer () { ((T*)_data)->T::~T(); }
>     operator T& () const { return *(T*)_data; }
>   };
>
> In gcc 2.96, it looks like the ResultBuffer's _data member is located
> one byte after the base pointer (probably because the parent struct is
> one byte in size).  So, the following placement new when the method is
> called, doesn't quite work (I think):
>
>   ::new (&result) int (...);
>
> In later gcc's, the sizeof AnyResultBuffer is still one, but it does
> not offset the _data member by a byte, like in 2.96.  So, the test
> works fine.
>
> Perhaps I'm missing something, but I would think you'd want the
> placement new to refer to the _data member directly...
>
> thanks,
>
> tim stack
>
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at aspectc.org
> http://www.aspectc.org/mailman/listinfo/aspectc-user




More information about the aspectc-user mailing list