+/* $Id: MD5.xs,v 1.35 2003/01/05 00:54:17 gisle Exp $ */
+
/*
* This library is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
}
#endif
-#ifndef SvPVbyte
+#include <patchlevel.h>
+#ifndef PERL_VERSION
+# include <could_not_find_Perl_patchlevel.h>
+#endif
+#if PATCHLEVEL <= 4 && !defined(PL_dowarn)
+ #define PL_dowarn dowarn
+#endif
+
+#ifdef SvPVbyte
+ #if PERL_REVISION == 5 && PERL_VERSION < 7
+ /* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
+ #undef SvPVbyte
+ #define SvPVbyte(sv, lp) \
+ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
+ ? ((lp = SvCUR(sv)), SvPVX(sv)) : my_sv_2pvbyte(aTHX_ sv, &lp))
+
+ static char *
+ my_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
+ {
+ sv_utf8_downgrade(sv,0);
+ return SvPV(sv,*lp);
+ }
+ #endif
+#else
#define SvPVbyte SvPV
#endif
XSRETURN(1);
void
+clone(self)
+ SV* self
+ PREINIT:
+ MD5_CTX* cont = get_md5_ctx(self);
+ char *myname = sv_reftype(SvRV(self),TRUE);
+ MD5_CTX* context;
+ PPCODE:
+ STRLEN my_na;
+ New(55, context, 1, MD5_CTX);
+ ST(0) = sv_newmortal();
+ sv_setref_pv(ST(0), myname , (void*)context);
+ SvREADONLY_on(SvRV(ST(0)));
+ memcpy(context,cont,sizeof(MD5_CTX));
+ XSRETURN(1);
+
+void
DESTROY(context)
MD5_CTX* context
CODE:
unsigned char digeststr[16];
PPCODE:
MD5Init(&ctx);
- if (PL_dowarn && items > 1) {
- data = (unsigned char *)SvPVbyte(ST(0), len);
- if (len == 11 && memEQ("Digest::MD5", data, 11)) {
- char *f = (ix == F_BIN) ? "md5" :
- (ix == F_HEX) ? "md5_hex" : "md5_base64";
- warn("&Digest::MD5::%s function probably called as method", f);
- }
+
+ if (PL_dowarn) {
+ char *msg = 0;
+ if (items == 1) {
+ if (SvROK(ST(0))) {
+ SV* sv = SvRV(ST(0));
+ if (SvOBJECT(sv) && strEQ(HvNAME(SvSTASH(sv)), "Digest::MD5"))
+ msg = "probably called as method";
+ else
+ msg = "called with reference argument";
+ }
+ }
+ else if (items > 1) {
+ data = (unsigned char *)SvPVbyte(ST(0), len);
+ if (len == 11 && memEQ("Digest::MD5", data, 11)) {
+ msg = "probably called as class method";
+ }
+ }
+ if (msg) {
+ char *f = (ix == F_BIN) ? "md5" :
+ (ix == F_HEX) ? "md5_hex" : "md5_base64";
+ warn("&Digest::MD5::%s function %s", f, msg);
+ }
}
+
for (i = 0; i < items; i++) {
data = (unsigned char *)(SvPVbyte(ST(i), len));
MD5Update(&ctx, data, len);