unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: #define SOMETHING some_value
Date: Thu, 15 Jun 2017 12:21:57 -0700	[thread overview]
Message-ID: <81DEFAEA-2D17-41BC-B5ED-5993ACDB7FCE@gmail.com> (raw)
In-Reply-To: <87shj62twk.fsf@netris.org>


> On Jun 11, 2017, at 12:42 PM, Mark H Weaver <mhw@netris.org> wrote:
> 
> Amirouche Boubekki <amirouche.boubekki@gmail.com> writes:
> 
>> What I do is that I hardcode the define in scheme using simple define form
>> 
>> for instance, the following:
>> 
>> #define SOMETHING some_value
>> 
>> Becomes:
>> 
>> (define SOMETHING some_value)
> 
> 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.
> 
> 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.
> 
> 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.
> 
> I'm sorry that I don't have a better answer for you.
> 
>      Mark
> 

I now have my ffi-helper automatically extracting #defines which are constants.
I process on cairo-svg.h + cairo.h and get the following.  I don’t think defining
and exporting all these as (define CAIRO_VERSION_MAJOR 1) etc is a good idea.

Comments on this method of providing access?

Matt

(define xxx-def-val
  (let ((deftab
	'((CAIRO_VERSION_MAJOR . 1)
	  (CAIRO_VERSION_MINOR . 14)
	  (CAIRO_VERSION_MICRO . 8)
	  (CAIRO_HAS_FC_FONT . 1)
	  (CAIRO_HAS_FT_FONT . 1)
	  (CAIRO_HAS_GOBJECT_FUNCTIONS . 1)
	  (CAIRO_HAS_IMAGE_SURFACE . 1)
	  (CAIRO_HAS_MIME_SURFACE . 1)
	  (CAIRO_HAS_OBSERVER_SURFACE . 1)
	  (CAIRO_HAS_PDF_SURFACE . 1)
	  (CAIRO_HAS_PNG_FUNCTIONS . 1)
	  (CAIRO_HAS_PS_SURFACE . 1)
	  (CAIRO_HAS_QUARTZ_FONT . 1)
	  (CAIRO_HAS_QUARTZ_IMAGE_SURFACE . 1)
	  (CAIRO_HAS_QUARTZ_SURFACE . 1)
	  (CAIRO_HAS_RECORDING_SURFACE . 1)
	  (CAIRO_HAS_SCRIPT_SURFACE . 1)
	  (CAIRO_HAS_SVG_SURFACE . 1)
	  (CAIRO_HAS_TEE_SURFACE . 1)
	  (CAIRO_HAS_USER_FONT . 1)
	  (CAIRO_HAS_XCB_SURFACE . 1)
	  (CAIRO_HAS_XLIB_SURFACE . 1)
	  (CAIRO_HAS_XLIB_XCB_FUNCTIONS . 1)
	  (CAIRO_HAS_XLIB_XRENDER_SURFACE . 1)
	  (CAIRO_HAS_XML_SURFACE . 1)
	  )))
    (lambda (k) (assq-ref deftab k))))





  parent reply	other threads:[~2017-06-15 19:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-10  8:31 #define SOMETHING some_value Catonano
2017-06-10  9:51 ` Amirouche Boubekki
2017-06-11 19:42   ` Mark H Weaver
2017-06-11 20:07     ` Matt Wette
2017-06-15 19:21     ` Matt Wette [this message]
2017-06-16 16:37       ` Catonano
2017-06-10 15:55 ` Matt Wette
2017-06-11 17:08   ` Catonano
2017-06-11 20:06     ` Mark H Weaver
2017-06-11 20:32       ` Catonano

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=81DEFAEA-2D17-41BC-B5ED-5993ACDB7FCE@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.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).