X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=mop.c;h=aafaef7581137014397245163a362b193a82e4c2;hb=e347ce3fe9e40dc060e73e07f282729f4191c878;hp=feae85846707ef5a32a5749399210f00b28f7bb5;hpb=95ac09c541e02e77935b0813c045c6e83fd9ad4a;p=gitmo%2FClass-MOP.git diff --git a/mop.c b/mop.c index feae858..aafaef7 100644 --- a/mop.c +++ b/mop.c @@ -1,7 +1,7 @@ #include "mop.h" void -mop_call_xs (pTHX_ void (*subaddr) (pTHX_ CV *), CV *cv, SV **mark) +mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark) { dSP; PUSHMARK(mark); @@ -78,6 +78,8 @@ mop_call0 (pTHX_ SV *const self, SV *const method) int mop_get_code_info (SV *coderef, char **pkg, char **name) { + GV *gv; + if (!SvOK(coderef) || !SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) { return 0; } @@ -93,17 +95,15 @@ mop_get_code_info (SV *coderef, char **pkg, char **name) we hit it without the guard, we segfault. The slightly odd return value strikes me as an improvement (mst) */ -#ifdef isGV_with_GP + if ( isGV_with_GP(CvGV(coderef)) ) { -#endif - *pkg = HvNAME( GvSTASH(CvGV(coderef)) ); - *name = GvNAME( CvGV(coderef) ); -#ifdef isGV_with_GP + gv = CvGV(coderef); + *pkg = HvNAME( GvSTASH(gv) ? GvSTASH(gv) : CvSTASH(coderef) ); + *name = GvNAME( CvGV(coderef) ); } else { - *pkg = "__UNKNOWN__"; - *name = "__ANON__"; + *pkg = "__UNKNOWN__"; + *name = "__ANON__"; } -#endif return 1; } @@ -127,54 +127,31 @@ mop_get_package_symbols (HV *stash, type_filter_t filter, get_package_symbols_cb } while ( (he = hv_iternext(stash)) ) { - SV *const gv = HeVAL(he); - SV *sv = NULL; - char *key; + GV * const gv = (GV*)HeVAL(he); STRLEN keylen; - char *package; - SV *fq; + const char * const key = HePV(he, keylen); + SV *sv = NULL; - switch( SvTYPE(gv) ) { -#ifndef SVt_RV - case SVt_RV: -#endif - case SVt_PV: - case SVt_IV: - /* expand the gv into a real typeglob if it - * contains stub functions and we were asked to - * return CODE symbols */ - if (filter == TYPE_FILTER_CODE) { - if (SvROK(gv)) { - /* we don't really care about the length, - but that's the API */ - key = HePV(he, keylen); - package = HvNAME(stash); - fq = newSVpvf("%s::%s", package, key); - sv = (SV *)get_cv(SvPV_nolen(fq), 0); - break; - } - - key = HePV(he, keylen); - gv_init((GV *)gv, stash, key, keylen, GV_ADDMULTI); - } - /* fall through */ - case SVt_PVGV: - switch (filter) { - case TYPE_FILTER_CODE: sv = (SV *)GvCVu(gv); break; - case TYPE_FILTER_ARRAY: sv = (SV *)GvAV(gv); break; - case TYPE_FILTER_IO: sv = (SV *)GvIO(gv); break; - case TYPE_FILTER_HASH: sv = (SV *)GvHV(gv); break; - case TYPE_FILTER_SCALAR: sv = (SV *)GvSV(gv); break; - default: - croak("Unknown type"); - } - break; - default: - continue; + if(isGV(gv)){ + switch (filter) { + case TYPE_FILTER_CODE: sv = (SV *)GvCVu(gv); break; + case TYPE_FILTER_ARRAY: sv = (SV *)GvAV(gv); break; + case TYPE_FILTER_IO: sv = (SV *)GvIO(gv); break; + case TYPE_FILTER_HASH: sv = (SV *)GvHV(gv); break; + case TYPE_FILTER_SCALAR: sv = (SV *)GvSV(gv); break; + default: + croak("Unknown type"); + } + } + /* expand the gv into a real typeglob if it + * contains stub functions or constants and we + * were asked to return CODE references */ + else if (filter == TYPE_FILTER_CODE) { + gv_init(gv, stash, key, keylen, GV_ADDMULTI); + sv = (SV *)GvCV(gv); } if (sv) { - const char *key = HePV(he, keylen); if (!cb(key, keylen, sv, ud)) { return; } @@ -222,13 +199,13 @@ static struct { DECLARE_KEY(ISA) }; -inline SV * +SV * mop_prehashed_key_for (mop_prehashed_key_t key) { return prehashed_keys[key].key; } -inline U32 +U32 mop_prehashed_hash_for (mop_prehashed_key_t key) { return prehashed_keys[key].hash; @@ -253,7 +230,7 @@ XS(mop_xs_simple_reader) dXSARGS; #endif register HE *he; - mop_prehashed_key_t key = CvXSUBANY(cv).any_i32; + mop_prehashed_key_t key = (mop_prehashed_key_t)CvXSUBANY(cv).any_i32; SV *self; if (items != 1) {