use strict;
use Config;
+# We require DynaLoader to make sure that mod2fname is loaded
+eval { require DynaLoader };
1 while unlink "XSLoader.pm";
open OUT, ">XSLoader.pm" or die $!;
package XSLoader;
-$VERSION = "0.16";
+$VERSION = "0.17";
#use strict;
=head1 VERSION
-Version 0.16
+Version 0.17
=head1 SYNOPSIS
# Tim.Bunce@ig.co.uk, August 1994
BEGIN {
- $VERSION = '1.22';
+ $VERSION = '1.23';
}
use Config;
EOT
}
+if ( $Config::Config{d_libname_unique} ) {
+ print OUT <<'EOT';
+sub mod2fname {
+ my $parts = shift;
+ my $so_len = length($Config::Config{dlext})+1;
+ my $name_max = 255; # No easy way to get this here
+
+ my $libname = "PL_" . join("__", @$parts);
+
+ return $libname if (length($libname)+$so_len) <= $name_max;
+
+ # It's too darned big, so we need to go strip. We use the same
+ # algorithm as xsubpp does. First, strip out doubled __
+ $libname =~ s/__/_/g;
+ return $libname if (length($libname)+$so_len) <= $name_max;
+
+ # Strip duplicate letters
+ 1 while $libname =~ s/(.)\1/\U$1/i;
+ return $libname if (length($libname)+$so_len) <= $name_max;
+
+ # Still too long. Truncate.
+ $libname = substr($libname, 0, $name_max - $so_len);
+ return $libname;
+}
+EOT
+}
# following long string contains $^O-specific stuff, which is factored out
print OUT expand_os_specific(<<'EOT');
next unless -d $dir; # skip over uninteresting directories
# check for common cases to avoid autoload of dl_findfile
- my $try = "$dir/$modfname.$dl_dlext";
+ my $try = "$dir/$modfname.$dl_dlext";
last if $file = ($do_expand) ? dl_expandspec($try) : ((-f $try) && $try);
# no luck here, save dir for possible later dl_findfile search
'Time::HiRes'=> q| ::is( ref Time::HiRes->can('usleep'),'CODE' ) |, # 5.7.3
);
-plan tests => 22 + keys(%modules) * 3;
+plan tests => 26 + keys(%modules) * 3;
# Try to load the module
}
}
}
+
+SKIP: {
+ skip "mod2fname not defined on this platform", 4
+ unless defined &DynaLoader::mod2fname && $Config{d_libname_unique};
+
+ is(
+ DynaLoader::mod2fname(["Hash", "Util"]),
+ "PL_Hash__Util",
+ "mod2fname + libname_unique works"
+ );
+
+ is(
+ DynaLoader::mod2fname([("Hash", "Util") x 25]),
+ "PL_" . join("_", ("Hash", "Util")x25),
+ "mod2fname + libname_unique collapses double __'s for long names"
+ );
+
+ is(
+ DynaLoader::mod2fname([("Haash", "Uttil") x 25]),
+ "PL_" . join("_", ("HAsh", "UTil")x25),
+ "mod2fname + libname_unique collapses repeated characters for long names"
+ );
+
+ is(
+ DynaLoader::mod2fname([("Hash", "Util")x30]),
+ substr(("PL_" . join("_", ("Hash", "Util")x30)), 0, 255 - (length($Config::Config{dlext})+1)),
+ "mod2fname + libname_unique correctly truncates long names"
+ );
+}