GV *to_string = gv_fetchmethod (SvSTASH (sv), "toString"); if (to_string) { dSP; SV *res_sv; /* result scalar */ ENTER; SAVETMPS; /* Declare function arguments */ PUSHMARK (SP); XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); PUTBACK; /* Call in scalar context (G_SCALAR) */ call_sv ((SV *)GvCV (to_string), G_SCALAR); SPAGAIN; /* Fetch returned SV from the stack */ res_sv = POPs; PUTBACK; /* Append returned SvPVX to our SV */ append_sv(res_sv, result); FREETMPS; LEAVE; } #### void func (SV *scalar) PPCODE: SV *result = newSV(INIT_SIZE); sv_setpv(result, ""); SvPOK_only(result); serialize(result, scalar); XPUSHs(result); #### SV* func (SV *scalar) CODE: SV *result = newSV(INIT_SIZE); sv_setpv(result, ""); SvPOK_only(result); serialize(result, scalar); RETVAL = result; OUTPUT: RETVAL