.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "XSLoader 3pm" .TH XSLoader 3pm 2023-12-15 "perl v5.38.2" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME XSLoader \- Dynamically load C libraries into Perl code .SH VERSION .IX Header "VERSION" Version 0.32 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& package YourPackage; \& require XSLoader; \& \& XSLoader::load(_\|_PACKAGE_\|_, $VERSION); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module defines a standard \fIsimplified\fR interface to the dynamic linking mechanisms available on many platforms. Its primary purpose is to implement cheap automatic dynamic loading of Perl modules. .PP For a more complicated interface, see DynaLoader. Many (most) features of \f(CW\*(C`DynaLoader\*(C'\fR are not implemented in \f(CW\*(C`XSLoader\*(C'\fR, like for example the \f(CW\*(C`dl_load_flags\*(C'\fR, not honored by \f(CW\*(C`XSLoader\*(C'\fR. .ie n .SS "Migration from ""DynaLoader""" .el .SS "Migration from \f(CWDynaLoader\fP" .IX Subsection "Migration from DynaLoader" A typical module using DynaLoader starts like this: .PP .Vb 2 \& package YourPackage; \& require DynaLoader; \& \& our @ISA = qw( OnePackage OtherPackage DynaLoader ); \& our $VERSION = \*(Aq0.01\*(Aq; \& _\|_PACKAGE_\|_\->bootstrap($VERSION); .Ve .PP Change this to .PP .Vb 2 \& package YourPackage; \& use XSLoader; \& \& our @ISA = qw( OnePackage OtherPackage ); \& our $VERSION = \*(Aq0.01\*(Aq; \& XSLoader::load(_\|_PACKAGE_\|_, $VERSION); .Ve .PP In other words: replace \f(CW\*(C`require DynaLoader\*(C'\fR by \f(CW\*(C`use XSLoader\*(C'\fR, remove \&\f(CW\*(C`DynaLoader\*(C'\fR from \f(CW@ISA\fR, change \f(CW\*(C`bootstrap\*(C'\fR by \f(CW\*(C`XSLoader::load\*(C'\fR. Do not forget to quote the name of your package on the \f(CW\*(C`XSLoader::load\*(C'\fR line, and add comma (\f(CW\*(C`,\*(C'\fR) before the arguments (\f(CW$VERSION\fR above). .PP Of course, if \f(CW@ISA\fR contained only \f(CW\*(C`DynaLoader\*(C'\fR, there is no need to have the \f(CW@ISA\fR assignment at all; moreover, if instead of \f(CW\*(C`our\*(C'\fR one uses the more backward-compatible .PP .Vb 1 \& use vars qw($VERSION @ISA); .Ve .PP one can remove this reference to \f(CW@ISA\fR together with the \f(CW@ISA\fR assignment. .PP If no \f(CW$VERSION\fR was specified on the \f(CW\*(C`bootstrap\*(C'\fR line, the last line becomes .PP .Vb 1 \& XSLoader::load(_\|_PACKAGE_\|_); .Ve .PP in which case it can be further simplified to .PP .Vb 1 \& XSLoader::load(); .Ve .PP as \f(CW\*(C`load\*(C'\fR will use \f(CW\*(C`caller\*(C'\fR to determine the package. .SS "Backward compatible boilerplate" .IX Subsection "Backward compatible boilerplate" If you want to have your cake and eat it too, you need a more complicated boilerplate. .PP .Vb 1 \& package YourPackage; \& \& our @ISA = qw( OnePackage OtherPackage ); \& our $VERSION = \*(Aq0.01\*(Aq; \& eval { \& require XSLoader; \& XSLoader::load(_\|_PACKAGE_\|_, $VERSION); \& 1; \& } or do { \& require DynaLoader; \& push @ISA, \*(AqDynaLoader\*(Aq; \& _\|_PACKAGE_\|_\->bootstrap($VERSION); \& }; .Ve .PP The parentheses about \f(CWXSLoader::load()\fR arguments are needed since we replaced \&\f(CW\*(C`use XSLoader\*(C'\fR by \f(CW\*(C`require\*(C'\fR, so the compiler does not know that a function \&\f(CWXSLoader::load()\fR is present. .PP This boilerplate uses the low-overhead \f(CW\*(C`XSLoader\*(C'\fR if present; if used with an antique Perl which has no \f(CW\*(C`XSLoader\*(C'\fR, it falls back to using \f(CW\*(C`DynaLoader\*(C'\fR. .SH "Order of initialization: early \fBload()\fP" .IX Header "Order of initialization: early load()" \&\fISkip this section if the XSUB functions are supposed to be called from other modules only; read it only if you call your XSUBs from the code in your module, or have a \fR\f(CI\*(C`BOOT:\*(C'\fR\fI section in your XS file (see "The BOOT: Keyword" in perlxs). What is described here is equally applicable to the DynaLoader interface.\fR .PP A sufficiently complicated module using XS would have both Perl code (defined in \fIYourPackage.pm\fR) and XS code (defined in \fIYourPackage.xs\fR). If this Perl code makes calls into this XS code, and/or this XS code makes calls to the Perl code, one should be careful with the order of initialization. .PP The call to \f(CWXSLoader::load()\fR (or \f(CWbootstrap()\fR) calls the module's bootstrap code. For modules build by \fIxsubpp\fR (nearly all modules) this has three side effects: .IP \(bu 4 A sanity check is done to ensure that the versions of the \fI.pm\fR and the (compiled) \fI.xs\fR parts are compatible. If \f(CW$VERSION\fR was specified, this is used for the check. If not specified, it defaults to \&\f(CW\*(C`$XS_VERSION // $VERSION\*(C'\fR (in the module's namespace) .IP \(bu 4 the XSUBs are made accessible from Perl .IP \(bu 4 if a \f(CW\*(C`BOOT:\*(C'\fR section was present in the \fI.xs\fR file, the code there is called. .PP Consequently, if the code in the \fI.pm\fR file makes calls to these XSUBs, it is convenient to have XSUBs installed before the Perl code is defined; for example, this makes prototypes for XSUBs visible to this Perl code. Alternatively, if the \f(CW\*(C`BOOT:\*(C'\fR section makes calls to Perl functions (or uses Perl variables) defined in the \fI.pm\fR file, they must be defined prior to the call to \f(CWXSLoader::load()\fR (or \f(CWbootstrap()\fR). .PP The first situation being much more frequent, it makes sense to rewrite the boilerplate as .PP .Vb 3 \& package YourPackage; \& use XSLoader; \& our ($VERSION, @ISA); \& \& BEGIN { \& @ISA = qw( OnePackage OtherPackage ); \& $VERSION = \*(Aq0.01\*(Aq; \& \& # Put Perl code used in the BOOT: section here \& \& XSLoader::load(_\|_PACKAGE_\|_, $VERSION); \& } \& \& # Put Perl code making calls into XSUBs here .Ve .SS "The most hairy case" .IX Subsection "The most hairy case" If the interdependence of your \f(CW\*(C`BOOT:\*(C'\fR section and Perl code is more complicated than this (e.g., the \f(CW\*(C`BOOT:\*(C'\fR section makes calls to Perl functions which make calls to XSUBs with prototypes), get rid of the \f(CW\*(C`BOOT:\*(C'\fR section altogether. Replace it with a function \f(CWonBOOT()\fR, and call it like this: .PP .Vb 3 \& package YourPackage; \& use XSLoader; \& our ($VERSION, @ISA); \& \& BEGIN { \& @ISA = qw( OnePackage OtherPackage ); \& $VERSION = \*(Aq0.01\*(Aq; \& XSLoader::load(_\|_PACKAGE_\|_, $VERSION); \& } \& \& # Put Perl code used in onBOOT() function here; calls to XSUBs are \& # prototype\-checked. \& \& onBOOT; \& \& # Put Perl initialization code assuming that XS is initialized here .Ve .SH DIAGNOSTICS .IX Header "DIAGNOSTICS" .ie n .IP """Can\*(Aqt find \*(Aq%s\*(Aq symbol in %s""" 4 .el .IP "\f(CWCan\*(Aqt find \*(Aq%s\*(Aq symbol in %s\fR" 4 .IX Item "Cant find %s symbol in %s" \&\fB(F)\fR The bootstrap symbol could not be found in the extension module. .ie n .IP """Can\*(Aqt load \*(Aq%s\*(Aq for module %s: %s""" 4 .el .IP "\f(CWCan\*(Aqt load \*(Aq%s\*(Aq for module %s: %s\fR" 4 .IX Item "Cant load %s for module %s: %s" \&\fB(F)\fR The loading or initialisation of the extension module failed. The detailed error follows. .ie n .IP """Undefined symbols present after loading %s: %s""" 4 .el .IP "\f(CWUndefined symbols present after loading %s: %s\fR" 4 .IX Item "Undefined symbols present after loading %s: %s" \&\fB(W)\fR As the message says, some symbols stay undefined although the extension module was correctly loaded and initialised. The list of undefined symbols follows. .SH LIMITATIONS .IX Header "LIMITATIONS" To reduce the overhead as much as possible, only one possible location is checked to find the extension DLL (this location is where \f(CW\*(C`make install\*(C'\fR would put the DLL). If not found, the search for the DLL is transparently delegated to \f(CW\*(C`DynaLoader\*(C'\fR, which looks for the DLL along the \f(CW@INC\fR list. .PP In particular, this is applicable to the structure of \f(CW@INC\fR used for testing not-yet-installed extensions. This means that running uninstalled extensions may have much more overhead than running the same extensions after \&\f(CW\*(C`make install\*(C'\fR. .SH "KNOWN BUGS" .IX Header "KNOWN BUGS" The new simpler way to call \f(CWXSLoader::load()\fR with no arguments at all does not work on Perl 5.8.4 and 5.8.5. .SH BUGS .IX Header "BUGS" Please report any bugs or feature requests via the \fBperlbug\fR\|(1) utility. .SH "SEE ALSO" .IX Header "SEE ALSO" DynaLoader .SH AUTHORS .IX Header "AUTHORS" Ilya Zakharevich originally extracted \f(CW\*(C`XSLoader\*(C'\fR from \f(CW\*(C`DynaLoader\*(C'\fR. .PP CPAN version is currently maintained by Sébastien Aperghis-Tramoni . .PP Previous maintainer was Michael G Schwern . .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright (C) 1990\-2011 by Larry Wall and others. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.