X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/5b0d046d5b6a6743be6888d02352b878151e1d6c..1781b9e935bea6cf2905e612da94b70028b25733:/src/emacs.c diff --git a/src/emacs.c b/src/emacs.c index 5f3d126e13..c737a41974 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1,6 +1,6 @@ /* Fully extensible Emacs, running on Unix, intended for GNU. -Copyright (C) 1985-1987, 1993-1995, 1997-1999, 2001-2011 +Copyright (C) 1985-1987, 1993-1995, 1997-1999, 2001-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -29,6 +29,8 @@ along with GNU Emacs. If not, see . */ #include #include +#include + #include "lisp.h" #ifdef WINDOWSNT @@ -45,6 +47,7 @@ along with GNU Emacs. If not, see . */ #include "commands.h" #include "intervals.h" +#include "character.h" #include "buffer.h" #include "window.h" @@ -65,6 +68,12 @@ along with GNU Emacs. If not, see . */ #include "nsterm.h" #endif +#if (defined PROFILING \ + && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__)) +# include +extern void moncontrol (int mode); +#endif + #ifdef HAVE_X_WINDOWS #include "xterm.h" #endif @@ -82,48 +91,12 @@ along with GNU Emacs. If not, see . */ #include #endif -#ifdef HAVE_LIBXML2 -#include -#endif - #ifndef O_RDWR #define O_RDWR 2 #endif -#ifdef HAVE_SETPGID -#if !defined (USG) -#undef setpgrp -#define setpgrp setpgid -#endif -#endif - static const char emacs_version[] = VERSION; -static const char emacs_copyright[] = "Copyright (C) 2011 Free Software Foundation, Inc."; - -/* Make these values available in GDB, which doesn't see macros. */ - -#ifdef USE_LSB_TAG -int gdb_use_lsb EXTERNALLY_VISIBLE = 1; -#else -int gdb_use_lsb EXTERNALLY_VISIBLE = 0; -#endif -#ifndef USE_LISP_UNION_TYPE -int gdb_use_union EXTERNALLY_VISIBLE = 0; -#else -int gdb_use_union EXTERNALLY_VISIBLE = 1; -#endif -int gdb_valbits EXTERNALLY_VISIBLE = VALBITS; -int gdb_gctypebits EXTERNALLY_VISIBLE = GCTYPEBITS; -#if defined (DATA_SEG_BITS) && ! defined (USE_LSB_TAG) -uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = DATA_SEG_BITS; -#else -uintptr_t gdb_data_seg_bits EXTERNALLY_VISIBLE = 0; -#endif -ptrdiff_t PVEC_FLAG EXTERNALLY_VISIBLE = PSEUDOVECTOR_FLAG; -ptrdiff_t gdb_array_mark_flag EXTERNALLY_VISIBLE = ARRAY_MARK_FLAG; -/* GDB might say "No enum type named pvec_type" if we don't have at - least one symbol with that type, and then xbacktrace could fail. */ -enum pvec_type gdb_pvec_type EXTERNALLY_VISIBLE = PVEC_TYPE_MASK; +static const char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc."; /* Empty lisp strings. To avoid having to build any others. */ Lisp_Object empty_unibyte_string, empty_multibyte_string; @@ -154,6 +127,8 @@ Lisp_Object Qfile_name_handler_alist; Lisp_Object Qrisky_local_variable; +Lisp_Object Qkill_emacs; + /* If non-zero, Emacs should not attempt to use a window-specific code, but instead should use the virtual terminal under which it was started. */ int inhibit_window_system; @@ -319,6 +294,12 @@ static void (*fatal_error_signal_hook) (void); pthread_t main_thread; #endif +#ifdef HAVE_NS +/* NS autrelease pool, for memory management. */ +static void *ns_pool; +#endif + + /* Handle bus errors, invalid instruction, etc. */ #ifndef FLOAT_CATCH_SIGILL @@ -565,7 +546,7 @@ static char dump_tz[] = "UtC0"; /* Define a dummy function F. Declare F too, to pacify gcc -Wmissing-prototypes. */ #define DEFINE_DUMMY_FUNCTION(f) \ - void f (void) EXTERNALLY_VISIBLE; void f (void) {} + void f (void) ATTRIBUTE_CONST EXTERNALLY_VISIBLE; void f (void) {} #ifndef GCC_CTORS_IN_LIBC DEFINE_DUMMY_FUNCTION (__do_global_ctors) @@ -949,7 +930,7 @@ main (int argc, char **argv) } /* Command line option --no-windows is deprecated and thus not mentioned - in the manual and usage informations. */ + in the manual and usage information. */ if (argmatch (argv, argc, "-nw", "--no-window-system", 6, NULL, &skip_args) || argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) inhibit_window_system = 1; @@ -1250,7 +1231,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_alloc_once (); init_obarray (); init_eval_once (); - init_character_once (); init_charset_once (); init_coding_once (); init_syntax_once (); /* Create standard syntax table. */ @@ -1303,9 +1283,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_eval (); init_data (); -#ifdef CLASH_DETECTION - init_filelock (); -#endif init_atimer (); running_asynch_code = 0; @@ -1316,7 +1293,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem = argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args); #ifdef HAVE_NS - ns_alloc_autorelease_pool (); + ns_pool = ns_alloc_autorelease_pool (); if (!noninteractive) { #ifdef NS_IMPL_COCOA @@ -1402,7 +1379,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #endif /* argmatch must not be used after here, - except when bulding temacs + except when building temacs because the -d argument has not been skipped in skip_args. */ #ifdef MSDOS @@ -1422,13 +1399,6 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_ntproc (); /* must precede init_editfns. */ #endif -#ifdef HAVE_NS -#ifndef CANNOT_DUMP - if (initialized) -#endif - ns_init_paths (); -#endif - /* Initialize and GC-protect Vinitial_environment and Vprocess_environment before set_initial_environment fills them in. */ @@ -1600,22 +1570,17 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_charset (); - init_editfns (); /* init_process uses Voperating_system_release. */ - init_process (); /* init_display uses add_keyboard_wait_descriptor. */ + init_editfns (); /* init_process_emacs uses Voperating_system_release. */ + init_process_emacs (); /* init_display uses add_keyboard_wait_descriptor. */ init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) init_display (); /* Determine terminal type. Calls init_sys_modes. */ - init_fns (); init_xdisp (); #ifdef HAVE_WINDOW_SYSTEM init_fringe (); - init_image (); #endif /* HAVE_WINDOW_SYSTEM */ init_macros (); init_floatfns (); -#ifdef HAVE_SOUND - init_sound (); -#endif init_window (); init_font (); @@ -1660,32 +1625,14 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #ifdef PROFILING if (initialized) { - extern void _mcleanup (); #ifdef __MINGW32__ extern unsigned char etext asm ("etext"); #else extern char etext; #endif -#ifdef HAVE___EXECUTABLE_START - /* This symbol is defined by GNU ld to the start of the text - segment. */ - extern char __executable_start[]; -#else - extern void safe_bcopy (); -#endif atexit (_mcleanup); -#ifdef HAVE___EXECUTABLE_START - monstartup (__executable_start, &etext); -#else - /* This uses safe_bcopy because that function comes first in the - Emacs executable. It might be better to use something that - gives the start of the text segment, but start_of_text is not - defined on all systems now. */ - /* FIXME: Does not work on architectures with function - descriptors. */ - monstartup (safe_bcopy, &etext); -#endif + monstartup ((uintptr_t) __executable_start, (uintptr_t) &etext); } else moncontrol (0); @@ -1834,7 +1781,7 @@ static const struct standard_args standard_args[] = static void sort_args (int argc, char **argv) { - char **new = (char **) xmalloc (sizeof (char *) * argc); + char **new = xmalloc (argc * sizeof *new); /* For each element of argv, the corresponding element of options is: 0 for an option that takes no arguments, @@ -2013,6 +1960,10 @@ all of which are called before Emacs is actually killed. */) shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil); +#ifdef HAVE_NS + ns_release_autorelease_pool (ns_pool); +#endif + /* If we have an auto-save list file, kill it because we are exiting Emacs deliberately (not crashing). Do it after shut_down_emacs, which does an auto-save. */ @@ -2117,7 +2068,7 @@ shut_down_emacs (int sig, int no_x, Lisp_Object stuff) #endif #ifdef HAVE_LIBXML2 - xmlCleanupParser (); + xml_cleanup_parser (); #endif } @@ -2399,6 +2350,7 @@ syms_of_emacs (void) { DEFSYM (Qfile_name_handler_alist, "file-name-handler-alist"); DEFSYM (Qrisky_local_variable, "risky-local-variable"); + DEFSYM (Qkill_emacs, "kill-emacs"); #ifndef CANNOT_DUMP defsubr (&Sdump_emacs); @@ -2472,9 +2424,11 @@ The value is nil if that directory's name is not known. */); DEFVAR_LISP ("installation-directory", Vinstallation_directory, doc: /* A directory within which to look for the `lib-src' and `etc' directories. -This is non-nil when we can't find those directories in their standard -installed locations, but we can find them near where the Emacs executable -was found. */); +In an installed Emacs, this is normally nil. It is non-nil if +both `lib-src' (on MS-DOS, `info') and `etc' directories are found +within the variable `invocation-directory' or its parent. For example, +this is the case when running an uninstalled Emacs executable from its +build directory. */); Vinstallation_directory = Qnil; DEFVAR_LISP ("system-messages-locale", Vsystem_messages_locale, @@ -2536,3 +2490,50 @@ libraries; only those already known by Emacs will be loaded. */); /* Make sure IS_DAEMON starts up as false. */ daemon_pipe[1] = 0; } + +/* Make these values available in GDB, which doesn't see macros. + This is last, so that the #undef lines don't mess up later code. */ + +enum + { + gdb_CHECK_LISP_OBJECT_TYPE = CHECK_LISP_OBJECT_TYPE, + gdb_DATA_SEG_BITS = DATA_SEG_BITS, + gdb_GCTYPEBITS = GCTYPEBITS, + gdb_USE_LSB_TAG = USE_LSB_TAG + }; + +#undef CHECK_LISP_OBJECT_TYPE +#undef DATA_SEG_BITS +#undef GCTYPEBITS +#undef USE_LSB_TAG + +enum + { + CHECK_LISP_OBJECT_TYPE = gdb_CHECK_LISP_OBJECT_TYPE, + DATA_SEG_BITS = gdb_DATA_SEG_BITS, + GCTYPEBITS = gdb_GCTYPEBITS, + USE_LSB_TAG = gdb_USE_LSB_TAG + }; + +/* These are trickier since they might fall out of int range. Each + symbol X has a corresponding X_VAL symbol, verified to have the + correct value. */ + +#define ARRAY_MARK_FLAG_VAL PTRDIFF_MIN +#define PSEUDOVECTOR_FLAG_VAL (PTRDIFF_MAX - PTRDIFF_MAX / 2) +#define VALMASK_VAL (USE_LSB_TAG ? -1 << GCTYPEBITS : VAL_MAX) + +verify (ARRAY_MARK_FLAG_VAL == ARRAY_MARK_FLAG); +verify (PSEUDOVECTOR_FLAG_VAL == PSEUDOVECTOR_FLAG); +verify (VALMASK_VAL == VALMASK); + +#undef ARRAY_MARK_FLAG +#undef PSEUDOVECTOR_FLAG +#undef VALMASK + +ptrdiff_t const EXTERNALLY_VISIBLE + ARRAY_MARK_FLAG = ARRAY_MARK_FLAG_VAL, + PSEUDOVECTOR_FLAG = PSEUDOVECTOR_FLAG_VAL; + +EMACS_INT const EXTERNALLY_VISIBLE + VALMASK = VALMASK_VAL;