Merge jv
authorHG Automerge
Thu, 12 Jan 2017 09:42:50 +0000
branchjv
changeset 21252 1b7c2d5523d5
parent 21251 32f12bea6608 (current diff)
parent 21232 621013a10bc9 (diff)
child 21285 7770135c2b54
Merge
AbstractOperatingSystem.st
ExternalStream.st
NonPositionableExternalStream.st
OSProcess.st
PipeStream.st
--- a/AbstractOperatingSystem.st	Tue Jan 10 13:26:39 2017 +0000
+++ b/AbstractOperatingSystem.st	Thu Jan 12 09:42:50 2017 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -946,7 +944,7 @@
      Use #monitorPid:action: for synchronization and exec status return,
      or #killProcess: to stop it."
 
-    |nullStream in out err shellAndArgs rslt auxFd|
+    |nullStream in out err shellAndArgs pid auxFd|
 
     aCommandString isNil ifTrue:[^ nil].
 
@@ -967,7 +965,7 @@
 
     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
 
-    rslt := self
+    pid := self
         exec:(shellAndArgs at:1)
         withArguments:(shellAndArgs at:2)
         environment:anEvironmentDictionary
@@ -984,7 +982,7 @@
         nullStream close.
     ].
 
-    ^ rslt
+    ^ pid
 
     "blocking at current prio (i.e. only higher prio threads execute):
 
--- a/ExternalStream.st	Tue Jan 10 13:26:39 2017 +0000
+++ b/ExternalStream.st	Thu Jan 12 09:42:50 2017 +0000
@@ -1690,18 +1690,16 @@
      This may be used to wrap fd's as returned by user
      primitive code, or to wrap pipe-fds into externalStreams."
 
-    |newStream|
-
-    newStream := self basicNew.
-    newStream text; buffered:buffered; eolMode:DefaultEOLMode; clearEOF.
-    ^ newStream connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol
+    ^ self new
+        buffered:buffered;
+        connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol.
 
     "
      the example below will probably fail (15 is a random FD):
 
      |s|
 
-     s := ExternalStream forFileDescriptor:15 mode:#radonly handleType:#filePointer.
+     s := ExternalStream forFileDescriptor:15 mode:#readonly buffered:false handleType:#filePointer.
      s next.
     "
 
@@ -2197,6 +2195,10 @@
     ^ self error:'not a FILE*'
 !
 
+handle
+    ^ handle
+!
+
 handleType
     ^ handleType
 !
@@ -4828,7 +4830,7 @@
      The openMode ('r', 'w' etc.) must match the mode in which
      the fileDescriptor was originally opened (otherwise i/o errors will be reported later)."
 
-    |retVal error openmode|
+    |error openmode|
 
     handle notNil ifTrue:[^ self errorAlreadyOpen].
     mode := modeSymbol.
@@ -4841,60 +4843,57 @@
 
     if (__isStringLike(openmode)) {
 #ifdef __win32__
-	__stxWrapApiEnterCritical();
+        __stxWrapApiEnterCritical();
 #endif
-	if (__isSmallInteger(aFileDescriptor)) {
-	    fd = __intVal(aFileDescriptor);
-	}
+        if (__isSmallInteger(aFileDescriptor)) {
+            fd = __intVal(aFileDescriptor);
+        }
 #ifdef __win32__
-	else if (__isExternalAddressLike(aFileDescriptor)) {
-	    fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
-	    if (fd < 0) {
-		if (__threadErrno == 0) {
-		    // no more file descriptors
-		    __threadErrno = EMFILE;
-		}
-		error = __mkSmallInteger(__threadErrno);
-		__stxWrapApiLeaveCritical();
-		goto out;
-	    }
-	}
+        else if (__isExternalAddressLike(aFileDescriptor)) {
+            fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
+            if (fd < 0) {
+                if (__threadErrno == 0) {
+                    // no more file descriptors
+                    __threadErrno = EMFILE;
+                }
+                error = __mkSmallInteger(__threadErrno);
+                __stxWrapApiLeaveCritical();
+                goto out;
+            }
+        }
 #endif
-	f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
+        f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
 #ifdef __win32__
-	__stxWrapApiLeaveCritical();
+        __stxWrapApiLeaveCritical();
 #endif
-	if (f == NULL) {
-	    error =__mkSmallInteger(__threadErrno);
-	} else {
-	    if (@global(FileOpenTrace) == true) {
-		fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f);
-	    }
-
-	    fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
-	    retVal = self;
-	}
+        if (f == NULL) {
+            error =__mkSmallInteger(__threadErrno);
+        } else {
+            if (@global(FileOpenTrace) == true) {
+                fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f);
+            }
+
+            fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
+        }
     }
 out:;
 %}.
-    retVal notNil ifTrue:[
-	position := 0.
-	buffered isNil ifTrue:[
-	    buffered := true.       "default is buffered"
-	].
-	handleType := handleTypeSymbol.
-	self registerForFinalization.
-	^ retVal
+    error notNil ifTrue:[
+        "
+         the open failed for some reason ...
+        "
+        OperatingSystem closeFd:aFileDescriptor.
+        lastErrorNumber := error.
+        position := nil.
+        ^ self openError:error
     ].
-    error notNil ifTrue:[
-	OperatingSystem closeFd:aFileDescriptor.
-	lastErrorNumber := error.
-	position := nil.
-	"
-	 the open failed for some reason ...
-	"
-	^ self openError:error
+
+    position := 0.
+    buffered isNil ifTrue:[
+        buffered := true.       "default is buffered"
     ].
+    handleType := handleTypeSymbol.
+    self registerForFinalization.
 !
 
 dupFd
@@ -5006,15 +5005,6 @@
     handleType := what.
 !
 
-setFileDescriptor:anInteger mode:openMode
-    <resource: #obsolete>
-    "set the handle based upon a given fileDescriptor -
-     notice: this one is based on the underlying OSs fileDescriptor -
-     this may not be available on all platforms (i.e. non unix systems)."
-
-    self setFileHandle:anInteger mode:openMode
-!
-
 setFileHandle:something
     "set the fileHandle to the given one;
      low level private & friend interface; may also be used to connect to some
--- a/NonPositionableExternalStream.st	Tue Jan 10 13:26:39 2017 +0000
+++ b/NonPositionableExternalStream.st	Thu Jan 12 09:42:50 2017 +0000
@@ -145,8 +145,8 @@
             raise.
     ].
 
-    rs := self forFileDescriptor:(pipe at:1) mode:#readWrite buffered:false handleType:#pipeFilePointer.
-    ws := self forFileDescriptor:(pipe at:2) mode:#readWrite buffered:false handleType:#pipeFilePointer.
+    rs := NonPositionableExternalStream forFileDescriptor:(pipe at:1) mode:#readWrite buffered:false handleType:#pipeFilePointer.
+    ws := NonPositionableExternalStream forFileDescriptor:(pipe at:2) mode:#readWrite buffered:false handleType:#pipeFilePointer.
     ^ Array with:rs with:ws
 
     "
@@ -187,13 +187,13 @@
 
     ptyPair := OperatingSystem makePTYPair.
     ptyPair notNil ifTrue:[
-	master := self forReadWriteToFileDescriptor:(ptyPair at:1).
-	master buffered:false.
-	slave := self forReadWriteToFileDescriptor:(ptyPair at:2).
-	slave buffered:false.
-	ptyPair at:1 put:master.
-	ptyPair at:2 put:slave.
-	^ ptyPair
+        master := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyPair at:1).
+        master buffered:false.
+        slave := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyPair at:2).
+        slave buffered:false.
+        ptyPair at:1 put:master.
+        ptyPair at:2 put:slave.
+        ^ ptyPair
     ].
     ^ nil
 
@@ -210,17 +210,17 @@
      This is the higher level equivalent of OperatingSystem>>makePipe
      (which returns an array of file-descriptors)."
 
-    |pipe rs ws|
+    |pipeArray rs ws|
 
-    pipe := OperatingSystem makePipe.
-    pipe isNil ifTrue:[
+    pipeArray := OperatingSystem makePipe.
+    pipeArray isNil ifTrue:[
         "/ ok, maybe someone has forgotten to close a stream; enforce finalization and try again
         'makePipe: enforcing finalization to close any open streams' infoPrintCR.
         ObjectMemory garbageCollect; finalize.
-        pipe := OperatingSystem makePipe.
+        pipeArray := OperatingSystem makePipe.
     ].
 
-    pipe isNil ifTrue:[
+    pipeArray isNil ifTrue:[
         |errorNumber errorHolder|
 
         errorNumber := OperatingSystem lastErrorNumber.
@@ -231,8 +231,8 @@
             raise.
     ].
 
-    rs := self forFileDescriptor:(pipe at:1) mode:#readonly buffered:false handleType:#pipeFilePointer.
-    ws := self forFileDescriptor:(pipe at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer.
+    rs := NonPositionableExternalStream forFileDescriptor:(pipeArray at:1) mode:#readonly buffered:false handleType:#pipeFilePointer.
+    ws := NonPositionableExternalStream forFileDescriptor:(pipeArray at:2) mode:#writeonly buffered:false handleType:#pipeFilePointer.
     ^ Array with:rs with:ws
 
     "
--- a/OSProcess.st	Tue Jan 10 13:26:39 2017 +0000
+++ b/OSProcess.st	Thu Jan 12 09:42:50 2017 +0000
@@ -387,7 +387,7 @@
                             data := shuffledStream nextLine.
                             data notNil ifTrue:[
                                 aStream nextPutLine:data
-                            ] .
+                            ].
                         ].
                     ] ifFalse:[
                         shuffledStream copyToEndInto:aStream.
@@ -467,11 +467,11 @@
 
     externalInStream := self setupShufflerForInput:inStream.
     externalAuxStream := self setupShufflerForInput:auxStream.
+    externalOutStream := self setupShufflerForOutput:outStream.
     errorStream == outStream ifTrue:[
-        externalErrorStream := externalOutStream := self setupShufflerForOutput:errorStream.
+        externalErrorStream := externalOutStream.
     ] ifFalse:[
         externalErrorStream := self setupShufflerForOutput:errorStream.
-        externalOutStream := self setupShufflerForOutput:outStream.
     ].
 
     "start the command"
@@ -489,8 +489,6 @@
                         inDirectory:directory
                         newPgrp:newPgrp
                         showWindow:showWindow.
-
-            pid
         ] 
         action:[:status |
             status stillAlive ifFalse:[
--- a/PipeStream.st	Tue Jan 10 13:26:39 2017 +0000
+++ b/PipeStream.st	Thu Jan 12 09:42:50 2017 +0000
@@ -525,12 +525,12 @@
     "terminate first under windows"
     OperatingSystem isMSDOSlike ifTrue:[
         self terminatePipeCommand.
-        self closeFileDescriptor.
+        self closeFile.
         ^ self.
     ].
 
     "terminate last under unix"
-    self closeFileDescriptor.
+    self closeFile.
     self terminatePipeCommand.
 !
 
@@ -580,42 +580,6 @@
 
 !PipeStream methodsFor:'private'!
 
-closeFileDescriptor
-    "alternative very low level close
-     This closes the underlying OS-fileDescriptor
-     - and will NOT write any buffered data to the stream.
-     You have been warned."
-
-    |action|
-
-%{
-#if !defined(transputer)
-    OBJ fp;
-    FILE *f;
-    extern close();
-    int retVal;
-
-    if ((fp = __INST(handle)) != nil) {
-        __INST(handle) = nil;
-        f = __FILEVal(fp);
-        if (@global(FileOpenTrace) == true) {
-            console_fprintf(stderr, "close [PipeStream] %"_lx_" fd=%d\n", (INT)f, fileno(f));
-        }
-#ifdef __win32__
-        do {
-            __threadErrno = 0;
-            retVal = __STX_C_NOINT_CALL1( "close", (void*)close, (void*)fileno(f) );
-        } while ((retVal < 0) && (__threadErrno == EINTR));
-#else
-        __BEGIN_INTERRUPTABLE__
-        close(fileno(f));
-        __END_INTERRUPTABLE__
-#endif
-    }
-#endif /* not transputer  */
-%}.
-!
-
 openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition inDirectory:aDirectory
     "open a pipe to the OS command in commandString;
      rwMode may be 'r' or 'w' or 'r+'.
@@ -697,15 +661,17 @@
         osProcess errorStream:errorDisposition.
     ]]]].
 
-    osProcess terminateActionBlock:[
-            "writing doesn't make sense - there is no reader any longer"
-            mode == #readwrite ifTrue:[
-                "... but allow to read the rest of the command's output"
-                self shutDownOutput.
-            ] ifFalse:[mode == #writeonly ifTrue:[
-                self closeFileDescriptor.
-            ]].
-       ].
+    mode ~~ #readonly ifTrue:[
+        osProcess terminateActionBlock:[
+                "writing doesn't make sense - there is no reader any longer"
+                mode == #readwrite ifTrue:[
+                    "... but allow to read the rest of the command's output"
+                    self shutDownOutput.
+                ] ifFalse:[mode == #writeonly ifTrue:[
+                    self closeFile.
+                ]].
+           ].
+    ].
 
     result := osProcess startProcess.
 
@@ -720,10 +686,10 @@
 
     result ifTrue:[
         "successfull creation of subprocesss"
-        self setFileHandle:myPipeEnd fileHandle mode:rwMode.
+        handle := myPipeEnd handle.
+        handleType := myPipeEnd handleType.
         myPipeEnd unregisterForFinalization.    "make sure filedesciptor is not closed by finalizer"
         myPipeEnd := nil.
-        handleType := #pipeFilePointer.
     ] ifFalse:[
         "the pipe open failed for some reason ...
          ... this may be either due to an invalid command string,