mje has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confusion over B::PV
by ikegami (Patriarch) on May 19, 2012 at 16:52 UTC | |
by mje (Curate) on May 19, 2012 at 17:14 UTC | |
by ikegami (Patriarch) on May 20, 2012 at 03:21 UTC | |
|
Re: Confusion over B::PV (POK)
by tye (Sage) on May 19, 2012 at 17:03 UTC | |
by mje (Curate) on May 19, 2012 at 17:59 UTC | |
by mje (Curate) on May 19, 2012 at 17:29 UTC |