From: Vincent Pit Date: Sat, 31 Mar 2012 12:57:46 +0000 (+0200) Subject: Make sure the source files are properly patched X-Git-Tag: v0.02~6 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fre-engine-Hooks.git;a=commitdiff_plain;h=d2b7e04fb8d40639a353ea53a1957b9872373c8b Make sure the source files are properly patched --- diff --git a/src/update.pl b/src/update.pl index 5383607..dea38cf 100644 --- a/src/update.pl +++ b/src/update.pl @@ -216,15 +216,24 @@ sub fetch_source_file { } } +my %patched_chunks; +my %expected_chunks = ( + 'regcomp.c' => [ qw, ('COMP_NODE_HOOK') x 3 ], + 'regexec.c' => [ qw ], +); + sub patch_regcomp { - my $line = $_[0]; + my ($line, $file) = @_; if ($line =~ /#\s*include\s+"INTERN\.h"/) { + push @{$patched_chunks{$file}}, 're_defs'; return "#include \"re_defs.h\"\n"; } elsif ($line =~ /^(\s*)RExC_rxi\s*=\s*ri\s*;\s*$/) { + push @{$patched_chunks{$file}}, 'COMP_BEGIN_HOOK'; return $line, "$1REH_CALL_COMP_BEGIN_HOOK(pRExC_state->rx);\n"; } elsif ($line =~ /FILL_ADVANCE_NODE(_ARG)?\(\s*([^\s,\)]+)/) { my $shift = $1 ? 2 : 1; + push @{$patched_chunks{$file}}, 'COMP_NODE_HOOK'; return $line, " REH_CALL_REGCOMP_HOOK(pRExC_state->rx, ($2) - $shift);\n" } @@ -232,11 +241,13 @@ sub patch_regcomp { } sub patch_regexec { - my $line = $_[0]; + my ($line, $file) = @_; if ($line =~ /#\s*include\s+"perl\.h"/) { + push @{$patched_chunks{$file}}, 're_defs'; return $line, "#include \"re_defs.h\"\n"; } elsif ($line =~ /^\s*reenter_switch:\s*$/) { + push @{$patched_chunks{$file}}, 'EXEC_NODE_HOOK'; return "\tREH_CALL_REGEXEC_HOOK(rex, scan, reginfo, st);\n", $line; } @@ -266,7 +277,13 @@ sub patch_source_file { open my $out, '>', $dst or die "Can't open $dst for writing: $!"; while (defined(my $line = <$in>)) { - print $out $mangler->($line); + print $out $mangler->($line, $dst); + } + + my $patched_chunks = join ' ', @{$patched_chunks{$dst}}; + my $expected_chunks = join ' ', @{$expected_chunks{$file}}; + unless ($patched_chunks eq $expected_chunks) { + die "File $dst was not properly patched (got \"$patched_chunks\", expected \"$expected_chunks\")\n"; } return 1;