Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/5.22.1/XSLoader.pm |
Statements | Executed 0 statements in 0s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 8 | 8 | 2.77ms | 2.77ms | load | XSLoader::
0 | 0 | 0 | 0s | 0s | bootstrap_inherit | XSLoader::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Generated from XSLoader.pm.PL (resolved %Config::Config value) | ||||
2 | |||||
3 | package XSLoader; | ||||
4 | |||||
5 | $VERSION = "0.20"; | ||||
6 | |||||
7 | #use strict; | ||||
8 | |||||
9 | package DynaLoader; | ||||
10 | |||||
11 | # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here. | ||||
12 | # NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB | ||||
13 | boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) && | ||||
14 | !defined(&dl_error); | ||||
15 | package XSLoader; | ||||
16 | |||||
17 | # spent 2.77ms within XSLoader::load which was called 8 times, avg 346µs/call:
# once (617µs+0s) by DateTime::BEGIN@18 at line 36 of POSIX.pm
# once (467µs+0s) by Class::Inspector::BEGIN@47 at line 17 of File/Spec/Unix.pm
# once (412µs+0s) by POSIX::BEGIN@11 at line 66 of Fcntl.pm
# once (318µs+0s) by DateTime::Format::Alami::BEGIN@114 at line 88 of re.pm
# once (310µs+0s) by DateTime::Helpers::BEGIN@8 at line 23 of List/Util.pm
# once (237µs+0s) by DateTime::try {...} at line 30 of DateTime.pm
# once (209µs+0s) by version::BEGIN@1 at line 14 of version/vxs.pm
# once (202µs+0s) by Module::Runtime::require_module at line 42 of Params/Validate/XS.pm | ||||
18 | package DynaLoader; | ||||
19 | |||||
20 | my ($caller, $modlibname) = caller(); | ||||
21 | my $module = $caller; | ||||
22 | |||||
23 | if (@_) { | ||||
24 | $module = $_[0]; | ||||
25 | } else { | ||||
26 | $_[0] = $module; | ||||
27 | } | ||||
28 | |||||
29 | # work with static linking too | ||||
30 | my $boots = "$module\::bootstrap"; | ||||
31 | goto &$boots if defined &$boots; | ||||
32 | |||||
33 | goto \&XSLoader::bootstrap_inherit unless $module and defined &dl_load_file; | ||||
34 | |||||
35 | my @modparts = split(/::/,$module); | ||||
36 | my $modfname = $modparts[-1]; | ||||
37 | |||||
38 | my $modpname = join('/',@modparts); | ||||
39 | my $c = () = split(/::/,$caller,-1); | ||||
40 | $modlibname =~ s,[\\/][^\\/]+$,, while $c--; # Q&D basename | ||||
41 | my $file = "$modlibname/auto/$modpname/$modfname.so"; | ||||
42 | |||||
43 | # print STDERR "XSLoader::load for $module ($file)\n" if $dl_debug; | ||||
44 | |||||
45 | my $bs = $file; | ||||
46 | $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library | ||||
47 | |||||
48 | if (-s $bs) { # only read file if it's not empty | ||||
49 | # print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug; | ||||
50 | eval { do $bs; }; | ||||
51 | warn "$bs: $@\n" if $@; | ||||
52 | goto \&XSLoader::bootstrap_inherit; | ||||
53 | } | ||||
54 | |||||
55 | goto \&XSLoader::bootstrap_inherit if not -f $file; | ||||
56 | |||||
57 | my $bootname = "boot_$module"; | ||||
58 | $bootname =~ s/\W/_/g; | ||||
59 | @DynaLoader::dl_require_symbols = ($bootname); | ||||
60 | |||||
61 | my $boot_symbol_ref; | ||||
62 | |||||
63 | # Many dynamic extension loading problems will appear to come from | ||||
64 | # this section of code: XYZ failed at line 123 of DynaLoader.pm. | ||||
65 | # Often these errors are actually occurring in the initialisation | ||||
66 | # C code of the extension XS file. Perl reports the error as being | ||||
67 | # in this perl code simply because this was the last perl code | ||||
68 | # it executed. | ||||
69 | |||||
70 | my $libref = dl_load_file($file, 0) or do { | ||||
71 | require Carp; | ||||
72 | Carp::croak("Can't load '$file' for module $module: " . dl_error()); | ||||
73 | }; | ||||
74 | push(@DynaLoader::dl_librefs,$libref); # record loaded object | ||||
75 | |||||
76 | my @unresolved = dl_undef_symbols(); | ||||
77 | if (@unresolved) { | ||||
78 | require Carp; | ||||
79 | Carp::carp("Undefined symbols present after loading $file: @unresolved\n"); | ||||
80 | } | ||||
81 | |||||
82 | $boot_symbol_ref = dl_find_symbol($libref, $bootname) or do { | ||||
83 | require Carp; | ||||
84 | Carp::croak("Can't find '$bootname' symbol in $file\n"); | ||||
85 | }; | ||||
86 | |||||
87 | push(@DynaLoader::dl_modules, $module); # record loaded module | ||||
88 | |||||
89 | boot: | ||||
90 | my $xs = dl_install_xsub($boots, $boot_symbol_ref, $file); | ||||
91 | |||||
92 | # See comment block above | ||||
93 | push(@DynaLoader::dl_shared_objects, $file); # record files loaded | ||||
94 | return &$xs(@_); | ||||
95 | } | ||||
96 | |||||
97 | sub bootstrap_inherit { | ||||
98 | require DynaLoader; | ||||
99 | goto \&DynaLoader::bootstrap_inherit; | ||||
100 | } | ||||
101 | |||||
102 | 1; | ||||
103 | |||||
104 | |||||
105 | __END__ | ||||
106 | |||||
107 | =head1 NAME | ||||
108 | |||||
109 | XSLoader - Dynamically load C libraries into Perl code | ||||
110 | |||||
111 | =head1 VERSION | ||||
112 | |||||
113 | Version 0.17 | ||||
114 | |||||
115 | =head1 SYNOPSIS | ||||
116 | |||||
117 | package YourPackage; | ||||
118 | require XSLoader; | ||||
119 | |||||
120 | XSLoader::load(); | ||||
121 | |||||
122 | =head1 DESCRIPTION | ||||
123 | |||||
124 | This module defines a standard I<simplified> interface to the dynamic | ||||
125 | linking mechanisms available on many platforms. Its primary purpose is | ||||
126 | to implement cheap automatic dynamic loading of Perl modules. | ||||
127 | |||||
128 | For a more complicated interface, see L<DynaLoader>. Many (most) | ||||
129 | features of C<DynaLoader> are not implemented in C<XSLoader>, like for | ||||
130 | example the C<dl_load_flags>, not honored by C<XSLoader>. | ||||
131 | |||||
132 | =head2 Migration from C<DynaLoader> | ||||
133 | |||||
134 | A typical module using L<DynaLoader|DynaLoader> starts like this: | ||||
135 | |||||
136 | package YourPackage; | ||||
137 | require DynaLoader; | ||||
138 | |||||
139 | our @ISA = qw( OnePackage OtherPackage DynaLoader ); | ||||
140 | our $VERSION = '0.01'; | ||||
141 | bootstrap YourPackage $VERSION; | ||||
142 | |||||
143 | Change this to | ||||
144 | |||||
145 | package YourPackage; | ||||
146 | use XSLoader; | ||||
147 | |||||
148 | our @ISA = qw( OnePackage OtherPackage ); | ||||
149 | our $VERSION = '0.01'; | ||||
150 | XSLoader::load 'YourPackage', $VERSION; | ||||
151 | |||||
152 | In other words: replace C<require DynaLoader> by C<use XSLoader>, remove | ||||
153 | C<DynaLoader> from C<@ISA>, change C<bootstrap> by C<XSLoader::load>. Do not | ||||
154 | forget to quote the name of your package on the C<XSLoader::load> line, | ||||
155 | and add comma (C<,>) before the arguments (C<$VERSION> above). | ||||
156 | |||||
157 | Of course, if C<@ISA> contained only C<DynaLoader>, there is no need to have | ||||
158 | the C<@ISA> assignment at all; moreover, if instead of C<our> one uses the | ||||
159 | more backward-compatible | ||||
160 | |||||
161 | use vars qw($VERSION @ISA); | ||||
162 | |||||
163 | one can remove this reference to C<@ISA> together with the C<@ISA> assignment. | ||||
164 | |||||
165 | If no C<$VERSION> was specified on the C<bootstrap> line, the last line becomes | ||||
166 | |||||
167 | XSLoader::load 'YourPackage'; | ||||
168 | |||||
169 | If the call to C<load> is from C<YourPackage>, then that can be further | ||||
170 | simplified to | ||||
171 | |||||
172 | XSLoader::load(); | ||||
173 | |||||
174 | as C<load> will use C<caller> to determine the package. | ||||
175 | |||||
176 | =head2 Backward compatible boilerplate | ||||
177 | |||||
178 | If you want to have your cake and eat it too, you need a more complicated | ||||
179 | boilerplate. | ||||
180 | |||||
181 | package YourPackage; | ||||
182 | use vars qw($VERSION @ISA); | ||||
183 | |||||
184 | @ISA = qw( OnePackage OtherPackage ); | ||||
185 | $VERSION = '0.01'; | ||||
186 | eval { | ||||
187 | require XSLoader; | ||||
188 | XSLoader::load('YourPackage', $VERSION); | ||||
189 | 1; | ||||
190 | } or do { | ||||
191 | require DynaLoader; | ||||
192 | push @ISA, 'DynaLoader'; | ||||
193 | bootstrap YourPackage $VERSION; | ||||
194 | }; | ||||
195 | |||||
196 | The parentheses about C<XSLoader::load()> arguments are needed since we replaced | ||||
197 | C<use XSLoader> by C<require>, so the compiler does not know that a function | ||||
198 | C<XSLoader::load()> is present. | ||||
199 | |||||
200 | This boilerplate uses the low-overhead C<XSLoader> if present; if used with | ||||
201 | an antique Perl which has no C<XSLoader>, it falls back to using C<DynaLoader>. | ||||
202 | |||||
203 | =head1 Order of initialization: early load() | ||||
204 | |||||
205 | I<Skip this section if the XSUB functions are supposed to be called from other | ||||
206 | modules only; read it only if you call your XSUBs from the code in your module, | ||||
207 | or have a C<BOOT:> section in your XS file (see L<perlxs/"The BOOT: Keyword">). | ||||
208 | What is described here is equally applicable to the L<DynaLoader|DynaLoader> | ||||
209 | interface.> | ||||
210 | |||||
211 | A sufficiently complicated module using XS would have both Perl code (defined | ||||
212 | in F<YourPackage.pm>) and XS code (defined in F<YourPackage.xs>). If this | ||||
213 | Perl code makes calls into this XS code, and/or this XS code makes calls to | ||||
214 | the Perl code, one should be careful with the order of initialization. | ||||
215 | |||||
216 | The call to C<XSLoader::load()> (or C<bootstrap()>) calls the module's | ||||
217 | bootstrap code. For modules build by F<xsubpp> (nearly all modules) this | ||||
218 | has three side effects: | ||||
219 | |||||
220 | =over | ||||
221 | |||||
222 | =item * | ||||
223 | |||||
224 | A sanity check is done to ensure that the versions of the F<.pm> and the | ||||
225 | (compiled) F<.xs> parts are compatible. If C<$VERSION> was specified, this | ||||
226 | is used for the check. If not specified, it defaults to | ||||
227 | C<$XS_VERSION // $VERSION> (in the module's namespace) | ||||
228 | |||||
229 | =item * | ||||
230 | |||||
231 | the XSUBs are made accessible from Perl | ||||
232 | |||||
233 | =item * | ||||
234 | |||||
235 | if a C<BOOT:> section was present in the F<.xs> file, the code there is called. | ||||
236 | |||||
237 | =back | ||||
238 | |||||
239 | Consequently, if the code in the F<.pm> file makes calls to these XSUBs, it is | ||||
240 | convenient to have XSUBs installed before the Perl code is defined; for | ||||
241 | example, this makes prototypes for XSUBs visible to this Perl code. | ||||
242 | Alternatively, if the C<BOOT:> section makes calls to Perl functions (or | ||||
243 | uses Perl variables) defined in the F<.pm> file, they must be defined prior to | ||||
244 | the call to C<XSLoader::load()> (or C<bootstrap()>). | ||||
245 | |||||
246 | The first situation being much more frequent, it makes sense to rewrite the | ||||
247 | boilerplate as | ||||
248 | |||||
249 | package YourPackage; | ||||
250 | use XSLoader; | ||||
251 | use vars qw($VERSION @ISA); | ||||
252 | |||||
253 | BEGIN { | ||||
254 | @ISA = qw( OnePackage OtherPackage ); | ||||
255 | $VERSION = '0.01'; | ||||
256 | |||||
257 | # Put Perl code used in the BOOT: section here | ||||
258 | |||||
259 | XSLoader::load 'YourPackage', $VERSION; | ||||
260 | } | ||||
261 | |||||
262 | # Put Perl code making calls into XSUBs here | ||||
263 | |||||
264 | =head2 The most hairy case | ||||
265 | |||||
266 | If the interdependence of your C<BOOT:> section and Perl code is | ||||
267 | more complicated than this (e.g., the C<BOOT:> section makes calls to Perl | ||||
268 | functions which make calls to XSUBs with prototypes), get rid of the C<BOOT:> | ||||
269 | section altogether. Replace it with a function C<onBOOT()>, and call it like | ||||
270 | this: | ||||
271 | |||||
272 | package YourPackage; | ||||
273 | use XSLoader; | ||||
274 | use vars qw($VERSION @ISA); | ||||
275 | |||||
276 | BEGIN { | ||||
277 | @ISA = qw( OnePackage OtherPackage ); | ||||
278 | $VERSION = '0.01'; | ||||
279 | XSLoader::load 'YourPackage', $VERSION; | ||||
280 | } | ||||
281 | |||||
282 | # Put Perl code used in onBOOT() function here; calls to XSUBs are | ||||
283 | # prototype-checked. | ||||
284 | |||||
285 | onBOOT; | ||||
286 | |||||
287 | # Put Perl initialization code assuming that XS is initialized here | ||||
288 | |||||
289 | |||||
290 | =head1 DIAGNOSTICS | ||||
291 | |||||
292 | =over | ||||
293 | |||||
294 | =item C<Can't find '%s' symbol in %s> | ||||
295 | |||||
296 | B<(F)> The bootstrap symbol could not be found in the extension module. | ||||
297 | |||||
298 | =item C<Can't load '%s' for module %s: %s> | ||||
299 | |||||
300 | B<(F)> The loading or initialisation of the extension module failed. | ||||
301 | The detailed error follows. | ||||
302 | |||||
303 | =item C<Undefined symbols present after loading %s: %s> | ||||
304 | |||||
305 | B<(W)> As the message says, some symbols stay undefined although the | ||||
306 | extension module was correctly loaded and initialised. The list of undefined | ||||
307 | symbols follows. | ||||
308 | |||||
309 | =back | ||||
310 | |||||
311 | =head1 LIMITATIONS | ||||
312 | |||||
313 | To reduce the overhead as much as possible, only one possible location | ||||
314 | is checked to find the extension DLL (this location is where C<make install> | ||||
315 | would put the DLL). If not found, the search for the DLL is transparently | ||||
316 | delegated to C<DynaLoader>, which looks for the DLL along the C<@INC> list. | ||||
317 | |||||
318 | In particular, this is applicable to the structure of C<@INC> used for testing | ||||
319 | not-yet-installed extensions. This means that running uninstalled extensions | ||||
320 | may have much more overhead than running the same extensions after | ||||
321 | C<make install>. | ||||
322 | |||||
323 | |||||
324 | =head1 KNOWN BUGS | ||||
325 | |||||
326 | The new simpler way to call C<XSLoader::load()> with no arguments at all | ||||
327 | does not work on Perl 5.8.4 and 5.8.5. | ||||
328 | |||||
329 | |||||
330 | =head1 BUGS | ||||
331 | |||||
332 | Please report any bugs or feature requests via the perlbug(1) utility. | ||||
333 | |||||
334 | |||||
335 | =head1 SEE ALSO | ||||
336 | |||||
337 | L<DynaLoader> | ||||
338 | |||||
339 | |||||
340 | =head1 AUTHORS | ||||
341 | |||||
342 | Ilya Zakharevich originally extracted C<XSLoader> from C<DynaLoader>. | ||||
343 | |||||
344 | CPAN version is currently maintained by SE<eacute>bastien Aperghis-Tramoni | ||||
345 | E<lt>sebastien@aperghis.netE<gt>. | ||||
346 | |||||
347 | Previous maintainer was Michael G Schwern <schwern@pobox.com>. | ||||
348 | |||||
349 | |||||
350 | =head1 COPYRIGHT & LICENSE | ||||
351 | |||||
352 | Copyright (C) 1990-2011 by Larry Wall and others. | ||||
353 | |||||
354 | This program is free software; you can redistribute it and/or modify | ||||
355 | it under the same terms as Perl itself. | ||||
356 | |||||
357 | =cut |