Call FETCH once on handle passed as 3rd arg to open()
authorFather Chrysostomos <sprout@cpan.org>
Sat, 19 Nov 2011 22:35:24 +0000 (14:35 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 20 Nov 2011 00:14:54 +0000 (16:14 -0800)
commit4ee6a9e8e4c361531b7884e075604202a3990a8f
treedcde2a11d317475b86f8f04e07052303fe9bfd47
parent21b5e840ca3d8b2cc03757792df203d73c518fad
Call FETCH once on handle passed as 3rd arg to open()

When open() has three arguments and the second ends with & the third
argument is treated as a handle.

In some cases get-magic was being skipped; in others, it was being
called three times.

This commit fixes it by modifying sv_2io.

In 5.8.x (before commit 7a5fd60d4), sv_2io did not call get-magic at
all except when croaking ("Bad filehandle: %"SVf).  In 5.10.0 (after
commit 7a5fd60d4), it started calling get-magic only if the sv was
neither a glob, a reference, or undef.  So it has never been reliable
in its invocation of get-magic.

sv_2io now consistently skips get-magic on the sv passed in directly
to it (open(), the only caller in the core, has already called get-
magic before passing it in).  It now calls get-magic on SvRV(sv) if
what is passed in is a reference, so open(fh, ">&", \$tied) will work.

Interestingly, open supports multiple levels of references:

\\\\\\\\\\\\open+f,">&",\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 \\\\\\\\\\\*STDOUT;print{f}"Just another Perl hacker,\n",.\\\\\\\y\\\
sv.c
t/op/tie_fetch_count.t