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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.