On Sun, Dec 12, 2004 at 07:54:32AM +0000 Sisyphus wrote: > Tassilo von Parseval wrote: > > > > > >PL_sv_yes looks like this: > > > > SV = PVNV(0x814d6b8) at 0x814c60c > > REFCNT = 2147483647 > > FLAGS = (NOK,POK,READONLY,pNOK,pPOK) > > IV = 0 > > NV = 1 > > PV = 0x814da80 "1"\0 > > CUR = 1 > > LEN = 2 > > > > Yes - I wrote a little module that uses overloading and did a > Devel::Peek::Dump() of the third argument - and got essentially the same > as that when the third overload argument was TRUE. I also found that > PL_sv_no (which is the FALSE value that the third overload argument can > take on) is very similar - except you get: > > PV = 0xblah ""\0 > CUR = 0 > LEN = 1 > > (On occasion that third arg can be PL_sv_undef - I'll Dump() it, too, > when I get around to it.) > > Ok - so I can assign PL_sv_yes in C-space by doing: > > sv = &PL_sv_yes; (should have realised.) > > How does it get done in perl-space ?
It's almost impossible. The problem is that the pointer to PL_sv_yes is destroyed once you allow an assignment: use Inline C => <<'EOC'; SV* yes () { return &PL_sv_yes; } void get_yes (SV *a) { if (a == &PL_sv_yes) printf("Received PL_sv_yes\n"); else printf("Something else\n"); } EOC get_yes(yes()); $a = yes(); get_yes($a); __END__ Received PL_sv_yes Something else That's because an assignment in the end means that Perl_sv_setsv_flags is called and that wont preserve the pointer. > It seems that overload.pm does it reliably, though I can't see where and > how it achieves it. There doesn't appear to be any shared object > associated with the overload module, so I take it that > PL_sv_yes/no/undef is being assigned from perl-space. The overloading mechanism is deeply hooked into the perl source. Passing around &PL_sv_yes is easy in XS and C. And that's what perl probably does. It puts &PL_sv_yes onto the stack and so your overload handler will receive an intact pointer to PL_sv_yes. You can only do that from Perl-space if you create an XSUB that returns &PL_sv_yes (as shown above). Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval