handle weak objects (with instances or non-WeakArray)
authorClaus Gittinger <cg@exept.de>
Wed, 05 Feb 2014 01:32:49 +0100
changeset 15942 a76da2251215
parent 15941 347e20055f41
child 15943 e232d88d7157
handle weak objects (with instances or non-WeakArray)
Object.st
--- a/Object.st	Tue Feb 04 22:17:36 2014 +0100
+++ b/Object.st	Wed Feb 05 01:32:49 2014 +0100
@@ -799,7 +799,6 @@
 
 	switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
 	    case __MASKSMALLINT(POINTERARRAY):
-	    case __MASKSMALLINT(WKPOINTERARRAY):
 		/*
 		 * pointers
 		 */
@@ -811,6 +810,18 @@
 		}
 		break;
 
+	    case __MASKSMALLINT(WKPOINTERARRAY):
+		if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) {
+		    OBJ *op;
+		    OBJ el;
+
+		    op = (OBJ *)pFirst + indx;
+		    el = *op;
+		    el = __WEAK_READ__(self, el);
+		    RETURN ( el );
+		}
+		break;
+
 	    case __MASKSMALLINT(BYTEARRAY):
 		/*
 		 * (unsigned) bytes
@@ -1059,6 +1070,16 @@
 
 	switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
 	    case __MASKSMALLINT(POINTERARRAY):
+		if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) {
+		    OBJ *op;
+
+		    op = (OBJ *)pFirst + indx;
+		    *op = anObject;
+		    __STORE(self, anObject);
+		    RETURN ( anObject );
+		}
+		break;
+
 	    case __MASKSMALLINT(WKPOINTERARRAY):
 		if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) {
 		    OBJ *op;
@@ -1066,6 +1087,7 @@
 		    op = (OBJ *)pFirst + indx;
 		    *op = anObject;
 		    __STORE(self, anObject);
+		    __WEAK_WRITE__(self, anObject);
 		    RETURN ( anObject );
 		}
 		break;
@@ -3743,7 +3765,7 @@
 
     |s|
 
-    "/ attention: TextStream is not present in ultra-mini standalone apps!
+    "/ attention: TextStream is not present in ultra-mini standalone apps
     s := TextStream isNil
 	    ifTrue:['' writeStream]
 	    ifFalse:[TextStream on:(String new:32)].
@@ -6611,7 +6633,9 @@
 
 	for (n=0, slot = lastUsed, prev = prevPrev = 0; slot; n++, slot = slot->next) {
 	   if (sel == slot->sel) {
+#ifdef XXDEBUG
 printf("cached slot %d (len=%d)\n", slot-sel_and_ilc, n);
+#endif
 		pIlc = &(slot->ilc);
 		// move to front
 		if (prev) {
@@ -6631,14 +6655,18 @@
 	    slot = nextFree;
 	    nextFree = nextFree + 1;
 	    if (nextFree >= &(sel_and_ilc[nilcs])) nextFree = 0;
+#ifdef XXDEBUG
 printf("new slot %d\n", slot-sel_and_ilc);
+#endif
 	} else {
 	    // no more for reuse - use least recently used
 	    slot = prev;
 	    prevPrev->next = 0;
 	    slot->next = lastUsed;
 	    lastUsed = slot;
+#ifdef XXDEBUG
 printf("reuse last slot %d\n", slot-sel_and_ilc);
+#endif
 	}
 
 	/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/
@@ -9921,11 +9949,11 @@
 !Object class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.747 2014-02-04 11:19:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.748 2014-02-05 00:32:49 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.747 2014-02-04 11:19:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.748 2014-02-05 00:32:49 cg Exp $'
 !
 
 version_SVN