diff options
| author | Joakim Verona | 2013-08-12 22:14:05 +0200 |
|---|---|---|
| committer | Joakim Verona | 2013-08-12 22:14:05 +0200 |
| commit | 30e2a1217667de18501bba00899c43a6f410906b (patch) | |
| tree | 62fa7c28959dd4b989c5483e2eddd56b0ebf84b6 /src | |
| parent | a4354e5eb57928af0afc313b81e7810a3365b383 (diff) | |
| parent | aa942e2bf4545365d7fb7e9d787e4a21642fbf4c (diff) | |
| download | emacs-30e2a1217667de18501bba00899c43a6f410906b.tar.gz emacs-30e2a1217667de18501bba00899c43a6f410906b.zip | |
merge from trunk
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 36 | ||||
| -rw-r--r-- | src/decompress.c | 98 |
2 files changed, 126 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 679b82ba63c..04c89b63fa4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,39 @@ | |||
| 1 | 2013-08-12 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * decompress.c <zlib_initialized> [WINDOWSNT]: New static variable. | ||
| 4 | (Fzlib_decompress_region) [WINDOWSNT]: Call init_zlib_functions if | ||
| 5 | not yet initialized. | ||
| 6 | |||
| 7 | 2013-08-12 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 8 | |||
| 9 | * decompress.c (Fzlib_decompress_region): Support zlib | ||
| 10 | decompression, too, and rename. | ||
| 11 | |||
| 12 | 2013-08-12 Paul Eggert <eggert@cs.ucla.edu> | ||
| 13 | |||
| 14 | Minor zlib configuration tweaks. | ||
| 15 | * decompress.c (fn_inflateInit2) [!WINDOWSNT]: | ||
| 16 | Don't assume presence of fn_inflateInit2_ zlib internal function. | ||
| 17 | |||
| 18 | 2013-08-12 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 19 | |||
| 20 | * decompress.c (Fzlib_decompress_gzipped_region): Rename to | ||
| 21 | include the zlib prefix. | ||
| 22 | |||
| 23 | 2013-08-12 Eli Zaretskii <eliz@gnu.org> | ||
| 24 | |||
| 25 | * decompress.c [WINDOWSNT]: Include windows.h and w32.h. | ||
| 26 | (DEF_ZLIB_FN, LOAD_ZLIB_FN) [WINDOWSNT]: New macros. Use them to | ||
| 27 | define static variables that are pointers to zlib functions to be | ||
| 28 | dynamically loaded. | ||
| 29 | (init_zlib_functions) [WINDOWSNT]: New function. | ||
| 30 | (fn_inflateInit2_, fn_inflate, fn_inflateEnd, fn_inflateInit2): | ||
| 31 | New macros. | ||
| 32 | (Fdecompress_gzipped_region, unwind_decompress): Use the fn_* | ||
| 33 | macros instead of invoking the zlib functions directly. | ||
| 34 | (syms_of_decompress): DEFSYM Qzlib_dll. Staticpro | ||
| 35 | Szlib_available_p. | ||
| 36 | |||
| 1 | 2013-08-12 Dmitry Antipov <dmantipov@yandex.ru> | 37 | 2013-08-12 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 38 | ||
| 3 | Avoid looping over all frame windows to freeze and unfreeze. | 39 | Avoid looping over all frame windows to freeze and unfreeze. |
diff --git a/src/decompress.c b/src/decompress.c index 866f4f51516..a09033ab8c3 100644 --- a/src/decompress.c +++ b/src/decompress.c | |||
| @@ -26,6 +26,60 @@ 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 | ||
| 29 | static 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 false; \ | ||
| 42 | } | ||
| 43 | |||
| 44 | DEF_ZLIB_FN (int, inflateInit2_, | ||
| 45 | (z_streamp strm, int windowBits, const char *version, int stream_size)); | ||
| 46 | |||
| 47 | DEF_ZLIB_FN (int, inflate, | ||
| 48 | (z_streamp strm, int flush)); | ||
| 49 | |||
| 50 | DEF_ZLIB_FN (int, inflateEnd, | ||
| 51 | (z_streamp strm)); | ||
| 52 | |||
| 53 | static bool zlib_initialized; | ||
| 54 | |||
| 55 | static bool | ||
| 56 | init_zlib_functions (void) | ||
| 57 | { | ||
| 58 | HMODULE library = w32_delayed_load (Qzlib_dll); | ||
| 59 | |||
| 60 | if (!library) | ||
| 61 | { | ||
| 62 | message1 ("zlib library not found"); | ||
| 63 | return false; | ||
| 64 | } | ||
| 65 | |||
| 66 | LOAD_ZLIB_FN (library, inflateInit2_); | ||
| 67 | LOAD_ZLIB_FN (library, inflate); | ||
| 68 | LOAD_ZLIB_FN (library, inflateEnd); | ||
| 69 | return true; | ||
| 70 | } | ||
| 71 | |||
| 72 | #define fn_inflateInit2(strm, windowBits) \ | ||
| 73 | fn_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) | ||
| 74 | |||
| 75 | #else /* !WINDOWSNT */ | ||
| 76 | |||
| 77 | #define fn_inflateInit2 inflateInit2 | ||
| 78 | #define fn_inflate inflate | ||
| 79 | #define fn_inflateEnd inflateEnd | ||
| 80 | |||
| 81 | #endif /* WINDOWSNT */ | ||
| 82 | |||
| 29 | 83 | ||
| 30 | struct decompress_unwind_data | 84 | struct decompress_unwind_data |
| 31 | { | 85 | { |
| @@ -37,7 +91,7 @@ static void | |||
| 37 | unwind_decompress (void *ddata) | 91 | unwind_decompress (void *ddata) |
| 38 | { | 92 | { |
| 39 | struct decompress_unwind_data *data = ddata; | 93 | struct decompress_unwind_data *data = ddata; |
| 40 | inflateEnd (data->stream); | 94 | fn_inflateEnd (data->stream); |
| 41 | 95 | ||
| 42 | /* Delete any uncompressed data already inserted and restore point. */ | 96 | /* Delete any uncompressed data already inserted and restore point. */ |
| 43 | if (data->start) | 97 | if (data->start) |
| @@ -47,10 +101,30 @@ unwind_decompress (void *ddata) | |||
| 47 | } | 101 | } |
| 48 | } | 102 | } |
| 49 | 103 | ||
| 50 | DEFUN ("decompress-gzipped-region", Fdecompress_gzipped_region, | 104 | DEFUN ("zlib-available-p", Fzlib_available_p, Szlib_available_p, 0, 0, 0, |
| 51 | Sdecompress_gzipped_region, | 105 | doc: /* Return t if zlib decompression is available in this instance of Emacs. */) |
| 106 | (void) | ||
| 107 | { | ||
| 108 | #ifdef WINDOWSNT | ||
| 109 | Lisp_Object found = Fassq (Qzlib_dll, Vlibrary_cache); | ||
| 110 | if (CONSP (found)) | ||
| 111 | return XCDR (found); | ||
| 112 | else | ||
| 113 | { | ||
| 114 | Lisp_Object status; | ||
| 115 | status = init_zlib_functions () ? Qt : Qnil; | ||
| 116 | Vlibrary_cache = Fcons (Fcons (Qzlib_dll, status), Vlibrary_cache); | ||
| 117 | return status; | ||
| 118 | } | ||
| 119 | #else | ||
| 120 | return Qt; | ||
| 121 | #endif | ||
| 122 | } | ||
| 123 | |||
| 124 | DEFUN ("zlib-decompress-region", Fzlib_decompress_region, | ||
| 125 | Szlib_decompress_region, | ||
| 52 | 2, 2, 0, | 126 | 2, 2, 0, |
| 53 | doc: /* Decompress a gzip-compressed region. | 127 | doc: /* Decompress a gzip- or zlib-compressed region. |
| 54 | Replace the text in the region by the decompressed data. | 128 | Replace the text in the region by the decompressed data. |
| 55 | On failure, return nil and leave the data in place. | 129 | On failure, return nil and leave the data in place. |
| 56 | This function can be called only in unibyte buffers. */) | 130 | This function can be called only in unibyte buffers. */) |
| @@ -67,6 +141,11 @@ This function can be called only in unibyte buffers. */) | |||
| 67 | if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) | 141 | if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) |
| 68 | error ("This function can be called only in unibyte buffers"); | 142 | error ("This function can be called only in unibyte buffers"); |
| 69 | 143 | ||
| 144 | #ifdef WINDOWSNT | ||
| 145 | if (!zlib_initialized) | ||
| 146 | zlib_initialized = init_zlib_functions (); | ||
| 147 | #endif | ||
| 148 | |||
| 70 | /* This is a unibyte buffer, so character positions and bytes are | 149 | /* This is a unibyte buffer, so character positions and bytes are |
| 71 | the same. */ | 150 | the same. */ |
| 72 | istart = XINT (start); | 151 | istart = XINT (start); |
| @@ -79,8 +158,9 @@ This function can be called only in unibyte buffers. */) | |||
| 79 | stream.avail_in = 0; | 158 | stream.avail_in = 0; |
| 80 | stream.next_in = Z_NULL; | 159 | stream.next_in = Z_NULL; |
| 81 | 160 | ||
| 82 | /* This magic number apparently means "this is gzip". */ | 161 | /* The magic number 32 apparently means "autodect both the gzip and |
| 83 | if (inflateInit2 (&stream, 16 + MAX_WBITS) != Z_OK) | 162 | zlib formats" according to zlib.h. */ |
| 163 | if (fn_inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK) | ||
| 84 | return Qnil; | 164 | return Qnil; |
| 85 | 165 | ||
| 86 | unwind_data.start = iend; | 166 | unwind_data.start = iend; |
| @@ -111,7 +191,7 @@ This function can be called only in unibyte buffers. */) | |||
| 111 | stream.avail_in = avail_in; | 191 | stream.avail_in = avail_in; |
| 112 | stream.next_out = GPT_ADDR; | 192 | stream.next_out = GPT_ADDR; |
| 113 | stream.avail_out = avail_out; | 193 | stream.avail_out = avail_out; |
| 114 | inflate_status = inflate (&stream, Z_NO_FLUSH); | 194 | inflate_status = fn_inflate (&stream, Z_NO_FLUSH); |
| 115 | pos_byte += avail_in - stream.avail_in; | 195 | pos_byte += avail_in - stream.avail_in; |
| 116 | decompressed = avail_out - stream.avail_out; | 196 | decompressed = avail_out - stream.avail_out; |
| 117 | insert_from_gap (decompressed, decompressed, 0); | 197 | insert_from_gap (decompressed, decompressed, 0); |
| @@ -137,7 +217,9 @@ This function can be called only in unibyte buffers. */) | |||
| 137 | void | 217 | void |
| 138 | syms_of_decompress (void) | 218 | syms_of_decompress (void) |
| 139 | { | 219 | { |
| 140 | defsubr (&Sdecompress_gzipped_region); | 220 | DEFSYM (Qzlib_dll, "zlib"); |
| 221 | defsubr (&Szlib_decompress_region); | ||
| 222 | defsubr (&Szlib_available_p); | ||
| 141 | } | 223 | } |
| 142 | 224 | ||
| 143 | #endif /* HAVE_ZLIB */ | 225 | #endif /* HAVE_ZLIB */ |