File | /usr/local/lib/perl5/5.10.1/darwin-2level/XSLoader.pm |
Statements Executed | 3 |
Statement Execution Time | 127µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
21 | 21 | 21 | 5.92ms | 6.51ms | load | XSLoader::
0 | 0 | 0 | 0s | 0s | bootstrap_inherit | XSLoader::
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.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 | |||||
14 | package 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 | ||||
18 | boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) && | ||||
19 | !defined(&dl_error); | ||||
20 | package XSLoader; | ||||
21 | |||||
22 | # spent 6.51ms (5.92+590µs) within XSLoader::load which was called 21 times, avg 310µs/call:
# once (413µs+590µs) by JSON::BEGIN@2 at line 1456 of JSON/XS.pm
# once (623µs+0s) by SimpleDB::Class::Cache::BEGIN@31 at line 29 of Memcached/libmemcached.pm
# once (528µs+0s) by UUID::Tiny::BEGIN@10 at line 36 of POSIX.pm
# once (422µs+0s) by IO::Uncompress::RawInflate::BEGIN@8 at line 91 of Compress/Raw/Zlib.pm
# once (357µs+0s) by IO::Socket::BEGIN@12 at line 412 of Socket.pm
# once (292µs+0s) by Moose::Exporter::BEGIN@11 at line 37 of Class/MOP.pm
# once (286µs+0s) by Module::Find::BEGIN@8 at line 248 of Cwd.pm
# once (277µs+0s) by Variable::Magic::BEGIN@204 at line 206 of Variable/Magic.pm
# once (268µs+0s) by Fcntl::BEGIN@214 at line 215 of Fcntl.pm
# once (266µs+0s) by UUID::Tiny::BEGIN@7 at line 24 of Digest/MD5.pm
# once (255µs+0s) by Test::Deep::Cache::Simple::BEGIN@7 at line 27 of List/Util.pm
# once (235µs+0s) by SimpleDB::Client::BEGIN@52 at line 13 of MIME/Base64.pm
# once (234µs+0s) by Params::Validate::BEGIN@5 at line 7 of Params/ValidateXS.pm
# once (231µs+0s) by Test::Deep::BEGIN@22 at line 36 of Data/Dumper.pm
# once (211µs+0s) by IO::Handle::BEGIN@266 at line 11 of IO.pm
# once (209µs+0s) by DateTime::BEGIN@13 at line 21 of DateTime.pm
# once (206µs+0s) by Devel::GlobalDestruction::BEGIN@10 at line 17 of Devel/GlobalDestruction.pm
# once (172µs+0s) by File::GlobMapper::BEGIN@10 at line 96 of File/Glob.pm
# once (170µs+0s) by Sub::Identify::BEGIN@6 at line 17 of Sub/Identify.pm
# once (162µs+0s) by MRO::Compat::BEGIN@10 at line 41 of mro.pm
# once (102µs+0s) by Moose::BEGIN@14 at line 19 of Moose/Exporter.pm | ||||
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 | ||||
97 | 3 | 127µs | 1 | 28µs | return &$xs(@_); # spent 28µs making 1 call to attributes::import |
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. | ||||
106 | sub 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 | |||||
117 | 1; | ||||
118 | |||||
119 | |||||
120 | __END__ | ||||
121 | |||||
122 | =head1 NAME | ||||
123 | |||||
124 | XSLoader - Dynamically load C libraries into Perl code | ||||
125 | |||||
126 | =head1 VERSION | ||||
127 | |||||
128 | Version 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 | |||||
139 | This module defines a standard I<simplified> interface to the dynamic | ||||
140 | linking mechanisms available on many platforms. Its primary purpose is | ||||
141 | to implement cheap automatic dynamic loading of Perl modules. | ||||
142 | |||||
143 | For a more complicated interface, see L<DynaLoader>. Many (most) | ||||
144 | features of C<DynaLoader> are not implemented in C<XSLoader>, like for | ||||
145 | example the C<dl_load_flags>, not honored by C<XSLoader>. | ||||
146 | |||||
147 | =head2 Migration from C<DynaLoader> | ||||
148 | |||||
149 | A 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 | |||||
158 | Change 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 | |||||
167 | In other words: replace C<require DynaLoader> by C<use XSLoader>, remove | ||||
168 | C<DynaLoader> from C<@ISA>, change C<bootstrap> by C<XSLoader::load>. Do not | ||||
169 | forget to quote the name of your package on the C<XSLoader::load> line, | ||||
170 | and add comma (C<,>) before the arguments (C<$VERSION> above). | ||||
171 | |||||
172 | Of course, if C<@ISA> contained only C<DynaLoader>, there is no need to have | ||||
173 | the C<@ISA> assignment at all; moreover, if instead of C<our> one uses the | ||||
174 | more backward-compatible | ||||
175 | |||||
176 | use vars qw($VERSION @ISA); | ||||
177 | |||||
178 | one can remove this reference to C<@ISA> together with the C<@ISA> assignment. | ||||
179 | |||||
180 | If 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 | |||||
186 | If you want to have your cake and eat it too, you need a more complicated | ||||
187 | boilerplate. | ||||
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 | |||||
204 | The parentheses about C<XSLoader::load()> arguments are needed since we replaced | ||||
205 | C<use XSLoader> by C<require>, so the compiler does not know that a function | ||||
206 | C<XSLoader::load()> is present. | ||||
207 | |||||
208 | This boilerplate uses the low-overhead C<XSLoader> if present; if used with | ||||
209 | an antic Perl which has no C<XSLoader>, it falls back to using C<DynaLoader>. | ||||
210 | |||||
211 | =head1 Order of initialization: early load() | ||||
212 | |||||
213 | I<Skip this section if the XSUB functions are supposed to be called from other | ||||
214 | modules only; read it only if you call your XSUBs from the code in your module, | ||||
215 | or have a C<BOOT:> section in your XS file (see L<perlxs/"The BOOT: Keyword">). | ||||
216 | What is described here is equally applicable to the L<DynaLoader|DynaLoader> | ||||
217 | interface.> | ||||
218 | |||||
219 | A sufficiently complicated module using XS would have both Perl code (defined | ||||
220 | in F<YourPackage.pm>) and XS code (defined in F<YourPackage.xs>). If this | ||||
221 | Perl code makes calls into this XS code, and/or this XS code makes calls to | ||||
222 | the Perl code, one should be careful with the order of initialization. | ||||
223 | |||||
224 | The call to C<XSLoader::load()> (or C<bootstrap()>) has three side effects: | ||||
225 | |||||
226 | =over | ||||
227 | |||||
228 | =item * | ||||
229 | |||||
230 | if C<$VERSION> was specified, a sanity check is done to ensure that the | ||||
231 | versions of the F<.pm> and the (compiled) F<.xs> parts are compatible; | ||||
232 | |||||
233 | =item * | ||||
234 | |||||
235 | the XSUBs are made accessible from Perl; | ||||
236 | |||||
237 | =item * | ||||
238 | |||||
239 | if a C<BOOT:> section was present in the F<.xs> file, the code there is called. | ||||
240 | |||||
241 | =back | ||||
242 | |||||
243 | Consequently, if the code in the F<.pm> file makes calls to these XSUBs, it is | ||||
244 | convenient to have XSUBs installed before the Perl code is defined; for | ||||
245 | example, this makes prototypes for XSUBs visible to this Perl code. | ||||
246 | Alternatively, if the C<BOOT:> section makes calls to Perl functions (or | ||||
247 | uses Perl variables) defined in the F<.pm> file, they must be defined prior to | ||||
248 | the call to C<XSLoader::load()> (or C<bootstrap()>). | ||||
249 | |||||
250 | The first situation being much more frequent, it makes sense to rewrite the | ||||
251 | boilerplate 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 | |||||
270 | If the interdependence of your C<BOOT:> section and Perl code is | ||||
271 | more complicated than this (e.g., the C<BOOT:> section makes calls to Perl | ||||
272 | functions which make calls to XSUBs with prototypes), get rid of the C<BOOT:> | ||||
273 | section altogether. Replace it with a function C<onBOOT()>, and call it like | ||||
274 | this: | ||||
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 | |||||
300 | B<(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 | |||||
304 | B<(F)> The loading or initialisation of the extension module failed. | ||||
305 | The detailed error follows. | ||||
306 | |||||
307 | =item C<Undefined symbols present after loading %s: %s> | ||||
308 | |||||
309 | B<(W)> As the message says, some symbols stay undefined although the | ||||
310 | extension module was correctly loaded and initialised. The list of undefined | ||||
311 | symbols follows. | ||||
312 | |||||
313 | =item C<XSLoader::load('Your::Module', $Your::Module::VERSION)> | ||||
314 | |||||
315 | B<(F)> You tried to invoke C<load()> without any argument. You must supply | ||||
316 | a module name, and optionally its version. | ||||
317 | |||||
318 | =back | ||||
319 | |||||
320 | |||||
321 | =head1 LIMITATIONS | ||||
322 | |||||
323 | To reduce the overhead as much as possible, only one possible location | ||||
324 | is checked to find the extension DLL (this location is where C<make install> | ||||
325 | would put the DLL). If not found, the search for the DLL is transparently | ||||
326 | delegated to C<DynaLoader>, which looks for the DLL along the C<@INC> list. | ||||
327 | |||||
328 | In particular, this is applicable to the structure of C<@INC> used for testing | ||||
329 | not-yet-installed extensions. This means that running uninstalled extensions | ||||
330 | may have much more overhead than running the same extensions after | ||||
331 | C<make install>. | ||||
332 | |||||
333 | |||||
334 | =head1 BUGS | ||||
335 | |||||
336 | Please report any bugs or feature requests via the perlbug(1) utility. | ||||
337 | |||||
338 | |||||
339 | =head1 SEE ALSO | ||||
340 | |||||
341 | L<DynaLoader> | ||||
342 | |||||
343 | |||||
344 | =head1 AUTHORS | ||||
345 | |||||
346 | Ilya Zakharevich originally extracted C<XSLoader> from C<DynaLoader>. | ||||
347 | |||||
348 | CPAN version is currently maintained by SE<eacute>bastien Aperghis-Tramoni | ||||
349 | E<lt>sebastien@aperghis.netE<gt>. | ||||
350 | |||||
351 | Previous maintainer was Michael G Schwern <schwern@pobox.com>. | ||||
352 | |||||
353 | |||||
354 | =head1 COPYRIGHT & LICENSE | ||||
355 | |||||
356 | Copyright (C) 1990-2007 by Larry Wall and others. | ||||
357 | |||||
358 | This program is free software; you can redistribute it and/or modify | ||||
359 | it under the same terms as Perl itself. | ||||
360 | |||||
361 | =cut |