In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/8c5b7c71cac94d2c88b24f50345e81080ffdf55d?hp=9e380ad423cc802b5d0aaef3b223a4f53b62b307>

- Log -----------------------------------------------------------------
commit 8c5b7c71cac94d2c88b24f50345e81080ffdf55d
Author: Nicholas Clark <[email protected]>
Date:   Sun Oct 24 17:00:23 2010 +0200

    B::hash() should only work on byte sequences.

M       ext/B/B.xs
M       ext/B/t/b.t

commit 90b16320f2d9f077cb58830cb1c93fbde7b6e34e
Author: Nicholas Clark <[email protected]>
Date:   Sun Oct 24 16:23:05 2010 +0200

    Refactor B::hash to use Perl_newSVpvf() instead of my_sprintf() and 
new_SVpvn*.

M       ext/B/B.xs

commit b45732d66ea1319bd17a11a2b11dc0e1942d0cef
Author: Nicholas Clark <[email protected]>
Date:   Sun Oct 24 16:05:55 2010 +0200

    More tests for B::hash().

M       ext/B/t/b.t
-----------------------------------------------------------------------

Summary of changes:
 ext/B/B.xs  |    6 ++----
 ext/B/t/b.t |   18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ext/B/B.xs b/ext/B/B.xs
index 138ec05..d71f587 100644
--- a/ext/B/B.xs
+++ b/ext/B/B.xs
@@ -781,11 +781,9 @@ hash(sv)
     CODE:
        STRLEN len;
        U32 hash = 0;
-       char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
-       const char *s = SvPV(sv, len);
+       const char *s = SvPVbyte(sv, len);
        PERL_HASH(hash, s, len);
-       len = my_sprintf(hexhash, "0x%"UVxf, (UV)hash);
-       ST(0) = newSVpvn_flags(hexhash, len, SVs_TEMP);
+       ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%"UVxf, (UV)hash));
 
 #define cast_I32(foo) (I32)foo
 IV
diff --git a/ext/B/t/b.t b/ext/B/t/b.t
index b32ce31..de306af 100644
--- a/ext/B/t/b.t
+++ b/ext/B/t/b.t
@@ -156,7 +156,23 @@ is(ref B::sv_undef(), "B::SPECIAL", "B::sv_undef()");
 is(B::ppname(0), "pp_null", "Testing ppname (this might break if opnames.h is 
changed)");
 is(B::opnumber("null"), 0, "Testing opnumber with opname (null)");
 is(B::opnumber("pp_null"), 0, "Testing opnumber with opname (pp_null)");
-like(B::hash("wibble"), qr/0x[0-9a-f]*/, "Testing B::hash()");
+{
+    my $hash = B::hash("wibble");
+    like($hash, qr/\A0x[0-9a-f]+\z/, "Testing B::hash(\"wibble\")");
+    unlike($hash, qr/\A0x0+\z/, "Testing B::hash(\"wibble\")");
+
+    like(B::hash("\0" x $_), qr/\A0x0+\z/, "Testing B::hash(\"0\" x $_)")
+        for 0..19;
+
+    $hash = eval {B::hash(chr 256)};
+    is($hash, undef, "B::hash() refuses non-octets");
+    like($@, qr/^Wide character in subroutine entry/);
+
+    $hash = B::hash(chr 163);
+    my $str = chr(163) . chr 256;
+    chop $str;
+    is(B::hash($str), $hash, 'B::hash() with chr 128-256 is well-behaved');
+}
 {
     is(B::cstring(undef), '0', "Testing B::cstring(undef)");
     is(B::perlstring(undef), '0', "Testing B::perlstring(undef)");

--
Perl5 Master Repository

Reply via email to