From 7594a463e1df515c782d29f7bda9d6b8fe058126 Mon Sep 17 00:00:00 2001 From: Ed J Date: Fri, 22 Jul 2022 22:32:11 +0100 Subject: [PATCH] use ExtUtils::ParseXS 3.21+ ExtUtils::Typemaps instead of copy-paste --- Basic/Gen/PP.pm | 139 ++++-------------------------------------------- Makefile.PL | 6 +-- 2 files changed, 13 insertions(+), 132 deletions(-) diff --git a/Basic/Gen/PP.pm b/Basic/Gen/PP.pm index 073420d4b..57298faf6 100644 --- a/Basic/Gen/PP.pm +++ b/Basic/Gen/PP.pm @@ -1001,88 +1001,14 @@ EOF pp_addpm {At => 'Top'}, <) { - next if /^\s*#/; - my $line_no = $. + 1; - if (/^INPUT\s*$/) { $mode = 'Input'; $current = \$junk; next; } - if (/^OUTPUT\s*$/) { $mode = 'Output'; $current = \$junk; next; } - if (/^TYPEMAP\s*$/) { $mode = 'Typemap'; $current = \$junk; next; } - if ($mode eq 'Typemap') { - chomp; - my $line = $_ ; - TrimWhitespace($_) ; - # skip blank lines and comment lines - next if /^$/ or /^#/ ; - my($t_type,$kind, $proto) = /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or - warn("Warning: File '$typemap' Line $. '$line' TYPEMAP entry needs 2 or 3 columns\n"), next; - $t_type = TidyType($t_type) ; - $type_kind{$t_type} = $kind ; - # prototype defaults to '$' - $proto = "\$" unless $proto ; - warn("Warning: File '$typemap' Line $. '$line' Invalid prototype '$proto'\n") - unless ValidProtoString($proto) ; - $proto_letter{$t_type} = C_string($proto) ; - } - elsif (/^\s/) { - $$current .= $_; - } - elsif ($mode eq 'Input') { - s/\s+$//; - $input_expr{$_} = ''; - $current = \$input_expr{$_}; - } - else { - s/\s+$//; - $output_expr{$_} = ''; - $current = \$output_expr{$_}; - } - } - close $fh; - } - 1; + $typemap_obj = ExtUtils::Typemaps->new; + $typemap_obj->merge(file => $_, replace => 1) for @typemaps; + $typemap_obj; } sub typemap { my ($oname, $type, $arg) = @_; $typemap_obj ||= _load_typemap(); # First reconstruct the type declaration to look up in type_kind - my $full_type=TidyType($type->get_decl('', {VarArrays2Ptrs=>1})); # Skip the variable name - die "The type =$full_type= does not have a typemap entry!\n" unless exists($type_kind{$full_type}); - my $typemap_kind = $type_kind{$full_type}; + my $full_type=ExtUtils::Typemaps::tidy_type($type->get_decl('', {VarArrays2Ptrs=>1})); # Skip the variable name + my $inputmap = $typemap_obj->get_inputmap(ctype => $full_type); + die "The type =$full_type= does not have a typemap entry!\n" unless $inputmap; # Look up the conversion from the INPUT typemap. Note that we need to do some # massaging of this. - my $input = $input_expr{$typemap_kind}; + my $input = $inputmap->code; $input =~ s/^(.*?)=\s*//s; # Remove all before = $input =~ s/\$(var|\{var\})/$oname/g; $input =~ s/\$(arg|\{arg\})/$arg/g; diff --git a/Makefile.PL b/Makefile.PL index 71382abca..33ef3d61d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -173,16 +173,16 @@ my %makefile_hash = ( PREREQ_PM => { @prereq }, LICENSE => 'perl', CONFIGURE_REQUIRES => { - 'Devel::CheckLib' => 1.01, + 'Devel::CheckLib' => '1.01', 'Carp' => 1.20, # EU::MM seems to need this not to crash 'ExtUtils::MakeMaker' => '7.12', # working .g.c 'File::Path' => 0, - 'ExtUtils::ParseXS' => 3.01, # avoids 2.21, known broken + 'ExtUtils::ParseXS' => '3.21', # ExtUtils::Typemaps::tidy_type 'ExtUtils::Depends' => '0.402', }, TEST_REQUIRES => { 'CPAN::Meta' => '2.120900', - 'IPC::Cmd' => 0.72, + 'IPC::Cmd' => '0.72', 'Test::Exception' => 0, 'Test::Warn' => 0, # for t/pptest.t 'Test::Deep' => 0,