changelog
[gitmo/Package-Stash-XS.git] / XS.xs
diff --git a/XS.xs b/XS.xs
index ea1a402..8c84081 100644 (file)
--- a/XS.xs
+++ b/XS.xs
 #define GvCV_set(gv, cv) (GvCV(gv) = (CV*)(cv))
 #endif
 
+#ifndef SVT_SCALAR
+#define SVT_SCALAR(svt) (svt <= SVt_PVLV)
+#endif
+
+#ifndef SVT_ARRAY
+#define SVT_ARRAY(svt) (svt == SVt_PVAV)
+#endif
+
+#ifndef SVT_HASH
+#define SVT_HASH(svt) (svt == SVt_PVHV)
+#endif
+
+#ifndef SVT_CODE
+#define SVT_CODE(svt) (svt == SVt_PVCV)
+#endif
+
+#ifndef SVT_IO
+#define SVT_IO(svt) (svt == SVt_PVIO)
+#endif
+
+#ifndef SVT_FORMAT
+#define SVT_FORMAT(svt) (svt == SVt_PVFM)
+#endif
+
 /* HACK: scalar slots are always populated on perl < 5.10, so treat undef
  * as nonexistent. this is consistent with the previous behavior of the pure
  * perl version of this module (since this is the behavior that perl sees
@@ -217,17 +241,19 @@ static int _valid_for_type(SV *value, vartype_t type)
 
     switch (type) {
     case VAR_SCALAR:
-        return sv_type != SVt_PVAV && sv_type != SVt_PVHV &&
-               sv_type != SVt_PVCV && sv_type != SVt_PVFM &&
-               sv_type != SVt_PVIO;
+        /* XXX is a glob a scalar? assigning a glob to the scalar slot seems
+         * to work here, but in pure perl i'm pretty sure it goes to the EGV
+         * slot, which seems more correct to me. just disable it for now
+         * i guess */
+        return SVT_SCALAR(sv_type) && sv_type != SVt_PVGV;
     case VAR_ARRAY:
-        return sv_type == SVt_PVAV;
+        return SVT_ARRAY(sv_type);
     case VAR_HASH:
-        return sv_type == SVt_PVHV;
+        return SVT_HASH(sv_type);
     case VAR_CODE:
-        return sv_type == SVt_PVCV;
+        return SVT_CODE(sv_type);
     case VAR_IO:
-        return sv_type == SVt_PVIO;
+        return SVT_IO(sv_type);
     default:
         return 0;
     }