summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-08-08 15:01:48 +0100
committerNicholas Clark <nick@ccl4.org>2009-08-08 17:54:36 +0100
commit85dca89a8f321bc581a3d365d95ab0c56368ed78 (patch)
treeca2336c2dad9d00e09d0201a98a2bb4107890f3f /sv.c
parentd5713896ecd1399c9c6c4076514a33eb2880d8c3 (diff)
downloadperl-85dca89a8f321bc581a3d365d95ab0c56368ed78.tar.gz
Perl_newIO() can become a mathom by making newIO() a wrapper around newSV_type()
and tweaking Perl_sv_upgrade().
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index a5a3554337..b8daf81546 100644
--- a/sv.c
+++ b/sv.c
@@ -1430,8 +1430,22 @@ Perl_sv_upgrade(pTHX_ register SV *const sv, svtype new_type)
SvNV_set(sv, 0);
#endif
- if (new_type == SVt_PVIO)
+ if (new_type == SVt_PVIO) {
+ IO * const io = MUTABLE_IO(sv);
+ GV *iogv = gv_fetchpvs("FileHandle::", 0, SVt_PVHV);
+
+ SvOBJECT_on(io);
+ /* Clear the stashcache because a new IO could overrule a package
+ name */
+ hv_clear(PL_stashcache);
+
+ /* unless exists($main::{FileHandle}) and
+ defined(%main::FileHandle::) */
+ if (!(iogv && GvHV(iogv) && HvARRAY(GvHV(iogv))))
+ iogv = gv_fetchpvs("IO::Handle::", GV_ADD, SVt_PVHV);
+ SvSTASH_set(io, MUTABLE_HV(SvREFCNT_inc(GvHV(iogv))));
IoPAGE_LEN(sv) = 60;
+ }
if (old_type < SVt_PV) {
/* referant will be NULL unless the old type was SVt_IV emulating
SVt_RV */