X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2FMouseUtil.xs;h=2e7f50bd83bcdbdf8ed7d16faf777951d9c5bc6b;hp=828982857161ec3e8321fd99180deb1984aa9bcd;hb=5ecfc2defd2955d68c9cbc3ad048ce80bd1020da;hpb=80aa5731d6763d8f38ba0fa057729af7026e6580 diff --git a/xs-src/MouseUtil.xs b/xs-src/MouseUtil.xs index 8289828..2e7f50b 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 */ @@ -196,6 +196,25 @@ mouse_call1 (pTHX_ SV *const self, SV *const method, SV* const arg1) return ret; } +SV* +mouse_get_metaclass_by_name(pTHX_ SV* const metaclass_name){ + CV* const get_metaclass = get_cvs("Mouse::Util::get_metaclass_by_name", TRUE); + SV* metaclass; + dSP; + + 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 +232,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 +286,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 +301,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;