Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h2xs generates incorrect code for Makefile.PL for enums #7602

Closed
p5pRT opened this issue Nov 19, 2004 · 10 comments
Closed

h2xs generates incorrect code for Makefile.PL for enums #7602

p5pRT opened this issue Nov 19, 2004 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 19, 2004

Migrated from rt.perl.org#32498 (status was 'resolved')

Searchable as RT32498$

@p5pRT
Copy link
Author

p5pRT commented Nov 19, 2004

From akolb@sun.com

Created by akolb@sun.com

The h2xs generates the following part of Makefile.PL for both #define and enum
constants​:

  my $generate_code =
  WriteMakefileSnippet ( C_FILE => $constscfname,
  XS_FILE => $constsxsfname,
  DEFAULT_TYPE => $opt_t,
  NAME => $module,
  NAMES => \@​const_names,

This produce an entry in the Makefile.PL​:

  my @​names = (qw(bar_enum def_bar def_foo foo_enum));

  ExtUtils​::Constant​::WriteConstants(
  NAME => 'Ltest',
  NAMES => \@​names,
  DEFAULT_TYPE => 'IV',
  C_FILE => 'const-c.inc',
  XS_FILE => 'const-xs.inc',
  );

The ExtUtils​::Constant module treats all simple names as #defines and for
each such name generates

#ifdef bar_enum
  *iv_return = bar_enum;
  return PERL_constant_ISIV;
#else
  return PERL_constant_NOTDEF;
#endif

for enums which do not have the name defined. Instead, for enum constants it
should generate a different code like

my @​names = (qw(def_bar def_foo),
  {name=>"bar_enum", macro=>"1"},
  {name=>"foo_enum", macro=>"1"});

  ExtUtils​::Constant​::WriteConstants(
  NAME => 'Ltest',
  NAMES => \@​names,
  DEFAULT_TYPE => 'IV',
  C_FILE => 'const-c.inc',
  XS_FILE => 'const-xs.inc',
  );

which will generate correct code for #defines and enums.

Perl Info

Flags:
    category=utilities
    severity=medium

Site configuration information for perl v5.8.4:

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=solaris, osvers=2.10, archname=i86pc-solaris-64int
    uname='sunos localhost 5.10 i86pc i386 i86pc'
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_TS_ERRNO',
    optimize='-xO3 -xspace -xildoff',
    cppflags=''
    ccversion='Sun WorkShop', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-R /usr/perl5/5.8.4/lib/i86pc-solaris-64int/CORE'
    cccdlflags='-KPIC', lddlflags='-G'

Locally applied patches:
    22667 The optree builder was looping when constructing the ops ...
    22715 Upgrade to FileCache 1.04
    22733 Missing copyright in the README.
    22746 fix a coredump caused by rv2gv not fully converting a PV ...
    22755 Fix 29149 - another UTF8 cache bug hit by substr.
    22774 [perl #28938] split could leave an array without ...
    22775 [perl #29127] scalar delete of empty slice returned garbage
    22776 [perl #28986] perl -e \"open m\" crashes Perl
    22777 add test for change #22776 (\"open m\" crashes Perl)
    22778 add test for change #22746 ([perl #29102] Crash on assign ...
    22781 [perl #29340] Bizarre copy of ARRAY make sure a pad op's ...
    22796 [perl #29346] Double warning for int(undef) and abs(undef) ...
    22818 BOM-marked and (BOMless) UTF-16 scripts not working
    22827 Smoke [5.9.2] 22818 FAIL(F) MSWin32 WinXP/.Net SP1 (x86/1 cpu)
    22830 [perl #29637] Thread creation time is hypersensitive
    22831 improve hashing algorithm for ptr tables in perl_clone: ...
    22839 [perl #29790] Optimization busted: '@a = \"b\", sort @a' ...
    22850 [PATCH] 'perl -v' fails if local_patches contains code snippets
    22852 TEST needs to ignore SCM files
    22886 Pod::Find should ignore SCM files and dirs
    22888 Remove redundant %SIG assignments from FileCache


@INC for perl v5.8.4:
    /usr/perl5/5.8.4/lib/i86pc-solaris-64int
    /usr/perl5/5.8.4/lib
    /usr/perl5/site_perl/5.8.4/i86pc-solaris-64int
    /usr/perl5/site_perl/5.8.4
    /usr/perl5/site_perl
    /usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int
    /usr/perl5/vendor_perl/5.8.4
    /usr/perl5/vendor_perl
    .


Environment for perl v5.8.4:
    HOME=/home/akolb
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/openwin/lib
    LOGDIR (unset)
    PATH=/usr/perl5/bin:/home/akolb/bin:/usr/bin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2005

From sitz@onastick.net

I got hit with this problem as well; the attached patch takes care of it
for me. It's a bit ugly, but don't know the h2xs codebase all that well.
It Works For Me(tm), and if nothing else, it's a start. If it needs an
overhaul, let me know and I'll be happy to give it a shot. =)

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2005

From sitz@onastick.net

h2xs.patch
--- h2xs-cvs	2005-01-17 00:29:53.826930528 -0500
+++ h2xs	2005-01-17 00:40:06.392806360 -0500
@@ -859,7 +859,6 @@
 
         # Remove C and C++ comments
         $src =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
-
         while ($src =~ /(\benum\s*([\w_]*)\s*\{\s([\s\w=,]+)\})/gsc) {
             my ($enum_name, $enum_body) =
                 $1 =~ /enum\s*([\w_]*)\s*\{\s([\s\w=,]+)\}/gs;
@@ -869,8 +868,9 @@
             for my $item (split /,/, $enum_body) {
                 my ($key, $declared_val) = $item =~ /(\w+)\s*(?:=\s*(.*))?/;
                 $val = defined($declared_val) && length($declared_val) ? $declared_val : 1 + $val;
+                print "Matched $key ($val)\n" if $opt_d;
                 $seen_define{$key} = $declared_val;
-                $const_names{$key}++;
+                $const_names{$key} = {name => $key, macro => 1};
             }
         } # while (...)
       } # if (!defined $opt_e or $opt_e)
@@ -1035,6 +1035,11 @@
   }
 }
 my @const_names = sort keys %const_names;
+my @const_keys = map { 
+			ref($const_names{$_}) eq 'HASH'
+				? $const_names{$_}
+				: $_
+		      } sort keys(%const_names);
 
 -d $modpmdir || mkpath([$modpmdir], 0, 0775);
 open(PM, ">$modpmname") || die "Can't create $ext$modpname/$modpmname: $!\n";
@@ -1422,7 +1427,7 @@
                    XS_FILE =>      $xsfallback,
                    DEFAULT_TYPE => $opt_t,
                    NAME =>         $module,
-                   NAMES =>        \@const_names,
+                   NAMES =>        \@const_keys,
                  );
   print XS "#include \"$constscfname\"\n";
 }
@@ -1906,7 +1911,7 @@
                            XS_FILE =>      $constsxsfname,
                            DEFAULT_TYPE => $opt_t,
                            NAME =>         $module,
-                           NAMES =>        \@const_names,
+                           NAMES =>        \@const_keys,
                  );
   print PL <<"END";
 if  (eval {require ExtUtils::Constant; 1}) {

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 19, 2005

From @rgs

akolb@​sun.com (via RT) wrote​:

The h2xs generates the following part of Makefile.PL for both #define and enum
constants​:

I suppose this is a duplicate of bug #32491, which has been fixed by
patch 23652. (see http​://public.activestate.com/cgi-bin/perlbrowse?patch=23652 )

@p5pRT
Copy link
Author

p5pRT commented Jan 19, 2005

From sitz@onastick.net

On Wed, Jan 19, 2005 at 12​:30​:51PM +0100, Rafael Garcia-Suarez wrote​:

akolb@​sun.com (via RT) wrote​:

The h2xs generates the following part of Makefile.PL for both #define and enum
constants​:

I suppose this is a duplicate of bug #32491, which has been fixed by
patch 23652. (see http​://public.activestate.com/cgi-bin/perlbrowse?patch=23652 )

Am I missing the glaringly obvious, or should this​:

  $seen_define{$key} = $declared_val;

read like this​:

  $seen_define{$key} = $val;

?

--noah

@p5pRT
Copy link
Author

p5pRT commented Jan 19, 2005

From @rgs

Noah wrote​:

On Wed, Jan 19, 2005 at 12​:30​:51PM +0100, Rafael Garcia-Suarez wrote​:

akolb@​sun.com (via RT) wrote​:

The h2xs generates the following part of Makefile.PL for both #define and enum
constants​:

I suppose this is a duplicate of bug #32491, which has been fixed by
patch 23652. (see http​://public.activestate.com/cgi-bin/perlbrowse?patch=23652 )

Am I missing the glaringly obvious, or should this​:

             $seen\_define\{$key\} = $declared\_val;

read like this​:

             $seen\_define\{$key\} = $val;

You're not ; it should. Thanks, applied as change #23822 to bleadperl.

@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2005

From xw5s-73y5@disposable.spamcon.org

[rgarciasuarez@​mandrakesoft.com - Wed Jan 19 03​:30​:16 2005]​:

I suppose this is a duplicate of bug #32491, which has been fixed by
patch 23652. (see http​://public.activestate.com/cgi-
bin/perlbrowse?patch=23652 )

No it isn't. If you look at sitz's patch, you'll see that the version
he was patching against already had patch 23652 applied.

There were previously (at least) two distinct problems​: 1) for some
enums no code was generated at all, and 2) when code was generated, it
was incorrect. Patches 23652 and 23822 fixed problem 1, but not
problem 2. So now incorrect code is generated for all enums.

Please read Alexander's original description of the problem. sitz's
patch looks like it's on the right track, although it doesn't work
as-is (it leaves a lot of references to the now undefined
@​const_names).

@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2005

From xw5s-73y5@disposable.spamcon.org

[aaronkaplan - Sun Sep 11 04​:10​:36 2005]​:
sitz's patch ... doesn't work
as-is (it leaves a lot of references to the now undefined
@​const_names).

Never mind that part of my comment, I had misapplied the patch.

@p5pRT
Copy link
Author

p5pRT commented Nov 14, 2008

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant