guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to pass the address of an pointer object to c?


From: Fis Trivial
Subject: How to pass the address of an pointer object to c?
Date: Sun, 1 Apr 2018 10:22:25 +0000

Hi, all.
I'am trying a wrap a math library written in c with guile scheme. Here
is an example declaration of c type and function in that math library:

typedef void* array;
typedef int err;

err randu(array* result, int ndims, long long *dims, dtype type);



The problem is I want to create a void* (aka array), and pass its
address (aka array*) to the underlying c function for modification. Here
the /array/ type acts as a handle.

I tried the following scheme code:

(let* ([val (make-pointer 0)]                     ; void* val = 0
       [&val (make-pointer (object-address val))] ; a pointer points to val?
       [randu (pointer->procedure int
                                   ; a function generating random matrix.
                                  (dynamic-func "randu" backend)
                                   ; result, ndims, dims, type
                                  (list '* uint32 '* int))]
       ; dims is an byte-vector representing c array, 0 represents an
       ; enum value in c.
       (randu &val 4 dims 0)))


But when I use gdb to watch the values in c code of randu with:
print *result

and gdb displayed:  0x1f,
while it should be 0 as defined in scheme code.

Is there anything I did wrong? Or there are other ways around? I want to
do it in scheme, otherwise I have to wrap every c functions.

Thanks. :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]