I havent ever seen a definition of a SV struct that allows you to easily see in a C debugger what the flags/type of an SV is. So I wrote this up.
#define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" struct pMG; typedef struct pMG pMG; struct pMG { XPVMG* sv_any; U32 sv_refcnt; union { U32 sv_flags; struct { unsigned long type : 8; unsigned long f_IOK : 1; unsigned long f_NOK : 1; unsigned long f_POK : 1; unsigned long f_ROK : 1; unsigned long p_IOK: 1; unsigned long p_NOK: 1; unsigned long p_POK : 1; unsigned long p_SCREAM_phv_CLONEABLE_phv_CLONEABLE_prv_PCS +_IMPORTED : 1; unsigned long s_PADSTALE_SVpad_STATE : 1; unsigned long s_PADTMP_SVpad_TYPED : 1; unsigned long s_PADMY_SVpad_OUR : 1; unsigned long s_TEMP : 1; unsigned long s_OBJECT : 1; unsigned long s_GMG : 1; unsigned long s_SMG : 1; unsigned long s_RMG : 1; unsigned long f_FAKE_SVphv_REHASH : 1; unsigned long f_OOK : 1; unsigned long f_BREAK: 1; unsigned long f_READONLY : 1; unsigned long f_AMAGIC : 1; unsigned long f_UTF8_SVphv_SHAREKEYS : 1; unsigned long pav_REAL_phv_LAZYDEL_pbm_VALID_repl_EVAL : 1 +; unsigned long f_IVisUV_pav_REIFY_phv_HASKFLAGS_pfm_COMPILE +D_pbm_TAIL_prv_WEAKREF : 1; } flagsraw; }; union { IV svu_iv; UV svu_uv; pMG* svu_rv; char* svu_pv; pMG** svu_array; HE** svu_hash; GP* svu_gp; } sv_u; }; #define SV pMG
Works on Visual C. Will generate millions of type warnings. Put right after the perl header includes. Makes debugging very easy. The SVANY is a MG struct. LVs are longer. SV type can't be an enum because enums must be 32 bits on MSVC (bad MS!!!).

In reply to Looking at a SV in C by bulk88

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.