#BUGFIX by cg
class: SignedByteArray
care for being immutable
changed:
#basicAt:put:
#from:to:put:
--- a/SignedByteArray.st Sun Jun 09 15:26:37 2019 +0200
+++ b/SignedByteArray.st Sun Jun 09 15:31:25 2019 +0200
@@ -119,35 +119,42 @@
REGISTER OBJ slf;
REGISTER OBJ cls;
- if (__bothSmallInteger(index, value)) {
- val = __intVal(value);
- if ((val >= -128) && (val <= 127)) {
- indx = __intVal(index) - 1;
- slf = self;
- if ((cls = __qClass(slf)) != @global(SignedByteArray)) {
- if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
- != __MASKSMALLINT(BYTEARRAY)) {
- goto fail;
+ if (! __isImmutable(self)) {
+ if (__bothSmallInteger(index, value)) {
+ val = __intVal(value);
+ if ((val >= -128) && (val <= 127)) {
+ indx = __intVal(index) - 1;
+ slf = self;
+ if ((cls = __qClass(slf)) != @global(SignedByteArray)) {
+ if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
+ != __MASKSMALLINT(BYTEARRAY)) {
+ goto fail;
+ }
+ if (indx < 0) goto fail;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
}
- if (indx < 0) goto fail;
- indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- }
- nIndex = __byteArraySize(slf);
- if ((unsigned)indx < (unsigned)nIndex) {
- __ByteArrayInstPtr(slf)->ba_element[indx] = val;
- RETURN ( value );
+ nIndex = __byteArraySize(slf);
+ if ((unsigned)indx < (unsigned)nIndex) {
+ __ByteArrayInstPtr(slf)->ba_element[indx] = val;
+ RETURN ( value );
+ }
}
}
}
fail: ;
%}.
+ "/ arrive here only in case of an error
+ self isImmutable ifTrue:[
+ self noModificationError
+ ].
^ super basicAt:index put:value
"
(self new:5) basicAt:1 put:-1; yourself
"
- "Modified: 19.4.1996 / 11:14:40 / cg"
+ "Modified: / 19-04-1996 / 11:14:40 / cg"
+ "Modified: / 09-06-2019 / 15:29:50 / Claus Gittinger"
! !
!SignedByteArray methodsFor:'converting'!
@@ -327,6 +334,10 @@
}
}
%}.
+ "/ arrive here only in case of an error
+ self isImmutable ifTrue:[
+ self noModificationError
+ ].
"
fall back in case of non-integer index or out-of-bound index/value;
will eventually lead to an out-of-bound signal raise
@@ -338,6 +349,8 @@
(self new:20) from:10 to:20 put:-5
(self new:20) from:1 to:10 put:-5
"
+
+ "Modified: / 09-06-2019 / 15:30:52 / Claus Gittinger"
! !
!SignedByteArray methodsFor:'queries'!