On Fri, 1 Nov 2002 12:53:41 -0500 (EST), Andy Dougherty wrote:

>At the moment, the bytecode "fingerprint" is built with Digest::MD5.
>Alas, Digest::MD5 wasn't standard with perl versions prior to 5.8.0.
>What should happen in those cases?  Anybody have any good ideas?

The attached patch is a fleshed-out (and lightly tested) 
example of my prior post. Invoking 'md5sum' in this way 
yields the same fingerprint as Digest::MD5. The fallback 
checksum is just the sum of ASCII values of all the ops, so 
it does not match the other two, and can be fooled, but it 
does give a warning in this case. Since the fingerprint is 
only there to help developers shoot themselves in the foot 
less often, perhaps this solution is sufficient.

BTW, I ran into this same problem recently while trying to 
build Parrot on a minimally-installed Debian box for a demo. 
Parrot failed on these missing items:
        stdio.h         (from pkg libc6-dev)
        Digest/MD5.pm   (from pkg libdigest-md5-perl)
        perldoc         (from pkg perl-doc)

I recognized the problems quickly, but only because I have 
been knee-deep in the code for a month. Missing C compilers 
also sting me frequently, as I am trying to get all the free 
Win32 compilers to work out-of-the-box with Parrot, and I 
don't have all my patches submitted yet, and sometimes 
forget to put the compiler-of-the-day in my PATH, or do a 
'perl Configure -cc=bcc32' (note the missing dash).

In Configure.pl and friends, I think that "fail early, fail 
loudly" should be a guiding principle, at least for the 
things with no workarounds. Unless someone thinks it is a 
bad idea, I intend to patch in that direction whenever I see 
relevant Configure code.

-- 
Hope this helps,
Bruce Gray

--- fingerprint_c.pl~   Thu Oct 24 09:14:10 2002
+++ fingerprint_c.pl    Fri Nov  1 14:50:43 2002
@@ -2,14 +2,32 @@
 
 use strict;
 use lib 'lib';
-use Digest::MD5 qw(md5_hex);
-use Data::Dumper;
 use Parrot::OpLib::core;
 
 my $len = 10;
-my $fingerprint = md5_hex join "\n", map {
-  join '_', $_->{NAME}, @{$_->{ARGS}}
+
+my $fingerprint = join "\n", map {
+    join '_', $_->{NAME}, @{$_->{ARGS}}
 } @$Parrot::OpLib::core::ops;
+if (eval {require Digest::MD5}) {
+       $fingerprint = Digest::MD5::md5_hex $fingerprint;
+}
+elsif (`md5sum </dev/null` and not $? ) { 
+       use File::Temp;
+       my ($fh, $filename) = File::Temp::tempfile() or die;
+       print $fh $fingerprint;
+       close $fh or die;
+       $fingerprint = substr(`md5sum $filename`, 0, 32);
+       die "Failed: Can't get valid checksum" unless $fingerprint and not $?;
+       unlink $filename or die;
+}
+else {
+       $fingerprint = unpack('H*', pack 'L', unpack "%128C*", $fingerprint) x 4;
+       warn "$0:warning - MD5 checksum not available - "    .
+             "Falling back to a much less secure checksum. " . 
+             "We recommend that you install the Digest::MD5 module, or the 'md5sum' 
+program.\n";
+}
+
 
 print << "EOF";
 /*

Reply via email to