1 ################################################################################
3 ## Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
4 ## Version 2.x, Copyright (C) 2001, Paul Marquess.
5 ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
7 ## This program is free software; you can redistribute it and/or
8 ## modify it under the same terms as Perl itself.
10 ################################################################################
20 __UNDEFINED__ sv_setuv(sv, uv) \
23 if (TeMpUv <= IV_MAX) \
24 sv_setiv(sv, TeMpUv); \
26 sv_setnv(sv, (double)TeMpUv); \
29 __UNDEFINED__ newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv))
31 __UNDEFINED__ sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv)))
32 __UNDEFINED__ SvUVX(sv) ((UV)SvIVX(sv))
33 __UNDEFINED__ SvUVXx(sv) SvUVX(sv)
34 __UNDEFINED__ SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
35 __UNDEFINED__ SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
38 * Always use the SvUVx() macro instead of sv_uv().
40 __UNDEFINED__ sv_uv(sv) SvUVx(sv)
42 #if !defined(SvUOK) && defined(SvIOK_UV)
43 # define SvUOK(sv) SvIOK_UV(sv)
46 __UNDEFINED__ XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) )
47 __UNDEFINED__ XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END
49 __UNDEFINED__ PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
50 __UNDEFINED__ XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
53 __UNDEFINED__ UTF8_SAFE_SKIP(s, e) (__ASSERT_((e) >= (s)) \
56 : (((e) - (s)) >= UTF8SKIP(s)) \
61 #if !defined(my_strnlen)
62 #if { NEED my_strnlen }
65 my_strnlen(const char *str, Size_t maxlen)
80 #define NEED_my_strnlen
114 RETVAL = SvUVx(++sv);
128 TARG = sv_newmortal();
138 TARG = sv_newmortal();
143 UTF8_SAFE_SKIP(s, adjustment)
147 /* Instead of passing in an 'e' ptr, use the real end, adjusted */
148 RETVAL = UTF8_SAFE_SKIP(s, s + UTF8SKIP(s) + adjustment);
157 RETVAL= my_strnlen(s, max);
163 ok(&Devel::PPPort::sv_setuv(42), 42);
164 ok(&Devel::PPPort::newSVuv(123), 123);
165 ok(&Devel::PPPort::sv_2uv("4711"), 4711);
166 ok(&Devel::PPPort::sv_2uv("1735928559"), 1735928559);
167 ok(&Devel::PPPort::SvUVx("1735928559"), 1735928559);
168 ok(&Devel::PPPort::SvUVx(1735928559), 1735928559);
169 ok(&Devel::PPPort::SvUVx(0xdeadbeef), 0xdeadbeef);
170 ok(&Devel::PPPort::XSRETURN_UV(), 42);
171 ok(&Devel::PPPort::PUSHu(), 42);
172 ok(&Devel::PPPort::XPUSHu(), 43);
173 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", 0), 1);
174 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", -1), 0);
175 ok(&Devel::PPPort::my_strnlen("abc\0def", 7), 3);