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: Re: #define SOMETHING some_value Date: Sun, 11 Jun 2017 13:07:20 -0700 Message-ID: References: <87shj62twk.fsf@netris.org> 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 1497211681 17369 195.159.176.226 (11 Jun 2017 20:08:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Jun 2017 20:08:01 +0000 (UTC) Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 11 22:07: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 1dK99R-0004Dv-Bk for guile-user@m.gmane.org; Sun, 11 Jun 2017 22:07:57 +0200 Original-Received: from localhost ([::1]:35059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dK99W-0000ai-O7 for guile-user@m.gmane.org; Sun, 11 Jun 2017 16:08:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dK98x-0000aX-Rd for guile-user@gnu.org; Sun, 11 Jun 2017 16:07:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dK98u-0000Q2-QH for guile-user@gnu.org; Sun, 11 Jun 2017 16:07:27 -0400 Original-Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:36360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dK98u-0000Pt-F8 for guile-user@gnu.org; Sun, 11 Jun 2017 16:07:24 -0400 Original-Received: by mail-pf0-x231.google.com with SMTP id x63so44399005pff.3 for ; Sun, 11 Jun 2017 13:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=nRoOSNknVuqQ6VduOor1nD9KOhi7EAwzq1PNTVf6Rqg=; b=TyA0vHMDhMeKdqlH9cmUPuWHmy4WQwVJdmpA8hfTKa1iqriMp1ZRSa4hUgBcwkEGDG Ag6dpCipvW9n2+hnc952MEYCk6uEJYlDHyleMvBlhbYiAofS6HHboyr4ufHyvtiAQc+D 27lZBegTKdyogyxz8rfdTeuLrjYhzu5k6t8wTyCBnyFN7HwXv2vyktwDvuAkjBvhvrhE pcP1itJ6/r1D8BZAoF5EQs1OBQ/1ObTRHAl4pMgi9JC6gHUXUQ6JsUHUwthLiUG6GYaH pHvF5yaMrisurSdOhSm9DebNVWbdFmazazZBfdmE/TinknUQVNYC6OQ20MqwfCeOPQ+C kSkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=nRoOSNknVuqQ6VduOor1nD9KOhi7EAwzq1PNTVf6Rqg=; b=QjFkscSUuvQ/4xiotkjuMrqT4K8alBoH5GtVQY6wmpo7iDpxSLSOvaXCl3FdtJHDGB pkT+/CrLeuaTyFRVDxNLJD7U5yUqcyA0a5WBUXewiwbE5v6ipkqncbkKhOCzZPM1mBi1 ldQ5fzLam6l7T2Y/gWSaAd7094gDdk6d6gbqGoZBWqlsEcgnGcyNnrAmSjAOjaEUYAdZ vS/ra10aLwYJ6f/+bJ+4lyBLs2KHiq+zv1gvQ59MOmDKDitaGAIfDmJefOTHuiA0Mnh7 pzh32eCyHHzFTew6XBVJvmQBG0RPYN0udfLllJamRvSmVGRD2xVhTgy5konV4pj6pqaE iLag== X-Gm-Message-State: AODbwcCgFqzoO/8WIlnl1qTU0Pl7xLNrKSvrN3384YBQjVynRSTjA2lo DdI3rjcFKqfLqg== X-Received: by 10.99.117.81 with SMTP id f17mr41184739pgn.117.1497211643214; Sun, 11 Jun 2017 13:07:23 -0700 (PDT) Original-Received: from [192.168.2.114] (216-165-236-44.championbroadband.com. [216.165.236.44]) by smtp.gmail.com with ESMTPSA id g27sm13240717pfd.80.2017.06.11.13.07.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Jun 2017 13:07:22 -0700 (PDT) In-Reply-To: <87shj62twk.fsf@netris.org> 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::231 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:13813 Archived-At: > On Jun 11, 2017, at 12:42 PM, Mark H Weaver wrote: >=20 > Amirouche Boubekki writes: >=20 >> What I do is that I hardcode the define in scheme using simple define = form >>=20 >> for instance, the following: >>=20 >> #define SOMETHING some_value >>=20 >> Becomes: >>=20 >> (define SOMETHING some_value) >=20 > Right. Unfortunately, preprocessor macros are replaced with their > right-hand-sides in the first phase of C compilation (preprocessing), > and then forgotten. These macros are not stored in the shared = objects, > so it's simply not possible for us to retrieve them. >=20 > For this reason, I'm sorry to say that the association between = SOMETHING > and some_value must be redundantly represented in your Guile bindings, > as Amirouche describes above. >=20 > It would be nice to have a tool to extract this information from .h > files automatically, but since there's no guarantee that the .h files > are present on the user's machine at run time, nor is there a robust = way > to find those .h files, this would be a tool for your convenience as a > developer, and would still require you to redundantly store the output > of this tool in your Scheme sources. >=20 > I'm sorry that I don't have a better answer for you. >=20 > Mark >=20 I am working on a tool =E2=80=9Cffi helper=E2=80=9D to automatically = generate the ffi code. The headers have to be present. And ffi-helper = will use pig-config to locate the header and libraries. With respect to = the #defines, I am working to autogenerate that, but I have to be able = to filter out the wanted stuff and not the cruft, so it will be looking = at simple defines (i.e., w/o args) and if those evaluate to a C constant = (e.g., integer or string) then keep, otherwise toss. Currently ffi-help will wrap enums. =46rom Cairo ;; typedef enum _cairo_status cairo_status_t; (define wrap-cairo_status_t (let ((vnl '((0 . CAIRO_STATUS_SUCCESS) (1 . CAIRO_STATUS_NO_MEMORY) (2 . CAIRO_STATUS_INVALID_RESTORE) ... (38 . CAIRO_STATUS_JBIG2_GLOBAL_MISSING) (39 . CAIRO_STATUS_LAST_STATUS)))) (lambda (name) (assq-ref vnl name)))) (define unwrap-cairo_status_t (let ((nvl '((CAIRO_STATUS_SUCCESS . 0) (CAIRO_STATUS_NO_MEMORY . 1) (CAIRO_STATUS_INVALID_RESTORE . 2) ... (CAIRO_STATUS_JBIG2_GLOBAL_MISSING . 38) (CAIRO_STATUS_LAST_STATUS . 39)))) (lambda (name) (assq-ref nvl name)))) (export wrap-cairo_status_t unwrap-cairo_status_t) It uses a helper file that looks like: ;; cairo.ffi -*- Scheme -*- (use-modules (ffi-help)) (define-ffi-helper (cairo cairo) #:pkg-config "cairo" #:include "cairo-svg.h" #:library "libcairo" #:filter (lambda (path) (string=3D? "cairo" (substring path 0 5))) )