aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjave2014-12-31 12:24:10 +0100
committerjave2014-12-31 12:24:10 +0100
commitbaba9e039136e183e055169ddd7ca1e983fc734f (patch)
tree9168fb077980351a25ea3a112f2abd105a11099a /src
parent4105b6a93047045553e10795742a808b805c85b7 (diff)
parent25346768fac53687c97c213fb99ff18fa805b073 (diff)
downloademacs-baba9e039136e183e055169ddd7ca1e983fc734f.tar.gz
emacs-baba9e039136e183e055169ddd7ca1e983fc734f.zip
merge upstream
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog120
-rw-r--r--src/Makefile.in43
-rw-r--r--src/buffer.c4
-rw-r--r--src/composite.c3
-rw-r--r--src/decompress.c51
-rw-r--r--src/dispextern.h5
-rw-r--r--src/editfns.c16
-rw-r--r--src/filelock.c7
-rw-r--r--src/frame.c2
-rw-r--r--src/gnutls.c775
-rw-r--r--src/image.c932
-rw-r--r--src/nsimage.m8
-rw-r--r--src/sysdep.c132
-rw-r--r--src/term.c2
-rw-r--r--src/w32.h13
-rw-r--r--src/xdisp.c171
-rw-r--r--src/xml.c94
-rw-r--r--src/xrdb.c5
-rw-r--r--src/xselect.c95
-rw-r--r--src/xsettings.c94
-rw-r--r--src/xterm.c22
-rw-r--r--src/xterm.h8
22 files changed, 1338 insertions, 1264 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 72601fe7c58..85eb113db82 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,121 @@
12014-12-31 Paul Eggert <eggert@cs.ucla.edu>
2
3 Simplify setfattr use by assuming GNU make
4 * Makefile.in (PAXCTL_if_present, SETFATTR_if_present): New macros.
5 (emacs$(EXEEXT), temacs$(EXEEXT), bootstrap-emacs$(EXEEXT)): Use them.
6 Simplify by using GNU make rather than shell conditionals,
7 by using ln -f rather than rm -f followed by ln,
8 and by preferring $@ to spelling out the destination.
9
102014-12-29 Eli Zaretskii <eliz@gnu.org>
11
12 * sysdep.c [WINDOWSNT]: Include sys/socket.h, without which this
13 file doesn't compile on MS-Windows.
14
152014-12-28 Paul Eggert <eggert@cs.ucla.edu>
16
17 Fix produce_composite_width typo
18 * term.c (produce_composite_glyph):
19 Fix typo that confused number of columns for pixel width.
20
212014-12-28 Paul Eggert <eggert@Penguin.CS.UCLA.EDU>
22
23 Wrap dll functions more simply
24 * decompress.c, gnutls.c, image.c, xml.c:
25 If WINDOWSNT, use '#define FOO fn_FOO' to wrap dll functions,
26 rather than the inverse when not WINDOWSNT. This isolates the
27 fn_* business into the WINDOWSNT-specific section of the code,
28 which makes it easier to maintain the generic code.
29 * decompress.c (DEF_ZLIB_FN, LOAD_ZLIB_FN):
30 * gnutls.c (DEF_GNUTLS_FN, LOAD_GNUTLS_FN):
31 * image.c (DEF_IMGLIB_FN, LOAD_IMGLIB_FN):
32 * xml.c (DEF_XML2_FN, LOAD_XML2_FN):
33 Remove. All uses replaced by DEF_DLL_FN.
34 * decompress.c (inflateInit2): Remove; no longer needed.
35 * w32.h (DEF_DLL_FN, LOAD_DLL_FN): New macros.
36
37 Port memory-full checking to GnuTLS 3.3
38 Instead of using gnutls_global_set_mem_functions, check every call
39 to a GnuTLS function that might return an indication of memory
40 exhaustion. Suggested by Dmitry Antipov in:
41 http://lists.gnu.org/archive/html/emacs-devel/2014-12/msg02056.html
42 * gnutls.c (gnutls_global_set_mem_functions) [WINDOWSNT]: Remove.
43 (init_gnutls_functions): Do not load gnutls_global_set_mem_functions.
44 (fn_gnutls_global_set_mem_functions) [!WINDOWSNT]: Remove.
45 All uses removed.
46 (check_memory_full): New function.
47 (emacs_gnutls_handshake, emacs_gnutls_handle_error)
48 (gnutls_make_error, gnutls_certificate_details, Fgnutls_peer_status)
49 (Fgnutls_boot): Use it.
50 (emacs_gnutls_global_init): Avoid gnutls_global_set_mem_functions.
51
522014-12-27 Paul Eggert <eggert@cs.ucla.edu>
53
54 Fix parse_settings to match internal documentation
55 * xsettings.c (parse_settings): Return the number of settings seen.
56 Count the settings changes accurately.
57 (read_settings): Don't confuse number of settings changes with
58 the return code from XGetWindowProperty.
59
602014-12-27 Eli Zaretskii <eliz@gnu.org>
61
62 * xdisp.c (set_iterator_to_next) <GET_FROM_STRING>: Limit search in
63 composition_compute_stop_pos to the number of characters in the
64 string. (Bug#19435)
65 <GET_FROM_BUFFER, GET_FROM_STRING>: Simplify code.
66
67 * composite.c (composition_compute_stop_pos): If no composition
68 was found in a string before ENDPOS, and ENDPOS is the string end,
69 no need to back up to a safe point.
70
71 * dispextern.h (struct it) <end_charpos>: Improve commentary.
72
732014-12-27 Jan Djärv <jan.h.d@swipnet.se>
74
75 * nsimage.m (allocInitFromFile:): Initialize bmRep.
76 (dealloc): Release bmRep.
77 (setPixmapData): Make bmRep local so class member is not
78 set (Bug#19133).
79 (setPixmapData): Rename local variable bmRep to avoid compiler
80 warning.
81
822014-12-27 Jan Djärv <jan.h.d@swipnet.se>
83
84 * xterm.c (do_ewmh_fullscreen): Don't remove maximized_horz/vert
85 when going to fullscreen (Bug#0x180004f).
86
872014-12-27 Stefan Monnier <monnier@iro.umontreal.ca>
88
89 * buffer.c (syms_of_buffer) <Vafter_change_functions>: fix docstring.
90
912014-12-27 Eli Zaretskii <eliz@gnu.org>
92
93 * gnutls.c (gnutls_init): Fix deprecation warning from GCC.
94
952014-12-26 Paul Eggert <eggert@cs.ucla.edu>
96
97 Use bool for boolean in xselect.c, xsettings.c
98 * xselect.c (x_get_local_selection, struct selection_data)
99 (x_selection_request_lisp_error, struct prop_location)
100 (x_handle_selection_request, x_convert_selection)
101 (waiting_for_other_props_on_window, expect_property_change)
102 (wait_for_property_change, x_handle_property_notify)
103 (x_get_foreign_selection, x_get_window_property)
104 (receive_incremental_selection)
105 (x_get_window_property_as_lisp_data)
106 (lisp_data_to_selection_data, Fx_get_selection_internal)
107 (x_send_client_event):
108 * xselect.c, xterm.h (x_handle_dnd_message):
109 * xsettings.c (dpyinfo_valid, parse_settings, read_settings)
110 (apply_xft_settings, read_and_apply_settings)
111 (xft_settings_event, init_gsettings, init_xsettings)
112 (syms_of_xsettings):
113 Use bool for boolean.
114 * xselect.c (x_get_window_property): Omit last arg, which was an
115 unused boolean.
116 * xsettings.c (apply_xft_settings): Remove 2nd arg, which was
117 always true. All callers changed.
118
12014-12-26 Eli Zaretskii <eliz@gnu.org> 1192014-12-26 Eli Zaretskii <eliz@gnu.org>
2 120
3 * w32proc.c (sys_spawnve, get_lcid_callback): Use strcpy instead 121 * w32proc.c (sys_spawnve, get_lcid_callback): Use strcpy instead
@@ -894,6 +1012,8 @@
894 * fileio.c (Fexpand_file_name): Use make_unibyte_string, not 1012 * fileio.c (Fexpand_file_name): Use make_unibyte_string, not
895 build_string, when importing a home directory. (Bug#18873) 1013 build_string, when importing a home directory. (Bug#18873)
896 1014
10152014-12-27 Eli Zaretskii <eliz@gnu.org>
1016
897 * dispnew.c (buffer_posn_from_coords): 1017 * dispnew.c (buffer_posn_from_coords):
898 Use WINDOW_WANTS_HEADER_LINE_P, not WINDOW_WANTS_MODELINE_P, to 1018 Use WINDOW_WANTS_HEADER_LINE_P, not WINDOW_WANTS_MODELINE_P, to
899 account for the header-line height. (Bug#18839) 1019 account for the header-line height. (Bug#18839)
diff --git a/src/Makefile.in b/src/Makefile.in
index 930cca3566c..0ea453005ff 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -114,6 +114,8 @@ TEMACS_LDFLAGS = $(LD_SWITCH_SYSTEM) $(LD_SWITCH_SYSTEM_TEMACS)
114## around this, newer ones setfattr. See Bug#11398 and Bug#16343. 114## around this, newer ones setfattr. See Bug#11398 and Bug#16343.
115PAXCTL = @PAXCTL@ 115PAXCTL = @PAXCTL@
116SETFATTR = @SETFATTR@ 116SETFATTR = @SETFATTR@
117PAXCTL_if_present = $(or $(PAXCTL),: paxctl)
118SETFATTR_if_present = $(or $(SETFATTR),: setfattr)
117 119
118## Some systems define this to request special libraries. 120## Some systems define this to request special libraries.
119LIBS_SYSTEM=@LIBS_SYSTEM@ 121LIBS_SYSTEM=@LIBS_SYSTEM@
@@ -459,17 +461,13 @@ $(srcdir)/macuvs.h $(lispsource)/international/charprop.el: \
459emacs$(EXEEXT): temacs$(EXEEXT) \ 461emacs$(EXEEXT): temacs$(EXEEXT) \
460 $(etc)/DOC $(lisp) $(leimdir)/leim-list.el \ 462 $(etc)/DOC $(lisp) $(leimdir)/leim-list.el \
461 $(lispsource)/international/charprop.el 463 $(lispsource)/international/charprop.el
462 if test "$(CANNOT_DUMP)" = "yes"; then \ 464ifeq ($(CANNOT_DUMP),yes)
463 rm -f emacs$(EXEEXT); \ 465 ln -f temacs$(EXEEXT) $@
464 ln temacs$(EXEEXT) emacs$(EXEEXT); \ 466else
465 else \ 467 LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump
466 LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump || exit 1; \ 468 $(PAXCTL_if_present) -zex $@
467 test "X$(PAXCTL)" = X || $(PAXCTL) -zex emacs$(EXEEXT); \ 469 ln -f $@ bootstrap-emacs$(EXEEXT)
468 while test -f bootstrap-emacs$(EXEEXT); do \ 470endif
469 rm -f bootstrap-emacs$(EXEEXT); \
470 done; \
471 ln emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \
472 fi
473 471
474## We run make-docfile twice because the command line may get too long 472## We run make-docfile twice because the command line may get too long
475## on some systems. The sed command operating on lisp.mk also reduces 473## on some systems. The sed command operating on lisp.mk also reduces
@@ -527,10 +525,10 @@ temacs$(EXEEXT): $(LIBXMENU) $(ALLOBJS) \
527 $(AM_V_CCLD)$(CC) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \ 525 $(AM_V_CCLD)$(CC) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \
528 -o temacs $(ALLOBJS) $(lib)/libgnu.a $(W32_RES_LINK) $(LIBES) 526 -o temacs $(ALLOBJS) $(lib)/libgnu.a $(W32_RES_LINK) $(LIBES)
529 $(MKDIR_P) $(etc) 527 $(MKDIR_P) $(etc)
530 test "$(CANNOT_DUMP)" = "yes" || \ 528ifneq ($(CANNOT_DUMP),yes)
531 test "X$(PAXCTL)" = X || $(PAXCTL) -r temacs$(EXEEXT) 529 $(PAXCTL_if_present) -r $@
532 test "$(CANNOT_DUMP)" = "yes" || test -z "$(SETFATTR)" || \ 530 $(SETFATTR_if_present) -n user.pax.flags -v er $@
533 $(SETFATTR) -n user.pax.flags -v er $@ 531endif
534 532
535## The following oldxmenu-related rules are only (possibly) used if 533## The following oldxmenu-related rules are only (possibly) used if
536## HAVE_X11 && !USE_GTK, but there is no harm in always defining them. 534## HAVE_X11 && !USE_GTK, but there is no harm in always defining them.
@@ -662,14 +660,13 @@ $(lispsource)/loaddefs.el: $(VCSWITNESS) | bootstrap-emacs$(EXEEXT)
662## files from loadup.el in source form. 660## files from loadup.el in source form.
663bootstrap-emacs$(EXEEXT): temacs$(EXEEXT) 661bootstrap-emacs$(EXEEXT): temacs$(EXEEXT)
664 $(MAKE) -C ../lisp update-subdirs 662 $(MAKE) -C ../lisp update-subdirs
665 if test "$(CANNOT_DUMP)" = "yes"; then \ 663ifeq ($(CANNOT_DUMP),yes)
666 rm -f bootstrap-emacs$(EXEEXT); \ 664 ln -f temacs$(EXEEXT) $@
667 ln temacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \ 665else
668 else \ 666 $(RUN_TEMACS) --batch --load loadup bootstrap
669 $(RUN_TEMACS) --batch --load loadup bootstrap || exit 1; \ 667 $(PAXCTL_if_present) -zex emacs$(EXEEXT)
670 test "X$(PAXCTL)" = X || $(PAXCTL) -zex emacs$(EXEEXT); \ 668 mv -f emacs$(EXEEXT) $@
671 mv -f emacs$(EXEEXT) bootstrap-emacs$(EXEEXT); \ 669endif
672 fi
673 @: Compile some files earlier to speed up further compilation. 670 @: Compile some files earlier to speed up further compilation.
674 $(MAKE) -C ../lisp compile-first EMACS="$(bootstrap_exe)" 671 $(MAKE) -C ../lisp compile-first EMACS="$(bootstrap_exe)"
675 672
diff --git a/src/buffer.c b/src/buffer.c
index 7e424bb3178..4e746903efc 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6074,9 +6074,9 @@ from happening repeatedly and making Emacs nonfunctional. */);
6074 doc: /* List of functions to call after each text change. 6074 doc: /* List of functions to call after each text change.
6075Three arguments are passed to each function: the positions of 6075Three arguments are passed to each function: the positions of
6076the beginning and end of the range of changed text, 6076the beginning and end of the range of changed text,
6077and the length in bytes of the pre-change text replaced by that range. 6077and the length in chars of the pre-change text replaced by that range.
6078\(For an insertion, the pre-change length is zero; 6078\(For an insertion, the pre-change length is zero;
6079for a deletion, that length is the number of bytes deleted, 6079for a deletion, that length is the number of chars deleted,
6080and the post-change beginning and end are at the same place.) 6080and the post-change beginning and end are at the same place.)
6081 6081
6082Buffer changes made while executing the `after-change-functions' 6082Buffer changes made while executing the `after-change-functions'
diff --git a/src/composite.c b/src/composite.c
index 8982c904096..0b52a9fcd2b 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1032,7 +1032,8 @@ composition_compute_stop_pos (struct composition_it *cmp_it, ptrdiff_t charpos,
1032 } 1032 }
1033 } 1033 }
1034 } 1034 }
1035 if (charpos == endpos) 1035 if (charpos == endpos
1036 && !(STRINGP (string) && endpos == SCHARS (string)))
1036 { 1037 {
1037 /* We couldn't find a composition point before ENDPOS. But, 1038 /* We couldn't find a composition point before ENDPOS. But,
1038 some character after ENDPOS may be composed with 1039 some character after ENDPOS may be composed with
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/dispextern.h b/src/dispextern.h
index 10a567ea485..908b62b5995 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2252,7 +2252,10 @@ struct it
2252 ptrdiff_t base_level_stop; 2252 ptrdiff_t base_level_stop;
2253 2253
2254 /* Maximum string or buffer position + 1. ZV when iterating over 2254 /* Maximum string or buffer position + 1. ZV when iterating over
2255 current_buffer. */ 2255 current_buffer. When iterating over a string in display_string,
2256 this can be smaller or greater than the number of string
2257 characters, depending on the values of PRECISION and FIELD_WIDTH
2258 with which display_string was called. */
2256 ptrdiff_t end_charpos; 2259 ptrdiff_t end_charpos;
2257 2260
2258 /* C string to iterate over. Non-null means get characters from 2261 /* C string to iterate over. Non-null means get characters from
diff --git a/src/editfns.c b/src/editfns.c
index 430c4c91fb3..2a7dd9209ae 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -93,6 +93,17 @@ static char const *initial_tz;
93 It is OK (though a bit slower) if the user chooses this value. */ 93 It is OK (though a bit slower) if the user chooses this value. */
94static char dump_tz_string[] = "TZ=UtC0"; 94static char dump_tz_string[] = "TZ=UtC0";
95 95
96/* The cached value of Vsystem_name. This is used only to compare it
97 to Vsystem_name, so it need not be visible to the GC. */
98static Lisp_Object cached_system_name;
99
100static void
101init_and_cache_system_name (void)
102{
103 init_system_name ();
104 cached_system_name = Vsystem_name;
105}
106
96void 107void
97init_editfns (void) 108init_editfns (void)
98{ 109{
@@ -102,7 +113,7 @@ init_editfns (void)
102 Lisp_Object tem; 113 Lisp_Object tem;
103 114
104 /* Set up system_name even when dumping. */ 115 /* Set up system_name even when dumping. */
105 init_system_name (); 116 init_and_cache_system_name ();
106 117
107#ifndef CANNOT_DUMP 118#ifndef CANNOT_DUMP
108 /* When just dumping out, set the time zone to a known unlikely value 119 /* When just dumping out, set the time zone to a known unlikely value
@@ -1365,6 +1376,8 @@ DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
1365 doc: /* Return the host name of the machine you are running on, as a string. */) 1376 doc: /* Return the host name of the machine you are running on, as a string. */)
1366 (void) 1377 (void)
1367{ 1378{
1379 if (EQ (Vsystem_name, cached_system_name))
1380 init_and_cache_system_name ();
1368 return Vsystem_name; 1381 return Vsystem_name;
1369} 1382}
1370 1383
@@ -4965,6 +4978,7 @@ functions if all the text being accessed has this property. */);
4965 4978
4966 DEFVAR_LISP ("system-name", Vsystem_name, 4979 DEFVAR_LISP ("system-name", Vsystem_name,
4967 doc: /* The host name of the machine Emacs is running on. */); 4980 doc: /* The host name of the machine Emacs is running on. */);
4981 Vsystem_name = cached_system_name = Qnil;
4968 4982
4969 DEFVAR_LISP ("user-full-name", Vuser_full_name, 4983 DEFVAR_LISP ("user-full-name", Vuser_full_name,
4970 doc: /* The full name of the user logged in. */); 4984 doc: /* The full name of the user logged in. */);
diff --git a/src/filelock.c b/src/filelock.c
index f857c488143..99215f215e7 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -592,9 +592,10 @@ current_lock_owner (lock_info_type *owner, char *lfname)
592 return -1; 592 return -1;
593 593
594 /* On current host? */ 594 /* On current host? */
595 if (STRINGP (Vsystem_name) 595 Lisp_Object system_name = Fsystem_name ();
596 && dot - (at + 1) == SBYTES (Vsystem_name) 596 if (STRINGP (system_name)
597 && memcmp (at + 1, SSDATA (Vsystem_name), SBYTES (Vsystem_name)) == 0) 597 && dot - (at + 1) == SBYTES (system_name)
598 && memcmp (at + 1, SSDATA (system_name), SBYTES (system_name)) == 0)
598 { 599 {
599 if (pid == getpid ()) 600 if (pid == getpid ())
600 ret = 2; /* We own it. */ 601 ret = 2; /* We own it. */
diff --git a/src/frame.c b/src/frame.c
index 2ad1c1b52b7..82a85bc48e6 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -5057,7 +5057,7 @@ keep it unchanged if this option is either `t' or a list containing
5057`vertical-scroll-bars'. 5057`vertical-scroll-bars'.
5058 5058
5059The default value is '(tool-bar-lines) on Lucid, Motif and Windows 5059The default value is '(tool-bar-lines) on Lucid, Motif and Windows
5060(which means that adding/removing a tool bar does not change the frame 5060\(which means that adding/removing a tool bar does not change the frame
5061height), nil on all other window systems including GTK+ (which means 5061height), nil on all other window systems including GTK+ (which means
5062that changing any of the parameters listed above may change the size of 5062that changing any of the parameters listed above may change the size of
5063the frame), and `t' otherwise (which means the frame size never changes 5063the frame), and `t' otherwise (which means the frame size never changes
diff --git a/src/gnutls.c b/src/gnutls.c
index bf9f1323546..f945778cc91 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -71,142 +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 (void, gnutls_global_set_mem_functions, 132DEF_DLL_FN (const char *, gnutls_strerror, (int));
133 (gnutls_alloc_function, gnutls_alloc_function, 133DEF_DLL_FN (void, gnutls_transport_set_errno, (gnutls_session_t, int));
134 gnutls_is_secure_function, gnutls_realloc_function, 134DEF_DLL_FN (const char *, gnutls_check_version, (const char *));
135 gnutls_free_function)); 135DEF_DLL_FN (void, gnutls_transport_set_lowat, (gnutls_session_t, int));
136DEF_GNUTLS_FN (int, gnutls_handshake, (gnutls_session_t)); 136DEF_DLL_FN (void, gnutls_transport_set_ptr2,
137DEF_GNUTLS_FN (int, gnutls_init, (gnutls_session_t *, gnutls_connection_end_t)); 137 (gnutls_session_t, gnutls_transport_ptr_t,
138DEF_GNUTLS_FN (int, gnutls_priority_set_direct, 138 gnutls_transport_ptr_t));
139 (gnutls_session_t, const char *, const char **)); 139DEF_DLL_FN (void, gnutls_transport_set_pull_function,
140DEF_GNUTLS_FN (size_t, gnutls_record_check_pending, (gnutls_session_t)); 140 (gnutls_session_t, gnutls_pull_func));
141DEF_GNUTLS_FN (ssize_t, gnutls_record_recv, (gnutls_session_t, void *, size_t)); 141DEF_DLL_FN (void, gnutls_transport_set_push_function,
142DEF_GNUTLS_FN (ssize_t, gnutls_record_send, 142 (gnutls_session_t, gnutls_push_func));
143 (gnutls_session_t, const void *, size_t)); 143DEF_DLL_FN (int, gnutls_x509_crt_check_hostname,
144DEF_GNUTLS_FN (const char *, gnutls_strerror, (int)); 144 (gnutls_x509_crt_t, const char *));
145DEF_GNUTLS_FN (void, gnutls_transport_set_errno, (gnutls_session_t, int)); 145DEF_DLL_FN (void, gnutls_x509_crt_deinit, (gnutls_x509_crt_t));
146DEF_GNUTLS_FN (const char *, gnutls_check_version, (const char *)); 146DEF_DLL_FN (int, gnutls_x509_crt_import,
147DEF_GNUTLS_FN (void, gnutls_transport_set_lowat, (gnutls_session_t, int)); 147 (gnutls_x509_crt_t, const gnutls_datum_t *,
148DEF_GNUTLS_FN (void, gnutls_transport_set_ptr2, 148 gnutls_x509_crt_fmt_t));
149 (gnutls_session_t, gnutls_transport_ptr_t, 149DEF_DLL_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *));
150 gnutls_transport_ptr_t)); 150DEF_DLL_FN (int, gnutls_x509_crt_get_fingerprint,
151DEF_GNUTLS_FN (void, gnutls_transport_set_pull_function, 151 (gnutls_x509_crt_t,
152 (gnutls_session_t, gnutls_pull_func)); 152 gnutls_digest_algorithm_t, void *, size_t *));
153DEF_GNUTLS_FN (void, gnutls_transport_set_push_function, 153DEF_DLL_FN (int, gnutls_x509_crt_get_version,
154 (gnutls_session_t, gnutls_push_func)); 154 (gnutls_x509_crt_t));
155DEF_GNUTLS_FN (int, gnutls_x509_crt_check_hostname, 155DEF_DLL_FN (int, gnutls_x509_crt_get_serial,
156 (gnutls_x509_crt_t, const char *)); 156 (gnutls_x509_crt_t, void *, size_t *));
157DEF_GNUTLS_FN (void, gnutls_x509_crt_deinit, (gnutls_x509_crt_t)); 157DEF_DLL_FN (int, gnutls_x509_crt_get_issuer_dn,
158DEF_GNUTLS_FN (int, gnutls_x509_crt_import, 158 (gnutls_x509_crt_t, char *, size_t *));
159 (gnutls_x509_crt_t, const gnutls_datum_t *, 159DEF_DLL_FN (time_t, gnutls_x509_crt_get_activation_time,
160 gnutls_x509_crt_fmt_t)); 160 (gnutls_x509_crt_t));
161DEF_GNUTLS_FN (int, gnutls_x509_crt_init, (gnutls_x509_crt_t *)); 161DEF_DLL_FN (time_t, gnutls_x509_crt_get_expiration_time,
162DEF_GNUTLS_FN (int, gnutls_x509_crt_get_fingerprint, 162 (gnutls_x509_crt_t));
163 (gnutls_x509_crt_t, 163DEF_DLL_FN (int, gnutls_x509_crt_get_dn,
164 gnutls_digest_algorithm_t, void *, size_t *)); 164 (gnutls_x509_crt_t, char *, size_t *));
165DEF_GNUTLS_FN (int, gnutls_x509_crt_get_version, 165DEF_DLL_FN (int, gnutls_x509_crt_get_pk_algorithm,
166 (gnutls_x509_crt_t)); 166 (gnutls_x509_crt_t, unsigned int *));
167DEF_GNUTLS_FN (int, gnutls_x509_crt_get_serial, 167DEF_DLL_FN (const char*, gnutls_pk_algorithm_get_name,
168 (gnutls_x509_crt_t, void *, size_t *)); 168 (gnutls_pk_algorithm_t));
169DEF_GNUTLS_FN (int, gnutls_x509_crt_get_issuer_dn, 169DEF_DLL_FN (int, gnutls_pk_bits_to_sec_param,
170 (gnutls_x509_crt_t, char *, size_t *)); 170 (gnutls_pk_algorithm_t, unsigned int));
171DEF_GNUTLS_FN (time_t, gnutls_x509_crt_get_activation_time, 171DEF_DLL_FN (int, gnutls_x509_crt_get_issuer_unique_id,
172 (gnutls_x509_crt_t)); 172 (gnutls_x509_crt_t, char *, size_t *));
173DEF_GNUTLS_FN (time_t, gnutls_x509_crt_get_expiration_time, 173DEF_DLL_FN (int, gnutls_x509_crt_get_subject_unique_id,
174 (gnutls_x509_crt_t)); 174 (gnutls_x509_crt_t, char *, size_t *));
175DEF_GNUTLS_FN (int, gnutls_x509_crt_get_dn, 175DEF_DLL_FN (int, gnutls_x509_crt_get_signature_algorithm,
176 (gnutls_x509_crt_t, char *, size_t *)); 176 (gnutls_x509_crt_t));
177DEF_GNUTLS_FN (int, gnutls_x509_crt_get_pk_algorithm, 177DEF_DLL_FN (int, gnutls_x509_crt_get_signature,
178 (gnutls_x509_crt_t, unsigned int *)); 178 (gnutls_x509_crt_t, char *, size_t *));
179DEF_GNUTLS_FN (const char*, gnutls_pk_algorithm_get_name, 179DEF_DLL_FN (int, gnutls_x509_crt_get_key_id,
180 (gnutls_pk_algorithm_t)); 180 (gnutls_x509_crt_t, unsigned int, unsigned char *, size_t *_size));
181DEF_GNUTLS_FN (int, gnutls_pk_bits_to_sec_param, 181DEF_DLL_FN (const char*, gnutls_sec_param_get_name, (gnutls_sec_param_t));
182 (gnutls_pk_algorithm_t, unsigned int)); 182DEF_DLL_FN (const char*, gnutls_sign_get_name, (gnutls_sign_algorithm_t));
183DEF_GNUTLS_FN (int, gnutls_x509_crt_get_issuer_unique_id, 183DEF_DLL_FN (int, gnutls_server_name_set,
184 (gnutls_x509_crt_t, char *, size_t *)); 184 (gnutls_session_t, gnutls_server_name_type_t,
185DEF_GNUTLS_FN (int, gnutls_x509_crt_get_subject_unique_id, 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_signature_algorithm, 187DEF_DLL_FN (const char*, gnutls_kx_get_name, (gnutls_kx_algorithm_t));
188 (gnutls_x509_crt_t)); 188DEF_DLL_FN (gnutls_protocol_t, gnutls_protocol_get_version,
189DEF_GNUTLS_FN (int, gnutls_x509_crt_get_signature, 189 (gnutls_session_t));
190 (gnutls_x509_crt_t, char *, size_t *)); 190DEF_DLL_FN (const char*, gnutls_protocol_get_name, (gnutls_protocol_t));
191DEF_GNUTLS_FN (int, gnutls_x509_crt_get_key_id, 191DEF_DLL_FN (gnutls_cipher_algorithm_t, gnutls_cipher_get,
192 (gnutls_x509_crt_t, unsigned int, 192 (gnutls_session_t));
193 unsigned char *, size_t *_size)); 193DEF_DLL_FN (const char*, gnutls_cipher_get_name,
194DEF_GNUTLS_FN (const char*, gnutls_sec_param_get_name, (gnutls_sec_param_t)); 194 (gnutls_cipher_algorithm_t));
195DEF_GNUTLS_FN (const char*, gnutls_sign_get_name, (gnutls_sign_algorithm_t)); 195DEF_DLL_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t));
196DEF_GNUTLS_FN (int, gnutls_server_name_set, (gnutls_session_t, 196DEF_DLL_FN (const char*, gnutls_mac_get_name, (gnutls_mac_algorithm_t));
197 gnutls_server_name_type_t,
198 const void *, size_t));
199DEF_GNUTLS_FN (gnutls_kx_algorithm_t, gnutls_kx_get, (gnutls_session_t));
200DEF_GNUTLS_FN (const char*, gnutls_kx_get_name, (gnutls_kx_algorithm_t));
201DEF_GNUTLS_FN (gnutls_protocol_t, gnutls_protocol_get_version,
202 (gnutls_session_t));
203DEF_GNUTLS_FN (const char*, gnutls_protocol_get_name, (gnutls_protocol_t));
204DEF_GNUTLS_FN (gnutls_cipher_algorithm_t, gnutls_cipher_get,
205 (gnutls_session_t));
206DEF_GNUTLS_FN (const char*, gnutls_cipher_get_name,
207 (gnutls_cipher_algorithm_t));
208DEF_GNUTLS_FN (gnutls_mac_algorithm_t, gnutls_mac_get, (gnutls_session_t));
209DEF_GNUTLS_FN (const char*, gnutls_mac_get_name, (gnutls_mac_algorithm_t));
210 197
211 198
212static bool 199static bool
@@ -221,83 +208,83 @@ init_gnutls_functions (void)
221 return 0; 208 return 0;
222 } 209 }
223 210
224 LOAD_GNUTLS_FN (library, gnutls_alert_get); 211 LOAD_DLL_FN (library, gnutls_alert_get);
225 LOAD_GNUTLS_FN (library, gnutls_alert_get_name); 212 LOAD_DLL_FN (library, gnutls_alert_get_name);
226 LOAD_GNUTLS_FN (library, gnutls_alert_send_appropriate); 213 LOAD_DLL_FN (library, gnutls_alert_send_appropriate);
227 LOAD_GNUTLS_FN (library, gnutls_anon_allocate_client_credentials); 214 LOAD_DLL_FN (library, gnutls_anon_allocate_client_credentials);
228 LOAD_GNUTLS_FN (library, gnutls_anon_free_client_credentials); 215 LOAD_DLL_FN (library, gnutls_anon_free_client_credentials);
229 LOAD_GNUTLS_FN (library, gnutls_bye); 216 LOAD_DLL_FN (library, gnutls_bye);
230 LOAD_GNUTLS_FN (library, gnutls_certificate_allocate_credentials); 217 LOAD_DLL_FN (library, gnutls_certificate_allocate_credentials);
231 LOAD_GNUTLS_FN (library, gnutls_certificate_free_credentials); 218 LOAD_DLL_FN (library, gnutls_certificate_free_credentials);
232 LOAD_GNUTLS_FN (library, gnutls_certificate_get_peers); 219 LOAD_DLL_FN (library, gnutls_certificate_get_peers);
233 LOAD_GNUTLS_FN (library, gnutls_certificate_set_verify_flags); 220 LOAD_DLL_FN (library, gnutls_certificate_set_verify_flags);
234 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_crl_file); 221 LOAD_DLL_FN (library, gnutls_certificate_set_x509_crl_file);
235 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_key_file); 222 LOAD_DLL_FN (library, gnutls_certificate_set_x509_key_file);
236#if GNUTLS_VERSION_MAJOR + \ 223# if ((GNUTLS_VERSION_MAJOR \
237 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 224 + (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20)) \
238 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_system_trust); 225 > 3)
239#endif 226 LOAD_DLL_FN (library, gnutls_certificate_set_x509_system_trust);
240 LOAD_GNUTLS_FN (library, gnutls_certificate_set_x509_trust_file); 227# endif
241 LOAD_GNUTLS_FN (library, gnutls_certificate_type_get); 228 LOAD_DLL_FN (library, gnutls_certificate_set_x509_trust_file);
242 LOAD_GNUTLS_FN (library, gnutls_certificate_verify_peers2); 229 LOAD_DLL_FN (library, gnutls_certificate_type_get);
243 LOAD_GNUTLS_FN (library, gnutls_credentials_set); 230 LOAD_DLL_FN (library, gnutls_certificate_verify_peers2);
244 LOAD_GNUTLS_FN (library, gnutls_deinit); 231 LOAD_DLL_FN (library, gnutls_credentials_set);
245 LOAD_GNUTLS_FN (library, gnutls_dh_set_prime_bits); 232 LOAD_DLL_FN (library, gnutls_deinit);
246 LOAD_GNUTLS_FN (library, gnutls_dh_get_prime_bits); 233 LOAD_DLL_FN (library, gnutls_dh_set_prime_bits);
247 LOAD_GNUTLS_FN (library, gnutls_error_is_fatal); 234 LOAD_DLL_FN (library, gnutls_dh_get_prime_bits);
248 LOAD_GNUTLS_FN (library, gnutls_global_init); 235 LOAD_DLL_FN (library, gnutls_error_is_fatal);
249 LOAD_GNUTLS_FN (library, gnutls_global_set_log_function); 236 LOAD_DLL_FN (library, gnutls_global_init);
250#ifdef HAVE_GNUTLS3 237 LOAD_DLL_FN (library, gnutls_global_set_log_function);
251 LOAD_GNUTLS_FN (library, gnutls_global_set_audit_log_function); 238# ifdef HAVE_GNUTLS3
252#endif 239 LOAD_DLL_FN (library, gnutls_global_set_audit_log_function);
253 LOAD_GNUTLS_FN (library, gnutls_global_set_log_level); 240# endif
254 LOAD_GNUTLS_FN (library, gnutls_global_set_mem_functions); 241 LOAD_DLL_FN (library, gnutls_global_set_log_level);
255 LOAD_GNUTLS_FN (library, gnutls_handshake); 242 LOAD_DLL_FN (library, gnutls_handshake);
256 LOAD_GNUTLS_FN (library, gnutls_init); 243 LOAD_DLL_FN (library, gnutls_init);
257 LOAD_GNUTLS_FN (library, gnutls_priority_set_direct); 244 LOAD_DLL_FN (library, gnutls_priority_set_direct);
258 LOAD_GNUTLS_FN (library, gnutls_record_check_pending); 245 LOAD_DLL_FN (library, gnutls_record_check_pending);
259 LOAD_GNUTLS_FN (library, gnutls_record_recv); 246 LOAD_DLL_FN (library, gnutls_record_recv);
260 LOAD_GNUTLS_FN (library, gnutls_record_send); 247 LOAD_DLL_FN (library, gnutls_record_send);
261 LOAD_GNUTLS_FN (library, gnutls_strerror); 248 LOAD_DLL_FN (library, gnutls_strerror);
262 LOAD_GNUTLS_FN (library, gnutls_transport_set_errno); 249 LOAD_DLL_FN (library, gnutls_transport_set_errno);
263 LOAD_GNUTLS_FN (library, gnutls_check_version); 250 LOAD_DLL_FN (library, gnutls_check_version);
264 /* 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
265 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. */
266 if (!fn_gnutls_check_version ("2.11.1")) 253 if (!fn_gnutls_check_version ("2.11.1"))
267 LOAD_GNUTLS_FN (library, gnutls_transport_set_lowat); 254 LOAD_DLL_FN (library, gnutls_transport_set_lowat);
268 LOAD_GNUTLS_FN (library, gnutls_transport_set_ptr2); 255 LOAD_DLL_FN (library, gnutls_transport_set_ptr2);
269 LOAD_GNUTLS_FN (library, gnutls_transport_set_pull_function); 256 LOAD_DLL_FN (library, gnutls_transport_set_pull_function);
270 LOAD_GNUTLS_FN (library, gnutls_transport_set_push_function); 257 LOAD_DLL_FN (library, gnutls_transport_set_push_function);
271 LOAD_GNUTLS_FN (library, gnutls_x509_crt_check_hostname); 258 LOAD_DLL_FN (library, gnutls_x509_crt_check_hostname);
272 LOAD_GNUTLS_FN (library, gnutls_x509_crt_deinit); 259 LOAD_DLL_FN (library, gnutls_x509_crt_deinit);
273 LOAD_GNUTLS_FN (library, gnutls_x509_crt_import); 260 LOAD_DLL_FN (library, gnutls_x509_crt_import);
274 LOAD_GNUTLS_FN (library, gnutls_x509_crt_init); 261 LOAD_DLL_FN (library, gnutls_x509_crt_init);
275 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_fingerprint); 262 LOAD_DLL_FN (library, gnutls_x509_crt_get_fingerprint);
276 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_version); 263 LOAD_DLL_FN (library, gnutls_x509_crt_get_version);
277 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_serial); 264 LOAD_DLL_FN (library, gnutls_x509_crt_get_serial);
278 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_issuer_dn); 265 LOAD_DLL_FN (library, gnutls_x509_crt_get_issuer_dn);
279 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_activation_time); 266 LOAD_DLL_FN (library, gnutls_x509_crt_get_activation_time);
280 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_expiration_time); 267 LOAD_DLL_FN (library, gnutls_x509_crt_get_expiration_time);
281 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_dn); 268 LOAD_DLL_FN (library, gnutls_x509_crt_get_dn);
282 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_pk_algorithm); 269 LOAD_DLL_FN (library, gnutls_x509_crt_get_pk_algorithm);
283 LOAD_GNUTLS_FN (library, gnutls_pk_algorithm_get_name); 270 LOAD_DLL_FN (library, gnutls_pk_algorithm_get_name);
284 LOAD_GNUTLS_FN (library, gnutls_pk_bits_to_sec_param); 271 LOAD_DLL_FN (library, gnutls_pk_bits_to_sec_param);
285 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_issuer_unique_id); 272 LOAD_DLL_FN (library, gnutls_x509_crt_get_issuer_unique_id);
286 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_subject_unique_id); 273 LOAD_DLL_FN (library, gnutls_x509_crt_get_subject_unique_id);
287 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_signature_algorithm); 274 LOAD_DLL_FN (library, gnutls_x509_crt_get_signature_algorithm);
288 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_signature); 275 LOAD_DLL_FN (library, gnutls_x509_crt_get_signature);
289 LOAD_GNUTLS_FN (library, gnutls_x509_crt_get_key_id); 276 LOAD_DLL_FN (library, gnutls_x509_crt_get_key_id);
290 LOAD_GNUTLS_FN (library, gnutls_sec_param_get_name); 277 LOAD_DLL_FN (library, gnutls_sec_param_get_name);
291 LOAD_GNUTLS_FN (library, gnutls_sign_get_name); 278 LOAD_DLL_FN (library, gnutls_sign_get_name);
292 LOAD_GNUTLS_FN (library, gnutls_server_name_set); 279 LOAD_DLL_FN (library, gnutls_server_name_set);
293 LOAD_GNUTLS_FN (library, gnutls_kx_get); 280 LOAD_DLL_FN (library, gnutls_kx_get);
294 LOAD_GNUTLS_FN (library, gnutls_kx_get_name); 281 LOAD_DLL_FN (library, gnutls_kx_get_name);
295 LOAD_GNUTLS_FN (library, gnutls_protocol_get_version); 282 LOAD_DLL_FN (library, gnutls_protocol_get_version);
296 LOAD_GNUTLS_FN (library, gnutls_protocol_get_name); 283 LOAD_DLL_FN (library, gnutls_protocol_get_name);
297 LOAD_GNUTLS_FN (library, gnutls_cipher_get); 284 LOAD_DLL_FN (library, gnutls_cipher_get);
298 LOAD_GNUTLS_FN (library, gnutls_cipher_get_name); 285 LOAD_DLL_FN (library, gnutls_cipher_get_name);
299 LOAD_GNUTLS_FN (library, gnutls_mac_get); 286 LOAD_DLL_FN (library, gnutls_mac_get);
300 LOAD_GNUTLS_FN (library, gnutls_mac_get_name); 287 LOAD_DLL_FN (library, gnutls_mac_get_name);
301 288
302 max_log_level = global_gnutls_log_level; 289 max_log_level = global_gnutls_log_level;
303 290
@@ -310,80 +297,89 @@ init_gnutls_functions (void)
310 return 1; 297 return 1;
311} 298}
312 299
313#else /* !WINDOWSNT */ 300# define gnutls_alert_get fn_gnutls_alert_get
314 301# define gnutls_alert_get_name fn_gnutls_alert_get_name
315#define fn_gnutls_alert_get gnutls_alert_get 302# define gnutls_alert_send_appropriate fn_gnutls_alert_send_appropriate
316#define fn_gnutls_alert_get_name gnutls_alert_get_name 303# define gnutls_anon_allocate_client_credentials fn_gnutls_anon_allocate_client_credentials
317#define fn_gnutls_alert_send_appropriate gnutls_alert_send_appropriate 304# define gnutls_anon_free_client_credentials fn_gnutls_anon_free_client_credentials
318#define fn_gnutls_anon_allocate_client_credentials gnutls_anon_allocate_client_credentials 305# define gnutls_bye fn_gnutls_bye
319#define fn_gnutls_anon_free_client_credentials gnutls_anon_free_client_credentials 306# define gnutls_certificate_allocate_credentials fn_gnutls_certificate_allocate_credentials
320#define fn_gnutls_bye gnutls_bye 307# define gnutls_certificate_free_credentials fn_gnutls_certificate_free_credentials
321#define fn_gnutls_certificate_allocate_credentials gnutls_certificate_allocate_credentials 308# define gnutls_certificate_get_peers fn_gnutls_certificate_get_peers
322#define fn_gnutls_certificate_free_credentials gnutls_certificate_free_credentials 309# define gnutls_certificate_set_verify_flags fn_gnutls_certificate_set_verify_flags
323#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
324#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
325#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
326#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
327#if GNUTLS_VERSION_MAJOR + \ 314# define gnutls_certificate_type_get fn_gnutls_certificate_type_get
328 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 315# define gnutls_certificate_verify_peers2 fn_gnutls_certificate_verify_peers2
329#define fn_gnutls_certificate_set_x509_system_trust gnutls_certificate_set_x509_system_trust 316# define gnutls_check_version fn_gnutls_check_version
330#endif 317# define gnutls_cipher_get fn_gnutls_cipher_get
331#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
332#define fn_gnutls_certificate_type_get gnutls_certificate_type_get 319# define gnutls_credentials_set fn_gnutls_credentials_set
333#define fn_gnutls_certificate_verify_peers2 gnutls_certificate_verify_peers2 320# define gnutls_deinit fn_gnutls_deinit
334#define fn_gnutls_cipher_get gnutls_cipher_get 321# define gnutls_dh_get_prime_bits fn_gnutls_dh_get_prime_bits
335#define fn_gnutls_cipher_get_name gnutls_cipher_get_name 322# define gnutls_dh_set_prime_bits fn_gnutls_dh_set_prime_bits
336#define fn_gnutls_credentials_set gnutls_credentials_set 323# define gnutls_error_is_fatal fn_gnutls_error_is_fatal
337#define fn_gnutls_deinit gnutls_deinit 324# define gnutls_global_init fn_gnutls_global_init
338#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
339#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
340#define fn_gnutls_error_is_fatal gnutls_error_is_fatal 327# define gnutls_global_set_log_level fn_gnutls_global_set_log_level
341#define fn_gnutls_global_init gnutls_global_init 328# define gnutls_handshake fn_gnutls_handshake
342#ifdef HAVE_GNUTLS3 329# define gnutls_init fn_gnutls_init
343#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
344#endif 369#endif
345#define fn_gnutls_global_set_log_function gnutls_global_set_log_function
346#define fn_gnutls_global_set_log_level gnutls_global_set_log_level
347#define fn_gnutls_global_set_mem_functions gnutls_global_set_mem_functions
348#define fn_gnutls_handshake gnutls_handshake
349#define fn_gnutls_init gnutls_init
350#define fn_gnutls_kx_get gnutls_kx_get
351#define fn_gnutls_kx_get_name gnutls_kx_get_name
352#define fn_gnutls_mac_get gnutls_mac_get
353#define fn_gnutls_mac_get_name gnutls_mac_get_name
354#define fn_gnutls_pk_algorithm_get_name gnutls_pk_algorithm_get_name
355#define fn_gnutls_pk_bits_to_sec_param gnutls_pk_bits_to_sec_param
356#define fn_gnutls_priority_set_direct gnutls_priority_set_direct
357#define fn_gnutls_protocol_get_name gnutls_protocol_get_name
358#define fn_gnutls_protocol_get_version gnutls_protocol_get_version
359#define fn_gnutls_record_check_pending gnutls_record_check_pending
360#define fn_gnutls_record_recv gnutls_record_recv
361#define fn_gnutls_record_send gnutls_record_send
362#define fn_gnutls_sec_param_get_name gnutls_sec_param_get_name
363#define fn_gnutls_server_name_set gnutls_server_name_set
364#define fn_gnutls_sign_get_name gnutls_sign_get_name
365#define fn_gnutls_strerror gnutls_strerror
366#define fn_gnutls_transport_set_ptr2 gnutls_transport_set_ptr2
367#define fn_gnutls_x509_crt_check_hostname gnutls_x509_crt_check_hostname
368#define fn_gnutls_x509_crt_deinit gnutls_x509_crt_deinit
369#define fn_gnutls_x509_crt_get_activation_time gnutls_x509_crt_get_activation_time
370#define fn_gnutls_x509_crt_get_dn gnutls_x509_crt_get_dn
371#define fn_gnutls_x509_crt_get_expiration_time gnutls_x509_crt_get_expiration_time
372#define fn_gnutls_x509_crt_get_fingerprint gnutls_x509_crt_get_fingerprint
373#define fn_gnutls_x509_crt_get_issuer_dn gnutls_x509_crt_get_issuer_dn
374#define fn_gnutls_x509_crt_get_issuer_unique_id gnutls_x509_crt_get_issuer_unique_id
375#define fn_gnutls_x509_crt_get_key_id gnutls_x509_crt_get_key_id
376#define fn_gnutls_x509_crt_get_pk_algorithm gnutls_x509_crt_get_pk_algorithm
377#define fn_gnutls_x509_crt_get_serial gnutls_x509_crt_get_serial
378#define fn_gnutls_x509_crt_get_signature_algorithm gnutls_x509_crt_get_signature_algorithm
379#define fn_gnutls_x509_crt_get_subject_unique_id gnutls_x509_crt_get_subject_unique_id
380#define fn_gnutls_x509_crt_get_version gnutls_x509_crt_get_version
381#define fn_gnutls_x509_crt_import gnutls_x509_crt_import
382#define fn_gnutls_x509_crt_init gnutls_x509_crt_init
383
384#endif /* !WINDOWSNT */
385 370
386 371
372/* Report memory exhaustion if ERR is an out-of-memory indication. */
373static void
374check_memory_full (int err)
375{
376 /* When GnuTLS exhausts memory, it doesn't say how much memory it
377 asked for, so tell the Emacs allocator that GnuTLS asked for no
378 bytes. This isn't accurate, but it's good enough. */
379 if (err == GNUTLS_E_MEMORY_ERROR)
380 memory_full (0);
381}
382
387#ifdef HAVE_GNUTLS3 383#ifdef HAVE_GNUTLS3
388/* Log a simple audit message. */ 384/* Log a simple audit message. */
389static void 385static void
@@ -432,11 +428,11 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
432 /* On W32 we cannot transfer socket handles between different runtime 428 /* On W32 we cannot transfer socket handles between different runtime
433 libraries, so we tell GnuTLS to use our special push/pull 429 libraries, so we tell GnuTLS to use our special push/pull
434 functions. */ 430 functions. */
435 fn_gnutls_transport_set_ptr2 (state, 431 gnutls_transport_set_ptr2 (state,
436 (gnutls_transport_ptr_t) proc, 432 (gnutls_transport_ptr_t) proc,
437 (gnutls_transport_ptr_t) proc); 433 (gnutls_transport_ptr_t) proc);
438 fn_gnutls_transport_set_push_function (state, &emacs_gnutls_push); 434 gnutls_transport_set_push_function (state, &emacs_gnutls_push);
439 fn_gnutls_transport_set_pull_function (state, &emacs_gnutls_pull); 435 gnutls_transport_set_pull_function (state, &emacs_gnutls_pull);
440 436
441 /* For non blocking sockets or other custom made pull/push 437 /* For non blocking sockets or other custom made pull/push
442 functions the gnutls_transport_set_lowat must be called, with 438 functions the gnutls_transport_set_lowat must be called, with
@@ -449,15 +445,15 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
449 zero by default in version 2.11.1, and the function 445 zero by default in version 2.11.1, and the function
450 gnutls_transport_set_lowat was removed from the library in 446 gnutls_transport_set_lowat was removed from the library in
451 version 2.99.0. */ 447 version 2.99.0. */
452 if (!fn_gnutls_check_version ("2.11.1")) 448 if (!gnutls_check_version ("2.11.1"))
453 fn_gnutls_transport_set_lowat (state, 0); 449 gnutls_transport_set_lowat (state, 0);
454#else 450#else
455 /* This is how GnuTLS takes sockets: as file descriptors passed 451 /* This is how GnuTLS takes sockets: as file descriptors passed
456 in. For an Emacs process socket, infd and outfd are the 452 in. For an Emacs process socket, infd and outfd are the
457 same but we use this two-argument version for clarity. */ 453 same but we use this two-argument version for clarity. */
458 fn_gnutls_transport_set_ptr2 (state, 454 gnutls_transport_set_ptr2 (state,
459 (void *) (intptr_t) proc->infd, 455 (void *) (intptr_t) proc->infd,
460 (void *) (intptr_t) proc->outfd); 456 (void *) (intptr_t) proc->outfd);
461#endif 457#endif
462 458
463 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; 459 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
@@ -465,11 +461,11 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
465 461
466 do 462 do
467 { 463 {
468 ret = fn_gnutls_handshake (state); 464 ret = gnutls_handshake (state);
469 emacs_gnutls_handle_error (state, ret); 465 emacs_gnutls_handle_error (state, ret);
470 QUIT; 466 QUIT;
471 } 467 }
472 while (ret < 0 && fn_gnutls_error_is_fatal (ret) == 0); 468 while (ret < 0 && gnutls_error_is_fatal (ret) == 0);
473 469
474 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED; 470 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
475 471
@@ -480,7 +476,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
480 } 476 }
481 else 477 else
482 { 478 {
483 fn_gnutls_alert_send_appropriate (state, ret); 479 check_memory_full (gnutls_alert_send_appropriate (state, ret));
484 } 480 }
485 return ret; 481 return ret;
486} 482}
@@ -488,14 +484,14 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
488ptrdiff_t 484ptrdiff_t
489emacs_gnutls_record_check_pending (gnutls_session_t state) 485emacs_gnutls_record_check_pending (gnutls_session_t state)
490{ 486{
491 return fn_gnutls_record_check_pending (state); 487 return gnutls_record_check_pending (state);
492} 488}
493 489
494#ifdef WINDOWSNT 490#ifdef WINDOWSNT
495void 491void
496emacs_gnutls_transport_set_errno (gnutls_session_t state, int err) 492emacs_gnutls_transport_set_errno (gnutls_session_t state, int err)
497{ 493{
498 fn_gnutls_transport_set_errno (state, err); 494 gnutls_transport_set_errno (state, err);
499} 495}
500#endif 496#endif
501 497
@@ -516,7 +512,7 @@ emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte)
516 512
517 while (nbyte > 0) 513 while (nbyte > 0)
518 { 514 {
519 rtnval = fn_gnutls_record_send (state, buf, nbyte); 515 rtnval = gnutls_record_send (state, buf, nbyte);
520 516
521 if (rtnval < 0) 517 if (rtnval < 0)
522 { 518 {
@@ -568,7 +564,7 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
568 proc->gnutls_handshakes_tried = 0; 564 proc->gnutls_handshakes_tried = 0;
569 return 0; 565 return 0;
570 } 566 }
571 rtnval = fn_gnutls_record_recv (state, buf, nbyte); 567 rtnval = gnutls_record_recv (state, buf, nbyte);
572 if (rtnval >= 0) 568 if (rtnval >= 0)
573 return rtnval; 569 return rtnval;
574 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH) 570 else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
@@ -597,15 +593,17 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
597 if (err >= 0) 593 if (err >= 0)
598 return 1; 594 return 1;
599 595
596 check_memory_full (err);
597
600 max_log_level = global_gnutls_log_level; 598 max_log_level = global_gnutls_log_level;
601 599
602 /* TODO: use gnutls-error-fatalp and gnutls-error-string. */ 600 /* TODO: use gnutls-error-fatalp and gnutls-error-string. */
603 601
604 str = fn_gnutls_strerror (err); 602 str = gnutls_strerror (err);
605 if (!str) 603 if (!str)
606 str = "unknown"; 604 str = "unknown";
607 605
608 if (fn_gnutls_error_is_fatal (err)) 606 if (gnutls_error_is_fatal (err))
609 { 607 {
610 ret = 0; 608 ret = 0;
611 GNUTLS_LOG2 (1, max_log_level, "fatal error:", str); 609 GNUTLS_LOG2 (1, max_log_level, "fatal error:", str);
@@ -632,9 +630,9 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
632 if (err == GNUTLS_E_WARNING_ALERT_RECEIVED 630 if (err == GNUTLS_E_WARNING_ALERT_RECEIVED
633 || err == GNUTLS_E_FATAL_ALERT_RECEIVED) 631 || err == GNUTLS_E_FATAL_ALERT_RECEIVED)
634 { 632 {
635 int alert = fn_gnutls_alert_get (session); 633 int alert = gnutls_alert_get (session);
636 int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1; 634 int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1;
637 str = fn_gnutls_alert_get_name (alert); 635 str = gnutls_alert_get_name (alert);
638 if (!str) 636 if (!str)
639 str = "unknown"; 637 str = "unknown";
640 638
@@ -662,6 +660,7 @@ gnutls_make_error (int err)
662 return Qgnutls_e_invalid_session; 660 return Qgnutls_e_invalid_session;
663 } 661 }
664 662
663 check_memory_full (err);
665 return make_number (err); 664 return make_number (err);
666} 665}
667 666
@@ -680,20 +679,20 @@ emacs_gnutls_deinit (Lisp_Object proc)
680 if (XPROCESS (proc)->gnutls_x509_cred) 679 if (XPROCESS (proc)->gnutls_x509_cred)
681 { 680 {
682 GNUTLS_LOG (2, log_level, "Deallocating x509 credentials"); 681 GNUTLS_LOG (2, log_level, "Deallocating x509 credentials");
683 fn_gnutls_certificate_free_credentials (XPROCESS (proc)->gnutls_x509_cred); 682 gnutls_certificate_free_credentials (XPROCESS (proc)->gnutls_x509_cred);
684 XPROCESS (proc)->gnutls_x509_cred = NULL; 683 XPROCESS (proc)->gnutls_x509_cred = NULL;
685 } 684 }
686 685
687 if (XPROCESS (proc)->gnutls_anon_cred) 686 if (XPROCESS (proc)->gnutls_anon_cred)
688 { 687 {
689 GNUTLS_LOG (2, log_level, "Deallocating anon credentials"); 688 GNUTLS_LOG (2, log_level, "Deallocating anon credentials");
690 fn_gnutls_anon_free_client_credentials (XPROCESS (proc)->gnutls_anon_cred); 689 gnutls_anon_free_client_credentials (XPROCESS (proc)->gnutls_anon_cred);
691 XPROCESS (proc)->gnutls_anon_cred = NULL; 690 XPROCESS (proc)->gnutls_anon_cred = NULL;
692 } 691 }
693 692
694 if (XPROCESS (proc)->gnutls_state) 693 if (XPROCESS (proc)->gnutls_state)
695 { 694 {
696 fn_gnutls_deinit (XPROCESS (proc)->gnutls_state); 695 gnutls_deinit (XPROCESS (proc)->gnutls_state);
697 XPROCESS (proc)->gnutls_state = NULL; 696 XPROCESS (proc)->gnutls_state = NULL;
698 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) 697 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
699 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1; 698 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1;
@@ -750,7 +749,7 @@ Usage: (gnutls-error-fatalp ERROR) */)
750 if (! TYPE_RANGED_INTEGERP (int, err)) 749 if (! TYPE_RANGED_INTEGERP (int, err))
751 error ("Not an error symbol or code"); 750 error ("Not an error symbol or code");
752 751
753 if (0 == fn_gnutls_error_is_fatal (XINT (err))) 752 if (0 == gnutls_error_is_fatal (XINT (err)))
754 return Qnil; 753 return Qnil;
755 754
756 return Qt; 755 return Qt;
@@ -782,7 +781,7 @@ usage: (gnutls-error-string ERROR) */)
782 if (! TYPE_RANGED_INTEGERP (int, err)) 781 if (! TYPE_RANGED_INTEGERP (int, err))
783 return build_string ("Not an error symbol or code"); 782 return build_string ("Not an error symbol or code");
784 783
785 return build_string (fn_gnutls_strerror (XINT (err))); 784 return build_string (gnutls_strerror (XINT (err)));
786} 785}
787 786
788DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0, 787DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0,
@@ -821,7 +820,8 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
821 820
822 /* Version. */ 821 /* Version. */
823 { 822 {
824 int version = fn_gnutls_x509_crt_get_version (cert); 823 int version = gnutls_x509_crt_get_version (cert);
824 check_memory_full (version);
825 if (version >= GNUTLS_E_SUCCESS) 825 if (version >= GNUTLS_E_SUCCESS)
826 res = nconc2 (res, list2 (intern (":version"), 826 res = nconc2 (res, list2 (intern (":version"),
827 make_number (version))); 827 make_number (version)));
@@ -829,11 +829,13 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
829 829
830 /* Serial. */ 830 /* Serial. */
831 buf_size = 0; 831 buf_size = 0;
832 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &buf_size); 832 err = gnutls_x509_crt_get_serial (cert, NULL, &buf_size);
833 check_memory_full (err);
833 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 834 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
834 { 835 {
835 void *serial = xmalloc (buf_size); 836 void *serial = xmalloc (buf_size);
836 err = fn_gnutls_x509_crt_get_serial (cert, serial, &buf_size); 837 err = gnutls_x509_crt_get_serial (cert, serial, &buf_size);
838 check_memory_full (err);
837 if (err >= GNUTLS_E_SUCCESS) 839 if (err >= GNUTLS_E_SUCCESS)
838 res = nconc2 (res, list2 (intern (":serial-number"), 840 res = nconc2 (res, list2 (intern (":serial-number"),
839 gnutls_hex_string (serial, buf_size, ""))); 841 gnutls_hex_string (serial, buf_size, "")));
@@ -842,11 +844,13 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
842 844
843 /* Issuer. */ 845 /* Issuer. */
844 buf_size = 0; 846 buf_size = 0;
845 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &buf_size); 847 err = gnutls_x509_crt_get_issuer_dn (cert, NULL, &buf_size);
848 check_memory_full (err);
846 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 849 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
847 { 850 {
848 char *dn = xmalloc (buf_size); 851 char *dn = xmalloc (buf_size);
849 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &buf_size); 852 err = gnutls_x509_crt_get_issuer_dn (cert, dn, &buf_size);
853 check_memory_full (err);
850 if (err >= GNUTLS_E_SUCCESS) 854 if (err >= GNUTLS_E_SUCCESS)
851 res = nconc2 (res, list2 (intern (":issuer"), 855 res = nconc2 (res, list2 (intern (":issuer"),
852 make_string (dn, buf_size))); 856 make_string (dn, buf_size)));
@@ -859,23 +863,25 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
859 that might add 1 to the year length. */ 863 that might add 1 to the year length. */
860 char buf[INT_STRLEN_BOUND (int) + 1 + sizeof "-12-31"]; 864 char buf[INT_STRLEN_BOUND (int) + 1 + sizeof "-12-31"];
861 struct tm t; 865 struct tm t;
862 time_t tim = fn_gnutls_x509_crt_get_activation_time (cert); 866 time_t tim = gnutls_x509_crt_get_activation_time (cert);
863 867
864 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))
865 res = nconc2 (res, list2 (intern (":valid-from"), build_string (buf))); 869 res = nconc2 (res, list2 (intern (":valid-from"), build_string (buf)));
866 870
867 tim = fn_gnutls_x509_crt_get_expiration_time (cert); 871 tim = gnutls_x509_crt_get_expiration_time (cert);
868 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))
869 res = nconc2 (res, list2 (intern (":valid-to"), build_string (buf))); 873 res = nconc2 (res, list2 (intern (":valid-to"), build_string (buf)));
870 } 874 }
871 875
872 /* Subject. */ 876 /* Subject. */
873 buf_size = 0; 877 buf_size = 0;
874 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &buf_size); 878 err = gnutls_x509_crt_get_dn (cert, NULL, &buf_size);
879 check_memory_full (err);
875 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 880 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
876 { 881 {
877 char *dn = xmalloc (buf_size); 882 char *dn = xmalloc (buf_size);
878 err = fn_gnutls_x509_crt_get_dn (cert, dn, &buf_size); 883 err = gnutls_x509_crt_get_dn (cert, dn, &buf_size);
884 check_memory_full (err);
879 if (err >= GNUTLS_E_SUCCESS) 885 if (err >= GNUTLS_E_SUCCESS)
880 res = nconc2 (res, list2 (intern (":subject"), 886 res = nconc2 (res, list2 (intern (":subject"),
881 make_string (dn, buf_size))); 887 make_string (dn, buf_size)));
@@ -888,16 +894,17 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
888 { 894 {
889 unsigned int bits; 895 unsigned int bits;
890 896
891 err = fn_gnutls_x509_crt_get_pk_algorithm (cert, &bits); 897 err = gnutls_x509_crt_get_pk_algorithm (cert, &bits);
898 check_memory_full (err);
892 if (err >= GNUTLS_E_SUCCESS) 899 if (err >= GNUTLS_E_SUCCESS)
893 { 900 {
894 const char *name = fn_gnutls_pk_algorithm_get_name (err); 901 const char *name = gnutls_pk_algorithm_get_name (err);
895 if (name) 902 if (name)
896 res = nconc2 (res, list2 (intern (":public-key-algorithm"), 903 res = nconc2 (res, list2 (intern (":public-key-algorithm"),
897 build_string (name))); 904 build_string (name)));
898 905
899 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
900 (err, bits)); 907 (err, bits));
901 res = nconc2 (res, list2 (intern (":certificate-security-level"), 908 res = nconc2 (res, list2 (intern (":certificate-security-level"),
902 build_string (name))); 909 build_string (name)));
903 } 910 }
@@ -905,11 +912,13 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
905 912
906 /* Unique IDs. */ 913 /* Unique IDs. */
907 buf_size = 0; 914 buf_size = 0;
908 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);
916 check_memory_full (err);
909 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 917 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
910 { 918 {
911 char *buf = xmalloc (buf_size); 919 char *buf = xmalloc (buf_size);
912 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);
921 check_memory_full (err);
913 if (err >= GNUTLS_E_SUCCESS) 922 if (err >= GNUTLS_E_SUCCESS)
914 res = nconc2 (res, list2 (intern (":issuer-unique-id"), 923 res = nconc2 (res, list2 (intern (":issuer-unique-id"),
915 make_string (buf, buf_size))); 924 make_string (buf, buf_size)));
@@ -917,11 +926,13 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
917 } 926 }
918 927
919 buf_size = 0; 928 buf_size = 0;
920 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);
930 check_memory_full (err);
921 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 931 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
922 { 932 {
923 char *buf = xmalloc (buf_size); 933 char *buf = xmalloc (buf_size);
924 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);
935 check_memory_full (err);
925 if (err >= GNUTLS_E_SUCCESS) 936 if (err >= GNUTLS_E_SUCCESS)
926 res = nconc2 (res, list2 (intern (":subject-unique-id"), 937 res = nconc2 (res, list2 (intern (":subject-unique-id"),
927 make_string (buf, buf_size))); 938 make_string (buf, buf_size)));
@@ -930,10 +941,11 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
930#endif 941#endif
931 942
932 /* Signature. */ 943 /* Signature. */
933 err = fn_gnutls_x509_crt_get_signature_algorithm (cert); 944 err = gnutls_x509_crt_get_signature_algorithm (cert);
945 check_memory_full (err);
934 if (err >= GNUTLS_E_SUCCESS) 946 if (err >= GNUTLS_E_SUCCESS)
935 { 947 {
936 const char *name = fn_gnutls_sign_get_name (err); 948 const char *name = gnutls_sign_get_name (err);
937 if (name) 949 if (name)
938 res = nconc2 (res, list2 (intern (":signature-algorithm"), 950 res = nconc2 (res, list2 (intern (":signature-algorithm"),
939 build_string (name))); 951 build_string (name)));
@@ -941,11 +953,13 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
941 953
942 /* Public key ID. */ 954 /* Public key ID. */
943 buf_size = 0; 955 buf_size = 0;
944 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);
957 check_memory_full (err);
945 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 958 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
946 { 959 {
947 void *buf = xmalloc (buf_size); 960 void *buf = xmalloc (buf_size);
948 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);
962 check_memory_full (err);
949 if (err >= GNUTLS_E_SUCCESS) 963 if (err >= GNUTLS_E_SUCCESS)
950 res = nconc2 (res, list2 (intern (":public-key-id"), 964 res = nconc2 (res, list2 (intern (":public-key-id"),
951 gnutls_hex_string (buf, buf_size, "sha1:"))); 965 gnutls_hex_string (buf, buf_size, "sha1:")));
@@ -954,13 +968,15 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
954 968
955 /* Certificate fingerprint. */ 969 /* Certificate fingerprint. */
956 buf_size = 0; 970 buf_size = 0;
957 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 971 err = gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
958 NULL, &buf_size); 972 NULL, &buf_size);
973 check_memory_full (err);
959 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 974 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
960 { 975 {
961 void *buf = xmalloc (buf_size); 976 void *buf = xmalloc (buf_size);
962 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 977 err = gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
963 buf, &buf_size); 978 buf, &buf_size);
979 check_memory_full (err);
964 if (err >= GNUTLS_E_SUCCESS) 980 if (err >= GNUTLS_E_SUCCESS)
965 res = nconc2 (res, list2 (intern (":certificate-id"), 981 res = nconc2 (res, list2 (intern (":certificate-id"),
966 gnutls_hex_string (buf, buf_size, "sha1:"))); 982 gnutls_hex_string (buf, buf_size, "sha1:")));
@@ -1061,7 +1077,8 @@ The return value is a property list with top-level keys :warnings and
1061 1077
1062 /* Diffie-Hellman prime bits. */ 1078 /* Diffie-Hellman prime bits. */
1063 { 1079 {
1064 int bits = fn_gnutls_dh_get_prime_bits (state); 1080 int bits = gnutls_dh_get_prime_bits (state);
1081 check_memory_full (bits);
1065 if (bits > 0) 1082 if (bits > 0)
1066 result = nconc2 (result, list2 (intern (":diffie-hellman-prime-bits"), 1083 result = nconc2 (result, list2 (intern (":diffie-hellman-prime-bits"),
1067 make_number (bits))); 1084 make_number (bits)));
@@ -1070,26 +1087,26 @@ The return value is a property list with top-level keys :warnings and
1070 /* Key exchange. */ 1087 /* Key exchange. */
1071 result = nconc2 1088 result = nconc2
1072 (result, list2 (intern (":key-exchange"), 1089 (result, list2 (intern (":key-exchange"),
1073 build_string (fn_gnutls_kx_get_name 1090 build_string (gnutls_kx_get_name
1074 (fn_gnutls_kx_get (state))))); 1091 (gnutls_kx_get (state)))));
1075 1092
1076 /* Protocol name. */ 1093 /* Protocol name. */
1077 result = nconc2 1094 result = nconc2
1078 (result, list2 (intern (":protocol"), 1095 (result, list2 (intern (":protocol"),
1079 build_string (fn_gnutls_protocol_get_name 1096 build_string (gnutls_protocol_get_name
1080 (fn_gnutls_protocol_get_version (state))))); 1097 (gnutls_protocol_get_version (state)))));
1081 1098
1082 /* Cipher name. */ 1099 /* Cipher name. */
1083 result = nconc2 1100 result = nconc2
1084 (result, list2 (intern (":cipher"), 1101 (result, list2 (intern (":cipher"),
1085 build_string (fn_gnutls_cipher_get_name 1102 build_string (gnutls_cipher_get_name
1086 (fn_gnutls_cipher_get (state))))); 1103 (gnutls_cipher_get (state)))));
1087 1104
1088 /* MAC name. */ 1105 /* MAC name. */
1089 result = nconc2 1106 result = nconc2
1090 (result, list2 (intern (":mac"), 1107 (result, list2 (intern (":mac"),
1091 build_string (fn_gnutls_mac_get_name 1108 build_string (gnutls_mac_get_name
1092 (fn_gnutls_mac_get (state))))); 1109 (gnutls_mac_get (state)))));
1093 1110
1094 1111
1095 return result; 1112 return result;
@@ -1104,11 +1121,8 @@ emacs_gnutls_global_init (void)
1104 int ret = GNUTLS_E_SUCCESS; 1121 int ret = GNUTLS_E_SUCCESS;
1105 1122
1106 if (!gnutls_global_initialized) 1123 if (!gnutls_global_initialized)
1107 { 1124 ret = gnutls_global_init ();
1108 fn_gnutls_global_set_mem_functions (xmalloc, xmalloc, NULL, 1125
1109 xrealloc, xfree);
1110 ret = fn_gnutls_global_init ();
1111 }
1112 gnutls_global_initialized = 1; 1126 gnutls_global_initialized = 1;
1113 1127
1114 return gnutls_make_error (ret); 1128 return gnutls_make_error (ret);
@@ -1257,11 +1271,11 @@ one trustfile (usually a CA bundle). */)
1257 1271
1258 if (TYPE_RANGED_INTEGERP (int, loglevel)) 1272 if (TYPE_RANGED_INTEGERP (int, loglevel))
1259 { 1273 {
1260 fn_gnutls_global_set_log_function (gnutls_log_function); 1274 gnutls_global_set_log_function (gnutls_log_function);
1261#ifdef HAVE_GNUTLS3 1275#ifdef HAVE_GNUTLS3
1262 fn_gnutls_global_set_audit_log_function (gnutls_audit_log_function); 1276 gnutls_global_set_audit_log_function (gnutls_audit_log_function);
1263#endif 1277#endif
1264 fn_gnutls_global_set_log_level (XINT (loglevel)); 1278 gnutls_global_set_log_level (XINT (loglevel));
1265 max_log_level = XINT (loglevel); 1279 max_log_level = XINT (loglevel);
1266 XPROCESS (proc)->gnutls_log_level = max_log_level; 1280 XPROCESS (proc)->gnutls_log_level = max_log_level;
1267 } 1281 }
@@ -1291,7 +1305,7 @@ one trustfile (usually a CA bundle). */)
1291 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;
1292 1306
1293 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); 1307 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials");
1294 fn_gnutls_certificate_allocate_credentials (&x509_cred); 1308 check_memory_full (gnutls_certificate_allocate_credentials (&x509_cred));
1295 XPROCESS (proc)->gnutls_x509_cred = x509_cred; 1309 XPROCESS (proc)->gnutls_x509_cred = x509_cred;
1296 1310
1297 verify_flags = Fplist_get (proplist, QCgnutls_bootprop_verify_flags); 1311 verify_flags = Fplist_get (proplist, QCgnutls_bootprop_verify_flags);
@@ -1305,12 +1319,12 @@ one trustfile (usually a CA bundle). */)
1305 else 1319 else
1306 GNUTLS_LOG (2, max_log_level, "ignoring invalid verify-flags"); 1320 GNUTLS_LOG (2, max_log_level, "ignoring invalid verify-flags");
1307 1321
1308 fn_gnutls_certificate_set_verify_flags (x509_cred, gnutls_verify_flags); 1322 gnutls_certificate_set_verify_flags (x509_cred, gnutls_verify_flags);
1309 } 1323 }
1310 else /* Qgnutls_anon: */ 1324 else /* Qgnutls_anon: */
1311 { 1325 {
1312 GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); 1326 GNUTLS_LOG (2, max_log_level, "allocating anon credentials");
1313 fn_gnutls_anon_allocate_client_credentials (&anon_cred); 1327 check_memory_full (gnutls_anon_allocate_client_credentials (&anon_cred));
1314 XPROCESS (proc)->gnutls_anon_cred = anon_cred; 1328 XPROCESS (proc)->gnutls_anon_cred = anon_cred;
1315 } 1329 }
1316 1330
@@ -1324,10 +1338,13 @@ one trustfile (usually a CA bundle). */)
1324 1338
1325#if GNUTLS_VERSION_MAJOR + \ 1339#if GNUTLS_VERSION_MAJOR + \
1326 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3 1340 (GNUTLS_VERSION_MINOR > 0 || GNUTLS_VERSION_PATCH >= 20) > 3
1327 ret = fn_gnutls_certificate_set_x509_system_trust (x509_cred); 1341 ret = gnutls_certificate_set_x509_system_trust (x509_cred);
1328 if (ret < GNUTLS_E_SUCCESS) 1342 if (ret < GNUTLS_E_SUCCESS)
1329 GNUTLS_LOG2i (4, max_log_level, 1343 {
1330 "setting system trust failed with code ", ret); 1344 check_memory_full (ret);
1345 GNUTLS_LOG2i (4, max_log_level,
1346 "setting system trust failed with code ", ret);
1347 }
1331#endif 1348#endif
1332 1349
1333 for (tail = trustfiles; CONSP (tail); tail = XCDR (tail)) 1350 for (tail = trustfiles; CONSP (tail); tail = XCDR (tail))
@@ -1344,7 +1361,7 @@ one trustfile (usually a CA bundle). */)
1344 name using the current ANSI codepage. */ 1361 name using the current ANSI codepage. */
1345 trustfile = ansi_encode_filename (trustfile); 1362 trustfile = ansi_encode_filename (trustfile);
1346#endif 1363#endif
1347 ret = fn_gnutls_certificate_set_x509_trust_file 1364 ret = gnutls_certificate_set_x509_trust_file
1348 (x509_cred, 1365 (x509_cred,
1349 SSDATA (trustfile), 1366 SSDATA (trustfile),
1350 file_format); 1367 file_format);
@@ -1370,7 +1387,7 @@ one trustfile (usually a CA bundle). */)
1370#ifdef WINDOWSNT 1387#ifdef WINDOWSNT
1371 crlfile = ansi_encode_filename (crlfile); 1388 crlfile = ansi_encode_filename (crlfile);
1372#endif 1389#endif
1373 ret = fn_gnutls_certificate_set_x509_crl_file 1390 ret = gnutls_certificate_set_x509_crl_file
1374 (x509_cred, SSDATA (crlfile), file_format); 1391 (x509_cred, SSDATA (crlfile), file_format);
1375 1392
1376 if (ret < GNUTLS_E_SUCCESS) 1393 if (ret < GNUTLS_E_SUCCESS)
@@ -1399,7 +1416,7 @@ one trustfile (usually a CA bundle). */)
1399 keyfile = ansi_encode_filename (keyfile); 1416 keyfile = ansi_encode_filename (keyfile);
1400 certfile = ansi_encode_filename (certfile); 1417 certfile = ansi_encode_filename (certfile);
1401#endif 1418#endif
1402 ret = fn_gnutls_certificate_set_x509_key_file 1419 ret = gnutls_certificate_set_x509_key_file
1403 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format); 1420 (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format);
1404 1421
1405 if (ret < GNUTLS_E_SUCCESS) 1422 if (ret < GNUTLS_E_SUCCESS)
@@ -1421,7 +1438,7 @@ one trustfile (usually a CA bundle). */)
1421 /* Call gnutls_init here: */ 1438 /* Call gnutls_init here: */
1422 1439
1423 GNUTLS_LOG (1, max_log_level, "gnutls_init"); 1440 GNUTLS_LOG (1, max_log_level, "gnutls_init");
1424 ret = fn_gnutls_init (&state, GNUTLS_CLIENT); 1441 ret = gnutls_init (&state, GNUTLS_CLIENT);
1425 XPROCESS (proc)->gnutls_state = state; 1442 XPROCESS (proc)->gnutls_state = state;
1426 if (ret < GNUTLS_E_SUCCESS) 1443 if (ret < GNUTLS_E_SUCCESS)
1427 return gnutls_make_error (ret); 1444 return gnutls_make_error (ret);
@@ -1440,27 +1457,25 @@ one trustfile (usually a CA bundle). */)
1440 } 1457 }
1441 1458
1442 GNUTLS_LOG (1, max_log_level, "setting the priority string"); 1459 GNUTLS_LOG (1, max_log_level, "setting the priority string");
1443 ret = fn_gnutls_priority_set_direct (state, 1460 ret = gnutls_priority_set_direct (state, priority_string_ptr, NULL);
1444 priority_string_ptr,
1445 NULL);
1446 if (ret < GNUTLS_E_SUCCESS) 1461 if (ret < GNUTLS_E_SUCCESS)
1447 return gnutls_make_error (ret); 1462 return gnutls_make_error (ret);
1448 1463
1449 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY; 1464 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY;
1450 1465
1451 if (INTEGERP (prime_bits)) 1466 if (INTEGERP (prime_bits))
1452 fn_gnutls_dh_set_prime_bits (state, XUINT (prime_bits)); 1467 gnutls_dh_set_prime_bits (state, XUINT (prime_bits));
1453 1468
1454 ret = EQ (type, Qgnutls_x509pki) 1469 ret = EQ (type, Qgnutls_x509pki)
1455 ? fn_gnutls_credentials_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred) 1470 ? gnutls_credentials_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred)
1456 : fn_gnutls_credentials_set (state, GNUTLS_CRD_ANON, anon_cred); 1471 : gnutls_credentials_set (state, GNUTLS_CRD_ANON, anon_cred);
1457 if (ret < GNUTLS_E_SUCCESS) 1472 if (ret < GNUTLS_E_SUCCESS)
1458 return gnutls_make_error (ret); 1473 return gnutls_make_error (ret);
1459 1474
1460 if (!gnutls_ip_address_p (c_hostname)) 1475 if (!gnutls_ip_address_p (c_hostname))
1461 { 1476 {
1462 ret = fn_gnutls_server_name_set (state, GNUTLS_NAME_DNS, c_hostname, 1477 ret = gnutls_server_name_set (state, GNUTLS_NAME_DNS, c_hostname,
1463 strlen (c_hostname)); 1478 strlen (c_hostname));
1464 if (ret < GNUTLS_E_SUCCESS) 1479 if (ret < GNUTLS_E_SUCCESS)
1465 return gnutls_make_error (ret); 1480 return gnutls_make_error (ret);
1466 } 1481 }
@@ -1476,7 +1491,7 @@ one trustfile (usually a CA bundle). */)
1476 check of the certificate's hostname with 1491 check of the certificate's hostname with
1477 gnutls_x509_crt_check_hostname against :hostname. */ 1492 gnutls_x509_crt_check_hostname against :hostname. */
1478 1493
1479 ret = fn_gnutls_certificate_verify_peers2 (state, &peer_verification); 1494 ret = gnutls_certificate_verify_peers2 (state, &peer_verification);
1480 if (ret < GNUTLS_E_SUCCESS) 1495 if (ret < GNUTLS_E_SUCCESS)
1481 return gnutls_make_error (ret); 1496 return gnutls_make_error (ret);
1482 1497
@@ -1514,47 +1529,50 @@ one trustfile (usually a CA bundle). */)
1514 /* 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
1515 OpenPGP keys. From now on X.509 certificates are assumed. This 1530 OpenPGP keys. From now on X.509 certificates are assumed. This
1516 can be easily extended to work with openpgp keys as well. */ 1531 can be easily extended to work with openpgp keys as well. */
1517 if (fn_gnutls_certificate_type_get (state) == GNUTLS_CRT_X509) 1532 if (gnutls_certificate_type_get (state) == GNUTLS_CRT_X509)
1518 { 1533 {
1519 gnutls_x509_crt_t gnutls_verify_cert; 1534 gnutls_x509_crt_t gnutls_verify_cert;
1520 const gnutls_datum_t *gnutls_verify_cert_list; 1535 const gnutls_datum_t *gnutls_verify_cert_list;
1521 unsigned int gnutls_verify_cert_list_size; 1536 unsigned int gnutls_verify_cert_list_size;
1522 1537
1523 ret = fn_gnutls_x509_crt_init (&gnutls_verify_cert); 1538 ret = gnutls_x509_crt_init (&gnutls_verify_cert);
1524 if (ret < GNUTLS_E_SUCCESS) 1539 if (ret < GNUTLS_E_SUCCESS)
1525 return gnutls_make_error (ret); 1540 return gnutls_make_error (ret);
1526 1541
1527 gnutls_verify_cert_list = 1542 gnutls_verify_cert_list =
1528 fn_gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size); 1543 gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size);
1529 1544
1530 if (gnutls_verify_cert_list == NULL) 1545 if (gnutls_verify_cert_list == NULL)
1531 { 1546 {
1532 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1547 gnutls_x509_crt_deinit (gnutls_verify_cert);
1533 emacs_gnutls_deinit (proc); 1548 emacs_gnutls_deinit (proc);
1534 error ("No x509 certificate was found\n"); 1549 error ("No x509 certificate was found\n");
1535 } 1550 }
1536 1551
1537 /* We only check the first certificate in the given chain. */ 1552 /* We only check the first certificate in the given chain. */
1538 ret = fn_gnutls_x509_crt_import (gnutls_verify_cert, 1553 ret = gnutls_x509_crt_import (gnutls_verify_cert,
1539 &gnutls_verify_cert_list[0], 1554 &gnutls_verify_cert_list[0],
1540 GNUTLS_X509_FMT_DER); 1555 GNUTLS_X509_FMT_DER);
1541 1556
1542 if (ret < GNUTLS_E_SUCCESS) 1557 if (ret < GNUTLS_E_SUCCESS)
1543 { 1558 {
1544 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1559 gnutls_x509_crt_deinit (gnutls_verify_cert);
1545 return gnutls_make_error (ret); 1560 return gnutls_make_error (ret);
1546 } 1561 }
1547 1562
1548 XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert; 1563 XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert;
1549 1564
1550 if (!fn_gnutls_x509_crt_check_hostname (gnutls_verify_cert, c_hostname)) 1565 int err = gnutls_x509_crt_check_hostname (gnutls_verify_cert,
1566 c_hostname);
1567 check_memory_full (err);
1568 if (!err)
1551 { 1569 {
1552 XPROCESS (proc)->gnutls_extra_peer_verification |= 1570 XPROCESS (proc)->gnutls_extra_peer_verification |=
1553 CERTIFICATE_NOT_MATCHING; 1571 CERTIFICATE_NOT_MATCHING;
1554 if (verify_error_all 1572 if (verify_error_all
1555 || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error))) 1573 || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error)))
1556 { 1574 {
1557 fn_gnutls_x509_crt_deinit (gnutls_verify_cert); 1575 gnutls_x509_crt_deinit (gnutls_verify_cert);
1558 emacs_gnutls_deinit (proc); 1576 emacs_gnutls_deinit (proc);
1559 error ("The x509 certificate does not match \"%s\"", c_hostname); 1577 error ("The x509 certificate does not match \"%s\"", c_hostname);
1560 } 1578 }
@@ -1595,10 +1613,9 @@ This function may also return `gnutls-e-again', or
1595 1613
1596 state = XPROCESS (proc)->gnutls_state; 1614 state = XPROCESS (proc)->gnutls_state;
1597 1615
1598 fn_gnutls_x509_crt_deinit (XPROCESS (proc)->gnutls_certificate); 1616 gnutls_x509_crt_deinit (XPROCESS (proc)->gnutls_certificate);
1599 1617
1600 ret = fn_gnutls_bye (state, 1618 ret = gnutls_bye (state, NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
1601 NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
1602 1619
1603 return gnutls_make_error (ret); 1620 return gnutls_make_error (ret);
1604} 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/nsimage.m b/src/nsimage.m
index 640dfcbc113..d5c06477f8b 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -351,15 +351,15 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
351 { 351 {
352 if ([rep respondsToSelector: @selector (getBitmapDataPlanes:)]) 352 if ([rep respondsToSelector: @selector (getBitmapDataPlanes:)])
353 { 353 {
354 NSBitmapImageRep *bmRep = (NSBitmapImageRep *) rep; 354 NSBitmapImageRep *bmr = (NSBitmapImageRep *) rep;
355 355
356 if ([bmRep numberOfPlanes] >= 3) 356 if ([bmr numberOfPlanes] >= 3)
357 [bmRep getBitmapDataPlanes: pixmapData]; 357 [bmr getBitmapDataPlanes: pixmapData];
358 358
359 /* The next two lines cause the DPI of the image to be ignored. 359 /* The next two lines cause the DPI of the image to be ignored.
360 This seems to be the behavior users expect. */ 360 This seems to be the behavior users expect. */
361 [self setScalesWhenResized: YES]; 361 [self setScalesWhenResized: YES];
362 [self setSize: NSMakeSize([bmRep pixelsWide], [bmRep pixelsHigh])]; 362 [self setSize: NSMakeSize([bmr pixelsWide], [bmr pixelsHigh])];
363 363
364 break; 364 break;
365 } 365 }
diff --git a/src/sysdep.c b/src/sysdep.c
index 24cc5cb0b40..7158f38dba2 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -110,6 +110,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
110#define _P_WAIT 0 110#define _P_WAIT 0
111int _cdecl _spawnlp (int, const char *, const char *, ...); 111int _cdecl _spawnlp (int, const char *, const char *, ...);
112int _cdecl _getpid (void); 112int _cdecl _getpid (void);
113/* The following is needed for O_CLOEXEC, F_SETFD, FD_CLOEXEC, and
114 several prototypes of functions called below. */
115#include <sys/socket.h>
113#endif 116#endif
114 117
115#include "syssignal.h" 118#include "syssignal.h"
@@ -1406,29 +1409,19 @@ setup_pty (int fd)
1406} 1409}
1407#endif /* HAVE_PTYS */ 1410#endif /* HAVE_PTYS */
1408 1411
1409#ifdef HAVE_SOCKETS
1410#include <sys/socket.h>
1411#include <netdb.h>
1412#endif /* HAVE_SOCKETS */
1413
1414#ifdef TRY_AGAIN
1415#ifndef HAVE_H_ERRNO
1416extern int h_errno;
1417#endif
1418#endif /* TRY_AGAIN */
1419
1420void 1412void
1421init_system_name (void) 1413init_system_name (void)
1422{ 1414{
1415 char *hostname_alloc = NULL;
1416 char *hostname;
1423#ifndef HAVE_GETHOSTNAME 1417#ifndef HAVE_GETHOSTNAME
1424 struct utsname uts; 1418 struct utsname uts;
1425 uname (&uts); 1419 uname (&uts);
1426 Vsystem_name = build_string (uts.nodename); 1420 hostname = uts.nodename;
1427#else /* HAVE_GETHOSTNAME */ 1421#else /* HAVE_GETHOSTNAME */
1428 char *hostname_alloc = NULL;
1429 char hostname_buf[256]; 1422 char hostname_buf[256];
1430 ptrdiff_t hostname_size = sizeof hostname_buf; 1423 ptrdiff_t hostname_size = sizeof hostname_buf;
1431 char *hostname = hostname_buf; 1424 hostname = hostname_buf;
1432 1425
1433 /* Try to get the host name; if the buffer is too short, try 1426 /* Try to get the host name; if the buffer is too short, try
1434 again. Apparently, the only indication gethostname gives of 1427 again. Apparently, the only indication gethostname gives of
@@ -1446,110 +1439,15 @@ init_system_name (void)
1446 hostname = hostname_alloc = xpalloc (hostname_alloc, &hostname_size, 1, 1439 hostname = hostname_alloc = xpalloc (hostname_alloc, &hostname_size, 1,
1447 min (PTRDIFF_MAX, SIZE_MAX), 1); 1440 min (PTRDIFF_MAX, SIZE_MAX), 1);
1448 } 1441 }
1449#ifdef HAVE_SOCKETS
1450 /* Turn the hostname into the official, fully-qualified hostname.
1451 Don't do this if we're going to dump; this can confuse system
1452 libraries on some machines and make the dumped emacs core dump. */
1453#ifndef CANNOT_DUMP
1454 if (initialized)
1455#endif /* not CANNOT_DUMP */
1456 if (! strchr (hostname, '.'))
1457 {
1458 int count;
1459#ifdef HAVE_GETADDRINFO
1460 struct addrinfo *res;
1461 struct addrinfo hints;
1462 int ret;
1463
1464 memset (&hints, 0, sizeof (hints));
1465 hints.ai_socktype = SOCK_STREAM;
1466 hints.ai_flags = AI_CANONNAME;
1467
1468 for (count = 0;; count++)
1469 {
1470 if ((ret = getaddrinfo (hostname, NULL, &hints, &res)) == 0
1471 || ret != EAI_AGAIN)
1472 break;
1473
1474 if (count >= 5)
1475 break;
1476 Fsleep_for (make_number (1), Qnil);
1477 }
1478
1479 if (ret == 0)
1480 {
1481 struct addrinfo *it = res;
1482 while (it)
1483 {
1484 char *fqdn = it->ai_canonname;
1485 if (fqdn && strchr (fqdn, '.')
1486 && strcmp (fqdn, "localhost.localdomain") != 0)
1487 break;
1488 it = it->ai_next;
1489 }
1490 if (it)
1491 {
1492 ptrdiff_t len = strlen (it->ai_canonname);
1493 if (hostname_size <= len)
1494 {
1495 hostname_size = len + 1;
1496 hostname = hostname_alloc = xrealloc (hostname_alloc,
1497 hostname_size);
1498 }
1499 strcpy (hostname, it->ai_canonname);
1500 }
1501 freeaddrinfo (res);
1502 }
1503#else /* !HAVE_GETADDRINFO */
1504 struct hostent *hp;
1505 for (count = 0;; count++)
1506 {
1507
1508#ifdef TRY_AGAIN
1509 h_errno = 0;
1510#endif
1511 hp = gethostbyname (hostname);
1512#ifdef TRY_AGAIN
1513 if (! (hp == 0 && h_errno == TRY_AGAIN))
1514#endif
1515
1516 break;
1517
1518 if (count >= 5)
1519 break;
1520 Fsleep_for (make_number (1), Qnil);
1521 }
1522
1523 if (hp)
1524 {
1525 char *fqdn = (char *) hp->h_name;
1526
1527 if (!strchr (fqdn, '.'))
1528 {
1529 /* We still don't have a fully qualified domain name.
1530 Try to find one in the list of alternate names */
1531 char **alias = hp->h_aliases;
1532 while (*alias
1533 && (!strchr (*alias, '.')
1534 || !strcmp (*alias, "localhost.localdomain")))
1535 alias++;
1536 if (*alias)
1537 fqdn = *alias;
1538 }
1539 hostname = fqdn;
1540 }
1541#endif /* !HAVE_GETADDRINFO */
1542 }
1543#endif /* HAVE_SOCKETS */
1544 Vsystem_name = build_string (hostname);
1545 xfree (hostname_alloc);
1546#endif /* HAVE_GETHOSTNAME */ 1442#endif /* HAVE_GETHOSTNAME */
1547 { 1443 char *p;
1548 char *p; 1444 for (p = hostname; *p; p++)
1549 for (p = SSDATA (Vsystem_name); *p; p++) 1445 if (*p == ' ' || *p == '\t')
1550 if (*p == ' ' || *p == '\t') 1446 *p = '-';
1551 *p = '-'; 1447 if (! (STRINGP (Vsystem_name) && SBYTES (Vsystem_name) == p - hostname
1552 } 1448 && strcmp (SSDATA (Vsystem_name), hostname) == 0))
1449 Vsystem_name = build_string (hostname);
1450 xfree (hostname_alloc);
1553} 1451}
1554 1452
1555sigset_t empty_mask; 1453sigset_t empty_mask;
diff --git a/src/term.c b/src/term.c
index 04f6e3318a0..bcb83e5891d 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1736,7 +1736,7 @@ produce_composite_glyph (struct it *it)
1736 { 1736 {
1737 struct composition *cmp = composition_table[it->cmp_it.id]; 1737 struct composition *cmp = composition_table[it->cmp_it.id];
1738 1738
1739 it->pixel_width = cmp->width; 1739 it->pixel_width = cmp->pixel_width;
1740 } 1740 }
1741 else 1741 else
1742 { 1742 {
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/xdisp.c b/src/xdisp.c
index 707418218f0..c87862d1b6d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -7372,27 +7372,15 @@ set_iterator_to_next (struct it *it, int reseat_p)
7372 else if (it->cmp_it.id >= 0) 7372 else if (it->cmp_it.id >= 0)
7373 { 7373 {
7374 /* We are currently getting glyphs from a composition. */ 7374 /* We are currently getting glyphs from a composition. */
7375 int i;
7376
7377 if (! it->bidi_p) 7375 if (! it->bidi_p)
7378 { 7376 {
7379 IT_CHARPOS (*it) += it->cmp_it.nchars; 7377 IT_CHARPOS (*it) += it->cmp_it.nchars;
7380 IT_BYTEPOS (*it) += it->cmp_it.nbytes; 7378 IT_BYTEPOS (*it) += it->cmp_it.nbytes;
7381 if (it->cmp_it.to < it->cmp_it.nglyphs)
7382 {
7383 it->cmp_it.from = it->cmp_it.to;
7384 }
7385 else
7386 {
7387 it->cmp_it.id = -1;
7388 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
7389 IT_BYTEPOS (*it),
7390 it->end_charpos, Qnil);
7391 }
7392 } 7379 }
7393 else if (! it->cmp_it.reversed_p) 7380 else
7394 { 7381 {
7395 /* Composition created while scanning forward. */ 7382 int i;
7383
7396 /* Update IT's char/byte positions to point to the first 7384 /* Update IT's char/byte positions to point to the first
7397 character of the next grapheme cluster, or to the 7385 character of the next grapheme cluster, or to the
7398 character visually after the current composition. */ 7386 character visually after the current composition. */
@@ -7400,52 +7388,34 @@ set_iterator_to_next (struct it *it, int reseat_p)
7400 bidi_move_to_visually_next (&it->bidi_it); 7388 bidi_move_to_visually_next (&it->bidi_it);
7401 IT_BYTEPOS (*it) = it->bidi_it.bytepos; 7389 IT_BYTEPOS (*it) = it->bidi_it.bytepos;
7402 IT_CHARPOS (*it) = it->bidi_it.charpos; 7390 IT_CHARPOS (*it) = it->bidi_it.charpos;
7391 }
7403 7392
7404 if (it->cmp_it.to < it->cmp_it.nglyphs) 7393 if ((! it->bidi_p || ! it->cmp_it.reversed_p)
7405 { 7394 && it->cmp_it.to < it->cmp_it.nglyphs)
7406 /* Proceed to the next grapheme cluster. */ 7395 {
7407 it->cmp_it.from = it->cmp_it.to; 7396 /* Composition created while scanning forward. Proceed
7408 } 7397 to the next grapheme cluster. */
7409 else 7398 it->cmp_it.from = it->cmp_it.to;
7410 { 7399 }
7411 /* No more grapheme clusters in this composition. 7400 else if ((it->bidi_p && it->cmp_it.reversed_p)
7412 Find the next stop position. */ 7401 && it->cmp_it.from > 0)
7413 ptrdiff_t stop = it->end_charpos; 7402 {
7414 if (it->bidi_it.scan_dir < 0) 7403 /* Composition created while scanning backward. Proceed
7415 /* Now we are scanning backward and don't know 7404 to the previous grapheme cluster. */
7416 where to stop. */ 7405 it->cmp_it.to = it->cmp_it.from;
7417 stop = -1;
7418 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
7419 IT_BYTEPOS (*it), stop, Qnil);
7420 }
7421 } 7406 }
7422 else 7407 else
7423 { 7408 {
7424 /* Composition created while scanning backward. */ 7409 /* No more grapheme clusters in this composition.
7425 /* Update IT's char/byte positions to point to the last 7410 Find the next stop position. */
7426 character of the previous grapheme cluster, or the 7411 ptrdiff_t stop = it->end_charpos;
7427 character visually after the current composition. */ 7412
7428 for (i = 0; i < it->cmp_it.nchars; i++) 7413 if (it->bidi_it.scan_dir < 0)
7429 bidi_move_to_visually_next (&it->bidi_it); 7414 /* Now we are scanning backward and don't know
7430 IT_BYTEPOS (*it) = it->bidi_it.bytepos; 7415 where to stop. */
7431 IT_CHARPOS (*it) = it->bidi_it.charpos; 7416 stop = -1;
7432 if (it->cmp_it.from > 0) 7417 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
7433 { 7418 IT_BYTEPOS (*it), stop, Qnil);
7434 /* Proceed to the previous grapheme cluster. */
7435 it->cmp_it.to = it->cmp_it.from;
7436 }
7437 else
7438 {
7439 /* No more grapheme clusters in this composition.
7440 Find the next stop position. */
7441 ptrdiff_t stop = it->end_charpos;
7442 if (it->bidi_it.scan_dir < 0)
7443 /* Now we are scanning backward and don't know
7444 where to stop. */
7445 stop = -1;
7446 composition_compute_stop_pos (&it->cmp_it, IT_CHARPOS (*it),
7447 IT_BYTEPOS (*it), stop, Qnil);
7448 }
7449 } 7419 }
7450 } 7420 }
7451 else 7421 else
@@ -7574,61 +7544,63 @@ set_iterator_to_next (struct it *it, int reseat_p)
7574 } 7544 }
7575 if (it->cmp_it.id >= 0) 7545 if (it->cmp_it.id >= 0)
7576 { 7546 {
7577 int i; 7547 /* We are delivering display elements from a composition.
7578 7548 Update the string position past the grapheme cluster
7549 we've just processed. */
7579 if (! it->bidi_p) 7550 if (! it->bidi_p)
7580 { 7551 {
7581 IT_STRING_CHARPOS (*it) += it->cmp_it.nchars; 7552 IT_STRING_CHARPOS (*it) += it->cmp_it.nchars;
7582 IT_STRING_BYTEPOS (*it) += it->cmp_it.nbytes; 7553 IT_STRING_BYTEPOS (*it) += it->cmp_it.nbytes;
7583 if (it->cmp_it.to < it->cmp_it.nglyphs)
7584 it->cmp_it.from = it->cmp_it.to;
7585 else
7586 {
7587 it->cmp_it.id = -1;
7588 composition_compute_stop_pos (&it->cmp_it,
7589 IT_STRING_CHARPOS (*it),
7590 IT_STRING_BYTEPOS (*it),
7591 it->end_charpos, it->string);
7592 }
7593 } 7554 }
7594 else if (! it->cmp_it.reversed_p) 7555 else
7595 { 7556 {
7557 int i;
7558
7596 for (i = 0; i < it->cmp_it.nchars; i++) 7559 for (i = 0; i < it->cmp_it.nchars; i++)
7597 bidi_move_to_visually_next (&it->bidi_it); 7560 bidi_move_to_visually_next (&it->bidi_it);
7598 IT_STRING_BYTEPOS (*it) = it->bidi_it.bytepos; 7561 IT_STRING_BYTEPOS (*it) = it->bidi_it.bytepos;
7599 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos; 7562 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos;
7563 }
7600 7564
7601 if (it->cmp_it.to < it->cmp_it.nglyphs) 7565 /* Did we exhaust all the grapheme clusters of this
7602 it->cmp_it.from = it->cmp_it.to; 7566 composition? */
7603 else 7567 if ((! it->bidi_p || ! it->cmp_it.reversed_p)
7604 { 7568 && (it->cmp_it.to < it->cmp_it.nglyphs))
7605 ptrdiff_t stop = it->end_charpos; 7569 {
7606 if (it->bidi_it.scan_dir < 0) 7570 /* Not all the grapheme clusters were processed yet;
7607 stop = -1; 7571 advance to the next cluster. */
7608 composition_compute_stop_pos (&it->cmp_it, 7572 it->cmp_it.from = it->cmp_it.to;
7609 IT_STRING_CHARPOS (*it), 7573 }
7610 IT_STRING_BYTEPOS (*it), stop, 7574 else if ((it->bidi_p && it->cmp_it.reversed_p)
7611 it->string); 7575 && it->cmp_it.from > 0)
7612 } 7576 {
7577 /* Likewise: advance to the next cluster, but going in
7578 the reverse direction. */
7579 it->cmp_it.to = it->cmp_it.from;
7613 } 7580 }
7614 else 7581 else
7615 { 7582 {
7616 for (i = 0; i < it->cmp_it.nchars; i++) 7583 /* This composition was fully processed; find the next
7617 bidi_move_to_visually_next (&it->bidi_it); 7584 candidate place for checking for composed
7618 IT_STRING_BYTEPOS (*it) = it->bidi_it.bytepos; 7585 characters. */
7619 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos; 7586 /* Always limit string searches to the string length;
7620 if (it->cmp_it.from > 0) 7587 any padding spaces are not part of the string, and
7621 it->cmp_it.to = it->cmp_it.from; 7588 there cannot be any compositions in that padding. */
7622 else 7589 ptrdiff_t stop = SCHARS (it->string);
7590
7591 if (it->bidi_p && it->bidi_it.scan_dir < 0)
7592 stop = -1;
7593 else if (it->end_charpos < stop)
7623 { 7594 {
7624 ptrdiff_t stop = it->end_charpos; 7595 /* Cf. PRECISION in reseat_to_string: we might be
7625 if (it->bidi_it.scan_dir < 0) 7596 limited in how many of the string characters we
7626 stop = -1; 7597 need to deliver. */
7627 composition_compute_stop_pos (&it->cmp_it, 7598 stop = it->end_charpos;
7628 IT_STRING_CHARPOS (*it),
7629 IT_STRING_BYTEPOS (*it), stop,
7630 it->string);
7631 } 7599 }
7600 composition_compute_stop_pos (&it->cmp_it,
7601 IT_STRING_CHARPOS (*it),
7602 IT_STRING_BYTEPOS (*it), stop,
7603 it->string);
7632 } 7604 }
7633 } 7605 }
7634 else 7606 else
@@ -7651,12 +7623,17 @@ set_iterator_to_next (struct it *it, int reseat_p)
7651 bidi_move_to_visually_next (&it->bidi_it); 7623 bidi_move_to_visually_next (&it->bidi_it);
7652 IT_STRING_BYTEPOS (*it) = it->bidi_it.bytepos; 7624 IT_STRING_BYTEPOS (*it) = it->bidi_it.bytepos;
7653 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos; 7625 IT_STRING_CHARPOS (*it) = it->bidi_it.charpos;
7626 /* If the scan direction changes, we may need to update
7627 the place where to check for composed characters. */
7654 if (prev_scan_dir != it->bidi_it.scan_dir) 7628 if (prev_scan_dir != it->bidi_it.scan_dir)
7655 { 7629 {
7656 ptrdiff_t stop = it->end_charpos; 7630 ptrdiff_t stop = SCHARS (it->string);
7657 7631
7658 if (it->bidi_it.scan_dir < 0) 7632 if (it->bidi_it.scan_dir < 0)
7659 stop = -1; 7633 stop = -1;
7634 else if (it->end_charpos < stop)
7635 stop = it->end_charpos;
7636
7660 composition_compute_stop_pos (&it->cmp_it, 7637 composition_compute_stop_pos (&it->cmp_it,
7661 IT_STRING_CHARPOS (*it), 7638 IT_STRING_CHARPOS (*it),
7662 IT_STRING_BYTEPOS (*it), stop, 7639 IT_STRING_BYTEPOS (*it), stop,
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,
diff --git a/src/xrdb.c b/src/xrdb.c
index e21206d0800..8500fb1095b 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -385,10 +385,11 @@ get_environ_db (void)
385 { 385 {
386 char *home = gethomedir (); 386 char *home = gethomedir ();
387 ptrdiff_t homelen = strlen (home); 387 ptrdiff_t homelen = strlen (home);
388 Lisp_Object system_name = Fsystem_name ();
388 ptrdiff_t filenamesize = (homelen + sizeof xdefaults 389 ptrdiff_t filenamesize = (homelen + sizeof xdefaults
389 + SBYTES (Vsystem_name)); 390 + SBYTES (system_name));
390 p = filename = xrealloc (home, filenamesize); 391 p = filename = xrealloc (home, filenamesize);
391 lispstpcpy (stpcpy (filename + homelen, xdefaults), Vsystem_name); 392 lispstpcpy (stpcpy (filename + homelen, xdefaults), system_name);
392 } 393 }
393 394
394 db = XrmGetFileDatabase (p); 395 db = XrmGetFileDatabase (p);
diff --git a/src/xselect.c b/src/xselect.c
index 92e89822293..3f8a1321954 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -46,9 +46,10 @@ struct prop_location;
46struct selection_data; 46struct selection_data;
47 47
48static void x_decline_selection_request (struct input_event *); 48static void x_decline_selection_request (struct input_event *);
49static int x_convert_selection (struct input_event *, Lisp_Object, Lisp_Object, 49static bool x_convert_selection (struct input_event *, Lisp_Object,
50 Atom, int, struct x_display_info *); 50 Lisp_Object, Atom, bool,
51static int waiting_for_other_props_on_window (Display *, Window); 51 struct x_display_info *);
52static bool waiting_for_other_props_on_window (Display *, Window);
52static struct prop_location *expect_property_change (Display *, Window, 53static struct prop_location *expect_property_change (Display *, Window,
53 Atom, int); 54 Atom, int);
54static void unexpect_property_change (struct prop_location *); 55static void unexpect_property_change (struct prop_location *);
@@ -360,7 +361,7 @@ x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
360 361
361static Lisp_Object 362static Lisp_Object
362x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type, 363x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
363 int local_request, struct x_display_info *dpyinfo) 364 bool local_request, struct x_display_info *dpyinfo)
364{ 365{
365 Lisp_Object local_value; 366 Lisp_Object local_value;
366 Lisp_Object handler_fn, value, check; 367 Lisp_Object handler_fn, value, check;
@@ -470,7 +471,7 @@ struct selection_data
470 ptrdiff_t size; 471 ptrdiff_t size;
471 int format; 472 int format;
472 Atom type; 473 Atom type;
473 int nofree; 474 bool nofree;
474 Atom property; 475 Atom property;
475 /* This can be set to non-NULL during x_reply_selection_request, if 476 /* This can be set to non-NULL during x_reply_selection_request, if
476 the selection is waiting for an INCR transfer to complete. Don't 477 the selection is waiting for an INCR transfer to complete. Don't
@@ -498,7 +499,7 @@ x_selection_request_lisp_error (void)
498 for (cs = converted_selections; cs; cs = next) 499 for (cs = converted_selections; cs; cs = next)
499 { 500 {
500 next = cs->next; 501 next = cs->next;
501 if (cs->nofree == 0 && cs->data) 502 if (! cs->nofree && cs->data)
502 xfree (cs->data); 503 xfree (cs->data);
503 xfree (cs); 504 xfree (cs);
504 } 505 }
@@ -531,7 +532,7 @@ struct prop_location
531 Window window; 532 Window window;
532 Atom property; 533 Atom property;
533 int desired_state; 534 int desired_state;
534 int arrived; 535 bool arrived;
535 struct prop_location *next; 536 struct prop_location *next;
536}; 537};
537 538
@@ -747,7 +748,7 @@ x_handle_selection_request (struct input_event *event)
747 Lisp_Object target_symbol = x_atom_to_symbol (dpyinfo, target); 748 Lisp_Object target_symbol = x_atom_to_symbol (dpyinfo, target);
748 Atom property = SELECTION_EVENT_PROPERTY (event); 749 Atom property = SELECTION_EVENT_PROPERTY (event);
749 Lisp_Object local_selection_data; 750 Lisp_Object local_selection_data;
750 int success = 0; 751 bool success = false;
751 ptrdiff_t count = SPECPDL_INDEX (); 752 ptrdiff_t count = SPECPDL_INDEX ();
752 GCPRO2 (local_selection_data, target_symbol); 753 GCPRO2 (local_selection_data, target_symbol);
753 754
@@ -805,9 +806,9 @@ x_handle_selection_request (struct input_event *event)
805 806
806 if (subproperty != None) 807 if (subproperty != None)
807 x_convert_selection (event, selection_symbol, subtarget, 808 x_convert_selection (event, selection_symbol, subtarget,
808 subproperty, 1, dpyinfo); 809 subproperty, true, dpyinfo);
809 } 810 }
810 success = 1; 811 success = true;
811 } 812 }
812 else 813 else
813 { 814 {
@@ -815,7 +816,7 @@ x_handle_selection_request (struct input_event *event)
815 property = SELECTION_EVENT_TARGET (event); 816 property = SELECTION_EVENT_TARGET (event);
816 success = x_convert_selection (event, selection_symbol, 817 success = x_convert_selection (event, selection_symbol,
817 target_symbol, property, 818 target_symbol, property,
818 0, dpyinfo); 819 false, dpyinfo);
819 } 820 }
820 821
821 DONE: 822 DONE:
@@ -844,15 +845,15 @@ x_handle_selection_request (struct input_event *event)
844 845
845/* Perform the requested selection conversion, and write the data to 846/* Perform the requested selection conversion, and write the data to
846 the converted_selections linked list, where it can be accessed by 847 the converted_selections linked list, where it can be accessed by
847 x_reply_selection_request. If FOR_MULTIPLE is non-zero, write out 848 x_reply_selection_request. If FOR_MULTIPLE, write out
848 the data even if conversion fails, using conversion_fail_tag. 849 the data even if conversion fails, using conversion_fail_tag.
849 850
850 Return 0 if the selection failed to convert, 1 otherwise. */ 851 Return true iff successful. */
851 852
852static int 853static bool
853x_convert_selection (struct input_event *event, Lisp_Object selection_symbol, 854x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
854 Lisp_Object target_symbol, Atom property, 855 Lisp_Object target_symbol, Atom property,
855 int for_multiple, struct x_display_info *dpyinfo) 856 bool for_multiple, struct x_display_info *dpyinfo)
856{ 857{
857 struct gcpro gcpro1; 858 struct gcpro gcpro1;
858 Lisp_Object lisp_selection; 859 Lisp_Object lisp_selection;
@@ -861,7 +862,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
861 862
862 lisp_selection 863 lisp_selection
863 = x_get_local_selection (selection_symbol, target_symbol, 864 = x_get_local_selection (selection_symbol, target_symbol,
864 0, dpyinfo); 865 false, dpyinfo);
865 866
866 /* A nil return value means we can't perform the conversion. */ 867 /* A nil return value means we can't perform the conversion. */
867 if (NILP (lisp_selection) 868 if (NILP (lisp_selection)
@@ -874,7 +875,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
874 cs->size = 1; 875 cs->size = 1;
875 cs->format = 32; 876 cs->format = 32;
876 cs->type = XA_ATOM; 877 cs->type = XA_ATOM;
877 cs->nofree = 1; 878 cs->nofree = true;
878 cs->property = property; 879 cs->property = property;
879 cs->wait_object = NULL; 880 cs->wait_object = NULL;
880 cs->next = converted_selections; 881 cs->next = converted_selections;
@@ -882,20 +883,20 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
882 } 883 }
883 884
884 UNGCPRO; 885 UNGCPRO;
885 return 0; 886 return false;
886 } 887 }
887 888
888 /* Otherwise, record the converted selection to binary. */ 889 /* Otherwise, record the converted selection to binary. */
889 cs = xmalloc (sizeof *cs); 890 cs = xmalloc (sizeof *cs);
890 cs->data = NULL; 891 cs->data = NULL;
891 cs->nofree = 1; 892 cs->nofree = true;
892 cs->property = property; 893 cs->property = property;
893 cs->wait_object = NULL; 894 cs->wait_object = NULL;
894 cs->next = converted_selections; 895 cs->next = converted_selections;
895 converted_selections = cs; 896 converted_selections = cs;
896 lisp_data_to_selection_data (dpyinfo, lisp_selection, cs); 897 lisp_data_to_selection_data (dpyinfo, lisp_selection, cs);
897 UNGCPRO; 898 UNGCPRO;
898 return 1; 899 return true;
899} 900}
900 901
901/* Handle a SelectionClear event EVENT, which indicates that some 902/* Handle a SelectionClear event EVENT, which indicates that some
@@ -1012,19 +1013,16 @@ x_clear_frame_selections (struct frame *f)
1012 } 1013 }
1013} 1014}
1014 1015
1015/* Nonzero if any properties for DISPLAY and WINDOW 1016/* True if any properties for DISPLAY and WINDOW
1016 are on the list of what we are waiting for. */ 1017 are on the list of what we are waiting for. */
1017 1018
1018static int 1019static bool
1019waiting_for_other_props_on_window (Display *display, Window window) 1020waiting_for_other_props_on_window (Display *display, Window window)
1020{ 1021{
1021 struct prop_location *rest = property_change_wait_list; 1022 for (struct prop_location *p = property_change_wait_list; p; p = p->next)
1022 while (rest) 1023 if (p->display == display && p->window == window)
1023 if (rest->display == display && rest->window == window) 1024 return true;
1024 return 1; 1025 return false;
1025 else
1026 rest = rest->next;
1027 return 0;
1028} 1026}
1029 1027
1030/* Add an entry to the list of property changes we are waiting for. 1028/* Add an entry to the list of property changes we are waiting for.
@@ -1043,7 +1041,7 @@ expect_property_change (Display *display, Window window,
1043 pl->property = property; 1041 pl->property = property;
1044 pl->desired_state = state; 1042 pl->desired_state = state;
1045 pl->next = property_change_wait_list; 1043 pl->next = property_change_wait_list;
1046 pl->arrived = 0; 1044 pl->arrived = false;
1047 property_change_wait_list = pl; 1045 property_change_wait_list = pl;
1048 return pl; 1046 return pl;
1049} 1047}
@@ -1106,7 +1104,7 @@ wait_for_property_change (struct prop_location *location)
1106 EMACS_INT secs = timeout / 1000; 1104 EMACS_INT secs = timeout / 1000;
1107 int nsecs = (timeout % 1000) * 1000000; 1105 int nsecs = (timeout % 1000) * 1000000;
1108 TRACE2 (" Waiting %"pI"d secs, %d nsecs", secs, nsecs); 1106 TRACE2 (" Waiting %"pI"d secs, %d nsecs", secs, nsecs);
1109 wait_reading_process_output (secs, nsecs, 0, 0, 1107 wait_reading_process_output (secs, nsecs, 0, false,
1110 property_change_reply, NULL, 0); 1108 property_change_reply, NULL, 0);
1111 1109
1112 if (NILP (XCAR (property_change_reply))) 1110 if (NILP (XCAR (property_change_reply)))
@@ -1138,7 +1136,7 @@ x_handle_property_notify (const XPropertyEvent *event)
1138 (event->state == PropertyDelete ? "deletion" : "change"), 1136 (event->state == PropertyDelete ? "deletion" : "change"),
1139 XGetAtomName (event->display, event->atom)); 1137 XGetAtomName (event->display, event->atom));
1140 1138
1141 rest->arrived = 1; 1139 rest->arrived = true;
1142 1140
1143 /* If this is the one wait_for_property_change is waiting for, 1141 /* If this is the one wait_for_property_change is waiting for,
1144 tell it to wake up. */ 1142 tell it to wake up. */
@@ -1204,7 +1202,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1204 during this time. In fact, the SAVE_TARGETS mechanism requires 1202 during this time. In fact, the SAVE_TARGETS mechanism requires
1205 us to handle a clipboard manager's requests before it returns 1203 us to handle a clipboard manager's requests before it returns
1206 SelectionNotify. */ 1204 SelectionNotify. */
1207#if 0 1205#if false
1208 x_start_queuing_selection_requests (); 1206 x_start_queuing_selection_requests ();
1209 record_unwind_protect_void (x_stop_queuing_selection_requests); 1207 record_unwind_protect_void (x_stop_queuing_selection_requests);
1210#endif 1208#endif
@@ -1216,7 +1214,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1216 secs = timeout / 1000; 1214 secs = timeout / 1000;
1217 nsecs = (timeout % 1000) * 1000000; 1215 nsecs = (timeout % 1000) * 1000000;
1218 TRACE1 (" Start waiting %"pI"d secs for SelectionNotify", secs); 1216 TRACE1 (" Start waiting %"pI"d secs for SelectionNotify", secs);
1219 wait_reading_process_output (secs, nsecs, 0, 0, 1217 wait_reading_process_output (secs, nsecs, 0, false,
1220 reading_selection_reply, NULL, 0); 1218 reading_selection_reply, NULL, 0);
1221 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply))); 1219 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply)));
1222 1220
@@ -1240,7 +1238,7 @@ static void
1240x_get_window_property (Display *display, Window window, Atom property, 1238x_get_window_property (Display *display, Window window, Atom property,
1241 unsigned char **data_ret, ptrdiff_t *bytes_ret, 1239 unsigned char **data_ret, ptrdiff_t *bytes_ret,
1242 Atom *actual_type_ret, int *actual_format_ret, 1240 Atom *actual_type_ret, int *actual_format_ret,
1243 unsigned long *actual_size_ret, int delete_p) 1241 unsigned long *actual_size_ret)
1244{ 1242{
1245 ptrdiff_t total_size; 1243 ptrdiff_t total_size;
1246 unsigned long bytes_remaining; 1244 unsigned long bytes_remaining;
@@ -1413,7 +1411,7 @@ receive_incremental_selection (struct x_display_info *dpyinfo,
1413 XFlush (display); 1411 XFlush (display);
1414 unblock_input (); 1412 unblock_input ();
1415 1413
1416 while (1) 1414 while (true)
1417 { 1415 {
1418 unsigned char *tmp_data; 1416 unsigned char *tmp_data;
1419 ptrdiff_t tmp_size_bytes; 1417 ptrdiff_t tmp_size_bytes;
@@ -1427,7 +1425,7 @@ receive_incremental_selection (struct x_display_info *dpyinfo,
1427 TRACE0 (" Get property value"); 1425 TRACE0 (" Get property value");
1428 x_get_window_property (display, window, property, 1426 x_get_window_property (display, window, property,
1429 &tmp_data, &tmp_size_bytes, 1427 &tmp_data, &tmp_size_bytes,
1430 type_ret, format_ret, size_ret, 1); 1428 type_ret, format_ret, size_ret);
1431 1429
1432 TRACE1 (" Read increment of %"pD"d bytes", tmp_size_bytes); 1430 TRACE1 (" Read increment of %"pD"d bytes", tmp_size_bytes);
1433 1431
@@ -1488,13 +1486,12 @@ x_get_window_property_as_lisp_data (struct x_display_info *dpyinfo,
1488 TRACE0 ("Reading selection data"); 1486 TRACE0 ("Reading selection data");
1489 1487
1490 x_get_window_property (display, window, property, &data, &bytes, 1488 x_get_window_property (display, window, property, &data, &bytes,
1491 &actual_type, &actual_format, &actual_size, 1); 1489 &actual_type, &actual_format, &actual_size);
1492 if (! data) 1490 if (! data)
1493 { 1491 {
1494 int there_is_a_selection_owner;
1495 block_input (); 1492 block_input ();
1496 there_is_a_selection_owner 1493 bool there_is_a_selection_owner
1497 = XGetSelectionOwner (display, selection_atom); 1494 = XGetSelectionOwner (display, selection_atom) != 0;
1498 unblock_input (); 1495 unblock_input ();
1499 if (there_is_a_selection_owner) 1496 if (there_is_a_selection_owner)
1500 signal_error ("Selection owner couldn't convert", 1497 signal_error ("Selection owner couldn't convert",
@@ -1687,7 +1684,7 @@ lisp_data_to_selection_data (struct x_display_info *dpyinfo,
1687 Lisp_Object type = Qnil; 1684 Lisp_Object type = Qnil;
1688 1685
1689 eassert (cs != NULL); 1686 eassert (cs != NULL);
1690 cs->nofree = 0; 1687 cs->nofree = false;
1691 1688
1692 if (CONSP (obj) && SYMBOLP (XCAR (obj))) 1689 if (CONSP (obj) && SYMBOLP (XCAR (obj)))
1693 { 1690 {
@@ -1714,7 +1711,7 @@ lisp_data_to_selection_data (struct x_display_info *dpyinfo,
1714 cs->format = 8; 1711 cs->format = 8;
1715 cs->size = SBYTES (obj); 1712 cs->size = SBYTES (obj);
1716 cs->data = SDATA (obj); 1713 cs->data = SDATA (obj);
1717 cs->nofree = 1; 1714 cs->nofree = true;
1718 } 1715 }
1719 else if (SYMBOLP (obj)) 1716 else if (SYMBOLP (obj))
1720 { 1717 {
@@ -1981,7 +1978,7 @@ On Nextstep, TIME-STAMP and TERMINAL are unused. */)
1981 if (!f) 1978 if (!f)
1982 error ("X selection unavailable for this frame"); 1979 error ("X selection unavailable for this frame");
1983 1980
1984 val = x_get_local_selection (selection_symbol, target_type, 1, 1981 val = x_get_local_selection (selection_symbol, target_type, true,
1985 FRAME_DISPLAY_INFO (f)); 1982 FRAME_DISPLAY_INFO (f));
1986 1983
1987 if (NILP (val) && FRAME_LIVE_P (f)) 1984 if (NILP (val) && FRAME_LIVE_P (f))
@@ -2432,7 +2429,7 @@ FRAME is on. If FRAME is nil, the selected frame is used. */)
2432 2429
2433/* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */ 2430/* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */
2434 2431
2435int 2432bool
2436x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event, 2433x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2437 struct x_display_info *dpyinfo, struct input_event *bufp) 2434 struct x_display_info *dpyinfo, struct input_event *bufp)
2438{ 2435{
@@ -2448,7 +2445,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2448 for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) 2445 for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
2449 if (dpyinfo->x_dnd_atoms[i] == event->message_type) break; 2446 if (dpyinfo->x_dnd_atoms[i] == event->message_type) break;
2450 2447
2451 if (i == dpyinfo->x_dnd_atoms_length) return 0; 2448 if (i == dpyinfo->x_dnd_atoms_length) return false;
2452 2449
2453 XSETFRAME (frame, f); 2450 XSETFRAME (frame, f);
2454 2451
@@ -2484,7 +2481,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2484 bufp->arg = vec; 2481 bufp->arg = vec;
2485 bufp->modifiers = 0; 2482 bufp->modifiers = 0;
2486 2483
2487 return 1; 2484 return true;
2488} 2485}
2489 2486
2490DEFUN ("x-send-client-message", Fx_send_client_message, 2487DEFUN ("x-send-client-message", Fx_send_client_message,
@@ -2535,7 +2532,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2535 Window wdest; 2532 Window wdest;
2536 XEvent event; 2533 XEvent event;
2537 struct frame *f = decode_window_system_frame (from); 2534 struct frame *f = decode_window_system_frame (from);
2538 int to_root; 2535 bool to_root;
2539 2536
2540 CHECK_NUMBER (format); 2537 CHECK_NUMBER (format);
2541 CHECK_CONS (values); 2538 CHECK_CONS (values);
@@ -2592,7 +2589,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2592 event then goes to clients selecting for events on the root window. */ 2589 event then goes to clients selecting for events on the root window. */
2593 x_catch_errors (dpyinfo->display); 2590 x_catch_errors (dpyinfo->display);
2594 { 2591 {
2595 int propagate = to_root ? False : True; 2592 bool propagate = !to_root;
2596 long mask = to_root ? 0xffffff : 0; 2593 long mask = to_root ? 0xffffff : 0;
2597 2594
2598 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event); 2595 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event);
diff --git a/src/xsettings.c b/src/xsettings.c
index 5f4275df545..066f426d241 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -68,11 +68,11 @@ store_config_changed_event (Lisp_Object arg, Lisp_Object display_name)
68 kbd_buffer_store_event (&event); 68 kbd_buffer_store_event (&event);
69} 69}
70 70
71/* Return non-zero if DPYINFO is still valid. */ 71/* Return true if DPYINFO is still valid. */
72static int 72static bool
73dpyinfo_valid (struct x_display_info *dpyinfo) 73dpyinfo_valid (struct x_display_info *dpyinfo)
74{ 74{
75 int found = 0; 75 bool found = false;
76 if (dpyinfo != NULL) 76 if (dpyinfo != NULL)
77 { 77 {
78 struct x_display_info *d; 78 struct x_display_info *d;
@@ -404,7 +404,7 @@ parse_settings (unsigned char *prop,
404 404
405 /* First 4 bytes is a serial number, skip that. */ 405 /* First 4 bytes is a serial number, skip that. */
406 406
407 if (bytes < 12) return BadLength; 407 if (bytes < 12) return settings_seen;
408 memcpy (&n_settings, prop+8, 4); 408 memcpy (&n_settings, prop+8, 4);
409 if (my_bo != that_bo) n_settings = bswap_32 (n_settings); 409 if (my_bo != that_bo) n_settings = bswap_32 (n_settings);
410 bytes_parsed = 12; 410 bytes_parsed = 12;
@@ -419,7 +419,7 @@ parse_settings (unsigned char *prop,
419 CARD32 vlen, ival = 0; 419 CARD32 vlen, ival = 0;
420 char name[128]; /* The names we are looking for are not this long. */ 420 char name[128]; /* The names we are looking for are not this long. */
421 char sval[128]; /* The values we are looking for are not this long. */ 421 char sval[128]; /* The values we are looking for are not this long. */
422 int want_this; 422 bool want_this;
423 int to_cpy; 423 int to_cpy;
424 424
425 sval[0] = '\0'; 425 sval[0] = '\0';
@@ -429,8 +429,8 @@ parse_settings (unsigned char *prop,
429 memcpy (&nlen, prop+bytes_parsed, 2); 429 memcpy (&nlen, prop+bytes_parsed, 2);
430 bytes_parsed += 2; 430 bytes_parsed += 2;
431 if (my_bo != that_bo) nlen = bswap_16 (nlen); 431 if (my_bo != that_bo) nlen = bswap_16 (nlen);
432 if (bytes_parsed+nlen > bytes) return BadLength; 432 if (bytes_parsed + nlen > bytes) return settings_seen;
433 to_cpy = nlen > 127 ? 127 : nlen; 433 to_cpy = min (nlen, sizeof name - 1);
434 memcpy (name, prop+bytes_parsed, to_cpy); 434 memcpy (name, prop+bytes_parsed, to_cpy);
435 name[to_cpy] = '\0'; 435 name[to_cpy] = '\0';
436 436
@@ -438,20 +438,19 @@ parse_settings (unsigned char *prop,
438 bytes_parsed = PAD (bytes_parsed); 438 bytes_parsed = PAD (bytes_parsed);
439 439
440 bytes_parsed += 4; /* Skip serial for this value */ 440 bytes_parsed += 4; /* Skip serial for this value */
441 if (bytes_parsed > bytes) return BadLength; 441 if (bytes_parsed > bytes) return settings_seen;
442 442
443 want_this = 443 want_this = strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0;
444#ifdef HAVE_XFT 444#ifdef HAVE_XFT
445 (nlen > 6 && strncmp (name, "Xft/", 4) == 0) 445 if ((nlen > 6 && memcmp (name, "Xft/", 4) == 0)
446 || strcmp (XSETTINGS_FONT_NAME, name) == 0 446 || strcmp (XSETTINGS_FONT_NAME, name) == 0)
447 || 447 want_this = true;
448#endif 448#endif
449 strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0;
450 449
451 switch (type) 450 switch (type)
452 { 451 {
453 case 0: /* Integer */ 452 case 0: /* Integer */
454 if (bytes_parsed+4 > bytes) return BadLength; 453 if (bytes_parsed + 4 > bytes) return settings_seen;
455 if (want_this) 454 if (want_this)
456 { 455 {
457 memcpy (&ival, prop+bytes_parsed, 4); 456 memcpy (&ival, prop+bytes_parsed, 4);
@@ -461,13 +460,13 @@ parse_settings (unsigned char *prop,
461 break; 460 break;
462 461
463 case 1: /* String */ 462 case 1: /* String */
464 if (bytes_parsed+4 > bytes) return BadLength; 463 if (bytes_parsed + 4 > bytes) return settings_seen;
465 memcpy (&vlen, prop+bytes_parsed, 4); 464 memcpy (&vlen, prop+bytes_parsed, 4);
466 bytes_parsed += 4; 465 bytes_parsed += 4;
467 if (my_bo != that_bo) vlen = bswap_32 (vlen); 466 if (my_bo != that_bo) vlen = bswap_32 (vlen);
468 if (want_this) 467 if (want_this)
469 { 468 {
470 to_cpy = vlen > 127 ? 127 : vlen; 469 to_cpy = min (vlen, sizeof sval - 1);
471 memcpy (sval, prop+bytes_parsed, to_cpy); 470 memcpy (sval, prop+bytes_parsed, to_cpy);
472 sval[to_cpy] = '\0'; 471 sval[to_cpy] = '\0';
473 } 472 }
@@ -477,17 +476,16 @@ parse_settings (unsigned char *prop,
477 476
478 case 2: /* RGB value */ 477 case 2: /* RGB value */
479 /* No need to parse this */ 478 /* No need to parse this */
480 if (bytes_parsed+8 > bytes) return BadLength; 479 if (bytes_parsed + 8 > bytes) return settings_seen;
481 bytes_parsed += 8; /* 4 values (r, b, g, alpha), 2 bytes each. */ 480 bytes_parsed += 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
482 break; 481 break;
483 482
484 default: /* Parse Error */ 483 default: /* Parse Error */
485 return BadValue; 484 return settings_seen;
486 } 485 }
487 486
488 if (want_this) 487 if (want_this)
489 { 488 {
490 ++settings_seen;
491 if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) 489 if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0)
492 { 490 {
493 dupstring (&settings->tb_style, sval); 491 dupstring (&settings->tb_style, sval);
@@ -557,6 +555,9 @@ parse_settings (unsigned char *prop,
557 settings->seen &= ~SEEN_LCDFILTER; 555 settings->seen &= ~SEEN_LCDFILTER;
558 } 556 }
559#endif /* HAVE_XFT */ 557#endif /* HAVE_XFT */
558 else
559 want_this = false;
560 settings_seen += want_this;
560 } 561 }
561 } 562 }
562 563
@@ -565,9 +566,9 @@ parse_settings (unsigned char *prop,
565 566
566/* Read settings from the XSettings property window on display for DPYINFO. 567/* Read settings from the XSettings property window on display for DPYINFO.
567 Store settings read in SETTINGS. 568 Store settings read in SETTINGS.
568 Return non-zero if successful, zero if not. */ 569 Return true iff successful. */
569 570
570static int 571static bool
571read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) 572read_settings (struct x_display_info *dpyinfo, struct xsettings *settings)
572{ 573{
573 Atom act_type; 574 Atom act_type;
@@ -576,6 +577,7 @@ read_settings (struct x_display_info *dpyinfo, struct xsettings *settings)
576 unsigned char *prop = NULL; 577 unsigned char *prop = NULL;
577 Display *dpy = dpyinfo->display; 578 Display *dpy = dpyinfo->display;
578 int rc; 579 int rc;
580 bool got_settings = false;
579 581
580 x_catch_errors (dpy); 582 x_catch_errors (dpy);
581 rc = XGetWindowProperty (dpy, 583 rc = XGetWindowProperty (dpy,
@@ -587,27 +589,26 @@ read_settings (struct x_display_info *dpyinfo, struct xsettings *settings)
587 589
588 if (rc == Success && prop != NULL && act_form == 8 && nitems > 0 590 if (rc == Success && prop != NULL && act_form == 8 && nitems > 0
589 && act_type == dpyinfo->Xatom_xsettings_prop) 591 && act_type == dpyinfo->Xatom_xsettings_prop)
590 rc = parse_settings (prop, nitems, settings); 592 got_settings = parse_settings (prop, nitems, settings) != 0;
591 593
592 XFree (prop); 594 XFree (prop);
593 595
594 x_uncatch_errors (); 596 x_uncatch_errors ();
595 597
596 return rc != 0; 598 return got_settings;
597} 599}
598 600
599/* Apply Xft settings in SETTINGS to the Xft library. 601/* Apply Xft settings in SETTINGS to the Xft library.
600 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */ 602 Store a Lisp event that Xft settings changed. */
601 603
602static void 604static void
603apply_xft_settings (struct x_display_info *dpyinfo, 605apply_xft_settings (struct x_display_info *dpyinfo,
604 int send_event_p,
605 struct xsettings *settings) 606 struct xsettings *settings)
606{ 607{
607#ifdef HAVE_XFT 608#ifdef HAVE_XFT
608 FcPattern *pat; 609 FcPattern *pat;
609 struct xsettings oldsettings; 610 struct xsettings oldsettings;
610 int changed = 0; 611 bool changed = false;
611 612
612 memset (&oldsettings, 0, sizeof (oldsettings)); 613 memset (&oldsettings, 0, sizeof (oldsettings));
613 pat = FcPatternCreate (); 614 pat = FcPatternCreate ();
@@ -627,7 +628,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
627 { 628 {
628 FcPatternDel (pat, FC_ANTIALIAS); 629 FcPatternDel (pat, FC_ANTIALIAS);
629 FcPatternAddBool (pat, FC_ANTIALIAS, settings->aa); 630 FcPatternAddBool (pat, FC_ANTIALIAS, settings->aa);
630 ++changed; 631 changed = true;
631 oldsettings.aa = settings->aa; 632 oldsettings.aa = settings->aa;
632 } 633 }
633 634
@@ -636,7 +637,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
636 { 637 {
637 FcPatternDel (pat, FC_HINTING); 638 FcPatternDel (pat, FC_HINTING);
638 FcPatternAddBool (pat, FC_HINTING, settings->hinting); 639 FcPatternAddBool (pat, FC_HINTING, settings->hinting);
639 ++changed; 640 changed = true;
640 oldsettings.hinting = settings->hinting; 641 oldsettings.hinting = settings->hinting;
641 } 642 }
642 if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba) 643 if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba)
@@ -644,7 +645,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
644 FcPatternDel (pat, FC_RGBA); 645 FcPatternDel (pat, FC_RGBA);
645 FcPatternAddInteger (pat, FC_RGBA, settings->rgba); 646 FcPatternAddInteger (pat, FC_RGBA, settings->rgba);
646 oldsettings.rgba = settings->rgba; 647 oldsettings.rgba = settings->rgba;
647 ++changed; 648 changed = true;
648 } 649 }
649 650
650 /* Older fontconfig versions don't have FC_LCD_FILTER. */ 651 /* Older fontconfig versions don't have FC_LCD_FILTER. */
@@ -653,7 +654,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
653 { 654 {
654 FcPatternDel (pat, FC_LCD_FILTER); 655 FcPatternDel (pat, FC_LCD_FILTER);
655 FcPatternAddInteger (pat, FC_LCD_FILTER, settings->lcdfilter); 656 FcPatternAddInteger (pat, FC_LCD_FILTER, settings->lcdfilter);
656 ++changed; 657 changed = true;
657 oldsettings.lcdfilter = settings->lcdfilter; 658 oldsettings.lcdfilter = settings->lcdfilter;
658 } 659 }
659 660
@@ -663,7 +664,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
663 { 664 {
664 FcPatternDel (pat, FC_HINT_STYLE); 665 FcPatternDel (pat, FC_HINT_STYLE);
665 FcPatternAddInteger (pat, FC_HINT_STYLE, settings->hintstyle); 666 FcPatternAddInteger (pat, FC_HINT_STYLE, settings->hintstyle);
666 ++changed; 667 changed = true;
667 oldsettings.hintstyle = settings->hintstyle; 668 oldsettings.hintstyle = settings->hintstyle;
668 } 669 }
669#endif 670#endif
@@ -673,7 +674,7 @@ apply_xft_settings (struct x_display_info *dpyinfo,
673 { 674 {
674 FcPatternDel (pat, FC_DPI); 675 FcPatternDel (pat, FC_DPI);
675 FcPatternAddDouble (pat, FC_DPI, settings->dpi); 676 FcPatternAddDouble (pat, FC_DPI, settings->dpi);
676 ++changed; 677 changed = true;
677 oldsettings.dpi = settings->dpi; 678 oldsettings.dpi = settings->dpi;
678 679
679 /* Changing the DPI on this display affects all frames on it. 680 /* Changing the DPI on this display affects all frames on it.
@@ -699,9 +700,8 @@ apply_xft_settings (struct x_display_info *dpyinfo,
699 char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth]; 700 char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth];
700 701
701 XftDefaultSet (dpyinfo->display, pat); 702 XftDefaultSet (dpyinfo->display, pat);
702 if (send_event_p) 703 store_config_changed_event (Qfont_render,
703 store_config_changed_event (Qfont_render, 704 XCAR (dpyinfo->name_list_element));
704 XCAR (dpyinfo->name_list_element));
705 Vxft_settings 705 Vxft_settings
706 = make_formatted_string (buf, format, 706 = make_formatted_string (buf, format,
707 oldsettings.aa, oldsettings.hinting, 707 oldsettings.aa, oldsettings.hinting,
@@ -715,17 +715,17 @@ apply_xft_settings (struct x_display_info *dpyinfo,
715} 715}
716 716
717/* Read XSettings from the display for DPYINFO. 717/* Read XSettings from the display for DPYINFO.
718 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */ 718 If SEND_EVENT_P store a Lisp event settings that changed. */
719 719
720static void 720static void
721read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) 721read_and_apply_settings (struct x_display_info *dpyinfo, bool send_event_p)
722{ 722{
723 struct xsettings settings; 723 struct xsettings settings;
724 724
725 if (!read_settings (dpyinfo, &settings)) 725 if (!read_settings (dpyinfo, &settings))
726 return; 726 return;
727 727
728 apply_xft_settings (dpyinfo, True, &settings); 728 apply_xft_settings (dpyinfo, &settings);
729 if (settings.seen & SEEN_TB_STYLE) 729 if (settings.seen & SEEN_TB_STYLE)
730 { 730 {
731 if (send_event_p) 731 if (send_event_p)
@@ -751,27 +751,27 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p)
751void 751void
752xft_settings_event (struct x_display_info *dpyinfo, const XEvent *event) 752xft_settings_event (struct x_display_info *dpyinfo, const XEvent *event)
753{ 753{
754 bool check_window_p = 0, apply_settings_p = 0; 754 bool check_window_p = false, apply_settings_p = false;
755 755
756 switch (event->type) 756 switch (event->type)
757 { 757 {
758 case DestroyNotify: 758 case DestroyNotify:
759 if (dpyinfo->xsettings_window == event->xany.window) 759 if (dpyinfo->xsettings_window == event->xany.window)
760 check_window_p = 1; 760 check_window_p = true;
761 break; 761 break;
762 762
763 case ClientMessage: 763 case ClientMessage:
764 if (event->xclient.message_type == dpyinfo->Xatom_xsettings_mgr 764 if (event->xclient.message_type == dpyinfo->Xatom_xsettings_mgr
765 && event->xclient.data.l[1] == dpyinfo->Xatom_xsettings_sel 765 && event->xclient.data.l[1] == dpyinfo->Xatom_xsettings_sel
766 && event->xclient.window == dpyinfo->root_window) 766 && event->xclient.window == dpyinfo->root_window)
767 check_window_p = 1; 767 check_window_p = true;
768 break; 768 break;
769 769
770 case PropertyNotify: 770 case PropertyNotify:
771 if (event->xproperty.window == dpyinfo->xsettings_window 771 if (event->xproperty.window == dpyinfo->xsettings_window
772 && event->xproperty.state == PropertyNewValue 772 && event->xproperty.state == PropertyNewValue
773 && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop) 773 && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop)
774 apply_settings_p = 1; 774 apply_settings_p = true;
775 break; 775 break;
776 } 776 }
777 777
@@ -781,11 +781,11 @@ xft_settings_event (struct x_display_info *dpyinfo, const XEvent *event)
781 dpyinfo->xsettings_window = None; 781 dpyinfo->xsettings_window = None;
782 get_prop_window (dpyinfo); 782 get_prop_window (dpyinfo);
783 if (dpyinfo->xsettings_window != None) 783 if (dpyinfo->xsettings_window != None)
784 apply_settings_p = 1; 784 apply_settings_p = true;
785 } 785 }
786 786
787 if (apply_settings_p) 787 if (apply_settings_p)
788 read_and_apply_settings (dpyinfo, True); 788 read_and_apply_settings (dpyinfo, true);
789} 789}
790 790
791/* Initialize GSettings and read startup values. */ 791/* Initialize GSettings and read startup values. */
@@ -795,7 +795,7 @@ init_gsettings (void)
795{ 795{
796#ifdef HAVE_GSETTINGS 796#ifdef HAVE_GSETTINGS
797 GVariant *val; 797 GVariant *val;
798 int schema_found = 0; 798 bool schema_found = false;
799 799
800#if ! GLIB_CHECK_VERSION (2, 36, 0) 800#if ! GLIB_CHECK_VERSION (2, 36, 0)
801 g_type_init (); 801 g_type_init ();
@@ -937,7 +937,7 @@ init_xsettings (struct x_display_info *dpyinfo)
937 937
938 get_prop_window (dpyinfo); 938 get_prop_window (dpyinfo);
939 if (dpyinfo->xsettings_window != None) 939 if (dpyinfo->xsettings_window != None)
940 read_and_apply_settings (dpyinfo, False); 940 read_and_apply_settings (dpyinfo, false);
941 941
942 unblock_input (); 942 unblock_input ();
943} 943}
@@ -1030,7 +1030,7 @@ syms_of_xsettings (void)
1030When this is non-nil and the system defined fixed width font changes, we 1030When this is non-nil and the system defined fixed width font changes, we
1031update frames dynamically. 1031update frames dynamically.
1032If this variable is nil, Emacs ignores system font changes. */); 1032If this variable is nil, Emacs ignores system font changes. */);
1033 use_system_font = 0; 1033 use_system_font = false;
1034 1034
1035 DEFVAR_LISP ("xft-settings", Vxft_settings, 1035 DEFVAR_LISP ("xft-settings", Vxft_settings,
1036 doc: /* Font settings applied to Xft. */); 1036 doc: /* Font settings applied to Xft. */);
diff --git a/src/xterm.c b/src/xterm.c
index f3b9cbe9a0f..c9b9e84b5e8 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -9244,13 +9244,9 @@ do_ewmh_fullscreen (struct frame *f)
9244 switch (f->want_fullscreen) 9244 switch (f->want_fullscreen)
9245 { 9245 {
9246 case FULLSCREEN_BOTH: 9246 case FULLSCREEN_BOTH:
9247 if (cur == FULLSCREEN_WIDTH || cur == FULLSCREEN_MAXIMIZED 9247 if (cur != FULLSCREEN_BOTH)
9248 || cur == FULLSCREEN_HEIGHT) 9248 set_wm_state (frame, true, dpyinfo->Xatom_net_wm_state_fullscreen,
9249 set_wm_state (frame, false, 9249 None);
9250 dpyinfo->Xatom_net_wm_state_maximized_horz,
9251 dpyinfo->Xatom_net_wm_state_maximized_vert);
9252 set_wm_state (frame, true,
9253 dpyinfo->Xatom_net_wm_state_fullscreen, None);
9254 break; 9250 break;
9255 case FULLSCREEN_WIDTH: 9251 case FULLSCREEN_WIDTH:
9256 if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_HEIGHT 9252 if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_HEIGHT
@@ -10515,8 +10511,9 @@ static bool
10515same_x_server (const char *name1, const char *name2) 10511same_x_server (const char *name1, const char *name2)
10516{ 10512{
10517 bool seen_colon = false; 10513 bool seen_colon = false;
10518 const char *system_name = SSDATA (Vsystem_name); 10514 Lisp_Object sysname = Fsystem_name ();
10519 ptrdiff_t system_name_length = SBYTES (Vsystem_name); 10515 const char *system_name = SSDATA (sysname);
10516 ptrdiff_t system_name_length = SBYTES (sysname);
10520 ptrdiff_t length_until_period = 0; 10517 ptrdiff_t length_until_period = 0;
10521 10518
10522 while (system_name[length_until_period] != 0 10519 while (system_name[length_until_period] != 0
@@ -10912,14 +10909,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10912#endif 10909#endif
10913 10910
10914 lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@"; 10911 lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@";
10915 if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name)) 10912 Lisp_Object system_name = Fsystem_name ();
10913 if (lim - SBYTES (Vinvocation_name) < SBYTES (system_name))
10916 memory_full (SIZE_MAX); 10914 memory_full (SIZE_MAX);
10917 dpyinfo->x_id = ++x_display_id; 10915 dpyinfo->x_id = ++x_display_id;
10918 dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name) 10916 dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name)
10919 + SBYTES (Vsystem_name) + 2); 10917 + SBYTES (system_name) + 2);
10920 char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name); 10918 char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
10921 *nametail++ = '@'; 10919 *nametail++ = '@';
10922 lispstpcpy (nametail, Vsystem_name); 10920 lispstpcpy (nametail, system_name);
10923 10921
10924 /* Figure out which modifier bits mean what. */ 10922 /* Figure out which modifier bits mean what. */
10925 x_find_modifier_meanings (dpyinfo); 10923 x_find_modifier_meanings (dpyinfo);
diff --git a/src/xterm.h b/src/xterm.h
index 84bb58c7232..13877d33935 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1049,10 +1049,10 @@ extern void x_send_client_event (Lisp_Object display,
1049 Lisp_Object format, 1049 Lisp_Object format,
1050 Lisp_Object values); 1050 Lisp_Object values);
1051 1051
1052extern int x_handle_dnd_message (struct frame *, 1052extern bool x_handle_dnd_message (struct frame *,
1053 const XClientMessageEvent *, 1053 const XClientMessageEvent *,
1054 struct x_display_info *, 1054 struct x_display_info *,
1055 struct input_event *); 1055 struct input_event *);
1056extern int x_check_property_data (Lisp_Object); 1056extern int x_check_property_data (Lisp_Object);
1057extern void x_fill_property_data (Display *, 1057extern void x_fill_property_data (Display *,
1058 Lisp_Object, 1058 Lisp_Object,