Category: Language-C interface
Superclass: Object
I am not part of the standard Smalltalk kernel class hierarchy. My instances contain values that are not interpreted by the Smalltalk system; they frequently hold "pointers" to data outside of the Smalltalk environment. The C callout mechanism allows my instances to be transformed into their corresponding C values for use in external routines.

Method category index

conversion (class)
instance creation (class)
primitive allocation (class)
subclass creation (class)
accessing (instance)
basic (instance)
C data access (instance)
conversion (instance)
finalization (instance)
pointer-like behavior (instance)
testing (instance)
testing functionality (instance)

conversion (class)

type
Nothing special in the default case - answer a CType for the receiver

top


instance creation (class)

address: anInteger
Answer a new object pointing to the passed address, anInteger

alloc: nBytes

Allocate nBytes bytes and return an instance of the receiver

gcAlloc: nBytes

Allocate nBytes bytes and return an instance of the receiver

gcNew: nBytes

Allocate nBytes bytes and return an instance of the receiver

new

Answer a new object pointing to NULL.

new: nBytes

Allocate nBytes bytes and return an instance of the receiver

top


primitive allocation (class)

alloc: nBytes type: cTypeObject
Allocate nBytes bytes and return a CObject of the given type

gcAlloc: nBytes type: cTypeObject

Allocate nBytes bytes and return a CObject of the given type

top


subclass creation (class)

inheritShape
Answer whether subclasses will have by default the same shape as this class. The default is true for the CObject hierarchy.

top


accessing (instance)

address
Answer the address the receiver is pointing to. The address can be absolute if the storage is nil, or relative to the Smalltalk object in #storage. In this case, an address of 0 corresponds to the first instance variable.

address: anInteger

Set the receiver to point to the passed address, anInteger

isAbsolute

Answer whether the object points into a garbage-collected Smalltalk storage, or it is an absolute address.

printOn: aStream

Print a representation of the receiver

storage

Answer the storage that the receiver is pointing into, or nil if the address is absolute.

storage: anObject

Change the receiver to point to the storage of anObject.

type: aCType

Set the receiver's type to aCType.

top


basic (instance)

= anObject
Return true if the receiver and aCObject are equal.

hash

Return a hash value for anObject.

top


C data access (instance)

at: byteOffset put: aValue type: aType
Store aValue as data of the given type from byteOffset bytes after the pointer stored in the receiver

at: byteOffset type: aType

Answer some data of the given type from byteOffset bytes after the pointer stored in the receiver

free

Free the receiver's pointer and set it to null. Big trouble hits you if the receiver doesn't point to the base of a malloc-ed area.

top


conversion (instance)

castTo: aType
Answer another CObject, pointing to the same address as the receiver, but belonging to the aType CType.

narrow

This method is called on CObjects returned by a C call-out whose return type is specified as a CType; it mostly allows one to change the class of the returned CObject. By default it does nothing, and that's why it is not called when #cObject is used to specify the return type.

type

Answer a CType for the receiver

top


finalization (instance)

finalize
To make the VM call this, use #addToBeFinalized. It frees automatically any memory pointed to by the CObject. It is not automatically enabled because big trouble hits you if you use #free and the receiver doesn't point to the base of a malloc-ed area.

top


pointer-like behavior (instance)

+ anInteger
Return another instance of the receiver's class which points at &receiver[anInteger] (or, if you prefer, what `receiver + anInteger' does in C).

- intOrPtr

If intOrPtr is an integer, return another instance of the receiver's class pointing at &receiver[-anInteger] (or, if you prefer, what `receiver - anInteger' does in C). If it is the same class as the receiver, return the difference in chars, i.e. in bytes, between the two pointed addresses (or, if you prefer, what `receiver - anotherCharPtr' does in C)

addressAt: anIndex

Return a new CObject of the element type, corresponding to an object that is anIndex places past the receiver (remember that CObjects represent pointers and that C pointers behave like arrays). anIndex is zero-based, just like with all other C-style accessing.

at: anIndex

Dereference a pointer that is anIndex places past the receiver (remember that CObjects represent pointers and that C pointers behave like arrays). anIndex is zero-based, just like with all other C-style accessing.

at: anIndex put: aValue

Store anIndex places past the receiver the passed Smalltalk object or CObject `aValue'; if it is a CObject is dereferenced: that is, this method is equivalent either to cobj[anIndex]=aValue or cobj[anIndex]=*aValue. anIndex is zero-based, just like with all other C-style accessing. In both cases, aValue should be of the element type or of the corresponding Smalltalk type (that is, a String is ok for an array of CStrings) to avoid typing problems which however will not be signaled because C is untyped.

decr

Adjust the pointer by sizeof(dereferencedType) bytes down (i.e. --receiver)

decrBy: anInteger

Adjust the pointer by anInteger elements down (i.e. receiver -= anInteger)

incr

Adjust the pointer by sizeof(dereferencedType) bytes up (i.e. ++receiver)

incrBy: anInteger

Adjust the pointer by anInteger elements up (i.e. receiver += anInteger)

top


testing (instance)

isNull
Return true if the receiver points to NULL.

top


testing functionality (instance)

isCObject
Answer `true'.

top