← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mojo-test.pl
  Run on Sat Feb 5 19:54:22 2011
Reported on Sat Feb 5 19:54:56 2011

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