aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/decompress.c51
-rw-r--r--src/gnutls.c726
-rw-r--r--src/image.c932
-rw-r--r--src/w32.h13
-rw-r--r--src/xml.c94
6 files changed, 940 insertions, 890 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index bdd1882c06a..9e3fb904b93 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,19 @@
12014-12-28 Paul Eggert <eggert@Penguin.CS.UCLA.EDU> 12014-12-28 Paul Eggert <eggert@Penguin.CS.UCLA.EDU>
2 2
3 Wrap dll functions more simply
4 * decompress.c, gnutls.c, image.c, xml.c:
5 If WINDOWSNT, use '#define FOO fn_FOO' to wrap dll functions,
6 rather than the inverse when not WINDOWSNT. This isolates the
7 fn_* business into the WINDOWSNT-specific section of the code,
8 which makes it easier to maintain the generic code.
9 * decompress.c (DEF_ZLIB_FN, LOAD_ZLIB_FN):
10 * gnutls.c (DEF_GNUTLS_FN, LOAD_GNUTLS_FN):
11 * image.c (DEF_IMGLIB_FN, LOAD_IMGLIB_FN):
12 * xml.c (DEF_XML2_FN, LOAD_XML2_FN):
13 Remove. All uses replaced by DEF_DLL_FN.
14 * decompress.c (inflateInit2): Remove; no longer needed.
15 * w32.h (DEF_DLL_FN, LOAD_DLL_FN): New macros.
16
3 Port memory-full checking to GnuTLS 3.3 17 Port memory-full checking to GnuTLS 3.3
4 Instead of using gnutls_global_set_mem_functions, check every call 18 Instead of using gnutls_global_set_mem_functions, check every call
5 to a GnuTLS function that might return an indication of memory 19 to a GnuTLS function that might return an indication of memory
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);
diff --git a/src/gnutls.c b/src/gnutls.c
index d28dbd07357..f945778cc91 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -71,138 +71,129 @@ enum extra_peer_verification
71 71
72#ifdef WINDOWSNT 72#ifdef WINDOWSNT
73 73
74/* Macro for defining functions that will be loaded from the GnuTLS DLL. */ 74DEF_DLL_FN (gnutls_alert_description_t, gnutls_alert_get,
75#define DEF_GNUTLS_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args 75 (gnutls_session_t));
76 76DEF_DLL_FN (const char *, gnutls_alert_get_name,
77/* Macro for loading GnuTLS functions from the library. */ 77 (gnutls_alert_description_t));
78#define LOAD_GNUTLS_FN(lib,func) { \ 78DEF_DLL_FN (int, gnutls_alert_send_appropriate, (gnutls_session_t, int));
79 fn_##func = (void *) GetProcAddress (lib, #func); \ 79DEF_DLL_FN (int, gnutls_anon_allocate_client_credentials,
80 if (!fn_##func) return 0; \ 80 (gnutls_anon_client_credentials_t *));
81 } 81DEF_DLL_FN (void, gnutls_anon_free_client_credentials,
82 82 (gnutls_anon_client_credentials_t));
83DEF_GNUTLS_FN (gnutls_alert_description_t, gnutls_alert_get, 83DEF_DLL_FN (int, gnutls_bye, (gnutls_session_t, gnutls_close_request_t));
84 (gnutls_session_t)); 84DEF_DLL_FN (int, gnutls_certificate_allocate_credentials,
85DEF_GNUTLS_FN (const char *, gnutls_alert_get_name, 85 (gnutls_certificate_credentials_t *));
86 (gnutls_alert_description_t)); 86DEF_DLL_FN (void, gnutls_certificate_free_credentials,
87DEF_GNUTLS_FN (int, gnutls_alert_send_appropriate, (gnutls_session_t, int)); 87 (gnutls_certificate_credentials_t));
88DEF_GNUTLS_FN (int, gnutls_anon_allocate_client_credentials, 88DEF_DLL_FN (const gnutls_datum_t *, gnutls_certificate_get_peers,
89 (gnutls_anon_client_credentials_t *)); 89 (gnutls_session_t, unsigned int *));
90DEF_GNUTLS_FN (void, gnutls_anon_free_client_credentials, 90DEF_DLL_FN (void, gnutls_certificate_set_verify_flags,
91 (gnutls_anon_client_credentials_t)); 91 (gnutls_certificate_credentials_t, unsigned int));
92DEF_GNUTLS_FN (int, gnutls_bye, (gnutls_session_t, gnutls_close_request_t)); 92DEF_DLL_FN (int, gnutls_certificate_set_x509_crl_file,
93DEF_GNUTLS_FN (int, gnutls_certificate_allocate_credentials, 93 (gnutls_certificate_credentials_t, const char *,
94 (gnutls_certificate_credentials_t *)); 94 gnutls_x509_crt_fmt_t));
95DEF_GNUTLS_FN (void, gnutls_certificate_free_credentials, 95DEF_DLL_FN (int, gnutls_certificate_set_x509_key_file,
96 (gnutls_certificate_credentials_t)); 96 (gnutls_certificate_credentials_t, const char *, const char *,
97DEF_GNUTLS_FN (const gnutls_datum_t *, gnutls_certificate_get_peers, 97 gnutls_x509_crt_fmt_t));
98 (gnutls_session_t, unsigned int *)); 98# if ((GNUTLS_VERSION_MAJOR \
99DEF_GNUTLS_FN (void, gnutls_certificate_set_verify_flags, 99 + (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20)) \
100 (gnutls_certificate_credentials_t, unsigned int)); 100 > 3)
101DEF_GNUTLS_FN (int, gnutls_certificate_set_x509_crl_file, 101DEF_DLL_FN (int, gnutls_certificate_set_x509_system_trust,
102 (gnutls_certificate_credentials_t, const char *, 102 (gnutls_certificate_credentials_t));
103 gnutls_x509_crt_fmt_t)); 103# endif
104DEF_GNUTLS_FN (int, gnutls_certificate_set_x509_key_file, 104DEF_DLL_FN (int, gnutls_certificate_set_x509_trust_file,
105 (gnutls_certificate_credentials_t, const char *, const char *, 105 (gnutls_certificate_credentials_t, const char *,
106 gnutls_x509_crt_fmt_t)); 106 gnutls_x509_crt_fmt_t));
107#if GNUTLS_VERSION_MAJOR + \ 107DEF_DLL_FN (gnutls_certificate_type_t, gnutls_certificate_type_get,
108 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 108 (gnutls_session_t));
109DEF_GNUTLS_FN (int, gnutls_certificate_set_x509_system_trust, 109DEF_DLL_FN (int, gnutls_certificate_verify_peers2,
110 (gnutls_certificate_credentials_t)); 110 (gnutls_session_t, unsigned int *));
111#endif 111DEF_DLL_FN (int, gnutls_credentials_set,
112DEF_GNUTLS_FN (int, gnutls_certificate_set_x509_trust_file, 112 (gnutls_session_t, gnutls_credentials_type_t, void *));
113 (gnutls_certificate_credentials_t, const char *, 113DEF_DLL_FN (void, gnutls_deinit, (gnutls_session_t));
114 gnutls_x509_crt_fmt_t)); 114DEF_DLL_FN (void, gnutls_dh_set_prime_bits,
115DEF_GNUTLS_FN (gnutls_certificate_type_t, gnutls_certificate_type_get, 115 (gnutls_session_t, unsigned int));
116 (gnutls_session_t)); 116DEF_DLL_FN (int, gnutls_dh_get_prime_bits, (gnutls_session_t));
117DEF_GNUTLS_FN (int, gnutls_certificate_verify_peers2, 117DEF_DLL_FN (int, gnutls_error_is_fatal, (int));
118 (gnutls_session_t, unsigned int *)); 118DEF_DLL_FN (int, gnutls_global_init, (void));
119DEF_GNUTLS_FN (int, gnutls_credentials_set, 119DEF_DLL_FN (void, gnutls_global_set_log_function, (gnutls_log_func));
120 (gnutls_session_t, gnutls_credentials_type_t, void *)); 120# ifdef HAVE_GNUTLS3
121DEF_GNUTLS_FN (void, gnutls_deinit, (gnutls_session_t)); 121DEF_DLL_FN (void, gnutls_global_set_audit_log_function, (gnutls_audit_log_func));
122DEF_GNUTLS_FN (void, gnutls_dh_set_prime_bits, 122# endif
123 (gnutls_session_t, unsigned int)); 123DEF_DLL_FN (void, gnutls_global_set_log_level, (int));
124DEF_GNUTLS_FN (int, gnutls_dh_get_prime_bits, (gnutls_session_t)); 124DEF_DLL_FN (int, gnutls_handshake, (gnutls_session_t));
125DEF_GNUTLS_FN (int, gnutls_error_is_fatal, (int)); 125DEF_DLL_FN (int, gnutls_init, (gnutls_session_t *, unsigned int));
126DEF_GNUTLS_FN (int, gnutls_global_init, (void)); 126DEF_DLL_FN (int, gnutls_priority_set_direct,
127DEF_GNUTLS_FN (void, gnutls_global_set_log_function, (gnutls_log_func)); 127 (gnutls_session_t, const char *, const char **));
128#ifdef HAVE_GNUTLS3 128DEF_DLL_FN (size_t, gnutls_record_check_pending, (gnutls_session_t));
129DEF_GNUTLS_FN (void, gnutls_global_set_audit_log_function, (gnutls_audit_log_func)); 129DEF_DLL_FN (ssize_t, gnutls_record_recv, (gnutls_session_t, void *, size_t));
130#endif 130DEF_DLL_FN (ssize_t, gnutls_record_send,
131DEF_GNUTLS_FN (void, gnutls_global_set_log_level, (int)); 131 (gnutls_session_t, const void *, size_t));
132DEF_GNUTLS_FN (int, gnutls_handshake, (gnutls_session_t)); 132DEF_DLL_FN (const char *, gnutls_strerror, (int));
133DEF_GNUTLS_FN (int, gnutls_init, (gnutls_session_t *, unsigned int)); 133DEF_DLL_FN (void, gnutls_transport_set_errno, (gnutls_session_t, int));
134DEF_GNUTLS_FN (int, gnutls_priority_set_direct, 134DEF_DLL_FN (const char *, gnutls_check_version, (const char *));
135 (gnutls_session_t, const char *, const char **)); 135DEF_DLL_FN (void, gnutls_transport_set_lowat, (gnutls_session_t, int));
136DEF_GNUTLS_FN (size_t, gnutls_record_check_pending, (gnutls_session_t)); 136DEF_DLL_FN (void, gnutls_transport_set_ptr2,
137DEF_GNUTLS_FN (ssize_t, gnutls_record_recv, (gnutls_session_t, void *, size_t)); 137 (gnutls_session_t, gnutls_transport_ptr_t,
138DEF_GNUTLS_FN (ssize_t, gnutls_record_send, 138 gnutls_transport_ptr_t));
139 (gnutls_session_t, const void *, size_t)); 139DEF_DLL_FN (void, gnutls_transport_set_pull_function,
140DEF_GNUTLS_FN (const char *, gnutls_strerror, (int)); 140 (gnutls_session_t, gnutls_pull_func));
141DEF_GNUTLS_FN (void, gnutls_transport_set_errno, (gnutls_session_t, int)); 141DEF_DLL_FN (void, gnutls_transport_set_push_function,
142DEF_GNUTLS_FN (const char *, gnutls_check_version, (const char *)); 142 (gnutls_session_t, gnutls_push_func));
143DEF_GNUTLS_FN (void, gnutls_transport_set_lowat, (gnutls_session_t, int)); 143DEF_DLL_FN (int, gnutls_x509_crt_check_hostname,
144DEF_GNUTLS_FN (void, gnutls_transport_set_ptr2, 144 (gnutls_x509_crt_t, const char *));
145 (gnutls_session_t, gnutls_transport_ptr_t, 145DEF_DLL_FN (void, gnutls_x509_crt_deinit, (gnutls_x509_crt_t));
146 gnutls_transport_ptr_t)); 146DEF_DLL_FN (int, gnutls_x509_crt_import,
147DEF_GNUTLS_FN (void, gnutls_transport_set_pull_function, 147 (gnutls_x509_crt_t, const gnutls_datum_t *,
148 (gnutls_session_t, gnutls_pull_func)); 148 gnutls_x509_crt_fmt_t));
149DEF_GNUTLS_FN (void, gnutls_transport_set_push_function, 149DEF_DLL_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *));
150 (gnutls_session_t, gnutls_push_func)); 150DEF_DLL_FN (int, gnutls_x509_crt_get_fingerprint,
151DEF_GNUTLS_FN (int, gnutls_x509_crt_check_hostname, 151 (gnutls_x509_crt_t,
152 (gnutls_x509_crt_t, const char *)); 152 gnutls_digest_algorithm_t, void *, size_t *));
153DEF_GNUTLS_FN (void, gnutls_x509_crt_deinit, (gnutls_x509_crt_t)); 153DEF_DLL_FN (int, gnutls_x509_crt_get_version,
154DEF_GNUTLS_FN (int, gnutls_x509_crt_import, 154 (gnutls_x509_crt_t));
155 (gnutls_x509_crt_t, const gnutls_datum_t *, 155DEF_DLL_FN (int, gnutls_x509_crt_get_serial,
156 gnutls_x509_crt_fmt_t)); 156 (gnutls_x509_crt_t, void *, size_t *));
157DEF_GNUTLS_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *)); 157DEF_DLL_FN (int, gnutls_x509_crt_get_issuer_dn,
158DEF_GNUTLS_FN (int, gnutls_x509_crt_get_fingerprint, 158 (gnutls_x509_crt_t, char *, size_t *));
159 (gnutls_x509_crt_t, 159DEF_DLL_FN (time_t, gnutls_x509_crt_get_activation_time,
160 gnutls_digest_algorithm_t, void *, size_t *)); 160 (gnutls_x509_crt_t));
161DEF_GNUTLS_FN (int, gnutls_x509_crt_get_version, 161DEF_DLL_FN (time_t, gnutls_x509_crt_get_expiration_time,
162 (gnutls_x509_crt_t)); 162 (gnutls_x509_crt_t));
163DEF_GNUTLS_FN (int, gnutls_x509_crt_get_serial, 163DEF_DLL_FN (int, gnutls_x509_crt_get_dn,
164 (gnutls_x509_crt_t, void *, size_t *)); 164 (gnutls_x509_crt_t, char *, size_t *));
165DEF_GNUTLS_FN (int, gnutls_x509_crt_get_issuer_dn, 165DEF_DLL_FN (int, gnutls_x509_crt_get_pk_algorithm,
166 (gnutls_x509_crt_t, char *, size_t *)); 166 (gnutls_x509_crt_t, unsigned int *));
167DEF_GNUTLS_FN (time_t, gnutls_x509_crt_get_activation_time, 167DEF_DLL_FN (const char*, gnutls_pk_algorithm_get_name,
168 (gnutls_x509_crt_t)); 168 (gnutls_pk_algorithm_t));
169DEF_GNUTLS_FN (time_t, gnutls_x509_crt_get_expiration_time, 169DEF_DLL_FN (int, gnutls_pk_bits_to_sec_param,
170 (gnutls_x509_crt_t)); 170 (gnutls_pk_algorithm_t, unsigned int));
171DEF_GNUTLS_FN (int, gnutls_x509_crt_get_dn, 171DEF_DLL_FN (int, gnutls_x509_crt_get_issuer_unique_id,
172 (gnutls_x509_crt_t, char *, size_t *)); 172 (gnutls_x509_crt_t, char *, size_t *));
173DEF_GNUTLS_FN (int, gnutls_x509_crt_get_pk_algorithm, 173DEF_DLL_FN (int, gnutls_x509_crt_get_subject_unique_id,
174 (gnutls_x509_crt_t, unsigned int *)); 174 (gnutls_x509_crt_t, char *, size_t *));
175DEF_GNUTLS_FN (const char*, gnutls_pk_algorithm_get_name, 175DEF_DLL_FN (int, gnutls_x509_crt_get_signature_algorithm,
176 (gnutls_pk_algorithm_t)); 176 (gnutls_x509_crt_t));
177DEF_GNUTLS_FN (int, gnutls_pk_bits_to_sec_param, 177DEF_DLL_FN (int, gnutls_x509_crt_get_signature,
178 (gnutls_pk_algorithm_t, unsigned int)); 178 (gnutls_x509_crt_t, char *, size_t *));
179DEF_GNUTLS_FN (int, gnutls_x509_crt_get_issuer_unique_id, 179DEF_DLL_FN (int, gnutls_x509_crt_get_key_id,
180 (gnutls_x509_crt_t, char *, size_t *)); 180 (gnutls_x509_crt_t, unsigned int, unsigned char *, size_t *_size));
181DEF_GNUTLS_FN (int, gnutls_x509_crt_get_subject_unique_id, 181DEF_DLL_FN (const char*, gnutls_sec_param_get_name, (gnutls_sec_param_t));
182 (gnutls_x509_crt_t, char *, size_t *)); 182DEF_DLL_FN (const char*, gnutls_sign_get_name, (gnutls_sign_algorithm_t));
183DEF_GNUTLS_FN (int, gnutls_x509_crt_get_signature_algorithm, 183DEF_DLL_FN (int, gnutls_server_name_set,
184 (gnutls_x509_crt_t)); 184 (gnutls_session_t, gnutls_server_name_type_t,
185DEF_GNUTLS_FN (int, gnutls_x509_crt_get_signature, 185 const void *, size_t));
186 (gnutls_x509_crt_t, char *, size_t *)); 186DEF_DLL_FN (gnutls_kx_algorithm_t, gnutls_kx_get, (gnutls_session_t));
187DEF_GNUTLS_FN (int, gnutls_x509_crt_get_key_id, 187DEF_DLL_FN (const char*, gnutls_kx_get_name, (gnutls_kx_algorithm_t));
188 (gnutls_x509_crt_t, unsigned int, 188DEF_DLL_FN (gnutls_protocol_t, gnutls_protocol_get_version,
189 unsigned char *, size_t *_size)); 189 (gnutls_session_t));
190DEF_GNUTLS_FN (const char*, gnutls_sec_param_get_name, (gnutls_sec_param_t)); 190DEF_DLL_FN (const char*, gnutls_protocol_get_name, (gnutls_protocol_t));
191DEF_GNUTLS_FN (const char*, gnutls_sign_get_name, (gnutls_sign_algorithm_t)); 191DEF_DLL_FN (gnutls_cipher_algorithm_t, gnutls_cipher_get,
192DEF_GNUTLS_FN (int, gnutls_server_name_set, (gnutls_session_t, 192 (gnutls_session_t));
193 gnutls_server_name_type_t, 193DEF_DLL_FN (const char*, gnutls_cipher_get_name,
194 const void *, size_t)); 194 (gnutls_cipher_algorithm_t));
195DEF_GNUTLS_FN (gnutls_kx_algorithm_t, gnutls_kx_get, (gnutls_session_t)); 195DEF_DLL_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t));
196DEF_GNUTLS_FN (const char*, gnutls_kx_get_name, (gnutls_kx_algorithm_t)); 196DEF_DLL_FN (const char*, gnutls_mac_get_name, (gnutls_mac_algorithm_t));
197DEF_GNUTLS_FN (gnutls_protocol_t, gnutls_protocol_get_version,
198 (gnutls_session_t));
199DEF_GNUTLS_FN (const char*, gnutls_protocol_get_name, (gnutls_protocol_t));
200DEF_GNUTLS_FN (gnutls_cipher_algorithm_t, gnutls_cipher_get,
201 (gnutls_session_t));
202DEF_GNUTLS_FN (const char*, gnutls_cipher_get_name,
203 (gnutls_cipher_algorithm_t));
204DEF_GNUTLS_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t));
205DEF_GNUTLS_FN (const char*, gnutls_mac_get_name, (gnutls_mac_algorithm_t));
206 197
207 198
208static bool 199static bool
@@ -217,82 +208,83 @@ init_gnutls_functions (void)
217 return 0; 208 return 0;
218 } 209 }
219 210
220 LOAD_GNUTLS_FN (library, gnutls_alert_get); 211 LOAD_DLL_FN (library, gnutls_alert_get);
221 LOAD_GNUTLS_FN (library, gnutls_alert_get_name); 212 LOAD_DLL_FN (library, gnutls_alert_get_name);
222 LOAD_GNUTLS_FN (library, gnutls_alert_send_appropriate); 213 LOAD_DLL_FN (library, gnutls_alert_send_appropriate);
223 LOAD_GNUTLS_FN (library, gnutls_anon_allocate_client_credentials); 214 LOAD_DLL_FN (library, gnutls_anon_allocate_client_credentials);
224 LOAD_GNUTLS_FN (library, gnutls_anon_free_client_credentials); 215 LOAD_DLL_FN (library, gnutls_anon_free_client_credentials);
225 LOAD_GNUTLS_FN (library, gnutls_bye); 216 LOAD_DLL_FN (library, gnutls_bye);
226 LOAD_GNUTLS_FN (library, gnutls_certificate_allocate_credentials); 217 LOAD_DLL_FN (library, gnutls_certificate_allocate_credentials);
227 LOAD_GNUTLS_FN (library, gnutls_certificate_free_credentials); 218 LOAD_DLL_FN (library, gnutls_certificate_free_credentials);
228 LOAD_GNUTLS_FN (library, gnutls_certificate_get_peers); 219 LOAD_DLL_FN (library, gnutls_certificate_get_peers);
229 LOAD_GNUTLS_FN (library, gnutls_certificate_set_verify_flags); 220 LOAD_DLL_FN (library, gnutls_certificate_set_verify_flags);
230 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_crl_file); 221 LOAD_DLL_FN (library, gnutls_certificate_set_x509_crl_file);
231 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_key_file); 222 LOAD_DLL_FN (library, gnutls_certificate_set_x509_key_file);
232#if GNUTLS_VERSION_MAJOR + \ 223# if ((GNUTLS_VERSION_MAJOR \
233 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 224 + (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20)) \
234 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_system_trust); 225 > 3)
235#endif 226 LOAD_DLL_FN (library, gnutls_certificate_set_x509_system_trust);
236 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_trust_file); 227# endif
237 LOAD_GNUTLS_FN (library, gnutls_certificate_type_get); 228 LOAD_DLL_FN (library, gnutls_certificate_set_x509_trust_file);
238 LOAD_GNUTLS_FN (library, gnutls_certificate_verify_peers2); 229 LOAD_DLL_FN (library, gnutls_certificate_type_get);
239 LOAD_GNUTLS_FN (library, gnutls_credentials_set); 230 LOAD_DLL_FN (library, gnutls_certificate_verify_peers2);
240 LOAD_GNUTLS_FN (library, gnutls_deinit); 231 LOAD_DLL_FN (library, gnutls_credentials_set);
241 LOAD_GNUTLS_FN (library, gnutls_dh_set_prime_bits); 232 LOAD_DLL_FN (library, gnutls_deinit);
242 LOAD_GNUTLS_FN (library, gnutls_dh_get_prime_bits); 233 LOAD_DLL_FN (library, gnutls_dh_set_prime_bits);
243 LOAD_GNUTLS_FN (library, gnutls_error_is_fatal); 234 LOAD_DLL_FN (library, gnutls_dh_get_prime_bits);
244 LOAD_GNUTLS_FN (library, gnutls_global_init); 235 LOAD_DLL_FN (library, gnutls_error_is_fatal);
245 LOAD_GNUTLS_FN (library, gnutls_global_set_log_function); 236 LOAD_DLL_FN (library, gnutls_global_init);
246#ifdef HAVE_GNUTLS3 237 LOAD_DLL_FN (library, gnutls_global_set_log_function);
247 LOAD_GNUTLS_FN (library, gnutls_global_set_audit_log_function); 238# ifdef HAVE_GNUTLS3
248#endif 239 LOAD_DLL_FN (library, gnutls_global_set_audit_log_function);
249 LOAD_GNUTLS_FN (library, gnutls_global_set_log_level); 240# endif
250 LOAD_GNUTLS_FN (library, gnutls_handshake); 241 LOAD_DLL_FN (library, gnutls_global_set_log_level);
251 LOAD_GNUTLS_FN (library, gnutls_init); 242 LOAD_DLL_FN (library, gnutls_handshake);
252 LOAD_GNUTLS_FN (library, gnutls_priority_set_direct); 243 LOAD_DLL_FN (library, gnutls_init);
253 LOAD_GNUTLS_FN (library, gnutls_record_check_pending); 244 LOAD_DLL_FN (library, gnutls_priority_set_direct);
254 LOAD_GNUTLS_FN (library, gnutls_record_recv); 245 LOAD_DLL_FN (library, gnutls_record_check_pending);
255 LOAD_GNUTLS_FN (library, gnutls_record_send); 246 LOAD_DLL_FN (library, gnutls_record_recv);
256 LOAD_GNUTLS_FN (library, gnutls_strerror); 247 LOAD_DLL_FN (library, gnutls_record_send);
257 LOAD_GNUTLS_FN (library, gnutls_transport_set_errno); 248 LOAD_DLL_FN (library, gnutls_strerror);
258 LOAD_GNUTLS_FN (library, gnutls_check_version); 249 LOAD_DLL_FN (library, gnutls_transport_set_errno);
250 LOAD_DLL_FN (library, gnutls_check_version);
259 /* We don't need to call gnutls_transport_set_lowat in GnuTLS 2.11.1 251 /* We don't need to call gnutls_transport_set_lowat in GnuTLS 2.11.1
260 and later, and the function was removed entirely in 3.0.0. */ 252 and later, and the function was removed entirely in 3.0.0. */
261 if (!fn_gnutls_check_version ("2.11.1")) 253 if (!fn_gnutls_check_version ("2.11.1"))
262 LOAD_GNUTLS_FN (library, gnutls_transport_set_lowat); 254 LOAD_DLL_FN (library, gnutls_transport_set_lowat);
263 LOAD_GNUTLS_FN (library, gnutls_transport_set_ptr2); 255 LOAD_DLL_FN (library, gnutls_transport_set_ptr2);
264 LOAD_GNUTLS_FN (library, gnutls_transport_set_pull_function); 256 LOAD_DLL_FN (library, gnutls_transport_set_pull_function);
265 LOAD_GNUTLS_FN (library, gnutls_transport_set_push_function); 257 LOAD_DLL_FN (library, gnutls_transport_set_push_function);
266 LOAD_GNUTLS_FN (library, gnutls_x509_crt_check_hostname); 258 LOAD_DLL_FN (library, gnutls_x509_crt_check_hostname);
267 LOAD_GNUTLS_FN (library, gnutls_x509_crt_deinit); 259 LOAD_DLL_FN (library, gnutls_x509_crt_deinit);
268 LOAD_GNUTLS_FN (library, gnutls_x509_crt_import); 260 LOAD_DLL_FN (library, gnutls_x509_crt_import);
269 LOAD_GNUTLS_FN (library, gnutls_x509_crt_init); 261 LOAD_DLL_FN (library, gnutls_x509_crt_init);
270 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_fingerprint); 262 LOAD_DLL_FN (library, gnutls_x509_crt_get_fingerprint);
271 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_version); 263 LOAD_DLL_FN (library, gnutls_x509_crt_get_version);
272 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_serial); 264 LOAD_DLL_FN (library, gnutls_x509_crt_get_serial);
273 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_issuer_dn); 265 LOAD_DLL_FN (library, gnutls_x509_crt_get_issuer_dn);
274 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_activation_time); 266 LOAD_DLL_FN (library, gnutls_x509_crt_get_activation_time);
275 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_expiration_time); 267 LOAD_DLL_FN (library, gnutls_x509_crt_get_expiration_time);
276 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_dn); 268 LOAD_DLL_FN (library, gnutls_x509_crt_get_dn);
277 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_pk_algorithm); 269 LOAD_DLL_FN (library, gnutls_x509_crt_get_pk_algorithm);
278 LOAD_GNUTLS_FN (library, gnutls_pk_algorithm_get_name); 270 LOAD_DLL_FN (library, gnutls_pk_algorithm_get_name);
279 LOAD_GNUTLS_FN (library, gnutls_pk_bits_to_sec_param); 271 LOAD_DLL_FN (library, gnutls_pk_bits_to_sec_param);
280 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_issuer_unique_id); 272 LOAD_DLL_FN (library, gnutls_x509_crt_get_issuer_unique_id);
281 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_subject_unique_id); 273 LOAD_DLL_FN (library, gnutls_x509_crt_get_subject_unique_id);
282 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_signature_algorithm); 274 LOAD_DLL_FN (library, gnutls_x509_crt_get_signature_algorithm);
283 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_signature); 275 LOAD_DLL_FN (library, gnutls_x509_crt_get_signature);
284 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_key_id); 276 LOAD_DLL_FN (library, gnutls_x509_crt_get_key_id);
285 LOAD_GNUTLS_FN (library, gnutls_sec_param_get_name); 277 LOAD_DLL_FN (library, gnutls_sec_param_get_name);
286 LOAD_GNUTLS_FN (library, gnutls_sign_get_name); 278 LOAD_DLL_FN (library, gnutls_sign_get_name);
287 LOAD_GNUTLS_FN (library, gnutls_server_name_set); 279 LOAD_DLL_FN (library, gnutls_server_name_set);
288 LOAD_GNUTLS_FN (library, gnutls_kx_get); 280 LOAD_DLL_FN (library, gnutls_kx_get);
289 LOAD_GNUTLS_FN (library, gnutls_kx_get_name); 281 LOAD_DLL_FN (library, gnutls_kx_get_name);
290 LOAD_GNUTLS_FN (library, gnutls_protocol_get_version); 282 LOAD_DLL_FN (library, gnutls_protocol_get_version);
291 LOAD_GNUTLS_FN (library, gnutls_protocol_get_name); 283 LOAD_DLL_FN (library, gnutls_protocol_get_name);
292 LOAD_GNUTLS_FN (library, gnutls_cipher_get); 284 LOAD_DLL_FN (library, gnutls_cipher_get);
293 LOAD_GNUTLS_FN (library, gnutls_cipher_get_name); 285 LOAD_DLL_FN (library, gnutls_cipher_get_name);
294 LOAD_GNUTLS_FN (library, gnutls_mac_get); 286 LOAD_DLL_FN (library, gnutls_mac_get);
295 LOAD_GNUTLS_FN (library, gnutls_mac_get_name); 287 LOAD_DLL_FN (library, gnutls_mac_get_name);
296 288
297 max_log_level = global_gnutls_log_level; 289 max_log_level = global_gnutls_log_level;
298 290
@@ -305,77 +297,76 @@ init_gnutls_functions (void)
305 return 1; 297 return 1;
306} 298}
307 299
308#else /* !WINDOWSNT */ 300# define gnutls_alert_get fn_gnutls_alert_get
309 301# define gnutls_alert_get_name fn_gnutls_alert_get_name
310#define fn_gnutls_alert_get gnutls_alert_get 302# define gnutls_alert_send_appropriate fn_gnutls_alert_send_appropriate
311#define fn_gnutls_alert_get_name gnutls_alert_get_name 303# define gnutls_anon_allocate_client_credentials fn_gnutls_anon_allocate_client_credentials
312#define fn_gnutls_alert_send_appropriate gnutls_alert_send_appropriate 304# define gnutls_anon_free_client_credentials fn_gnutls_anon_free_client_credentials
313#define fn_gnutls_anon_allocate_client_credentials gnutls_anon_allocate_client_credentials 305# define gnutls_bye fn_gnutls_bye
314#define fn_gnutls_anon_free_client_credentials gnutls_anon_free_client_credentials 306# define gnutls_certificate_allocate_credentials fn_gnutls_certificate_allocate_credentials
315#define fn_gnutls_bye gnutls_bye 307# define gnutls_certificate_free_credentials fn_gnutls_certificate_free_credentials
316#define fn_gnutls_certificate_allocate_credentials gnutls_certificate_allocate_credentials 308# define gnutls_certificate_get_peers fn_gnutls_certificate_get_peers
317#define fn_gnutls_certificate_free_credentials gnutls_certificate_free_credentials 309# define gnutls_certificate_set_verify_flags fn_gnutls_certificate_set_verify_flags
318#define fn_gnutls_certificate_get_peers gnutls_certificate_get_peers 310# define gnutls_certificate_set_x509_crl_file fn_gnutls_certificate_set_x509_crl_file
319#define fn_gnutls_certificate_set_verify_flags gnutls_certificate_set_verify_flags 311# define gnutls_certificate_set_x509_key_file fn_gnutls_certificate_set_x509_key_file
320#define fn_gnutls_certificate_set_x509_crl_file gnutls_certificate_set_x509_crl_file 312# define gnutls_certificate_set_x509_system_trust fn_gnutls_certificate_set_x509_system_trust
321#define fn_gnutls_certificate_set_x509_key_file gnutls_certificate_set_x509_key_file 313# define gnutls_certificate_set_x509_trust_file fn_gnutls_certificate_set_x509_trust_file
322#if GNUTLS_VERSION_MAJOR + \ 314# define gnutls_certificate_type_get fn_gnutls_certificate_type_get
323 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 315# define gnutls_certificate_verify_peers2 fn_gnutls_certificate_verify_peers2
324#define fn_gnutls_certificate_set_x509_system_trust gnutls_certificate_set_x509_system_trust 316# define gnutls_check_version fn_gnutls_check_version
325#endif 317# define gnutls_cipher_get fn_gnutls_cipher_get
326#define fn_gnutls_certificate_set_x509_trust_file gnutls_certificate_set_x509_trust_file 318# define gnutls_cipher_get_name fn_gnutls_cipher_get_name
327#define fn_gnutls_certificate_type_get gnutls_certificate_type_get 319# define gnutls_credentials_set fn_gnutls_credentials_set
328#define fn_gnutls_certificate_verify_peers2 gnutls_certificate_verify_peers2 320# define gnutls_deinit fn_gnutls_deinit
329#define fn_gnutls_cipher_get gnutls_cipher_get 321# define gnutls_dh_get_prime_bits fn_gnutls_dh_get_prime_bits
330#define fn_gnutls_cipher_get_name gnutls_cipher_get_name 322# define gnutls_dh_set_prime_bits fn_gnutls_dh_set_prime_bits
331#define fn_gnutls_credentials_set gnutls_credentials_set 323# define gnutls_error_is_fatal fn_gnutls_error_is_fatal
332#define fn_gnutls_deinit gnutls_deinit 324# define gnutls_global_init fn_gnutls_global_init
333#define fn_gnutls_dh_get_prime_bits gnutls_dh_get_prime_bits 325# define gnutls_global_set_audit_log_function fn_gnutls_global_set_audit_log_function
334#define fn_gnutls_dh_set_prime_bits gnutls_dh_set_prime_bits 326# define gnutls_global_set_log_function fn_gnutls_global_set_log_function
335#define fn_gnutls_error_is_fatal gnutls_error_is_fatal 327# define gnutls_global_set_log_level fn_gnutls_global_set_log_level
336#define fn_gnutls_global_init gnutls_global_init 328# define gnutls_handshake fn_gnutls_handshake
337#ifdef HAVE_GNUTLS3 329# define gnutls_init fn_gnutls_init
338#define fn_gnutls_global_set_audit_log_function gnutls_global_set_audit_log_function 330# define gnutls_kx_get fn_gnutls_kx_get
331# define gnutls_kx_get_name fn_gnutls_kx_get_name
332# define gnutls_mac_get fn_gnutls_mac_get
333# define gnutls_mac_get_name fn_gnutls_mac_get_name
334# define gnutls_pk_algorithm_get_name fn_gnutls_pk_algorithm_get_name
335# define gnutls_pk_bits_to_sec_param fn_gnutls_pk_bits_to_sec_param
336# define gnutls_priority_set_direct fn_gnutls_priority_set_direct
337# define gnutls_protocol_get_name fn_gnutls_protocol_get_name
338# define gnutls_protocol_get_version fn_gnutls_protocol_get_version
339# define gnutls_record_check_pending fn_gnutls_record_check_pending
340# define gnutls_record_recv fn_gnutls_record_recv
341# define gnutls_record_send fn_gnutls_record_send
342# define gnutls_sec_param_get_name fn_gnutls_sec_param_get_name
343# define gnutls_server_name_set fn_gnutls_server_name_set
344# define gnutls_sign_get_name fn_gnutls_sign_get_name
345# define gnutls_strerror fn_gnutls_strerror
346# define gnutls_transport_set_errno fn_gnutls_transport_set_errno
347# define gnutls_transport_set_lowat fn_gnutls_transport_set_lowat
348# define gnutls_transport_set_ptr2 fn_gnutls_transport_set_ptr2
349# define gnutls_transport_set_pull_function fn_gnutls_transport_set_pull_function
350# define gnutls_transport_set_push_function fn_gnutls_transport_set_push_function
351# define gnutls_x509_crt_check_hostname fn_gnutls_x509_crt_check_hostname
352# define gnutls_x509_crt_deinit fn_gnutls_x509_crt_deinit
353# define gnutls_x509_crt_get_activation_time fn_gnutls_x509_crt_get_activation_time
354# define gnutls_x509_crt_get_dn fn_gnutls_x509_crt_get_dn
355# define gnutls_x509_crt_get_expiration_time fn_gnutls_x509_crt_get_expiration_time
356# define gnutls_x509_crt_get_fingerprint fn_gnutls_x509_crt_get_fingerprint
357# define gnutls_x509_crt_get_issuer_dn fn_gnutls_x509_crt_get_issuer_dn
358# define gnutls_x509_crt_get_issuer_unique_id fn_gnutls_x509_crt_get_issuer_unique_id
359# define gnutls_x509_crt_get_key_id fn_gnutls_x509_crt_get_key_id
360# define gnutls_x509_crt_get_pk_algorithm fn_gnutls_x509_crt_get_pk_algorithm
361# define gnutls_x509_crt_get_serial fn_gnutls_x509_crt_get_serial
362# define gnutls_x509_crt_get_signature fn_gnutls_x509_crt_get_signature
363# define gnutls_x509_crt_get_signature_algorithm fn_gnutls_x509_crt_get_signature_algorithm
364# define gnutls_x509_crt_get_subject_unique_id fn_gnutls_x509_crt_get_subject_unique_id
365# define gnutls_x509_crt_get_version fn_gnutls_x509_crt_get_version
366# define gnutls_x509_crt_import fn_gnutls_x509_crt_import
367# define gnutls_x509_crt_init fn_gnutls_x509_crt_init
368
339#endif 369#endif
340#define fn_gnutls_global_set_log_function gnutls_global_set_log_function
341#define fn_gnutls_global_set_log_level gnutls_global_set_log_level
342#define fn_gnutls_handshake gnutls_handshake
343#define fn_gnutls_init gnutls_init
344#define fn_gnutls_kx_get gnutls_kx_get
345#define fn_gnutls_kx_get_name gnutls_kx_get_name
346#define fn_gnutls_mac_get gnutls_mac_get
347#define fn_gnutls_mac_get_name gnutls_mac_get_name
348#define fn_gnutls_pk_algorithm_get_name gnutls_pk_algorithm_get_name
349#define fn_gnutls_pk_bits_to_sec_param gnutls_pk_bits_to_sec_param
350#define fn_gnutls_priority_set_direct gnutls_priority_set_direct
351#define fn_gnutls_protocol_get_name gnutls_protocol_get_name
352#define fn_gnutls_protocol_get_version gnutls_protocol_get_version
353#define fn_gnutls_record_check_pending gnutls_record_check_pending
354#define fn_gnutls_record_recv gnutls_record_recv
355#define fn_gnutls_record_send gnutls_record_send
356#define fn_gnutls_sec_param_get_name gnutls_sec_param_get_name
357#define fn_gnutls_server_name_set gnutls_server_name_set
358#define fn_gnutls_sign_get_name gnutls_sign_get_name
359#define fn_gnutls_strerror gnutls_strerror
360#define fn_gnutls_transport_set_ptr2 gnutls_transport_set_ptr2
361#define fn_gnutls_x509_crt_check_hostname gnutls_x509_crt_check_hostname
362#define fn_gnutls_x509_crt_deinit gnutls_x509_crt_deinit
363#define fn_gnutls_x509_crt_get_activation_time gnutls_x509_crt_get_activation_time
364#define fn_gnutls_x509_crt_get_dn gnutls_x509_crt_get_dn
365#define fn_gnutls_x509_crt_get_expiration_time gnutls_x509_crt_get_expiration_time
366#define fn_gnutls_x509_crt_get_fingerprint gnutls_x509_crt_get_fingerprint
367#define fn_gnutls_x509_crt_get_issuer_dn gnutls_x509_crt_get_issuer_dn
368#define fn_gnutls_x509_crt_get_issuer_unique_id gnutls_x509_crt_get_issuer_unique_id
369#define fn_gnutls_x509_crt_get_key_id gnutls_x509_crt_get_key_id
370#define fn_gnutls_x509_crt_get_pk_algorithm gnutls_x509_crt_get_pk_algorithm
371#define fn_gnutls_x509_crt_get_serial gnutls_x509_crt_get_serial
372#define fn_gnutls_x509_crt_get_signature_algorithm gnutls_x509_crt_get_signature_algorithm
373#define fn_gnutls_x509_crt_get_subject_unique_id gnutls_x509_crt_get_subject_unique_id
374#define fn_gnutls_x509_crt_get_version gnutls_x509_crt_get_version
375#define fn_gnutls_x509_crt_import gnutls_x509_crt_import
376#define fn_gnutls_x509_crt_init gnutls_x509_crt_init
377
378#endif /* !WINDOWSNT */
379 370
380 371
381/* Report memory exhaustion if ERR is an out-of-memory indication. */ 372/* Report memory exhaustion if ERR is an out-of-memory indication. */
@@ -437,11 +428,11 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
437 /* On W32 we cannot transfer socket handles between different runtime 428 /* On W32 we cannot transfer socket handles between different runtime
438 libraries, so we tell GnuTLS to use our special push/pull 429 libraries, so we tell GnuTLS to use our special push/pull
439 functions. */ 430 functions. */
440 fn_gnutls_transport_set_ptr2 (state, 431 gnutls_transport_set_ptr2 (state,
441 (gnutls_transport_ptr_t) proc, 432 (gnutls_transport_ptr_t) proc,
442 (gnutls_transport_ptr_t) proc); 433 (gnutls_transport_ptr_t) proc);
443 fn_gnutls_transport_set_push_function (state, &emacs_gnutls_push); 434 gnutls_transport_set_push_function (state, &emacs_gnutls_push);
444 fn_gnutls_transport_set_pull_function (state, &emacs_gnutls_pull); 435 gnutls_transport_set_pull_function (state, &emacs_gnutls_pull);
445 436
446 /* For non blocking sockets or other custom made pull/push 437 /* For non blocking sockets or other custom made pull/push
447 functions the gnutls_transport_set_lowat must be called, with 438 functions the gnutls_transport_set_lowat must be called, with
@@ -454,15 +445,15 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
454 zero by default in version 2.11.1, and the function 445 zero by default in version 2.11.1, and the function
455 gnutls_transport_set_lowat was removed from the library in 446 gnutls_transport_set_lowat was removed from the library in
456 version 2.99.0. */ 447 version 2.99.0. */
457 if (!fn_gnutls_check_version ("2.11.1")) 448 if (!gnutls_check_version ("2.11.1"))
458 fn_gnutls_transport_set_lowat (state, 0); 449 gnutls_transport_set_lowat (state, 0);
459#else 450#else
460 /* This is how GnuTLS takes sockets: as file descriptors passed 451 /* This is how GnuTLS takes sockets: as file descriptors passed
461 in. For an Emacs process socket, infd and outfd are the 452 in. For an Emacs process socket, infd and outfd are the
462 same but we use this two-argument version for clarity. */ 453 same but we use this two-argument version for clarity. */
463 fn_gnutls_transport_set_ptr2 (state, 454 gnutls_transport_set_ptr2 (state,
464 (void *) (intptr_t) proc->infd, 455 (void *) (intptr_t) proc->infd,
465 (void *) (intptr_t) proc->outfd); 456 (void *) (intptr_t) proc->outfd);
466#endif 457#endif
467 458
468 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; 459 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
@@ -470,11 +461,11 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
470 461
471 do 462 do
472 { 463 {
473 ret = fn_gnutls_handshake (state); 464 ret = gnutls_handshake (state);
474 emacs_gnutls_handle_error (state, ret); 465 emacs_gnutls_handle_error (state, ret);
475 QUIT; 466 QUIT;
476 } 467 }
477 while (ret < 0 && fn_gnutls_error_is_fatal (ret) == 0); 468 while (ret < 0 && gnutls_error_is_fatal (ret) == 0);
478 469
479 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED; 470 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
480 471
@@ -485,7 +476,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
485 } 476 }
486 else 477 else
487 { 478 {
488 check_memory_full (fn_gnutls_alert_send_appropriate (state, ret)); 479 check_memory_full (gnutls_alert_send_appropriate (state, ret));
489 } 480 }
490 return ret; 481 return ret;
491} 482}
@@ -493,14 +484,14 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
493ptrdiff_t 484ptrdiff_t
494emacs_gnutls_record_check_pending (gnutls_session_t state) 485emacs_gnutls_record_check_pending (gnutls_session_t state)
495{ 486{
496 return fn_gnutls_record_check_pending (state); 487 return gnutls_record_check_pending (state);
497} 488}
498 489
499#ifdef WINDOWSNT 490#ifdef WINDOWSNT
500void 491void
501emacs_gnutls_transport_set_errno (gnutls_session_t state, int err) 492emacs_gnutls_transport_set_errno (gnutls_session_t state, int err)
502{ 493{
503 fn_gnutls_transport_set_errno (state, err); 494 gnutls_transport_set_errno (state, err);
504} 495}
505#endif 496#endif
506 497
@@ -521,7 +512,7 @@ emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte)
521 512
522 while (nbyte > 0) 513 while (nbyte > 0)
523 { 514 {
524 rtnval = fn_gnutls_record_send (state, buf, nbyte); 515 rtnval = gnutls_record_send (state, buf, nbyte);
525 516
526 if (rtnval < 0) 517 if (rtnval < 0)
527 { 518 {
@@ -573,7 +564,7 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
573 proc->gnutls_handshakes_tried = 0; 564 proc->gnutls_handshakes_tried = 0;
574 return 0; 565 return 0;
575 } 566 }
576 rtnval = fn_gnutls_record_recv (state, buf, nbyte); 567 rtnval = gnutls_record_recv (state, buf, nbyte);
577 if (rtnval >= 0) 568 if (rtnval >= 0)
578 return rtnval; 569 return rtnval;
579 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH) 570 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
@@ -608,11 +599,11 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
608 599
609 /* TODO: use gnutls-error-fatalp and gnutls-error-string. */ 600 /* TODO: use gnutls-error-fatalp and gnutls-error-string. */
610 601
611 str = fn_gnutls_strerror (err); 602 str = gnutls_strerror (err);
612 if (!str) 603 if (!str)
613 str = "unknown"; 604 str = "unknown";
614 605
615 if (fn_gnutls_error_is_fatal (err)) 606 if (gnutls_error_is_fatal (err))
616 { 607 {
617 ret = 0; 608 ret = 0;
618 GNUTLS_LOG2 (1, max_log_level, "fatal error:", str); 609 GNUTLS_LOG2 (1, max_log_level, "fatal error:", str);
@@ -639,9 +630,9 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
639 if (err == GNUTLS_E_WARNING_ALERT_RECEIVED 630 if (err == GNUTLS_E_WARNING_ALERT_RECEIVED
640 || err == GNUTLS_E_FATAL_ALERT_RECEIVED) 631 || err == GNUTLS_E_FATAL_ALERT_RECEIVED)
641 { 632 {
642 int alert = fn_gnutls_alert_get (session); 633 int alert = gnutls_alert_get (session);
643 int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1; 634 int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1;
644 str = fn_gnutls_alert_get_name (alert); 635 str = gnutls_alert_get_name (alert);
645 if (!str) 636 if (!str)
646 str = "unknown"; 637 str = "unknown";
647 638
@@ -688,20 +679,20 @@ emacs_gnutls_deinit (Lisp_Object proc)
688 if (XPROCESS (proc)->gnutls_x509_cred) 679 if (XPROCESS (proc)->gnutls_x509_cred)
689 { 680 {
690 GNUTLS_LOG (2, log_level, "Deallocating x509 credentials"); 681 GNUTLS_LOG (2, log_level, "Deallocating x509 credentials");
691 fn_gnutls_certificate_free_credentials (XPROCESS (proc)->gnutls_x509_cred); 682 gnutls_certificate_free_credentials (XPROCESS (proc)->gnutls_x509_cred);
692 XPROCESS (proc)->gnutls_x509_cred = NULL; 683 XPROCESS (proc)->gnutls_x509_cred = NULL;
693 } 684 }
694 685
695 if (XPROCESS (proc)->gnutls_anon_cred) 686 if (XPROCESS (proc)->gnutls_anon_cred)
696 { 687 {
697 GNUTLS_LOG (2, log_level, "Deallocating anon credentials"); 688 GNUTLS_LOG (2, log_level, "Deallocating anon credentials");
698 fn_gnutls_anon_free_client_credentials (XPROCESS (proc)->gnutls_anon_cred); 689 gnutls_anon_free_client_credentials (XPROCESS (proc)->gnutls_anon_cred);
699 XPROCESS (proc)->gnutls_anon_cred = NULL; 690 XPROCESS (proc)->gnutls_anon_cred = NULL;
700 } 691 }
701 692
702 if (XPROCESS (proc)->gnutls_state) 693 if (XPROCESS (proc)->gnutls_state)
703 { 694 {
704 fn_gnutls_deinit (XPROCESS (proc)->gnutls_state); 695 gnutls_deinit (XPROCESS (proc)->gnutls_state);
705 XPROCESS (proc)->gnutls_state = NULL; 696 XPROCESS (proc)->gnutls_state = NULL;
706 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) 697 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
707 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1; 698 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1;
@@ -758,7 +749,7 @@ Usage: (gnutls-error-fatalp ERROR) */)
758 if (! TYPE_RANGED_INTEGERP (int, err)) 749 if (! TYPE_RANGED_INTEGERP (int, err))
759 error ("Not an error symbol or code"); 750 error ("Not an error symbol or code");
760 751
761 if (0 == fn_gnutls_error_is_fatal (XINT (err))) 752 if (0 == gnutls_error_is_fatal (XINT (err)))
762 return Qnil; 753 return Qnil;
763 754
764 return Qt; 755 return Qt;
@@ -790,7 +781,7 @@ usage: (gnutls-error-string ERROR) */)
790 if (! TYPE_RANGED_INTEGERP (int, err)) 781 if (! TYPE_RANGED_INTEGERP (int, err))
791 return build_string ("Not an error symbol or code"); 782 return build_string ("Not an error symbol or code");
792 783
793 return build_string (fn_gnutls_strerror (XINT (err))); 784 return build_string (gnutls_strerror (XINT (err)));
794} 785}
795 786
796DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0, 787DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0,
@@ -829,7 +820,7 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
829 820
830 /* Version. */ 821 /* Version. */
831 { 822 {
832 int version = fn_gnutls_x509_crt_get_version (cert); 823 int version = gnutls_x509_crt_get_version (cert);
833 check_memory_full (version); 824 check_memory_full (version);
834 if (version >= GNUTLS_E_SUCCESS) 825 if (version >= GNUTLS_E_SUCCESS)
835 res = nconc2 (res, list2 (intern (":version"), 826 res = nconc2 (res, list2 (intern (":version"),
@@ -838,12 +829,12 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
838 829
839 /* Serial. */ 830 /* Serial. */
840 buf_size = 0; 831 buf_size = 0;
841 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &buf_size); 832 err = gnutls_x509_crt_get_serial (cert, NULL, &buf_size);
842 check_memory_full (err); 833 check_memory_full (err);
843 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 834 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
844 { 835 {
845 void *serial = xmalloc (buf_size); 836 void *serial = xmalloc (buf_size);
846 err = fn_gnutls_x509_crt_get_serial (cert, serial, &buf_size); 837 err = gnutls_x509_crt_get_serial (cert, serial, &buf_size);
847 check_memory_full (err); 838 check_memory_full (err);
848 if (err >= GNUTLS_E_SUCCESS) 839 if (err >= GNUTLS_E_SUCCESS)
849 res = nconc2 (res, list2 (intern (":serial-number"), 840 res = nconc2 (res, list2 (intern (":serial-number"),
@@ -853,12 +844,12 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
853 844
854 /* Issuer. */ 845 /* Issuer. */
855 buf_size = 0; 846 buf_size = 0;
856 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &buf_size); 847 err = gnutls_x509_crt_get_issuer_dn (cert, NULL, &buf_size);
857 check_memory_full (err); 848 check_memory_full (err);
858 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 849 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
859 { 850 {
860 char *dn = xmalloc (buf_size); 851 char *dn = xmalloc (buf_size);
861 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &buf_size); 852 err = gnutls_x509_crt_get_issuer_dn (cert, dn, &buf_size);
862 check_memory_full (err); 853 check_memory_full (err);
863 if (err >= GNUTLS_E_SUCCESS) 854 if (err >= GNUTLS_E_SUCCESS)
864 res = nconc2 (res, list2 (intern (":issuer"), 855 res = nconc2 (res, list2 (intern (":issuer"),
@@ -872,24 +863,24 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
872 that might add 1 to the year length. */ 863 that might add 1 to the year length. */
873 char buf[INT_STRLEN_BOUND (int) + 1 + sizeof "-12-31"]; 864 char buf[INT_STRLEN_BOUND (int) + 1 + sizeof "-12-31"];
874 struct tm t; 865 struct tm t;
875 time_t tim = fn_gnutls_x509_crt_get_activation_time (cert); 866 time_t tim = gnutls_x509_crt_get_activation_time (cert);
876 867
877 if (gmtime_r (&tim, &t) && strftime (buf, sizeof buf, "%Y-%m-%d", &t)) 868 if (gmtime_r (&tim, &t) && strftime (buf, sizeof buf, "%Y-%m-%d", &t))
878 res = nconc2 (res, list2 (intern (":valid-from"), build_string (buf))); 869 res = nconc2 (res, list2 (intern (":valid-from"), build_string (buf)));
879 870
880 tim = fn_gnutls_x509_crt_get_expiration_time (cert); 871 tim = gnutls_x509_crt_get_expiration_time (cert);
881 if (gmtime_r (&tim, &t) && strftime (buf, sizeof buf, "%Y-%m-%d", &t)) 872 if (gmtime_r (&tim, &t) && strftime (buf, sizeof buf, "%Y-%m-%d", &t))
882 res = nconc2 (res, list2 (intern (":valid-to"), build_string (buf))); 873 res = nconc2 (res, list2 (intern (":valid-to"), build_string (buf)));
883 } 874 }
884 875
885 /* Subject. */ 876 /* Subject. */
886 buf_size = 0; 877 buf_size = 0;
887 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &buf_size); 878 err = gnutls_x509_crt_get_dn (cert, NULL, &buf_size);
888 check_memory_full (err); 879 check_memory_full (err);
889 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 880 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
890 { 881 {
891 char *dn = xmalloc (buf_size); 882 char *dn = xmalloc (buf_size);
892 err = fn_gnutls_x509_crt_get_dn (cert, dn, &buf_size); 883 err = gnutls_x509_crt_get_dn (cert, dn, &buf_size);
893 check_memory_full (err); 884 check_memory_full (err);
894 if (err >= GNUTLS_E_SUCCESS) 885 if (err >= GNUTLS_E_SUCCESS)
895 res = nconc2 (res, list2 (intern (":subject"), 886 res = nconc2 (res, list2 (intern (":subject"),
@@ -903,17 +894,17 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
903 { 894 {
904 unsigned int bits; 895 unsigned int bits;
905 896
906 err = fn_gnutls_x509_crt_get_pk_algorithm (cert, &bits); 897 err = gnutls_x509_crt_get_pk_algorithm (cert, &bits);
907 check_memory_full (err); 898 check_memory_full (err);
908 if (err >= GNUTLS_E_SUCCESS) 899 if (err >= GNUTLS_E_SUCCESS)
909 { 900 {
910 const char *name = fn_gnutls_pk_algorithm_get_name (err); 901 const char *name = gnutls_pk_algorithm_get_name (err);
911 if (name) 902 if (name)
912 res = nconc2 (res, list2 (intern (":public-key-algorithm"), 903 res = nconc2 (res, list2 (intern (":public-key-algorithm"),
913 build_string (name))); 904 build_string (name)));
914 905
915 name = fn_gnutls_sec_param_get_name (fn_gnutls_pk_bits_to_sec_param 906 name = gnutls_sec_param_get_name (gnutls_pk_bits_to_sec_param
916 (err, bits)); 907 (err, bits));
917 res = nconc2 (res, list2 (intern (":certificate-security-level"), 908 res = nconc2 (res, list2 (intern (":certificate-security-level"),
918 build_string (name))); 909 build_string (name)));
919 } 910 }
@@ -921,12 +912,12 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
921 912
922 /* Unique IDs. */ 913 /* Unique IDs. */
923 buf_size = 0; 914 buf_size = 0;
924 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size); 915 err = gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size);
925 check_memory_full (err); 916 check_memory_full (err);
926 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 917 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
927 { 918 {
928 char *buf = xmalloc (buf_size); 919 char *buf = xmalloc (buf_size);
929 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size); 920 err = gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size);
930 check_memory_full (err); 921 check_memory_full (err);
931 if (err >= GNUTLS_E_SUCCESS) 922 if (err >= GNUTLS_E_SUCCESS)
932 res = nconc2 (res, list2 (intern (":issuer-unique-id"), 923 res = nconc2 (res, list2 (intern (":issuer-unique-id"),
@@ -935,12 +926,12 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
935 } 926 }
936 927
937 buf_size = 0; 928 buf_size = 0;
938 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size); 929 err = gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size);
939 check_memory_full (err); 930 check_memory_full (err);
940 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 931 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
941 { 932 {
942 char *buf = xmalloc (buf_size); 933 char *buf = xmalloc (buf_size);
943 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size); 934 err = gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size);
944 check_memory_full (err); 935 check_memory_full (err);
945 if (err >= GNUTLS_E_SUCCESS) 936 if (err >= GNUTLS_E_SUCCESS)
946 res = nconc2 (res, list2 (intern (":subject-unique-id"), 937 res = nconc2 (res, list2 (intern (":subject-unique-id"),
@@ -950,11 +941,11 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
950#endif 941#endif
951 942
952 /* Signature. */ 943 /* Signature. */
953 err = fn_gnutls_x509_crt_get_signature_algorithm (cert); 944 err = gnutls_x509_crt_get_signature_algorithm (cert);
954 check_memory_full (err); 945 check_memory_full (err);
955 if (err >= GNUTLS_E_SUCCESS) 946 if (err >= GNUTLS_E_SUCCESS)
956 { 947 {
957 const char *name = fn_gnutls_sign_get_name (err); 948 const char *name = gnutls_sign_get_name (err);
958 if (name) 949 if (name)
959 res = nconc2 (res, list2 (intern (":signature-algorithm"), 950 res = nconc2 (res, list2 (intern (":signature-algorithm"),
960 build_string (name))); 951 build_string (name)));
@@ -962,12 +953,12 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
962 953
963 /* Public key ID. */ 954 /* Public key ID. */
964 buf_size = 0; 955 buf_size = 0;
965 err = fn_gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size); 956 err = gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size);
966 check_memory_full (err); 957 check_memory_full (err);
967 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 958 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
968 { 959 {
969 void *buf = xmalloc (buf_size); 960 void *buf = xmalloc (buf_size);
970 err = fn_gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size); 961 err = gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size);
971 check_memory_full (err); 962 check_memory_full (err);
972 if (err >= GNUTLS_E_SUCCESS) 963 if (err >= GNUTLS_E_SUCCESS)
973 res = nconc2 (res, list2 (intern (":public-key-id"), 964 res = nconc2 (res, list2 (intern (":public-key-id"),
@@ -977,14 +968,14 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
977 968
978 /* Certificate fingerprint. */ 969 /* Certificate fingerprint. */
979 buf_size = 0; 970 buf_size = 0;
980 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 971 err = gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
981 NULL, &buf_size); 972 NULL, &buf_size);
982 check_memory_full (err); 973 check_memory_full (err);
983 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 974 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
984 { 975 {
985 void *buf = xmalloc (buf_size); 976 void *buf = xmalloc (buf_size);
986 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 977 err = gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
987 buf, &buf_size); 978 buf, &buf_size);
988 check_memory_full (err); 979 check_memory_full (err);
989 if (err >= GNUTLS_E_SUCCESS) 980 if (err >= GNUTLS_E_SUCCESS)
990 res = nconc2 (res, list2 (intern (":certificate-id"), 981 res = nconc2 (res, list2 (intern (":certificate-id"),
@@ -1086,7 +1077,7 @@ The return value is a property list with top-level keys :warnings and
1086 1077
1087 /* Diffie-Hellman prime bits. */ 1078 /* Diffie-Hellman prime bits. */
1088 { 1079 {
1089 int bits = fn_gnutls_dh_get_prime_bits (state); 1080 int bits = gnutls_dh_get_prime_bits (state);
1090 check_memory_full (bits); 1081 check_memory_full (bits);
1091 if (bits > 0) 1082 if (bits > 0)
1092 result = nconc2 (result, list2 (intern (":diffie-hellman-prime-bits"), 1083 result = nconc2 (result, list2 (intern (":diffie-hellman-prime-bits"),
@@ -1096,26 +1087,26 @@ The return value is a property list with top-level keys :warnings and
1096 /* Key exchange. */ 1087 /* Key exchange. */
1097 result = nconc2 1088 result = nconc2
1098 (result, list2 (intern (":key-exchange"), 1089 (result, list2 (intern (":key-exchange"),
1099 build_string (fn_gnutls_kx_get_name 1090 build_string (gnutls_kx_get_name
1100 (fn_gnutls_kx_get (state))))); 1091 (gnutls_kx_get (state)))));
1101 1092
1102 /* Protocol name. */ 1093 /* Protocol name. */
1103 result = nconc2 1094 result = nconc2
1104 (result, list2 (intern (":protocol"), 1095 (result, list2 (intern (":protocol"),
1105 build_string (fn_gnutls_protocol_get_name 1096 build_string (gnutls_protocol_get_name
1106 (fn_gnutls_protocol_get_version (state))))); 1097 (gnutls_protocol_get_version (state)))));
1107 1098
1108 /* Cipher name. */ 1099 /* Cipher name. */
1109 result = nconc2 1100 result = nconc2
1110 (result, list2 (intern (":cipher"), 1101 (result, list2 (intern (":cipher"),
1111 build_string (fn_gnutls_cipher_get_name 1102 build_string (gnutls_cipher_get_name
1112 (fn_gnutls_cipher_get (state))))); 1103 (gnutls_cipher_get (state)))));
1113 1104
1114 /* MAC name. */ 1105 /* MAC name. */
1115 result = nconc2 1106 result = nconc2
1116 (result, list2 (intern (":mac"), 1107 (result, list2 (intern (":mac"),
1117 build_string (fn_gnutls_mac_get_name 1108 build_string (gnutls_mac_get_name
1118 (fn_gnutls_mac_get (state))))); 1109 (gnutls_mac_get (state)))));
1119 1110
1120 1111
1121 return result; 1112 return result;
@@ -1130,7 +1121,7 @@ emacs_gnutls_global_init (void)
1130 int ret = GNUTLS_E_SUCCESS; 1121 int ret = GNUTLS_E_SUCCESS;
1131 1122
1132 if (!gnutls_global_initialized) 1123 if (!gnutls_global_initialized)
1133 ret = fn_gnutls_global_init (); 1124 ret = gnutls_global_init ();
1134 1125
1135 gnutls_global_initialized = 1; 1126 gnutls_global_initialized = 1;
1136 1127
@@ -1280,11 +1271,11 @@ one trustfile (usually a CA bundle). */)
1280 1271
1281 if (TYPE_RANGED_INTEGERP (int, loglevel)) 1272 if (TYPE_RANGED_INTEGERP (int, loglevel))
1282 { 1273 {
1283 fn_gnutls_global_set_log_function (gnutls_log_function); 1274 gnutls_global_set_log_function (gnutls_log_function);
1284#ifdef HAVE_GNUTLS3 1275#ifdef HAVE_GNUTLS3
1285 fn_gnutls_global_set_audit_log_function (gnutls_audit_log_function); 1276 gnutls_global_set_audit_log_function (gnutls_audit_log_function);
1286#endif 1277#endif
1287 fn_gnutls_global_set_log_level (XINT (loglevel)); 1278 gnutls_global_set_log_level (XINT (loglevel));
1288 max_log_level = XINT (loglevel); 1279 max_log_level = XINT (loglevel);
1289 XPROCESS (proc)->gnutls_log_level = max_log_level; 1280 XPROCESS (proc)->gnutls_log_level = max_log_level;
1290 } 1281 }
@@ -1314,8 +1305,7 @@ one trustfile (usually a CA bundle). */)
1314 unsigned int gnutls_verify_flags = GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT; 1305 unsigned int gnutls_verify_flags = GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT;
1315 1306
1316 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); 1307 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials");
1317 check_memory_full ((fn_gnutls_certificate_allocate_credentials 1308 check_memory_full (gnutls_certificate_allocate_credentials (&x509_cred));
1318 (&x509_cred)));
1319 XPROCESS (proc)->gnutls_x509_cred = x509_cred; 1309 XPROCESS (proc)->gnutls_x509_cred = x509_cred;
1320 1310
1321 verify_flags = Fplist_get (proplist, QCgnutls_bootprop_verify_flags); 1311 verify_flags = Fplist_get (proplist, QCgnutls_bootprop_verify_flags);
@@ -1329,13 +1319,12 @@ one trustfile (usually a CA bundle). */)
1329 else 1319 else
1330 GNUTLS_LOG (2, max_log_level, "ignoring invalid verify-flags"); 1320 GNUTLS_LOG (2, max_log_level, "ignoring invalid verify-flags");
1331 1321
1332 fn_gnutls_certificate_set_verify_flags (x509_cred, gnutls_verify_flags); 1322 gnutls_certificate_set_verify_flags (x509_cred, gnutls_verify_flags);
1333 } 1323 }
1334 else /* Qgnutls_anon: */ 1324 else /* Qgnutls_anon: */
1335 { 1325 {
1336 GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); 1326 GNUTLS_LOG (2, max_log_level, "allocating anon credentials");
1337 check_memory_full ((fn_gnutls_anon_allocate_client_credentials 1327 check_memory_full (gnutls_anon_allocate_client_credentials (&anon_cred));
1338 (&anon_cred)));
1339 XPROCESS (proc)->gnutls_anon_cred = anon_cred; 1328 XPROCESS (proc)->gnutls_anon_cred = anon_cred;
1340 } 1329 }
1341 1330
@@ -1349,7 +1338,7 @@ one trustfile (usually a CA bundle). */)
1349 1338
1350#if GNUTLS_VERSION_MAJOR + \ 1339#if GNUTLS_VERSION_MAJOR + \
1351 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 1340 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3
1352 ret = fn_gnutls_certificate_set_x509_system_trust (x509_cred); 1341 ret = gnutls_certificate_set_x509_system_trust (x509_cred);
1353 if (ret < GNUTLS_E_SUCCESS) 1342 if (ret < GNUTLS_E_SUCCESS)
1354 { 1343 {
1355 check_memory_full (ret); 1344 check_memory_full (ret);
@@ -1372,7 +1361,7 @@ one trustfile (usually a CA bundle). */)
1372 name using the current ANSI codepage. */ 1361 name using the current ANSI codepage. */
1373 trustfile = ansi_encode_filename (trustfile); 1362 trustfile = ansi_encode_filename (trustfile);
1374#endif 1363#endif
1375 ret = fn_gnutls_certificate_set_x509_trust_file 1364 ret = gnutls_certificate_set_x509_trust_file
1376 (x509_cred, 1365 (x509_cred,
1377 SSDATA (trustfile), 1366 SSDATA (trustfile),
1378 file_format); 1367 file_format);
@@ -1398,7 +1387,7 @@ one trustfile (usually a CA bundle). */)
1398#ifdef WINDOWSNT 1387#ifdef WINDOWSNT
1399 crlfile = ansi_encode_filename (crlfile); 1388 crlfile = ansi_encode_filename (crlfile);
1400#endif 1389#endif
1401 ret = fn_gnutls_certificate_set_x509_crl_file 1390 ret = gnutls_certificate_set_x509_crl_file
1402 (x509_cred, SSDATA (crlfile), file_format); 1391 (x509_cred, SSDATA (crlfile), file_format);
1403 1392
1404 if (ret < GNUTLS_E_SUCCESS) 1393 if (ret < GNUTLS_E_SUCCESS)
@@ -1427,7 +1416,7 @@ one trustfile (usually a CA bundle). */)
1427 keyfile = ansi_encode_filename (keyfile); 1416 keyfile = ansi_encode_filename (keyfile);
1428 certfile = ansi_encode_filename (certfile); 1417 certfile = ansi_encode_filename (certfile);
1429#endif 1418#endif
1430 ret = fn_gnutls_certificate_set_x509_key_file 1419 ret = gnutls_certificate_set_x509_key_file
1431 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format); 1420 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format);
1432 1421
1433 if (ret < GNUTLS_E_SUCCESS) 1422 if (ret < GNUTLS_E_SUCCESS)
@@ -1449,7 +1438,7 @@ one trustfile (usually a CA bundle). */)
1449 /* Call gnutls_init here: */ 1438 /* Call gnutls_init here: */
1450 1439
1451 GNUTLS_LOG (1, max_log_level, "gnutls_init"); 1440 GNUTLS_LOG (1, max_log_level, "gnutls_init");
1452 ret = fn_gnutls_init (&state, GNUTLS_CLIENT); 1441 ret = gnutls_init (&state, GNUTLS_CLIENT);
1453 XPROCESS (proc)->gnutls_state = state; 1442 XPROCESS (proc)->gnutls_state = state;
1454 if (ret < GNUTLS_E_SUCCESS) 1443 if (ret < GNUTLS_E_SUCCESS)
1455 return gnutls_make_error (ret); 1444 return gnutls_make_error (ret);
@@ -1468,27 +1457,25 @@ one trustfile (usually a CA bundle). */)
1468 } 1457 }
1469 1458
1470 GNUTLS_LOG (1, max_log_level, "setting the priority string"); 1459 GNUTLS_LOG (1, max_log_level, "setting the priority string");
1471 ret = fn_gnutls_priority_set_direct (state, 1460 ret = gnutls_priority_set_direct (state, priority_string_ptr, NULL);
1472 priority_string_ptr,
1473 NULL);
1474 if (ret < GNUTLS_E_SUCCESS) 1461 if (ret < GNUTLS_E_SUCCESS)
1475 return gnutls_make_error (ret); 1462 return gnutls_make_error (ret);
1476 1463
1477 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY; 1464 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY;
1478 1465
1479 if (INTEGERP (prime_bits)) 1466 if (INTEGERP (prime_bits))
1480 fn_gnutls_dh_set_prime_bits (state, XUINT (prime_bits)); 1467 gnutls_dh_set_prime_bits (state, XUINT (prime_bits));
1481 1468
1482 ret = EQ (type, Qgnutls_x509pki) 1469 ret = EQ (type, Qgnutls_x509pki)
1483 ? fn_gnutls_credentials_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred) 1470 ? gnutls_credentials_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred)
1484 : fn_gnutls_credentials_set (state, GNUTLS_CRD_ANON, anon_cred); 1471 : gnutls_credentials_set (state, GNUTLS_CRD_ANON, anon_cred);
1485 if (ret < GNUTLS_E_SUCCESS) 1472 if (ret < GNUTLS_E_SUCCESS)
1486 return gnutls_make_error (ret); 1473 return gnutls_make_error (ret);
1487 1474
1488 if (!gnutls_ip_address_p (c_hostname)) 1475 if (!gnutls_ip_address_p (c_hostname))
1489 { 1476 {
1490 ret = fn_gnutls_server_name_set (state, GNUTLS_NAME_DNS, c_hostname, 1477 ret = gnutls_server_name_set (state, GNUTLS_NAME_DNS, c_hostname,
1491 strlen (c_hostname)); 1478 strlen (c_hostname));
1492 if (ret < GNUTLS_E_SUCCESS) 1479 if (ret < GNUTLS_E_SUCCESS)
1493 return gnutls_make_error (ret); 1480 return gnutls_make_error (ret);
1494 } 1481 }
@@ -1504,7 +1491,7 @@ one trustfile (usually a CA bundle). */)
1504 check of the certificate's hostname with 1491 check of the certificate's hostname with
1505 gnutls_x509_crt_check_hostname against :hostname. */ 1492 gnutls_x509_crt_check_hostname against :hostname. */
1506 1493
1507 ret = fn_gnutls_certificate_verify_peers2 (state, &peer_verification); 1494 ret = gnutls_certificate_verify_peers2 (state, &peer_verification);
1508 if (ret < GNUTLS_E_SUCCESS) 1495 if (ret < GNUTLS_E_SUCCESS)
1509 return gnutls_make_error (ret); 1496 return gnutls_make_error (ret);
1510 1497
@@ -1542,41 +1529,41 @@ one trustfile (usually a CA bundle). */)
1542 /* Up to here the process is the same for X.509 certificates and 1529 /* Up to here the process is the same for X.509 certificates and
1543 OpenPGP keys. From now on X.509 certificates are assumed. This 1530 OpenPGP keys. From now on X.509 certificates are assumed. This
1544 can be easily extended to work with openpgp keys as well. */ 1531 can be easily extended to work with openpgp keys as well. */
1545 if (fn_gnutls_certificate_type_get (state) == GNUTLS_CRT_X509) 1532 if (gnutls_certificate_type_get (state) == GNUTLS_CRT_X509)
1546 { 1533 {
1547 gnutls_x509_crt_t gnutls_verify_cert; 1534 gnutls_x509_crt_t gnutls_verify_cert;
1548 const gnutls_datum_t *gnutls_verify_cert_list; 1535 const gnutls_datum_t *gnutls_verify_cert_list;
1549 unsigned int gnutls_verify_cert_list_size; 1536 unsigned int gnutls_verify_cert_list_size;
1550 1537
1551 ret = fn_gnutls_x509_crt_init (&gnutls_verify_cert); 1538 ret = gnutls_x509_crt_init (&gnutls_verify_cert);
1552 if (ret < GNUTLS_E_SUCCESS) 1539 if (ret < GNUTLS_E_SUCCESS)
1553 return gnutls_make_error (ret); 1540 return gnutls_make_error (ret);
1554 1541
1555 gnutls_verify_cert_list = 1542 gnutls_verify_cert_list =
1556 fn_gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size); 1543 gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size);
1557 1544
1558 if (gnutls_verify_cert_list == NULL) 1545 if (gnutls_verify_cert_list == NULL)
1559 { 1546 {
1560 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1547 gnutls_x509_crt_deinit (gnutls_verify_cert);
1561 emacs_gnutls_deinit (proc); 1548 emacs_gnutls_deinit (proc);
1562 error ("No x509 certificate was found\n"); 1549 error ("No x509 certificate was found\n");
1563 } 1550 }
1564 1551
1565 /* We only check the first certificate in the given chain. */ 1552 /* We only check the first certificate in the given chain. */
1566 ret = fn_gnutls_x509_crt_import (gnutls_verify_cert, 1553 ret = gnutls_x509_crt_import (gnutls_verify_cert,
1567 &gnutls_verify_cert_list[0], 1554 &gnutls_verify_cert_list[0],
1568 GNUTLS_X509_FMT_DER); 1555 GNUTLS_X509_FMT_DER);
1569 1556
1570 if (ret < GNUTLS_E_SUCCESS) 1557 if (ret < GNUTLS_E_SUCCESS)
1571 { 1558 {
1572 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1559 gnutls_x509_crt_deinit (gnutls_verify_cert);
1573 return gnutls_make_error (ret); 1560 return gnutls_make_error (ret);
1574 } 1561 }
1575 1562
1576 XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert; 1563 XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert;
1577 1564
1578 int err 1565 int err = gnutls_x509_crt_check_hostname (gnutls_verify_cert,
1579 = fn_gnutls_x509_crt_check_hostname (gnutls_verify_cert, c_hostname); 1566 c_hostname);
1580 check_memory_full (err); 1567 check_memory_full (err);
1581 if (!err) 1568 if (!err)
1582 { 1569 {
@@ -1585,7 +1572,7 @@ one trustfile (usually a CA bundle). */)
1585 if (verify_error_all 1572 if (verify_error_all
1586 || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error))) 1573 || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error)))
1587 { 1574 {
1588 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1575 gnutls_x509_crt_deinit (gnutls_verify_cert);
1589 emacs_gnutls_deinit (proc); 1576 emacs_gnutls_deinit (proc);
1590 error ("The x509 certificate does not match \"%s\"", c_hostname); 1577 error ("The x509 certificate does not match \"%s\"", c_hostname);
1591 } 1578 }
@@ -1626,10 +1613,9 @@ This function may also return `gnutls-e-again', or
1626 1613
1627 state = XPROCESS (proc)->gnutls_state; 1614 state = XPROCESS (proc)->gnutls_state;
1628 1615
1629 fn_gnutls_x509_crt_deinit (XPROCESS (proc)->gnutls_certificate); 1616 gnutls_x509_crt_deinit (XPROCESS (proc)->gnutls_certificate);
1630 1617
1631 ret = fn_gnutls_bye (state, 1618 ret = gnutls_bye (state, NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
1632 NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
1633 1619
1634 return gnutls_make_error (ret); 1620 return gnutls_make_error (ret);
1635} 1621}
diff --git a/src/image.c b/src/image.c
index a73a7251753..4cba8863b88 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1859,19 +1859,6 @@ mark_image_cache (struct image_cache *c)
1859 X / NS / W32 support code 1859 X / NS / W32 support code
1860 ***********************************************************************/ 1860 ***********************************************************************/
1861 1861
1862#ifdef WINDOWSNT
1863
1864/* Macro for defining functions that will be loaded from image DLLs. */
1865#define DEF_IMGLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
1866
1867/* Macro for loading those image functions from the library. */
1868#define LOAD_IMGLIB_FN(lib,func) { \
1869 fn_##func = (void *) GetProcAddress (lib, #func); \
1870 if (!fn_##func) return 0; \
1871 }
1872
1873#endif /* WINDOWSNT */
1874
1875/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the 1862/* Return true if XIMG's size WIDTH x HEIGHT doesn't break the
1876 windowing system. 1863 windowing system.
1877 WIDTH and HEIGHT must both be positive. 1864 WIDTH and HEIGHT must both be positive.
@@ -3377,12 +3364,14 @@ xpm_free_colors (Display *dpy, Colormap cmap, Pixel *pixels, int npixels, void *
3377 3364
3378/* XPM library details. */ 3365/* XPM library details. */
3379 3366
3380DEF_IMGLIB_FN (void, XpmFreeAttributes, (XpmAttributes *)); 3367DEF_DLL_FN (void, XpmFreeAttributes, (XpmAttributes *));
3381DEF_IMGLIB_FN (int, XpmCreateImageFromBuffer, (Display *, char *, xpm_XImage **, 3368DEF_DLL_FN (int, XpmCreateImageFromBuffer,
3382 xpm_XImage **, XpmAttributes *)); 3369 (Display *, char *, xpm_XImage **,
3383DEF_IMGLIB_FN (int, XpmReadFileToImage, (Display *, char *, xpm_XImage **, 3370 xpm_XImage **, XpmAttributes *));
3384 xpm_XImage **, XpmAttributes *)); 3371DEF_DLL_FN (int, XpmReadFileToImage,
3385DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *)); 3372 (Display *, char *, xpm_XImage **,
3373 xpm_XImage **, XpmAttributes *));
3374DEF_DLL_FN (void, XImageFree, (xpm_XImage *));
3386 3375
3387static bool 3376static bool
3388init_xpm_functions (void) 3377init_xpm_functions (void)
@@ -3392,22 +3381,24 @@ init_xpm_functions (void)
3392 if (!(library = w32_delayed_load (Qxpm))) 3381 if (!(library = w32_delayed_load (Qxpm)))
3393 return 0; 3382 return 0;
3394 3383
3395 LOAD_IMGLIB_FN (library, XpmFreeAttributes); 3384 LOAD_DLL_FN (library, XpmFreeAttributes);
3396 LOAD_IMGLIB_FN (library, XpmCreateImageFromBuffer); 3385 LOAD_DLL_FN (library, XpmCreateImageFromBuffer);
3397 LOAD_IMGLIB_FN (library, XpmReadFileToImage); 3386 LOAD_DLL_FN (library, XpmReadFileToImage);
3398 LOAD_IMGLIB_FN (library, XImageFree); 3387 LOAD_DLL_FN (library, XImageFree);
3399 return 1; 3388 return 1;
3400} 3389}
3401 3390
3402#endif /* WINDOWSNT */ 3391# undef XImageFree
3392# undef XpmCreateImageFromBuffer
3393# undef XpmFreeAttributes
3394# undef XpmReadFileToImage
3403 3395
3404#if defined HAVE_NTGUI && !defined WINDOWSNT 3396# define XImageFree fn_XImageFree
3405/* Glue for code below */ 3397# define XpmCreateImageFromBuffer fn_XpmCreateImageFromBuffer
3406#define fn_XpmReadFileToImage XpmReadFileToImage 3398# define XpmFreeAttributes fn_XpmFreeAttributes
3407#define fn_XpmCreateImageFromBuffer XpmCreateImageFromBuffer 3399# define XpmReadFileToImage fn_XpmReadFileToImage
3408#define fn_XImageFree XImageFree 3400
3409#define fn_XpmFreeAttributes XpmFreeAttributes 3401#endif /* WINDOWSNT */
3410#endif /* HAVE_NTGUI && !WINDOWSNT */
3411 3402
3412/* Value is true if COLOR_SYMBOLS is a valid color symbols list 3403/* Value is true if COLOR_SYMBOLS is a valid color symbols list
3413 for XPM images. Such a list must consist of conses whose car and 3404 for XPM images. Such a list must consist of conses whose car and
@@ -3624,9 +3615,9 @@ xpm_load (struct frame *f, struct image *img)
3624#endif 3615#endif
3625 /* XpmReadFileToPixmap is not available in the Windows port of 3616 /* XpmReadFileToPixmap is not available in the Windows port of
3626 libxpm. But XpmReadFileToImage almost does what we want. */ 3617 libxpm. But XpmReadFileToImage almost does what we want. */
3627 rc = fn_XpmReadFileToImage (&hdc, SDATA (file), 3618 rc = XpmReadFileToImage (&hdc, SDATA (file),
3628 &xpm_image, &xpm_mask, 3619 &xpm_image, &xpm_mask,
3629 &attrs); 3620 &attrs);
3630#else 3621#else
3631 rc = XpmReadFileToImage (FRAME_X_DISPLAY (f), SSDATA (file), 3622 rc = XpmReadFileToImage (FRAME_X_DISPLAY (f), SSDATA (file),
3632 &img->ximg, &img->mask_img, 3623 &img->ximg, &img->mask_img,
@@ -3648,9 +3639,9 @@ xpm_load (struct frame *f, struct image *img)
3648#ifdef HAVE_NTGUI 3639#ifdef HAVE_NTGUI
3649 /* XpmCreatePixmapFromBuffer is not available in the Windows port 3640 /* XpmCreatePixmapFromBuffer is not available in the Windows port
3650 of libxpm. But XpmCreateImageFromBuffer almost does what we want. */ 3641 of libxpm. But XpmCreateImageFromBuffer almost does what we want. */
3651 rc = fn_XpmCreateImageFromBuffer (&hdc, SDATA (buffer), 3642 rc = XpmCreateImageFromBuffer (&hdc, SDATA (buffer),
3652 &xpm_image, &xpm_mask, 3643 &xpm_image, &xpm_mask,
3653 &attrs); 3644 &attrs);
3654#else 3645#else
3655 rc = XpmCreateImageFromBuffer (FRAME_X_DISPLAY (f), SSDATA (buffer), 3646 rc = XpmCreateImageFromBuffer (FRAME_X_DISPLAY (f), SSDATA (buffer),
3656 &img->ximg, &img->mask_img, 3647 &img->ximg, &img->mask_img,
@@ -3699,7 +3690,7 @@ xpm_load (struct frame *f, struct image *img)
3699 img->pixmap = xpm_image->bitmap; 3690 img->pixmap = xpm_image->bitmap;
3700 /* XImageFree in libXpm frees XImage struct without destroying 3691 /* XImageFree in libXpm frees XImage struct without destroying
3701 the bitmap, which is what we want. */ 3692 the bitmap, which is what we want. */
3702 fn_XImageFree (xpm_image); 3693 XImageFree (xpm_image);
3703 } 3694 }
3704 if (xpm_mask && xpm_mask->bitmap) 3695 if (xpm_mask && xpm_mask->bitmap)
3705 { 3696 {
@@ -3713,7 +3704,7 @@ xpm_load (struct frame *f, struct image *img)
3713 SelectObject (hdc, old_obj); 3704 SelectObject (hdc, old_obj);
3714 3705
3715 img->mask = xpm_mask->bitmap; 3706 img->mask = xpm_mask->bitmap;
3716 fn_XImageFree (xpm_mask); 3707 XImageFree (xpm_mask);
3717 DeleteDC (hdc); 3708 DeleteDC (hdc);
3718 } 3709 }
3719 3710
@@ -3737,11 +3728,7 @@ xpm_load (struct frame *f, struct image *img)
3737 eassert (img->width > 0 && img->height > 0); 3728 eassert (img->width > 0 && img->height > 0);
3738 3729
3739 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */ 3730 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
3740#ifdef HAVE_NTGUI
3741 fn_XpmFreeAttributes (&attrs);
3742#else
3743 XpmFreeAttributes (&attrs); 3731 XpmFreeAttributes (&attrs);
3744#endif /* HAVE_NTGUI */
3745 3732
3746#ifdef HAVE_X_WINDOWS 3733#ifdef HAVE_X_WINDOWS
3747 /* Maybe fill in the background field while we have ximg handy. */ 3734 /* Maybe fill in the background field while we have ximg handy. */
@@ -5535,39 +5522,42 @@ png_image_p (Lisp_Object object)
5535 5522
5536#if defined HAVE_PNG && !defined HAVE_NS 5523#if defined HAVE_PNG && !defined HAVE_NS
5537 5524
5538#ifdef WINDOWSNT 5525# ifdef WINDOWSNT
5539/* PNG library details. */ 5526/* PNG library details. */
5540 5527
5541DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp)); 5528DEF_DLL_FN (png_voidp, png_get_io_ptr, (png_structp));
5542DEF_IMGLIB_FN (int, png_sig_cmp, (png_bytep, png_size_t, png_size_t)); 5529DEF_DLL_FN (int, png_sig_cmp, (png_bytep, png_size_t, png_size_t));
5543DEF_IMGLIB_FN (png_structp, png_create_read_struct, (png_const_charp, png_voidp, 5530DEF_DLL_FN (png_structp, png_create_read_struct,
5544 png_error_ptr, png_error_ptr)); 5531 (png_const_charp, png_voidp, png_error_ptr, png_error_ptr));
5545DEF_IMGLIB_FN (png_infop, png_create_info_struct, (png_structp)); 5532DEF_DLL_FN (png_infop, png_create_info_struct, (png_structp));
5546DEF_IMGLIB_FN (void, png_destroy_read_struct, (png_structpp, png_infopp, png_infopp)); 5533DEF_DLL_FN (void, png_destroy_read_struct,
5547DEF_IMGLIB_FN (void, png_set_read_fn, (png_structp, png_voidp, png_rw_ptr)); 5534 (png_structpp, png_infopp, png_infopp));
5548DEF_IMGLIB_FN (void, png_set_sig_bytes, (png_structp, int)); 5535DEF_DLL_FN (void, png_set_read_fn, (png_structp, png_voidp, png_rw_ptr));
5549DEF_IMGLIB_FN (void, png_read_info, (png_structp, png_infop)); 5536DEF_DLL_FN (void, png_set_sig_bytes, (png_structp, int));
5550DEF_IMGLIB_FN (png_uint_32, png_get_IHDR, (png_structp, png_infop, 5537DEF_DLL_FN (void, png_read_info, (png_structp, png_infop));
5551 png_uint_32 *, png_uint_32 *, 5538DEF_DLL_FN (png_uint_32, png_get_IHDR,
5552 int *, int *, int *, int *, int *)); 5539 (png_structp, png_infop, png_uint_32 *, png_uint_32 *,
5553DEF_IMGLIB_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32)); 5540 int *, int *, int *, int *, int *));
5554DEF_IMGLIB_FN (void, png_set_strip_16, (png_structp)); 5541DEF_DLL_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32));
5555DEF_IMGLIB_FN (void, png_set_expand, (png_structp)); 5542DEF_DLL_FN (void, png_set_strip_16, (png_structp));
5556DEF_IMGLIB_FN (void, png_set_gray_to_rgb, (png_structp)); 5543DEF_DLL_FN (void, png_set_expand, (png_structp));
5557DEF_IMGLIB_FN (void, png_set_background, (png_structp, png_color_16p, 5544DEF_DLL_FN (void, png_set_gray_to_rgb, (png_structp));
5558 int, int, double)); 5545DEF_DLL_FN (void, png_set_background,
5559DEF_IMGLIB_FN (png_uint_32, png_get_bKGD, (png_structp, png_infop, png_color_16p *)); 5546 (png_structp, png_color_16p, int, int, double));
5560DEF_IMGLIB_FN (void, png_read_update_info, (png_structp, png_infop)); 5547DEF_DLL_FN (png_uint_32, png_get_bKGD,
5561DEF_IMGLIB_FN (png_byte, png_get_channels, (png_structp, png_infop)); 5548 (png_structp, png_infop, png_color_16p *));
5562DEF_IMGLIB_FN (png_size_t, png_get_rowbytes, (png_structp, png_infop)); 5549DEF_DLL_FN (void, png_read_update_info, (png_structp, png_infop));
5563DEF_IMGLIB_FN (void, png_read_image, (png_structp, png_bytepp)); 5550DEF_DLL_FN (png_byte, png_get_channels, (png_structp, png_infop));
5564DEF_IMGLIB_FN (void, png_read_end, (png_structp, png_infop)); 5551DEF_DLL_FN (png_size_t, png_get_rowbytes, (png_structp, png_infop));
5565DEF_IMGLIB_FN (void, png_error, (png_structp, png_const_charp)); 5552DEF_DLL_FN (void, png_read_image, (png_structp, png_bytepp));
5566 5553DEF_DLL_FN (void, png_read_end, (png_structp, png_infop));
5567#if (PNG_LIBPNG_VER >= 10500) 5554DEF_DLL_FN (void, png_error, (png_structp, png_const_charp));
5568DEF_IMGLIB_FN (void, png_longjmp, (png_structp, int)) PNG_NORETURN; 5555
5569DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t)); 5556# if (PNG_LIBPNG_VER >= 10500)
5570#endif /* libpng version >= 1.5 */ 5557DEF_DLL_FN (void, png_longjmp, (png_structp, int)) PNG_NORETURN;
5558DEF_DLL_FN (jmp_buf *, png_set_longjmp_fn,
5559 (png_structp, png_longjmp_ptr, size_t));
5560# endif /* libpng version >= 1.5 */
5571 5561
5572static bool 5562static bool
5573init_png_functions (void) 5563init_png_functions (void)
@@ -5577,87 +5567,107 @@ init_png_functions (void)
5577 if (!(library = w32_delayed_load (Qpng))) 5567 if (!(library = w32_delayed_load (Qpng)))
5578 return 0; 5568 return 0;
5579 5569
5580 LOAD_IMGLIB_FN (library, png_get_io_ptr); 5570 LOAD_DLL_FN (library, png_get_io_ptr);
5581 LOAD_IMGLIB_FN (library, png_sig_cmp); 5571 LOAD_DLL_FN (library, png_sig_cmp);
5582 LOAD_IMGLIB_FN (library, png_create_read_struct); 5572 LOAD_DLL_FN (library, png_create_read_struct);
5583 LOAD_IMGLIB_FN (library, png_create_info_struct); 5573 LOAD_DLL_FN (library, png_create_info_struct);
5584 LOAD_IMGLIB_FN (library, png_destroy_read_struct); 5574 LOAD_DLL_FN (library, png_destroy_read_struct);
5585 LOAD_IMGLIB_FN (library, png_set_read_fn); 5575 LOAD_DLL_FN (library, png_set_read_fn);
5586 LOAD_IMGLIB_FN (library, png_set_sig_bytes); 5576 LOAD_DLL_FN (library, png_set_sig_bytes);
5587 LOAD_IMGLIB_FN (library, png_read_info); 5577 LOAD_DLL_FN (library, png_read_info);
5588 LOAD_IMGLIB_FN (library, png_get_IHDR); 5578 LOAD_DLL_FN (library, png_get_IHDR);
5589 LOAD_IMGLIB_FN (library, png_get_valid); 5579 LOAD_DLL_FN (library, png_get_valid);
5590 LOAD_IMGLIB_FN (library, png_set_strip_16); 5580 LOAD_DLL_FN (library, png_set_strip_16);
5591 LOAD_IMGLIB_FN (library, png_set_expand); 5581 LOAD_DLL_FN (library, png_set_expand);
5592 LOAD_IMGLIB_FN (library, png_set_gray_to_rgb); 5582 LOAD_DLL_FN (library, png_set_gray_to_rgb);
5593 LOAD_IMGLIB_FN (library, png_set_background); 5583 LOAD_DLL_FN (library, png_set_background);
5594 LOAD_IMGLIB_FN (library, png_get_bKGD); 5584 LOAD_DLL_FN (library, png_get_bKGD);
5595 LOAD_IMGLIB_FN (library, png_read_update_info); 5585 LOAD_DLL_FN (library, png_read_update_info);
5596 LOAD_IMGLIB_FN (library, png_get_channels); 5586 LOAD_DLL_FN (library, png_get_channels);
5597 LOAD_IMGLIB_FN (library, png_get_rowbytes); 5587 LOAD_DLL_FN (library, png_get_rowbytes);
5598 LOAD_IMGLIB_FN (library, png_read_image); 5588 LOAD_DLL_FN (library, png_read_image);
5599 LOAD_IMGLIB_FN (library, png_read_end); 5589 LOAD_DLL_FN (library, png_read_end);
5600 LOAD_IMGLIB_FN (library, png_error); 5590 LOAD_DLL_FN (library, png_error);
5601 5591
5602#if (PNG_LIBPNG_VER >= 10500) 5592# if (PNG_LIBPNG_VER >= 10500)
5603 LOAD_IMGLIB_FN (library, png_longjmp); 5593 LOAD_DLL_FN (library, png_longjmp);
5604 LOAD_IMGLIB_FN (library, png_set_longjmp_fn); 5594 LOAD_DLL_FN (library, png_set_longjmp_fn);
5605#endif /* libpng version >= 1.5 */ 5595# endif /* libpng version >= 1.5 */
5606 5596
5607 return 1; 5597 return 1;
5608} 5598}
5609#else
5610
5611#define fn_png_get_io_ptr png_get_io_ptr
5612#define fn_png_sig_cmp png_sig_cmp
5613#define fn_png_create_read_struct png_create_read_struct
5614#define fn_png_create_info_struct png_create_info_struct
5615#define fn_png_destroy_read_struct png_destroy_read_struct
5616#define fn_png_set_read_fn png_set_read_fn
5617#define fn_png_set_sig_bytes png_set_sig_bytes
5618#define fn_png_read_info png_read_info
5619#define fn_png_get_IHDR png_get_IHDR
5620#define fn_png_get_valid png_get_valid
5621#define fn_png_set_strip_16 png_set_strip_16
5622#define fn_png_set_expand png_set_expand
5623#define fn_png_set_gray_to_rgb png_set_gray_to_rgb
5624#define fn_png_set_background png_set_background
5625#define fn_png_get_bKGD png_get_bKGD
5626#define fn_png_read_update_info png_read_update_info
5627#define fn_png_get_channels png_get_channels
5628#define fn_png_get_rowbytes png_get_rowbytes
5629#define fn_png_read_image png_read_image
5630#define fn_png_read_end png_read_end
5631#define fn_png_error png_error
5632
5633#if (PNG_LIBPNG_VER >= 10500)
5634#define fn_png_longjmp png_longjmp
5635#define fn_png_set_longjmp_fn png_set_longjmp_fn
5636#endif /* libpng version >= 1.5 */
5637 5599
5638#endif /* WINDOWSNT */ 5600# undef png_create_info_struct
5601# undef png_create_read_struct
5602# undef png_destroy_read_struct
5603# undef png_error
5604# undef png_get_bKGD
5605# undef png_get_channels
5606# undef png_get_IHDR
5607# undef png_get_io_ptr
5608# undef png_get_rowbytes
5609# undef png_get_valid
5610# undef png_longjmp
5611# undef png_read_end
5612# undef png_read_image
5613# undef png_read_info
5614# undef png_read_update_info
5615# undef png_set_background
5616# undef png_set_expand
5617# undef png_set_gray_to_rgb
5618# undef png_set_longjmp_fn
5619# undef png_set_read_fn
5620# undef png_set_sig_bytes
5621# undef png_set_strip_16
5622# undef png_sig_cmp
5623
5624# define png_create_info_struct fn_png_create_info_struct
5625# define png_create_read_struct fn_png_create_read_struct
5626# define png_destroy_read_struct fn_png_destroy_read_struct
5627# define png_error fn_png_error
5628# define png_get_bKGD fn_png_get_bKGD
5629# define png_get_channels fn_png_get_channels
5630# define png_get_IHDR fn_png_get_IHDR
5631# define png_get_io_ptr fn_png_get_io_ptr
5632# define png_get_rowbytes fn_png_get_rowbytes
5633# define png_get_valid fn_png_get_valid
5634# define png_longjmp fn_png_longjmp
5635# define png_read_end fn_png_read_end
5636# define png_read_image fn_png_read_image
5637# define png_read_info fn_png_read_info
5638# define png_read_update_info fn_png_read_update_info
5639# define png_set_background fn_png_set_background
5640# define png_set_expand fn_png_set_expand
5641# define png_set_gray_to_rgb fn_png_set_gray_to_rgb
5642# define png_set_longjmp_fn fn_png_set_longjmp_fn
5643# define png_set_read_fn fn_png_set_read_fn
5644# define png_set_sig_bytes fn_png_set_sig_bytes
5645# define png_set_strip_16 fn_png_set_strip_16
5646# define png_sig_cmp fn_png_sig_cmp
5647
5648# endif /* WINDOWSNT */
5639 5649
5640/* Fast implementations of setjmp and longjmp. Although setjmp and longjmp 5650/* Fast implementations of setjmp and longjmp. Although setjmp and longjmp
5641 will do, POSIX _setjmp and _longjmp (if available) are often faster. 5651 will do, POSIX _setjmp and _longjmp (if available) are often faster.
5642 Do not use sys_setjmp, as PNG supports only jmp_buf. 5652 Do not use sys_setjmp, as PNG supports only jmp_buf.
5643 It's OK if the longjmp substitute restores the signal mask. */ 5653 It's OK if the longjmp substitute restores the signal mask. */
5644#ifdef HAVE__SETJMP 5654# ifdef HAVE__SETJMP
5645# define FAST_SETJMP(j) _setjmp (j) 5655# define FAST_SETJMP(j) _setjmp (j)
5646# define FAST_LONGJMP _longjmp 5656# define FAST_LONGJMP _longjmp
5647#else 5657# else
5648# define FAST_SETJMP(j) setjmp (j) 5658# define FAST_SETJMP(j) setjmp (j)
5649# define FAST_LONGJMP longjmp 5659# define FAST_LONGJMP longjmp
5650#endif 5660# endif
5651 5661
5652#if PNG_LIBPNG_VER < 10500 5662# if PNG_LIBPNG_VER < 10500
5653#define PNG_LONGJMP(ptr) FAST_LONGJMP ((ptr)->jmpbuf, 1) 5663# define PNG_LONGJMP(ptr) FAST_LONGJMP ((ptr)->jmpbuf, 1)
5654#define PNG_JMPBUF(ptr) ((ptr)->jmpbuf) 5664# define PNG_JMPBUF(ptr) ((ptr)->jmpbuf)
5655#else 5665# else
5656/* In libpng version 1.5, the jmpbuf member is hidden. (Bug#7908) */ 5666/* In libpng version 1.5, the jmpbuf member is hidden. (Bug#7908) */
5657#define PNG_LONGJMP(ptr) fn_png_longjmp (ptr, 1) 5667# define PNG_LONGJMP(ptr) png_longjmp (ptr, 1)
5658#define PNG_JMPBUF(ptr) \ 5668# define PNG_JMPBUF(ptr) \
5659 (*fn_png_set_longjmp_fn (ptr, FAST_LONGJMP, sizeof (jmp_buf))) 5669 (*png_set_longjmp_fn (ptr, FAST_LONGJMP, sizeof (jmp_buf)))
5660#endif 5670# endif
5661 5671
5662/* Error and warning handlers installed when the PNG library 5672/* Error and warning handlers installed when the PNG library
5663 is initialized. */ 5673 is initialized. */
@@ -5697,10 +5707,10 @@ struct png_memory_storage
5697static void 5707static void
5698png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length) 5708png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length)
5699{ 5709{
5700 struct png_memory_storage *tbr = fn_png_get_io_ptr (png_ptr); 5710 struct png_memory_storage *tbr = png_get_io_ptr (png_ptr);
5701 5711
5702 if (length > tbr->len - tbr->index) 5712 if (length > tbr->len - tbr->index)
5703 fn_png_error (png_ptr, "Read error"); 5713 png_error (png_ptr, "Read error");
5704 5714
5705 memcpy (data, tbr->bytes + tbr->index, length); 5715 memcpy (data, tbr->bytes + tbr->index, length);
5706 tbr->index = tbr->index + length; 5716 tbr->index = tbr->index + length;
@@ -5714,10 +5724,10 @@ png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length)
5714static void 5724static void
5715png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length) 5725png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5716{ 5726{
5717 FILE *fp = fn_png_get_io_ptr (png_ptr); 5727 FILE *fp = png_get_io_ptr (png_ptr);
5718 5728
5719 if (fread (data, 1, length, fp) < length) 5729 if (fread (data, 1, length, fp) < length)
5720 fn_png_error (png_ptr, "Read error"); 5730 png_error (png_ptr, "Read error");
5721} 5731}
5722 5732
5723 5733
@@ -5779,7 +5789,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5779 5789
5780 /* Check PNG signature. */ 5790 /* Check PNG signature. */
5781 if (fread (sig, 1, sizeof sig, fp) != sizeof sig 5791 if (fread (sig, 1, sizeof sig, fp) != sizeof sig
5782 || fn_png_sig_cmp (sig, 0, sizeof sig)) 5792 || png_sig_cmp (sig, 0, sizeof sig))
5783 { 5793 {
5784 fclose (fp); 5794 fclose (fp);
5785 image_error ("Not a PNG file: `%s'", file, Qnil); 5795 image_error ("Not a PNG file: `%s'", file, Qnil);
@@ -5801,7 +5811,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5801 5811
5802 /* Check PNG signature. */ 5812 /* Check PNG signature. */
5803 if (tbr.len < sizeof sig 5813 if (tbr.len < sizeof sig
5804 || fn_png_sig_cmp (tbr.bytes, 0, sizeof sig)) 5814 || png_sig_cmp (tbr.bytes, 0, sizeof sig))
5805 { 5815 {
5806 image_error ("Not a PNG image: `%s'", img->spec, Qnil); 5816 image_error ("Not a PNG image: `%s'", img->spec, Qnil);
5807 return 0; 5817 return 0;
@@ -5812,13 +5822,13 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5812 } 5822 }
5813 5823
5814 /* Initialize read and info structs for PNG lib. */ 5824 /* Initialize read and info structs for PNG lib. */
5815 png_ptr = fn_png_create_read_struct (PNG_LIBPNG_VER_STRING, 5825 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
5816 NULL, my_png_error, 5826 NULL, my_png_error,
5817 my_png_warning); 5827 my_png_warning);
5818 if (png_ptr) 5828 if (png_ptr)
5819 { 5829 {
5820 info_ptr = fn_png_create_info_struct (png_ptr); 5830 info_ptr = png_create_info_struct (png_ptr);
5821 end_info = fn_png_create_info_struct (png_ptr); 5831 end_info = png_create_info_struct (png_ptr);
5822 } 5832 }
5823 5833
5824 c->png_ptr = png_ptr; 5834 c->png_ptr = png_ptr;
@@ -5830,7 +5840,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5830 5840
5831 if (! (info_ptr && end_info)) 5841 if (! (info_ptr && end_info))
5832 { 5842 {
5833 fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); 5843 png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info);
5834 png_ptr = 0; 5844 png_ptr = 0;
5835 } 5845 }
5836 if (! png_ptr) 5846 if (! png_ptr)
@@ -5845,7 +5855,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5845 { 5855 {
5846 error: 5856 error:
5847 if (c->png_ptr) 5857 if (c->png_ptr)
5848 fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); 5858 png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info);
5849 xfree (c->pixels); 5859 xfree (c->pixels);
5850 xfree (c->rows); 5860 xfree (c->rows);
5851 if (c->fp) 5861 if (c->fp)
@@ -5858,14 +5868,14 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5858 5868
5859 /* Read image info. */ 5869 /* Read image info. */
5860 if (!NILP (specified_data)) 5870 if (!NILP (specified_data))
5861 fn_png_set_read_fn (png_ptr, &tbr, png_read_from_memory); 5871 png_set_read_fn (png_ptr, &tbr, png_read_from_memory);
5862 else 5872 else
5863 fn_png_set_read_fn (png_ptr, fp, png_read_from_file); 5873 png_set_read_fn (png_ptr, fp, png_read_from_file);
5864 5874
5865 fn_png_set_sig_bytes (png_ptr, sizeof sig); 5875 png_set_sig_bytes (png_ptr, sizeof sig);
5866 fn_png_read_info (png_ptr, info_ptr); 5876 png_read_info (png_ptr, info_ptr);
5867 fn_png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 5877 png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
5868 &interlace_type, NULL, NULL); 5878 &interlace_type, NULL, NULL);
5869 5879
5870 if (! (width <= INT_MAX && height <= INT_MAX 5880 if (! (width <= INT_MAX && height <= INT_MAX
5871 && check_image_size (f, width, height))) 5881 && check_image_size (f, width, height)))
@@ -5881,7 +5891,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5881 5891
5882 /* If image contains simply transparency data, we prefer to 5892 /* If image contains simply transparency data, we prefer to
5883 construct a clipping mask. */ 5893 construct a clipping mask. */
5884 if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) 5894 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
5885 transparent_p = 1; 5895 transparent_p = 1;
5886 else 5896 else
5887 transparent_p = 0; 5897 transparent_p = 0;
@@ -5892,16 +5902,16 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5892 5902
5893 /* Strip more than 8 bits per channel. */ 5903 /* Strip more than 8 bits per channel. */
5894 if (bit_depth == 16) 5904 if (bit_depth == 16)
5895 fn_png_set_strip_16 (png_ptr); 5905 png_set_strip_16 (png_ptr);
5896 5906
5897 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel 5907 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
5898 if available. */ 5908 if available. */
5899 fn_png_set_expand (png_ptr); 5909 png_set_expand (png_ptr);
5900 5910
5901 /* Convert grayscale images to RGB. */ 5911 /* Convert grayscale images to RGB. */
5902 if (color_type == PNG_COLOR_TYPE_GRAY 5912 if (color_type == PNG_COLOR_TYPE_GRAY
5903 || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 5913 || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
5904 fn_png_set_gray_to_rgb (png_ptr); 5914 png_set_gray_to_rgb (png_ptr);
5905 5915
5906 /* Handle alpha channel by combining the image with a background 5916 /* Handle alpha channel by combining the image with a background
5907 color. Do this only if a real alpha channel is supplied. For 5917 color. Do this only if a real alpha channel is supplied. For
@@ -5927,24 +5937,24 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5927 bg.green = color.green >> shift; 5937 bg.green = color.green >> shift;
5928 bg.blue = color.blue >> shift; 5938 bg.blue = color.blue >> shift;
5929 5939
5930 fn_png_set_background (png_ptr, &bg, 5940 png_set_background (png_ptr, &bg,
5931 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); 5941 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
5932 } 5942 }
5933 } 5943 }
5934 5944
5935 /* Update info structure. */ 5945 /* Update info structure. */
5936 fn_png_read_update_info (png_ptr, info_ptr); 5946 png_read_update_info (png_ptr, info_ptr);
5937 5947
5938 /* Get number of channels. Valid values are 1 for grayscale images 5948 /* Get number of channels. Valid values are 1 for grayscale images
5939 and images with a palette, 2 for grayscale images with transparency 5949 and images with a palette, 2 for grayscale images with transparency
5940 information (alpha channel), 3 for RGB images, and 4 for RGB 5950 information (alpha channel), 3 for RGB images, and 4 for RGB
5941 images with alpha channel, i.e. RGBA. If conversions above were 5951 images with alpha channel, i.e. RGBA. If conversions above were
5942 sufficient we should only have 3 or 4 channels here. */ 5952 sufficient we should only have 3 or 4 channels here. */
5943 channels = fn_png_get_channels (png_ptr, info_ptr); 5953 channels = png_get_channels (png_ptr, info_ptr);
5944 eassert (channels == 3 || channels == 4); 5954 eassert (channels == 3 || channels == 4);
5945 5955
5946 /* Number of bytes needed for one row of the image. */ 5956 /* Number of bytes needed for one row of the image. */
5947 row_bytes = fn_png_get_rowbytes (png_ptr, info_ptr); 5957 row_bytes = png_get_rowbytes (png_ptr, info_ptr);
5948 5958
5949 /* Allocate memory for the image. */ 5959 /* Allocate memory for the image. */
5950 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height 5960 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height
@@ -5956,8 +5966,8 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5956 rows[i] = pixels + i * row_bytes; 5966 rows[i] = pixels + i * row_bytes;
5957 5967
5958 /* Read the entire image. */ 5968 /* Read the entire image. */
5959 fn_png_read_image (png_ptr, rows); 5969 png_read_image (png_ptr, rows);
5960 fn_png_read_end (png_ptr, info_ptr); 5970 png_read_end (png_ptr, info_ptr);
5961 if (fp) 5971 if (fp)
5962 { 5972 {
5963 fclose (fp); 5973 fclose (fp);
@@ -6021,21 +6031,21 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
6021 overrode it. */ 6031 overrode it. */
6022 { 6032 {
6023 png_color_16 *bg; 6033 png_color_16 *bg;
6024 if (fn_png_get_bKGD (png_ptr, info_ptr, &bg)) 6034 if (png_get_bKGD (png_ptr, info_ptr, &bg))
6025 { 6035 {
6026 img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue); 6036 img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue);
6027 img->background_valid = 1; 6037 img->background_valid = 1;
6028 } 6038 }
6029 } 6039 }
6030 6040
6031#ifdef COLOR_TABLE_SUPPORT 6041# ifdef COLOR_TABLE_SUPPORT
6032 /* Remember colors allocated for this image. */ 6042 /* Remember colors allocated for this image. */
6033 img->colors = colors_in_color_table (&img->ncolors); 6043 img->colors = colors_in_color_table (&img->ncolors);
6034 free_color_table (); 6044 free_color_table ();
6035#endif /* COLOR_TABLE_SUPPORT */ 6045# endif /* COLOR_TABLE_SUPPORT */
6036 6046
6037 /* Clean up. */ 6047 /* Clean up. */
6038 fn_png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info); 6048 png_destroy_read_struct (&c->png_ptr, &c->info_ptr, &c->end_info);
6039 xfree (rows); 6049 xfree (rows);
6040 xfree (pixels); 6050 xfree (pixels);
6041 6051
@@ -6170,15 +6180,15 @@ jpeg_image_p (Lisp_Object object)
6170 6180
6171/* Work around a warning about HAVE_STDLIB_H being redefined in 6181/* Work around a warning about HAVE_STDLIB_H being redefined in
6172 jconfig.h. */ 6182 jconfig.h. */
6173#ifdef HAVE_STDLIB_H 6183# ifdef HAVE_STDLIB_H
6174#undef HAVE_STDLIB_H 6184# undef HAVE_STDLIB_H
6175#endif /* HAVE_STLIB_H */ 6185# endif
6176 6186
6177#if defined (HAVE_NTGUI) && !defined (__WIN32__) 6187# if defined (HAVE_NTGUI) && !defined (__WIN32__)
6178/* In older releases of the jpeg library, jpeglib.h will define boolean 6188/* In older releases of the jpeg library, jpeglib.h will define boolean
6179 differently depending on __WIN32__, so make sure it is defined. */ 6189 differently depending on __WIN32__, so make sure it is defined. */
6180#define __WIN32__ 1 6190# define __WIN32__ 1
6181#endif 6191# endif
6182 6192
6183/* rpcndr.h (via windows.h) and jpeglib.h both define boolean types. 6193/* rpcndr.h (via windows.h) and jpeglib.h both define boolean types.
6184 Some versions of jpeglib try to detect whether rpcndr.h is loaded, 6194 Some versions of jpeglib try to detect whether rpcndr.h is loaded,
@@ -6194,23 +6204,25 @@ jpeg_image_p (Lisp_Object object)
6194 different name. This name, jpeg_boolean, remains in effect through 6204 different name. This name, jpeg_boolean, remains in effect through
6195 the rest of image.c. 6205 the rest of image.c.
6196*/ 6206*/
6197#if defined CYGWIN && defined HAVE_NTGUI 6207# if defined CYGWIN && defined HAVE_NTGUI
6198#define boolean jpeg_boolean 6208# define boolean jpeg_boolean
6199#endif 6209# endif
6200#include <jpeglib.h> 6210# include <jpeglib.h>
6201#include <jerror.h> 6211# include <jerror.h>
6202 6212
6203#ifdef WINDOWSNT 6213# ifdef WINDOWSNT
6204 6214
6205/* JPEG library details. */ 6215/* JPEG library details. */
6206DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t)); 6216DEF_DLL_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t));
6207DEF_IMGLIB_FN (boolean, jpeg_start_decompress, (j_decompress_ptr)); 6217DEF_DLL_FN (boolean, jpeg_start_decompress, (j_decompress_ptr));
6208DEF_IMGLIB_FN (boolean, jpeg_finish_decompress, (j_decompress_ptr)); 6218DEF_DLL_FN (boolean, jpeg_finish_decompress, (j_decompress_ptr));
6209DEF_IMGLIB_FN (void, jpeg_destroy_decompress, (j_decompress_ptr)); 6219DEF_DLL_FN (void, jpeg_destroy_decompress, (j_decompress_ptr));
6210DEF_IMGLIB_FN (int, jpeg_read_header, (j_decompress_ptr, boolean)); 6220DEF_DLL_FN (int, jpeg_read_header, (j_decompress_ptr, boolean));
6211DEF_IMGLIB_FN (JDIMENSION, jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, JDIMENSION)); 6221DEF_DLL_FN (JDIMENSION, jpeg_read_scanlines,
6212DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *)); 6222 (j_decompress_ptr, JSAMPARRAY, JDIMENSION));
6213DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int)); 6223DEF_DLL_FN (struct jpeg_error_mgr *, jpeg_std_error,
6224 (struct jpeg_error_mgr *));
6225DEF_DLL_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int));
6214 6226
6215static bool 6227static bool
6216init_jpeg_functions (void) 6228init_jpeg_functions (void)
@@ -6220,37 +6232,46 @@ init_jpeg_functions (void)
6220 if (!(library = w32_delayed_load (Qjpeg))) 6232 if (!(library = w32_delayed_load (Qjpeg)))
6221 return 0; 6233 return 0;
6222 6234
6223 LOAD_IMGLIB_FN (library, jpeg_finish_decompress); 6235 LOAD_DLL_FN (library, jpeg_finish_decompress);
6224 LOAD_IMGLIB_FN (library, jpeg_read_scanlines); 6236 LOAD_DLL_FN (library, jpeg_read_scanlines);
6225 LOAD_IMGLIB_FN (library, jpeg_start_decompress); 6237 LOAD_DLL_FN (library, jpeg_start_decompress);
6226 LOAD_IMGLIB_FN (library, jpeg_read_header); 6238 LOAD_DLL_FN (library, jpeg_read_header);
6227 LOAD_IMGLIB_FN (library, jpeg_CreateDecompress); 6239 LOAD_DLL_FN (library, jpeg_CreateDecompress);
6228 LOAD_IMGLIB_FN (library, jpeg_destroy_decompress); 6240 LOAD_DLL_FN (library, jpeg_destroy_decompress);
6229 LOAD_IMGLIB_FN (library, jpeg_std_error); 6241 LOAD_DLL_FN (library, jpeg_std_error);
6230 LOAD_IMGLIB_FN (library, jpeg_resync_to_restart); 6242 LOAD_DLL_FN (library, jpeg_resync_to_restart);
6231 return 1; 6243 return 1;
6232} 6244}
6233 6245
6246# undef jpeg_CreateDecompress
6247# undef jpeg_destroy_decompress
6248# undef jpeg_finish_decompress
6249# undef jpeg_read_header
6250# undef jpeg_read_scanlines
6251# undef jpeg_resync_to_restart
6252# undef jpeg_start_decompress
6253# undef jpeg_std_error
6254
6255# define jpeg_CreateDecompress fn_jpeg_CreateDecompress
6256# define jpeg_destroy_decompress fn_jpeg_destroy_decompress
6257# define jpeg_finish_decompress fn_jpeg_finish_decompress
6258# define jpeg_read_header fn_jpeg_read_header
6259# define jpeg_read_scanlines fn_jpeg_read_scanlines
6260# define jpeg_resync_to_restart fn_jpeg_resync_to_restart
6261# define jpeg_start_decompress fn_jpeg_start_decompress
6262# define jpeg_std_error fn_jpeg_std_error
6263
6234/* Wrapper since we can't directly assign the function pointer 6264/* Wrapper since we can't directly assign the function pointer
6235 to another function pointer that was declared more completely easily. */ 6265 to another function pointer that was declared more completely easily. */
6236static boolean 6266static boolean
6237jpeg_resync_to_restart_wrapper (j_decompress_ptr cinfo, int desired) 6267jpeg_resync_to_restart_wrapper (j_decompress_ptr cinfo, int desired)
6238{ 6268{
6239 return fn_jpeg_resync_to_restart (cinfo, desired); 6269 return jpeg_resync_to_restart (cinfo, desired);
6240} 6270}
6271# undef jpeg_resync_to_restart
6272# define jpeg_resync_to_restart jpeg_resync_to_restart_wrapper
6241 6273
6242#else 6274# endif /* WINDOWSNT */
6243
6244#define fn_jpeg_CreateDecompress(a,b,c) jpeg_create_decompress (a)
6245#define fn_jpeg_start_decompress jpeg_start_decompress
6246#define fn_jpeg_finish_decompress jpeg_finish_decompress
6247#define fn_jpeg_destroy_decompress jpeg_destroy_decompress
6248#define fn_jpeg_read_header jpeg_read_header
6249#define fn_jpeg_read_scanlines jpeg_read_scanlines
6250#define fn_jpeg_std_error jpeg_std_error
6251#define jpeg_resync_to_restart_wrapper jpeg_resync_to_restart
6252
6253#endif /* WINDOWSNT */
6254 6275
6255struct my_jpeg_error_mgr 6276struct my_jpeg_error_mgr
6256{ 6277{
@@ -6358,7 +6379,7 @@ jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, ptrdiff_t len)
6358 src->init_source = our_common_init_source; 6379 src->init_source = our_common_init_source;
6359 src->fill_input_buffer = our_memory_fill_input_buffer; 6380 src->fill_input_buffer = our_memory_fill_input_buffer;
6360 src->skip_input_data = our_memory_skip_input_data; 6381 src->skip_input_data = our_memory_skip_input_data;
6361 src->resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ 6382 src->resync_to_restart = jpeg_resync_to_restart; /* Use default method. */
6362 src->term_source = our_common_term_source; 6383 src->term_source = our_common_term_source;
6363 src->bytes_in_buffer = len; 6384 src->bytes_in_buffer = len;
6364 src->next_input_byte = data; 6385 src->next_input_byte = data;
@@ -6464,7 +6485,7 @@ jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6464 src->mgr.init_source = our_common_init_source; 6485 src->mgr.init_source = our_common_init_source;
6465 src->mgr.fill_input_buffer = our_stdio_fill_input_buffer; 6486 src->mgr.fill_input_buffer = our_stdio_fill_input_buffer;
6466 src->mgr.skip_input_data = our_stdio_skip_input_data; 6487 src->mgr.skip_input_data = our_stdio_skip_input_data;
6467 src->mgr.resync_to_restart = jpeg_resync_to_restart_wrapper; /* Use default method. */ 6488 src->mgr.resync_to_restart = jpeg_resync_to_restart; /* Use default. */
6468 src->mgr.term_source = our_common_term_source; 6489 src->mgr.term_source = our_common_term_source;
6469 src->mgr.bytes_in_buffer = 0; 6490 src->mgr.bytes_in_buffer = 0;
6470 src->mgr.next_input_byte = NULL; 6491 src->mgr.next_input_byte = NULL;
@@ -6515,7 +6536,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6515 6536
6516 /* Customize libjpeg's error handling to call my_error_exit when an 6537 /* Customize libjpeg's error handling to call my_error_exit when an
6517 error is detected. This function will perform a longjmp. */ 6538 error is detected. This function will perform a longjmp. */
6518 mgr->cinfo.err = fn_jpeg_std_error (&mgr->pub); 6539 mgr->cinfo.err = jpeg_std_error (&mgr->pub);
6519 mgr->pub.error_exit = my_error_exit; 6540 mgr->pub.error_exit = my_error_exit;
6520 if (sys_setjmp (mgr->setjmp_buffer)) 6541 if (sys_setjmp (mgr->setjmp_buffer))
6521 { 6542 {
@@ -6541,7 +6562,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6541 /* Close the input file and destroy the JPEG object. */ 6562 /* Close the input file and destroy the JPEG object. */
6542 if (fp) 6563 if (fp)
6543 fclose (fp); 6564 fclose (fp);
6544 fn_jpeg_destroy_decompress (&mgr->cinfo); 6565 jpeg_destroy_decompress (&mgr->cinfo);
6545 6566
6546 /* If we already have an XImage, free that. */ 6567 /* If we already have an XImage, free that. */
6547 x_destroy_x_image (ximg); 6568 x_destroy_x_image (ximg);
@@ -6553,7 +6574,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6553 6574
6554 /* Create the JPEG decompression object. Let it read from fp. 6575 /* Create the JPEG decompression object. Let it read from fp.
6555 Read the JPEG image header. */ 6576 Read the JPEG image header. */
6556 fn_jpeg_CreateDecompress (&mgr->cinfo, JPEG_LIB_VERSION, sizeof *&mgr->cinfo); 6577 jpeg_CreateDecompress (&mgr->cinfo, JPEG_LIB_VERSION, sizeof *&mgr->cinfo);
6557 6578
6558 if (NILP (specified_data)) 6579 if (NILP (specified_data))
6559 jpeg_file_src (&mgr->cinfo, fp); 6580 jpeg_file_src (&mgr->cinfo, fp);
@@ -6561,12 +6582,12 @@ jpeg_load_body (struct frame *f, struct image *img,
6561 jpeg_memory_src (&mgr->cinfo, SDATA (specified_data), 6582 jpeg_memory_src (&mgr->cinfo, SDATA (specified_data),
6562 SBYTES (specified_data)); 6583 SBYTES (specified_data));
6563 6584
6564 fn_jpeg_read_header (&mgr->cinfo, 1); 6585 jpeg_read_header (&mgr->cinfo, 1);
6565 6586
6566 /* Customize decompression so that color quantization will be used. 6587 /* Customize decompression so that color quantization will be used.
6567 Start decompression. */ 6588 Start decompression. */
6568 mgr->cinfo.quantize_colors = 1; 6589 mgr->cinfo.quantize_colors = 1;
6569 fn_jpeg_start_decompress (&mgr->cinfo); 6590 jpeg_start_decompress (&mgr->cinfo);
6570 width = img->width = mgr->cinfo.output_width; 6591 width = img->width = mgr->cinfo.output_width;
6571 height = img->height = mgr->cinfo.output_height; 6592 height = img->height = mgr->cinfo.output_height;
6572 6593
@@ -6629,14 +6650,14 @@ jpeg_load_body (struct frame *f, struct image *img,
6629 JPOOL_IMAGE, row_stride, 1); 6650 JPOOL_IMAGE, row_stride, 1);
6630 for (y = 0; y < height; ++y) 6651 for (y = 0; y < height; ++y)
6631 { 6652 {
6632 fn_jpeg_read_scanlines (&mgr->cinfo, buffer, 1); 6653 jpeg_read_scanlines (&mgr->cinfo, buffer, 1);
6633 for (x = 0; x < mgr->cinfo.output_width; ++x) 6654 for (x = 0; x < mgr->cinfo.output_width; ++x)
6634 XPutPixel (ximg, x, y, colors[buffer[0][x]]); 6655 XPutPixel (ximg, x, y, colors[buffer[0][x]]);
6635 } 6656 }
6636 6657
6637 /* Clean up. */ 6658 /* Clean up. */
6638 fn_jpeg_finish_decompress (&mgr->cinfo); 6659 jpeg_finish_decompress (&mgr->cinfo);
6639 fn_jpeg_destroy_decompress (&mgr->cinfo); 6660 jpeg_destroy_decompress (&mgr->cinfo);
6640 if (fp) 6661 if (fp)
6641 fclose (fp); 6662 fclose (fp);
6642 6663
@@ -6760,22 +6781,22 @@ tiff_image_p (Lisp_Object object)
6760 6781
6761#ifdef HAVE_TIFF 6782#ifdef HAVE_TIFF
6762 6783
6763#include <tiffio.h> 6784# include <tiffio.h>
6764 6785
6765#ifdef WINDOWSNT 6786# ifdef WINDOWSNT
6766 6787
6767/* TIFF library details. */ 6788/* TIFF library details. */
6768DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler)); 6789DEF_DLL_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler));
6769DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetWarningHandler, (TIFFErrorHandler)); 6790DEF_DLL_FN (TIFFErrorHandler, TIFFSetWarningHandler, (TIFFErrorHandler));
6770DEF_IMGLIB_FN (TIFF *, TIFFOpen, (const char *, const char *)); 6791DEF_DLL_FN (TIFF *, TIFFOpen, (const char *, const char *));
6771DEF_IMGLIB_FN (TIFF *, TIFFClientOpen, (const char *, const char *, thandle_t, 6792DEF_DLL_FN (TIFF *, TIFFClientOpen,
6772 TIFFReadWriteProc, TIFFReadWriteProc, 6793 (const char *, const char *, thandle_t, TIFFReadWriteProc,
6773 TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, 6794 TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc,
6774 TIFFMapFileProc, TIFFUnmapFileProc)); 6795 TIFFMapFileProc, TIFFUnmapFileProc));
6775DEF_IMGLIB_FN (int, TIFFGetField, (TIFF *, ttag_t, ...)); 6796DEF_DLL_FN (int, TIFFGetField, (TIFF *, ttag_t, ...));
6776DEF_IMGLIB_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int)); 6797DEF_DLL_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
6777DEF_IMGLIB_FN (void, TIFFClose, (TIFF *)); 6798DEF_DLL_FN (void, TIFFClose, (TIFF *));
6778DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t)); 6799DEF_DLL_FN (int, TIFFSetDirectory, (TIFF *, tdir_t));
6779 6800
6780static bool 6801static bool
6781init_tiff_functions (void) 6802init_tiff_functions (void)
@@ -6785,28 +6806,36 @@ init_tiff_functions (void)
6785 if (!(library = w32_delayed_load (Qtiff))) 6806 if (!(library = w32_delayed_load (Qtiff)))
6786 return 0; 6807 return 0;
6787 6808
6788 LOAD_IMGLIB_FN (library, TIFFSetErrorHandler); 6809 LOAD_DLL_FN (library, TIFFSetErrorHandler);
6789 LOAD_IMGLIB_FN (library, TIFFSetWarningHandler); 6810 LOAD_DLL_FN (library, TIFFSetWarningHandler);
6790 LOAD_IMGLIB_FN (library, TIFFOpen); 6811 LOAD_DLL_FN (library, TIFFOpen);
6791 LOAD_IMGLIB_FN (library, TIFFClientOpen); 6812 LOAD_DLL_FN (library, TIFFClientOpen);
6792 LOAD_IMGLIB_FN (library, TIFFGetField); 6813 LOAD_DLL_FN (library, TIFFGetField);
6793 LOAD_IMGLIB_FN (library, TIFFReadRGBAImage); 6814 LOAD_DLL_FN (library, TIFFReadRGBAImage);
6794 LOAD_IMGLIB_FN (library, TIFFClose); 6815 LOAD_DLL_FN (library, TIFFClose);
6795 LOAD_IMGLIB_FN (library, TIFFSetDirectory); 6816 LOAD_DLL_FN (library, TIFFSetDirectory);
6796 return 1; 6817 return 1;
6797} 6818}
6798 6819
6799#else 6820# undef TIFFClientOpen
6821# undef TIFFClose
6822# undef TIFFGetField
6823# undef TIFFOpen
6824# undef TIFFReadRGBAImage
6825# undef TIFFSetDirectory
6826# undef TIFFSetErrorHandler
6827# undef TIFFSetWarningHandler
6800 6828
6801#define fn_TIFFSetErrorHandler TIFFSetErrorHandler 6829# define TIFFClientOpen fn_TIFFClientOpen
6802#define fn_TIFFSetWarningHandler TIFFSetWarningHandler 6830# define TIFFClose fn_TIFFClose
6803#define fn_TIFFOpen TIFFOpen 6831# define TIFFGetField fn_TIFFGetField
6804#define fn_TIFFClientOpen TIFFClientOpen 6832# define TIFFOpen fn_TIFFOpen
6805#define fn_TIFFGetField TIFFGetField 6833# define TIFFReadRGBAImage fn_TIFFReadRGBAImage
6806#define fn_TIFFReadRGBAImage TIFFReadRGBAImage 6834# define TIFFSetDirectory fn_TIFFSetDirectory
6807#define fn_TIFFClose TIFFClose 6835# define TIFFSetErrorHandler fn_TIFFSetErrorHandler
6808#define fn_TIFFSetDirectory TIFFSetDirectory 6836# define TIFFSetWarningHandler fn_TIFFSetWarningHandler
6809#endif /* WINDOWSNT */ 6837
6838# endif /* WINDOWSNT */
6810 6839
6811 6840
6812/* Reading from a memory buffer for TIFF images Based on the PNG 6841/* Reading from a memory buffer for TIFF images Based on the PNG
@@ -6904,11 +6933,11 @@ tiff_size_of_memory (thandle_t data)
6904 compiler error compiling tiff_handler, see Bugzilla bug #17406 6933 compiler error compiling tiff_handler, see Bugzilla bug #17406
6905 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17406). Declaring 6934 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17406). Declaring
6906 this function as external works around that problem. */ 6935 this function as external works around that problem. */
6907#if defined (__MINGW32__) && __GNUC__ == 3 6936# if defined (__MINGW32__) && __GNUC__ == 3
6908# define MINGW_STATIC 6937# define MINGW_STATIC
6909#else 6938# else
6910# define MINGW_STATIC static 6939# define MINGW_STATIC static
6911#endif 6940# endif
6912 6941
6913MINGW_STATIC void 6942MINGW_STATIC void
6914tiff_handler (const char *, const char *, const char *, va_list) 6943tiff_handler (const char *, const char *, const char *, va_list)
@@ -6927,7 +6956,7 @@ tiff_handler (const char *log_format, const char *title,
6927 add_to_log (log_format, build_string (title), 6956 add_to_log (log_format, build_string (title),
6928 make_string (buf, max (0, min (len, sizeof buf - 1)))); 6957 make_string (buf, max (0, min (len, sizeof buf - 1))));
6929} 6958}
6930#undef MINGW_STATIC 6959# undef MINGW_STATIC
6931 6960
6932static void tiff_error_handler (const char *, const char *, va_list) 6961static void tiff_error_handler (const char *, const char *, va_list)
6933 ATTRIBUTE_FORMAT_PRINTF (2, 0); 6962 ATTRIBUTE_FORMAT_PRINTF (2, 0);
@@ -6966,8 +6995,8 @@ tiff_load (struct frame *f, struct image *img)
6966 specified_file = image_spec_value (img->spec, QCfile, NULL); 6995 specified_file = image_spec_value (img->spec, QCfile, NULL);
6967 specified_data = image_spec_value (img->spec, QCdata, NULL); 6996 specified_data = image_spec_value (img->spec, QCdata, NULL);
6968 6997
6969 fn_TIFFSetErrorHandler ((TIFFErrorHandler) tiff_error_handler); 6998 TIFFSetErrorHandler ((TIFFErrorHandler) tiff_error_handler);
6970 fn_TIFFSetWarningHandler ((TIFFErrorHandler) tiff_warning_handler); 6999 TIFFSetWarningHandler ((TIFFErrorHandler) tiff_warning_handler);
6971 7000
6972 if (NILP (specified_data)) 7001 if (NILP (specified_data))
6973 { 7002 {
@@ -6978,12 +7007,12 @@ tiff_load (struct frame *f, struct image *img)
6978 image_error ("Cannot find image file `%s'", specified_file, Qnil); 7007 image_error ("Cannot find image file `%s'", specified_file, Qnil);
6979 return 0; 7008 return 0;
6980 } 7009 }
6981#ifdef WINDOWSNT 7010# ifdef WINDOWSNT
6982 file = ansi_encode_filename (file); 7011 file = ansi_encode_filename (file);
6983#endif 7012# endif
6984 7013
6985 /* Try to open the image file. */ 7014 /* Try to open the image file. */
6986 tiff = fn_TIFFOpen (SSDATA (file), "r"); 7015 tiff = TIFFOpen (SSDATA (file), "r");
6987 if (tiff == NULL) 7016 if (tiff == NULL)
6988 { 7017 {
6989 image_error ("Cannot open `%s'", file, Qnil); 7018 image_error ("Cannot open `%s'", file, Qnil);
@@ -7003,14 +7032,14 @@ tiff_load (struct frame *f, struct image *img)
7003 memsrc.len = SBYTES (specified_data); 7032 memsrc.len = SBYTES (specified_data);
7004 memsrc.index = 0; 7033 memsrc.index = 0;
7005 7034
7006 tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc, 7035 tiff = TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc,
7007 tiff_read_from_memory, 7036 tiff_read_from_memory,
7008 tiff_write_from_memory, 7037 tiff_write_from_memory,
7009 tiff_seek_in_memory, 7038 tiff_seek_in_memory,
7010 tiff_close_memory, 7039 tiff_close_memory,
7011 tiff_size_of_memory, 7040 tiff_size_of_memory,
7012 tiff_mmap_memory, 7041 tiff_mmap_memory,
7013 tiff_unmap_memory); 7042 tiff_unmap_memory);
7014 7043
7015 if (!tiff) 7044 if (!tiff)
7016 { 7045 {
@@ -7024,24 +7053,24 @@ tiff_load (struct frame *f, struct image *img)
7024 { 7053 {
7025 EMACS_INT ino = XFASTINT (image); 7054 EMACS_INT ino = XFASTINT (image);
7026 if (! (TYPE_MINIMUM (tdir_t) <= ino && ino <= TYPE_MAXIMUM (tdir_t) 7055 if (! (TYPE_MINIMUM (tdir_t) <= ino && ino <= TYPE_MAXIMUM (tdir_t)
7027 && fn_TIFFSetDirectory (tiff, ino))) 7056 && TIFFSetDirectory (tiff, ino)))
7028 { 7057 {
7029 image_error ("Invalid image number `%s' in image `%s'", 7058 image_error ("Invalid image number `%s' in image `%s'",
7030 image, img->spec); 7059 image, img->spec);
7031 fn_TIFFClose (tiff); 7060 TIFFClose (tiff);
7032 return 0; 7061 return 0;
7033 } 7062 }
7034 } 7063 }
7035 7064
7036 /* Get width and height of the image, and allocate a raster buffer 7065 /* Get width and height of the image, and allocate a raster buffer
7037 of width x height 32-bit values. */ 7066 of width x height 32-bit values. */
7038 fn_TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width); 7067 TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width);
7039 fn_TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height); 7068 TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height);
7040 7069
7041 if (!check_image_size (f, width, height)) 7070 if (!check_image_size (f, width, height))
7042 { 7071 {
7043 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); 7072 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7044 fn_TIFFClose (tiff); 7073 TIFFClose (tiff);
7045 return 0; 7074 return 0;
7046 } 7075 }
7047 7076
@@ -7050,16 +7079,16 @@ tiff_load (struct frame *f, struct image *img)
7050 && image_create_x_image_and_pixmap (f, img, width, height, 0, 7079 && image_create_x_image_and_pixmap (f, img, width, height, 0,
7051 &ximg, 0))) 7080 &ximg, 0)))
7052 { 7081 {
7053 fn_TIFFClose (tiff); 7082 TIFFClose (tiff);
7054 return 0; 7083 return 0;
7055 } 7084 }
7056 7085
7057 buf = xmalloc (sizeof *buf * width * height); 7086 buf = xmalloc (sizeof *buf * width * height);
7058 7087
7059 rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); 7088 rc = TIFFReadRGBAImage (tiff, width, height, buf, 0);
7060 7089
7061 /* Count the number of images in the file. */ 7090 /* Count the number of images in the file. */
7062 for (count = 1; fn_TIFFSetDirectory (tiff, count); count++) 7091 for (count = 1; TIFFSetDirectory (tiff, count); count++)
7063 continue; 7092 continue;
7064 7093
7065 if (count > 1) 7094 if (count > 1)
@@ -7067,7 +7096,7 @@ tiff_load (struct frame *f, struct image *img)
7067 Fcons (make_number (count), 7096 Fcons (make_number (count),
7068 img->lisp_data)); 7097 img->lisp_data));
7069 7098
7070 fn_TIFFClose (tiff); 7099 TIFFClose (tiff);
7071 if (!rc) 7100 if (!rc)
7072 { 7101 {
7073 image_error ("Error reading TIFF image `%s'", img->spec, Qnil); 7102 image_error ("Error reading TIFF image `%s'", img->spec, Qnil);
@@ -7093,11 +7122,11 @@ tiff_load (struct frame *f, struct image *img)
7093 } 7122 }
7094 } 7123 }
7095 7124
7096#ifdef COLOR_TABLE_SUPPORT 7125# ifdef COLOR_TABLE_SUPPORT
7097 /* Remember the colors allocated for the image. Free the color table. */ 7126 /* Remember the colors allocated for the image. Free the color table. */
7098 img->colors = colors_in_color_table (&img->ncolors); 7127 img->colors = colors_in_color_table (&img->ncolors);
7099 free_color_table (); 7128 free_color_table ();
7100#endif /* COLOR_TABLE_SUPPORT */ 7129# endif /* COLOR_TABLE_SUPPORT */
7101 7130
7102 img->width = width; 7131 img->width = width;
7103 img->height = height; 7132 img->height = height;
@@ -7114,9 +7143,8 @@ tiff_load (struct frame *f, struct image *img)
7114 return 1; 7143 return 1;
7115} 7144}
7116 7145
7117#else /* HAVE_TIFF */ 7146#elif defined HAVE_NS
7118 7147
7119#ifdef HAVE_NS
7120static bool 7148static bool
7121tiff_load (struct frame *f, struct image *img) 7149tiff_load (struct frame *f, struct image *img)
7122{ 7150{
@@ -7124,9 +7152,8 @@ tiff_load (struct frame *f, struct image *img)
7124 image_spec_value (img->spec, QCfile, NULL), 7152 image_spec_value (img->spec, QCfile, NULL),
7125 image_spec_value (img->spec, QCdata, NULL)); 7153 image_spec_value (img->spec, QCdata, NULL));
7126} 7154}
7127#endif /* HAVE_NS */
7128 7155
7129#endif /* !HAVE_TIFF */ 7156#endif
7130 7157
7131 7158
7132 7159
@@ -7226,54 +7253,54 @@ gif_image_p (Lisp_Object object)
7226 7253
7227#ifdef HAVE_GIF 7254#ifdef HAVE_GIF
7228 7255
7229#if defined (HAVE_NTGUI) 7256# ifdef HAVE_NTGUI
7230 7257
7231/* winuser.h might define DrawText to DrawTextA or DrawTextW. 7258/* winuser.h might define DrawText to DrawTextA or DrawTextW.
7232 Undefine before redefining to avoid a preprocessor warning. */ 7259 Undefine before redefining to avoid a preprocessor warning. */
7233#ifdef DrawText 7260# ifdef DrawText
7234#undef DrawText 7261# undef DrawText
7235#endif 7262# endif
7236/* avoid conflict with QuickdrawText.h */ 7263/* avoid conflict with QuickdrawText.h */
7237#define DrawText gif_DrawText 7264# define DrawText gif_DrawText
7238#include <gif_lib.h> 7265# include <gif_lib.h>
7239#undef DrawText 7266# undef DrawText
7240 7267
7241/* Giflib before 5.0 didn't define these macros (used only if HAVE_NTGUI). */ 7268/* Giflib before 5.0 didn't define these macros (used only if HAVE_NTGUI). */
7242#ifndef GIFLIB_MINOR 7269# ifndef GIFLIB_MINOR
7243#define GIFLIB_MINOR 0 7270# define GIFLIB_MINOR 0
7244#endif 7271# endif
7245#ifndef GIFLIB_RELEASE 7272# ifndef GIFLIB_RELEASE
7246#define GIFLIB_RELEASE 0 7273# define GIFLIB_RELEASE 0
7247#endif 7274# endif
7248 7275
7249#else /* HAVE_NTGUI */ 7276# else /* HAVE_NTGUI */
7250 7277
7251#include <gif_lib.h> 7278# include <gif_lib.h>
7252 7279
7253#endif /* HAVE_NTGUI */ 7280# endif /* HAVE_NTGUI */
7254 7281
7255/* Giflib before 5.0 didn't define these macros. */ 7282/* Giflib before 5.0 didn't define these macros. */
7256#ifndef GIFLIB_MAJOR 7283# ifndef GIFLIB_MAJOR
7257#define GIFLIB_MAJOR 4 7284# define GIFLIB_MAJOR 4
7258#endif 7285# endif
7259 7286
7260#ifdef WINDOWSNT 7287# ifdef WINDOWSNT
7261 7288
7262/* GIF library details. */ 7289/* GIF library details. */
7263#if 5 < GIFLIB_MAJOR + (1 <= GIFLIB_MINOR) 7290# if 5 < GIFLIB_MAJOR + (1 <= GIFLIB_MINOR)
7264DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *, int *)); 7291DEF_DLL_FN (int, DGifCloseFile, (GifFileType *, int *));
7265#else 7292# else
7266DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *)); 7293DEF_DLL_FN (int, DGifCloseFile, (GifFileType *));
7267#endif 7294# endif
7268DEF_IMGLIB_FN (int, DGifSlurp, (GifFileType *)); 7295DEF_DLL_FN (int, DGifSlurp, (GifFileType *));
7269#if GIFLIB_MAJOR < 5 7296# if GIFLIB_MAJOR < 5
7270DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc)); 7297DEF_DLL_FN (GifFileType *, DGifOpen, (void *, InputFunc));
7271DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *)); 7298DEF_DLL_FN (GifFileType *, DGifOpenFileName, (const char *));
7272#else 7299# else
7273DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc, int *)); 7300DEF_DLL_FN (GifFileType *, DGifOpen, (void *, InputFunc, int *));
7274DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *, int *)); 7301DEF_DLL_FN (GifFileType *, DGifOpenFileName, (const char *, int *));
7275DEF_IMGLIB_FN (char *, GifErrorString, (int)); 7302DEF_DLL_FN (char *, GifErrorString, (int));
7276#endif 7303# endif
7277 7304
7278static bool 7305static bool
7279init_gif_functions (void) 7306init_gif_functions (void)
@@ -7283,27 +7310,29 @@ init_gif_functions (void)
7283 if (!(library = w32_delayed_load (Qgif))) 7310 if (!(library = w32_delayed_load (Qgif)))
7284 return 0; 7311 return 0;
7285 7312
7286 LOAD_IMGLIB_FN (library, DGifCloseFile); 7313 LOAD_DLL_FN (library, DGifCloseFile);
7287 LOAD_IMGLIB_FN (library, DGifSlurp); 7314 LOAD_DLL_FN (library, DGifSlurp);
7288 LOAD_IMGLIB_FN (library, DGifOpen); 7315 LOAD_DLL_FN (library, DGifOpen);
7289 LOAD_IMGLIB_FN (library, DGifOpenFileName); 7316 LOAD_DLL_FN (library, DGifOpenFileName);
7290#if GIFLIB_MAJOR >= 5 7317# if GIFLIB_MAJOR >= 5
7291 LOAD_IMGLIB_FN (library, GifErrorString); 7318 LOAD_DLL_FN (library, GifErrorString);
7292#endif 7319# endif
7293 return 1; 7320 return 1;
7294} 7321}
7295 7322
7296#else 7323# undef DGifCloseFile
7324# undef DGifOpen
7325# undef DGifOpenFileName
7326# undef DGifSlurp
7327# undef GifErrorString
7297 7328
7298#define fn_DGifCloseFile DGifCloseFile 7329# define DGifCloseFile fn_DGifCloseFile
7299#define fn_DGifSlurp DGifSlurp 7330# define DGifOpen fn_DGifOpen
7300#define fn_DGifOpen DGifOpen 7331# define DGifOpenFileName fn_DGifOpenFileName
7301#define fn_DGifOpenFileName DGifOpenFileName 7332# define DGifSlurp fn_DGifSlurp
7302#if 5 <= GIFLIB_MAJOR 7333# define GifErrorString fn_GifErrorString
7303# define fn_GifErrorString GifErrorString
7304#endif
7305 7334
7306#endif /* WINDOWSNT */ 7335# endif /* WINDOWSNT */
7307 7336
7308/* Reading a GIF image from memory 7337/* Reading a GIF image from memory
7309 Based on the PNG memory stuff to a certain extent. */ 7338 Based on the PNG memory stuff to a certain extent. */
@@ -7340,9 +7369,9 @@ gif_close (GifFileType *gif, int *err)
7340 int retval; 7369 int retval;
7341 7370
7342#if 5 < GIFLIB_MAJOR + (1 <= GIFLIB_MINOR) 7371#if 5 < GIFLIB_MAJOR + (1 <= GIFLIB_MINOR)
7343 retval = fn_DGifCloseFile (gif, err); 7372 retval = DGifCloseFile (gif, err);
7344#else 7373#else
7345 retval = fn_DGifCloseFile (gif); 7374 retval = DGifCloseFile (gif);
7346#if GIFLIB_MAJOR >= 5 7375#if GIFLIB_MAJOR >= 5
7347 if (err) 7376 if (err)
7348 *err = gif->Error; 7377 *err = gif->Error;
@@ -7390,18 +7419,18 @@ gif_load (struct frame *f, struct image *img)
7390 7419
7391 /* Open the GIF file. */ 7420 /* Open the GIF file. */
7392#if GIFLIB_MAJOR < 5 7421#if GIFLIB_MAJOR < 5
7393 gif = fn_DGifOpenFileName (SSDATA (file)); 7422 gif = DGifOpenFileName (SSDATA (file));
7394 if (gif == NULL) 7423 if (gif == NULL)
7395 { 7424 {
7396 image_error ("Cannot open `%s'", file, Qnil); 7425 image_error ("Cannot open `%s'", file, Qnil);
7397 return 0; 7426 return 0;
7398 } 7427 }
7399#else 7428#else
7400 gif = fn_DGifOpenFileName (SSDATA (file), &gif_err); 7429 gif = DGifOpenFileName (SSDATA (file), &gif_err);
7401 if (gif == NULL) 7430 if (gif == NULL)
7402 { 7431 {
7403 image_error ("Cannot open `%s': %s", 7432 image_error ("Cannot open `%s': %s",
7404 file, build_string (fn_GifErrorString (gif_err))); 7433 file, build_string (GifErrorString (gif_err)));
7405 return 0; 7434 return 0;
7406 } 7435 }
7407#endif 7436#endif
@@ -7421,18 +7450,18 @@ gif_load (struct frame *f, struct image *img)
7421 memsrc.index = 0; 7450 memsrc.index = 0;
7422 7451
7423#if GIFLIB_MAJOR < 5 7452#if GIFLIB_MAJOR < 5
7424 gif = fn_DGifOpen (&memsrc, gif_read_from_memory); 7453 gif = DGifOpen (&memsrc, gif_read_from_memory);
7425 if (!gif) 7454 if (!gif)
7426 { 7455 {
7427 image_error ("Cannot open memory source `%s'", img->spec, Qnil); 7456 image_error ("Cannot open memory source `%s'", img->spec, Qnil);
7428 return 0; 7457 return 0;
7429 } 7458 }
7430#else 7459#else
7431 gif = fn_DGifOpen (&memsrc, gif_read_from_memory, &gif_err); 7460 gif = DGifOpen (&memsrc, gif_read_from_memory, &gif_err);
7432 if (!gif) 7461 if (!gif)
7433 { 7462 {
7434 image_error ("Cannot open memory source `%s': %s", 7463 image_error ("Cannot open memory source `%s': %s",
7435 img->spec, build_string (fn_GifErrorString (gif_err))); 7464 img->spec, build_string (GifErrorString (gif_err)));
7436 return 0; 7465 return 0;
7437 } 7466 }
7438#endif 7467#endif
@@ -7447,7 +7476,7 @@ gif_load (struct frame *f, struct image *img)
7447 } 7476 }
7448 7477
7449 /* Read entire contents. */ 7478 /* Read entire contents. */
7450 rc = fn_DGifSlurp (gif); 7479 rc = DGifSlurp (gif);
7451 if (rc == GIF_ERROR || gif->ImageCount <= 0) 7480 if (rc == GIF_ERROR || gif->ImageCount <= 0)
7452 { 7481 {
7453 image_error ("Error reading `%s'", img->spec, Qnil); 7482 image_error ("Error reading `%s'", img->spec, Qnil);
@@ -7681,7 +7710,7 @@ gif_load (struct frame *f, struct image *img)
7681 if (gif_close (gif, &gif_err) == GIF_ERROR) 7710 if (gif_close (gif, &gif_err) == GIF_ERROR)
7682 { 7711 {
7683#if 5 <= GIFLIB_MAJOR 7712#if 5 <= GIFLIB_MAJOR
7684 char *error_text = fn_GifErrorString (gif_err); 7713 char *error_text = GifErrorString (gif_err);
7685 7714
7686 if (error_text) 7715 if (error_text)
7687 image_error ("Error closing `%s': %s", 7716 image_error ("Error closing `%s': %s",
@@ -8593,7 +8622,7 @@ and `imagemagick-types-inhibit'. */)
8593 SVG 8622 SVG
8594 ***********************************************************************/ 8623 ***********************************************************************/
8595 8624
8596#if defined (HAVE_RSVG) 8625#ifdef HAVE_RSVG
8597 8626
8598/* Function prototypes. */ 8627/* Function prototypes. */
8599 8628
@@ -8641,11 +8670,11 @@ static const struct image_keyword svg_format[SVG_LAST] =
8641 {":background", IMAGE_STRING_OR_NIL_VALUE, 0} 8670 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}
8642}; 8671};
8643 8672
8644#if defined HAVE_NTGUI && defined WINDOWSNT 8673# if defined HAVE_NTGUI && defined WINDOWSNT
8645static bool init_svg_functions (void); 8674static bool init_svg_functions (void);
8646#else 8675# else
8647#define init_svg_functions NULL 8676#define init_svg_functions NULL
8648#endif 8677# endif
8649 8678
8650/* Structure describing the image type `svg'. Its the same type of 8679/* Structure describing the image type `svg'. Its the same type of
8651 structure defined for all image formats, handled by emacs image 8680 structure defined for all image formats, handled by emacs image
@@ -8679,32 +8708,34 @@ svg_image_p (Lisp_Object object)
8679 return fmt[SVG_FILE].count + fmt[SVG_DATA].count == 1; 8708 return fmt[SVG_FILE].count + fmt[SVG_DATA].count == 1;
8680} 8709}
8681 8710
8682#include <librsvg/rsvg.h> 8711# include <librsvg/rsvg.h>
8683 8712
8684#ifdef WINDOWSNT 8713# ifdef WINDOWSNT
8685 8714
8686/* SVG library functions. */ 8715/* SVG library functions. */
8687DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new, (void)); 8716DEF_DLL_FN (RsvgHandle *, rsvg_handle_new, (void));
8688DEF_IMGLIB_FN (void, rsvg_handle_get_dimensions, (RsvgHandle *, RsvgDimensionData *)); 8717DEF_DLL_FN (void, rsvg_handle_get_dimensions,
8689DEF_IMGLIB_FN (gboolean, rsvg_handle_write, (RsvgHandle *, const guchar *, gsize, GError **)); 8718 (RsvgHandle *, RsvgDimensionData *));
8690DEF_IMGLIB_FN (gboolean, rsvg_handle_close, (RsvgHandle *, GError **)); 8719DEF_DLL_FN (gboolean, rsvg_handle_write,
8691DEF_IMGLIB_FN (GdkPixbuf *, rsvg_handle_get_pixbuf, (RsvgHandle *)); 8720 (RsvgHandle *, const guchar *, gsize, GError **));
8692DEF_IMGLIB_FN (void, rsvg_handle_set_base_uri, (RsvgHandle *, const char *)); 8721DEF_DLL_FN (gboolean, rsvg_handle_close, (RsvgHandle *, GError **));
8693 8722DEF_DLL_FN (GdkPixbuf *, rsvg_handle_get_pixbuf, (RsvgHandle *));
8694DEF_IMGLIB_FN (int, gdk_pixbuf_get_width, (const GdkPixbuf *)); 8723DEF_DLL_FN (void, rsvg_handle_set_base_uri, (RsvgHandle *, const char *));
8695DEF_IMGLIB_FN (int, gdk_pixbuf_get_height, (const GdkPixbuf *)); 8724
8696DEF_IMGLIB_FN (guchar *, gdk_pixbuf_get_pixels, (const GdkPixbuf *)); 8725DEF_DLL_FN (int, gdk_pixbuf_get_width, (const GdkPixbuf *));
8697DEF_IMGLIB_FN (int, gdk_pixbuf_get_rowstride, (const GdkPixbuf *)); 8726DEF_DLL_FN (int, gdk_pixbuf_get_height, (const GdkPixbuf *));
8698DEF_IMGLIB_FN (GdkColorspace, gdk_pixbuf_get_colorspace, (const GdkPixbuf *)); 8727DEF_DLL_FN (guchar *, gdk_pixbuf_get_pixels, (const GdkPixbuf *));
8699DEF_IMGLIB_FN (int, gdk_pixbuf_get_n_channels, (const GdkPixbuf *)); 8728DEF_DLL_FN (int, gdk_pixbuf_get_rowstride, (const GdkPixbuf *));
8700DEF_IMGLIB_FN (gboolean, gdk_pixbuf_get_has_alpha, (const GdkPixbuf *)); 8729DEF_DLL_FN (GdkColorspace, gdk_pixbuf_get_colorspace, (const GdkPixbuf *));
8701DEF_IMGLIB_FN (int, gdk_pixbuf_get_bits_per_sample, (const GdkPixbuf *)); 8730DEF_DLL_FN (int, gdk_pixbuf_get_n_channels, (const GdkPixbuf *));
8702 8731DEF_DLL_FN (gboolean, gdk_pixbuf_get_has_alpha, (const GdkPixbuf *));
8703#if ! GLIB_CHECK_VERSION (2, 36, 0) 8732DEF_DLL_FN (int, gdk_pixbuf_get_bits_per_sample, (const GdkPixbuf *));
8704DEF_IMGLIB_FN (void, g_type_init, (void)); 8733
8705#endif 8734# if ! GLIB_CHECK_VERSION (2, 36, 0)
8706DEF_IMGLIB_FN (void, g_object_unref, (gpointer)); 8735DEF_DLL_FN (void, g_type_init, (void));
8707DEF_IMGLIB_FN (void, g_error_free, (GError *)); 8736# endif
8737DEF_DLL_FN (void, g_object_unref, (gpointer));
8738DEF_DLL_FN (void, g_error_free, (GError *));
8708 8739
8709Lisp_Object Qgdk_pixbuf, Qglib, Qgobject; 8740Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
8710 8741
@@ -8724,56 +8755,71 @@ init_svg_functions (void)
8724 return 0; 8755 return 0;
8725 } 8756 }
8726 8757
8727 LOAD_IMGLIB_FN (library, rsvg_handle_new); 8758 LOAD_DLL_FN (library, rsvg_handle_new);
8728 LOAD_IMGLIB_FN (library, rsvg_handle_get_dimensions); 8759 LOAD_DLL_FN (library, rsvg_handle_get_dimensions);
8729 LOAD_IMGLIB_FN (library, rsvg_handle_write); 8760 LOAD_DLL_FN (library, rsvg_handle_write);
8730 LOAD_IMGLIB_FN (library, rsvg_handle_close); 8761 LOAD_DLL_FN (library, rsvg_handle_close);
8731 LOAD_IMGLIB_FN (library, rsvg_handle_get_pixbuf); 8762 LOAD_DLL_FN (library, rsvg_handle_get_pixbuf);
8732 LOAD_IMGLIB_FN (library, rsvg_handle_set_base_uri); 8763 LOAD_DLL_FN (library, rsvg_handle_set_base_uri);
8733 8764
8734 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_width); 8765 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_width);
8735 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_height); 8766 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_height);
8736 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_pixels); 8767 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_pixels);
8737 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_rowstride); 8768 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_rowstride);
8738 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_colorspace); 8769 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_colorspace);
8739 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_n_channels); 8770 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_n_channels);
8740 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_has_alpha); 8771 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_has_alpha);
8741 LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_bits_per_sample); 8772 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_bits_per_sample);
8742 8773
8743#if ! GLIB_CHECK_VERSION (2, 36, 0) 8774# if ! GLIB_CHECK_VERSION (2, 36, 0)
8744 LOAD_IMGLIB_FN (gobject, g_type_init); 8775 LOAD_DLL_FN (gobject, g_type_init);
8745#endif 8776# endif
8746 LOAD_IMGLIB_FN (gobject, g_object_unref); 8777 LOAD_DLL_FN (gobject, g_object_unref);
8747 LOAD_IMGLIB_FN (glib, g_error_free); 8778 LOAD_DLL_FN (glib, g_error_free);
8748 8779
8749 return 1; 8780 return 1;
8750} 8781}
8751 8782
8752#else
8753/* The following aliases for library functions allow dynamic loading 8783/* The following aliases for library functions allow dynamic loading
8754 to be used on some platforms. */ 8784 to be used on some platforms. */
8755#define fn_rsvg_handle_new rsvg_handle_new
8756#define fn_rsvg_handle_get_dimensions rsvg_handle_get_dimensions
8757#define fn_rsvg_handle_write rsvg_handle_write
8758#define fn_rsvg_handle_close rsvg_handle_close
8759#define fn_rsvg_handle_get_pixbuf rsvg_handle_get_pixbuf
8760#define fn_rsvg_handle_set_base_uri rsvg_handle_set_base_uri
8761
8762#define fn_gdk_pixbuf_get_width gdk_pixbuf_get_width
8763#define fn_gdk_pixbuf_get_height gdk_pixbuf_get_height
8764#define fn_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels
8765#define fn_gdk_pixbuf_get_rowstride gdk_pixbuf_get_rowstride
8766#define fn_gdk_pixbuf_get_colorspace gdk_pixbuf_get_colorspace
8767#define fn_gdk_pixbuf_get_n_channels gdk_pixbuf_get_n_channels
8768#define fn_gdk_pixbuf_get_has_alpha gdk_pixbuf_get_has_alpha
8769#define fn_gdk_pixbuf_get_bits_per_sample gdk_pixbuf_get_bits_per_sample
8770 8785
8771#if ! GLIB_CHECK_VERSION (2, 36, 0) 8786# undef gdk_pixbuf_get_bits_per_sample
8772#define fn_g_type_init g_type_init 8787# undef gdk_pixbuf_get_colorspace
8773#endif 8788# undef gdk_pixbuf_get_has_alpha
8774#define fn_g_object_unref g_object_unref 8789# undef gdk_pixbuf_get_height
8775#define fn_g_error_free g_error_free 8790# undef gdk_pixbuf_get_n_channels
8776#endif /* !WINDOWSNT */ 8791# undef gdk_pixbuf_get_pixels
8792# undef gdk_pixbuf_get_rowstride
8793# undef gdk_pixbuf_get_width
8794# undef g_error_free
8795# undef g_object_unref
8796# undef g_type_init
8797# undef rsvg_handle_close
8798# undef rsvg_handle_get_dimensions
8799# undef rsvg_handle_get_pixbuf
8800# undef rsvg_handle_new
8801# undef rsvg_handle_set_base_uri
8802# undef rsvg_handle_write
8803
8804# define gdk_pixbuf_get_bits_per_sample fn_gdk_pixbuf_get_bits_per_sample
8805# define gdk_pixbuf_get_colorspace fn_gdk_pixbuf_get_colorspace
8806# define gdk_pixbuf_get_has_alpha fn_gdk_pixbuf_get_has_alpha
8807# define gdk_pixbuf_get_height fn_gdk_pixbuf_get_height
8808# define gdk_pixbuf_get_n_channels fn_gdk_pixbuf_get_n_channels
8809# define gdk_pixbuf_get_pixels fn_gdk_pixbuf_get_pixels
8810# define gdk_pixbuf_get_rowstride fn_gdk_pixbuf_get_rowstride
8811# define gdk_pixbuf_get_width fn_gdk_pixbuf_get_width
8812# define g_error_free fn_g_error_free
8813# define g_object_unref fn_g_object_unref
8814# define g_type_init fn_g_type_init
8815# define rsvg_handle_close fn_rsvg_handle_close
8816# define rsvg_handle_get_dimensions fn_rsvg_handle_get_dimensions
8817# define rsvg_handle_get_pixbuf fn_rsvg_handle_get_pixbuf
8818# define rsvg_handle_new fn_rsvg_handle_new
8819# define rsvg_handle_set_base_uri fn_rsvg_handle_set_base_uri
8820# define rsvg_handle_write fn_rsvg_handle_write
8821
8822# endif /* !WINDOWSNT */
8777 8823
8778/* Load SVG image IMG for use on frame F. Value is true if 8824/* Load SVG image IMG for use on frame F. Value is true if
8779 successful. */ 8825 successful. */
@@ -8862,28 +8908,28 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8862#if ! GLIB_CHECK_VERSION (2, 36, 0) 8908#if ! GLIB_CHECK_VERSION (2, 36, 0)
8863 /* g_type_init is a glib function that must be called prior to 8909 /* g_type_init is a glib function that must be called prior to
8864 using gnome type library functions (obsolete since 2.36.0). */ 8910 using gnome type library functions (obsolete since 2.36.0). */
8865 fn_g_type_init (); 8911 g_type_init ();
8866#endif 8912#endif
8867 8913
8868 /* Make a handle to a new rsvg object. */ 8914 /* Make a handle to a new rsvg object. */
8869 rsvg_handle = fn_rsvg_handle_new (); 8915 rsvg_handle = rsvg_handle_new ();
8870 8916
8871 /* Set base_uri for properly handling referenced images (via 'href'). 8917 /* Set base_uri for properly handling referenced images (via 'href').
8872 See rsvg bug 596114 - "image refs are relative to curdir, not .svg file" 8918 See rsvg bug 596114 - "image refs are relative to curdir, not .svg file"
8873 (https://bugzilla.gnome.org/show_bug.cgi?id=596114). */ 8919 (https://bugzilla.gnome.org/show_bug.cgi?id=596114). */
8874 if (filename) 8920 if (filename)
8875 fn_rsvg_handle_set_base_uri(rsvg_handle, filename); 8921 rsvg_handle_set_base_uri(rsvg_handle, filename);
8876 8922
8877 /* Parse the contents argument and fill in the rsvg_handle. */ 8923 /* Parse the contents argument and fill in the rsvg_handle. */
8878 fn_rsvg_handle_write (rsvg_handle, contents, size, &err); 8924 rsvg_handle_write (rsvg_handle, contents, size, &err);
8879 if (err) goto rsvg_error; 8925 if (err) goto rsvg_error;
8880 8926
8881 /* The parsing is complete, rsvg_handle is ready to used, close it 8927 /* The parsing is complete, rsvg_handle is ready to used, close it
8882 for further writes. */ 8928 for further writes. */
8883 fn_rsvg_handle_close (rsvg_handle, &err); 8929 rsvg_handle_close (rsvg_handle, &err);
8884 if (err) goto rsvg_error; 8930 if (err) goto rsvg_error;
8885 8931
8886 fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data); 8932 rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
8887 if (! check_image_size (f, dimension_data.width, dimension_data.height)) 8933 if (! check_image_size (f, dimension_data.width, dimension_data.height))
8888 { 8934 {
8889 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); 8935 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
@@ -8892,26 +8938,26 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8892 8938
8893 /* We can now get a valid pixel buffer from the svg file, if all 8939 /* We can now get a valid pixel buffer from the svg file, if all
8894 went ok. */ 8940 went ok. */
8895 pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle); 8941 pixbuf = rsvg_handle_get_pixbuf (rsvg_handle);
8896 if (!pixbuf) goto rsvg_error; 8942 if (!pixbuf) goto rsvg_error;
8897 fn_g_object_unref (rsvg_handle); 8943 g_object_unref (rsvg_handle);
8898 8944
8899 /* Extract some meta data from the svg handle. */ 8945 /* Extract some meta data from the svg handle. */
8900 width = fn_gdk_pixbuf_get_width (pixbuf); 8946 width = gdk_pixbuf_get_width (pixbuf);
8901 height = fn_gdk_pixbuf_get_height (pixbuf); 8947 height = gdk_pixbuf_get_height (pixbuf);
8902 pixels = fn_gdk_pixbuf_get_pixels (pixbuf); 8948 pixels = gdk_pixbuf_get_pixels (pixbuf);
8903 rowstride = fn_gdk_pixbuf_get_rowstride (pixbuf); 8949 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
8904 8950
8905 /* Validate the svg meta data. */ 8951 /* Validate the svg meta data. */
8906 eassert (fn_gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); 8952 eassert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
8907 eassert (fn_gdk_pixbuf_get_n_channels (pixbuf) == 4); 8953 eassert (gdk_pixbuf_get_n_channels (pixbuf) == 4);
8908 eassert (fn_gdk_pixbuf_get_has_alpha (pixbuf)); 8954 eassert (gdk_pixbuf_get_has_alpha (pixbuf));
8909 eassert (fn_gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); 8955 eassert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
8910 8956
8911 /* Try to create a x pixmap to hold the svg pixmap. */ 8957 /* Try to create a x pixmap to hold the svg pixmap. */
8912 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) 8958 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
8913 { 8959 {
8914 fn_g_object_unref (pixbuf); 8960 g_object_unref (pixbuf);
8915 return 0; 8961 return 0;
8916 } 8962 }
8917 8963
@@ -8968,7 +9014,7 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8968 free_color_table (); 9014 free_color_table ();
8969#endif /* COLOR_TABLE_SUPPORT */ 9015#endif /* COLOR_TABLE_SUPPORT */
8970 9016
8971 fn_g_object_unref (pixbuf); 9017 g_object_unref (pixbuf);
8972 9018
8973 img->width = width; 9019 img->width = width;
8974 img->height = height; 9020 img->height = height;
@@ -8983,11 +9029,11 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
8983 return 1; 9029 return 1;
8984 9030
8985 rsvg_error: 9031 rsvg_error:
8986 fn_g_object_unref (rsvg_handle); 9032 g_object_unref (rsvg_handle);
8987 /* FIXME: Use error->message so the user knows what is the actual 9033 /* FIXME: Use error->message so the user knows what is the actual
8988 problem with the image. */ 9034 problem with the image. */
8989 image_error ("Error parsing SVG image `%s'", img->spec, Qnil); 9035 image_error ("Error parsing SVG image `%s'", img->spec, Qnil);
8990 fn_g_error_free (err); 9036 g_error_free (err);
8991 return 0; 9037 return 0;
8992} 9038}
8993 9039
diff --git a/src/w32.h b/src/w32.h
index e0aedcbffa2..18e12b2458c 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -225,4 +225,17 @@ extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p,
225 const void* buf, size_t sz); 225 const void* buf, size_t sz);
226#endif /* HAVE_GNUTLS */ 226#endif /* HAVE_GNUTLS */
227 227
228/* Definine a function that will be loaded from a DLL. */
229#define DEF_DLL_FN(type, func, args) static type (FAR CDECL *fn_##func) args
230
231/* Load a function from the DLL. */
232#define LOAD_DLL_FN(lib, func) \
233 do \
234 { \
235 fn_##func = (void *) GetProcAddress (lib, #func); \
236 if (!fn_##func) \
237 return false; \
238 } \
239 while (false)
240
228#endif /* EMACS_W32_H */ 241#endif /* EMACS_W32_H */
diff --git a/src/xml.c b/src/xml.c
index d418202182b..6be3bc74e97 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -33,26 +33,17 @@ static Lisp_Object Qlibxml2_dll;
33 33
34#ifdef WINDOWSNT 34#ifdef WINDOWSNT
35 35
36#include <windows.h> 36# include <windows.h>
37#include "w32.h" 37# include "w32.h"
38 38
39/* Macro for defining functions that will be loaded from the libxml2 DLL. */ 39DEF_DLL_FN (htmlDocPtr, htmlReadMemory,
40#define DEF_XML2_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
41
42/* Macro for loading libxml2 functions from the library. */
43#define LOAD_XML2_FN(lib,func) { \
44 fn_##func = (void *) GetProcAddress (lib, #func); \
45 if (!fn_##func) goto bad_library; \
46 }
47
48DEF_XML2_FN (htmlDocPtr, htmlReadMemory,
49 (const char *, int, const char *, const char *, int)); 40 (const char *, int, const char *, const char *, int));
50DEF_XML2_FN (xmlDocPtr, xmlReadMemory, 41DEF_DLL_FN (xmlDocPtr, xmlReadMemory,
51 (const char *, int, const char *, const char *, int)); 42 (const char *, int, const char *, const char *, int));
52DEF_XML2_FN (xmlNodePtr, xmlDocGetRootElement, (xmlDocPtr)); 43DEF_DLL_FN (xmlNodePtr, xmlDocGetRootElement, (xmlDocPtr));
53DEF_XML2_FN (void, xmlFreeDoc, (xmlDocPtr)); 44DEF_DLL_FN (void, xmlFreeDoc, (xmlDocPtr));
54DEF_XML2_FN (void, xmlCleanupParser, (void)); 45DEF_DLL_FN (void, xmlCleanupParser, (void));
55DEF_XML2_FN (void, xmlCheckVersion, (int)); 46DEF_DLL_FN (void, xmlCheckVersion, (int));
56 47
57static int 48static int
58libxml2_loaded_p (void) 49libxml2_loaded_p (void)
@@ -64,14 +55,33 @@ libxml2_loaded_p (void)
64 return 0; 55 return 0;
65} 56}
66 57
67#else /* !WINDOWSNT */ 58# undef htmlReadMemory
59# undef xmlCheckVersion
60# undef xmlCleanupParser
61# undef xmlDocGetRootElement
62# undef xmlFreeDoc
63# undef xmlReadMemory
64
65# define htmlReadMemory fn_htmlReadMemory
66# define xmlCheckVersion fn_xmlCheckVersion
67# define xmlCleanupParser fn_xmlCleanupParser
68# define xmlDocGetRootElement fn_xmlDocGetRootElement
69# define xmlFreeDoc fn_xmlFreeDoc
70# define xmlReadMemory fn_xmlReadMemory
71
72static bool
73load_dll_functions (HMODULE library)
74{
75 LOAD_DLL_FN (library, htmlReadMemory);
76 LOAD_DLL_FN (library, xmlReadMemory);
77 LOAD_DLL_FN (library, xmlDocGetRootElement);
78 LOAD_DLL_FN (library, xmlFreeDoc);
79 LOAD_DLL_FN (library, xmlCleanupParser);
80 LOAD_DLL_FN (library, xmlCheckVersion);
81 return true;
82}
68 83
69#define fn_htmlReadMemory htmlReadMemory 84#else /* !WINDOWSNT */
70#define fn_xmlReadMemory xmlReadMemory
71#define fn_xmlDocGetRootElement xmlDocGetRootElement
72#define fn_xmlFreeDoc xmlFreeDoc
73#define fn_xmlCleanupParser xmlCleanupParser
74#define fn_xmlCheckVersion xmlCheckVersion
75 85
76static int 86static int
77libxml2_loaded_p (void) 87libxml2_loaded_p (void)
@@ -97,14 +107,8 @@ init_libxml2_functions (void)
97 return 0; 107 return 0;
98 } 108 }
99 109
100 /* LOAD_XML2_FN jumps to bad_library if it fails to find the 110 if (! load_dll_functions (library))
101 named function. */ 111 goto bad_library;
102 LOAD_XML2_FN (library, htmlReadMemory);
103 LOAD_XML2_FN (library, xmlReadMemory);
104 LOAD_XML2_FN (library, xmlDocGetRootElement);
105 LOAD_XML2_FN (library, xmlFreeDoc);
106 LOAD_XML2_FN (library, xmlCleanupParser);
107 LOAD_XML2_FN (library, xmlCheckVersion);
108 112
109 Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qt), Vlibrary_cache); 113 Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qt), Vlibrary_cache);
110 return 1; 114 return 1;
@@ -182,7 +186,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
182 const char *burl = ""; 186 const char *burl = "";
183 ptrdiff_t istart, iend, istart_byte, iend_byte; 187 ptrdiff_t istart, iend, istart_byte, iend_byte;
184 188
185 fn_xmlCheckVersion (LIBXML_VERSION); 189 xmlCheckVersion (LIBXML_VERSION);
186 190
187 validate_region (&start, &end); 191 validate_region (&start, &end);
188 192
@@ -201,16 +205,16 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
201 } 205 }
202 206
203 if (htmlp) 207 if (htmlp)
204 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 208 doc = htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
205 iend_byte - istart_byte, burl, "utf-8", 209 iend_byte - istart_byte, burl, "utf-8",
206 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 210 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 211 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
208 HTML_PARSE_NOBLANKS); 212 HTML_PARSE_NOBLANKS);
209 else 213 else
210 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 214 doc = xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
211 iend_byte - istart_byte, burl, "utf-8", 215 iend_byte - istart_byte, burl, "utf-8",
212 XML_PARSE_NONET|XML_PARSE_NOWARNING| 216 XML_PARSE_NONET|XML_PARSE_NOWARNING|
213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 217 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
214 218
215 if (doc != NULL) 219 if (doc != NULL)
216 { 220 {
@@ -232,14 +236,14 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
232 if (NILP (result)) { 236 if (NILP (result)) {
233 /* The document doesn't have toplevel comments or we discarded 237 /* The document doesn't have toplevel comments or we discarded
234 them. Get the tree the proper way. */ 238 them. Get the tree the proper way. */
235 xmlNode *node = fn_xmlDocGetRootElement (doc); 239 xmlNode *node = xmlDocGetRootElement (doc);
236 if (node != NULL) 240 if (node != NULL)
237 result = make_dom (node); 241 result = make_dom (node);
238 } else 242 } else
239 result = Fcons (intern ("top"), 243 result = Fcons (intern ("top"),
240 Fcons (Qnil, Fnreverse (Fcons (r, result)))); 244 Fcons (Qnil, Fnreverse (Fcons (r, result))));
241 245
242 fn_xmlFreeDoc (doc); 246 xmlFreeDoc (doc);
243 } 247 }
244 248
245 return result; 249 return result;
@@ -249,7 +253,7 @@ void
249xml_cleanup_parser (void) 253xml_cleanup_parser (void)
250{ 254{
251 if (libxml2_loaded_p ()) 255 if (libxml2_loaded_p ())
252 fn_xmlCleanupParser (); 256 xmlCleanupParser ();
253} 257}
254 258
255DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region, 259DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,