[squeak-dev] FFI - structure pointer

Schwab,Wilhelm K bschwab at anest.ufl.edu
Sat Apr 3 13:36:56 UTC 2010

Andreas, John, anybody,

I need to find the address of a "function" (it is in fact a global structure pointer somewhere in memory) and pass it to another function.

Suppose the structure is called Type and the function allocate_one().  I call the function something like

allocateOne:type size:anInt
  <cdecl: SomeOtherStruct* 'allocate_one' ( Type* long ) >

but I am having an awful time getting the pointer to Type.  Given that dlsym() will return a pointer to it, how can I represent that in Smalltalk?  I have tried variations on

  "Indirectly call dlsym()"
  address := Library default getProcAddress:'name_of_global_struct'.

  "try to create Type* from the resulting address"
  type := Type fromHandle:address.
  type := Type fromHandle:address getHandle.
  type := ExternalData fromHandle:address type:Type externalType asPointerType.

  Something := Library default allocateOne:type size:2.

and it either complains about bad arguments during the call or segment faults.  Any ideas or similar examples?


More information about the Squeak-dev mailing list