diff --git a/compiler/ppu.pas b/compiler/ppu.pas index 346b4b664c..a249dc67b9 100644 --- a/compiler/ppu.pas +++ b/compiler/ppu.pas @@ -43,7 +43,7 @@ type {$endif Test_Double_checksum} const - CurrentPPUVersion = 132; + CurrentPPUVersion = 133; { buffer sizes } maxentrysize = 1024; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index c49a0a0728..5a28d5b619 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -3002,6 +3002,7 @@ implementation trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte); trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte); trecordsymtable(symtable).datasize:=ppufile.getasizeint; + trecordsymtable(symtable).paddingsize:=ppufile.getword; trecordsymtable(symtable).ppuload(ppufile); { requires usefieldalignment to be set } symtable.defowner:=self; @@ -3087,6 +3088,7 @@ implementation ppufile.putbyte(byte(trecordsymtable(symtable).padalignment)); ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment)); ppufile.putasizeint(trecordsymtable(symtable).datasize); + ppufile.putword(trecordsymtable(symtable).paddingsize); end; ppufile.writeentry(ibrecorddef); @@ -4385,6 +4387,7 @@ implementation stringdispose(import_lib); symtable:=tObjectSymtable.create(self,objrealname^,0); tObjectSymtable(symtable).datasize:=ppufile.getasizeint; + tObjectSymtable(symtable).paddingsize:=ppufile.getword; tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte); tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte); vmt_offset:=ppufile.getlongint; @@ -4555,6 +4558,7 @@ implementation else ppufile.putstring(''); ppufile.putasizeint(tObjectSymtable(symtable).datasize); + ppufile.putword(tObjectSymtable(symtable).paddingsize); ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment)); ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment)); ppufile.putlongint(vmt_offset); @@ -4804,6 +4808,10 @@ implementation if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and (tObjectSymtable(symtable).usefieldalignment=C_alignment) then tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment; + { the padding is not inherited for Objective-C classes (maybe not + for cppclass either?) } + if objecttype=odt_objcclass then + tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize; if (oo_has_vmt in objectoptions) and (oo_has_vmt in c.objectoptions) then tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint); diff --git a/compiler/symtable.pas b/compiler/symtable.pas index d74608887b..61d7083ea3 100644 --- a/compiler/symtable.pas +++ b/compiler/symtable.pas @@ -92,14 +92,18 @@ interface function has_single_field(out sym:tfieldvarsym): boolean; function get_unit_symtable: tsymtable; protected - _datasize : asizeint; + { size in bytes including padding } + _datasize : asizeint; { size in bits of the data in case of bitpacked record. Only important during construction, } { no need to save in/restore from ppu file. datasize is always (databitsize+7) div 8. } databitsize : asizeint; + { size in bytes of padding } + _paddingsize : word; procedure setdatasize(val: asizeint); public function iscurrentunit: boolean; override; property datasize : asizeint read _datasize write setdatasize; + property paddingsize: word read _paddingsize write _paddingsize; end; trecordsymtable = class(tabstractrecordsymtable) @@ -1021,6 +1025,8 @@ implementation procedure tabstractrecordsymtable.addalignmentpadding; + var + padded_datasize: asizeint; begin { make the record size aligned correctly so it can be used as elements in an array. For C records we @@ -1043,7 +1049,9 @@ implementation else padalignment:=min(recordalignment,usefieldalignment); end; - _datasize:=align(_datasize,padalignment); + padded_datasize:=align(_datasize,padalignment); + _paddingsize:=padded_datasize-_datasize; + _datasize:=padded_datasize; end; diff --git a/compiler/utils/ppudump.pp b/compiler/utils/ppudump.pp index bd39491134..8d8c05b799 100644 --- a/compiler/utils/ppudump.pp +++ b/compiler/utils/ppudump.pp @@ -1975,11 +1975,12 @@ begin writeln(space,' Name of Record : ',getstring); write (space,' Options : '); readobjectdefoptions; - writeln(space,' FieldAlign : ',getbyte); - writeln(space,' RecordAlign : ',getbyte); - writeln(space,' PadAlign : ',getbyte); - writeln(space,'UseFieldAlignment : ',getbyte); - writeln(space,' DataSize : ',getaint); + writeln(space,' FieldAlign : ',shortint(getbyte)); + writeln(space,' RecordAlign : ',shortint(getbyte)); + writeln(space,' PadAlign : ',shortint(getbyte)); + writeln(space,'UseFieldAlignment : ',shortint(getbyte)); + writeln(space,' DataSize : ',getasizeint); + writeln(space,' PaddingSize : ',getword); if not EndOfEntry then HasMoreInfos; {read the record definitions and symbols} @@ -2013,9 +2014,10 @@ begin end; writeln(space,' External name : ',getstring); writeln(space,' Import lib : ',getstring); - writeln(space,' DataSize : ',getaint); - writeln(space,' FieldAlign : ',getbyte); - writeln(space,' RecordAlign : ',getbyte); + writeln(space,' DataSize : ',getasizeint); + writeln(space,' PaddingSize : ',getword); + writeln(space,' FieldAlign : ',shortint(getbyte)); + writeln(space,' RecordAlign : ',shortint(getbyte)); writeln(space,' Vmt offset : ',getlongint); write (space, ' Ancestor Class : '); readderef('');