This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Provide __ASSERT_
[perl5.git] / dist / Devel-PPPort / parts / inc / uv
CommitLineData
adfe19db
MHM
1################################################################################
2##
b2049988 3## Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
adfe19db
MHM
4## Version 2.x, Copyright (C) 2001, Paul Marquess.
5## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
6##
7## This program is free software; you can redistribute it and/or
8## modify it under the same terms as Perl itself.
9##
10################################################################################
11
12=provides
13
adfe19db 14__UNDEFINED__
679ad62d 15SvUOK
adfe19db
MHM
16
17=implementation
18
0d0f8426
MHM
19__UNDEFINED__ sv_setuv(sv, uv) \
20 STMT_START { \
21 UV TeMpUv = uv; \
22 if (TeMpUv <= IV_MAX) \
23 sv_setiv(sv, TeMpUv); \
24 else \
25 sv_setnv(sv, (double)TeMpUv); \
26 } STMT_END
27
28__UNDEFINED__ newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv))
adfe19db
MHM
29
30__UNDEFINED__ sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv)))
31__UNDEFINED__ SvUVX(sv) ((UV)SvIVX(sv))
32__UNDEFINED__ SvUVXx(sv) SvUVX(sv)
33__UNDEFINED__ SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
34__UNDEFINED__ SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
35
36/* Hint: sv_uv
37 * Always use the SvUVx() macro instead of sv_uv().
38 */
39__UNDEFINED__ sv_uv(sv) SvUVx(sv)
40
679ad62d
MHM
41#if !defined(SvUOK) && defined(SvIOK_UV)
42# define SvUOK(sv) SvIOK_UV(sv)
43#endif
44
adfe19db
MHM
45__UNDEFINED__ XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) )
46__UNDEFINED__ XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END
47
96ad942f
MHM
48__UNDEFINED__ PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
49__UNDEFINED__ XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
50
adfe19db
MHM
51=xsubs
52
53SV *
54sv_setuv(uv)
b2049988
MHM
55 UV uv
56 CODE:
57 RETVAL = newSViv(1);
58 sv_setuv(RETVAL, uv);
59 OUTPUT:
60 RETVAL
adfe19db
MHM
61
62SV *
63newSVuv(uv)
b2049988
MHM
64 UV uv
65 CODE:
66 RETVAL = newSVuv(uv);
67 OUTPUT:
68 RETVAL
adfe19db
MHM
69
70UV
71sv_2uv(sv)
b2049988
MHM
72 SV *sv
73 CODE:
74 RETVAL = sv_2uv(sv);
75 OUTPUT:
76 RETVAL
adfe19db
MHM
77
78UV
79SvUVx(sv)
b2049988
MHM
80 SV *sv
81 CODE:
82 sv--;
83 RETVAL = SvUVx(++sv);
84 OUTPUT:
85 RETVAL
adfe19db
MHM
86
87void
88XSRETURN_UV()
b2049988
MHM
89 PPCODE:
90 XSRETURN_UV(42);
adfe19db 91
96ad942f
MHM
92void
93PUSHu()
b2049988
MHM
94 PREINIT:
95 dTARG;
96 PPCODE:
97 TARG = sv_newmortal();
98 EXTEND(SP, 1);
99 PUSHu(42);
100 XSRETURN(1);
96ad942f
MHM
101
102void
103XPUSHu()
b2049988
MHM
104 PREINIT:
105 dTARG;
106 PPCODE:
107 TARG = sv_newmortal();
108 XPUSHu(43);
109 XSRETURN(1);
96ad942f
MHM
110
111=tests plan => 10
adfe19db
MHM
112
113ok(&Devel::PPPort::sv_setuv(42), 42);
114ok(&Devel::PPPort::newSVuv(123), 123);
115ok(&Devel::PPPort::sv_2uv("4711"), 4711);
116ok(&Devel::PPPort::sv_2uv("1735928559"), 1735928559);
117ok(&Devel::PPPort::SvUVx("1735928559"), 1735928559);
118ok(&Devel::PPPort::SvUVx(1735928559), 1735928559);
119ok(&Devel::PPPort::SvUVx(0xdeadbeef), 0xdeadbeef);
120ok(&Devel::PPPort::XSRETURN_UV(), 42);
96ad942f
MHM
121ok(&Devel::PPPort::PUSHu(), 42);
122ok(&Devel::PPPort::XPUSHu(), 43);