OSObject subclasses
Subclasses of class OSObject are used to model particular kinds of memory references. OSObject closely models C-style addressing and structure sharing.
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.
OSImmediate
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).
OSBaseType
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:
OSBool8, OSBool16, OSBool32
OSChar8, OSChar16
OSFloat32, OSFloat64
OSInt8, OSInt16, OSInt32, OSInt64, OSLong
OSUInt8, OSUInt16, OSUInt32, OSUInt64, OSULong
OSVoid
OSStructure
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:
OSPoint members: #(x y) types: #(int32 int32).
Fields within the struct can now be accessed symbolically, rather than with hard-coded offsets. In this simple example, the getter for x would look like the following:
x
^self int32At: #x
OSUnion
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.
OSVariableStructure
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
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:
| ptr |
ptr := OSObjectPointer calloc: 1 itemType: OSPoint.
ptr at: 0 put: (point := OSPoint calloc x: 12; y:13)
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:
| ptr |
ptr := OSPointPointer calloc: 1.
ptr at: 0 put: (point := OSPoint calloc x: 12; y:13)
Last modified date: 08/10/2017