#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);
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)) );
+ GV *gv = CvGV(coderef);
+ *pkg = HvNAME( GvSTASH(gv) ? GvSTASH(gv) : CvSTASH(coderef) );
*name = GvNAME( CvGV(coderef) );
-#ifdef isGV_with_GP
} else {
*pkg = "__UNKNOWN__";
*name = "__ANON__";
}
-#endif
return 1;
}
but that's the API */
key = HePV(he, keylen);
package = HvNAME(stash);
- fq = newSVpvf("%s::%s", package, key);
+ fq = sv_2mortal(newSVpvf("%s::%s", package, key));
sv = (SV *)get_cv(SvPV_nolen(fq), 0);
break;
}
return ret;
}
+#define DECLARE_KEY(name) { #name, #name, NULL, 0 }
+#define DECLARE_KEY_WITH_VALUE(name, value) { #name, value, NULL, 0 }
+
/* the order of these has to match with those in mop.h */
static struct {
const char *name;
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;
mop_prehash_keys ()
{
int i;
-
for (i = 0; i < key_last; i++) {
const char *value = prehashed_keys[i].value;
prehashed_keys[i].key = newSVpv(value, strlen(value));
}
}
-SV *
-mop_simple_reader (SV *self, mop_prehashed_key_t key)
+XS(mop_xs_simple_reader)
{
+#ifdef dVAR
+ dVAR; dXSARGS;
+#else
+ dXSARGS;
+#endif
register HE *he;
+ mop_prehashed_key_t key = (mop_prehashed_key_t)CvXSUBANY(cv).any_i32;
+ SV *self;
+
+ if (items != 1) {
+ croak("expected exactly one argument");
+ }
+
+ self = ST(0);
if (!SvROK(self)) {
croak("can't call %s as a class method", prehashed_keys[key].name);
croak("object is not a hashref");
}
- if (!(he = hv_fetch_ent((HV *)SvRV(self), prehashed_keys[key].key, 0, prehashed_keys[key].hash))) {
- return &PL_sv_undef;
+ if ((he = hv_fetch_ent((HV *)SvRV(self), prehashed_keys[key].key, 0, prehashed_keys[key].hash))) {
+ ST(0) = HeVAL(he);
}
-
- return SvREFCNT_inc(HeVAL(he));
-}
-
-XS(mop_xs_simple_reader)
-{
-#ifdef dVAR
- dVAR; dXSARGS;
-#else
- dXSARGS;
-#endif
-
- if (items != 1) {
- croak("expected exactly one argument");
+ else {
+ ST(0) = &PL_sv_undef;
}
- ST(0) = mop_simple_reader (ST(0), CvXSUBANY(cv).any_i32);
- sv_2mortal(ST(0));
XSRETURN(1);
}