Browse Source

* Change ptrint to ptruint, because pointers are being compared and
therefore $7fffffff<$80000001 should be true.
- Remove final traces of custom memory management.

git-svn-id: trunk@4569 -

daniel 19 years ago
parent
commit
c11d547b15

+ 62 - 62
packages/base/paszlib/infblock.pas

@@ -103,7 +103,7 @@ begin
   if (c <> nil) then
   if (c <> nil) then
     c^ := s.check;
     c^ := s.check;
   if (s.mode = BTREE) or (s.mode = DTREE) then
   if (s.mode = BTREE) or (s.mode = DTREE) then
-    ZFREE(z, s.sub.trees.blens);
+    freemem(s.sub.trees.blens);
   if (s.mode = CODES) then
   if (s.mode = CODES) then
     inflate_codes_free(s.sub.decode.codes, z);
     inflate_codes_free(s.sub.decode.codes, z);
 
 
@@ -131,26 +131,26 @@ function inflate_blocks_new(var z : z_stream;
 var
 var
   s : pInflate_blocks_state;
   s : pInflate_blocks_state;
 begin
 begin
-  s := pInflate_blocks_state( ZALLOC(z,1, sizeof(inflate_blocks_state)) );
+  new(s);
   if (s = nil) then
   if (s = nil) then
   begin
   begin
     inflate_blocks_new := s;
     inflate_blocks_new := s;
     exit;
     exit;
   end;
   end;
-  s^.hufts := huft_ptr( ZALLOC(z, sizeof(inflate_huft), MANY) );
+  getmem(s^.hufts,sizeof(inflate_huft)*MANY);
 
 
   if (s^.hufts = nil) then
   if (s^.hufts = nil) then
   begin
   begin
-    ZFREE(z, s);
+    dispose(s);
     inflate_blocks_new := nil;
     inflate_blocks_new := nil;
     exit;
     exit;
   end;
   end;
 
 
-  s^.window := Pbyte( ZALLOC(z, 1, w) );
+  getmem(s^.window,w);
   if (s^.window = nil) then
   if (s^.window = nil) then
   begin
   begin
-    ZFREE(z, s^.hufts);
-    ZFREE(z, s);
+    freemem(s^.hufts);
+    dispose(s);
     inflate_blocks_new := nil;
     inflate_blocks_new := nil;
     exit;
     exit;
   end;
   end;
@@ -198,10 +198,10 @@ begin
   b := s.bitb;
   b := s.bitb;
   k := s.bitk;
   k := s.bitk;
   q := s.write;
   q := s.write;
-  if ptrint(q) < ptrint(s.read) then
-    m := cardinal(ptrint(s.read)-ptrint(q)-1)
+  if ptruint(q) < ptruint(s.read) then
+    m := cardinal(ptruint(s.read)-ptruint(q)-1)
   else
   else
-    m := cardinal(ptrint(s.zend)-ptrint(q));
+    m := cardinal(ptruint(s.zend)-ptruint(q));
 
 
 { decompress an inflated block }
 { decompress an inflated block }
 
 
@@ -223,7 +223,7 @@ begin
             s.bitb := b;
             s.bitb := b;
             s.bitk := k;
             s.bitk := k;
             z.avail_in := n;
             z.avail_in := n;
-            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+            Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
             z.next_in := p;
             z.next_in := p;
             s.write := q;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             inflate_blocks := inflate_flush(s,z,r);
@@ -275,7 +275,7 @@ begin
                   s.bitb := b;
                   s.bitb := b;
                   s.bitk := k;
                   s.bitk := k;
                   z.avail_in := n;
                   z.avail_in := n;
-                  Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+                  Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
                   z.next_in := p;
                   z.next_in := p;
                   s.write := q;
                   s.write := q;
                   inflate_blocks := inflate_flush(s,z,r);
                   inflate_blocks := inflate_flush(s,z,r);
@@ -315,7 +315,7 @@ begin
               s.bitb := b;
               s.bitb := b;
               s.bitk := k;
               s.bitk := k;
               z.avail_in := n;
               z.avail_in := n;
-              Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+              Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
               z.next_in := p;
               z.next_in := p;
               s.write := q;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               inflate_blocks := inflate_flush(s,z,r);
@@ -337,7 +337,7 @@ begin
             s.bitb := b;
             s.bitb := b;
             s.bitk := k;
             s.bitk := k;
             z.avail_in := n;
             z.avail_in := n;
-            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+            Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
             z.next_in := p;
             z.next_in := p;
             s.write := q;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             inflate_blocks := inflate_flush(s,z,r);
@@ -358,7 +358,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -386,7 +386,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -399,10 +399,10 @@ begin
           if (q = s.zend) and (s.read <> s.window) then
           if (q = s.zend) and (s.read <> s.window) then
           begin
           begin
             q := s.window;
             q := s.window;
-            if ptrint(q) < ptrint(s.read) then
-              m := cardinal(ptrint(s.read)-ptrint(q)-1)
+            if ptruint(q) < ptruint(s.read) then
+              m := cardinal(ptruint(s.read)-ptruint(q)-1)
             else
             else
-              m := cardinal(ptrint(s.zend)-ptrint(q));
+              m := cardinal(ptruint(s.zend)-ptruint(q));
           end;
           end;
 
 
           if (m = 0) then
           if (m = 0) then
@@ -411,19 +411,19 @@ begin
             s.write := q;
             s.write := q;
             r := inflate_flush(s,z,r);
             r := inflate_flush(s,z,r);
             q := s.write;
             q := s.write;
-            if ptrint(q) < ptrint(s.read) then
-              m := cardinal(ptrint(s.read)-ptrint(q)-1)
+            if ptruint(q) < ptruint(s.read) then
+              m := cardinal(ptruint(s.read)-ptruint(q)-1)
             else
             else
-              m := cardinal(ptrint(s.zend)-ptrint(q));
+              m := cardinal(ptruint(s.zend)-ptruint(q));
 
 
             {WRAP}
             {WRAP}
             if (q = s.zend) and (s.read <> s.window) then
             if (q = s.zend) and (s.read <> s.window) then
             begin
             begin
               q := s.window;
               q := s.window;
-              if ptrint(q) < ptrint(s.read) then
-                m := cardinal(ptrint(s.read)-ptrint(q)-1)
+              if ptruint(q) < ptruint(s.read) then
+                m := cardinal(ptruint(s.read)-ptruint(q)-1)
               else
               else
-                m := cardinal(ptrint(s.zend)-ptrint(q));
+                m := cardinal(ptruint(s.zend)-ptruint(q));
             end;
             end;
 
 
             if (m = 0) then
             if (m = 0) then
@@ -432,7 +432,7 @@ begin
               s.bitb := b;
               s.bitb := b;
               s.bitk := k;
               s.bitk := k;
               z.avail_in := n;
               z.avail_in := n;
-              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+              Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
               z.next_in := p;
               z.next_in := p;
               s.write := q;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               inflate_blocks := inflate_flush(s,z,r);
@@ -454,13 +454,13 @@ begin
         if (s.sub.left = 0) then
         if (s.sub.left = 0) then
         begin
         begin
           {$IFDEF ZLIB_DEBUG}
           {$IFDEF ZLIB_DEBUG}
-          if (ptrint(q) >= ptrint(s.read)) then
+          if (ptruint(q) >= ptruint(s.read)) then
             Tracev('inflate:       stored end '+
             Tracev('inflate:       stored end '+
-                IntToStr(z.total_out + ptrint(q) - ptrint(s.read)) + ' total out')
+                IntToStr(z.total_out + ptruint(q) - ptruint(s.read)) + ' total out')
           else
           else
             Tracev('inflate:       stored end '+
             Tracev('inflate:       stored end '+
-                    IntToStr(z.total_out + ptrint(s.zend) - ptrint(s.read) +
-                    ptrint(q) - ptrint(s.window)) +  ' total out');
+                    IntToStr(z.total_out + ptruint(s.zend) - ptruint(s.read) +
+                    ptruint(q) - ptruint(s.window)) +  ' total out');
           {$ENDIF}
           {$ENDIF}
           if s.last then
           if s.last then
             s.mode := DRY
             s.mode := DRY
@@ -482,7 +482,7 @@ begin
             s.bitb := b;
             s.bitb := b;
             s.bitk := k;
             s.bitk := k;
             z.avail_in := n;
             z.avail_in := n;
-            Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+            Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
             z.next_in := p;
             z.next_in := p;
             s.write := q;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             inflate_blocks := inflate_flush(s,z,r);
@@ -506,7 +506,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -514,7 +514,7 @@ begin
         end;
         end;
   {$endif}
   {$endif}
         t := 258 + (t and $1f) + ((t shr 5) and $1f);
         t := 258 + (t and $1f) + ((t shr 5) and $1f);
-        s.sub.trees.blens := Pcardinalarray( ZALLOC(z, t, sizeof(cardinal)) );
+        getmem(s.sub.trees.blens,t*sizeof(cardinal));
         if (s.sub.trees.blens = nil) then
         if (s.sub.trees.blens = nil) then
         begin
         begin
           r := Z_MEM_ERROR;
           r := Z_MEM_ERROR;
@@ -522,7 +522,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -558,7 +558,7 @@ begin
               s.bitb := b;
               s.bitb := b;
               s.bitk := k;
               s.bitk := k;
               z.avail_in := n;
               z.avail_in := n;
-              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+              Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
               z.next_in := p;
               z.next_in := p;
               s.write := q;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               inflate_blocks := inflate_flush(s,z,r);
@@ -586,7 +586,7 @@ begin
                                 s.sub.trees.tb, s.hufts^, z);
                                 s.sub.trees.tb, s.hufts^, z);
         if (t <> Z_OK) then
         if (t <> Z_OK) then
         begin
         begin
-          ZFREE(z, s.sub.trees.blens);
+          freemem(s.sub.trees.blens);
           r := t;
           r := t;
           if (r = Z_DATA_ERROR) then
           if (r = Z_DATA_ERROR) then
             s.mode := BLKBAD;
             s.mode := BLKBAD;
@@ -594,7 +594,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -630,7 +630,7 @@ begin
               s.bitb := b;
               s.bitb := b;
               s.bitk := k;
               s.bitk := k;
               z.avail_in := n;
               z.avail_in := n;
-              Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+              Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
               z.next_in := p;
               z.next_in := p;
               s.write := q;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               inflate_blocks := inflate_flush(s,z,r);
@@ -680,7 +680,7 @@ begin
                 s.bitb := b;
                 s.bitb := b;
                 s.bitk := k;
                 s.bitk := k;
                 z.avail_in := n;
                 z.avail_in := n;
-                Inc(z.total_in, ptrint(p)-ptrint(z.next_in));
+                Inc(z.total_in, ptruint(p)-ptruint(z.next_in));
                 z.next_in := p;
                 z.next_in := p;
                 s.write := q;
                 s.write := q;
                 inflate_blocks := inflate_flush(s,z,r);
                 inflate_blocks := inflate_flush(s,z,r);
@@ -706,7 +706,7 @@ begin
             if (i + j > 258 + (t and $1f) + ((t shr 5) and $1f)) or
             if (i + j > 258 + (t and $1f) + ((t shr 5) and $1f)) or
                ((c = 16) and (i < 1)) then
                ((c = 16) and (i < 1)) then
             begin
             begin
-              ZFREE(z, s.sub.trees.blens);
+              freemem(s.sub.trees.blens);
               s.mode := BLKBAD;
               s.mode := BLKBAD;
               z.msg := 'invalid bit length repeat';
               z.msg := 'invalid bit length repeat';
               r := Z_DATA_ERROR;
               r := Z_DATA_ERROR;
@@ -714,7 +714,7 @@ begin
               s.bitb := b;
               s.bitb := b;
               s.bitk := k;
               s.bitk := k;
               z.avail_in := n;
               z.avail_in := n;
-              Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+              Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
               z.next_in := p;
               z.next_in := p;
               s.write := q;
               s.write := q;
               inflate_blocks := inflate_flush(s,z,r);
               inflate_blocks := inflate_flush(s,z,r);
@@ -740,7 +740,7 @@ begin
           t := inflate_trees_dynamic(257 + (t and $1f),
           t := inflate_trees_dynamic(257 + (t and $1f),
                   1 + ((t shr 5) and $1f),
                   1 + ((t shr 5) and $1f),
                   s.sub.trees.blens^, bl, bd, tl, td, s.hufts^, z);
                   s.sub.trees.blens^, bl, bd, tl, td, s.hufts^, z);
-          ZFREE(z, s.sub.trees.blens);
+          freemem(s.sub.trees.blens);
           if (t <> Z_OK) then
           if (t <> Z_OK) then
           begin
           begin
             if (t = cardinal(Z_DATA_ERROR)) then
             if (t = cardinal(Z_DATA_ERROR)) then
@@ -750,7 +750,7 @@ begin
             s.bitb := b;
             s.bitb := b;
             s.bitk := k;
             s.bitk := k;
             z.avail_in := n;
             z.avail_in := n;
-            Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+            Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
             z.next_in := p;
             z.next_in := p;
             s.write := q;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             inflate_blocks := inflate_flush(s,z,r);
@@ -768,7 +768,7 @@ begin
             s.bitb := b;
             s.bitb := b;
             s.bitk := k;
             s.bitk := k;
             z.avail_in := n;
             z.avail_in := n;
-            Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+            Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
             z.next_in := p;
             z.next_in := p;
             s.write := q;
             s.write := q;
             inflate_blocks := inflate_flush(s,z,r);
             inflate_blocks := inflate_flush(s,z,r);
@@ -787,7 +787,7 @@ begin
         s.bitb := b;
         s.bitb := b;
         s.bitk := k;
         s.bitk := k;
         z.avail_in := n;
         z.avail_in := n;
-        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+        Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
         z.next_in := p;
         z.next_in := p;
         s.write := q;
         s.write := q;
 
 
@@ -805,18 +805,18 @@ begin
         b := s.bitb;
         b := s.bitb;
         k := s.bitk;
         k := s.bitk;
         q := s.write;
         q := s.write;
-        if ptrint(q) < ptrint(s.read) then
-          m := cardinal(ptrint(s.read)-ptrint(q)-1)
+        if ptruint(q) < ptruint(s.read) then
+          m := cardinal(ptruint(s.read)-ptruint(q)-1)
         else
         else
-          m := cardinal(ptrint(s.zend)-ptrint(q));
+          m := cardinal(ptruint(s.zend)-ptruint(q));
         {$IFDEF ZLIB_DEBUG}
         {$IFDEF ZLIB_DEBUG}
-        if (ptrint(q) >= ptrint(s.read)) then
+        if (ptruint(q) >= ptruint(s.read)) then
           Tracev('inflate:       codes end '+
           Tracev('inflate:       codes end '+
-              IntToStr(z.total_out + ptrint(q) - ptrint(s.read)) + ' total out')
+              IntToStr(z.total_out + ptrint(q) - ptruint(s.read)) + ' total out')
         else
         else
           Tracev('inflate:       codes end '+
           Tracev('inflate:       codes end '+
-                  IntToStr(z.total_out + ptrint(s.zend) - ptrint(s.read) +
-                  ptrint(q) - ptrint(s.window)) +  ' total out');
+                  IntToStr(z.total_out + ptruint(s.zend) - ptruint(s.read) +
+                  ptruint(q) - ptruint(s.window)) +  ' total out');
         {$ENDIF}
         {$ENDIF}
         if (not s.last) then
         if (not s.last) then
         begin
         begin
@@ -847,10 +847,10 @@ begin
         q := s.write;
         q := s.write;
 
 
         { not needed anymore, we are done:
         { not needed anymore, we are done:
-        if ptrint(q) < ptrint(s.read) then
-          m := cardinal(ptrint(s.read)-ptrint(q)-1)
+        if ptruint(q) < ptruint(s.read) then
+          m := cardinal(ptruint(s.read)-ptruint(q)-1)
         else
         else
-          m := cardinal(ptrint(s.zend)-ptrint(q));
+          m := cardinal(ptruint(s.zend)-ptruint(q));
         }
         }
 
 
         if (s.read <> s.write) then
         if (s.read <> s.write) then
@@ -859,7 +859,7 @@ begin
           s.bitb := b;
           s.bitb := b;
           s.bitk := k;
           s.bitk := k;
           z.avail_in := n;
           z.avail_in := n;
-          Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+          Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
           z.next_in := p;
           z.next_in := p;
           s.write := q;
           s.write := q;
           inflate_blocks := inflate_flush(s,z,r);
           inflate_blocks := inflate_flush(s,z,r);
@@ -876,7 +876,7 @@ begin
         s.bitb := b;
         s.bitb := b;
         s.bitk := k;
         s.bitk := k;
         z.avail_in := n;
         z.avail_in := n;
-        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+        Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
         z.next_in := p;
         z.next_in := p;
         s.write := q;
         s.write := q;
         inflate_blocks := inflate_flush(s,z,r);
         inflate_blocks := inflate_flush(s,z,r);
@@ -889,7 +889,7 @@ begin
         s.bitb := b;
         s.bitb := b;
         s.bitk := k;
         s.bitk := k;
         z.avail_in := n;
         z.avail_in := n;
-        Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+        Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
         z.next_in := p;
         z.next_in := p;
         s.write := q;
         s.write := q;
         inflate_blocks := inflate_flush(s,z,r);
         inflate_blocks := inflate_flush(s,z,r);
@@ -902,7 +902,7 @@ begin
       s.bitb := b;
       s.bitb := b;
       s.bitk := k;
       s.bitk := k;
       z.avail_in := n;
       z.avail_in := n;
-      Inc(z.total_in, ptrint(p) - ptrint(z.next_in));
+      Inc(z.total_in, ptruint(p) - ptruint(z.next_in));
       z.next_in := p;
       z.next_in := p;
       s.write := q;
       s.write := q;
       inflate_blocks := inflate_flush(s,z,r);
       inflate_blocks := inflate_flush(s,z,r);
@@ -917,9 +917,9 @@ function inflate_blocks_free(s : pInflate_blocks_state;
                              var z : z_stream) : integer;
                              var z : z_stream) : integer;
 begin
 begin
   inflate_blocks_reset(s^, z, nil);
   inflate_blocks_reset(s^, z, nil);
-  ZFREE(z, s^.window);
-  ZFREE(z, s^.hufts);
-  ZFREE(z, s);
+  freemem(s^.window);
+  freemem(s^.hufts);
+  dispose(s);
   {$IFDEF ZLIB_DEBUG}
   {$IFDEF ZLIB_DEBUG}
   Trace('inflate:   blocks freed');
   Trace('inflate:   blocks freed');
   {$ENDIF}  
   {$ENDIF}  

+ 2 - 2
packages/base/paszlib/infcodes.pas

@@ -42,7 +42,7 @@ function inflate_codes_new (bl : cardinal;
 var
 var
  c : pInflate_codes_state;
  c : pInflate_codes_state;
 begin
 begin
-  c := pInflate_codes_state( ZALLOC(z,1,sizeof(inflate_codes_state)) );
+  new(c);
   if (c <> Z_NULL) then
   if (c <> Z_NULL) then
   begin
   begin
     c^.mode := START;
     c^.mode := START;
@@ -564,7 +564,7 @@ end;
 procedure inflate_codes_free(c : pInflate_codes_state;
 procedure inflate_codes_free(c : pInflate_codes_state;
                              var z : z_stream);
                              var z : z_stream);
 begin
 begin
-  ZFREE(z, c);
+  dispose(c);
   {$IFDEF ZLIB_DEBUG}  
   {$IFDEF ZLIB_DEBUG}  
   Tracev('inflate:       codes free');
   Tracev('inflate:       codes free');
   {$ENDIF}
   {$ENDIF}

+ 11 - 11
packages/base/paszlib/inftrees.pas

@@ -450,7 +450,7 @@ var
   v : Pcardinalarray;     { work area for huft_build }
   v : Pcardinalarray;     { work area for huft_build }
 begin
 begin
   hn := 0;
   hn := 0;
-  v := Pcardinalarray( ZALLOC(z, 19, sizeof(cardinal)) );
+  getmem(v,19*sizeof(cardinal));
   if (v = nil) then
   if (v = nil) then
   begin
   begin
     inflate_trees_bits := Z_MEM_ERROR;
     inflate_trees_bits := Z_MEM_ERROR;
@@ -468,7 +468,7 @@ begin
       z.msg := 'incomplete dynamic bit lengths tree';
       z.msg := 'incomplete dynamic bit lengths tree';
       r := Z_DATA_ERROR;
       r := Z_DATA_ERROR;
     end;
     end;
-  ZFREE(z, v);
+  freemem(v);
   inflate_trees_bits := r;
   inflate_trees_bits := r;
 end;
 end;
 
 
@@ -491,7 +491,7 @@ var
 begin
 begin
   hn := 0;
   hn := 0;
   { allocate work area }
   { allocate work area }
-  v := Pcardinalarray( ZALLOC(z, 288, sizeof(cardinal)) );
+  getmem(v,288*sizeof(cardinal));
   if (v = nil) then
   if (v = nil) then
   begin
   begin
     inflate_trees_dynamic := Z_MEM_ERROR;
     inflate_trees_dynamic := Z_MEM_ERROR;
@@ -511,7 +511,7 @@ begin
         r := Z_DATA_ERROR;
         r := Z_DATA_ERROR;
       end;
       end;
 
 
-    ZFREE(z, v);
+    freemem(v);
     inflate_trees_dynamic := r;
     inflate_trees_dynamic := r;
     exit;
     exit;
   end;
   end;
@@ -539,14 +539,14 @@ begin
           z.msg := 'empty distance tree with lengths';
           z.msg := 'empty distance tree with lengths';
           r := Z_DATA_ERROR;
           r := Z_DATA_ERROR;
         end;
         end;
-    ZFREE(z, v);
+    freemem(v);
     inflate_trees_dynamic := r;
     inflate_trees_dynamic := r;
     exit;
     exit;
 {$endif}
 {$endif}
   end;
   end;
 
 
   { done }
   { done }
-  ZFREE(z, v);
+  freemem(v);
   inflate_trees_dynamic := Z_OK;
   inflate_trees_dynamic := Z_OK;
 end;
 end;
 
 
@@ -730,16 +730,16 @@ begin
     f := 0;
     f := 0;
 
 
     { allocate memory }
     { allocate memory }
-    c := pFixed_table( ZALLOC(z, 288, sizeof(cardinal)) );
+    getmem(c,288*sizeof(cardinal));
     if (c = nil) then
     if (c = nil) then
     begin
     begin
       inflate_trees_fixed := Z_MEM_ERROR;
       inflate_trees_fixed := Z_MEM_ERROR;
       exit;
       exit;
     end;
     end;
-    v := Pcardinalarray( ZALLOC(z, 288, sizeof(cardinal)) );
+    getmem(v,288*sizeof(cardinal));
     if (v = nil) then
     if (v = nil) then
     begin
     begin
-      ZFREE(z, c);
+      freemem(c);
       inflate_trees_fixed := Z_MEM_ERROR;
       inflate_trees_fixed := Z_MEM_ERROR;
       exit;
       exit;
     end;
     end;
@@ -765,8 +765,8 @@ begin
                fixed_mem, f, v^);
                fixed_mem, f, v^);
 
 
     { done }
     { done }
-    ZFREE(z, v);
-    ZFREE(z, c);
+    freemem(v);
+    freemem(c);
     fixed_built := True;
     fixed_built := True;
   end;
   end;
   bl := fixed_bl;
   bl := fixed_bl;

+ 0 - 40
packages/base/paszlib/zbase.pas

@@ -281,10 +281,6 @@ type
      blocks : pInflate_blocks_state;    { current inflate_blocks state }
      blocks : pInflate_blocks_state;    { current inflate_blocks state }
    end;
    end;
 
 
-type
-  alloc_func = function(opaque : pointer; items : cardinal; size : cardinal) : pointer;
-  free_func = procedure(opaque : pointer; address : pointer);
-
 type
 type
   z_streamp = ^z_stream;
   z_streamp = ^z_stream;
   z_stream = record
   z_stream = record
@@ -311,21 +307,6 @@ type
    opaque before calling the init function. All other fields are set by the
    opaque before calling the init function. All other fields are set by the
    compression library and must not be updated by the application.
    compression library and must not be updated by the application.
 
 
-   The opaque value provided by the application will be passed as the first
-   parameter for calls of zalloc and zfree. This can be useful for custom
-   memory management. The compression library attaches no meaning to the
-   opaque value.
-
-   zalloc must return Z_NULL if there is not enough memory for the object.
-   On 16-bit systems, the functions zalloc and zfree must be able to allocate
-   exactly 65536 bytes, but will not be required to allocate more than this
-   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
-   pointers returned by zalloc for objects of exactly 65536 bytes *must*
-   have their offset normalized to zero. The default allocation function
-   provided by this library ensures this (see zutil.c). To reduce memory
-   requirements and avoid any allocation of 64K objects, at the expense of
-   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
-
    The fields total_in and total_out can be used for statistics or
    The fields total_in and total_out can be used for statistics or
    progress reports. After compression, total_in holds the total size of
    progress reports. After compression, total_in holds the total size of
    the uncompressed data and may be saved for use in the decompressor
    the uncompressed data and may be saved for use in the decompressor
@@ -418,12 +399,6 @@ function zlibVersion : string;
 
 
 function zError(err : integer) : string;
 function zError(err : integer) : string;
 
 
-function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
-
-procedure ZFREE (var strm : z_stream; ptr : pointer);
-
-procedure TRY_FREE (var strm : z_stream; ptr : pointer);
-
 const
 const
   ZLIB_VERSION : string[10] = '1.1.2';
   ZLIB_VERSION : string[10] = '1.1.2';
 
 
@@ -508,19 +483,4 @@ begin
     WriteLn(x);
     WriteLn(x);
 end;
 end;
 
 
-function ZALLOC (var strm : z_stream; items : cardinal; size : cardinal) : pointer;
-begin
-  getmem(ZALLOC,items*size);
-end;
-
-procedure ZFREE (var strm : z_stream; ptr : pointer);
-begin
-  freemem(ptr);
-end;
-
-procedure TRY_FREE (var strm : z_stream; ptr : pointer);
-begin
-  freemem(ptr);
-end;
-
 end.
 end.

+ 20 - 23
packages/base/paszlib/zdeflate.pas

@@ -71,10 +71,7 @@ function deflateInit_(strm : z_streamp;
 
 
 function deflateInit (var strm : z_stream; level : integer) : integer;
 function deflateInit (var strm : z_stream; level : integer) : integer;
 
 
-{  Initializes the internal stream state for compression. The fields
-   zalloc, zfree and opaque must be initialized before by the caller.
-   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
-   use default allocation functions.
+{  Initializes the internal stream state for compression.
 
 
      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
    1 gives best speed, 9 gives best compression, 0 gives no compression at
    1 gives best speed, 9 gives best compression, 0 gives no compression at
@@ -196,7 +193,7 @@ function deflateInit2_(var strm : z_stream;
                        stream_size : integer) : integer;
                        stream_size : integer) : integer;
 
 
 {  This is another version of deflateInit with more compression options. The
 {  This is another version of deflateInit with more compression options. The
-   fields next_in, zalloc, zfree and opaque must be initialized before by
+   fields next_in, and opaque must be initialized before by
    the caller.
    the caller.
 
 
      The method parameter is the compression method. It must be Z_DEFLATED in
      The method parameter is the compression method. It must be Z_DEFLATED in
@@ -295,7 +292,7 @@ function deflateCopy (dest : z_streamp;
 
 
      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
-   (such as zalloc being NULL). msg is left unchanged in both source and
+   (such as getmem returns nil). msg is left unchanged in both source and
    destination. }
    destination. }
 
 
 {EXPORT}
 {EXPORT}
@@ -307,7 +304,7 @@ function deflateReset (var strm : z_stream) : integer;
    that may have been set by deflateInit2.
    that may have been set by deflateInit2.
 
 
       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
       deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NIL). }
+   stream state was inconsistent (such as getmem or state being NIL). }
 
 
 
 
 {EXPORT}
 {EXPORT}
@@ -557,7 +554,7 @@ begin
     exit;
     exit;
   end;
   end;
 
 
-  s := deflate_state_ptr (ZALLOC(strm, 1, sizeof(deflate_state)));
+  getmem(s,sizeof(deflate_state));
   if (s = nil) then
   if (s = nil) then
   begin
   begin
     deflateInit2_ := Z_MEM_ERROR;
     deflateInit2_ := Z_MEM_ERROR;
@@ -576,13 +573,13 @@ begin
   s^.hash_mask := s^.hash_size - 1;
   s^.hash_mask := s^.hash_size - 1;
   s^.hash_shift :=  ((s^.hash_bits+MIN_MATCH-1) div MIN_MATCH);
   s^.hash_shift :=  ((s^.hash_bits+MIN_MATCH-1) div MIN_MATCH);
 
 
-  s^.window := Pbytearray (ZALLOC(strm, s^.w_size, 2*sizeof(Byte)));
-  s^.prev   := pzPosfArray (ZALLOC(strm, s^.w_size, sizeof(Pos)));
-  s^.head   := pzPosfArray (ZALLOC(strm, s^.hash_size, sizeof(Pos)));
+  getmem(s^.window,s^.w_size*2*sizeof(byte));
+  getmem(s^.prev,s^.w_size*sizeof(pos));
+  getmem(s^.head,s^.hash_size*sizeof(pos));
 
 
   s^.lit_bufsize := 1 shl (memLevel + 6); { 16K elements by default }
   s^.lit_bufsize := 1 shl (memLevel + 6); { 16K elements by default }
 
 
-  overlay := Pwordarray (ZALLOC(strm, s^.lit_bufsize, sizeof(word)+2));
+  getmem(overlay,s^.lit_bufsize*(sizeof(word)+2));
   s^.pending_buf := Pbytearray(overlay);
   s^.pending_buf := Pbytearray(overlay);
   s^.pending_buf_size := longint(s^.lit_bufsize) * (sizeof(word)+longint(2));
   s^.pending_buf_size := longint(s^.lit_bufsize) * (sizeof(word)+longint(2));
 
 
@@ -718,7 +715,7 @@ begin
 
 
   strm.total_out := 0;
   strm.total_out := 0;
   strm.total_in := 0;
   strm.total_in := 0;
-  strm.msg := '';      { use zfree if we ever allocate msg dynamically }
+  strm.msg := '';      { use freemem if we ever allocate msg dynamically }
   strm.data_type := Z_UNKNOWN;
   strm.data_type := Z_UNKNOWN;
 
 
   s := deflate_state_ptr(strm.state);
   s := deflate_state_ptr(strm.state);
@@ -1045,12 +1042,12 @@ begin
   end;
   end;
 
 
   { Deallocate in reverse order of allocations: }
   { Deallocate in reverse order of allocations: }
-  TRY_FREE(strm, s^.pending_buf);
-  TRY_FREE(strm, s^.head);
-  TRY_FREE(strm, s^.prev);
-  TRY_FREE(strm, s^.window);
+  freemem(s^.pending_buf);
+  freemem(s^.head);
+  freemem(s^.prev);
+  freemem(s^.window);
 
 
-  ZFREE(strm, s);
+  freemem(s);
   strm.state := Z_NULL;
   strm.state := Z_NULL;
 
 
   if status = BUSY_STATE then
   if status = BUSY_STATE then
@@ -1087,7 +1084,7 @@ begin
   ss := deflate_state_ptr(source^.state);
   ss := deflate_state_ptr(source^.state);
   dest^ := source^;
   dest^ := source^;
 
 
-  ds := deflate_state_ptr( ZALLOC(dest^, 1, sizeof(deflate_state)) );
+  getmem(ds,sizeof(deflate_state));
   if (ds = Z_NULL) then
   if (ds = Z_NULL) then
   begin
   begin
     deflateCopy := Z_MEM_ERROR;
     deflateCopy := Z_MEM_ERROR;
@@ -1097,10 +1094,10 @@ begin
   ds^ := ss^;
   ds^ := ss^;
   ds^.strm := dest;
   ds^.strm := dest;
 
 
-  ds^.window := Pbytearray ( ZALLOC(dest^, ds^.w_size, 2*sizeof(Byte)) );
-  ds^.prev   := pzPosfArray ( ZALLOC(dest^, ds^.w_size, sizeof(Pos)) );
-  ds^.head   := pzPosfArray ( ZALLOC(dest^, ds^.hash_size, sizeof(Pos)) );
-  overlay := Pwordarray ( ZALLOC(dest^, ds^.lit_bufsize, sizeof(word)+2) );
+  getmem(ds^.window,ds^.w_size*2*sizeof(byte));
+  getmem(ds^.prev,ds^.w_size*sizeof(pos));
+  getmem(ds^.head,ds^.hash_size*sizeof(pos));
+  getmem(overlay,ds^.lit_bufsize*(sizeof(word)+2));
   ds^.pending_buf := Pbytearray ( overlay );
   ds^.pending_buf := Pbytearray ( overlay );
 
 
   if (ds^.window = Z_NULL) or (ds^.prev = Z_NULL) or (ds^.head = Z_NULL)
   if (ds^.window = Z_NULL) or (ds^.prev = Z_NULL) or (ds^.head = Z_NULL)

+ 5 - 10
packages/base/paszlib/zinflate.pas

@@ -17,10 +17,7 @@ uses
 
 
 function inflateInit(var z : z_stream) : integer;
 function inflateInit(var z : z_stream) : integer;
 
 
-{    Initializes the internal stream state for decompression. The fields
-   zalloc, zfree and opaque must be initialized before by the caller.  If
-   zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
-   allocation functions.
+{    Initializes the internal stream state for decompression.
 
 
      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
      inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
    enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
    enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
@@ -44,9 +41,7 @@ function inflateInit2(var z: z_stream;
                        windowBits : integer) : integer;
                        windowBits : integer) : integer;
 
 
 {
 {
-     This is another version of inflateInit with an extra parameter. The
-   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
-   before by the caller.
+     This is another version of inflateInit with an extra parameter.
 
 
      The windowBits parameter is the base two logarithm of the maximum window
      The windowBits parameter is the base two logarithm of the maximum window
    size (the size of the history buffer).  It should be in the range 8..15 for
    size (the size of the history buffer).  It should be in the range 8..15 for
@@ -85,7 +80,7 @@ function inflateReset(var z : z_stream) : integer;
    The stream will keep attributes that may have been set by inflateInit2.
    The stream will keep attributes that may have been set by inflateInit2.
 
 
       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
       inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NULL).
+   stream state was inconsistent (such as getmem or state being NULL).
 }
 }
 
 
 
 
@@ -235,7 +230,7 @@ begin
   end;
   end;
   if (z.state^.blocks <> Z_NULL) then
   if (z.state^.blocks <> Z_NULL) then
     inflate_blocks_free(z.state^.blocks, z);
     inflate_blocks_free(z.state^.blocks, z);
-  ZFREE(z, z.state);
+  dispose(z.state);
   z.state := Z_NULL;
   z.state := Z_NULL;
   {$IFDEF ZLIB_DEBUG}
   {$IFDEF ZLIB_DEBUG}
   Tracev('inflate: end');
   Tracev('inflate: end');
@@ -259,7 +254,7 @@ begin
   { SetLength(strm.msg, 255); }
   { SetLength(strm.msg, 255); }
   z.msg := '';
   z.msg := '';
 
 
-  z.state := pInternal_state( ZALLOC(z,1,sizeof(internal_state)) );
+  new(z.state);
   if z.state=nil then
   if z.state=nil then
   begin
   begin
     inflateInit2_ := Z_MEM_ERROR;
     inflateInit2_ := Z_MEM_ERROR;