[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ffi helper
Re: ffi helper
Thu, 23 Mar 2017 18:43:02 -0700
> On Mar 23, 2017, at 10:43 AM, Amirouche <address@hidden> wrote:
> Héllo Matt!
> Le 09/03/2017 à 03:06, Matt Wette a écrit :
>> I’m now working on a FFI helper based on the nyacc C99 parser.
>> My current prototyping goal is to autogenerate the functions for cairo.h.
>> I will assume going with scheme-bytestructures.
>> I’ll keep this list posted on progress.
> Let me know, when it will be possible to try.
> FWIW I started some bindings for libgit2 but
> I got stuck... Basically because it's overwhelming.
> I got stuck trying to bind "git clone" . Here is the signature:
> |int git_clone(git_repository **out, const char *url, const char *local_path,
> const git_clone_options *options);|
> It requires a double pointer "out". Then it also
> has a "options" which is a "git_clone_options" struct
> which in turns requires |another struct named git_checkout_options.
> I am still not sure how to declare function pointers in
> guile-bytestructures and libgit2 make heavy use of those.
> It's located at https://gitlab.com/amirouche/guile-git
> Maybe it's too complicated, instead I can try to
> regenerate my wiredtiger bindings . What is
> specific about it is that it has functions pointers
> in struct.
>  https://libgit2.github.com/libgit2/#HEAD/group/clone/git_clone
>  which has unit tests, so it will be "easy" to know if it works or not
Lot of good items to chew on. I will be looking as far as the pointer pointer
I wonder if this will work for the out
(use-modules ((bytestructures guile) #:prefix bs:))
(use-modules ((system foreign) #:prefix ffi:))
;; int git_clone(git_repository **out,
;; const char *url,
;; const char *local_path,
;; const git_clone_options *options);
(let ((f (pointer->procedure
(list '* '* '* '*))))
(lambda (url local_path options)
(let* ((out_ptr (make-pointer 0))
(out_ptr_ptr (scm->pointer out_ptr))
(_url (string->pointer url))
(_local_path (string->pointer local_path))
(_options (make-pointer 0)) ;; todo
(res (f out_ptr_ptr _url _local_path _options)))
(if (zero? res)
(error "call failed"))))))