[fpc-devel] (patch) An attempt to improve assignments/functionresult reuse

Thorsten Engler thorsten.engler at gmx.net
Sun Dec 9 03:10:30 CET 2007


> >> Are you sure with the strings?
> > 
> > Yes. Any function that returns a string is supplied with one more 
> > argument than it was declared. After calling the function, register 
> > eax (which is used to contain the non-parameter result) is not used.
> > Here is a simple example:
> 
> I'am not sure but there might be a reason why we did it this way.

For what it's worth, I noticed that difference as well. The following code
snippet describes Delphi's behavior (in regards to passing results as
parameters and limited to types covered by RTTI):

if Assigned(imeResult.ipeInfo) then
  if (imeResult.ipeInfo.Kind in [tkString, tkLString, tkWString, tkDynArray,
tkMethod, tkInterface, tkVariant])
    or ( (imeResult.ipeInfo.Kind in [tkArray, tkRecord, tkSet])
      and (imeResult.ipeAlignedSize > 4)
    ) then begin
      SetLength(imeParams, Succ(Length(imeParams)));
      IntfParam := @imeParams[High(imeParams)];
      IntfParam^ := imeResult;
      IntfParam.ipeFlags := [pfOut];
      FillParamInfo(IntfMethod, IntfParam);
      FillChar(imeResult, SizeOf(imeResult), 0);
      imeResultIn := riInParam;
    end;

The Delphi approach leads to faster and simpler code as the result doesn't
need to be protected by an implicit try/finally.

Cheers,
Thorsten




More information about the fpc-devel mailing list