Recent

Author Topic: [CLOSED] Code cleanup at procedure fpc_dynarray_setlength  (Read 1447 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 409
[CLOSED] Code cleanup at procedure fpc_dynarray_setlength
« on: February 08, 2024, 12:37:04 pm »
procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
  dimcount : sizeint;dims : pdynarrayindex);[Public,Alias:'FPC_DYNARR_SETLENGTH']; compilerproc;
contains the following lines:
Code: Pascal  [Select][+][-]
  1. ...
  2. newp:=getmem(size);
  3. fillchar(newp^,sizeof(tdynarray),0);
  4. ...
  5. newp^.refcount:=1;
  6. newp^.high:=dims[0]-1;
  7. ...

Because
Code: Pascal  [Select][+][-]
  1. tdynarray = { packed } record
  2.   refcount : ptrint;
  3.   high : tdynarrayindex;
  4. end;
the "fillchar(newp^,sizeof(tdynarray),0);" line is equivalent to "newp^.refcount:=0;newp^.high:=0;". Later in code we have "newp^.refcount:=1;newp^.high:=dims[0]-1;" which makes the presence of the fillchar line useless.
The following patch removes the fillchar line.
« Last Edit: February 11, 2024, 10:05:23 am by lagprogramming »

PascalDragon

  • Hero Member
  • *****
  • Posts: 6395
  • Compiler Developer
Re: Code cleanup at procedure fpc_dynarray_setlength
« Reply #1 on: February 08, 2024, 09:11:59 pm »
The following patch removes the fillchar line.

This is called safe programming in case the record should ever be extended and also to ensure that any potential padding bytes are cleared as well.

d2010

  • Sr. Member
  • ****
  • Posts: 264
Re: [CLOSED] Code cleanup at procedure fpc_dynarray_setlength
« Reply #2 on: March 30, 2026, 07:42:24 am »
Please How to prefix conditional out-off-function?
C:Q1=I need declare prefixCaller on outside of function , is inside all lines-with-caller?
C:Q2=I need declare entire code of "Lista_variabilelor_locale" is totally depends by var-c2lisp_generate_namelist_of_localvars_from_setq?.
Best regards..

My definition prefixCaller ==c2lisp_generate_namelist_of_localvars_from_setq
If c2lisp_generate_namelist_of_localvars_from_setq<>1 then
the function "Lista_variabilelor_locale" is totally not used.
Tne Entire-code of "Lista_variabilelor_locale" depends too much
variabile-switch
c2lisp_generate_namelist_of_localvars_from_setq:integer=0;
(== is good reason, )
That I need skip-all-callers of function  "Lista_variabilelor_locale".
Best regards..


Code: Pascal  [Select][+][-]
  1. Function Lista_variabilelor_locale(s185:string):boolean;
  2.   Var o109:Boolean;
  3.       nth,gap,dwg:integer;
  4.       t110,p110:pchar;
  5.  
  6.    function OdSetLocale_h:boolean;
  7.               Begin
  8.                     result:=true;
  9.                End;
  10.  
  11.  Begin
  12.       t110:=nil;
  13.       p110:=nil;
  14.       result:=false;
  15.       gap:=000;
  16.       if (length(s185)<01)or(s185[1]=#00) then exit;
  17.       result:=true;
  18.       o109:=((la=opl_SetQ)or(last_la=opl_unsconst));
  19.       if (length(s185)>2) and (s185[01]='$')and(s185[2]='$') then delete(s185,1,2);
  20.       Sho_lower(s185);
  21.       if (c2lisp_generate_namelist_of_localvars_from_setq=1)and((length(s185)+2)<length(v_c2lisp_namelist_of_localvars_setqS)) then
  22.              Begin dwg:=pos(' '+s185+' ',v_c2lisp_namelist_of_localvars_setqS);
  23.                    if (dwg>00) then v_c2lisp_namelist_of_localvars_setqS:= v_c2lisp_namelist_of_localvars_setqS + s185+' ';
  24.               End;
  25. End;//off-Lista_variabilelor_locale("")
  26. ---------------------------------------------------------------------
  27.  
  28.  
  29. Function expr_all_setqOp:NavTree;
  30. var tr:NavTree;op:EnodeType; docec:word;
  31. Begin tr:=expr_else_pt_cond_semnalizat_de_pct_si_virgula; docec:=00;
  32.     while la=opl_Setq do
  33.                begin  op := laVal3.typ;
  34.                       if (length(laVal3.s)>0) then  Lista_variabilelor_locale(laVal3.s);
  35.                       if (tr<kzeropin) then tr:=makeNode_id0(op,tr,kNavtreeNil) else
  36.       if (tr>kzeropin)and(tr^.typ IN [ConstNd,SetqNd])and(length(tr^.soh)>02)and(tr^.soh[1]='$')and(tr^.soh[2]='$')
  37.                           then tr^.typ:=op
  38.                           else tr:=makeNode_id0(op,tr,kNavtreeNil);
  39.                       LexiconManager(000);
  40.                       tr^.right:=expr_else_pt_cond_semnalizat_de_pct_si_virgula();
  41.               end;{while}
  42.  
  43.            result:=tr;
  44. end;//off("asociativitate de la dreapta la stanga")
  45.  
  46.  
  47. Function check_if_last_is_var(cc1,cc2,cc3,cc4:char;tokr:ENodeType):ENodeType;
  48. Begin
  49.            inc(pig);
  50.            la:=opl_setq;
  51.            if (last_la<>opl_unsconst)or(length(last_laVal.s)<01)or(last_laVal.s[1]<>'$')
  52.               then begin dec(pig,2);
  53.                scho.q:='1234';
  54.                scho.q[1]:=cc1;
  55.                scho.q[2]:=cc2;
  56.                scho.q[3]:=cc3;
  57.                scho.q[4]:=cc4;
  58.                 dfn_get_error('.eExpectedVariable for'+scho.q,000);
  59.               end;
  60.           if (length(laVal3.s)>0) then
  61.                lista_variabilelor_locale(laVal3.s);
  62.              {actualizare lista_var_defun}
  63.            if (tokr<EndPrognkNd) then inc(tokr);  
  64.            check_if_last_is_var:=tokr;
  65.  End;
  66.  
  67.  
  68.  
  69.  
  70. Procedure LexiconNumericPlus(lef_or_right:integer);
  71. var laOld:tap_laval22safearray; opentok:word;la13:TokenOpl;
  72. begin  opentok:=00;
  73.      laOld:=laVal3;
  74.      la13:=la;
  75.      inc(pig);
  76.   if (lef_or_right=2623)and(cAsiHost20hdi.car[pig]<>'+')and(cAsiHost20hdi.car[pig]='=') then
  77.        Begin la:=opl_Setq; laVal3:=laOld; laVal3.strR:=00; laVal3.strL:=0;
  78.              inc(pig);
  79.              laVal3.typ:=AddEqNd;LaVal3.restype:=RT_NONE;
  80.              Exit;
  81.           End;
  82.   if (lef_or_right=2628)and(cAsiHost20hdi.car[pig]<>'+')and(cAsiHost20hdi.car[pig]='=') then
  83.        Begin la:=opl_Setq; laVal3:=laOld; laVal3.strR:=00; laVal3.strL:=0;
  84.              inc(pig);
  85.              laVal3.typ:=AddEqNd;LaVal3.restype:=RT_NONE;
  86.              Exit;
  87.           End;
  88.   if (lef_or_right=2628)and(cAsiHost20hdi.car[pig]<>'+') then
  89.        Begin la:=opl_addo; laVal3:=laOld; laVal3.strR:=00; laVal3.strL:=0;
  90.              laVal3.typ:=PlusNd;LaVal3.restype:=RT_NONE;
  91.              Exit;
  92.           End;
  93.  
  94.  
  95.      if (length(laVal3.s)>0) then  lista_variabilelor_locale(laVal3.s);
  96.           Case cAsiHost20hdi.car[pig] of
  97. '+':begin inc(pig);
  98.       if (la13=opl_unsconst)and(laOld.resType=RT_ATOMVAR) then opentok:=02 else
  99.         Begin LexiconManager(225);
  100.              if (la=opl_unsconst)and(laVal3.resType=RT_ATOMVAR) then opentok:=01;
  101.         End;
  102.       Case opentok of
  103. 01: Begin la:=opl_Unary;laVal3.strR:=00; laVal3.strL:=0;
  104.            laVal3.typ:=incrementNd;LaVal3.restype:=RT_DECPOST; End; //off(" ++boca ")
  105. 02: Begin la:=opl_Unary;laVal3:=laOld; laVal3.strR:=00; laVal3.strL:=0;
  106.          laVal3.typ:=incrementNd;LaVal3.restype:=RT_DECSUFX End; //off(" boca++ ")
  107.   else      dfn_get_error('eVap!t180errorA..eCannot use ++ without variabile name',0000);
  108.      end;
  109.    end;//case( "++");_
  110. '=':laVal3.typ:=check_if_last_is_var('+=',laVal3.typ);
  111. '0'..'9':Begin if (la=opl_Lparen) then  Begin ParseNumberNegative(false); end else
  112.                 Begin  la := opl_Addo;laVal3.typ:=PlusNd;End;
  113.          End;
  114. else Begin la := opl_AddO;laVal3.typ:=PlusNd;End;
  115.            end;{+,+=}
  116. End;
  117.  



 

TinyPortal © 2005-2018