pointers as parameters / dllcc

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

pointers as parameters / dllcc

Matthias Junker
i'm new with dllcc and i have a question. let's assume i have the following
c function signature:

void apr_hash_this(apr_hash_index_t *hi, const void **key,
                                apr_ssize_t *klen, void **val);

key and val are the pointers where the results of the function are stored.

now: that's how i can use it in c:

          const char *entryname;
          svn_dirent_t *val;
     
          apr_hash_this (hi, (void *) &entryname, NULL, (void *) &val);

(nevermind hi and NULL, got that figured out)

so now my question: how can i create the parameters val and entryname
properly,
so that i can invoke that function?
i couldn't find anything in the dllcc manual, if i missed something,
please hit me.

any help is really apreciated.

Matt


Reply | Threaded
Open this post in threaded view
|

Re: pointers as parameters / dllcc

Reinout Heeck

On Oct 23, 2007, at 1:09 AM, Matthias Junker wrote:

> i'm new with dllcc and i have a question. let's assume i have the  
> following
> c function signature:
>
> void apr_hash_this(apr_hash_index_t *hi, const void **key,
>                                apr_ssize_t *klen, void **val);
>
> key and val are the pointers where the results of the function are  
> stored.
>
> now: that's how i can use it in c:
>
>          const char *entryname;
>          svn_dirent_t *val;
>               apr_hash_this (hi, (void *) &entryname, NULL, (void  
> *) &val);
>
> (nevermind hi and NULL, got that figured out)
>
> so now my question: how can i create the parameters val and  
> entryname properly,
> so that i can invoke that function?


Essentially you need to do the same as in C.
-allocate space for the result holders
-call into c
-obtain/use the content of the result holder
-deallocate the result holders


Here is an example, the temp variables 'keys' and 'values' are of  
interest.
Note how they get allocated (using #calloc), dereferenced (using  
#contents) and freed (using #freePointer).


importCFDictionary: aRef
        | keys values size res |
        size := self CFDictionaryGetCount: aRef.
        keys := self CFPropertyListRef calloc: size.
       
        [values := self CFPropertyListRef calloc: size.
       
        [self
                CFDictionaryGetKeysAndValuesDict: aRef
                keys: keys
                values: values.
        res := Dictionary new.
        0 to: size - 1
                do:
                        [:offset |
                        | key value |
                        key := self importCFString: keys contents.
                        keys += 1.
                        value := self importCFObject: values contents.
                        values += 1.
                        res at: key put: value].
        ^res]
                        ensure: [values freePointer]]
                        ensure: [keys freePointer]


HTH,

Reinout
-------