diff options
author | Steffen Mueller <smueller@cpan.org> | 2011-02-18 21:36:32 +0100 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2011-07-12 20:54:49 +0200 |
commit | 1c4122e74f3056f153d10d3df120bd391ae8b252 (patch) | |
tree | e4f4c7c3270e2c61a1205c76f0bf02ed85cdf378 /dist | |
parent | 64620e570f04c1f2e1add2025a595fa0eae323b4 (diff) | |
download | perl-1c4122e74f3056f153d10d3df120bd391ae8b252.tar.gz |
Make get_(in|out)putmap more flexible
They now also accept ctypes which are resolved to xstypes via the
typemap section.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm | 34 | ||||
-rw-r--r-- | dist/ExtUtils-ParseXS/t/510-t-bare.t | 6 |
2 files changed, 35 insertions, 5 deletions
diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm index 933af7e8f5..9755293c1f 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps.pm @@ -449,7 +449,14 @@ Fetches an entry of the INPUT section of the typemap. Mandatory named arguments: The C<xstype> of the -entry. +entry or the C<ctype> of the typemap that can be used to find +the C<xstype>. To wit, the following pieces of code +are equivalent: + + my $type = $typemap->get_typemap(ctype => $ctype) + my $input_map = $typemap->get_inputmap(xstype => $type->xstype); + + my $input_map = $typemap->get_inputmap(ctype => $ctype); Returns the C<ExtUtils::Typemaps::InputMap> object for the entry if found. @@ -460,7 +467,16 @@ sub get_inputmap { my $self = shift; my %args = @_; my $xstype = $args{xstype}; - die("Need xstype argument") if not defined $xstype; + my $ctype = $args{ctype}; + die("Need xstype or ctype argument") + if not defined $xstype + and not defined $ctype; + die("Need xstype OR ctype arguments, not both") + if defined $xstype and defined $ctype; + + if (defined $ctype) { + $xstype = $self->get_typemap(ctype => $ctype)->xstype; + } my $index = $self->{input_lookup}{$xstype}; return() if not defined $index; @@ -473,7 +489,8 @@ Fetches an entry of the OUTPUT section of the typemap. Mandatory named arguments: The C<xstype> of the -entry. +entry or the C<ctype> of the typemap that can be used to +resolve the C<xstype>. (See above for an example.) Returns the C<ExtUtils::Typemaps::InputMap> object for the entry if found. @@ -484,7 +501,16 @@ sub get_outputmap { my $self = shift; my %args = @_; my $xstype = $args{xstype}; - die("Need xstype argument") if not defined $xstype; + my $ctype = $args{ctype}; + die("Need xstype or ctype argument") + if not defined $xstype + and not defined $ctype; + die("Need xstype OR ctype arguments, not both") + if defined $xstype and defined $ctype; + + if (defined $ctype) { + $xstype = $self->get_typemap(ctype => $ctype)->xstype; + } my $index = $self->{output_lookup}{$xstype}; return() if not defined $index; diff --git a/dist/ExtUtils-ParseXS/t/510-t-bare.t b/dist/ExtUtils-ParseXS/t/510-t-bare.t index b76b10a7c4..a58bca874a 100644 --- a/dist/ExtUtils-ParseXS/t/510-t-bare.t +++ b/dist/ExtUtils-ParseXS/t/510-t-bare.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 29; +use Test::More tests => 30; use ExtUtils::Typemaps; # typemap only @@ -44,6 +44,10 @@ HERE my $in = $map->get_inputmap(xstype => 'T_UV'); isa_ok($in, 'ExtUtils::Typemaps::InputMap'); is($in->xstype, 'T_UV'); + + # test fetching inputmap by ctype + my $in2 = $map->get_inputmap(ctype => 'unsigned int'); + is_deeply($in2, $in, "get_inputmap returns the same typemap for ctype and xstype"); } |