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