[Top][All Lists]

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

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

From: Matt Wette
Subject: Re: How to pass the address of an pointer object to c?
Date: Sun, 1 Apr 2018 06:19:41 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 04/01/2018 03:22 AM, Fis Trivial wrote:
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. :)

(let* ((val (make-bytevector (sizeof '*)))
         (&val (bytevector->pointer))

reply via email to

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