guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #define SOMETHING some_value


From: Matt Wette
Subject: Re: #define SOMETHING some_value
Date: Thu, 15 Jun 2017 12:21:57 -0700

> On Jun 11, 2017, at 12:42 PM, Mark H Weaver <address@hidden> wrote:
> 
> Amirouche Boubekki <address@hidden> 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))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]