remobjects/pascalscript

Dynamic array result types cause Access Violation in FPC

dezlov opened this issue · 1 comments

Functions which use dynamic array types as results produce Access Violation when array is being accessed.

Consider registering the following type and function:

type
  TTestArrayType = Array of String;

function TestReturn: TTestArrayType;
begin
  SetLength(Result, 1); // <<<--- ACCESS VIOLATION !!!
  Result[0] := 'TestReturn';
end; 

Then, simply call TestReturn in a script to get Access Violation in fpc_dynarray_setlength at assembler line cmpl $0x0,(%eax).

It is worth noting that using dynamic array types as parameters, or changing the calling convention to cdecl works fine.

Tested with FPC 3.0.4 on Windows 7 and 10 64-bit.

Could it be due to some changes in FPC calling convention related to how dynamic arrays are passed to functions, i.e. registers vs stack?

May be related to FPC issue: https://bugs.freepascal.org/view.php?id=29230