|
Class: ImmutableByteArray
Object
|
+--Collection
|
+--SequenceableCollection
|
+--ArrayedCollection
|
+--UninterpretedBytes
|
+--ByteArray
|
+--ImmutableByteArray
- Package:
- stx:libbasic
- Category:
- System-Compiler-Support
- Version:
- rev:
1.30
date: 2021/04/12 17:45:17
- user: stefan
- file: ImmutableByteArray.st directory: libbasic
- module: stx stc-classLibrary: libbasic
By default, byte array literals in smalltalk are mutable objects. That
may lead to some subtle (and hard to find errors), if some method passes
a literal byte-array object as argument to someone else, who changes the
bytearray using at:put: like messages. Since the bytearray object is kept in
the first methods literals, the bytearray constant has now been changed without
having the method's sourcecode reflect this. Thus, the method will
behave differently from what its source may make you think.
To help finding this kind of 'feature/bug', the compiler can be
configured to create instances of this ImmutableByteArray instead of ByteArrays
for literals. Instances of ImmutableByteArray catch storing accesses and
enter the debugger. Although useful, this feature is disabled by default
for compatibility to other smalltalk implementations.
(Also, if turned on, this makes inspecting bytearray literals entered in
a workspace somewhat strange: you cannot modify it any longer).
Turn the ImmutableArray feature on, by setting the Parser's class variable
'ArraysAreImmutable' to true or use the new launchers settings menu.
This class should be used only by the compiler.
ATTENTION:
there may be still code around which checks for explicit class being ByteArray
(both in Smalltalk and in primitive code). All code like foo 'class == ByteArray'
or '__isByteArray()' will not work with ImmutableByteArrays - consider using '__isByteArrayLike()'.
A somewhat better approach would be to either add a flag to the object (mutability)
and check this dynamically (expensive) or to place immutable objects into a readonly
memory segment (the good solution). We will eventually implement the second in the future...
copyrightCOPYRIGHT (c) 2009 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
fromPackedString: aString
-
(comment from inherited method)
ST-80 compatibility: decode a byteArray from a packed string in which
6bits are encoded per character. The argument, aString must be a multiple
of 4 in size (since 24 is the lcm of 6 and 8).
Every 6 bit packet is encoded as a character in 32..95.
Characters below 32 are ignored (so line breaks can be inserted at any place).
An addition final byte defines how many bytes of the last triple are valid.
This is somewhat like the radix-encoding used in good old PDP11 times ;-)
ST-80 uses this encoding for Images ...
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421.
PS: It took a while to figure that one out ...
PPS: I don't like it ;-)
queries
-
mutableClass
-
answer an equivalent mustable class
testing
-
hasImmutableInstances
-
accessing
-
at: index put: value
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
basicAt: index put: value
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
byteAt: index put: value
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
doubleAt: index put: anInteger
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
doubleAt: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
floatAt: index put: anInteger
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
floatAt: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
signedInt128At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
signedInt16At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
signedInt32At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
signedInt64At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt128At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt16At: index put: anInteger
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt16At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt32At: index put: anInteger
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt32At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt64At: index put: anInteger
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
-
unsignedInt64At: index put: anInteger MSB: msb
-
Trigger an error if an immutable bytearray is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger (or proceed in an exception handler).
converting
-
asByteArray
-
return the receiver as a (mutable) byteArray
Usage example(s):
#[1 2 3 4] asImmutableByteArray asByteArray
|
-
asImmutableCollection
-
(comment from inherited method)
return a write-protected copy of myself
-
asMutableCollection
-
return a writable copy of myself
-
beImmutable
-
that's what I am
-
beMutable
-
you never go back
-
beUnsigned
-
that's what I am-
Usage example(s):
#[1 2 3 128 255] asImmutableByteArray beUnsigned
|
copying
-
shallowCopy
-
when copying, return a real (mutable) ByteArray
Usage example(s):
#[1 2 3 4] asImmutableByteArray shallowCopy
|
copying-private
-
postCopy
-
when copied, make me a real (mutable) ByteArray
-
postDeepCopy
-
when copied, make me a real (mutable) ByteArray
printing & storing
-
displayOn: aGCOrStream
-
what a kludge - Dolphin and Squeak mean: printOn: a stream;
private
-
species
-
Copies should be mutable
-
speciesForCopy
-
Copies should be mutable
queries
-
isImmutable
-
return true, if the receiver is immutable.
Since I am an immutable byte array, return always true here
-
isLiteral
-
return true, if the receiver can be used as a literal constant in ST syntax
(i.e. can be used in constant arrays)
specials
-
become: anotherObject
-
trigger an error if I should become something else
(this would be an even more tricky manipulation)
-
becomeNil
-
trigger an error if I should become nil
(this would be an even more tricky manipulation)
-
becomeSameAs: anotherObject
-
trigger an error if I should become something else
(this would be an even more tricky manipulation)
|