From: Vincent Pit Date: Tue, 25 Aug 2009 23:03:20 +0000 (+0200) Subject: Make svu_validate_uv() return the usable size_t value X-Git-Tag: v0.07~34 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c4a764bda5221cbd26c8a4e719cee49059703af6;p=perl%2Fmodules%2FScalar-Vec-Util.git Make svu_validate_uv() return the usable size_t value Not sure why I didn't do it in the first place. --- diff --git a/Util.xs b/Util.xs index 013bea2..f487539 100644 --- a/Util.xs +++ b/Util.xs @@ -11,31 +11,26 @@ #include "bitvect.h" -STATIC void svu_validate_uv(pTHX_ SV *sv, size_t *offset, const char *desc) { -#define svu_validate_uv(S, O, D) svu_validate_uv(aTHX_ (S), (O), (D)) +STATIC size_t svu_validate_uv(pTHX_ SV *sv, const char *desc) { +#define svu_validate_uv(S, D) svu_validate_uv(aTHX_ (S), (D)) IV i; if (SvOK(sv) && SvIOK(sv)) { if (SvIsUV(sv)) - *offset = SvUVX(sv); + return SvUVX(sv); else { i = SvIVX(sv); - if (i < 0) - goto fail; - *offset = i; + if (i >= 0) + return i; } } else { i = SvIV(sv); - if (i < 0) - goto fail; - *offset = i; + if (i >= 0) + return i; } - return; - -fail: - *offset = 0; croak("Invalid negative %s", desc ? desc : "integer"); + return 0; } /* --- XS ------------------------------------------------------------------ */ @@ -58,10 +53,10 @@ PREINIT: size_t s, l, n, o; char f, *v; CODE: - svu_validate_uv(sl, &l, "length"); + l = svu_validate_uv(sl, "length"); if (!l) XSRETURN(0); - svu_validate_uv(ss, &s, "offset"); + s = svu_validate_uv(ss, "offset"); f = SvTRUE(sf); SvUPGRADE(sv, SVt_PV); @@ -87,11 +82,11 @@ PREINIT: size_t fs, ts, l, lf = 0, n, o; char *t, *f; CODE: - svu_validate_uv(sl, &l, "length"); + l = svu_validate_uv(sl, "length"); if (!l) XSRETURN(0); - svu_validate_uv(sfs, &fs, "offset"); - svu_validate_uv(sts, &ts, "offset"); + fs = svu_validate_uv(sfs, "offset"); + ts = svu_validate_uv(sts, "offset"); SvUPGRADE(sf, SVt_PV); SvUPGRADE(st, SVt_PV); @@ -133,11 +128,11 @@ PREINIT: size_t s1, s2, l, o, n; char *v1, *v2; CODE: - svu_validate_uv(sl, &l, "length"); + l = svu_validate_uv(sl, "length"); if (!l) XSRETURN_YES; - svu_validate_uv(ss1, &s1, "offset"); - svu_validate_uv(ss2, &s2, "offset"); + s1 = svu_validate_uv(ss1, "offset"); + s2 = svu_validate_uv(ss2, "offset"); SvUPGRADE(sv1, SVt_PV); SvUPGRADE(sv2, SVt_PV);