This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
delay allocating trans table until needed
authorZefram <zefram@fysh.org>
Sat, 25 Feb 2012 15:41:17 +0000 (15:41 +0000)
committerZefram <zefram@fysh.org>
Sat, 25 Feb 2012 15:49:01 +0000 (15:49 +0000)
commit9100eeb186d403d6c6c6ef15844209cad5a9b9f0
tree711e77c82c5995fd558d5b175490419a80ab43f3
parent236cbe8d7a6747fb6144c93dd767895f8acffd00
delay allocating trans table until needed

Previously, a table was being allocated for OP_TRANS(|R), in a
PVOP arrangement, as soon as the op was built.  However, it wasn't
used immediately, and for UTF8-flagged ops it would be thrown away,
replaced by an SV-based translation table in a SVOP or PADOP arrangement.
This mutation of the op structure occurred in pmtrans(), some time after
original op building.  If an error occurred before pmtrans(), requiring
the op to be freed, op_clear() would be misled by the UTF8 flags into
treating the PV as an SV or pad index, causing crashes in the latter
case [perl #102858].  op_clear() was implicitly assuming that pmtrans()
had been performed, due to lacking any explicit indication of the op's
state of construction.

Now, the PV table is allocated by pmtrans(), when it's actually going to
populate it.  The PV doesn't get allocated at all for UTF8-flagged ops.
Prior to pmtrans(), the op_pv/op_sv/op_padix field is all bits zero,
so there's no problem with freeing the op.
op.c
pad.c
t/op/tr.t
toke.c