develooper Front page | perl.perl5.porters | Postings from June 2008

Re: [perl #55896] h2xs does not handle properly enum constants

Thread Previous
From:
Steve Peters
Date:
June 20, 2008 04:53
Subject:
Re: [perl #55896] h2xs does not handle properly enum constants
Message ID:
fd7a59d30806200452x64186994rc62e35e74129341e@mail.gmail.com
> Hello
>
> I've used h2xs (hence ExtUtils::Constant) to generate bindings for
> Augeas [1] library. Augeas header file includes constants defined with
> enums:
>
> enum aug_flags {
>    AUG_NONE = 0,
>    AUG_SAVE_BACKUP  = (1 << 0),  /* Keep the original file with a
>                                     .augsave extension */
>    AUG_SAVE_NEWFILE = (1 << 1),  /* Save changes into a file with
>                                     extension .augnew, and do not
>                                     overwrite the original file. Takes
>                                     precedence over AUG_SAVE_BACKUP */
>    AUG_TYPE_CHECK   = (1 << 2)   /* Typecheck lenses; since it can be very
>                                     expensive it is not done by default */
> };
>
> h2xs correctly detects these constants, but it will generate a C code
> that expects these constants to be #defined. See the generated
> const-c.inc:
>  case 8:
>    if (memEQ(name, "AUG_NONE", 8)) {
> #ifdef AUG_NONE
>      *iv_return = AUG_NONE;
>      return PERL_constant_ISIV;
> #else
>      return PERL_constant_NOTDEF;
> #endif
>    }
>    break;
>
> This code does not work as the constants are not known to cpp.
>
> In itself, it not a big problem, but finding out what's wrong is a
> pain when you're beginning  to learn XS :-/
>
> There's a workaround suggested on Sun's blogs [2] which works fine.
> (This blog also feature a fine explanation of the enum problem)
>
> HTH
>
> [1] http://augeas.net/
> [2] http://blogs.sun.com/akolb/entry/pitfals_of_the_perl_xs
>

As a side note, there have been several fixes that have gone into h2xs
since that blog entry was created, so I'm not sure how relevant it may
still be.  Setting the precedent for --skip-ppport is a bit troubling.

I had thought that all the enum problems had been nailed down though.
Is there a particular .h that is causing problems.  What was the exact
command line you were using?

Steve Peters
steve@fisharerojo.org

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About