X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=MOP.xs;h=e4bdb81f6902cc3eb6adf78c3eee7fb917d58bc8;hb=8a474a03f00135ee9033203dc2170769fc69fae2;hp=8506f362691957a1ccbb7db1d75af2c884af0c67;hpb=cc856b56d46c0867b9585240cc7e3c8b556316b4;p=gitmo%2FClass-MOP.git diff --git a/MOP.xs b/MOP.xs index 8506f36..e4bdb81 100644 --- a/MOP.xs +++ b/MOP.xs @@ -3,6 +3,7 @@ #include "perl.h" #include "XSUB.h" +#define NEED_sv_2pv_flags #define NEED_sv_2pv_nolen #include "ppport.h" @@ -77,6 +78,7 @@ get_all_package_symbols(self, ...) PREINIT: HV *stash = NULL; SV *type_filter = NULL; + register HE *he; PPCODE: switch ( GIMME_V ) { @@ -88,15 +90,10 @@ get_all_package_symbols(self, ...) PUTBACK; - if ( SvROK(self) ) { - SV **val = hv_fetchs((HV *)SvRV(self), "package", 0); - if ( val ) { - stash = gv_stashsv(*val, 0); - } - } + if (SvROK(self) && (he = hv_fetch_ent((HV *)SvRV(self), key_package, 0, hash_package))) + stash = gv_stashsv(HeVAL(he),0); if ( stash ) { - register HE *entry; (void)hv_iterinit(stash); @@ -104,17 +101,16 @@ get_all_package_symbols(self, ...) const char *const type = SvPV_nolen(type_filter); - while ((entry = hv_iternext(stash))) { - SV *const gv = hv_iterval(stash, entry); - SV *const key = hv_iterkeysv(entry); + while ((he = hv_iternext(stash))) { + SV *const gv = HeVAL(he); SV *sv; char *package = HvNAME(stash); STRLEN pkglen = strlen(package); + char *key; + STRLEN keylen; char *fq; STRLEN fqlen; - SPAGAIN; - switch( SvTYPE(gv) ) { case SVt_PVGV: switch (*type) { @@ -129,29 +125,32 @@ get_all_package_symbols(self, ...) break; case SVt_RV: /* BAH! constants are horrible */ - fqlen = pkglen + SvCUR(key) + 3; + key = HePV(he, keylen); + fqlen = pkglen + keylen + 3; fq = (char *)alloca(fqlen); - snprintf(fq, fqlen, "%s::%s", package, SvPV_nolen(key)); + snprintf(fq, fqlen, "%s::%s", package, key); sv = (SV*)get_cv(fq, 0); + sv_2mortal(sv); break; default: continue; } if ( sv ) { + SV *key = hv_iterkeysv(he); SPAGAIN; EXTEND(SP, 2); PUSHs(key); - PUSHs(newRV_noinc(sv)); + PUSHs(sv_2mortal(newRV_inc(sv))); PUTBACK; } } } else { EXTEND(SP, HvKEYS(stash) * 2); - while ((entry = hv_iternext(stash))) { - SV *key = hv_iterkeysv(entry); - SV *sv = hv_iterval(stash, entry); + while ((he = hv_iternext(stash))) { + SV *key = hv_iterkeysv(he); + SV *sv = HeVAL(he); SPAGAIN; PUSHs(key); PUSHs(sv);