Parameter types
The supported parameter types for the C language are:
none, void
This is not a valid parameter type. If used as the return type, the value nil is returned.
object
No conversion is performed. The parameter value is passed directly to the called function. Returned values are passed directly back to Smalltalk. The PlatformFunction author must ensure that only valid VA Smalltalk objects are returned.
struct
Can be used as a parameter or return type; for parameters, this is valid only for byte, word, or long objects and nil. For byte, word, and long objects, the passed parameter is a pointer to the first instance variable of the object. For nil, 0 (NULL) is passed. For return types, this is an instance of OSStructure that was passed into the invoking call method.
char, char8
If used as a parameter type, the parameter must be a Character whose numeric value is between 0 and 255. The parameter is converted to a C char. If used as a return value, the low 8 bits of the return value are converted to a Character before returning to Smalltalk.
char16
All instances of Character are converted. This means that the passed-in values will be between 0 and 65535 and the low 16 bits of the return value are converted to a Character on return.
float, double, extended
If used as a parameter type, the parameter must be a Float. The parameter is converted to the specified size of float. If used as a return value, the result is converted to an instance of Float.
bool, boolean
For outgoing parameters, only true or false can be converted. The passed parameter is TRUE for true, FALSE for false. As a return type, 0 is converted to false, and all other values are converted to true. The passed value for true is platform-dependent. The value of !0 in C is passed.
int8, int16, int32, int64, uint8, uint16, uint32, uint64
If used as a parameter type, the parameter must be an Integer that can be represented in 32 bits or 64 bits, Character, Boolean, or nil (see Passed parameters). Instances of OSObject with reftype immediate (namely true, false, nil, Characters, and SmallIntegers) can also be used (see OSObjects). If used as a return type, the low n (8, 16, 32, 64) bits of the return value are sign- or zero-extended (signed or unsigned, respectively) and then converted to a Smalltalk Integer. The return value in Smalltalk is guaranteed to be within these given ranges:
int8
-128...127
int16
-32768...32767
int32
-2147483648...2147483647
int64
-2305843009213693952...2305843009213693951
uint8
0...255
uint16
0...65535
uint32
0...4294967295
uint64
0...18446744073709551616
pointer
As a parameter type, this is an amalgamation of the struct, char, bool, and int type conversions. If the parameter is a byte, word, or long object or nil, the struct conversion is performed. If the parameter is true or false, the bool conversion is performed. If the parameter is a Character, the char16 conversion is performed. If the parameter is an Integer, the uint32 conversion is performed on a 32-bit virtual machine or a uint64 on a 64-bit virtual machine.
Instances of OSObject can also be supplied as the parameter. If the OSObject reftype is handle, the handle is dereferenced and the offset is added. All other objects cause the conversion to fail. If used as a return type, the uint32 conversion is performed on a 32-bit virtual machine or a uint64 on a 64-bit virtual machine.
safePointer
As a parameter type, the parameter may be a byte, word or long object. Instances of OSObject can also be supplied as the parameter provided they do not have reftype immediate. If used as a return type, the uint32 conversion is performed on a 32-bit virtual machine or a uint64 on a 64-bit virtual machine.
Passed parameters
The specified type of an argument passed to a platform function call should accurately reflect the type specified in the declaration of the function in C.
For example, if the first argument in a C function is a int * (i.e. pointer), then the first argument type of the associated platform function is best expressed as pointer. Defining the argument type instead as an int16 is not only semantically incorrect, but it will also be functionally incorrect in many cases since the incoming pointer value will be truncated to 16 bits.
The example given above was not true in versions of VA Smalltalk prior to 9.0. In these older versions of the product, all values passed to C functions were extended to a 32-bit quantity before being passed (except for int64 and uint64 which are passed as 64-bit quantities). This meant that one could pass pointer sized values through int8 types. The change in version 9.0 has to do with implementation details of newer virtual machines introduced in that version.
Last modified date: 11/05/2019