summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorJohn Tobey <jtobey@user1.channel1.com>1997-06-24 23:44:33 +1200
committerTim Bunce <Tim.Bunce@ig.co.uk>1997-08-07 00:00:00 +1200
commit72dbcb4b16ba8abae7db52f83482564e4d62acc4 (patch)
treec6f9319a426174a48a358f6bbe7d1d6d80693904 /pp.c
parent1b1626e441fa9750f3953e46530f2e95046bb007 (diff)
downloadperl-72dbcb4b16ba8abae7db52f83482564e4d62acc4.tar.gz
Re: Can't pack literals as pointers
MHO, pack("p","foo") should evaluate to a pointer that's valid in the urrent context. pack("p",undef) should return the NULL value. urrently, they both produce the error "Modification of a read-only alue attempted". This looks pretty easy to fix, so I've prepared a diff against the 5.004_01 distribution. This tests fine on my Linux. I hope I'm not introducing a memory leak or other ailment... Credited: Tim Bunce <Tim.Bunce@ig.co.uk> Credited: Gurusamy Sarathy <gsar@engin.umich.edu>
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/pp.c b/pp.c
index 1cea53fd10..fa36c500dc 100644
--- a/pp.c
+++ b/pp.c
@@ -3834,7 +3834,14 @@ PP(pp_pack)
case 'p':
while (len-- > 0) {
fromstr = NEXTFROM;
- aptr = SvPV_force(fromstr, na); /* XXX Error if TEMP? */
+ if (fromstr == &sv_undef)
+ aptr = NULL;
+ else {
+ if (SvREADONLY(fromstr) && curcop != &compiling) {
+ fromstr = sv_mortalcopy(fromstr);
+ }
+ aptr = SvPV_force(fromstr, na);
+ }
sv_catpvn(cat, (char*)&aptr, sizeof(char*));
}
break;