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 and Fortran, other wacky headers on IRIX #5925

Closed
p5pRT opened this issue Sep 13, 2002 · 7 comments
Closed

[PATCH] h2ph and Fortran, other wacky headers on IRIX #5925

p5pRT opened this issue Sep 13, 2002 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 13, 2002

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

Searchable as RT17222$

@p5pRT
Copy link
Author

p5pRT commented Sep 13, 2002

From allens@cpan.org

Hi. One problem I have recently encountered in running h2ph -a -h -l *.h
sys/*.h etcetera (as advised in h2ph's manpage), even with the h2ph from
5.8.0, is that IRIX happens to have some Fortran-only headers in /usr/include,
plus others such as the pda.h header in /usr/include/sys, which has​:

#if MP
#error "This code is not mp safe - mutex locking needed to protect
#error "the jump_war_pid and jump_war_uthreadid fields
#endif

Both of these understandably cause h2ph to stop with a 'Cannot parse'
error. In our case, none of the headers in question are desired for
conversion to .ph files (and if they were, manual conversion would be the
best way to go in any event, I suspect)... but that h2ph dies instead of
simply skipping to the next header file creates problems in doing an entire
directory or set of directories. Below is a patch to add a -e option to
h2ph, causing it to skip such files, along with a patch to the h2ph test to
account for slight differences due to this. (Neither of these files differs
between bleadperl and perl-5.8.0, incidentally.)

Inline Patch
--- utils/h2ph.PL.old	Thu Sep 12 19:31:16 2002
+++ utils/h2ph.PL	Thu Sep 12 21:49:50 2002
@@ -42,8 +42,8 @@
 use File::Path qw(mkpath);
 use Getopt::Std;
 
-getopts('Dd:rlhaQ');
-use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q);
+getopts('Dd:rlhaQe');
+use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q $opt_e);
 die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
 my @inc_dirs = inc_dirs() if $opt_a;
 
@@ -65,13 +65,21 @@
 @isatype{@isatype} = (1) x @isatype;
 my $inif = 0;
 my %Is_converted;
+my %bad_file = ();
 
 @ARGV = ('-') unless @ARGV;
 
 build_preamble_if_necessary();
 
+sub reindent($) {
+    my($text) = shift;
+    $text =~ s/\n/\n    /g;
+    $text =~ s/        /\t/g;
+    $text;
+}
+
 my ($t, $tab, %curargs, $new, $eval_index, $dir, $name, $args, $outfile);
-my ($incl, $next);
+my ($incl, $incl_type, $next);
 while (defined (my $file = next_file())) {
     if (-l $file and -d $file) {
         link_if_possible($file) if ($opt_l);
@@ -169,22 +177,31 @@
                       print OUT $t,"unless(defined(\&$name)) {\n    sub $name () {\t",$new,";}\n}\n";
 		    }
 		}
-	    } elsif (/^(include|import)\s*[<"](.*)[>"]/) {
-		($incl = $2) =~ s/\.h$/.ph/;
-		print OUT $t,"require '$incl';\n";
-	    } elsif(/^include_next\s*[<"](.*)[>"]/) {
-		($incl = $1) =~ s/\.h$/.ph/;
+	    } elsif (/^(include|import|include_next)\s*[<\"](.*)[>\"]/) {
+                $incl_type = $1;
+                $incl = $2;
+                if (($incl_type eq 'include_next') ||
+                    ($opt_e && exists($bad_file{$incl}))) {
+                    $incl =~ s/\.h$/.ph/;
 		print OUT ($t,
 			   "eval {\n");
                 $tab += 4;
                 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
+                    print OUT ($t, "my(\@REM);\n");
+                    if ($incl_type eq 'include_next') {
 		print OUT ($t,
 			   "my(\%INCD) = map { \$INC{\$_} => 1 } ",
-			   "(grep { \$_ eq \"$incl\" } keys(\%INC));\n");
+			           "(grep { \$_ eq \"$incl\" } ",
+                                   "keys(\%INC));\n");
 		print OUT ($t,
-			   "my(\@REM) = map { \"\$_/$incl\" } ",
+			           "\@REM = map { \"\$_/$incl\" } ",
 			   "(grep { not exists(\$INCD{\"\$_/$incl\"})",
-			   "and -f \"\$_/$incl\" } \@INC);\n");
+			           " and -f \"\$_/$incl\" } \@INC);\n");
+                    } else {
+                        print OUT ($t,
+                                   "\@REM = map { \"\$_/$incl\" } ",
+                                   "(grep {-r \"\$_/$incl\" } \@INC);\n");
+                    }
 		print OUT ($t,
 			   "require \"\$REM[0]\" if \@REM;\n");
                 $tab -= 4;
@@ -193,6 +210,10 @@
 			   "};\n");
 		print OUT ($t,
 			   "warn(\$\@) if \$\@;\n");
+                } else {
+                    $incl =~ s/\.h$/.ph/;
+		    print OUT $t,"require '$incl';\n";
+                }
 	    } elsif (/^ifdef\s+(\w+)/) {
 		print OUT $t,"if(defined(&$1)) {\n";
 		$tab += 4;
@@ -274,22 +295,22 @@
 	    }
 	}
     }
-    print OUT "1;\n";
-
     $Is_converted{$file} = 1;
+    if ($opt_e && exists($bad_file{$file})) {
+        unlink($Dest_dir . '/' . $outfile);
+        $next = '';
+    } else {
+        print OUT "1;\n";
     queue_includes_from($file) if ($opt_a);
+    }
 }
 
-exit $Exit;
-
-
-sub reindent($) {
-    my($text) = shift;
-    $text =~ s/\n/\n    /g;
-    $text =~ s/        /\t/g;
-    $text;
+if ($opt_e && (scalar(keys %bad_file) > 0)) {
+    warn "Was unable to convert the following files:\n";
+    warn "\t" . join("\n\t",sort(keys %bad_file)) . "\n";
 }
 
+exit $Exit;
 
 sub expr {
     my $joined_args;
@@ -485,7 +506,15 @@
                      $in   =~ s!\'T KNOW!!) {
                 $out    =~ s!I DON$!I_DO_NOT_KNOW!;
             } else {
+                if ($opt_e) {
+                    warn "Cannot parse $file:\n$in\n";
+                    $bad_file{$file} = 1;
+                    $in = '';
+                    $out = undef;
+                    last READ;
+                } else {
 		die "Cannot parse:\n$in\n";
+                }
             }
         }
 
--- t/lib/h2ph.pht.old	Sat Jun  1 13:03:47 2002
+++ t/lib/h2ph.pht	Thu Sep 12 21:50:19 2002
@@ -48,8 +48,9 @@
     require 'sys/socket.ph';
     require 'sys/ioctl.ph';
     eval {
+	my(@REM);
 	my(%INCD) = map { $INC{$_} => 1 } (grep { $_ eq "sys/fcntl.ph" } keys(%INC));
-	my(@REM) = map { "$_/sys/fcntl.ph" } (grep { not exists($INCD{"$_/sys/fcntl.ph"})and -f "$_/sys/fcntl.ph" } @INC);
+	@REM = map { "$_/sys/fcntl.ph" } (grep { not exists($INCD{"$_/sys/fcntl.ph"}) and -f "$_/sys/fcntl.ph" } @INC);
 	require "$REM[0]" if @REM;
     };
     warn($@) if $@;


-----------------------------------------------------------------
---
Flags:   category=Patch   severity=medium

@p5pRT
Copy link
Author

p5pRT commented Sep 29, 2002

From @hvds

Allen Smith (via RT) <perlbug@​perl.org> wrote​:
:Below is a patch to add a -e option to h2ph, causing it to skip [problem]
:files, along with a patch to the h2ph test [output] to account for slight
:differences due to this.

Thanks, applied as #17939.

Hugo

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2002

From @jhi

Since the patch was applied, I'm marking the problem ticket as resolved.

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2002

@jhi - Status changed from 'new' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2002

From easmith@beatrice.rutgers.edu

In message <rt-17222-42531.1.16914034363852@​bugs6.perl.org> (on 27 November 2002 05​:00​:15 -0000), perlbug@​perl.org (Jarkko Hietaniemi (via RT)) wrote​:

Since the patch was applied, I'm marking the problem ticket as resolved.

Oh. Yes, thank you. I really need to get around to working on _tests_ and
_documentation_ for this, of course - thanks for the reminder! (ADD -
Attention Deficit Disorder - while under treatment still makes me rather
absent-minded...)

  -Allen

--
Allen Smith http​://cesario.rutgers.edu/easmith/
September 11, 2001 A Day That Shall Live In Infamy II
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." - Benjamin Franklin

@p5pRT
Copy link
Author

p5pRT commented Jan 5, 2003

From @jhi

Reminder... but please just send any patches to p5p, since replying
to this will auto-reopen the problem ticket :-)

@p5pRT
Copy link
Author

p5pRT commented Jan 5, 2003

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

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

No branches or pull requests

1 participant