Pascal Script: Dynamic array result types cause Access Violation
Original Reporter info from Mantis: dezlov
-
Reporter name: Denis Kozlov
Original Reporter info from Mantis: dezlov
- Reporter name: Denis Kozlov
Description:
Functions which use dynamic array types as results produce Access Violation in fpc_dynarray_setlength
at assembler line 0040B511 833800 cmpl $0x0,(%eax)
.
Example function signature:
type TTestArrayType = Array of String;
function TestReturn: TTestArrayType;
It is worth noting that using dynamic array types as parameters, or changing the calling convention to cdecl
works fine.
Tested on Windows 7 and 10:
* Lazarus 1.4.4 + FPC 2.6.4 = WORKS
* Lazarus 1.8.4 + FPC 3.0.4 = FAILS
* Lazarus 2.0.0 + FPC 3.0.4 = FAILS
Call stack:
#0 fpc_dynarray_setlength at :0
#1 TESTRETURN(<error reading variable: Cannot access memory at address 0x0>) at project.pas:51
#2 REALCALL_REGISTER(0x4017e0, 0, 0, 0, 0xfffffffc, 0, 4, 0x0) at x86.inc:113
#3 TPSEXEC__INNERFUSECALL(0x0, 0x4017e0, CDREGISTER, 0x1826270, 0x183de80, <error reading variable>) at x86.inc:607
#4 DELPHIFUNCTIONPROC(0x18a18f0, 0x1826ad0, 0x1815600, 0x1815660, CDREGISTER) at uPSRuntime.pas:11972
#5 DELPHIFUNCTIONPROC_REGISTER(0x18a18f0, 0x1826ad0, 0x1815600, 0x1815660) at uPSRuntime.pas:11985
#6 TPSEXEC__RUNSCRIPT(<error reading variable>) at uPSRuntime.pas:7873
#7 TPSSCRIPT__EXECUTE(<error reading variable>) at uPSComponent.pas:678
#8 TTESTAPPLICATION__DORUN(<error reading variable>) at project.pas:87
#9 CUSTAPP$_$TCUSTOMAPPLICATION_$__$$_RUN at :0
#10 main at project.pas:119
Steps to reproduce:
Sample project attached.
Open project in Lazarus, click Run, and enjoy an Access Violation.
Mantis conversion info:
- Mantis ID: 35291
- Version: 2.0
- Monitored by: » dezlov (Denis Kozlov)