[squeak-dev] FFI | How to declare pointer to external structure in #fields?

Eliot Miranda eliot.miranda at gmail.com
Mon May 18 19:31:31 UTC 2020


Hi Marcel,


ExternalStructure compileFields: #((other 'FFITestPoint2*')) a
WordArray(65544 131080)

ExternalStructure compileFields: #((other 'FFITestPoint2 *')) a
WordArray(65544 131080)

On Mon, May 18, 2020 at 12:27 PM Eliot Miranda <eliot.miranda at gmail.com>
wrote:

>
>
> On Mon, May 18, 2020 at 12:26 PM Eliot Miranda <eliot.miranda at gmail.com>
> wrote:
>
>> Hi Marcel,
>>
>> On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <marcel.taeumel at hpi.de>
>> wrote:
>>
>>> Hi, there!
>>>
>>> In the #fields method of a new ExternalStructure, how can I express a
>>> pointer to another external structure?
>>>
>>> First, non-pointer works as expected:
>>> ^ #( (other MyStruct) )
>>>
>>> Second, this just treats it as a void*, which returns a generic
>>> ExternalData:
>>> ^ #( (other 'MyStruct*') )
>>>
>>> Third, this gives me a debugger:
>>> ^ #( (other MyStruct *) )
>>>
>>> :-)
>>>
>>
>> ExternalStructure class>>#compileFields:withAccessors: implies it is some
>> variation on (filedName 'StructType *).
>>
>
> I mean  #(fieldName 'StructType*')
>
>
>> See
>>
>> fieldName := spec first.
>> fieldType := spec second.
>> isPointerField := fieldType last = $*.
>> fieldType := (fieldType findTokens: '*') first withBlanksTrimmed.
>> externalType := ExternalType atomicTypeNamed: fieldType.
>> selfRefering := isPointerField and: [externalType isNil and: [fieldType =
>> self asString]].
>> selfRefering ifTrue: [
>> externalType := ExternalType void asPointerType
>> ] ifFalse:[
>> externalType == nil ifTrue: ["non-atomic"
>> Symbol
>> hasInterned: fieldType
>> ifTrue: [:sym | externalType := ExternalType structTypeNamed: sym].
>> ].
>> externalType == nil ifTrue:[
>> Transcript show: '(' , fieldType , ' is void)'.
>> externalType := ExternalType void.
>> ].
>>
>> So ...isPointerField should be true.
>> ExternalType atomicTypeNamed: 'MyStruct*' should answer nil.
>> ExternalType structTypeNamed: sym should receive MyStruct.
>> If MyStruct doesn't answer anything (externalType is nil) then an error
>> should appear in the transcript.
>>
>> HTH
>> _,,,^..^,,,_
>> best, Eliot
>>
>
>
> --
> _,,,^..^,,,_
> best, Eliot
>


-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200518/dbecaf5f/attachment.html>


More information about the Squeak-dev mailing list