From: John Tobey Date: Tue, 24 Jun 1997 11:44:33 +0000 (+1200) Subject: Re: Can't pack literals as pointers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=72dbcb4b16ba8abae7db52f83482564e4d62acc4;p=p5sagit%2Fp5-mst-13.2.git 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 Credited: Gurusamy Sarathy --- diff --git a/pp.c b/pp.c index 1cea53f..fa36c50 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;