Skip to contentSkip to conversation

2.4.21 zlib merge #1 turboc

PATCH New Jörn Engel 1 participant 5 messages Jun 14, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4.21 zlib merge #1 turboc

Hi Marcelo!

This patchset hat already made it into Linus' tree. It merges the interesting bits from zlib 1.1.4 into the kernel zlib, which is based on 1.1.3.

Remove Turbo C workaround and fix modulo operation.

Jörn

Signature · 24 lines
If you're willing to restrict the flexibility of your approach,
you can almost always do something better.
-- John Carmack

--- linux-2.4.20/lib/zlib_inflate/infcodes.c~zlib_merge_turboc	2002-11-29 00:53:15.000000000 +0100
+++ linux-2.4.20/lib/zlib_inflate/infcodes.c	2003-06-10 16:59:38.000000000 +0200
@@ -146,15 +146,9 @@
       DUMPBITS(j)
       c->mode = COPY;
     case COPY:          /* o: copying bytes in window, waiting for space */
-#ifndef __TURBOC__ /* Turbo C bug for following expression */
-      f = (uInt)(q - s->window) < c->sub.copy.dist ?
-          s->end - (c->sub.copy.dist - (q - s->window)) :
-          q - c->sub.copy.dist;
-#else
       f = q - c->sub.copy.dist;
-      if ((uInt)(q - s->window) < c->sub.copy.dist)
-        f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
-#endif
+      while (f < s->window)             /* modulo window size-"while" instead */
+        f += s->end - s->window;        /* of "if" handles invalid distances */
       while (c->len)
       {
         NEEDOUT
#1 lore raw

PATCH 1/1 2.4.21 zlib merge #2 return

Fix one return code in huft_build.

Jörn

Signature · 13 lines
Those who come seeking peace without a treaty are plotting.
-- Sun Tzu

--- linux-2.4.20/lib/zlib_inflate/inftrees.c~zlib_merge_return	2002-11-29 00:53:15.000000000 +0100
+++ linux-2.4.20/lib/zlib_inflate/inftrees.c	2003-06-10 17:00:25.000000000 +0200
@@ -228,7 +228,7 @@
 
         /* allocate new table */
         if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
-          return Z_MEM_ERROR;   /* not enough memory */
+          return Z_DATA_ERROR;  /* overflow of MANY */
         u[h] = q = hp + *hn;
         *hn += z;
#2 lore raw

PATCH 1/1 2.4.21 zlib merge #3 inffast

Reformat zlib_inflate_fast a bit, change one conditional into a loop and fix one of three conditional cases.

Jörn

Signature · 64 lines
Beware of bugs in the above code; I have only proved it correct, but
not tried it.
-- Donald Knuth

--- linux-2.4.20/lib/zlib_inflate/inffast.c~zlib_merge_inffast	2002-11-29 00:53:15.000000000 +0100
+++ linux-2.4.20/lib/zlib_inflate/inffast.c	2003-06-10 17:00:43.000000000 +0200
@@ -88,28 +88,41 @@
 
             /* do the copy */
             m -= c;
-            if ((uInt)(q - s->window) >= d)     /* offset before dest */
-            {                                   /*  just copy */
-              r = q - d;
-              *q++ = *r++;  c--;        /* minimum count is three, */
-              *q++ = *r++;  c--;        /*  so unroll loop a little */
-            }
-            else                        /* else offset after destination */
+            r = q - d;
+            if (r < s->window)                  /* wrap if needed */
             {
-              e = d - (uInt)(q - s->window); /* bytes from offset to end */
-              r = s->end - e;           /* pointer to offset */
-              if (c > e)                /* if source crosses, */
+              do {
+                r += s->end - s->window;        /* force pointer in window */
+              } while (r < s->window);          /* covers invalid distances */
+              e = s->end - r;
+              if (c > e)
               {
-                c -= e;                 /* copy to end of window */
+                c -= e;                         /* wrapped copy */
                 do {
-                  *q++ = *r++;
+                    *q++ = *r++;
                 } while (--e);
-                r = s->window;          /* copy rest from start of window */
+                r = s->window;
+                do {
+                    *q++ = *r++;
+                } while (--c);
+              }
+              else                              /* normal copy */
+              {
+                *q++ = *r++;  c--;
+                *q++ = *r++;  c--;
+                do {
+                    *q++ = *r++;
+                } while (--c);
               }
             }
-            do {                        /* copy all or what's left */
-              *q++ = *r++;
-            } while (--c);
+            else                                /* normal copy */
+            {
+              *q++ = *r++;  c--;
+              *q++ = *r++;  c--;
+              do {
+                *q++ = *r++;
+              } while (--c);
+            }
             break;
           }
           else if ((e & 64) == 0)
#3 lore raw

PATCH 1/1 2.4.21 zlib merge #4 windowBits

Disallow windowBits <9 (windowBits=9 would hit a bug) for deflate and do the same for ppp.

Jörn

Signature · 25 lines
Anything that can go wrong, will.
-- Finagle's Law

--- linux-2.4.20/lib/zlib_deflate/deflate.c~zlib_merge_magic	2003-06-10 12:37:17.000000000 +0200
+++ linux-2.4.20/lib/zlib_deflate/deflate.c	2003-06-10 17:01:02.000000000 +0200
@@ -215,7 +215,7 @@
         windowBits = -windowBits;
     }
     if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
-        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+        windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
 	strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
         return Z_STREAM_ERROR;
     }
--- linux-2.4.20/include/linux/ppp-comp.h~zlib_merge_magic	1999-08-06 19:44:11.000000000 +0200
+++ linux-2.4.20/include/linux/ppp-comp.h	2003-06-10 17:01:02.000000000 +0200
@@ -177,7 +177,7 @@
 #define CI_DEFLATE_DRAFT	24	/* value used in original draft RFC */
 #define CILEN_DEFLATE		4	/* length of its config option */
 
-#define DEFLATE_MIN_SIZE	8
+#define DEFLATE_MIN_SIZE	9
 #define DEFLATE_MAX_SIZE	15
 #define DEFLATE_METHOD_VAL	8
 #define DEFLATE_SIZE(x)		(((x) >> 4) + DEFLATE_MIN_SIZE)
#4 lore raw

PATCH 1/1 2.4.21 zlib changes #1 memlevel

Reduce MAX_MEM_LEVEL to 8. This reduces zlib memory consumption by 128k (from ~400k to ~270k) at the theoretical cost of worse compression. No code currently in the kernel actually uses the better compression, so the practical cost is zero.

Jörn

Signature · 14 lines
A victorious army first wins and then seeks battle.
-- Sun Tzu

--- linux-2.4.20/include/linux/zconf.h~zlib_memlevel	2002-11-29 00:53:15.000000000 +0100
+++ linux-2.4.20/include/linux/zconf.h	2003-06-10 17:01:16.000000000 +0200
@@ -35,7 +35,7 @@
 
 /* Maximum value for memLevel in deflateInit2 */
 #ifndef MAX_MEM_LEVEL
-#  define MAX_MEM_LEVEL 9
+#  define MAX_MEM_LEVEL 8
 #endif
 
 /* Maximum value for windowBits in deflateInit2 and inflateInit2.