Permalink
Browse files

Attempt to fix ns_do_applescript crash

Create NSString object rather than storing a reference to a Lisp_Object, which may get
invalidated by the garbage collector before execution has finished

Conflicts:
	src/nsfns.m
  • Loading branch information...
1 parent db9ec52 commit e7ee0d5059eca359377293ca35a36c69a092081d @davidswelt committed Oct 20, 2012
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/nsfns.m
View
@@ -104,9 +104,11 @@ Updated by Christian Limpach (chris@nice.ch)
extern BOOL ns_in_resize;
/* Static variables to handle applescript execution. */
-static Lisp_Object as_script, *as_result;
+static NSString *as_script;
+static Lisp_Object *as_result;
static int as_status;
+
/* ==========================================================================
Internal utility functions
@@ -1999,7 +2001,6 @@ cons cell of form (beginning . length), or nil if all
// [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
UNBLOCK_INPUT;
-
return Qnil;
}
@@ -2603,19 +2604,18 @@ and GNUstep implementations ("distributor-specific release
string or a number containing the resulting script value. Otherwise,
1 is returned. */
static int
-ns_do_applescript (script, result)
- Lisp_Object script, *result;
+ns_do_applescript (NSString* script, Lisp_Object *result)
{
NSAppleEventDescriptor *desc;
NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;
NSAppleScript* scriptObject =
- [[NSAppleScript alloc] initWithSource:
- [NSString stringWithUTF8String: SDATA (script)]];
+ [[NSAppleScript alloc] initWithSource: script];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
[scriptObject release];
+ [script release];
*result = Qnil;
@@ -2685,7 +2685,10 @@ and GNUstep implementations ("distributor-specific release
BLOCK_INPUT;
GCPRO1 (script);
- as_script = script;
+ as_script = [[NSString stringWithUTF8String: SDATA (script)] retain];
+ // as_script is released explicitly by ns_do_applescript, so
+ // we retain it here
+
as_result = &result;
/* executing apple script requires the event loop to run, otherwise

0 comments on commit e7ee0d5

Please sign in to comment.