I made my modifications to shared.xs 1.12, which was the latest version when I started. I noticed jdhedden released 1.14 recently which I have installed but haven't got around to catching up with yet. I need to add all my changes and tracing to it before I can continue my investigations.
Here's the output from a really simple test I ran (that won't work without the mods I've made). Sorry for the mess it will look in the browser, but if you C&P it to an editor with a reasonably wide screen it should sort itself out.
At main.C:\test\sharedGlob.pl.17 At main.C:\test\sharedGlo +b.pl.18 At main.C:\test\sharedGlob.pl.20 +At main.C:\test\sharedGlob.pl.21 SV = RV(0x186801c) at 0x1909554 SV = PVMG(0x184c6ac) at 0 +x190a800 SV = PVLV(0x1866e3c) at 0x2251f0 +SV = PVLV(0x1866e3c) at 0x18c414c REFCNT = 1 REFCNT = 1 + REFCNT = 1 + REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) FLAGS = (PADBUSY,PADMY, +GMG,SMG,ROK) FLAGS = (GMG,SMG,RMG) + FLAGS = (GMG,SMG,RMG) RV = 0x225130 IV = 0 + IV = 0 + IV = 0 SV = PVGV(0x1919e44) at 0x225130 NV = 0 + NV = 0 + NV = 0 REFCNT = 1 RV = 0x225130 + PV = 0 + PV = 0 FLAGS = (GMG,SMG) SV = PVGV(0x1919e44) at + 0x225130 MAGIC = 0x1829c44 + MAGIC = 0x1919fec IV = 0 REFCNT = 2 + MG_VIRTUAL = 0x348048 + MG_VIRTUAL = 0x348048 NV = 0 FLAGS = (GMG,SMG) + MG_TYPE = PERL_MAGIC_tiedelem(p) + MG_TYPE = PERL_MAGIC_tiedelem(p) MAGIC = 0x1829894 IV = 0 + MG_FLAGS = 0x12 + MG_FLAGS = 0x12 MG_VIRTUAL = &PL_vtbl_glob NV = 0 + REFCOUNTED + REFCOUNTED MG_TYPE = PERL_MAGIC_glob(*) MAGIC = 0x191a09c + MG_OBJ = 0x190aaf4 + MG_OBJ = 0x190aaf4 MG_OBJ = 0x225130 MG_VIRTUAL = 0x3480 +2c SV = RV(0x1868014) at 0x190aaf4 + SV = RV(0x1868014) at 0x190aaf4 NAME = "GEN0" MG_TYPE = PERL_MAGI +C_shared_scalar(n) REFCNT = 2 + REFCNT = 2 NAMELEN = 4 MG_FLAGS = 0x10 + FLAGS = (ROK) + FLAGS = (ROK) GvSTASH = 0x18acf54 "Symbol" MG_PTR = 0x18b3e20 +"" RV = 0x1833bf8 + RV = 0x1833bf8 GP = 0x1919e94 MAGIC = 0x1829894 + SV = PVMG(0x184c68c) at 0x1833bf8 + SV = PVMG(0x184c68c) at 0x1833bf8 SV = 0x190b78c MG_VIRTUAL = &PL_vt +bl_glob REFCNT = 1 + REFCNT = 1 REFCNT = 1 MG_TYPE = PERL_MAGI +C_glob(*) FLAGS = (OBJECT,IOK,pIOK) + FLAGS = (OBJECT,IOK,pIOK) IO = 0x0 MG_OBJ = 0x225130 + IV = 25902612 + IV = 25902612 FORM = 0x0 NAME = "GEN0" + NV = 0 + NV = 0 AV = 0x0 NAMELEN = 4 + PV = 0 + PV = 0 HV = 0x0 GvSTASH = 0x18acf54 " +Symbol" STASH = 0x18b12a0 "threads::shared::tie" + STASH = 0x18b12a0 "threads::shared::tie" CV = 0x0 GP = 0x1919e94 + MG_LEN = -2 + MG_LEN = -2 CVGEN = 0x0 SV = 0x190b78c + MG_PTR = 0x22504c => HEf_SVKEY + MG_PTR = 0x18331f4 => HEf_SVKEY GPFLAGS = 0x0 REFCNT = 2 + SV = PV(0x18de30c) at 0x22504c + SV = PV(0x18de2e8) at 0x18331f4 LINE = 103 IO = 0x0 + REFCNT = 2 + REFCNT = 2 FILE = "c:/Perl/lib/Symbol.pm" FORM = 0x0 + FLAGS = (POK,pPOK) + FLAGS = (POK,pPOK) FLAGS = 0x0 AV = 0x0 + PV = 0x18bbffc "direct"\0 + PV = 0x18bbffc "indirect"\0 EGV = 0x225130 "GEN0" HV = 0x0 + CUR = 6 + CUR = 8 CV = 0x0 + LEN = 7 + LEN = 9 CVGEN = 0x0 + TYPE = T + TYPE = T GPFLAGS = 0x0 + TARGOFF = 0 + TARGOFF = 0 LINE = 103 + TARGLEN = 0 + TARGLEN = 0 FILE = "c:/Perl/lib +/Symbol.pm" TARG = 0x184ede0 + TARG = 0x184ede0 FLAGS = 0x0 EGV = 0x225130 " +GEN0" PV = 0x225130 "" CUR = 0 LEN = 0 MAGIC = 0x191a3ac MG_VIRTUAL = 0x34802c MG_TYPE = PERL_MAGIC_ +shared_scalar(n) MG_FLAGS = 0x10 MG_PTR = 0x18b3e2c ""
What it shows is the output from Devel::Peek::Dump() of the same glob returned from Symbol::gensym():
The first (leftmost) is what it looks like as returned.
The second is how it looks after it has been shared (after mods). You can see that it is still the same animal. It has retained the glob magic, and gains the shared scalar magic. At this point, the shared copy works as the original in every way I've tried. If I use a glob returned by IO::Socket::INET, all the methods work on the copy as normal. In the originating thread and in any other thread that uses it.
The third is what you see after you assign the original as a value to a shared hash.
The fourth if you assign the copy.
As you can see, all the glob and shared scalar magic has been replaced by shared element magic and all the good stuff done by share() seems to have been blown away.
Maybe I'm misinterpreting this output, this is somewhat of a work in progress that has recently been interupted by other things. What I do know is that after you assign a globref to a hash (or array element), it no longer acts as a globref, which is probably why it was disabled in the first place.
But I am convinced that it is a limitation of the magic handling in share.xs, rather than a fundamental limitation of perl's magic handling.
In reply to Re^4: Sharing globs
by BrowserUk
in thread Sharing globs
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |