*** empty log message ***
[bpt/emacs.git] / src / emacs.c
index a6d3356..cdc80ae 100644 (file)
@@ -1,6 +1,6 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985,86,87,93,94,95,97,98,1999,2001,02,03,2004
-      Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2001,
+     2002, 2003, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -42,6 +42,8 @@ Boston, MA 02111-1307, USA.  */
 
 #ifdef WINDOWSNT
 #include <fcntl.h>
+#include <windows.h> /* just for w32.h */
+#include "w32.h"
 #endif
 
 #include "lisp.h"
@@ -342,6 +344,14 @@ int fatal_error_in_progress;
 
 void (*fatal_error_signal_hook) P_ ((void));
 
+#ifdef HAVE_GTK_AND_PTHREAD
+/* When compiled with GTK and running under Gnome, multiple threads meay be
+   created.  Keep track of our main thread to make sure signals are delivered
+   to it (see syssignal.h).  */
+
+pthread_t main_thread;
+#endif
+
 
 #ifdef SIGUSR1
 SIGTYPE
@@ -350,6 +360,7 @@ handle_USR1_signal (sig)
 {
   struct input_event buf;
 
+  SIGNAL_THREAD_CHECK (sig);
   bzero (&buf, sizeof buf);
   buf.kind = USER_SIGNAL_EVENT;
   buf.frame_or_window = selected_frame;
@@ -365,6 +376,7 @@ handle_USR2_signal (sig)
 {
   struct input_event buf;
 
+  SIGNAL_THREAD_CHECK (sig);
   bzero (&buf, sizeof buf);
   buf.kind = USER_SIGNAL_EVENT;
   buf.code = 1;
@@ -379,6 +391,7 @@ SIGTYPE
 fatal_error_signal (sig)
      int sig;
 {
+  SIGNAL_THREAD_CHECK (sig);
   fatal_error_code = sig;
   signal (sig, SIG_DFL);
 
@@ -418,6 +431,7 @@ memory_warning_signal (sig)
      int sig;
 {
   signal (sig, memory_warning_signal);
+  SIGNAL_THREAD_CHECK (sig);
 
   malloc_warning ("Operating system warns that virtual memory is running low.\n");
 
@@ -584,7 +598,7 @@ init_cmdargs (argc, argv, skip_args)
           They are decoded in the function command-line after we know
           locale-coding-system.  */
        Vcommand_line_args
-         = Fcons (make_unibyte_string (argv[i], strlen (argv[i])), 
+         = Fcons (make_unibyte_string (argv[i], strlen (argv[i])),
                   Vcommand_line_args);
     }
 
@@ -748,7 +762,9 @@ malloc_initialize_hook ()
        }
 
       malloc_set_state (malloc_state_ptr);
+#ifndef XMALLOC_OVERRUN_CHECK
       free (malloc_state_ptr);
+#endif
     }
   else
     {
@@ -1021,10 +1037,16 @@ main (argc, argv
      Also call realloc and free for consistency.  */
   free (realloc (malloc (4), 4));
 
+# ifndef SYNC_INPUT
   /* Arrange to disable interrupt input inside malloc etc.  */
   uninterrupt_malloc ();
+# endif /* not SYNC_INPUT */
 #endif /* not SYSTEM_MALLOC */
 
+#ifdef HAVE_GTK_AND_PTHREAD
+  main_thread = pthread_self ();
+#endif /* HAVE_GTK_AND_PTHREAD */
+
 #if defined (MSDOS) || defined (WINDOWSNT)
   /* We do all file input/output as binary files.  When we need to translate
      newlines, we do that manually.  */
@@ -1113,7 +1135,10 @@ main (argc, argv
   /* Handle the -batch switch, which means don't do interactive display.  */
   noninteractive = 0;
   if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
-    noninteractive = 1;
+    {
+      noninteractive = 1;
+      Vundo_outer_limit = Qnil;
+    }
   if (argmatch (argv, argc, "-script", "--script", 3, &junk, &skip_args))
     {
       noninteractive = 1;      /* Set batch mode.  */
@@ -1283,7 +1308,7 @@ main (argc, argv
          creates a full-fledge output_mac type frame.  This does not
          work correctly before syms_of_textprop, syms_of_macfns,
          syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search,
-         syms_of_frame, mac_initialize, and init_keyboard have already
+         syms_of_frame, mac_term_init, and init_keyboard have already
          been called.  */
       syms_of_textprop ();
       syms_of_macfns ();
@@ -1295,7 +1320,7 @@ main (argc, argv
       syms_of_search ();
       syms_of_frame ();
 
-      mac_initialize ();
+      mac_term_init (build_string ("Mac"), NULL, NULL);
       init_keyboard ();
 #endif
 
@@ -1631,6 +1656,7 @@ main (argc, argv
 #ifdef HAVE_NTGUI
       globals_of_w32fns ();
       globals_of_w32menu ();
+      globals_of_w32select ();
 #endif  /* HAVE_NTGUI */
     }
 
@@ -1984,9 +2010,9 @@ sort_args (argc, argv)
 
   bcopy (new, argv, sizeof (char *) * argc);
 
-  free (options);
-  free (new);
-  free (priority);
+  xfree (options);
+  xfree (new);
+  xfree (priority);
 }
 \f
 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
@@ -2236,6 +2262,12 @@ You must run Emacs in batch mode in order to dump it.  */)
   memory_warnings (my_edata, malloc_warning);
 #endif /* not WINDOWSNT */
 #endif
+#if !defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) && !defined SYNC_INPUT
+  /* Pthread may call malloc before main, and then we will get an endless
+     loop, because pthread_self (see alloc.c) calls malloc the first time
+     it is called on some systems.  */
+  reset_malloc_hooks ();
+#endif
 #ifdef DOUG_LEA_MALLOC
   malloc_state_ptr = malloc_get_state ();
 #endif
@@ -2401,7 +2433,16 @@ syms_of_emacs ()
 Many arguments are deleted from the list as they are processed.  */);
 
   DEFVAR_LISP ("system-type", &Vsystem_type,
-              doc: /* Value is symbol indicating type of operating system you are using.  */);
++             doc: /* Value is symbol indicating type of operating system you are using.
++Special values:
++  `gnu/linux'   compiled for a GNU/Linux system.
++  `darwin'      compiled for Darwin (GNU-Darwin, Mac OS X, ...).
++  `macos'       compiled for Mac OS 9.
++  `ms-dos'      compiled as an MS-DOS application.
++  `windows-nt'  compiled as a native W32 application.
++  `cygwin'      compiled using the Cygwin library.
++  `vax-vms' or `axp-vms': compiled for a (Open)VMS system.
++Anything else indicates some sort of Unix system.  */);
   Vsystem_type = intern (SYSTEM_TYPE);
 
   DEFVAR_LISP ("system-configuration", &Vsystem_configuration,