]> code.delx.au - gnu-emacs/blobdiff - src/mac.c
Merge from emacs--devo--0
[gnu-emacs] / src / mac.c
index be6953a0d5538519d502530a67f08c7e37160a94..9c1a08075f85176491eabf62c97eb317dd6f4a2e 100644 (file)
--- a/src/mac.c
+++ b/src/mac.c
@@ -1,12 +1,12 @@
 /* Unix emulation routines for GNU Emacs on the Mac OS.
    Copyright (C) 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006 Free Software Foundation, Inc.
+                 2005, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -79,6 +79,17 @@ static ComponentInstance as_scripting_component;
 /* The single script context used for all script executions.  */
 static OSAID as_script_context;
 
+#ifndef MAC_OS_X
+#if TARGET_API_MAC_CARBON
+static int wakeup_from_rne_enabled_p = 0;
+#define ENABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 1)
+#define DISABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 0)
+#else
+#define ENABLE_WAKEUP_FROM_RNE 0
+#define DISABLE_WAKEUP_FROM_RNE 0
+#endif
+#endif
+
 #ifndef MAC_OSX
 static OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *));
 static OSErr fsspec_to_posix_pathname P_ ((const FSSpec *, char *, int));
@@ -835,8 +846,8 @@ OSStatus
 create_apple_event_from_event_ref (event, num_params, names, types, result)
      EventRef event;
      UInt32 num_params;
-     EventParamName *names;
-     EventParamType *types;
+     const EventParamName *names;
+     const EventParamType *types;
      AppleEvent *result;
 {
   OSStatus err;
@@ -891,7 +902,7 @@ OSErr
 create_apple_event_from_drag_ref (drag, num_types, types, result)
      DragRef drag;
      UInt32 num_types;
-     FlavorType *types;
+     const FlavorType *types;
      AppleEvent *result;
 {
   OSErr err;
@@ -1118,18 +1129,15 @@ Lisp_Object
 cfdate_to_lisp (date)
      CFDateRef date;
 {
-  static const CFGregorianDate epoch_gdate = {1970, 1, 1, 0, 0, 0.0};
-  static CFAbsoluteTime epoch = 0.0, sec;
-  int high, low;
+  CFTimeInterval sec;
+  int high, low, microsec;
 
-  if (epoch == 0.0)
-    epoch = CFGregorianDateGetAbsoluteTime (epoch_gdate, NULL);
-
-  sec = CFDateGetAbsoluteTime (date) - epoch;
+  sec = CFDateGetAbsoluteTime (date) + kCFAbsoluteTimeIntervalSince1970;
   high = sec / 65536.0;
   low = sec - high * 65536.0;
+  microsec = (sec - floor (sec)) * 1000000.0;
 
-  return list3 (make_number (high), make_number (low), make_number (0));
+  return list3 (make_number (high), make_number (low), make_number (microsec));
 }
 
 
@@ -1315,7 +1323,7 @@ cfproperty_list_to_lisp (plist, with_tag, hash_bound)
 
 static void
 skip_white_space (p)
-     char **p;
+     const char **p;
 {
   /* WhiteSpace = {<space> | <horizontal tab>} */
   while (*P == ' ' || *P == '\t')
@@ -1324,7 +1332,7 @@ skip_white_space (p)
 
 static int
 parse_comment (p)
-     char **p;
+     const char **p;
 {
   /* Comment = "!" {<any character except null or newline>} */
   if (*P == '!')
@@ -1342,7 +1350,7 @@ parse_comment (p)
 /* Don't interpret filename.  Just skip until the newline.  */
 static int
 parse_include_file (p)
-     char **p;
+     const char **p;
 {
   /* IncludeFile = "#" WhiteSpace "include" WhiteSpace FileName WhiteSpace */
   if (*P == '#')
@@ -1359,7 +1367,7 @@ parse_include_file (p)
 
 static char
 parse_binding (p)
-     char **p;
+     const char **p;
 {
   /* Binding = "." | "*"  */
   if (*P == '.' || *P == '*')
@@ -1377,7 +1385,7 @@ parse_binding (p)
 
 static Lisp_Object
 parse_component (p)
-     char **p;
+     const char **p;
 {
   /*  Component = "?" | ComponentName
       ComponentName = NameChar {NameChar}
@@ -1389,7 +1397,7 @@ parse_component (p)
     }
   else if (isalnum (*P) || *P == '_' || *P == '-')
     {
-      char *start = P++;
+      const char *start = P++;
 
       while (isalnum (*P) || *P == '_' || *P == '-')
        P++;
@@ -1402,7 +1410,7 @@ parse_component (p)
 
 static Lisp_Object
 parse_resource_name (p)
-     char **p;
+     const char **p;
 {
   Lisp_Object result = Qnil, component;
   char binding;
@@ -1436,7 +1444,7 @@ parse_resource_name (p)
 
 static Lisp_Object
 parse_value (p)
-     char **p;
+     const char **p;
 {
   char *q, *buf;
   Lisp_Object seq = Qnil, result;
@@ -1526,7 +1534,7 @@ parse_value (p)
 
 static Lisp_Object
 parse_resource_line (p)
-     char **p;
+     const char **p;
 {
   Lisp_Object quarks, value;
 
@@ -1629,7 +1637,7 @@ xrm_q_put_resource (database, quarks, value)
 void
 xrm_merge_string_database (database, data)
      XrmDatabase database;
-     char *data;
+     const char *data;
 {
   Lisp_Object quarks_value;
 
@@ -1705,7 +1713,7 @@ xrm_q_get_resource (database, quark_name, quark_class)
 Lisp_Object
 xrm_get_resource (database, name, class)
      XrmDatabase database;
-     char *name, *class;
+     const char *name, *class;
 {
   Lisp_Object key, query_cache, quark_name, quark_class, tmp;
   int i, nn, nc;
@@ -1794,7 +1802,7 @@ xrm_cfproperty_list_to_value (plist)
 
 XrmDatabase
 xrm_get_preference_database (application)
-     char *application;
+     const char *application;
 {
 #if TARGET_API_MAC_CARBON
   CFStringRef app_id, *keys, user_doms[2], host_doms[2];
@@ -1817,8 +1825,6 @@ xrm_get_preference_database (application)
 
   GCPRO3 (database, quarks, value);
 
-  BLOCK_INPUT;
-
   app_id = kCFPreferencesCurrentApplication;
   if (application)
     {
@@ -1826,6 +1832,8 @@ xrm_get_preference_database (application)
       if (app_id == NULL)
        goto out;
     }
+  if (!CFPreferencesAppSynchronize (app_id))
+    goto out;
 
   key_set = CFSetCreateMutable (NULL, 0, &kCFCopyStringSetCallBacks);
   if (key_set == NULL)
@@ -1868,8 +1876,6 @@ xrm_get_preference_database (application)
     CFRelease (key_set);
   CFRelease (app_id);
 
-  UNBLOCK_INPUT;
-
   UNGCPRO;
 
   return database;
@@ -2252,7 +2258,7 @@ sys_open (const char *path, int oflag)
       int res = open (mac_pathname, oflag);
       /* if (oflag == O_WRONLY || oflag == O_RDWR) */
       if (oflag & O_CREAT)
-        fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
+        fsetfileinfo (mac_pathname, MAC_EMACS_CREATOR_CODE, 'TEXT');
       return res;
 #else /* not __MRC__ */
       return open (mac_pathname, oflag);
@@ -2278,7 +2284,7 @@ sys_creat (const char *path, mode_t mode)
     {
 #ifdef __MRC__
       int result = creat (mac_pathname);
-      fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
+      fsetfileinfo (mac_pathname, MAC_EMACS_CREATOR_CODE, 'TEXT');
       return result;
 #else /* not __MRC__ */
       return creat (mac_pathname, mode);
@@ -2406,7 +2412,7 @@ sys_fopen (const char *name, const char *mode)
     {
 #ifdef __MRC__
       if (mode[0] == 'w' || mode[0] == 'a')
-        fsetfileinfo (mac_pathname, 'EMAx', 'TEXT');
+        fsetfileinfo (mac_pathname, MAC_EMACS_CREATOR_CODE, 'TEXT');
 #endif /* not __MRC__ */
       return fopen (mac_pathname, mode);
     }
@@ -2431,6 +2437,7 @@ select (nfds, rfds, wfds, efds, timeout)
      BLOCK_INPUT block, in case that some input has already been read
      asynchronously.  */
   BLOCK_INPUT;
+  ENABLE_WAKEUP_FROM_RNE;
   if (!detect_input_pending ())
     {
 #if TARGET_API_MAC_CARBON
@@ -2461,6 +2468,7 @@ select (nfds, rfds, wfds, efds, timeout)
        }
 #endif /* not TARGET_API_MAC_CARBON */
     }
+  DISABLE_WAKEUP_FROM_RNE;
   UNBLOCK_INPUT;
 
   if (err == noErr)
@@ -4305,7 +4313,7 @@ assumed. Return non-nil if successful.  */)
   OSType cCode;
   CHECK_STRING (filename);
 
-  cCode = mac_get_code_from_arg(code, 'EMAx');
+  cCode = mac_get_code_from_arg(code, MAC_EMACS_CREATOR_CODE);
 
   if (NILP(Ffile_exists_p(filename)) || !NILP(Ffile_directory_p(filename))) {
     return Qnil;
@@ -4611,6 +4619,7 @@ otherwise.  */)
   CFStringRef app_id, key_str;
   CFPropertyListRef app_plist = NULL, plist;
   Lisp_Object result = Qnil, tmp;
+  struct gcpro gcpro1, gcpro2;
 
   if (STRINGP (key))
     key = Fcons (key, Qnil);
@@ -4627,6 +4636,8 @@ otherwise.  */)
   if (!NILP (hash_bound))
     CHECK_NUMBER (hash_bound);
 
+  GCPRO2 (key, format);
+
   BLOCK_INPUT;
 
   app_id = kCFPreferencesCurrentApplication;
@@ -4636,6 +4647,9 @@ otherwise.  */)
       if (app_id == NULL)
        goto out;
     }
+  if (!CFPreferencesAppSynchronize (app_id))
+    goto out;
+
   key_str = cfstring_create_with_string (XCAR (key));
   if (key_str == NULL)
     goto out;
@@ -4681,6 +4695,8 @@ otherwise.  */)
 
   UNBLOCK_INPUT;
 
+  UNGCPRO;
+
   return result;
 }
 
@@ -4836,8 +4852,8 @@ DEFUN ("mac-code-convert-string", Fmac_code_convert_string, Smac_code_convert_st
        doc: /* Convert STRING from SOURCE encoding to TARGET encoding.
 The conversion is performed using the converter provided by the system.
 Each encoding is specified by either a coding system symbol, a mime
-charset string, or an integer as a CFStringEncoding value.  Nil for
-encoding means UTF-16 in native byte order, no byte order mark.
+charset string, or an integer as a CFStringEncoding value.  An encoding
+of nil means UTF-16 in native byte order, no byte order mark.
 On Mac OS X 10.2 and later, you can do Unicode Normalization by
 specifying the optional argument NORMALIZATION-FORM with a symbol NFD,
 NFKD, NFC, NFKC, HFS+D, or HFS+C.
@@ -4846,6 +4862,7 @@ On successful conversion, return the result string, else return nil.  */)
      Lisp_Object string, source, target, normalization_form;
 {
   Lisp_Object result = Qnil;
+  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   CFStringEncoding src_encoding, tgt_encoding;
   CFStringRef str = NULL;
 
@@ -4856,6 +4873,8 @@ On successful conversion, return the result string, else return nil.  */)
     CHECK_SYMBOL (target);
   CHECK_SYMBOL (normalization_form);
 
+  GCPRO4 (string, source, target, normalization_form);
+
   BLOCK_INPUT;
 
   src_encoding = get_cfstring_encoding_from_lisp (source);
@@ -4896,6 +4915,8 @@ On successful conversion, return the result string, else return nil.  */)
 
   UNBLOCK_INPUT;
 
+  UNGCPRO;
+
   return result;
 }
 
@@ -4965,11 +4986,11 @@ extern int noninteractive;
    3. [If SELECT_USE_CFSOCKET is set]
       Only the window event channel and socket read/write channels are
       involved, and timeout is not too short (greater than
-      SELECT_TIMEOUT_THRESHHOLD_RUNLOOP seconds).
+      SELECT_TIMEOUT_THRESHOLD_RUNLOOP seconds).
       -> Create CFSocket for each socket and add it into the current
          event RunLoop so that the current event loop gets quit when
-         the socket becomes ready.  Then ReceiveNextEvent can wait for
-         both kinds of inputs.
+         the socket becomes ready.  Then CFRunLoopRunInMode can wait
+         for both kinds of inputs.
    4. Otherwise.
       -> Periodically poll the window input channel while repeatedly
          executing `select' with a short timeout
@@ -4983,6 +5004,10 @@ extern int noninteractive;
 #if SELECT_USE_CFSOCKET
 #define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2
 
+/* Dictionary of file descriptors vs CFSocketRef's allocated in
+   sys_select.  */
+static CFMutableDictionaryRef cfsockets_for_select;
+
 static void
 socket_callback (s, type, address, data, info)
      CFSocketRef s;
@@ -4991,12 +5016,6 @@ socket_callback (s, type, address, data, info)
      const void *data;
      void *info;
 {
-  int fd = CFSocketGetNative (s);
-  SELECT_TYPE *ofds = (SELECT_TYPE *)info;
-
-  if ((type == kCFSocketReadCallBack && FD_ISSET (fd, &ofds[0]))
-      || (type == kCFSocketConnectCallBack && FD_ISSET (fd, &ofds[1])))
-    QuitEventLoop (GetCurrentEventLoop ());
 }
 #endif /* SELECT_USE_CFSOCKET */
 
@@ -5006,40 +5025,64 @@ select_and_poll_event (nfds, rfds, wfds, efds, timeout)
      SELECT_TYPE *rfds, *wfds, *efds;
      EMACS_TIME *timeout;
 {
-  OSStatus err = noErr;
+  int timedout_p = 0;
   int r = 0;
+  EMACS_TIME select_timeout;
+  EventTimeout timeoutval =
+    (timeout
+     ? (EMACS_SECS (*timeout) * kEventDurationSecond
+       + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
+     : kEventDurationForever);
+  SELECT_TYPE orfds, owfds, oefds;
 
-  /* Try detect_input_pending before ReceiveNextEvent in the same
+  if (timeout == NULL)
+    {
+      if (rfds) orfds = *rfds;
+      if (wfds) owfds = *wfds;
+      if (efds) oefds = *efds;
+    }
+
+  /* Try detect_input_pending before CFRunLoopRunInMode in the same
      BLOCK_INPUT block, in case that some input has already been read
      asynchronously.  */
   BLOCK_INPUT;
-  if (!detect_input_pending ())
+  while (1)
     {
-      EMACS_TIME select_timeout;
-      EventTimeout timeoutval =
-       (timeout
-        ? (EMACS_SECS (*timeout) * kEventDurationSecond
-           + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
-        : kEventDurationForever);
+      if (detect_input_pending ())
+       break;
 
       EMACS_SET_SECS_USECS (select_timeout, 0, 0);
       r = select (nfds, rfds, wfds, efds, &select_timeout);
+      if (r != 0)
+       break;
+
       if (timeoutval == 0.0)
-       err = eventLoopTimedOutErr;
-      else if (r == 0)
+       timedout_p = 1;
+      else
        {
 #if USE_CG_DRAWING
          mac_prepare_for_quickdraw (NULL);
 #endif
-         err = ReceiveNextEvent (0, NULL, timeoutval,
-                                 kEventLeaveInQueue, NULL);
+         if (CFRunLoopRunInMode (kCFRunLoopDefaultMode,
+                                 timeoutval >= 0 ? timeoutval : 100000, true)
+             == kCFRunLoopRunTimedOut)
+           timedout_p = 1;
        }
+
+      if (timeout == NULL && timedout_p)
+       {
+         if (rfds) *rfds = orfds;
+         if (wfds) *wfds = owfds;
+         if (efds) *efds = oefds;
+       }
+      else
+       break;
     }
   UNBLOCK_INPUT;
 
   if (r != 0)
     return r;
-  else if (err == noErr)
+  else if (!timedout_p)
     {
       /* Pretend that `select' is interrupted by a signal.  */
       detect_input_pending ();
@@ -5050,31 +5093,68 @@ select_and_poll_event (nfds, rfds, wfds, efds, timeout)
     return 0;
 }
 
+/* Clean up the CFSocket associated with the file descriptor FD in
+   case the same descriptor is used in other threads later.  If no
+   CFSocket is associated with FD, then return 0 without closing FD.
+   Otherwise, return 1 with closing FD.  */
+
+int
+mac_try_close_socket (fd)
+     int fd;
+{
+#if SELECT_USE_CFSOCKET
+  if (cfsockets_for_select)
+    {
+      void *key = (void *) fd;
+      CFSocketRef socket =
+       (CFSocketRef) CFDictionaryGetValue (cfsockets_for_select, key);
+
+      if (socket)
+       {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+         CFOptionFlags flags = CFSocketGetSocketFlags (socket);
+
+         if (!(flags & kCFSocketCloseOnInvalidate))
+           CFSocketSetSocketFlags (socket, flags | kCFSocketCloseOnInvalidate);
+#endif
+         BLOCK_INPUT;
+         CFSocketInvalidate (socket);
+         CFDictionaryRemoveValue (cfsockets_for_select, key);
+         UNBLOCK_INPUT;
+
+         return 1;
+       }
+    }
+#endif
+
+  return 0;
+}
+
 int
 sys_select (nfds, rfds, wfds, efds, timeout)
      int nfds;
      SELECT_TYPE *rfds, *wfds, *efds;
      EMACS_TIME *timeout;
 {
-  OSStatus err = noErr;
+  int timedout_p = 0;
   int r;
   EMACS_TIME select_timeout;
-  static SELECT_TYPE ofds[3];
+  SELECT_TYPE orfds, owfds, oefds;
 
   if (inhibit_window_system || noninteractive
       || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds))
     return select (nfds, rfds, wfds, efds, timeout);
 
   FD_CLR (0, rfds);
-  ofds[0] = *rfds;
+  orfds = *rfds;
 
   if (wfds)
-    ofds[1] = *wfds;
+    owfds = *wfds;
   else
-    FD_ZERO (&ofds[1]);
+    FD_ZERO (&owfds);
 
   if (efds)
-    ofds[2] = *efds;
+    oefds = *efds;
   else
     {
       EventTimeout timeoutval =
@@ -5102,24 +5182,23 @@ sys_select (nfds, rfds, wfds, efds, timeout)
       if (r != 0 || timeoutval == 0.0)
        return r;
 
-      *rfds = ofds[0];
+      *rfds = orfds;
       if (wfds)
-       *wfds = ofds[1];
+       *wfds = owfds;
 
 #if SELECT_USE_CFSOCKET
       if (timeoutval > 0 && timeoutval <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP)
        goto poll_periodically;
 
-      /* Try detect_input_pending before ReceiveNextEvent in the same
-        BLOCK_INPUT block, in case that some input has already been
-        read asynchronously.  */
+      /* Try detect_input_pending before CFRunLoopRunInMode in the
+        same BLOCK_INPUT block, in case that some input has already
+        been read asynchronously.  */
       BLOCK_INPUT;
       if (!detect_input_pending ())
        {
          int minfd, fd;
          CFRunLoopRef runloop =
            (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ());
-         static CFSocketContext context = {0, ofds, NULL, NULL, NULL};
          static CFMutableDictionaryRef sources;
 
          if (sources == NULL)
@@ -5127,6 +5206,11 @@ sys_select (nfds, rfds, wfds, efds, timeout)
              CFDictionaryCreateMutable (NULL, 0, NULL,
                                         &kCFTypeDictionaryValueCallBacks);
 
+         if (cfsockets_for_select == NULL)
+           cfsockets_for_select =
+             CFDictionaryCreateMutable (NULL, 0, NULL,
+                                        &kCFTypeDictionaryValueCallBacks);
+
          for (minfd = 1; ; minfd++) /* nfds-1 works as a sentinel.  */
            if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds)))
              break;
@@ -5138,21 +5222,22 @@ sys_select (nfds, rfds, wfds, efds, timeout)
                CFRunLoopSourceRef source =
                  (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key);
 
-               if (source == NULL)
+               if (source == NULL || !CFRunLoopSourceIsValid (source))
                  {
                    CFSocketRef socket =
                      CFSocketCreateWithNative (NULL, fd,
                                                (kCFSocketReadCallBack
                                                 | kCFSocketConnectCallBack),
-                                               socket_callback, &context);
+                                               socket_callback, NULL);
 
                    if (socket == NULL)
                      continue;
+                   CFDictionarySetValue (cfsockets_for_select, key, socket);
                    source = CFSocketCreateRunLoopSource (NULL, socket, 0);
                    CFRelease (socket);
                    if (source == NULL)
                      continue;
-                   CFDictionaryAddValue (sources, key, source);
+                   CFDictionarySetValue (sources, key, source);
                    CFRelease (source);
                  }
                CFRunLoopAddSource (runloop, source, kCFRunLoopDefaultMode);
@@ -5161,8 +5246,10 @@ sys_select (nfds, rfds, wfds, efds, timeout)
 #if USE_CG_DRAWING
          mac_prepare_for_quickdraw (NULL);
 #endif
-         err = ReceiveNextEvent (0, NULL, timeoutval,
-                                 kEventLeaveInQueue, NULL);
+         if (CFRunLoopRunInMode (kCFRunLoopDefaultMode,
+                                 timeoutval >= 0 ? timeoutval : 100000, true)
+             == kCFRunLoopRunTimedOut)
+           timedout_p = 1;
 
          for (fd = minfd; fd < nfds; fd++)
            if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds)))
@@ -5176,7 +5263,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
        }
       UNBLOCK_INPUT;
 
-      if (err == noErr || err == eventLoopQuitErr)
+      if (!timedout_p)
        {
          EMACS_SET_SECS_USECS (select_timeout, 0, 0);
          return select_and_poll_event (nfds, rfds, wfds, efds,
@@ -5212,11 +5299,11 @@ sys_select (nfds, rfds, wfds, efds, timeout)
        if (r != 0)
          return r;
 
-       *rfds = ofds[0];
+       *rfds = orfds;
        if (wfds)
-         *wfds = ofds[1];
+         *wfds = owfds;
        if (efds)
-         *efds = ofds[2];
+         *efds = oefds;
 
        if (timeout)
          {
@@ -5292,8 +5379,8 @@ init_mac_osx_environment ()
   /* P should have sufficient room for the pathname of the bundle plus
      the subpath in it leading to the respective directories.  Q
      should have three times that much room because EMACSLOADPATH can
-     have the value "<path to lisp dir>:<path to leim dir>:<path to
-     site-lisp dir>".  */
+     have the value "<path to site-lisp dir>:<path to lisp dir>:<path
+     to leim dir>".  */
   p = (char *) alloca (app_bundle_pathname_len + 50);
   q = (char *) alloca (3 * app_bundle_pathname_len + 150);
   if (!getenv ("EMACSLOADPATH"))
@@ -5301,12 +5388,12 @@ init_mac_osx_environment ()
       q[0] = '\0';
 
       strcpy (p, app_bundle_pathname);
-      strcat (p, "/Contents/Resources/lisp");
+      strcat (p, "/Contents/Resources/site-lisp");
       if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
        strcat (q, p);
 
       strcpy (p, app_bundle_pathname);
-      strcat (p, "/Contents/Resources/leim");
+      strcat (p, "/Contents/Resources/lisp");
       if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
        {
          if (q[0] != '\0')
@@ -5315,7 +5402,7 @@ init_mac_osx_environment ()
        }
 
       strcpy (p, app_bundle_pathname);
-      strcat (p, "/Contents/Resources/site-lisp");
+      strcat (p, "/Contents/Resources/leim");
       if (stat (p, &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
        {
          if (q[0] != '\0')
@@ -5375,6 +5462,18 @@ init_mac_osx_environment ()
 }
 #endif /* MAC_OSX */
 
+#if TARGET_API_MAC_CARBON
+void
+mac_wakeup_from_rne ()
+{
+#ifndef MAC_OSX
+  if (wakeup_from_rne_enabled_p)
+    /* Post a harmless event so as to wake up from
+       ReceiveNextEvent.  */
+    mac_post_mouse_moved_event ();
+#endif
+}
+#endif
 
 void
 syms_of_mac ()