guile-user
[Top][All Lists]
Advanced

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

Re: ffi helper


From: Matt Wette
Subject: Re: ffi helper
Date: 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.
>> 
>> Matt
> 
> 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" [1]. 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 [2]. What is
> specific about it is that it has functions pointers
> in struct.
> 
> Tx:)
> 
> [1] https://libgit2.github.com/libgit2/#HEAD/group/clone/git_clone
> [2] 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);
(define git_clone
 (let ((f (pointer->procedure
             int
             (lib-func "git_clone")
             (list '* '* '* '*))))
    (lambda (url local_path options)
      (let* ((out_ptr (make-pointer 0))
             (out_ptr_ptr (scm->pointer out_ptr))
             (_out_ptr_ptr (pointer-address))
             (_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)
            out_ptr
            (error "call failed"))))))




reply via email to

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