1 /* This file is part of the Scalar::Vec::Util Perl module.
2 * See http://search.cpan.org/dist/Scalar-Vec-Util/ */
4 #define PERL_NO_GET_CONTEXT
9 #define __PACKAGE__ "Scalar::Vec::Util"
13 STATIC const char svu_error_invarg[] = "Invalid argument";
15 /* --- XS ------------------------------------------------------------------ */
17 MODULE = Scalar::Vec::Util PACKAGE = Scalar::Vec::Util
23 HV *stash = gv_stashpv(__PACKAGE__, 1);
24 newCONSTSUB(stash, "SVU_PP", newSVuv(0));
25 newCONSTSUB(stash, "SVU_SIZE", newSVuv(SVU_SIZE));
29 vfill(SV *sv, SV *ss, SV *sl, SV *sf)
34 if (!SvOK(sv) || !SvOK(ss) || !SvOK(sl) || !SvOK(sf)) {
35 croak(svu_error_invarg);
39 if (!l) { XSRETURN(0); }
42 if (SvTYPE(sv) < SVt_PV) { SvUPGRADE(sv, SVt_PV); }
48 Zero(v + o, n - o, char);
61 vcopy(SV *sf, SV *sfs, SV *st, SV *sts, SV *sl)
63 size_t fs, ts, l, lf = 0, n, o;
66 if (!SvOK(sf) || !SvOK(sfs) || !SvOK(st) || !SvOK(sts) || !SvOK(sl)) {
67 croak(svu_error_invarg);
71 if (!l) { XSRETURN(0); }
74 if (SvTYPE(sf) < SVt_PV) { SvUPGRADE(sf, SVt_PV); }
75 if (SvTYPE(st) < SVt_PV) { SvUPGRADE(st, SVt_PV); }
81 Zero(t + o, n - o, char);
88 f = SvPVX(sf); /* We do it there in case st == sf. */
93 lf = fs + l - o * CHAR_BIT;
94 l = o * CHAR_BIT - fs;
98 bv_move(f, ts, fs, l);
100 bv_copy(t, ts, f, fs, l);
104 bv_fill(t, ts + l, lf, 0);
110 veq(SV *sv1, SV *ss1, SV *sv2, SV *ss2, SV *sl)
112 size_t s1, s2, l, o, n;
115 if (!SvOK(sv1) || !SvOK(ss1) || !SvOK(sv2) || !SvOK(ss2) || !SvOK(sl)) {
116 croak(svu_error_invarg);
122 if (SvTYPE(sv1) < SVt_PV) { SvUPGRADE(sv1, SVt_PV); }
123 if (SvTYPE(sv2) < SVt_PV) { SvUPGRADE(sv2, SVt_PV); }
128 l = o * CHAR_BIT - s1;
134 l = o * CHAR_BIT - s2;
140 RETVAL = newSVuv(bv_eq(v1, s1, v2, s2, l));