Commit 46ce5d9 for gzip
commit 46ce5d97c49158fbbe051fdbfd6d4ba4020bb9ed
Author: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu Nov 12 14:48:11 2026 -0800
gzip: tell other modules about buffer alignment
* gzip.c (BUFFER_ALIGNED): Move from here ...
* gzip.h: ... to here.
(EXTERN, DECLARE): Remove, as they are more trouble than they’re
worth. All uses removed.
(inbuf, outbuf, window): Declare with alignment to help the compiler.
diff --git a/deflate.c b/deflate.c
index ef51e1c..b3c2b67 100644
--- a/deflate.c
+++ b/deflate.c
@@ -130,7 +130,7 @@ typedef unsigned IPos;
* save space in the various tables. IPos is used only for parameter passing.
*/
-/* DECLARE(uch, window, 2L*WSIZE); */
+/* extern Pos BUFFER_ALIGNED window[2 * WSIZE]; */
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least WSIZE
* bytes. With this organization, matches are limited to a distance of
@@ -139,13 +139,13 @@ typedef unsigned IPos;
* the window size to 64K, which is quite useful on MSDOS.
*/
-/* DECLARE(Pos, prev, WSIZE); */
+/* extern Pos prev[WSIZE]; */
/* Link to older string with same hash index. To limit the size of this
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K.
*/
-/* DECLARE(Pos, head, 1<<HASH_BITS); */
+/* extern Pos head[1 << HASH_BITS]; */
/* Heads of the hash chains or NIL. */
static ulg const window_size = 2 * WSIZE;
diff --git a/gzip.c b/gzip.c
index 7360f40..c49f9e3 100644
--- a/gzip.c
+++ b/gzip.c
@@ -170,21 +170,12 @@ gzip_unlinkat (_GL_ATTRIBUTE_MAYBE_UNUSED int fd, char const *file, int flags)
/* global buffers */
-/* With IBM_Z_DFLTCC, DEFLATE COMPRESSION works faster with
- page-aligned input and output buffers, and requires page-aligned
- windows; the alignment requirement is 4096. On other platforms
- alignment doesn't hurt, and alignment up to 4096 is portable so
- let's do that. */
-#if defined HAVE_C_ALIGNASOF || defined alignas
-# define BUFFER_ALIGNED alignas (4096)
-#else
-# define BUFFER_ALIGNED /**/
-#endif
-DECLARE(uch BUFFER_ALIGNED, inbuf, INBUFSIZ +INBUF_EXTRA);
-DECLARE(uch BUFFER_ALIGNED, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
-DECLARE(ush, d_buf, DIST_BUFSIZE);
-DECLARE(uch BUFFER_ALIGNED, window, 2L*WSIZE);
-DECLARE(ush, tab_prefix, 1L << BITS);
+/* See gzip.h for commentary on these. */
+uch BUFFER_ALIGNED inbuf[INBUFSIZ + INBUF_EXTRA];
+uch BUFFER_ALIGNED outbuf[OUTBUFSIZ + OUTBUF_EXTRA];
+ush d_buf[DIST_BUFSIZE];
+uch BUFFER_ALIGNED window[2 * WSIZE];
+ush tab_prefix[1 << BITS];
/* local variables */
diff --git a/gzip.h b/gzip.h
index 5d15594..724b46c 100644
--- a/gzip.h
+++ b/gzip.h
@@ -83,17 +83,36 @@ extern int method; /* compression method */
# define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
#endif
-#define EXTERN(type, array) extern type array[]
-#define DECLARE(type, array, size) type array[size]
+/* With IBM_Z_DFLTCC, DEFLATE COMPRESSION works faster with
+ page-aligned input and output buffers, and requires page-aligned
+ windows; the alignment requirement is 4096. On other platforms
+ alignment doesn't hurt, and alignment up to 4096 is portable so
+ let's do that. */
+#if defined HAVE_C_ALIGNASOF || defined alignas
+# define BUFFER_ALIGNED alignas (4096)
+#else
+# define BUFFER_ALIGNED /**/
+#endif
+
+/* Global buffers. */
+
+/* Input buffer. */
+extern uch BUFFER_ALIGNED inbuf[];
-EXTERN(uch, inbuf); /* input buffer */
-EXTERN(uch, outbuf); /* output buffer */
-EXTERN(ush, d_buf); /* buffer for distances, see trees.c */
-EXTERN(uch, window); /* Sliding window and suffix table (unlzw) */
+/* Output buffer. */
+extern uch BUFFER_ALIGNED outbuf[];
+
+/* Buffer for distances; see trees.c. */
+extern ush d_buf[];
+
+/* Sliding window and suffix table (unlzw). */
+extern uch BUFFER_ALIGNED window[];
#define tab_suffix window
+
#define tab_prefix prev /* hash link (see deflate.c) */
#define head (prev + WSIZE) /* hash head (see deflate.c) */
-EXTERN (ush, tab_prefix); /* prefix code (see unlzw.c) */
+/* prefix code (see unlzw.c) */
+extern ush tab_prefix[];
extern unsigned insize; /* valid bytes in inbuf */
extern unsigned inptr; /* index of next byte to be processed in inbuf */
diff --git a/trees.c b/trees.c
index 9c27a0e..e5bd3d5 100644
--- a/trees.c
+++ b/trees.c
@@ -251,9 +251,9 @@ static int base_dist[D_CODES];
/* First normalized distance for each code (0 = distance of 1) */
#define l_buf inbuf
-/* DECLARE(uch, l_buf, LIT_BUFSIZE); buffer for literals or lengths */
+/* extern uch BUFFER_ALIGNED l_buf[LIT_BUFSIZE]; literals or lengths */
-/* DECLARE(ush, d_buf, DIST_BUFSIZE); buffer for distances */
+/* extern ush d_buf[DIST_BUFSIZE]; distances */
static uch flag_buf[(LIT_BUFSIZE/8)];
/* flag_buf is a bit array distinguishing literals from lengths in
diff --git a/unlzw.c b/unlzw.c
index 4f37fcd..479ad4f 100644
--- a/unlzw.c
+++ b/unlzw.c
@@ -69,7 +69,7 @@ union bytes
}
#endif
-/* DECLARE (ush, tab_prefix, 1 << BITS); -- prefix code */
+/* extern ush tab_prefix[1 << BITS]; prefix code */
#define clear_tab_prefixof() memzero (tab_prefix, 256);
#define de_stack ((char_type *)(&d_buf[DIST_BUFSIZE-1]))