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.user Subject: ffi-helper: looking for C libraries to try Date: Fri, 14 Jul 2017 16:17:20 -0700 Message-ID: <22E467C6-8BCD-43B6-90B3-CFC43FC8799E@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 1500074283 21626 195.159.176.226 (14 Jul 2017 23:18:03 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 14 Jul 2017 23:18:03 +0000 (UTC) To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jul 15 01:17:58 2017 Return-path: Envelope-to: guile-user@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 1dW9qP-00052b-It for guile-user@m.gmane.org; Sat, 15 Jul 2017 01:17:57 +0200 Original-Received: from localhost ([::1]:40137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW9qQ-0001an-9i for guile-user@m.gmane.org; Fri, 14 Jul 2017 19:17:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW9q0-0001ah-5k for guile-user@gnu.org; Fri, 14 Jul 2017 19:17:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW9pv-0003A0-2D for guile-user@gnu.org; Fri, 14 Jul 2017 19:17:32 -0400 Original-Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:36009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW9pu-00039k-S2 for guile-user@gnu.org; Fri, 14 Jul 2017 19:17:26 -0400 Original-Received: by mail-pf0-x229.google.com with SMTP id q86so51685327pfl.3 for ; Fri, 14 Jul 2017 16:17:25 -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=xwRhicNfAX5vfWdwiKIMmggCqqVwhfrPbO1H8oLkVRU=; b=mSDCvpEw+LPjzpDgwp32/ocL8NbGVqs1kzczLwwPEuBha5xqc5E836SHfSuQ2NhQQP eosDzrip0CL2353c+5qp+gH02WEJQbAtuhHbxlLxKRpifT9UX9YB3fjRPJmzv6qHXVxH S9L0y9BXa82NdSYBSiKSD9BPxqeTO51RpsU+f7LESuAc+Y/3EJvseR9DQHYGwnT/dW2F kM5lUu8EF3oNmGCUBWcb01FZdQxIxaGPQ8Uws7zjHvQiok1ZoRMgOKPSB+bVtBVa1HDq YmkgSRT+a2+nsBH2v4KAddVNTEDSrp+XZ7TtJeuR5JY/uMXArSoU6EufZN5gO8JbyIkC I5Zg== 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=xwRhicNfAX5vfWdwiKIMmggCqqVwhfrPbO1H8oLkVRU=; b=O2qZccV6NW54UnQbBjBbESt9vTVUjA71QpwN/8Yk5uuhH+DnQ0tsAfC5WCrXiBZF9R tbJdfBEoRkAVvbpLmo9URLFvEgBeTqwC0bQrM5QiSCS3oYVVHF8cjF6w9n14A9G5XHSd ru+YxupLnS858plIeWwGOOZQ8eBTK60h742q/PSeeSNqfiDGLVUcqspM9Sozm9Eit1on 3hz3k+r00CxPGhM0vqK1EgiadbuAM9GRV7vCyw46gj9gH4oFO+XMU8yWc80d4eoyKP6h xADUcx56WNV550G+VJ9RQ3GJyus+qnnpiaEvhiH11ALEGi2DXEv/CUPJ8jHAXh9ZzS5S IFyw== X-Gm-Message-State: AIVw110tPB6fern8MTmgRwPkH1xlnPSgN/ytk/ELpOBYvokMYPFqpUGW f5PWaObyVxxSnTvPnbY= X-Received: by 10.99.53.129 with SMTP id c123mr17095916pga.87.1500074243705; Fri, 14 Jul 2017 16:17:23 -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 204sm19143223pfu.50.2017.07.14.16.17.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 16:17:22 -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::229 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13920 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 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.=20 If you have suggestions for test cases, please post. They should be = commonly used. =20 (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=E2=80=99m = sure bugs remain. (define-ffi-module (cairo cairo) #:pkg-config "cairo" #:include '(=E2=80=9Ccairo.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 =E2=80=9Ccairo.ffi=E2=80=9D file to =E2=80=9Ccairo.scm= =E2=80=9D 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 =E2=80=9Ccairo.ffi=E2=80=9D= 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) ;; =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)=