From: Jesse Luehrs Date: Fri, 5 Aug 2011 18:40:43 +0000 (-0500) Subject: macro-ize X-Git-Tag: 0.23~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a829b7a6273ae1d8c7e4c45587bf47d76c066fed;p=gitmo%2FPackage-Stash-XS.git macro-ize --- diff --git a/XS.xs b/XS.xs index ea1a402..2c9639e 100644 --- a/XS.xs +++ b/XS.xs @@ -28,6 +28,30 @@ #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,15 @@ 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; + return SVT_SCALAR(sv_type); 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; }