aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.gdbinit91
-rw-r--r--src/ChangeLog572
-rw-r--r--src/Makefile.in16
-rw-r--r--src/alloc.c30
-rw-r--r--src/buffer.c2
-rw-r--r--src/data.c164
-rw-r--r--src/dbusbind.c1793
-rw-r--r--src/dired.c41
-rw-r--r--src/dispextern.h1
-rw-r--r--src/dispnew.c19
-rw-r--r--src/editfns.c164
-rw-r--r--src/emacsgtkfixed.c31
-rw-r--r--src/emacsgtkfixed.h26
-rw-r--r--src/eval.c2
-rw-r--r--src/fileio.c22
-rw-r--r--src/filelock.c8
-rw-r--r--src/font.h7
-rw-r--r--src/frame.h3
-rw-r--r--src/gmalloc.c603
-rw-r--r--src/gnutls.c10
-rw-r--r--src/gtkutil.c2
-rw-r--r--src/intervals.c1
-rw-r--r--src/keyboard.c179
-rw-r--r--src/keymap.c17
-rw-r--r--src/lisp.h61
-rw-r--r--src/lisp.mk3
-rw-r--r--src/lread.c4
-rw-r--r--src/m/vax.h23
-rw-r--r--src/makefile.w32-in3
-rw-r--r--src/ns.mk12
-rw-r--r--src/nsterm.m11
-rw-r--r--src/print.c130
-rw-r--r--src/process.c50
-rw-r--r--src/ralloc.c60
-rw-r--r--src/regex.c17
-rw-r--r--src/s/ms-w32.h2
-rw-r--r--src/search.c181
-rw-r--r--src/sound.c7
-rw-r--r--src/sysdep.c228
-rw-r--r--src/syssignal.h15
-rw-r--r--src/term.c2
-rw-r--r--src/undo.c15
-rw-r--r--src/unexaix.c25
-rw-r--r--src/w32fns.c14
-rw-r--r--src/w32font.c7
-rw-r--r--src/w32menu.c9
-rw-r--r--src/w32proc.c20
-rw-r--r--src/w32term.c25
-rw-r--r--src/window.c5
-rw-r--r--src/xdisp.c184
-rw-r--r--src/xfns.c7
-rw-r--r--src/xgselect.c15
-rw-r--r--src/xselect.c1
-rw-r--r--src/xterm.c2
-rw-r--r--src/xterm.h1
55 files changed, 2420 insertions, 2523 deletions
diff --git a/src/.gdbinit b/src/.gdbinit
index 7cd828733b1..8f8508f291f 100644
--- a/src/.gdbinit
+++ b/src/.gdbinit
@@ -54,7 +54,7 @@ end
54 54
55define xgetint 55define xgetint
56 set $bugfix = $arg0 56 set $bugfix = $arg0
57 set $int = gdb_use_union ? $bugfix.s.val : (gdb_use_lsb ? $bugfix : $bugfix << gdb_gctypebits) >> gdb_gctypebits 57 set $int = gdb_use_union ? $bugfix.s.val : (gdb_use_lsb ? $bugfix >> (gdb_gctypebits - 1) : $bugfix << gdb_gctypebits) >> gdb_gctypebits
58end 58end
59 59
60define xgettype 60define xgettype
@@ -703,60 +703,6 @@ Print $ as a misc free-cell pointer.
703This command assumes that $ is an Emacs Lisp Misc value. 703This command assumes that $ is an Emacs Lisp Misc value.
704end 704end
705 705
706define xintfwd
707 xgetptr $
708 print (struct Lisp_Intfwd *) $ptr
709end
710document xintfwd
711Print $ as an integer forwarding pointer.
712This command assumes that $ is an Emacs Lisp Misc value.
713end
714
715define xboolfwd
716 xgetptr $
717 print (struct Lisp_Boolfwd *) $ptr
718end
719document xboolfwd
720Print $ as a boolean forwarding pointer.
721This command assumes that $ is an Emacs Lisp Misc value.
722end
723
724define xobjfwd
725 xgetptr $
726 print (struct Lisp_Objfwd *) $ptr
727end
728document xobjfwd
729Print $ as an object forwarding pointer.
730This command assumes that $ is an Emacs Lisp Misc value.
731end
732
733define xbufobjfwd
734 xgetptr $
735 print (struct Lisp_Buffer_Objfwd *) $ptr
736end
737document xbufobjfwd
738Print $ as a buffer-local object forwarding pointer.
739This command assumes that $ is an Emacs Lisp Misc value.
740end
741
742define xkbobjfwd
743 xgetptr $
744 print (struct Lisp_Kboard_Objfwd *) $ptr
745end
746document xkbobjfwd
747Print $ as a kboard-local object forwarding pointer.
748This command assumes that $ is an Emacs Lisp Misc value.
749end
750
751define xbuflocal
752 xgetptr $
753 print (struct Lisp_Buffer_Local_Value *) $ptr
754end
755document xbuflocal
756Print $ as a buffer-local-value pointer.
757This command assumes that $ is an Emacs Lisp Misc value.
758end
759
760define xsymbol 706define xsymbol
761 set $sym = $ 707 set $sym = $
762 xgetptr $sym 708 xgetptr $sym
@@ -1003,8 +949,15 @@ end
1003 949
1004define xpr 950define xpr
1005 xtype 951 xtype
1006 if $type == Lisp_Int 952 if gdb_use_union
1007 xint 953 if $type == Lisp_Int
954 xint
955 end
956 end
957 if !gdb_use_union
958 if $type == Lisp_Int0 || $type == Lisp_Int1
959 xint
960 end
1008 end 961 end
1009 if $type == Lisp_Symbol 962 if $type == Lisp_Symbol
1010 xsymbol 963 xsymbol
@@ -1023,36 +976,12 @@ define xpr
1023 if $misc == Lisp_Misc_Free 976 if $misc == Lisp_Misc_Free
1024 xmiscfree 977 xmiscfree
1025 end 978 end
1026 if $misc == Lisp_Misc_Boolfwd
1027 xboolfwd
1028 end
1029 if $misc == Lisp_Misc_Marker 979 if $misc == Lisp_Misc_Marker
1030 xmarker 980 xmarker
1031 end 981 end
1032 if $misc == Lisp_Misc_Intfwd
1033 xintfwd
1034 end
1035 if $misc == Lisp_Misc_Boolfwd
1036 xboolfwd
1037 end
1038 if $misc == Lisp_Misc_Objfwd
1039 xobjfwd
1040 end
1041 if $misc == Lisp_Misc_Buffer_Objfwd
1042 xbufobjfwd
1043 end
1044 if $misc == Lisp_Misc_Buffer_Local_Value
1045 xbuflocal
1046 end
1047# if $misc == Lisp_Misc_Some_Buffer_Local_Value
1048# xvalue
1049# end
1050 if $misc == Lisp_Misc_Overlay 982 if $misc == Lisp_Misc_Overlay
1051 xoverlay 983 xoverlay
1052 end 984 end
1053 if $misc == Lisp_Misc_Kboard_Objfwd
1054 xkbobjfwd
1055 end
1056# if $misc == Lisp_Misc_Save_Value 985# if $misc == Lisp_Misc_Save_Value
1057# xsavevalue 986# xsavevalue
1058# end 987# end
diff --git a/src/ChangeLog b/src/ChangeLog
index 0fa21336900..ea898893073 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,575 @@
12012-05-20 Ken Brown <kbrown@cornell.edu>
2
3 * gmalloc.c (_free_internal_nolock, _realloc_internal_nolock)
4 [CYGWIN]: Cast ptr to (char *) before comparing to _heapbase.
5
62012-05-19 Ken Brown <kbrown@cornell.edu>
7
8 * xfns.c (x_in_use): Remove `static' qualifier.
9 * xterm.h (x_in_use): Declare.
10 * xgselect.c: Include xterm.h.
11 (xg_select): Test `x_in_use' instead of `inhibit_window_system'
12 and `display_arg' (bug#9754).
13
142012-05-19 Paul Eggert <eggert@cs.ucla.edu>
15
16 * s/ms-w32.h (HAVE_GETDOMAINNAME): Remove; not needed.
17
18 * m/vax.h: Remove; no longer needed since HAVE_FTIME is being removed.
19 * s/ms-w32.h (HAVE_FTIME): Remove; not needed.
20
212012-05-18 Eli Zaretskii <eliz@gnu.org>
22
23 Fix compilation with -DGLYPH_DEBUG=1 on MS-Windows.
24
25 * w32term.c [GLYPH_DEBUG]: Add prototype for x_check_font.
26 (x_check_font) [GLYPH_DEBUG]: New function, copied from xterm.c
27
28 * w32fns.c (unwind_create_frame) [GLYPH_DEBUG]: Fix broken
29 reference to image_cache->refcount.
30 (x_create_tip_frame): Fix broken use of FRAME_IMAGE_CACHE.
31
322012-05-17 Juri Linkov <juri@jurta.org>
33
34 * search.c (Fword_search_regexp, Fword_search_backward)
35 (Fword_search_forward, Fword_search_backward_lax)
36 (Fword_search_forward_lax): Move functions to isearch.el
37 (bug#10145, bug#11381).
38
392012-05-16 Paul Eggert <eggert@cs.ucla.edu>
40
41 * xgselect.c (xg_select): Just invoke 'select' if -nw (Bug#9754).
42
432012-05-15 Stefan Monnier <monnier@iro.umontreal.ca>
44
45 * lread.c (init_obarray): Declare Qt and Qnil as special.
46
472012-05-14 Glenn Morris <rgm@gnu.org>
48
49 * nsterm.m (ns_init_paths): Fix typo ("libexec" not "lib-exec").
50 Put "libexec" before "bin", for the sake of init_callproc_1.
51
522012-05-14 Paul Eggert <eggert@cs.ucla.edu>
53
54 * keyboard.c (kbd_buffer_get_event) [!HAVE_DBUS]: Omit unused local.
55
56 * unexaix.c: Port to more-recent AIX compilers.
57 (report_error, report_error_1, make_hdr, copy_sym)
58 (mark_x, adjust_lnnoptrs, unrelocate_symbols):
59 Make arguments const char *, not char *, to avoid violations of C
60 standard and to fix some AIX warnings reported by Gilles Pion.
61
622012-05-14 Eli Zaretskii <eliz@gnu.org>
63
64 * xdisp.c (handle_stop): Don't call get_overlay_strings_1 if we
65 already have overlays loaded.
66 (handle_single_display_spec): Before returning without displaying
67 fringe bitmap, synchronize the bidi iterator with the main display
68 iterator, by calling iterate_out_of_display_property.
69 (iterate_out_of_display_property): Detect buffer iteration by
70 testing that it->string is a Lisp string.
71 (get_next_display_element): When the current object is exhausted,
72 and there's something on it->stack, call set_iterator_to_next to
73 proceed with what's on the stack, instead of returning zero.
74 (set_iterator_to_next): If called at the end of a Lisp string,
75 proceed to consider_string_end without incrementing string
76 position. Don't increment display vector index past the end of
77 the display vector. (Bug#11417)
78 (pos_visible_p): Don't report a position visible when move_it_to
79 stopped at the last line of window, which happens to be scanned
80 backwards by the bidi iteration. (Bug#11464)
81
822012-05-14 Eli Zaretskii <eliz@gnu.org>
83
84 * xdisp.c (handle_single_display_spec): Return 1 for left-margin
85 and right-margin display specs even if the spec is invalid or we
86 are on a TTY, and thus unable to display on the fringes. That's
87 because the text with the property will not be displayed anyway,
88 so we need to signal to the caller that this is a "replacing"
89 display spec. This fixes display when the spec is invalid or we
90 are on a TTY.
91
922012-05-14 Paul Eggert <eggert@cs.ucla.edu>
93
94 * unexaix.c (make_hdr): Fix typo in prototype.
95 This bug broke the build on AIX. Problem reported by Gilles Pion.
96
972012-05-14 Michael Albinus <michael.albinus@gmx.de>
98
99 * keyboard.c (kbd_buffer_get_event): Read special events also in
100 batch mode. (Bug#11415)
101
1022012-05-12 Glenn Morris <rgm@gnu.org>
103
104 * ns.mk: Update for ns_appbindir no longer having trailing "/".
105
1062012-05-12 Eli Zaretskii <eliz@gnu.org>
107
108 * lisp.mk (lisp): Add newcomment.elc.
109
1102012-05-12 Glenn Morris <rgm@gnu.org>
111
112 * Makefile.in (MKDIR_P): New, set by configure.
113 * ns.mk (${ns_appdir}, ${ns_appbindir}Emacs): Use $MKDIR_P.
114
1152012-05-11 Paul Eggert <eggert@cs.ucla.edu>
116
117 Remove unused function hourglass_started.
118 * dispextern.h (hourglass_started):
119 * w32fns.c (hourglass_started):
120 * xdisp.c (hourglass_started): Remove.
121
1222012-05-10 Juanma Barranquero <lekktu@gmail.com>
123
124 * makefile.w32-in ($(BLD)/gmalloc.$(O), $(BLD)/w32menu.$(O)):
125 Update dependencies.
126
1272012-05-10 Paul Eggert <eggert@cs.ucla.edu>
128
129 * xgselect.c (xg_select): Put maxfds+1 into a var.
130 This is slightly clearer, and pacifies Ubuntu 12.04 gcc.
131
132 * sound.c (DEFAULT_ALSA_SOUND_DEVICE): Define only if HAVE_ALSA.
133
1342012-05-10 Dave Abrahams <dave@boostpro.com>
135
136 * filelock.c (syms_of_filelock): New boolean create-lockfiles.
137 (lock_file): If create_lockfiles is 0, do nothing. (Bug#11227)
138
1392012-05-09 Michael Albinus <michael.albinus@gmx.de>
140
141 * dbusbind.c (xd_registered_buses): New internal Lisp object.
142 Rename all occurences of Vdbus_registered_buses to xd_registered_buses.
143 (syms_of_dbusbind): Remove declaration of Vdbus_registered_buses.
144 Initialize xd_registered_buses.
145
1462012-05-09 Paul Eggert <eggert@cs.ucla.edu>
147
148 Untag more efficiently if USE_LSB_TAG.
149 This is based on a proposal by YAMAMOTO Mitsuharu in
150 <http://lists.gnu.org/archive/html/emacs-devel/2008-01/msg01876.html>.
151 For an admittedly artificial (nth 8000 longlist) benchmark on
152 Fedora 15 x86-64, this yields a 25% CPU speedup. Also, it shrinks
153 Emacs's overall text size by 1%.
154 * lisp.h (XUNTAG): New macro.
155 (XCONS, XVECTOR, XSTRING, XSYMBOL, XFLOAT, XMISC, XPROCESS, XWINDOW)
156 (XTERMINAL, XSUBR, XBUFFER, XCHAR_TABLE, XSUB_CHAR_TABLE, XBOOL_VECTOR)
157 (XSETTYPED_PSEUDOVECTOR, XHASH_TABLE, TYPED_PSEUDOVECTORP): Use it.
158 * eval.c (Fautoload):
159 * font.h (XFONT_SPEC, XFONT_ENTITY, XFONT_OBJECT):
160 * frame.h (XFRAME): Use XUNTAG.
161
162 Port recent dbusbind.c changes to 32-bit --with-wide-int.
163 * dbusbind.c (xd_append_arg, xd_retrieve_arg, Fdbus_message_internal):
164 Remove unportable assumptions about print widths of types like
165 dbus_uint32_t.
166 (xd_get_connection_address, Fdbus_init_bus): Cast Emacs integer to
167 intptr_t when converting between pointer and integer, to avoid GCC
168 warnings about wrong width.
169
1702012-05-09 Eli Zaretskii <eliz@gnu.org>
171
172 * w32proc.c (new_child): Force Windows to reserve only 64KB of
173 stack for each reader_thread, instead of defaulting to 8MB
174 determined by the linker. This avoids failures in creating
175 subprocesses on Windows 7, see the discussion in this thread:
176 http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00119.html.
177
1782012-05-07 Jérémy Compostella <jeremy.compostella@gmail.com>
179
180 Fix up display of the *Minibuf-0* buffer in the mini window.
181 * keyboard.c (read_char): Don't clear the echo area if there's no
182 message to clear.
183 * xdisp.c (redisplay_internal): Redisplay the mini window (with the
184 contents of *Minibuf-0*) if there's no message displayed in its stead.
185
1862012-05-07 Michael Albinus <michael.albinus@gmx.de>
187
188 * dbusbind.c (XD_DEBUG_MESSAGE): Don't print message twice in
189 batch mode.
190
1912012-05-06 Chong Yidong <cyd@gnu.org>
192
193 * lisp.mk (lisp): Update.
194
1952012-05-05 Jim Meyering <meyering@redhat.com>
196
197 * w32font.c (fill_in_logfont): NUL-terminate a string (Bug#11372).
198
1992012-05-04 Stefan Monnier <monnier@iro.umontreal.ca>
200
201 * data.c (PUT_ERROR): New macro.
202 (syms_of_data): Use it. Add new error type `user-error'.
203 * undo.c (user_error): New function.
204 (Fprimitive_undo): Use it.
205 * print.c (print_error_message): Adjust print style for `user-error'.
206 * keyboard.c (user_error): New function.
207 (Fexit_recursive_edit, Fabort_recursive_edit): Use it.
208
2092012-05-03 Paul Eggert <eggert@cs.ucla.edu>
210
211 Do not limit current-time-string to years 1000..9999.
212 * editfns.c (TM_YEAR_IN_ASCTIME_RANGE): Remove.
213 (Fcurrent_time_string): Support any year that is supported by the
214 underlying localtime representation. Don't use asctime, as it
215 has undefined behavior for years outside the range -999..9999.
216
2172012-05-02 Paul Eggert <eggert@cs.ucla.edu>
218
219 Fix race conditions involving setenv, gmtime, localtime, asctime.
220 Without this fix, interrupts could mess up code that uses these
221 nonreentrant functions, since setting TZ invalidates existing
222 tm_zone or tzname values, and since most of these functions return
223 pointers to static storage.
224 * editfns.c (format_time_string, Fdecode_time, Fencode_time)
225 (Fcurrent_time_string, Fcurrent_time_zone, Fset_time_zone_rule):
226 Grow the critical sections to include not just invoking
227 localtime/gmtime, but also accessing these functions' results
228 including their tm_zone values if any, and any related TZ setting.
229 (format_time_string): Last arg is now struct tm *, not struct tm **,
230 so that the struct tm is saved in the critical section.
231 All callers changed. Simplify allocation of initial buffer, partly
232 motivated by the fact that memory allocation needs to be outside
233 the critical section.
234
2352012-05-02 Dmitry Antipov <dmantipov@yandex.ru>
236
237 * intervals.c (adjust_intervals_for_insertion): Initialize `newi'
238 with RESET_INTERVAL.
239
240 * buffer.c (Fget_buffer_create, Fmake_indirect_buffer):
241 Remove duplicated buffer name initialization.
242
2432012-05-02 Jim Meyering <jim@meyering.net>
244
245 * xterm.c (x_term_init): Use memcpy instead of strncpy (Bug#11373).
246
247 * xfns.c (x_window): Use xstrdup (Bug#11375).
248
2492012-05-02 Eli Zaretskii <eliz@gnu.org>
250
251 * xdisp.c (pos_visible_p): If already at a newline from the
252 display string before the 'while' loop, don't walk back the glyphs
253 from it3.glyph_row. Solves assertion violation when the display
254 string begins with a newline (egg.el). (Bug#11367)
255
2562012-05-01 Stefan Monnier <monnier@iro.umontreal.ca>
257
258 * keyboard.c (Fexecute_extended_command, Vsuggest_key_bindings):
259 Move to simple.el.
260
2612012-05-01 Glenn Morris <rgm@gnu.org>
262
263 * syssignal.h: Remove reference to BROKEN_SIGINFO (last used in
264 s/ptx4.h), BROKEN_SIGTSTP (last used in m/ustation.h, m/dpx2.h),
265 and BROKEN_SIGURG (was in s/gnu-linux.h prior to 2008-02-10).
266 All were removed before 23.1.
267
268 * dispnew.c: Remove HAVE_LIBNCURSES test;
269 it is always true on relevant platforms.
270
271 * Makefile.in (LD_SWITCH_X_SITE_RPATH):
272 Rename from LD_SWITCH_X_SITE_AUX_RPATH.
273
274 * Makefile.in (LD_SWITCH_X_SITE_AUX): Remove; no longer used.
275
2762012-04-30 Andreas Schwab <schwab@linux-m68k.org>
277
278 * .gdbinit (xpr): Remove checks for no longer existing misc types.
279 (xintfwd, xboolfwd, xobjfwd, xbufobjfwd, xkbobjfwd, xbuflocal):
280 Remove.
281
2822012-04-28 Paul Eggert <eggert@cs.ucla.edu>
283
284 Do not avoid creating empty evaporating overlays (Bug#9642).
285 * buffer.c (Fmove_overlay): Revert the change of 2012-04-23.
286 That is, do not delete an evaporating overlay if it becomes
287 empty after its bounds are adjusted to fit within its buffer.
288 This fix caused other problems, and I'm reverting it until we get
289 to the bottom of them.
290
2912012-04-27 Chong Yidong <cyd@gnu.org>
292
293 * xselect.c (x_convert_selection): Initialize a pointer (Bug#11315).
294
2952012-04-27 Eli Zaretskii <eliz@gnu.org>
296
297 * xdisp.c (pos_visible_p): If the window start position is beyond
298 ZV, start the display from buffer beginning. Prevents assertion
299 violation in init_iterator when the minibuffer window is scrolled
300 via the scroll bar.
301
302 * window.c (window_scroll_pixel_based): Likewise.
303
3042012-04-27 Chong Yidong <cyd@gnu.org>
305
306 * keymap.c (where_is_internal): Doc fix (Bug#10872).
307
3082012-04-27 Glenn Morris <rgm@gnu.org>
309
310 * fileio.c (Fcopy_file, Fset_file_selinux_context):
311 Ignore ENOTSUP failures from setfilecon functions. (Bug#11245)
312
3132012-04-27 Eli Zaretskii <eliz@gnu.org>
314
315 * dispnew.c (swap_glyph_pointers, copy_row_except_pointers):
316 Don't overrun array limits of glyph row's used[] array. (Bug#11288)
317
3182012-04-26 Eli Zaretskii <eliz@gnu.org>
319
320 * xdisp.c (IT_DISPLAYING_WHITESPACE): In addition to the loaded
321 display element, check also the underlying string or buffer
322 character. (Bug#11341)
323
324 * w32menu.c: Include w32heap.h.
325 (add_menu_item): If the call to AppendMenuW (via
326 unicode_append_menu) fails, disable Unicode menus only if we are
327 running on Windows 9X/Me.
328
3292012-04-24 Andreas Schwab <schwab@linux-m68k.org>
330
331 * .gdbinit (xpr): Handle USE_2_TAGS_FOR_INTS.
332 (xgetint): Add missing shift for LSB tags.
333
3342012-04-24 Martin Rudalics <rudalics@gmx.at>
335
336 * keyboard.c (read_char): Don't wipe echo area for select window
337 events: These might get delayed via `mouse-autoselect-window'
338 (Bug#11304).
339
3402012-04-24 Juanma Barranquero <lekktu@gmail.com>
341
342 * gnutls.c (init_gnutls_functions): Protect against (unlikely)
343 manipulation of :loaded-from data.
344
3452012-04-23 Juanma Barranquero <lekktu@gmail.com>
346
347 * gnutls.c (init_gnutls_functions): The value of :loaded-from is
348 now a cons (bug#11311).
349
3502012-04-23 Paul Eggert <eggert@cs.ucla.edu>
351
352 Do not create empty overlays with the evaporate property (Bug#9642).
353 * buffer.c (Fmove_overlay): Delete an evaporating overlay
354 if it becomes empty after its bounds are adjusted to fit within
355 its buffer. Without this fix, in a nonempty buffer (let ((o
356 (make-overlay 1 2))) (overlay-put o 'evaporate t) (move-overlay o 0 1))
357 yields an empty overlay that has the evaporate property, which is
358 not supposed to happen.
359
360 Fix minor GTK3 problems found by static checking.
361 * emacsgtkfixed.c (EMACS_TYPE_FIXED, EMACS_FIXED, EmacsFixed)
362 (EmacsFixedPrivate, EmacsFixedClass, struct _EmacsFixed)
363 (struct _EmacsFixedClass, emacs_fixed_get_type):
364 Move decls here from emacsgtkfixed.h, since they needn't be public.
365 (emacs_fixed_get_type): Now static.
366 (emacs_fixed_class_init): Omit unused local.
367 (emacs_fixed_child_type): Remove; unused.
368 * emacsgtkfixed.h (EMACS_TYPE_FIXED, EMACS_FIXED, EmacsFixed)
369 (EmacsFixedPrivate, EmacsFixedClass, struct _EmacsFixed)
370 (struct _EmacsFixedClass): Move to emacsgtkfixed.c.
371 (EMACS_FIXED_CLASS, EMACS_IS_FIXED, EMACS_IS_FIXED_CLASS)
372 (EMACS_FIXED_GET_CLASS): Remove; unused.
373 * gtkutil.c (xg_create_frame_widgets) [!HAVE_GTK3]: Omit unused local.
374
375 * keyboard.c (handle_async_input): Define only if SYNC_INPUT || SIGIO.
376 Problem reported by Juanma Barranquero for Windows -Wunused-function.
377
3782012-04-22 Paul Eggert <eggert@cs.ucla.edu>
379
380 Modernize and clean up gmalloc.c to assume C89 (Bug#9119).
381 * gmalloc.c: (_MALLOC_INTERNAL, _MALLOC_H, _PP, __ptr_t)
382 (__malloc_size_t, __malloc_ptrdiff_t):
383 Remove. All uses removed, replaced by the definiens if needed,
384 since we can assume C89 or better now.
385 Include <stdint.h>, for PTRDIFF_MAX, uintptr_t.
386 (protect_malloc_state, align, get_contiguous_space)
387 (malloc_atfork_handler_prepare, malloc_atfork_handler_parent)
388 (malloc_atfork_handler_child, malloc_enable_thread)
389 (malloc_initialize_1, __malloc_initialize, morecore_nolock)
390 (_malloc_internal_nolock, _malloc_internal, malloc, _malloc)
391 (_free, _realloc, _free_internal_nolock, _free_internal, free, cfree)
392 (special_realloc, _realloc_internal_nolock, _realloc_internal)
393 (realloc, calloc, __default_morecore, memalign, valloc, checkhdr)
394 (freehook, mallochook, reallochook, mabort, mcheck, mprobe):
395 Define using prototypes, not old style.
396 (align, _malloc_internal_nolock, _free_internal_nolock, memalign):
397 Don't assume ptrdiff_t and uintptr_t are no wider than unsigned long.
398 (align): Don't assume that signed integer overflow wraps around.
399 Omit unused local var.
400 (malloc_initialize_1, morecore_nolock, _malloc_internal_nolock)
401 (_free_internal_nolock, memalign, mallochook, reallochook):
402 Omit no-longer-needed casts.
403 (valloc): Use getpagesize, not __getpagesize.
404 (MAGICWORD, MAGICFREE): Now randomish size_t values, not 32-bit.
405 (struct hdr): The 'magic' member is now size_t, not unsigned long.
406
407 * dbusbind.c (XD_DBUS_VALIDATE_OBJECT): Define only if needed.
408
4092012-04-22 Michael Albinus <michael.albinus@gmx.de>
410
411 Move functions from C to Lisp. Make non-blocking method calls
412 the default. Implement further D-Bus standard interfaces.
413
414 * dbusbind.c (DBUS_NUM_MESSAGE_TYPES): Declare.
415 (QCdbus_request_name_allow_replacement)
416 (QCdbus_request_name_replace_existing)
417 (QCdbus_request_name_do_not_queue)
418 (QCdbus_request_name_reply_primary_owner)
419 (QCdbus_request_name_reply_in_queue)
420 (QCdbus_request_name_reply_exists)
421 (QCdbus_request_name_reply_already_owner): Move to dbus.el.
422 (QCdbus_registered_serial, QCdbus_registered_method)
423 (QCdbus_registered_signal): New Lisp objects.
424 (XD_DEBUG_MESSAGE): Use sizeof.
425 (XD_MESSAGE_TYPE_TO_STRING, XD_OBJECT_TO_STRING)
426 (XD_DBUS_VALIDATE_BUS_ADDRESS, XD_DBUS_VALIDATE_OBJECT)
427 (XD_DBUS_VALIDATE_BUS_NAME, XD_DBUS_VALIDATE_PATH)
428 (XD_DBUS_VALIDATE_INTERFACE, XD_DBUS_VALIDATE_MEMBER): New macros.
429 (XD_CHECK_DBUS_SERIAL): Rename from CHECK_DBUS_SERIAL_GET_SERIAL.
430 (xd_signature, xd_append_arg): Allow float for integer types.
431 (xd_get_connection_references): New function.
432 (xd_get_connection_address): Rename from xd_initialize.
433 Return cached address.
434 (xd_remove_watch): Do not unset $DBUS_SESSION_BUS_ADDRESS.
435 (xd_close_bus): Rename from Fdbus_close_bus. Not needed on Lisp
436 level.
437 (Fdbus_init_bus): New optional arg PRIVATE. Cache address.
438 Return number of refcounts.
439 (Fdbus_get_unique_name): Make stronger parameter check.
440 (Fdbus_message_internal): New defun.
441 (Fdbus_call_method, Fdbus_call_method_asynchronously)
442 (Fdbus_method_return_internal, Fdbus_method_error_internal)
443 (Fdbus_send_signal, Fdbus_register_service)
444 (Fdbus_register_signal, Fdbus_register_method): Move to dbus.el.
445 (xd_read_message_1): Obey new structure of Vdbus_registered_objects.
446 (xd_read_queued_messages): Obey new structure of Vdbus_registered_buses.
447 (Vdbus_compiled_version, Vdbus_runtime_version)
448 (Vdbus_message_type_invalid, Vdbus_message_type_method_call)
449 (Vdbus_message_type_method_return, Vdbus_message_type_error)
450 (Vdbus_message_type_signal): New defvars.
451 (Vdbus_registered_buses, Vdbus_registered_objects_table):
452 Adapt docstring.
453
4542012-04-22 Paul Eggert <eggert@cs.ucla.edu>
455
456 Fix GC_MALLOC_CHECK debugging output on 64-bit hosts.
457 * alloc.c (emacs_blocked_malloc) [GC_MALLOC_CHECK]:
458 Do not assume ptrdiff_t is the same width as 'int'.
459
460 * alloc.c: Handle unusual debugging option combinations.
461 (GC_CHECK_MARKED_OBJECTS): Undef if ! GC_MARK_STACK,
462 since the two debugging options are incompatible.
463 (GC_MALLOC_CHECK): Similarly, undef if GC_CHECK_MARKED_OBJECTS
464 is defined.
465 (mem_init, mem_insert, mem_insert_fixup):
466 Define if GC_MARK_STACK || GC_MALLOC_CHECK.
467 (NEED_MEM_INSERT): Remove; no longer needed.
468
4692012-04-22 Leo Liu <sdl.web@gmail.com>
470
471 * sysdep.c (list_system_processes): Support Darwin (Bug#5725).
472
4732012-04-22 Paul Eggert <eggert@cs.ucla.edu>
474
475 * sysdep.c [__FreeBSD__]: Minor cleanups.
476 (list_system_processes, system_process_attributes) [__FreeBSD__]:
477 Use Emacs indenting style more consistently. Avoid some casts.
478 Use 'double' consistently rather than mixing 'float' and 'double'.
479
4802012-04-21 Eduard Wiebe <usenet@pusto.de>
481
482 * sysdep.c (list_system_processes, system_process_attributes):
483 Add implementation for FreeBSD (Bug#5243).
484
4852012-04-21 Andreas Schwab <schwab@linux-m68k.org>
486
487 * lisp.mk (lisp): Update.
488
4892012-04-20 Paul Eggert <eggert@cs.ucla.edu>
490
491 * keyboard.c (process_pending_signals): Define only if SYNC_INPUT.
492 It is never used otherwise.
493
4942012-04-20 Stefan Monnier <monnier@iro.umontreal.ca>
495
496 * print.c (print_preprocess): Only check print_depth if print-circle
497 is nil.
498 (print_object): Check for cycles even when print-circle is nil and
499 print-gensym is t, but only check print_depth if print-circle is nil.
500
5012012-04-20 Chong Yidong <cyd@gnu.org>
502
503 * process.c (wait_reading_process_output): If EIO occurs on a pty,
504 set the status to "failed" and ensure that sentinel is run.
505
5062012-04-20 Glenn Morris <rgm@gnu.org>
507
508 * process.c (Fset_process_inherit_coding_system_flag)
509 (Fset_process_query_on_exit_flag): Doc fix (mention return value).
510 (Fmake_network_process, Fmake_serial_process): Doc fix.
511
5122012-04-20 Eli Zaretskii <eliz@gnu.org>
513
514 * xdisp.c (string_buffer_position_lim): Limit starting position to
515 BEGV.
516 (set_cursor_from_row): If called for a mode-line or header-line
517 row, return zero immediately.
518 (try_cursor_movement): If inside continuation line, don't back up
519 farther than the first row after the header line, if any.
520 Don't consider the header-line row as "partially visible", even if
521 MATRIX_ROW_PARTIALLY_VISIBLE_P returns non-zero. (Bug#11261)
522
5232012-04-20 Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp> (tiny change)
524
525 * lread.c (lisp_file_lexically_bound_p): Fix hang at ";-*-\n"
526 (bug#11238).
527
5282012-04-20 Teodor Zlatanov <tzz@lifelogs.com>
5292012-04-18 Paul Eggert <eggert@cs.ucla.edu>
530
531 configure: new option --enable-gcc-warnings (Bug#11207)
532 * Makefile.in (C_WARNINGS_SWITCH): Remove.
533 (WARN_CFLAGS, WERROR_CFLAGS): New macros.
534 (ALL_CFLAGS): Use new macros rather than old.
535 * process.c: Ignore -Wstrict-overflow to work around GCC bug 52904.
536 * regex.c: Ignore -Wstrict-overflow. If !emacs, also ignore
537 -Wunused-but-set-variable, -Wunused-function, -Wunused-macros,
538 -Wunused-result, -Wunused-variable. This should go away once
539 the Emacs and Gnulib regex code is merged.
540 (xmalloc, xrealloc): Now static.
541
5422012-04-17 Paul Eggert <eggert@cs.ucla.edu>
543
544 * dired.c (Fsystem_groups): Remove unused local.
545
5462012-04-17 Glenn Morris <rgm@gnu.org>
547
548 * dired.c (Fsystem_users): Doc fix.
549
5502012-04-17 Dmitry Antipov <dmantipov@yandex.ru>
551
552 * dired.c (Fsystem_users, Fsystem_groups): New functions. (Bug#7900)
553 (syms_of_dired): Add them.
554
12012-04-16 Paul Eggert <eggert@cs.ucla.edu> 5552012-04-16 Paul Eggert <eggert@cs.ucla.edu>
2 556
557 Fix minor alloc.c problems found by static checking.
558 * alloc.c (_malloc_internal, _free_internal) [!DOUG_LEA_MALLOC]:
559 New extern decls, to avoid calling undeclared functions.
560 (dont_register_blocks): Define if ((!SYSTEM_MALLOC && !SYNC_INPUT)
561 && GC_MALLOC_CHECK), not if ((GC_MARK_STACK || defined
562 GC_MALLOC_CHECK) && GC_MALLOC_CHECK), to match when it's used.
563 (NEED_MEM_INSERT): New macro.
564 (mem_insert, mem_insert_fixup) [!NEED_MEM_INSERT]: Remove; unused.
565 Remove one incorrect comment and fix another.
566
567 Fix minor ralloc.c problems found by static checking.
568 See http://lists.gnu.org/archive/html/emacs-devel/2011-12/msg00720.html
569 * ralloc.c (ALIGNED, ROUND_TO_PAGE, HEAP_PTR_SIZE)
570 (r_alloc_size_in_use, r_alloc_freeze, r_alloc_thaw): Remove; unused.
571 (r_alloc_sbrk): Now static.
572
3 Improve ralloc.c interface checking. 573 Improve ralloc.c interface checking.
4 See http://lists.gnu.org/archive/html/emacs-devel/2011-12/msg00720.html 574 See http://lists.gnu.org/archive/html/emacs-devel/2011-12/msg00720.html
5 * buffer.c (ralloc_reset_variable, r_alloc, r_re_alloc) 575 * buffer.c (ralloc_reset_variable, r_alloc, r_re_alloc)
@@ -22,7 +592,7 @@
22 (union aligned_Lisp_Misc): Define. 592 (union aligned_Lisp_Misc): Define.
23 (MARKER_BLOCK_SIZE, struct marker_block): Use union 593 (MARKER_BLOCK_SIZE, struct marker_block): Use union
24 aligned_Lisp_Misc instead of union Lisp_Misc. 594 aligned_Lisp_Misc instead of union Lisp_Misc.
25 (Fmake_symbol, allocate_misc, gc_sweep): Adjust 595 (Fmake_symbol, allocate_misc, gc_sweep): Adjust.
26 596
272012-04-14 Paul Eggert <eggert@cs.ucla.edu> 5972012-04-14 Paul Eggert <eggert@cs.ucla.edu>
28 598
diff --git a/src/Makefile.in b/src/Makefile.in
index e8b68040c44..8d4c5306782 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -40,6 +40,7 @@ version = @version@
40# Substitute an assignment for the MAKE variable, because 40# Substitute an assignment for the MAKE variable, because
41# BSD doesn't have it as a default. 41# BSD doesn't have it as a default.
42@SET_MAKE@ 42@SET_MAKE@
43MKDIR_P = @MKDIR_P@
43# Don't use LIBS. configure puts stuff in it that either shouldn't be 44# Don't use LIBS. configure puts stuff in it that either shouldn't be
44# linked with Emacs or is duplicated by the other stuff below. 45# linked with Emacs or is duplicated by the other stuff below.
45# LIBS = @LIBS@ 46# LIBS = @LIBS@
@@ -68,7 +69,8 @@ OTHER_FILES = @OTHER_FILES@
68PROFILING_CFLAGS = @PROFILING_CFLAGS@ 69PROFILING_CFLAGS = @PROFILING_CFLAGS@
69 70
70## Flags to pass to the compiler to enable build warnings 71## Flags to pass to the compiler to enable build warnings
71C_WARNINGS_SWITCH = @C_WARNINGS_SWITCH@ 72WARN_CFLAGS = @WARN_CFLAGS@
73WERROR_CFLAGS = @WERROR_CFLAGS@
72 74
73## Machine-specific CFLAGS. 75## Machine-specific CFLAGS.
74C_SWITCH_MACHINE=@C_SWITCH_MACHINE@ 76C_SWITCH_MACHINE=@C_SWITCH_MACHINE@
@@ -93,11 +95,9 @@ C_SWITCH_X_SITE=@C_SWITCH_X_SITE@
93## substituted in this or any other Makefile. Cf C_SWITCH_X_SITE. 95## substituted in this or any other Makefile. Cf C_SWITCH_X_SITE.
94LD_SWITCH_X_SITE= 96LD_SWITCH_X_SITE=
95 97
96## Next two must come before LD_SWITCH_SYSTEM. 98## This must come before LD_SWITCH_SYSTEM.
97## If needed, a -R option that says where to find X windows at run time. 99## If needed, a -rpath option that says where to find X windows at run time.
98LD_SWITCH_X_SITE_AUX=@LD_SWITCH_X_SITE_AUX@ 100LD_SWITCH_X_SITE_RPATH=@LD_SWITCH_X_SITE_RPATH@
99## As above, but using -rpath instead.
100LD_SWITCH_X_SITE_AUX_RPATH=@LD_SWITCH_X_SITE_AUX_RPATH@
101 101
102## System-specific LDFLAGS. 102## System-specific LDFLAGS.
103LD_SWITCH_SYSTEM=@LD_SWITCH_SYSTEM@ 103LD_SWITCH_SYSTEM=@LD_SWITCH_SYSTEM@
@@ -291,7 +291,7 @@ CANNOT_DUMP=@CANNOT_DUMP@
291DEPDIR=deps 291DEPDIR=deps
292## -MMD -MF $(DEPDIR)/$*.d if AUTO_DEPEND; else empty. 292## -MMD -MF $(DEPDIR)/$*.d if AUTO_DEPEND; else empty.
293DEPFLAGS=@DEPFLAGS@ 293DEPFLAGS=@DEPFLAGS@
294## test -d $(DEPDIR) || mkdir $(DEPDIR) (if AUTO_DEPEND); else ':'. 294## ${MKDIR_P} ${DEPDIR} (if AUTO_DEPEND); else ':'.
295MKDEPDIR=@MKDEPDIR@ 295MKDEPDIR=@MKDEPDIR@
296 296
297## DO NOT use -R. There is a special hack described in lastfile.c 297## DO NOT use -R. There is a special hack described in lastfile.c
@@ -315,7 +315,7 @@ ALL_CFLAGS=-Demacs -DHAVE_CONFIG_H $(MYCPPFLAGS) -I. -I$(srcdir) \
315 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \ 315 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
316 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \ 316 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \
317 $(LIBGNUTLS_CFLAGS) \ 317 $(LIBGNUTLS_CFLAGS) \
318 $(C_WARNINGS_SWITCH) $(CFLAGS) 318 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
319ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS) 319ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS)
320 320
321.SUFFIXES: .m 321.SUFFIXES: .m
diff --git a/src/alloc.c b/src/alloc.c
index 0e68817629c..a120ce9b61f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -49,10 +49,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
49#include <setjmp.h> 49#include <setjmp.h>
50#include <verify.h> 50#include <verify.h>
51 51
52/* GC_CHECK_MARKED_OBJECTS means do sanity checks on allocated objects.
53 Doable only if GC_MARK_STACK. */
54#if ! GC_MARK_STACK
55# undef GC_CHECK_MARKED_OBJECTS
56#endif
57
52/* GC_MALLOC_CHECK defined means perform validity checks of malloc'd 58/* GC_MALLOC_CHECK defined means perform validity checks of malloc'd
53 memory. Can do this only if using gmalloc.c. */ 59 memory. Can do this only if using gmalloc.c and if not checking
60 marked objects. */
54 61
55#if defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC 62#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \
63 || defined GC_CHECK_MARKED_OBJECTS)
56#undef GC_MALLOC_CHECK 64#undef GC_MALLOC_CHECK
57#endif 65#endif
58 66
@@ -82,6 +90,8 @@ extern POINTER_TYPE *sbrk ();
82 90
83extern size_t _bytes_used; 91extern size_t _bytes_used;
84extern size_t __malloc_extra_blocks; 92extern size_t __malloc_extra_blocks;
93extern void *_malloc_internal (size_t);
94extern void _free_internal (void *);
85 95
86#endif /* not DOUG_LEA_MALLOC */ 96#endif /* not DOUG_LEA_MALLOC */
87 97
@@ -314,7 +324,6 @@ static Lisp_Object Vdead;
314#ifdef GC_MALLOC_CHECK 324#ifdef GC_MALLOC_CHECK
315 325
316enum mem_type allocated_mem_type; 326enum mem_type allocated_mem_type;
317static int dont_register_blocks;
318 327
319#endif /* GC_MALLOC_CHECK */ 328#endif /* GC_MALLOC_CHECK */
320 329
@@ -390,9 +399,11 @@ static int live_float_p (struct mem_node *, void *);
390static int live_misc_p (struct mem_node *, void *); 399static int live_misc_p (struct mem_node *, void *);
391static void mark_maybe_object (Lisp_Object); 400static void mark_maybe_object (Lisp_Object);
392static void mark_memory (void *, void *); 401static void mark_memory (void *, void *);
402#if GC_MARK_STACK || defined GC_MALLOC_CHECK
393static void mem_init (void); 403static void mem_init (void);
394static struct mem_node *mem_insert (void *, void *, enum mem_type); 404static struct mem_node *mem_insert (void *, void *, enum mem_type);
395static void mem_insert_fixup (struct mem_node *); 405static void mem_insert_fixup (struct mem_node *);
406#endif
396static void mem_rotate_left (struct mem_node *); 407static void mem_rotate_left (struct mem_node *);
397static void mem_rotate_right (struct mem_node *); 408static void mem_rotate_right (struct mem_node *);
398static void mem_delete (struct mem_node *); 409static void mem_delete (struct mem_node *);
@@ -942,9 +953,6 @@ lisp_free (POINTER_TYPE *block)
942/* The entry point is lisp_align_malloc which returns blocks of at most 953/* The entry point is lisp_align_malloc which returns blocks of at most
943 BLOCK_BYTES and guarantees they are aligned on a BLOCK_ALIGN boundary. */ 954 BLOCK_BYTES and guarantees they are aligned on a BLOCK_ALIGN boundary. */
944 955
945/* Use posix_memalloc if the system has it and we're using the system's
946 malloc (because our gmalloc.c routines don't have posix_memalign although
947 its memalloc could be used). */
948#if defined (HAVE_POSIX_MEMALIGN) && defined (SYSTEM_MALLOC) 956#if defined (HAVE_POSIX_MEMALIGN) && defined (SYSTEM_MALLOC)
949#define USE_POSIX_MEMALIGN 1 957#define USE_POSIX_MEMALIGN 1
950#endif 958#endif
@@ -1001,7 +1009,7 @@ struct ablocks
1001 struct ablock blocks[ABLOCKS_SIZE]; 1009 struct ablock blocks[ABLOCKS_SIZE];
1002}; 1010};
1003 1011
1004/* Size of the block requested from malloc or memalign. */ 1012/* Size of the block requested from malloc or posix_memalign. */
1005#define ABLOCKS_BYTES (sizeof (struct ablocks) - BLOCK_PADDING) 1013#define ABLOCKS_BYTES (sizeof (struct ablocks) - BLOCK_PADDING)
1006 1014
1007#define ABLOCK_ABASE(block) \ 1015#define ABLOCK_ABASE(block) \
@@ -1223,6 +1231,10 @@ static void (*old_free_hook) (void*, const void*);
1223# define BYTES_USED _bytes_used 1231# define BYTES_USED _bytes_used
1224#endif 1232#endif
1225 1233
1234#ifdef GC_MALLOC_CHECK
1235static int dont_register_blocks;
1236#endif
1237
1226static size_t bytes_used_when_reconsidered; 1238static size_t bytes_used_when_reconsidered;
1227 1239
1228/* Value of _bytes_used, when spare_memory was freed. */ 1240/* Value of _bytes_used, when spare_memory was freed. */
@@ -1302,7 +1314,7 @@ emacs_blocked_malloc (size_t size, const void *ptr)
1302 { 1314 {
1303 fprintf (stderr, "Malloc returned %p which is already in use\n", 1315 fprintf (stderr, "Malloc returned %p which is already in use\n",
1304 value); 1316 value);
1305 fprintf (stderr, "Region in use is %p...%p, %u bytes, type %d\n", 1317 fprintf (stderr, "Region in use is %p...%p, %td bytes, type %d\n",
1306 m->start, m->end, (char *) m->end - (char *) m->start, 1318 m->start, m->end, (char *) m->end - (char *) m->start,
1307 m->type); 1319 m->type);
1308 abort (); 1320 abort ();
@@ -5826,7 +5838,7 @@ mark_buffer (Lisp_Object buf)
5826} 5838}
5827 5839
5828/* Mark the Lisp pointers in the terminal objects. 5840/* Mark the Lisp pointers in the terminal objects.
5829 Called by the Fgarbage_collector. */ 5841 Called by Fgarbage_collect. */
5830 5842
5831static void 5843static void
5832mark_terminals (void) 5844mark_terminals (void)
diff --git a/src/buffer.c b/src/buffer.c
index 9bac3ec742b..2ddbc699481 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -392,7 +392,6 @@ even if it is dead. The return value is never nil. */)
392 392
393 BVAR (b, mark) = Fmake_marker (); 393 BVAR (b, mark) = Fmake_marker ();
394 BUF_MARKERS (b) = NULL; 394 BUF_MARKERS (b) = NULL;
395 BVAR (b, name) = name;
396 395
397 /* Put this in the alist of all live buffers. */ 396 /* Put this in the alist of all live buffers. */
398 XSETBUFFER (buffer, b); 397 XSETBUFFER (buffer, b);
@@ -612,7 +611,6 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
612 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); 611 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
613 612
614 BVAR (b, mark) = Fmake_marker (); 613 BVAR (b, mark) = Fmake_marker ();
615 BVAR (b, name) = name;
616 614
617 /* The multibyte status belongs to the base buffer. */ 615 /* The multibyte status belongs to the base buffer. */
618 BVAR (b, enable_multibyte_characters) = BVAR (b->base_buffer, enable_multibyte_characters); 616 BVAR (b, enable_multibyte_characters) = BVAR (b->base_buffer, enable_multibyte_characters);
diff --git a/src/data.c b/src/data.c
index bd1d89992cb..feacea2c08b 100644
--- a/src/data.c
+++ b/src/data.c
@@ -51,7 +51,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; 51Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
52static Lisp_Object Qsubr; 52static Lisp_Object Qsubr;
53Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; 53Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
54Lisp_Object Qerror, Qquit, Qargs_out_of_range; 54Lisp_Object Qerror, Quser_error, Qquit, Qargs_out_of_range;
55static Lisp_Object Qwrong_type_argument; 55static Lisp_Object Qwrong_type_argument;
56Lisp_Object Qvoid_variable, Qvoid_function; 56Lisp_Object Qvoid_variable, Qvoid_function;
57static Lisp_Object Qcyclic_function_indirection; 57static Lisp_Object Qcyclic_function_indirection;
@@ -2937,6 +2937,7 @@ syms_of_data (void)
2937 DEFSYM (Qtop_level, "top-level"); 2937 DEFSYM (Qtop_level, "top-level");
2938 2938
2939 DEFSYM (Qerror, "error"); 2939 DEFSYM (Qerror, "error");
2940 DEFSYM (Quser_error, "user-error");
2940 DEFSYM (Qquit, "quit"); 2941 DEFSYM (Qquit, "quit");
2941 DEFSYM (Qwrong_type_argument, "wrong-type-argument"); 2942 DEFSYM (Qwrong_type_argument, "wrong-type-argument");
2942 DEFSYM (Qargs_out_of_range, "args-out-of-range"); 2943 DEFSYM (Qargs_out_of_range, "args-out-of-range");
@@ -3004,102 +3005,42 @@ syms_of_data (void)
3004 Fput (Qerror, Qerror_message, 3005 Fput (Qerror, Qerror_message,
3005 make_pure_c_string ("error")); 3006 make_pure_c_string ("error"));
3006 3007
3007 Fput (Qquit, Qerror_conditions, 3008#define PUT_ERROR(sym, tail, msg) \
3008 pure_cons (Qquit, Qnil)); 3009 Fput (sym, Qerror_conditions, pure_cons (sym, tail)); \
3009 Fput (Qquit, Qerror_message, 3010 Fput (sym, Qerror_message, make_pure_c_string (msg))
3010 make_pure_c_string ("Quit")); 3011
3011 3012 PUT_ERROR (Qquit, Qnil, "Quit");
3012 Fput (Qwrong_type_argument, Qerror_conditions, 3013
3013 pure_cons (Qwrong_type_argument, error_tail)); 3014 PUT_ERROR (Quser_error, error_tail, "");
3014 Fput (Qwrong_type_argument, Qerror_message, 3015 PUT_ERROR (Qwrong_type_argument, error_tail, "Wrong type argument");
3015 make_pure_c_string ("Wrong type argument")); 3016 PUT_ERROR (Qargs_out_of_range, error_tail, "Args out of range");
3016 3017 PUT_ERROR (Qvoid_function, error_tail,
3017 Fput (Qargs_out_of_range, Qerror_conditions, 3018 "Symbol's function definition is void");
3018 pure_cons (Qargs_out_of_range, error_tail)); 3019 PUT_ERROR (Qcyclic_function_indirection, error_tail,
3019 Fput (Qargs_out_of_range, Qerror_message, 3020 "Symbol's chain of function indirections contains a loop");
3020 make_pure_c_string ("Args out of range")); 3021 PUT_ERROR (Qcyclic_variable_indirection, error_tail,
3021 3022 "Symbol's chain of variable indirections contains a loop");
3022 Fput (Qvoid_function, Qerror_conditions,
3023 pure_cons (Qvoid_function, error_tail));
3024 Fput (Qvoid_function, Qerror_message,
3025 make_pure_c_string ("Symbol's function definition is void"));
3026
3027 Fput (Qcyclic_function_indirection, Qerror_conditions,
3028 pure_cons (Qcyclic_function_indirection, error_tail));
3029 Fput (Qcyclic_function_indirection, Qerror_message,
3030 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
3031
3032 Fput (Qcyclic_variable_indirection, Qerror_conditions,
3033 pure_cons (Qcyclic_variable_indirection, error_tail));
3034 Fput (Qcyclic_variable_indirection, Qerror_message,
3035 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
3036
3037 DEFSYM (Qcircular_list, "circular-list"); 3023 DEFSYM (Qcircular_list, "circular-list");
3038 Fput (Qcircular_list, Qerror_conditions, 3024 PUT_ERROR (Qcircular_list, error_tail, "List contains a loop");
3039 pure_cons (Qcircular_list, error_tail)); 3025 PUT_ERROR (Qvoid_variable, error_tail, "Symbol's value as variable is void");
3040 Fput (Qcircular_list, Qerror_message, 3026 PUT_ERROR (Qsetting_constant, error_tail,
3041 make_pure_c_string ("List contains a loop")); 3027 "Attempt to set a constant symbol");
3042 3028 PUT_ERROR (Qinvalid_read_syntax, error_tail, "Invalid read syntax");
3043 Fput (Qvoid_variable, Qerror_conditions, 3029 PUT_ERROR (Qinvalid_function, error_tail, "Invalid function");
3044 pure_cons (Qvoid_variable, error_tail)); 3030 PUT_ERROR (Qwrong_number_of_arguments, error_tail,
3045 Fput (Qvoid_variable, Qerror_message, 3031 "Wrong number of arguments");
3046 make_pure_c_string ("Symbol's value as variable is void")); 3032 PUT_ERROR (Qno_catch, error_tail, "No catch for tag");
3047 3033 PUT_ERROR (Qend_of_file, error_tail, "End of file during parsing");
3048 Fput (Qsetting_constant, Qerror_conditions,
3049 pure_cons (Qsetting_constant, error_tail));
3050 Fput (Qsetting_constant, Qerror_message,
3051 make_pure_c_string ("Attempt to set a constant symbol"));
3052
3053 Fput (Qinvalid_read_syntax, Qerror_conditions,
3054 pure_cons (Qinvalid_read_syntax, error_tail));
3055 Fput (Qinvalid_read_syntax, Qerror_message,
3056 make_pure_c_string ("Invalid read syntax"));
3057
3058 Fput (Qinvalid_function, Qerror_conditions,
3059 pure_cons (Qinvalid_function, error_tail));
3060 Fput (Qinvalid_function, Qerror_message,
3061 make_pure_c_string ("Invalid function"));
3062
3063 Fput (Qwrong_number_of_arguments, Qerror_conditions,
3064 pure_cons (Qwrong_number_of_arguments, error_tail));
3065 Fput (Qwrong_number_of_arguments, Qerror_message,
3066 make_pure_c_string ("Wrong number of arguments"));
3067
3068 Fput (Qno_catch, Qerror_conditions,
3069 pure_cons (Qno_catch, error_tail));
3070 Fput (Qno_catch, Qerror_message,
3071 make_pure_c_string ("No catch for tag"));
3072
3073 Fput (Qend_of_file, Qerror_conditions,
3074 pure_cons (Qend_of_file, error_tail));
3075 Fput (Qend_of_file, Qerror_message,
3076 make_pure_c_string ("End of file during parsing"));
3077 3034
3078 arith_tail = pure_cons (Qarith_error, error_tail); 3035 arith_tail = pure_cons (Qarith_error, error_tail);
3079 Fput (Qarith_error, Qerror_conditions, 3036 Fput (Qarith_error, Qerror_conditions, arith_tail);
3080 arith_tail); 3037 Fput (Qarith_error, Qerror_message, make_pure_c_string ("Arithmetic error"));
3081 Fput (Qarith_error, Qerror_message, 3038
3082 make_pure_c_string ("Arithmetic error")); 3039 PUT_ERROR (Qbeginning_of_buffer, error_tail, "Beginning of buffer");
3083 3040 PUT_ERROR (Qend_of_buffer, error_tail, "End of buffer");
3084 Fput (Qbeginning_of_buffer, Qerror_conditions, 3041 PUT_ERROR (Qbuffer_read_only, error_tail, "Buffer is read-only");
3085 pure_cons (Qbeginning_of_buffer, error_tail)); 3042 PUT_ERROR (Qtext_read_only, pure_cons (Qbuffer_read_only, error_tail),
3086 Fput (Qbeginning_of_buffer, Qerror_message, 3043 "Text is read-only");
3087 make_pure_c_string ("Beginning of buffer"));
3088
3089 Fput (Qend_of_buffer, Qerror_conditions,
3090 pure_cons (Qend_of_buffer, error_tail));
3091 Fput (Qend_of_buffer, Qerror_message,
3092 make_pure_c_string ("End of buffer"));
3093
3094 Fput (Qbuffer_read_only, Qerror_conditions,
3095 pure_cons (Qbuffer_read_only, error_tail));
3096 Fput (Qbuffer_read_only, Qerror_message,
3097 make_pure_c_string ("Buffer is read-only"));
3098
3099 Fput (Qtext_read_only, Qerror_conditions,
3100 pure_cons (Qtext_read_only, error_tail));
3101 Fput (Qtext_read_only, Qerror_message,
3102 make_pure_c_string ("Text is read-only"));
3103 3044
3104 DEFSYM (Qrange_error, "range-error"); 3045 DEFSYM (Qrange_error, "range-error");
3105 DEFSYM (Qdomain_error, "domain-error"); 3046 DEFSYM (Qdomain_error, "domain-error");
@@ -3107,30 +3048,17 @@ syms_of_data (void)
3107 DEFSYM (Qoverflow_error, "overflow-error"); 3048 DEFSYM (Qoverflow_error, "overflow-error");
3108 DEFSYM (Qunderflow_error, "underflow-error"); 3049 DEFSYM (Qunderflow_error, "underflow-error");
3109 3050
3110 Fput (Qdomain_error, Qerror_conditions, 3051 PUT_ERROR (Qdomain_error, arith_tail, "Arithmetic domain error");
3111 pure_cons (Qdomain_error, arith_tail)); 3052
3112 Fput (Qdomain_error, Qerror_message, 3053 PUT_ERROR (Qrange_error, arith_tail, "Arithmetic range error");
3113 make_pure_c_string ("Arithmetic domain error")); 3054
3114 3055 PUT_ERROR (Qsingularity_error, Fcons (Qdomain_error, arith_tail),
3115 Fput (Qrange_error, Qerror_conditions, 3056 "Arithmetic singularity error");
3116 pure_cons (Qrange_error, arith_tail)); 3057
3117 Fput (Qrange_error, Qerror_message, 3058 PUT_ERROR (Qoverflow_error, Fcons (Qdomain_error, arith_tail),
3118 make_pure_c_string ("Arithmetic range error")); 3059 "Arithmetic overflow error");
3119 3060 PUT_ERROR (Qunderflow_error, Fcons (Qdomain_error, arith_tail),
3120 Fput (Qsingularity_error, Qerror_conditions, 3061 "Arithmetic underflow error");
3121 pure_cons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3122 Fput (Qsingularity_error, Qerror_message,
3123 make_pure_c_string ("Arithmetic singularity error"));
3124
3125 Fput (Qoverflow_error, Qerror_conditions,
3126 pure_cons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3127 Fput (Qoverflow_error, Qerror_message,
3128 make_pure_c_string ("Arithmetic overflow error"));
3129
3130 Fput (Qunderflow_error, Qerror_conditions,
3131 pure_cons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3132 Fput (Qunderflow_error, Qerror_message,
3133 make_pure_c_string ("Arithmetic underflow error"));
3134 3062
3135 staticpro (&Qnil); 3063 staticpro (&Qnil);
3136 staticpro (&Qt); 3064 staticpro (&Qt);
diff --git a/src/dbusbind.c b/src/dbusbind.c
index ad1a3f3cbe8..62923b462b5 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -28,19 +28,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28#include "keyboard.h" 28#include "keyboard.h"
29#include "process.h" 29#include "process.h"
30 30
31#ifndef DBUS_NUM_MESSAGE_TYPES
32#define DBUS_NUM_MESSAGE_TYPES 5
33#endif
34
31 35
32/* Subroutines. */ 36/* Subroutines. */
33static Lisp_Object Qdbus_init_bus; 37static Lisp_Object Qdbus_init_bus;
34static Lisp_Object Qdbus_close_bus;
35static Lisp_Object Qdbus_get_unique_name; 38static Lisp_Object Qdbus_get_unique_name;
36static Lisp_Object Qdbus_call_method; 39static Lisp_Object Qdbus_message_internal;
37static Lisp_Object Qdbus_call_method_asynchronously;
38static Lisp_Object Qdbus_method_return_internal;
39static Lisp_Object Qdbus_method_error_internal;
40static Lisp_Object Qdbus_send_signal;
41static Lisp_Object Qdbus_register_service;
42static Lisp_Object Qdbus_register_signal;
43static Lisp_Object Qdbus_register_method;
44 40
45/* D-Bus error symbol. */ 41/* D-Bus error symbol. */
46static Lisp_Object Qdbus_error; 42static Lisp_Object Qdbus_error;
@@ -51,17 +47,6 @@ static Lisp_Object QCdbus_system_bus, QCdbus_session_bus;
51/* Lisp symbol for method call timeout. */ 47/* Lisp symbol for method call timeout. */
52static Lisp_Object QCdbus_timeout; 48static Lisp_Object QCdbus_timeout;
53 49
54/* Lisp symbols for name request flags. */
55static Lisp_Object QCdbus_request_name_allow_replacement;
56static Lisp_Object QCdbus_request_name_replace_existing;
57static Lisp_Object QCdbus_request_name_do_not_queue;
58
59/* Lisp symbols for name request replies. */
60static Lisp_Object QCdbus_request_name_reply_primary_owner;
61static Lisp_Object QCdbus_request_name_reply_in_queue;
62static Lisp_Object QCdbus_request_name_reply_exists;
63static Lisp_Object QCdbus_request_name_reply_already_owner;
64
65/* Lisp symbols of D-Bus types. */ 50/* Lisp symbols of D-Bus types. */
66static Lisp_Object QCdbus_type_byte, QCdbus_type_boolean; 51static Lisp_Object QCdbus_type_byte, QCdbus_type_boolean;
67static Lisp_Object QCdbus_type_int16, QCdbus_type_uint16; 52static Lisp_Object QCdbus_type_int16, QCdbus_type_uint16;
@@ -75,6 +60,15 @@ static Lisp_Object QCdbus_type_unix_fd;
75static Lisp_Object QCdbus_type_array, QCdbus_type_variant; 60static Lisp_Object QCdbus_type_array, QCdbus_type_variant;
76static Lisp_Object QCdbus_type_struct, QCdbus_type_dict_entry; 61static Lisp_Object QCdbus_type_struct, QCdbus_type_dict_entry;
77 62
63/* Lisp symbols of objects in `dbus-registered-objects-table'. */
64static Lisp_Object QCdbus_registered_serial, QCdbus_registered_method;
65static Lisp_Object QCdbus_registered_signal;
66
67/* Alist of D-Bus buses we are polling for messages.
68 The key is the symbol or string of the bus, and the value is the
69 connection address. */
70static Lisp_Object xd_registered_buses;
71
78/* Whether we are reading a D-Bus event. */ 72/* Whether we are reading a D-Bus event. */
79static int xd_in_read_queued_messages = 0; 73static int xd_in_read_queued_messages = 0;
80 74
@@ -120,14 +114,15 @@ static int xd_in_read_queued_messages = 0;
120 } while (0) 114 } while (0)
121 115
122/* Macros for debugging. In order to enable them, build with 116/* Macros for debugging. In order to enable them, build with
123 "MYCPPFLAGS='-DDBUS_DEBUG -Wall' make". */ 117 "env MYCPPFLAGS='-DDBUS_DEBUG -Wall' make". */
124#ifdef DBUS_DEBUG 118#ifdef DBUS_DEBUG
125#define XD_DEBUG_MESSAGE(...) \ 119#define XD_DEBUG_MESSAGE(...) \
126 do { \ 120 do { \
127 char s[1024]; \ 121 char s[1024]; \
128 snprintf (s, sizeof s, __VA_ARGS__); \ 122 snprintf (s, sizeof s, __VA_ARGS__); \
129 printf ("%s: %s\n", __func__, s); \ 123 if (!noninteractive) \
130 message ("%s: %s", __func__, s); \ 124 printf ("%s: %s\n", __func__, s); \
125 message ("%s: %s", __func__, s); \
131 } while (0) 126 } while (0)
132#define XD_DEBUG_VALID_LISP_OBJECT_P(object) \ 127#define XD_DEBUG_VALID_LISP_OBJECT_P(object) \
133 do { \ 128 do { \
@@ -144,7 +139,7 @@ static int xd_in_read_queued_messages = 0;
144 if (!NILP (Vdbus_debug)) \ 139 if (!NILP (Vdbus_debug)) \
145 { \ 140 { \
146 char s[1024]; \ 141 char s[1024]; \
147 snprintf (s, 1023, __VA_ARGS__); \ 142 snprintf (s, sizeof s, __VA_ARGS__); \
148 message ("%s: %s", __func__, s); \ 143 message ("%s: %s", __func__, s); \
149 } \ 144 } \
150 } while (0) 145 } while (0)
@@ -241,23 +236,115 @@ xd_symbol_to_dbus_type (Lisp_Object object)
241#define XD_NEXT_VALUE(object) \ 236#define XD_NEXT_VALUE(object) \
242 ((XD_DBUS_TYPE_P (CAR_SAFE (object))) ? CDR_SAFE (object) : object) 237 ((XD_DBUS_TYPE_P (CAR_SAFE (object))) ? CDR_SAFE (object) : object)
243 238
239/* Transform the message type to its string representation for debug
240 messages. */
241#define XD_MESSAGE_TYPE_TO_STRING(mtype) \
242 ((mtype == DBUS_MESSAGE_TYPE_INVALID) \
243 ? "DBUS_MESSAGE_TYPE_INVALID" \
244 : (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) \
245 ? "DBUS_MESSAGE_TYPE_METHOD_CALL" \
246 : (mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN) \
247 ? "DBUS_MESSAGE_TYPE_METHOD_RETURN" \
248 : (mtype == DBUS_MESSAGE_TYPE_ERROR) \
249 ? "DBUS_MESSAGE_TYPE_ERROR" \
250 : "DBUS_MESSAGE_TYPE_SIGNAL")
251
252/* Transform the object to its string representation for debug
253 messages. */
254#define XD_OBJECT_TO_STRING(object) \
255 SDATA (format2 ("%s", object, Qnil))
256
244/* Check whether X is a valid dbus serial number. If valid, set 257/* Check whether X is a valid dbus serial number. If valid, set
245 SERIAL to its value. Otherwise, signal an error. */ 258 SERIAL to its value. Otherwise, signal an error. */
246#define CHECK_DBUS_SERIAL_GET_SERIAL(x, serial) \ 259#define XD_CHECK_DBUS_SERIAL(x, serial) \
247 do \ 260 do { \
248 { \ 261 dbus_uint32_t DBUS_SERIAL_MAX = -1; \
249 dbus_uint32_t DBUS_SERIAL_MAX = -1; \ 262 if (NATNUMP (x) && XINT (x) <= DBUS_SERIAL_MAX) \
250 if (NATNUMP (x) && XINT (x) <= DBUS_SERIAL_MAX) \ 263 serial = XINT (x); \
251 serial = XINT (x); \ 264 else if (MOST_POSITIVE_FIXNUM < DBUS_SERIAL_MAX \
252 else if (MOST_POSITIVE_FIXNUM < DBUS_SERIAL_MAX \ 265 && FLOATP (x) \
253 && FLOATP (x) \ 266 && 0 <= XFLOAT_DATA (x) \
254 && 0 <= XFLOAT_DATA (x) \ 267 && XFLOAT_DATA (x) <= DBUS_SERIAL_MAX) \
255 && XFLOAT_DATA (x) <= DBUS_SERIAL_MAX) \ 268 serial = XFLOAT_DATA (x); \
256 serial = XFLOAT_DATA (x); \ 269 else \
257 else \ 270 XD_SIGNAL2 (build_string ("Invalid dbus serial"), x); \
258 XD_SIGNAL2 (build_string ("Invalid dbus serial"), x); \ 271 } while (0)
259 } \ 272
260 while (0) 273#define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \
274 do { \
275 if (STRINGP (bus)) \
276 { \
277 DBusAddressEntry **entries; \
278 int len; \
279 DBusError derror; \
280 dbus_error_init (&derror); \
281 if (!dbus_parse_address (SSDATA (bus), &entries, &len, &derror)) \
282 XD_ERROR (derror); \
283 /* Cleanup. */ \
284 dbus_error_free (&derror); \
285 dbus_address_entries_free (entries); \
286 } \
287 \
288 else \
289 { \
290 CHECK_SYMBOL (bus); \
291 if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \
292 XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \
293 /* We do not want to have an autolaunch for the session bus. */ \
294 if (EQ (bus, QCdbus_session_bus) \
295 && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) \
296 XD_SIGNAL2 (build_string ("No connection to bus"), bus); \
297 } \
298 } while (0)
299
300#if (HAVE_DBUS_VALIDATE_BUS_NAME || HAVE_DBUS_VALIDATE_PATH \
301 || XD_DBUS_VALIDATE_OBJECT || HAVE_DBUS_VALIDATE_MEMBER)
302#define XD_DBUS_VALIDATE_OBJECT(object, func) \
303 do { \
304 if (!NILP (object)) \
305 { \
306 DBusError derror; \
307 CHECK_STRING (object); \
308 dbus_error_init (&derror); \
309 if (!func (SSDATA (object), &derror)) \
310 XD_ERROR (derror); \
311 /* Cleanup. */ \
312 dbus_error_free (&derror); \
313 } \
314 } while (0)
315#endif
316
317#if HAVE_DBUS_VALIDATE_BUS_NAME
318#define XD_DBUS_VALIDATE_BUS_NAME(bus_name) \
319 XD_DBUS_VALIDATE_OBJECT(bus_name, dbus_validate_bus_name);
320#else
321#define XD_DBUS_VALIDATE_BUS_NAME(bus_name) \
322 if (!NILP (bus_name)) CHECK_STRING (bus_name);
323#endif
324
325#if HAVE_DBUS_VALIDATE_PATH
326#define XD_DBUS_VALIDATE_PATH(path) \
327 XD_DBUS_VALIDATE_OBJECT(path, dbus_validate_path);
328#else
329#define XD_DBUS_VALIDATE_PATH(path) \
330 if (!NILP (path)) CHECK_STRING (path);
331#endif
332
333#if HAVE_DBUS_VALIDATE_INTERFACE
334#define XD_DBUS_VALIDATE_INTERFACE(interface) \
335 XD_DBUS_VALIDATE_OBJECT(interface, dbus_validate_interface);
336#else
337#define XD_DBUS_VALIDATE_INTERFACE(interface) \
338 if (!NILP (interface)) CHECK_STRING (interface);
339#endif
340
341#if HAVE_DBUS_VALIDATE_MEMBER
342#define XD_DBUS_VALIDATE_MEMBER(member) \
343 XD_DBUS_VALIDATE_OBJECT(member, dbus_validate_member);
344#else
345#define XD_DBUS_VALIDATE_MEMBER(member) \
346 if (!NILP (member)) CHECK_STRING (member);
347#endif
261 348
262/* Append to SIGNATURE a copy of X, making sure SIGNATURE does 349/* Append to SIGNATURE a copy of X, making sure SIGNATURE does
263 not become too long. */ 350 not become too long. */
@@ -293,11 +380,6 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
293 { 380 {
294 case DBUS_TYPE_BYTE: 381 case DBUS_TYPE_BYTE:
295 case DBUS_TYPE_UINT16: 382 case DBUS_TYPE_UINT16:
296 case DBUS_TYPE_UINT32:
297 case DBUS_TYPE_UINT64:
298#ifdef DBUS_TYPE_UNIX_FD
299 case DBUS_TYPE_UNIX_FD:
300#endif
301 CHECK_NATNUM (object); 383 CHECK_NATNUM (object);
302 sprintf (signature, "%c", dtype); 384 sprintf (signature, "%c", dtype);
303 break; 385 break;
@@ -309,14 +391,19 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
309 break; 391 break;
310 392
311 case DBUS_TYPE_INT16: 393 case DBUS_TYPE_INT16:
312 case DBUS_TYPE_INT32:
313 case DBUS_TYPE_INT64:
314 CHECK_NUMBER (object); 394 CHECK_NUMBER (object);
315 sprintf (signature, "%c", dtype); 395 sprintf (signature, "%c", dtype);
316 break; 396 break;
317 397
398 case DBUS_TYPE_UINT32:
399 case DBUS_TYPE_UINT64:
400#ifdef DBUS_TYPE_UNIX_FD
401 case DBUS_TYPE_UNIX_FD:
402#endif
403 case DBUS_TYPE_INT32:
404 case DBUS_TYPE_INT64:
318 case DBUS_TYPE_DOUBLE: 405 case DBUS_TYPE_DOUBLE:
319 CHECK_FLOAT (object); 406 CHECK_NUMBER_OR_FLOAT (object);
320 sprintf (signature, "%c", dtype); 407 sprintf (signature, "%c", dtype);
321 break; 408 break;
322 409
@@ -352,8 +439,8 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
352 } 439 }
353 440
354 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the 441 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the
355 only element, the value of this element is used as he array's 442 only element, the value of this element is used as the
356 element signature. */ 443 array's element signature. */
357 if ((subtype == DBUS_TYPE_SIGNATURE) 444 if ((subtype == DBUS_TYPE_SIGNATURE)
358 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt))) 445 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt)))
359 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 446 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
@@ -469,7 +556,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
469 CHECK_NATNUM (object); 556 CHECK_NATNUM (object);
470 { 557 {
471 unsigned char val = XFASTINT (object) & 0xFF; 558 unsigned char val = XFASTINT (object) & 0xFF;
472 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 559 XD_DEBUG_MESSAGE ("%c %u", dtype, val);
473 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 560 if (!dbus_message_iter_append_basic (iter, dtype, &val))
474 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 561 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
475 return; 562 return;
@@ -488,7 +575,8 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
488 CHECK_NUMBER (object); 575 CHECK_NUMBER (object);
489 { 576 {
490 dbus_int16_t val = XINT (object); 577 dbus_int16_t val = XINT (object);
491 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 578 int pval = val;
579 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
492 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 580 if (!dbus_message_iter_append_basic (iter, dtype, &val))
493 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 581 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
494 return; 582 return;
@@ -498,17 +586,18 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
498 CHECK_NATNUM (object); 586 CHECK_NATNUM (object);
499 { 587 {
500 dbus_uint16_t val = XFASTINT (object); 588 dbus_uint16_t val = XFASTINT (object);
501 XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); 589 unsigned int pval = val;
590 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
502 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 591 if (!dbus_message_iter_append_basic (iter, dtype, &val))
503 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 592 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
504 return; 593 return;
505 } 594 }
506 595
507 case DBUS_TYPE_INT32: 596 case DBUS_TYPE_INT32:
508 CHECK_NUMBER (object);
509 { 597 {
510 dbus_int32_t val = XINT (object); 598 dbus_int32_t val = extract_float (object);
511 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 599 int pval = val;
600 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
512 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 601 if (!dbus_message_iter_append_basic (iter, dtype, &val))
513 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 602 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
514 return; 603 return;
@@ -518,39 +607,38 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
518#ifdef DBUS_TYPE_UNIX_FD 607#ifdef DBUS_TYPE_UNIX_FD
519 case DBUS_TYPE_UNIX_FD: 608 case DBUS_TYPE_UNIX_FD:
520#endif 609#endif
521 CHECK_NATNUM (object);
522 { 610 {
523 dbus_uint32_t val = XFASTINT (object); 611 dbus_uint32_t val = extract_float (object);
524 XD_DEBUG_MESSAGE ("%c %u", dtype, val); 612 unsigned int pval = val;
613 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
525 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 614 if (!dbus_message_iter_append_basic (iter, dtype, &val))
526 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 615 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
527 return; 616 return;
528 } 617 }
529 618
530 case DBUS_TYPE_INT64: 619 case DBUS_TYPE_INT64:
531 CHECK_NUMBER (object);
532 { 620 {
533 dbus_int64_t val = XINT (object); 621 dbus_int64_t val = extract_float (object);
534 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 622 printmax_t pval = val;
623 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
535 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 624 if (!dbus_message_iter_append_basic (iter, dtype, &val))
536 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 625 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
537 return; 626 return;
538 } 627 }
539 628
540 case DBUS_TYPE_UINT64: 629 case DBUS_TYPE_UINT64:
541 CHECK_NATNUM (object);
542 { 630 {
543 dbus_uint64_t val = XFASTINT (object); 631 dbus_uint64_t val = extract_float (object);
544 XD_DEBUG_MESSAGE ("%c %"pI"d", dtype, XFASTINT (object)); 632 uprintmax_t pval = val;
633 XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval);
545 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 634 if (!dbus_message_iter_append_basic (iter, dtype, &val))
546 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 635 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
547 return; 636 return;
548 } 637 }
549 638
550 case DBUS_TYPE_DOUBLE: 639 case DBUS_TYPE_DOUBLE:
551 CHECK_FLOAT (object);
552 { 640 {
553 double val = XFLOAT_DATA (object); 641 double val = extract_float (object);
554 XD_DEBUG_MESSAGE ("%c %f", dtype, val); 642 XD_DEBUG_MESSAGE ("%c %f", dtype, val);
555 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 643 if (!dbus_message_iter_append_basic (iter, dtype, &val))
556 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 644 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
@@ -614,7 +702,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
614 dtype, CAR_SAFE (XD_NEXT_VALUE (object))); 702 dtype, CAR_SAFE (XD_NEXT_VALUE (object)));
615 703
616 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature, 704 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature,
617 SDATA (format2 ("%s", object, Qnil))); 705 XD_OBJECT_TO_STRING (object));
618 if (!dbus_message_iter_open_container (iter, dtype, 706 if (!dbus_message_iter_open_container (iter, dtype,
619 signature, &subiter)) 707 signature, &subiter))
620 XD_SIGNAL3 (build_string ("Cannot open container"), 708 XD_SIGNAL3 (build_string ("Cannot open container"),
@@ -627,7 +715,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
627 dtype, CAR_SAFE (XD_NEXT_VALUE (object))); 715 dtype, CAR_SAFE (XD_NEXT_VALUE (object)));
628 716
629 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature, 717 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature,
630 SDATA (format2 ("%s", object, Qnil))); 718 XD_OBJECT_TO_STRING (object));
631 if (!dbus_message_iter_open_container (iter, dtype, 719 if (!dbus_message_iter_open_container (iter, dtype,
632 signature, &subiter)) 720 signature, &subiter))
633 XD_SIGNAL3 (build_string ("Cannot open container"), 721 XD_SIGNAL3 (build_string ("Cannot open container"),
@@ -637,8 +725,7 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
637 case DBUS_TYPE_STRUCT: 725 case DBUS_TYPE_STRUCT:
638 case DBUS_TYPE_DICT_ENTRY: 726 case DBUS_TYPE_DICT_ENTRY:
639 /* These containers do not require a signature. */ 727 /* These containers do not require a signature. */
640 XD_DEBUG_MESSAGE ("%c %s", dtype, 728 XD_DEBUG_MESSAGE ("%c %s", dtype, XD_OBJECT_TO_STRING (object));
641 SDATA (format2 ("%s", object, Qnil)));
642 if (!dbus_message_iter_open_container (iter, dtype, NULL, &subiter)) 729 if (!dbus_message_iter_open_container (iter, dtype, NULL, &subiter))
643 XD_SIGNAL2 (build_string ("Cannot open container"), 730 XD_SIGNAL2 (build_string ("Cannot open container"),
644 make_number (dtype)); 731 make_number (dtype));
@@ -678,7 +765,7 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
678 unsigned int val; 765 unsigned int val;
679 dbus_message_iter_get_basic (iter, &val); 766 dbus_message_iter_get_basic (iter, &val);
680 val = val & 0xFF; 767 val = val & 0xFF;
681 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 768 XD_DEBUG_MESSAGE ("%c %u", dtype, val);
682 return make_number (val); 769 return make_number (val);
683 } 770 }
684 771
@@ -693,24 +780,30 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
693 case DBUS_TYPE_INT16: 780 case DBUS_TYPE_INT16:
694 { 781 {
695 dbus_int16_t val; 782 dbus_int16_t val;
783 int pval;
696 dbus_message_iter_get_basic (iter, &val); 784 dbus_message_iter_get_basic (iter, &val);
697 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 785 pval = val;
786 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
698 return make_number (val); 787 return make_number (val);
699 } 788 }
700 789
701 case DBUS_TYPE_UINT16: 790 case DBUS_TYPE_UINT16:
702 { 791 {
703 dbus_uint16_t val; 792 dbus_uint16_t val;
793 int pval;
704 dbus_message_iter_get_basic (iter, &val); 794 dbus_message_iter_get_basic (iter, &val);
705 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 795 pval = val;
796 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
706 return make_number (val); 797 return make_number (val);
707 } 798 }
708 799
709 case DBUS_TYPE_INT32: 800 case DBUS_TYPE_INT32:
710 { 801 {
711 dbus_int32_t val; 802 dbus_int32_t val;
803 int pval;
712 dbus_message_iter_get_basic (iter, &val); 804 dbus_message_iter_get_basic (iter, &val);
713 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 805 pval = val;
806 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
714 return make_fixnum_or_float (val); 807 return make_fixnum_or_float (val);
715 } 808 }
716 809
@@ -720,24 +813,30 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
720#endif 813#endif
721 { 814 {
722 dbus_uint32_t val; 815 dbus_uint32_t val;
816 unsigned int pval = val;
723 dbus_message_iter_get_basic (iter, &val); 817 dbus_message_iter_get_basic (iter, &val);
724 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 818 pval = val;
819 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
725 return make_fixnum_or_float (val); 820 return make_fixnum_or_float (val);
726 } 821 }
727 822
728 case DBUS_TYPE_INT64: 823 case DBUS_TYPE_INT64:
729 { 824 {
730 dbus_int64_t val; 825 dbus_int64_t val;
826 printmax_t pval;
731 dbus_message_iter_get_basic (iter, &val); 827 dbus_message_iter_get_basic (iter, &val);
732 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 828 pval = val;
829 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
733 return make_fixnum_or_float (val); 830 return make_fixnum_or_float (val);
734 } 831 }
735 832
736 case DBUS_TYPE_UINT64: 833 case DBUS_TYPE_UINT64:
737 { 834 {
738 dbus_uint64_t val; 835 dbus_uint64_t val;
836 uprintmax_t pval;
739 dbus_message_iter_get_basic (iter, &val); 837 dbus_message_iter_get_basic (iter, &val);
740 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 838 pval = val;
839 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
741 return make_fixnum_or_float (val); 840 return make_fixnum_or_float (val);
742 } 841 }
743 842
@@ -777,7 +876,7 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
777 result = Fcons (xd_retrieve_arg (subtype, &subiter), result); 876 result = Fcons (xd_retrieve_arg (subtype, &subiter), result);
778 dbus_message_iter_next (&subiter); 877 dbus_message_iter_next (&subiter);
779 } 878 }
780 XD_DEBUG_MESSAGE ("%c %s", dtype, SDATA (format2 ("%s", result, Qnil))); 879 XD_DEBUG_MESSAGE ("%c %s", dtype, XD_OBJECT_TO_STRING (result));
781 RETURN_UNGCPRO (Fnreverse (result)); 880 RETURN_UNGCPRO (Fnreverse (result));
782 } 881 }
783 882
@@ -787,85 +886,37 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
787 } 886 }
788} 887}
789 888
790/* Initialize D-Bus connection. BUS is either a Lisp symbol, :system 889/* Return the number of references of the shared CONNECTION. */
791 or :session, or a string denoting the bus address. It tells which 890static int
792 D-Bus to initialize. If RAISE_ERROR is non-zero, signal an error 891xd_get_connection_references (DBusConnection *connection)
793 when the connection cannot be initialized. */ 892{
893 ptrdiff_t *refcount;
894
895 /* We cannot access the DBusConnection structure, it is not public.
896 But we know, that the reference counter is the first field in
897 that structure. */
898 refcount = (void *) &connection;
899 refcount = (void *) *refcount;
900 return *refcount;
901}
902
903/* Return D-Bus connection address. BUS is either a Lisp symbol,
904 :system or :session, or a string denoting the bus address. */
794static DBusConnection * 905static DBusConnection *
795xd_initialize (Lisp_Object bus, int raise_error) 906xd_get_connection_address (Lisp_Object bus)
796{ 907{
797 DBusConnection *connection; 908 DBusConnection *connection;
798 DBusError derror; 909 Lisp_Object val;
799
800 /* Parameter check. */
801 if (!STRINGP (bus))
802 {
803 CHECK_SYMBOL (bus);
804 if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus)))
805 {
806 if (raise_error)
807 XD_SIGNAL2 (build_string ("Wrong bus name"), bus);
808 else
809 return NULL;
810 }
811
812 /* We do not want to have an autolaunch for the session bus. */
813 if (EQ (bus, QCdbus_session_bus)
814 && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL)
815 {
816 if (raise_error)
817 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
818 else
819 return NULL;
820 }
821 }
822 910
823 /* Open a connection to the bus. */ 911 val = CDR_SAFE (Fassoc (bus, xd_registered_buses));
824 dbus_error_init (&derror); 912 if (NILP (val))
825 913 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
826 if (STRINGP (bus))
827 connection = dbus_connection_open (SSDATA (bus), &derror);
828 else 914 else
829 if (EQ (bus, QCdbus_system_bus)) 915 connection = (DBusConnection *) (intptr_t) XFASTINT (val);
830 connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror);
831 else
832 connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
833
834 if (dbus_error_is_set (&derror))
835 {
836 if (raise_error)
837 XD_ERROR (derror);
838 else
839 connection = NULL;
840 }
841
842 /* If it is not the system or session bus, we must register
843 ourselves. Otherwise, we have called dbus_bus_get, which has
844 configured us to exit if the connection closes - we undo this
845 setting. */
846 if (connection != NULL)
847 {
848 if (STRINGP (bus))
849 dbus_bus_register (connection, &derror);
850 else
851 dbus_connection_set_exit_on_disconnect (connection, FALSE);
852 }
853
854 if (dbus_error_is_set (&derror))
855 {
856 if (raise_error)
857 XD_ERROR (derror);
858 else
859 connection = NULL;
860 }
861 916
862 if (connection == NULL && raise_error) 917 if (!dbus_connection_get_is_connected (connection))
863 XD_SIGNAL2 (build_string ("No connection to bus"), bus); 918 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
864 919
865 /* Cleanup. */
866 dbus_error_free (&derror);
867
868 /* Return the result. */
869 return connection; 920 return connection;
870} 921}
871 922
@@ -896,8 +947,8 @@ xd_add_watch (DBusWatch *watch, void *data)
896 int fd = xd_find_watch_fd (watch); 947 int fd = xd_find_watch_fd (watch);
897 948
898 XD_DEBUG_MESSAGE ("fd %d, write %d, enabled %d", 949 XD_DEBUG_MESSAGE ("fd %d, write %d, enabled %d",
899 fd, flags & DBUS_WATCH_WRITABLE, 950 fd, flags & DBUS_WATCH_WRITABLE,
900 dbus_watch_get_enabled (watch)); 951 dbus_watch_get_enabled (watch));
901 952
902 if (fd == -1) 953 if (fd == -1)
903 return FALSE; 954 return FALSE;
@@ -929,8 +980,8 @@ xd_remove_watch (DBusWatch *watch, void *data)
929 /* Unset session environment. */ 980 /* Unset session environment. */
930 if (XSYMBOL (QCdbus_session_bus) == data) 981 if (XSYMBOL (QCdbus_session_bus) == data)
931 { 982 {
932 XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS"); 983 // XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS");
933 unsetenv ("DBUS_SESSION_BUS_ADDRESS"); 984 // unsetenv ("DBUS_SESSION_BUS_ADDRESS");
934 } 985 }
935 986
936 if (flags & DBUS_WATCH_WRITABLE) 987 if (flags & DBUS_WATCH_WRITABLE)
@@ -949,23 +1000,111 @@ xd_toggle_watch (DBusWatch *watch, void *data)
949 xd_remove_watch (watch, data); 1000 xd_remove_watch (watch, data);
950} 1001}
951 1002
952DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 1, 0, 1003/* Close connection to D-Bus BUS. */
953 doc: /* Initialize connection to D-Bus BUS. */) 1004static void
954 (Lisp_Object bus) 1005xd_close_bus (Lisp_Object bus)
1006{
1007 DBusConnection *connection;
1008 Lisp_Object val;
1009
1010 /* Check whether we are connected. */
1011 val = Fassoc (bus, xd_registered_buses);
1012 if (NILP (val))
1013 return;
1014
1015 /* Retrieve bus address. */
1016 connection = xd_get_connection_address (bus);
1017
1018 /* Close connection, if there isn't another shared application. */
1019 if (xd_get_connection_references (connection) == 1)
1020 {
1021 XD_DEBUG_MESSAGE ("Close connection to bus %s",
1022 XD_OBJECT_TO_STRING (bus));
1023 dbus_connection_close (connection);
1024 }
1025
1026 /* Decrement reference count. */
1027 dbus_connection_unref (connection);
1028
1029 /* Remove bus from list of registered buses. */
1030 xd_registered_buses = Fdelete (val, xd_registered_buses);
1031
1032 /* Return. */
1033 return;
1034}
1035
1036DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 2, 0,
1037 doc: /* Establish the connection to D-Bus BUS.
1038
1039BUS can be either the symbol `:system' or the symbol `:session', or it
1040can be a string denoting the address of the corresponding bus. For
1041the system and session buses, this function is called when loading
1042`dbus.el', there is no need to call it again.
1043
1044The function returns a number, which counts the connections this Emacs
1045session has established to the BUS under the same unique name (see
1046`dbus-get-unique-name'). It depends on the libraries Emacs is linked
1047with, and on the environment Emacs is running. For example, if Emacs
1048is linked with the gtk toolkit, and it runs in a GTK-aware environment
1049like Gnome, another connection might already be established.
1050
1051When PRIVATE is non-nil, a new connection is established instead of
1052reusing an existing one. It results in a new unique name at the bus.
1053This can be used, if it is necessary to distinguish from another
1054connection used in the same Emacs process, like the one established by
1055GTK+. It should be used with care for at least the `:system' and
1056`:session' buses, because other Emacs Lisp packages might already use
1057this connection to those buses. */)
1058 (Lisp_Object bus, Lisp_Object private)
955{ 1059{
956 DBusConnection *connection; 1060 DBusConnection *connection;
957 void *busp; 1061 DBusError derror;
1062 Lisp_Object val;
1063 int refcount;
958 1064
959 /* Check parameter. */ 1065 /* Check parameter. */
960 if (SYMBOLP (bus)) 1066 XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
961 busp = XSYMBOL (bus); 1067
962 else if (STRINGP (bus)) 1068 /* Close bus if it is already open. */
963 busp = XSTRING (bus); 1069 xd_close_bus (bus);
1070
1071 /* Initialize. */
1072 dbus_error_init (&derror);
1073
1074 /* Open the connection. */
1075 if (STRINGP (bus))
1076 if (NILP (private))
1077 connection = dbus_connection_open (SSDATA (bus), &derror);
1078 else
1079 connection = dbus_connection_open_private (SSDATA (bus), &derror);
1080
1081 else
1082 if (NILP (private))
1083 connection = dbus_bus_get (EQ (bus, QCdbus_system_bus)
1084 ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
1085 &derror);
1086 else
1087 connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus)
1088 ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
1089 &derror);
1090
1091 if (dbus_error_is_set (&derror))
1092 XD_ERROR (derror);
1093
1094 if (connection == NULL)
1095 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
1096
1097 /* If it is not the system or session bus, we must register
1098 ourselves. Otherwise, we have called dbus_bus_get, which has
1099 configured us to exit if the connection closes - we undo this
1100 setting. */
1101 if (STRINGP (bus))
1102 dbus_bus_register (connection, &derror);
964 else 1103 else
965 wrong_type_argument (intern ("D-Bus"), bus); 1104 dbus_connection_set_exit_on_disconnect (connection, FALSE);
966 1105
967 /* Open a connection to the bus. */ 1106 if (dbus_error_is_set (&derror))
968 connection = xd_initialize (bus, TRUE); 1107 XD_ERROR (derror);
969 1108
970 /* Add the watch functions. We pass also the bus as data, in order 1109 /* Add the watch functions. We pass also the bus as data, in order
971 to distinguish between the buses in xd_remove_watch. */ 1110 to distinguish between the buses in xd_remove_watch. */
@@ -973,36 +1112,27 @@ DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 1, 0,
973 xd_add_watch, 1112 xd_add_watch,
974 xd_remove_watch, 1113 xd_remove_watch,
975 xd_toggle_watch, 1114 xd_toggle_watch,
976 busp, NULL)) 1115 SYMBOLP (bus)
1116 ? (void *) XSYMBOL (bus)
1117 : (void *) XSTRING (bus),
1118 NULL))
977 XD_SIGNAL1 (build_string ("Cannot add watch functions")); 1119 XD_SIGNAL1 (build_string ("Cannot add watch functions"));
978 1120
979 /* Add bus to list of registered buses. */ 1121 /* Add bus to list of registered buses. */
980 Vdbus_registered_buses = Fcons (bus, Vdbus_registered_buses); 1122 XSETFASTINT (val, (intptr_t) connection);
1123 xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses);
981 1124
982 /* We do not want to abort. */ 1125 /* We do not want to abort. */
983 putenv ((char *) "DBUS_FATAL_WARNINGS=0"); 1126 putenv ((char *) "DBUS_FATAL_WARNINGS=0");
984 1127
985 /* Return. */ 1128 /* Cleanup. */
986 return Qnil; 1129 dbus_error_free (&derror);
987}
988
989DEFUN ("dbus-close-bus", Fdbus_close_bus, Sdbus_close_bus, 1, 1, 0,
990 doc: /* Close connection to D-Bus BUS. */)
991 (Lisp_Object bus)
992{
993 DBusConnection *connection;
994
995 /* Open a connection to the bus. */
996 connection = xd_initialize (bus, TRUE);
997
998 /* Decrement reference count to the bus. */
999 dbus_connection_unref (connection);
1000
1001 /* Remove bus from list of registered buses. */
1002 Vdbus_registered_buses = Fdelete (bus, Vdbus_registered_buses);
1003 1130
1004 /* Return. */ 1131 /* Return reference counter. */
1005 return Qnil; 1132 refcount = xd_get_connection_references (connection);
1133 XD_DEBUG_MESSAGE ("Bus %s, Reference counter %d",
1134 XD_OBJECT_TO_STRING (bus), refcount);
1135 return make_number (refcount);
1006} 1136}
1007 1137
1008DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name, 1138DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
@@ -1013,8 +1143,11 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
1013 DBusConnection *connection; 1143 DBusConnection *connection;
1014 const char *name; 1144 const char *name;
1015 1145
1016 /* Open a connection to the bus. */ 1146 /* Check parameter. */
1017 connection = xd_initialize (bus, TRUE); 1147 XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
1148
1149 /* Retrieve bus address. */
1150 connection = xd_get_connection_address (bus);
1018 1151
1019 /* Request the name. */ 1152 /* Request the name. */
1020 name = dbus_bus_get_unique_name (connection); 1153 name = dbus_bus_get_unique_name (connection);
@@ -1025,341 +1158,243 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
1025 return build_string (name); 1158 return build_string (name);
1026} 1159}
1027 1160
1028DEFUN ("dbus-call-method", Fdbus_call_method, Sdbus_call_method, 5, MANY, 0, 1161DEFUN ("dbus-message-internal", Fdbus_message_internal, Sdbus_message_internal,
1029 doc: /* Call METHOD on the D-Bus BUS. 1162 4, MANY, 0,
1030 1163 doc: /* Send a D-Bus message.
1031BUS is either a Lisp symbol, `:system' or `:session', or a string 1164This is an internal function, it shall not be used outside dbus.el.
1032denoting the bus address. 1165
1033 1166The following usages are expected:
1034SERVICE is the D-Bus service name to be used. PATH is the D-Bus 1167
1035object path SERVICE is registered at. INTERFACE is an interface 1168`dbus-call-method', `dbus-call-method-asynchronously':
1036offered by SERVICE. It must provide METHOD. 1169 \(dbus-message-internal
1037 1170 dbus-message-type-method-call BUS SERVICE PATH INTERFACE METHOD HANDLER
1038If the parameter `:timeout' is given, the following integer TIMEOUT 1171 &optional :timeout TIMEOUT &rest ARGS)
1039specifies the maximum number of milliseconds the method call must 1172
1040return. The default value is 25,000. If the method call doesn't 1173`dbus-send-signal':
1041return in time, a D-Bus error is raised. 1174 \(dbus-message-internal
1042 1175 dbus-message-type-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS)
1043All other arguments ARGS are passed to METHOD as arguments. They are 1176
1044converted into D-Bus types via the following rules: 1177`dbus-method-return-internal':
1045 1178 \(dbus-message-internal
1046 t and nil => DBUS_TYPE_BOOLEAN 1179 dbus-message-type-method-return BUS SERVICE SERIAL &rest ARGS)
1047 number => DBUS_TYPE_UINT32 1180
1048 integer => DBUS_TYPE_INT32 1181`dbus-method-error-internal':
1049 float => DBUS_TYPE_DOUBLE 1182 \(dbus-message-internal
1050 string => DBUS_TYPE_STRING 1183 dbus-message-type-error BUS SERVICE SERIAL &rest ARGS)
1051 list => DBUS_TYPE_ARRAY 1184
1052 1185usage: (dbus-message-internal &rest REST) */)
1053All arguments can be preceded by a type symbol. For details about
1054type symbols, see Info node `(dbus)Type Conversion'.
1055
1056`dbus-call-method' returns the resulting values of METHOD as a list of
1057Lisp objects. The type conversion happens the other direction as for
1058input arguments. It follows the mapping rules:
1059
1060 DBUS_TYPE_BOOLEAN => t or nil
1061 DBUS_TYPE_BYTE => number
1062 DBUS_TYPE_UINT16 => number
1063 DBUS_TYPE_INT16 => integer
1064 DBUS_TYPE_UINT32 => number or float
1065 DBUS_TYPE_UNIX_FD => number or float
1066 DBUS_TYPE_INT32 => integer or float
1067 DBUS_TYPE_UINT64 => number or float
1068 DBUS_TYPE_INT64 => integer or float
1069 DBUS_TYPE_DOUBLE => float
1070 DBUS_TYPE_STRING => string
1071 DBUS_TYPE_OBJECT_PATH => string
1072 DBUS_TYPE_SIGNATURE => string
1073 DBUS_TYPE_ARRAY => list
1074 DBUS_TYPE_VARIANT => list
1075 DBUS_TYPE_STRUCT => list
1076 DBUS_TYPE_DICT_ENTRY => list
1077
1078Example:
1079
1080\(dbus-call-method
1081 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
1082 "org.gnome.seahorse.Keys" "GetKeyField"
1083 "openpgp:657984B8C7A966DD" "simple-name")
1084
1085 => (t ("Philip R. Zimmermann"))
1086
1087If the result of the METHOD call is just one value, the converted Lisp
1088object is returned instead of a list containing this single Lisp object.
1089
1090\(dbus-call-method
1091 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer"
1092 "org.freedesktop.Hal.Device" "GetPropertyString"
1093 "system.kernel.machine")
1094
1095 => "i686"
1096
1097usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TIMEOUT &rest ARGS) */)
1098 (ptrdiff_t nargs, Lisp_Object *args) 1186 (ptrdiff_t nargs, Lisp_Object *args)
1099{ 1187{
1100 Lisp_Object bus, service, path, interface, method; 1188 Lisp_Object message_type, bus, service, handler;
1189 Lisp_Object path = Qnil;
1190 Lisp_Object interface = Qnil;
1191 Lisp_Object member = Qnil;
1101 Lisp_Object result; 1192 Lisp_Object result;
1102 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 1193 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1103 DBusConnection *connection; 1194 DBusConnection *connection;
1104 DBusMessage *dmessage; 1195 DBusMessage *dmessage;
1105 DBusMessage *reply;
1106 DBusMessageIter iter; 1196 DBusMessageIter iter;
1107 DBusError derror;
1108 unsigned int dtype; 1197 unsigned int dtype;
1198 unsigned int mtype;
1199 dbus_uint32_t serial = 0;
1200 unsigned int ui_serial;
1109 int timeout = -1; 1201 int timeout = -1;
1110 ptrdiff_t i = 5; 1202 ptrdiff_t count;
1111 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 1203 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1112 1204
1205 /* Initialize parameters. */
1206 message_type = args[0];
1207 bus = args[1];
1208 service = args[2];
1209 handler = Qnil;
1210
1211 CHECK_NATNUM (message_type);
1212 mtype = XFASTINT (message_type);
1213 if ((mtype <= DBUS_MESSAGE_TYPE_INVALID) || (mtype >= DBUS_NUM_MESSAGE_TYPES))
1214 XD_SIGNAL2 (build_string ("Invalid message type"), message_type);
1215
1216 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1217 || (mtype == DBUS_MESSAGE_TYPE_SIGNAL))
1218 {
1219 path = args[3];
1220 interface = args[4];
1221 member = args[5];
1222 if (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1223 handler = args[6];
1224 count = (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) ? 7 : 6;
1225 }
1226 else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */
1227 {
1228 XD_CHECK_DBUS_SERIAL (args[3], serial);
1229 count = 4;
1230 }
1231
1113 /* Check parameters. */ 1232 /* Check parameters. */
1114 bus = args[0]; 1233 XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
1115 service = args[1]; 1234 XD_DBUS_VALIDATE_BUS_NAME (service);
1116 path = args[2]; 1235 if (nargs < count)
1117 interface = args[3]; 1236 xsignal2 (Qwrong_number_of_arguments,
1118 method = args[4]; 1237 Qdbus_message_internal,
1119 1238 make_number (nargs));
1120 CHECK_STRING (service); 1239
1121 CHECK_STRING (path); 1240 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1122 CHECK_STRING (interface); 1241 || (mtype == DBUS_MESSAGE_TYPE_SIGNAL))
1123 CHECK_STRING (method); 1242 {
1124 GCPRO5 (bus, service, path, interface, method); 1243 XD_DBUS_VALIDATE_PATH (path);
1125 1244 XD_DBUS_VALIDATE_INTERFACE (interface);
1126 XD_DEBUG_MESSAGE ("%s %s %s %s", 1245 XD_DBUS_VALIDATE_MEMBER (member);
1127 SDATA (service), 1246 if (!NILP (handler) && (!FUNCTIONP (handler)))
1128 SDATA (path), 1247 wrong_type_argument (Qinvalid_function, handler);
1129 SDATA (interface), 1248 }
1130 SDATA (method));
1131
1132 /* Open a connection to the bus. */
1133 connection = xd_initialize (bus, TRUE);
1134
1135 /* Create the message. */
1136 dmessage = dbus_message_new_method_call (SSDATA (service),
1137 SSDATA (path),
1138 SSDATA (interface),
1139 SSDATA (method));
1140 UNGCPRO;
1141 if (dmessage == NULL)
1142 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1143 1249
1144 /* Check for timeout parameter. */ 1250 /* Protect Lisp variables. */
1145 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) 1251 GCPRO6 (bus, service, path, interface, member, handler);
1252
1253 /* Trace parameters. */
1254 switch (mtype)
1146 { 1255 {
1147 CHECK_NATNUM (args[i+1]); 1256 case DBUS_MESSAGE_TYPE_METHOD_CALL:
1148 timeout = XFASTINT (args[i+1]); 1257 XD_DEBUG_MESSAGE ("%s %s %s %s %s %s %s",
1149 i = i+2; 1258 XD_MESSAGE_TYPE_TO_STRING (mtype),
1259 XD_OBJECT_TO_STRING (bus),
1260 XD_OBJECT_TO_STRING (service),
1261 XD_OBJECT_TO_STRING (path),
1262 XD_OBJECT_TO_STRING (interface),
1263 XD_OBJECT_TO_STRING (member),
1264 XD_OBJECT_TO_STRING (handler));
1265 break;
1266 case DBUS_MESSAGE_TYPE_SIGNAL:
1267 XD_DEBUG_MESSAGE ("%s %s %s %s %s %s",
1268 XD_MESSAGE_TYPE_TO_STRING (mtype),
1269 XD_OBJECT_TO_STRING (bus),
1270 XD_OBJECT_TO_STRING (service),
1271 XD_OBJECT_TO_STRING (path),
1272 XD_OBJECT_TO_STRING (interface),
1273 XD_OBJECT_TO_STRING (member));
1274 break;
1275 default: /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */
1276 ui_serial = serial;
1277 XD_DEBUG_MESSAGE ("%s %s %s %u",
1278 XD_MESSAGE_TYPE_TO_STRING (mtype),
1279 XD_OBJECT_TO_STRING (bus),
1280 XD_OBJECT_TO_STRING (service),
1281 ui_serial);
1150 } 1282 }
1151 1283
1152 /* Initialize parameter list of message. */ 1284 /* Retrieve bus address. */
1153 dbus_message_iter_init_append (dmessage, &iter); 1285 connection = xd_get_connection_address (bus);
1154 1286
1155 /* Append parameters to the message. */ 1287 /* Create the D-Bus message. */
1156 for (; i < nargs; ++i) 1288 dmessage = dbus_message_new (mtype);
1289 if (dmessage == NULL)
1290 {
1291 UNGCPRO;
1292 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1293 }
1294
1295 if (STRINGP (service))
1157 { 1296 {
1158 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]); 1297 if (mtype != DBUS_MESSAGE_TYPE_SIGNAL)
1159 if (XD_DBUS_TYPE_P (args[i])) 1298 /* Set destination. */
1160 { 1299 {
1161 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1300 if (!dbus_message_set_destination (dmessage, SSDATA (service)))
1162 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1301 {
1163 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4, 1302 UNGCPRO;
1164 SDATA (format2 ("%s", args[i], Qnil)), 1303 XD_SIGNAL2 (build_string ("Unable to set the destination"),
1165 SDATA (format2 ("%s", args[i+1], Qnil))); 1304 service);
1166 ++i; 1305 }
1167 } 1306 }
1307
1168 else 1308 else
1309 /* Set destination for unicast signals. */
1169 { 1310 {
1170 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1311 Lisp_Object uname;
1171 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
1172 SDATA (format2 ("%s", args[i], Qnil)));
1173 }
1174 1312
1175 /* Check for valid signature. We use DBUS_TYPE_INVALID as 1313 /* If it is the same unique name as we are registered at the
1176 indication that there is no parent type. */ 1314 bus or an unknown name, we regard it as broadcast message
1177 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); 1315 due to backward compatibility. */
1316 if (dbus_bus_name_has_owner (connection, SSDATA (service), NULL))
1317 uname = call2 (intern ("dbus-get-name-owner"), bus, service);
1318 else
1319 uname = Qnil;
1178 1320
1179 xd_append_arg (dtype, args[i], &iter); 1321 if (STRINGP (uname)
1322 && (strcmp (dbus_bus_get_unique_name (connection), SSDATA (uname))
1323 != 0)
1324 && (!dbus_message_set_destination (dmessage, SSDATA (service))))
1325 {
1326 UNGCPRO;
1327 XD_SIGNAL2 (build_string ("Unable to set signal destination"),
1328 service);
1329 }
1330 }
1180 } 1331 }
1181 1332
1182 /* Send the message. */ 1333 /* Set message parameters. */
1183 dbus_error_init (&derror); 1334 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1184 reply = dbus_connection_send_with_reply_and_block (connection, 1335 || (mtype == DBUS_MESSAGE_TYPE_SIGNAL))
1185 dmessage,
1186 timeout,
1187 &derror);
1188
1189 if (dbus_error_is_set (&derror))
1190 XD_ERROR (derror);
1191
1192 if (reply == NULL)
1193 XD_SIGNAL1 (build_string ("No reply"));
1194
1195 XD_DEBUG_MESSAGE ("Message sent");
1196
1197 /* Collect the results. */
1198 result = Qnil;
1199 GCPRO1 (result);
1200
1201 if (dbus_message_iter_init (reply, &iter))
1202 { 1336 {
1203 /* Loop over the parameters of the D-Bus reply message. Construct a 1337 if ((!dbus_message_set_path (dmessage, SSDATA (path)))
1204 Lisp list, which is returned by `dbus-call-method'. */ 1338 || (!dbus_message_set_interface (dmessage, SSDATA (interface)))
1205 while ((dtype = dbus_message_iter_get_arg_type (&iter)) 1339 || (!dbus_message_set_member (dmessage, SSDATA (member))))
1206 != DBUS_TYPE_INVALID)
1207 { 1340 {
1208 result = Fcons (xd_retrieve_arg (dtype, &iter), result); 1341 UNGCPRO;
1209 dbus_message_iter_next (&iter); 1342 XD_SIGNAL1 (build_string ("Unable to set the message parameter"));
1210 } 1343 }
1211 } 1344 }
1212 else
1213 {
1214 /* No arguments: just return nil. */
1215 }
1216
1217 /* Cleanup. */
1218 dbus_error_free (&derror);
1219 dbus_message_unref (dmessage);
1220 dbus_message_unref (reply);
1221
1222 /* Return the result. If there is only one single Lisp object,
1223 return it as-it-is, otherwise return the reversed list. */
1224 if (XFASTINT (Flength (result)) == 1)
1225 RETURN_UNGCPRO (CAR_SAFE (result));
1226 else
1227 RETURN_UNGCPRO (Fnreverse (result));
1228}
1229 1345
1230DEFUN ("dbus-call-method-asynchronously", Fdbus_call_method_asynchronously, 1346 else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */
1231 Sdbus_call_method_asynchronously, 6, MANY, 0, 1347 {
1232 doc: /* Call METHOD on the D-Bus BUS asynchronously. 1348 if (!dbus_message_set_reply_serial (dmessage, serial))
1233 1349 {
1234BUS is either a Lisp symbol, `:system' or `:session', or a string 1350 UNGCPRO;
1235denoting the bus address. 1351 XD_SIGNAL1 (build_string ("Unable to create a return message"));
1236 1352 }
1237SERVICE is the D-Bus service name to be used. PATH is the D-Bus
1238object path SERVICE is registered at. INTERFACE is an interface
1239offered by SERVICE. It must provide METHOD.
1240
1241HANDLER is a Lisp function, which is called when the corresponding
1242return message has arrived. If HANDLER is nil, no return message will
1243be expected.
1244
1245If the parameter `:timeout' is given, the following integer TIMEOUT
1246specifies the maximum number of milliseconds the method call must
1247return. The default value is 25,000. If the method call doesn't
1248return in time, a D-Bus error is raised.
1249
1250All other arguments ARGS are passed to METHOD as arguments. They are
1251converted into D-Bus types via the following rules:
1252
1253 t and nil => DBUS_TYPE_BOOLEAN
1254 number => DBUS_TYPE_UINT32
1255 integer => DBUS_TYPE_INT32
1256 float => DBUS_TYPE_DOUBLE
1257 string => DBUS_TYPE_STRING
1258 list => DBUS_TYPE_ARRAY
1259
1260All arguments can be preceded by a type symbol. For details about
1261type symbols, see Info node `(dbus)Type Conversion'.
1262
1263Unless HANDLER is nil, the function returns a key into the hash table
1264`dbus-registered-objects-table'. The corresponding entry in the hash
1265table is removed, when the return message has been arrived, and
1266HANDLER is called.
1267
1268Example:
1269
1270\(dbus-call-method-asynchronously
1271 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer"
1272 "org.freedesktop.Hal.Device" "GetPropertyString" 'message
1273 "system.kernel.machine")
1274
1275 => (:system 2)
1276
1277 -| i686
1278
1279usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLER &optional :timeout TIMEOUT &rest ARGS) */)
1280 (ptrdiff_t nargs, Lisp_Object *args)
1281{
1282 Lisp_Object bus, service, path, interface, method, handler;
1283 Lisp_Object result;
1284 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
1285 DBusConnection *connection;
1286 DBusMessage *dmessage;
1287 DBusMessageIter iter;
1288 unsigned int dtype;
1289 dbus_uint32_t serial;
1290 int timeout = -1;
1291 ptrdiff_t i = 6;
1292 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1293 1353
1294 /* Check parameters. */ 1354 if ((mtype == DBUS_MESSAGE_TYPE_ERROR)
1295 bus = args[0]; 1355 && (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED)))
1296 service = args[1]; 1356 {
1297 path = args[2]; 1357 UNGCPRO;
1298 interface = args[3]; 1358 XD_SIGNAL1 (build_string ("Unable to create a error message"));
1299 method = args[4]; 1359 }
1300 handler = args[5]; 1360 }
1301
1302 CHECK_STRING (service);
1303 CHECK_STRING (path);
1304 CHECK_STRING (interface);
1305 CHECK_STRING (method);
1306 if (!NILP (handler) && !FUNCTIONP (handler))
1307 wrong_type_argument (Qinvalid_function, handler);
1308 GCPRO6 (bus, service, path, interface, method, handler);
1309
1310 XD_DEBUG_MESSAGE ("%s %s %s %s",
1311 SDATA (service),
1312 SDATA (path),
1313 SDATA (interface),
1314 SDATA (method));
1315
1316 /* Open a connection to the bus. */
1317 connection = xd_initialize (bus, TRUE);
1318
1319 /* Create the message. */
1320 dmessage = dbus_message_new_method_call (SSDATA (service),
1321 SSDATA (path),
1322 SSDATA (interface),
1323 SSDATA (method));
1324 if (dmessage == NULL)
1325 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1326 1361
1327 /* Check for timeout parameter. */ 1362 /* Check for timeout parameter. */
1328 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) 1363 if ((count+2 <= nargs) && (EQ ((args[count]), QCdbus_timeout)))
1329 { 1364 {
1330 CHECK_NATNUM (args[i+1]); 1365 CHECK_NATNUM (args[count+1]);
1331 timeout = XFASTINT (args[i+1]); 1366 timeout = XFASTINT (args[count+1]);
1332 i = i+2; 1367 count = count+2;
1333 } 1368 }
1334 1369
1335 /* Initialize parameter list of message. */ 1370 /* Initialize parameter list of message. */
1336 dbus_message_iter_init_append (dmessage, &iter); 1371 dbus_message_iter_init_append (dmessage, &iter);
1337 1372
1338 /* Append parameters to the message. */ 1373 /* Append parameters to the message. */
1339 for (; i < nargs; ++i) 1374 for (; count < nargs; ++count)
1340 { 1375 {
1341 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]); 1376 dtype = XD_OBJECT_TO_DBUS_TYPE (args[count]);
1342 if (XD_DBUS_TYPE_P (args[i])) 1377 if (XD_DBUS_TYPE_P (args[count]))
1343 { 1378 {
1344 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1379 XD_DEBUG_VALID_LISP_OBJECT_P (args[count]);
1345 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); 1380 XD_DEBUG_VALID_LISP_OBJECT_P (args[count+1]);
1346 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4, 1381 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", count - 4,
1347 SDATA (format2 ("%s", args[i], Qnil)), 1382 XD_OBJECT_TO_STRING (args[count]),
1348 SDATA (format2 ("%s", args[i+1], Qnil))); 1383 XD_OBJECT_TO_STRING (args[count+1]));
1349 ++i; 1384 ++count;
1350 } 1385 }
1351 else 1386 else
1352 { 1387 {
1353 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); 1388 XD_DEBUG_VALID_LISP_OBJECT_P (args[count]);
1354 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4, 1389 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", count - 4,
1355 SDATA (format2 ("%s", args[i], Qnil))); 1390 XD_OBJECT_TO_STRING (args[count]));
1356 } 1391 }
1357 1392
1358 /* Check for valid signature. We use DBUS_TYPE_INVALID as 1393 /* Check for valid signature. We use DBUS_TYPE_INVALID as
1359 indication that there is no parent type. */ 1394 indication that there is no parent type. */
1360 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); 1395 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[count]);
1361 1396
1362 xd_append_arg (dtype, args[i], &iter); 1397 xd_append_arg (dtype, args[count], &iter);
1363 } 1398 }
1364 1399
1365 if (!NILP (handler)) 1400 if (!NILP (handler))
@@ -1368,11 +1403,15 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1368 message queue. */ 1403 message queue. */
1369 if (!dbus_connection_send_with_reply (connection, dmessage, 1404 if (!dbus_connection_send_with_reply (connection, dmessage,
1370 NULL, timeout)) 1405 NULL, timeout))
1371 XD_SIGNAL1 (build_string ("Cannot send message")); 1406 {
1407 UNGCPRO;
1408 XD_SIGNAL1 (build_string ("Cannot send message"));
1409 }
1372 1410
1373 /* The result is the key in Vdbus_registered_objects_table. */ 1411 /* The result is the key in Vdbus_registered_objects_table. */
1374 serial = dbus_message_get_serial (dmessage); 1412 serial = dbus_message_get_serial (dmessage);
1375 result = list2 (bus, make_fixnum_or_float (serial)); 1413 result = list3 (QCdbus_registered_serial,
1414 bus, make_fixnum_or_float (serial));
1376 1415
1377 /* Create a hash table entry. */ 1416 /* Create a hash table entry. */
1378 Fputhash (result, handler, Vdbus_registered_objects_table); 1417 Fputhash (result, handler, Vdbus_registered_objects_table);
@@ -1382,12 +1421,15 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1382 /* Send the message. The message is just added to the outgoing 1421 /* Send the message. The message is just added to the outgoing
1383 message queue. */ 1422 message queue. */
1384 if (!dbus_connection_send (connection, dmessage, NULL)) 1423 if (!dbus_connection_send (connection, dmessage, NULL))
1385 XD_SIGNAL1 (build_string ("Cannot send message")); 1424 {
1425 UNGCPRO;
1426 XD_SIGNAL1 (build_string ("Cannot send message"));
1427 }
1386 1428
1387 result = Qnil; 1429 result = Qnil;
1388 } 1430 }
1389 1431
1390 XD_DEBUG_MESSAGE ("Message sent"); 1432 XD_DEBUG_MESSAGE ("Message sent: %s", XD_OBJECT_TO_STRING (result));
1391 1433
1392 /* Cleanup. */ 1434 /* Cleanup. */
1393 dbus_message_unref (dmessage); 1435 dbus_message_unref (dmessage);
@@ -1396,300 +1438,6 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1396 RETURN_UNGCPRO (result); 1438 RETURN_UNGCPRO (result);
1397} 1439}
1398 1440
1399DEFUN ("dbus-method-return-internal", Fdbus_method_return_internal,
1400 Sdbus_method_return_internal,
1401 3, MANY, 0,
1402 doc: /* Return for message SERIAL on the D-Bus BUS.
1403This is an internal function, it shall not be used outside dbus.el.
1404
1405usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1406 (ptrdiff_t nargs, Lisp_Object *args)
1407{
1408 Lisp_Object bus, service;
1409 struct gcpro gcpro1, gcpro2;
1410 DBusConnection *connection;
1411 DBusMessage *dmessage;
1412 DBusMessageIter iter;
1413 dbus_uint32_t serial;
1414 unsigned int ui_serial, dtype;
1415 ptrdiff_t i;
1416 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1417
1418 /* Check parameters. */
1419 bus = args[0];
1420 service = args[2];
1421
1422 CHECK_DBUS_SERIAL_GET_SERIAL (args[1], serial);
1423 CHECK_STRING (service);
1424 GCPRO2 (bus, service);
1425
1426 ui_serial = serial;
1427 XD_DEBUG_MESSAGE ("%u %s ", ui_serial, SSDATA (service));
1428
1429 /* Open a connection to the bus. */
1430 connection = xd_initialize (bus, TRUE);
1431
1432 /* Create the message. */
1433 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN);
1434 if ((dmessage == NULL)
1435 || (!dbus_message_set_reply_serial (dmessage, serial))
1436 || (!dbus_message_set_destination (dmessage, SSDATA (service))))
1437 {
1438 UNGCPRO;
1439 XD_SIGNAL1 (build_string ("Unable to create a return message"));
1440 }
1441
1442 UNGCPRO;
1443
1444 /* Initialize parameter list of message. */
1445 dbus_message_iter_init_append (dmessage, &iter);
1446
1447 /* Append parameters to the message. */
1448 for (i = 3; i < nargs; ++i)
1449 {
1450 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]);
1451 if (XD_DBUS_TYPE_P (args[i]))
1452 {
1453 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1454 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1455 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
1456 SDATA (format2 ("%s", args[i], Qnil)),
1457 SDATA (format2 ("%s", args[i+1], Qnil)));
1458 ++i;
1459 }
1460 else
1461 {
1462 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1463 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
1464 SDATA (format2 ("%s", args[i], Qnil)));
1465 }
1466
1467 /* Check for valid signature. We use DBUS_TYPE_INVALID as
1468 indication that there is no parent type. */
1469 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
1470
1471 xd_append_arg (dtype, args[i], &iter);
1472 }
1473
1474 /* Send the message. The message is just added to the outgoing
1475 message queue. */
1476 if (!dbus_connection_send (connection, dmessage, NULL))
1477 XD_SIGNAL1 (build_string ("Cannot send message"));
1478
1479 XD_DEBUG_MESSAGE ("Message sent");
1480
1481 /* Cleanup. */
1482 dbus_message_unref (dmessage);
1483
1484 /* Return. */
1485 return Qt;
1486}
1487
1488DEFUN ("dbus-method-error-internal", Fdbus_method_error_internal,
1489 Sdbus_method_error_internal,
1490 3, MANY, 0,
1491 doc: /* Return error message for message SERIAL on the D-Bus BUS.
1492This is an internal function, it shall not be used outside dbus.el.
1493
1494usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1495 (ptrdiff_t nargs, Lisp_Object *args)
1496{
1497 Lisp_Object bus, service;
1498 struct gcpro gcpro1, gcpro2;
1499 DBusConnection *connection;
1500 DBusMessage *dmessage;
1501 DBusMessageIter iter;
1502 dbus_uint32_t serial;
1503 unsigned int ui_serial, dtype;
1504 ptrdiff_t i;
1505 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1506
1507 /* Check parameters. */
1508 bus = args[0];
1509 service = args[2];
1510
1511 CHECK_DBUS_SERIAL_GET_SERIAL (args[1], serial);
1512 CHECK_STRING (service);
1513 GCPRO2 (bus, service);
1514
1515 ui_serial = serial;
1516 XD_DEBUG_MESSAGE ("%u %s ", ui_serial, SSDATA (service));
1517
1518 /* Open a connection to the bus. */
1519 connection = xd_initialize (bus, TRUE);
1520
1521 /* Create the message. */
1522 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1523 if ((dmessage == NULL)
1524 || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED))
1525 || (!dbus_message_set_reply_serial (dmessage, serial))
1526 || (!dbus_message_set_destination (dmessage, SSDATA (service))))
1527 {
1528 UNGCPRO;
1529 XD_SIGNAL1 (build_string ("Unable to create a error message"));
1530 }
1531
1532 UNGCPRO;
1533
1534 /* Initialize parameter list of message. */
1535 dbus_message_iter_init_append (dmessage, &iter);
1536
1537 /* Append parameters to the message. */
1538 for (i = 3; i < nargs; ++i)
1539 {
1540 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]);
1541 if (XD_DBUS_TYPE_P (args[i]))
1542 {
1543 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1544 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1545 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
1546 SDATA (format2 ("%s", args[i], Qnil)),
1547 SDATA (format2 ("%s", args[i+1], Qnil)));
1548 ++i;
1549 }
1550 else
1551 {
1552 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1553 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
1554 SDATA (format2 ("%s", args[i], Qnil)));
1555 }
1556
1557 /* Check for valid signature. We use DBUS_TYPE_INVALID as
1558 indication that there is no parent type. */
1559 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
1560
1561 xd_append_arg (dtype, args[i], &iter);
1562 }
1563
1564 /* Send the message. The message is just added to the outgoing
1565 message queue. */
1566 if (!dbus_connection_send (connection, dmessage, NULL))
1567 XD_SIGNAL1 (build_string ("Cannot send message"));
1568
1569 XD_DEBUG_MESSAGE ("Message sent");
1570
1571 /* Cleanup. */
1572 dbus_message_unref (dmessage);
1573
1574 /* Return. */
1575 return Qt;
1576}
1577
1578DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0,
1579 doc: /* Send signal SIGNAL on the D-Bus BUS.
1580
1581BUS is either a Lisp symbol, `:system' or `:session', or a string
1582denoting the bus address.
1583
1584SERVICE is the D-Bus service name SIGNAL is sent from. PATH is the
1585D-Bus object path SERVICE is registered at. INTERFACE is an interface
1586offered by SERVICE. It must provide signal SIGNAL.
1587
1588All other arguments ARGS are passed to SIGNAL as arguments. They are
1589converted into D-Bus types via the following rules:
1590
1591 t and nil => DBUS_TYPE_BOOLEAN
1592 number => DBUS_TYPE_UINT32
1593 integer => DBUS_TYPE_INT32
1594 float => DBUS_TYPE_DOUBLE
1595 string => DBUS_TYPE_STRING
1596 list => DBUS_TYPE_ARRAY
1597
1598All arguments can be preceded by a type symbol. For details about
1599type symbols, see Info node `(dbus)Type Conversion'.
1600
1601Example:
1602
1603\(dbus-send-signal
1604 :session "org.gnu.Emacs" "/org/gnu/Emacs"
1605 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
1606
1607usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1608 (ptrdiff_t nargs, Lisp_Object *args)
1609{
1610 Lisp_Object bus, service, path, interface, signal;
1611 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
1612 DBusConnection *connection;
1613 DBusMessage *dmessage;
1614 DBusMessageIter iter;
1615 unsigned int dtype;
1616 ptrdiff_t i;
1617 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
1618
1619 /* Check parameters. */
1620 bus = args[0];
1621 service = args[1];
1622 path = args[2];
1623 interface = args[3];
1624 signal = args[4];
1625
1626 CHECK_STRING (service);
1627 CHECK_STRING (path);
1628 CHECK_STRING (interface);
1629 CHECK_STRING (signal);
1630 GCPRO5 (bus, service, path, interface, signal);
1631
1632 XD_DEBUG_MESSAGE ("%s %s %s %s",
1633 SDATA (service),
1634 SDATA (path),
1635 SDATA (interface),
1636 SDATA (signal));
1637
1638 /* Open a connection to the bus. */
1639 connection = xd_initialize (bus, TRUE);
1640
1641 /* Create the message. */
1642 dmessage = dbus_message_new_signal (SSDATA (path),
1643 SSDATA (interface),
1644 SSDATA (signal));
1645 UNGCPRO;
1646 if (dmessage == NULL)
1647 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1648
1649 /* Initialize parameter list of message. */
1650 dbus_message_iter_init_append (dmessage, &iter);
1651
1652 /* Append parameters to the message. */
1653 for (i = 5; i < nargs; ++i)
1654 {
1655 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]);
1656 if (XD_DBUS_TYPE_P (args[i]))
1657 {
1658 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1659 XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
1660 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
1661 SDATA (format2 ("%s", args[i], Qnil)),
1662 SDATA (format2 ("%s", args[i+1], Qnil)));
1663 ++i;
1664 }
1665 else
1666 {
1667 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
1668 XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
1669 SDATA (format2 ("%s", args[i], Qnil)));
1670 }
1671
1672 /* Check for valid signature. We use DBUS_TYPE_INVALID as
1673 indication that there is no parent type. */
1674 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
1675
1676 xd_append_arg (dtype, args[i], &iter);
1677 }
1678
1679 /* Send the message. The message is just added to the outgoing
1680 message queue. */
1681 if (!dbus_connection_send (connection, dmessage, NULL))
1682 XD_SIGNAL1 (build_string ("Cannot send message"));
1683
1684 XD_DEBUG_MESSAGE ("Signal sent");
1685
1686 /* Cleanup. */
1687 dbus_message_unref (dmessage);
1688
1689 /* Return. */
1690 return Qt;
1691}
1692
1693/* Read one queued incoming message of the D-Bus BUS. 1441/* Read one queued incoming message of the D-Bus BUS.
1694 BUS is either a Lisp symbol, :system or :session, or a string denoting 1442 BUS is either a Lisp symbol, :system or :session, or a string denoting
1695 the bus address. */ 1443 the bus address. */
@@ -1702,7 +1450,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1702 DBusMessage *dmessage; 1450 DBusMessage *dmessage;
1703 DBusMessageIter iter; 1451 DBusMessageIter iter;
1704 unsigned int dtype; 1452 unsigned int dtype;
1705 int mtype; 1453 unsigned int mtype;
1706 dbus_uint32_t serial; 1454 dbus_uint32_t serial;
1707 unsigned int ui_serial; 1455 unsigned int ui_serial;
1708 const char *uname, *path, *interface, *member; 1456 const char *uname, *path, *interface, *member;
@@ -1744,23 +1492,19 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1744 member = dbus_message_get_member (dmessage); 1492 member = dbus_message_get_member (dmessage);
1745 1493
1746 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s", 1494 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s",
1747 (mtype == DBUS_MESSAGE_TYPE_INVALID) 1495 XD_MESSAGE_TYPE_TO_STRING (mtype),
1748 ? "DBUS_MESSAGE_TYPE_INVALID"
1749 : (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1750 ? "DBUS_MESSAGE_TYPE_METHOD_CALL"
1751 : (mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN)
1752 ? "DBUS_MESSAGE_TYPE_METHOD_RETURN"
1753 : (mtype == DBUS_MESSAGE_TYPE_ERROR)
1754 ? "DBUS_MESSAGE_TYPE_ERROR"
1755 : "DBUS_MESSAGE_TYPE_SIGNAL",
1756 ui_serial, uname, path, interface, member, 1496 ui_serial, uname, path, interface, member,
1757 SDATA (format2 ("%s", args, Qnil))); 1497 XD_OBJECT_TO_STRING (args));
1498
1499 if (mtype == DBUS_MESSAGE_TYPE_INVALID)
1500 goto cleanup;
1758 1501
1759 if ((mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN) 1502 else if ((mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN)
1760 || (mtype == DBUS_MESSAGE_TYPE_ERROR)) 1503 || (mtype == DBUS_MESSAGE_TYPE_ERROR))
1761 { 1504 {
1762 /* Search for a registered function of the message. */ 1505 /* Search for a registered function of the message. */
1763 key = list2 (bus, make_fixnum_or_float (serial)); 1506 key = list3 (QCdbus_registered_serial, bus,
1507 make_fixnum_or_float (serial));
1764 value = Fgethash (key, Vdbus_registered_objects_table, Qnil); 1508 value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
1765 1509
1766 /* There shall be exactly one entry. Construct an event. */ 1510 /* There shall be exactly one entry. Construct an event. */
@@ -1777,7 +1521,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1777 event.arg = Fcons (value, args); 1521 event.arg = Fcons (value, args);
1778 } 1522 }
1779 1523
1780 else /* (mtype != DBUS_MESSAGE_TYPE_METHOD_RETURN) */ 1524 else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */
1781 { 1525 {
1782 /* Vdbus_registered_objects_table requires non-nil interface and 1526 /* Vdbus_registered_objects_table requires non-nil interface and
1783 member. */ 1527 member. */
@@ -1785,7 +1529,10 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1785 goto cleanup; 1529 goto cleanup;
1786 1530
1787 /* Search for a registered function of the message. */ 1531 /* Search for a registered function of the message. */
1788 key = list3 (bus, build_string (interface), build_string (member)); 1532 key = list4 ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
1533 ? QCdbus_registered_method
1534 : QCdbus_registered_signal,
1535 bus, build_string (interface), build_string (member));
1789 value = Fgethash (key, Vdbus_registered_objects_table, Qnil); 1536 value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
1790 1537
1791 /* Loop over the registered functions. Construct an event. */ 1538 /* Loop over the registered functions. Construct an event. */
@@ -1835,8 +1582,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1835 /* Store it into the input event queue. */ 1582 /* Store it into the input event queue. */
1836 kbd_buffer_store_event (&event); 1583 kbd_buffer_store_event (&event);
1837 1584
1838 XD_DEBUG_MESSAGE ("Event stored: %s", 1585 XD_DEBUG_MESSAGE ("Event stored: %s", XD_OBJECT_TO_STRING (event.arg));
1839 SDATA (format2 ("%s", event.arg, Qnil)));
1840 1586
1841 /* Cleanup. */ 1587 /* Cleanup. */
1842 cleanup: 1588 cleanup:
@@ -1851,8 +1597,8 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1851static Lisp_Object 1597static Lisp_Object
1852xd_read_message (Lisp_Object bus) 1598xd_read_message (Lisp_Object bus)
1853{ 1599{
1854 /* Open a connection to the bus. */ 1600 /* Retrieve bus address. */
1855 DBusConnection *connection = xd_initialize (bus, TRUE); 1601 DBusConnection *connection = xd_get_connection_address (bus);
1856 1602
1857 /* Non blocking read of the next available message. */ 1603 /* Non blocking read of the next available message. */
1858 dbus_connection_read_write (connection, 0); 1604 dbus_connection_read_write (connection, 0);
@@ -1867,16 +1613,18 @@ xd_read_message (Lisp_Object bus)
1867static void 1613static void
1868xd_read_queued_messages (int fd, void *data, int for_read) 1614xd_read_queued_messages (int fd, void *data, int for_read)
1869{ 1615{
1870 Lisp_Object busp = Vdbus_registered_buses; 1616 Lisp_Object busp = xd_registered_buses;
1871 Lisp_Object bus = Qnil; 1617 Lisp_Object bus = Qnil;
1618 Lisp_Object key;
1872 1619
1873 /* Find bus related to fd. */ 1620 /* Find bus related to fd. */
1874 if (data != NULL) 1621 if (data != NULL)
1875 while (!NILP (busp)) 1622 while (!NILP (busp))
1876 { 1623 {
1877 if ((SYMBOLP (CAR_SAFE (busp)) && XSYMBOL (CAR_SAFE (busp)) == data) 1624 key = CAR_SAFE (CAR_SAFE (busp));
1878 || (STRINGP (CAR_SAFE (busp)) && XSTRING (CAR_SAFE (busp)) == data)) 1625 if ((SYMBOLP (key) && XSYMBOL (key) == data)
1879 bus = CAR_SAFE (busp); 1626 || (STRINGP (key) && XSTRING (key) == data))
1627 bus = key;
1880 busp = CDR_SAFE (busp); 1628 busp = CDR_SAFE (busp);
1881 } 1629 }
1882 1630
@@ -1889,327 +1637,6 @@ xd_read_queued_messages (int fd, void *data, int for_read)
1889 xd_in_read_queued_messages = 0; 1637 xd_in_read_queued_messages = 0;
1890} 1638}
1891 1639
1892DEFUN ("dbus-register-service", Fdbus_register_service, Sdbus_register_service,
1893 2, MANY, 0,
1894 doc: /* Register known name SERVICE on the D-Bus BUS.
1895
1896BUS is either a Lisp symbol, `:system' or `:session', or a string
1897denoting the bus address.
1898
1899SERVICE is the D-Bus service name that should be registered. It must
1900be a known name.
1901
1902FLAGS are keywords, which control how the service name is registered.
1903The following keywords are recognized:
1904
1905`:allow-replacement': Allow another service to become the primary
1906owner if requested.
1907
1908`:replace-existing': Request to replace the current primary owner.
1909
1910`:do-not-queue': If we can not become the primary owner do not place
1911us in the queue.
1912
1913The function returns a keyword, indicating the result of the
1914operation. One of the following keywords is returned:
1915
1916`:primary-owner': Service has become the primary owner of the
1917requested name.
1918
1919`:in-queue': Service could not become the primary owner and has been
1920placed in the queue.
1921
1922`:exists': Service is already in the queue.
1923
1924`:already-owner': Service is already the primary owner.
1925
1926Example:
1927
1928\(dbus-register-service :session dbus-service-emacs)
1929
1930 => :primary-owner.
1931
1932\(dbus-register-service
1933 :session "org.freedesktop.TextEditor"
1934 dbus-service-allow-replacement dbus-service-replace-existing)
1935
1936 => :already-owner.
1937
1938usage: (dbus-register-service BUS SERVICE &rest FLAGS) */)
1939 (ptrdiff_t nargs, Lisp_Object *args)
1940{
1941 Lisp_Object bus, service;
1942 DBusConnection *connection;
1943 ptrdiff_t i;
1944 unsigned int value;
1945 unsigned int flags = 0;
1946 int result;
1947 DBusError derror;
1948
1949 bus = args[0];
1950 service = args[1];
1951
1952 /* Check parameters. */
1953 CHECK_STRING (service);
1954
1955 /* Process flags. */
1956 for (i = 2; i < nargs; ++i) {
1957 value = ((EQ (args[i], QCdbus_request_name_replace_existing))
1958 ? DBUS_NAME_FLAG_REPLACE_EXISTING
1959 : (EQ (args[i], QCdbus_request_name_allow_replacement))
1960 ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT
1961 : (EQ (args[i], QCdbus_request_name_do_not_queue))
1962 ? DBUS_NAME_FLAG_DO_NOT_QUEUE
1963 : -1);
1964 if (value == -1)
1965 XD_SIGNAL2 (build_string ("Unrecognized name request flag"), args[i]);
1966 flags |= value;
1967 }
1968
1969 /* Open a connection to the bus. */
1970 connection = xd_initialize (bus, TRUE);
1971
1972 /* Request the known name from the bus. */
1973 dbus_error_init (&derror);
1974 result = dbus_bus_request_name (connection, SSDATA (service), flags,
1975 &derror);
1976 if (dbus_error_is_set (&derror))
1977 XD_ERROR (derror);
1978
1979 /* Cleanup. */
1980 dbus_error_free (&derror);
1981
1982 /* Return object. */
1983 switch (result)
1984 {
1985 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
1986 return QCdbus_request_name_reply_primary_owner;
1987 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
1988 return QCdbus_request_name_reply_in_queue;
1989 case DBUS_REQUEST_NAME_REPLY_EXISTS:
1990 return QCdbus_request_name_reply_exists;
1991 case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
1992 return QCdbus_request_name_reply_already_owner;
1993 default:
1994 /* This should not happen. */
1995 XD_SIGNAL2 (build_string ("Could not register service"), service);
1996 }
1997}
1998
1999DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal,
2000 6, MANY, 0,
2001 doc: /* Register for signal SIGNAL on the D-Bus BUS.
2002
2003BUS is either a Lisp symbol, `:system' or `:session', or a string
2004denoting the bus address.
2005
2006SERVICE is the D-Bus service name used by the sending D-Bus object.
2007It can be either a known name or the unique name of the D-Bus object
2008sending the signal. When SERVICE is nil, related signals from all
2009D-Bus objects shall be accepted.
2010
2011PATH is the D-Bus object path SERVICE is registered. It can also be
2012nil if the path name of incoming signals shall not be checked.
2013
2014INTERFACE is an interface offered by SERVICE. It must provide SIGNAL.
2015HANDLER is a Lisp function to be called when the signal is received.
2016It must accept as arguments the values SIGNAL is sending.
2017
2018All other arguments ARGS, if specified, must be strings. They stand
2019for the respective arguments of the signal in their order, and are
2020used for filtering as well. A nil argument might be used to preserve
2021the order.
2022
2023INTERFACE, SIGNAL and HANDLER must not be nil. Example:
2024
2025\(defun my-signal-handler (device)
2026 (message "Device %s added" device))
2027
2028\(dbus-register-signal
2029 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
2030 "org.freedesktop.Hal.Manager" "DeviceAdded" 'my-signal-handler)
2031
2032 => ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
2033 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" my-signal-handler))
2034
2035`dbus-register-signal' returns an object, which can be used in
2036`dbus-unregister-object' for removing the registration.
2037
2038usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARGS) */)
2039 (ptrdiff_t nargs, Lisp_Object *args)
2040{
2041 Lisp_Object bus, service, path, interface, signal, handler;
2042 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
2043 Lisp_Object uname, key, key1, value;
2044 DBusConnection *connection;
2045 ptrdiff_t i;
2046 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2047 int rulelen;
2048 DBusError derror;
2049
2050 /* Check parameters. */
2051 bus = args[0];
2052 service = args[1];
2053 path = args[2];
2054 interface = args[3];
2055 signal = args[4];
2056 handler = args[5];
2057
2058 if (!NILP (service)) CHECK_STRING (service);
2059 if (!NILP (path)) CHECK_STRING (path);
2060 CHECK_STRING (interface);
2061 CHECK_STRING (signal);
2062 if (!FUNCTIONP (handler))
2063 wrong_type_argument (Qinvalid_function, handler);
2064 GCPRO6 (bus, service, path, interface, signal, handler);
2065
2066 /* Retrieve unique name of service. If service is a known name, we
2067 will register for the corresponding unique name, if any. Signals
2068 are sent always with the unique name as sender. Note: the unique
2069 name of "org.freedesktop.DBus" is that string itself. */
2070 if ((STRINGP (service))
2071 && (SBYTES (service) > 0)
2072 && (strcmp (SSDATA (service), DBUS_SERVICE_DBUS) != 0)
2073 && (strncmp (SSDATA (service), ":", 1) != 0))
2074 uname = call2 (intern ("dbus-get-name-owner"), bus, service);
2075 else
2076 uname = service;
2077
2078 /* Create a matching rule if the unique name exists (when no
2079 wildcard). */
2080 if (NILP (uname) || (SBYTES (uname) > 0))
2081 {
2082 /* Open a connection to the bus. */
2083 connection = xd_initialize (bus, TRUE);
2084
2085 /* Create a rule to receive related signals. */
2086 rulelen = snprintf (rule, sizeof rule,
2087 "type='signal',interface='%s',member='%s'",
2088 SDATA (interface),
2089 SDATA (signal));
2090 if (! (0 <= rulelen && rulelen < sizeof rule))
2091 string_overflow ();
2092
2093 /* Add unique name and path to the rule if they are non-nil. */
2094 if (!NILP (uname))
2095 {
2096 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2097 ",sender='%s'", SDATA (uname));
2098 if (! (0 <= len && len < sizeof rule - rulelen))
2099 string_overflow ();
2100 rulelen += len;
2101 }
2102
2103 if (!NILP (path))
2104 {
2105 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2106 ",path='%s'", SDATA (path));
2107 if (! (0 <= len && len < sizeof rule - rulelen))
2108 string_overflow ();
2109 rulelen += len;
2110 }
2111
2112 /* Add arguments to the rule if they are non-nil. */
2113 for (i = 6; i < nargs; ++i)
2114 if (!NILP (args[i]))
2115 {
2116 int len;
2117 CHECK_STRING (args[i]);
2118 len = snprintf (rule + rulelen, sizeof rule - rulelen,
2119 ",arg%"pD"d='%s'", i - 6, SDATA (args[i]));
2120 if (! (0 <= len && len < sizeof rule - rulelen))
2121 string_overflow ();
2122 rulelen += len;
2123 }
2124
2125 /* Add the rule to the bus. */
2126 dbus_error_init (&derror);
2127 dbus_bus_add_match (connection, rule, &derror);
2128 if (dbus_error_is_set (&derror))
2129 {
2130 UNGCPRO;
2131 XD_ERROR (derror);
2132 }
2133
2134 /* Cleanup. */
2135 dbus_error_free (&derror);
2136
2137 XD_DEBUG_MESSAGE ("Matching rule \"%s\" created", rule);
2138 }
2139
2140 /* Create a hash table entry. */
2141 key = list3 (bus, interface, signal);
2142 key1 = list5 (uname, service, path, handler, build_string (rule));
2143 value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
2144
2145 if (NILP (Fmember (key1, value)))
2146 Fputhash (key, Fcons (key1, value), Vdbus_registered_objects_table);
2147
2148 /* Return object. */
2149 RETURN_UNGCPRO (list2 (key, list3 (service, path, handler)));
2150}
2151
2152DEFUN ("dbus-register-method", Fdbus_register_method, Sdbus_register_method,
2153 6, 7, 0,
2154 doc: /* Register for method METHOD on the D-Bus BUS.
2155
2156BUS is either a Lisp symbol, `:system' or `:session', or a string
2157denoting the bus address.
2158
2159SERVICE is the D-Bus service name of the D-Bus object METHOD is
2160registered for. It must be a known name (See discussion of
2161DONT-REGISTER-SERVICE below).
2162
2163PATH is the D-Bus object path SERVICE is registered (See discussion of
2164DONT-REGISTER-SERVICE below). INTERFACE is the interface offered by
2165SERVICE. It must provide METHOD.
2166
2167HANDLER is a Lisp function to be called when a method call is
2168received. It must accept the input arguments of METHOD. The return
2169value of HANDLER is used for composing the returning D-Bus message.
2170In case HANDLER shall return a reply message with an empty argument
2171list, HANDLER must return the symbol `:ignore'.
2172
2173When DONT-REGISTER-SERVICE is non-nil, the known name SERVICE is not
2174registered. This means that other D-Bus clients have no way of
2175noticing the newly registered method. When interfaces are constructed
2176incrementally by adding single methods or properties at a time,
2177DONT-REGISTER-SERVICE can be used to prevent other clients from
2178discovering the still incomplete interface.*/)
2179 (Lisp_Object bus, Lisp_Object service, Lisp_Object path,
2180 Lisp_Object interface, Lisp_Object method, Lisp_Object handler,
2181 Lisp_Object dont_register_service)
2182{
2183 Lisp_Object key, key1, value;
2184 Lisp_Object args[2] = { bus, service };
2185
2186 /* Check parameters. */
2187 CHECK_STRING (service);
2188 CHECK_STRING (path);
2189 CHECK_STRING (interface);
2190 CHECK_STRING (method);
2191 if (!FUNCTIONP (handler))
2192 wrong_type_argument (Qinvalid_function, handler);
2193 /* TODO: We must check for a valid service name, otherwise there is
2194 a segmentation fault. */
2195
2196 /* Request the name. */
2197 if (NILP (dont_register_service))
2198 Fdbus_register_service (2, args);
2199
2200 /* Create a hash table entry. We use nil for the unique name,
2201 because the method might be called from anybody. */
2202 key = list3 (bus, interface, method);
2203 key1 = list4 (Qnil, service, path, handler);
2204 value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
2205
2206 if (NILP (Fmember (key1, value)))
2207 Fputhash (key, Fcons (key1, value), Vdbus_registered_objects_table);
2208
2209 /* Return object. */
2210 return list2 (key, list3 (service, path, handler));
2211}
2212
2213 1640
2214void 1641void
2215syms_of_dbusbind (void) 1642syms_of_dbusbind (void)
@@ -2218,35 +1645,11 @@ syms_of_dbusbind (void)
2218 DEFSYM (Qdbus_init_bus, "dbus-init-bus"); 1645 DEFSYM (Qdbus_init_bus, "dbus-init-bus");
2219 defsubr (&Sdbus_init_bus); 1646 defsubr (&Sdbus_init_bus);
2220 1647
2221 DEFSYM (Qdbus_close_bus, "dbus-close-bus");
2222 defsubr (&Sdbus_close_bus);
2223
2224 DEFSYM (Qdbus_get_unique_name, "dbus-get-unique-name"); 1648 DEFSYM (Qdbus_get_unique_name, "dbus-get-unique-name");
2225 defsubr (&Sdbus_get_unique_name); 1649 defsubr (&Sdbus_get_unique_name);
2226 1650
2227 DEFSYM (Qdbus_call_method, "dbus-call-method"); 1651 DEFSYM (Qdbus_message_internal, "dbus-message-internal");
2228 defsubr (&Sdbus_call_method); 1652 defsubr (&Sdbus_message_internal);
2229
2230 DEFSYM (Qdbus_call_method_asynchronously, "dbus-call-method-asynchronously");
2231 defsubr (&Sdbus_call_method_asynchronously);
2232
2233 DEFSYM (Qdbus_method_return_internal, "dbus-method-return-internal");
2234 defsubr (&Sdbus_method_return_internal);
2235
2236 DEFSYM (Qdbus_method_error_internal, "dbus-method-error-internal");
2237 defsubr (&Sdbus_method_error_internal);
2238
2239 DEFSYM (Qdbus_send_signal, "dbus-send-signal");
2240 defsubr (&Sdbus_send_signal);
2241
2242 DEFSYM (Qdbus_register_service, "dbus-register-service");
2243 defsubr (&Sdbus_register_service);
2244
2245 DEFSYM (Qdbus_register_signal, "dbus-register-signal");
2246 defsubr (&Sdbus_register_signal);
2247
2248 DEFSYM (Qdbus_register_method, "dbus-register-method");
2249 defsubr (&Sdbus_register_method);
2250 1653
2251 DEFSYM (Qdbus_error, "dbus-error"); 1654 DEFSYM (Qdbus_error, "dbus-error");
2252 Fput (Qdbus_error, Qerror_conditions, 1655 Fput (Qdbus_error, Qerror_conditions,
@@ -2256,13 +1659,6 @@ syms_of_dbusbind (void)
2256 1659
2257 DEFSYM (QCdbus_system_bus, ":system"); 1660 DEFSYM (QCdbus_system_bus, ":system");
2258 DEFSYM (QCdbus_session_bus, ":session"); 1661 DEFSYM (QCdbus_session_bus, ":session");
2259 DEFSYM (QCdbus_request_name_allow_replacement, ":allow-replacement");
2260 DEFSYM (QCdbus_request_name_replace_existing, ":replace-existing");
2261 DEFSYM (QCdbus_request_name_do_not_queue, ":do-not-queue");
2262 DEFSYM (QCdbus_request_name_reply_primary_owner, ":primary-owner");
2263 DEFSYM (QCdbus_request_name_reply_exists, ":exists");
2264 DEFSYM (QCdbus_request_name_reply_in_queue, ":in-queue");
2265 DEFSYM (QCdbus_request_name_reply_already_owner, ":already-owner");
2266 DEFSYM (QCdbus_timeout, ":timeout"); 1662 DEFSYM (QCdbus_timeout, ":timeout");
2267 DEFSYM (QCdbus_type_byte, ":byte"); 1663 DEFSYM (QCdbus_type_byte, ":byte");
2268 DEFSYM (QCdbus_type_boolean, ":boolean"); 1664 DEFSYM (QCdbus_type_boolean, ":boolean");
@@ -2276,20 +1672,66 @@ syms_of_dbusbind (void)
2276 DEFSYM (QCdbus_type_string, ":string"); 1672 DEFSYM (QCdbus_type_string, ":string");
2277 DEFSYM (QCdbus_type_object_path, ":object-path"); 1673 DEFSYM (QCdbus_type_object_path, ":object-path");
2278 DEFSYM (QCdbus_type_signature, ":signature"); 1674 DEFSYM (QCdbus_type_signature, ":signature");
2279
2280#ifdef DBUS_TYPE_UNIX_FD 1675#ifdef DBUS_TYPE_UNIX_FD
2281 DEFSYM (QCdbus_type_unix_fd, ":unix-fd"); 1676 DEFSYM (QCdbus_type_unix_fd, ":unix-fd");
2282#endif 1677#endif
2283
2284 DEFSYM (QCdbus_type_array, ":array"); 1678 DEFSYM (QCdbus_type_array, ":array");
2285 DEFSYM (QCdbus_type_variant, ":variant"); 1679 DEFSYM (QCdbus_type_variant, ":variant");
2286 DEFSYM (QCdbus_type_struct, ":struct"); 1680 DEFSYM (QCdbus_type_struct, ":struct");
2287 DEFSYM (QCdbus_type_dict_entry, ":dict-entry"); 1681 DEFSYM (QCdbus_type_dict_entry, ":dict-entry");
1682 DEFSYM (QCdbus_registered_serial, ":serial");
1683 DEFSYM (QCdbus_registered_method, ":method");
1684 DEFSYM (QCdbus_registered_signal, ":signal");
1685
1686 DEFVAR_LISP ("dbus-compiled-version",
1687 Vdbus_compiled_version,
1688 doc: /* The version of D-Bus Emacs is compiled against. */);
1689#ifdef DBUS_VERSION_STRING
1690 Vdbus_compiled_version = make_pure_c_string (DBUS_VERSION_STRING);
1691#else
1692 Vdbus_compiled_version = Qnil;
1693#endif
1694
1695 DEFVAR_LISP ("dbus-runtime-version",
1696 Vdbus_runtime_version,
1697 doc: /* The version of D-Bus Emacs runs with. */);
1698 {
1699#ifdef DBUS_VERSION
1700 int major, minor, micro;
1701 char s[1024];
1702 dbus_get_version (&major, &minor, &micro);
1703 snprintf (s, sizeof s, "%d.%d.%d", major, minor, micro);
1704 Vdbus_runtime_version = make_string (s, strlen (s));
1705#else
1706 Vdbus_runtime_version = Qnil;
1707#endif
1708 }
1709
1710 DEFVAR_LISP ("dbus-message-type-invalid",
1711 Vdbus_message_type_invalid,
1712 doc: /* This value is never a valid message type. */);
1713 Vdbus_message_type_invalid = make_number (DBUS_MESSAGE_TYPE_INVALID);
2288 1714
2289 DEFVAR_LISP ("dbus-registered-buses", 1715 DEFVAR_LISP ("dbus-message-type-method-call",
2290 Vdbus_registered_buses, 1716 Vdbus_message_type_method_call,
2291 doc: /* List of D-Bus buses we are polling for messages. */); 1717 doc: /* Message type of a method call message. */);
2292 Vdbus_registered_buses = Qnil; 1718 Vdbus_message_type_method_call = make_number (DBUS_MESSAGE_TYPE_METHOD_CALL);
1719
1720 DEFVAR_LISP ("dbus-message-type-method-return",
1721 Vdbus_message_type_method_return,
1722 doc: /* Message type of a method return message. */);
1723 Vdbus_message_type_method_return
1724 = make_number (DBUS_MESSAGE_TYPE_METHOD_RETURN);
1725
1726 DEFVAR_LISP ("dbus-message-type-error",
1727 Vdbus_message_type_error,
1728 doc: /* Message type of an error reply message. */);
1729 Vdbus_message_type_error = make_number (DBUS_MESSAGE_TYPE_ERROR);
1730
1731 DEFVAR_LISP ("dbus-message-type-signal",
1732 Vdbus_message_type_signal,
1733 doc: /* Message type of a signal message. */);
1734 Vdbus_message_type_signal = make_number (DBUS_MESSAGE_TYPE_SIGNAL);
2293 1735
2294 DEFVAR_LISP ("dbus-registered-objects-table", 1736 DEFVAR_LISP ("dbus-registered-objects-table",
2295 Vdbus_registered_objects_table, 1737 Vdbus_registered_objects_table,
@@ -2299,27 +1741,28 @@ There are two different uses of the hash table: for accessing
2299registered interfaces properties, targeted by signals or method calls, 1741registered interfaces properties, targeted by signals or method calls,
2300and for calling handlers in case of non-blocking method call returns. 1742and for calling handlers in case of non-blocking method call returns.
2301 1743
2302In the first case, the key in the hash table is the list (BUS 1744In the first case, the key in the hash table is the list (TYPE BUS
2303INTERFACE MEMBER). BUS is either a Lisp symbol, `:system' or 1745INTERFACE MEMBER). TYPE is one of the Lisp symbols `:method',
1746`:signal' or `:property'. BUS is either a Lisp symbol, `:system' or
2304`:session', or a string denoting the bus address. INTERFACE is a 1747`:session', or a string denoting the bus address. INTERFACE is a
2305string which denotes a D-Bus interface, and MEMBER, also a string, is 1748string which denotes a D-Bus interface, and MEMBER, also a string, is
2306either a method, a signal or a property INTERFACE is offering. All 1749either a method, a signal or a property INTERFACE is offering. All
2307arguments but BUS must not be nil. 1750arguments but BUS must not be nil.
2308 1751
2309The value in the hash table is a list of quadruple lists 1752The value in the hash table is a list of quadruple lists \((UNAME
2310\((UNAME SERVICE PATH OBJECT) (UNAME SERVICE PATH OBJECT) ...). 1753SERVICE PATH OBJECT [RULE]) ...). SERVICE is the service name as
2311SERVICE is the service name as registered, UNAME is the corresponding 1754registered, UNAME is the corresponding unique name. In case of
2312unique name. In case of registered methods and properties, UNAME is 1755registered methods and properties, UNAME is nil. PATH is the object
2313nil. PATH is the object path of the sending object. All of them can 1756path of the sending object. All of them can be nil, which means a
2314be nil, which means a wildcard then. OBJECT is either the handler to 1757wildcard then. OBJECT is either the handler to be called when a D-Bus
2315be called when a D-Bus message, which matches the key criteria, 1758message, which matches the key criteria, arrives (TYPE `:method' and
2316arrives (methods and signals), or a cons cell containing the value of 1759`:signal'), or a cons cell containing the value of the property (TYPE
2317the property. 1760`:property').
2318 1761
2319For signals, there is also a fifth element RULE, which keeps the match 1762For entries of type `:signal', there is also a fifth element RULE,
2320string the signal is registered with. 1763which keeps the match string the signal is registered with.
2321 1764
2322In the second case, the key in the hash table is the list (BUS 1765In the second case, the key in the hash table is the list (:serial BUS
2323SERIAL). BUS is either a Lisp symbol, `:system' or `:session', or a 1766SERIAL). BUS is either a Lisp symbol, `:system' or `:session', or a
2324string denoting the bus address. SERIAL is the serial number of the 1767string denoting the bus address. SERIAL is the serial number of the
2325non-blocking method call, a reply is expected. Both arguments must 1768non-blocking method call, a reply is expected. Both arguments must
@@ -2343,6 +1786,10 @@ be called when the D-Bus reply message arrives. */);
2343 Vdbus_debug = Qnil; 1786 Vdbus_debug = Qnil;
2344#endif 1787#endif
2345 1788
1789 /* Initialize internal objects. */
1790 xd_registered_buses = Qnil;
1791 staticpro (&xd_registered_buses);
1792
2346 Fprovide (intern_c_string ("dbusbind"), Qnil); 1793 Fprovide (intern_c_string ("dbusbind"), Qnil);
2347 1794
2348} 1795}
diff --git a/src/dired.c b/src/dired.c
index 9b0f94a0760..367bcb4031d 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -1015,6 +1015,45 @@ Comparison is in lexicographic order and case is significant. */)
1015 return Fstring_lessp (Fcar (f1), Fcar (f2)); 1015 return Fstring_lessp (Fcar (f1), Fcar (f2));
1016} 1016}
1017 1017
1018
1019DEFUN ("system-users", Fsystem_users, Ssystem_users, 0, 0, 0,
1020 doc: /* Return a list of user names currently registered in the system.
1021If we don't know how to determine that on this platform, just
1022return a list with one element, taken from `user-real-login-name'. */)
1023 (void)
1024{
1025 Lisp_Object users = Qnil;
1026#if defined HAVE_GETPWENT && defined HAVE_ENDPWENT
1027 struct passwd *pw;
1028
1029 while ((pw = getpwent ()))
1030 users = Fcons (DECODE_SYSTEM (build_string (pw->pw_name)), users);
1031
1032 endpwent ();
1033#endif
1034 if (EQ (users, Qnil))
1035 /* At least current user is always known. */
1036 users = Fcons (Vuser_real_login_name, Qnil);
1037 return users;
1038}
1039
1040DEFUN ("system-groups", Fsystem_groups, Ssystem_groups, 0, 0, 0,
1041 doc: /* Return a list of user group names currently registered in the system.
1042The value may be nil if not supported on this platform. */)
1043 (void)
1044{
1045 Lisp_Object groups = Qnil;
1046#if defined HAVE_GETGRENT && defined HAVE_ENDGRENT
1047 struct group *gr;
1048
1049 while ((gr = getgrent ()))
1050 groups = Fcons (DECODE_SYSTEM (build_string (gr->gr_name)), groups);
1051
1052 endgrent ();
1053#endif
1054 return groups;
1055}
1056
1018void 1057void
1019syms_of_dired (void) 1058syms_of_dired (void)
1020{ 1059{
@@ -1032,6 +1071,8 @@ syms_of_dired (void)
1032 defsubr (&Sfile_name_all_completions); 1071 defsubr (&Sfile_name_all_completions);
1033 defsubr (&Sfile_attributes); 1072 defsubr (&Sfile_attributes);
1034 defsubr (&Sfile_attributes_lessp); 1073 defsubr (&Sfile_attributes_lessp);
1074 defsubr (&Ssystem_users);
1075 defsubr (&Ssystem_groups);
1035 1076
1036 DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions, 1077 DEFVAR_LISP ("completion-ignored-extensions", Vcompletion_ignored_extensions,
1037 doc: /* Completion ignores file names ending in any string in this list. 1078 doc: /* Completion ignores file names ending in any string in this list.
diff --git a/src/dispextern.h b/src/dispextern.h
index e45d4b1e558..b4aa0153846 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3271,7 +3271,6 @@ extern Window tip_window;
3271EXFUN (Fx_hide_tip, 0); 3271EXFUN (Fx_hide_tip, 0);
3272extern void start_hourglass (void); 3272extern void start_hourglass (void);
3273extern void cancel_hourglass (void); 3273extern void cancel_hourglass (void);
3274extern int hourglass_started (void);
3275extern int hourglass_shown_p; 3274extern int hourglass_shown_p;
3276struct atimer; /* Defined in atimer.h. */ 3275struct atimer; /* Defined in atimer.h. */
3277/* If non-null, an asynchronous timer that, when it expires, displays 3276/* If non-null, an asynchronous timer that, when it expires, displays
diff --git a/src/dispnew.c b/src/dispnew.c
index 1f494b5685b..73c58ceded8 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -1,5 +1,6 @@
1/* Updating of data structures for redisplay. 1/* Updating of data structures for redisplay.
2 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc. 2
3Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
@@ -92,7 +93,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
92#endif 93#endif
93#endif /* not __GNU_LIBRARY__ */ 94#endif /* not __GNU_LIBRARY__ */
94 95
95#if defined (HAVE_TERM_H) && defined (GNU_LINUX) && defined (HAVE_LIBNCURSES) 96#if defined (HAVE_TERM_H) && defined (GNU_LINUX)
96#include <term.h> /* for tgetent */ 97#include <term.h> /* for tgetent */
97#endif 98#endif
98 99
@@ -1089,12 +1090,16 @@ swap_glyph_pointers (struct glyph_row *a, struct glyph_row *b)
1089 for (i = 0; i < LAST_AREA + 1; ++i) 1090 for (i = 0; i < LAST_AREA + 1; ++i)
1090 { 1091 {
1091 struct glyph *temp = a->glyphs[i]; 1092 struct glyph *temp = a->glyphs[i];
1092 short used_tem = a->used[i];
1093 1093
1094 a->glyphs[i] = b->glyphs[i]; 1094 a->glyphs[i] = b->glyphs[i];
1095 b->glyphs[i] = temp; 1095 b->glyphs[i] = temp;
1096 a->used[i] = b->used[i]; 1096 if (i < LAST_AREA)
1097 b->used[i] = used_tem; 1097 {
1098 short used_tem = a->used[i];
1099
1100 a->used[i] = b->used[i];
1101 b->used[i] = used_tem;
1102 }
1098 } 1103 }
1099 a->hash = b->hash; 1104 a->hash = b->hash;
1100 b->hash = hash_tem; 1105 b->hash = hash_tem;
@@ -1109,7 +1114,7 @@ static inline void
1109copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from) 1114copy_row_except_pointers (struct glyph_row *to, struct glyph_row *from)
1110{ 1115{
1111 struct glyph *pointers[1 + LAST_AREA]; 1116 struct glyph *pointers[1 + LAST_AREA];
1112 short used[1 + LAST_AREA]; 1117 short used[LAST_AREA];
1113 unsigned hashval; 1118 unsigned hashval;
1114 1119
1115 /* Save glyph pointers of TO. */ 1120 /* Save glyph pointers of TO. */
@@ -6312,7 +6317,7 @@ init_display (void)
6312#ifdef HAVE_X11 6317#ifdef HAVE_X11
6313 Vwindow_system_version = make_number (11); 6318 Vwindow_system_version = make_number (11);
6314#endif 6319#endif
6315#if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES) 6320#ifdef GNU_LINUX
6316 /* In some versions of ncurses, 6321 /* In some versions of ncurses,
6317 tputs crashes if we have not called tgetent. 6322 tputs crashes if we have not called tgetent.
6318 So call tgetent. */ 6323 So call tgetent. */
diff --git a/src/editfns.c b/src/editfns.c
index a41565d8588..d266ca9951d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -73,20 +73,13 @@ extern char **environ;
73 73
74#define TM_YEAR_BASE 1900 74#define TM_YEAR_BASE 1900
75 75
76/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
77 asctime to have well-defined behavior. */
78#ifndef TM_YEAR_IN_ASCTIME_RANGE
79# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
80 (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
81#endif
82
83#ifdef WINDOWSNT 76#ifdef WINDOWSNT
84extern Lisp_Object w32_get_internal_run_time (void); 77extern Lisp_Object w32_get_internal_run_time (void);
85#endif 78#endif
86 79
87static void time_overflow (void) NO_RETURN; 80static void time_overflow (void) NO_RETURN;
88static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object, 81static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object,
89 int, time_t *, struct tm **); 82 int, time_t *, struct tm *);
90static int tm_diff (struct tm *, struct tm *); 83static int tm_diff (struct tm *, struct tm *);
91static void update_buffer_properties (EMACS_INT, EMACS_INT); 84static void update_buffer_properties (EMACS_INT, EMACS_INT);
92 85
@@ -1704,7 +1697,7 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */)
1704 (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal) 1697 (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal)
1705{ 1698{
1706 time_t t; 1699 time_t t;
1707 struct tm *tm; 1700 struct tm tm;
1708 1701
1709 CHECK_STRING (format_string); 1702 CHECK_STRING (format_string);
1710 format_string = code_convert_string_norecord (format_string, 1703 format_string = code_convert_string_norecord (format_string,
@@ -1715,54 +1708,55 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */)
1715 1708
1716static Lisp_Object 1709static Lisp_Object
1717format_time_string (char const *format, ptrdiff_t formatlen, 1710format_time_string (char const *format, ptrdiff_t formatlen,
1718 Lisp_Object timeval, int ut, time_t *tval, struct tm **tmp) 1711 Lisp_Object timeval, int ut, time_t *tval, struct tm *tmp)
1719{ 1712{
1720 ptrdiff_t size; 1713 char buffer[4000];
1714 char *buf = buffer;
1715 size_t size = sizeof buffer;
1716 size_t len;
1717 Lisp_Object bufstring;
1721 int usec; 1718 int usec;
1722 int ns; 1719 int ns;
1723 struct tm *tm; 1720 struct tm *tm;
1721 USE_SAFE_ALLOCA;
1724 1722
1725 if (! (lisp_time_argument (timeval, tval, &usec) 1723 if (! (lisp_time_argument (timeval, tval, &usec)
1726 && 0 <= usec && usec < 1000000)) 1724 && 0 <= usec && usec < 1000000))
1727 error ("Invalid time specification"); 1725 error ("Invalid time specification");
1728 ns = usec * 1000; 1726 ns = usec * 1000;
1729 1727
1730 /* This is probably enough. */
1731 size = formatlen;
1732 if (size <= (STRING_BYTES_BOUND - 50) / 6)
1733 size = size * 6 + 50;
1734
1735 BLOCK_INPUT;
1736 tm = ut ? gmtime (tval) : localtime (tval);
1737 UNBLOCK_INPUT;
1738 if (! tm)
1739 time_overflow ();
1740 *tmp = tm;
1741
1742 synchronize_system_time_locale ();
1743
1744 while (1) 1728 while (1)
1745 { 1729 {
1746 char *buf = (char *) alloca (size + 1); 1730 BLOCK_INPUT;
1747 size_t result; 1731
1732 synchronize_system_time_locale ();
1733
1734 tm = ut ? gmtime (tval) : localtime (tval);
1735 if (! tm)
1736 {
1737 UNBLOCK_INPUT;
1738 time_overflow ();
1739 }
1740 *tmp = *tm;
1748 1741
1749 buf[0] = '\1'; 1742 buf[0] = '\1';
1750 BLOCK_INPUT; 1743 len = emacs_nmemftime (buf, size, format, formatlen, tm, ut, ns);
1751 result = emacs_nmemftime (buf, size, format, formatlen, tm, ut, ns); 1744 if ((0 < len && len < size) || (len == 0 && buf[0] == '\0'))
1752 UNBLOCK_INPUT; 1745 break;
1753 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
1754 return code_convert_string_norecord (make_unibyte_string (buf, result),
1755 Vlocale_coding_system, 0);
1756 1746
1757 /* If buffer was too small, make it bigger and try again. */ 1747 /* Buffer was too small, so make it bigger and try again. */
1758 BLOCK_INPUT; 1748 len = emacs_nmemftime (NULL, SIZE_MAX, format, formatlen, tm, ut, ns);
1759 result = emacs_nmemftime (NULL, (size_t) -1, format, formatlen,
1760 tm, ut, ns);
1761 UNBLOCK_INPUT; 1749 UNBLOCK_INPUT;
1762 if (STRING_BYTES_BOUND <= result) 1750 if (STRING_BYTES_BOUND <= len)
1763 string_overflow (); 1751 string_overflow ();
1764 size = result + 1; 1752 size = len + 1;
1753 SAFE_ALLOCA (buf, char *, size);
1765 } 1754 }
1755
1756 UNBLOCK_INPUT;
1757 bufstring = make_unibyte_string (buf, len);
1758 SAFE_FREE ();
1759 return code_convert_string_norecord (bufstring, Vlocale_coding_system, 0);
1766} 1760}
1767 1761
1768DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0, 1762DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0,
@@ -1792,31 +1786,32 @@ DOW and ZONE.) */)
1792 1786
1793 BLOCK_INPUT; 1787 BLOCK_INPUT;
1794 decoded_time = localtime (&time_spec); 1788 decoded_time = localtime (&time_spec);
1789 /* Make a copy, in case a signal handler modifies TZ or the struct. */
1790 if (decoded_time)
1791 save_tm = *decoded_time;
1795 UNBLOCK_INPUT; 1792 UNBLOCK_INPUT;
1796 if (! (decoded_time 1793 if (! (decoded_time
1797 && MOST_NEGATIVE_FIXNUM - TM_YEAR_BASE <= decoded_time->tm_year 1794 && MOST_NEGATIVE_FIXNUM - TM_YEAR_BASE <= save_tm.tm_year
1798 && decoded_time->tm_year <= MOST_POSITIVE_FIXNUM - TM_YEAR_BASE)) 1795 && save_tm.tm_year <= MOST_POSITIVE_FIXNUM - TM_YEAR_BASE))
1799 time_overflow (); 1796 time_overflow ();
1800 XSETFASTINT (list_args[0], decoded_time->tm_sec); 1797 XSETFASTINT (list_args[0], save_tm.tm_sec);
1801 XSETFASTINT (list_args[1], decoded_time->tm_min); 1798 XSETFASTINT (list_args[1], save_tm.tm_min);
1802 XSETFASTINT (list_args[2], decoded_time->tm_hour); 1799 XSETFASTINT (list_args[2], save_tm.tm_hour);
1803 XSETFASTINT (list_args[3], decoded_time->tm_mday); 1800 XSETFASTINT (list_args[3], save_tm.tm_mday);
1804 XSETFASTINT (list_args[4], decoded_time->tm_mon + 1); 1801 XSETFASTINT (list_args[4], save_tm.tm_mon + 1);
1805 /* On 64-bit machines an int is narrower than EMACS_INT, thus the 1802 /* On 64-bit machines an int is narrower than EMACS_INT, thus the
1806 cast below avoids overflow in int arithmetics. */ 1803 cast below avoids overflow in int arithmetics. */
1807 XSETINT (list_args[5], TM_YEAR_BASE + (EMACS_INT) decoded_time->tm_year); 1804 XSETINT (list_args[5], TM_YEAR_BASE + (EMACS_INT) save_tm.tm_year);
1808 XSETFASTINT (list_args[6], decoded_time->tm_wday); 1805 XSETFASTINT (list_args[6], save_tm.tm_wday);
1809 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil; 1806 list_args[7] = save_tm.tm_isdst ? Qt : Qnil;
1810 1807
1811 /* Make a copy, in case gmtime modifies the struct. */
1812 save_tm = *decoded_time;
1813 BLOCK_INPUT; 1808 BLOCK_INPUT;
1814 decoded_time = gmtime (&time_spec); 1809 decoded_time = gmtime (&time_spec);
1815 UNBLOCK_INPUT;
1816 if (decoded_time == 0) 1810 if (decoded_time == 0)
1817 list_args[8] = Qnil; 1811 list_args[8] = Qnil;
1818 else 1812 else
1819 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time)); 1813 XSETINT (list_args[8], tm_diff (&save_tm, decoded_time));
1814 UNBLOCK_INPUT;
1820 return Flist (9, list_args); 1815 return Flist (9, list_args);
1821} 1816}
1822 1817
@@ -1898,21 +1893,23 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1898 else 1893 else
1899 error ("Invalid time zone specification"); 1894 error ("Invalid time zone specification");
1900 1895
1896 BLOCK_INPUT;
1897
1901 /* Set TZ before calling mktime; merely adjusting mktime's returned 1898 /* Set TZ before calling mktime; merely adjusting mktime's returned
1902 value doesn't suffice, since that would mishandle leap seconds. */ 1899 value doesn't suffice, since that would mishandle leap seconds. */
1903 set_time_zone_rule (tzstring); 1900 set_time_zone_rule (tzstring);
1904 1901
1905 BLOCK_INPUT;
1906 value = mktime (&tm); 1902 value = mktime (&tm);
1907 UNBLOCK_INPUT;
1908 1903
1909 /* Restore TZ to previous value. */ 1904 /* Restore TZ to previous value. */
1910 newenv = environ; 1905 newenv = environ;
1911 environ = oldenv; 1906 environ = oldenv;
1912 xfree (newenv);
1913#ifdef LOCALTIME_CACHE 1907#ifdef LOCALTIME_CACHE
1914 tzset (); 1908 tzset ();
1915#endif 1909#endif
1910 UNBLOCK_INPUT;
1911
1912 xfree (newenv);
1916 } 1913 }
1917 1914
1918 if (value == (time_t) -1) 1915 if (value == (time_t) -1)
@@ -1939,24 +1936,37 @@ but this is considered obsolete. */)
1939{ 1936{
1940 time_t value; 1937 time_t value;
1941 struct tm *tm; 1938 struct tm *tm;
1942 register char *tem; 1939 char buf[sizeof "Mon Apr 30 12:49:17 " + INT_STRLEN_BOUND (int) + 1];
1940 int len IF_LINT (= 0);
1943 1941
1944 if (! lisp_time_argument (specified_time, &value, NULL)) 1942 if (! lisp_time_argument (specified_time, &value, NULL))
1945 error ("Invalid time specification"); 1943 error ("Invalid time specification");
1946 1944
1947 /* Convert to a string, checking for out-of-range time stamps. 1945 /* Convert to a string in ctime format, except without the trailing
1948 Don't use 'ctime', as that might dump core if VALUE is out of 1946 newline, and without the 4-digit year limit. Don't use asctime
1949 range. */ 1947 or ctime, as they might dump core if the year is outside the
1948 range -999 .. 9999. */
1950 BLOCK_INPUT; 1949 BLOCK_INPUT;
1951 tm = localtime (&value); 1950 tm = localtime (&value);
1951 if (tm)
1952 {
1953 static char const wday_name[][4] =
1954 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
1955 static char const mon_name[][4] =
1956 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1957 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
1958 printmax_t year_base = TM_YEAR_BASE;
1959
1960 len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"pMd,
1961 wday_name[tm->tm_wday], mon_name[tm->tm_mon], tm->tm_mday,
1962 tm->tm_hour, tm->tm_min, tm->tm_sec,
1963 tm->tm_year + year_base);
1964 }
1952 UNBLOCK_INPUT; 1965 UNBLOCK_INPUT;
1953 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year) && (tem = asctime (tm)))) 1966 if (! tm)
1954 time_overflow (); 1967 time_overflow ();
1955 1968
1956 /* Remove the trailing newline. */ 1969 return make_unibyte_string (buf, len);
1957 tem[strlen (tem) - 1] = '\0';
1958
1959 return build_string (tem);
1960} 1970}
1961 1971
1962/* Yield A - B, measured in seconds. 1972/* Yield A - B, measured in seconds.
@@ -2000,22 +2010,22 @@ the data it can't find. */)
2000 (Lisp_Object specified_time) 2010 (Lisp_Object specified_time)
2001{ 2011{
2002 time_t value; 2012 time_t value;
2013 int offset;
2003 struct tm *t; 2014 struct tm *t;
2004 struct tm localtm; 2015 struct tm localtm;
2005 struct tm *localt;
2006 Lisp_Object zone_offset, zone_name; 2016 Lisp_Object zone_offset, zone_name;
2007 2017
2008 zone_offset = Qnil; 2018 zone_offset = Qnil;
2009 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, specified_time, 2019 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, specified_time,
2010 0, &value, &localt); 2020 0, &value, &localtm);
2011 localtm = *localt;
2012 BLOCK_INPUT; 2021 BLOCK_INPUT;
2013 t = gmtime (&value); 2022 t = gmtime (&value);
2023 if (t)
2024 offset = tm_diff (&localtm, t);
2014 UNBLOCK_INPUT; 2025 UNBLOCK_INPUT;
2015 2026
2016 if (t) 2027 if (t)
2017 { 2028 {
2018 int offset = tm_diff (&localtm, t);
2019 zone_offset = make_number (offset); 2029 zone_offset = make_number (offset);
2020 if (SCHARS (zone_name) == 0) 2030 if (SCHARS (zone_name) == 0)
2021 { 2031 {
@@ -2053,9 +2063,16 @@ only the former. */)
2053 (Lisp_Object tz) 2063 (Lisp_Object tz)
2054{ 2064{
2055 const char *tzstring; 2065 const char *tzstring;
2066 char **old_environbuf;
2067
2068 if (! (NILP (tz) || EQ (tz, Qt)))
2069 CHECK_STRING (tz);
2070
2071 BLOCK_INPUT;
2056 2072
2057 /* When called for the first time, save the original TZ. */ 2073 /* When called for the first time, save the original TZ. */
2058 if (!environbuf) 2074 old_environbuf = environbuf;
2075 if (!old_environbuf)
2059 initial_tz = (char *) getenv ("TZ"); 2076 initial_tz = (char *) getenv ("TZ");
2060 2077
2061 if (NILP (tz)) 2078 if (NILP (tz))
@@ -2063,15 +2080,14 @@ only the former. */)
2063 else if (EQ (tz, Qt)) 2080 else if (EQ (tz, Qt))
2064 tzstring = "UTC0"; 2081 tzstring = "UTC0";
2065 else 2082 else
2066 { 2083 tzstring = SSDATA (tz);
2067 CHECK_STRING (tz);
2068 tzstring = SSDATA (tz);
2069 }
2070 2084
2071 set_time_zone_rule (tzstring); 2085 set_time_zone_rule (tzstring);
2072 xfree (environbuf);
2073 environbuf = environ; 2086 environbuf = environ;
2074 2087
2088 UNBLOCK_INPUT;
2089
2090 xfree (old_environbuf);
2075 return Qnil; 2091 return Qnil;
2076} 2092}
2077 2093
diff --git a/src/emacsgtkfixed.c b/src/emacsgtkfixed.c
index e45cc716a31..194d3d3879f 100644
--- a/src/emacsgtkfixed.c
+++ b/src/emacsgtkfixed.c
@@ -30,6 +30,28 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#ifdef HAVE_XWIDGETS 30#ifdef HAVE_XWIDGETS
31#include "xwidget.h" 31#include "xwidget.h"
32#endif 32#endif
33
34#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
35#define EMACS_FIXED(obj) \
36 G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed)
37
38typedef struct _EmacsFixed EmacsFixed;
39typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
40typedef struct _EmacsFixedClass EmacsFixedClass;
41
42struct _EmacsFixed
43{
44 GtkFixed container;
45
46 /*< private >*/
47 EmacsFixedPrivate *priv;
48};
49
50struct _EmacsFixedClass
51{
52 GtkFixedClass parent_class;
53};
54
33struct _EmacsFixedPrivate 55struct _EmacsFixedPrivate
34{ 56{
35 struct frame *f; 57 struct frame *f;
@@ -42,6 +64,7 @@ static void emacs_fixed_get_preferred_width (GtkWidget *widget,
42static void emacs_fixed_get_preferred_height (GtkWidget *widget, 64static void emacs_fixed_get_preferred_height (GtkWidget *widget,
43 gint *minimum, 65 gint *minimum,
44 gint *natural); 66 gint *natural);
67static GType emacs_fixed_get_type (void);
45G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED) 68G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
46 69
47#ifdef HAVE_XWIDGETS 70#ifdef HAVE_XWIDGETS
@@ -164,10 +187,8 @@ static void
164emacs_fixed_class_init (EmacsFixedClass *klass) 187emacs_fixed_class_init (EmacsFixedClass *klass)
165{ 188{
166 GtkWidgetClass *widget_class; 189 GtkWidgetClass *widget_class;
167 GtkFixedClass *fixed_class;
168 190
169 widget_class = (GtkWidgetClass*) klass; 191 widget_class = (GtkWidgetClass*) klass;
170 fixed_class = (GtkFixedClass*) klass;
171 192
172 widget_class->get_preferred_width = emacs_fixed_get_preferred_width; 193 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
173 widget_class->get_preferred_height = emacs_fixed_get_preferred_height; 194 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
@@ -177,12 +198,6 @@ emacs_fixed_class_init (EmacsFixedClass *klass)
177 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate)); 198 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
178} 199}
179 200
180static GType
181emacs_fixed_child_type (GtkFixed *container)
182{
183 return GTK_TYPE_WIDGET;
184}
185
186static void 201static void
187emacs_fixed_init (EmacsFixed *fixed) 202emacs_fixed_init (EmacsFixed *fixed)
188{ 203{
diff --git a/src/emacsgtkfixed.h b/src/emacsgtkfixed.h
index 90fb37e521b..3fa294aa41e 100644
--- a/src/emacsgtkfixed.h
+++ b/src/emacsgtkfixed.h
@@ -27,33 +27,7 @@ G_BEGIN_DECLS
27 27
28struct frame; 28struct frame;
29 29
30#define EMACS_TYPE_FIXED (emacs_fixed_get_type ())
31#define EMACS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMACS_TYPE_FIXED, EmacsFixed))
32#define EMACS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EMACS_TYPE_FIXED, EmacsFixedClass))
33#define EMACS_IS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMACS_TYPE_FIXED))
34#define EMACS_IS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EMACS_TYPE_FIXED))
35#define EMACS_FIXED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMACS_TYPE_FIXED, EmacsFixedClass))
36
37typedef struct _EmacsFixed EmacsFixed;
38typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
39typedef struct _EmacsFixedClass EmacsFixedClass;
40
41struct _EmacsFixed
42{
43 GtkFixed container;
44
45 /*< private >*/
46 EmacsFixedPrivate *priv;
47};
48
49
50struct _EmacsFixedClass
51{
52 GtkFixedClass parent_class;
53};
54
55extern GtkWidget *emacs_fixed_new (struct frame *f); 30extern GtkWidget *emacs_fixed_new (struct frame *f);
56extern GType emacs_fixed_get_type (void);
57 31
58G_END_DECLS 32G_END_DECLS
59 33
diff --git a/src/eval.c b/src/eval.c
index cb0518f34ec..3d0e82c2d9f 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2048,7 +2048,7 @@ this does nothing and returns nil. */)
2048 We used to use 0 here, but that leads to accidental sharing in 2048 We used to use 0 here, but that leads to accidental sharing in
2049 purecopy's hash-consing, so we use a (hopefully) unique integer 2049 purecopy's hash-consing, so we use a (hopefully) unique integer
2050 instead. */ 2050 instead. */
2051 docstring = make_number (XPNTR (function)); 2051 docstring = make_number (XUNTAG (function, Lisp_Symbol));
2052 return Ffset (function, 2052 return Ffset (function,
2053 Fpurecopy (list5 (Qautoload, file, docstring, 2053 Fpurecopy (list5 (Qautoload, file, docstring,
2054 interactive, type))); 2054 interactive, type)));
diff --git a/src/fileio.c b/src/fileio.c
index 3a74672b9a6..f09ba2c394c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1,6 +1,6 @@
1/* File IO for GNU Emacs. 1/* File IO for GNU Emacs.
2 2
3Copyright (C) 1985-1988, 1993-2012 Free Software Foundation, Inc. 3Copyright (C) 1985-1988, 1993-2012 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -87,17 +87,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
87#define FILE_SYSTEM_CASE(filename) (filename) 87#define FILE_SYSTEM_CASE(filename) (filename)
88#endif 88#endif
89 89
90/* Nonzero during writing of auto-save files */ 90/* Nonzero during writing of auto-save files. */
91static int auto_saving; 91static int auto_saving;
92 92
93/* Nonzero umask during creation of auto-save directories */ 93/* Nonzero umask during creation of auto-save directories. */
94static int auto_saving_dir_umask; 94static int auto_saving_dir_umask;
95 95
96/* Set by auto_save_1 to mode of original file so Fwrite_region will create 96/* Set by auto_save_1 to mode of original file so Fwrite_region will create
97 a new file with the same mode as the original */ 97 a new file with the same mode as the original. */
98static int auto_save_mode_bits; 98static int auto_save_mode_bits;
99 99
100/* Set by auto_save_1 if an error occurred during the last auto-save. */ 100/* Set by auto_save_1 if an error occurred during the last auto-save. */
101static int auto_save_error_occurred; 101static int auto_save_error_occurred;
102 102
103/* The symbol bound to coding-system-for-read when 103/* The symbol bound to coding-system-for-read when
@@ -111,7 +111,7 @@ static Lisp_Object Qauto_save_coding;
111 which gives a list of operations it handles.. */ 111 which gives a list of operations it handles.. */
112static Lisp_Object Qoperations; 112static Lisp_Object Qoperations;
113 113
114/* Lisp functions for translating file formats */ 114/* Lisp functions for translating file formats. */
115static Lisp_Object Qformat_decode, Qformat_annotate_function; 115static Lisp_Object Qformat_decode, Qformat_annotate_function;
116 116
117/* Lisp function for setting buffer-file-coding-system and the 117/* Lisp function for setting buffer-file-coding-system and the
@@ -2044,9 +2044,10 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
2044#if HAVE_LIBSELINUX 2044#if HAVE_LIBSELINUX
2045 if (conlength > 0) 2045 if (conlength > 0)
2046 { 2046 {
2047 /* Set the modified context back to the file. */ 2047 /* Set the modified context back to the file. */
2048 fail = fsetfilecon (ofd, con); 2048 fail = fsetfilecon (ofd, con);
2049 if (fail) 2049 /* See http://debbugs.gnu.org/11245 for ENOTSUP. */
2050 if (fail && errno != ENOTSUP)
2050 report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil)); 2051 report_file_error ("Doing fsetfilecon", Fcons (newname, Qnil));
2051 2052
2052 freecon (con); 2053 freecon (con);
@@ -2917,10 +2918,11 @@ compiled with SELinux support. */)
2917 error ("Doing context_range_set"); 2918 error ("Doing context_range_set");
2918 } 2919 }
2919 2920
2920 /* Set the modified context back to the file. */ 2921 /* Set the modified context back to the file. */
2921 fail = lsetfilecon (SSDATA (encoded_absname), 2922 fail = lsetfilecon (SSDATA (encoded_absname),
2922 context_str (parsed_con)); 2923 context_str (parsed_con));
2923 if (fail) 2924 /* See http://debbugs.gnu.org/11245 for ENOTSUP. */
2925 if (fail && errno != ENOTSUP)
2924 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil)); 2926 report_file_error ("Doing lsetfilecon", Fcons (absname, Qnil));
2925 2927
2926 context_free (parsed_con); 2928 context_free (parsed_con);
diff --git a/src/filelock.c b/src/filelock.c
index 2613eec4aca..d8914c73328 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -550,6 +550,10 @@ lock_file (Lisp_Object fn)
550 struct gcpro gcpro1; 550 struct gcpro gcpro1;
551 USE_SAFE_ALLOCA; 551 USE_SAFE_ALLOCA;
552 552
553 /* Don't do locking if the user has opted out. */
554 if (! create_lockfiles)
555 return;
556
553 /* Don't do locking while dumping Emacs. 557 /* Don't do locking while dumping Emacs.
554 Uncompressing wtmp files uses call-process, which does not work 558 Uncompressing wtmp files uses call-process, which does not work
555 in an uninitialized Emacs. */ 559 in an uninitialized Emacs. */
@@ -722,6 +726,10 @@ syms_of_filelock (void)
722 doc: /* The directory for writing temporary files. */); 726 doc: /* The directory for writing temporary files. */);
723 Vtemporary_file_directory = Qnil; 727 Vtemporary_file_directory = Qnil;
724 728
729 DEFVAR_BOOL ("create-lockfiles", create_lockfiles,
730 doc: /* Non-nil means use lockfiles to avoid editing collisions. */);
731 create_lockfiles = 1;
732
725#ifdef CLASH_DETECTION 733#ifdef CLASH_DETECTION
726 defsubr (&Sunlock_buffer); 734 defsubr (&Sunlock_buffer);
727 defsubr (&Slock_buffer); 735 defsubr (&Slock_buffer);
diff --git a/src/font.h b/src/font.h
index 663cc675c05..ea392d2e3fa 100644
--- a/src/font.h
+++ b/src/font.h
@@ -469,11 +469,12 @@ struct font_bitmap
469 } while (0) 469 } while (0)
470 470
471#define XFONT_SPEC(p) \ 471#define XFONT_SPEC(p) \
472 (eassert (FONT_SPEC_P(p)), (struct font_spec *) XPNTR (p)) 472 (eassert (FONT_SPEC_P (p)), (struct font_spec *) XUNTAG (p, Lisp_Vectorlike))
473#define XFONT_ENTITY(p) \ 473#define XFONT_ENTITY(p) \
474 (eassert (FONT_ENTITY_P(p)), (struct font_entity *) XPNTR (p)) 474 (eassert (FONT_ENTITY_P (p)), \
475 (struct font_entity *) XUNTAG (p, Lisp_Vectorlike))
475#define XFONT_OBJECT(p) \ 476#define XFONT_OBJECT(p) \
476 (eassert (FONT_OBJECT_P(p)), (struct font *) XPNTR (p)) 477 (eassert (FONT_OBJECT_P (p)), (struct font *) XUNTAG (p, Lisp_Vectorlike))
477#define XSETFONT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FONT)) 478#define XSETFONT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FONT))
478 479
479/* Number of pt per inch (from the TeXbook). */ 480/* Number of pt per inch (from the TeXbook). */
diff --git a/src/frame.h b/src/frame.h
index 5c89fc69628..9779f4a0926 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -501,7 +501,8 @@ struct frame
501 501
502typedef struct frame *FRAME_PTR; 502typedef struct frame *FRAME_PTR;
503 503
504#define XFRAME(p) (eassert (FRAMEP(p)),(struct frame *) XPNTR (p)) 504#define XFRAME(p) \
505 (eassert (FRAMEP (p)), (struct frame *) XUNTAG (p, Lisp_Vectorlike))
505#define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME)) 506#define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME))
506 507
507/* Given a window, return its frame as a Lisp_Object. */ 508/* Given a window, return its frame as a Lisp_Object. */
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 7b5e6df009b..b53199e7312 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -1,9 +1,3 @@
1/* This file is no longer automatically generated from libc. */
2
3#define _MALLOC_INTERNAL
4
5/* The malloc headers and source files from the C library follow here. */
6
7/* Declarations for `malloc' and friends. 1/* Declarations for `malloc' and friends.
8 Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004, 2 Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004,
9 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007 Free Software Foundation, Inc.
@@ -27,12 +21,6 @@ Fifth Floor, Boston, MA 02110-1301, USA.
27 The author may be reached (Email) at the address mike@ai.mit.edu, 21 The author may be reached (Email) at the address mike@ai.mit.edu,
28 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 22 or (US mail) as Mike Haertel c/o Free Software Foundation. */
29 23
30#ifndef _MALLOC_H
31
32#define _MALLOC_H 1
33
34#ifdef _MALLOC_INTERNAL
35
36#ifdef HAVE_CONFIG_H 24#ifdef HAVE_CONFIG_H
37#include <config.h> 25#include <config.h>
38#endif 26#endif
@@ -41,62 +29,44 @@ Fifth Floor, Boston, MA 02110-1301, USA.
41#define USE_PTHREAD 29#define USE_PTHREAD
42#endif 30#endif
43 31
44#undef PP
45#define PP(args) args
46#undef __ptr_t
47#define __ptr_t void *
48
49#include <string.h> 32#include <string.h>
50#include <limits.h> 33#include <limits.h>
34#include <stdint.h>
51#include <unistd.h> 35#include <unistd.h>
52 36
53#ifdef USE_PTHREAD 37#ifdef USE_PTHREAD
54#include <pthread.h> 38#include <pthread.h>
55#endif 39#endif
56 40
57#endif /* _MALLOC_INTERNAL. */
58
59
60#ifdef __cplusplus 41#ifdef __cplusplus
61extern "C" 42extern "C"
62{ 43{
63#endif 44#endif
64 45
65#include <stddef.h> 46#include <stddef.h>
66#define __malloc_size_t size_t
67#define __malloc_ptrdiff_t ptrdiff_t
68 47
69 48
70/* Allocate SIZE bytes of memory. */ 49/* Allocate SIZE bytes of memory. */
71extern __ptr_t malloc PP ((__malloc_size_t __size)); 50extern void *malloc (size_t size);
72/* Re-allocate the previously allocated block 51/* Re-allocate the previously allocated block
73 in __ptr_t, making the new block SIZE bytes long. */ 52 in ptr, making the new block SIZE bytes long. */
74extern __ptr_t realloc PP ((__ptr_t __ptr, __malloc_size_t __size)); 53extern void *realloc (void *ptr, size_t size);
75/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ 54/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
76extern __ptr_t calloc PP ((__malloc_size_t __nmemb, __malloc_size_t __size)); 55extern void *calloc (size_t nmemb, size_t size);
77/* Free a block allocated by `malloc', `realloc' or `calloc'. */ 56/* Free a block allocated by `malloc', `realloc' or `calloc'. */
78extern void free PP ((__ptr_t __ptr)); 57extern void free (void *ptr);
79 58
80/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ 59/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
81#if !defined (_MALLOC_INTERNAL) || defined (MSDOS) /* Avoid conflict. */ 60#ifdef MSDOS
82extern __ptr_t memalign PP ((__malloc_size_t __alignment, 61extern void *memalign (size_t, size_t);
83 __malloc_size_t __size)); 62extern int posix_memalign (void **, size_t, size_t);
84extern int posix_memalign PP ((__ptr_t *, __malloc_size_t,
85 __malloc_size_t size));
86#endif
87
88/* Allocate SIZE bytes on a page boundary. */
89#if ! (defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC))
90extern __ptr_t valloc PP ((__malloc_size_t __size));
91#endif 63#endif
92 64
93#ifdef USE_PTHREAD 65#ifdef USE_PTHREAD
94/* Set up mutexes and make malloc etc. thread-safe. */ 66/* Set up mutexes and make malloc etc. thread-safe. */
95extern void malloc_enable_thread PP ((void)); 67extern void malloc_enable_thread (void);
96#endif 68#endif
97 69
98#ifdef _MALLOC_INTERNAL
99
100/* The allocator divides the heap into blocks of fixed size; large 70/* The allocator divides the heap into blocks of fixed size; large
101 requests receive one or more whole blocks, and small requests 71 requests receive one or more whole blocks, and small requests
102 receive a fragment of a block. Fragment sizes are powers of two, 72 receive a fragment of a block. Fragment sizes are powers of two,
@@ -128,22 +98,22 @@ typedef union
128 { 98 {
129 struct 99 struct
130 { 100 {
131 __malloc_size_t nfree; /* Free frags in a fragmented block. */ 101 size_t nfree; /* Free frags in a fragmented block. */
132 __malloc_size_t first; /* First free fragment of the block. */ 102 size_t first; /* First free fragment of the block. */
133 } frag; 103 } frag;
134 /* For a large object, in its first block, this has the number 104 /* For a large object, in its first block, this has the number
135 of blocks in the object. In the other blocks, this has a 105 of blocks in the object. In the other blocks, this has a
136 negative number which says how far back the first block is. */ 106 negative number which says how far back the first block is. */
137 __malloc_ptrdiff_t size; 107 ptrdiff_t size;
138 } info; 108 } info;
139 } busy; 109 } busy;
140 /* Heap information for a free block 110 /* Heap information for a free block
141 (that may be the first of a free cluster). */ 111 (that may be the first of a free cluster). */
142 struct 112 struct
143 { 113 {
144 __malloc_size_t size; /* Size (in blocks) of a free cluster. */ 114 size_t size; /* Size (in blocks) of a free cluster. */
145 __malloc_size_t next; /* Index of next free cluster. */ 115 size_t next; /* Index of next free cluster. */
146 __malloc_size_t prev; /* Index of previous free cluster. */ 116 size_t prev; /* Index of previous free cluster. */
147 } free; 117 } free;
148 } malloc_info; 118 } malloc_info;
149 119
@@ -155,13 +125,13 @@ extern malloc_info *_heapinfo;
155 125
156/* Address to block number and vice versa. */ 126/* Address to block number and vice versa. */
157#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1) 127#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
158#define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase)) 128#define ADDRESS(B) ((void *) (((B) - 1) * BLOCKSIZE + _heapbase))
159 129
160/* Current search index for the heap table. */ 130/* Current search index for the heap table. */
161extern __malloc_size_t _heapindex; 131extern size_t _heapindex;
162 132
163/* Limit of valid info table indices. */ 133/* Limit of valid info table indices. */
164extern __malloc_size_t _heaplimit; 134extern size_t _heaplimit;
165 135
166/* Doubly linked lists of free fragments. */ 136/* Doubly linked lists of free fragments. */
167struct list 137struct list
@@ -177,26 +147,26 @@ extern struct list _fraghead[];
177struct alignlist 147struct alignlist
178 { 148 {
179 struct alignlist *next; 149 struct alignlist *next;
180 __ptr_t aligned; /* The address that memaligned returned. */ 150 void *aligned; /* The address that memaligned returned. */
181 __ptr_t exact; /* The address that malloc returned. */ 151 void *exact; /* The address that malloc returned. */
182 }; 152 };
183extern struct alignlist *_aligned_blocks; 153extern struct alignlist *_aligned_blocks;
184 154
185/* Instrumentation. */ 155/* Instrumentation. */
186extern __malloc_size_t _chunks_used; 156extern size_t _chunks_used;
187extern __malloc_size_t _bytes_used; 157extern size_t _bytes_used;
188extern __malloc_size_t _chunks_free; 158extern size_t _chunks_free;
189extern __malloc_size_t _bytes_free; 159extern size_t _bytes_free;
190 160
191/* Internal versions of `malloc', `realloc', and `free' 161/* Internal versions of `malloc', `realloc', and `free'
192 used when these functions need to call each other. 162 used when these functions need to call each other.
193 They are the same but don't call the hooks. */ 163 They are the same but don't call the hooks. */
194extern __ptr_t _malloc_internal PP ((__malloc_size_t __size)); 164extern void *_malloc_internal (size_t);
195extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size)); 165extern void *_realloc_internal (void *, size_t);
196extern void _free_internal PP ((__ptr_t __ptr)); 166extern void _free_internal (void *);
197extern __ptr_t _malloc_internal_nolock PP ((__malloc_size_t __size)); 167extern void *_malloc_internal_nolock (size_t);
198extern __ptr_t _realloc_internal_nolock PP ((__ptr_t __ptr, __malloc_size_t __size)); 168extern void *_realloc_internal_nolock (void *, size_t);
199extern void _free_internal_nolock PP ((__ptr_t __ptr)); 169extern void _free_internal_nolock (void *);
200 170
201#ifdef USE_PTHREAD 171#ifdef USE_PTHREAD
202extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex; 172extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
@@ -228,39 +198,36 @@ extern int _malloc_thread_enabled_p;
228#define UNLOCK_ALIGNED_BLOCKS() 198#define UNLOCK_ALIGNED_BLOCKS()
229#endif 199#endif
230 200
231#endif /* _MALLOC_INTERNAL. */
232
233/* Given an address in the middle of a malloc'd object, 201/* Given an address in the middle of a malloc'd object,
234 return the address of the beginning of the object. */ 202 return the address of the beginning of the object. */
235extern __ptr_t malloc_find_object_address PP ((__ptr_t __ptr)); 203extern void *malloc_find_object_address (void *ptr);
236 204
237/* Underlying allocation function; successive calls should 205/* Underlying allocation function; successive calls should
238 return contiguous pieces of memory. */ 206 return contiguous pieces of memory. */
239extern __ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)); 207extern void *(*__morecore) (ptrdiff_t size);
240 208
241/* Default value of `__morecore'. */ 209/* Default value of `__morecore'. */
242extern __ptr_t __default_morecore PP ((__malloc_ptrdiff_t __size)); 210extern void *__default_morecore (ptrdiff_t size);
243 211
244/* If not NULL, this function is called after each time 212/* If not NULL, this function is called after each time
245 `__morecore' is called to increase the data size. */ 213 `__morecore' is called to increase the data size. */
246extern void (*__after_morecore_hook) PP ((void)); 214extern void (*__after_morecore_hook) (void);
247 215
248/* Number of extra blocks to get each time we ask for more core. 216/* Number of extra blocks to get each time we ask for more core.
249 This reduces the frequency of calling `(*__morecore)'. */ 217 This reduces the frequency of calling `(*__morecore)'. */
250extern __malloc_size_t __malloc_extra_blocks; 218extern size_t __malloc_extra_blocks;
251 219
252/* Nonzero if `malloc' has been called and done its initialization. */ 220/* Nonzero if `malloc' has been called and done its initialization. */
253extern int __malloc_initialized; 221extern int __malloc_initialized;
254/* Function called to initialize malloc data structures. */ 222/* Function called to initialize malloc data structures. */
255extern int __malloc_initialize PP ((void)); 223extern int __malloc_initialize (void);
256 224
257/* Hooks for debugging versions. */ 225/* Hooks for debugging versions. */
258extern void (*__malloc_initialize_hook) PP ((void)); 226extern void (*__malloc_initialize_hook) (void);
259extern void (*__free_hook) PP ((__ptr_t __ptr)); 227extern void (*__free_hook) (void *ptr);
260extern __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size)); 228extern void *(*__malloc_hook) (size_t size);
261extern __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size)); 229extern void *(*__realloc_hook) (void *ptr, size_t size);
262extern __ptr_t (*__memalign_hook) PP ((__malloc_size_t __size, 230extern void *(*__memalign_hook) (size_t size, size_t alignment);
263 __malloc_size_t __alignment));
264 231
265/* Return values for `mprobe': these are the kinds of inconsistencies that 232/* Return values for `mprobe': these are the kinds of inconsistencies that
266 `mcheck' enables detection of. */ 233 `mcheck' enables detection of. */
@@ -277,52 +244,37 @@ enum mcheck_status
277 before `malloc' is ever called. ABORTFUNC is called with an error code 244 before `malloc' is ever called. ABORTFUNC is called with an error code
278 (see enum above) when an inconsistency is detected. If ABORTFUNC is 245 (see enum above) when an inconsistency is detected. If ABORTFUNC is
279 null, the standard function prints on stderr and then calls `abort'. */ 246 null, the standard function prints on stderr and then calls `abort'. */
280extern int mcheck PP ((void (*__abortfunc) PP ((enum mcheck_status)))); 247extern int mcheck (void (*abortfunc) (enum mcheck_status));
281 248
282/* Check for aberrations in a particular malloc'd block. You must have 249/* Check for aberrations in a particular malloc'd block. You must have
283 called `mcheck' already. These are the same checks that `mcheck' does 250 called `mcheck' already. These are the same checks that `mcheck' does
284 when you free or reallocate a block. */ 251 when you free or reallocate a block. */
285extern enum mcheck_status mprobe PP ((__ptr_t __ptr)); 252extern enum mcheck_status mprobe (void *ptr);
286 253
287/* Activate a standard collection of tracing hooks. */ 254/* Activate a standard collection of tracing hooks. */
288extern void mtrace PP ((void)); 255extern void mtrace (void);
289extern void muntrace PP ((void)); 256extern void muntrace (void);
290 257
291/* Statistics available to the user. */ 258/* Statistics available to the user. */
292struct mstats 259struct mstats
293 { 260 {
294 __malloc_size_t bytes_total; /* Total size of the heap. */ 261 size_t bytes_total; /* Total size of the heap. */
295 __malloc_size_t chunks_used; /* Chunks allocated by the user. */ 262 size_t chunks_used; /* Chunks allocated by the user. */
296 __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */ 263 size_t bytes_used; /* Byte total of user-allocated chunks. */
297 __malloc_size_t chunks_free; /* Chunks in the free list. */ 264 size_t chunks_free; /* Chunks in the free list. */
298 __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */ 265 size_t bytes_free; /* Byte total of chunks in the free list. */
299 }; 266 };
300 267
301/* Pick up the current statistics. */ 268/* Pick up the current statistics. */
302extern struct mstats mstats PP ((void)); 269extern struct mstats mstats (void);
303 270
304/* Call WARNFUN with a warning message when memory usage is high. */ 271/* Call WARNFUN with a warning message when memory usage is high. */
305extern void memory_warnings PP ((__ptr_t __start, 272extern void memory_warnings (void *start, void (*warnfun) (const char *));
306 void (*__warnfun) PP ((const char *))));
307
308
309/* Relocating allocator. */
310
311/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
312extern __ptr_t r_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
313
314/* Free the storage allocated in HANDLEPTR. */
315extern void r_alloc_free PP ((__ptr_t *__handleptr));
316
317/* Adjust the block at HANDLEPTR to be SIZE bytes long. */
318extern __ptr_t r_re_alloc PP ((__ptr_t *__handleptr, __malloc_size_t __size));
319
320 273
321#ifdef __cplusplus 274#ifdef __cplusplus
322} 275}
323#endif 276#endif
324 277
325#endif /* malloc.h */
326/* Memory allocator `malloc'. 278/* Memory allocator `malloc'.
327 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 279 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
328 Written May 1989 by Mike Haertel. 280 Written May 1989 by Mike Haertel.
@@ -345,10 +297,6 @@ Fifth Floor, Boston, MA 02110-1301, USA.
345 The author may be reached (Email) at the address mike@ai.mit.edu, 297 The author may be reached (Email) at the address mike@ai.mit.edu,
346 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 298 or (US mail) as Mike Haertel c/o Free Software Foundation. */
347 299
348#ifndef _MALLOC_INTERNAL
349#define _MALLOC_INTERNAL
350#include <malloc.h>
351#endif
352#include <errno.h> 300#include <errno.h>
353 301
354/* On Cygwin there are two heaps. temacs uses the static heap 302/* On Cygwin there are two heaps. temacs uses the static heap
@@ -362,15 +310,15 @@ Fifth Floor, Boston, MA 02110-1301, USA.
362 this is changed in the future, we'll have to similarly deal with 310 this is changed in the future, we'll have to similarly deal with
363 reinitializing ralloc. */ 311 reinitializing ralloc. */
364#ifdef CYGWIN 312#ifdef CYGWIN
365extern __ptr_t bss_sbrk PP ((ptrdiff_t __size)); 313extern void *bss_sbrk (ptrdiff_t size);
366extern int bss_sbrk_did_unexec; 314extern int bss_sbrk_did_unexec;
367char *bss_sbrk_heapbase; /* _heapbase for static heap */ 315char *bss_sbrk_heapbase; /* _heapbase for static heap */
368malloc_info *bss_sbrk_heapinfo; /* _heapinfo for static heap */ 316malloc_info *bss_sbrk_heapinfo; /* _heapinfo for static heap */
369#endif 317#endif
370__ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = __default_morecore; 318void *(*__morecore) (ptrdiff_t size) = __default_morecore;
371 319
372/* Debugging hook for `malloc'. */ 320/* Debugging hook for `malloc'. */
373__ptr_t (*__malloc_hook) PP ((__malloc_size_t __size)); 321void *(*__malloc_hook) (size_t size);
374 322
375/* Pointer to the base of the first block. */ 323/* Pointer to the base of the first block. */
376char *_heapbase; 324char *_heapbase;
@@ -379,30 +327,30 @@ char *_heapbase;
379malloc_info *_heapinfo; 327malloc_info *_heapinfo;
380 328
381/* Number of info entries. */ 329/* Number of info entries. */
382static __malloc_size_t heapsize; 330static size_t heapsize;
383 331
384/* Search index in the info table. */ 332/* Search index in the info table. */
385__malloc_size_t _heapindex; 333size_t _heapindex;
386 334
387/* Limit of valid info table indices. */ 335/* Limit of valid info table indices. */
388__malloc_size_t _heaplimit; 336size_t _heaplimit;
389 337
390/* Free lists for each fragment size. */ 338/* Free lists for each fragment size. */
391struct list _fraghead[BLOCKLOG]; 339struct list _fraghead[BLOCKLOG];
392 340
393/* Instrumentation. */ 341/* Instrumentation. */
394__malloc_size_t _chunks_used; 342size_t _chunks_used;
395__malloc_size_t _bytes_used; 343size_t _bytes_used;
396__malloc_size_t _chunks_free; 344size_t _chunks_free;
397__malloc_size_t _bytes_free; 345size_t _bytes_free;
398 346
399/* Are you experienced? */ 347/* Are you experienced? */
400int __malloc_initialized; 348int __malloc_initialized;
401 349
402__malloc_size_t __malloc_extra_blocks; 350size_t __malloc_extra_blocks;
403 351
404void (*__malloc_initialize_hook) PP ((void)); 352void (*__malloc_initialize_hook) (void);
405void (*__after_morecore_hook) PP ((void)); 353void (*__after_morecore_hook) (void);
406 354
407#if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE 355#if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE
408 356
@@ -419,12 +367,11 @@ void (*__after_morecore_hook) PP ((void));
419#include <sys/mman.h> 367#include <sys/mman.h>
420 368
421static int state_protected_p; 369static int state_protected_p;
422static __malloc_size_t last_state_size; 370static size_t last_state_size;
423static malloc_info *last_heapinfo; 371static malloc_info *last_heapinfo;
424 372
425void 373void
426protect_malloc_state (protect_p) 374protect_malloc_state (int protect_p)
427 int protect_p;
428{ 375{
429 /* If _heapinfo has been relocated, make sure its old location 376 /* If _heapinfo has been relocated, make sure its old location
430 isn't left read-only; it will be reused by malloc. */ 377 isn't left read-only; it will be reused by malloc. */
@@ -453,29 +400,25 @@ protect_malloc_state (protect_p)
453 400
454 401
455/* Aligned allocation. */ 402/* Aligned allocation. */
456static __ptr_t align PP ((__malloc_size_t)); 403static void *
457static __ptr_t 404align (size_t size)
458align (size)
459 __malloc_size_t size;
460{ 405{
461 __ptr_t result; 406 void *result;
462 unsigned long int adj; 407 ptrdiff_t adj;
463 408
464 /* align accepts an unsigned argument, but __morecore accepts a 409 /* align accepts an unsigned argument, but __morecore accepts a
465 signed one. This could lead to trouble if SIZE overflows a 410 signed one. This could lead to trouble if SIZE overflows the
466 signed int type accepted by __morecore. We just punt in that 411 ptrdiff_t type accepted by __morecore. We just punt in that
467 case, since they are requesting a ludicrous amount anyway. */ 412 case, since they are requesting a ludicrous amount anyway. */
468 if ((__malloc_ptrdiff_t)size < 0) 413 if (PTRDIFF_MAX < size)
469 result = 0; 414 result = 0;
470 else 415 else
471 result = (*__morecore) (size); 416 result = (*__morecore) (size);
472 adj = (unsigned long int) ((unsigned long int) ((char *) result - 417 adj = (uintptr_t) result % BLOCKSIZE;
473 (char *) NULL)) % BLOCKSIZE;
474 if (adj != 0) 418 if (adj != 0)
475 { 419 {
476 __ptr_t new;
477 adj = BLOCKSIZE - adj; 420 adj = BLOCKSIZE - adj;
478 new = (*__morecore) (adj); 421 (*__morecore) (adj);
479 result = (char *) result + adj; 422 result = (char *) result + adj;
480 } 423 }
481 424
@@ -488,14 +431,11 @@ align (size)
488/* Get SIZE bytes, if we can get them starting at END. 431/* Get SIZE bytes, if we can get them starting at END.
489 Return the address of the space we got. 432 Return the address of the space we got.
490 If we cannot get space at END, fail and return 0. */ 433 If we cannot get space at END, fail and return 0. */
491static __ptr_t get_contiguous_space PP ((__malloc_ptrdiff_t, __ptr_t)); 434static void *
492static __ptr_t 435get_contiguous_space (ptrdiff_t size, void *position)
493get_contiguous_space (size, position)
494 __malloc_ptrdiff_t size;
495 __ptr_t position;
496{ 436{
497 __ptr_t before; 437 void *before;
498 __ptr_t after; 438 void *after;
499 439
500 before = (*__morecore) (0); 440 before = (*__morecore) (0);
501 /* If we can tell in advance that the break is at the wrong place, 441 /* If we can tell in advance that the break is at the wrong place,
@@ -525,7 +465,7 @@ get_contiguous_space (size, position)
525static inline void 465static inline void
526register_heapinfo (void) 466register_heapinfo (void)
527{ 467{
528 __malloc_size_t block, blocks; 468 size_t block, blocks;
529 469
530 block = BLOCK (_heapinfo); 470 block = BLOCK (_heapinfo);
531 blocks = BLOCKIFY (heapsize * sizeof (malloc_info)); 471 blocks = BLOCKIFY (heapsize * sizeof (malloc_info));
@@ -548,21 +488,21 @@ pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
548int _malloc_thread_enabled_p; 488int _malloc_thread_enabled_p;
549 489
550static void 490static void
551malloc_atfork_handler_prepare () 491malloc_atfork_handler_prepare (void)
552{ 492{
553 LOCK (); 493 LOCK ();
554 LOCK_ALIGNED_BLOCKS (); 494 LOCK_ALIGNED_BLOCKS ();
555} 495}
556 496
557static void 497static void
558malloc_atfork_handler_parent () 498malloc_atfork_handler_parent (void)
559{ 499{
560 UNLOCK_ALIGNED_BLOCKS (); 500 UNLOCK_ALIGNED_BLOCKS ();
561 UNLOCK (); 501 UNLOCK ();
562} 502}
563 503
564static void 504static void
565malloc_atfork_handler_child () 505malloc_atfork_handler_child (void)
566{ 506{
567 UNLOCK_ALIGNED_BLOCKS (); 507 UNLOCK_ALIGNED_BLOCKS ();
568 UNLOCK (); 508 UNLOCK ();
@@ -570,7 +510,7 @@ malloc_atfork_handler_child ()
570 510
571/* Set up mutexes and make malloc etc. thread-safe. */ 511/* Set up mutexes and make malloc etc. thread-safe. */
572void 512void
573malloc_enable_thread () 513malloc_enable_thread (void)
574{ 514{
575 if (_malloc_thread_enabled_p) 515 if (_malloc_thread_enabled_p)
576 return; 516 return;
@@ -589,7 +529,7 @@ malloc_enable_thread ()
589#endif 529#endif
590 530
591static void 531static void
592malloc_initialize_1 () 532malloc_initialize_1 (void)
593{ 533{
594#ifdef GC_MCHECK 534#ifdef GC_MCHECK
595 mcheck (NULL); 535 mcheck (NULL);
@@ -609,7 +549,7 @@ malloc_initialize_1 ()
609 (*__malloc_initialize_hook) (); 549 (*__malloc_initialize_hook) ();
610 550
611 heapsize = HEAP / BLOCKSIZE; 551 heapsize = HEAP / BLOCKSIZE;
612 _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info)); 552 _heapinfo = align (heapsize * sizeof (malloc_info));
613 if (_heapinfo == NULL) 553 if (_heapinfo == NULL)
614 return; 554 return;
615 memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); 555 memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
@@ -630,7 +570,7 @@ malloc_initialize_1 ()
630 main will call malloc which calls this function. That is before any threads 570 main will call malloc which calls this function. That is before any threads
631 or signal handlers has been set up, so we don't need thread protection. */ 571 or signal handlers has been set up, so we don't need thread protection. */
632int 572int
633__malloc_initialize () 573__malloc_initialize (void)
634{ 574{
635 if (__malloc_initialized) 575 if (__malloc_initialized)
636 return 0; 576 return 0;
@@ -644,14 +584,12 @@ static int morecore_recursing;
644 584
645/* Get neatly aligned memory, initializing or 585/* Get neatly aligned memory, initializing or
646 growing the heap info table as necessary. */ 586 growing the heap info table as necessary. */
647static __ptr_t morecore_nolock PP ((__malloc_size_t)); 587static void *
648static __ptr_t 588morecore_nolock (size_t size)
649morecore_nolock (size)
650 __malloc_size_t size;
651{ 589{
652 __ptr_t result; 590 void *result;
653 malloc_info *newinfo, *oldinfo; 591 malloc_info *newinfo, *oldinfo;
654 __malloc_size_t newsize; 592 size_t newsize;
655 593
656 if (morecore_recursing) 594 if (morecore_recursing)
657 /* Avoid recursion. The caller will know how to handle a null return. */ 595 /* Avoid recursion. The caller will know how to handle a null return. */
@@ -664,7 +602,7 @@ morecore_nolock (size)
664 PROTECT_MALLOC_STATE (0); 602 PROTECT_MALLOC_STATE (0);
665 603
666 /* Check if we need to grow the info table. */ 604 /* Check if we need to grow the info table. */
667 if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize) 605 if ((size_t) BLOCK ((char *) result + size) > heapsize)
668 { 606 {
669 /* Calculate the new _heapinfo table size. We do not account for the 607 /* Calculate the new _heapinfo table size. We do not account for the
670 added blocks in the table itself, as we hope to place them in 608 added blocks in the table itself, as we hope to place them in
@@ -673,7 +611,7 @@ morecore_nolock (size)
673 newsize = heapsize; 611 newsize = heapsize;
674 do 612 do
675 newsize *= 2; 613 newsize *= 2;
676 while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize); 614 while ((size_t) BLOCK ((char *) result + size) > newsize);
677 615
678 /* We must not reuse existing core for the new info table when called 616 /* We must not reuse existing core for the new info table when called
679 from realloc in the case of growing a large block, because the 617 from realloc in the case of growing a large block, because the
@@ -689,8 +627,8 @@ morecore_nolock (size)
689 `morecore_recursing' flag and return null. */ 627 `morecore_recursing' flag and return null. */
690 int save = errno; /* Don't want to clobber errno with ENOMEM. */ 628 int save = errno; /* Don't want to clobber errno with ENOMEM. */
691 morecore_recursing = 1; 629 morecore_recursing = 1;
692 newinfo = (malloc_info *) _realloc_internal_nolock 630 newinfo = _realloc_internal_nolock (_heapinfo,
693 (_heapinfo, newsize * sizeof (malloc_info)); 631 newsize * sizeof (malloc_info));
694 morecore_recursing = 0; 632 morecore_recursing = 0;
695 if (newinfo == NULL) 633 if (newinfo == NULL)
696 errno = save; 634 errno = save;
@@ -710,7 +648,7 @@ morecore_nolock (size)
710 /* Allocate new space for the malloc info table. */ 648 /* Allocate new space for the malloc info table. */
711 while (1) 649 while (1)
712 { 650 {
713 newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); 651 newinfo = align (newsize * sizeof (malloc_info));
714 652
715 /* Did it fail? */ 653 /* Did it fail? */
716 if (newinfo == NULL) 654 if (newinfo == NULL)
@@ -721,8 +659,8 @@ morecore_nolock (size)
721 659
722 /* Is it big enough to record status for its own space? 660 /* Is it big enough to record status for its own space?
723 If so, we win. */ 661 If so, we win. */
724 if ((__malloc_size_t) BLOCK ((char *) newinfo 662 if ((size_t) BLOCK ((char *) newinfo
725 + newsize * sizeof (malloc_info)) 663 + newsize * sizeof (malloc_info))
726 < newsize) 664 < newsize)
727 break; 665 break;
728 666
@@ -759,13 +697,12 @@ morecore_nolock (size)
759} 697}
760 698
761/* Allocate memory from the heap. */ 699/* Allocate memory from the heap. */
762__ptr_t 700void *
763_malloc_internal_nolock (size) 701_malloc_internal_nolock (size_t size)
764 __malloc_size_t size;
765{ 702{
766 __ptr_t result; 703 void *result;
767 __malloc_size_t block, blocks, lastblocks, start; 704 size_t block, blocks, lastblocks, start;
768 register __malloc_size_t i; 705 register size_t i;
769 struct list *next; 706 struct list *next;
770 707
771 /* ANSI C allows `malloc (0)' to either return NULL, or to return a 708 /* ANSI C allows `malloc (0)' to either return NULL, or to return a
@@ -790,7 +727,7 @@ _malloc_internal_nolock (size)
790 { 727 {
791 /* Small allocation to receive a fragment of a block. 728 /* Small allocation to receive a fragment of a block.
792 Determine the logarithm to base two of the fragment size. */ 729 Determine the logarithm to base two of the fragment size. */
793 register __malloc_size_t log = 1; 730 register size_t log = 1;
794 --size; 731 --size;
795 while ((size /= 2) != 0) 732 while ((size /= 2) != 0)
796 ++log; 733 ++log;
@@ -803,15 +740,14 @@ _malloc_internal_nolock (size)
803 /* There are free fragments of this size. 740 /* There are free fragments of this size.
804 Pop a fragment out of the fragment list and return it. 741 Pop a fragment out of the fragment list and return it.
805 Update the block's nfree and first counters. */ 742 Update the block's nfree and first counters. */
806 result = (__ptr_t) next; 743 result = next;
807 next->prev->next = next->next; 744 next->prev->next = next->next;
808 if (next->next != NULL) 745 if (next->next != NULL)
809 next->next->prev = next->prev; 746 next->next->prev = next->prev;
810 block = BLOCK (result); 747 block = BLOCK (result);
811 if (--_heapinfo[block].busy.info.frag.nfree != 0) 748 if (--_heapinfo[block].busy.info.frag.nfree != 0)
812 _heapinfo[block].busy.info.frag.first = (unsigned long int) 749 _heapinfo[block].busy.info.frag.first =
813 ((unsigned long int) ((char *) next->next - (char *) NULL) 750 (uintptr_t) next->next % BLOCKSIZE >> log;
814 % BLOCKSIZE) >> log;
815 751
816 /* Update the statistics. */ 752 /* Update the statistics. */
817 ++_chunks_used; 753 ++_chunks_used;
@@ -843,7 +779,7 @@ _malloc_internal_nolock (size)
843 next->prev = &_fraghead[log]; 779 next->prev = &_fraghead[log];
844 _fraghead[log].next = next; 780 _fraghead[log].next = next;
845 781
846 for (i = 2; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i) 782 for (i = 2; i < (size_t) (BLOCKSIZE >> log); ++i)
847 { 783 {
848 next = (struct list *) ((char *) result + (i << log)); 784 next = (struct list *) ((char *) result + (i << log));
849 next->next = _fraghead[log].next; 785 next->next = _fraghead[log].next;
@@ -877,7 +813,7 @@ _malloc_internal_nolock (size)
877 if (block == start) 813 if (block == start)
878 { 814 {
879 /* Need to get more from the system. Get a little extra. */ 815 /* Need to get more from the system. Get a little extra. */
880 __malloc_size_t wantblocks = blocks + __malloc_extra_blocks; 816 size_t wantblocks = blocks + __malloc_extra_blocks;
881 block = _heapinfo[0].free.prev; 817 block = _heapinfo[0].free.prev;
882 lastblocks = _heapinfo[block].free.size; 818 lastblocks = _heapinfo[block].free.size;
883 /* Check to see if the new core will be contiguous with the 819 /* Check to see if the new core will be contiguous with the
@@ -959,11 +895,10 @@ _malloc_internal_nolock (size)
959 return result; 895 return result;
960} 896}
961 897
962__ptr_t 898void *
963_malloc_internal (size) 899_malloc_internal (size_t size)
964 __malloc_size_t size;
965{ 900{
966 __ptr_t result; 901 void *result;
967 902
968 LOCK (); 903 LOCK ();
969 result = _malloc_internal_nolock (size); 904 result = _malloc_internal_nolock (size);
@@ -972,11 +907,10 @@ _malloc_internal (size)
972 return result; 907 return result;
973} 908}
974 909
975__ptr_t 910void *
976malloc (size) 911malloc (size_t size)
977 __malloc_size_t size;
978{ 912{
979 __ptr_t (*hook) (__malloc_size_t); 913 void *(*hook) (size_t);
980 914
981 if (!__malloc_initialized && !__malloc_initialize ()) 915 if (!__malloc_initialized && !__malloc_initialize ())
982 return NULL; 916 return NULL;
@@ -998,24 +932,24 @@ malloc (size)
998/* On some ANSI C systems, some libc functions call _malloc, _free 932/* On some ANSI C systems, some libc functions call _malloc, _free
999 and _realloc. Make them use the GNU functions. */ 933 and _realloc. Make them use the GNU functions. */
1000 934
1001__ptr_t 935extern void *_malloc (size_t);
1002_malloc (size) 936extern void _free (void *);
1003 __malloc_size_t size; 937extern void *_realloc (void *, size_t);
938
939void *
940_malloc (size_t size)
1004{ 941{
1005 return malloc (size); 942 return malloc (size);
1006} 943}
1007 944
1008void 945void
1009_free (ptr) 946_free (void *ptr)
1010 __ptr_t ptr;
1011{ 947{
1012 free (ptr); 948 free (ptr);
1013} 949}
1014 950
1015__ptr_t 951void *
1016_realloc (ptr, size) 952_realloc (void *ptr, size_t size)
1017 __ptr_t ptr;
1018 __malloc_size_t size;
1019{ 953{
1020 return realloc (ptr, size); 954 return realloc (ptr, size);
1021} 955}
@@ -1043,14 +977,9 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1043 The author may be reached (Email) at the address mike@ai.mit.edu, 977 The author may be reached (Email) at the address mike@ai.mit.edu,
1044 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 978 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1045 979
1046#ifndef _MALLOC_INTERNAL
1047#define _MALLOC_INTERNAL
1048#include <malloc.h>
1049#endif
1050
1051 980
1052/* Debugging hook for free. */ 981/* Debugging hook for free. */
1053void (*__free_hook) PP ((__ptr_t __ptr)); 982void (*__free_hook) (void *__ptr);
1054 983
1055/* List of blocks allocated by memalign. */ 984/* List of blocks allocated by memalign. */
1056struct alignlist *_aligned_blocks = NULL; 985struct alignlist *_aligned_blocks = NULL;
@@ -1058,15 +987,14 @@ struct alignlist *_aligned_blocks = NULL;
1058/* Return memory to the heap. 987/* Return memory to the heap.
1059 Like `_free_internal' but don't lock mutex. */ 988 Like `_free_internal' but don't lock mutex. */
1060void 989void
1061_free_internal_nolock (ptr) 990_free_internal_nolock (void *ptr)
1062 __ptr_t ptr;
1063{ 991{
1064 int type; 992 int type;
1065 __malloc_size_t block, blocks; 993 size_t block, blocks;
1066 register __malloc_size_t i; 994 register size_t i;
1067 struct list *prev, *next; 995 struct list *prev, *next;
1068 __ptr_t curbrk; 996 void *curbrk;
1069 const __malloc_size_t lesscore_threshold 997 const size_t lesscore_threshold
1070 /* Threshold of free space at which we will return some to the system. */ 998 /* Threshold of free space at which we will return some to the system. */
1071 = FINAL_FREE_BLOCKS + 2 * __malloc_extra_blocks; 999 = FINAL_FREE_BLOCKS + 2 * __malloc_extra_blocks;
1072 1000
@@ -1076,7 +1004,7 @@ _free_internal_nolock (ptr)
1076 return; 1004 return;
1077 1005
1078#ifdef CYGWIN 1006#ifdef CYGWIN
1079 if (ptr < _heapbase) 1007 if ((char *) ptr < _heapbase)
1080 /* We're being asked to free something in the static heap. */ 1008 /* We're being asked to free something in the static heap. */
1081 return; 1009 return;
1082#endif 1010#endif
@@ -1162,12 +1090,12 @@ _free_internal_nolock (ptr)
1162 It's possible that moving _heapinfo will allow us to 1090 It's possible that moving _heapinfo will allow us to
1163 return some space to the system. */ 1091 return some space to the system. */
1164 1092
1165 __malloc_size_t info_block = BLOCK (_heapinfo); 1093 size_t info_block = BLOCK (_heapinfo);
1166 __malloc_size_t info_blocks = _heapinfo[info_block].busy.info.size; 1094 size_t info_blocks = _heapinfo[info_block].busy.info.size;
1167 __malloc_size_t prev_block = _heapinfo[block].free.prev; 1095 size_t prev_block = _heapinfo[block].free.prev;
1168 __malloc_size_t prev_blocks = _heapinfo[prev_block].free.size; 1096 size_t prev_blocks = _heapinfo[prev_block].free.size;
1169 __malloc_size_t next_block = _heapinfo[block].free.next; 1097 size_t next_block = _heapinfo[block].free.next;
1170 __malloc_size_t next_blocks = _heapinfo[next_block].free.size; 1098 size_t next_blocks = _heapinfo[next_block].free.size;
1171 1099
1172 if (/* Win if this block being freed is last in core, the info table 1100 if (/* Win if this block being freed is last in core, the info table
1173 is just before it, the previous free block is just before the 1101 is just before it, the previous free block is just before the
@@ -1190,7 +1118,7 @@ _free_internal_nolock (ptr)
1190 ) 1118 )
1191 { 1119 {
1192 malloc_info *newinfo; 1120 malloc_info *newinfo;
1193 __malloc_size_t oldlimit = _heaplimit; 1121 size_t oldlimit = _heaplimit;
1194 1122
1195 /* Free the old info table, clearing _heaplimit to avoid 1123 /* Free the old info table, clearing _heaplimit to avoid
1196 recursion into this code. We don't want to return the 1124 recursion into this code. We don't want to return the
@@ -1205,8 +1133,7 @@ _free_internal_nolock (ptr)
1205 _heapindex = 0; 1133 _heapindex = 0;
1206 1134
1207 /* Allocate new space for the info table and move its data. */ 1135 /* Allocate new space for the info table and move its data. */
1208 newinfo = (malloc_info *) _malloc_internal_nolock (info_blocks 1136 newinfo = _malloc_internal_nolock (info_blocks * BLOCKSIZE);
1209 * BLOCKSIZE);
1210 PROTECT_MALLOC_STATE (0); 1137 PROTECT_MALLOC_STATE (0);
1211 memmove (newinfo, _heapinfo, info_blocks * BLOCKSIZE); 1138 memmove (newinfo, _heapinfo, info_blocks * BLOCKSIZE);
1212 _heapinfo = newinfo; 1139 _heapinfo = newinfo;
@@ -1222,7 +1149,7 @@ _free_internal_nolock (ptr)
1222 /* Now see if we can return stuff to the system. */ 1149 /* Now see if we can return stuff to the system. */
1223 if (block + blocks == _heaplimit && blocks >= lesscore_threshold) 1150 if (block + blocks == _heaplimit && blocks >= lesscore_threshold)
1224 { 1151 {
1225 register __malloc_size_t bytes = blocks * BLOCKSIZE; 1152 register size_t bytes = blocks * BLOCKSIZE;
1226 _heaplimit -= blocks; 1153 _heaplimit -= blocks;
1227 (*__morecore) (-bytes); 1154 (*__morecore) (-bytes);
1228 _heapinfo[_heapinfo[block].free.prev].free.next 1155 _heapinfo[_heapinfo[block].free.prev].free.next
@@ -1255,7 +1182,7 @@ _free_internal_nolock (ptr)
1255 /* If all fragments of this block are free, remove them 1182 /* If all fragments of this block are free, remove them
1256 from the fragment list and free the whole block. */ 1183 from the fragment list and free the whole block. */
1257 next = prev; 1184 next = prev;
1258 for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i) 1185 for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i)
1259 next = next->next; 1186 next = next->next;
1260 prev->prev->next = next; 1187 prev->prev->next = next;
1261 if (next != NULL) 1188 if (next != NULL)
@@ -1280,7 +1207,7 @@ _free_internal_nolock (ptr)
1280 /* If some fragments of this block are free, link this 1207 /* If some fragments of this block are free, link this
1281 fragment into the fragment list after the first free 1208 fragment into the fragment list after the first free
1282 fragment of this block. */ 1209 fragment of this block. */
1283 next = (struct list *) ptr; 1210 next = ptr;
1284 next->next = prev->next; 1211 next->next = prev->next;
1285 next->prev = prev; 1212 next->prev = prev;
1286 prev->next = next; 1213 prev->next = next;
@@ -1293,11 +1220,10 @@ _free_internal_nolock (ptr)
1293 /* No fragments of this block are free, so link this 1220 /* No fragments of this block are free, so link this
1294 fragment into the fragment list and announce that 1221 fragment into the fragment list and announce that
1295 it is the first free fragment of this block. */ 1222 it is the first free fragment of this block. */
1296 prev = (struct list *) ptr; 1223 prev = ptr;
1297 _heapinfo[block].busy.info.frag.nfree = 1; 1224 _heapinfo[block].busy.info.frag.nfree = 1;
1298 _heapinfo[block].busy.info.frag.first = (unsigned long int) 1225 _heapinfo[block].busy.info.frag.first =
1299 ((unsigned long int) ((char *) ptr - (char *) NULL) 1226 (uintptr_t) ptr % BLOCKSIZE >> type;
1300 % BLOCKSIZE >> type);
1301 prev->next = _fraghead[type].next; 1227 prev->next = _fraghead[type].next;
1302 prev->prev = &_fraghead[type]; 1228 prev->prev = &_fraghead[type];
1303 prev->prev->next = prev; 1229 prev->prev->next = prev;
@@ -1313,8 +1239,7 @@ _free_internal_nolock (ptr)
1313/* Return memory to the heap. 1239/* Return memory to the heap.
1314 Like `free' but don't call a __free_hook if there is one. */ 1240 Like `free' but don't call a __free_hook if there is one. */
1315void 1241void
1316_free_internal (ptr) 1242_free_internal (void *ptr)
1317 __ptr_t ptr;
1318{ 1243{
1319 LOCK (); 1244 LOCK ();
1320 _free_internal_nolock (ptr); 1245 _free_internal_nolock (ptr);
@@ -1324,10 +1249,9 @@ _free_internal (ptr)
1324/* Return memory to the heap. */ 1249/* Return memory to the heap. */
1325 1250
1326void 1251void
1327free (ptr) 1252free (void *ptr)
1328 __ptr_t ptr;
1329{ 1253{
1330 void (*hook) (__ptr_t) = __free_hook; 1254 void (*hook) (void *) = __free_hook;
1331 1255
1332 if (hook != NULL) 1256 if (hook != NULL)
1333 (*hook) (ptr); 1257 (*hook) (ptr);
@@ -1340,8 +1264,7 @@ free (ptr)
1340weak_alias (free, cfree) 1264weak_alias (free, cfree)
1341#else 1265#else
1342void 1266void
1343cfree (ptr) 1267cfree (void *ptr)
1344 __ptr_t ptr;
1345{ 1268{
1346 free (ptr); 1269 free (ptr);
1347} 1270}
@@ -1368,32 +1291,24 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1368 The author may be reached (Email) at the address mike@ai.mit.edu, 1291 The author may be reached (Email) at the address mike@ai.mit.edu,
1369 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1292 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1370 1293
1371#ifndef _MALLOC_INTERNAL
1372#define _MALLOC_INTERNAL
1373#include <malloc.h>
1374#endif
1375
1376
1377#define min(A, B) ((A) < (B) ? (A) : (B)) 1294#define min(A, B) ((A) < (B) ? (A) : (B))
1378 1295
1379/* On Cygwin the dumped emacs may try to realloc storage allocated in 1296/* On Cygwin the dumped emacs may try to realloc storage allocated in
1380 the static heap. We just malloc space in the new heap and copy the 1297 the static heap. We just malloc space in the new heap and copy the
1381 data. */ 1298 data. */
1382#ifdef CYGWIN 1299#ifdef CYGWIN
1383__ptr_t 1300void *
1384special_realloc (ptr, size) 1301special_realloc (void *ptr, size_t size)
1385 __ptr_t ptr;
1386 __malloc_size_t size;
1387{ 1302{
1388 __ptr_t result; 1303 void *result;
1389 int type; 1304 int type;
1390 __malloc_size_t block, oldsize; 1305 size_t block, oldsize;
1391 1306
1392 block = ((char *) ptr - bss_sbrk_heapbase) / BLOCKSIZE + 1; 1307 block = ((char *) ptr - bss_sbrk_heapbase) / BLOCKSIZE + 1;
1393 type = bss_sbrk_heapinfo[block].busy.type; 1308 type = bss_sbrk_heapinfo[block].busy.type;
1394 oldsize = 1309 oldsize =
1395 type == 0 ? bss_sbrk_heapinfo[block].busy.info.size * BLOCKSIZE 1310 type == 0 ? bss_sbrk_heapinfo[block].busy.info.size * BLOCKSIZE
1396 : (__malloc_size_t) 1 << type; 1311 : (size_t) 1 << type;
1397 result = _malloc_internal_nolock (size); 1312 result = _malloc_internal_nolock (size);
1398 if (result != NULL) 1313 if (result != NULL)
1399 memcpy (result, ptr, min (oldsize, size)); 1314 memcpy (result, ptr, min (oldsize, size));
@@ -1402,7 +1317,7 @@ special_realloc (ptr, size)
1402#endif 1317#endif
1403 1318
1404/* Debugging hook for realloc. */ 1319/* Debugging hook for realloc. */
1405__ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size)); 1320void *(*__realloc_hook) (void *ptr, size_t size);
1406 1321
1407/* Resize the given region to the new size, returning a pointer 1322/* Resize the given region to the new size, returning a pointer
1408 to the (possibly moved) region. This is optimized for speed; 1323 to the (possibly moved) region. This is optimized for speed;
@@ -1410,14 +1325,12 @@ __ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size));
1410 achieved by unconditionally allocating and copying to a 1325 achieved by unconditionally allocating and copying to a
1411 new region. This module has incestuous knowledge of the 1326 new region. This module has incestuous knowledge of the
1412 internals of both free and malloc. */ 1327 internals of both free and malloc. */
1413__ptr_t 1328void *
1414_realloc_internal_nolock (ptr, size) 1329_realloc_internal_nolock (void *ptr, size_t size)
1415 __ptr_t ptr;
1416 __malloc_size_t size;
1417{ 1330{
1418 __ptr_t result; 1331 void *result;
1419 int type; 1332 int type;
1420 __malloc_size_t block, blocks, oldlimit; 1333 size_t block, blocks, oldlimit;
1421 1334
1422 if (size == 0) 1335 if (size == 0)
1423 { 1336 {
@@ -1428,7 +1341,7 @@ _realloc_internal_nolock (ptr, size)
1428 return _malloc_internal_nolock (size); 1341 return _malloc_internal_nolock (size);
1429 1342
1430#ifdef CYGWIN 1343#ifdef CYGWIN
1431 if (ptr < _heapbase) 1344 if ((char *) ptr < _heapbase)
1432 /* ptr points into the static heap */ 1345 /* ptr points into the static heap */
1433 return special_realloc (ptr, size); 1346 return special_realloc (ptr, size);
1434#endif 1347#endif
@@ -1497,7 +1410,7 @@ _realloc_internal_nolock (ptr, size)
1497 (void) _malloc_internal_nolock (blocks * BLOCKSIZE); 1410 (void) _malloc_internal_nolock (blocks * BLOCKSIZE);
1498 else 1411 else
1499 { 1412 {
1500 __ptr_t previous 1413 void *previous
1501 = _malloc_internal_nolock ((block - _heapindex) * BLOCKSIZE); 1414 = _malloc_internal_nolock ((block - _heapindex) * BLOCKSIZE);
1502 (void) _malloc_internal_nolock (blocks * BLOCKSIZE); 1415 (void) _malloc_internal_nolock (blocks * BLOCKSIZE);
1503 _free_internal_nolock (previous); 1416 _free_internal_nolock (previous);
@@ -1512,8 +1425,8 @@ _realloc_internal_nolock (ptr, size)
1512 default: 1425 default:
1513 /* Old size is a fragment; type is logarithm 1426 /* Old size is a fragment; type is logarithm
1514 to base two of the fragment size. */ 1427 to base two of the fragment size. */
1515 if (size > (__malloc_size_t) (1 << (type - 1)) && 1428 if (size > (size_t) (1 << (type - 1)) &&
1516 size <= (__malloc_size_t) (1 << type)) 1429 size <= (size_t) (1 << type))
1517 /* The new size is the same kind of fragment. */ 1430 /* The new size is the same kind of fragment. */
1518 result = ptr; 1431 result = ptr;
1519 else 1432 else
@@ -1523,7 +1436,7 @@ _realloc_internal_nolock (ptr, size)
1523 result = _malloc_internal_nolock (size); 1436 result = _malloc_internal_nolock (size);
1524 if (result == NULL) 1437 if (result == NULL)
1525 goto out; 1438 goto out;
1526 memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type)); 1439 memcpy (result, ptr, min (size, (size_t) 1 << type));
1527 _free_internal_nolock (ptr); 1440 _free_internal_nolock (ptr);
1528 } 1441 }
1529 break; 1442 break;
@@ -1534,12 +1447,10 @@ _realloc_internal_nolock (ptr, size)
1534 return result; 1447 return result;
1535} 1448}
1536 1449
1537__ptr_t 1450void *
1538_realloc_internal (ptr, size) 1451_realloc_internal (void *ptr, size_t size)
1539 __ptr_t ptr;
1540 __malloc_size_t size;
1541{ 1452{
1542 __ptr_t result; 1453 void *result;
1543 1454
1544 LOCK (); 1455 LOCK ();
1545 result = _realloc_internal_nolock (ptr, size); 1456 result = _realloc_internal_nolock (ptr, size);
@@ -1548,12 +1459,10 @@ _realloc_internal (ptr, size)
1548 return result; 1459 return result;
1549} 1460}
1550 1461
1551__ptr_t 1462void *
1552realloc (ptr, size) 1463realloc (void *ptr, size_t size)
1553 __ptr_t ptr;
1554 __malloc_size_t size;
1555{ 1464{
1556 __ptr_t (*hook) (__ptr_t, __malloc_size_t); 1465 void *(*hook) (void *, size_t);
1557 1466
1558 if (!__malloc_initialized && !__malloc_initialize ()) 1467 if (!__malloc_initialized && !__malloc_initialize ())
1559 return NULL; 1468 return NULL;
@@ -1581,19 +1490,12 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1581 The author may be reached (Email) at the address mike@ai.mit.edu, 1490 The author may be reached (Email) at the address mike@ai.mit.edu,
1582 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1491 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1583 1492
1584#ifndef _MALLOC_INTERNAL
1585#define _MALLOC_INTERNAL
1586#include <malloc.h>
1587#endif
1588
1589/* Allocate an array of NMEMB elements each SIZE bytes long. 1493/* Allocate an array of NMEMB elements each SIZE bytes long.
1590 The entire array is initialized to zeros. */ 1494 The entire array is initialized to zeros. */
1591__ptr_t 1495void *
1592calloc (nmemb, size) 1496calloc (register size_t nmemb, register size_t size)
1593 register __malloc_size_t nmemb;
1594 register __malloc_size_t size;
1595{ 1497{
1596 register __ptr_t result = malloc (nmemb * size); 1498 register void *result = malloc (nmemb * size);
1597 1499
1598 if (result != NULL) 1500 if (result != NULL)
1599 (void) memset (result, 0, nmemb * size); 1501 (void) memset (result, 0, nmemb * size);
@@ -1618,11 +1520,6 @@ along with the GNU C Library; see the file COPYING. If not, write to
1618the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 1520the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
1619MA 02110-1301, USA. */ 1521MA 02110-1301, USA. */
1620 1522
1621#ifndef _MALLOC_INTERNAL
1622#define _MALLOC_INTERNAL
1623#include <malloc.h>
1624#endif
1625
1626/* uClibc defines __GNU_LIBRARY__, but it is not completely 1523/* uClibc defines __GNU_LIBRARY__, but it is not completely
1627 compatible. */ 1524 compatible. */
1628#if !defined (__GNU_LIBRARY__) || defined (__UCLIBC__) 1525#if !defined (__GNU_LIBRARY__) || defined (__UCLIBC__)
@@ -1631,8 +1528,7 @@ MA 02110-1301, USA. */
1631/* It is best not to declare this and cast its result on foreign operating 1528/* It is best not to declare this and cast its result on foreign operating
1632 systems with potentially hostile include files. */ 1529 systems with potentially hostile include files. */
1633 1530
1634#include <stddef.h> 1531extern void *__sbrk (ptrdiff_t increment);
1635extern __ptr_t __sbrk PP ((ptrdiff_t increment));
1636#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */ 1532#endif /* __GNU_LIBRARY__ && ! defined (__UCLIBC__) */
1637 1533
1638#ifndef NULL 1534#ifndef NULL
@@ -1642,19 +1538,18 @@ extern __ptr_t __sbrk PP ((ptrdiff_t increment));
1642/* Allocate INCREMENT more bytes of data space, 1538/* Allocate INCREMENT more bytes of data space,
1643 and return the start of data space, or NULL on errors. 1539 and return the start of data space, or NULL on errors.
1644 If INCREMENT is negative, shrink data space. */ 1540 If INCREMENT is negative, shrink data space. */
1645__ptr_t 1541void *
1646__default_morecore (increment) 1542__default_morecore (ptrdiff_t increment)
1647 __malloc_ptrdiff_t increment;
1648{ 1543{
1649 __ptr_t result; 1544 void *result;
1650#if defined (CYGWIN) 1545#if defined (CYGWIN)
1651 if (!bss_sbrk_did_unexec) 1546 if (!bss_sbrk_did_unexec)
1652 { 1547 {
1653 return bss_sbrk (increment); 1548 return bss_sbrk (increment);
1654 } 1549 }
1655#endif 1550#endif
1656 result = (__ptr_t) __sbrk (increment); 1551 result = (void *) __sbrk (increment);
1657 if (result == (__ptr_t) -1) 1552 if (result == (void *) -1)
1658 return NULL; 1553 return NULL;
1659 return result; 1554 return result;
1660} 1555}
@@ -1675,22 +1570,14 @@ License along with this library; see the file COPYING. If
1675not, write to the Free Software Foundation, Inc., 51 Franklin Street, 1570not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1676Fifth Floor, Boston, MA 02110-1301, USA. */ 1571Fifth Floor, Boston, MA 02110-1301, USA. */
1677 1572
1678#ifndef _MALLOC_INTERNAL 1573void *(*__memalign_hook) (size_t size, size_t alignment);
1679#define _MALLOC_INTERNAL
1680#include <malloc.h>
1681#endif
1682
1683__ptr_t (*__memalign_hook) PP ((__malloc_size_t __size,
1684 __malloc_size_t __alignment));
1685 1574
1686__ptr_t 1575void *
1687memalign (alignment, size) 1576memalign (size_t alignment, size_t size)
1688 __malloc_size_t alignment;
1689 __malloc_size_t size;
1690{ 1577{
1691 __ptr_t result; 1578 void *result;
1692 unsigned long int adj, lastadj; 1579 size_t adj, lastadj;
1693 __ptr_t (*hook) (__malloc_size_t, __malloc_size_t) = __memalign_hook; 1580 void *(*hook) (size_t, size_t) = __memalign_hook;
1694 1581
1695 if (hook) 1582 if (hook)
1696 return (*hook) (alignment, size); 1583 return (*hook) (alignment, size);
@@ -1703,7 +1590,7 @@ memalign (alignment, size)
1703 1590
1704 /* Figure out how much we will need to pad this particular block 1591 /* Figure out how much we will need to pad this particular block
1705 to achieve the required alignment. */ 1592 to achieve the required alignment. */
1706 adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; 1593 adj = (uintptr_t) result % alignment;
1707 1594
1708 do 1595 do
1709 { 1596 {
@@ -1714,7 +1601,7 @@ memalign (alignment, size)
1714 return NULL; 1601 return NULL;
1715 1602
1716 lastadj = adj; 1603 lastadj = adj;
1717 adj = (unsigned long int) ((char *) result - (char *) NULL) % alignment; 1604 adj = (uintptr_t) result % alignment;
1718 /* It's conceivable we might have been so unlucky as to get a 1605 /* It's conceivable we might have been so unlucky as to get a
1719 different block with weaker alignment. If so, this block is too 1606 different block with weaker alignment. If so, this block is too
1720 short to contain SIZE after alignment correction. So we must 1607 short to contain SIZE after alignment correction. So we must
@@ -1735,7 +1622,7 @@ memalign (alignment, size)
1735 break; 1622 break;
1736 if (l == NULL) 1623 if (l == NULL)
1737 { 1624 {
1738 l = (struct alignlist *) malloc (sizeof (struct alignlist)); 1625 l = malloc (sizeof (struct alignlist));
1739 if (l != NULL) 1626 if (l != NULL)
1740 { 1627 {
1741 l->next = _aligned_blocks; 1628 l->next = _aligned_blocks;
@@ -1767,15 +1654,12 @@ memalign (alignment, size)
1767#endif 1654#endif
1768 1655
1769int 1656int
1770posix_memalign (memptr, alignment, size) 1657posix_memalign (void **memptr, size_t alignment, size_t size)
1771 __ptr_t *memptr;
1772 __malloc_size_t alignment;
1773 __malloc_size_t size;
1774{ 1658{
1775 __ptr_t mem; 1659 void *mem;
1776 1660
1777 if (alignment == 0 1661 if (alignment == 0
1778 || alignment % sizeof (__ptr_t) != 0 1662 || alignment % sizeof (void *) != 0
1779 || (alignment & (alignment - 1)) != 0) 1663 || (alignment & (alignment - 1)) != 0)
1780 return EINVAL; 1664 return EINVAL;
1781 1665
@@ -1809,43 +1693,27 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1809 The author may be reached (Email) at the address mike@ai.mit.edu, 1693 The author may be reached (Email) at the address mike@ai.mit.edu,
1810 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1694 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1811 1695
1812#if defined (_MALLOC_INTERNAL) && defined (GMALLOC_INHIBIT_VALLOC)
1813
1814/* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition 1696/* Emacs defines GMALLOC_INHIBIT_VALLOC to avoid this definition
1815 on MSDOS, where it conflicts with a system header file. */ 1697 on MSDOS, where it conflicts with a system header file. */
1816 1698
1817#define ELIDE_VALLOC 1699#ifndef GMALLOC_INHIBIT_VALLOC
1818
1819#endif
1820
1821#ifndef ELIDE_VALLOC
1822 1700
1823#if defined (__GNU_LIBRARY__) || defined (_LIBC) 1701/* Allocate SIZE bytes on a page boundary. */
1824#include <stddef.h> 1702extern void *valloc (size_t);
1825#include <sys/cdefs.h>
1826#if defined (__GLIBC__) && __GLIBC__ >= 2
1827/* __getpagesize is already declared in <unistd.h> with return type int */
1828#else
1829extern size_t __getpagesize PP ((void));
1830#endif
1831#else
1832#include "getpagesize.h"
1833#define __getpagesize() getpagesize ()
1834#endif
1835 1703
1836#ifndef _MALLOC_INTERNAL 1704#if defined _SC_PAGESIZE || !defined HAVE_GETPAGESIZE
1837#define _MALLOC_INTERNAL 1705# include "getpagesize.h"
1838#include <malloc.h> 1706#elif !defined getpagesize
1707extern int getpagesize (void);
1839#endif 1708#endif
1840 1709
1841static __malloc_size_t pagesize; 1710static size_t pagesize;
1842 1711
1843__ptr_t 1712void *
1844valloc (size) 1713valloc (size_t size)
1845 __malloc_size_t size;
1846{ 1714{
1847 if (pagesize == 0) 1715 if (pagesize == 0)
1848 pagesize = __getpagesize (); 1716 pagesize = getpagesize ();
1849 1717
1850 return memalign (pagesize, size); 1718 return memalign (pagesize, size);
1851} 1719}
@@ -1876,41 +1744,31 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1876 The author may be reached (Email) at the address mike@ai.mit.edu, 1744 The author may be reached (Email) at the address mike@ai.mit.edu,
1877 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1745 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1878 1746
1879#ifdef emacs
1880#include <stdio.h>
1881#else
1882#ifndef _MALLOC_INTERNAL
1883#define _MALLOC_INTERNAL
1884#include <malloc.h>
1885#include <stdio.h> 1747#include <stdio.h>
1886#endif
1887#endif
1888 1748
1889/* Old hook values. */ 1749/* Old hook values. */
1890static void (*old_free_hook) (__ptr_t ptr); 1750static void (*old_free_hook) (void *ptr);
1891static __ptr_t (*old_malloc_hook) (__malloc_size_t size); 1751static void *(*old_malloc_hook) (size_t size);
1892static __ptr_t (*old_realloc_hook) (__ptr_t ptr, __malloc_size_t size); 1752static void *(*old_realloc_hook) (void *ptr, size_t size);
1893 1753
1894/* Function to call when something awful happens. */ 1754/* Function to call when something awful happens. */
1895static void (*abortfunc) (enum mcheck_status); 1755static void (*abortfunc) (enum mcheck_status);
1896 1756
1897/* Arbitrary magical numbers. */ 1757/* Arbitrary magical numbers. */
1898#define MAGICWORD 0xfedabeeb 1758#define MAGICWORD (SIZE_MAX / 11 ^ SIZE_MAX / 13 << 3)
1899#define MAGICFREE 0xd8675309 1759#define MAGICFREE (SIZE_MAX / 17 ^ SIZE_MAX / 19 << 4)
1900#define MAGICBYTE ((char) 0xd7) 1760#define MAGICBYTE ((char) 0xd7)
1901#define MALLOCFLOOD ((char) 0x93) 1761#define MALLOCFLOOD ((char) 0x93)
1902#define FREEFLOOD ((char) 0x95) 1762#define FREEFLOOD ((char) 0x95)
1903 1763
1904struct hdr 1764struct hdr
1905 { 1765 {
1906 __malloc_size_t size; /* Exact size requested by user. */ 1766 size_t size; /* Exact size requested by user. */
1907 unsigned long int magic; /* Magic number to check header integrity. */ 1767 size_t magic; /* Magic number to check header integrity. */
1908 }; 1768 };
1909 1769
1910static enum mcheck_status checkhdr (const struct hdr *);
1911static enum mcheck_status 1770static enum mcheck_status
1912checkhdr (hdr) 1771checkhdr (const struct hdr *hdr)
1913 const struct hdr *hdr;
1914{ 1772{
1915 enum mcheck_status status; 1773 enum mcheck_status status;
1916 switch (hdr->magic) 1774 switch (hdr->magic)
@@ -1933,10 +1791,8 @@ checkhdr (hdr)
1933 return status; 1791 return status;
1934} 1792}
1935 1793
1936static void freehook (__ptr_t);
1937static void 1794static void
1938freehook (ptr) 1795freehook (void *ptr)
1939 __ptr_t ptr;
1940{ 1796{
1941 struct hdr *hdr; 1797 struct hdr *hdr;
1942 1798
@@ -1955,15 +1811,13 @@ freehook (ptr)
1955 __free_hook = freehook; 1811 __free_hook = freehook;
1956} 1812}
1957 1813
1958static __ptr_t mallochook (__malloc_size_t); 1814static void *
1959static __ptr_t 1815mallochook (size_t size)
1960mallochook (size)
1961 __malloc_size_t size;
1962{ 1816{
1963 struct hdr *hdr; 1817 struct hdr *hdr;
1964 1818
1965 __malloc_hook = old_malloc_hook; 1819 __malloc_hook = old_malloc_hook;
1966 hdr = (struct hdr *) malloc (sizeof (struct hdr) + size + 1); 1820 hdr = malloc (sizeof (struct hdr) + size + 1);
1967 __malloc_hook = mallochook; 1821 __malloc_hook = mallochook;
1968 if (hdr == NULL) 1822 if (hdr == NULL)
1969 return NULL; 1823 return NULL;
@@ -1971,18 +1825,15 @@ mallochook (size)
1971 hdr->size = size; 1825 hdr->size = size;
1972 hdr->magic = MAGICWORD; 1826 hdr->magic = MAGICWORD;
1973 ((char *) &hdr[1])[size] = MAGICBYTE; 1827 ((char *) &hdr[1])[size] = MAGICBYTE;
1974 memset ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); 1828 memset (hdr + 1, MALLOCFLOOD, size);
1975 return (__ptr_t) (hdr + 1); 1829 return hdr + 1;
1976} 1830}
1977 1831
1978static __ptr_t reallochook (__ptr_t, __malloc_size_t); 1832static void *
1979static __ptr_t 1833reallochook (void *ptr, size_t size)
1980reallochook (ptr, size)
1981 __ptr_t ptr;
1982 __malloc_size_t size;
1983{ 1834{
1984 struct hdr *hdr = NULL; 1835 struct hdr *hdr = NULL;
1985 __malloc_size_t osize = 0; 1836 size_t osize = 0;
1986 1837
1987 if (ptr) 1838 if (ptr)
1988 { 1839 {
@@ -1997,7 +1848,7 @@ reallochook (ptr, size)
1997 __free_hook = old_free_hook; 1848 __free_hook = old_free_hook;
1998 __malloc_hook = old_malloc_hook; 1849 __malloc_hook = old_malloc_hook;
1999 __realloc_hook = old_realloc_hook; 1850 __realloc_hook = old_realloc_hook;
2000 hdr = (struct hdr *) realloc ((__ptr_t) hdr, sizeof (struct hdr) + size + 1); 1851 hdr = realloc (hdr, sizeof (struct hdr) + size + 1);
2001 __free_hook = freehook; 1852 __free_hook = freehook;
2002 __malloc_hook = mallochook; 1853 __malloc_hook = mallochook;
2003 __realloc_hook = reallochook; 1854 __realloc_hook = reallochook;
@@ -2009,12 +1860,11 @@ reallochook (ptr, size)
2009 ((char *) &hdr[1])[size] = MAGICBYTE; 1860 ((char *) &hdr[1])[size] = MAGICBYTE;
2010 if (size > osize) 1861 if (size > osize)
2011 memset ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); 1862 memset ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize);
2012 return (__ptr_t) (hdr + 1); 1863 return hdr + 1;
2013} 1864}
2014 1865
2015static void 1866static void
2016mabort (status) 1867mabort (enum mcheck_status status)
2017 enum mcheck_status status;
2018{ 1868{
2019 const char *msg; 1869 const char *msg;
2020 switch (status) 1870 switch (status)
@@ -2047,8 +1897,7 @@ mabort (status)
2047static int mcheck_used = 0; 1897static int mcheck_used = 0;
2048 1898
2049int 1899int
2050mcheck (func) 1900mcheck (void (*func) (enum mcheck_status))
2051 void (*func) (enum mcheck_status);
2052{ 1901{
2053 abortfunc = (func != NULL) ? func : &mabort; 1902 abortfunc = (func != NULL) ? func : &mabort;
2054 1903
@@ -2068,7 +1917,7 @@ mcheck (func)
2068} 1917}
2069 1918
2070enum mcheck_status 1919enum mcheck_status
2071mprobe (__ptr_t ptr) 1920mprobe (void *ptr)
2072{ 1921{
2073 return mcheck_used ? checkhdr (ptr) : MCHECK_DISABLED; 1922 return mcheck_used ? checkhdr (ptr) : MCHECK_DISABLED;
2074} 1923}
diff --git a/src/gnutls.c b/src/gnutls.c
index 70eea3b0b89..cf471314849 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -200,8 +200,12 @@ init_gnutls_functions (Lisp_Object libraries)
200 200
201 max_log_level = global_gnutls_log_level; 201 max_log_level = global_gnutls_log_level;
202 202
203 GNUTLS_LOG2 (1, max_log_level, "GnuTLS library loaded:", 203 {
204 SDATA (Fget (Qgnutls_dll, QCloaded_from))); 204 Lisp_Object name = CAR_SAFE (Fget (Qgnutls_dll, QCloaded_from));
205 GNUTLS_LOG2 (1, max_log_level, "GnuTLS library loaded:",
206 STRINGP (name) ? (const char *) SDATA (name) : "unknown");
207 }
208
205 return 1; 209 return 1;
206} 210}
207 211
@@ -419,7 +423,7 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, EMACS_INT nbyte)
419 { 423 {
420 proc->gnutls_handshakes_tried++; 424 proc->gnutls_handshakes_tried++;
421 emacs_gnutls_handshake (proc); 425 emacs_gnutls_handshake (proc);
422 GNUTLS_LOG2i (5, log_level, "Retried handshake", 426 GNUTLS_LOG2i (5, log_level, "Retried handshake",
423 proc->gnutls_handshakes_tried); 427 proc->gnutls_handshakes_tried);
424 return -1; 428 return -1;
425 } 429 }
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 4dbef65dedf..c8a505273fe 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1090,7 +1090,9 @@ xg_create_frame_widgets (FRAME_PTR f)
1090 GtkWidget *wtop; 1090 GtkWidget *wtop;
1091 GtkWidget *wvbox, *whbox; 1091 GtkWidget *wvbox, *whbox;
1092 GtkWidget *wfixed; 1092 GtkWidget *wfixed;
1093#ifndef HAVE_GTK3
1093 GtkRcStyle *style; 1094 GtkRcStyle *style;
1095#endif
1094 char *title = 0; 1096 char *title = 0;
1095 1097
1096 BLOCK_INPUT; 1098 BLOCK_INPUT;
diff --git a/src/intervals.c b/src/intervals.c
index 88f47f58b52..a750ccd13f7 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -1000,6 +1000,7 @@ adjust_intervals_for_insertion (INTERVAL tree,
1000 Lisp_Object pleft, pright; 1000 Lisp_Object pleft, pright;
1001 struct interval newi; 1001 struct interval newi;
1002 1002
1003 RESET_INTERVAL (&newi);
1003 pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist; 1004 pleft = NULL_INTERVAL_P (prev) ? Qnil : prev->plist;
1004 pright = NULL_INTERVAL_P (i) ? Qnil : i->plist; 1005 pright = NULL_INTERVAL_P (i) ? Qnil : i->plist;
1005 newi.plist = merge_properties_sticky (pleft, pright); 1006 newi.plist = merge_properties_sticky (pleft, pright);
diff --git a/src/keyboard.c b/src/keyboard.c
index 133b28234a8..82609bb4cb2 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1203,6 +1203,12 @@ This also exits all active minibuffers. */)
1203 Fthrow (Qtop_level, Qnil); 1203 Fthrow (Qtop_level, Qnil);
1204} 1204}
1205 1205
1206static void user_error (const char*) NO_RETURN;
1207static void user_error (const char *msg)
1208{
1209 xsignal1 (Quser_error, build_string (msg));
1210}
1211
1206static Lisp_Object Fexit_recursive_edit (void) NO_RETURN; 1212static Lisp_Object Fexit_recursive_edit (void) NO_RETURN;
1207DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", 1213DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "",
1208 doc: /* Exit from the innermost recursive edit or minibuffer. */) 1214 doc: /* Exit from the innermost recursive edit or minibuffer. */)
@@ -1211,7 +1217,7 @@ DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0,
1211 if (command_loop_level > 0 || minibuf_level > 0) 1217 if (command_loop_level > 0 || minibuf_level > 0)
1212 Fthrow (Qexit, Qnil); 1218 Fthrow (Qexit, Qnil);
1213 1219
1214 error ("No recursive edit is in progress"); 1220 user_error ("No recursive edit is in progress");
1215} 1221}
1216 1222
1217static Lisp_Object Fabort_recursive_edit (void) NO_RETURN; 1223static Lisp_Object Fabort_recursive_edit (void) NO_RETURN;
@@ -1222,7 +1228,7 @@ DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0,
1222 if (command_loop_level > 0 || minibuf_level > 0) 1228 if (command_loop_level > 0 || minibuf_level > 0)
1223 Fthrow (Qexit, Qt); 1229 Fthrow (Qexit, Qt);
1224 1230
1225 error ("No recursive edit is in progress"); 1231 user_error ("No recursive edit is in progress");
1226} 1232}
1227 1233
1228#if defined (HAVE_MOUSE) || defined (HAVE_GPM) 1234#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
@@ -2987,11 +2993,16 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2987 own stuff with the echo area. */ 2993 own stuff with the echo area. */
2988 if (!CONSP (c) 2994 if (!CONSP (c)
2989 || (!(EQ (Qhelp_echo, XCAR (c))) 2995 || (!(EQ (Qhelp_echo, XCAR (c)))
2990 && !(EQ (Qswitch_frame, XCAR (c))))) 2996 && !(EQ (Qswitch_frame, XCAR (c)))
2997 /* Don't wipe echo area for select window events: These might
2998 get delayed via `mouse-autoselect-window' (Bug#11304). */
2999 && !(EQ (Qselect_window, XCAR (c)))))
2991 { 3000 {
2992 if (!NILP (echo_area_buffer[0])) 3001 if (!NILP (echo_area_buffer[0]))
2993 safe_run_hooks (Qecho_area_clear_hook); 3002 {
2994 clear_message (1, 0); 3003 safe_run_hooks (Qecho_area_clear_hook);
3004 clear_message (1, 0);
3005 }
2995 } 3006 }
2996 3007
2997 reread_for_input_method: 3008 reread_for_input_method:
@@ -3778,7 +3789,6 @@ kbd_buffer_get_event (KBOARD **kbp,
3778 int *used_mouse_menu, 3789 int *used_mouse_menu,
3779 struct timeval *end_time) 3790 struct timeval *end_time)
3780{ 3791{
3781 register int c;
3782 Lisp_Object obj; 3792 Lisp_Object obj;
3783 3793
3784#ifdef subprocesses 3794#ifdef subprocesses
@@ -3795,16 +3805,18 @@ kbd_buffer_get_event (KBOARD **kbp,
3795 } 3805 }
3796#endif /* subprocesses */ 3806#endif /* subprocesses */
3797 3807
3808#ifndef HAVE_DBUS /* We want to read D-Bus events in batch mode. */
3798 if (noninteractive 3809 if (noninteractive
3799 /* In case we are running as a daemon, only do this before 3810 /* In case we are running as a daemon, only do this before
3800 detaching from the terminal. */ 3811 detaching from the terminal. */
3801 || (IS_DAEMON && daemon_pipe[1] >= 0)) 3812 || (IS_DAEMON && daemon_pipe[1] >= 0))
3802 { 3813 {
3803 c = getchar (); 3814 int c = getchar ();
3804 XSETINT (obj, c); 3815 XSETINT (obj, c);
3805 *kbp = current_kboard; 3816 *kbp = current_kboard;
3806 return obj; 3817 return obj;
3807 } 3818 }
3819#endif /* ! HAVE_DBUS */
3808 3820
3809 /* Wait until there is input available. */ 3821 /* Wait until there is input available. */
3810 for (;;) 3822 for (;;)
@@ -7185,6 +7197,7 @@ tty_read_avail_input (struct terminal *terminal,
7185 return nread; 7197 return nread;
7186} 7198}
7187 7199
7200#if defined SYNC_INPUT || defined SIGIO
7188static void 7201static void
7189handle_async_input (void) 7202handle_async_input (void)
7190{ 7203{
@@ -7211,7 +7224,9 @@ handle_async_input (void)
7211 --handling_signal; 7224 --handling_signal;
7212#endif 7225#endif
7213} 7226}
7227#endif /* SYNC_INPUT || SIGIO */
7214 7228
7229#ifdef SYNC_INPUT
7215void 7230void
7216process_pending_signals (void) 7231process_pending_signals (void)
7217{ 7232{
@@ -7219,6 +7234,7 @@ process_pending_signals (void)
7219 handle_async_input (); 7234 handle_async_input ();
7220 do_pending_atimers (); 7235 do_pending_atimers ();
7221} 7236}
7237#endif
7222 7238
7223#ifdef SIGIO /* for entire page */ 7239#ifdef SIGIO /* for entire page */
7224/* Note SIGIO has been undef'd if FIONREAD is missing. */ 7240/* Note SIGIO has been undef'd if FIONREAD is missing. */
@@ -10350,146 +10366,6 @@ a special event, so ignore the prefix argument and don't clear it. */)
10350 10366
10351 10367
10352 10368
10353DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command,
10354 1, 1, "P",
10355 doc: /* Read function name, then read its arguments and call it.
10356
10357To pass a numeric argument to the command you are invoking with, specify
10358the numeric argument to this command.
10359
10360Noninteractively, the argument PREFIXARG is the prefix argument to
10361give to the command you invoke, if it asks for an argument. */)
10362 (Lisp_Object prefixarg)
10363{
10364 Lisp_Object function;
10365 EMACS_INT saved_last_point_position;
10366 Lisp_Object saved_keys, saved_last_point_position_buffer;
10367 Lisp_Object bindings, value;
10368 struct gcpro gcpro1, gcpro2, gcpro3;
10369#ifdef HAVE_WINDOW_SYSTEM
10370 /* The call to Fcompleting_read will start and cancel the hourglass,
10371 but if the hourglass was already scheduled, this means that no
10372 hourglass will be shown for the actual M-x command itself.
10373 So we restart it if it is already scheduled. Note that checking
10374 hourglass_shown_p is not enough, normally the hourglass is not shown,
10375 just scheduled to be shown. */
10376 int hstarted = hourglass_started ();
10377#endif
10378
10379 saved_keys = Fvector (this_command_key_count,
10380 XVECTOR (this_command_keys)->contents);
10381 saved_last_point_position_buffer = last_point_position_buffer;
10382 saved_last_point_position = last_point_position;
10383 GCPRO3 (saved_keys, prefixarg, saved_last_point_position_buffer);
10384
10385 function = call0 (intern ("read-extended-command"));
10386
10387#ifdef HAVE_WINDOW_SYSTEM
10388 if (hstarted) start_hourglass ();
10389#endif
10390
10391 if (STRINGP (function) && SCHARS (function) == 0)
10392 error ("No command name given");
10393
10394 /* Set this_command_keys to the concatenation of saved_keys and
10395 function, followed by a RET. */
10396 {
10397 Lisp_Object *keys;
10398 int i;
10399
10400 this_command_key_count = 0;
10401 this_command_key_count_reset = 0;
10402 this_single_command_key_start = 0;
10403
10404 keys = XVECTOR (saved_keys)->contents;
10405 for (i = 0; i < ASIZE (saved_keys); i++)
10406 add_command_key (keys[i]);
10407
10408 for (i = 0; i < SCHARS (function); i++)
10409 add_command_key (Faref (function, make_number (i)));
10410
10411 add_command_key (make_number ('\015'));
10412 }
10413
10414 last_point_position = saved_last_point_position;
10415 last_point_position_buffer = saved_last_point_position_buffer;
10416
10417 UNGCPRO;
10418
10419 function = Fintern (function, Qnil);
10420 KVAR (current_kboard, Vprefix_arg) = prefixarg;
10421 Vthis_command = function;
10422 real_this_command = function;
10423
10424 /* If enabled, show which key runs this command. */
10425 if (!NILP (Vsuggest_key_bindings)
10426 && NILP (Vexecuting_kbd_macro)
10427 && SYMBOLP (function))
10428 bindings = Fwhere_is_internal (function, Voverriding_local_map,
10429 Qt, Qnil, Qnil);
10430 else
10431 bindings = Qnil;
10432
10433 value = Qnil;
10434 GCPRO3 (bindings, value, function);
10435 value = Fcommand_execute (function, Qt, Qnil, Qnil);
10436
10437 /* If the command has a key binding, print it now. */
10438 if (!NILP (bindings)
10439 && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)),
10440 Qmouse_movement)))
10441 {
10442 /* But first wait, and skip the message if there is input. */
10443 Lisp_Object waited;
10444
10445 /* If this command displayed something in the echo area;
10446 wait a few seconds, then display our suggestion message. */
10447 if (NILP (echo_area_buffer[0]))
10448 waited = sit_for (make_number (0), 0, 2);
10449 else if (NUMBERP (Vsuggest_key_bindings))
10450 waited = sit_for (Vsuggest_key_bindings, 0, 2);
10451 else
10452 waited = sit_for (make_number (2), 0, 2);
10453
10454 if (!NILP (waited) && ! CONSP (Vunread_command_events))
10455 {
10456 Lisp_Object binding;
10457 char *newmessage;
10458 int message_p = push_message ();
10459 int count = SPECPDL_INDEX ();
10460 ptrdiff_t newmessage_len, newmessage_alloc;
10461 USE_SAFE_ALLOCA;
10462
10463 record_unwind_protect (pop_message_unwind, Qnil);
10464 binding = Fkey_description (bindings, Qnil);
10465 newmessage_alloc =
10466 (sizeof "You can run the command `' with "
10467 + SBYTES (SYMBOL_NAME (function)) + SBYTES (binding));
10468 SAFE_ALLOCA (newmessage, char *, newmessage_alloc);
10469 newmessage_len =
10470 esprintf (newmessage, "You can run the command `%s' with %s",
10471 SDATA (SYMBOL_NAME (function)),
10472 SDATA (binding));
10473 message2 (newmessage,
10474 newmessage_len,
10475 STRING_MULTIBYTE (binding));
10476 if (NUMBERP (Vsuggest_key_bindings))
10477 waited = sit_for (Vsuggest_key_bindings, 0, 2);
10478 else
10479 waited = sit_for (make_number (2), 0, 2);
10480
10481 if (!NILP (waited) && message_p)
10482 restore_message ();
10483
10484 SAFE_FREE ();
10485 unbind_to (count, Qnil);
10486 }
10487 }
10488
10489 RETURN_UNGCPRO (value);
10490}
10491
10492
10493/* Return nonzero if input events are pending. */ 10369/* Return nonzero if input events are pending. */
10494 10370
10495int 10371int
@@ -11804,7 +11680,6 @@ syms_of_keyboard (void)
11804 defsubr (&Sset_quit_char); 11680 defsubr (&Sset_quit_char);
11805 defsubr (&Sset_input_mode); 11681 defsubr (&Sset_input_mode);
11806 defsubr (&Scurrent_input_mode); 11682 defsubr (&Scurrent_input_mode);
11807 defsubr (&Sexecute_extended_command);
11808 defsubr (&Sposn_at_point); 11683 defsubr (&Sposn_at_point);
11809 defsubr (&Sposn_at_x_y); 11684 defsubr (&Sposn_at_x_y);
11810 11685
@@ -12208,12 +12083,6 @@ If this variable is non-nil, `delayed-warnings-hook' will be run
12208immediately after running `post-command-hook'. */); 12083immediately after running `post-command-hook'. */);
12209 Vdelayed_warnings_list = Qnil; 12084 Vdelayed_warnings_list = Qnil;
12210 12085
12211 DEFVAR_LISP ("suggest-key-bindings", Vsuggest_key_bindings,
12212 doc: /* Non-nil means show the equivalent key-binding when M-x command has one.
12213The value can be a length of time to show the message for.
12214If the value is non-nil and not a number, we wait 2 seconds. */);
12215 Vsuggest_key_bindings = Qt;
12216
12217 DEFVAR_LISP ("timer-list", Vtimer_list, 12086 DEFVAR_LISP ("timer-list", Vtimer_list,
12218 doc: /* List of active absolute time timers in order of increasing time. */); 12087 doc: /* List of active absolute time timers in order of increasing time. */);
12219 Vtimer_list = Qnil; 12088 Vtimer_list = Qnil;
@@ -12409,7 +12278,7 @@ keys_of_keyboard (void)
12409} 12278}
12410 12279
12411/* Mark the pointers in the kboard objects. 12280/* Mark the pointers in the kboard objects.
12412 Called by the Fgarbage_collector. */ 12281 Called by Fgarbage_collect. */
12413void 12282void
12414mark_kboards (void) 12283mark_kboards (void)
12415{ 12284{
diff --git a/src/keymap.c b/src/keymap.c
index ecaeb32896e..9f82175edc0 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2553,7 +2553,8 @@ where_is_internal (Lisp_Object definition, Lisp_Object keymaps,
2553DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, 2553DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0,
2554 doc: /* Return list of keys that invoke DEFINITION. 2554 doc: /* Return list of keys that invoke DEFINITION.
2555If KEYMAP is a keymap, search only KEYMAP and the global keymap. 2555If KEYMAP is a keymap, search only KEYMAP and the global keymap.
2556If KEYMAP is nil, search all the currently active keymaps. 2556If KEYMAP is nil, search all the currently active keymaps, except
2557 for `overriding-local-map' (which is ignored).
2557If KEYMAP is a list of keymaps, search only those keymaps. 2558If KEYMAP is a list of keymaps, search only those keymaps.
2558 2559
2559If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found, 2560If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found,
@@ -2568,9 +2569,17 @@ If optional 4th arg NOINDIRECT is non-nil, don't follow indirections
2568to other keymaps or slots. This makes it possible to search for an 2569to other keymaps or slots. This makes it possible to search for an
2569indirect definition itself. 2570indirect definition itself.
2570 2571
2571If optional 5th arg NO-REMAP is non-nil, don't search for key sequences 2572The optional 5th arg NO-REMAP alters how command remapping is handled:
2572that invoke a command which is remapped to DEFINITION, but include the 2573
2573remapped command in the returned list. */) 2574- If another command OTHER-COMMAND is remapped to DEFINITION, normally
2575 search for the bindings of OTHER-COMMAND and include them in the
2576 returned list. But if NO-REMAP is non-nil, include the vector
2577 [remap OTHER-COMMAND] in the returned list instead, without
2578 searching for those other bindings.
2579
2580- If DEFINITION is remapped to OTHER-COMMAND, normally return the
2581 bindings for OTHER-COMMAND. But if NO-REMAP is non-nil, return the
2582 bindings for DEFINITION instead, ignoring its remapping. */)
2574 (Lisp_Object definition, Lisp_Object keymap, Lisp_Object firstonly, Lisp_Object noindirect, Lisp_Object no_remap) 2583 (Lisp_Object definition, Lisp_Object keymap, Lisp_Object firstonly, Lisp_Object noindirect, Lisp_Object no_remap)
2575{ 2584{
2576 /* The keymaps in which to search. */ 2585 /* The keymaps in which to search. */
diff --git a/src/lisp.h b/src/lisp.h
index 37fa81b63f6..068b221d8af 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -479,6 +479,7 @@ enum pvec_type
479 (var) = (type) | (intptr_t) (ptr)) 479 (var) = (type) | (intptr_t) (ptr))
480 480
481#define XPNTR(a) ((intptr_t) ((a) & ~TYPEMASK)) 481#define XPNTR(a) ((intptr_t) ((a) & ~TYPEMASK))
482#define XUNTAG(a, type) ((intptr_t) ((a) - (type)))
482 483
483#else /* not USE_LSB_TAG */ 484#else /* not USE_LSB_TAG */
484 485
@@ -585,6 +586,13 @@ extern Lisp_Object make_number (EMACS_INT);
585# define XSETFASTINT(a, b) (XSETINT (a, b)) 586# define XSETFASTINT(a, b) (XSETINT (a, b))
586#endif 587#endif
587 588
589/* Extract the pointer value of the Lisp object A, under the
590 assumption that A's type is TYPE. This is a fallback
591 implementation if nothing faster is available. */
592#ifndef XUNTAG
593# define XUNTAG(a, type) XPNTR (a)
594#endif
595
588#define EQ(x, y) (XHASH (x) == XHASH (y)) 596#define EQ(x, y) (XHASH (x) == XHASH (y))
589 597
590/* Number of bits in a fixnum, including the sign bit. */ 598/* Number of bits in a fixnum, including the sign bit. */
@@ -611,15 +619,20 @@ extern Lisp_Object make_number (EMACS_INT);
611 619
612/* Extract a value or address from a Lisp_Object. */ 620/* Extract a value or address from a Lisp_Object. */
613 621
614#define XCONS(a) (eassert (CONSP (a)), (struct Lisp_Cons *) XPNTR (a)) 622#define XCONS(a) (eassert (CONSP (a)), \
615#define XVECTOR(a) (eassert (VECTORLIKEP (a)), (struct Lisp_Vector *) XPNTR (a)) 623 (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
616#define XSTRING(a) (eassert (STRINGP (a)), (struct Lisp_String *) XPNTR (a)) 624#define XVECTOR(a) (eassert (VECTORLIKEP (a)), \
617#define XSYMBOL(a) (eassert (SYMBOLP (a)), (struct Lisp_Symbol *) XPNTR (a)) 625 (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike))
618#define XFLOAT(a) (eassert (FLOATP (a)), (struct Lisp_Float *) XPNTR (a)) 626#define XSTRING(a) (eassert (STRINGP (a)), \
627 (struct Lisp_String *) XUNTAG (a, Lisp_String))
628#define XSYMBOL(a) (eassert (SYMBOLP (a)), \
629 (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
630#define XFLOAT(a) (eassert (FLOATP (a)), \
631 (struct Lisp_Float *) XUNTAG (a, Lisp_Float))
619 632
620/* Misc types. */ 633/* Misc types. */
621 634
622#define XMISC(a) ((union Lisp_Misc *) XPNTR (a)) 635#define XMISC(a) ((union Lisp_Misc *) XUNTAG (a, Lisp_Misc))
623#define XMISCANY(a) (eassert (MISCP (a)), &(XMISC (a)->u_any)) 636#define XMISCANY(a) (eassert (MISCP (a)), &(XMISC (a)->u_any))
624#define XMISCTYPE(a) (XMISCANY (a)->type) 637#define XMISCTYPE(a) (XMISCANY (a)->type)
625#define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker)) 638#define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker))
@@ -639,14 +652,24 @@ extern Lisp_Object make_number (EMACS_INT);
639 652
640/* Pseudovector types. */ 653/* Pseudovector types. */
641 654
642#define XPROCESS(a) (eassert (PROCESSP (a)), (struct Lisp_Process *) XPNTR (a)) 655#define XPROCESS(a) (eassert (PROCESSP (a)), \
643#define XWINDOW(a) (eassert (WINDOWP (a)), (struct window *) XPNTR (a)) 656 (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike))
644#define XTERMINAL(a) (eassert (TERMINALP (a)), (struct terminal *) XPNTR (a)) 657#define XWINDOW(a) (eassert (WINDOWP (a)), \
645#define XSUBR(a) (eassert (SUBRP (a)), (struct Lisp_Subr *) XPNTR (a)) 658 (struct window *) XUNTAG (a, Lisp_Vectorlike))
646#define XBUFFER(a) (eassert (BUFFERP (a)), (struct buffer *) XPNTR (a)) 659#define XTERMINAL(a) (eassert (TERMINALP (a)), \
647#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), (struct Lisp_Char_Table *) XPNTR (a)) 660 (struct terminal *) XUNTAG (a, Lisp_Vectorlike))
648#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), (struct Lisp_Sub_Char_Table *) XPNTR (a)) 661#define XSUBR(a) (eassert (SUBRP (a)), \
649#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), (struct Lisp_Bool_Vector *) XPNTR (a)) 662 (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike))
663#define XBUFFER(a) (eassert (BUFFERP (a)), \
664 (struct buffer *) XUNTAG (a, Lisp_Vectorlike))
665#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \
666 (struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike))
667#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \
668 ((struct Lisp_Sub_Char_Table *) \
669 XUNTAG (a, Lisp_Vectorlike)))
670#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \
671 ((struct Lisp_Bool_Vector *) \
672 XUNTAG (a, Lisp_Vectorlike)))
650 673
651/* Construct a Lisp_Object from a value or address. */ 674/* Construct a Lisp_Object from a value or address. */
652 675
@@ -673,7 +696,9 @@ extern Lisp_Object make_number (EMACS_INT);
673/* The cast to struct vectorlike_header * avoids aliasing issues. */ 696/* The cast to struct vectorlike_header * avoids aliasing issues. */
674#define XSETPSEUDOVECTOR(a, b, code) \ 697#define XSETPSEUDOVECTOR(a, b, code) \
675 XSETTYPED_PSEUDOVECTOR(a, b, \ 698 XSETTYPED_PSEUDOVECTOR(a, b, \
676 ((struct vectorlike_header *) XPNTR (a))->size, \ 699 (((struct vectorlike_header *) \
700 XUNTAG (a, Lisp_Vectorlike)) \
701 ->size), \
677 code) 702 code)
678#define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \ 703#define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \
679 (XSETVECTOR (a, b), \ 704 (XSETVECTOR (a, b), \
@@ -1281,7 +1306,7 @@ struct Lisp_Hash_Table
1281 1306
1282 1307
1283#define XHASH_TABLE(OBJ) \ 1308#define XHASH_TABLE(OBJ) \
1284 ((struct Lisp_Hash_Table *) XPNTR (OBJ)) 1309 ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike))
1285 1310
1286#define XSET_HASH_TABLE(VAR, PTR) \ 1311#define XSET_HASH_TABLE(VAR, PTR) \
1287 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE)) 1312 (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
@@ -1739,7 +1764,7 @@ typedef struct {
1739 code is CODE. */ 1764 code is CODE. */
1740#define TYPED_PSEUDOVECTORP(x, t, code) \ 1765#define TYPED_PSEUDOVECTORP(x, t, code) \
1741 (VECTORLIKEP (x) \ 1766 (VECTORLIKEP (x) \
1742 && (((((struct t *) XPNTR (x))->size \ 1767 && (((((struct t *) XUNTAG (x, Lisp_Vectorlike))->size \
1743 & (PSEUDOVECTOR_FLAG | (code)))) \ 1768 & (PSEUDOVECTOR_FLAG | (code)))) \
1744 == (PSEUDOVECTOR_FLAG | (code)))) 1769 == (PSEUDOVECTOR_FLAG | (code))))
1745 1770
@@ -2381,7 +2406,7 @@ extern Lisp_Object Qerror, Qquit, Qargs_out_of_range;
2381extern Lisp_Object Qvoid_variable, Qvoid_function; 2406extern Lisp_Object Qvoid_variable, Qvoid_function;
2382extern Lisp_Object Qinvalid_read_syntax; 2407extern Lisp_Object Qinvalid_read_syntax;
2383extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; 2408extern Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
2384extern Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; 2409extern Lisp_Object Quser_error, Qend_of_file, Qarith_error, Qmark_inactive;
2385extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; 2410extern Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
2386extern Lisp_Object Qtext_read_only; 2411extern Lisp_Object Qtext_read_only;
2387extern Lisp_Object Qinteractive_form; 2412extern Lisp_Object Qinteractive_form;
diff --git a/src/lisp.mk b/src/lisp.mk
index c082630f717..4608cc3f687 100644
--- a/src/lisp.mk
+++ b/src/lisp.mk
@@ -128,9 +128,12 @@ lisp = \
128 $(lispsource)/emacs-lisp/lisp-mode.elc \ 128 $(lispsource)/emacs-lisp/lisp-mode.elc \
129 $(lispsource)/textmodes/text-mode.elc \ 129 $(lispsource)/textmodes/text-mode.elc \
130 $(lispsource)/textmodes/fill.elc \ 130 $(lispsource)/textmodes/fill.elc \
131 $(lispsource)/newcomment.elc \
131 $(lispsource)/replace.elc \ 132 $(lispsource)/replace.elc \
133 $(lispsource)/emacs-lisp/tabulated-list.elc \
132 $(lispsource)/buff-menu.elc \ 134 $(lispsource)/buff-menu.elc \
133 $(lispsource)/fringe.elc \ 135 $(lispsource)/fringe.elc \
136 $(lispsource)/emacs-lisp/regexp-opt.elc \
134 $(lispsource)/image.elc \ 137 $(lispsource)/image.elc \
135 $(lispsource)/international/fontset.elc \ 138 $(lispsource)/international/fontset.elc \
136 $(lispsource)/dnd.elc \ 139 $(lispsource)/dnd.elc \
diff --git a/src/lread.c b/src/lread.c
index 50465fd01e8..6b657f61ed0 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -24,7 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24#include <sys/stat.h> 24#include <sys/stat.h>
25#include <sys/file.h> 25#include <sys/file.h>
26#include <errno.h> 26#include <errno.h>
27#include <limits.h> /* for CHAR_BIT */ 27#include <limits.h> /* For CHAR_BIT. */
28#include <setjmp.h> 28#include <setjmp.h>
29#include "lisp.h" 29#include "lisp.h"
30#include "intervals.h" 30#include "intervals.h"
@@ -3990,10 +3990,12 @@ init_obarray (void)
3990 /* XSYMBOL (Qnil)->function = Qunbound; */ 3990 /* XSYMBOL (Qnil)->function = Qunbound; */
3991 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil); 3991 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
3992 XSYMBOL (Qnil)->constant = 1; 3992 XSYMBOL (Qnil)->constant = 1;
3993 XSYMBOL (Qnil)->declared_special = 1;
3993 XSYMBOL (Qnil)->plist = Qnil; 3994 XSYMBOL (Qnil)->plist = Qnil;
3994 3995
3995 Qt = intern_c_string ("t"); 3996 Qt = intern_c_string ("t");
3996 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt); 3997 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
3998 XSYMBOL (Qnil)->declared_special = 1;
3997 XSYMBOL (Qt)->constant = 1; 3999 XSYMBOL (Qt)->constant = 1;
3998 4000
3999 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ 4001 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
diff --git a/src/m/vax.h b/src/m/vax.h
deleted file mode 100644
index e4bed4090b9..00000000000
--- a/src/m/vax.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/* machine description file for vax.
2
3Copyright (C) 1985-1986, 2001-2012 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20
21/* #define vax -- appears to be done automatically */
22
23#define HAVE_FTIME
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 303445bc2d6..f62c501e1fa 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -930,7 +930,7 @@ $(BLD)/fringe.$(O) : \
930 930
931$(BLD)/gmalloc.$(O) : \ 931$(BLD)/gmalloc.$(O) : \
932 $(SRC)/gmalloc.c \ 932 $(SRC)/gmalloc.c \
933 $(SRC)/getpagesize.h \ 933 $(NT_INC)/stdint.h \
934 $(NT_INC)/unistd.h \ 934 $(NT_INC)/unistd.h \
935 $(CONFIG_H) 935 $(CONFIG_H)
936 936
@@ -1514,6 +1514,7 @@ $(BLD)/w32menu.$(O) : \
1514 $(SRC)/w32menu.c \ 1514 $(SRC)/w32menu.c \
1515 $(SRC)/buffer.h \ 1515 $(SRC)/buffer.h \
1516 $(SRC)/keymap.h \ 1516 $(SRC)/keymap.h \
1517 $(SRC)/w32heap.h \
1517 $(BLOCKINPUT_H) \ 1518 $(BLOCKINPUT_H) \
1518 $(CHARSET_H) \ 1519 $(CHARSET_H) \
1519 $(CODING_H) \ 1520 $(CODING_H) \
diff --git a/src/ns.mk b/src/ns.mk
index d3b5afeb99e..77fbf5845d9 100644
--- a/src/ns.mk
+++ b/src/ns.mk
@@ -1,6 +1,6 @@
1### autodeps.mk --- src/Makefile fragment for GNU Emacs 1### autodeps.mk --- src/Makefile fragment for GNU Emacs
2 2
3## Copyright (C) 2008-2012 Free Software Foundation, Inc. 3## Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 4
5## This file is part of GNU Emacs. 5## This file is part of GNU Emacs.
6 6
@@ -27,13 +27,13 @@
27 27
28${ns_appdir}: ${ns_appsrc} 28${ns_appdir}: ${ns_appsrc}
29 rm -fr ${ns_appdir} 29 rm -fr ${ns_appdir}
30 mkdir -p ${ns_appdir} 30 ${MKDIR_P} ${ns_appdir}
31 ( cd ${ns_appsrc} ; tar cfh - . ) | ( cd ${ns_appdir} ; umask 022; tar xf - ) 31 ( cd ${ns_appsrc} ; tar cfh - . ) | ( cd ${ns_appdir} ; umask 022; tar xf - )
32 32
33${ns_appbindir}Emacs: emacs${EXEEXT} 33${ns_appbindir}/Emacs: emacs${EXEEXT}
34 mkdir -p ${ns_appbindir} 34 ${MKDIR_P} ${ns_appbindir}
35 cp -f emacs${EXEEXT} ${ns_appbindir}Emacs 35 cp -f emacs${EXEEXT} ${ns_appbindir}/Emacs
36 36
37ns-app: ${ns_appdir} ${ns_appbindir}Emacs 37ns-app: ${ns_appdir} ${ns_appbindir}/Emacs
38 38
39### ns.mk ends here 39### ns.mk ends here
diff --git a/src/nsterm.m b/src/nsterm.m
index 7cbaf991311..4b8b2bb4820 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -338,11 +338,18 @@ ns_init_paths (void)
338/*NSLog (@"loadPath: '%@'\n", resourcePaths); */ 338/*NSLog (@"loadPath: '%@'\n", resourcePaths); */
339 } 339 }
340 340
341 /* Normally, Emacs does not add its own bin/ directory to the PATH.
342 However, a self-contained NS build has a different layout, with
343 bin/ and libexec/ subdirectories in the directory that contains
344 Emacs.app itself.
345 We put libexec first, because init_callproc_1 uses the first
346 element to initialize exec-directory. An alternative would be
347 for init_callproc to check for invocation-directory/libexec. */
341 if (!getenv ("EMACSPATH")) 348 if (!getenv ("EMACSPATH"))
342 { 349 {
343 NSArray *paths = [binDir stringsByAppendingPaths: 350 NSArray *paths = [binDir stringsByAppendingPaths:
344 [NSArray arrayWithObjects: @"bin", 351 [NSArray arrayWithObjects: @"libexec",
345 @"lib-exec", nil]]; 352 @"bin", nil]];
346 NSEnumerator *pathEnum = [paths objectEnumerator]; 353 NSEnumerator *pathEnum = [paths objectEnumerator];
347 resourcePaths = @""; 354 resourcePaths = @"";
348 while (resourcePath = [pathEnum nextObject]) 355 while (resourcePath = [pathEnum nextObject])
diff --git a/src/print.c b/src/print.c
index c5c03274f77..5b1ea748799 100644
--- a/src/print.c
+++ b/src/print.c
@@ -95,14 +95,14 @@ static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
95int print_output_debug_flag EXTERNALLY_VISIBLE = 1; 95int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
96 96
97 97
98/* Low level output routines for characters and strings */ 98/* Low level output routines for characters and strings. */
99 99
100/* Lisp functions to do output using a stream 100/* Lisp functions to do output using a stream
101 must have the stream in a variable called printcharfun 101 must have the stream in a variable called printcharfun
102 and must start with PRINTPREPARE, end with PRINTFINISH, 102 and must start with PRINTPREPARE, end with PRINTFINISH,
103 and use PRINTDECLARE to declare common variables. 103 and use PRINTDECLARE to declare common variables.
104 Use PRINTCHAR to output one character, 104 Use PRINTCHAR to output one character,
105 or call strout to output a block of characters. */ 105 or call strout to output a block of characters. */
106 106
107#define PRINTDECLARE \ 107#define PRINTDECLARE \
108 struct buffer *old = current_buffer; \ 108 struct buffer *old = current_buffer; \
@@ -867,7 +867,6 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
867{ 867{
868 Lisp_Object errname, errmsg, file_error, tail; 868 Lisp_Object errname, errmsg, file_error, tail;
869 struct gcpro gcpro1; 869 struct gcpro gcpro1;
870 int i;
871 870
872 if (context != 0) 871 if (context != 0)
873 write_string_1 (context, -1, stream); 872 write_string_1 (context, -1, stream);
@@ -895,9 +894,8 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
895 } 894 }
896 else 895 else
897 { 896 {
898 Lisp_Object error_conditions; 897 Lisp_Object error_conditions = Fget (errname, Qerror_conditions);
899 errmsg = Fget (errname, Qerror_message); 898 errmsg = Fget (errname, Qerror_message);
900 error_conditions = Fget (errname, Qerror_conditions);
901 file_error = Fmemq (Qfile_error, error_conditions); 899 file_error = Fmemq (Qfile_error, error_conditions);
902 } 900 }
903 901
@@ -911,22 +909,30 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
911 if (!NILP (file_error) && CONSP (tail)) 909 if (!NILP (file_error) && CONSP (tail))
912 errmsg = XCAR (tail), tail = XCDR (tail); 910 errmsg = XCAR (tail), tail = XCDR (tail);
913 911
914 if (STRINGP (errmsg)) 912 {
915 Fprinc (errmsg, stream); 913 const char *sep = ": ";
916 else
917 write_string_1 ("peculiar error", -1, stream);
918 914
919 for (i = 0; CONSP (tail); tail = XCDR (tail), i = 1) 915 if (!STRINGP (errmsg))
920 { 916 write_string_1 ("peculiar error", -1, stream);
921 Lisp_Object obj; 917 else if (SCHARS (errmsg))
918 Fprinc (errmsg, stream);
919 else
920 sep = NULL;
922 921
923 write_string_1 (i ? ", " : ": ", 2, stream); 922 for (; CONSP (tail); tail = XCDR (tail), sep = ", ")
924 obj = XCAR (tail); 923 {
925 if (!NILP (file_error) || EQ (errname, Qend_of_file)) 924 Lisp_Object obj;
926 Fprinc (obj, stream); 925
927 else 926 if (sep)
928 Fprin1 (obj, stream); 927 write_string_1 (sep, 2, stream);
929 } 928 obj = XCAR (tail);
929 if (!NILP (file_error)
930 || EQ (errname, Qend_of_file) || EQ (errname, Quser_error))
931 Fprinc (obj, stream);
932 else
933 Fprin1 (obj, stream);
934 }
935 }
930 936
931 UNGCPRO; 937 UNGCPRO;
932} 938}
@@ -1132,15 +1138,15 @@ print_preprocess (Lisp_Object obj)
1132 int loop_count = 0; 1138 int loop_count = 0;
1133 Lisp_Object halftail; 1139 Lisp_Object halftail;
1134 1140
1135 /* Give up if we go so deep that print_object will get an error. */
1136 /* See similar code in print_object. */
1137 if (print_depth >= PRINT_CIRCLE)
1138 error ("Apparently circular structure being printed");
1139
1140 /* Avoid infinite recursion for circular nested structure 1141 /* Avoid infinite recursion for circular nested structure
1141 in the case where Vprint_circle is nil. */ 1142 in the case where Vprint_circle is nil. */
1142 if (NILP (Vprint_circle)) 1143 if (NILP (Vprint_circle))
1143 { 1144 {
1145 /* Give up if we go so deep that print_object will get an error. */
1146 /* See similar code in print_object. */
1147 if (print_depth >= PRINT_CIRCLE)
1148 error ("Apparently circular structure being printed");
1149
1144 for (i = 0; i < print_depth; i++) 1150 for (i = 0; i < print_depth; i++)
1145 if (EQ (obj, being_printed[i])) 1151 if (EQ (obj, being_printed[i]))
1146 return; 1152 return;
@@ -1242,7 +1248,7 @@ static void print_check_string_charset_prop (INTERVAL interval, Lisp_Object stri
1242#define PRINT_STRING_NON_CHARSET_FOUND 1 1248#define PRINT_STRING_NON_CHARSET_FOUND 1
1243#define PRINT_STRING_UNSAFE_CHARSET_FOUND 2 1249#define PRINT_STRING_UNSAFE_CHARSET_FOUND 2
1244 1250
1245/* Bitwise or of the above macros. */ 1251/* Bitwise or of the above macros. */
1246static int print_check_string_result; 1252static int print_check_string_result;
1247 1253
1248static void 1254static void
@@ -1325,48 +1331,46 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1325 1331
1326 QUIT; 1332 QUIT;
1327 1333
1328 /* See similar code in print_preprocess. */
1329 if (print_depth >= PRINT_CIRCLE)
1330 error ("Apparently circular structure being printed");
1331
1332 /* Detect circularities and truncate them. */ 1334 /* Detect circularities and truncate them. */
1333 if (PRINT_CIRCLE_CANDIDATE_P (obj)) 1335 if (NILP (Vprint_circle))
1334 { 1336 {
1335 if (NILP (Vprint_circle) && NILP (Vprint_gensym)) 1337 /* Simple but incomplete way. */
1336 { 1338 int i;
1337 /* Simple but incomplete way. */ 1339
1338 int i; 1340 /* See similar code in print_preprocess. */
1339 for (i = 0; i < print_depth; i++) 1341 if (print_depth >= PRINT_CIRCLE)
1340 if (EQ (obj, being_printed[i])) 1342 error ("Apparently circular structure being printed");
1341 { 1343
1342 sprintf (buf, "#%d", i); 1344 for (i = 0; i < print_depth; i++)
1343 strout (buf, -1, -1, printcharfun); 1345 if (EQ (obj, being_printed[i]))
1344 return; 1346 {
1345 } 1347 sprintf (buf, "#%d", i);
1346 being_printed[print_depth] = obj; 1348 strout (buf, -1, -1, printcharfun);
1347 } 1349 return;
1348 else 1350 }
1351 being_printed[print_depth] = obj;
1352 }
1353 else if (PRINT_CIRCLE_CANDIDATE_P (obj))
1354 {
1355 /* With the print-circle feature. */
1356 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1357 if (INTEGERP (num))
1349 { 1358 {
1350 /* With the print-circle feature. */ 1359 EMACS_INT n = XINT (num);
1351 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); 1360 if (n < 0)
1352 if (INTEGERP (num)) 1361 { /* Add a prefix #n= if OBJ has not yet been printed;
1362 that is, its status field is nil. */
1363 sprintf (buf, "#%"pI"d=", -n);
1364 strout (buf, -1, -1, printcharfun);
1365 /* OBJ is going to be printed. Remember that fact. */
1366 Fputhash (obj, make_number (- n), Vprint_number_table);
1367 }
1368 else
1353 { 1369 {
1354 EMACS_INT n = XINT (num); 1370 /* Just print #n# if OBJ has already been printed. */
1355 if (n < 0) 1371 sprintf (buf, "#%"pI"d#", n);
1356 { /* Add a prefix #n= if OBJ has not yet been printed; 1372 strout (buf, -1, -1, printcharfun);
1357 that is, its status field is nil. */ 1373 return;
1358 sprintf (buf, "#%"pI"d=", -n);
1359 strout (buf, -1, -1, printcharfun);
1360 /* OBJ is going to be printed. Remember that fact. */
1361 Fputhash (obj, make_number (- n), Vprint_number_table);
1362 }
1363 else
1364 {
1365 /* Just print #n# if OBJ has already been printed. */
1366 sprintf (buf, "#%"pI"d#", n);
1367 strout (buf, -1, -1, printcharfun);
1368 return;
1369 }
1370 } 1374 }
1371 } 1375 }
1372 } 1376 }
diff --git a/src/process.c b/src/process.c
index 65020299e75..cf6d40052a7 100644
--- a/src/process.c
+++ b/src/process.c
@@ -120,6 +120,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
120#include "nsterm.h" 120#include "nsterm.h"
121#endif 121#endif
122 122
123/* Work around GCC 4.7.0 bug with strict overflow checking; see
124 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>.
125 These lines can be removed once the GCC bug is fixed. */
126#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
127# pragma GCC diagnostic ignored "-Wstrict-overflow"
128#endif
129
123Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; 130Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
124Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; 131Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
125Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; 132Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
@@ -1070,7 +1077,9 @@ is more appropriate for saving the process buffer.
1070 1077
1071Binding the variable `inherit-process-coding-system' to non-nil before 1078Binding the variable `inherit-process-coding-system' to non-nil before
1072starting the process is an alternative way of setting the inherit flag 1079starting the process is an alternative way of setting the inherit flag
1073for the process which will run. */) 1080for the process which will run.
1081
1082This function returns FLAG. */)
1074 (register Lisp_Object process, Lisp_Object flag) 1083 (register Lisp_Object process, Lisp_Object flag)
1075{ 1084{
1076 CHECK_PROCESS (process); 1085 CHECK_PROCESS (process);
@@ -1083,7 +1092,8 @@ DEFUN ("set-process-query-on-exit-flag",
1083 2, 2, 0, 1092 2, 2, 0,
1084 doc: /* Specify if query is needed for PROCESS when Emacs is exited. 1093 doc: /* Specify if query is needed for PROCESS when Emacs is exited.
1085If the second argument FLAG is non-nil, Emacs will query the user before 1094If the second argument FLAG is non-nil, Emacs will query the user before
1086exiting or killing a buffer if PROCESS is running. */) 1095exiting or killing a buffer if PROCESS is running. This function
1096returns FLAG. */)
1087 (register Lisp_Object process, Lisp_Object flag) 1097 (register Lisp_Object process, Lisp_Object flag)
1088{ 1098{
1089 CHECK_PROCESS (process); 1099 CHECK_PROCESS (process);
@@ -2525,7 +2535,7 @@ could be "COM1", or "\\\\.\\COM10" for ports higher than COM9 (double
2525the backslashes in strings). 2535the backslashes in strings).
2526 2536
2527:speed SPEED -- (mandatory) is handled by `serial-process-configure', 2537:speed SPEED -- (mandatory) is handled by `serial-process-configure',
2528which is called by `make-serial-process'. 2538which this function calls.
2529 2539
2530:name NAME -- NAME is the name of the process. If NAME is not given, 2540:name NAME -- NAME is the name of the process. If NAME is not given,
2531the value of PORT is used. 2541the value of PORT is used.
@@ -2554,13 +2564,12 @@ but you can send outgoing data. The stopped state is cleared by
2554 2564
2555:plist PLIST -- Install PLIST as the initial plist of the process. 2565:plist PLIST -- Install PLIST as the initial plist of the process.
2556 2566
2557:speed
2558:bytesize 2567:bytesize
2559:parity 2568:parity
2560:stopbits 2569:stopbits
2561:flowcontrol 2570:flowcontrol
2562-- These arguments are handled by `serial-process-configure', which is 2571-- This function calls `serial-process-configure' to handle these
2563called by `make-serial-process'. 2572arguments.
2564 2573
2565The original argument list, possibly modified by later configuration, 2574The original argument list, possibly modified by later configuration,
2566is available via the function `process-contact'. 2575is available via the function `process-contact'.
@@ -2794,7 +2803,7 @@ The stopped state is cleared by `continue-process' and set by
2794:filter-multibyte BOOL -- If BOOL is non-nil, strings given to the 2803:filter-multibyte BOOL -- If BOOL is non-nil, strings given to the
2795process filter are multibyte, otherwise they are unibyte. 2804process filter are multibyte, otherwise they are unibyte.
2796If this keyword is not specified, the strings are multibyte if 2805If this keyword is not specified, the strings are multibyte if
2797`default-enable-multibyte-characters' is non-nil. 2806the default value of `enable-multibyte-characters' is non-nil.
2798 2807
2799:sentinel SENTINEL -- Install SENTINEL as the process sentinel. 2808:sentinel SENTINEL -- Install SENTINEL as the process sentinel.
2800 2809
@@ -4891,16 +4900,23 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4891 It can't hurt. */ 4900 It can't hurt. */
4892 else if (nread == -1 && errno == EIO) 4901 else if (nread == -1 && errno == EIO)
4893 { 4902 {
4894 /* Don't do anything if only a pty, with no associated 4903 struct Lisp_Process *p = XPROCESS (proc);
4895 process (bug#10933). */ 4904
4896 if (XPROCESS (proc)->pid != -2) { 4905 /* Clear the descriptor now, so we only raise the
4897 /* Clear the descriptor now, so we only raise the signal 4906 signal once. */
4898 once. */ 4907 FD_CLR (channel, &input_wait_mask);
4899 FD_CLR (channel, &input_wait_mask); 4908 FD_CLR (channel, &non_keyboard_wait_mask);
4900 FD_CLR (channel, &non_keyboard_wait_mask); 4909
4901 4910 if (p->pid == -2)
4902 kill (getpid (), SIGCHLD); 4911 {
4903 } 4912 /* If the EIO occurs on a pty, sigchld_handler's
4913 wait3() will not find the process object to
4914 delete. Do it here. */
4915 p->tick = ++process_tick;
4916 p->status = Qfailed;
4917 }
4918 else
4919 kill (getpid (), SIGCHLD);
4904 } 4920 }
4905#endif /* HAVE_PTYS */ 4921#endif /* HAVE_PTYS */
4906 /* If we can detect process termination, don't consider the 4922 /* If we can detect process termination, don't consider the
diff --git a/src/ralloc.c b/src/ralloc.c
index 896ad9f3155..4bb2f240438 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -95,10 +95,8 @@ static int extra_bytes;
95/* Macros for rounding. Note that rounding to any value is possible 95/* Macros for rounding. Note that rounding to any value is possible
96 by changing the definition of PAGE. */ 96 by changing the definition of PAGE. */
97#define PAGE (getpagesize ()) 97#define PAGE (getpagesize ())
98#define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0)
99#define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ 98#define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \
100 & ~(page_size - 1)) 99 & ~(page_size - 1))
101#define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
102 100
103#define MEM_ALIGN sizeof (double) 101#define MEM_ALIGN sizeof (double)
104#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ 102#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \
@@ -151,7 +149,6 @@ typedef struct heap
151} *heap_ptr; 149} *heap_ptr;
152 150
153#define NIL_HEAP ((heap_ptr) 0) 151#define NIL_HEAP ((heap_ptr) 0)
154#define HEAP_PTR_SIZE (sizeof (struct heap))
155 152
156/* This is the first heap object. 153/* This is the first heap object.
157 If we need additional heap objects, each one resides at the beginning of 154 If we need additional heap objects, each one resides at the beginning of
@@ -366,15 +363,6 @@ relinquish (void)
366 } 363 }
367 } 364 }
368} 365}
369
370/* Return the total size in use by relocating allocator,
371 above where malloc gets space. */
372
373long
374r_alloc_size_in_use (void)
375{
376 return (char *) break_value - (char *) virtual_break_value;
377}
378 366
379/* The meat - allocating, freeing, and relocating blocs. */ 367/* The meat - allocating, freeing, and relocating blocs. */
380 368
@@ -748,7 +736,7 @@ free_bloc (bloc_ptr bloc)
748 __morecore hook values - in particular, __default_morecore in the 736 __morecore hook values - in particular, __default_morecore in the
749 GNU malloc package. */ 737 GNU malloc package. */
750 738
751POINTER 739static POINTER
752r_alloc_sbrk (long int size) 740r_alloc_sbrk (long int size)
753{ 741{
754 register bloc_ptr b; 742 register bloc_ptr b;
@@ -1014,52 +1002,6 @@ r_re_alloc (POINTER *ptr, SIZE size)
1014 return *ptr; 1002 return *ptr;
1015} 1003}
1016 1004
1017/* Disable relocations, after making room for at least SIZE bytes
1018 of non-relocatable heap if possible. The relocatable blocs are
1019 guaranteed to hold still until thawed, even if this means that
1020 malloc must return a null pointer. */
1021
1022void
1023r_alloc_freeze (long int size)
1024{
1025 if (! r_alloc_initialized)
1026 r_alloc_init ();
1027
1028 /* If already frozen, we can't make any more room, so don't try. */
1029 if (r_alloc_freeze_level > 0)
1030 size = 0;
1031 /* If we can't get the amount requested, half is better than nothing. */
1032 while (size > 0 && r_alloc_sbrk (size) == 0)
1033 size /= 2;
1034 ++r_alloc_freeze_level;
1035 if (size > 0)
1036 r_alloc_sbrk (-size);
1037}
1038
1039void
1040r_alloc_thaw (void)
1041{
1042
1043 if (! r_alloc_initialized)
1044 r_alloc_init ();
1045
1046 if (--r_alloc_freeze_level < 0)
1047 abort ();
1048
1049 /* This frees all unused blocs. It is not too inefficient, as the resize
1050 and memcpy is done only once. Afterwards, all unreferenced blocs are
1051 already shrunk to zero size. */
1052 if (!r_alloc_freeze_level)
1053 {
1054 bloc_ptr *b = &first_bloc;
1055 while (*b)
1056 if (!(*b)->variable)
1057 free_bloc (*b);
1058 else
1059 b = &(*b)->next;
1060 }
1061}
1062
1063 1005
1064#if defined (emacs) && defined (DOUG_LEA_MALLOC) 1006#if defined (emacs) && defined (DOUG_LEA_MALLOC)
1065 1007
diff --git a/src/regex.c b/src/regex.c
index 0f9150193ec..d16a5148054 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -33,6 +33,19 @@
33 #pragma alloca 33 #pragma alloca
34#endif 34#endif
35 35
36/* Ignore some GCC warnings for now. This section should go away
37 once the Emacs and Gnulib regex code is merged. */
38#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
39# pragma GCC diagnostic ignored "-Wstrict-overflow"
40# ifndef emacs
41# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
42# pragma GCC diagnostic ignored "-Wunused-function"
43# pragma GCC diagnostic ignored "-Wunused-macros"
44# pragma GCC diagnostic ignored "-Wunused-result"
45# pragma GCC diagnostic ignored "-Wunused-variable"
46# endif
47#endif
48
36#ifdef HAVE_CONFIG_H 49#ifdef HAVE_CONFIG_H
37# include <config.h> 50# include <config.h>
38#endif 51#endif
@@ -198,7 +211,7 @@
198 211
199/* When used in Emacs's lib-src, we need xmalloc and xrealloc. */ 212/* When used in Emacs's lib-src, we need xmalloc and xrealloc. */
200 213
201void * 214static void *
202xmalloc (size_t size) 215xmalloc (size_t size)
203{ 216{
204 register void *val; 217 register void *val;
@@ -211,7 +224,7 @@ xmalloc (size_t size)
211 return val; 224 return val;
212} 225}
213 226
214void * 227static void *
215xrealloc (void *block, size_t size) 228xrealloc (void *block, size_t size)
216{ 229{
217 register void *val; 230 register void *val;
diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h
index e89ecb05931..63fc2f1f62b 100644
--- a/src/s/ms-w32.h
+++ b/src/s/ms-w32.h
@@ -122,7 +122,6 @@ struct sigaction {
122 122
123#define HAVE_GETTIMEOFDAY 1 123#define HAVE_GETTIMEOFDAY 1
124#define HAVE_GETHOSTNAME 1 124#define HAVE_GETHOSTNAME 1
125#undef HAVE_GETDOMAINNAME
126#define HAVE_DUP2 1 125#define HAVE_DUP2 1
127#define HAVE_RENAME 1 126#define HAVE_RENAME 1
128#define HAVE_CLOSEDIR 1 127#define HAVE_CLOSEDIR 1
@@ -147,7 +146,6 @@ struct sigaction {
147#define HAVE_FMOD 1 146#define HAVE_FMOD 1
148#undef HAVE_RINT 147#undef HAVE_RINT
149#undef HAVE_CBRT 148#undef HAVE_CBRT
150#define HAVE_FTIME 1
151#undef HAVE_RES_INIT /* For -lresolv on Suns. */ 149#undef HAVE_RES_INIT /* For -lresolv on Suns. */
152#undef HAVE_SETSID 150#undef HAVE_SETSID
153#undef HAVE_FPATHCONF 151#undef HAVE_FPATHCONF
diff --git a/src/search.c b/src/search.c
index 1f3ccc25dc8..2bf5f78d93b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2078,102 +2078,6 @@ set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes)
2078 XSETBUFFER (last_thing_searched, current_buffer); 2078 XSETBUFFER (last_thing_searched, current_buffer);
2079} 2079}
2080 2080
2081DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0,
2082 doc: /* Return a regexp which matches words, ignoring punctuation.
2083Given STRING, a string of words separated by word delimiters,
2084compute a regexp that matches those exact words separated by
2085arbitrary punctuation. If LAX is non-nil, the end of the string
2086need not match a word boundary unless it ends in whitespace.
2087
2088Used in `word-search-forward', `word-search-backward',
2089`word-search-forward-lax', `word-search-backward-lax'. */)
2090 (Lisp_Object string, Lisp_Object lax)
2091{
2092 register unsigned char *o;
2093 register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0;
2094 Lisp_Object val;
2095 int prev_c = 0;
2096 EMACS_INT adjust;
2097 int whitespace_at_end;
2098
2099 CHECK_STRING (string);
2100 len = SCHARS (string);
2101
2102 for (i = 0, i_byte = 0; i < len; )
2103 {
2104 int c;
2105
2106 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
2107
2108 if (SYNTAX (c) != Sword)
2109 {
2110 punct_count++;
2111 if (SYNTAX (prev_c) == Sword)
2112 word_count++;
2113 }
2114
2115 prev_c = c;
2116 }
2117
2118 if (SYNTAX (prev_c) == Sword)
2119 {
2120 word_count++;
2121 whitespace_at_end = 0;
2122 }
2123 else
2124 {
2125 whitespace_at_end = 1;
2126 if (!word_count)
2127 return empty_unibyte_string;
2128 }
2129
2130 adjust = - punct_count + 5 * (word_count - 1)
2131 + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4);
2132 if (STRING_MULTIBYTE (string))
2133 val = make_uninit_multibyte_string (len + adjust,
2134 SBYTES (string)
2135 + adjust);
2136 else
2137 val = make_uninit_string (len + adjust);
2138
2139 o = SDATA (val);
2140 *o++ = '\\';
2141 *o++ = 'b';
2142 prev_c = 0;
2143
2144 for (i = 0, i_byte = 0; i < len; )
2145 {
2146 int c;
2147 EMACS_INT i_byte_orig = i_byte;
2148
2149 FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
2150
2151 if (SYNTAX (c) == Sword)
2152 {
2153 memcpy (o, SDATA (string) + i_byte_orig, i_byte - i_byte_orig);
2154 o += i_byte - i_byte_orig;
2155 }
2156 else if (SYNTAX (prev_c) == Sword && --word_count)
2157 {
2158 *o++ = '\\';
2159 *o++ = 'W';
2160 *o++ = '\\';
2161 *o++ = 'W';
2162 *o++ = '*';
2163 }
2164
2165 prev_c = c;
2166 }
2167
2168 if (NILP (lax) || whitespace_at_end)
2169 {
2170 *o++ = '\\';
2171 *o++ = 'b';
2172 }
2173
2174 return val;
2175}
2176
2177DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, 2081DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4,
2178 "MSearch backward: ", 2082 "MSearch backward: ",
2179 doc: /* Search backward from point for STRING. 2083 doc: /* Search backward from point for STRING.
@@ -2216,86 +2120,6 @@ See also the functions `match-beginning', `match-end' and `replace-match'. */)
2216 return search_command (string, bound, noerror, count, 1, 0, 0); 2120 return search_command (string, bound, noerror, count, 1, 0, 0);
2217} 2121}
2218 2122
2219DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4,
2220 "sWord search backward: ",
2221 doc: /* Search backward from point for STRING, ignoring differences in punctuation.
2222Set point to the beginning of the occurrence found, and return point.
2223An optional second argument bounds the search; it is a buffer position.
2224The match found must not extend before that position.
2225Optional third argument, if t, means if fail just return nil (no error).
2226 If not nil and not t, move to limit of search and return nil.
2227Optional fourth argument is repeat count--search for successive occurrences.
2228
2229Relies on the function `word-search-regexp' to convert a sequence
2230of words in STRING to a regexp used to search words without regard
2231to punctuation. */)
2232 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
2233{
2234 return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0);
2235}
2236
2237DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4,
2238 "sWord search: ",
2239 doc: /* Search forward from point for STRING, ignoring differences in punctuation.
2240Set point to the end of the occurrence found, and return point.
2241An optional second argument bounds the search; it is a buffer position.
2242The match found must not extend after that position.
2243Optional third argument, if t, means if fail just return nil (no error).
2244 If not nil and not t, move to limit of search and return nil.
2245Optional fourth argument is repeat count--search for successive occurrences.
2246
2247Relies on the function `word-search-regexp' to convert a sequence
2248of words in STRING to a regexp used to search words without regard
2249to punctuation. */)
2250 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
2251{
2252 return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0);
2253}
2254
2255DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4,
2256 "sWord search backward: ",
2257 doc: /* Search backward from point for STRING, ignoring differences in punctuation.
2258Set point to the beginning of the occurrence found, and return point.
2259
2260Unlike `word-search-backward', the end of STRING need not match a word
2261boundary, unless STRING ends in whitespace.
2262
2263An optional second argument bounds the search; it is a buffer position.
2264The match found must not extend before that position.
2265Optional third argument, if t, means if fail just return nil (no error).
2266 If not nil and not t, move to limit of search and return nil.
2267Optional fourth argument is repeat count--search for successive occurrences.
2268
2269Relies on the function `word-search-regexp' to convert a sequence
2270of words in STRING to a regexp used to search words without regard
2271to punctuation. */)
2272 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
2273{
2274 return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0);
2275}
2276
2277DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4,
2278 "sWord search: ",
2279 doc: /* Search forward from point for STRING, ignoring differences in punctuation.
2280Set point to the end of the occurrence found, and return point.
2281
2282Unlike `word-search-forward', the end of STRING need not match a word
2283boundary, unless STRING ends in whitespace.
2284
2285An optional second argument bounds the search; it is a buffer position.
2286The match found must not extend after that position.
2287Optional third argument, if t, means if fail just return nil (no error).
2288 If not nil and not t, move to limit of search and return nil.
2289Optional fourth argument is repeat count--search for successive occurrences.
2290
2291Relies on the function `word-search-regexp' to convert a sequence
2292of words in STRING to a regexp used to search words without regard
2293to punctuation. */)
2294 (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
2295{
2296 return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0);
2297}
2298
2299DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, 2123DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
2300 "sRE search backward: ", 2124 "sRE search backward: ",
2301 doc: /* Search backward from point for match for regular expression REGEXP. 2125 doc: /* Search backward from point for match for regular expression REGEXP.
@@ -3252,11 +3076,6 @@ is to bind it with `let' around a small expression. */);
3252 defsubr (&Sposix_string_match); 3076 defsubr (&Sposix_string_match);
3253 defsubr (&Ssearch_forward); 3077 defsubr (&Ssearch_forward);
3254 defsubr (&Ssearch_backward); 3078 defsubr (&Ssearch_backward);
3255 defsubr (&Sword_search_regexp);
3256 defsubr (&Sword_search_forward);
3257 defsubr (&Sword_search_backward);
3258 defsubr (&Sword_search_forward_lax);
3259 defsubr (&Sword_search_backward_lax);
3260 defsubr (&Sre_search_forward); 3079 defsubr (&Sre_search_forward);
3261 defsubr (&Sre_search_backward); 3080 defsubr (&Sre_search_backward);
3262 defsubr (&Sposix_search_forward); 3081 defsubr (&Sposix_search_forward);
diff --git a/src/sound.c b/src/sound.c
index 5fd5bd5c0de..9b58c01453a 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -124,9 +124,6 @@ static int parse_sound (Lisp_Object, Lisp_Object *);
124#ifndef DEFAULT_SOUND_DEVICE 124#ifndef DEFAULT_SOUND_DEVICE
125#define DEFAULT_SOUND_DEVICE "/dev/dsp" 125#define DEFAULT_SOUND_DEVICE "/dev/dsp"
126#endif 126#endif
127#ifndef DEFAULT_ALSA_SOUND_DEVICE
128#define DEFAULT_ALSA_SOUND_DEVICE "default"
129#endif
130 127
131 128
132/* Structure forward declarations. */ 129/* Structure forward declarations. */
@@ -908,6 +905,10 @@ vox_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes)
908 905
909/* This driver is available on GNU/Linux. */ 906/* This driver is available on GNU/Linux. */
910 907
908#ifndef DEFAULT_ALSA_SOUND_DEVICE
909#define DEFAULT_ALSA_SOUND_DEVICE "default"
910#endif
911
911static void 912static void
912alsa_sound_perror (const char *msg, int err) 913alsa_sound_perror (const char *msg, int err)
913{ 914{
diff --git a/src/sysdep.c b/src/sysdep.c
index edaaa4c93d7..81529fc7d9b 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -37,6 +37,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37#include "sysselect.h" 37#include "sysselect.h"
38#include "blockinput.h" 38#include "blockinput.h"
39 39
40#ifdef __FreeBSD__
41#include <sys/sysctl.h>
42#include <sys/user.h>
43#include <sys/resource.h> */
44#include <math.h>
45#endif
46
47#ifdef DARWIN_OS
48#include <sys/sysctl.h>
49#endif
50
40#ifdef WINDOWSNT 51#ifdef WINDOWSNT
41#define read sys_read 52#define read sys_read
42#define write sys_write 53#define write sys_write
@@ -2529,6 +2540,50 @@ list_system_processes (void)
2529 return proclist; 2540 return proclist;
2530} 2541}
2531 2542
2543#elif defined BSD_SYSTEM
2544
2545Lisp_Object
2546list_system_processes (void)
2547{
2548#ifdef DARWIN_OS
2549 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
2550#else
2551 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC};
2552#endif
2553 size_t len;
2554 struct kinfo_proc *procs;
2555 size_t i;
2556
2557 struct gcpro gcpro1;
2558 Lisp_Object proclist = Qnil;
2559
2560 if (sysctl (mib, 3, NULL, &len, NULL, 0) != 0)
2561 return proclist;
2562
2563 procs = xmalloc (len);
2564 if (sysctl (mib, 3, procs, &len, NULL, 0) != 0)
2565 {
2566 xfree (procs);
2567 return proclist;
2568 }
2569
2570 GCPRO1 (proclist);
2571 len /= sizeof (struct kinfo_proc);
2572 for (i = 0; i < len; i++)
2573 {
2574#ifdef DARWIN_OS
2575 proclist = Fcons (make_fixnum_or_float (procs[i].kp_proc.p_pid), proclist);
2576#else
2577 proclist = Fcons (make_fixnum_or_float (procs[i].ki_pid), proclist);
2578#endif
2579 }
2580 UNGCPRO;
2581
2582 xfree (procs);
2583
2584 return proclist;
2585}
2586
2532/* The WINDOWSNT implementation is in w32.c. 2587/* The WINDOWSNT implementation is in w32.c.
2533 The MSDOS implementation is in dosfns.c. */ 2588 The MSDOS implementation is in dosfns.c. */
2534#elif !defined (WINDOWSNT) && !defined (MSDOS) 2589#elif !defined (WINDOWSNT) && !defined (MSDOS)
@@ -3079,6 +3134,179 @@ system_process_attributes (Lisp_Object pid)
3079 return attrs; 3134 return attrs;
3080} 3135}
3081 3136
3137#elif defined __FreeBSD__
3138
3139Lisp_Object
3140system_process_attributes (Lisp_Object pid)
3141{
3142 int proc_id;
3143 int pagesize = getpagesize ();
3144 int npages;
3145 int fscale;
3146 struct passwd *pw;
3147 struct group *gr;
3148 char *ttyname;
3149 size_t len;
3150 char args[MAXPATHLEN];
3151 EMACS_TIME t, now;
3152
3153 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
3154 struct kinfo_proc proc;
3155 size_t proclen = sizeof proc;
3156
3157 struct gcpro gcpro1, gcpro2;
3158 Lisp_Object attrs = Qnil;
3159 Lisp_Object decoded_comm;
3160
3161 CHECK_NUMBER_OR_FLOAT (pid);
3162 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid);
3163 mib[3] = proc_id;
3164
3165 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
3166 return attrs;
3167
3168 GCPRO2 (attrs, decoded_comm);
3169
3170 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs);
3171
3172 BLOCK_INPUT;
3173 pw = getpwuid (proc.ki_uid);
3174 UNBLOCK_INPUT;
3175 if (pw)
3176 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
3177
3178 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (proc.ki_svgid)), attrs);
3179
3180 BLOCK_INPUT;
3181 gr = getgrgid (proc.ki_svgid);
3182 UNBLOCK_INPUT;
3183 if (gr)
3184 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
3185
3186 decoded_comm = code_convert_string_norecord
3187 (make_unibyte_string (proc.ki_comm, strlen (proc.ki_comm)),
3188 Vlocale_coding_system, 0);
3189
3190 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
3191 {
3192 char state[2] = {'\0', '\0'};
3193 switch (proc.ki_stat)
3194 {
3195 case SRUN:
3196 state[0] = 'R';
3197 break;
3198
3199 case SSLEEP:
3200 state[0] = 'S';
3201 break;
3202
3203 case SLOCK:
3204 state[0] = 'D';
3205 break;
3206
3207 case SZOMB:
3208 state[0] = 'Z';
3209 break;
3210
3211 case SSTOP:
3212 state[0] = 'T';
3213 break;
3214 }
3215 attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
3216 }
3217
3218 attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.ki_ppid)), attrs);
3219 attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.ki_pgid)), attrs);
3220 attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (proc.ki_sid)), attrs);
3221
3222 BLOCK_INPUT;
3223 ttyname = proc.ki_tdev == NODEV ? NULL : devname (proc.ki_tdev, S_IFCHR);
3224 UNBLOCK_INPUT;
3225 if (ttyname)
3226 attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
3227
3228 attrs = Fcons (Fcons (Qtpgid, make_fixnum_or_float (proc.ki_tpgid)), attrs);
3229 attrs = Fcons (Fcons (Qminflt, make_fixnum_or_float (proc.ki_rusage.ru_minflt)), attrs);
3230 attrs = Fcons (Fcons (Qmajflt, make_fixnum_or_float (proc.ki_rusage.ru_majflt)), attrs);
3231 attrs = Fcons (Fcons (Qcminflt, make_number (proc.ki_rusage_ch.ru_minflt)), attrs);
3232 attrs = Fcons (Fcons (Qcmajflt, make_number (proc.ki_rusage_ch.ru_majflt)), attrs);
3233
3234#define TIMELIST(ts) \
3235 list3 (make_number (EMACS_SECS (ts) >> 16 & 0xffff), \
3236 make_number (EMACS_SECS (ts) & 0xffff), \
3237 make_number (EMACS_USECS (ts)))
3238
3239 attrs = Fcons (Fcons (Qutime, TIMELIST (proc.ki_rusage.ru_utime)), attrs);
3240 attrs = Fcons (Fcons (Qstime, TIMELIST (proc.ki_rusage.ru_stime)), attrs);
3241 EMACS_ADD_TIME (t, proc.ki_rusage.ru_utime, proc.ki_rusage.ru_stime);
3242 attrs = Fcons (Fcons (Qtime, TIMELIST (t)), attrs);
3243
3244 attrs = Fcons (Fcons (Qcutime, TIMELIST (proc.ki_rusage_ch.ru_utime)), attrs);
3245 attrs = Fcons (Fcons (Qcstime, TIMELIST (proc.ki_rusage_ch.ru_utime)), attrs);
3246 EMACS_ADD_TIME (t, proc.ki_rusage_ch.ru_utime, proc.ki_rusage_ch.ru_stime);
3247 attrs = Fcons (Fcons (Qctime, TIMELIST (t)), attrs);
3248
3249 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)),
3250 attrs);
3251 attrs = Fcons (Fcons (Qpri, make_number (proc.ki_pri.pri_native)), attrs);
3252 attrs = Fcons (Fcons (Qnice, make_number (proc.ki_nice)), attrs);
3253 attrs = Fcons (Fcons (Qstart, TIMELIST (proc.ki_start)), attrs);
3254 attrs = Fcons (Fcons (Qvsize, make_number (proc.ki_size >> 10)), attrs);
3255 attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)),
3256 attrs);
3257
3258 EMACS_GET_TIME (now);
3259 EMACS_SUB_TIME (t, now, proc.ki_start);
3260 attrs = Fcons (Fcons (Qetime, TIMELIST (t)), attrs);
3261
3262#undef TIMELIST
3263
3264 len = sizeof fscale;
3265 if (sysctlbyname ("kern.fscale", &fscale, &len, NULL, 0) == 0)
3266 {
3267 double pcpu;
3268 fixpt_t ccpu;
3269 len = sizeof ccpu;
3270 if (sysctlbyname ("kern.ccpu", &ccpu, &len, NULL, 0) == 0)
3271 {
3272 pcpu = (100.0 * proc.ki_pctcpu / fscale
3273 / (1 - exp (proc.ki_swtime * log ((double) ccpu / fscale))));
3274 attrs = Fcons (Fcons (Qpcpu, make_fixnum_or_float (pcpu)), attrs);
3275 }
3276 }
3277
3278 len = sizeof npages;
3279 if (sysctlbyname ("hw.availpages", &npages, &len, NULL, 0) == 0)
3280 {
3281 double pmem = (proc.ki_flag & P_INMEM
3282 ? 100.0 * proc.ki_rssize / npages
3283 : 0);
3284 attrs = Fcons (Fcons (Qpmem, make_fixnum_or_float (pmem)), attrs);
3285 }
3286
3287 mib[2] = KERN_PROC_ARGS;
3288 len = MAXPATHLEN;
3289 if (sysctl (mib, 4, args, &len, NULL, 0) == 0)
3290 {
3291 int i;
3292 for (i = 0; i < len; i++)
3293 {
3294 if (! args[i] && i < len - 1)
3295 args[i] = ' ';
3296 }
3297
3298 decoded_comm =
3299 (code_convert_string_norecord
3300 (make_unibyte_string (args, strlen (args)),
3301 Vlocale_coding_system, 0));
3302
3303 attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
3304 }
3305
3306 UNGCPRO;
3307 return attrs;
3308}
3309
3082/* The WINDOWSNT implementation is in w32.c. 3310/* The WINDOWSNT implementation is in w32.c.
3083 The MSDOS implementation is in dosfns.c. */ 3311 The MSDOS implementation is in dosfns.c. */
3084#elif !defined (WINDOWSNT) && !defined (MSDOS) 3312#elif !defined (WINDOWSNT) && !defined (MSDOS)
diff --git a/src/syssignal.h b/src/syssignal.h
index 86135d71215..a2522f24429 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -1,5 +1,6 @@
1/* syssignal.h - System-dependent definitions for signals. 1/* syssignal.h - System-dependent definitions for signals.
2 Copyright (C) 1993, 1999, 2001-2012 Free Software Foundation, Inc. 2
3Copyright (C) 1993, 1999, 2001-2012 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
@@ -82,24 +83,18 @@ void croak (char *) NO_RETURN;
82 83
83#define sigfree() sigsetmask (SIGEMPTYMASK) 84#define sigfree() sigsetmask (SIGEMPTYMASK)
84 85
85#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
86#undef SIGINFO
87#endif
88#if defined (SIGIO) && defined (BROKEN_SIGIO) 86#if defined (SIGIO) && defined (BROKEN_SIGIO)
89# undef SIGIO 87# undef SIGIO
90#endif 88#endif
89/* Last user: m/ibmrs6000.h */
91#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL) 90#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
92#undef SIGPOLL 91#undef SIGPOLL
93#endif 92#endif
94#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP) 93/* Last user: m/ibmrs6000.h */
95#undef SIGTSTP
96#endif
97#if defined (SIGURG) && defined (BROKEN_SIGURG)
98#undef SIGURG
99#endif
100#if defined (SIGAIO) && defined (BROKEN_SIGAIO) 94#if defined (SIGAIO) && defined (BROKEN_SIGAIO)
101#undef SIGAIO 95#undef SIGAIO
102#endif 96#endif
97/* Last user: m/ibmrs6000.h */
103#if defined (SIGPTY) && defined (BROKEN_SIGPTY) 98#if defined (SIGPTY) && defined (BROKEN_SIGPTY)
104#undef SIGPTY 99#undef SIGPTY
105#endif 100#endif
diff --git a/src/term.c b/src/term.c
index 53458c559dd..ce300f9442a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3601,7 +3601,7 @@ delete_tty (struct terminal *terminal)
3601 3601
3602 3602
3603/* Mark the pointers in the tty_display_info objects. 3603/* Mark the pointers in the tty_display_info objects.
3604 Called by the Fgarbage_collector. */ 3604 Called by Fgarbage_collect. */
3605 3605
3606void 3606void
3607mark_ttys (void) 3607mark_ttys (void)
diff --git a/src/undo.c b/src/undo.c
index 4041a2adacc..b0acd0c216f 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -436,6 +436,13 @@ truncate_undo_list (struct buffer *b)
436 436
437 unbind_to (count, Qnil); 437 unbind_to (count, Qnil);
438} 438}
439
440static void user_error (const char*) NO_RETURN;
441static void user_error (const char *msg)
442{
443 xsignal1 (Quser_error, build_string (msg));
444}
445
439 446
440DEFUN ("primitive-undo", Fprimitive_undo, Sprimitive_undo, 2, 2, 0, 447DEFUN ("primitive-undo", Fprimitive_undo, Sprimitive_undo, 2, 2, 0,
441 doc: /* Undo N records from the front of the list LIST. 448 doc: /* Undo N records from the front of the list LIST.
@@ -528,7 +535,7 @@ Return what remains of the list. */)
528 end = Fcdr (cdr); 535 end = Fcdr (cdr);
529 536
530 if (XINT (beg) < BEGV || XINT (end) > ZV) 537 if (XINT (beg) < BEGV || XINT (end) > ZV)
531 error ("Changes to be undone are outside visible portion of buffer"); 538 user_error ("Changes to be undone are outside visible portion of buffer");
532 Fput_text_property (beg, end, prop, val, Qnil); 539 Fput_text_property (beg, end, prop, val, Qnil);
533 } 540 }
534 else if (INTEGERP (car) && INTEGERP (cdr)) 541 else if (INTEGERP (car) && INTEGERP (cdr))
@@ -537,7 +544,7 @@ Return what remains of the list. */)
537 544
538 if (XINT (car) < BEGV 545 if (XINT (car) < BEGV
539 || XINT (cdr) > ZV) 546 || XINT (cdr) > ZV)
540 error ("Changes to be undone are outside visible portion of buffer"); 547 user_error ("Changes to be undone are outside visible portion of buffer");
541 /* Set point first thing, so that undoing this undo 548 /* Set point first thing, so that undoing this undo
542 does not send point back to where it is now. */ 549 does not send point back to where it is now. */
543 Fgoto_char (car); 550 Fgoto_char (car);
@@ -588,14 +595,14 @@ Return what remains of the list. */)
588 if (pos < 0) 595 if (pos < 0)
589 { 596 {
590 if (-pos < BEGV || -pos > ZV) 597 if (-pos < BEGV || -pos > ZV)
591 error ("Changes to be undone are outside visible portion of buffer"); 598 user_error ("Changes to be undone are outside visible portion of buffer");
592 SET_PT (-pos); 599 SET_PT (-pos);
593 Finsert (1, &membuf); 600 Finsert (1, &membuf);
594 } 601 }
595 else 602 else
596 { 603 {
597 if (pos < BEGV || pos > ZV) 604 if (pos < BEGV || pos > ZV)
598 error ("Changes to be undone are outside visible portion of buffer"); 605 user_error ("Changes to be undone are outside visible portion of buffer");
599 SET_PT (pos); 606 SET_PT (pos);
600 607
601 /* Now that we record marker adjustments 608 /* Now that we record marker adjustments
diff --git a/src/unexaix.c b/src/unexaix.c
index 1bf65b68518..29fa0fd6287 100644
--- a/src/unexaix.c
+++ b/src/unexaix.c
@@ -78,13 +78,13 @@ static long data_scnptr;
78static long load_scnptr; 78static long load_scnptr;
79static long orig_load_scnptr; 79static long orig_load_scnptr;
80static long orig_data_scnptr; 80static long orig_data_scnptr;
81static int unrelocate_symbols (int, int, char *, char *); 81static int unrelocate_symbols (int, int, const char *, const char *);
82 82
83#ifndef MAX_SECTIONS 83#ifndef MAX_SECTIONS
84#define MAX_SECTIONS 10 84#define MAX_SECTIONS 10
85#endif 85#endif
86 86
87static int adjust_lnnoptrs (int, int, char *); 87static int adjust_lnnoptrs (int, int, const char *);
88 88
89static int pagemask; 89static int pagemask;
90 90
@@ -92,7 +92,7 @@ static int pagemask;
92#include "lisp.h" 92#include "lisp.h"
93 93
94static void 94static void
95report_error (char *file, int fd) 95report_error (const char *file, int fd)
96{ 96{
97 if (fd) 97 if (fd)
98 close (fd); 98 close (fd);
@@ -104,16 +104,16 @@ report_error (char *file, int fd)
104#define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 104#define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
105 105
106static void 106static void
107report_error_1 (int fd, char *msg, int a1, int a2) 107report_error_1 (int fd, const char *msg, int a1, int a2)
108{ 108{
109 close (fd); 109 close (fd);
110 error (msg, a1, a2); 110 error (msg, a1, a2);
111} 111}
112 112
113static int make_hdr (int, int, unsigned, unsigned, unsigned, char *, char *); 113static int make_hdr (int, int, const char *, const char *);
114static void mark_x (char *); 114static void mark_x (const char *);
115static int copy_text_and_data (int); 115static int copy_text_and_data (int);
116static int copy_sym (int, int, char *, char *); 116static int copy_sym (int, int, const char *, const char *);
117static void write_segment (int, char *, char *); 117static void write_segment (int, char *, char *);
118 118
119/* **************************************************************** 119/* ****************************************************************
@@ -159,7 +159,7 @@ unexec (const char *new_name, const char *a_name)
159 */ 159 */
160static int 160static int
161make_hdr (int new, int a_out, 161make_hdr (int new, int a_out,
162 char *a_name, char *new_name) 162 const char *a_name, const char *new_name)
163{ 163{
164 int scns; 164 int scns;
165 unsigned int bss_start; 165 unsigned int bss_start;
@@ -429,7 +429,7 @@ write_segment (int new, char *ptr, char *end)
429 * Copy the relocation information and symbol table from the a.out to the new 429 * Copy the relocation information and symbol table from the a.out to the new
430 */ 430 */
431static int 431static int
432copy_sym (int new, int a_out, char *a_name, char *new_name) 432copy_sym (int new, int a_out, const char *a_name, const char *new_name)
433{ 433{
434 char page[UnexBlockSz]; 434 char page[UnexBlockSz];
435 int n; 435 int n;
@@ -465,7 +465,7 @@ copy_sym (int new, int a_out, char *a_name, char *new_name)
465 * After successfully building the new a.out, mark it executable 465 * After successfully building the new a.out, mark it executable
466 */ 466 */
467static void 467static void
468mark_x (char *name) 468mark_x (const char *name)
469{ 469{
470 struct stat sbuf; 470 struct stat sbuf;
471 int um; 471 int um;
@@ -483,7 +483,7 @@ mark_x (char *name)
483} 483}
484 484
485static int 485static int
486adjust_lnnoptrs (int writedesc, int readdesc, char *new_name) 486adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
487{ 487{
488 int nsyms; 488 int nsyms;
489 int naux; 489 int naux;
@@ -530,7 +530,8 @@ adjust_lnnoptrs (int writedesc, int readdesc, char *new_name)
530} 530}
531 531
532static int 532static int
533unrelocate_symbols (int new, int a_out, char *a_name, char *new_name) 533unrelocate_symbols (int new, int a_out,
534 const char *a_name, const char *new_name)
534{ 535{
535 int i; 536 int i;
536 LDHDR ldhdr; 537 LDHDR ldhdr;
diff --git a/src/w32fns.c b/src/w32fns.c
index 510d1e94f16..f5161117f9d 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -4003,7 +4003,7 @@ unwind_create_frame (Lisp_Object frame)
4003#if GLYPH_DEBUG 4003#if GLYPH_DEBUG
4004 /* Check that reference counts are indeed correct. */ 4004 /* Check that reference counts are indeed correct. */
4005 xassert (dpyinfo->reference_count == dpyinfo_refcount); 4005 xassert (dpyinfo->reference_count == dpyinfo_refcount);
4006 xassert (dpyinfo->image_cache->refcount == image_cache_refcount); 4006 xassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
4007#endif 4007#endif
4008 return Qt; 4008 return Qt;
4009 } 4009 }
@@ -5016,16 +5016,6 @@ no value of TYPE (always string in the MS Windows case). */)
5016 cursor. Duplicated from xdisp.c, but cannot use the version there 5016 cursor. Duplicated from xdisp.c, but cannot use the version there
5017 due to lack of atimers on w32. */ 5017 due to lack of atimers on w32. */
5018#define DEFAULT_HOURGLASS_DELAY 1 5018#define DEFAULT_HOURGLASS_DELAY 1
5019/* Return non-zero if hourglass timer has been started or hourglass is
5020 shown. */
5021/* PENDING: if W32 can use atimers (atimer.[hc]) then the common impl in
5022 xdisp.c could be used. */
5023
5024int
5025hourglass_started (void)
5026{
5027 return hourglass_shown_p || hourglass_timer;
5028}
5029 5019
5030/* Cancel a currently active hourglass timer, and start a new one. */ 5020/* Cancel a currently active hourglass timer, and start a new one. */
5031 5021
@@ -5246,7 +5236,7 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5246 5236
5247#if GLYPH_DEBUG 5237#if GLYPH_DEBUG
5248 image_cache_refcount = 5238 image_cache_refcount =
5249 FRAME_IMAGE_CACHE ? FRAME_IMAGE_CACHE (f)->refcount : 0; 5239 FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
5250 dpyinfo_refcount = dpyinfo->reference_count; 5240 dpyinfo_refcount = dpyinfo->reference_count;
5251#endif /* GLYPH_DEBUG */ 5241#endif /* GLYPH_DEBUG */
5252 FRAME_KBOARD (f) = kb; 5242 FRAME_KBOARD (f) = kb;
diff --git a/src/w32font.c b/src/w32font.c
index dab9f4c61b4..8badace9635 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -2045,8 +2045,11 @@ fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec)
2045 /* Font families are interned, but allow for strings also in case of 2045 /* Font families are interned, but allow for strings also in case of
2046 user input. */ 2046 user input. */
2047 else if (SYMBOLP (tmp)) 2047 else if (SYMBOLP (tmp))
2048 strncpy (logfont->lfFaceName, 2048 {
2049 SDATA (ENCODE_SYSTEM (SYMBOL_NAME (tmp))), LF_FACESIZE); 2049 strncpy (logfont->lfFaceName,
2050 SDATA (ENCODE_SYSTEM (SYMBOL_NAME (tmp))), LF_FACESIZE);
2051 logfont->lfFaceName[LF_FACESIZE-1] = '\0';
2052 }
2050 } 2053 }
2051 2054
2052 tmp = AREF (font_spec, FONT_ADSTYLE_INDEX); 2055 tmp = AREF (font_spec, FONT_ADSTYLE_INDEX);
diff --git a/src/w32menu.c b/src/w32menu.c
index 9091cb81627..5b95a083d90 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -48,6 +48,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
48 48
49#include "dispextern.h" 49#include "dispextern.h"
50 50
51#include "w32heap.h" /* for osinfo_cache */
52
51#undef HAVE_DIALOGS /* TODO: Implement native dialogs. */ 53#undef HAVE_DIALOGS /* TODO: Implement native dialogs. */
52 54
53#ifndef TRUE 55#ifndef TRUE
@@ -1498,8 +1500,11 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
1498 AppendMenu (menu, fuFlags, 1500 AppendMenu (menu, fuFlags,
1499 item != NULL ? (UINT) item: (UINT) wv->call_data, 1501 item != NULL ? (UINT) item: (UINT) wv->call_data,
1500 out_string); 1502 out_string);
1501 /* Don't use Unicode menus in future. */ 1503 /* Don't use Unicode menus in future, unless this is Windows
1502 unicode_append_menu = NULL; 1504 NT or later, where a failure of AppendMenuW does NOT mean
1505 Unicode menus are unsupported. */
1506 if (osinfo_cache.dwPlatformId != VER_PLATFORM_WIN32_NT)
1507 unicode_append_menu = NULL;
1503 } 1508 }
1504 1509
1505 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW)) 1510 if (unicode_append_menu && (fuFlags & MF_OWNERDRAW))
diff --git a/src/w32proc.c b/src/w32proc.c
index 28591f90128..5bdeba25958 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -141,7 +141,25 @@ new_child (void)
141 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL); 141 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL);
142 if (cp->char_consumed) 142 if (cp->char_consumed)
143 { 143 {
144 cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id); 144 /* The 0x00010000 flag is STACK_SIZE_PARAM_IS_A_RESERVATION.
145 It means that the 64K stack we are requesting in the 2nd
146 argument is how much memory should be reserved for the
147 stack. If we don't use this flag, the memory requested
148 by the 2nd argument is the amount actually _committed_,
149 but Windows reserves 8MB of memory for each thread's
150 stack. (The 8MB figure comes from the -stack
151 command-line argument we pass to the linker when building
152 Emacs, but that's because we need a large stack for
153 Emacs's main thread.) Since we request 2GB of reserved
154 memory at startup (see w32heap.c), which is close to the
155 maximum memory available for a 32-bit process on Windows,
156 the 8MB reservation for each thread causes failures in
157 starting subprocesses, because we create a thread running
158 reader_thread for each subprocess. As 8MB of stack is
159 way too much for reader_thread, forcing Windows to
160 reserve less wins the day. */
161 cp->thrd = CreateThread (NULL, 64 * 1024, reader_thread, cp,
162 0x00010000, &id);
145 if (cp->thrd) 163 if (cp->thrd)
146 return cp; 164 return cp;
147 } 165 }
diff --git a/src/w32term.c b/src/w32term.c
index 18a3753f9e9..2ccd7574332 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -231,6 +231,10 @@ static void my_set_focus (struct frame *, HWND);
231static void my_set_foreground_window (HWND); 231static void my_set_foreground_window (HWND);
232static void my_destroy_window (struct frame *, HWND); 232static void my_destroy_window (struct frame *, HWND);
233 233
234#if GLYPH_DEBUG
235static void x_check_font (struct frame *, struct font *);
236#endif
237
234static Lisp_Object Qvendor_specific_keysyms; 238static Lisp_Object Qvendor_specific_keysyms;
235 239
236 240
@@ -5906,6 +5910,27 @@ x_wm_set_icon_position (struct frame *f, int icon_x, int icon_y)
5906 5910
5907 5911
5908/*********************************************************************** 5912/***********************************************************************
5913 Fonts
5914 ***********************************************************************/
5915
5916#if GLYPH_DEBUG
5917
5918/* Check that FONT is valid on frame F. It is if it can be found in F's
5919 font table. */
5920
5921static void
5922x_check_font (struct frame *f, struct font *font)
5923{
5924 xassert (font != NULL && ! NILP (font->props[FONT_TYPE_INDEX]));
5925 if (font->driver->check)
5926 xassert (font->driver->check (f, font) == 0);
5927}
5928
5929#endif /* GLYPH_DEBUG != 0 */
5930
5931
5932
5933/***********************************************************************
5909 Initialization 5934 Initialization
5910 ***********************************************************************/ 5935 ***********************************************************************/
5911 5936
diff --git a/src/window.c b/src/window.c
index 710e496fe88..827d3646e49 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4226,6 +4226,11 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4226 void *itdata = NULL; 4226 void *itdata = NULL;
4227 4227
4228 SET_TEXT_POS_FROM_MARKER (start, w->start); 4228 SET_TEXT_POS_FROM_MARKER (start, w->start);
4229 /* Scrolling a minibuffer window via scroll bar when the echo area
4230 shows long text sometimes resets the minibuffer contents behind
4231 our backs. */
4232 if (CHARPOS (start) > ZV)
4233 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
4229 4234
4230 /* If PT is not visible in WINDOW, move back one half of 4235 /* If PT is not visible in WINDOW, move back one half of
4231 the screen. Allow PT to be partially visible, otherwise 4236 the screen. Allow PT to be partially visible, otherwise
diff --git a/src/xdisp.c b/src/xdisp.c
index 2025eda79a7..90cd3cd9e2c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -385,11 +385,21 @@ static Lisp_Object Qline_height;
385#define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0 385#define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
386#endif /* HAVE_WINDOW_SYSTEM */ 386#endif /* HAVE_WINDOW_SYSTEM */
387 387
388/* Test if the display element loaded in IT is a space or tab 388/* Test if the display element loaded in IT, or the underlying buffer
389 character. This is used to determine word wrapping. */ 389 or string character, is a space or a TAB character. This is used
390 390 to determine where word wrapping can occur. */
391#define IT_DISPLAYING_WHITESPACE(it) \ 391
392 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) 392#define IT_DISPLAYING_WHITESPACE(it) \
393 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
394 || ((STRINGP (it->string) \
395 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
396 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
397 || (it->s \
398 && (it->s[IT_BYTEPOS (*it)] == ' ' \
399 || it->s[IT_BYTEPOS (*it)] == '\t')) \
400 || (IT_BYTEPOS (*it) < ZV_BYTE \
401 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
402 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
393 403
394/* Name of the face used to highlight trailing whitespace. */ 404/* Name of the face used to highlight trailing whitespace. */
395 405
@@ -841,6 +851,7 @@ static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
841static int trailing_whitespace_p (EMACS_INT); 851static int trailing_whitespace_p (EMACS_INT);
842static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT); 852static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT);
843static void push_it (struct it *, struct text_pos *); 853static void push_it (struct it *, struct text_pos *);
854static void iterate_out_of_display_property (struct it *);
844static void pop_it (struct it *); 855static void pop_it (struct it *);
845static void sync_frame_with_window_matrix_rows (struct window *); 856static void sync_frame_with_window_matrix_rows (struct window *);
846static void select_frame_for_redisplay (Lisp_Object); 857static void select_frame_for_redisplay (Lisp_Object);
@@ -1270,6 +1281,11 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1270 } 1281 }
1271 1282
1272 SET_TEXT_POS_FROM_MARKER (top, w->start); 1283 SET_TEXT_POS_FROM_MARKER (top, w->start);
1284 /* Scrolling a minibuffer window via scroll bar when the echo area
1285 shows long text sometimes resets the minibuffer contents behind
1286 our backs. */
1287 if (CHARPOS (top) > ZV)
1288 SET_TEXT_POS (top, BEGV, BEGV_BYTE);
1273 1289
1274 /* Compute exact mode line heights. */ 1290 /* Compute exact mode line heights. */
1275 if (WINDOW_WANTS_MODELINE_P (w)) 1291 if (WINDOW_WANTS_MODELINE_P (w))
@@ -1303,8 +1319,8 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1303 glyph. */ 1319 glyph. */
1304 int top_x = it.current_x; 1320 int top_x = it.current_x;
1305 int top_y = it.current_y; 1321 int top_y = it.current_y;
1306 enum it_method it_method = it.method;
1307 /* Calling line_bottom_y may change it.method, it.position, etc. */ 1322 /* Calling line_bottom_y may change it.method, it.position, etc. */
1323 enum it_method it_method = it.method;
1308 int bottom_y = (last_height = 0, line_bottom_y (&it)); 1324 int bottom_y = (last_height = 0, line_bottom_y (&it));
1309 int window_top_y = WINDOW_HEADER_LINE_HEIGHT (w); 1325 int window_top_y = WINDOW_HEADER_LINE_HEIGHT (w);
1310 1326
@@ -1312,6 +1328,31 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1312 visible_p = bottom_y > window_top_y; 1328 visible_p = bottom_y > window_top_y;
1313 else if (top_y < it.last_visible_y) 1329 else if (top_y < it.last_visible_y)
1314 visible_p = 1; 1330 visible_p = 1;
1331 if (bottom_y >= it.last_visible_y
1332 && it.bidi_p && it.bidi_it.scan_dir == -1
1333 && IT_CHARPOS (it) < charpos)
1334 {
1335 /* When the last line of the window is scanned backwards
1336 under bidi iteration, we could be duped into thinking
1337 that we have passed CHARPOS, when in fact move_it_to
1338 simply stopped short of CHARPOS because it reached
1339 last_visible_y. To see if that's what happened, we call
1340 move_it_to again with a slightly larger vertical limit,
1341 and see if it actually moved vertically; if it did, we
1342 didn't really reach CHARPOS, which is beyond window end. */
1343 struct it save_it = it;
1344 /* Why 10? because we don't know how many canonical lines
1345 will the height of the next line(s) be. So we guess. */
1346 int ten_more_lines =
1347 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w)));
1348
1349 move_it_to (&it, charpos, -1, bottom_y + ten_more_lines, -1,
1350 MOVE_TO_POS | MOVE_TO_Y);
1351 if (it.current_y > top_y)
1352 visible_p = 0;
1353
1354 it = save_it;
1355 }
1315 if (visible_p) 1356 if (visible_p)
1316 { 1357 {
1317 if (it_method == GET_FROM_DISPLAY_VECTOR) 1358 if (it_method == GET_FROM_DISPLAY_VECTOR)
@@ -1375,6 +1416,7 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1375 Lisp_Object startpos, endpos; 1416 Lisp_Object startpos, endpos;
1376 EMACS_INT start, end; 1417 EMACS_INT start, end;
1377 struct it it3; 1418 struct it it3;
1419 int it3_moved;
1378 1420
1379 /* Find the first and the last buffer positions 1421 /* Find the first and the last buffer positions
1380 covered by the display string. */ 1422 covered by the display string. */
@@ -1431,6 +1473,15 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1431 begins. */ 1473 begins. */
1432 start_display (&it3, w, top); 1474 start_display (&it3, w, top);
1433 move_it_to (&it3, -1, 0, top_y, -1, MOVE_TO_X | MOVE_TO_Y); 1475 move_it_to (&it3, -1, 0, top_y, -1, MOVE_TO_X | MOVE_TO_Y);
1476 /* If it3_moved stays zero after the 'while' loop
1477 below, that means we already were at a newline
1478 before the loop (e.g., the display string begins
1479 with a newline), so we don't need to (and cannot)
1480 inspect the glyphs of it3.glyph_row, because
1481 PRODUCE_GLYPHS will not produce anything for a
1482 newline, and thus it3.glyph_row stays at its
1483 stale content it got at top of the window. */
1484 it3_moved = 0;
1434 /* Finally, advance the iterator until we hit the 1485 /* Finally, advance the iterator until we hit the
1435 first display element whose character position is 1486 first display element whose character position is
1436 CHARPOS, or until the first newline from the 1487 CHARPOS, or until the first newline from the
@@ -1442,6 +1493,7 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1442 if (IT_CHARPOS (it3) == charpos 1493 if (IT_CHARPOS (it3) == charpos
1443 || ITERATOR_AT_END_OF_LINE_P (&it3)) 1494 || ITERATOR_AT_END_OF_LINE_P (&it3))
1444 break; 1495 break;
1496 it3_moved = 1;
1445 set_iterator_to_next (&it3, 0); 1497 set_iterator_to_next (&it3, 0);
1446 } 1498 }
1447 top_x = it3.current_x - it3.pixel_width; 1499 top_x = it3.current_x - it3.pixel_width;
@@ -1452,7 +1504,8 @@ pos_visible_p (struct window *w, EMACS_INT charpos, int *x, int *y,
1452 display string, move back over the glyphs 1504 display string, move back over the glyphs
1453 produced from the string, until we find the 1505 produced from the string, until we find the
1454 rightmost glyph not from the string. */ 1506 rightmost glyph not from the string. */
1455 if (IT_CHARPOS (it3) != charpos && EQ (it3.object, string)) 1507 if (it3_moved
1508 && IT_CHARPOS (it3) != charpos && EQ (it3.object, string))
1456 { 1509 {
1457 struct glyph *g = it3.glyph_row->glyphs[TEXT_AREA] 1510 struct glyph *g = it3.glyph_row->glyphs[TEXT_AREA]
1458 + it3.glyph_row->used[TEXT_AREA]; 1511 + it3.glyph_row->used[TEXT_AREA];
@@ -3113,7 +3166,15 @@ handle_stop (struct it *it)
3113 overlays even if the actual buffer text is replaced. */ 3166 overlays even if the actual buffer text is replaced. */
3114 if (!handle_overlay_change_p 3167 if (!handle_overlay_change_p
3115 || it->sp > 1 3168 || it->sp > 1
3116 || !get_overlay_strings_1 (it, 0, 0)) 3169 /* Don't call get_overlay_strings_1 if we already
3170 have overlay strings loaded, because doing so
3171 will load them again and push the iterator state
3172 onto the stack one more time, which is not
3173 expected by the rest of the code that processes
3174 overlay strings. */
3175 || (it->n_overlay_strings <= 0
3176 ? !get_overlay_strings_1 (it, 0, 0)
3177 : 0))
3117 { 3178 {
3118 if (it->ellipsis_p) 3179 if (it->ellipsis_p)
3119 setup_for_ellipsis (it, 0); 3180 setup_for_ellipsis (it, 0);
@@ -4672,10 +4733,22 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4672 if (!FRAME_WINDOW_P (it->f)) 4733 if (!FRAME_WINDOW_P (it->f))
4673 /* If we return here, POSITION has been advanced 4734 /* If we return here, POSITION has been advanced
4674 across the text with this property. */ 4735 across the text with this property. */
4675 return 0; 4736 {
4737 /* Synchronize the bidi iterator with POSITION. This is
4738 needed because we are not going to push the iterator
4739 on behalf of this display property, so there will be
4740 no pop_it call to do this synchronization for us. */
4741 if (it->bidi_p)
4742 {
4743 it->position = *position;
4744 iterate_out_of_display_property (it);
4745 *position = it->position;
4746 }
4747 return 1;
4748 }
4676 } 4749 }
4677 else if (!frame_window_p) 4750 else if (!frame_window_p)
4678 return 0; 4751 return 1;
4679 4752
4680#ifdef HAVE_WINDOW_SYSTEM 4753#ifdef HAVE_WINDOW_SYSTEM
4681 value = XCAR (XCDR (spec)); 4754 value = XCAR (XCDR (spec));
@@ -4683,7 +4756,15 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4683 || !(fringe_bitmap = lookup_fringe_bitmap (value))) 4756 || !(fringe_bitmap = lookup_fringe_bitmap (value)))
4684 /* If we return here, POSITION has been advanced 4757 /* If we return here, POSITION has been advanced
4685 across the text with this property. */ 4758 across the text with this property. */
4686 return 0; 4759 {
4760 if (it && it->bidi_p)
4761 {
4762 it->position = *position;
4763 iterate_out_of_display_property (it);
4764 *position = it->position;
4765 }
4766 return 1;
4767 }
4687 4768
4688 if (it) 4769 if (it)
4689 { 4770 {
@@ -5004,7 +5085,7 @@ string_buffer_position_lim (Lisp_Object string,
5004 Lisp_Object limit, prop, pos; 5085 Lisp_Object limit, prop, pos;
5005 int found = 0; 5086 int found = 0;
5006 5087
5007 pos = make_number (from); 5088 pos = make_number (max (from, BEGV));
5008 5089
5009 if (!back_p) /* looking forward */ 5090 if (!back_p) /* looking forward */
5010 { 5091 {
@@ -5624,7 +5705,7 @@ push_it (struct it *it, struct text_pos *position)
5624static void 5705static void
5625iterate_out_of_display_property (struct it *it) 5706iterate_out_of_display_property (struct it *it)
5626{ 5707{
5627 int buffer_p = BUFFERP (it->object); 5708 int buffer_p = !STRINGP (it->string);
5628 EMACS_INT eob = (buffer_p ? ZV : it->end_charpos); 5709 EMACS_INT eob = (buffer_p ? ZV : it->end_charpos);
5629 EMACS_INT bob = (buffer_p ? BEGV : 0); 5710 EMACS_INT bob = (buffer_p ? BEGV : 0);
5630 5711
@@ -6801,6 +6882,16 @@ get_next_display_element (struct it *it)
6801 && FACE_FROM_ID (it->f, face_id)->box == FACE_NO_BOX); 6882 && FACE_FROM_ID (it->f, face_id)->box == FACE_NO_BOX);
6802 } 6883 }
6803 } 6884 }
6885 /* If we reached the end of the object we've been iterating (e.g., a
6886 display string or an overlay string), and there's something on
6887 IT->stack, proceed with what's on the stack. It doesn't make
6888 sense to return zero if there's unprocessed stuff on the stack,
6889 because otherwise that stuff will never be displayed. */
6890 if (!success_p && it->sp > 0)
6891 {
6892 set_iterator_to_next (it, 0);
6893 success_p = get_next_display_element (it);
6894 }
6804 6895
6805 /* Value is 0 if end of buffer or string reached. */ 6896 /* Value is 0 if end of buffer or string reached. */
6806 return success_p; 6897 return success_p;
@@ -6982,7 +7073,7 @@ set_iterator_to_next (struct it *it, int reseat_p)
6982 display vector entry (these entries may contain faces). */ 7073 display vector entry (these entries may contain faces). */
6983 it->face_id = it->saved_face_id; 7074 it->face_id = it->saved_face_id;
6984 7075
6985 if (it->dpvec + it->current.dpvec_index == it->dpend) 7076 if (it->dpvec + it->current.dpvec_index >= it->dpend)
6986 { 7077 {
6987 int recheck_faces = it->ellipsis_p; 7078 int recheck_faces = it->ellipsis_p;
6988 7079
@@ -7020,6 +7111,26 @@ set_iterator_to_next (struct it *it, int reseat_p)
7020 case GET_FROM_STRING: 7111 case GET_FROM_STRING:
7021 /* Current display element is a character from a Lisp string. */ 7112 /* Current display element is a character from a Lisp string. */
7022 xassert (it->s == NULL && STRINGP (it->string)); 7113 xassert (it->s == NULL && STRINGP (it->string));
7114 /* Don't advance past string end. These conditions are true
7115 when set_iterator_to_next is called at the end of
7116 get_next_display_element, in which case the Lisp string is
7117 already exhausted, and all we want is pop the iterator
7118 stack. */
7119 if (it->current.overlay_string_index >= 0)
7120 {
7121 /* This is an overlay string, so there's no padding with
7122 spaces, and the number of characters in the string is
7123 where the string ends. */
7124 if (IT_STRING_CHARPOS (*it) >= SCHARS (it->string))
7125 goto consider_string_end;
7126 }
7127 else
7128 {
7129 /* Not an overlay string. There could be padding, so test
7130 against it->end_charpos . */
7131 if (IT_STRING_CHARPOS (*it) >= it->end_charpos)
7132 goto consider_string_end;
7133 }
7023 if (it->cmp_it.id >= 0) 7134 if (it->cmp_it.id >= 0)
7024 { 7135 {
7025 int i; 7136 int i;
@@ -12754,6 +12865,9 @@ redisplay_internal (void)
12754 frames. Zero means, only selected_window is considered. */ 12865 frames. Zero means, only selected_window is considered. */
12755 int consider_all_windows_p; 12866 int consider_all_windows_p;
12756 12867
12868 /* Non-zero means redisplay has to redisplay the miniwindow */
12869 int update_miniwindow_p = 0;
12870
12757 TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p)); 12871 TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p));
12758 12872
12759 /* No redisplay if running in batch mode or frame is not yet fully 12873 /* No redisplay if running in batch mode or frame is not yet fully
@@ -12940,6 +13054,10 @@ redisplay_internal (void)
12940 && !MINI_WINDOW_P (XWINDOW (selected_window)))) 13054 && !MINI_WINDOW_P (XWINDOW (selected_window))))
12941 { 13055 {
12942 int window_height_changed_p = echo_area_display (0); 13056 int window_height_changed_p = echo_area_display (0);
13057
13058 if (message_cleared_p)
13059 update_miniwindow_p = 1;
13060
12943 must_finish = 1; 13061 must_finish = 1;
12944 13062
12945 /* If we don't display the current message, don't clear the 13063 /* If we don't display the current message, don't clear the
@@ -12976,7 +13094,7 @@ redisplay_internal (void)
12976/* FIXME: this causes all frames to be updated, which seems unnecessary 13094/* FIXME: this causes all frames to be updated, which seems unnecessary
12977 since only the current frame needs to be considered. This function needs 13095 since only the current frame needs to be considered. This function needs
12978 to be rewritten with two variables, consider_all_windows and 13096 to be rewritten with two variables, consider_all_windows and
12979 consider_all_frames. */ 13097 consider_all_frames. */
12980 consider_all_windows_p = 1; 13098 consider_all_windows_p = 1;
12981 ++windows_or_buffers_changed; 13099 ++windows_or_buffers_changed;
12982 ++update_mode_lines; 13100 ++update_mode_lines;
@@ -13169,7 +13287,8 @@ redisplay_internal (void)
13169 then we can't just move the cursor. */ 13287 then we can't just move the cursor. */
13170 else if (! (!NILP (Vtransient_mark_mode) 13288 else if (! (!NILP (Vtransient_mark_mode)
13171 && !NILP (BVAR (current_buffer, mark_active))) 13289 && !NILP (BVAR (current_buffer, mark_active)))
13172 && (EQ (selected_window, BVAR (current_buffer, last_selected_window)) 13290 && (EQ (selected_window,
13291 BVAR (current_buffer, last_selected_window))
13173 || highlight_nonselected_windows) 13292 || highlight_nonselected_windows)
13174 && NILP (w->region_showing) 13293 && NILP (w->region_showing)
13175 && NILP (Vshow_trailing_whitespace) 13294 && NILP (Vshow_trailing_whitespace)
@@ -13322,7 +13441,7 @@ redisplay_internal (void)
13322 } 13441 }
13323 else if (FRAME_VISIBLE_P (sf) && !FRAME_OBSCURED_P (sf)) 13442 else if (FRAME_VISIBLE_P (sf) && !FRAME_OBSCURED_P (sf))
13324 { 13443 {
13325 Lisp_Object mini_window; 13444 Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf);
13326 struct frame *mini_frame; 13445 struct frame *mini_frame;
13327 13446
13328 displayed_buffer = XBUFFER (XWINDOW (selected_window)->buffer); 13447 displayed_buffer = XBUFFER (XWINDOW (selected_window)->buffer);
@@ -13331,6 +13450,10 @@ redisplay_internal (void)
13331 internal_condition_case_1 (redisplay_window_1, selected_window, 13450 internal_condition_case_1 (redisplay_window_1, selected_window,
13332 list_of_error, 13451 list_of_error,
13333 redisplay_window_error); 13452 redisplay_window_error);
13453 if (update_miniwindow_p)
13454 internal_condition_case_1 (redisplay_window_1, mini_window,
13455 list_of_error,
13456 redisplay_window_error);
13334 13457
13335 /* Compare desired and current matrices, perform output. */ 13458 /* Compare desired and current matrices, perform output. */
13336 13459
@@ -13751,6 +13874,13 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13751 comes from a text property, not from an overlay. */ 13874 comes from a text property, not from an overlay. */
13752 int string_from_text_prop = 0; 13875 int string_from_text_prop = 0;
13753 13876
13877 /* Don't even try doing anything if called for a mode-line or
13878 header-line row, since the rest of the code isn't prepared to
13879 deal with such calamities. */
13880 xassert (!row->mode_line_p);
13881 if (row->mode_line_p)
13882 return 0;
13883
13754 /* Skip over glyphs not having an object at the start and the end of 13884 /* Skip over glyphs not having an object at the start and the end of
13755 the row. These are special glyphs like truncation marks on 13885 the row. These are special glyphs like truncation marks on
13756 terminal frames. */ 13886 terminal frames. */
@@ -14971,6 +15101,8 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
14971 else if (rc != CURSOR_MOVEMENT_SUCCESS 15101 else if (rc != CURSOR_MOVEMENT_SUCCESS
14972 && !NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))) 15102 && !NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
14973 { 15103 {
15104 struct glyph_row *row1;
15105
14974 /* If rows are bidi-reordered and point moved, back up 15106 /* If rows are bidi-reordered and point moved, back up
14975 until we find a row that does not belong to a 15107 until we find a row that does not belong to a
14976 continuation line. This is because we must consider 15108 continuation line. This is because we must consider
@@ -14981,24 +15113,28 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
14981 /* FIXME: Revisit this when glyph ``spilling'' in 15113 /* FIXME: Revisit this when glyph ``spilling'' in
14982 continuation lines' rows is implemented for 15114 continuation lines' rows is implemented for
14983 bidi-reordered rows. */ 15115 bidi-reordered rows. */
14984 while (MATRIX_ROW_CONTINUATION_LINE_P (row)) 15116 for (row1 = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
15117 MATRIX_ROW_CONTINUATION_LINE_P (row);
15118 --row)
14985 { 15119 {
14986 /* If we hit the beginning of the displayed portion 15120 /* If we hit the beginning of the displayed portion
14987 without finding the first row of a continued 15121 without finding the first row of a continued
14988 line, give up. */ 15122 line, give up. */
14989 if (row <= w->current_matrix->rows) 15123 if (row <= row1)
14990 { 15124 {
14991 rc = CURSOR_MOVEMENT_MUST_SCROLL; 15125 rc = CURSOR_MOVEMENT_MUST_SCROLL;
14992 break; 15126 break;
14993 } 15127 }
14994 xassert (row->enabled_p); 15128 xassert (row->enabled_p);
14995 --row;
14996 } 15129 }
14997 } 15130 }
14998 if (must_scroll) 15131 if (must_scroll)
14999 ; 15132 ;
15000 else if (rc != CURSOR_MOVEMENT_SUCCESS 15133 else if (rc != CURSOR_MOVEMENT_SUCCESS
15001 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w, row) 15134 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w, row)
15135 /* Make sure this isn't a header line by any chance, since
15136 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15137 && !row->mode_line_p
15002 && make_cursor_line_fully_visible_p) 15138 && make_cursor_line_fully_visible_p)
15003 { 15139 {
15004 if (PT == MATRIX_ROW_END_CHARPOS (row) 15140 if (PT == MATRIX_ROW_END_CHARPOS (row)
@@ -29068,14 +29204,6 @@ init_xdisp (void)
29068 29204
29069/* Platform-independent portion of hourglass implementation. */ 29205/* Platform-independent portion of hourglass implementation. */
29070 29206
29071/* Return non-zero if hourglass timer has been started or hourglass is
29072 shown. */
29073int
29074hourglass_started (void)
29075{
29076 return hourglass_shown_p || hourglass_atimer != NULL;
29077}
29078
29079/* Cancel a currently active hourglass timer, and start a new one. */ 29207/* Cancel a currently active hourglass timer, and start a new one. */
29080void 29208void
29081start_hourglass (void) 29209start_hourglass (void)
diff --git a/src/xfns.c b/src/xfns.c
index df1b39b018f..717378f1cd1 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -136,7 +136,7 @@ char *gray_bitmap_bits = gray_bits;
136 136
137/* Nonzero if using X. */ 137/* Nonzero if using X. */
138 138
139static int x_in_use; 139int x_in_use;
140 140
141static Lisp_Object Qnone; 141static Lisp_Object Qnone;
142static Lisp_Object Qsuppress_icon; 142static Lisp_Object Qsuppress_icon;
@@ -2439,7 +2439,6 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2439 2439
2440 /* Do some needed geometry management. */ 2440 /* Do some needed geometry management. */
2441 { 2441 {
2442 ptrdiff_t len;
2443 char *tem, shell_position[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)]; 2442 char *tem, shell_position[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2444 Arg gal[10]; 2443 Arg gal[10];
2445 int gac = 0; 2444 int gac = 0;
@@ -2508,13 +2507,11 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2508 } 2507 }
2509 } 2508 }
2510 2509
2511 len = strlen (shell_position) + 1;
2512 /* We don't free this because we don't know whether 2510 /* We don't free this because we don't know whether
2513 it is safe to free it while the frame exists. 2511 it is safe to free it while the frame exists.
2514 It isn't worth the trouble of arranging to free it 2512 It isn't worth the trouble of arranging to free it
2515 when the frame is deleted. */ 2513 when the frame is deleted. */
2516 tem = (char *) xmalloc (len); 2514 tem = (char *) xstrdup (shell_position);
2517 strncpy (tem, shell_position, len);
2518 XtSetArg (gal[gac], XtNgeometry, tem); gac++; 2515 XtSetArg (gal[gac], XtNgeometry, tem); gac++;
2519 XtSetValues (shell_widget, gal, gac); 2516 XtSetValues (shell_widget, gal, gac);
2520 } 2517 }
diff --git a/src/xgselect.c b/src/xgselect.c
index 80dbfc32aee..69ad93b3127 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <http§://www.gnu.org/licenses/>. */
27#include <glib.h> 27#include <glib.h>
28#include <errno.h> 28#include <errno.h>
29#include <setjmp.h> 29#include <setjmp.h>
30#include "xterm.h"
30 31
31static GPollFD *gfds; 32static GPollFD *gfds;
32static ptrdiff_t gfds_size; 33static ptrdiff_t gfds_size;
@@ -38,10 +39,13 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
38 SELECT_TYPE all_rfds, all_wfds; 39 SELECT_TYPE all_rfds, all_wfds;
39 EMACS_TIME tmo, *tmop = timeout; 40 EMACS_TIME tmo, *tmop = timeout;
40 41
41 GMainContext *context = g_main_context_default (); 42 GMainContext *context;
42 int have_wfds = wfds != NULL; 43 int have_wfds = wfds != NULL;
43 int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0; 44 int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0;
44 int i, nfds, tmo_in_millisec; 45 int i, nfds, fds_lim, tmo_in_millisec;
46
47 if (!x_in_use)
48 return select (max_fds, rfds, wfds, efds, timeout);
45 49
46 if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds)); 50 if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
47 else FD_ZERO (&all_rfds); 51 else FD_ZERO (&all_rfds);
@@ -49,6 +53,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
49 else FD_ZERO (&all_wfds); 53 else FD_ZERO (&all_wfds);
50 54
51 /* Update event sources in GLib. */ 55 /* Update event sources in GLib. */
56 context = g_main_context_default ();
52 g_main_context_pending (context); 57 g_main_context_pending (context);
53 58
54 do { 59 do {
@@ -97,14 +102,14 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
97 if (our_tmo) tmop = &tmo; 102 if (our_tmo) tmop = &tmo;
98 } 103 }
99 104
100 nfds = select (max_fds+1, &all_rfds, have_wfds ? &all_wfds : NULL, 105 fds_lim = max_fds + 1;
101 efds, tmop); 106 nfds = select (fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL, efds, tmop);
102 107
103 if (nfds < 0) 108 if (nfds < 0)
104 retval = nfds; 109 retval = nfds;
105 else if (nfds > 0) 110 else if (nfds > 0)
106 { 111 {
107 for (i = 0; i < max_fds+1; ++i) 112 for (i = 0; i < fds_lim; ++i)
108 { 113 {
109 if (FD_ISSET (i, &all_rfds)) 114 if (FD_ISSET (i, &all_rfds))
110 { 115 {
diff --git a/src/xselect.c b/src/xselect.c
index 173cf78bdaa..15ce8d487fa 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -931,6 +931,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
931 931
932 /* Otherwise, record the converted selection to binary. */ 932 /* Otherwise, record the converted selection to binary. */
933 cs = xmalloc (sizeof (struct selection_data)); 933 cs = xmalloc (sizeof (struct selection_data));
934 cs->data = NULL;
934 cs->nofree = 1; 935 cs->nofree = 1;
935 cs->property = property; 936 cs->property = property;
936 cs->wait_object = NULL; 937 cs->wait_object = NULL;
diff --git a/src/xterm.c b/src/xterm.c
index 289bd6a8b71..e8fd26c36dc 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10164,7 +10164,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10164 10164
10165 /* Set the name of the terminal. */ 10165 /* Set the name of the terminal. */
10166 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1); 10166 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
10167 strncpy (terminal->name, SSDATA (display_name), SBYTES (display_name)); 10167 memcpy (terminal->name, SSDATA (display_name), SBYTES (display_name));
10168 terminal->name[SBYTES (display_name)] = 0; 10168 terminal->name[SBYTES (display_name)] = 0;
10169 10169
10170#if 0 10170#if 0
diff --git a/src/xterm.h b/src/xterm.h
index 86daa7bd27e..89eb493a43c 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1038,6 +1038,7 @@ extern void x_clipboard_manager_save_all (void);
1038 1038
1039extern struct x_display_info * check_x_display_info (Lisp_Object); 1039extern struct x_display_info * check_x_display_info (Lisp_Object);
1040extern Lisp_Object x_get_focus_frame (struct frame *); 1040extern Lisp_Object x_get_focus_frame (struct frame *);
1041extern int x_in_use;
1041 1042
1042#ifdef USE_GTK 1043#ifdef USE_GTK
1043extern int xg_set_icon (struct frame *, Lisp_Object); 1044extern int xg_set_icon (struct frame *, Lisp_Object);