summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-02-21 14:54:00 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-02-21 14:54:00 +0000
commit976009d465e53e9c4cc16adb46a02a8ef0c38fbb (patch)
tree5ef4c105b1ec9501e9818c7064980c8499d8998b
parent34aaaa845400abfb74d5e84f98d1d59cdb650982 (diff)
downloadperl-976009d465e53e9c4cc16adb46a02a8ef0c38fbb.tar.gz
Make unpack C and unpack U truly equivalent.
p4raw-id: //depot/perl@8875
-rw-r--r--pp.c35
-rwxr-xr-xt/op/pack.t15
2 files changed, 19 insertions, 31 deletions
diff --git a/pp.c b/pp.c
index 2b975e4a8d..d8d00820f2 100644
--- a/pp.c
+++ b/pp.c
@@ -4329,6 +4329,7 @@ PP(pp_unpack)
}
break;
case 'C':
+ case 'U':
if (len > strend - s)
len = strend - s;
if (checksum) {
@@ -4337,7 +4338,10 @@ PP(pp_unpack)
STRLEN l;
auv = utf8_to_uv((U8*)s, strend - s,
&l, UTF8_ALLOW_ANYUV);
- culong += auv;
+ if (checksum > 32)
+ cdouble += (NV)auv;
+ else
+ culong += auv;
s += l;
len -= l;
}
@@ -4375,35 +4379,6 @@ PP(pp_unpack)
}
}
break;
- case 'U':
- if (len > strend - s)
- len = strend - s;
- if (checksum) {
- while (len-- > 0 && s < strend) {
- STRLEN alen;
- auint = utf8_to_uv((U8*)s, strend - s, &alen, 0);
- along = alen;
- s += along;
- if (checksum > 32)
- cdouble += (NV)auint;
- else
- culong += auint;
- }
- }
- else {
- EXTEND(SP, len);
- EXTEND_MORTAL(len);
- while (len-- > 0 && s < strend) {
- STRLEN alen;
- auint = utf8_to_uv((U8*)s, strend - s, &alen, 0);
- along = alen;
- s += along;
- sv = NEWSV(37, 0);
- sv_setuv(sv, (UV)auint);
- PUSHs(sv_2mortal(sv));
- }
- }
- break;
case 's':
#if SHORTSIZE == SIZE16
along = (strend - s) / SIZE16;
diff --git a/t/op/pack.t b/t/op/pack.t
index 3483597fbe..db033f3013 100755
--- a/t/op/pack.t
+++ b/t/op/pack.t
@@ -6,7 +6,7 @@ BEGIN {
require Config; import Config;
}
-print "1..163\n";
+print "1..165\n";
$format = "c2 x5 C C x s d i l a6";
# Need the expression in here to force ary[5] to be numeric. This avoids
@@ -453,3 +453,16 @@ print "ok $test\n"; $test++;
print "ok $test\n"; $test++;
}
+# 164: pack C and pack U equivalence
+
+print "not " unless pack("C", 0x100) eq pack("U", 0x100) &&
+ chr(0x100) eq pack("U", 0x100);
+print "ok $test\n"; $test++;
+
+# 165: unpack C and unpack U equivalence
+
+print "not " unless "@{[unpack('C*', chr(0x100) . chr(0x200))]}" eq
+ "@{[unpack('U*', chr(0x100) . chr(0x200))]}" &&
+ "@{[unpack('U*', chr(0x100) . chr(0x200))]}" eq "256 512";
+print "ok $test\n"; $test++;
+