← Index
NYTProf Performance Profile   « line view »
For t/bug-md-11.t
  Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

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