+2003-12-07 Gisle Aas <gisle@ActiveState.com>
+
+ Release 2.33
+
+ Enable explicit context passing for slight performance
+ improvement in threaded perls.
+
+ Tweaks to the Makefile.PL so that it is suitable both for
+ core and CPAN use.
+
+
+
+2003-12-05 Gisle Aas <gisle@ActiveState.com>
+
+ Release 2.32
+
+ Don't run u32align test program on HP-UX 10.20 as it
+ will hang. Patch by H.Merijn Brand <h.m.brand@hccnet.nl>.
+
+ Fixed documentation typo.
+
+
+
2003-11-28 Gisle Aas <gisle@ActiveState.com>
Release 2.31
use strict;
use vars qw($VERSION @ISA @EXPORT_OK);
-$VERSION = '2.31'; # $Date: 2003/11/28 13:06:19 $
+$VERSION = '2.33'; # $Date: 2003/12/07 08:40:18 $
require Exporter;
*import = \&Exporter::import;
Since the MD5 algorithm is byte oriented you might only add bits as
multiples of 8, so you probably want to just use add() instead. The
add_bits() method is provided for compatibility with other digest
-implementations. See L<Digest> for description arguments to
-add_bits().
+implementations. See L<Digest> for description of the arguments
+that add_bits() take.
=item $md5->digest
-/* $Id: MD5.xs,v 1.40 2003/07/22 05:59:27 gisle Exp $ */
+/* $Id: MD5.xs,v 1.42 2003/12/06 22:35:16 gisle Exp $ */
/*
* This library is free software; you can redistribute it and/or
#ifdef __cplusplus
extern "C" {
#endif
+#define PERL_NO_GET_CONTEXT /* we want efficiency */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define SvPVbyte SvPV
#endif
+#ifndef dTHX
+ #define pTHX_
+ #define aTHX_
+#endif
+
/* Perl does not guarantee that U32 is exactly 32 bits. Some system
* has no integral type with exactly 32 bits. For instance, A Cray has
* short, int and long all at 64 bits so we need to apply this macro
#define INT2PTR(any,d) (any)(d)
#endif
-static MD5_CTX* get_md5_ctx(SV* sv)
+static MD5_CTX* get_md5_ctx(pTHX_ SV* sv)
{
if (SvROK(sv)) {
sv = SvRV(sv);
#define F_HEX 1
#define F_B64 2
-static SV* make_mortal_sv(const unsigned char *src, int type)
+static SV* make_mortal_sv(pTHX_ const unsigned char *src, int type)
{
STRLEN len;
char result[33];
sv_setref_pv(ST(0), sclass, (void*)context);
SvREADONLY_on(SvRV(ST(0)));
} else {
- context = get_md5_ctx(xclass);
+ context = get_md5_ctx(aTHX_ xclass);
}
MD5Init(context);
XSRETURN(1);
clone(self)
SV* self
PREINIT:
- MD5_CTX* cont = get_md5_ctx(self);
+ MD5_CTX* cont = get_md5_ctx(aTHX_ self);
char *myname = sv_reftype(SvRV(self),TRUE);
MD5_CTX* context;
PPCODE:
add(self, ...)
SV* self
PREINIT:
- MD5_CTX* context = get_md5_ctx(self);
+ MD5_CTX* context = get_md5_ctx(aTHX_ self);
int i;
unsigned char *data;
STRLEN len;
SV* self
InputStream fh
PREINIT:
- MD5_CTX* context = get_md5_ctx(self);
+ MD5_CTX* context = get_md5_ctx(aTHX_ self);
STRLEN fill = context->bytes_low & 0x3F;
unsigned char buffer[4096];
int n;
PPCODE:
MD5Final(digeststr, context);
MD5Init(context); /* In case it is reused */
- ST(0) = make_mortal_sv(digeststr, ix);
+ ST(0) = make_mortal_sv(aTHX_ digeststr, ix);
XSRETURN(1);
void
MD5Update(&ctx, data, len);
}
MD5Final(digeststr, &ctx);
- ST(0) = make_mortal_sv(digeststr, ix);
+ ST(0) = make_mortal_sv(aTHX_ digeststr, ix);
XSRETURN(1);
-require 5.004;
+#!perl -w
+
+BEGIN { require 5.004 }
use strict;
use Config qw(%Config);
use ExtUtils::MakeMaker;
+my $PERL_CORE = grep $_ eq "PERL_CORE=1", @ARGV;
+
my @extra;
@extra = (DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment();
}
push(@extra, 'INSTALLDIRS' => 'perl') if $] >= 5.008;
+push(@extra, 'MAN3PODS' => {}) if $PERL_CORE; # Pods built by installman.
WriteMakefile(
'NAME' => 'Digest::MD5',
'VERSION_FROM' => 'MD5.pm',
- MAN3PODS => {}, # Pods will be built by installman.
+ 'PREREQ_PM' => { 'File::Spec' => 0,
+ 'Digest::base' => '1.00',
+ },
@extra,
'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
);
sub free_u32_alignment
{
- return 0 if $Config{d_u32align};
- return 1 if $Config{'byteorder'} eq '1234' || $Config{'byteorder'} eq '4321';
+ $|=1;
+ if (exists $Config{d_u32align}) {
+ print "Perl's config says that U32 access must ";
+ print "not " unless $Config{d_u32align};
+ print "be aligned.\n";
+ return !$Config{d_u32align};
+ }
+
+ if ($^O eq 'VMS' || $^O eq 'MSWin32') {
+ print "Assumes that $^O implies free alignment for U32 access.\n";
+ return 1;
+ }
+
+ if ($^O eq 'hpux' && $Config{osvers} < 11.0) {
+ print "Will not test for free alignment on older HP-UX.\n";
+ return 0;
+ }
+
+ print "Testing alignment requirements for U32... ";
+ open(ALIGN_TEST, ">u32align.c") or die "$!";
+ print ALIGN_TEST <<'EOT'; close(ALIGN_TEST);
+/*--------------------------------------------------------------*/
+/* This program allocates a buffer of U8 (char) and then tries */
+/* to access it through a U32 pointer at every offset. The */
+/* program is expected to die with a bus error/seg fault for */
+/* machines that do not support unaligned integer read/write */
+/*--------------------------------------------------------------*/
+
+#include <stdio.h>
+#include "EXTERN.h"
+#include "perl.h"
+
+#ifdef printf
+ #undef printf
+#endif
+
+int main(int argc, char** argv, char** env)
+{
+#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
+ U8 buf[] = "\0\0\0\1\0\0\0\0";
+ U32 *up;
+ int i;
+
+ if (sizeof(U32) != 4) {
+ printf("sizeof(U32) is not 4, but %d\n", sizeof(U32));
+ exit(1);
+ }
+
+ fflush(stdout);
+
+ for (i = 0; i < 4; i++) {
+ up = (U32*)(buf + i);
+ if (! ((*up == 1 << (8*i)) || /* big-endian */
+ (*up == 1 << (8*(3-i))) /* little-endian */
+ )
+ )
+ {
+ printf("read failed (%x)\n", *up);
+ exit(2);
+ }
+ }
+
+ /* write test */
+ for (i = 0; i < 4; i++) {
+ up = (U32*)(buf + i);
+ *up = 0xBeef;
+ if (*up != 0xBeef) {
+ printf("write failed (%x)\n", *up);
+ exit(3);
+ }
+ }
+
+ printf("no restrictions\n");
+ exit(0);
+#else
+ printf("unusual byteorder, playing safe\n");
+ exit(1);
+#endif
+ return 0;
+}
+/*--------------------------------------------------------------*/
+EOT
+
+ my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE";
+ my $exe = "u32align$Config{exe_ext}";
+ $cc_cmd .= " -o $exe";
+ my $rc;
+ $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}");
+ if ($rc) {
+ print "Can't compile test program. Will ensure alignment to play safe.\n\n";
+ unlink("u32align.c", $exe, "u32align$Config{obj_ext}");
+ return 0;
+ }
+
+ $rc = system("./$exe");
+ unlink("u32align.c", $exe, "u32align$Config{obj_ext}");
+
+ return 1 unless $rc;
+
+ if ($rc > 0x80) {
+ $rc >>= 8;
+ print "Test program exit status was $rc\n";
+ } else {
+ if ($rc & 0x80) {
+ $rc &= ~0x80;
+ print "Core dump deleted\n";
+ unlink("core");
+ }
+ print "signal $rc\n";
+ }
return 0;
}
my $EXPECT;
if (ord "A" == 193) { # EBCDIC
$EXPECT = <<EOT;
-8f87b430c5e308f6cb3c01b6820f2f0c Changes
+15e4c91ad67f5ff238033305376c9140 Changes
0565ec21b15c0f23f4c51fb327c8926d README
-1d676ae6942cd3abbdc912c79e4bbb1f MD5.pm
-45e5e6785b47fb922f33b4a74c29a148 MD5.xs
+f0f77710cd8d5ba7d9faedec8d02dc2f MD5.pm
+f9848c0ee3b20a9177465eec19361e6c MD5.xs
276da0aa4e9a08b7fe09430c9c5690aa rfc1321.txt
EOT
} elsif ("\n" eq "\015") { # MacOS
$EXPECT = <<EOT;
-28b11667b3a84a233cbdaf92ebb57578 Changes
+dea016b088ab4d88a5e7cbd9c15a9c88 Changes
6c950a0211a5a28f023bb482037698cd README
-be02581437f3d15bdc2d67551575bf60 MD5.pm
-ca3f8cb317c5d088ed9f97204c6b8cda MD5.xs
+f057c88277ecee875cf6f0352468407a MD5.pm
+5bae62404829e6fd8ad0d4f8d5ccea54 MD5.xs
754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt
EOT
} else {
# This is the output of: 'md5sum Changes README MD5.pm MD5.xs rfc1321.txt'
$EXPECT = <<EOT;
-a6a640087a028adbfa3fb3570e4104e6 Changes
+0f09886e2c129bdabf57674c6822bd4f Changes
6c950a0211a5a28f023bb482037698cd README
-be02581437f3d15bdc2d67551575bf60 MD5.pm
-ca3f8cb317c5d088ed9f97204c6b8cda MD5.xs
+f057c88277ecee875cf6f0352468407a MD5.pm
+5bae62404829e6fd8ad0d4f8d5ccea54 MD5.xs
754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt
EOT
}
INPUT
T_MD5_CTX
- $var = get_md5_ctx($arg)
+ $var = get_md5_ctx(aTHX_ $arg)