#1 2016-06-18 05:56:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,695
Website

FPC parameter passing for dynamic arrays

This discussion is about how we may fix/include in mORMot.pas one of the latest breaking change in trunk.

http://wiki.freepascal.org/User_Changes … e_pointers states:

Dynamic array parameters are passed like pointers
Old behaviour: When using the default calling convention, dynamic array parameters were passed on the stack.
New behaviour: When using the default calling convention, dynamic array parameters are now passed like a pointer (which may be in a register).
Reason: Delphi compatibility, ensuring that SetPointerProp can be used with dynamic arrays.
Remedy: Adjust pure assembler routines that have dynamic array parameters.
svn: 30870, 30878, 31622

I guess we have to remove $ifdef FPC in the following statement:

      if (ValueType in [smvRecord{$ifndef NOVARIANTS},smvVariant{$endif}
          {$ifdef FPC},smvDynArray{$endif}]) or
         (ValueDirection in [smdVar,smdOut]) or
         ((ValueDirection=smdResult) and (ValueType in CONST_ARGS_RESULT_BY_REF)) then
        Include(ValueKindAsm,vPassedByReference);

Then we should fix also

      case ValueType of
      smvDynArray:
        {$ifdef FPC} // FIXME ?
          if vIsObjArray in ValueKindAsm then
             DynArrays[IndexVar].Init(ArgTypeInfo,V^) else
             DynArrays[IndexVar].Init(ArgTypeInfo,V);
        {$else}
        DynArrays[IndexVar].Init(ArgTypeInfo,V^);
        {$endif}

and

        // alf: TODO: fix smvDynArray as expected by fpc\compiler\i386\cpupara.pas
        {$ifdef FPC}or ((ValueType in [smvRecord,smvDynArray]) and
          not (vPassedByReference in ValueKindAsm)){$endif} then begin
        // this parameter would go on the stack
        InStackOffset := ArgsSizeInStack;
        inc(ArgsSizeInStack,SizeInStack);
      end else begin

Offline

#2 2016-06-18 08:30:55

hnb
Member
Registered: 2015-06-15
Posts: 291

Re: FPC parameter passing for dynamic arrays

The change for dynamic arrays is right move. The topic is quiet old. See my post (in 2013 my post was +/- ignored...):

http://lists.freepascal.org/fpc-devel/2 … 32586.html

You can try to track how it is done in PascalScript (with my patch for this breaking change):

http://forum.lazarus.freepascal.org/ind … #msg196402
http://bugs.freepascal.org/view.php?id=29230


best regards,
Maciej Izak

Offline

#3 2016-06-18 10:14:48

AOG
Member
Registered: 2014-02-24
Posts: 447

Re: FPC parameter passing for dynamic arrays

If the weather remains as bad as it is right now, I will have a look at it again ... ;-)
Tests will be done with FPC fixes (3.0.1/3.0.2) and FPC trunk (with PPTypeInfo).

Offline

Board footer

Powered by FluxBB