Package symbol manipulators into XS
[gitmo/Class-MOP.git] / mop.c
diff --git a/mop.c b/mop.c
index 19b90bc..dfb178b 100644 (file)
--- 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);
@@ -96,7 +96,8 @@ mop_get_code_info (SV *coderef, char **pkg, char **name)
 #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 {
@@ -149,7 +150,7 @@ mop_get_package_symbols (HV *stash, type_filter_t filter, get_package_symbols_cb
                            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;
                     }
@@ -202,6 +203,9 @@ mop_get_all_package_symbols (HV *stash, type_filter_t filter)
     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;
@@ -219,13 +223,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;
@@ -235,7 +239,6 @@ void
 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));
@@ -251,7 +254,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) {