Merge jv
authorMerge Script
Fri, 01 Jul 2016 06:44:28 +0200
branchjv
changeset 3980 684738628cf4
parent 3976 65cb26adfc9b (current diff)
parent 3979 0dc60bd4deac (diff)
child 3982 ae3dcd46d257
Merge
ZipArchive.st
--- a/InternalPipeStream.st	Thu Jun 30 07:04:26 2016 +0200
+++ b/InternalPipeStream.st	Fri Jul 01 06:44:28 2016 +0200
@@ -1,7 +1,9 @@
 "{ Package: 'stx:libbasic2' }"
 
+"{ NameSpace: Smalltalk }"
+
 Stream subclass:#InternalPipeStream
-	instanceVariableNames:'queue'
+	instanceVariableNames:'queue closed contentsSpecies'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Streams'
@@ -13,6 +15,7 @@
 "
     not useful on its own, but can be used to talk to a vt100
     terminal view ...
+    
     See example.
 "
 !
@@ -50,13 +53,14 @@
     top iconLabel:'doctor'.
     top open.
     top waitUntilVisible.
+    top onChangeEvaluate:[:what :aParameter :changedObject | what == #destroyed ifTrue:[userInput close]].
 
     terminal translateNLToCRNL:true.
     terminal inputTranslateCRToNL:true.
     terminal localEcho:true.
 
     elizasOutput nextPutLine:'Hi, I am Eliza'.
-    elizasOutput nextPutLine:'What is your problem ?'.
+    elizasOutput nextPutLine:'What is your problem (type end to finish conversation) ?'.
     elizasOutput nextPutLine:''.
     elizasOutput nextPutAll:'>'.
 
@@ -64,7 +68,7 @@
         |line answer matchingRule|
 
         line := userInput nextLine.
-        (#('quit' 'exit' 'end' 'bye') includes:line) ifTrue:[
+        ((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
             top destroy.
             ^ self
         ].
@@ -86,22 +90,35 @@
 !InternalPipeStream methodsFor:'accessing'!
 
 atEnd
-    ^ false . "/ queue notNil
+    ^ closed and:[queue isEmpty]
 !
 
 close
-    queue := nil
+    "if there is any partner waiting at either side of the queue,
+     tell it that the pipe is no longer active.
+     (readers will read an EOF condition, writers will get a write error).
+     Either side may close the internal pipe."
+     
+    closed := true.
+    queue readSemaphore signalForAll
+!
+
+isOpen
+    ^ closed not
 !
 
 next
     "return the next element from the stream (might block until something is written)"
 
+    (closed and:[queue isEmpty]) ifTrue:[^ self pastEndRead].
     ^ queue next
 !
 
 nextAvailableBytes:nMax into:aBuffer startingAt:startIndex
     |n idx ch|
 
+    (closed and:[queue isEmpty and:[self pastEndRead isNil]]) ifTrue:[^ 0].
+
     n := 0.
     idx := startIndex.
     [n <= nMax] whileTrue:[
@@ -113,10 +130,19 @@
     ^ n
 !
 
-nextPut:something
+nextPut:anObject
     "write an element (might wakeup readers)"
 
-    queue nextPut:something
+    closed ifTrue:[ self errorNotOpen].
+    queue nextPut:anObject
+
+    "
+     |s|
+     s := InternalPipeStream new.
+     s nextPut:$a.
+     s nextPut:$b.
+     s nextPut:$c.
+    "
 !
 
 size
@@ -125,19 +151,37 @@
 
 !InternalPipeStream methodsFor:'initialization'!
 
+contentsSpecies:aClass
+    "by default, I will return a String of elements, if reading multiple elements.
+     However, you may change this to eg. an array, if desired"
+
+    contentsSpecies := aClass.
+!
+
 initialize
     queue := SharedQueue new.
+    closed := false.
+! !
+
+!InternalPipeStream methodsFor:'queries'!
+
+contentsSpecies
+    ^ contentsSpecies ? String
 ! !
 
 !InternalPipeStream methodsFor:'synchronization'!
 
 readWait
     queue readSemaphore wait
+!
+
+writeWaitWithTimeoutMs:timeout
+    queue writeSemaphore waitWithTimeoutMs:timeout
 ! !
 
 !InternalPipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/InternalPipeStream.st,v 1.4 2014-06-02 22:16:14 vrany Exp $'
+    ^ '$Header$'
 ! !
 
--- a/Lazy.st	Thu Jun 30 07:04:26 2016 +0200
+++ b/Lazy.st	Fri Jul 01 06:44:28 2016 +0200
@@ -76,49 +76,51 @@
 "
   Evaluates the factorial, starting only when the
   result is actually required (when printString is sent).
-						[exBegin]
+                                                [exBegin]
     | fac |
     fac := [100 factorial] lazyValue.
     Transcript showCR: 'Doing nothing. '.
     (Delay forSeconds: 2) wait.
     Transcript showCR: fac printString.
-						[exEnd]
+                                                [exEnd]
 
 
-  Starts evaluating both factorials only when required (by the touch),
+  Starts evaluating both factorials only when required (by the value),
   and waits until both blocks have finished before continuing.
-						[exBegin]
+                                                [exBegin]
     | fac1 fac2 |
     fac1 := [Transcript showCR: 'Starting fac1.. '. 100 factorial] lazyValue.
     fac2 := [Transcript showCR: 'Starting fac2.. '. 120 factorial] lazyValue.
-    fac2 touch.
-    fac1 touch.
+    fac2 value.
+    fac1 value.
     Transcript showCR: 'both completed.'.
-						[exEnd]
+                                                [exEnd]
 
 
   Demonstrates how to pass arguments to a lazy evaluation block.
-						[exBegin]
+                                                [exBegin]
     | temp |
     temp := [:x :y :z | x * y * z] lazyValueWithArguments: #(2 3 4).
     Transcript  showCR: temp printString.
-						[exEnd]
+                                                [exEnd]
 "
 ! !
 
 !Lazy methodsFor:'evaluating'!
 
 block: aBlock
-	"Execute aBlock in parallel, but ensure that any messages sent
-	 to me before execution of the block has terminated are
-	 suspended until it has terminated. Do not start the evaluation
-	 until at least one message has been sent to the receiver."
+    "Execute aBlock in parallel, but ensure that any messages sent
+     to me before execution of the block has terminated are
+     suspended until it has terminated. Do not start the evaluation
+     until at least one message has been sent to the receiver."
 
-	startSemaphore := Semaphore new.
-	endSemaphore := Semaphore new.
-	[startSemaphore wait.
-	 result := aBlock value.
-	 endSemaphore signal] fork
+    startSemaphore := Semaphore new.
+    endSemaphore := Semaphore new.
+    [
+        startSemaphore wait.
+        result := aBlock value.
+        endSemaphore signal
+    ] fork.
 !
 
 block: aBlock value: aValue
@@ -175,13 +177,28 @@
 
 !Lazy methodsFor:'synchronising'!
 
+_evaluate_
+    "answer the computed value"
+
+    |startSema endSema|
+
+    startSema := startSemaphore.
+    startSema notNil ifTrue:[
+        startSema signal.          "Start the evaluation."
+        endSema := endSemaphore.
+        endSema notNil ifTrue:[
+            endSema waitUncounted.     "Wait until evaluation completed."
+        ].
+        startSemaphore := endSemaphore := nil.
+    ].
+
+    ^ result
+!
+
 doesNotUnderstand: aMessage
     "Any message to a Lazy will end up here."
 
-    startSemaphore signal.          "Start the evaluation."
-    endSemaphore waitUncounted.     "Wait until evaluation completed."
-
-    ^ aMessage sendTo:result
+    ^ aMessage sendTo:self _evaluate_
 ! !
 
 !Lazy methodsFor:'testing'!
--- a/ZipArchive.st	Thu Jun 30 07:04:26 2016 +0200
+++ b/ZipArchive.st	Fri Jul 01 06:44:28 2016 +0200
@@ -3231,6 +3231,12 @@
     endOfArchive   := anEndPosition.
 !
 
+signatureInformation
+    "for compatibility with SignedZipArchive"
+    
+    ^ nil
+!
+
 size
     ^self fileSize
 !
@@ -3994,6 +4000,7 @@
     ^ false.
 ! !
 
+
 !ZipArchive methodsFor:'reading'!
 
 extract:fileName
@@ -4103,6 +4110,7 @@
     "Created: / 21-11-2010 / 11:51:41 / cg"
 ! !
 
+
 !ZipArchive methodsFor:'reading - stream'!
 
 extract:fileName intoStream: aWriteStream