ahausladen / JsonDataObjects

JSON parser for Delphi 2009 and newer
MIT License
413 stars 160 forks source link

JsonDataObjects failing on ARM64 #18

Closed kstrophus closed 8 years ago

kstrophus commented 8 years ago

Hi Andy,

This library is not functioning correctly on iOS 64 bit targets (ARM64). All other targets seem to work fine. I have some sample code at the end of this post.

I have dug a bit and found this so far:

class procedure TJsonBaseObject.StrToJSONStr(const AppendMethod: TWriterAppendMethod; const S: string); 2266: //EndP := P + Length(S); 2267: EndP := P + PLongInt(@PByte(S)[-4])^;

Line 2267 is calculating huge EndP values in ARM64 and causing the while loops to crash. However, if I comment out line 2267 and use line 2266 then EndP correctly points to the line end.

Next:

procedure TJsonOutputWriter.TJsonStringBuilder.DoneConvertToString(var S: string); 6803: Pointer(S) := P; // keep the RefCnt=1

In ARM64 after line 6803 executes S is not updated and still points to the blank text it was initialized to earlier in this method. Line 6803 seems to have no effect when investigated in the debugger.

Sample code:

procedure TForm1.Button1Click(Sender: TObject); var jo: TJSONObject; begin jo := TJSONObject.Create;

jo.I['ACCOUNTID'] := 225; jo.B['BOOLVAL'] := False; jo.S['VERSION'] := '1.0'; jo.S['LOCATION'] := 'RVK'; jo.S['USERID'] := 'S.TESTER'; jo.S['GARBAGE#####'] := 'Ooga\booga'; jo.S['SUBTOCALL'] := 'G2.WEB.CONNECT.SUB'; jo.D['DT'] := Now; jo.S['ACTION'] := 'CONNECT';

Memo1.Text := jo.ToJSON(true); // Crash if line 2267 is active, no crash if line 2266 is active. // When no crash then this always returns an empty string.

jo.Free; end;

ahausladen commented 8 years ago

I don't have any Apple device so I can't test it. I can only make assumptions. So fixing those bugs may take some time and commits. Embarcadero made LongWord and LongInt for ARM64 incompatible to Win32, ARM32 and Win64. In my opinion they broke it. On ARM64 SizeOf(LongInt) is 8, for all other platforms including Win64 it is 4.