X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xs-src%2FMouseAccessor.xs;h=cf40488d8dda8b5a4d237f3737d0fb7c7511b97d;hb=bce7d15517f1e232f5f1c2fe23d72aa13b7d1770;hp=3df9fdaf28223e65ac2dbc37d18e9699d53f0235;hpb=05e658dc1915e54a27d218201b3a9d7314ccdabe;p=gitmo%2FMouse.git diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index 3df9fda..cf40488 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -19,11 +19,9 @@ mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { if(items < 1){ croak("Too few arguments for %s", GvNAME(CvGV(cv))); } - /* NOTE: If self has GETMAGIC, $self->accessor will invoke GETMAGIC - * before calling methods, so SvGETMAGIC(self) is not necessarily needed here. + * before calling methods, so SvGETMAGIC(self) is not required here. */ - return ST(0); } @@ -37,12 +35,14 @@ mouse_accessor_generate(pTHX_ SV* const attr, XSUBADDR_t const accessor_impl){ xsub = newXS(NULL, accessor_impl, __FILE__); sv_2mortal((SV*)xsub); - mg = sv_magicext((SV*)xsub, MOUSE_xa_slot(xa), PERL_MAGIC_ext, &mouse_accessor_vtbl, (char*)xa, HEf_SVKEY); + mg = sv_magicext((SV*)xsub, MOUSE_xa_slot(xa), + PERL_MAGIC_ext, &mouse_accessor_vtbl, (char*)xa, HEf_SVKEY); MOUSE_mg_flags(mg) = (U16)MOUSE_xa_flags(xa); /* NOTE: - * although we use MAGIC for gc, we also store mg to CvXSUBANY for efficiency (gfx) + * although we use MAGIC for gc, we also store mg to + * CvXSUBANY for efficiency (gfx) */ CvXSUBANY(xsub).any_ptr = (void*)mg; @@ -50,17 +50,6 @@ mouse_accessor_generate(pTHX_ SV* const attr, XSUBADDR_t const accessor_impl){ } -#define PUSH_VALUE(value, flags) STMT_START { \ - if((flags) & MOUSEf_ATTR_SHOULD_AUTO_DEREF && GIMME_V == G_ARRAY){ \ - mouse_push_values(aTHX_ value, (flags)); \ - } \ - else{ \ - dSP; \ - XPUSHs(value ? value : &PL_sv_undef); \ - PUTBACK; \ - } \ - } STMT_END \ - /* pushes return values, does auto-deref if needed */ static void mouse_push_values(pTHX_ SV* const value, U16 const flags){ @@ -111,6 +100,18 @@ mouse_push_values(pTHX_ SV* const value, U16 const flags){ PUTBACK; } +STATIC_INLINE void +mouse_push_value(pTHX_ SV* const value, U16 const flags) { + if(flags & MOUSEf_ATTR_SHOULD_AUTO_DEREF && GIMME_V == G_ARRAY){ + mouse_push_values(aTHX_ value, flags); + } + else{ + dSP; + XPUSHs(value ? value : &PL_sv_undef); + PUTBACK; + } +} + static void mouse_attr_get(pTHX_ SV* const self, MAGIC* const mg){ U16 const flags = MOUSE_mg_flags(mg); @@ -123,7 +124,7 @@ mouse_attr_get(pTHX_ SV* const self, MAGIC* const mg){ value = mouse_xa_set_default(aTHX_ MOUSE_mg_xa(mg), self); } - PUSH_VALUE(value, flags); + mouse_push_value(aTHX_ value, flags); } static void @@ -163,7 +164,7 @@ mouse_attr_set(pTHX_ SV* const self, MAGIC* const mg, SV* value){ assert(SvTYPE(value) != SVTYPEMASK); } - PUSH_VALUE(value, flags); + mouse_push_value(aTHX_ value, flags); } XS(XS_Mouse_accessor) @@ -243,18 +244,21 @@ mouse_simple_accessor_generate(pTHX_ MAGIC* mg; if(!fq_name){ - /* anonymous xsubs need sv_2mortal */ + /* anonymous xsubs need sv_2mortal() */ sv_2mortal((SV*)xsub); } - mg = sv_magicext((SV*)xsub, slot, PERL_MAGIC_ext, &mouse_accessor_vtbl, (char*)dptr, dlen); + mg = sv_magicext((SV*)xsub, slot, + PERL_MAGIC_ext, &mouse_accessor_vtbl, (char*)dptr, dlen); + SvREFCNT_dec(slot); /* sv_magicext() increases refcnt in mg_obj */ if(dlen == HEf_SVKEY){ SvREFCNT_dec(dptr); } /* NOTE: - * although we use MAGIC for gc, we also store mg to CvXSUBANY for efficiency (gfx) + * although we use MAGIC for gc, we also store mg to CvXSUBANY + * for efficiency (gfx) */ CvXSUBANY(xsub).any_ptr = (void*)mg;