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

[PATCH] h2ph produces incorrect code in preamble #10341

Closed
p5pRT opened this issue Apr 23, 2010 · 5 comments
Closed

[PATCH] h2ph produces incorrect code in preamble #10341

p5pRT opened this issue Apr 23, 2010 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 23, 2010

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

Searchable as RT74614$

@p5pRT
Copy link
Author

p5pRT commented Apr 23, 2010

From r.m.barker@btinternet.com

The h2ph utility produces non-compiling code in its preamble,
generated by build_preamble_if_necessary(). If one of the
build-in macros has arguments; e.g. __INT64_C(c) produces

unless (defined &__INT64_C(c)) { sub __INT64_C(c)() { &cLL } }

(note double prototype). The preamble also contains "&int"
because it thinks "int" is a macro not a type.
These issues produce warnings but this is hidden by the test
suite because there is an error in lib/h2ph.t.

The patch fixes h2ph.PL to produce compiling code and fixes
h2ph.t to properly trap warnings or failures to compile.

(Perhaps severity should be "low" because I guess no one is
using h2ph, otherwise this would have been spotted earlier.)

Perl Info

Flags:
    category=utilities
    severity=medium

Site configuration information for perl 5.13.0:

Configured by robin at Thu Apr 22 12:22:28 BST 2010.

Summary of my perl5 (revision 5 version 13 subversion 0) configuration:
  Commit id: 4fd8f0cd61ad36e90cd5082dffa22afb90dcc58f
  Platform:
    osname=linux, osvers=2.6.31-20-generic, archname=i686-linux-64int
    uname='linux spade-ubuntu 2.6.31-20-generic #58-ubuntu smp fri mar 12 05:23:09 utc 2010 i686 gnulinux '
    config_args='-des -Dcc=gcc -Duse64bitint -Doptimize=-O2 -g -Dusedevel -Dman3dir=none'
    hint=recommended, useposix=true, d_sigaction=define
    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='gcc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.5.0', 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='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/lib64
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.10.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.10.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector'

Locally applied patches:
    


@INC for perl 5.13.0:
    lib
    /usr/local/lib/perl5/site_perl/5.13.0/i686-linux-64int
    /usr/local/lib/perl5/site_perl/5.13.0
    /usr/local/lib/perl5/5.13.0/i686-linux-64int
    /usr/local/lib/perl5/5.13.0
    /usr/local/lib/perl5/site_perl
    .


Environment for perl 5.13.0:
    HOME=/home/robin
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/lib:/usr/local/lib
    LOGDIR (unset)
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Apr 23, 2010

From rmbarker@cpan.org

0009-Fix-h2ph-and-test.patch
From 7010c9a4ee0dd0a6ff494670c45e04c98a1f8556 Mon Sep 17 00:00:00 2001
From: Robin Barker <rmbarker@cpan.org>
Date: Thu, 22 Apr 2010 11:51:20 +0100
Subject: [PATCH 9/9] Fix h2ph and test

---
 lib/h2ph.t    |   12 ++++++++++--
 utils/h2ph.PL |   28 +++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/lib/h2ph.t b/lib/h2ph.t
index 27dd7b9..58885d3 100644
--- a/lib/h2ph.t
+++ b/lib/h2ph.t
@@ -18,7 +18,7 @@ if (!(-e $extracted_program)) {
     exit 0;
 }
 
-plan(4);
+plan(5);
 
 # quickly compare two text files
 sub txt_compare {
@@ -41,8 +41,16 @@ $result = runperl( progfile => 'lib/h2ph.pht',
                    stderr => 1 );
 like( $result, qr/syntax OK$/, "output compiles");
 
+$result = runperl( progfile => '_h2ph_pre.ph', 
+                   switches => ['-c'], 
+                   stderr => 1 );
+like( $result, qr/syntax OK$/, "preample compiles");
+
 $result = runperl( switches => ["-w"], 
-                   prog => '$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);');
+                   stderr => 1,
+                   prog => <<'PROG' );
+$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);
+PROG
 is( $result, '', "output free of warnings" );
 
 # cleanup
diff --git a/utils/h2ph.PL b/utils/h2ph.PL
index 8f56db4..474076e 100644
--- a/utils/h2ph.PL
+++ b/utils/h2ph.PL
@@ -401,7 +401,10 @@ if ($opt_e && (scalar(keys %bad_file) > 0)) {
 exit $Exit;
 
 sub expr {
-    $new = '"(assembly code)"' and return if /\b__asm__\b/; # freak out.
+    if (/\b__asm__\b/) {	# freak out
+	$new = '"(assembly code)"';
+	return 
+    }
     my $joined_args;
     if(keys(%curargs)) {
 	$joined_args = join('|', keys(%curargs));
@@ -770,7 +773,7 @@ sub inc_dirs
 sub build_preamble_if_necessary
 {
     # Increment $VERSION every time this function is modified:
-    my $VERSION     = 2;
+    my $VERSION     = 3;
     my $preamble    = "$Dest_dir/_h2ph_pre.ph";
 
     # Can we skip building the preamble file?
@@ -798,7 +801,16 @@ sub build_preamble_if_necessary
 		# parenthesized value:  d=(v)
 		$define{$_} = $1;
 	    }
-	    if ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
+	    if (/^(\w+)\((\w)\)$/) {
+		my($macro, $arg) = ($1, $2);
+		my $def = $define{$_};
+		$def =~ s/$arg/\$\{$arg\}/g;
+		print PREAMBLE <<DEFINE;
+unless (defined &$macro) { sub $macro(\$) { my (\$$arg) = \@_; \"$def\" } }
+
+DEFINE
+	    } elsif
+		($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
 		# float:
 		print PREAMBLE
 		    "unless (defined &$_) { sub $_() { $1 } }\n\n";
@@ -807,8 +819,14 @@ sub build_preamble_if_necessary
 		print PREAMBLE
 		    "unless (defined &$_) { sub $_() { $1 } }\n\n";
 	    } elsif ($define{$_} =~ /^\w+$/) {
-		print PREAMBLE
-		    "unless (defined &$_) { sub $_() { &$define{$_} } }\n\n";
+		my $def = $define{$_};
+		if ($isatype{$def}) {
+		  print PREAMBLE
+		    "unless (defined &$_) { sub $_() { \"$def\" } }\n\n";
+		} else {
+		  print PREAMBLE
+		    "unless (defined &$_) { sub $_() { &$def } }\n\n";
+	        }
 	    } else {
 		print PREAMBLE
 		    "unless (defined &$_) { sub $_() { \"",
-- 
1.6.3.3

@p5pRT
Copy link
Author

p5pRT commented Apr 26, 2010

From @rgs

Thanks, applied to bleadperl.

@p5pRT
Copy link
Author

p5pRT commented Apr 26, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Apr 26, 2010

@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