Open p5pRT opened 16 years ago
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
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
The RT System itself - Status changed from 'new' to 'open'
p5p@spam.wizbit.be - Status changed from 'open' to 'stalled'
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?
If you try the example in the blog[1]\, the only bug that has been fixed in 5.10 is
870c868 \< my ($key\, $declared_val) = $item =~ /(\w*)\s*=\s*(.*)/; --- > my ($key\, $declared_val) = $item =~ /(\w+)\s*[=\,]*\s*(.*)/;
all of the others remain. The .h in question is:
#define XST_DEFINE 1
typedef enum xst_enum { XST_ENUM_1\, XST_ENUM_2\, } xst_enum_t;
typedef enum xst_enum_val { XST_ENUM_VAL_1 = 1\, XST_ENUM_VAL_2 = 2\, } xst_enum_val_t;
The command was:
h2xs --skip-ppport --overwrite-ok --autogen-xsubs --name=XS::Test xs_test.h
Regards
Jeff
[1] http://blogs.sun.com/akolb/entry/pitfals_of_the_perl_xs
The RT System itself - Status changed from 'stalled' to 'open'
[1] http://blogs.sun.com/akolb/entry/pitfals_of_the_perl_xs
Sigh. "your blog" is not the place to report bugs. (To be clear\, I believe that all entries in this ticket have been made by helpful third parties attempting to relay the findings of the blog author to the *right* place to report bugs)
Moreover\, "your blog" (or any third party hosted URL) can go away. I've retrieved the blog post from the Wayback machine and attached it here before its content is lost forever.
(I don't know if the dodgy HTML a side effect of the Wayback machine or an accurate reflection of what the now defunct blogs.sun.org generated)
Nicholas Clark
Migrated from rt.perl.org#55896 (status was 'open')
Searchable as RT55896$