Browse Source

* updated for dynarr:=nil

peter 23 years ago
parent
commit
1338dbd992
2 changed files with 25 additions and 9 deletions
  1. 5 1
      rtl/inc/compproc.inc
  2. 20 8
      rtl/inc/dynarr.inc

+ 5 - 1
rtl/inc/compproc.inc

@@ -50,6 +50,7 @@ function fpc_shortstr_to_chararray(arraysize: longint; const src: ShortString):
 
 
 function fpc_dynarray_length(p : pointer) : tdynarrayindex; compilerproc;
 function fpc_dynarray_length(p : pointer) : tdynarrayindex; compilerproc;
 function fpc_dynarray_high(p : pointer) : tdynarrayindex; compilerproc;
 function fpc_dynarray_high(p : pointer) : tdynarrayindex; compilerproc;
+procedure fpc_dynarray_clear(var p : pointer;ti : pointer); compilerproc;
 procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); compilerproc;
 procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); compilerproc;
 procedure fpc_dynarray_incr_ref(var p : pointer); compilerproc;
 procedure fpc_dynarray_incr_ref(var p : pointer); compilerproc;
 procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
 procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
@@ -255,7 +256,10 @@ Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;var Buf); compiler
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.12  2001-12-03 21:39:20  peter
+  Revision 1.13  2002-01-21 20:16:08  peter
+    * updated for dynarr:=nil
+
+  Revision 1.12  2001/12/03 21:39:20  peter
     * freemem(var) -> freemem(value)
     * freemem(var) -> freemem(value)
 
 
   Revision 1.11  2001/09/29 21:32:47  jonas
   Revision 1.11  2001/09/29 21:32:47  jonas

+ 20 - 8
rtl/inc/dynarr.inc

@@ -53,19 +53,28 @@ function fpc_dynarray_high(p : pointer) : tdynarrayindex;[Public,Alias:'FPC_DYNA
   end;
   end;
 
 
 { releases and finalizes the data of a dyn. array and sets p to nil }
 { releases and finalizes the data of a dyn. array and sets p to nil }
-procedure dynarray_clear(var p : pdynarray;ti : pdynarraytypeinfo);
+procedure fpc_dynarray_clear(var p : pointer;ti : pointer); [Public,Alias:'FPC_DYNARRAY_CLEAR']; {$ifdef hascompilerproc} compilerproc; {$endif}
   begin
   begin
+     if p=nil then
+       exit;
+
      { skip kind and name }
      { skip kind and name }
-     inc(pointer(ti),ord(ti^.namelen));
+     inc(pointer(ti),ord(pdynarraytypeinfo(ti)^.namelen));
 
 
      { finalize all data }
      { finalize all data }
-     int_finalizearray(pointer(p)+sizeof(tdynarray),ti^.eletype,p^.high+1,ti^.elesize);
+     int_finalizearray(p+sizeof(tdynarray),pdynarraytypeinfo(ti)^.eletype,pdynarray(p)^.high+1,
+                       pdynarraytypeinfo(ti)^.elesize);
 
 
      { release the data }
      { release the data }
-     freemem(p,sizeof(tdynarray)+(p^.high+1)*ti^.elesize);
+     freemem(p,sizeof(tdynarray)+(pdynarray(p)^.high+1)*pdynarraytypeinfo(ti)^.elesize);
      p:=nil;
      p:=nil;
   end;
   end;
 
 
+{$ifdef hascompilerproc}
+{ alias for internal use }
+Procedure fpc_dynarray_clear (var p : pointer;ti : pointer);[external name 'FPC_DYNARRAY_CLEAR'];
+{$endif hascompilerproc}
+
 
 
 procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer);[Public,Alias:'FPC_DYNARRAY_DECR_REF']; {$ifdef hascompilerproc} compilerproc; {$endif}
 procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer);[Public,Alias:'FPC_DYNARRAY_DECR_REF']; {$ifdef hascompilerproc} compilerproc; {$endif}
   var
   var
@@ -81,7 +90,7 @@ procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer);[Public,Alias:'FPC
      { decr. ref. count }
      { decr. ref. count }
      { should we remove the array? }
      { should we remove the array? }
      if declocked(realp^.refcount) then
      if declocked(realp^.refcount) then
-       dynarray_clear(realp,pdynarraytypeinfo(ti));
+       fpc_dynarray_clear(realp,pdynarraytypeinfo(ti));
      p := nil;
      p := nil;
   end;
   end;
 
 
@@ -156,7 +165,7 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
           { if the new dimension is 0, we've to release all data }
           { if the new dimension is 0, we've to release all data }
           if dims[dimcount-1]=0 then
           if dims[dimcount-1]=0 then
             begin
             begin
-               dynarray_clear(realp,pdynarraytypeinfo(pti));
+               fpc_dynarray_clear(realp,pdynarraytypeinfo(pti));
                p:=nil;
                p:=nil;
                exit;
                exit;
             end;
             end;
@@ -186,7 +195,7 @@ procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
                { if the array is now removed             }
                { if the array is now removed             }
                { fpc_dynarray_decr_ref(p,ti); }
                { fpc_dynarray_decr_ref(p,ti); }
                if declocked(realp^.refcount) then
                if declocked(realp^.refcount) then
-                 dynarray_clear(realp,pdynarraytypeinfo(ti));
+                 fpc_dynarray_clear(realp,pdynarraytypeinfo(ti));
             end
             end
           else if dims[dimcount-1]<>realp^.high+1 then
           else if dims[dimcount-1]<>realp^.high+1 then
             begin
             begin
@@ -252,7 +261,10 @@ function fpc_dynarray_copy(var p : pointer;ti : pointer;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.14  2001-12-29 15:51:11  jonas
+  Revision 1.15  2002-01-21 20:16:08  peter
+    * updated for dynarr:=nil
+
+  Revision 1.14  2001/12/29 15:51:11  jonas
     * correctly check for 0-size dynarray in previous patch
     * correctly check for 0-size dynarray in previous patch
 
 
   Revision 1.13  2001/12/28 14:19:07  jonas
   Revision 1.13  2001/12/28 14:19:07  jonas