unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: Guile User <guile-user@gnu.org>
Subject: ffi-helper: looking for C libraries to try
Date: Fri, 14 Jul 2017 16:17:20 -0700	[thread overview]
Message-ID: <22E467C6-8BCD-43B6-90B3-CFC43FC8799E@gmail.com> (raw)


Hi All,

I am working on a ffi-helper: a program that will read in a C dot-h file and generate a Guile dot-scm file which
defines a module to provide hooks into the associated C library.  My goal is to have something to release ~Oct 2017.

I am looking for suggestions for libraries (w/ includes of course) to use as test cases to flush-out and debug my code.  I have worked on cairo and now working on gdbm.  I tried git2 but those headers are too broken. 

If you have suggestions for test cases, please post.  They should be commonly used.  
(I use MacPorts and would want them to be installable in that context.)

Status:

I have now been able to compile-ffi the following on my Mac. I’m sure bugs remain.

(define-ffi-module (cairo cairo)
 #:pkg-config "cairo"
 #:include '(“cairo.h" "cairo-pdf.h" "cairo-svg.h")

 ;; the following are bent pipe to scm-module
 #:export (make-cairo-unit-matrix)
 )

(define (make-cairo-unit-matrix)
 (make-cairo_matrix_t #(1.0 0.0 0.0 1.0 0.0 0.0)))

I convert the above “cairo.ffi” file to “cairo.scm” using the following command

	mwette$ guild compile-ffi cairo/cairo.ffi

The above generates 397 FFI declarations in cairo.scm, a file which is about 6000 lines long, compared to the original “cairo.ffi” which is less than 10 lines long.

Some generated code:

;; typedef struct _cairo_device cairo_device_t;
(define-fh-pointer-type cairo_device_t*)

;; union _cairo_path_data_t {
;;   struct {
;;     cairo_path_data_type_t type;
;;     int length;
;;   } header;
;;   struct {
;;     double x, y;
;;   } point;
;; };
(define cairo_path_data_t-desc
 (bs:union
   (list `(header
            ,(bs:struct
               (list `(type ,cairo_path_data_type_t-desc)
                     `(length ,int))))
         `(point ,(bs:struct (list `(y ,double) `(x ,double)))))))
(export cairo_path_data_t-desc)
(define-fh-bytestructure-type/p cairo_path_data_t cairo_path_data_t-desc)
(define union-_cairo_path_data_t cairo_path_data_t)

;; typedef enum _cairo_path_data_type {
;;   CAIRO_PATH_MOVE_TO,
;;   CAIRO_PATH_LINE_TO,
;;   CAIRO_PATH_CURVE_TO,
;;   CAIRO_PATH_CLOSE_PATH,
;; } cairo_path_data_type_t;
(define-fh-enum-type cairo_path_data_type_t
 '((CAIRO_PATH_MOVE_TO . 0)
   (CAIRO_PATH_LINE_TO . 1)
   (CAIRO_PATH_CURVE_TO . 2)
   (CAIRO_PATH_CLOSE_PATH . 3))
 )

;; typedef void (*cairo_destroy_func_t)(void *data);
(define (wrap-cairo_destroy_func_t proc) ;; => pointer
(ffi:procedure->pointer ffi:void proc (list '*))
)
(export wrap-cairo_destroy_func_t)

;; cairo_status_t cairo_device_set_user_data(cairo_device_t *device, const 
;;     cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t 
;;     destroy);
(define cairo_device_set_user_data
 (let ((~f (ffi:pointer->procedure
             ffi:int
             (lib-func "cairo_device_set_user_data")
             (list '* '* '* '*))))
   (lambda (device key user_data destroy)
     (let ((~device (unwrap-cairo_device_t* device))
           (~key (unwrap-cairo_user_data_key_t* key))
           (~user_data (unwrap~pointer user_data))
           (~destroy (unwrap-cairo_destroy_func_t destroy)))
       (wrap-cairo_status_t
         (~f ~device ~key ~user_data ~destroy))))))
(export cairo_device_set_user_data)


             reply	other threads:[~2017-07-14 23:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 23:17 Matt Wette [this message]
2017-07-15  0:04 ` ffi-helper: looking for C libraries to try Mike Gran
2017-07-15  0:44 ` Amirouche Boubekki
2017-07-15  4:35   ` Matt Wette
2017-07-15  8:24     ` Amirouche
2017-07-15 12:37       ` Matt Wette
2017-07-15 12:42         ` Matt Wette
2017-07-15 13:15     ` Matt Wette
2017-08-01 16:20       ` Matt Wette
2017-07-15  0:55 ` Amirouche
2017-07-15  3:01   ` Matt Wette
2017-08-08 10:00 ` Catonano
2017-08-12 19:55   ` Matt Wette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22E467C6-8BCD-43B6-90B3-CFC43FC8799E@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).