Skip to content

Commit 6be8ed2

Browse files
committed
XS: INTERFACE: support perl package names
XS currently allows a Perl package name to be used where a C type is expected; behind the scenes, s/:/_/g is performed on the type string. For example this XS declaration, X::Y foo(...) causes this C declaration to be emitted for RETVAL: X__Y RETVAL; However, in the presence of the INTERFACE keyword, e.g. X::Y foo(...) INTERFACE: .... an extra variable to hold a function pointer is declared and initialised, but the return type of the function gets declared as X::Y rather than X__Y, resulting in uncompilable C code being generated. This commit fixes that. Before, the code emitted was: dXSFUNCTION(X::Y); XSFUNCTION = XSINTERFACE_FUNC(X::Y,cv,XSANY.any_dptr); but is now: dXSFUNCTION(X__Y); XSFUNCTION = XSINTERFACE_FUNC(X__Y,cv,XSANY.any_dptr);
1 parent 831d408 commit 6be8ed2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,14 @@ EOF
593593
| dXSI32;
594594
EOF
595595

596-
print ExtUtils::ParseXS::Q(<<"EOF") if $self->{seen_INTERFACE};
597-
| dXSFUNCTION($self->{decl}{return_type}{type});
596+
if ($self->{seen_INTERFACE}) {
597+
my $type = $self->{decl}{return_type}{type};
598+
$type =~ tr/:/_/
599+
unless $pxs->{config_RetainCplusplusHierarchicalTypes};
600+
print ExtUtils::ParseXS::Q(<<"EOF") if $self->{seen_INTERFACE};
601+
| dXSFUNCTION($type);
598602
EOF
603+
}
599604

600605

601606
{
@@ -3724,8 +3729,11 @@ sub as_code {
37243729
my $macro = $xsub->{interface_macro};
37253730
$macro = 'XSINTERFACE_FUNC' unless defined $macro;
37263731

3732+
my $type = $xsub->{decl}{return_type}{type};
3733+
$type =~ tr/:/_/
3734+
unless $pxs->{config_RetainCplusplusHierarchicalTypes};
37273735
print <<"EOF";
3728-
XSFUNCTION = $macro($xsub->{decl}{return_type}{type},cv,XSANY.any_dptr);
3736+
XSFUNCTION = $macro($type,cv,XSANY.any_dptr);
37293737
EOF
37303738
}
37313739

dist/ExtUtils-ParseXS/t/001-basic.t

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,6 +4828,24 @@ EOF
48284828
[ 0, 0, qr{\bXSFUNCTION\(\)},
48294829
"got XSFUNCTION call" ],
48304830
],
4831+
[
4832+
'INTERFACE with perl package name',
4833+
[ Q(<<'EOF') ],
4834+
|TYPEMAP: <<EOTM
4835+
|X::Y T_IV
4836+
|EOTM
4837+
|
4838+
|X::Y
4839+
|foo()
4840+
| INTERFACE: f1
4841+
EOF
4842+
[ 0, 0, qr{\b\QdXSFUNCTION(X__Y)},
4843+
"got XSFUNCTION declaration" ],
4844+
[ 0, 0, qr{\QXSFUNCTION = XSINTERFACE_FUNC(X__Y,cv,XSANY.any_dptr);},
4845+
"got XSFUNCTION assign" ],
4846+
[ 0, 0, qr{\bXSFUNCTION\(\)},
4847+
"got XSFUNCTION call" ],
4848+
],
48314849
);
48324850

48334851
test_many($preamble, 'XS_Foo_', \@test_fns);

0 commit comments

Comments
 (0)