eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ImmutableByteArray':

Home

everywhere
www.exept.de
for:
[back]

Class: ImmutableByteArray


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--ByteArray
                  |
                  +--ImmutableByteArray

Package:
stx:libbasic
Category:
System-Compiler-Support
Version:
rev: ? date: ? ?
user: ?
file: ? directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


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.

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.
    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...


Related information:

    ImmutableString
    ImmutableArray
    Parser
    Scanner

Instance protocol:

accessing
o  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.

o  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.

converting
o  asByteArray
return the receiver as a (mutable) byteArray

o  asImmutableByteArray

copying
o  copyEmpty
when copying, return a real (mutable) ByteArray

o  copyEmptyAndGrow: size
when copying, return a real (mutable) ByteArray

o  postCopy
when copied, make me a real (mutable) ByteArray

o  postDeepCopy
when copied, make me a real (mutable) ByteArray

o  shallowCopy
when copying, return a real (mutable) ByteArray

error handling
o  creator
find the method that contains me

o  noModificationError
a store is attempted - for our convenience, find the method that
contains me, for a nicer error message

private
o  species
Copies should be mutable

queries
o  isLiteral
return true, if the receiver can be used as a literal constant in ST syntax
(i.e. can be used in constant arrays)

o  referencesAny: aCollection
redefined to speed up searching when many byteArray instances are present

specials
o  become: anotherObject
trigger an error if I should become something else
(this would be an even more tricky manipulation)

o  becomeNil
trigger an error if I should become nil
(this would be an even more tricky manipulation)



ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 19:36:05 GMT