← Index
NYTProf Performance Profile   « line view »
For -e
  Run on Thu Jun 30 16:23:05 2016
Reported on Thu Jun 30 16:24:01 2016

Filename/home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/5.22.1/XSLoader.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
8882.77ms2.77msXSLoader::::loadXSLoader::load
0000s0sXSLoader::::bootstrap_inheritXSLoader::bootstrap_inherit
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# Generated from XSLoader.pm.PL (resolved %Config::Config value)
2
3package XSLoader;
4
5$VERSION = "0.20";
6
7#use strict;
8
9package 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
13boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
14 !defined(&dl_error);
15package 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
sub load {
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
97sub bootstrap_inherit {
98 require DynaLoader;
99 goto \&DynaLoader::bootstrap_inherit;
100}
101
1021;
103
104
105__END__
106
107=head1 NAME
108
109XSLoader - Dynamically load C libraries into Perl code
110
111=head1 VERSION
112
113Version 0.17
114
115=head1 SYNOPSIS
116
117 package YourPackage;
118 require XSLoader;
119
120 XSLoader::load();
121
122=head1 DESCRIPTION
123
124This module defines a standard I<simplified> interface to the dynamic
125linking mechanisms available on many platforms. Its primary purpose is
126to implement cheap automatic dynamic loading of Perl modules.
127
128For a more complicated interface, see L<DynaLoader>. Many (most)
129features of C<DynaLoader> are not implemented in C<XSLoader>, like for
130example the C<dl_load_flags>, not honored by C<XSLoader>.
131
132=head2 Migration from C<DynaLoader>
133
134A 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
143Change 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
152In other words: replace C<require DynaLoader> by C<use XSLoader>, remove
153C<DynaLoader> from C<@ISA>, change C<bootstrap> by C<XSLoader::load>. Do not
154forget to quote the name of your package on the C<XSLoader::load> line,
155and add comma (C<,>) before the arguments (C<$VERSION> above).
156
157Of course, if C<@ISA> contained only C<DynaLoader>, there is no need to have
158the C<@ISA> assignment at all; moreover, if instead of C<our> one uses the
159more backward-compatible
160
161 use vars qw($VERSION @ISA);
162
163one can remove this reference to C<@ISA> together with the C<@ISA> assignment.
164
165If no C<$VERSION> was specified on the C<bootstrap> line, the last line becomes
166
167 XSLoader::load 'YourPackage';
168
169If the call to C<load> is from C<YourPackage>, then that can be further
170simplified to
171
172 XSLoader::load();
173
174as C<load> will use C<caller> to determine the package.
175
176=head2 Backward compatible boilerplate
177
178If you want to have your cake and eat it too, you need a more complicated
179boilerplate.
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
196The parentheses about C<XSLoader::load()> arguments are needed since we replaced
197C<use XSLoader> by C<require>, so the compiler does not know that a function
198C<XSLoader::load()> is present.
199
200This boilerplate uses the low-overhead C<XSLoader> if present; if used with
201an antique Perl which has no C<XSLoader>, it falls back to using C<DynaLoader>.
202
203=head1 Order of initialization: early load()
204
205I<Skip this section if the XSUB functions are supposed to be called from other
206modules only; read it only if you call your XSUBs from the code in your module,
207or have a C<BOOT:> section in your XS file (see L<perlxs/"The BOOT: Keyword">).
208What is described here is equally applicable to the L<DynaLoader|DynaLoader>
209interface.>
210
211A sufficiently complicated module using XS would have both Perl code (defined
212in F<YourPackage.pm>) and XS code (defined in F<YourPackage.xs>). If this
213Perl code makes calls into this XS code, and/or this XS code makes calls to
214the Perl code, one should be careful with the order of initialization.
215
216The call to C<XSLoader::load()> (or C<bootstrap()>) calls the module's
217bootstrap code. For modules build by F<xsubpp> (nearly all modules) this
218has three side effects:
219
220=over
221
222=item *
223
224A 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
226is used for the check. If not specified, it defaults to
227C<$XS_VERSION // $VERSION> (in the module's namespace)
228
229=item *
230
231the XSUBs are made accessible from Perl
232
233=item *
234
235if a C<BOOT:> section was present in the F<.xs> file, the code there is called.
236
237=back
238
239Consequently, if the code in the F<.pm> file makes calls to these XSUBs, it is
240convenient to have XSUBs installed before the Perl code is defined; for
241example, this makes prototypes for XSUBs visible to this Perl code.
242Alternatively, if the C<BOOT:> section makes calls to Perl functions (or
243uses Perl variables) defined in the F<.pm> file, they must be defined prior to
244the call to C<XSLoader::load()> (or C<bootstrap()>).
245
246The first situation being much more frequent, it makes sense to rewrite the
247boilerplate 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
266If the interdependence of your C<BOOT:> section and Perl code is
267more complicated than this (e.g., the C<BOOT:> section makes calls to Perl
268functions which make calls to XSUBs with prototypes), get rid of the C<BOOT:>
269section altogether. Replace it with a function C<onBOOT()>, and call it like
270this:
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
296B<(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
300B<(F)> The loading or initialisation of the extension module failed.
301The detailed error follows.
302
303=item C<Undefined symbols present after loading %s: %s>
304
305B<(W)> As the message says, some symbols stay undefined although the
306extension module was correctly loaded and initialised. The list of undefined
307symbols follows.
308
309=back
310
311=head1 LIMITATIONS
312
313To reduce the overhead as much as possible, only one possible location
314is checked to find the extension DLL (this location is where C<make install>
315would put the DLL). If not found, the search for the DLL is transparently
316delegated to C<DynaLoader>, which looks for the DLL along the C<@INC> list.
317
318In particular, this is applicable to the structure of C<@INC> used for testing
319not-yet-installed extensions. This means that running uninstalled extensions
320may have much more overhead than running the same extensions after
321C<make install>.
322
323
324=head1 KNOWN BUGS
325
326The new simpler way to call C<XSLoader::load()> with no arguments at all
327does not work on Perl 5.8.4 and 5.8.5.
328
329
330=head1 BUGS
331
332Please report any bugs or feature requests via the perlbug(1) utility.
333
334
335=head1 SEE ALSO
336
337L<DynaLoader>
338
339
340=head1 AUTHORS
341
342Ilya Zakharevich originally extracted C<XSLoader> from C<DynaLoader>.
343
344CPAN version is currently maintained by SE<eacute>bastien Aperghis-Tramoni
345E<lt>sebastien@aperghis.netE<gt>.
346
347Previous maintainer was Michael G Schwern <schwern@pobox.com>.
348
349
350=head1 COPYRIGHT & LICENSE
351
352Copyright (C) 1990-2011 by Larry Wall and others.
353
354This program is free software; you can redistribute it and/or modify
355it under the same terms as Perl itself.
356
357=cut