← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:10 2016

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