1N/Ause Config;
1N/A
1N/Asub to_string {
1N/A my ($value) = @_;
1N/A $value =~ s/\\/\\\\/g;
1N/A $value =~ s/'/\\'/g;
1N/A return "'$value'";
1N/A}
1N/A
1N/Aunlink "DynaLoader.pm" if -f "DynaLoader.pm";
1N/Aopen OUT, ">DynaLoader.pm" or die $!;
1N/Aprint OUT <<'EOT';
1N/A
1N/A# Generated from DynaLoader.pm.PL
1N/A
1N/Apackage DynaLoader;
1N/A
1N/A# And Gandalf said: 'Many folk like to know beforehand what is to
1N/A# be set on the table; but those who have laboured to prepare the
1N/A# feast like to keep their secret; for wonder makes the words of
1N/A# praise louder.'
1N/A
1N/A# (Quote from Tolkien suggested by Anno Siegel.)
1N/A#
1N/A# See pod text at end of file for documentation.
1N/A# See also ext/DynaLoader/README in source tree for other information.
1N/A#
1N/A# Tim.Bunce@ig.co.uk, August 1994
1N/A
1N/Ause vars qw($VERSION *AUTOLOAD);
1N/A
1N/A$VERSION = '1.05'; # avoid typo warning
1N/A
1N/Arequire AutoLoader;
1N/A*AUTOLOAD = \&AutoLoader::AUTOLOAD;
1N/A
1N/Ause Config;
1N/A
1N/A# The following require can't be removed during maintenance
1N/A# releases, sadly, because of the risk of buggy code that does
1N/A# require Carp; Carp::croak "..."; without brackets dying
1N/A# if Carp hasn't been loaded in earlier compile time. :-(
1N/A# We'll let those bugs get found on the development track.
1N/Arequire Carp if $] < 5.00450;
1N/A
1N/A# enable debug/trace messages from DynaLoader perl code
1N/A$dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
1N/A
1N/A#
1N/A# Flags to alter dl_load_file behaviour. Assigned bits:
1N/A# 0x01 make symbols available for linking later dl_load_file's.
1N/A# (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
1N/A# (ignored under VMS; effect is built-in to image linking)
1N/A#
1N/A# This is called as a class method $module->dl_load_flags. The
1N/A# definition here will be inherited and result on "default" loading
1N/A# behaviour unless a sub-class of DynaLoader defines its own version.
1N/A#
1N/A
1N/Asub dl_load_flags { 0x00 }
1N/A
1N/A# ($dl_dlext, $dlsrc)
1N/A# = @Config::Config{'dlext', 'dlsrc'};
1N/AEOT
1N/A
1N/Aprint OUT " (\$dl_dlext, \$dlsrc) = (",
1N/A to_string($Config::Config{'dlext'}), ",",
1N/A to_string($Config::Config{'dlsrc'}), ")\n;" ;
1N/A
1N/Aprint OUT <<'EOT';
1N/A
1N/A# Some systems need special handling to expand file specifications
1N/A# (VMS support by Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU>)
1N/A# See dl_expandspec() for more details. Should be harmless but
1N/A# inefficient to define on systems that don't need it.
1N/A$Is_VMS = $^O eq 'VMS';
1N/A$do_expand = $Is_VMS;
1N/A$Is_MacOS = $^O eq 'MacOS';
1N/A
1N/Amy $Mac_FS;
1N/A$Mac_FS = eval { require Mac::FileSpec::Unixish } if $Is_MacOS;
1N/A
1N/A@dl_shared_objects = (); # shared objects for symbols we have
1N/A@dl_require_symbols = (); # names of symbols we need
1N/A@dl_resolve_using = (); # names of files to link with
1N/A@dl_library_path = (); # path to look for files
1N/A
1N/A#XSLoader.pm may have added elements before we were required
1N/A#@dl_librefs = (); # things we have loaded
1N/A#@dl_modules = (); # Modules we have loaded
1N/A
1N/A# This is a fix to support DLD's unfortunate desire to relink -lc
1N/A@dl_resolve_using = dl_findfile('-lc') if $dlsrc eq "dl_dld.xs";
1N/A
1N/AEOT
1N/A
1N/Amy $cfg_dl_library_path = <<'EOT';
1N/Apush(@dl_library_path, split(' ', $Config::Config{libpth}));
1N/AEOT
1N/A
1N/Asub dquoted_comma_list {
1N/A join(", ", map {qq("$_")} @_);
1N/A}
1N/A
1N/Aif ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
1N/A eval $cfg_dl_library_path;
1N/A if (!$ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
1N/A my $dl_library_path = dquoted_comma_list(@dl_library_path);
1N/A print OUT <<EOT;
1N/A# The below \@dl_library_path has been expanded (%Config) in Perl build time.
1N/A
1N/A\@dl_library_path = ($dl_library_path);
1N/A
1N/AEOT
1N/A }
1N/A}
1N/Aelse {
1N/A print OUT <<EOT;
1N/A# Initialise \@dl_library_path with the 'standard' library path
1N/A# for this platform as determined by Configure.
1N/A
1N/A$cfg_dl_library_path
1N/A
1N/AEOT
1N/A}
1N/A
1N/Amy $ldlibpthname;
1N/Amy $ldlibpthname_defined;
1N/Amy $pthsep;
1N/A
1N/Aif ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
1N/A $ldlibpthname = $Config::Config{ldlibpthname};
1N/A $ldlibpthname_defined = defined $Config::Config{ldlibpthname} ? 1 : 0;
1N/A $pthsep = $Config::Config{path_sep};
1N/A}
1N/Aelse {
1N/A $ldlibpthname = q($Config::Config{ldlibpthname});
1N/A $ldlibpthname_defined = q(defined $Config::Config{ldlibpthname});
1N/A $pthsep = q($Config::Config{path_sep});
1N/A print OUT <<EOT;
1N/Amy \$ldlibpthname = $ldlibpthname;
1N/Amy \$ldlibpthname_defined = $ldlibpthname_defined;
1N/Amy \$pthsep = $pthsep;
1N/A
1N/AEOT
1N/A}
1N/A
1N/Amy $env_dl_library_path = <<'EOT';
1N/Aif ($ldlibpthname_defined &&
1N/A exists $ENV{$ldlibpthname}) {
1N/A push(@dl_library_path, split(/$pthsep/, $ENV{$ldlibpthname}));
1N/A}
1N/A
1N/A# E.g. HP-UX supports both its native SHLIB_PATH *and* LD_LIBRARY_PATH.
1N/A
1N/Aif ($ldlibpthname_defined &&
1N/A $ldlibpthname ne 'LD_LIBRARY_PATH' &&
1N/A exists $ENV{LD_LIBRARY_PATH}) {
1N/A push(@dl_library_path, split(/$pthsep/, $ENV{LD_LIBRARY_PATH}));
1N/A}
1N/AEOT
1N/A
1N/Aif ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS} && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
1N/A eval $env_dl_library_path;
1N/A}
1N/Aelse {
1N/A print OUT <<EOT;
1N/A# Add to \@dl_library_path any extra directories we can gather from environment
1N/A# during runtime.
1N/A
1N/A$env_dl_library_path
1N/A
1N/AEOT
1N/A}
1N/A
1N/Aif ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS} && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
1N/A my $dl_library_path = dquoted_comma_list(@dl_library_path);
1N/A print OUT <<EOT;
1N/A# The below \@dl_library_path has been expanded (%Config, %ENV)
1N/A# in Perl build time.
1N/A
1N/A\@dl_library_path = ($dl_library_path);
1N/A
1N/AEOT
1N/A}
1N/A
1N/Aprint OUT <<'EOT';
1N/A# No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
1N/A# NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB
1N/Aboot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
1N/A !defined(&dl_error);
1N/A
1N/Aif ($dl_debug) {
1N/A print STDERR "DynaLoader.pm loaded (@INC, @dl_library_path)\n";
1N/A print STDERR "DynaLoader not linked into this perl\n"
1N/A unless defined(&boot_DynaLoader);
1N/A}
1N/A
1N/A1; # End of main code
1N/A
1N/A
1N/Asub croak { require Carp; Carp::croak(@_) }
1N/A
1N/Asub bootstrap_inherit {
1N/A my $module = $_[0];
1N/A local *isa = *{"$module\::ISA"};
1N/A local @isa = (@isa, 'DynaLoader');
1N/A # Cannot goto due to delocalization. Will report errors on a wrong line?
1N/A bootstrap(@_);
1N/A}
1N/A
1N/A# The bootstrap function cannot be autoloaded (without complications)
1N/A# so we define it here:
1N/A
1N/Asub bootstrap {
1N/A # use local vars to enable $module.bs script to edit values
1N/A local(@args) = @_;
1N/A local($module) = $args[0];
1N/A local(@dirs, $file);
1N/A
1N/A unless ($module) {
1N/A require Carp;
1N/A Carp::confess("Usage: DynaLoader::bootstrap(module)");
1N/A }
1N/A
1N/A # A common error on platforms which don't support dynamic loading.
1N/A # Since it's fatal and potentially confusing we give a detailed message.
1N/A croak("Can't load module $module, dynamic loading not available in this perl.\n".
1N/A " (You may need to build a new perl executable which either supports\n".
1N/A " dynamic loading or has the $module module statically linked into it.)\n")
1N/A unless defined(&dl_load_file);
1N/A
1N/AEOT
1N/A
1N/Aprint OUT <<'EOT' if $^O eq 'os2';
1N/A # Can dynaload, but cannot dynaload Perl modules...
1N/A die 'Dynaloaded Perl modules are not available in this build of Perl' if $OS2::is_static;
1N/A
1N/AEOT
1N/A
1N/Aprint OUT <<'EOT';
1N/A my @modparts = split(/::/,$module);
1N/A my $modfname = $modparts[-1];
1N/A
1N/A # Some systems have restrictions on files names for DLL's etc.
1N/A # mod2fname returns appropriate file base name (typically truncated)
1N/A # It may also edit @modparts if required.
1N/A $modfname = &mod2fname(\@modparts) if defined &mod2fname;
1N/A
1N/A # Truncate the module name to 8.3 format for NetWare
1N/A if (($^O eq 'NetWare') && (length($modfname) > 8)) {
1N/A $modfname = substr($modfname, 0, 8);
1N/A }
1N/A
1N/A my $modpname = join(($Is_MacOS ? ':' : '/'),@modparts);
1N/A
1N/A print STDERR "DynaLoader::bootstrap for $module ",
1N/A ($Is_MacOS
1N/A ? "(:auto:$modpname:$modfname.$dl_dlext)\n" :
1N/A "(auto/$modpname/$modfname.$dl_dlext)\n")
1N/A if $dl_debug;
1N/A
1N/A foreach (@INC) {
1N/A chop($_ = VMS::Filespec::unixpath($_)) if $Is_VMS;
1N/A my $dir;
1N/A if ($Is_MacOS) {
1N/A my $path = $_;
1N/A if ($Mac_FS && ! -d $path) {
1N/A $path = Mac::FileSpec::Unixish::nativize($path);
1N/A }
1N/A $path .= ":" unless /:$/;
1N/A $dir = "${path}auto:$modpname";
1N/A } else {
1N/A $dir = "$_/auto/$modpname";
1N/A }
1N/A
1N/A next unless -d $dir; # skip over uninteresting directories
1N/A
1N/A # check for common cases to avoid autoload of dl_findfile
1N/A my $try = $Is_MacOS ? "$dir:$modfname.$dl_dlext" : "$dir/$modfname.$dl_dlext";
1N/A last if $file = ($do_expand) ? dl_expandspec($try) : ((-f $try) && $try);
1N/A
1N/A # no luck here, save dir for possible later dl_findfile search
1N/A push @dirs, $dir;
1N/A }
1N/A # last resort, let dl_findfile have a go in all known locations
1N/A $file = dl_findfile(map("-L$_",@dirs,@INC), $modfname) unless $file;
1N/A
1N/A croak("Can't locate loadable object for module $module in \@INC (\@INC contains: @INC)")
1N/A unless $file; # wording similar to error from 'require'
1N/A
1N/A $file = uc($file) if $Is_VMS && $Config::Config{d_vms_case_sensitive_symbols};
1N/A my $bootname = "boot_$module";
1N/A $bootname =~ s/\W/_/g;
1N/A @dl_require_symbols = ($bootname);
1N/A
1N/A # Execute optional '.bootstrap' perl script for this module.
1N/A # The .bs file can be used to configure @dl_resolve_using etc to
1N/A # match the needs of the individual module on this architecture.
1N/A my $bs = $file;
1N/A $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library
1N/A if (-s $bs) { # only read file if it's not empty
1N/A print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug;
1N/A eval { do $bs; };
1N/A warn "$bs: $@\n" if $@;
1N/A }
1N/A
1N/A my $boot_symbol_ref;
1N/A
1N/A if ($^O eq 'darwin') {
1N/A if ($boot_symbol_ref = dl_find_symbol(0, $bootname)) {
1N/A goto boot; #extension library has already been loaded, e.g. darwin
1N/A }
1N/A }
1N/A
1N/A # Many dynamic extension loading problems will appear to come from
1N/A # this section of code: XYZ failed at line 123 of DynaLoader.pm.
1N/A # Often these errors are actually occurring in the initialisation
1N/A # C code of the extension XS file. Perl reports the error as being
1N/A # in this perl code simply because this was the last perl code
1N/A # it executed.
1N/A
1N/A my $libref = dl_load_file($file, $module->dl_load_flags) or
1N/A croak("Can't load '$file' for module $module: ".dl_error());
1N/A
1N/A push(@dl_librefs,$libref); # record loaded object
1N/A
1N/A my @unresolved = dl_undef_symbols();
1N/A if (@unresolved) {
1N/A require Carp;
1N/A Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
1N/A }
1N/A
1N/A $boot_symbol_ref = dl_find_symbol($libref, $bootname) or
1N/A croak("Can't find '$bootname' symbol in $file\n");
1N/A
1N/A push(@dl_modules, $module); # record loaded module
1N/A
1N/A boot:
1N/A my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
1N/A
1N/A # See comment block above
1N/A
1N/A push(@dl_shared_objects, $file); # record files loaded
1N/A
1N/A &$xs(@args);
1N/A}
1N/A
1N/A
1N/A#sub _check_file { # private utility to handle dl_expandspec vs -f tests
1N/A# my($file) = @_;
1N/A# return $file if (!$do_expand && -f $file); # the common case
1N/A# return $file if ( $do_expand && ($file=dl_expandspec($file)));
1N/A# return undef;
1N/A#}
1N/A
1N/A
1N/A# Let autosplit and the autoloader deal with these functions:
1N/A__END__
1N/A
1N/A
1N/Asub dl_findfile {
1N/A # Read ext/DynaLoader/DynaLoader.doc for detailed information.
1N/A # This function does not automatically consider the architecture
1N/A # or the perl library auto directories.
1N/A my (@args) = @_;
1N/A my (@dirs, $dir); # which directories to search
1N/A my (@found); # full paths to real files we have found
1N/AEOT
1N/A
1N/Aprint OUT ' my $dl_ext= ' . to_string($Config::Config{'dlext'}) .
1N/A "; # \$Config::Config{'dlext'} suffix for perl extensions\n";
1N/Aprint OUT ' my $dl_so = ' . to_string($Config::Config{'so'}) .
1N/A "; # \$Config::Config{'so'} suffix for shared libraries\n";
1N/A
1N/Aprint OUT <<'EOT';
1N/A
1N/A print STDERR "dl_findfile(@args)\n" if $dl_debug;
1N/A
1N/A # accumulate directories but process files as they appear
1N/A arg: foreach(@args) {
1N/A # Special fast case: full filepath requires no search
1N/A if ($Is_VMS && m%[:>/\]]% && -f $_) {
1N/A push(@found,dl_expandspec(VMS::Filespec::vmsify($_)));
1N/A last arg unless wantarray;
1N/A next;
1N/A }
1N/A elsif ($Is_MacOS) {
1N/A if (m/:/ && -f $_) {
1N/A push(@found,$_);
1N/A last arg unless wantarray;
1N/A }
1N/A }
1N/A elsif (m:/: && -f $_ && !$do_expand) {
1N/A push(@found,$_);
1N/A last arg unless wantarray;
1N/A next;
1N/A }
1N/A
1N/A # Deal with directories first:
1N/A # Using a -L prefix is the preferred option (faster and more robust)
1N/A if (m:^-L:) { s/^-L//; push(@dirs, $_); next; }
1N/A
1N/A if ($Is_MacOS) {
1N/A # Otherwise we try to try to spot directories by a heuristic
1N/A # (this is a more complicated issue than it first appears)
1N/A if (m/:/ && -d $_) { push(@dirs, $_); next; }
1N/A # Only files should get this far...
1N/A my(@names, $name); # what filenames to look for
1N/A s/^-l//;
1N/A push(@names, $_);
1N/A foreach $dir (@dirs, @dl_library_path) {
1N/A next unless -d $dir;
1N/A $dir =~ s/^([^:]+)$/:$1/;
1N/A $dir =~ s/:$//;
1N/A foreach $name (@names) {
1N/A my($file) = "$dir:$name";
1N/A print STDERR " checking in $dir for $name\n" if $dl_debug;
1N/A if (-f $file) {
1N/A push(@found, $file);
1N/A next arg; # no need to look any further
1N/A }
1N/A }
1N/A }
1N/A next;
1N/A }
1N/A
1N/A # Otherwise we try to try to spot directories by a heuristic
1N/A # (this is a more complicated issue than it first appears)
1N/A if (m:/: && -d $_) { push(@dirs, $_); next; }
1N/A
1N/A # VMS: we may be using native VMS directory syntax instead of
1N/A # Unix emulation, so check this as well
1N/A if ($Is_VMS && /[:>\]]/ && -d $_) { push(@dirs, $_); next; }
1N/A
1N/A # Only files should get this far...
1N/A my(@names, $name); # what filenames to look for
1N/A if (m:-l: ) { # convert -lname to appropriate library name
1N/A s/-l//;
1N/A push(@names,"lib$_.$dl_so");
1N/A push(@names,"lib$_.a");
1N/A } else { # Umm, a bare name. Try various alternatives:
1N/A # these should be ordered with the most likely first
1N/A push(@names,"$_.$dl_ext") unless m/\.$dl_ext$/o;
1N/A push(@names,"$_.$dl_so") unless m/\.$dl_so$/o;
1N/A push(@names,"lib$_.$dl_so") unless m:/:;
1N/A push(@names,"$_.a") if !m/\.a$/ and $dlsrc eq "dl_dld.xs";
1N/A push(@names, $_);
1N/A }
1N/A foreach $dir (@dirs, @dl_library_path) {
1N/A next unless -d $dir;
1N/A chop($dir = VMS::Filespec::unixpath($dir)) if $Is_VMS;
1N/A foreach $name (@names) {
1N/A my($file) = "$dir/$name";
1N/A print STDERR " checking in $dir for $name\n" if $dl_debug;
1N/A $file = ($do_expand) ? dl_expandspec($file) : (-f $file && $file);
1N/A #$file = _check_file($file);
1N/A if ($file) {
1N/A push(@found, $file);
1N/A next arg; # no need to look any further
1N/A }
1N/A }
1N/A }
1N/A }
1N/A if ($dl_debug) {
1N/A foreach(@dirs) {
1N/A print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
1N/A }
1N/A print STDERR "dl_findfile found: @found\n";
1N/A }
1N/A return $found[0] unless wantarray;
1N/A @found;
1N/A}
1N/A
1N/A
1N/Asub dl_expandspec {
1N/A my($spec) = @_;
1N/A # Optional function invoked if DynaLoader.pm sets $do_expand.
1N/A # Most systems do not require or use this function.
1N/A # Some systems may implement it in the dl_*.xs file in which case
1N/A # this autoload version will not be called but is harmless.
1N/A
1N/A # This function is designed to deal with systems which treat some
1N/A # 'filenames' in a special way. For example VMS 'Logical Names'
1N/A # (something like unix environment variables - but different).
1N/A # This function should recognise such names and expand them into
1N/A # full file paths.
1N/A # Must return undef if $spec is invalid or file does not exist.
1N/A
1N/A my $file = $spec; # default output to input
1N/A
1N/A if ($Is_VMS) { # dl_expandspec should be defined in dl_vms.xs
1N/A require Carp;
1N/A Carp::croak("dl_expandspec: should be defined in XS file!\n");
1N/A } else {
1N/A return undef unless -f $file;
1N/A }
1N/A print STDERR "dl_expandspec($spec) => $file\n" if $dl_debug;
1N/A $file;
1N/A}
1N/A
1N/Asub dl_find_symbol_anywhere
1N/A{
1N/A my $sym = shift;
1N/A my $libref;
1N/A foreach $libref (@dl_librefs) {
1N/A my $symref = dl_find_symbol($libref,$sym);
1N/A return $symref if $symref;
1N/A }
1N/A return undef;
1N/A}
1N/A
1N/A=head1 NAME
1N/A
1N/ADynaLoader - Dynamically load C libraries into Perl code
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A package YourPackage;
1N/A require DynaLoader;
1N/A @ISA = qw(... DynaLoader ...);
1N/A bootstrap YourPackage;
1N/A
1N/A # optional method for 'global' loading
1N/A sub dl_load_flags { 0x01 }
1N/A
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThis document defines a standard generic interface to the dynamic
1N/Alinking mechanisms available on many platforms. Its primary purpose is
1N/Ato implement automatic dynamic loading of Perl modules.
1N/A
1N/AThis document serves as both a specification for anyone wishing to
1N/Aimplement the DynaLoader for a new platform and as a guide for
1N/Aanyone wishing to use the DynaLoader directly in an application.
1N/A
1N/AThe DynaLoader is designed to be a very simple high-level
1N/Ainterface that is sufficiently general to cover the requirements
1N/Aof SunOS, HP-UX, NeXT, Linux, VMS and other platforms.
1N/A
1N/AIt is also hoped that the interface will cover the needs of OS/2, NT
1N/Aetc and also allow pseudo-dynamic linking (using C<ld -A> at runtime).
1N/A
1N/AIt must be stressed that the DynaLoader, by itself, is practically
1N/Auseless for accessing non-Perl libraries because it provides almost no
1N/APerl-to-C 'glue'. There is, for example, no mechanism for calling a C
1N/Alibrary function or supplying arguments. A C::DynaLib module
1N/Ais available from CPAN sites which performs that function for some
1N/Acommon system types. And since the year 2000, there's also Inline::C,
1N/Aa module that allows you to write Perl subroutines in C. Also available
1N/Afrom your local CPAN site.
1N/A
1N/ADynaLoader Interface Summary
1N/A
1N/A @dl_library_path
1N/A @dl_resolve_using
1N/A @dl_require_symbols
1N/A $dl_debug
1N/A @dl_librefs
1N/A @dl_modules
1N/A @dl_shared_objects
1N/A Implemented in:
1N/A bootstrap($modulename) Perl
1N/A @filepaths = dl_findfile(@names) Perl
1N/A $flags = $modulename->dl_load_flags Perl
1N/A $symref = dl_find_symbol_anywhere($symbol) Perl
1N/A
1N/A $libref = dl_load_file($filename, $flags) C
1N/A $status = dl_unload_file($libref) C
1N/A $symref = dl_find_symbol($libref, $symbol) C
1N/A @symbols = dl_undef_symbols() C
1N/A dl_install_xsub($name, $symref [, $filename]) C
1N/A $message = dl_error C
1N/A
1N/A=over 4
1N/A
1N/A=item @dl_library_path
1N/A
1N/AThe standard/default list of directories in which dl_findfile() will
1N/Asearch for libraries etc. Directories are searched in order:
1N/A$dl_library_path[0], [1], ... etc
1N/A
1N/A@dl_library_path is initialised to hold the list of 'normal' directories
1N/A(F</usr/lib>, etc) determined by B<Configure> (C<$Config{'libpth'}>). This should
1N/Aensure portability across a wide range of platforms.
1N/A
1N/A@dl_library_path should also be initialised with any other directories
1N/Athat can be determined from the environment at runtime (such as
1N/ALD_LIBRARY_PATH for SunOS).
1N/A
1N/AAfter initialisation @dl_library_path can be manipulated by an
1N/Aapplication using push and unshift before calling dl_findfile().
1N/AUnshift can be used to add directories to the front of the search order
1N/Aeither to save search time or to override libraries with the same name
1N/Ain the 'normal' directories.
1N/A
1N/AThe load function that dl_load_file() calls may require an absolute
1N/Apathname. The dl_findfile() function and @dl_library_path can be
1N/Aused to search for and return the absolute pathname for the
1N/Alibrary/object that you wish to load.
1N/A
1N/A=item @dl_resolve_using
1N/A
1N/AA list of additional libraries or other shared objects which can be
1N/Aused to resolve any undefined symbols that might be generated by a
1N/Alater call to load_file().
1N/A
1N/AThis is only required on some platforms which do not handle dependent
1N/Alibraries automatically. For example the Socket Perl extension
1N/Alibrary (F<auto/Socket/Socket.so>) contains references to many socket
1N/Afunctions which need to be resolved when it's loaded. Most platforms
1N/Awill automatically know where to find the 'dependent' library (e.g.,
1N/AF</usr/lib/libsocket.so>). A few platforms need to be told the
1N/Alocation of the dependent library explicitly. Use @dl_resolve_using
1N/Afor this.
1N/A
1N/AExample usage:
1N/A
1N/A @dl_resolve_using = dl_findfile('-lsocket');
1N/A
1N/A=item @dl_require_symbols
1N/A
1N/AA list of one or more symbol names that are in the library/object file
1N/Ato be dynamically loaded. This is only required on some platforms.
1N/A
1N/A=item @dl_librefs
1N/A
1N/AAn array of the handles returned by successful calls to dl_load_file(),
1N/Amade by bootstrap, in the order in which they were loaded.
1N/ACan be used with dl_find_symbol() to look for a symbol in any of
1N/Athe loaded files.
1N/A
1N/A=item @dl_modules
1N/A
1N/AAn array of module (package) names that have been bootstrap'ed.
1N/A
1N/A=item @dl_shared_objects
1N/A
1N/AAn array of file names for the shared objects that were loaded.
1N/A
1N/A=item dl_error()
1N/A
1N/ASyntax:
1N/A
1N/A $message = dl_error();
1N/A
1N/AError message text from the last failed DynaLoader function. Note
1N/Athat, similar to errno in unix, a successful function call does not
1N/Areset this message.
1N/A
1N/AImplementations should detect the error as soon as it occurs in any of
1N/Athe other functions and save the corresponding message for later
1N/Aretrieval. This will avoid problems on some platforms (such as SunOS)
1N/Awhere the error message is very temporary (e.g., dlerror()).
1N/A
1N/A=item $dl_debug
1N/A
1N/AInternal debugging messages are enabled when $dl_debug is set true.
1N/ACurrently setting $dl_debug only affects the Perl side of the
1N/ADynaLoader. These messages should help an application developer to
1N/Aresolve any DynaLoader usage problems.
1N/A
1N/A$dl_debug is set to C<$ENV{'PERL_DL_DEBUG'}> if defined.
1N/A
1N/AFor the DynaLoader developer/porter there is a similar debugging
1N/Avariable added to the C code (see dlutils.c) and enabled if Perl was
1N/Abuilt with the B<-DDEBUGGING> flag. This can also be set via the
1N/APERL_DL_DEBUG environment variable. Set to 1 for minimal information or
1N/Ahigher for more.
1N/A
1N/A=item dl_findfile()
1N/A
1N/ASyntax:
1N/A
1N/A @filepaths = dl_findfile(@names)
1N/A
1N/ADetermine the full paths (including file suffix) of one or more
1N/Aloadable files given their generic names and optionally one or more
1N/Adirectories. Searches directories in @dl_library_path by default and
1N/Areturns an empty list if no files were found.
1N/A
1N/ANames can be specified in a variety of platform independent forms. Any
1N/Anames in the form B<-lname> are converted into F<libname.*>, where F<.*> is
1N/Aan appropriate suffix for the platform.
1N/A
1N/AIf a name does not already have a suitable prefix and/or suffix then
1N/Athe corresponding file will be searched for by trying combinations of
1N/Aprefix and suffix appropriate to the platform: "$name.o", "lib$name.*"
1N/Aand "$name".
1N/A
1N/AIf any directories are included in @names they are searched before
1N/A@dl_library_path. Directories may be specified as B<-Ldir>. Any other
1N/Anames are treated as filenames to be searched for.
1N/A
1N/AUsing arguments of the form C<-Ldir> and C<-lname> is recommended.
1N/A
1N/AExample:
1N/A
1N/A @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
1N/A
1N/A
1N/A=item dl_expandspec()
1N/A
1N/ASyntax:
1N/A
1N/A $filepath = dl_expandspec($spec)
1N/A
1N/ASome unusual systems, such as VMS, require special filename handling in
1N/Aorder to deal with symbolic names for files (i.e., VMS's Logical Names).
1N/A
1N/ATo support these systems a dl_expandspec() function can be implemented
1N/Aeither in the F<dl_*.xs> file or code can be added to the autoloadable
1N/Adl_expandspec() function in F<DynaLoader.pm>. See F<DynaLoader.pm> for
1N/Amore information.
1N/A
1N/A=item dl_load_file()
1N/A
1N/ASyntax:
1N/A
1N/A $libref = dl_load_file($filename, $flags)
1N/A
1N/ADynamically load $filename, which must be the path to a shared object
1N/Aor library. An opaque 'library reference' is returned as a handle for
1N/Athe loaded object. Returns undef on error.
1N/A
1N/AThe $flags argument to alters dl_load_file behaviour.
1N/AAssigned bits:
1N/A
1N/A 0x01 make symbols available for linking later dl_load_file's.
1N/A (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
1N/A (ignored under VMS; this is a normal part of image linking)
1N/A
1N/A(On systems that provide a handle for the loaded object such as SunOS
1N/Aand HPUX, $libref will be that handle. On other systems $libref will
1N/Atypically be $filename or a pointer to a buffer containing $filename.
1N/AThe application should not examine or alter $libref in any way.)
1N/A
1N/AThis is the function that does the real work. It should use the
1N/Acurrent values of @dl_require_symbols and @dl_resolve_using if required.
1N/A
1N/A SunOS: dlopen($filename)
1N/A HP-UX: shl_load($filename)
1N/A Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
1N/A NeXT: rld_load($filename, @dl_resolve_using)
1N/A VMS: lib$find_image_symbol($filename,$dl_require_symbols[0])
1N/A
1N/A(The dlopen() function is also used by Solaris and some versions of
1N/ALinux, and is a common choice when providing a "wrapper" on other
1N/Amechanisms as is done in the OS/2 port.)
1N/A
1N/A=item dl_unload_file()
1N/A
1N/ASyntax:
1N/A
1N/A $status = dl_unload_file($libref)
1N/A
1N/ADynamically unload $libref, which must be an opaque 'library reference' as
1N/Areturned from dl_load_file. Returns one on success and zero on failure.
1N/A
1N/AThis function is optional and may not necessarily be provided on all platforms.
1N/AIf it is defined, it is called automatically when the interpreter exits for
1N/Aevery shared object or library loaded by DynaLoader::bootstrap. All such
1N/Alibrary references are stored in @dl_librefs by DynaLoader::Bootstrap as it
1N/Aloads the libraries. The files are unloaded in last-in, first-out order.
1N/A
1N/AThis unloading is usually necessary when embedding a shared-object perl (e.g.
1N/Aone configured with -Duseshrplib) within a larger application, and the perl
1N/Ainterpreter is created and destroyed several times within the lifetime of the
1N/Aapplication. In this case it is possible that the system dynamic linker will
1N/Aunload and then subsequently reload the shared libperl without relocating any
1N/Areferences to it from any files DynaLoaded by the previous incarnation of the
1N/Ainterpreter. As a result, any shared objects opened by DynaLoader may point to
1N/Aa now invalid 'ghost' of the libperl shared object, causing apparently random
1N/Amemory corruption and crashes. This behaviour is most commonly seen when using
1N/AApache and mod_perl built with the APXS mechanism.
1N/A
1N/A SunOS: dlclose($libref)
1N/A HP-UX: ???
1N/A Linux: ???
1N/A NeXT: ???
1N/A VMS: ???
1N/A
1N/A(The dlclose() function is also used by Solaris and some versions of
1N/ALinux, and is a common choice when providing a "wrapper" on other
1N/Amechanisms as is done in the OS/2 port.)
1N/A
1N/A=item dl_load_flags()
1N/A
1N/ASyntax:
1N/A
1N/A $flags = dl_load_flags $modulename;
1N/A
1N/ADesigned to be a method call, and to be overridden by a derived class
1N/A(i.e. a class which has DynaLoader in its @ISA). The definition in
1N/ADynaLoader itself returns 0, which produces standard behavior from
1N/Adl_load_file().
1N/A
1N/A=item dl_find_symbol()
1N/A
1N/ASyntax:
1N/A
1N/A $symref = dl_find_symbol($libref, $symbol)
1N/A
1N/AReturn the address of the symbol $symbol or C<undef> if not found. If the
1N/Atarget system has separate functions to search for symbols of different
1N/Atypes then dl_find_symbol() should search for function symbols first and
1N/Athen other types.
1N/A
1N/AThe exact manner in which the address is returned in $symref is not
1N/Acurrently defined. The only initial requirement is that $symref can
1N/Abe passed to, and understood by, dl_install_xsub().
1N/A
1N/A SunOS: dlsym($libref, $symbol)
1N/A HP-UX: shl_findsym($libref, $symbol)
1N/A Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
1N/A NeXT: rld_lookup("_$symbol")
1N/A VMS: lib$find_image_symbol($libref,$symbol)
1N/A
1N/A
1N/A=item dl_find_symbol_anywhere()
1N/A
1N/ASyntax:
1N/A
1N/A $symref = dl_find_symbol_anywhere($symbol)
1N/A
1N/AApplies dl_find_symbol() to the members of @dl_librefs and returns
1N/Athe first match found.
1N/A
1N/A=item dl_undef_symbols()
1N/A
1N/AExample
1N/A
1N/A @symbols = dl_undef_symbols()
1N/A
1N/AReturn a list of symbol names which remain undefined after load_file().
1N/AReturns C<()> if not known. Don't worry if your platform does not provide
1N/Aa mechanism for this. Most do not need it and hence do not provide it,
1N/Athey just return an empty list.
1N/A
1N/A
1N/A=item dl_install_xsub()
1N/A
1N/ASyntax:
1N/A
1N/A dl_install_xsub($perl_name, $symref [, $filename])
1N/A
1N/ACreate a new Perl external subroutine named $perl_name using $symref as
1N/Aa pointer to the function which implements the routine. This is simply
1N/Aa direct call to newXSUB(). Returns a reference to the installed
1N/Afunction.
1N/A
1N/AThe $filename parameter is used by Perl to identify the source file for
1N/Athe function if required by die(), caller() or the debugger. If
1N/A$filename is not defined then "DynaLoader" will be used.
1N/A
1N/A
1N/A=item bootstrap()
1N/A
1N/ASyntax:
1N/A
1N/Abootstrap($module)
1N/A
1N/AThis is the normal entry point for automatic dynamic loading in Perl.
1N/A
1N/AIt performs the following actions:
1N/A
1N/A=over 8
1N/A
1N/A=item *
1N/A
1N/Alocates an auto/$module directory by searching @INC
1N/A
1N/A=item *
1N/A
1N/Auses dl_findfile() to determine the filename to load
1N/A
1N/A=item *
1N/A
1N/Asets @dl_require_symbols to C<("boot_$module")>
1N/A
1N/A=item *
1N/A
1N/Aexecutes an F<auto/$module/$module.bs> file if it exists
1N/A(typically used to add to @dl_resolve_using any files which
1N/Aare required to load the module on the current platform)
1N/A
1N/A=item *
1N/A
1N/Acalls dl_load_flags() to determine how to load the file.
1N/A
1N/A=item *
1N/A
1N/Acalls dl_load_file() to load the file
1N/A
1N/A=item *
1N/A
1N/Acalls dl_undef_symbols() and warns if any symbols are undefined
1N/A
1N/A=item *
1N/A
1N/Acalls dl_find_symbol() for "boot_$module"
1N/A
1N/A=item *
1N/A
1N/Acalls dl_install_xsub() to install it as "${module}::bootstrap"
1N/A
1N/A=item *
1N/A
1N/Acalls &{"${module}::bootstrap"} to bootstrap the module (actually
1N/Ait uses the function reference returned by dl_install_xsub for speed)
1N/A
1N/A=back
1N/A
1N/A=back
1N/A
1N/A
1N/A=head1 AUTHOR
1N/A
1N/ATim Bunce, 11 August 1994.
1N/A
1N/AThis interface is based on the work and comments of (in no particular
1N/Aorder): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
1N/ASiegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.
1N/A
1N/ALarry Wall designed the elegant inherited bootstrap mechanism and
1N/Aimplemented the first Perl 5 dynamic loader using it.
1N/A
1N/ASolaris global loading added by Nick Ing-Simmons with design/coding
1N/Aassistance from Tim Bunce, January 1996.
1N/A
1N/A=cut
1N/AEOT
1N/A
1N/Aclose OUT or die $!;
1N/A