From 23d170b9efd9f27233a37c2d09d9d7cbb02b6112 Mon Sep 17 00:00:00 2001 From: Carlo Sirna Date: Fri, 21 Oct 2016 20:47:50 +0200 Subject: [PATCH 1/2] Fixed Access violation with 64 bit compilers and updated defines for most recent delphi versions --- superobject.pas | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/superobject.pas b/superobject.pas index 4cd4282..58503b0 100644 --- a/superobject.pas +++ b/superobject.pas @@ -89,7 +89,8 @@ {$ifend} {$if defined(VER230) or defined(VER240) or defined(VER250) or - defined(VER260) or defined(VER270) or defined(VER280)} + defined(VER260) or defined(VER270) or defined(VER280) or + defined(VER290) or defined(VER300) or defined(VER310) } {$define VER210ORGREATER} {$define VER230ORGREATER} {$ifend} @@ -6143,7 +6144,7 @@ function TSuperRttiContext.FromJson(TypeInfo: PTypeInfo; const obj: ISuperObject procedure FromDynArray; var - i: Integer; + i: NativeInt; // Integer; bugfix: see comment on DynArraySetLength p: Pointer; pb: PByte; val: TValue; @@ -6155,7 +6156,13 @@ function TSuperRttiContext.FromJson(TypeInfo: PTypeInfo; const obj: ISuperObject begin i := obj.AsArray.Length; p := nil; - DynArraySetLength(p, TypeInfo, 1, @i); + // This is the declaration of DynArraySetLength: + // procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt: NativeInt; lengthVec: PNativeint); + // + // THE LAST ARGUMENT MUST POINT TO A NATIVEINT (32/64 bit integer depending on client architecture) not to a 32 bit integer! + // + // when i was declared as a plain 32 bit integer, it was causing random access violations if compiled for Win64 + DynArraySetLength( p, TypeInfo, 1, @i); pb := p; typ := GetTypeData(TypeInfo); if typ.elType <> nil then From 67c5f29aadf929a9c8b18b3e2517d0c5dfc3d218 Mon Sep 17 00:00:00 2001 From: Carlo Sirna Date: Fri, 21 Oct 2016 21:13:56 +0200 Subject: [PATCH 2/2] Bug in ParseFile: fmShareDenyWrite used in a wrong way --- superobject.pas | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/superobject.pas b/superobject.pas index 58503b0..5e437af 100644 --- a/superobject.pas +++ b/superobject.pas @@ -95,13 +95,13 @@ {$define VER230ORGREATER} {$ifend} -{$if defined(FPC) or defined(VER170) or defined(VER180) or defined(VER190) +{$if defined(FPC) or defined(VER170) or defined(VER180) or defined(VER190) or defined(VER200) or defined(VER210ORGREATER)} {$DEFINE HAVE_INLINE} {$ifend} {$if defined(VER210ORGREATER)} - {$define HAVE_RTTI} + {$define HAVE_RTTI} {$ifend} {$if defined(VER230ORGREATER)} @@ -1182,8 +1182,7 @@ function ObjectFindNext(var F: TSuperObjectIter): boolean; procedure ObjectFindClose(var F: TSuperObjectIter); begin - if Assigned(F.Ite) then - FreeAndNil(F.Ite); + FreeAndNil(F.Ite); F.val := nil; end; @@ -2247,7 +2246,7 @@ class function TSuperObject.ParseFile(const FileName: string; strict: Boolean; var stream: TFileStream; begin - stream := TFileStream.Create(FileName, fmOpenRead, fmShareDenyWrite); + stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite ); try Result := ParseStream(stream, strict, partial, this, options, put, dt); finally