eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ExternalStructure':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ExternalStructure


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--ExternalBytes
                  |
                  +--ExternalStructure

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.10 date: 2018/05/11 01:36:37
user: cg
file: ExternalStructure.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


Instances of this class represent external (non-Smalltalk) data,
typically C-structs or C++ instances.
They are only useful to represent handles as returned by C functions as smalltalk objects.

ExternallStructures are much like ExternalBytes - however, the latter
allow you to access bytes via indexed at:/at:put: messages, whilst instances of subclasses of me
allow access via the corresponding getter/setter methods of my C-type.

Usage: normally (within eXept), these are to be used with the ctype framework, which parses
c header files and generates structure descriptions (ctypes).
However, this class can also be used without such type descriptions, by subclassing it
and redefining sizeof (to return the size in bytes of the structure) and getters
(as 'self longAt:idx', unsignedLOngAt:idx, etc.).


Related information:

    ExternalBytes
    ExternalAddress
    [how to write primitive code]

Class protocol:

Squeak compatibility
o  externalNew

instance creation
o  fromExternalAddress: anExternalAddress

o  new
allocate some memory usable for data;
the memory is not controlled by the garbage collector.
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).

Use this, if you have to pass a block of bytes to some
external destination (such as a C function) which does not copy the
data, but instead keeps a reference to it. For example, many functions
which expect strings simply keep a ref to the passed string - for those,
an ST/X string-pointer is not the right thing to pass, since ST/X objects
may change their address.

DANGER ALERT: the memory is NOT automatically freed until it is either
MANUALLY freed (see #free) or the returned externalBytes object
is unprotected or the classes releaseAllMemory method is called.

o  unprotectedNew
allocate some memory usable for data;
the memory is under the control of the garbage collector.
Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).

DANGER ALERT: the memory block as allocated will be automatically freed
as soon as the reference to the returned externalBytes object
is gone (by the next garbage collect).
If the memory has been passed to a C-function which
remembers this pointer, bad things may happen ....

queries
o  cType

o  fields
for Squeak compatibility support: may return a literal array structure definition,
from which the size and layout of the fields can be constructed.
Returns nil for ST/X subclasses, which redefine the sizeof method

o  sizeof
the sizeof my instances in bytes

** This method raises an error - it must be redefined in concrete classes **

utilities
o  generateCTypeFromFieldDescription: fieldsSpec
to support Squeak external structures, which define a fields method,
which returns a literal array spec of fields


Instance protocol:

private
o  fromExternalAddress: anExternalAddressOrExternalStructure

testing
o  isExternalStructure



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 23 Sep 2018 10:28:45 GMT