Object>>rollToArity:?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Object>>rollToArity:?

abergel
Esteban,

What Object>>rollToArity: is supposed to do? It belongs to UnifiedFFI

Cheers,
Alexandre
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Object>>rollToArity:?

EstebanLM
I’m not happy with the method name, but I think is well explained in method comments:

ExternalAddress>>rollToArity: arity
        "This will 'roll' a pointer to a certain arity.
        What does this means? Let's say I have a method who will be called with a ** arity:
       
        method: aPointer
                self ffiCall: #( method ( MyExternalObjectClass **aPointer) )
               
        This usually means that method will put a pointer in the address of aPointer.
        And what I actually want is this pointer. So I do Something like this:
       
        p := MyExternalObjectClass new.
        self mehod: p.
       
        And I expect to have 'p' correctly initialised on return.
        Well... tha's not so simple :)
       
        When compiling #method:, UnifiedFFI needs to first 'roll' the pointer (which means to
        take a pointer of a pointer of a pointer... as many pointers as arity solicited), and then,
        after call, it needs to 'unroll' all this pointers (see #unrollFromArity: method)  
        “

ByteArray>>rollToArity: arity
        "This is complicated... I assuming this ways of calling a function:
         
  arity == 1:
        -----------
        ByteArray works as pointer buffer of single pointer to something:
        ex 1)
                buffer := ByteArray new: 4.
                self ffiCall: #( void function (int *buffer) ).
        ex 2)
                buffer := 'Hello, World' asByteArray.
                self ffiCall: #( void function (char *buffer) ).
       
        arity > 1:
        ----------
        ByteArray works as pointer to allocate results:
        ex 1)
                pointer := ByteArray new: (FFIExternalType pointerSize).
                self ffiCall: #( void function ( char **answer )).
           
        In this case this will not work fine because content of ByteArray needs to be a
        pointer too, and then it needs to be allocated in the heap... while this could be
        managed, I'm puting for the moment just an error and a recommendation of using an
        ExternalAddress.
        "


basically, is the equivalent of “&” operator in C.
you can manually do the same by doing:

| var |
var := 42 pointer.

who will give you a byte array with signedLongAt: 1 == 42.

… but since old NB was doing this implicitly, we need to provide it too :)

Esteban

ps: Why do you need to know it? This is internal in UnifiedFFI so nobody should need to deal with it.

> On 17 Feb 2016, at 16:49, Alexandre Bergel <[hidden email]> wrote:
>
> Esteban,
>
> What Object>>rollToArity: is supposed to do? It belongs to UnifiedFFI
>
> Cheers,
> Alexandre
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
>
>
>
>