aboutsummaryrefslogtreecommitdiffstats
path: root/src/emacs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emacs.c')
-rw-r--r--src/emacs.c122
1 files changed, 75 insertions, 47 deletions
diff --git a/src/emacs.c b/src/emacs.c
index c1d517900ca..0e77223ee00 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1,6 +1,6 @@
1/* Fully extensible Emacs, running on Unix, intended for GNU. 1/* Fully extensible Emacs, running on Unix, intended for GNU.
2 2
3Copyright (C) 1985-1987, 1993-1995, 1997-1999, 2001-2011 3Copyright (C) 1985-1987, 1993-1995, 1997-1999, 2001-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -82,6 +82,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
82#include <sys/personality.h> 82#include <sys/personality.h>
83#endif 83#endif
84 84
85#ifdef HAVE_LIBXML2
86#include <libxml/parser.h>
87#endif
88
85#ifndef O_RDWR 89#ifndef O_RDWR
86#define O_RDWR 2 90#define O_RDWR 2
87#endif 91#endif
@@ -94,7 +98,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
94#endif 98#endif
95 99
96static const char emacs_version[] = VERSION; 100static const char emacs_version[] = VERSION;
97static const char emacs_copyright[] = "Copyright (C) 2011 Free Software Foundation, Inc."; 101static const char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc.";
98 102
99/* Make these values available in GDB, which doesn't see macros. */ 103/* Make these values available in GDB, which doesn't see macros. */
100 104
@@ -150,6 +154,8 @@ Lisp_Object Qfile_name_handler_alist;
150 154
151Lisp_Object Qrisky_local_variable; 155Lisp_Object Qrisky_local_variable;
152 156
157Lisp_Object Qkill_emacs;
158
153/* If non-zero, Emacs should not attempt to use a window-specific code, 159/* If non-zero, Emacs should not attempt to use a window-specific code,
154 but instead should use the virtual terminal under which it was started. */ 160 but instead should use the virtual terminal under which it was started. */
155int inhibit_window_system; 161int inhibit_window_system;
@@ -158,7 +164,7 @@ int inhibit_window_system;
158 data on the first attempt to change it inside asynchronous code. */ 164 data on the first attempt to change it inside asynchronous code. */
159int running_asynch_code; 165int running_asynch_code;
160 166
161#if defined(HAVE_X_WINDOWS) || defined(HAVE_NS) 167#if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
162/* If non-zero, -d was specified, meaning we're using some window system. */ 168/* If non-zero, -d was specified, meaning we're using some window system. */
163int display_arg; 169int display_arg;
164#endif 170#endif
@@ -167,11 +173,15 @@ int display_arg;
167 Tells GC how to save a copy of the stack. */ 173 Tells GC how to save a copy of the stack. */
168char *stack_bottom; 174char *stack_bottom;
169 175
176#if defined (DOUG_LEA_MALLOC) || defined (GNU_LINUX)
170/* The address where the heap starts (from the first sbrk (0) call). */ 177/* The address where the heap starts (from the first sbrk (0) call). */
171static void *my_heap_start; 178static void *my_heap_start;
179#endif
172 180
181#ifdef GNU_LINUX
173/* The gap between BSS end and heap start as far as we can tell. */ 182/* The gap between BSS end and heap start as far as we can tell. */
174static unsigned long heap_bss_diff; 183static uprintmax_t heap_bss_diff;
184#endif
175 185
176/* Nonzero means running Emacs without interactive terminal. */ 186/* Nonzero means running Emacs without interactive terminal. */
177int noninteractive; 187int noninteractive;
@@ -311,6 +321,12 @@ static void (*fatal_error_signal_hook) (void);
311pthread_t main_thread; 321pthread_t main_thread;
312#endif 322#endif
313 323
324#ifdef HAVE_NS
325/* NS autrelease pool, for memory management. */
326static void *ns_pool;
327#endif
328
329
314 330
315/* Handle bus errors, invalid instruction, etc. */ 331/* Handle bus errors, invalid instruction, etc. */
316#ifndef FLOAT_CATCH_SIGILL 332#ifndef FLOAT_CATCH_SIGILL
@@ -354,8 +370,7 @@ fatal_error_signal (int sig)
354 370
355/* Handler for SIGDANGER. */ 371/* Handler for SIGDANGER. */
356void 372void
357memory_warning_signal (sig) 373memory_warning_signal (int sig)
358 int sig;
359{ 374{
360 signal (sig, memory_warning_signal); 375 signal (sig, memory_warning_signal);
361 SIGNAL_THREAD_CHECK (sig); 376 SIGNAL_THREAD_CHECK (sig);
@@ -717,6 +732,7 @@ main (int argc, char **argv)
717 setenv ("G_SLICE", "always-malloc", 1); 732 setenv ("G_SLICE", "always-malloc", 1);
718#endif 733#endif
719 734
735#ifdef GNU_LINUX
720 if (!initialized) 736 if (!initialized)
721 { 737 {
722 extern char my_endbss[]; 738 extern char my_endbss[];
@@ -727,6 +743,7 @@ main (int argc, char **argv)
727 743
728 heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static); 744 heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static);
729 } 745 }
746#endif
730 747
731#ifdef RUN_TIME_REMAP 748#ifdef RUN_TIME_REMAP
732 if (initialized) 749 if (initialized)
@@ -799,7 +816,7 @@ main (int argc, char **argv)
799 { 816 {
800 static char heapexec[] = "EMACS_HEAP_EXEC=true"; 817 static char heapexec[] = "EMACS_HEAP_EXEC=true";
801 /* Set this so we only do this once. */ 818 /* Set this so we only do this once. */
802 putenv(heapexec); 819 putenv (heapexec);
803 820
804 /* A flag to turn off address randomization which is introduced 821 /* A flag to turn off address randomization which is introduced
805 in linux kernel shipped with fedora core 4 */ 822 in linux kernel shipped with fedora core 4 */
@@ -839,7 +856,7 @@ main (int argc, char **argv)
839 stack allocation routine for new process that the allocation 856 stack allocation routine for new process that the allocation
840 fails if stack limit is not on page boundary. So, round up the 857 fails if stack limit is not on page boundary. So, round up the
841 new limit to page boundary. */ 858 new limit to page boundary. */
842 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize(); 859 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize ();
843#endif 860#endif
844 if (newlim > rlim.rlim_max) 861 if (newlim > rlim.rlim_max)
845 { 862 {
@@ -940,7 +957,7 @@ main (int argc, char **argv)
940 } 957 }
941 958
942 /* Command line option --no-windows is deprecated and thus not mentioned 959 /* Command line option --no-windows is deprecated and thus not mentioned
943 in the manual and usage informations. */ 960 in the manual and usage information. */
944 if (argmatch (argv, argc, "-nw", "--no-window-system", 6, NULL, &skip_args) 961 if (argmatch (argv, argc, "-nw", "--no-window-system", 6, NULL, &skip_args)
945 || argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) 962 || argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
946 inhibit_window_system = 1; 963 inhibit_window_system = 1;
@@ -1065,15 +1082,17 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1065 if (!dname_arg || !strchr (dname_arg, '\n')) 1082 if (!dname_arg || !strchr (dname_arg, '\n'))
1066 { /* In orig, child: now exec w/special daemon name. */ 1083 { /* In orig, child: now exec w/special daemon name. */
1067 char fdStr[80]; 1084 char fdStr[80];
1085 int fdStrlen =
1086 snprintf (fdStr, sizeof fdStr,
1087 "--daemon=\n%d,%d\n%s", daemon_pipe[0],
1088 daemon_pipe[1], dname_arg ? dname_arg : "");
1068 1089
1069 if (dname_arg && strlen (dname_arg) > 70) 1090 if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr))
1070 { 1091 {
1071 fprintf (stderr, "daemon: child name too long\n"); 1092 fprintf (stderr, "daemon: child name too long\n");
1072 exit (1); 1093 exit (1);
1073 } 1094 }
1074 1095
1075 sprintf (fdStr, "--daemon=\n%d,%d\n%s", daemon_pipe[0],
1076 daemon_pipe[1], dname_arg ? dname_arg : "");
1077 argv[skip_args] = fdStr; 1096 argv[skip_args] = fdStr;
1078 1097
1079 execv (argv[0], argv); 1098 execv (argv[0], argv);
@@ -1086,7 +1105,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1086 || strlen (dname_arg) < 1 || strlen (dname_arg) > 70) 1105 || strlen (dname_arg) < 1 || strlen (dname_arg) > 70)
1087 { 1106 {
1088 fprintf (stderr, "emacs daemon: daemon name absent or too long\n"); 1107 fprintf (stderr, "emacs daemon: daemon name absent or too long\n");
1089 exit(1); 1108 exit (1);
1090 } 1109 }
1091 dname_arg2[0] = '\0'; 1110 dname_arg2[0] = '\0';
1092 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), 1111 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]),
@@ -1104,7 +1123,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1104 fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC); 1123 fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC);
1105 1124
1106#ifdef HAVE_SETSID 1125#ifdef HAVE_SETSID
1107 setsid(); 1126 setsid ();
1108#endif 1127#endif
1109#else /* DOS_NT */ 1128#else /* DOS_NT */
1110 fprintf (stderr, "This platform does not support the -daemon flag.\n"); 1129 fprintf (stderr, "This platform does not support the -daemon flag.\n");
@@ -1117,7 +1136,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1117#if defined (USG5) && defined (INTERRUPT_INPUT) 1136#if defined (USG5) && defined (INTERRUPT_INPUT)
1118 setpgrp (); 1137 setpgrp ();
1119#endif 1138#endif
1120#if defined (HAVE_GTK_AND_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC) 1139#if defined (HAVE_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
1121 { 1140 {
1122 extern void malloc_enable_thread (void); 1141 extern void malloc_enable_thread (void);
1123 1142
@@ -1305,7 +1324,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1305 = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args); 1324 = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args);
1306 1325
1307#ifdef HAVE_NS 1326#ifdef HAVE_NS
1308 ns_alloc_autorelease_pool(); 1327 ns_pool = ns_alloc_autorelease_pool ();
1309 if (!noninteractive) 1328 if (!noninteractive)
1310 { 1329 {
1311#ifdef NS_IMPL_COCOA 1330#ifdef NS_IMPL_COCOA
@@ -1313,12 +1332,12 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1313 { 1332 {
1314 /* FIXME: Do the right thing if getenv returns NULL, or if 1333 /* FIXME: Do the right thing if getenv returns NULL, or if
1315 chdir fails. */ 1334 chdir fails. */
1316 if (!strncmp(argv[skip_args], "-psn", 4)) 1335 if (!strncmp (argv[skip_args], "-psn", 4))
1317 { 1336 {
1318 skip_args += 1; 1337 skip_args += 1;
1319 chdir (getenv ("HOME")); 1338 chdir (getenv ("HOME"));
1320 } 1339 }
1321 else if (skip_args+1 < argc && !strncmp(argv[skip_args+1], "-psn", 4)) 1340 else if (skip_args+1 < argc && !strncmp (argv[skip_args+1], "-psn", 4))
1322 { 1341 {
1323 skip_args += 2; 1342 skip_args += 2;
1324 chdir (getenv ("HOME")); 1343 chdir (getenv ("HOME"));
@@ -1355,24 +1374,17 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1355 /* If we have the form --display=NAME, 1374 /* If we have the form --display=NAME,
1356 convert it into -d name. 1375 convert it into -d name.
1357 This requires inserting a new element into argv. */ 1376 This requires inserting a new element into argv. */
1358 if (displayname != 0 && skip_args - count_before == 1) 1377 if (displayname && count_before < skip_args)
1359 { 1378 {
1360 char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); 1379 if (skip_args == count_before + 1)
1361 int j; 1380 {
1362 1381 memmove (argv + count_before + 3, argv + count_before + 2,
1363 for (j = 0; j < count_before + 1; j++) 1382 (argc - (count_before + 2)) * sizeof *argv);
1364 new[j] = argv[j]; 1383 argv[count_before + 2] = displayname;
1365 new[count_before + 1] = (char *) "-d"; 1384 argc++;
1366 new[count_before + 2] = displayname; 1385 }
1367 for (j = count_before + 2; j <argc; j++) 1386 argv[count_before + 1] = (char *) "-d";
1368 new[j + 1] = argv[j];
1369 argv = new;
1370 argc++;
1371 } 1387 }
1372 /* Change --display to -d, when its arg is separate. */
1373 else if (displayname != 0 && skip_args > count_before
1374 && argv[count_before + 1][1] == '-')
1375 argv[count_before + 1] = (char *) "-d";
1376 1388
1377 if (! no_site_lisp) 1389 if (! no_site_lisp)
1378 { 1390 {
@@ -1398,7 +1410,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1398#endif 1410#endif
1399 1411
1400 /* argmatch must not be used after here, 1412 /* argmatch must not be used after here,
1401 except when bulding temacs 1413 except when building temacs
1402 because the -d argument has not been skipped in skip_args. */ 1414 because the -d argument has not been skipped in skip_args. */
1403 1415
1404#ifdef MSDOS 1416#ifdef MSDOS
@@ -1550,9 +1562,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1550 1562
1551#ifdef MSDOS 1563#ifdef MSDOS
1552 syms_of_xmenu (); 1564 syms_of_xmenu ();
1553 syms_of_dosfns(); 1565 syms_of_dosfns ();
1554 syms_of_msdos(); 1566 syms_of_msdos ();
1555 syms_of_win16select(); 1567 syms_of_win16select ();
1556#endif /* MSDOS */ 1568#endif /* MSDOS */
1557 1569
1558#ifdef HAVE_NS 1570#ifdef HAVE_NS
@@ -1587,6 +1599,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1587 /* Initialization that must be done even if the global variable 1599 /* Initialization that must be done even if the global variable
1588 initialized is non zero. */ 1600 initialized is non zero. */
1589#ifdef HAVE_NTGUI 1601#ifdef HAVE_NTGUI
1602 globals_of_w32font ();
1590 globals_of_w32fns (); 1603 globals_of_w32fns ();
1591 globals_of_w32menu (); 1604 globals_of_w32menu ();
1592 globals_of_w32select (); 1605 globals_of_w32select ();
@@ -1651,7 +1664,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1651 GNU/Linux and MinGW. It might work on some other systems too. 1664 GNU/Linux and MinGW. It might work on some other systems too.
1652 Give it a try and tell us if it works on your system. To compile 1665 Give it a try and tell us if it works on your system. To compile
1653 for profiling, use the configure option --enable-profiling. */ 1666 for profiling, use the configure option --enable-profiling. */
1654#if defined (__FreeBSD__) || defined (GNU_LINUX) || defined(__MINGW32__) 1667#if defined (__FreeBSD__) || defined (GNU_LINUX) || defined (__MINGW32__)
1655#ifdef PROFILING 1668#ifdef PROFILING
1656 if (initialized) 1669 if (initialized)
1657 { 1670 {
@@ -1835,8 +1848,8 @@ sort_args (int argc, char **argv)
1835 0 for an option that takes no arguments, 1848 0 for an option that takes no arguments,
1836 1 for an option that takes one argument, etc. 1849 1 for an option that takes one argument, etc.
1837 -1 for an ordinary non-option argument. */ 1850 -1 for an ordinary non-option argument. */
1838 int *options = (int *) xmalloc (sizeof (int) * argc); 1851 int *options = xnmalloc (argc, sizeof *options);
1839 int *priority = (int *) xmalloc (sizeof (int) * argc); 1852 int *priority = xnmalloc (argc, sizeof *priority);
1840 int to = 1; 1853 int to = 1;
1841 int incoming_used = 1; 1854 int incoming_used = 1;
1842 int from; 1855 int from;
@@ -1989,6 +2002,7 @@ all of which are called before Emacs is actually killed. */)
1989{ 2002{
1990 struct gcpro gcpro1; 2003 struct gcpro gcpro1;
1991 Lisp_Object hook; 2004 Lisp_Object hook;
2005 int exit_code;
1992 2006
1993 GCPRO1 (arg); 2007 GCPRO1 (arg);
1994 2008
@@ -2007,13 +2021,20 @@ all of which are called before Emacs is actually killed. */)
2007 2021
2008 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil); 2022 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
2009 2023
2024#ifdef HAVE_NS
2025 ns_release_autorelease_pool (ns_pool);
2026#endif
2027
2010 /* If we have an auto-save list file, 2028 /* If we have an auto-save list file,
2011 kill it because we are exiting Emacs deliberately (not crashing). 2029 kill it because we are exiting Emacs deliberately (not crashing).
2012 Do it after shut_down_emacs, which does an auto-save. */ 2030 Do it after shut_down_emacs, which does an auto-save. */
2013 if (STRINGP (Vauto_save_list_file_name)) 2031 if (STRINGP (Vauto_save_list_file_name))
2014 unlink (SSDATA (Vauto_save_list_file_name)); 2032 unlink (SSDATA (Vauto_save_list_file_name));
2015 2033
2016 exit (INTEGERP (arg) ? XINT (arg) : EXIT_SUCCESS); 2034 exit_code = EXIT_SUCCESS;
2035 if (noninteractive && (fflush (stdout) || ferror (stdout)))
2036 exit_code = EXIT_FAILURE;
2037 exit (INTEGERP (arg) ? XINT (arg) : exit_code);
2017} 2038}
2018 2039
2019 2040
@@ -2101,6 +2122,10 @@ shut_down_emacs (int sig, int no_x, Lisp_Object stuff)
2101#ifdef HAVE_NS 2122#ifdef HAVE_NS
2102 ns_term_shutdown (sig); 2123 ns_term_shutdown (sig);
2103#endif 2124#endif
2125
2126#ifdef HAVE_LIBXML2
2127 xmlCleanupParser ();
2128#endif
2104} 2129}
2105 2130
2106 2131
@@ -2135,7 +2160,7 @@ You must run Emacs in batch mode in order to dump it. */)
2135 { 2160 {
2136 fprintf (stderr, "**************************************************\n"); 2161 fprintf (stderr, "**************************************************\n");
2137 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); 2162 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n");
2138 fprintf (stderr, "heap (%lu bytes). This usually means that exec-shield\n", 2163 fprintf (stderr, "heap (%"pMu" bytes). This usually means that exec-shield\n",
2139 heap_bss_diff); 2164 heap_bss_diff);
2140 fprintf (stderr, "or something similar is in effect. The dump may\n"); 2165 fprintf (stderr, "or something similar is in effect. The dump may\n");
2141 fprintf (stderr, "fail because of this. See the section about\n"); 2166 fprintf (stderr, "fail because of this. See the section about\n");
@@ -2182,7 +2207,7 @@ You must run Emacs in batch mode in order to dump it. */)
2182 memory_warnings (my_edata, malloc_warning); 2207 memory_warnings (my_edata, malloc_warning);
2183 } 2208 }
2184#endif /* not WINDOWSNT */ 2209#endif /* not WINDOWSNT */
2185#if defined (HAVE_GTK_AND_PTHREAD) && !defined SYNC_INPUT 2210#if defined (HAVE_PTHREAD) && !defined SYNC_INPUT
2186 /* Pthread may call malloc before main, and then we will get an endless 2211 /* Pthread may call malloc before main, and then we will get an endless
2187 loop, because pthread_self (see alloc.c) calls malloc the first time 2212 loop, because pthread_self (see alloc.c) calls malloc the first time
2188 it is called on some systems. */ 2213 it is called on some systems. */
@@ -2381,6 +2406,7 @@ syms_of_emacs (void)
2381{ 2406{
2382 DEFSYM (Qfile_name_handler_alist, "file-name-handler-alist"); 2407 DEFSYM (Qfile_name_handler_alist, "file-name-handler-alist");
2383 DEFSYM (Qrisky_local_variable, "risky-local-variable"); 2408 DEFSYM (Qrisky_local_variable, "risky-local-variable");
2409 DEFSYM (Qkill_emacs, "kill-emacs");
2384 2410
2385#ifndef CANNOT_DUMP 2411#ifndef CANNOT_DUMP
2386 defsubr (&Sdump_emacs); 2412 defsubr (&Sdump_emacs);
@@ -2454,9 +2480,11 @@ The value is nil if that directory's name is not known. */);
2454 2480
2455 DEFVAR_LISP ("installation-directory", Vinstallation_directory, 2481 DEFVAR_LISP ("installation-directory", Vinstallation_directory,
2456 doc: /* A directory within which to look for the `lib-src' and `etc' directories. 2482 doc: /* A directory within which to look for the `lib-src' and `etc' directories.
2457This is non-nil when we can't find those directories in their standard 2483In an installed Emacs, this is normally nil. It is non-nil if
2458installed locations, but we can find them near where the Emacs executable 2484both `lib-src' (on MS-DOS, `info') and `etc' directories are found
2459was found. */); 2485within the variable `invocation-directory' or its parent. For example,
2486this is the case when running an uninstalled Emacs executable from its
2487build directory. */);
2460 Vinstallation_directory = Qnil; 2488 Vinstallation_directory = Qnil;
2461 2489
2462 DEFVAR_LISP ("system-messages-locale", Vsystem_messages_locale, 2490 DEFVAR_LISP ("system-messages-locale", Vsystem_messages_locale,