summaryrefslogtreecommitdiffstats
path: root/upstream/debian-unstable/man3/XSLoader.3perl
blob: aa627c8ab71e933fe5d026ae69da3ad9e77e523b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
.\" -*- 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 3perl"
.TH XSLoader 3perl 2024-05-30 "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
<sebastien@aperghis.net>.
.PP
Previous maintainer was Michael G Schwern <schwern@pobox.com>.
.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.