aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuuki Harano2020-12-27 03:13:00 +0900
committerYuuki Harano2020-12-27 03:13:00 +0900
commitb64089c37b4305a511e5ddbf02746862c7c7575e (patch)
treec6978d471e4b0b061b7cc9c46147968379aec94f /src
parent565d8f57d349c19d9bbb5d5d5fdacf3c70b85d42 (diff)
parent4b2ca6bfc079c66cfcf39f2f36dc139012787535 (diff)
downloademacs-b64089c37b4305a511e5ddbf02746862c7c7575e.tar.gz
emacs-b64089c37b4305a511e5ddbf02746862c7c7575e.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in2
-rw-r--r--src/alloc.c8
-rw-r--r--src/buffer.c88
-rw-r--r--src/buffer.h10
-rw-r--r--src/callproc.c518
-rw-r--r--src/coding.c30
-rw-r--r--src/coding.h3
-rw-r--r--src/dispnew.c9
-rw-r--r--src/fileio.c7
-rw-r--r--src/gtkutil.c7
-rw-r--r--src/image.c68
-rw-r--r--src/lisp.h6
-rw-r--r--src/minibuf.c2
-rw-r--r--src/nsfns.m8
-rw-r--r--src/nsfont.m7
-rw-r--r--src/nsimage.m26
-rw-r--r--src/nsmenu.m2
-rw-r--r--src/nsselect.m10
-rw-r--r--src/nsterm.h2
-rw-r--r--src/nsterm.m10
-rw-r--r--src/nsxwidget.m19
-rw-r--r--src/pdumper.c2
-rw-r--r--src/print.c2
-rw-r--r--src/process.c167
-rw-r--r--src/sysdep.c26
-rw-r--r--src/w32.h2
-rw-r--r--src/w32fns.c2
-rw-r--r--src/w32gui.h2
-rw-r--r--src/w32proc.c4
-rw-r--r--src/w32term.c4
-rw-r--r--src/window.c7
-rw-r--r--src/xdisp.c4
-rw-r--r--src/xfns.c2
-rw-r--r--src/xterm.c9
-rw-r--r--src/xwidget.c3
35 files changed, 563 insertions, 515 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index ce809e90c82..b0d4be0a56c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -341,7 +341,7 @@ HAVE_PDUMPER = @HAVE_PDUMPER@
341 341
342## ARM Macs require that all code have a valid signature. Since pump 342## ARM Macs require that all code have a valid signature. Since pump
343## invalidates the signature, we must re-sign to fix it. 343## invalidates the signature, we must re-sign to fix it.
344DO_CODESIGN=$(patsubst aarch64-apple-darwin%,yes,@configuration@) 344DO_CODESIGN=$(patsubst arm-apple-darwin%,yes,@configuration@)
345 345
346# 'make' verbosity. 346# 'make' verbosity.
347AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ 347AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
diff --git a/src/alloc.c b/src/alloc.c
index 51088eb0e77..42d096ef2ae 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -664,7 +664,7 @@ display_malloc_warning (void)
664 call3 (intern ("display-warning"), 664 call3 (intern ("display-warning"),
665 intern ("alloc"), 665 intern ("alloc"),
666 build_string (pending_malloc_warning), 666 build_string (pending_malloc_warning),
667 intern ("emergency")); 667 intern (":emergency"));
668 pending_malloc_warning = 0; 668 pending_malloc_warning = 0;
669} 669}
670 670
@@ -732,7 +732,11 @@ static void
732malloc_unblock_input (void) 732malloc_unblock_input (void)
733{ 733{
734 if (block_input_in_memory_allocators) 734 if (block_input_in_memory_allocators)
735 unblock_input (); 735 {
736 int err = errno;
737 unblock_input ();
738 errno = err;
739 }
736} 740}
737# define MALLOC_BLOCK_INPUT malloc_block_input () 741# define MALLOC_BLOCK_INPUT malloc_block_input ()
738# define MALLOC_UNBLOCK_INPUT malloc_unblock_input () 742# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
diff --git a/src/buffer.c b/src/buffer.c
index dfc34faf6e6..9e44345616e 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -37,7 +37,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
37#include "window.h" 37#include "window.h"
38#include "commands.h" 38#include "commands.h"
39#include "character.h" 39#include "character.h"
40#include "coding.h"
41#include "buffer.h" 40#include "buffer.h"
42#include "region-cache.h" 41#include "region-cache.h"
43#include "indent.h" 42#include "indent.h"
@@ -514,16 +513,33 @@ get_truename_buffer (register Lisp_Object filename)
514 return Qnil; 513 return Qnil;
515} 514}
516 515
517DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0, 516/* Run buffer-list-update-hook if Vrun_hooks is non-nil, and BUF is NULL
517 or does not have buffer hooks inhibited. BUF is NULL when called by
518 make-indirect-buffer, since it does not inhibit buffer hooks. */
519
520static void
521run_buffer_list_update_hook (struct buffer *buf)
522{
523 if (! (NILP (Vrun_hooks) || (buf && buf->inhibit_buffer_hooks)))
524 call1 (Vrun_hooks, Qbuffer_list_update_hook);
525}
526
527DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 2, 0,
518 doc: /* Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed. 528 doc: /* Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed.
519If BUFFER-OR-NAME is a string and a live buffer with that name exists, 529If BUFFER-OR-NAME is a string and a live buffer with that name exists,
520return that buffer. If no such buffer exists, create a new buffer with 530return that buffer. If no such buffer exists, create a new buffer with
521that name and return it. If BUFFER-OR-NAME starts with a space, the new 531that name and return it.
522buffer does not keep undo information. 532
533If BUFFER-OR-NAME starts with a space, the new buffer does not keep undo
534information. If optional argument INHIBIT-BUFFER-HOOKS is non-nil, the
535new buffer does not run the hooks `kill-buffer-hook',
536`kill-buffer-query-functions', and `buffer-list-update-hook'. This
537avoids slowing down internal or temporary buffers that are never
538presented to users or passed on to other applications.
523 539
524If BUFFER-OR-NAME is a buffer instead of a string, return it as given, 540If BUFFER-OR-NAME is a buffer instead of a string, return it as given,
525even if it is dead. The return value is never nil. */) 541even if it is dead. The return value is never nil. */)
526 (register Lisp_Object buffer_or_name) 542 (register Lisp_Object buffer_or_name, Lisp_Object inhibit_buffer_hooks)
527{ 543{
528 register Lisp_Object buffer, name; 544 register Lisp_Object buffer, name;
529 register struct buffer *b; 545 register struct buffer *b;
@@ -598,11 +614,7 @@ even if it is dead. The return value is never nil. */)
598 set_string_intervals (name, NULL); 614 set_string_intervals (name, NULL);
599 bset_name (b, name); 615 bset_name (b, name);
600 616
601 b->inhibit_buffer_hooks 617 b->inhibit_buffer_hooks = !NILP (inhibit_buffer_hooks);
602 = (STRINGP (Vcode_conversion_workbuf_name)
603 && strncmp (SSDATA (name), SSDATA (Vcode_conversion_workbuf_name),
604 SBYTES (Vcode_conversion_workbuf_name)) == 0);
605
606 bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt); 618 bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt);
607 619
608 reset_buffer (b); 620 reset_buffer (b);
@@ -614,9 +626,8 @@ even if it is dead. The return value is never nil. */)
614 /* Put this in the alist of all live buffers. */ 626 /* Put this in the alist of all live buffers. */
615 XSETBUFFER (buffer, b); 627 XSETBUFFER (buffer, b);
616 Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer))); 628 Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer)));
617 /* And run buffer-list-update-hook. */ 629
618 if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks) 630 run_buffer_list_update_hook (b);
619 call1 (Vrun_hooks, Qbuffer_list_update_hook);
620 631
621 return buffer; 632 return buffer;
622} 633}
@@ -890,9 +901,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
890 set_buffer_internal_1 (old_b); 901 set_buffer_internal_1 (old_b);
891 } 902 }
892 903
893 /* Run buffer-list-update-hook. */ 904 run_buffer_list_update_hook (NULL);
894 if (!NILP (Vrun_hooks))
895 call1 (Vrun_hooks, Qbuffer_list_update_hook);
896 905
897 return buf; 906 return buf;
898} 907}
@@ -1536,9 +1545,7 @@ This does not change the name of the visited file (if any). */)
1536 && !NILP (BVAR (current_buffer, auto_save_file_name))) 1545 && !NILP (BVAR (current_buffer, auto_save_file_name)))
1537 call0 (intern ("rename-auto-save-file")); 1546 call0 (intern ("rename-auto-save-file"));
1538 1547
1539 /* Run buffer-list-update-hook. */ 1548 run_buffer_list_update_hook (current_buffer);
1540 if (!NILP (Vrun_hooks) && !current_buffer->inhibit_buffer_hooks)
1541 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1542 1549
1543 /* Refetch since that last call may have done GC. */ 1550 /* Refetch since that last call may have done GC. */
1544 return BVAR (current_buffer, name); 1551 return BVAR (current_buffer, name);
@@ -1612,7 +1619,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1612 buf = Fget_buffer (scratch); 1619 buf = Fget_buffer (scratch);
1613 if (NILP (buf)) 1620 if (NILP (buf))
1614 { 1621 {
1615 buf = Fget_buffer_create (scratch); 1622 buf = Fget_buffer_create (scratch, Qnil);
1616 Fset_buffer_major_mode (buf); 1623 Fset_buffer_major_mode (buf);
1617 } 1624 }
1618 return buf; 1625 return buf;
@@ -1636,7 +1643,7 @@ other_buffer_safely (Lisp_Object buffer)
1636 buf = Fget_buffer (scratch); 1643 buf = Fget_buffer (scratch);
1637 if (NILP (buf)) 1644 if (NILP (buf))
1638 { 1645 {
1639 buf = Fget_buffer_create (scratch); 1646 buf = Fget_buffer_create (scratch, Qnil);
1640 Fset_buffer_major_mode (buf); 1647 Fset_buffer_major_mode (buf);
1641 } 1648 }
1642 1649
@@ -1713,7 +1720,9 @@ buffer to be killed as the current buffer. If any of them returns nil,
1713the buffer is not killed. The hook `kill-buffer-hook' is run before the 1720the buffer is not killed. The hook `kill-buffer-hook' is run before the
1714buffer is actually killed. The buffer being killed will be current 1721buffer is actually killed. The buffer being killed will be current
1715while the hook is running. Functions called by any of these hooks are 1722while the hook is running. Functions called by any of these hooks are
1716supposed to not change the current buffer. 1723supposed to not change the current buffer. Neither hook is run for
1724internal or temporary buffers created by `get-buffer-create' or
1725`generate-new-buffer' with argument INHIBIT-BUFFER-HOOKS non-nil.
1717 1726
1718Any processes that have this buffer as the `process-buffer' are killed 1727Any processes that have this buffer as the `process-buffer' are killed
1719with SIGHUP. This function calls `replace-buffer-in-windows' for 1728with SIGHUP. This function calls `replace-buffer-in-windows' for
@@ -1973,9 +1982,7 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1973 bset_width_table (b, Qnil); 1982 bset_width_table (b, Qnil);
1974 unblock_input (); 1983 unblock_input ();
1975 1984
1976 /* Run buffer-list-update-hook. */ 1985 run_buffer_list_update_hook (b);
1977 if (!NILP (Vrun_hooks) && !b->inhibit_buffer_hooks)
1978 call1 (Vrun_hooks, Qbuffer_list_update_hook);
1979 1986
1980 return Qt; 1987 return Qt;
1981} 1988}
@@ -2015,9 +2022,7 @@ record_buffer (Lisp_Object buffer)
2015 fset_buffer_list (f, Fcons (buffer, Fdelq (buffer, f->buffer_list))); 2022 fset_buffer_list (f, Fcons (buffer, Fdelq (buffer, f->buffer_list)));
2016 fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list)); 2023 fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list));
2017 2024
2018 /* Run buffer-list-update-hook. */ 2025 run_buffer_list_update_hook (XBUFFER (buffer));
2019 if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
2020 call1 (Vrun_hooks, Qbuffer_list_update_hook);
2021} 2026}
2022 2027
2023 2028
@@ -2054,9 +2059,7 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal,
2054 fset_buried_buffer_list 2059 fset_buried_buffer_list
2055 (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list))); 2060 (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)));
2056 2061
2057 /* Run buffer-list-update-hook. */ 2062 run_buffer_list_update_hook (XBUFFER (buffer));
2058 if (!NILP (Vrun_hooks) && !XBUFFER (buffer)->inhibit_buffer_hooks)
2059 call1 (Vrun_hooks, Qbuffer_list_update_hook);
2060 2063
2061 return Qnil; 2064 return Qnil;
2062} 2065}
@@ -5349,10 +5352,11 @@ init_buffer_once (void)
5349 Fput (Qkill_buffer_hook, Qpermanent_local, Qt); 5352 Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
5350 5353
5351 /* Super-magic invisible buffer. */ 5354 /* Super-magic invisible buffer. */
5352 Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1")); 5355 Vprin1_to_string_buffer =
5356 Fget_buffer_create (build_pure_c_string (" prin1"), Qt);
5353 Vbuffer_alist = Qnil; 5357 Vbuffer_alist = Qnil;
5354 5358
5355 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*"))); 5359 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*"), Qnil));
5356 5360
5357 inhibit_modification_hooks = 0; 5361 inhibit_modification_hooks = 0;
5358} 5362}
@@ -5397,7 +5401,7 @@ init_buffer (void)
5397#endif /* USE_MMAP_FOR_BUFFERS */ 5401#endif /* USE_MMAP_FOR_BUFFERS */
5398 5402
5399 AUTO_STRING (scratch, "*scratch*"); 5403 AUTO_STRING (scratch, "*scratch*");
5400 Fset_buffer (Fget_buffer_create (scratch)); 5404 Fset_buffer (Fget_buffer_create (scratch, Qnil));
5401 if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) 5405 if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
5402 Fset_buffer_multibyte (Qnil); 5406 Fset_buffer_multibyte (Qnil);
5403 5407
@@ -6300,9 +6304,14 @@ Use Custom to set this variable and update the display. */);
6300 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions, 6304 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions,
6301 doc: /* List of functions called with no args to query before killing a buffer. 6305 doc: /* List of functions called with no args to query before killing a buffer.
6302The buffer being killed will be current while the functions are running. 6306The buffer being killed will be current while the functions are running.
6307See `kill-buffer'.
6303 6308
6304If any of them returns nil, the buffer is not killed. Functions run by 6309If any of them returns nil, the buffer is not killed. Functions run by
6305this hook are supposed to not change the current buffer. */); 6310this hook are supposed to not change the current buffer.
6311
6312This hook is not run for internal or temporary buffers created by
6313`get-buffer-create' or `generate-new-buffer' with argument
6314INHIBIT-BUFFER-HOOKS non-nil. */);
6306 Vkill_buffer_query_functions = Qnil; 6315 Vkill_buffer_query_functions = Qnil;
6307 6316
6308 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook, 6317 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook,
@@ -6315,9 +6324,12 @@ The function `kill-all-local-variables' runs this before doing anything else. *
6315 doc: /* Hook run when the buffer list changes. 6324 doc: /* Hook run when the buffer list changes.
6316Functions (implicitly) running this hook are `get-buffer-create', 6325Functions (implicitly) running this hook are `get-buffer-create',
6317`make-indirect-buffer', `rename-buffer', `kill-buffer', `bury-buffer' 6326`make-indirect-buffer', `rename-buffer', `kill-buffer', `bury-buffer'
6318and `select-window'. Functions run by this hook should avoid calling 6327and `select-window'. This hook is not run for internal or temporary
6319`select-window' with a nil NORECORD argument or `with-temp-buffer' 6328buffers created by `get-buffer-create' or `generate-new-buffer' with
6320since either may lead to infinite recursion. */); 6329argument INHIBIT-BUFFER-HOOKS non-nil.
6330
6331Functions run by this hook should avoid calling `select-window' with a
6332nil NORECORD argument since it may lead to infinite recursion. */);
6321 Vbuffer_list_update_hook = Qnil; 6333 Vbuffer_list_update_hook = Qnil;
6322 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook"); 6334 DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook");
6323 6335
diff --git a/src/buffer.h b/src/buffer.h
index fe549c5dac1..b8c5162be4a 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -663,11 +663,11 @@ struct buffer
663 /* Non-zero whenever the narrowing is changed in this buffer. */ 663 /* Non-zero whenever the narrowing is changed in this buffer. */
664 bool_bf clip_changed : 1; 664 bool_bf clip_changed : 1;
665 665
666 /* Non-zero for internally used temporary buffers that don't need to 666 /* Non-zero for internal or temporary buffers that don't need to
667 run hooks kill-buffer-hook, buffer-list-update-hook, and 667 run hooks kill-buffer-hook, kill-buffer-query-functions, and
668 kill-buffer-query-functions. This is used in coding.c to avoid 668 buffer-list-update-hook. This is used in coding.c to avoid
669 slowing down en/decoding when there are a lot of these hooks 669 slowing down en/decoding when a lot of these hooks are
670 defined. */ 670 defined, as well as by with-temp-buffer, for example. */
671 bool_bf inhibit_buffer_hooks : 1; 671 bool_bf inhibit_buffer_hooks : 1;
672 672
673 /* List of overlays that end at or before the current center, 673 /* List of overlays that end at or before the current center,
diff --git a/src/callproc.c b/src/callproc.c
index e3346e2eabb..3ecd6880274 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -100,6 +100,15 @@ enum
100 }; 100 };
101 101
102static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int, ptrdiff_t); 102static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int, ptrdiff_t);
103
104#ifdef DOS_NT
105# define CHILD_SETUP_TYPE int
106#else
107# define CHILD_SETUP_TYPE _Noreturn void
108#endif
109
110static CHILD_SETUP_TYPE child_setup (int, int, int, char **, char **,
111 const char *);
103 112
104/* Return the current buffer's working directory, or the home 113/* Return the current buffer's working directory, or the home
105 directory if it's unreachable, as a string suitable for a system call. 114 directory if it's unreachable, as a string suitable for a system call.
@@ -300,8 +309,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
300#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 309#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
301 char *tempfile = NULL; 310 char *tempfile = NULL;
302#else 311#else
303 sigset_t oldset; 312 pid_t pid = -1;
304 pid_t pid;
305#endif 313#endif
306 int child_errno; 314 int child_errno;
307 int fd_output, fd_error; 315 int fd_output, fd_error;
@@ -405,9 +413,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
405 413
406 if (! (NILP (buffer) || EQ (buffer, Qt) || FIXNUMP (buffer))) 414 if (! (NILP (buffer) || EQ (buffer, Qt) || FIXNUMP (buffer)))
407 { 415 {
408 Lisp_Object spec_buffer; 416 Lisp_Object spec_buffer = buffer;
409 spec_buffer = buffer; 417 buffer = Fget_buffer_create (buffer, Qnil);
410 buffer = Fget_buffer_create (buffer);
411 /* Mention the buffer name for a better error message. */ 418 /* Mention the buffer name for a better error message. */
412 if (NILP (buffer)) 419 if (NILP (buffer))
413 CHECK_BUFFER (spec_buffer); 420 CHECK_BUFFER (spec_buffer);
@@ -542,8 +549,11 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
542 callproc_fd[CALLPROC_STDERR] = fd_error; 549 callproc_fd[CALLPROC_STDERR] = fd_error;
543 } 550 }
544 551
552 char **env = make_environment_block (current_dir);
553
545#ifdef MSDOS /* MW, July 1993 */ 554#ifdef MSDOS /* MW, July 1993 */
546 status = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir); 555 status = child_setup (filefd, fd_output, fd_error, new_argv, env,
556 SSDATA (current_dir));
547 557
548 if (status < 0) 558 if (status < 0)
549 { 559 {
@@ -586,73 +596,10 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
586 596
587#ifndef MSDOS 597#ifndef MSDOS
588 598
589 block_input (); 599 child_errno
590 block_child_signal (&oldset); 600 = emacs_spawn (&pid, filefd, fd_output, fd_error, new_argv, env,
591 601 SSDATA (current_dir), NULL);
592#ifdef WINDOWSNT 602 eassert ((child_errno == 0) == (0 < pid));
593 pid = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
594#else /* not WINDOWSNT */
595
596 /* vfork, and prevent local vars from being clobbered by the vfork. */
597 {
598 Lisp_Object volatile buffer_volatile = buffer;
599 Lisp_Object volatile coding_systems_volatile = coding_systems;
600 Lisp_Object volatile current_dir_volatile = current_dir;
601 bool volatile display_p_volatile = display_p;
602 int volatile fd_error_volatile = fd_error;
603 int volatile filefd_volatile = filefd;
604 ptrdiff_t volatile count_volatile = count;
605 ptrdiff_t volatile sa_avail_volatile = sa_avail;
606 ptrdiff_t volatile sa_count_volatile = sa_count;
607 char **volatile new_argv_volatile = new_argv;
608 int volatile callproc_fd_volatile[CALLPROC_FDS];
609 for (i = 0; i < CALLPROC_FDS; i++)
610 callproc_fd_volatile[i] = callproc_fd[i];
611
612 pid = vfork ();
613
614 buffer = buffer_volatile;
615 coding_systems = coding_systems_volatile;
616 current_dir = current_dir_volatile;
617 display_p = display_p_volatile;
618 fd_error = fd_error_volatile;
619 filefd = filefd_volatile;
620 count = count_volatile;
621 sa_avail = sa_avail_volatile;
622 sa_count = sa_count_volatile;
623 new_argv = new_argv_volatile;
624
625 for (i = 0; i < CALLPROC_FDS; i++)
626 callproc_fd[i] = callproc_fd_volatile[i];
627 fd_output = callproc_fd[CALLPROC_STDOUT];
628 }
629
630 if (pid == 0)
631 {
632#ifdef DARWIN_OS
633 /* Work around a macOS bug, where SIGCHLD is apparently
634 delivered to a vforked child instead of to its parent. See:
635 https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html
636 */
637 signal (SIGCHLD, SIG_DFL);
638#endif
639
640 unblock_child_signal (&oldset);
641 dissociate_controlling_tty ();
642
643 /* Emacs ignores SIGPIPE, but the child should not. */
644 signal (SIGPIPE, SIG_DFL);
645 /* Likewise for SIGPROF. */
646#ifdef SIGPROF
647 signal (SIGPROF, SIG_DFL);
648#endif
649
650 child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
651 }
652
653#endif /* not WINDOWSNT */
654
655 child_errno = errno;
656 603
657 if (pid > 0) 604 if (pid > 0)
658 { 605 {
@@ -672,9 +619,6 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
672 } 619 }
673 } 620 }
674 621
675 unblock_child_signal (&oldset);
676 unblock_input ();
677
678 if (pid < 0) 622 if (pid < 0)
679 report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, child_errno); 623 report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, child_errno);
680 624
@@ -1188,16 +1132,6 @@ exec_failed (char const *name, int err)
1188 _exit (err == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); 1132 _exit (err == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE);
1189} 1133}
1190 1134
1191#else
1192
1193/* Do nothing. There is no need to fail, as DOS_NT platforms do not
1194 fork and exec, and handle alloca exhaustion in a different way. */
1195
1196static void
1197exec_failed (char const *name, int err)
1198{
1199}
1200
1201#endif 1135#endif
1202 1136
1203/* This is the last thing run in a newly forked inferior 1137/* This is the last thing run in a newly forked inferior
@@ -1206,8 +1140,6 @@ exec_failed (char const *name, int err)
1206 Initialize inferior's priority, pgrp, connected dir and environment. 1140 Initialize inferior's priority, pgrp, connected dir and environment.
1207 then exec another program based on new_argv. 1141 then exec another program based on new_argv.
1208 1142
1209 If SET_PGRP, put the subprocess into a separate process group.
1210
1211 CURRENT_DIR is an elisp string giving the path of the current 1143 CURRENT_DIR is an elisp string giving the path of the current
1212 directory the subprocess should have. Since we can't really signal 1144 directory the subprocess should have. Since we can't really signal
1213 a decent error from within the child, this should be verified as an 1145 a decent error from within the child, this should be verified as an
@@ -1217,12 +1149,10 @@ exec_failed (char const *name, int err)
1217 On MS-Windows, either return a pid or return -1 and set errno. 1149 On MS-Windows, either return a pid or return -1 and set errno.
1218 On MS-DOS, either return an exit status or signal an error. */ 1150 On MS-DOS, either return an exit status or signal an error. */
1219 1151
1220CHILD_SETUP_TYPE 1152static CHILD_SETUP_TYPE
1221child_setup (int in, int out, int err, char **new_argv, bool set_pgrp, 1153child_setup (int in, int out, int err, char **new_argv, char **env,
1222 Lisp_Object current_dir) 1154 const char *current_dir)
1223{ 1155{
1224 char **env;
1225 char *pwd_var;
1226#ifdef WINDOWSNT 1156#ifdef WINDOWSNT
1227 int cpid; 1157 int cpid;
1228 HANDLE handles[3]; 1158 HANDLE handles[3];
@@ -1236,24 +1166,6 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1236 src/alloca.c) it is safe because that changes the superior's 1166 src/alloca.c) it is safe because that changes the superior's
1237 static variables as if the superior had done alloca and will be 1167 static variables as if the superior had done alloca and will be
1238 cleaned up in the usual way. */ 1168 cleaned up in the usual way. */
1239 {
1240 char *temp;
1241 ptrdiff_t i;
1242
1243 i = SBYTES (current_dir);
1244#ifdef MSDOS
1245 /* MSDOS must have all environment variables malloc'ed, because
1246 low-level libc functions that launch subsidiary processes rely
1247 on that. */
1248 pwd_var = xmalloc (i + 5);
1249#else
1250 if (MAX_ALLOCA - 5 < i)
1251 exec_failed (new_argv[0], ENOMEM);
1252 pwd_var = alloca (i + 5);
1253#endif
1254 temp = pwd_var + 4;
1255 memcpy (pwd_var, "PWD=", 4);
1256 lispstpcpy (temp, current_dir);
1257 1169
1258#ifndef DOS_NT 1170#ifndef DOS_NT
1259 /* We can't signal an Elisp error here; we're in a vfork. Since 1171 /* We can't signal an Elisp error here; we're in a vfork. Since
@@ -1261,101 +1173,13 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1261 should only return an error if the directory's permissions 1173 should only return an error if the directory's permissions
1262 are changed between the check and this chdir, but we should 1174 are changed between the check and this chdir, but we should
1263 at least check. */ 1175 at least check. */
1264 if (chdir (temp) < 0) 1176 if (chdir (current_dir) < 0)
1265 _exit (EXIT_CANCELED); 1177 _exit (EXIT_CANCELED);
1266#else /* DOS_NT */ 1178#endif
1267 /* Get past the drive letter, so that d:/ is left alone. */
1268 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1269 {
1270 temp += 2;
1271 i -= 2;
1272 }
1273#endif /* DOS_NT */
1274
1275 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1276 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1277 temp[--i] = 0;
1278 }
1279
1280 /* Set `env' to a vector of the strings in the environment. */
1281 {
1282 register Lisp_Object tem;
1283 register char **new_env;
1284 char **p, **q;
1285 register int new_length;
1286 Lisp_Object display = Qnil;
1287
1288 new_length = 0;
1289
1290 for (tem = Vprocess_environment;
1291 CONSP (tem) && STRINGP (XCAR (tem));
1292 tem = XCDR (tem))
1293 {
1294 if (strncmp (SSDATA (XCAR (tem)), "DISPLAY", 7) == 0
1295 && (SDATA (XCAR (tem)) [7] == '\0'
1296 || SDATA (XCAR (tem)) [7] == '='))
1297 /* DISPLAY is specified in process-environment. */
1298 display = Qt;
1299 new_length++;
1300 }
1301
1302 /* If not provided yet, use the frame's DISPLAY. */
1303 if (NILP (display))
1304 {
1305 Lisp_Object tmp = Fframe_parameter (selected_frame, Qdisplay);
1306 if (!STRINGP (tmp) && CONSP (Vinitial_environment))
1307 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1308 tmp = Fgetenv_internal (build_string ("DISPLAY"),
1309 Vinitial_environment);
1310 if (STRINGP (tmp))
1311 {
1312 display = tmp;
1313 new_length++;
1314 }
1315 }
1316
1317 /* new_length + 2 to include PWD and terminating 0. */
1318 if (MAX_ALLOCA / sizeof *env - 2 < new_length)
1319 exec_failed (new_argv[0], ENOMEM);
1320 env = new_env = alloca ((new_length + 2) * sizeof *env);
1321 /* If we have a PWD envvar, pass one down,
1322 but with corrected value. */
1323 if (egetenv ("PWD"))
1324 *new_env++ = pwd_var;
1325
1326 if (STRINGP (display))
1327 {
1328 if (MAX_ALLOCA - sizeof "DISPLAY=" < SBYTES (display))
1329 exec_failed (new_argv[0], ENOMEM);
1330 char *vdata = alloca (sizeof "DISPLAY=" + SBYTES (display));
1331 lispstpcpy (stpcpy (vdata, "DISPLAY="), display);
1332 new_env = add_env (env, new_env, vdata);
1333 }
1334
1335 /* Overrides. */
1336 for (tem = Vprocess_environment;
1337 CONSP (tem) && STRINGP (XCAR (tem));
1338 tem = XCDR (tem))
1339 new_env = add_env (env, new_env, SSDATA (XCAR (tem)));
1340
1341 *new_env = 0;
1342
1343 /* Remove variable names without values. */
1344 p = q = env;
1345 while (*p != 0)
1346 {
1347 while (*q != 0 && strchr (*q, '=') == NULL)
1348 q++;
1349 *p = *q++;
1350 if (*p != 0)
1351 p++;
1352 }
1353 }
1354
1355 1179
1356#ifdef WINDOWSNT 1180#ifdef WINDOWSNT
1357 prepare_standard_handles (in, out, err, handles); 1181 prepare_standard_handles (in, out, err, handles);
1358 set_process_dir (SSDATA (current_dir)); 1182 set_process_dir (current_dir);
1359 /* Spawn the child. (See w32proc.c:sys_spawnve). */ 1183 /* Spawn the child. (See w32proc.c:sys_spawnve). */
1360 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env); 1184 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1361 reset_standard_handles (in, out, err, handles); 1185 reset_standard_handles (in, out, err, handles);
@@ -1391,6 +1215,183 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1391#endif /* not WINDOWSNT */ 1215#endif /* not WINDOWSNT */
1392} 1216}
1393 1217
1218/* Start a new asynchronous subprocess. If successful, return zero
1219 and store the process identifier of the new process in *NEWPID.
1220 Use STDIN, STDOUT, and STDERR as standard streams for the new
1221 process. Use ARGV as argument vector for the new process; use
1222 process image file ARGV[0]. Use ENVP for the environment block for
1223 the new process. Use CWD as working directory for the new process.
1224 If PTY is not NULL, it must be a pseudoterminal device. If PTY is
1225 NULL, don't perform any terminal setup. */
1226
1227int
1228emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err,
1229 char **argv, char **envp, const char *cwd, const char *pty)
1230{
1231 sigset_t oldset;
1232 int pid;
1233
1234 block_input ();
1235 block_child_signal (&oldset);
1236
1237#ifndef WINDOWSNT
1238 /* vfork, and prevent local vars from being clobbered by the vfork. */
1239 pid_t *volatile newpid_volatile = newpid;
1240 const char *volatile cwd_volatile = cwd;
1241 const char *volatile pty_volatile = pty;
1242 char **volatile argv_volatile = argv;
1243 int volatile stdin_volatile = std_in;
1244 int volatile stdout_volatile = std_out;
1245 int volatile stderr_volatile = std_err;
1246 char **volatile envp_volatile = envp;
1247
1248#ifdef DARWIN_OS
1249 /* Darwin doesn't let us run setsid after a vfork, so use fork when
1250 necessary. Below, we reset SIGCHLD handling after a vfork, as
1251 apparently macOS can mistakenly deliver SIGCHLD to the child. */
1252 if (pty != NULL)
1253 pid = fork ();
1254 else
1255 pid = vfork ();
1256#else
1257 pid = vfork ();
1258#endif
1259
1260 newpid = newpid_volatile;
1261 cwd = cwd_volatile;
1262 pty = pty_volatile;
1263 argv = argv_volatile;
1264 std_in = stdin_volatile;
1265 std_out = stdout_volatile;
1266 std_err = stderr_volatile;
1267 envp = envp_volatile;
1268
1269 if (pid == 0)
1270#endif /* not WINDOWSNT */
1271 {
1272 bool pty_flag = pty != NULL;
1273 /* Make the pty be the controlling terminal of the process. */
1274#ifdef HAVE_PTYS
1275 dissociate_controlling_tty ();
1276
1277 /* Make the pty's terminal the controlling terminal. */
1278 if (pty_flag && std_in >= 0)
1279 {
1280#ifdef TIOCSCTTY
1281 /* We ignore the return value
1282 because faith@cs.unc.edu says that is necessary on Linux. */
1283 ioctl (std_in, TIOCSCTTY, 0);
1284#endif
1285 }
1286#if defined (LDISC1)
1287 if (pty_flag && std_in >= 0)
1288 {
1289 struct termios t;
1290 tcgetattr (std_in, &t);
1291 t.c_lflag = LDISC1;
1292 if (tcsetattr (std_in, TCSANOW, &t) < 0)
1293 emacs_perror ("create_process/tcsetattr LDISC1");
1294 }
1295#else
1296#if defined (NTTYDISC) && defined (TIOCSETD)
1297 if (pty_flag && std_in >= 0)
1298 {
1299 /* Use new line discipline. */
1300 int ldisc = NTTYDISC;
1301 ioctl (std_in, TIOCSETD, &ldisc);
1302 }
1303#endif
1304#endif
1305
1306#if !defined (DONT_REOPEN_PTY)
1307/*** There is a suggestion that this ought to be a
1308 conditional on TIOCSPGRP, or !defined TIOCSCTTY.
1309 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
1310 that system does seem to need this code, even though
1311 both TIOCSCTTY is defined. */
1312 /* Now close the pty (if we had it open) and reopen it.
1313 This makes the pty the controlling terminal of the subprocess. */
1314 if (pty_flag)
1315 {
1316
1317 /* I wonder if emacs_close (emacs_open (pty, ...))
1318 would work? */
1319 if (std_in >= 0)
1320 emacs_close (std_in);
1321 std_out = std_in = emacs_open (pty, O_RDWR, 0);
1322
1323 if (std_in < 0)
1324 {
1325 emacs_perror (pty);
1326 _exit (EXIT_CANCELED);
1327 }
1328
1329 }
1330#endif /* not DONT_REOPEN_PTY */
1331
1332#ifdef SETUP_SLAVE_PTY
1333 if (pty_flag)
1334 {
1335 SETUP_SLAVE_PTY;
1336 }
1337#endif /* SETUP_SLAVE_PTY */
1338#endif /* HAVE_PTYS */
1339
1340#ifdef DARWIN_OS
1341 /* Work around a macOS bug, where SIGCHLD is apparently
1342 delivered to a vforked child instead of to its parent. See:
1343 https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html
1344 */
1345 signal (SIGCHLD, SIG_DFL);
1346#endif
1347
1348 signal (SIGINT, SIG_DFL);
1349 signal (SIGQUIT, SIG_DFL);
1350#ifdef SIGPROF
1351 signal (SIGPROF, SIG_DFL);
1352#endif
1353
1354 /* Emacs ignores SIGPIPE, but the child should not. */
1355 signal (SIGPIPE, SIG_DFL);
1356 /* Likewise for SIGPROF. */
1357#ifdef SIGPROF
1358 signal (SIGPROF, SIG_DFL);
1359#endif
1360
1361 /* Stop blocking SIGCHLD in the child. */
1362 unblock_child_signal (&oldset);
1363
1364 if (pty_flag)
1365 child_setup_tty (std_out);
1366
1367 if (std_err < 0)
1368 std_err = std_out;
1369#ifdef WINDOWSNT
1370 pid = child_setup (std_in, std_out, std_err, argv, envp, cwd);
1371#else /* not WINDOWSNT */
1372 child_setup (std_in, std_out, std_err, argv, envp, cwd);
1373#endif /* not WINDOWSNT */
1374 }
1375
1376 /* Back in the parent process. */
1377
1378 int vfork_error = pid < 0 ? errno : 0;
1379
1380 /* Stop blocking in the parent. */
1381 unblock_child_signal (&oldset);
1382 unblock_input ();
1383
1384 if (pid < 0)
1385 {
1386 eassert (0 < vfork_error);
1387 return vfork_error;
1388 }
1389
1390 eassert (0 < pid);
1391 *newpid = pid;
1392 return 0;
1393}
1394
1394static bool 1395static bool
1395getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value, 1396getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value,
1396 ptrdiff_t *valuelen, Lisp_Object env) 1397 ptrdiff_t *valuelen, Lisp_Object env)
@@ -1514,6 +1515,119 @@ egetenv_internal (const char *var, ptrdiff_t len)
1514 return 0; 1515 return 0;
1515} 1516}
1516 1517
1518/* Create a new environment block. You can pass the returned pointer
1519 to `execve'. Add unwind protections for all newly-allocated
1520 objects. Don't call any Lisp code or the garbage collector while
1521 the block is active. */
1522
1523char **
1524make_environment_block (Lisp_Object current_dir)
1525{
1526 char **env;
1527 char *pwd_var;
1528
1529 {
1530 char *temp;
1531 ptrdiff_t i;
1532
1533 i = SBYTES (current_dir);
1534 pwd_var = xmalloc (i + 5);
1535 record_unwind_protect_ptr (xfree, pwd_var);
1536 temp = pwd_var + 4;
1537 memcpy (pwd_var, "PWD=", 4);
1538 lispstpcpy (temp, current_dir);
1539
1540#ifdef DOS_NT
1541 /* Get past the drive letter, so that d:/ is left alone. */
1542 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1543 {
1544 temp += 2;
1545 i -= 2;
1546 }
1547#endif /* DOS_NT */
1548
1549 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1550 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1551 temp[--i] = 0;
1552 }
1553
1554 /* Set `env' to a vector of the strings in the environment. */
1555
1556 {
1557 register Lisp_Object tem;
1558 register char **new_env;
1559 char **p, **q;
1560 register int new_length;
1561 Lisp_Object display = Qnil;
1562
1563 new_length = 0;
1564
1565 for (tem = Vprocess_environment;
1566 CONSP (tem) && STRINGP (XCAR (tem));
1567 tem = XCDR (tem))
1568 {
1569 if (strncmp (SSDATA (XCAR (tem)), "DISPLAY", 7) == 0
1570 && (SDATA (XCAR (tem)) [7] == '\0'
1571 || SDATA (XCAR (tem)) [7] == '='))
1572 /* DISPLAY is specified in process-environment. */
1573 display = Qt;
1574 new_length++;
1575 }
1576
1577 /* If not provided yet, use the frame's DISPLAY. */
1578 if (NILP (display))
1579 {
1580 Lisp_Object tmp = Fframe_parameter (selected_frame, Qdisplay);
1581 if (!STRINGP (tmp) && CONSP (Vinitial_environment))
1582 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1583 tmp = Fgetenv_internal (build_string ("DISPLAY"),
1584 Vinitial_environment);
1585 if (STRINGP (tmp))
1586 {
1587 display = tmp;
1588 new_length++;
1589 }
1590 }
1591
1592 /* new_length + 2 to include PWD and terminating 0. */
1593 env = new_env = xnmalloc (new_length + 2, sizeof *env);
1594 record_unwind_protect_ptr (xfree, env);
1595 /* If we have a PWD envvar, pass one down,
1596 but with corrected value. */
1597 if (egetenv ("PWD"))
1598 *new_env++ = pwd_var;
1599
1600 if (STRINGP (display))
1601 {
1602 char *vdata = xmalloc (sizeof "DISPLAY=" + SBYTES (display));
1603 record_unwind_protect_ptr (xfree, vdata);
1604 lispstpcpy (stpcpy (vdata, "DISPLAY="), display);
1605 new_env = add_env (env, new_env, vdata);
1606 }
1607
1608 /* Overrides. */
1609 for (tem = Vprocess_environment;
1610 CONSP (tem) && STRINGP (XCAR (tem));
1611 tem = XCDR (tem))
1612 new_env = add_env (env, new_env, SSDATA (XCAR (tem)));
1613
1614 *new_env = 0;
1615
1616 /* Remove variable names without values. */
1617 p = q = env;
1618 while (*p != 0)
1619 {
1620 while (*q != 0 && strchr (*q, '=') == NULL)
1621 q++;
1622 *p = *q++;
1623 if (*p != 0)
1624 p++;
1625 }
1626 }
1627
1628 return env;
1629}
1630
1517 1631
1518/* This is run before init_cmdargs. */ 1632/* This is run before init_cmdargs. */
1519 1633
diff --git a/src/coding.c b/src/coding.c
index 2142e7fa518..8c2443889d4 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7821,7 +7821,7 @@ encode_coding (struct coding_system *coding)
7821 7821
7822/* A string that serves as name of the reusable work buffer, and as base 7822/* A string that serves as name of the reusable work buffer, and as base
7823 name of temporary work buffers used for code-conversion operations. */ 7823 name of temporary work buffers used for code-conversion operations. */
7824Lisp_Object Vcode_conversion_workbuf_name; 7824static Lisp_Object Vcode_conversion_workbuf_name;
7825 7825
7826/* The reusable working buffer, created once and never killed. */ 7826/* The reusable working buffer, created once and never killed. */
7827static Lisp_Object Vcode_conversion_reused_workbuf; 7827static Lisp_Object Vcode_conversion_reused_workbuf;
@@ -7839,7 +7839,7 @@ code_conversion_restore (Lisp_Object arg)
7839 if (! NILP (workbuf)) 7839 if (! NILP (workbuf))
7840 { 7840 {
7841 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) 7841 if (EQ (workbuf, Vcode_conversion_reused_workbuf))
7842 reused_workbuf_in_use = 0; 7842 reused_workbuf_in_use = false;
7843 else 7843 else
7844 Fkill_buffer (workbuf); 7844 Fkill_buffer (workbuf);
7845 } 7845 }
@@ -7857,13 +7857,13 @@ code_conversion_save (bool with_work_buf, bool multibyte)
7857 { 7857 {
7858 Lisp_Object name 7858 Lisp_Object name
7859 = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); 7859 = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
7860 workbuf = Fget_buffer_create (name); 7860 workbuf = Fget_buffer_create (name, Qt);
7861 } 7861 }
7862 else 7862 else
7863 { 7863 {
7864 if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) 7864 if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf)))
7865 Vcode_conversion_reused_workbuf 7865 Vcode_conversion_reused_workbuf
7866 = Fget_buffer_create (Vcode_conversion_workbuf_name); 7866 = Fget_buffer_create (Vcode_conversion_workbuf_name, Qt);
7867 workbuf = Vcode_conversion_reused_workbuf; 7867 workbuf = Vcode_conversion_reused_workbuf;
7868 } 7868 }
7869 } 7869 }
@@ -7881,7 +7881,7 @@ code_conversion_save (bool with_work_buf, bool multibyte)
7881 bset_undo_list (current_buffer, Qt); 7881 bset_undo_list (current_buffer, Qt);
7882 bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); 7882 bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil);
7883 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) 7883 if (EQ (workbuf, Vcode_conversion_reused_workbuf))
7884 reused_workbuf_in_use = 1; 7884 reused_workbuf_in_use = true;
7885 set_buffer_internal (current); 7885 set_buffer_internal (current);
7886 } 7886 }
7887 7887
@@ -10354,8 +10354,8 @@ decode_file_name (Lisp_Object fname)
10354#endif 10354#endif
10355} 10355}
10356 10356
10357Lisp_Object 10357static Lisp_Object
10358encode_file_name (Lisp_Object fname) 10358encode_file_name_1 (Lisp_Object fname)
10359{ 10359{
10360 /* This is especially important during bootstrap and dumping, when 10360 /* This is especially important during bootstrap and dumping, when
10361 file-name encoding is not yet known, and therefore any non-ASCII 10361 file-name encoding is not yet known, and therefore any non-ASCII
@@ -10380,6 +10380,19 @@ encode_file_name (Lisp_Object fname)
10380#endif 10380#endif
10381} 10381}
10382 10382
10383Lisp_Object
10384encode_file_name (Lisp_Object fname)
10385{
10386 Lisp_Object encoded = encode_file_name_1 (fname);
10387 /* No system accepts NUL bytes in filenames. Allowing them can
10388 cause subtle bugs because the system would silently use a
10389 different filename than expected. Perform this check after
10390 encoding to not miss NUL bytes introduced through encoding. */
10391 CHECK_TYPE (memchr (SSDATA (encoded), '\0', SBYTES (encoded)) == NULL,
10392 Qfilenamep, fname);
10393 return encoded;
10394}
10395
10383DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, 10396DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string,
10384 2, 4, 0, 10397 2, 4, 0,
10385 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result. 10398 doc: /* Decode STRING which is encoded in CODING-SYSTEM, and return the result.
@@ -11639,7 +11652,7 @@ syms_of_coding (void)
11639 staticpro (&Vcode_conversion_workbuf_name); 11652 staticpro (&Vcode_conversion_workbuf_name);
11640 Vcode_conversion_workbuf_name = build_pure_c_string (" *code-conversion-work*"); 11653 Vcode_conversion_workbuf_name = build_pure_c_string (" *code-conversion-work*");
11641 11654
11642 reused_workbuf_in_use = 0; 11655 reused_workbuf_in_use = false;
11643 PDUMPER_REMEMBER_SCALAR (reused_workbuf_in_use); 11656 PDUMPER_REMEMBER_SCALAR (reused_workbuf_in_use);
11644 11657
11645 DEFSYM (Qcharset, "charset"); 11658 DEFSYM (Qcharset, "charset");
@@ -11780,6 +11793,7 @@ syms_of_coding (void)
11780 DEFSYM (Qignored, "ignored"); 11793 DEFSYM (Qignored, "ignored");
11781 11794
11782 DEFSYM (Qutf_8_string_p, "utf-8-string-p"); 11795 DEFSYM (Qutf_8_string_p, "utf-8-string-p");
11796 DEFSYM (Qfilenamep, "filenamep");
11783 11797
11784 defsubr (&Scoding_system_p); 11798 defsubr (&Scoding_system_p);
11785 defsubr (&Sread_coding_system); 11799 defsubr (&Sread_coding_system);
diff --git a/src/coding.h b/src/coding.h
index 4973cf89eb1..9ad1e954f8d 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -97,9 +97,6 @@ enum define_coding_undecided_arg_index
97 97
98extern Lisp_Object Vcoding_system_hash_table; 98extern Lisp_Object Vcoding_system_hash_table;
99 99
100/* Name (or base name) of work buffer for code conversion. */
101extern Lisp_Object Vcode_conversion_workbuf_name;
102
103/* Enumeration of index to an attribute vector of a coding system. */ 100/* Enumeration of index to an attribute vector of a coding system. */
104 101
105enum coding_attr_index 102enum coding_attr_index
diff --git a/src/dispnew.c b/src/dispnew.c
index 1aee18e7477..893e49160de 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6057,6 +6057,8 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
6057 intmax_t sec; 6057 intmax_t sec;
6058 int nsec; 6058 int nsec;
6059 bool do_display = display_option > 0; 6059 bool do_display = display_option > 0;
6060 bool curbuf_eq_winbuf
6061 = (current_buffer == XBUFFER (XWINDOW (selected_window)->contents));
6060 6062
6061 swallow_events (do_display); 6063 swallow_events (do_display);
6062 6064
@@ -6111,6 +6113,13 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
6111 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display, 6113 wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
6112 Qnil, NULL, 0); 6114 Qnil, NULL, 0);
6113 6115
6116 if (reading && curbuf_eq_winbuf)
6117 /* Timers and process filters/sentinels may have changed the selected
6118 window (e.g. in response to a connection from emacsclient), in which
6119 case we should follow it (unless we weren't in the selected-window's
6120 buffer to start with). */
6121 set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
6122
6114 return detect_input_pending () ? Qnil : Qt; 6123 return detect_input_pending () ? Qnil : Qt;
6115} 6124}
6116 6125
diff --git a/src/fileio.c b/src/fileio.c
index c97f4daf20c..23b4523c944 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3050,7 +3050,6 @@ file_accessible_directory_p (Lisp_Object file)
3050 ptrdiff_t len = SBYTES (file); 3050 ptrdiff_t len = SBYTES (file);
3051 char const *dir; 3051 char const *dir;
3052 bool ok; 3052 bool ok;
3053 int saved_errno;
3054 USE_SAFE_ALLOCA; 3053 USE_SAFE_ALLOCA;
3055 3054
3056 /* Normally a file "FOO" is an accessible directory if "FOO/." exists. 3055 /* Normally a file "FOO" is an accessible directory if "FOO/." exists.
@@ -3075,9 +3074,7 @@ file_accessible_directory_p (Lisp_Object file)
3075 } 3074 }
3076 3075
3077 ok = file_access_p (dir, F_OK); 3076 ok = file_access_p (dir, F_OK);
3078 saved_errno = errno;
3079 SAFE_FREE (); 3077 SAFE_FREE ();
3080 errno = saved_errno;
3081 return ok; 3078 return ok;
3082#endif /* !DOS_NT */ 3079#endif /* !DOS_NT */
3083} 3080}
@@ -4004,7 +4001,7 @@ by calling `format-decode', which see. */)
4004 4001
4005 record_unwind_current_buffer (); 4002 record_unwind_current_buffer ();
4006 4003
4007 workbuf = Fget_buffer_create (name); 4004 workbuf = Fget_buffer_create (name, Qt);
4008 buf = XBUFFER (workbuf); 4005 buf = XBUFFER (workbuf);
4009 4006
4010 delete_all_overlays (buf); 4007 delete_all_overlays (buf);
@@ -5752,7 +5749,7 @@ auto_save_error (Lisp_Object error_val)
5752 Lisp_Object msg = CALLN (Fformat, format, BVAR (current_buffer, name), 5749 Lisp_Object msg = CALLN (Fformat, format, BVAR (current_buffer, name),
5753 Ferror_message_string (error_val)); 5750 Ferror_message_string (error_val));
5754 call3 (intern ("display-warning"), 5751 call3 (intern ("display-warning"),
5755 intern ("auto-save"), msg, intern ("error")); 5752 intern ("auto-save"), msg, intern (":error"));
5756 5753
5757 return Qnil; 5754 return Qnil;
5758} 5755}
diff --git a/src/gtkutil.c b/src/gtkutil.c
index a62616bbfc6..9ab844e8311 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -3313,14 +3313,11 @@ xg_get_menu_item_label (GtkMenuItem *witem)
3313static bool 3313static bool
3314xg_item_label_same_p (GtkMenuItem *witem, const char *label) 3314xg_item_label_same_p (GtkMenuItem *witem, const char *label)
3315{ 3315{
3316 bool is_same = 0;
3317 char *utf8_label = get_utf8_string (label); 3316 char *utf8_label = get_utf8_string (label);
3318 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0; 3317 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0;
3319 3318
3320 if (! old_label && ! utf8_label) 3319 bool is_same = (!old_label == !utf8_label
3321 is_same = 1; 3320 && (!old_label || strcmp (utf8_label, old_label) == 0));
3322 else if (old_label && utf8_label)
3323 is_same = strcmp (utf8_label, old_label) == 0;
3324 3321
3325 if (utf8_label) g_free (utf8_label); 3322 if (utf8_label) g_free (utf8_label);
3326 3323
diff --git a/src/image.c b/src/image.c
index b62e7bcd2ef..8843852f71d 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1904,37 +1904,61 @@ which is then usually a filename. */)
1904} 1904}
1905 1905
1906static size_t 1906static size_t
1907image_frame_cache_size (struct frame *f) 1907image_size_in_bytes (struct image *img)
1908{ 1908{
1909 size_t total = 0; 1909 size_t size = 0;
1910
1910#if defined USE_CAIRO 1911#if defined USE_CAIRO
1911 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1912 Emacs_Pixmap pm = img->pixmap;
1913 if (pm)
1914 size += pm->height * pm->bytes_per_line;
1915 Emacs_Pixmap msk = img->mask;
1916 if (msk)
1917 size += msk->height * msk->bytes_per_line;
1912 1918
1913 if (!c) 1919#elif defined HAVE_X_WINDOWS
1914 return 0; 1920 /* Use a nominal depth of 24 bpp for pixmap and 1 bpp for mask,
1921 to avoid having to query the server. */
1922 if (img->pixmap != NO_PIXMAP)
1923 size += img->width * img->height * 3;
1924 if (img->mask != NO_PIXMAP)
1925 size += img->width * img->height / 8;
1926
1927 if (img->ximg && img->ximg->data)
1928 size += img->ximg->bytes_per_line * img->ximg->height;
1929 if (img->mask_img && img->mask_img->data)
1930 size += img->mask_img->bytes_per_line * img->mask_img->height;
1915 1931
1916 for (ptrdiff_t i = 0; i < c->used; ++i) 1932#elif defined HAVE_NS
1917 { 1933 if (img->pixmap)
1918 struct image *img = c->images[i]; 1934 size += ns_image_size_in_bytes (img->pixmap);
1935 if (img->mask)
1936 size += ns_image_size_in_bytes (img->mask);
1919 1937
1920 if (img && img->pixmap && img->pixmap != NO_PIXMAP)
1921 total += img->pixmap->width * img->pixmap->height *
1922 img->pixmap->bits_per_pixel / 8;
1923 }
1924#elif defined HAVE_NTGUI 1938#elif defined HAVE_NTGUI
1925 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1939 if (img->pixmap)
1940 size += w32_image_size (img->pixmap);
1941 if (img->mask)
1942 size += w32_image_size (img->mask);
1943
1944#endif
1945
1946 return size;
1947}
1926 1948
1949static size_t
1950image_frame_cache_size (struct frame *f)
1951{
1952 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1927 if (!c) 1953 if (!c)
1928 return 0; 1954 return 0;
1929 1955
1956 size_t total = 0;
1930 for (ptrdiff_t i = 0; i < c->used; ++i) 1957 for (ptrdiff_t i = 0; i < c->used; ++i)
1931 { 1958 {
1932 struct image *img = c->images[i]; 1959 struct image *img = c->images[i];
1933 1960 total += img ? image_size_in_bytes (img) : 0;
1934 if (img && img->pixmap && img->pixmap != NO_PIXMAP)
1935 total += w32_image_size (img);
1936 } 1961 }
1937#endif
1938 return total; 1962 return total;
1939} 1963}
1940 1964
@@ -2501,7 +2525,7 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id)
2501 2525
2502 /* Look up SPEC in the hash table of the image cache. */ 2526 /* Look up SPEC in the hash table of the image cache. */
2503 hash = sxhash (spec); 2527 hash = sxhash (spec);
2504 img = search_image_cache (f, spec, hash, foreground, background, true); 2528 img = search_image_cache (f, spec, hash, foreground, background, false);
2505 if (img && img->load_failed_p) 2529 if (img && img->load_failed_p)
2506 { 2530 {
2507 free_image (f, img); 2531 free_image (f, img);
@@ -9897,8 +9921,9 @@ svg_load (struct frame *f, struct image *img)
9897 } 9921 }
9898 /* If the file was slurped into memory properly, parse it. */ 9922 /* If the file was slurped into memory properly, parse it. */
9899 if (!STRINGP (base_uri)) 9923 if (!STRINGP (base_uri))
9900 base_uri = ENCODE_FILE (file); 9924 base_uri = file;
9901 success_p = svg_load_image (f, img, contents, size, SSDATA (base_uri)); 9925 success_p = svg_load_image (f, img, contents, size,
9926 SSDATA (ENCODE_FILE (base_uri)));
9902 xfree (contents); 9927 xfree (contents);
9903 } 9928 }
9904 /* Else it's not a file, it's a Lisp object. Load the image from a 9929 /* Else it's not a file, it's a Lisp object. Load the image from a
@@ -9916,7 +9941,8 @@ svg_load (struct frame *f, struct image *img)
9916 if (!STRINGP (base_uri)) 9941 if (!STRINGP (base_uri))
9917 base_uri = BVAR (current_buffer, filename); 9942 base_uri = BVAR (current_buffer, filename);
9918 success_p = svg_load_image (f, img, SSDATA (data), SBYTES (data), 9943 success_p = svg_load_image (f, img, SSDATA (data), SBYTES (data),
9919 (NILP (base_uri) ? NULL : SSDATA (base_uri))); 9944 (STRINGP (base_uri) ?
9945 SSDATA (ENCODE_FILE (base_uri)) : NULL));
9920 } 9946 }
9921 9947
9922 return success_p; 9948 return success_p;
diff --git a/src/lisp.h b/src/lisp.h
index e83304462fa..501bcd14a6f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4493,14 +4493,14 @@ extern void setup_process_coding_systems (Lisp_Object);
4493 4493
4494/* Defined in callproc.c. */ 4494/* Defined in callproc.c. */
4495#ifdef DOS_NT 4495#ifdef DOS_NT
4496# define CHILD_SETUP_TYPE int
4497# define CHILD_SETUP_ERROR_DESC "Spawning child process" 4496# define CHILD_SETUP_ERROR_DESC "Spawning child process"
4498#else 4497#else
4499# define CHILD_SETUP_TYPE _Noreturn void
4500# define CHILD_SETUP_ERROR_DESC "Doing vfork" 4498# define CHILD_SETUP_ERROR_DESC "Doing vfork"
4501#endif 4499#endif
4502 4500
4503extern CHILD_SETUP_TYPE child_setup (int, int, int, char **, bool, Lisp_Object); 4501extern int emacs_spawn (pid_t *, int, int, int, char **, char **, const char *,
4502 const char *);
4503extern char **make_environment_block (Lisp_Object);
4504extern void init_callproc_1 (void); 4504extern void init_callproc_1 (void);
4505extern void init_callproc (void); 4505extern void init_callproc (void);
4506extern void set_initial_environment (void); 4506extern void set_initial_environment (void);
diff --git a/src/minibuf.c b/src/minibuf.c
index fc3fd92a880..1940564a80a 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -809,7 +809,7 @@ get_minibuffer (EMACS_INT depth)
809 static char const name_fmt[] = " *Minibuf-%"pI"d*"; 809 static char const name_fmt[] = " *Minibuf-%"pI"d*";
810 char name[sizeof name_fmt + INT_STRLEN_BOUND (EMACS_INT)]; 810 char name[sizeof name_fmt + INT_STRLEN_BOUND (EMACS_INT)];
811 AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, depth)); 811 AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, depth));
812 buf = Fget_buffer_create (lname); 812 buf = Fget_buffer_create (lname, Qnil);
813 813
814 /* Although the buffer's name starts with a space, undo should be 814 /* Although the buffer's name starts with a space, undo should be
815 enabled in it. */ 815 enabled in it. */
diff --git a/src/nsfns.m b/src/nsfns.m
index c7956497c4c..f3c5a9ef679 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -456,7 +456,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
456static void 456static void
457ns_set_represented_filename (struct frame *f) 457ns_set_represented_filename (struct frame *f)
458{ 458{
459 Lisp_Object filename, encoded_filename; 459 Lisp_Object filename;
460 Lisp_Object buf = XWINDOW (f->selected_window)->contents; 460 Lisp_Object buf = XWINDOW (f->selected_window)->contents;
461 NSAutoreleasePool *pool; 461 NSAutoreleasePool *pool;
462 NSString *fstr; 462 NSString *fstr;
@@ -473,9 +473,7 @@ ns_set_represented_filename (struct frame *f)
473 473
474 if (! NILP (filename)) 474 if (! NILP (filename))
475 { 475 {
476 encoded_filename = ENCODE_UTF_8 (filename); 476 fstr = [NSString stringWithLispString:filename];
477
478 fstr = [NSString stringWithLispString:encoded_filename];
479 if (fstr == nil) fstr = @""; 477 if (fstr == nil) fstr = @"";
480 } 478 }
481 else 479 else
@@ -3012,7 +3010,7 @@ DEFUN ("ns-show-character-palette",
3012#endif 3010#endif
3013 3011
3014 3012
3015/* Whether N bytes at STR are in the [0,127] range. */ 3013/* Whether N bytes at STR are in the [1,127] range. */
3016static bool 3014static bool
3017all_nonzero_ascii (unsigned char *str, ptrdiff_t n) 3015all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
3018{ 3016{
diff --git a/src/nsfont.m b/src/nsfont.m
index 378a6408401..9e4caca9102 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -329,7 +329,7 @@ static NSString
329{ 329{
330 Lisp_Object script = assq_no_quit (XCAR (otf), Votf_script_alist); 330 Lisp_Object script = assq_no_quit (XCAR (otf), Votf_script_alist);
331 return CONSP (script) 331 return CONSP (script)
332 ? [NSString stringWithUTF8String: SSDATA (SYMBOL_NAME (XCDR ((script))))] 332 ? [NSString stringWithLispString: SYMBOL_NAME (XCDR ((script)))]
333 : @""; 333 : @"";
334} 334}
335 335
@@ -345,7 +345,7 @@ static NSString
345 if (!strncmp (SSDATA (r), reg, SBYTES (r))) 345 if (!strncmp (SSDATA (r), reg, SBYTES (r)))
346 { 346 {
347 script = XCDR (XCAR (rts)); 347 script = XCDR (XCAR (rts));
348 return [NSString stringWithUTF8String: SSDATA (SYMBOL_NAME (script))]; 348 return [NSString stringWithLispString: SYMBOL_NAME (script)];
349 } 349 }
350 rts = XCDR (rts); 350 rts = XCDR (rts);
351 } 351 }
@@ -370,8 +370,7 @@ static NSString
370 { 370 {
371 Lisp_Object key = XCAR (tmp), val = XCDR (tmp); 371 Lisp_Object key = XCAR (tmp), val = XCDR (tmp);
372 if (EQ (key, QCscript) && SYMBOLP (val)) 372 if (EQ (key, QCscript) && SYMBOLP (val))
373 return [NSString stringWithUTF8String: 373 return [NSString stringWithLispString: SYMBOL_NAME (val)];
374 SSDATA (SYMBOL_NAME (val))];
375 if (EQ (key, QClang) && SYMBOLP (val)) 374 if (EQ (key, QClang) && SYMBOLP (val))
376 return ns_lang_to_script (val); 375 return ns_lang_to_script (val);
377 if (EQ (key, QCotf) && CONSP (val) && SYMBOLP (XCAR (val))) 376 if (EQ (key, QCotf) && CONSP (val) && SYMBOLP (XCAR (val)))
diff --git a/src/nsimage.m b/src/nsimage.m
index da6f01cf6a3..c47a2b2d64a 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -235,6 +235,11 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
235 [(EmacsImage *)img setAlphaAtX: x Y: y to: a]; 235 [(EmacsImage *)img setAlphaAtX: x Y: y to: a];
236} 236}
237 237
238size_t
239ns_image_size_in_bytes (void *img)
240{
241 return [(EmacsImage *)img sizeInBytes];
242}
238 243
239/* ========================================================================== 244/* ==========================================================================
240 245
@@ -257,7 +262,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
257 found = ENCODE_FILE (found); 262 found = ENCODE_FILE (found);
258 263
259 image = [[EmacsImage alloc] initByReferencingFile: 264 image = [[EmacsImage alloc] initByReferencingFile:
260 [NSString stringWithUTF8String: SSDATA (found)]]; 265 [NSString stringWithLispString: found]];
261 266
262 image->bmRep = nil; 267 image->bmRep = nil;
263#ifdef NS_IMPL_COCOA 268#ifdef NS_IMPL_COCOA
@@ -273,7 +278,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
273 278
274 [image setSize: NSMakeSize([imgRep pixelsWide], [imgRep pixelsHigh])]; 279 [image setSize: NSMakeSize([imgRep pixelsWide], [imgRep pixelsHigh])];
275 280
276 [image setName: [NSString stringWithUTF8String: SSDATA (file)]]; 281 [image setName: [NSString stringWithLispString: file]];
277 282
278 return image; 283 return image;
279} 284}
@@ -610,5 +615,22 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
610 smoothing = s; 615 smoothing = s;
611} 616}
612 617
618/* Approximate allocated size of image in bytes. */
619- (size_t) sizeInBytes
620{
621 size_t bytes = 0;
622 NSImageRep *rep;
623 NSEnumerator *reps = [[self representations] objectEnumerator];
624 while ((rep = (NSImageRep *) [reps nextObject]))
625 {
626 if ([rep respondsToSelector: @selector (bytesPerRow)])
627 {
628 NSBitmapImageRep *bmr = (NSBitmapImageRep *) rep;
629 bytes += [bmr bytesPerRow] * [bmr numberOfPlanes] * [bmr pixelsHigh];
630 }
631 }
632 return bytes;
633}
634
613 635
614@end 636@end
diff --git a/src/nsmenu.m b/src/nsmenu.m
index a286a80da17..efad978316e 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -970,7 +970,7 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
970 } 970 }
971 971
972 pmenu = [[EmacsMenu alloc] initWithTitle: 972 pmenu = [[EmacsMenu alloc] initWithTitle:
973 [NSString stringWithUTF8String: SSDATA (title)]]; 973 [NSString stringWithLispString: title]];
974 [pmenu fillWithWidgetValue: first_wv->contents]; 974 [pmenu fillWithWidgetValue: first_wv->contents];
975 free_menubar_widget_value_tree (first_wv); 975 free_menubar_widget_value_tree (first_wv);
976 unbind_to (specpdl_count, Qnil); 976 unbind_to (specpdl_count, Qnil);
diff --git a/src/nsselect.m b/src/nsselect.m
index 7b1937f5d99..95fce4d0f78 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -58,7 +58,7 @@ symbol_to_nsstring (Lisp_Object sym)
58 if (EQ (sym, QPRIMARY)) return NXPrimaryPboard; 58 if (EQ (sym, QPRIMARY)) return NXPrimaryPboard;
59 if (EQ (sym, QSECONDARY)) return NXSecondaryPboard; 59 if (EQ (sym, QSECONDARY)) return NXSecondaryPboard;
60 if (EQ (sym, QTEXT)) return NSPasteboardTypeString; 60 if (EQ (sym, QTEXT)) return NSPasteboardTypeString;
61 return [NSString stringWithUTF8String: SSDATA (SYMBOL_NAME (sym))]; 61 return [NSString stringWithLispString: SYMBOL_NAME (sym)];
62} 62}
63 63
64static NSPasteboard * 64static NSPasteboard *
@@ -170,17 +170,12 @@ ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype)
170 } 170 }
171 else 171 else
172 { 172 {
173 char *utfStr;
174 NSString *type, *nsStr; 173 NSString *type, *nsStr;
175 NSEnumerator *tenum; 174 NSEnumerator *tenum;
176 175
177 CHECK_STRING (str); 176 CHECK_STRING (str);
178 177
179 utfStr = SSDATA (str); 178 nsStr = [NSString stringWithLispString: str];
180 nsStr = [[NSString alloc] initWithBytesNoCopy: utfStr
181 length: SBYTES (str)
182 encoding: NSUTF8StringEncoding
183 freeWhenDone: NO];
184 // FIXME: Why those 2 different code paths? 179 // FIXME: Why those 2 different code paths?
185 if (gtype == nil) 180 if (gtype == nil)
186 { 181 {
@@ -196,7 +191,6 @@ ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype)
196 eassert (gtype == NSPasteboardTypeString); 191 eassert (gtype == NSPasteboardTypeString);
197 [pb setString: nsStr forType: gtype]; 192 [pb setString: nsStr forType: gtype];
198 } 193 }
199 [nsStr release];
200 ns_store_pb_change_count (pb); 194 ns_store_pb_change_count (pb);
201 } 195 }
202} 196}
diff --git a/src/nsterm.h b/src/nsterm.h
index f292993d8f7..94472ec1070 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -666,6 +666,7 @@ typedef id instancetype;
666- (BOOL)setFrame: (unsigned int) index; 666- (BOOL)setFrame: (unsigned int) index;
667- (void)setTransform: (double[3][3]) m; 667- (void)setTransform: (double[3][3]) m;
668- (void)setSmoothing: (BOOL)s; 668- (void)setSmoothing: (BOOL)s;
669- (size_t)sizeInBytes;
669@end 670@end
670 671
671 672
@@ -1195,6 +1196,7 @@ extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1195 1196
1196extern int ns_display_pixel_height (struct ns_display_info *); 1197extern int ns_display_pixel_height (struct ns_display_info *);
1197extern int ns_display_pixel_width (struct ns_display_info *); 1198extern int ns_display_pixel_width (struct ns_display_info *);
1199extern size_t ns_image_size_in_bytes (void *img);
1198 1200
1199/* This in nsterm.m */ 1201/* This in nsterm.m */
1200extern float ns_antialias_threshold; 1202extern float ns_antialias_threshold;
diff --git a/src/nsterm.m b/src/nsterm.m
index 7972fa4dabb..2a117a07801 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5541,9 +5541,8 @@ ns_term_init (Lisp_Object display_name)
5541 /* There are 752 colors defined in rgb.txt. */ 5541 /* There are 752 colors defined in rgb.txt. */
5542 if ( cl == nil || [[cl allKeys] count] < 752) 5542 if ( cl == nil || [[cl allKeys] count] < 752)
5543 { 5543 {
5544 Lisp_Object color_file, color_map, color; 5544 Lisp_Object color_file, color_map, color, name;
5545 unsigned long c; 5545 unsigned long c;
5546 char *name;
5547 5546
5548 color_file = Fexpand_file_name (build_string ("rgb.txt"), 5547 color_file = Fexpand_file_name (build_string ("rgb.txt"),
5549 Fsymbol_value (intern ("data-directory"))); 5548 Fsymbol_value (intern ("data-directory")));
@@ -5556,14 +5555,14 @@ ns_term_init (Lisp_Object display_name)
5556 for ( ; CONSP (color_map); color_map = XCDR (color_map)) 5555 for ( ; CONSP (color_map); color_map = XCDR (color_map))
5557 { 5556 {
5558 color = XCAR (color_map); 5557 color = XCAR (color_map);
5559 name = SSDATA (XCAR (color)); 5558 name = XCAR (color);
5560 c = XFIXNUM (XCDR (color)); 5559 c = XFIXNUM (XCDR (color));
5561 [cl setColor: 5560 [cl setColor:
5562 [NSColor colorForEmacsRed: RED_FROM_ULONG (c) / 255.0 5561 [NSColor colorForEmacsRed: RED_FROM_ULONG (c) / 255.0
5563 green: GREEN_FROM_ULONG (c) / 255.0 5562 green: GREEN_FROM_ULONG (c) / 255.0
5564 blue: BLUE_FROM_ULONG (c) / 255.0 5563 blue: BLUE_FROM_ULONG (c) / 255.0
5565 alpha: 1.0] 5564 alpha: 1.0]
5566 forKey: [NSString stringWithUTF8String: name]]; 5565 forKey: [NSString stringWithLispString: name]];
5567 } 5566 }
5568 5567
5569 /* FIXME: Report any errors writing the color file below. */ 5568 /* FIXME: Report any errors writing the color file below. */
@@ -7619,8 +7618,7 @@ not_in_argv (NSString *arg)
7619 [self registerForDraggedTypes: ns_drag_types]; 7618 [self registerForDraggedTypes: ns_drag_types];
7620 7619
7621 tem = f->name; 7620 tem = f->name;
7622 name = [NSString stringWithUTF8String: 7621 name = NILP (tem) ? @"Emacs" : [NSString stringWithLispString:tem];
7623 NILP (tem) ? "Emacs" : SSDATA (tem)];
7624 [win setTitle: name]; 7622 [win setTitle: name];
7625 7623
7626 /* toolbar support */ 7624 /* toolbar support */
diff --git a/src/nsxwidget.m b/src/nsxwidget.m
index dbd4cb29a62..915fd8b59ce 100644
--- a/src/nsxwidget.m
+++ b/src/nsxwidget.m
@@ -296,8 +296,6 @@ static NSString *xwScript;
296 296
297/* Xwidget webkit commands. */ 297/* Xwidget webkit commands. */
298 298
299static Lisp_Object build_string_with_nsstr (NSString *nsstr);
300
301bool 299bool
302nsxwidget_is_web_view (struct xwidget *xw) 300nsxwidget_is_web_view (struct xwidget *xw)
303{ 301{
@@ -309,14 +307,14 @@ Lisp_Object
309nsxwidget_webkit_uri (struct xwidget *xw) 307nsxwidget_webkit_uri (struct xwidget *xw)
310{ 308{
311 XwWebView *xwWebView = (XwWebView *) xw->xwWidget; 309 XwWebView *xwWebView = (XwWebView *) xw->xwWidget;
312 return build_string_with_nsstr (xwWebView.URL.absoluteString); 310 return [xwWebView.URL.absoluteString lispString];
313} 311}
314 312
315Lisp_Object 313Lisp_Object
316nsxwidget_webkit_title (struct xwidget *xw) 314nsxwidget_webkit_title (struct xwidget *xw)
317{ 315{
318 XwWebView *xwWebView = (XwWebView *) xw->xwWidget; 316 XwWebView *xwWebView = (XwWebView *) xw->xwWidget;
319 return build_string_with_nsstr (xwWebView.title); 317 return [xwWebView.title lispString];
320} 318}
321 319
322/* @Note ATS - Need application transport security in 'Info.plist' or 320/* @Note ATS - Need application transport security in 'Info.plist' or
@@ -350,15 +348,6 @@ nsxwidget_webkit_zoom (struct xwidget *xw, double zoom_change)
350 /* TODO: setMagnification:centeredAtPoint. */ 348 /* TODO: setMagnification:centeredAtPoint. */
351} 349}
352 350
353/* Build lisp string */
354static Lisp_Object
355build_string_with_nsstr (NSString *nsstr)
356{
357 const char *utfstr = [nsstr UTF8String];
358 NSUInteger bytes = [nsstr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
359 return make_string (utfstr, bytes);
360}
361
362/* Recursively convert an objc native type JavaScript value to a Lisp 351/* Recursively convert an objc native type JavaScript value to a Lisp
363 value. Mostly copied from GTK xwidget 'webkit_js_to_lisp'. */ 352 value. Mostly copied from GTK xwidget 'webkit_js_to_lisp'. */
364static Lisp_Object 353static Lisp_Object
@@ -367,7 +356,7 @@ js_to_lisp (id value)
367 if (value == nil || [value isKindOfClass:NSNull.class]) 356 if (value == nil || [value isKindOfClass:NSNull.class])
368 return Qnil; 357 return Qnil;
369 else if ([value isKindOfClass:NSString.class]) 358 else if ([value isKindOfClass:NSString.class])
370 return build_string_with_nsstr ((NSString *) value); 359 return [(NSString *) value lispString];
371 else if ([value isKindOfClass:NSNumber.class]) 360 else if ([value isKindOfClass:NSNumber.class])
372 { 361 {
373 NSNumber *nsnum = (NSNumber *) value; 362 NSNumber *nsnum = (NSNumber *) value;
@@ -407,7 +396,7 @@ js_to_lisp (id value)
407 { 396 {
408 NSString *prop_key = (NSString *) [keys objectAtIndex:i]; 397 NSString *prop_key = (NSString *) [keys objectAtIndex:i];
409 id prop_value = [nsdict valueForKey:prop_key]; 398 id prop_value = [nsdict valueForKey:prop_key];
410 p->contents[i] = Fcons (build_string_with_nsstr (prop_key), 399 p->contents[i] = Fcons ([prop_key lispString],
411 js_to_lisp (prop_value)); 400 js_to_lisp (prop_value));
412 } 401 }
413 XSETVECTOR (obj, p); 402 XSETVECTOR (obj, p);
diff --git a/src/pdumper.c b/src/pdumper.c
index 0096a4d45a3..f31e5888970 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2692,7 +2692,7 @@ dump_hash_table (struct dump_context *ctx,
2692static dump_off 2692static dump_off
2693dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer) 2693dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
2694{ 2694{
2695#if CHECK_STRUCTS && !defined HASH_buffer_EE36B4292E 2695#if CHECK_STRUCTS && !defined HASH_buffer_99D642C1CB
2696# error "buffer changed. See CHECK_STRUCTS comment in config.h." 2696# error "buffer changed. See CHECK_STRUCTS comment in config.h."
2697#endif 2697#endif
2698 struct buffer munged_buffer = *in_buffer; 2698 struct buffer munged_buffer = *in_buffer;
diff --git a/src/print.c b/src/print.c
index 008bf5e6391..ec271d914cc 100644
--- a/src/print.c
+++ b/src/print.c
@@ -562,7 +562,7 @@ temp_output_buffer_setup (const char *bufname)
562 562
563 record_unwind_current_buffer (); 563 record_unwind_current_buffer ();
564 564
565 Fset_buffer (Fget_buffer_create (build_string (bufname))); 565 Fset_buffer (Fget_buffer_create (build_string (bufname), Qnil));
566 566
567 Fkill_all_local_variables (); 567 Fkill_all_local_variables ();
568 delete_all_overlays (current_buffer); 568 delete_all_overlays (current_buffer);
diff --git a/src/process.c b/src/process.c
index b2d94d8f8a8..c306e6bbdd3 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1731,7 +1731,7 @@ usage: (make-process &rest ARGS) */)
1731 1731
1732 buffer = Fplist_get (contact, QCbuffer); 1732 buffer = Fplist_get (contact, QCbuffer);
1733 if (!NILP (buffer)) 1733 if (!NILP (buffer))
1734 buffer = Fget_buffer_create (buffer); 1734 buffer = Fget_buffer_create (buffer, Qnil);
1735 1735
1736 /* Make sure that the child will be able to chdir to the current 1736 /* Make sure that the child will be able to chdir to the current
1737 buffer's current directory, or its unhandled equivalent. We 1737 buffer's current directory, or its unhandled equivalent. We
@@ -1768,7 +1768,7 @@ usage: (make-process &rest ARGS) */)
1768 QCname, 1768 QCname,
1769 concat2 (name, build_string (" stderr")), 1769 concat2 (name, build_string (" stderr")),
1770 QCbuffer, 1770 QCbuffer,
1771 Fget_buffer_create (xstderr), 1771 Fget_buffer_create (xstderr, Qnil),
1772 QCnoquery, 1772 QCnoquery,
1773 query_on_exit ? Qnil : Qt); 1773 query_on_exit ? Qnil : Qt);
1774 } 1774 }
@@ -2047,13 +2047,12 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2047{ 2047{
2048 struct Lisp_Process *p = XPROCESS (process); 2048 struct Lisp_Process *p = XPROCESS (process);
2049 int inchannel, outchannel; 2049 int inchannel, outchannel;
2050 pid_t pid; 2050 pid_t pid = -1;
2051 int vfork_errno; 2051 int vfork_errno;
2052 int forkin, forkout, forkerr = -1; 2052 int forkin, forkout, forkerr = -1;
2053 bool pty_flag = 0; 2053 bool pty_flag = 0;
2054 char pty_name[PTY_NAME_SIZE]; 2054 char pty_name[PTY_NAME_SIZE];
2055 Lisp_Object lisp_pty_name = Qnil; 2055 Lisp_Object lisp_pty_name = Qnil;
2056 sigset_t oldset;
2057 2056
2058 inchannel = outchannel = -1; 2057 inchannel = outchannel = -1;
2059 2058
@@ -2124,152 +2123,28 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2124 if (!EQ (p->command, Qt)) 2123 if (!EQ (p->command, Qt))
2125 add_process_read_fd (inchannel); 2124 add_process_read_fd (inchannel);
2126 2125
2126 ptrdiff_t count = SPECPDL_INDEX ();
2127
2127 /* This may signal an error. */ 2128 /* This may signal an error. */
2128 setup_process_coding_systems (process); 2129 setup_process_coding_systems (process);
2129 2130 char **env = make_environment_block (current_dir);
2130 block_input ();
2131 block_child_signal (&oldset);
2132
2133#ifndef WINDOWSNT
2134 /* vfork, and prevent local vars from being clobbered by the vfork. */
2135 Lisp_Object volatile current_dir_volatile = current_dir;
2136 Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name;
2137 char **volatile new_argv_volatile = new_argv;
2138 int volatile forkin_volatile = forkin;
2139 int volatile forkout_volatile = forkout;
2140 int volatile forkerr_volatile = forkerr;
2141 struct Lisp_Process *p_volatile = p;
2142
2143#ifdef DARWIN_OS
2144 /* Darwin doesn't let us run setsid after a vfork, so use fork when
2145 necessary. Also, reset SIGCHLD handling after a vfork, as
2146 apparently macOS can mistakenly deliver SIGCHLD to the child. */
2147 if (pty_flag)
2148 pid = fork ();
2149 else
2150 {
2151 pid = vfork ();
2152 if (pid == 0)
2153 signal (SIGCHLD, SIG_DFL);
2154 }
2155#else
2156 pid = vfork ();
2157#endif
2158
2159 current_dir = current_dir_volatile;
2160 lisp_pty_name = lisp_pty_name_volatile;
2161 new_argv = new_argv_volatile;
2162 forkin = forkin_volatile;
2163 forkout = forkout_volatile;
2164 forkerr = forkerr_volatile;
2165 p = p_volatile;
2166 2131
2167 pty_flag = p->pty_flag; 2132 pty_flag = p->pty_flag;
2133 eassert (pty_flag == ! NILP (lisp_pty_name));
2168 2134
2169 if (pid == 0) 2135 vfork_errno
2170#endif /* not WINDOWSNT */ 2136 = emacs_spawn (&pid, forkin, forkout, forkerr, new_argv, env,
2171 { 2137 SSDATA (current_dir),
2172 /* Make the pty be the controlling terminal of the process. */ 2138 pty_flag ? SSDATA (lisp_pty_name) : NULL);
2173#ifdef HAVE_PTYS
2174 dissociate_controlling_tty ();
2175
2176 /* Make the pty's terminal the controlling terminal. */
2177 if (pty_flag && forkin >= 0)
2178 {
2179#ifdef TIOCSCTTY
2180 /* We ignore the return value
2181 because faith@cs.unc.edu says that is necessary on Linux. */
2182 ioctl (forkin, TIOCSCTTY, 0);
2183#endif
2184 }
2185#if defined (LDISC1)
2186 if (pty_flag && forkin >= 0)
2187 {
2188 struct termios t;
2189 tcgetattr (forkin, &t);
2190 t.c_lflag = LDISC1;
2191 if (tcsetattr (forkin, TCSANOW, &t) < 0)
2192 emacs_perror ("create_process/tcsetattr LDISC1");
2193 }
2194#else
2195#if defined (NTTYDISC) && defined (TIOCSETD)
2196 if (pty_flag && forkin >= 0)
2197 {
2198 /* Use new line discipline. */
2199 int ldisc = NTTYDISC;
2200 ioctl (forkin, TIOCSETD, &ldisc);
2201 }
2202#endif
2203#endif
2204 2139
2205#if !defined (DONT_REOPEN_PTY) 2140 eassert ((vfork_errno == 0) == (0 < pid));
2206/*** There is a suggestion that this ought to be a
2207 conditional on TIOCSPGRP, or !defined TIOCSCTTY.
2208 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
2209 that system does seem to need this code, even though
2210 both TIOCSCTTY is defined. */
2211 /* Now close the pty (if we had it open) and reopen it.
2212 This makes the pty the controlling terminal of the subprocess. */
2213 if (pty_flag)
2214 {
2215 2141
2216 /* I wonder if emacs_close (emacs_open (SSDATA (lisp_pty_name), ...))
2217 would work? */
2218 if (forkin >= 0)
2219 emacs_close (forkin);
2220 forkout = forkin = emacs_open (SSDATA (lisp_pty_name), O_RDWR, 0);
2221
2222 if (forkin < 0)
2223 {
2224 emacs_perror (SSDATA (lisp_pty_name));
2225 _exit (EXIT_CANCELED);
2226 }
2227
2228 }
2229#endif /* not DONT_REOPEN_PTY */
2230
2231#ifdef SETUP_SLAVE_PTY
2232 if (pty_flag)
2233 {
2234 SETUP_SLAVE_PTY;
2235 }
2236#endif /* SETUP_SLAVE_PTY */
2237#endif /* HAVE_PTYS */
2238
2239 signal (SIGINT, SIG_DFL);
2240 signal (SIGQUIT, SIG_DFL);
2241#ifdef SIGPROF
2242 signal (SIGPROF, SIG_DFL);
2243#endif
2244
2245 /* Emacs ignores SIGPIPE, but the child should not. */
2246 signal (SIGPIPE, SIG_DFL);
2247
2248 /* Stop blocking SIGCHLD in the child. */
2249 unblock_child_signal (&oldset);
2250
2251 if (pty_flag)
2252 child_setup_tty (forkout);
2253
2254 if (forkerr < 0)
2255 forkerr = forkout;
2256#ifdef WINDOWSNT
2257 pid = child_setup (forkin, forkout, forkerr, new_argv, 1, current_dir);
2258#else /* not WINDOWSNT */
2259 child_setup (forkin, forkout, forkerr, new_argv, 1, current_dir);
2260#endif /* not WINDOWSNT */
2261 }
2262
2263 /* Back in the parent process. */
2264
2265 vfork_errno = errno;
2266 p->pid = pid; 2142 p->pid = pid;
2267 if (pid >= 0) 2143 if (pid >= 0)
2268 p->alive = 1; 2144 p->alive = 1;
2269 2145
2270 /* Stop blocking in the parent. */ 2146 /* Environment block no longer needed. */
2271 unblock_child_signal (&oldset); 2147 unbind_to (count, Qnil);
2272 unblock_input ();
2273 2148
2274 if (pid < 0) 2149 if (pid < 0)
2275 report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, vfork_errno); 2150 report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, vfork_errno);
@@ -2443,7 +2318,7 @@ usage: (make-pipe-process &rest ARGS) */)
2443 buffer = Fplist_get (contact, QCbuffer); 2318 buffer = Fplist_get (contact, QCbuffer);
2444 if (NILP (buffer)) 2319 if (NILP (buffer))
2445 buffer = name; 2320 buffer = name;
2446 buffer = Fget_buffer_create (buffer); 2321 buffer = Fget_buffer_create (buffer, Qnil);
2447 pset_buffer (p, buffer); 2322 pset_buffer (p, buffer);
2448 2323
2449 pset_childp (p, contact); 2324 pset_childp (p, contact);
@@ -3173,7 +3048,7 @@ usage: (make-serial-process &rest ARGS) */)
3173 buffer = Fplist_get (contact, QCbuffer); 3048 buffer = Fplist_get (contact, QCbuffer);
3174 if (NILP (buffer)) 3049 if (NILP (buffer))
3175 buffer = name; 3050 buffer = name;
3176 buffer = Fget_buffer_create (buffer); 3051 buffer = Fget_buffer_create (buffer, Qnil);
3177 pset_buffer (p, buffer); 3052 pset_buffer (p, buffer);
3178 3053
3179 pset_childp (p, contact); 3054 pset_childp (p, contact);
@@ -4188,7 +4063,7 @@ usage: (make-network-process &rest ARGS) */)
4188 open_socket: 4063 open_socket:
4189 4064
4190 if (!NILP (buffer)) 4065 if (!NILP (buffer))
4191 buffer = Fget_buffer_create (buffer); 4066 buffer = Fget_buffer_create (buffer, Qnil);
4192 4067
4193 /* Unwind bind_polling_period. */ 4068 /* Unwind bind_polling_period. */
4194 unbind_to (count, Qnil); 4069 unbind_to (count, Qnil);
@@ -4637,6 +4512,12 @@ network_lookup_address_info_1 (Lisp_Object host, const char *service,
4637 if (STRING_MULTIBYTE (host) && SBYTES (host) != SCHARS (host)) 4512 if (STRING_MULTIBYTE (host) && SBYTES (host) != SCHARS (host))
4638 error ("Non-ASCII hostname %s detected, please use puny-encode-domain", 4513 error ("Non-ASCII hostname %s detected, please use puny-encode-domain",
4639 SSDATA (host)); 4514 SSDATA (host));
4515
4516#ifdef WINDOWSNT
4517 /* Ensure socket support is loaded if available. */
4518 init_winsock (TRUE);
4519#endif
4520
4640 ret = getaddrinfo (SSDATA (host), service, hints, res); 4521 ret = getaddrinfo (SSDATA (host), service, hints, res);
4641 if (ret) 4522 if (ret)
4642 { 4523 {
@@ -4961,7 +4842,7 @@ server_accept_connection (Lisp_Object server, int channel)
4961 if (!NILP (buffer)) 4842 if (!NILP (buffer))
4962 { 4843 {
4963 args[1] = buffer; 4844 args[1] = buffer;
4964 buffer = Fget_buffer_create (Fformat (nargs, args)); 4845 buffer = Fget_buffer_create (Fformat (nargs, args), Qnil);
4965 } 4846 }
4966 } 4847 }
4967 4848
diff --git a/src/sysdep.c b/src/sysdep.c
index 29c88f5308e..eeb9d184940 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -314,33 +314,21 @@ get_current_dir_name_or_unreachable (void)
314 && emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0 314 && emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0
315 && dotstat.st_ino == pwdstat.st_ino 315 && dotstat.st_ino == pwdstat.st_ino
316 && dotstat.st_dev == pwdstat.st_dev) 316 && dotstat.st_dev == pwdstat.st_dev)
317 { 317 return strdup (pwd);
318 char *buf = malloc (pwdlen + 1);
319 if (!buf)
320 return NULL;
321 return memcpy (buf, pwd, pwdlen + 1);
322 }
323 else 318 else
324 { 319 {
325 ptrdiff_t buf_size = min (bufsize_max, 1024); 320 ptrdiff_t buf_size = min (bufsize_max, 1024);
326 char *buf = malloc (buf_size);
327 if (!buf)
328 return NULL;
329 for (;;) 321 for (;;)
330 { 322 {
323 char *buf = malloc (buf_size);
324 if (!buf)
325 return NULL;
331 if (getcwd (buf, buf_size) == buf) 326 if (getcwd (buf, buf_size) == buf)
332 return buf; 327 return buf;
333 int getcwd_errno = errno; 328 free (buf);
334 if (getcwd_errno != ERANGE || buf_size == bufsize_max) 329 if (errno != ERANGE || buf_size == bufsize_max)
335 { 330 return NULL;
336 free (buf);
337 errno = getcwd_errno;
338 return NULL;
339 }
340 buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; 331 buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max;
341 buf = realloc (buf, buf_size);
342 if (!buf)
343 return NULL;
344 } 332 }
345 } 333 }
346} 334}
diff --git a/src/w32.h b/src/w32.h
index 1afb8ad0873..e23ea6a675d 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -216,7 +216,7 @@ extern int sys_rename_replace (char const *, char const *, BOOL);
216extern int pipe2 (int *, int); 216extern int pipe2 (int *, int);
217extern void register_aux_fd (int); 217extern void register_aux_fd (int);
218 218
219extern void set_process_dir (char *); 219extern void set_process_dir (const char *);
220extern int sys_spawnve (int, char *, char **, char **); 220extern int sys_spawnve (int, char *, char **, char **);
221extern void register_child (pid_t, int); 221extern void register_child (pid_t, int);
222 222
diff --git a/src/w32fns.c b/src/w32fns.c
index a840f0e1227..36bee0676ba 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -7372,7 +7372,7 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
7372 7372
7373 tip_f = XFRAME (tip_frame); 7373 tip_f = XFRAME (tip_frame);
7374 window = FRAME_ROOT_WINDOW (tip_f); 7374 window = FRAME_ROOT_WINDOW (tip_f);
7375 tip_buf = Fget_buffer_create (tip); 7375 tip_buf = Fget_buffer_create (tip, Qnil);
7376 /* We will mark the tip window a "pseudo-window" below, and such 7376 /* We will mark the tip window a "pseudo-window" below, and such
7377 windows cannot have display margins. */ 7377 windows cannot have display margins. */
7378 bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0)); 7378 bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
diff --git a/src/w32gui.h b/src/w32gui.h
index fc8131130fb..f6cfa9fb87e 100644
--- a/src/w32gui.h
+++ b/src/w32gui.h
@@ -46,7 +46,7 @@ extern int w32_load_image (struct frame *f, struct image *img,
46 Lisp_Object spec_file, Lisp_Object spec_data); 46 Lisp_Object spec_file, Lisp_Object spec_data);
47extern bool w32_can_use_native_image_api (Lisp_Object); 47extern bool w32_can_use_native_image_api (Lisp_Object);
48extern void w32_gdiplus_shutdown (void); 48extern void w32_gdiplus_shutdown (void);
49extern size_t w32_image_size (struct image *); 49extern size_t w32_image_size (Emacs_Pixmap);
50 50
51#define FACE_DEFAULT (~0) 51#define FACE_DEFAULT (~0)
52 52
diff --git a/src/w32proc.c b/src/w32proc.c
index 0cf82013065..66cdf7de461 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -3019,9 +3019,9 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[3])
3019} 3019}
3020 3020
3021void 3021void
3022set_process_dir (char * dir) 3022set_process_dir (const char * dir)
3023{ 3023{
3024 process_dir = dir; 3024 process_dir = (char *) dir;
3025} 3025}
3026 3026
3027/* To avoid problems with winsock implementations that work over dial-up 3027/* To avoid problems with winsock implementations that work over dial-up
diff --git a/src/w32term.c b/src/w32term.c
index a038e4593f4..989b056ff2e 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1992,12 +1992,12 @@ w32_draw_image_foreground (struct glyph_string *s)
1992} 1992}
1993 1993
1994size_t 1994size_t
1995w32_image_size (struct image *img) 1995w32_image_size (Emacs_Pixmap pixmap)
1996{ 1996{
1997 BITMAP bm_info; 1997 BITMAP bm_info;
1998 size_t rv = 0; 1998 size_t rv = 0;
1999 1999
2000 if (GetObject (img->pixmap, sizeof (BITMAP), &bm_info)) 2000 if (GetObject (pixmap, sizeof (BITMAP), &bm_info))
2001 rv = bm_info.bmWidth * bm_info.bmHeight * bm_info.bmBitsPixel / 8; 2001 rv = bm_info.bmWidth * bm_info.bmHeight * bm_info.bmBitsPixel / 8;
2002 return rv; 2002 return rv;
2003} 2003}
diff --git a/src/window.c b/src/window.c
index bcc989b5a79..5db166e345e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -617,11 +617,12 @@ equals the special symbol `mark-for-redisplay'.
617Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that 617Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
618applications and internal routines often select a window temporarily for 618applications and internal routines often select a window temporarily for
619various purposes; mostly, to simplify coding. As a rule, such 619various purposes; mostly, to simplify coding. As a rule, such
620selections should be not recorded and therefore will not pollute 620selections should not be recorded and therefore will not pollute
621`buffer-list-update-hook'. Selections that "really count" are those 621`buffer-list-update-hook'. Selections that "really count" are those
622causing a visible change in the next redisplay of WINDOW's frame and 622causing a visible change in the next redisplay of WINDOW's frame and
623should be always recorded. So if you think of running a function each 623should always be recorded. So if you think of running a function each
624time a window gets selected put it on `buffer-list-update-hook'. 624time a window gets selected, put it on `buffer-list-update-hook' or
625`window-selection-change-functions'.
625 626
626Also note that the main editor command loop sets the current buffer to 627Also note that the main editor command loop sets the current buffer to
627the buffer of the selected window before each command. */) 628the buffer of the selected window before each command. */)
diff --git a/src/xdisp.c b/src/xdisp.c
index 5533c82d143..c28a5cf5188 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10880,7 +10880,7 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte)
10880 /* Ensure the Messages buffer exists, and switch to it. 10880 /* Ensure the Messages buffer exists, and switch to it.
10881 If we created it, set the major-mode. */ 10881 If we created it, set the major-mode. */
10882 bool newbuffer = NILP (Fget_buffer (Vmessages_buffer_name)); 10882 bool newbuffer = NILP (Fget_buffer (Vmessages_buffer_name));
10883 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name)); 10883 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name, Qnil));
10884 if (newbuffer 10884 if (newbuffer
10885 && !NILP (Ffboundp (intern ("messages-buffer-mode")))) 10885 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
10886 call0 (intern ("messages-buffer-mode")); 10886 call0 (intern ("messages-buffer-mode"));
@@ -11366,7 +11366,7 @@ ensure_echo_area_buffers (void)
11366 static char const name_fmt[] = " *Echo Area %d*"; 11366 static char const name_fmt[] = " *Echo Area %d*";
11367 char name[sizeof name_fmt + INT_STRLEN_BOUND (int)]; 11367 char name[sizeof name_fmt + INT_STRLEN_BOUND (int)];
11368 AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, i)); 11368 AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, i));
11369 echo_buffer[i] = Fget_buffer_create (lname); 11369 echo_buffer[i] = Fget_buffer_create (lname, Qnil);
11370 bset_truncate_lines (XBUFFER (echo_buffer[i]), Qnil); 11370 bset_truncate_lines (XBUFFER (echo_buffer[i]), Qnil);
11371 /* to force word wrap in echo area - 11371 /* to force word wrap in echo area -
11372 it was decided to postpone this*/ 11372 it was decided to postpone this*/
diff --git a/src/xfns.c b/src/xfns.c
index 46e4bd73a6b..abe293e903e 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -7041,7 +7041,7 @@ Text larger than the specified size is clipped. */)
7041 7041
7042 tip_f = XFRAME (tip_frame); 7042 tip_f = XFRAME (tip_frame);
7043 window = FRAME_ROOT_WINDOW (tip_f); 7043 window = FRAME_ROOT_WINDOW (tip_f);
7044 tip_buf = Fget_buffer_create (tip); 7044 tip_buf = Fget_buffer_create (tip, Qnil);
7045 /* We will mark the tip window a "pseudo-window" below, and such 7045 /* We will mark the tip window a "pseudo-window" below, and such
7046 windows cannot have display margins. */ 7046 windows cannot have display margins. */
7047 bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0)); 7047 bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
diff --git a/src/xterm.c b/src/xterm.c
index 3de0d2e73c0..7f8728e47c4 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -8947,7 +8947,9 @@ handle_one_xevent (struct x_display_info *dpyinfo,
8947 if (!f 8947 if (!f
8948 && (f = any) 8948 && (f = any)
8949 && configureEvent.xconfigure.window == FRAME_X_WINDOW (f) 8949 && configureEvent.xconfigure.window == FRAME_X_WINDOW (f)
8950 && FRAME_VISIBLE_P(f)) 8950 && (FRAME_VISIBLE_P(f)
8951 || !(configureEvent.xconfigure.width <= 1
8952 && configureEvent.xconfigure.height <= 1)))
8951 { 8953 {
8952 block_input (); 8954 block_input ();
8953 if (FRAME_X_DOUBLE_BUFFERED_P (f)) 8955 if (FRAME_X_DOUBLE_BUFFERED_P (f))
@@ -8962,7 +8964,10 @@ handle_one_xevent (struct x_display_info *dpyinfo,
8962 f = 0; 8964 f = 0;
8963 } 8965 }
8964#endif 8966#endif
8965 if (f && FRAME_VISIBLE_P(f)) 8967 if (f
8968 && (FRAME_VISIBLE_P(f)
8969 || !(configureEvent.xconfigure.width <= 1
8970 && configureEvent.xconfigure.height <= 1)))
8966 { 8971 {
8967#ifdef USE_GTK 8972#ifdef USE_GTK
8968 /* For GTK+ don't call x_net_wm_state for the scroll bar 8973 /* For GTK+ don't call x_net_wm_state for the scroll bar
diff --git a/src/xwidget.c b/src/xwidget.c
index 893292cf5ae..44ca0424d50 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -100,7 +100,8 @@ Returns the newly constructed xwidget, or nil if construction fails. */)
100 Lisp_Object val; 100 Lisp_Object val;
101 xw->type = type; 101 xw->type = type;
102 xw->title = title; 102 xw->title = title;
103 xw->buffer = NILP (buffer) ? Fcurrent_buffer () : Fget_buffer_create (buffer); 103 xw->buffer = (NILP (buffer) ? Fcurrent_buffer ()
104 : Fget_buffer_create (buffer, Qnil));
104 xw->height = XFIXNAT (height); 105 xw->height = XFIXNAT (height);
105 xw->width = XFIXNAT (width); 106 xw->width = XFIXNAT (width);
106 xw->kill_without_query = false; 107 xw->kill_without_query = false;