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