aboutsummaryrefslogtreecommitdiffstats
path: root/src/decompress.c
diff options
context:
space:
mode:
authorPaul Eggert2014-12-26 09:32:06 -0800
committerPaul Eggert2014-12-28 00:33:27 -0800
commite092accb6bb8aea08dab1796d707b3adce55a38c (patch)
treef3f2bad267ce9f3f2ec61441a03447027ae3a3ea /src/decompress.c
parent1505643bb70ce66e86d6c72902fe7e9199e93606 (diff)
downloademacs-e092accb6bb8aea08dab1796d707b3adce55a38c.tar.gz
emacs-e092accb6bb8aea08dab1796d707b3adce55a38c.zip
Wrap dll functions more simply
* decompress.c, gnutls.c, image.c, xml.c: If WINDOWSNT, use '#define FOO fn_FOO' to wrap dll functions, rather than the inverse when not WINDOWSNT. This isolates the fn_* business into the WINDOWSNT-specific section of the code, which makes it easier to maintain the generic code. * decompress.c (DEF_ZLIB_FN, LOAD_ZLIB_FN): * gnutls.c (DEF_GNUTLS_FN, LOAD_GNUTLS_FN): * image.c (DEF_IMGLIB_FN, LOAD_IMGLIB_FN): * xml.c (DEF_XML2_FN, LOAD_XML2_FN): Remove. All uses replaced by DEF_DLL_FN. * w32.h (DEF_DLL_FN, LOAD_DLL_FN): New macros.
Diffstat (limited to 'src/decompress.c')
-rw-r--r--src/decompress.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/src/decompress.c b/src/decompress.c
index 24ce852245c..f86aa6facbf 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -31,26 +31,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31static Lisp_Object Qzlib_dll; 31static Lisp_Object Qzlib_dll;
32 32
33#ifdef WINDOWSNT 33#ifdef WINDOWSNT
34#include <windows.h> 34# include <windows.h>
35#include "w32.h" 35# include "w32.h"
36 36
37/* Macro for defining functions that will be loaded from the zlib DLL. */ 37DEF_DLL_FN (int, inflateInit2_,
38#define DEF_ZLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args 38 (z_streamp strm, int windowBits, const char *version,
39 39 int stream_size));
40/* Macro for loading zlib functions from the library. */ 40DEF_DLL_FN (int, inflate, (z_streamp strm, int flush));
41#define LOAD_ZLIB_FN(lib,func) { \ 41DEF_DLL_FN (int, inflateEnd, (z_streamp strm));
42 fn_##func = (void *) GetProcAddress (lib, #func); \
43 if (!fn_##func) return false; \
44 }
45
46DEF_ZLIB_FN (int, inflateInit2_,
47 (z_streamp strm, int windowBits, const char *version, int stream_size));
48
49DEF_ZLIB_FN (int, inflate,
50 (z_streamp strm, int flush));
51
52DEF_ZLIB_FN (int, inflateEnd,
53 (z_streamp strm));
54 42
55static bool zlib_initialized; 43static bool zlib_initialized;
56 44
@@ -62,20 +50,19 @@ init_zlib_functions (void)
62 if (!library) 50 if (!library)
63 return false; 51 return false;
64 52
65 LOAD_ZLIB_FN (library, inflateInit2_); 53 LOAD_DLL_FN (library, inflateInit2_);
66 LOAD_ZLIB_FN (library, inflate); 54 LOAD_DLL_FN (library, inflate);
67 LOAD_ZLIB_FN (library, inflateEnd); 55 LOAD_DLL_FN (library, inflateEnd);
68 return true; 56 return true;
69} 57}
70 58
71#define fn_inflateInit2(strm, windowBits) \ 59# undef inflate
72 fn_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) 60# undef inflateEnd
73 61# undef inflateInit2_
74#else /* !WINDOWSNT */
75 62
76#define fn_inflateInit2 inflateInit2 63# define inflate fn_inflate
77#define fn_inflate inflate 64# define inflateEnd fn_inflateEnd
78#define fn_inflateEnd inflateEnd 65# define inflateInit2_ fn_inflateInit2_
79 66
80#endif /* WINDOWSNT */ 67#endif /* WINDOWSNT */
81 68
@@ -90,7 +77,7 @@ static void
90unwind_decompress (void *ddata) 77unwind_decompress (void *ddata)
91{ 78{
92 struct decompress_unwind_data *data = ddata; 79 struct decompress_unwind_data *data = ddata;
93 fn_inflateEnd (data->stream); 80 inflateEnd (data->stream);
94 81
95 /* Delete any uncompressed data already inserted on error. */ 82 /* Delete any uncompressed data already inserted on error. */
96 if (data->start) 83 if (data->start)
@@ -167,7 +154,7 @@ This function can be called only in unibyte buffers. */)
167 154
168 /* The magic number 32 apparently means "autodetect both the gzip and 155 /* The magic number 32 apparently means "autodetect both the gzip and
169 zlib formats" according to zlib.h. */ 156 zlib formats" according to zlib.h. */
170 if (fn_inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK) 157 if (inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK)
171 return Qnil; 158 return Qnil;
172 159
173 unwind_data.start = iend; 160 unwind_data.start = iend;
@@ -197,7 +184,7 @@ This function can be called only in unibyte buffers. */)
197 stream.avail_in = avail_in; 184 stream.avail_in = avail_in;
198 stream.next_out = GPT_ADDR; 185 stream.next_out = GPT_ADDR;
199 stream.avail_out = avail_out; 186 stream.avail_out = avail_out;
200 inflate_status = fn_inflate (&stream, Z_NO_FLUSH); 187 inflate_status = inflate (&stream, Z_NO_FLUSH);
201 pos_byte += avail_in - stream.avail_in; 188 pos_byte += avail_in - stream.avail_in;
202 decompressed = avail_out - stream.avail_out; 189 decompressed = avail_out - stream.avail_out;
203 insert_from_gap (decompressed, decompressed, 0); 190 insert_from_gap (decompressed, decompressed, 0);