aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2013-08-12 16:15:01 +0300
committerEli Zaretskii2013-08-12 16:15:01 +0300
commit594a430782d12499543637915fd974483523f500 (patch)
treeed3011bd979d4ed2aedee2fe19effb0ef00450bd /src
parent7a67e06b99a85ae700a7ccc75468397d53af59ed (diff)
downloademacs-594a430782d12499543637915fd974483523f500.tar.gz
emacs-594a430782d12499543637915fd974483523f500.zip
Fix build with zlib on MS-Windows.
configure.ac (LIBZ): Comment on w32 peculiarities regarding LIBZ. src/decompress.c [WINDOWSNT]: Include windows.h and w32.h. (DEF_ZLIB_FN, LOAD_ZLIB_FN) [WINDOWSNT]: New macros. Use them to define static variables that are pointers to zlib functions to be dynamically loaded. (init_zlib_functions) [WINDOWSNT]: New function. (fn_inflateInit2_, fn_inflate, fn_inflateEnd, fn_inflateInit2): New macros. (Fdecompress_gzipped_region, unwind_decompress): Use the fn_* macros instead of invoking the zlib functions directly. (syms_of_decompress): DEFSYM Qzlib_dll. Staticpro Szlib_available_p. lisp/term/w32-win.el (dynamic-library-alist): Add DLLs for zlib.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/decompress.c80
2 files changed, 91 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 679b82ba63c..44af7c6b385 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,17 @@
12013-08-12 Eli Zaretskii <eliz@gnu.org>
2
3 * decompress.c [WINDOWSNT]: Include windows.h and w32.h.
4 (DEF_ZLIB_FN, LOAD_ZLIB_FN) [WINDOWSNT]: New macros. Use them to
5 define static variables that are pointers to zlib functions to be
6 dynamically loaded.
7 (init_zlib_functions) [WINDOWSNT]: New function.
8 (fn_inflateInit2_, fn_inflate, fn_inflateEnd, fn_inflateInit2):
9 New macros.
10 (Fdecompress_gzipped_region, unwind_decompress): Use the fn_*
11 macros instead of invoking the zlib functions directly.
12 (syms_of_decompress): DEFSYM Qzlib_dll. Staticpro
13 Szlib_available_p.
14
12013-08-12 Dmitry Antipov <dmantipov@yandex.ru> 152013-08-12 Dmitry Antipov <dmantipov@yandex.ru>
2 16
3 Avoid looping over all frame windows to freeze and unfreeze. 17 Avoid looping over all frame windows to freeze and unfreeze.
diff --git a/src/decompress.c b/src/decompress.c
index 866f4f51516..af8435b2fd0 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -26,6 +26,58 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include "character.h" 26#include "character.h"
27#include "buffer.h" 27#include "buffer.h"
28 28
29static Lisp_Object Qzlib_dll;
30
31#ifdef WINDOWSNT
32#include <windows.h>
33#include "w32.h"
34
35/* Macro for defining functions that will be loaded from the zlib DLL. */
36#define DEF_ZLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
37
38/* Macro for loading zlib functions from the library. */
39#define LOAD_ZLIB_FN(lib,func) { \
40 fn_##func = (void *) GetProcAddress (lib, #func); \
41 if (!fn_##func) return 0; \
42 }
43
44DEF_ZLIB_FN (int, inflateInit2_,
45 (z_streamp strm, int windowBits, const char *version, int stream_size));
46
47DEF_ZLIB_FN (int, inflate,
48 (z_streamp strm, int flush));
49
50DEF_ZLIB_FN (int, inflateEnd,
51 (z_streamp strm));
52
53static bool
54init_zlib_functions (void)
55{
56 HMODULE library = w32_delayed_load (Qzlib_dll);
57
58 if (!library)
59 {
60 message1 ("zlib library not found");
61 return 0;
62 }
63
64 LOAD_ZLIB_FN (library, inflateInit2_);
65 LOAD_ZLIB_FN (library, inflate);
66 LOAD_ZLIB_FN (library, inflateEnd);
67 return 1;
68}
69
70#else /* !WINDOWSNT */
71
72#define fn_inflateInit2_ inflateInit2_
73#define fn_inflate inflate
74#define fn_inflateEnd inflateEnd
75
76#endif /* WINDOWSNT */
77
78#define fn_inflateInit2(strm, windowBits) \
79 fn_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
80
29 81
30struct decompress_unwind_data 82struct decompress_unwind_data
31{ 83{
@@ -37,7 +89,7 @@ static void
37unwind_decompress (void *ddata) 89unwind_decompress (void *ddata)
38{ 90{
39 struct decompress_unwind_data *data = ddata; 91 struct decompress_unwind_data *data = ddata;
40 inflateEnd (data->stream); 92 fn_inflateEnd (data->stream);
41 93
42 /* Delete any uncompressed data already inserted and restore point. */ 94 /* Delete any uncompressed data already inserted and restore point. */
43 if (data->start) 95 if (data->start)
@@ -47,6 +99,26 @@ unwind_decompress (void *ddata)
47 } 99 }
48} 100}
49 101
102DEFUN ("zlib-available-p", Fzlib_available_p, Szlib_available_p, 0, 0, 0,
103 doc: /* Return t if zlib decompression is available in this instance of Emacs. */)
104 (void)
105{
106#ifdef WINDOWSNT
107 Lisp_Object found = Fassq (Qzlib_dll, Vlibrary_cache);
108 if (CONSP (found))
109 return XCDR (found);
110 else
111 {
112 Lisp_Object status;
113 status = init_zlib_functions () ? Qt : Qnil;
114 Vlibrary_cache = Fcons (Fcons (Qzlib_dll, status), Vlibrary_cache);
115 return status;
116 }
117#else
118 return Qt;
119#endif
120}
121
50DEFUN ("decompress-gzipped-region", Fdecompress_gzipped_region, 122DEFUN ("decompress-gzipped-region", Fdecompress_gzipped_region,
51 Sdecompress_gzipped_region, 123 Sdecompress_gzipped_region,
52 2, 2, 0, 124 2, 2, 0,
@@ -80,7 +152,7 @@ This function can be called only in unibyte buffers. */)
80 stream.next_in = Z_NULL; 152 stream.next_in = Z_NULL;
81 153
82 /* This magic number apparently means "this is gzip". */ 154 /* This magic number apparently means "this is gzip". */
83 if (inflateInit2 (&stream, 16 + MAX_WBITS) != Z_OK) 155 if (fn_inflateInit2 (&stream, 16 + MAX_WBITS) != Z_OK)
84 return Qnil; 156 return Qnil;
85 157
86 unwind_data.start = iend; 158 unwind_data.start = iend;
@@ -111,7 +183,7 @@ This function can be called only in unibyte buffers. */)
111 stream.avail_in = avail_in; 183 stream.avail_in = avail_in;
112 stream.next_out = GPT_ADDR; 184 stream.next_out = GPT_ADDR;
113 stream.avail_out = avail_out; 185 stream.avail_out = avail_out;
114 inflate_status = inflate (&stream, Z_NO_FLUSH); 186 inflate_status = fn_inflate (&stream, Z_NO_FLUSH);
115 pos_byte += avail_in - stream.avail_in; 187 pos_byte += avail_in - stream.avail_in;
116 decompressed = avail_out - stream.avail_out; 188 decompressed = avail_out - stream.avail_out;
117 insert_from_gap (decompressed, decompressed, 0); 189 insert_from_gap (decompressed, decompressed, 0);
@@ -137,7 +209,9 @@ This function can be called only in unibyte buffers. */)
137void 209void
138syms_of_decompress (void) 210syms_of_decompress (void)
139{ 211{
212 DEFSYM (Qzlib_dll, "zlib");
140 defsubr (&Sdecompress_gzipped_region); 213 defsubr (&Sdecompress_gzipped_region);
214 defsubr (&Szlib_available_p);
141} 215}
142 216
143#endif /* HAVE_ZLIB */ 217#endif /* HAVE_ZLIB */