summaryrefslogtreecommitdiff
path: root/pp_pack.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-02-20 16:26:56 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-20 16:26:56 +0000
commit735b914b6122ad8117831a13734ab73e13d1e5bc (patch)
tree4934005371e59d20000ee84956e0fe7e60f052d7 /pp_pack.c
parent13089db4da7b2c2e95e9627db24ff15c9fdc44f8 (diff)
downloadperl-735b914b6122ad8117831a13734ab73e13d1e5bc.tar.gz
Forgot from #14790.
p4raw-id: //depot/perl@14793
Diffstat (limited to 'pp_pack.c')
-rw-r--r--pp_pack.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/pp_pack.c b/pp_pack.c
index b66d68283a..61185a46e0 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -1720,8 +1720,27 @@ PP(pp_pack)
buf[sizeof(buf) - 1] &= 0x7f; /* clear continue bit */
sv_catpvn(cat, in, (buf + sizeof(buf)) - in);
}
- else
- DIE(aTHX_ "Cannot compress non integer");
+ else {
+ char *from, *result, *in;
+ SV *norm;
+ STRLEN len;
+ bool done;
+
+ /* Copy string and check for compliance */
+ from = SvPV(fromstr, len);
+ if ((norm = is_an_int(from, len)) == NULL)
+ DIE(aTHX_ "can compress only unsigned integer");
+
+ New('w', result, len, char);
+ in = result + len;
+ done = FALSE;
+ while (!done)
+ *--in = div128(norm, &done) | 0x80;
+ result[len - 1] &= 0x7F; /* clear continue bit */
+ sv_catpvn(cat, in, (result + len) - in);
+ Safefree(result);
+ SvREFCNT_dec(norm); /* free norm */
+ }
}
break;
case 'i':