--- a/WeakArr.st Mon Oct 10 01:29:01 1994 +0100
+++ b/WeakArr.st Mon Oct 10 01:29:28 1994 +0100
@@ -12,16 +12,16 @@
Array variableSubclass:#WeakArray
instanceVariableNames:'watcher dependents'
- classVariableNames:''
+ classVariableNames:'RegistrationFailedSignal'
poolDictionaries:''
- category:'System-Support'
+ category:'Collections-Arrayed'
!
WeakArray comment:'
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.5 1994-08-05 01:03:04 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.6 1994-10-10 00:29:09 claus Exp $
'!
!WeakArray class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.5 1994-08-05 01:03:04 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/WeakArr.st,v 1.6 1994-10-10 00:29:09 claus Exp $
"
!
@@ -75,29 +75,50 @@
"
! !
+!WeakArray class methodsFor:'initialization'!
+
+initialize
+ "setup the private signal"
+
+ RegistrationFailedSignal isNil ifTrue:[
+ Object initialize.
+
+ RegistrationFailedSignal := Object errorSignal newSignalMayProceed:true.
+ RegistrationFailedSignal nameClass:self message:#registrationFailedSignal.
+ RegistrationFailedSignal notifierString:'weakArray registration failed'.
+ ]
+! !
+
!WeakArray class methodsFor:'instance creation'!
new:size
"return a new weakArray with size slots"
- |newArray|
-
"This is a kludge: I would like to set WEAK-flag in the classes
- initialize method, but no order of class-init is defined ...
+ initialize method, but no order of class-init is defined (yet) ...
Therefore it could happen, that a WeakArray is used by other
class inits BEFORE this initialize is evaluated. To avoid this,
- the WEAK bit in the class is set when the first WeakArray is
+ the WEAK bit in the class is set here, when the first WeakArray is
created."
self flags:(Behavior flagWeakPointers).
ObjectMemory disposeInterruptHandler:self.
- newArray := self basicNew:size.
+ ^ (self basicNew:size) registerAsWeakArray
+! !
+
+!WeakArray methodsFor:'GC registration'!
+
+registerAsWeakArray
+ "register the receiver in the VM -
+ i.e. tell the VM to nil disposed entries in the receiver
+ and notify the disposeInterruptHandler whenever that happened."
+
+ |ok|
%{
- OBJ ok;
OBJ __addShadowObject();
- ok = __addShadowObject(newArray, 0);
+ ok = __addShadowObject(self, 0);
if (ok == false) {
/*
* this happens when too many shadow objects are
@@ -108,30 +129,30 @@
* that does not help.
*/
nonTenuringScavenge(__context);
- ok = __addShadowObject(newArray, 0);
+ ok = __addShadowObject(self, 0);
if (ok == false) {
/* try more ... */
scavenge(__context);
- ok = __addShadowObject(newArray, 0);
+ ok = __addShadowObject(self, 0);
if (ok == false) {
/* hard stuff - need full collect */
__garbageCollect(__context);
- ok = __addShadowObject(newArray, 0);
+ ok = __addShadowObject(self, 0);
if (ok == false) {
/* mhmh - it seems that there are really many shadow
objects around - force creation */
- ok = __addShadowObject(newArray, 1);
+ ok = __addShadowObject(self, 1);
if (ok == false) {
/* no chance - something must be wrong */
- newArray = nil;
}
}
}
}
}
-%}
-.
- ^ newArray
+%}.
+ ok ifFalse:[
+ ^ RegistrationFailedSignal raiseRequestWith:self
+ ]
! !
!WeakArray class methodsFor:'dispose handling'!
@@ -163,6 +184,17 @@
]
! !
+!WeakArray methodsFor:'copying'!
+
+postCopy
+ "copying alone does not really help - we have to tell
+ the VM, that there is a new WeakArray around ...
+ Q: who copies weakArrays ?"
+
+ self dependents:nil.
+ self registerAsWeakArray.
+! !
+
!WeakArray methodsFor:'accessing'!
dependents