First, I find no T_OBJECT in my typemap file. Perhaps you meant T_PTROBJ?

If so, then no, RETVAL= PL_sv__undef isn't the thing to do. When in doubt, use the source! From typemap:

INPUT T_PTROBJ if (sv_derived_from($arg, \"${ntype}\")) { IV tmp = SvIV((SV*)SvRV($arg)); $var = INT2PTR($type,tmp); } else croak(\"$var is not of type ${ntype}\") OUTPUT T_PTROBJ sv_setref_pv($arg, \"${ntype}\", (void*)$var);
so your code ends up doing: sv_setref_pv(ST(0),"cstruct",(void*)&PL_sv__undef); so you'd get a new object that is a blessed reference to undef (well, unless that attempt fails, which it probably does).

You have a couple of ways you can go. You could extend the typemap to handle a failure case:

OUTPUT OUTPUT T_PTROBJ if( NULL != $var ) sv_setref_pv($arg, \"${ntype}\", (void*)$var); else sv_setsv( $arg, &PL_sv__undef );

Or something close to that.

Update: The "other ways" I decided not to describe since they seemed inferior after I saw how easy that was.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: perlxs new() returning undef by tye
in thread perlxs new() returning undef by bmdhacks

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.