[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: New way to do XS constants



Excerpts from the mail message of Graham Barr:
) #ifdef B110
)         newCONSTSUB(stash,"B110", newSViv(B110));
) #else
)         av_push(export_fail, newSVpv("B110",4));
) #endif
) 
) So that the import of B110 will fail if it does not exist.
) 
) But all of this requires entering long-hand. I think the original
) question was to get xsubpp to help out a bit, which I think would
) be a good idea.

Okay, so I should modify constants_pm_c.PLX to add code to the
C<XS(boot_Module__Name)> routine in the generated Name.c?
Perhaps just a C<#include "constants.h"> with F<constants.h>
generated by a modified constants_pm_c.PLX [otherwise the
B<make> dependencies would be too tricky]?

I guess having the C++ detect-the-data-type-of-the-constant hack
in the module load routine doesn't really add much overhead since
that determination is actually made at C++ compile time.  The
C detect-constant-signedness is truely run-time but is very few
instructions.

I forgot to mention that constants_pm_c.PLX doesn't yet support
C<#ifdef>ing the constant definitions, but that such support is
planned.  But you need the ability to specify constants that are
C<enum>s [for example] and so should not be C<#ifdef>ed or where
the C<#ifdef> [or some other type of C<#if>] uses something other
than the constant's name.

I planned to have a switch for the common cases [no C<#ifdef>s or
all C<#ifdef>s using the constants' names] and let F<Makefile.PL>
provide a C<sub MY::const_ifdef> for the tricky cases that mix the
two or need other C<#if> constructs.

It'd probably also be a good idea to make this code generation
easy to do outside of B<make> so rather than writing a C<sub
MY::const_ifdef> for the tricky case you could decide to just
generate the code and edit it and then have the F<constants.h>
distributed with the module [and not regenerated by B<make>].

But I still like a simple F<constants.pm> because these
alternatives quickly become so opaque, especially with so many
binary distributions floating around that don't include source
code.

Any comments on how my proposed solution divines the list of
constants?

Thanks,
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


Follow-Ups from:
Tim Bunce <Tim.Bunce@ig.co.uk>
Graham Barr <gbarr@pobox.com>
References to:
Graham Barr <gbarr@pobox.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]