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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.