Every OSObject has an indirection level that describes how many times a pointer must be followed to reach the actual data (a sequence of bytes in memory). The operation of dereferencing a pointer results in another pointer or immediate data and reduces the indirection level of the new pointer by one.
You can use subclasses of OSImmediate to represent C-style typedefs to unsigned 8-, 16-, 32- or 64-bit values. Instances of
OSImmediate cannot be dereferenced. All subclasses of
OSImmediate have indirection level zero. To model
HWND (the C typedef
#typedef HWND unsigned long), add a new subclass of
OSImmediate.
OSImmediate provides the inherited class instance variable
fixedSize that must be assigned before the class can be used. In this example,
fixedSize is 4 (the size of unsigned long).
You use subclasses of OSBaseType to represent pointers to C base types. Dereferencing an
OSBaseType answers a Smalltalk immediate type. All subclasses of
OSBaseType have indirection level one. To model
int * (a pointer to a C array of
int), use the class
OSInt32. Dereferencing an instance of
OSInt32 results in a signed Smalltalk integer. VA Smalltalk provides the following standard
OSBaseType subclasses:
You use subclasses of OSStructure to represent arrays of structs. All subclasses of
OSStructure have indirection level one. To model struct
POINT * (a pointer to a C structure
struct {int x, y} POINT;), a new subclass of
OSStructure is required.
OSStructure provides the inherited class instance variables
fixedSize that must be assigned before the class can be used. In this example,
fixedSize is 8 (the size of
int x, y;).
OSStructure subclasses support auto-layout generation in later versions of VA Smalltalk
(>= 8.6.2). This means the struct's size, alignment and field offsets will be automatically computed based on the struct's definition and the platform ABI rules. In the example above, it would look like the following:
You use subclasses of OSUnion to represent arrays of unions. An
OSUnion is a specialization of
OSStructure and was introduced alongside the auto-layout generation feature.
You use subclasses of OSVariableStructure represent variable-sized structures. Dereferencing is disallowed because the size of each element is not known. To model
struct DATA * (a pointer to
struct {int cbSize; char data1]} DATA;), a new subclass of
OSVariableStructure is required.
OSStructure provides the inherited class instance variables
fixedSize and
variableSize that you must assign before the class can be used. In this example,
fixedSize is 4 (the size of
int cbSize;) and
variableSize is 1 (the size of one data element in the variable-sized portion of the structure, or
char data 1];).
OSObjectPointer is used to represent pointers to other instances of
OSObject. Dereferencing an
OSObjectPointer answers a new instance of
OSObjectPointer or an
OSObject subclass.
To model struct POINT ** (a pointer to a pointer to a C structure
struct {int x, y;} POINT;), a new instance of
OSObjectPointer is created. The following example uses an
OSObjectPointer to model a pointer to an
OSPoint:
OSObjectPointer can point to any
OSObject. You can also use subclasses of
OSObjectPointer to model pointers to a single type of
OSObject. The class of this
OSObject is specified by assigning the
defaultItemType class instance variable in the new
OSObjectPointer subclass. For example, by defining
OSPointPointer (a subclass of
OSObjectPointer) and assigning
defaultItemType to
OSPoint, the above code fragment could be rewritten as:
Copyright 2005, 2020 Instantiations, Inc. All rights reserved.