I am attempting to fix some XS code and have reached a point where I'm slightly confused with the output of B::PV. The XS code now does a sv_setsv(sv, 100) (it used to do a sv_setpvn) and the test code is:
use Devel::Peek; use B qw( svref_2object SVf_IOK SVf_NOK SVf_POK ); sub is_iv { my $sv = svref_2object(my $ref = \$_[0]); my $flags = $sv->FLAGS; my $x = $sv->PV; if (wantarray) { return ($flags & SVf_IOK, $x); } else { return $flags & SVf_IOK; } } # code to connect to database here $sth = $dbh->prepare(q/select a from PERL_DBD_drop_me/); $sth->execute; $sth->bind_col(1, \$r, {TYPE => SQL_INTEGER}); $sth->fetch; # this will do a sv_setiv($r, 100) is($r, 100, "correct value returned SQL_INTEGER") or Dump($r); my ($iv, $pv) = is_iv($r); ok($iv, "ivok bind integer") or Dump($r); ok($pv, "pv not null bind integer") or Dump($r);
The output is:
not ok 10 - pv not null bind integer # Failed test 'pv not null bind integer' # at t/sql_type_cast.t line 149. SV = PVIV(0x9f81420) at 0xa1353f4 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 100 PV = 0xa23fd88 "100"\0 # <--- should this be set? CUR = 3 LEN = 4
I am unsure why B::PV returns undef. Could someone explain this? Thanks.
In reply to Confusion over B::PV by mje
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |