Hi,
How does one set the value from perl-space and from C-space (ie - 2 separate questions) so that 'sv==&PL_sv_yes' returns true ?
I've been testing for that condition as regards the third argument that my 'use overload' xsubs receive - and it has been working flawlessly, Sometimes the condition is true, sometimes not. The condition has always tested as I want and expect, and the response has always been appropriate to the condition. But all my attempts to write code such that 'sv==&PL_sv_yes' returns true have failed.
Here is what I tried:
use warnings;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'EOC';
void set_TRUE(SV * a) { sv_setsv(a, &PL_sv_yes); if(a == &PL_sv_yes) printf("Set to &PL_sv_yes\n"); // Never happens }
void is_TRUE(SV * a) { if(SvTRUE(a)) printf("true : "); else printf("NOT true : ");
if(a == &PL_sv_yes) printf("true\n"); else printf("NOT true\n"); }
EOC
$x = ''; set_TRUE($x);
print $x, "\n";
for(TRUE, $x, 1, '1', '', 0, '0', undef) {is_TRUE($_)}
__END__
prints: 1 true : NOT true true : NOT true true : NOT true NOT true : NOT true NOT true : NOT true NOT true : NOT true NOT true : NOT true
I could perhaps use SvTRUE() to test that "third argument", but for the moment what's really puzzling me is how my current method of testing ever worked to begin with.
Maybe the answer would be apparent if I wrote an overloaded package and then did a Devel::Peek::Dump() of the third argument within the overload function. (I'll do that if necessary.)
Cheers, Rob