Skip to content

Commit 09e774d

Browse files
committed
perlxs.pod: update TYPEMAP: keyword
1 parent ac07e97 commit 09e774d

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

dist/ExtUtils-ParseXS/lib/perlxs.pod

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,22 +1818,61 @@ interpreter which is running the XS parser.
18181818

18191819
=head3 The TYPEMAP: Keyword
18201820

1821-
Starting with Perl 5.16, you can embed typemaps into your XS code
1822-
instead of or in addition to typemaps in a separate file. Multiple
1823-
such embedded typemaps will be processed in order of appearance in
1824-
the XS code and like local typemap files take precedence over the
1825-
default typemap, the embedded typemaps may overwrite previous
1826-
definitions of TYPEMAP, INPUT, and OUTPUT stanzas. The syntax for
1827-
embedded typemaps is
1828-
1829-
TYPEMAP: <<HERE
1830-
... your typemap code here ...
1831-
HERE
1832-
1833-
where the C<TYPEMAP> keyword must appear in the first column of a
1834-
new line.
1835-
1836-
Refer to L<perlxstypemap> for details on writing typemaps.
1821+
TYPEMAP: <<EOF
1822+
myint T_MYIV
1823+
INPUT
1824+
T_MYIV
1825+
$var = ($type)my_SvIV($arg)
1826+
OUTPUT
1827+
T_MYIV
1828+
my_sv_setiv($arg, (IV)$var);
1829+
EOF
1830+
1831+
Since 5.16.0.
1832+
1833+
Typemaps are mappings and code templates which allow the XS parser to
1834+
automatically generate code snippets which convert between Perl and C
1835+
values. The C<TYPEMAP> keyword can be used to embed typemap declarations
1836+
directly into your XS code, instead of (or in addition to) typemaps in a
1837+
separate file. Multiple such embedded typemaps will be processed in order
1838+
of appearance in the XS code. Typemaps are processed in the order:
1839+
1840+
=over
1841+
1842+
=item *
1843+
1844+
The system typemap file.
1845+
1846+
=item *
1847+
1848+
A local typemap file, typically specified by C<xsubpp -typemap typemap>
1849+
in the F<Makefile>.
1850+
1851+
=item *
1852+
1853+
C<TYPEMAP:> entries, in order.
1854+
1855+
=back
1856+
1857+
The most recently-applied entries take precedence, so for example you can
1858+
use C<TYPEMAP:> to individually override specific C<TYPEMAP>, C<INPUT>, or
1859+
C<OUTPUT> entries in the system typemap. In general, typemap changes
1860+
affect any subsequent XSUBs within the file, until further updates. Note
1861+
however that due a quirk in parsing, it is possible for a C<TYPEMAP:>
1862+
entry immediately I<after> an XSUB to affect that XSUB.
1863+
1864+
The C<TYPEMAP> keyword syntax is intended to mimic Perl's "heredoc"
1865+
syntax, and the keyword must be followed by one of these three forms:
1866+
1867+
<< FOO
1868+
<< 'FOO'
1869+
<< "FOO"
1870+
1871+
where C<FOO> can be just about any sequence of characters, which must be
1872+
matched at the start of a subsequent line.
1873+
1874+
See L</Using Typemaps> and L<perlxstypemap> for more details on writing
1875+
typemaps.
18371876

18381877
=head3 The BOOT: Keyword
18391878

0 commit comments

Comments
 (0)