in reply to perlxs new() returning undef
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:
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).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);
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")
|
|---|