1XSLoader(3pm)          Perl Programmers Reference Guide          XSLoader(3pm)
2
3
4

NAME

6       XSLoader - Dynamically load C libraries into Perl code
7

VERSION

9       Version 0.15
10

SYNOPSIS

12           package YourPackage;
13           require XSLoader;
14
15           XSLoader::load();
16

DESCRIPTION

18       This module defines a standard simplified interface to the dynamic
19       linking mechanisms available on many platforms.  Its primary purpose is
20       to implement cheap automatic dynamic loading of Perl modules.
21
22       For a more complicated interface, see DynaLoader.  Many (most) features
23       of "DynaLoader" are not implemented in "XSLoader", like for example the
24       "dl_load_flags", not honored by "XSLoader".
25
26   Migration from "DynaLoader"
27       A typical module using DynaLoader starts like this:
28
29           package YourPackage;
30           require DynaLoader;
31
32           our @ISA = qw( OnePackage OtherPackage DynaLoader );
33           our $VERSION = '0.01';
34           bootstrap YourPackage $VERSION;
35
36       Change this to
37
38           package YourPackage;
39           use XSLoader;
40
41           our @ISA = qw( OnePackage OtherPackage );
42           our $VERSION = '0.01';
43           XSLoader::load 'YourPackage', $VERSION;
44
45       In other words: replace "require DynaLoader" by "use XSLoader", remove
46       "DynaLoader" from @ISA, change "bootstrap" by "XSLoader::load".  Do not
47       forget to quote the name of your package on the "XSLoader::load" line,
48       and add comma (",") before the arguments ($VERSION above).
49
50       Of course, if @ISA contained only "DynaLoader", there is no need to
51       have the @ISA assignment at all; moreover, if instead of "our" one uses
52       the more backward-compatible
53
54           use vars qw($VERSION @ISA);
55
56       one can remove this reference to @ISA together with the @ISA
57       assignment.
58
59       If no $VERSION was specified on the "bootstrap" line, the last line
60       becomes
61
62           XSLoader::load 'YourPackage';
63
64       If the call to "load" is from the YourPackage, then that can be further
65       simplified to
66
67           XSLoader::load();
68
69       as "load" will use "caller" to determine the package.
70
71   Backward compatible boilerplate
72       If you want to have your cake and eat it too, you need a more
73       complicated boilerplate.
74
75           package YourPackage;
76           use vars qw($VERSION @ISA);
77
78           @ISA = qw( OnePackage OtherPackage );
79           $VERSION = '0.01';
80           eval {
81              require XSLoader;
82              XSLoader::load('YourPackage', $VERSION);
83              1;
84           } or do {
85              require DynaLoader;
86              push @ISA, 'DynaLoader';
87              bootstrap YourPackage $VERSION;
88           };
89
90       The parentheses about "XSLoader::load()" arguments are needed since we
91       replaced "use XSLoader" by "require", so the compiler does not know
92       that a function "XSLoader::load()" is present.
93
94       This boilerplate uses the low-overhead "XSLoader" if present; if used
95       with an antic Perl which has no "XSLoader", it falls back to using
96       "DynaLoader".
97

Order of initialization: early load()

99       Skip this section if the XSUB functions are supposed to be called from
100       other modules only; read it only if you call your XSUBs from the code
101       in your module, or have a "BOOT:" section in your XS file (see "The
102       BOOT: Keyword" in perlxs).  What is described here is equally
103       applicable to the DynaLoader interface.
104
105       A sufficiently complicated module using XS would have both Perl code
106       (defined in YourPackage.pm) and XS code (defined in YourPackage.xs).
107       If this Perl code makes calls into this XS code, and/or this XS code
108       makes calls to the Perl code, one should be careful with the order of
109       initialization.
110
111       The call to "XSLoader::load()" (or "bootstrap()") calls the module's
112       bootstrap code. For modules build by xsubpp (nearly all modules) this
113       has three side effects:
114
115       ·   A sanity check is done to ensure that the versions of the .pm and
116           the (compiled) .xs parts are compatible. If $VERSION was specified,
117           this is used for the check. If not specified, it defaults to
118           "$XS_VERSION // $VERSION" (in the module's namespace)
119
120       ·   the XSUBs are made accessible from Perl
121
122       ·   if a "BOOT:" section was present in the .xs file, the code there is
123           called.
124
125       Consequently, if the code in the .pm file makes calls to these XSUBs,
126       it is convenient to have XSUBs installed before the Perl code is
127       defined; for example, this makes prototypes for XSUBs visible to this
128       Perl code.  Alternatively, if the "BOOT:" section makes calls to Perl
129       functions (or uses Perl variables) defined in the .pm file, they must
130       be defined prior to the call to "XSLoader::load()" (or "bootstrap()").
131
132       The first situation being much more frequent, it makes sense to rewrite
133       the boilerplate as
134
135           package YourPackage;
136           use XSLoader;
137           use vars qw($VERSION @ISA);
138
139           BEGIN {
140              @ISA = qw( OnePackage OtherPackage );
141              $VERSION = '0.01';
142
143              # Put Perl code used in the BOOT: section here
144
145              XSLoader::load 'YourPackage', $VERSION;
146           }
147
148           # Put Perl code making calls into XSUBs here
149
150   The most hairy case
151       If the interdependence of your "BOOT:" section and Perl code is more
152       complicated than this (e.g., the "BOOT:" section makes calls to Perl
153       functions which make calls to XSUBs with prototypes), get rid of the
154       "BOOT:" section altogether.  Replace it with a function "onBOOT()", and
155       call it like this:
156
157           package YourPackage;
158           use XSLoader;
159           use vars qw($VERSION @ISA);
160
161           BEGIN {
162              @ISA = qw( OnePackage OtherPackage );
163              $VERSION = '0.01';
164              XSLoader::load 'YourPackage', $VERSION;
165           }
166
167           # Put Perl code used in onBOOT() function here; calls to XSUBs are
168           # prototype-checked.
169
170           onBOOT;
171
172           # Put Perl initialization code assuming that XS is initialized here
173

DIAGNOSTICS

175       "Can't find '%s' symbol in %s"
176           (F) The bootstrap symbol could not be found in the extension
177           module.
178
179       "Can't load '%s' for module %s: %s"
180           (F) The loading or initialisation of the extension module failed.
181           The detailed error follows.
182
183       "Undefined symbols present after loading %s: %s"
184           (W) As the message says, some symbols stay undefined although the
185           extension module was correctly loaded and initialised. The list of
186           undefined symbols follows.
187

LIMITATIONS

189       To reduce the overhead as much as possible, only one possible location
190       is checked to find the extension DLL (this location is where "make
191       install" would put the DLL).  If not found, the search for the DLL is
192       transparently delegated to "DynaLoader", which looks for the DLL along
193       the @INC list.
194
195       In particular, this is applicable to the structure of @INC used for
196       testing not-yet-installed extensions.  This means that running
197       uninstalled extensions may have much more overhead than running the
198       same extensions after "make install".
199

KNOWN BUGS

201       The new simpler way to call "XSLoader::load()" with no arguments at all
202       does not work on Perl 5.8.4 and 5.8.5.
203

BUGS

205       Please report any bugs or feature requests via the perlbug(1) utility.
206

SEE ALSO

208       DynaLoader
209

AUTHORS

211       Ilya Zakharevich originally extracted "XSLoader" from "DynaLoader".
212
213       CPAN version is currently maintained by Sebastien Aperghis-Tramoni
214       <sebastien@aperghis.net>.
215
216       Previous maintainer was Michael G Schwern <schwern@pobox.com>.
217
219       Copyright (C) 1990-2011 by Larry Wall and others.
220
221       This program is free software; you can redistribute it and/or modify it
222       under the same terms as Perl itself.
223
224
225
226perl v5.16.3                      2019-01-21                     XSLoader(3pm)
Impressum