From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.devel Subject: ffi-helper: status Date: Fri, 7 Jul 2017 17:18:08 -0700 Message-ID: <0EB36A0A-DB92-4007-8906-3C8953045E69@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499473114 3911 195.159.176.226 (8 Jul 2017 00:18:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 8 Jul 2017 00:18:34 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jul 08 02:18:27 2017 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTdS1-0000Gf-0b for guile-devel@m.gmane.org; Sat, 08 Jul 2017 02:18:21 +0200 Original-Received: from localhost ([::1]:59293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTdS1-0003BP-D1 for guile-devel@m.gmane.org; Fri, 07 Jul 2017 20:18:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTdRv-0003BG-QZ for guile-devel@gnu.org; Fri, 07 Jul 2017 20:18:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTdRs-0008KC-MT for guile-devel@gnu.org; Fri, 07 Jul 2017 20:18:15 -0400 Original-Received: from mail-pf0-x22d.google.com ([2607:f8b0:400e:c00::22d]:35664) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dTdRs-0008Jo-Ft for guile-devel@gnu.org; Fri, 07 Jul 2017 20:18:12 -0400 Original-Received: by mail-pf0-x22d.google.com with SMTP id c73so24011638pfk.2 for ; Fri, 07 Jul 2017 17:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=aTdUODrzPZOoScnnGsLal2Ucl6c/Czc16ZVUKRhAhvg=; b=TgWQVzRHggsKHulp7RyotaSxaJPWsia7CsqOUuMKEns2OCtQMmHsr1xk52LcjQztoR ZsPxGi0U0cwjmt9nVC1qK91DFIQzTn/uk/VMtQqBNnumPCOvAK/qGqru1Zukjyopm7qu HbkEfDcy4OqgTqEw9f5+y1OfF7bIcZgsbTtPQeoXuT16XAfIEDyu4QEbxMj7/JxzS0+q qKjXSNU7r70HZGLHxvdTMiQ7BHYvlhNgq2ZS8WgvEXauVwaZuQRCtjG2qXcv7BQw3Yr0 f8xhN18qfKOatLhkeLrnWQypdC7q6HQVCQCpNFSxCTpmmQMakSEiuAcJvxZSBivv+eEY 8BxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=aTdUODrzPZOoScnnGsLal2Ucl6c/Czc16ZVUKRhAhvg=; b=MC8DKK+o2O/GwEFgu5P6XizkOu9gTLtIe64eqcF7/YzlUb4fxUGxCW/mymXWOm02cp dNYO5B0Ao73FMnL5dwe8inOAI16vxdaGLypmjcmHBIDq4we6qzVw5f+5+SWcUFgbb205 wwRWj6a2Hnbpli4T++cf6K9Iz0VXZtKlVFws1P9/5ZtcneKHnwCFYzvi/IBAfPCkWikn CX6a6O91Kpz5hmcSN+qwhUxGf5BrWw7S0Co9FdL/MQZhQmY/rref+9Bf8N4jjejfR+uv hvTNGs5mUNE2uhjKokKQNoXIjl3VkYqzxhLLBxtJX1v5L0KL85kCrNf3JY9HzlbnFSh2 z4QA== X-Gm-Message-State: AIVw110r8tQGBfygaQw2oHMXufvGwJoqTD1ujZOD9X210LwA5CaxgMfR 4fbxZM31K3OyJFbfzsE= X-Received: by 10.99.97.69 with SMTP id v66mr3840957pgb.217.1499473091032; Fri, 07 Jul 2017 17:18:11 -0700 (PDT) Original-Received: from nautilus.championbroadband.com (216-165-236-44.championbroadband.com. [216.165.236.44]) by smtp.gmail.com with ESMTPSA id e131sm7923764pgc.64.2017.07.07.17.18.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jul 2017 17:18:09 -0700 (PDT) X-Mailer: Apple Mail (2.3273) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22d X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19243 Archived-At: 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 have now been able to compile-ffi the following on my Mac. There is = some non-standard C syntax in sys/cdefs.h that is driving me crazy, but I have a hack around it (see inc-help = below). I=E2=80=99m sure there are numerous bugs. (define-ffi-module (cairo cairo) #:pkg-config "cairo" #:include '("cairo.h" "cairo-pdf.h" "cairo-svg.h" ) #:inc-help (cond ((string-contains %host-type "darwin") '(("__builtin" "__builtin_va_list=3Dvoid*") ("sys/cdefs.h" "__DARWIN_ALIAS(X)=3D"))) (else '())) ;; 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))) Some of the other Cairo headers (e.g., cairo-ft.h) give me problems with = the rat=E2=80=99s nest under /usr/include. However, the above generates 397 FFI declarations into a cairo.scm file = which is about 6000 lines long. I=E2=80=99m not=20 sure if I want to start testing this code or start converting = suggestions and have guile-users do some testing. =20 Matt P.S. Here is some sample code from the auto-generated file = cairo/cairo.scm. =20 Notice that the helper includes the original C declarations as comments. ;; 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) ;; =3D> 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=20 ;; cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t=20= ;; 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)