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>
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;