[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug in objc_alignof_type
From: |
Frederic De Jaeger |
Subject: |
bug in objc_alignof_type |
Date: |
09 Apr 2003 00:16:57 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Hi list,
I'm using :
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,pascal,objc,ada --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3 20030309 (Debian prerelease)
on an i386.
Consider this C type
typedef struct
{
int (indexSystem);
int (indexPort);
int (eliteRank);
double (money);
double (date);
NSString *(nameShip);
NSString *(stationName);
id (dicoShip);
BOOL (finish);
}(Contract);
apparently, the field "money" is aligned on a word. Here, its offset
is 12 in the record.
In various place of gnustep base, the offset is computed using
objc_alignof_type. For example, this is a piece of code from NSArchiver.m
[...]
for (;;)
{
(*_eValImp)(self, eValSel, type, (char*)buf + offset);
offset += objc_sizeof_type(type);
type = objc_skip_typespec(type);
if (*type == _C_STRUCT_E)
{
break;
}
else
{
! int align = objc_alignof_type(type);
! int rem = offset % align;
!
! if (rem != 0)
! {
! offset += align - rem;
! }
! }
}
[...]
In the case of the double type, objc_alignof_type answers 8. Thus,
the result of that computation is that offset is incremented by 4 in
order to align on double word boundary. Offset will be set to 16
instead of 12, with all the funny consequences.
Apparently, it looks like a bug of gcc. Does it ?
Cheers,
Frédéric De Jaeger
- bug in objc_alignof_type,
Frederic De Jaeger <=