emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r105446: Fix that executing applescri


From: Jan D.
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105446: Fix that executing applescript may hang emacs uninterruptedly.
Date: Sun, 14 Aug 2011 12:39:38 +0200
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105446
fixes bug(s): http://debbugs.gnu.org/7276
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Sun 2011-08-14 12:39:38 +0200
message:
  Fix that executing applescript may hang emacs uninterruptedly.
  
  * nsfns.m (as_script, as_result, as_status): New static variables.
  (ns_run_ascript): New function.
  (Fns_do_applescript): Set variables as_*. Make an NSApplicationDefined
  event with data2 set to NSAPP_DATA2_RUNASSCRIPT, post it and then start
  the event loop.  Get status from as_status.
  
  * nsterm.h (ns_run_ascript): Declare.
  (NSAPP_DATA2_RUNASSCRIPT): Define.
  
  * nsterm.m (sendEvent): If event is NSApplicationDefined and
  data2 is NSAPP_DATA2_RUNASSCRIPT, call ns_run_ascript and then exit
  the event loop (Bug#7276).
modified:
  src/ChangeLog
  src/nsfns.m
  src/nsterm.h
  src/nsterm.m
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2011-08-14 09:08:02 +0000
+++ b/src/ChangeLog     2011-08-14 10:39:38 +0000
@@ -1,3 +1,18 @@
+2011-08-14  Jan Djärv  <address@hidden>
+
+       * nsterm.h (ns_run_ascript): Declare.
+       (NSAPP_DATA2_RUNASSCRIPT): Define.
+
+       * nsfns.m (as_script, as_result, as_status): New static variables.
+       (ns_run_ascript): New function.
+       (Fns_do_applescript): Set variables as_*. Make an NSApplicationDefined
+       event with data2 set to NSAPP_DATA2_RUNASSCRIPT, post it and then start
+       the event loop.  Get status from as_status (Bug#7276).
+
+       * nsterm.m (sendEvent): If event is NSApplicationDefined and
+       data2 is NSAPP_DATA2_RUNASSCRIPT, call ns_run_ascript and then exit
+       the event loop (Bug#7276).
+
 2011-08-14  Andreas Schwab  <address@hidden>
 
        * gnutls.c (QCgnutls_bootprop_priority)

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2011-07-28 18:29:09 +0000
+++ b/src/nsfns.m       2011-08-14 10:39:38 +0000
@@ -97,6 +97,9 @@
 
 extern BOOL ns_in_resize;
 
+/* Static variables to handle applescript execution.  */
+static Lisp_Object as_script, *as_result;
+static int as_status;
 
 /* ==========================================================================
 
@@ -2052,6 +2055,15 @@
   return 0;
 }
 
+/* Helper function called from sendEvent to run applescript
+   from within the main event loop.  */
+
+void
+ns_run_ascript (void)
+{
+  as_status = ns_do_applescript (as_script, as_result);
+}
+
 DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
        doc: /* Execute AppleScript SCRIPT and return the result.
 If compilation and execution are successful, the resulting script value
@@ -2061,12 +2073,37 @@
 {
   Lisp_Object result;
   int status;
+  NSEvent *nxev;
 
   CHECK_STRING (script);
   check_ns ();
 
   BLOCK_INPUT;
-  status = ns_do_applescript (script, &result);
+
+  as_script = script;
+  as_result = &result;
+
+  /* executing apple script requires the event loop to run, otherwise
+     errors aren't returned and executeAndReturnError hangs forever.
+     Post an event that runs applescript and then start the event loop.
+     The event loop is exited when the script is done.  */
+  nxev = [NSEvent otherEventWithType: NSApplicationDefined
+                            location: NSMakePoint (0, 0)
+                       modifierFlags: 0
+                           timestamp: 0
+                        windowNumber: [[NSApp mainWindow] windowNumber]
+                             context: [NSApp context]
+                             subtype: 0
+                               data1: 0
+                               data2: NSAPP_DATA2_RUNASSCRIPT];
+
+  [NSApp postEvent: nxev atStart: NO];
+  [NSApp run];
+
+  status = as_status;
+  as_status = 0;
+  as_script = Qnil;
+  as_result = 0;
   UNBLOCK_INPUT;
   if (status == 0)
     return result;
@@ -2670,4 +2707,7 @@
   /* used only in fontset.c */
   check_window_system_func = check_ns;
 
+  as_status = 0;
+  as_script = Qnil;
+  as_result = 0;
 }

=== modified file 'src/nsterm.h'
--- a/src/nsterm.h      2011-07-28 18:50:05 +0000
+++ b/src/nsterm.h      2011-08-14 10:39:38 +0000
@@ -795,6 +795,9 @@
 extern void x_activate_menubar (struct frame *);
 extern void free_frame_menubar (struct frame *);
 
+#define NSAPP_DATA2_RUNASSCRIPT 10
+extern void ns_run_ascript (void);
+
 extern void ns_init_paths (void);
 extern void syms_of_nsterm (void);
 extern void syms_of_nsfns (void);

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2011-07-28 18:41:21 +0000
+++ b/src/nsterm.m      2011-08-14 10:39:38 +0000
@@ -4257,6 +4257,16 @@
 /*  NSTRACE (sendEvent); */
 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
 
+#ifdef NS_IMPL_COCOA
+  if (type == NSApplicationDefined
+      && [theEvent data2] == NSAPP_DATA2_RUNASSCRIPT)
+    {
+      ns_run_ascript ();
+      [self stop: self];
+      return;
+    }
+#endif
+
   if (type == NSCursorUpdate && window == nil)
     {
       fprintf (stderr, "Dropping external cursor update event.\n");


reply via email to

[Prev in Thread] Current Thread [Next in Thread]