From: serg on

Hello,

part of C library looks like:

typedef struct some_struct {
. . .
} some_struct;

int func_1(some_struct **ic_ptr);

int func_2(some_struct *ic);


There are appropriate CL cffi descriptions:

(cffi:defcstruct some-struct
. . .
)

(cffi:defcfun ("func_1" func-1) :int
(ic-ptr :pointer))

(cffi:defcfun ("func_2" func-2) :int
(ic :pointer))


Provided the necessary parts are loaded in image
how could next C statements expressed in CL?

some_struct *p;

func_1(&p);
func_2(p);

--
Regards,
Serg

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Stelian Ionescu on
On Thu, 15 Apr 2010 17:22:55 +0300, serg wrote:

> Hello,
>
> part of C library looks like:
>
> typedef struct some_struct {
> . . .
> } some_struct;
>
> int func_1(some_struct **ic_ptr);
>
> int func_2(some_struct *ic);
>
>
> There are appropriate CL cffi descriptions:
>
> (cffi:defcstruct some-struct
> . . .
> )
>
> (cffi:defcfun ("func_1" func-1) :int
> (ic-ptr :pointer))
>
> (cffi:defcfun ("func_2" func-2) :int
> (ic :pointer))
>
>
> Provided the necessary parts are loaded in image how could next C
> statements expressed in CL?
>
> some_struct *p;
>
> func_1(&p);
> func_2(p);

What you need to keep in mind is that there's no «&» in CFFI, but only
«*»; therefore you need to change your code to this style:

some_struct **p = alloca(sizeof(some_struct *));
func_1(p);
func_2(*p);

so:

(with-foreign-object (p :pointer)
(func-1 p)
(func-2 (mem-ref p :pointer)))

just like alloca, with-foreign-object allocated the pointer on the stack
(at least on the best CL implementations: SBCL, CCL, etc...)

--
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
http://common-lisp.net/project/iolib