WeakValueDictionary.st
branchjv
changeset 19559 d35a89d5c0ec
parent 19103 71257a47eba2
parent 19543 2ab62a8fbe29
child 19811 65fec19facb0
--- a/WeakValueDictionary.st	Sun Apr 03 07:04:52 2016 +0200
+++ b/WeakValueDictionary.st	Fri Apr 08 07:02:36 2016 +0100
@@ -77,7 +77,7 @@
     ^ ret
 !
 
-at:key ifAbsentPut:anObject
+at:key ifAbsentPut:replacementBlock
     "return the element indexed by aKey if present,
      if not present, store the result of evaluating valueBlock
      under aKey and return it.
@@ -85,14 +85,26 @@
      Redefined to block interrupts, to avoid trouble when dependencies
      are added within interrupting high prio processes.
      WARNING: do not add elements while iterating over the receiver.
-	      Iterate over a copy to do this."
+              Iterate over a copy to do this."
 
-    |ret|
+    |val|
 
-    [
-	ret := super at:key ifAbsentPut:anObject.
-    ] valueUninterruptably.
-    ^ ret
+    OperatingSystem blockInterrupts ifTrue:[
+        "/ already blocked
+        val := super at:key ifAbsentPut:replacementBlock.
+    ] ifFalse:[
+        [
+            val := super at:key ifAbsentPut:replacementBlock.
+        ] ensure:[
+            OperatingSystem unblockInterrupts.
+        ].
+    ].
+
+    val class == SmallInteger ifTrue:[
+        self error:'WeakValueDictionary: invalid value'.
+    ].
+
+    ^ val
 !
 
 at:key put:anObject
@@ -101,16 +113,26 @@
      Redefined to block interrupts, to avoid trouble when dependencies
      are added within interrupting high prio processes."
 
-    |ret|
+    |val|
+
+    anObject class == SmallInteger ifTrue:[
+        self error:'WeakValueDictionary: invalid value'.
+    ].
+
+    (OperatingSystem blockInterrupts) ifTrue:[
+        "/ already blocked
+        ^ super at:key put:anObject.
+    ].
 
     [
-	ret := super at:key put:anObject.
-    ] valueUninterruptably.
-    ^ ret
+        val := super at:key put:anObject.
+    ] ensure:[
+        OperatingSystem unblockInterrupts.
+    ].
+    ^ val
 
     "Modified: 6.5.1996 / 12:22:26 / stefan"
-    "Created: 6.5.1996 / 14:47:37 / stefan"
-    "Modified: 20.10.1996 / 14:05:04 / cg"
+    "Modified: 29.1.1997 / 15:08:45 / cg"
 !
 
 removeKey:aKey ifAbsent:aBlock
@@ -204,10 +226,6 @@
     super possiblyShrink
 !
 
-slotIsEmpty:probe
-    ^ probe isNil or:[probe == 0 "collected"]
-!
-
 valueContainerOfSize:n
     "return a container for values of size n.
      use WeakArrays here."