Back: CLongDouble-accessing Up: Base classes Forward: CObject class-conversion   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.35 CObject

Defined in namespace Smalltalk
Superclass: Object
Category: Language-C interface
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.

1.35.1 CObject class: conversion  (class)
1.35.2 CObject class: instance creation  (class)
1.35.3 CObject class: primitive allocation  (class)
1.35.4 CObject class: subclass creation  (class)
1.35.5 CObject: accessing  (instance)
1.35.6 CObject: basic  (instance)
1.35.7 CObject: C data access  (instance)
1.35.8 CObject: conversion  (instance)
1.35.9 CObject: finalization  (instance)
1.35.10 CObject: pointer-like behavior  (instance)
1.35.11 CObject: testing  (instance)
1.35.12 CObject: testing functionality  (instance)


1.35.1 CObject class: conversion

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


1.35.2 CObject class: instance creation

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


1.35.3 CObject class: primitive allocation

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


1.35.4 CObject class: subclass creation

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


1.35.5 CObject: accessing

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.


1.35.6 CObject: basic

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

hash
Return a hash value for anObject.


1.35.7 CObject: C data access

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.


1.35.8 CObject: conversion

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


1.35.9 CObject: finalization

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.


1.35.10 CObject: pointer-like behavior

+ 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)


1.35.11 CObject: testing

isNull
Return true if the receiver points to NULL.


1.35.12 CObject: testing functionality

isCObject
Answer `true'.



Back: CObject-testing Up: CObject Forward: Collection   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on August, 19 2010 using texi2html