emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 5b10a03: Fix Windows build link-time zlib error (bug


From: Andrea Corallo
Subject: feature/native-comp 5b10a03: Fix Windows build link-time zlib error (bug#45303)
Date: Mon, 21 Dec 2020 04:47:37 -0500 (EST)

branch: feature/native-comp
commit 5b10a0324d5e5fd975e5833f1a058274780226e2
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    Fix Windows build link-time zlib error (bug#45303)
    
        * src/lisp.h (md5_gz_stream): Declare.
        * src/comp.c (accumulate_and_process_md5)
        (final_process_md5, md5_gz_stream): Remove.
        * src/decompress.c (accumulate_and_process_md5)
        (final_process_md5, md5_gz_stream): Move from comp.c.
---
 src/comp.c       |  88 -----------------------------------------------
 src/decompress.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lisp.h       |   4 +++
 3 files changed, 106 insertions(+), 88 deletions(-)

diff --git a/src/comp.c b/src/comp.c
index 8907993..70f61bf 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -665,94 +665,6 @@ comp_hash_string (Lisp_Object string)
   return digest;
 }
 
-#define MD5_BLOCKSIZE 32768 /* From md5.c  */
-
-static char acc_buff[2 * MD5_BLOCKSIZE];
-static size_t acc_size;
-
-static void
-accumulate_and_process_md5 (void *data, size_t len, struct md5_ctx *ctxt)
-{
-  eassert (len <= MD5_BLOCKSIZE);
-  /* We may optimize this saving some of these memcpy/move using
-     directly the outer buffers but so far I'll not bother.  */
-  memcpy (acc_buff + acc_size, data, len);
-  acc_size += len;
-  if (acc_size >= MD5_BLOCKSIZE)
-    {
-      acc_size -= MD5_BLOCKSIZE;
-      md5_process_block (acc_buff, MD5_BLOCKSIZE, ctxt);
-      memmove (acc_buff, acc_buff + MD5_BLOCKSIZE, acc_size);
-    }
-}
-
-static void
-final_process_md5 (struct md5_ctx *ctxt)
-{
-  if (acc_size)
-    {
-      md5_process_bytes (acc_buff, acc_size, ctxt);
-      acc_size = 0;
-    }
-}
-
-static int
-md5_gz_stream (FILE *source, void *resblock)
-{
-  z_stream stream;
-  unsigned char in[MD5_BLOCKSIZE];
-  unsigned char out[MD5_BLOCKSIZE];
-
-  eassert (!acc_size);
-
-  struct md5_ctx ctx;
-  md5_init_ctx (&ctx);
-
-  /* allocate inflate state */
-  stream.zalloc = Z_NULL;
-  stream.zfree = Z_NULL;
-  stream.opaque = Z_NULL;
-  stream.avail_in = 0;
-  stream.next_in = Z_NULL;
-  int res = inflateInit2 (&stream, MAX_WBITS + 32);
-  if (res != Z_OK)
-    return -1;
-
-  do {
-    stream.avail_in = fread (in, 1, MD5_BLOCKSIZE, source);
-    if (ferror (source)) {
-      inflateEnd (&stream);
-      return -1;
-    }
-    if (stream.avail_in == 0)
-      break;
-    stream.next_in = in;
-
-    do {
-      stream.avail_out = MD5_BLOCKSIZE;
-      stream.next_out = out;
-      res = inflate (&stream, Z_NO_FLUSH);
-
-      if (res != Z_OK && res != Z_STREAM_END)
-       return -1;
-
-      accumulate_and_process_md5 (out, MD5_BLOCKSIZE - stream.avail_out, &ctx);
-    } while (!stream.avail_out);
-
-  } while (res != Z_STREAM_END);
-
-  final_process_md5 (&ctx);
-  inflateEnd (&stream);
-
-  if (res != Z_STREAM_END)
-    return -1;
-
-  md5_finish_ctx (&ctx, resblock);
-
-  return 0;
-}
-#undef MD5_BLOCKSIZE
-
 static Lisp_Object
 comp_hash_source_file (Lisp_Object filename)
 {
diff --git a/src/decompress.c b/src/decompress.c
index 8e8f244..afd43e1 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -25,6 +25,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "buffer.h"
 #include "composite.h"
+#include "md5.h"
 
 #include <verify.h>
 
@@ -66,6 +67,107 @@ init_zlib_functions (void)
 #endif /* WINDOWSNT */
 
 
+
+#define MD5_BLOCKSIZE 32768 /* From md5.c  */
+
+static char acc_buff[2 * MD5_BLOCKSIZE];
+static size_t acc_size;
+
+static void
+accumulate_and_process_md5 (void *data, size_t len, struct md5_ctx *ctxt)
+{
+  eassert (len <= MD5_BLOCKSIZE);
+  /* We may optimize this saving some of these memcpy/move using
+     directly the outer buffers but so far don't bother.  */
+  memcpy (acc_buff + acc_size, data, len);
+  acc_size += len;
+  if (acc_size >= MD5_BLOCKSIZE)
+    {
+      acc_size -= MD5_BLOCKSIZE;
+      md5_process_block (acc_buff, MD5_BLOCKSIZE, ctxt);
+      memmove (acc_buff, acc_buff + MD5_BLOCKSIZE, acc_size);
+    }
+}
+
+static void
+final_process_md5 (struct md5_ctx *ctxt)
+{
+  if (acc_size)
+    {
+      md5_process_bytes (acc_buff, acc_size, ctxt);
+      acc_size = 0;
+    }
+}
+
+int
+md5_gz_stream (FILE *source, void *resblock)
+{
+  z_stream stream;
+  unsigned char in[MD5_BLOCKSIZE];
+  unsigned char out[MD5_BLOCKSIZE];
+
+#ifdef WINDOWSNT
+  if (!zlib_initialized)
+    zlib_initialized = init_zlib_functions ();
+  if (!zlib_initialized)
+    {
+      message1 ("zlib library not found");
+      return -1;
+    }
+#endif
+
+  eassert (!acc_size);
+
+  struct md5_ctx ctx;
+  md5_init_ctx (&ctx);
+
+  /* allocate inflate state */
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
+  stream.opaque = Z_NULL;
+  stream.avail_in = 0;
+  stream.next_in = Z_NULL;
+  int res = inflateInit2 (&stream, MAX_WBITS + 32);
+  if (res != Z_OK)
+    return -1;
+
+  do {
+    stream.avail_in = fread (in, 1, MD5_BLOCKSIZE, source);
+    if (ferror (source)) {
+      inflateEnd (&stream);
+      return -1;
+    }
+    if (stream.avail_in == 0)
+      break;
+    stream.next_in = in;
+
+    do {
+      stream.avail_out = MD5_BLOCKSIZE;
+      stream.next_out = out;
+      res = inflate (&stream, Z_NO_FLUSH);
+
+      if (res != Z_OK && res != Z_STREAM_END)
+       return -1;
+
+      accumulate_and_process_md5 (out, MD5_BLOCKSIZE - stream.avail_out, &ctx);
+    } while (!stream.avail_out);
+
+  } while (res != Z_STREAM_END);
+
+  final_process_md5 (&ctx);
+  inflateEnd (&stream);
+
+  if (res != Z_STREAM_END)
+    return -1;
+
+  md5_finish_ctx (&ctx, resblock);
+
+  return 0;
+}
+#undef MD5_BLOCKSIZE
+
+
+
 struct decompress_unwind_data
 {
   ptrdiff_t old_point, orig, start, nbytes;
diff --git a/src/lisp.h b/src/lisp.h
index 923e742..7dc517b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4720,7 +4720,11 @@ extern void syms_of_lcms2 (void);
 #endif
 
 #ifdef HAVE_ZLIB
+
+#include <stdio.h>
+
 /* Defined in decompress.c.  */
+extern int md5_gz_stream (FILE *, void *);
 extern void syms_of_decompress (void);
 #endif
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]