Skip to content

Commit f3f436a

Browse files
committed
perlxs.pod: update EXAMPLES section
Rewrite this section: =head1 EXAMPLES Basically, delete the one big example in this section and instead provide links to various other examples already present in this document instead.
1 parent ae9183e commit f3f436a

File tree

1 file changed

+23
-56
lines changed

1 file changed

+23
-56
lines changed

dist/ExtUtils-ParseXS/lib/perlxs.pod

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,77 +4789,44 @@ structure than a C<dMY_CXT> in another source file.
47894789

47904790
=head1 EXAMPLES
47914791

4792-
File C<RPC.xs>: Interface to some ONC+ RPC bind library functions.
4792+
Fairly complete examples of XS files can be found elsewhere in this
4793+
document:
47934794

4794-
#define PERL_NO_GET_CONTEXT
4795-
#include "EXTERN.h"
4796-
#include "perl.h"
4797-
#include "XSUB.h"
4798-
4799-
/* Note: On glibc 2.13 and earlier, this needs be <rpc/rpc.h> */
4800-
#include <tirpc/rpc.h>
4801-
4802-
typedef struct netconfig Netconfig;
4803-
4804-
MODULE = RPC PACKAGE = RPC
4805-
4806-
SV *
4807-
rpcb_gettime(host = "localhost")
4808-
char *host
4809-
PREINIT:
4810-
time_t timep;
4811-
CODE:
4812-
ST(0) = sv_newmortal();
4813-
if (rpcb_gettime(host, &timep))
4814-
sv_setnv(ST(0), (double)timep);
4815-
4816-
4817-
Netconfig *
4818-
getnetconfigent(netid="udp")
4819-
char *netid
4795+
=over
48204796

4797+
=item *
48214798

4822-
MODULE = RPC PACKAGE = NetconfigPtr PREFIX = rpcb_
4799+
L</T_PTROBJ and opaque handles>
48234800

4824-
void
4825-
rpcb_DESTROY(netconf)
4826-
Netconfig *netconf
4827-
CODE:
4828-
printf("NetconfigPtr::DESTROY\n");
4829-
free(netconf);
4801+
=item *
48304802

4831-
File C<typemap>: Custom typemap for RPC.xs. (cf. L<perlxstypemap>)
4803+
L</A complete C++ example>
48324804

4833-
TYPEMAP
4834-
Netconfig * T_PTROBJ
4805+
=item *
48354806

4836-
File C<RPC.pm>: Perl module for the RPC extension.
4807+
L</Safely Storing Static Data in XS>
48374808

4838-
package RPC;
4809+
=back
48394810

4840-
require Exporter;
4841-
require DynaLoader;
4842-
@ISA = qw(Exporter DynaLoader);
4843-
@EXPORT = qw(rpcb_gettime getnetconfigent);
4811+
while L</SYNOPSIS> contains an overview of an XS file and L<perlxstut>
4812+
contains various worked examples.
48444813

4845-
bootstrap RPC;
4846-
1;
4814+
You can of course look at existing XS distributions on CPAN for
4815+
inspiration, although bear in mind that many of these will have been
4816+
created before this document was rewritten in 2025, and so may not follow
4817+
current best practices.
48474818

4848-
File C<rpctest.pl>: Perl test program for the RPC extension.
4819+
Note that when wrapping a real library, you'll often need to add a line
4820+
like this to the .xs file:
48494821

4850-
use RPC;
4822+
#include <foobar.h>
48514823

4852-
$netconf = getnetconfigent();
4853-
$a = rpcb_gettime();
4854-
print "time = $a\n";
4855-
print "netconf = $netconf\n";
4824+
and add entries like:
48564825

4857-
$netconf = getnetconfigent("tcp");
4858-
$a = rpcb_gettime("poplar");
4859-
print "time = $a\n";
4860-
print "netconf = $netconf\n";
4826+
LIBS => ['-lfoo', '-lbar'],
48614827

4862-
In Makefile.PL add -ltirpc and -I/usr/include/tirpc.
4828+
to F<Makefile.PL> or similar. And don't forget to add test scripts under
4829+
t/.
48634830

48644831
=head1 CAVEATS
48654832

0 commit comments

Comments
 (0)