If you have control over the free/destroy portion, and your code looks like you do, why not keep the struct in a scalar or SV as a string? If its inside an object, there is a implicit guarantee not to look at it from Perl (and it would be an error to crack open the object). This way you get Perls reference counting system and you can vaguely visually guess if something is null or not in that struct from Perl's debugger.

Its very easy manipulate blessed hash objects from XS. Just use "self" and "HV * self" and then do hv_fetch'es on it. If you want to be extra safe (and slower), make your own typemap entry and your own type that does a sv_derived_from (look at Perl's default typemap), and finally a "#define MYHVTYPE HV" to trick XSPP not to overwrite the default HV * typemap entry. XS typemaps are evaled as the inside of a double quotes expression by XSPP. "${\'some string'}" or " ".(1 == 2 ? "true" : "false"). " " work. In the 2nd typemap example, I broke the double quotes and put in raw perl code. Step through output_init in ParseXS.pm and you'll see the eval XSPP makes. Not 100% if all the details above are correct, but theories are correct.

In reply to Re: Mixing C and perl by bulk88
in thread Mixing C and perl by jpl

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.