X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2FMouseUtil.xs;h=f99c6f6a1e9a0a11b3bbda5cbb1b3b783463e361;hp=828982857161ec3e8321fd99180deb1984aa9bcd;hb=0aad026606f2d1d5d27cfb8824dd182f790fa9e2;hpb=80aa5731d6763d8f38ba0fa057729af7026e6580 diff --git a/xs-src/MouseUtil.xs b/xs-src/MouseUtil.xs index 8289828..f99c6f6 100644 --- a/xs-src/MouseUtil.xs +++ b/xs-src/MouseUtil.xs @@ -21,8 +21,8 @@ mouse_mro_get_linear_isa(pTHX_ HV* const stash){ return isa; /* returns the cache if available */ } else{ - SvREADONLY_off(isa); - av_clear(isa); + SvREFCNT_dec(isa); + GvAV(cachegv) = isa = newAV(); } get_linear_isa = get_cv("Mouse::Util::get_linear_isa", TRUE); @@ -65,7 +65,7 @@ mouse_mro_get_linear_isa(pTHX_ HV* const stash){ } sv_setiv(gen, (IV)mro_get_pkg_gen(stash)); - return GvAV(cachegv); + return isa; } #endif /* !no_mor_get_linear_isa */ @@ -156,9 +156,8 @@ mouse_is_class_loaded(pTHX_ SV * const klass){ } -SV * -mouse_call0 (pTHX_ SV *const self, SV *const method) -{ +SV* +mouse_call0 (pTHX_ SV* const self, SV* const method) { dSP; SV *ret; @@ -175,9 +174,8 @@ mouse_call0 (pTHX_ SV *const self, SV *const method) return ret; } -SV * -mouse_call1 (pTHX_ SV *const self, SV *const method, SV* const arg1) -{ +SV* +mouse_call1 (pTHX_ SV* const self, SV* const method, SV* const arg1) { dSP; SV *ret; @@ -196,6 +194,39 @@ mouse_call1 (pTHX_ SV *const self, SV *const method, SV* const arg1) return ret; } +int +mouse_predicate_call(pTHX_ SV* const self, SV* const method) { + SV* const value = mcall0(self, method); + return SvTRUE(value); +} + +SV* +mouse_get_metaclass(pTHX_ SV* metaclass_name){ + CV* const get_metaclass = get_cvs("Mouse::Util::get_metaclass_by_name", TRUE); + SV* metaclass; + dSP; + + assert(metaclass_name); + if(IsObject(metaclass_name)){ + HV* const stash = SvSTASH(metaclass_name); + + metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); + sv_2mortal(metaclass_name); + } + + PUSHMARK(SP); + XPUSHs(metaclass_name); + PUTBACK; + + call_sv((SV*)get_metaclass, G_SCALAR); + + SPAGAIN; + metaclass = POPs; + PUTBACK; + + return metaclass; +} + MAGIC* mouse_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags){ MAGIC* mg; @@ -213,6 +244,21 @@ mouse_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags){ return NULL; } +GV* +mouse_stash_fetch(pTHX_ HV* const stash, const char* const name, I32 const namelen, I32 const create) { + GV** const gvp = (GV**)hv_fetch(stash, name, namelen, create); + + if(gvp){ + if(!isGV(*gvp)){ + gv_init(*gvp, stash, name, namelen, GV_ADDMULTI); + } + return *gvp; + } + else{ + return NULL; + } +} + MODULE = Mouse::Util PACKAGE = Mouse::Util PROTOTYPES: DISABLE @@ -252,7 +298,9 @@ get_code_ref(SV* package, SV* name) CODE: { HV* stash; - HE* he; + STRLEN name_len; + const char* name_pv; + GV* gv; if(!SvOK(package)){ croak("You must define a package name"); @@ -265,19 +313,10 @@ CODE: if(!stash){ XSRETURN_UNDEF; } - he = hv_fetch_ent(stash, name, FALSE, 0U); - if(he){ - GV* const gv = (GV*)hv_iterval(stash, he); - if(!isGV(gv)){ /* special constant or stub */ - STRLEN len; - const char* const pv = SvPV_const(name, len); - gv_init(gv, stash, pv, len, GV_ADDMULTI); - } - RETVAL = GvCVu(gv); - } - else{ - RETVAL = NULL; - } + + name_pv = SvPV_const(name, name_len); + gv = stash_fetch(stash, name_pv, name_len, FALSE); + RETVAL = gv ? GvCVu(gv) : NULL; if(!RETVAL){ XSRETURN_UNDEF;