[libmath-prime-util-perl] 91/181: XS tweaks from bulk88
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:10 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit 50b9d5c693cd50290922c1e821916755bdd9ff26
Author: Dana Jacobsen <dana at acm.org>
Date: Wed Jan 1 01:23:08 2014 -0800
XS tweaks from bulk88
---
XS.xs | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/XS.xs b/XS.xs
index 3ce3d02..d681e8c 100644
--- a/XS.xs
+++ b/XS.xs
@@ -89,16 +89,21 @@ static int _validate_int(pTHX_ SV* n, int negok)
int ret, isneg = 0;
/* TODO: magic, grok_number, etc. */
- /* fix multiple magic aware Sv*V getters */
- if (SvGAMAGIC(n)) return 0; /* Leave while we still can */
- if (!SvOK(n)) croak("Parameter must be defined");
- if (SvIOK(n)) { /* If defined as number, use that */
- if (SvIsUV(n) || SvIV(n) >= 0) return 1;
+ if ((SvFLAGS(n) & (SVf_IOK |
+#if PERL_REVISION >=5 && PERL_VERSION >= 9 && PERL_SUBVERSION >= 4
+ SVf_ROK |
+#else
+ SVf_AMAGIC |
+#endif
+ SVs_GMG )) == SVf_IOK) { /* If defined as number, use it */
+ if (SvIsUV(n) || SvIVX(n) >= 0) return 1; /* The normal case */
if (negok) return -1;
- else croak("Parameter '%" SVf "' must be a positive integer", n);
+ else croak("Parameter '%" SVf "' must be a positive integer", n);
}
+ if (SvGAMAGIC(n)) return 0; /* Leave while we still can */
+ if (!SvOK(n)) croak("Parameter must be defined");
if (SvROK(n) && !sv_isa(n, "Math::BigInt")) return 0;
- ptr = SvPV(n, len); /* Includes stringifying bigints */
+ ptr = SvPV_nomg(n, len); /* Includes stringifying bigints */
if (len == 0 || ptr == 0) croak("Parameter must be a positive integer");
if (ptr[0] == '-' && negok) {
isneg = 1; ptr++; len--; /* Read negative sign */
@@ -684,7 +689,7 @@ carmichael_lambda(IN SV* svn)
}
return; /* skip implicit PUTBACK */
-int
+bool
_validate_num(SV* svn, ...)
PREINIT:
SV* sv1;
@@ -694,8 +699,9 @@ _validate_num(SV* svn, ...)
* $is_valid = _validate_num( $n [, $min [, $max] ] )
* Return 0 if we're befuddled by the input.
* Otherwise croak if n isn't >= 0 and integer, n < min, or n > max.
+ * Small bigints will be converted to scalars.
*/
- RETVAL = 0;
+ RETVAL = FALSE;
if (_validate_int(aTHX_ svn, 0)) {
if (SvROK(svn)) { /* Convert small Math::BigInt object into scalar */
UV n = my_svuv(svn);
@@ -713,7 +719,7 @@ _validate_num(SV* svn, ...)
MPUassert( items <= 3, "_validate_num takes at most 3 parameters");
}
}
- RETVAL = 1;
+ RETVAL = TRUE;
}
OUTPUT:
RETVAL
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list