www.delorie.com/gnu/docs/smalltalk/gst_37.html   search  
 
Buy GNU books!


GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6 Other functions available to modules

In addition to the functions above, the VMProxy that is made available to modules contains entry-points for many functions that aid in developing GNU Smalltalk extensions in C. This node documents these functions and the macros that are defined by `libgst/gstpub.h'.

Function: void asyncSignal (OOP)
This functions accepts an OOP for a Semaphore object and signals that object so that one of the processes waiting on that semaphore is waken up. Since a Smalltalk call-in is not an atomic operation, the correct way to signal a semaphore is not to send the signal method to the object but, rather, to use:

 
    asyncSignal(semaphoreOOP)

The signal request will be processed as soon as the next message send is executed.

Caution: This and the next one are the only functions in the intepreterProxy that can be called from within a signal handler.

Function: void asyncSignalAndUnregister (OOP)
This functions accepts an OOP for a Semaphore object and signals that object so that one of the processes waiting on that semaphore is waken up; the signal request will be processed as soon as the next message send is executed. The object is then removed from the registry.

Function: void syncWait (OOP)
This functions accepts an OOP for a Semaphore object and puts the current process to sleep, unless the semaphore has excess signals on it. Since a Smalltalk call-in is not an atomic operation, the correct way to signal a semaphore is not to send the wait method to the object but, rather, to use:

 
    syncWait(semaphoreOOP)

The sync in the name of this function distinguishes it from asyncSignal, in that it cannot be called from within a signal handler.

Function: OOP objectAlloc (OOP, int)
The objectAlloc function allocates an OOP for a newly created instance of the class whose OOP is passed as the first parameter; if that parameter is not a class the results are undefined (for now, read as "the program will most likely core dump", but that could change in a future version).

The second parameter is used only if the class is an indexable one, otherwise it is discarded: it contains the number of indexed instance variables in the object that is going to be created. Simple uses of objectAlloc include:

 
OOP myClassOOP;
OOP myNewObject;
myNewObjectData obj;
...
myNewObject = objectAlloc(myClassOOP, 0);
obj = (myNewObjectData) OOP_TO_OBJ (myNewObject);
obj->arguments = objectAlloc(classNameToOOP("Array"), 10);
...

The macros are(15):

Macro: mst_Object OOP_TO_OBJ (OOP)
Dereference a pointer to an OOP into a pointer to the actual object data (see section 3.7 Manipulating instances of your own Smalltalk classes from C). The result of OOP_TO_OBJ is not valid anymore if a garbage-collection happens; for this reason, you should assume that a pointer to object data is not valid after doing a call-in, calling objectAlloc, and caling any of the "C to Smalltalk" functions (see section 3.4 Manipulating Smalltalk data from C).

Macro: OOP OOP_CLASS (OOP)
Return the OOP for the class of the given object. For example, OOP_CLASS(proxy->stringToOOP("Wonderful GNU Smalltalk")) is the String class, as returned by classNameToOOP("String").

Macro: mst_Boolean IS_INT (OOP)
Return a Boolean indicating whether or not the OOP is an Integer object; the value of SmallInteger objects is encoded directly in the OOP, not separately in a mst_Object structure. It is not safe to use OOP_TO_OBJ and OOP_CLASS if isInt returns false.

Macro: mst_Boolean IS_OOP (OOP)
Return a Boolean indicating whether or not the OOP is a `real' object (and not a SmallInteger). It is safe to use OOP_TO_OBJ and OOP_CLASS only if IS_OOP returns true.

Macro: mst_Boolean ARRAY_OOP_AT (mst_Object, int)
Access the character given in the second parameter of the given Array object. Note that this is necessary because of the way mst_Object is defined, which prevents indexedOOP from working.

Macro: mst_Boolean STRING_OOP_AT (mst_Object, int)
Access the character given in the second parameter of the given String or ByteArray object. Note that this is necessary because of the way mst_Object is defined, which prevents indexedByte from working.

Macro: mst_Boolean INDEXED_WORD (some-object-type, int)
Access the given indexed instance variable in a variableWordSubclass. The first parameter must be a structure declared as described in 3.7 Manipulating instances of your own Smalltalk classes from C).

Macro: mst_Boolean INDEXED_BYTE (some-object-type, int)
Access the given indexed instance variable in a variableByteSubclass. The first parameter must be a structure declared as described in 3.7 Manipulating instances of your own Smalltalk classes from C).

Macro: mst_Boolean INDEXED_OOP (some-object-type, int)
Access the given indexed instance variable in a variableSubclass. The first parameter must be a structure declared as described in 3.7 Manipulating instances of your own Smalltalk classes from C).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003