Profile of XSLoader.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For bin/dpath
Run on Tue Jun 5 15:30:18 2012
Reported on Tue Jun 5 15:30:48 2012

Filename | /home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/x86_64-linux-thread-multi/XSLoader.pm
Statements | Executed 0 statements in 0s

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
11 | 11 | 11 | 13.8ms | 13.8ms | XSLoader::::loadXSLoader::load
0 | 0 | 0 | 0s | 0s | XSLoader::::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 |  |  |  |  |
3 |  |  |  |  | package XSLoader;
4 |  |  |  |  |
5 |  |  |  |  | $VERSION = "0.15";
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 |  |  |  |  | package DynaLoader;
13 |  |  |  |  |
14 |  |  |  |  | # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
15 |  |  |  |  | # NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB
16 |  |  |  |  | boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
17 |  |  |  |  | !defined(&dl_error);
18 |  |  |  |  | package XSLoader;
19 |  |  |  |  |
20 |  |  |  |  | # spent 13.8ms within XSLoader::load which was called 11 times, avg 1.26ms/call: # once (2.47ms+0s) by B::BEGIN@17 at line 27 of B.pm # once (2.22ms+0s) by Safe::BEGIN@46 at line 31 of Opcode.pm # once (2.17ms+0s) by Data::DPath::Context::BEGIN@22 at line 36 of POSIX.pm # once (1.30ms+0s) by Class::XSAccessor::Array::BEGIN@6 at line 11 of Class/XSAccessor.pm # once (973µs+0s) by POSIX::BEGIN@13 at line 66 of Fcntl.pm # once (944µs+0s) by IO::Handle::BEGIN@266 at line 11 of IO.pm # once (810µs+0s) by Data::DPath::Context::BEGIN@17 at line 21 of List/Util.pm # once (765µs+0s) by B::Deparse::BEGIN@3436 at line 85 of re.pm # once (748µs+0s) by YAML::XS::BEGIN@19 at line 7 of YAML/XS/LibYAML.pm # once (720µs+0s) by Attribute::Handlers::BEGIN@110 at line 101 of attributes.pm # once (710µs+0s) by Data::DPath::Path::BEGIN@13 at line 36 of Data/Dumper.pm sub load {
21 |  |  |  |  | package DynaLoader;
22 |  |  |  |  |
23 |  |  |  |  | my ($module, $modlibname) = caller();
24 |  |  |  |  |
25 |  |  |  |  | if (@_) {
26 |  |  |  |  | $module = $_[0];
27 |  |  |  |  | } else {
28 |  |  |  |  | $_[0] = $module;
29 |  |  |  |  | }
30 |  |  |  |  |
31 |  |  |  |  | # work with static linking too
32 |  |  |  |  | my $boots = "$module\::bootstrap";
33 |  |  |  |  | goto &$boots if defined &$boots;
34 |  |  |  |  |
35 |  |  |  |  | goto \&XSLoader::bootstrap_inherit unless $module and defined &dl_load_file;
36 |  |  |  |  |
37 |  |  |  |  | my @modparts = split(/::/,$module);
38 |  |  |  |  | my $modfname = $modparts[-1];
39 |  |  |  |  |
40 |  |  |  |  | my $modpname = join('/',@modparts);
41 |  |  |  |  | my $c = @modparts;
42 |  |  |  |  | $modlibname =~ s,[\\/][^\\/]+$,, while $c--; # Q&D basename
43 |  |  |  |  | my $file = "$modlibname/auto/$modpname/$modfname.so";
44 |  |  |  |  |
45 |  |  |  |  | # print STDERR "XSLoader::load for $module ($file)\n" if $dl_debug;
46 |  |  |  |  |
47 |  |  |  |  | my $bs = $file;
48 |  |  |  |  | $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library
49 |  |  |  |  |
50 |  |  |  |  | if (-s $bs) { # only read file if it's not empty
51 |  |  |  |  | # print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug;
52 |  |  |  |  | eval { do $bs; };
53 |  |  |  |  | warn "$bs: $@\n" if $@;
54 |  |  |  |  | }
55 |  |  |  |  |
56 |  |  |  |  | goto \&XSLoader::bootstrap_inherit if not -f $file or -s $bs;
57 |  |  |  |  |
58 |  |  |  |  | my $bootname = "boot_$module";
59 |  |  |  |  | $bootname =~ s/\W/_/g;
60 |  |  |  |  | @DynaLoader::dl_require_symbols = ($bootname);
61 |  |  |  |  |
62 |  |  |  |  | my $boot_symbol_ref;
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
95 |  |  |  |  | return &$xs(@_);
96 |  |  |  |  | }
97 |  |  |  |  |
98 |  |  |  |  | sub bootstrap_inherit {
99 |  |  |  |  | require DynaLoader;
100 |  |  |  |  | goto \&DynaLoader::bootstrap_inherit;
101 |  |  |  |  | }
102 |  |  |  |  |
103 |  |  |  |  | 1;
104 |  |  |  |  |
105 |  |  |  |  |
106 |  |  |  |  | __END__
107 |  |  |  |  |
108 |  |  |  |  | =head1 NAME
109 |  |  |  |  |
110 |  |  |  |  | XSLoader - Dynamically load C libraries into Perl code
111 |  |  |  |  |
112 |  |  |  |  | =head1 VERSION
113 |  |  |  |  |
114 |  |  |  |  | Version 0.15
115 |  |  |  |  |
116 |  |  |  |  | =head1 SYNOPSIS
117 |  |  |  |  |
118 |  |  |  |  | package YourPackage;
119 |  |  |  |  | require XSLoader;
120 |  |  |  |  |
121 |  |  |  |  | XSLoader::load();
122 |  |  |  |  |
123 |  |  |  |  | =head1 DESCRIPTION
124 |  |  |  |  |
125 |  |  |  |  | This module defines a standard I<simplified> interface to the dynamic
126 |  |  |  |  | linking mechanisms available on many platforms. Its primary purpose is
127 |  |  |  |  | to implement cheap automatic dynamic loading of Perl modules.
128 |  |  |  |  |
129 |  |  |  |  | For a more complicated interface, see L<DynaLoader>. Many (most)
130 |  |  |  |  | features of C<DynaLoader> are not implemented in C<XSLoader>, like for
131 |  |  |  |  | example the C<dl_load_flags>, not honored by C<XSLoader>.
132 |  |  |  |  |
133 |  |  |  |  | =head2 Migration from C<DynaLoader>
134 |  |  |  |  |
135 |  |  |  |  | A 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 |  |  |  |  |
144 |  |  |  |  | Change 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 |  |  |  |  |
153 |  |  |  |  | In other words: replace C<require DynaLoader> by C<use XSLoader>, remove
154 |  |  |  |  | C<DynaLoader> from C<@ISA>, change C<bootstrap> by C<XSLoader::load>. Do not
155 |  |  |  |  | forget to quote the name of your package on the C<XSLoader::load> line,
156 |  |  |  |  | and add comma (C<,>) before the arguments (C<$VERSION> above).
157 |  |  |  |  |
158 |  |  |  |  | Of course, if C<@ISA> contained only C<DynaLoader>, there is no need to have
159 |  |  |  |  | the C<@ISA> assignment at all; moreover, if instead of C<our> one uses the
160 |  |  |  |  | more backward-compatible
161 |  |  |  |  |
162 |  |  |  |  | use vars qw($VERSION @ISA);
163 |  |  |  |  |
164 |  |  |  |  | one can remove this reference to C<@ISA> together with the C<@ISA> assignment.
165 |  |  |  |  |
166 |  |  |  |  | If no C<$VERSION> was specified on the C<bootstrap> line, the last line becomes
167 |  |  |  |  |
168 |  |  |  |  | XSLoader::load 'YourPackage';
169 |  |  |  |  |
170 |  |  |  |  | If the call to C<load> is from the YourPackage, then that can be further
171 |  |  |  |  | simplified to
172 |  |  |  |  |
173 |  |  |  |  | XSLoader::load();
174 |  |  |  |  |
175 |  |  |  |  | as C<load> will use C<caller> to determine the package.
176 |  |  |  |  |
177 |  |  |  |  | =head2 Backward compatible boilerplate
178 |  |  |  |  |
179 |  |  |  |  | If you want to have your cake and eat it too, you need a more complicated
180 |  |  |  |  | boilerplate.
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 |  |  |  |  |
197 |  |  |  |  | The parentheses about C<XSLoader::load()> arguments are needed since we replaced
198 |  |  |  |  | C<use XSLoader> by C<require>, so the compiler does not know that a function
199 |  |  |  |  | C<XSLoader::load()> is present.
200 |  |  |  |  |
201 |  |  |  |  | This boilerplate uses the low-overhead C<XSLoader> if present; if used with
202 |  |  |  |  | an antic Perl which has no C<XSLoader>, it falls back to using C<DynaLoader>.
203 |  |  |  |  |
204 |  |  |  |  | =head1 Order of initialization: early load()
205 |  |  |  |  |
206 |  |  |  |  | I<Skip this section if the XSUB functions are supposed to be called from other
207 |  |  |  |  | modules only; read it only if you call your XSUBs from the code in your module,
208 |  |  |  |  | or have a C<BOOT:> section in your XS file (see L<perlxs/"The BOOT: Keyword">).
209 |  |  |  |  | What is described here is equally applicable to the L<DynaLoader|DynaLoader>
210 |  |  |  |  | interface.>
211 |  |  |  |  |
212 |  |  |  |  | A sufficiently complicated module using XS would have both Perl code (defined
213 |  |  |  |  | in F<YourPackage.pm>) and XS code (defined in F<YourPackage.xs>). If this
214 |  |  |  |  | Perl code makes calls into this XS code, and/or this XS code makes calls to
215 |  |  |  |  | the Perl code, one should be careful with the order of initialization.
216 |  |  |  |  |
217 |  |  |  |  | The call to C<XSLoader::load()> (or C<bootstrap()>) calls the module's
218 |  |  |  |  | bootstrap code. For modules build by F<xsubpp> (nearly all modules) this
219 |  |  |  |  | has three side effects:
220 |  |  |  |  |
221 |  |  |  |  | =over
222 |  |  |  |  |
223 |  |  |  |  | =item *
224 |  |  |  |  |
225 |  |  |  |  | A 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
227 |  |  |  |  | is used for the check. If not specified, it defaults to
228 |  |  |  |  | C<$XS_VERSION // $VERSION> (in the module's namespace)
229 |  |  |  |  |
230 |  |  |  |  | =item *
231 |  |  |  |  |
232 |  |  |  |  | the XSUBs are made accessible from Perl
233 |  |  |  |  |
234 |  |  |  |  | =item *
235 |  |  |  |  |
236 |  |  |  |  | if a C<BOOT:> section was present in the F<.xs> file, the code there is called.
237 |  |  |  |  |
238 |  |  |  |  | =back
239 |  |  |  |  |
240 |  |  |  |  | Consequently, if the code in the F<.pm> file makes calls to these XSUBs, it is
241 |  |  |  |  | convenient to have XSUBs installed before the Perl code is defined; for
242 |  |  |  |  | example, this makes prototypes for XSUBs visible to this Perl code.
243 |  |  |  |  | Alternatively, if the C<BOOT:> section makes calls to Perl functions (or
244 |  |  |  |  | uses Perl variables) defined in the F<.pm> file, they must be defined prior to
245 |  |  |  |  | the call to C<XSLoader::load()> (or C<bootstrap()>).
246 |  |  |  |  |
247 |  |  |  |  | The first situation being much more frequent, it makes sense to rewrite the
248 |  |  |  |  | boilerplate 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 |  |  |  |  |
267 |  |  |  |  | If the interdependence of your C<BOOT:> section and Perl code is
268 |  |  |  |  | more complicated than this (e.g., the C<BOOT:> section makes calls to Perl
269 |  |  |  |  | functions which make calls to XSUBs with prototypes), get rid of the C<BOOT:>
270 |  |  |  |  | section altogether. Replace it with a function C<onBOOT()>, and call it like
271 |  |  |  |  | this:
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 |  |  |  |  |
297 |  |  |  |  | B<(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 |  |  |  |  |
301 |  |  |  |  | B<(F)> The loading or initialisation of the extension module failed.
302 |  |  |  |  | The detailed error follows.
303 |  |  |  |  |
304 |  |  |  |  | =item C<Undefined symbols present after loading %s: %s>
305 |  |  |  |  |
306 |  |  |  |  | B<(W)> As the message says, some symbols stay undefined although the
307 |  |  |  |  | extension module was correctly loaded and initialised. The list of undefined
308 |  |  |  |  | symbols follows.
309 |  |  |  |  |
310 |  |  |  |  | =back
311 |  |  |  |  |
312 |  |  |  |  | =head1 LIMITATIONS
313 |  |  |  |  |
314 |  |  |  |  | To reduce the overhead as much as possible, only one possible location
315 |  |  |  |  | is checked to find the extension DLL (this location is where C<make install>
316 |  |  |  |  | would put the DLL). If not found, the search for the DLL is transparently
317 |  |  |  |  | delegated to C<DynaLoader>, which looks for the DLL along the C<@INC> list.
318 |  |  |  |  |
319 |  |  |  |  | In particular, this is applicable to the structure of C<@INC> used for testing
320 |  |  |  |  | not-yet-installed extensions. This means that running uninstalled extensions
321 |  |  |  |  | may have much more overhead than running the same extensions after
322 |  |  |  |  | C<make install>.
323 |  |  |  |  |
324 |  |  |  |  |
325 |  |  |  |  | =head1 KNOWN BUGS
326 |  |  |  |  |
327 |  |  |  |  | The new simpler way to call C<XSLoader::load()> with no arguments at all
328 |  |  |  |  | does not work on Perl 5.8.4 and 5.8.5.
329 |  |  |  |  |
330 |  |  |  |  |
331 |  |  |  |  | =head1 BUGS
332 |  |  |  |  |
333 |  |  |  |  | Please report any bugs or feature requests via the perlbug(1) utility.
334 |  |  |  |  |
335 |  |  |  |  |
336 |  |  |  |  | =head1 SEE ALSO
337 |  |  |  |  |
338 |  |  |  |  | L<DynaLoader>
339 |  |  |  |  |
340 |  |  |  |  |
341 |  |  |  |  | =head1 AUTHORS
342 |  |  |  |  |
343 |  |  |  |  | Ilya Zakharevich originally extracted C<XSLoader> from C<DynaLoader>.
344 |  |  |  |  |
345 |  |  |  |  | CPAN version is currently maintained by SE<eacute>bastien Aperghis-Tramoni
346 |  |  |  |  | E<lt>sebastien@aperghis.netE<gt>.
347 |  |  |  |  |
348 |  |  |  |  | Previous maintainer was Michael G Schwern <schwern@pobox.com>.
349 |  |  |  |  |
350 |  |  |  |  |
351 |  |  |  |  | =head1 COPYRIGHT & LICENSE
352 |  |  |  |  |
353 |  |  |  |  | Copyright (C) 1990-2011 by Larry Wall and others.
354 |  |  |  |  |
355 |  |  |  |  | This program is free software; you can redistribute it and/or modify
356 |  |  |  |  | it under the same terms as Perl itself.
357 |  |  |  |  |
358 |  |  |  |  | =cut