comparison src/emacs.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents b2472a1930f2
children ca9a9ec9c1c1
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
41 #include "syssignal.h" /* Always include before systty.h */ 41 #include "syssignal.h" /* Always include before systty.h */
42 #include "systty.h" 42 #include "systty.h"
43 #include "sysfile.h" 43 #include "sysfile.h"
44 #include "systime.h" 44 #include "systime.h"
45 45
46 #ifdef HAVE_SHLIB
47 #include "sysdll.h"
48 #endif
49
46 #if defined (HAVE_LOCALE_H) && \ 50 #if defined (HAVE_LOCALE_H) && \
47 (defined (I18N2) || defined (I18N3) || defined (I18N4)) 51 (defined (I18N2) || defined (I18N3) || defined (I18N4))
48 #include <locale.h> 52 #include <locale.h>
49 #endif 53 #endif
50 54
61 #if defined (WINDOWSNT) 65 #if defined (WINDOWSNT)
62 #include <windows.h> 66 #include <windows.h>
63 #endif 67 #endif
64 68
65 /* For PATH_EXEC */ 69 /* For PATH_EXEC */
66 #include "paths.h" 70 #include <paths.h>
67
68 extern void memory_warnings (void *, void (*warnfun) (CONST char *));
69 71
70 #if !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC 72 #if !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC
71 extern void *(*__malloc_hook)(size_t); 73 extern void *(*__malloc_hook)(size_t);
72 extern void *(*__realloc_hook)(void *, size_t); 74 extern void *(*__realloc_hook)(void *, size_t);
73 extern void (*__free_hook)(void *); 75 extern void (*__free_hook)(void *);
83 85
84 #ifdef DOUG_LEA_MALLOC 86 #ifdef DOUG_LEA_MALLOC
85 # include <malloc.h> 87 # include <malloc.h>
86 /* Preserves a pointer to the memory allocated that copies that 88 /* Preserves a pointer to the memory allocated that copies that
87 static data inside glibc's malloc. */ 89 static data inside glibc's malloc. */
88 void *malloc_state_ptr; 90 static void *malloc_state_ptr;
89 #endif 91 #endif /* DOUG_LEA_MALLOC */
92
93 # ifdef REL_ALLOC
94 void r_alloc_reinit (void);
95 # endif
90 96
91 /* Variable whose value is symbol giving operating system type. */ 97 /* Variable whose value is symbol giving operating system type. */
92 Lisp_Object Vsystem_type; 98 Lisp_Object Vsystem_type;
93 99
94 /* Variable whose value is string giving configuration built for. */ 100 /* Variable whose value is string giving configuration built for. */
152 variable. */ 158 variable. */
153 CONST char *display_use; 159 CONST char *display_use;
154 160
155 /* If non-zero, then the early error handler will only print the error 161 /* If non-zero, then the early error handler will only print the error
156 message and exit. */ 162 message and exit. */
157 int suppress_early_backtrace; 163 int suppress_early_error_handler_backtrace;
158 164
159 /* An address near the bottom of the stack. 165 /* An address near the bottom of the stack.
160 Tells GC how to save a copy of the stack. */ 166 Tells GC how to save a copy of the stack. */
161 char *stack_bottom; 167 char *stack_bottom;
162 168
535 * does; it was provided by NeXT, and it presumable makes NS's mallocator 541 * does; it was provided by NeXT, and it presumable makes NS's mallocator
536 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in 542 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in
537 * unexnext.c are both completely undocumented, even in NS header files! 543 * unexnext.c are both completely undocumented, even in NS header files!
538 * But hey, it solves all NS related memory problems, so who's 544 * But hey, it solves all NS related memory problems, so who's
539 * complaining? */ 545 * complaining? */
540 if (initialized) 546 if (initialized && malloc_jumpstart (malloc_cookie) != 0)
541 if (malloc_jumpstart (malloc_cookie) != 0) 547 fprintf (stderr, "malloc jumpstart failed!\n");
542 printf ("malloc jumpstart failed!\n");
543 #endif /* NeXT */ 548 #endif /* NeXT */
544 549
545 /* 550 /*
546 #if defined (GNU_MALLOC) && \ 551 #if defined (GNU_MALLOC) && \
547 defined (ERROR_CHECK_MALLOC) && \ 552 defined (ERROR_CHECK_MALLOC) && \
893 syms_of_lread (); 898 syms_of_lread ();
894 syms_of_macros (); 899 syms_of_macros ();
895 syms_of_marker (); 900 syms_of_marker ();
896 syms_of_md5 (); 901 syms_of_md5 ();
897 #ifdef HAVE_DATABASE 902 #ifdef HAVE_DATABASE
898 syms_of_dbm (); 903 syms_of_database ();
899 #endif 904 #endif
900 #ifdef HAVE_MENUBARS 905 #ifdef HAVE_MENUBARS
901 syms_of_menubar (); 906 syms_of_menubar ();
902 #endif 907 #endif
903 syms_of_minibuf (); 908 syms_of_minibuf ();
944 syms_of_objects_x (); 949 syms_of_objects_x ();
945 #ifdef HAVE_MENUBARS 950 #ifdef HAVE_MENUBARS
946 syms_of_menubar_x (); 951 syms_of_menubar_x ();
947 #endif 952 #endif
948 syms_of_xselect (); 953 syms_of_xselect ();
949 #ifdef EPOCH
950 syms_of_epoch ();
951 #endif
952 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS) 954 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
953 syms_of_gui_x (); 955 syms_of_gui_x ();
954 #endif 956 #endif
955 #endif /* HAVE_X_WINDOWS */ 957 #endif /* HAVE_X_WINDOWS */
956 958
1259 vars_of_lread (); 1261 vars_of_lread ();
1260 vars_of_lstream (); 1262 vars_of_lstream ();
1261 vars_of_macros (); 1263 vars_of_macros ();
1262 vars_of_md5 (); 1264 vars_of_md5 ();
1263 #ifdef HAVE_DATABASE 1265 #ifdef HAVE_DATABASE
1264 vars_of_dbm (); 1266 vars_of_database ();
1265 #endif 1267 #endif
1266 #ifdef HAVE_MENUBARS 1268 #ifdef HAVE_MENUBARS
1267 vars_of_menubar (); 1269 vars_of_menubar ();
1268 #endif 1270 #endif
1269 vars_of_minibuf (); 1271 vars_of_minibuf ();
1317 #ifdef HAVE_MENUBARS 1319 #ifdef HAVE_MENUBARS
1318 vars_of_menubar_x (); 1320 vars_of_menubar_x ();
1319 #endif 1321 #endif
1320 vars_of_objects_x (); 1322 vars_of_objects_x ();
1321 vars_of_xselect (); 1323 vars_of_xselect ();
1322 #ifdef EPOCH
1323 vars_of_epoch ();
1324 #endif
1325 #ifdef HAVE_SCROLLBARS 1324 #ifdef HAVE_SCROLLBARS
1326 vars_of_scrollbar_x (); 1325 vars_of_scrollbar_x ();
1327 #endif 1326 #endif
1328 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS) 1327 #if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
1329 vars_of_gui_x (); 1328 vars_of_gui_x ();
1860 static JMP_BUF run_temacs_catch; 1859 static JMP_BUF run_temacs_catch;
1861 1860
1862 static int run_temacs_argc; 1861 static int run_temacs_argc;
1863 static char **run_temacs_argv; 1862 static char **run_temacs_argv;
1864 static char *run_temacs_args; 1863 static char *run_temacs_args;
1865 static int run_temacs_argv_size; 1864 static size_t run_temacs_argv_size;
1866 static int run_temacs_args_size; 1865 static size_t run_temacs_args_size;
1867
1868 extern int gc_in_progress;
1869 1866
1870 DEFUN ("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /* 1867 DEFUN ("running-temacs-p", Frunning_temacs_p, 0, 0, 0, /*
1871 True if running temacs. This means we are in the dumping stage. 1868 True if running temacs. This means we are in the dumping stage.
1872 This is false during normal execution of the `xemacs' program, and 1869 This is false during normal execution of the `xemacs' program, and
1873 becomes false once `run-emacs-from-temacs' is run. 1870 becomes false once `run-emacs-from-temacs' is run.
1980 #ifdef QUANTIFY 1977 #ifdef QUANTIFY
1981 quantify_stop_recording_data (); 1978 quantify_stop_recording_data ();
1982 quantify_clear_data (); 1979 quantify_clear_data ();
1983 #endif /* QUANTIFY */ 1980 #endif /* QUANTIFY */
1984 1981
1985 suppress_early_backtrace = 0; 1982 suppress_early_error_handler_backtrace = 0;
1986 lim_data = 0; /* force reinitialization of this variable */ 1983 lim_data = 0; /* force reinitialization of this variable */
1987 1984
1988 /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */ 1985 /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */
1989 assert (sizeof (Lisp_Object) == sizeof (void *)); 1986 assert (sizeof (Lisp_Object) == sizeof (void *));
1990 1987
2026 environ=_environ; 2023 environ=_environ;
2027 } 2024 }
2028 #endif /* _SCO_DS */ 2025 #endif /* _SCO_DS */
2029 vol_envp = environ; 2026 vol_envp = environ;
2030 } 2027 }
2031 #ifdef RUN_TIME_REMAP 2028 #ifdef RUN_TIME_REMAP
2032 else 2029 else
2033 /* obviously no-one uses this because where it was before initalized was 2030 /* obviously no-one uses this because where it was before initalized was
2034 *always* true */ 2031 *always* true */
2035 run_time_remap (argv[0]); 2032 run_time_remap (argv[0]);
2036 #endif 2033 #endif
2037 2034
2038 #ifdef DOUG_LEA_MALLOC 2035 #ifdef DOUG_LEA_MALLOC
2039 if (initialized && (malloc_state_ptr != NULL)) 2036 if (initialized && (malloc_state_ptr != NULL))
2040 { 2037 {
2041 malloc_set_state (malloc_state_ptr); 2038 int rc = malloc_set_state (malloc_state_ptr);
2039 if (rc != 0)
2040 {
2041 fprintf (stderr, "malloc_set_state failed, rc = %d\n", rc);
2042 abort ();
2043 }
2042 #if 0 2044 #if 0
2043 free (malloc_state_ptr); 2045 free (malloc_state_ptr);
2044 #endif 2046 #endif
2045 /* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only) and Linux libc5 */ 2047 /* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only) and Linux libc5 */
2046 #if (defined(__GLIBC__) && __GLIBC_MINOR__ >= 1) || \ 2048 #if (defined(__GLIBC__) && __GLIBC_MINOR__ >= 1) || \
2051 #endif 2053 #endif
2052 #ifdef REL_ALLOC 2054 #ifdef REL_ALLOC
2053 r_alloc_reinit (); 2055 r_alloc_reinit ();
2054 #endif 2056 #endif
2055 } 2057 }
2056 #endif 2058 #endif /* DOUG_LEA_MALLOC */
2057 2059
2058 run_temacs_argc = -1; 2060 run_temacs_argc = -1;
2059 2061
2060 main_1 (vol_argc, vol_argv, vol_envp, restarted); 2062 main_1 (vol_argc, vol_argv, vol_envp, restarted);
2061 return 0; /* unreached */ 2063 return 0; /* unreached */
2062 } 2064 }
2063 2065
2064 2066
2067 /* Dumping apparently isn't supported by versions of GCC >= 2.8. */
2068 /* The following needs conditionalization on whether either XEmacs or */
2069 /* various system shared libraries have been built and linked with */
2070 /* GCC >= 2.8. -slb */
2071 #if defined(GNU_MALLOC)
2072 static void
2073 voodoo_free_hook(void *mem)
2074 {
2075 /* Disable all calls to free() when XEmacs is exiting and it doesn't */
2076 /* matter. */
2077 __free_hook = voodoo_free_hook;
2078 }
2079 #endif
2080
2065 DEFUN ("kill-emacs", Fkill_emacs, 0, 1, "P", /* 2081 DEFUN ("kill-emacs", Fkill_emacs, 0, 1, "P", /*
2066 Exit the XEmacs job and kill it. Ask for confirmation, without argument. 2082 Exit the XEmacs job and kill it. Ask for confirmation, without argument.
2067 If ARG is an integer, return ARG as the exit program code. 2083 If ARG is an integer, return ARG as the exit program code.
2068 If ARG is a string, stuff it as keyboard input. 2084 If ARG is a string, stuff it as keyboard input.
2069 2085
2113 } 2129 }
2114 2130
2115 UNGCPRO; 2131 UNGCPRO;
2116 2132
2117 shut_down_emacs (0, ((STRINGP (arg)) ? arg : Qnil)); 2133 shut_down_emacs (0, ((STRINGP (arg)) ? arg : Qnil));
2134
2135 #if defined(GNU_MALLOC)
2136 __free_hook = voodoo_free_hook;
2137 #endif
2118 2138
2119 exit ((INTP (arg)) ? XINT (arg) : 0); 2139 exit ((INTP (arg)) ? XINT (arg) : 0);
2120 /* NOTREACHED */ 2140 /* NOTREACHED */
2121 return Qnil; /* I'm sick of the compiler warning */ 2141 return Qnil; /* I'm sick of the compiler warning */
2122 } 2142 }
2280 2300
2281 return Qnil; 2301 return Qnil;
2282 } 2302 }
2283 2303
2284 #else /* not HAVE_SHM */ 2304 #else /* not HAVE_SHM */
2305 extern void disable_free_hook (void);
2285 2306
2286 DEFUN ("dump-emacs", Fdump_emacs, 2, 2, 0, /* 2307 DEFUN ("dump-emacs", Fdump_emacs, 2, 2, 0, /*
2287 Dump current state of XEmacs into executable file FILENAME. 2308 Dump current state of XEmacs into executable file FILENAME.
2288 Take symbols from SYMFILE (presumably the file you executed to run XEmacs). 2309 Take symbols from SYMFILE (presumably the file you executed to run XEmacs).
2289 This is used in the file `loadup.el' when building XEmacs. 2310 This is used in the file `loadup.el' when building XEmacs.
2303 #ifdef FREE_CHECKING 2324 #ifdef FREE_CHECKING
2304 Freally_free (Qnil); 2325 Freally_free (Qnil);
2305 2326
2306 /* When we're dumping, we can't use the debugging free() */ 2327 /* When we're dumping, we can't use the debugging free() */
2307 2328
2308 disable_free_hook (); 2329 #endif
2330 #if 1 /* martin */
2309 #endif 2331 #endif
2310 2332
2311 CHECK_STRING (intoname); 2333 CHECK_STRING (intoname);
2312 intoname = Fexpand_file_name (intoname, Qnil); 2334 intoname = Fexpand_file_name (intoname, Qnil);
2313 if (!NILP (symname)) 2335 if (!NILP (symname))
2353 close (fd); 2375 close (fd);
2354 } 2376 }
2355 } 2377 }
2356 #else /* not MSDOS and EMX */ 2378 #else /* not MSDOS and EMX */
2357 { 2379 {
2358 CONST char *intoname_ext; 2380 char *intoname_ext;
2359 CONST char *symname_ext; 2381 char *symname_ext;
2360 2382
2361 GET_C_STRING_FILENAME_DATA_ALLOCA (intoname, intoname_ext); 2383 GET_C_STRING_FILENAME_DATA_ALLOCA (intoname, intoname_ext);
2362 if (STRINGP (symname)) 2384 if (STRINGP (symname))
2363 GET_C_STRING_FILENAME_DATA_ALLOCA (symname, symname_ext); 2385 GET_C_STRING_FILENAME_DATA_ALLOCA (symname, symname_ext);
2364 else 2386 else
2365 symname_ext = 0; 2387 symname_ext = 0;
2388
2389 garbage_collect_1 ();
2366 #ifdef DOUG_LEA_MALLOC 2390 #ifdef DOUG_LEA_MALLOC
2367 malloc_state_ptr = malloc_get_state (); 2391 malloc_state_ptr = malloc_get_state ();
2368 #endif 2392 #endif
2369 /* here we break our rule that the filename conversion should 2393 #ifdef ERROR_CHECK_MALLOC
2370 be performed at the actual time that the system call is made. 2394 disable_free_hook ();
2371 It's a whole lot easier to do the conversion here than to 2395 #endif
2372 modify all the unexec routines to ensure that filename 2396 /* here we break our rule that the filename conversion should
2373 conversion is applied everywhere. Don't worry about memory 2397 be performed at the actual time that the system call is made.
2374 leakage because this call only happens once. */ 2398 It's a whole lot easier to do the conversion here than to
2375 unexec ((char *) intoname_ext, (char *) symname_ext, 2399 modify all the unexec routines to ensure that filename
2376 (uintptr_t) my_edata, 2400 conversion is applied everywhere. Don't worry about memory
2377 0, 0); 2401 leakage because this call only happens once. */
2402 unexec (intoname_ext, symname_ext, (uintptr_t) my_edata, 0, 0);
2378 #ifdef DOUG_LEA_MALLOC 2403 #ifdef DOUG_LEA_MALLOC
2379 free (malloc_state_ptr); 2404 free (malloc_state_ptr);
2380 #endif 2405 #endif
2381 } 2406 }
2382 #endif /* not MSDOS and EMX */ 2407 #endif /* not MSDOS and EMX */
2393 #ifndef SEPCHAR 2418 #ifndef SEPCHAR
2394 #define SEPCHAR ':' 2419 #define SEPCHAR ':'
2395 #endif 2420 #endif
2396 2421
2397 DEFUN ("decode-path-internal", Fdecode_path_internal, 1, 1, 0, /* 2422 DEFUN ("decode-path-internal", Fdecode_path_internal, 1, 1, 0, /*
2398 Explode a colon-separated list of paths into a string list. 2423 Explode a colon-separated list of paths into a list of strings.
2399 */ 2424 */
2400 (cd_path)) 2425 (cd_path))
2401 { 2426 {
2402 if (NILP(cd_path)) 2427 if (NILP (cd_path))
2403 { 2428 return Qnil;
2404 return Qnil; 2429
2405 }
2406 CHECK_STRING (cd_path); 2430 CHECK_STRING (cd_path);
2407 2431
2408 return (!XSTRING_LENGTH(cd_path)) ? 2432 return !XSTRING_LENGTH (cd_path) ?
2409 list1(Qnil) : 2433 list1 (Qnil) :
2410 decode_path(XSTRING_DATA(cd_path)); 2434 decode_path ((char *) XSTRING_DATA (cd_path));
2411 } 2435 }
2412 2436
2413 Lisp_Object 2437 Lisp_Object
2414 decode_path (CONST char *path) 2438 decode_path (CONST char *path)
2415 { 2439 {
2416 REGISTER CONST char *p; 2440 REGISTER CONST char *p;
2417 Lisp_Object lpath = Qnil; 2441 Lisp_Object lpath = Qnil;
2418 2442
2419 if (!path || !strlen(path)) return Qnil; 2443 if (!path || !strlen (path)) return Qnil;
2420 2444
2421 #if defined (MSDOS) || defined (WIN32) 2445 #if defined (MSDOS) || defined (WIN32)
2422 dostounix_filename (path); 2446 dostounix_filename (path);
2423 #endif 2447 #endif
2424 2448
2476 assert_failed (CONST char *file, int line, CONST char *expr) 2500 assert_failed (CONST char *file, int line, CONST char *expr)
2477 { 2501 {
2478 stderr_out ("Fatal error: assertion failed, file %s, line %d, %s\n", 2502 stderr_out ("Fatal error: assertion failed, file %s, line %d, %s\n",
2479 file, line, expr); 2503 file, line, expr);
2480 #undef abort /* avoid infinite #define loop... */ 2504 #undef abort /* avoid infinite #define loop... */
2481 #if defined (_WIN32) && defined (DEBUG_XEMACS) 2505 #if defined (WINDOWSNT) && defined (DEBUG_XEMACS)
2482 DebugBreak (); 2506 DebugBreak ();
2483 #elif !defined (ASSERTIONS_DONT_ABORT) 2507 #elif !defined (ASSERTIONS_DONT_ABORT)
2484 abort (); 2508 abort ();
2485 #endif 2509 #endif
2486 } 2510 }
2549 2573
2550 void 2574 void
2551 vars_of_emacs (void) 2575 vars_of_emacs (void)
2552 { 2576 {
2553 DEFVAR_BOOL ("suppress-early-error-handler-backtrace", 2577 DEFVAR_BOOL ("suppress-early-error-handler-backtrace",
2554 &suppress_early_backtrace /* 2578 &suppress_early_error_handler_backtrace /*
2555 Non-nil means early error handler shouldn't print a backtrace 2579 Non-nil means early error handler shouldn't print a backtrace.
2556 */ ); 2580 */ );
2557 2581
2558 DEFVAR_LISP ("command-line-args", &Vcommand_line_args /* 2582 DEFVAR_LISP ("command-line-args", &Vcommand_line_args /*
2559 Args passed by shell to XEmacs, as a list of strings. 2583 Args passed by shell to XEmacs, as a list of strings.
2560 */ ); 2584 */ );
2582 "installed locations, but we can find them\n" 2606 "installed locations, but we can find them\n"
2583 "near where the XEmacs executable was found."); 2607 "near where the XEmacs executable was found.");
2584 #endif 2608 #endif
2585 2609
2586 DEFVAR_LISP ("system-type", &Vsystem_type /* 2610 DEFVAR_LISP ("system-type", &Vsystem_type /*
2587 Value is symbol indicating type of operating system you are using. 2611 Symbol indicating type of operating system you are using.
2588 */ ); 2612 */ );
2589 Vsystem_type = intern (SYSTEM_TYPE); 2613 Vsystem_type = intern (SYSTEM_TYPE);
2590 Fprovide (intern(SYSTEM_TYPE)); 2614 Fprovide (intern(SYSTEM_TYPE));
2591 2615
2592 #ifndef EMACS_CONFIGURATION 2616 #ifndef EMACS_CONFIGURATION
2593 # define EMACS_CONFIGURATION "UNKNOWN" 2617 # define EMACS_CONFIGURATION "UNKNOWN"
2594 #endif 2618 #endif
2595 DEFVAR_LISP ("system-configuration", &Vsystem_configuration /* 2619 DEFVAR_LISP ("system-configuration", &Vsystem_configuration /*
2596 Value is string indicating configuration XEmacs was built for. 2620 String naming the configuration XEmacs was built for.
2597 */ ); 2621 */ );
2598 Vsystem_configuration = Fpurecopy (build_string (EMACS_CONFIGURATION)); 2622 Vsystem_configuration = Fpurecopy (build_string (EMACS_CONFIGURATION));
2599 2623
2600 #ifndef EMACS_CONFIG_OPTIONS 2624 #ifndef EMACS_CONFIG_OPTIONS
2601 # define EMACS_CONFIG_OPTIONS "UNKNOWN" 2625 # define EMACS_CONFIG_OPTIONS "UNKNOWN"