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 incorrectly parses enums with implicit values #7601

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

h2xs incorrectly parses enums with implicit values #7601

p5pRT opened this issue Nov 19, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 19, 2004

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

Searchable as RT32491$

@p5pRT
Copy link
Author

p5pRT commented Nov 19, 2004

From akolb@sun.com

Created by akolb@sun.com

Consider the following enum​:

typedef enum xxx {
  XXX_A, /* value A */
  XXX_B /* Value B */
} xxx_t;

It is not parsed by h2xs correctly. nd no code is generated for it.
The problem is here​:

  for my $item (split /,/, $enum_body) {
  my ($key, $declared_val) = $item =~ /(\w*)\s*=\s*(.*)/;
  ^
  $val = length($declared_val) ? $declared_val : 1 + $val;
  $seen_define{$key} = $declared_val;
  $const_names{$key}++;

Note that the regex requires assignment operator. Changing the regexp to

  my ($key, $declared_val) = $item =~ /(\w+)\s*[=,]*\s*(.*)/;

fixes the problem.

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/local/bin:/usr/bin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2004

From @rgs

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

Consider the following enum​:

typedef enum xxx {
XXX_A, /* value A */
XXX_B /* Value B */
} xxx_t;

It is not parsed by h2xs correctly. nd no code is generated for it.
The problem is here​:

        for my $item \(split /\,/\, $enum\_body\) \{
            my \($key\, $declared\_val\) = $item =~ /\(\\w\*\)\\s\*=\\s\*\(\.\*\)/;
                                                         ^
            $val = length\($declared\_val\) ? $declared\_val : 1 \+ $val;
            $seen\_define\{$key\} = $declared\_val;
            $const\_names\{$key\}\+\+;

Note that the regex requires assignment operator. Changing the regexp to

            my \($key\, $declared\_val\) = $item =~ /\(\\w\+\)\\s\*\[=\,\]\*\\s\*\(\.\*\)/;

fixes the problem.

... but wrongly since ',' is guaranteed not to appear in $item. Anyway,
thanks for your report and that step in the good direction; I applied a
fix as follows to the development branch of perl :

Change 23652 by rgs@​grubert on 2004/12/14 16​:22​:42

  Fix for [perl #32491] h2xs incorrectly parses enums with implicit values

Affected files ...

... //depot/perl/utils/h2xs.PL#92 edit

Differences ...

==== //depot/perl/utils/h2xs.PL#92 (text) ====

@​@​ -901,8 +901,8 @​@​
  next if $opt_e && $enum_name =~ /$opt_e/;
  my $val = 0;
  for my $item (split /,/, $enum_body) {
- my ($key, $declared_val) = $item =~ /(\w+)\s*=\s*(.*)/;
- $val = length($declared_val) ? $declared_val : 1 + $val;
+ my ($key, $declared_val) = $item =~ /(\w+)\s*(?​:=\s*(.*))?/;
+ $val = defined($declared_val) && length($declared_val) ? $declared_val : 1 + $val;
  $seen_define{$key} = $declared_val;
  $const_names{$key}++;
  }

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2004

@rgs - 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