* fixed alignment/endianess for sparc

git-svn-id: trunk@6957 -
This commit is contained in:
marc 2005-03-16 00:25:46 +00:00
parent 6278435a3d
commit 92fe571ea8
4 changed files with 78 additions and 31 deletions

View File

@ -243,23 +243,36 @@ type
PMethodNameTable = ^TMethodNameTable;
PFieldClassTable = ^TFieldClassTable;
TFieldClassTable = packed record
TFieldClassTable =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
Count: Word;
Entries: array[Word] of TPersistentClass;
end;
PFieldInfo = ^TFieldInfo;
TFieldInfo = packed record
TFieldInfo =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
FieldOffset: LongWord;
ClassTypeIndex: Word;
Name: ShortString;
end;
PFieldTable = ^TFieldTable;
TFieldTable = packed record
TFieldTable =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
FieldCount: Word;
ClassTable: PFieldClassTable;
// Fields: array[Word] of TFieldInfo; Elements have variant size!
{ should be array[Word] of TFieldinfo; but Elements have variant size! force at least proper alignment }
Fields: array[0..0] of TFieldInfo;
end;
function GetVMTSize(AClass: TClass): integer;
@ -488,15 +501,19 @@ begin
end;
end;
Result:=Result+'}';
FieldInfo := PFieldInfo(Pointer(FieldTable) + 6);
Result:=Result+' Fields={';
for i:=0 to FieldTable^.FieldCount-1 do begin
if i>0 then Result:=Result+',';
Result:=Result+IntToStr(i)+':Name="'+FieldInfo^.Name+'"'
+':Offset='+IntToStr(FieldInfo^.FieldOffset);
Inc(Pointer(FieldInfo), 7 + Length(FieldInfo^.Name));
FieldInfo := @FieldTable^.Fields;
Result := Result + ' Fields={';
for i := 0 to FieldTable^.FieldCount-1 do begin
if i > 0 then Result:=Result+',';
Result := Result + IntToStr(i)
+ ':Name="' + FieldInfo^.Name + '"'
+ ':Offset=' +IntToStr(FieldInfo^.FieldOffset);
FieldInfo := @FieldInfo^.Name + 1 + Length(FieldInfo^.Name);
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
FieldInfo := Align(FieldInfo, SizeOf(Pointer));
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
end;
Result:=Result+'}';
Result := Result+'}';
end;
//------------------------------------------------------------------------------
@ -998,8 +1015,12 @@ begin
NewFieldTable^.ClassTable:=NewClassTable;
// set vmtTypeInfo
TypeDataSize:=SizeOf(TTypeData)+2; // TTypeData + one word for new prop count
TypeInfoSize:=SizeOf(TTypeKind)+1+length(NewClassName)+TypeDataSize;
TypeDataSize := SizeOf(TTypeData) + 2; // TTypeData + one word for new prop count
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
if TypeDataSize and (SizeOf(Pointer) - 1) <> 0
then Inc(TypeDataSize, SizeOf(Pointer)); // a few bytes to much, but atleast enough
{$endif}
TypeInfoSize := SizeOf(TTypeKind) + 1 + length(NewClassName) + TypeDataSize;
{$warnings off}
if SizeOf(TTypeKind)<>1 then
raise Exception.Create('CreateNewClass SizeOf(TTypeInfo^.Kind)<>1');
@ -1022,6 +1043,9 @@ begin
NewTypeData^.PropCount:=GetTypeData(NewTypeData^.ParentInfo)^.PropCount;
NewTypeData^.UnitName:=NewUnitName;
AddedPropCount:=PWord(@(NewTypeData^.UnitName)+Length(NewTypeData^.UnitName)+1);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
AddedPropCount := Align(AddedPropCount, SizeOf(Pointer));
{$endif}
AddedPropCount^:=0;
// copy the standard methods

View File

@ -1589,6 +1589,17 @@ end;
// -----------------------------------------------------------
function AlignToPtr(const p: Pointer): Pointer;
begin
{$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
Result := Align(p, SizeOf(Pointer));
{$ELSE}
Result := p;
{$ENDIF}
end;
// -----------------------------------------------------------
var
PropertyEditorMapperList:TList;
PropertyClassList:TList;
@ -1619,6 +1630,7 @@ var
TypeInfo: PTypeInfo;
TypeData: PTypeData;
PropInfo: PPropInfo;
PropData: ^TPropData;
CurCount, i: integer;
//CurParent: TClass;
begin
@ -1633,10 +1645,10 @@ begin
// read all property infos of current class
TypeData:=GetTypeData(TypeInfo);
// skip unitname
PropInfo:=(@TypeData^.UnitName+Length(TypeData^.UnitName)+1);
PropData:=AlignToPtr(Pointer(@TypeData^.UnitName)+Length(TypeData^.UnitName)+1);
// read property count
CurCount:=PWord(PropInfo)^;
inc(PtrInt(PropInfo),SizeOf(Word));
CurCount:=PropData^.PropCount;
PropInfo:=@PropData^.PropList;
{writeln('TPropInfoList.Create D ',CurCount,' TypeData^.ClassType=',DbgS(TypeData^.ClassType));
writeln('TPropInfoList.Create E ClassName="',TypeData^.ClassType.ClassName,'"',
@ -1667,7 +1679,7 @@ begin
end;
// point PropInfo to next propinfo record.
// Located at Name[Length(Name)+1] !
PropInfo:=PPropInfo(pointer(@PropInfo^.Name)+PByte(@PropInfo^.Name)^+1);
PropInfo:=PPropInfo(AlignToPtr(pointer(@PropInfo^.Name)+PByte(@PropInfo^.Name)^+1));
dec(CurCount);
end;
TypeInfo:=TypeData^.ParentInfo;
@ -2889,9 +2901,11 @@ end;
function TEnumPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
var
L: Longint;
TypeData: PTypeData;
begin
L := OrdValue;
with GetTypeData(GetPropType)^ do
TypeData := GetTypeData(GetPropType);
with TypeData^ do
if (L < MinValue) or (L > MaxValue) then L := MaxValue;
Result := GetEnumName(GetPropType, L);
end;

View File

@ -1962,7 +1962,17 @@ begin
ExponentAndSign:=Exponent or ((e.ExponentAndSign and $8000) shr 4);
// i386 extended has leading 1, double has not (shl 1)
// i386 has 64 bit, double has 52 bit (shr 12)
Mantissa:=(e.Mantissa shl 1) shr 12;
{$IFDEF FPC_REQUIRES_PROPER_ALIGNMENT}
{$IFDEF ENDIAN_BIG}
// accessing Mantissa will couse trouble, copy it first
System.Move(e.Mantissa, Mantissa, SizeOf(Mantissa));
Mantissa := (Mantissa shl 1) shr 12;
{$ELSE ENDIAN_BIG}
Mantissa := (e.Mantissa shl 1) shr 12;
{$ENDIF ENDIAN_BIG}
{$ELSE FPC_REQUIRES_PROPER_ALIGNMENT}
Mantissa := (e.Mantissa shl 1) shr 12;
{$ENDIF FPC_REQUIRES_PROPER_ALIGNMENT}
// put together
QWord(Result):=Mantissa or (qword(ExponentAndSign) shl 52);
end;
@ -2405,22 +2415,20 @@ begin
end;
function TLRSObjectReader.ReadFloat: Extended;
{$ifdef Endian_BIG}
{$ifndef FPC_HAS_TYPE_EXTENDED}
var
e: array[1..10] of byte;
{$endif}
begin
{$ifdef Endian_BIG}
if SizeOf(extended)=10 then begin
Read(Result, 10);
ReverseBytes(@Result,10);
end else begin
Read(e,10);
Result:=ConvertLRSExtendedToDouble(@e);
end;
{$else not Endian_BIG}
{$ifdef FPC_HAS_TYPE_EXTENDED}
Read(Result, 10);
{$endif}
{$ifdef ENDIAN_BIG}
ReverseBytes(@Result, 10);
{$endif ENDIAN_BIG}
{$else FPC_HAS_TYPE_EXTENDED}
Read(e, 10);
Result := ConvertLRSExtendedToDouble(@e);
{$endif FPC_HAS_TYPE_EXTENDED}
end;
function TLRSObjectReader.ReadSingle: Single;

View File

@ -739,6 +739,7 @@ procedure TPkgManager.OnApplicationIdle(Sender: TObject);
begin
if (Screen.ActiveCustomForm<>nil)
and (fsModal in Screen.ActiveCustomForm.FormState) then exit;
if PackageGraph = nil then Exit;
PackageGraph.CloseUnneededPackages;
end;