Author: rfm
Date: Sun Apr  9 11:56:55 2017
New Revision: 40461

URL: http://svn.gna.org/viewcvs/gnustep?rev=40461&view=rev
Log:
apply bug #49021

Modified:
    libs/base/trunk/ChangeLog
    libs/base/trunk/Headers/Foundation/NSTask.h
    libs/base/trunk/Source/NSTask.m

Modified: libs/base/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=40461&r1=40460&r2=40461&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog   (original)
+++ libs/base/trunk/ChangeLog   Sun Apr  9 11:56:55 2017
@@ -1,3 +1,10 @@
+2017-04-09  Richard Frith-Macdonald <[email protected]>
+
+       * Headers/Foundation/NSTask.h:
+       * Source/NSTask.m:
+       Apply OSX compatibility fix for NSTask notifications (bug #49021)
+       by Larry Campbell.
+
 2017-04-03  Richard Frith-Macdonald <[email protected]>
 
        * Source/NSOperation.m: Fix leak spotted by David Lobron.

Modified: libs/base/trunk/Headers/Foundation/NSTask.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/Foundation/NSTask.h?rev=40461&r1=40460&r2=40461&view=diff
==============================================================================
--- libs/base/trunk/Headers/Foundation/NSTask.h (original)
+++ libs/base/trunk/Headers/Foundation/NSTask.h Sun Apr  9 11:56:55 2017
@@ -36,6 +36,8 @@
 extern "C" {
 #endif
 
+@class  NSThread;
+
 #if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
 enum {
   NSTaskTerminationReasonExit = 1,
@@ -61,6 +63,7 @@
   BOOL         _hasTerminated;
   BOOL         _hasCollected;
   BOOL         _hasNotified;
+  NSThread      *_launchingThread;
   NSTaskTerminationReason       _terminationReason;
 #endif
 #if     GS_NONFRAGILE

Modified: libs/base/trunk/Source/NSTask.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSTask.m?rev=40461&r1=40460&r2=40461&view=diff
==============================================================================
--- libs/base/trunk/Source/NSTask.m     (original)
+++ libs/base/trunk/Source/NSTask.m     Sun Apr  9 11:56:55 2017
@@ -222,6 +222,7 @@
 @interface NSTask (Private)
 - (NSString *) _fullLaunchPath;
 - (void) _collectChild;
+- (void) _notifyOfTermination;
 - (void) _terminatedChild: (int)status reason: (NSTaskTerminationReason)reason;
 @end
 
@@ -317,6 +318,7 @@
   RELEASE(_standardError);
   RELEASE(_standardInput);
   RELEASE(_standardOutput);
+  RELEASE(_launchingThread);
   [super dealloc];
 }
 
@@ -407,10 +409,16 @@
  * Raises an NSInvalidArgumentException if the launch path is not
  * set or if the subtask cannot be started for some reason
  * (eg. the executable does not exist or the task has already been launched).
+ * The actual launching is done in a concrete subclass; this method just
+ * takes care of actions common to all subclasses.
  */
 - (void) launch
 {
-  [self subclassResponsibility: _cmd];
+  if (_launchingThread != [NSThread currentThread])
+    {
+      [_launchingThread release];
+      _launchingThread = [[NSThread currentThread] retain];
+    }
 }
 
 /**
@@ -900,6 +908,22 @@
   [self subclassResponsibility: _cmd];
 }
 
+- (void) _notifyOfTermination
+{
+  NSNotificationQueue   *q;
+  NSNotification        *n;
+
+  n = [NSNotification notificationWithName: NSTaskDidTerminateNotification
+                                    object: self
+                                  userInfo: nil];
+
+  q = [NSNotificationQueue defaultQueue];
+  [q enqueueNotification: n
+            postingStyle: NSPostASAP
+            coalesceMask: NSNotificationNoCoalescing
+                forModes: nil];
+}
+
 - (void) _terminatedChild: (int)status reason: (NSTaskTerminationReason)reason
 {
   [tasksLock lock];
@@ -912,17 +936,18 @@
   _hasTerminated = YES;
   if (_hasNotified == NO)
     {
-      NSNotification   *n;
-
       _hasNotified = YES;
-      n = [NSNotification notificationWithName: NSTaskDidTerminateNotification
-                                       object: self
-                                     userInfo: nil];
-
-      [[NSNotificationQueue defaultQueue] enqueueNotification: n
-                   postingStyle: NSPostASAP
-                   coalesceMask: NSNotificationNoCoalescing
-                       forModes: nil];
+      if (_launchingThread != nil)
+       {
+         [self performSelector: @selector(_notifyOfTermination)
+                      onThread: _launchingThread
+                    withObject: nil
+                 waitUntilDone: NO];
+       }
+      else
+       {
+         [self _notifyOfTermination];
+       }
     }
 }
 
@@ -1127,6 +1152,8 @@
       [NSException raise: NSInvalidArgumentException
                   format: @"NSTask - task has already been launched"];
     }
+
+  [super launch];
 
   lpath = [self _fullLaunchPath];
   wexecutable = (const unichar*)[lpath fileSystemRepresentation];
@@ -1455,6 +1482,8 @@
                   format: @"NSTask - task has already been launched"];
     }
 
+  [super launch];
+
   lpath = [self _fullLaunchPath];
   executable = [lpath fileSystemRepresentation];
   args[0] = executable;


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to