Skip to content

Commit 326b81e

Browse files
tonycozbook
authored andcommitted
TARG has some subtleties, mention them
Mostly lessons learned from #22784.
1 parent 54c282d commit 326b81e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pod/perlguts.pod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,24 @@ need a C<dTARG> in your variable declarations so that the C<*PUSH*>
23702370
macros can make use of the local variable C<TARG>. See also
23712371
C<dTARGET> and C<dXSTARG>.
23722372

2373+
Be careful with TARG: each non-recursive call to your OP, or XSUB for
2374+
dXSTARG, will use the same SV for TARG for each call, so you can't
2375+
assume the SV is pristine since the results from the previous call to
2376+
your OP or XSUB may still be in TARG.
2377+
2378+
Other state such as a cached numeric version of a PV or the cached
2379+
UTF-8 length may also be set. You can avoid problems with this by
2380+
using the normal sv_set*() APIs instead of trying to optimize by
2381+
directly manipulating the SV.
2382+
2383+
For OPs that implement the C<OA_TARGLEX> optimization, TARG may be
2384+
special in other ways, there may be references to it, it might be
2385+
blessed, it might be tied, or magical in other ways.
2386+
2387+
You must not use TARG to return a reference, since that reference will
2388+
be live until the next time the OP or XSUB executes non-recursively,
2389+
or until perl exits.
2390+
23732391
=head2 Scratchpads
23742392

23752393
The question remains on when the SVs which are I<target>s for opcodes

0 commit comments

Comments
 (0)