Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* sv.h |
79072805 | 2 | * |
eb1102fc | 3 | * Copyright (c) 1991-2002, Larry Wall |
79072805 LW |
4 | * |
5 | * You may distribute under the terms of either the GNU General Public | |
6 | * License or the Artistic License, as specified in the README file. | |
7 | * | |
79072805 LW |
8 | */ |
9 | ||
a0d0e21e LW |
10 | #ifdef sv_flags |
11 | #undef sv_flags /* Convex has this in <signal.h> for sigvec() */ | |
12 | #endif | |
13 | ||
954c1994 | 14 | /* |
ccfc67b7 JH |
15 | =head1 SV Flags |
16 | ||
954c1994 | 17 | =for apidoc AmU||svtype |
8cf8f3d1 | 18 | An enum of flags for Perl types. These are found in the file B<sv.h> |
954c1994 GS |
19 | in the C<svtype> enum. Test these flags with the C<SvTYPE> macro. |
20 | ||
21 | =for apidoc AmU||SVt_PV | |
22 | Pointer type flag for scalars. See C<svtype>. | |
23 | ||
24 | =for apidoc AmU||SVt_IV | |
25 | Integer type flag for scalars. See C<svtype>. | |
26 | ||
27 | =for apidoc AmU||SVt_NV | |
28 | Double type flag for scalars. See C<svtype>. | |
29 | ||
30 | =for apidoc AmU||SVt_PVMG | |
31 | Type flag for blessed scalars. See C<svtype>. | |
32 | ||
33 | =for apidoc AmU||SVt_PVAV | |
34 | Type flag for arrays. See C<svtype>. | |
35 | ||
36 | =for apidoc AmU||SVt_PVHV | |
37 | Type flag for hashes. See C<svtype>. | |
38 | ||
39 | =for apidoc AmU||SVt_PVCV | |
40 | Type flag for code refs. See C<svtype>. | |
41 | ||
42 | =cut | |
43 | */ | |
44 | ||
79072805 | 45 | typedef enum { |
a0d0e21e LW |
46 | SVt_NULL, /* 0 */ |
47 | SVt_IV, /* 1 */ | |
48 | SVt_NV, /* 2 */ | |
49 | SVt_RV, /* 3 */ | |
50 | SVt_PV, /* 4 */ | |
51 | SVt_PVIV, /* 5 */ | |
52 | SVt_PVNV, /* 6 */ | |
53 | SVt_PVMG, /* 7 */ | |
54 | SVt_PVBM, /* 8 */ | |
55 | SVt_PVLV, /* 9 */ | |
56 | SVt_PVAV, /* 10 */ | |
57 | SVt_PVHV, /* 11 */ | |
58 | SVt_PVCV, /* 12 */ | |
59 | SVt_PVGV, /* 13 */ | |
60 | SVt_PVFM, /* 14 */ | |
61 | SVt_PVIO /* 15 */ | |
79072805 LW |
62 | } svtype; |
63 | ||
79072805 LW |
64 | /* Using C's structural equivalence to help emulate C++ inheritance here... */ |
65 | ||
5e045b90 | 66 | struct STRUCT_SV { /* struct sv { */ |
463ee0b2 | 67 | void* sv_any; /* pointer to something */ |
79072805 | 68 | U32 sv_refcnt; /* how many references to us */ |
8990e307 | 69 | U32 sv_flags; /* what we are */ |
79072805 LW |
70 | }; |
71 | ||
72 | struct gv { | |
463ee0b2 | 73 | XPVGV* sv_any; /* pointer to something */ |
79072805 | 74 | U32 sv_refcnt; /* how many references to us */ |
8990e307 | 75 | U32 sv_flags; /* what we are */ |
79072805 LW |
76 | }; |
77 | ||
78 | struct cv { | |
232e078e | 79 | XPVCV* sv_any; /* pointer to something */ |
79072805 | 80 | U32 sv_refcnt; /* how many references to us */ |
8990e307 | 81 | U32 sv_flags; /* what we are */ |
79072805 LW |
82 | }; |
83 | ||
84 | struct av { | |
463ee0b2 | 85 | XPVAV* sv_any; /* pointer to something */ |
79072805 | 86 | U32 sv_refcnt; /* how many references to us */ |
8990e307 | 87 | U32 sv_flags; /* what we are */ |
79072805 LW |
88 | }; |
89 | ||
90 | struct hv { | |
463ee0b2 | 91 | XPVHV* sv_any; /* pointer to something */ |
79072805 | 92 | U32 sv_refcnt; /* how many references to us */ |
8990e307 LW |
93 | U32 sv_flags; /* what we are */ |
94 | }; | |
95 | ||
96 | struct io { | |
97 | XPVIO* sv_any; /* pointer to something */ | |
98 | U32 sv_refcnt; /* how many references to us */ | |
99 | U32 sv_flags; /* what we are */ | |
79072805 LW |
100 | }; |
101 | ||
954c1994 | 102 | /* |
ccfc67b7 JH |
103 | =head1 SV Manipulation Functions |
104 | ||
954c1994 GS |
105 | =for apidoc Am|U32|SvREFCNT|SV* sv |
106 | Returns the value of the object's reference count. | |
107 | ||
108 | =for apidoc Am|SV*|SvREFCNT_inc|SV* sv | |
109 | Increments the reference count of the given SV. | |
110 | ||
111 | =for apidoc Am|void|SvREFCNT_dec|SV* sv | |
112 | Decrements the reference count of the given SV. | |
113 | ||
114 | =for apidoc Am|svtype|SvTYPE|SV* sv | |
115 | Returns the type of the SV. See C<svtype>. | |
116 | ||
117 | =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type | |
118 | Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to | |
119 | perform the upgrade if necessary. See C<svtype>. | |
120 | ||
121 | =cut | |
122 | */ | |
123 | ||
463ee0b2 | 124 | #define SvANY(sv) (sv)->sv_any |
79072805 | 125 | #define SvFLAGS(sv) (sv)->sv_flags |
aeea060c | 126 | #define SvREFCNT(sv) (sv)->sv_refcnt |
a863c7d1 | 127 | |
4d1ff10f | 128 | #ifdef USE_5005THREADS |
dce16143 | 129 | |
3d35f11b GS |
130 | # if defined(VMS) |
131 | # define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count) | |
132 | # define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count)) | |
133 | # else | |
134 | # ifdef EMULATE_ATOMIC_REFCOUNTS | |
135 | # define ATOMIC_INC(count) STMT_START { \ | |
136 | MUTEX_LOCK(&PL_svref_mutex); \ | |
137 | ++count; \ | |
138 | MUTEX_UNLOCK(&PL_svref_mutex); \ | |
139 | } STMT_END | |
140 | # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \ | |
141 | MUTEX_LOCK(&PL_svref_mutex); \ | |
142 | res = (--count == 0); \ | |
143 | MUTEX_UNLOCK(&PL_svref_mutex); \ | |
144 | } STMT_END | |
145 | # else | |
146 | # define ATOMIC_INC(count) atomic_inc(&count) | |
147 | # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count)) | |
148 | # endif /* EMULATE_ATOMIC_REFCOUNTS */ | |
149 | # endif /* VMS */ | |
dce16143 MB |
150 | #else |
151 | # define ATOMIC_INC(count) (++count) | |
83b0a010 | 152 | # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0)) |
4d1ff10f | 153 | #endif /* USE_5005THREADS */ |
dce16143 | 154 | |
5b7ea690 | 155 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC) |
dce16143 MB |
156 | # define SvREFCNT_inc(sv) \ |
157 | ({ \ | |
158 | SV *nsv = (SV*)(sv); \ | |
159 | if (nsv) \ | |
160 | ATOMIC_INC(SvREFCNT(nsv)); \ | |
161 | nsv; \ | |
162 | }) | |
8990e307 | 163 | #else |
9ede5bc8 | 164 | # ifdef USE_5005THREADS |
3d35f11b GS |
165 | # if defined(VMS) && defined(__ALPHA) |
166 | # define SvREFCNT_inc(sv) \ | |
167 | (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv) | |
168 | # else | |
169 | # define SvREFCNT_inc(sv) sv_newref((SV*)sv) | |
170 | # endif | |
a863c7d1 | 171 | # else |
dce16143 | 172 | # define SvREFCNT_inc(sv) \ |
6b88bc9c | 173 | ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv) |
a863c7d1 | 174 | # endif |
8990e307 LW |
175 | #endif |
176 | ||
91f3b821 | 177 | #define SvREFCNT_dec(sv) sv_free((SV*)(sv)) |
a863c7d1 | 178 | |
8990e307 LW |
179 | #define SVTYPEMASK 0xff |
180 | #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) | |
79072805 LW |
181 | |
182 | #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt)) | |
183 | ||
8990e307 LW |
184 | #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */ |
185 | #define SVs_PADTMP 0x00000200 /* in use as tmp */ | |
186 | #define SVs_PADMY 0x00000400 /* in use a "my" variable */ | |
187 | #define SVs_TEMP 0x00000800 /* string is stealable? */ | |
188 | #define SVs_OBJECT 0x00001000 /* is "blessed" */ | |
189 | #define SVs_GMG 0x00002000 /* has magical get method */ | |
190 | #define SVs_SMG 0x00004000 /* has magical set method */ | |
191 | #define SVs_RMG 0x00008000 /* has random magical methods */ | |
192 | ||
193 | #define SVf_IOK 0x00010000 /* has valid public integer value */ | |
194 | #define SVf_NOK 0x00020000 /* has valid public numeric value */ | |
195 | #define SVf_POK 0x00040000 /* has valid public pointer value */ | |
196 | #define SVf_ROK 0x00080000 /* has a valid reference pointer */ | |
a0d0e21e | 197 | |
748a9306 | 198 | #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */ |
8990e307 | 199 | #define SVf_OOK 0x00200000 /* has valid offset value */ |
645c22ef DM |
200 | #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used |
201 | * by SV's in final arena cleanup */ | |
8990e307 LW |
202 | #define SVf_READONLY 0x00800000 /* may not be modified */ |
203 | ||
a0d0e21e | 204 | |
8990e307 LW |
205 | #define SVp_IOK 0x01000000 /* has valid non-public integer value */ |
206 | #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ | |
207 | #define SVp_POK 0x04000000 /* has valid non-public pointer value */ | |
208 | #define SVp_SCREAM 0x08000000 /* has been studied? */ | |
209 | ||
5b7ea690 | 210 | #define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded */ |
5bc28da9 | 211 | |
430eacda | 212 | #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE) |
5bc28da9 | 213 | |
a0d0e21e LW |
214 | #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ |
215 | SVp_IOK|SVp_NOK|SVp_POK) | |
216 | ||
9e7bc3e8 | 217 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ |
a0d0e21e | 218 | |
c240c76d | 219 | #define PRIVSHIFT 8 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */ |
8990e307 LW |
220 | |
221 | /* Some private flags. */ | |
222 | ||
f472eb5c | 223 | /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */ |
032d6771 | 224 | #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */ |
524189f1 | 225 | #define SVpad_TYPED 0x40000000 /* Typed Lexical */ |
032d6771 | 226 | |
25da4f38 IZ |
227 | #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */ |
228 | ||
229 | #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */ | |
8990e307 LW |
230 | |
231 | #define SVpbm_VALID 0x80000000 | |
bbce6d69 | 232 | #define SVpbm_TAIL 0x40000000 |
8990e307 | 233 | |
25da4f38 IZ |
234 | #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */ |
235 | ||
6bfc225d | 236 | #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ |
51594c39 | 237 | #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ |
19692e8d | 238 | #define SVphv_HASKFLAGS 0x80000000 /* keys have flag byte after hash */ |
bf6bd887 | 239 | |
810b8aa5 GS |
240 | #define SVprv_WEAKREF 0x80000000 /* Weak reference */ |
241 | ||
ed6116ce LW |
242 | struct xrv { |
243 | SV * xrv_rv; /* pointer to another SV */ | |
244 | }; | |
245 | ||
79072805 | 246 | struct xpv { |
ed6116ce LW |
247 | char * xpv_pv; /* pointer to malloced string */ |
248 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
249 | STRLEN xpv_len; /* allocated size */ | |
79072805 LW |
250 | }; |
251 | ||
252 | struct xpviv { | |
ed6116ce LW |
253 | char * xpv_pv; /* pointer to malloced string */ |
254 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
255 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 256 | IV xiv_iv; /* integer value or pv offset */ |
79072805 LW |
257 | }; |
258 | ||
ff68c719 | 259 | struct xpvuv { |
260 | char * xpv_pv; /* pointer to malloced string */ | |
261 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
262 | STRLEN xpv_len; /* allocated size */ | |
263 | UV xuv_uv; /* unsigned value or pv offset */ | |
264 | }; | |
265 | ||
79072805 | 266 | struct xpvnv { |
ed6116ce LW |
267 | char * xpv_pv; /* pointer to malloced string */ |
268 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
269 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 270 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 271 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
272 | }; |
273 | ||
6ee623d5 | 274 | /* These structure must match the beginning of struct xpvhv in hv.h. */ |
79072805 | 275 | struct xpvmg { |
ed6116ce LW |
276 | char * xpv_pv; /* pointer to malloced string */ |
277 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
278 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 279 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 280 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
281 | MAGIC* xmg_magic; /* linked list of magicalness */ |
282 | HV* xmg_stash; /* class package */ | |
283 | }; | |
284 | ||
285 | struct xpvlv { | |
ed6116ce LW |
286 | char * xpv_pv; /* pointer to malloced string */ |
287 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
288 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 289 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 290 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
291 | MAGIC* xmg_magic; /* linked list of magicalness */ |
292 | HV* xmg_stash; /* class package */ | |
8990e307 | 293 | |
79072805 LW |
294 | STRLEN xlv_targoff; |
295 | STRLEN xlv_targlen; | |
296 | SV* xlv_targ; | |
297 | char xlv_type; | |
298 | }; | |
299 | ||
300 | struct xpvgv { | |
ed6116ce LW |
301 | char * xpv_pv; /* pointer to malloced string */ |
302 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
303 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 304 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 305 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
306 | MAGIC* xmg_magic; /* linked list of magicalness */ |
307 | HV* xmg_stash; /* class package */ | |
8990e307 | 308 | |
79072805 LW |
309 | GP* xgv_gp; |
310 | char* xgv_name; | |
311 | STRLEN xgv_namelen; | |
312 | HV* xgv_stash; | |
a5f75d66 | 313 | U8 xgv_flags; |
79072805 LW |
314 | }; |
315 | ||
316 | struct xpvbm { | |
ed6116ce LW |
317 | char * xpv_pv; /* pointer to malloced string */ |
318 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
319 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 320 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 321 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
322 | MAGIC* xmg_magic; /* linked list of magicalness */ |
323 | HV* xmg_stash; /* class package */ | |
8990e307 | 324 | |
79072805 LW |
325 | I32 xbm_useful; /* is this constant pattern being useful? */ |
326 | U16 xbm_previous; /* how many characters in string before rare? */ | |
327 | U8 xbm_rare; /* rarest character in string */ | |
328 | }; | |
329 | ||
d22779f5 | 330 | /* This structure much match XPVCV in cv.h */ |
44a8e56a | 331 | |
77a005ab MB |
332 | typedef U16 cv_flags_t; |
333 | ||
79072805 | 334 | struct xpvfm { |
ed6116ce LW |
335 | char * xpv_pv; /* pointer to malloced string */ |
336 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
337 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 338 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 339 | NV xnv_nv; /* numeric value, if any */ |
79072805 LW |
340 | MAGIC* xmg_magic; /* linked list of magicalness */ |
341 | HV* xmg_stash; /* class package */ | |
8990e307 | 342 | |
79072805 LW |
343 | HV * xcv_stash; |
344 | OP * xcv_start; | |
345 | OP * xcv_root; | |
acfe0abc | 346 | void (*xcv_xsub)(pTHX_ CV*); |
a0d0e21e LW |
347 | ANY xcv_xsubany; |
348 | GV * xcv_gv; | |
57843af0 | 349 | char * xcv_file; |
b195d487 | 350 | long xcv_depth; /* >= 2 indicates recursive call */ |
79072805 | 351 | AV * xcv_padlist; |
748a9306 | 352 | CV * xcv_outside; |
4d1ff10f | 353 | #ifdef USE_5005THREADS |
f6d98b14 | 354 | perl_mutex *xcv_mutexp; /* protects xcv_owner */ |
52e1cb5e | 355 | struct perl_thread *xcv_owner; /* current owner thread */ |
4d1ff10f | 356 | #endif /* USE_5005THREADS */ |
77a005ab | 357 | cv_flags_t xcv_flags; |
44a8e56a | 358 | |
11a7ac70 | 359 | IV xfm_lines; |
79072805 LW |
360 | }; |
361 | ||
8990e307 LW |
362 | struct xpvio { |
363 | char * xpv_pv; /* pointer to malloced string */ | |
364 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ | |
365 | STRLEN xpv_len; /* allocated size */ | |
a0d0e21e | 366 | IV xiv_iv; /* integer value or pv offset */ |
65202027 | 367 | NV xnv_nv; /* numeric value, if any */ |
8990e307 LW |
368 | MAGIC* xmg_magic; /* linked list of magicalness */ |
369 | HV* xmg_stash; /* class package */ | |
370 | ||
760ac839 LW |
371 | PerlIO * xio_ifp; /* ifp and ofp are normally the same */ |
372 | PerlIO * xio_ofp; /* but sockets need separate streams */ | |
4755096e GS |
373 | /* Cray addresses everything by word boundaries (64 bits) and |
374 | * code and data pointers cannot be mixed (which is exactly what | |
375 | * Perl_filter_add() tries to do with the dirp), hence the following | |
376 | * union trick (as suggested by Gurusamy Sarathy). | |
377 | * For further information see Geir Johansen's problem report titled | |
378 | [ID 20000612.002] Perl problem on Cray system | |
379 | * The any pointer (known as IoANY()) will also be a good place | |
380 | * to hang any IO disciplines to. | |
381 | */ | |
382 | union { | |
383 | DIR * xiou_dirp; /* for opendir, readdir, etc */ | |
384 | void * xiou_any; /* for alignment */ | |
385 | } xio_dirpu; | |
11a7ac70 JH |
386 | IV xio_lines; /* $. */ |
387 | IV xio_page; /* $% */ | |
388 | IV xio_page_len; /* $= */ | |
389 | IV xio_lines_left; /* $- */ | |
8990e307 LW |
390 | char * xio_top_name; /* $^ */ |
391 | GV * xio_top_gv; /* $^ */ | |
392 | char * xio_fmt_name; /* $~ */ | |
393 | GV * xio_fmt_gv; /* $~ */ | |
394 | char * xio_bottom_name;/* $^B */ | |
395 | GV * xio_bottom_gv; /* $^B */ | |
396 | short xio_subprocess; /* -| or |- */ | |
397 | char xio_type; | |
398 | char xio_flags; | |
399 | }; | |
4755096e GS |
400 | #define xio_dirp xio_dirpu.xiou_dirp |
401 | #define xio_any xio_dirpu.xiou_any | |
8990e307 | 402 | |
e0c19803 GS |
403 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ |
404 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ | |
405 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ | |
406 | #define IOf_DIDTOP 8 /* just did top of form */ | |
407 | #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */ | |
408 | #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */ | |
409 | #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */ | |
8990e307 | 410 | |
ed6116ce LW |
411 | /* The following macros define implementation-independent predicates on SVs. */ |
412 | ||
954c1994 GS |
413 | /* |
414 | =for apidoc Am|bool|SvNIOK|SV* sv | |
415 | Returns a boolean indicating whether the SV contains a number, integer or | |
416 | double. | |
417 | ||
418 | =for apidoc Am|bool|SvNIOKp|SV* sv | |
419 | Returns a boolean indicating whether the SV contains a number, integer or | |
420 | double. Checks the B<private> setting. Use C<SvNIOK>. | |
421 | ||
422 | =for apidoc Am|void|SvNIOK_off|SV* sv | |
423 | Unsets the NV/IV status of an SV. | |
424 | ||
425 | =for apidoc Am|bool|SvOK|SV* sv | |
426 | Returns a boolean indicating whether the value is an SV. | |
427 | ||
428 | =for apidoc Am|bool|SvIOKp|SV* sv | |
429 | Returns a boolean indicating whether the SV contains an integer. Checks | |
430 | the B<private> setting. Use C<SvIOK>. | |
431 | ||
432 | =for apidoc Am|bool|SvNOKp|SV* sv | |
433 | Returns a boolean indicating whether the SV contains a double. Checks the | |
434 | B<private> setting. Use C<SvNOK>. | |
435 | ||
436 | =for apidoc Am|bool|SvPOKp|SV* sv | |
437 | Returns a boolean indicating whether the SV contains a character string. | |
438 | Checks the B<private> setting. Use C<SvPOK>. | |
439 | ||
440 | =for apidoc Am|bool|SvIOK|SV* sv | |
441 | Returns a boolean indicating whether the SV contains an integer. | |
442 | ||
443 | =for apidoc Am|void|SvIOK_on|SV* sv | |
444 | Tells an SV that it is an integer. | |
445 | ||
446 | =for apidoc Am|void|SvIOK_off|SV* sv | |
447 | Unsets the IV status of an SV. | |
448 | ||
449 | =for apidoc Am|void|SvIOK_only|SV* sv | |
450 | Tells an SV that it is an integer and disables all other OK bits. | |
451 | ||
e331fc52 JH |
452 | =for apidoc Am|void|SvIOK_only_UV|SV* sv |
453 | Tells and SV that it is an unsigned integer and disables all other OK bits. | |
454 | ||
455 | =for apidoc Am|void|SvIOK_UV|SV* sv | |
456 | Returns a boolean indicating whether the SV contains an unsigned integer. | |
457 | ||
28e5dec8 JH |
458 | =for apidoc Am|void|SvUOK|SV* sv |
459 | Returns a boolean indicating whether the SV contains an unsigned integer. | |
460 | ||
e331fc52 | 461 | =for apidoc Am|void|SvIOK_notUV|SV* sv |
d1be9408 | 462 | Returns a boolean indicating whether the SV contains a signed integer. |
e331fc52 | 463 | |
954c1994 GS |
464 | =for apidoc Am|bool|SvNOK|SV* sv |
465 | Returns a boolean indicating whether the SV contains a double. | |
466 | ||
467 | =for apidoc Am|void|SvNOK_on|SV* sv | |
468 | Tells an SV that it is a double. | |
469 | ||
470 | =for apidoc Am|void|SvNOK_off|SV* sv | |
471 | Unsets the NV status of an SV. | |
472 | ||
473 | =for apidoc Am|void|SvNOK_only|SV* sv | |
474 | Tells an SV that it is a double and disables all other OK bits. | |
475 | ||
476 | =for apidoc Am|bool|SvPOK|SV* sv | |
477 | Returns a boolean indicating whether the SV contains a character | |
478 | string. | |
479 | ||
480 | =for apidoc Am|void|SvPOK_on|SV* sv | |
481 | Tells an SV that it is a string. | |
482 | ||
483 | =for apidoc Am|void|SvPOK_off|SV* sv | |
484 | Unsets the PV status of an SV. | |
485 | ||
486 | =for apidoc Am|void|SvPOK_only|SV* sv | |
487 | Tells an SV that it is a string and disables all other OK bits. | |
d5ce4a7c | 488 | Will also turn off the UTF8 status. |
954c1994 GS |
489 | |
490 | =for apidoc Am|bool|SvOOK|SV* sv | |
491 | Returns a boolean indicating whether the SvIVX is a valid offset value for | |
492 | the SvPVX. This hack is used internally to speed up removal of characters | |
493 | from the beginning of a SvPV. When SvOOK is true, then the start of the | |
494 | allocated string buffer is really (SvPVX - SvIVX). | |
495 | ||
496 | =for apidoc Am|bool|SvROK|SV* sv | |
497 | Tests if the SV is an RV. | |
498 | ||
499 | =for apidoc Am|void|SvROK_on|SV* sv | |
500 | Tells an SV that it is an RV. | |
501 | ||
502 | =for apidoc Am|void|SvROK_off|SV* sv | |
503 | Unsets the RV status of an SV. | |
504 | ||
505 | =for apidoc Am|SV*|SvRV|SV* sv | |
506 | Dereferences an RV to return the SV. | |
507 | ||
508 | =for apidoc Am|IV|SvIVX|SV* sv | |
645c22ef DM |
509 | Returns the raw value in the SV's IV slot, without checks or conversions. |
510 | Only use when you are sure SvIOK is true. See also C<SvIV()>. | |
954c1994 GS |
511 | |
512 | =for apidoc Am|UV|SvUVX|SV* sv | |
645c22ef DM |
513 | Returns the raw value in the SV's UV slot, without checks or conversions. |
514 | Only use when you are sure SvIOK is true. See also C<SvUV()>. | |
954c1994 GS |
515 | |
516 | =for apidoc Am|NV|SvNVX|SV* sv | |
645c22ef DM |
517 | Returns the raw value in the SV's NV slot, without checks or conversions. |
518 | Only use when you are sure SvNOK is true. See also C<SvNV()>. | |
954c1994 GS |
519 | |
520 | =for apidoc Am|char*|SvPVX|SV* sv | |
645c22ef | 521 | Returns a pointer to the physical string in the SV. The SV must contain a |
954c1994 GS |
522 | string. |
523 | ||
524 | =for apidoc Am|STRLEN|SvCUR|SV* sv | |
525 | Returns the length of the string which is in the SV. See C<SvLEN>. | |
526 | ||
527 | =for apidoc Am|STRLEN|SvLEN|SV* sv | |
659239a4 MG |
528 | Returns the size of the string buffer in the SV, not including any part |
529 | attributable to C<SvOOK>. See C<SvCUR>. | |
954c1994 GS |
530 | |
531 | =for apidoc Am|char*|SvEND|SV* sv | |
532 | Returns a pointer to the last character in the string which is in the SV. | |
533 | See C<SvCUR>. Access the character as *(SvEND(sv)). | |
534 | ||
535 | =for apidoc Am|HV*|SvSTASH|SV* sv | |
536 | Returns the stash of the SV. | |
537 | ||
538 | =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len | |
539 | Set the length of the string which is in the SV. See C<SvCUR>. | |
540 | ||
541 | =cut | |
542 | */ | |
543 | ||
79072805 | 544 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
748a9306 | 545 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
a0d0e21e | 546 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
25da4f38 | 547 | SVp_IOK|SVp_NOK|SVf_IVisUV)) |
79072805 | 548 | |
137365c5 JH |
549 | #ifdef __GNUC__ |
550 | #define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv))}) | |
551 | #else | |
552 | #define assert_not_ROK(sv) 0 | |
553 | #endif | |
554 | ||
463ee0b2 | 555 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
137365c5 JH |
556 | #define SvOK_off(sv) (assert_not_ROK(sv), \ |
557 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ | |
d41ff1b8 | 558 | SVf_IVisUV|SVf_UTF8), \ |
25da4f38 | 559 | SvOOK_off(sv)) |
137365c5 JH |
560 | #define SvOK_off_exc_UV(sv) (assert_not_ROK(sv), \ |
561 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ | |
d41ff1b8 | 562 | SVf_UTF8), \ |
a0d0e21e | 563 | SvOOK_off(sv)) |
79072805 | 564 | |
8990e307 LW |
565 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
566 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) | |
155aba94 | 567 | #define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) |
8990e307 LW |
568 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) |
569 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) | |
570 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) | |
137365c5 JH |
571 | #define SvPOKp_on(sv) (assert_not_ROK(sv), \ |
572 | SvFLAGS(sv) |= SVp_POK) | |
463ee0b2 | 573 | |
79072805 | 574 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
155aba94 | 575 | #define SvIOK_on(sv) ((void)SvOOK_off(sv), \ |
a0d0e21e | 576 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
25da4f38 | 577 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV)) |
155aba94 | 578 | #define SvIOK_only(sv) ((void)SvOK_off(sv), \ |
a0d0e21e | 579 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
155aba94 | 580 | #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \ |
25da4f38 | 581 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
70401c6b | 582 | |
25da4f38 IZ |
583 | #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ |
584 | == (SVf_IOK|SVf_IVisUV)) | |
28e5dec8 | 585 | #define SvUOK(sv) SvIOK_UV(sv) |
25da4f38 IZ |
586 | #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ |
587 | == SVf_IOK) | |
588 | ||
7d7ce6cc | 589 | #define SvVOK(sv) (SvMAGICAL(sv) && mg_find(sv,'V')) |
25da4f38 IZ |
590 | #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV) |
591 | #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV) | |
592 | #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV) | |
79072805 LW |
593 | |
594 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) | |
a0d0e21e | 595 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
8990e307 | 596 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
155aba94 | 597 | #define SvNOK_only(sv) ((void)SvOK_off(sv), \ |
a0d0e21e | 598 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
79072805 | 599 | |
914184e1 JH |
600 | /* |
601 | =for apidoc Am|void|SvUTF8|SV* sv | |
602 | Returns a boolean indicating whether the SV contains UTF-8 encoded data. | |
603 | ||
604 | =for apidoc Am|void|SvUTF8_on|SV *sv | |
d5ce4a7c GA |
605 | Turn on the UTF8 status of an SV (the data is not changed, just the flag). |
606 | Do not use frivolously. | |
914184e1 JH |
607 | |
608 | =for apidoc Am|void|SvUTF8_off|SV *sv | |
609 | Unsets the UTF8 status of an SV. | |
610 | ||
611 | =for apidoc Am|void|SvPOK_only_UTF8|SV* sv | |
d5ce4a7c GA |
612 | Tells an SV that it is a string and disables all other OK bits, |
613 | and leaves the UTF8 status as it was. | |
f1a1024e | 614 | |
914184e1 JH |
615 | =cut |
616 | */ | |
617 | ||
a7cb1f99 GS |
618 | #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8) |
619 | #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8)) | |
620 | #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8)) | |
5bc28da9 | 621 | |
79072805 | 622 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) |
137365c5 JH |
623 | #define SvPOK_on(sv) (assert_not_ROK(sv), \ |
624 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) | |
8990e307 | 625 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
137365c5 JH |
626 | #define SvPOK_only(sv) (assert_not_ROK(sv), \ |
627 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ | |
d41ff1b8 GS |
628 | SVf_IVisUV|SVf_UTF8), \ |
629 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) | |
137365c5 JH |
630 | #define SvPOK_only_UTF8(sv) (assert_not_ROK(sv), \ |
631 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ | |
d41ff1b8 | 632 | SVf_IVisUV), \ |
a0d0e21e | 633 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
79072805 LW |
634 | |
635 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) | |
155aba94 | 636 | #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) |
79072805 | 637 | #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv)) |
79072805 | 638 | |
a0d0e21e LW |
639 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
640 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) | |
641 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) | |
642 | ||
ed6116ce | 643 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
a0d0e21e | 644 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
a0d0e21e | 645 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) |
79072805 | 646 | |
8990e307 LW |
647 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
648 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) | |
649 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) | |
79072805 | 650 | |
8990e307 LW |
651 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
652 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) | |
653 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) | |
ed6116ce | 654 | |
8990e307 LW |
655 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
656 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) | |
657 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) | |
ed6116ce | 658 | |
8990e307 LW |
659 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
660 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) | |
661 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) | |
ed6116ce | 662 | |
9e7bc3e8 JD |
663 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) |
664 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) | |
665 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) | |
a0d0e21e | 666 | |
8cf8f3d1 | 667 | #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC)) |
1426bbf4 | 668 | |
a0d0e21e LW |
669 | /* |
670 | #define Gv_AMG(stash) \ | |
671 | (HV_AMAGICmb(stash) && \ | |
672 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) | |
673 | */ | |
3280af22 | 674 | #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash)) |
a0d0e21e | 675 | |
810b8aa5 GS |
676 | #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \ |
677 | == (SVf_ROK|SVprv_WEAKREF)) | |
678 | #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF)) | |
679 | #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF)) | |
680 | ||
a0d0e21e | 681 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) |
ed6116ce | 682 | |
8990e307 | 683 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
ed6116ce | 684 | |
8990e307 LW |
685 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
686 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) | |
687 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) | |
ed6116ce | 688 | |
8990e307 LW |
689 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
690 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) | |
ed6116ce | 691 | |
8990e307 LW |
692 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
693 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) | |
694 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) | |
79072805 | 695 | |
8990e307 LW |
696 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
697 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) | |
698 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) | |
79072805 | 699 | |
8990e307 LW |
700 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
701 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) | |
702 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) | |
79072805 | 703 | |
8990e307 LW |
704 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
705 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) | |
706 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) | |
79072805 | 707 | |
8990e307 LW |
708 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
709 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) | |
710 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) | |
79072805 | 711 | |
25da4f38 IZ |
712 | #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL) |
713 | #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL) | |
714 | #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL) | |
715 | ||
8990e307 LW |
716 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
717 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) | |
718 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) | |
719 | ||
8990e307 LW |
720 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) |
721 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) | |
722 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) | |
723 | ||
1cc8b4c5 AB |
724 | #ifdef USE_ITHREADS |
725 | /* The following uses the FAKE flag to show that a regex pointer is infact | |
8ca6097c | 726 | its own offset in the regexpad for ithreads */ |
1cc8b4c5 AB |
727 | #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE) |
728 | #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE) | |
729 | #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) | |
730 | #endif | |
731 | ||
ed6116ce LW |
732 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
733 | #define SvRVx(sv) SvRV(sv) | |
734 | ||
463ee0b2 LW |
735 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
736 | #define SvIVXx(sv) SvIVX(sv) | |
ff68c719 | 737 | #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv |
738 | #define SvUVXx(sv) SvUVX(sv) | |
463ee0b2 LW |
739 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv |
740 | #define SvNVXx(sv) SvNVX(sv) | |
741 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv | |
742 | #define SvPVXx(sv) SvPVX(sv) | |
79072805 | 743 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
79072805 LW |
744 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
745 | #define SvLENx(sv) SvLEN(sv) | |
746 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) | |
6b88bc9c | 747 | #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv)) |
79072805 LW |
748 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
749 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash | |
750 | ||
28e5dec8 JH |
751 | /* Ask a scalar nicely to try to become an IV, if possible. |
752 | Not guaranteed to stay returning void */ | |
753 | /* Macro won't actually call sv_2iv if already IOK */ | |
754 | #define SvIV_please(sv) \ | |
755 | STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \ | |
756 | (void) SvIV(sv); } STMT_END | |
79072805 | 757 | #define SvIV_set(sv, val) \ |
80b92232 | 758 | STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ |
759 | (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END | |
79072805 | 760 | #define SvNV_set(sv, val) \ |
80b92232 | 761 | STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ |
762 | (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END | |
79072805 | 763 | #define SvPV_set(sv, val) \ |
80b92232 | 764 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
765 | (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END | |
79072805 | 766 | #define SvCUR_set(sv, val) \ |
80b92232 | 767 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
768 | (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END | |
79072805 | 769 | #define SvLEN_set(sv, val) \ |
80b92232 | 770 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
771 | (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END | |
79072805 | 772 | #define SvEND_set(sv, val) \ |
80b92232 | 773 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
774 | (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END | |
79072805 LW |
775 | |
776 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare | |
777 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful | |
778 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous | |
779 | ||
780 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines | |
781 | ||
782 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type | |
783 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ | |
784 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff | |
785 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen | |
786 | ||
8990e307 LW |
787 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
788 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp | |
789 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp | |
4755096e | 790 | #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any |
8990e307 LW |
791 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines |
792 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page | |
793 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len | |
794 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left | |
795 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name | |
796 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv | |
797 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name | |
798 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv | |
799 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name | |
800 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv | |
801 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess | |
802 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type | |
803 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags | |
804 | ||
50952442 JH |
805 | /* IoTYPE(sv) is a single character telling the type of I/O connection. */ |
806 | #define IoTYPE_RDONLY '<' | |
807 | #define IoTYPE_WRONLY '>' | |
808 | #define IoTYPE_RDWR '+' | |
809 | #define IoTYPE_APPEND 'a' | |
810 | #define IoTYPE_PIPE '|' | |
811 | #define IoTYPE_STD '-' /* stdin or stdout */ | |
812 | #define IoTYPE_SOCKET 's' | |
813 | #define IoTYPE_CLOSED ' ' | |
03fcf2fc GS |
814 | |
815 | /* | |
954c1994 GS |
816 | =for apidoc Am|bool|SvTAINTED|SV* sv |
817 | Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if | |
818 | not. | |
819 | ||
820 | =for apidoc Am|void|SvTAINTED_on|SV* sv | |
821 | Marks an SV as tainted. | |
822 | ||
823 | =for apidoc Am|void|SvTAINTED_off|SV* sv | |
824 | Untaints an SV. Be I<very> careful with this routine, as it short-circuits | |
825 | some of Perl's fundamental security features. XS module authors should not | |
826 | use this function unless they fully understand all the implications of | |
827 | unconditionally untainting the value. Untainting should be done in the | |
828 | standard perl fashion, via a carefully crafted regexp, rather than directly | |
829 | untainting variables. | |
830 | ||
831 | =for apidoc Am|void|SvTAINT|SV* sv | |
832 | Taints an SV if tainting is enabled | |
833 | ||
834 | =cut | |
835 | */ | |
836 | ||
bbce6d69 | 837 | #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) |
3280af22 NIS |
838 | #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END |
839 | #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END | |
bbce6d69 | 840 | |
c6ee37c5 MB |
841 | #define SvTAINT(sv) \ |
842 | STMT_START { \ | |
3280af22 | 843 | if (PL_tainting) { \ |
3280af22 | 844 | if (PL_tainted) \ |
c6ee37c5 MB |
845 | SvTAINTED_on(sv); \ |
846 | } \ | |
847 | } STMT_END | |
79072805 | 848 | |
954c1994 GS |
849 | /* |
850 | =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len | |
5f08bad4 ST |
851 | Like C<SvPV> but will force the SV into containing just a string |
852 | (C<SvPOK_only>). You want force if you are going to update the C<SvPVX> | |
853 | directly. | |
954c1994 | 854 | |
645c22ef | 855 | =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len |
5f08bad4 ST |
856 | Like C<SvPV> but will force the SV into containing just a string |
857 | (C<SvPOK_only>). You want force if you are going to update the C<SvPVX> | |
858 | directly. Doesn't process magic. | |
645c22ef | 859 | |
954c1994 | 860 | =for apidoc Am|char*|SvPV|SV* sv|STRLEN len |
5f08bad4 ST |
861 | Returns a pointer to the string in the SV, or a stringified form of |
862 | the SV if the SV does not contain a string. The SV may cache the | |
863 | stringified version becoming C<SvPOK>. Handles 'get' magic. See also | |
645c22ef DM |
864 | C<SvPVx> for a version which guarantees to evaluate sv only once. |
865 | ||
866 | =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len | |
867 | A version of C<SvPV> which guarantees to evaluate sv only once. | |
954c1994 GS |
868 | |
869 | =for apidoc Am|char*|SvPV_nolen|SV* sv | |
5f08bad4 ST |
870 | Returns a pointer to the string in the SV, or a stringified form of |
871 | the SV if the SV does not contain a string. The SV may cache the | |
872 | stringified form becoming C<SvPOK>. Handles 'get' magic. | |
954c1994 GS |
873 | |
874 | =for apidoc Am|IV|SvIV|SV* sv | |
645c22ef DM |
875 | Coerces the given SV to an integer and returns it. See C<SvIVx> for a |
876 | version which guarantees to evaluate sv only once. | |
877 | ||
878 | =for apidoc Am|IV|SvIVx|SV* sv | |
879 | Coerces the given SV to an integer and returns it. Guarantees to evaluate | |
d1be9408 | 880 | sv only once. Use the more efficient C<SvIV> otherwise. |
954c1994 GS |
881 | |
882 | =for apidoc Am|NV|SvNV|SV* sv | |
645c22ef DM |
883 | Coerce the given SV to a double and return it. See C<SvNVx> for a version |
884 | which guarantees to evaluate sv only once. | |
885 | ||
886 | =for apidoc Am|NV|SvNVx|SV* sv | |
887 | Coerces the given SV to a double and returns it. Guarantees to evaluate | |
d1be9408 | 888 | sv only once. Use the more efficient C<SvNV> otherwise. |
954c1994 GS |
889 | |
890 | =for apidoc Am|UV|SvUV|SV* sv | |
645c22ef DM |
891 | Coerces the given SV to an unsigned integer and returns it. See C<SvUVx> |
892 | for a version which guarantees to evaluate sv only once. | |
893 | ||
894 | =for apidoc Am|UV|SvUVx|SV* sv | |
895 | Coerces the given SV to an unsigned integer and returns it. Guarantees to | |
d1be9408 | 896 | evaluate sv only once. Use the more efficient C<SvUV> otherwise. |
954c1994 GS |
897 | |
898 | =for apidoc Am|bool|SvTRUE|SV* sv | |
899 | Returns a boolean indicating whether Perl would evaluate the SV as true or | |
900 | false, defined or undefined. Does not handle 'get' magic. | |
901 | ||
645c22ef | 902 | =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len |
b70b15d2 | 903 | Like C<SvPV_force>, but converts sv to utf8 first if necessary. |
645c22ef DM |
904 | |
905 | =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len | |
b70b15d2 | 906 | Like C<SvPV>, but converts sv to utf8 first if necessary. |
645c22ef | 907 | |
b70b15d2 TJ |
908 | =for apidoc Am|char*|SvPVutf8_nolen|SV* sv |
909 | Like C<SvPV_nolen>, but converts sv to utf8 first if necessary. | |
645c22ef DM |
910 | |
911 | =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len | |
912 | Like C<SvPV_force>, but converts sv to byte representation first if necessary. | |
913 | ||
914 | =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len | |
915 | Like C<SvPV>, but converts sv to byte representation first if necessary. | |
916 | ||
b70b15d2 | 917 | =for apidoc Am|char*|SvPVbyte_nolen|SV* sv |
645c22ef DM |
918 | Like C<SvPV_nolen>, but converts sv to byte representation first if necessary. |
919 | ||
920 | =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len | |
b70b15d2 | 921 | Like C<SvPV_force>, but converts sv to utf8 first if necessary. |
d1be9408 | 922 | Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force> |
645c22ef DM |
923 | otherwise. |
924 | ||
925 | =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len | |
b70b15d2 | 926 | Like C<SvPV>, but converts sv to utf8 first if necessary. |
d1be9408 | 927 | Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8> |
645c22ef DM |
928 | otherwise. |
929 | ||
930 | =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len | |
931 | Like C<SvPV_force>, but converts sv to byte representation first if necessary. | |
d1be9408 | 932 | Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force> |
645c22ef DM |
933 | otherwise. |
934 | ||
935 | =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len | |
936 | Like C<SvPV>, but converts sv to byte representation first if necessary. | |
d1be9408 | 937 | Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte> |
645c22ef DM |
938 | otherwise. |
939 | ||
940 | ||
954c1994 GS |
941 | =cut |
942 | */ | |
943 | ||
25da4f38 | 944 | /* Let us hope that bitmaps for UV and IV are the same */ |
463ee0b2 | 945 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
ff68c719 | 946 | #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) |
463ee0b2 | 947 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
79072805 | 948 | |
baca2b92 | 949 | /* ----*/ |
8d6d96c1 | 950 | |
8d6d96c1 HS |
951 | #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC) |
952 | ||
8d6d96c1 HS |
953 | #define SvPV_flags(sv, lp, flags) \ |
954 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ | |
955 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) | |
79072805 | 956 | |
8d6d96c1 | 957 | #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) |
baca2b92 | 958 | |
8d6d96c1 HS |
959 | #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) |
960 | ||
8d6d96c1 | 961 | #define SvPV_force_flags(sv, lp, flags) \ |
ff68c719 | 962 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
8d6d96c1 | 963 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) |
a0d0e21e | 964 | |
1fa8b10d | 965 | #define SvPV_nolen(sv) \ |
5bc28da9 NIS |
966 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
967 | ? SvPVX(sv) : sv_2pv_nolen(sv)) | |
70401c6b | 968 | |
baca2b92 | 969 | #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) |
5bc28da9 | 970 | |
baca2b92 | 971 | /* ----*/ |
70401c6b | 972 | |
5bc28da9 NIS |
973 | #define SvPVutf8(sv, lp) \ |
974 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \ | |
975 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp)) | |
70401c6b | 976 | |
5bc28da9 | 977 | #define SvPVutf8_force(sv, lp) \ |
70401c6b | 978 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \ |
5bc28da9 NIS |
979 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp)) |
980 | ||
baca2b92 | 981 | |
5bc28da9 NIS |
982 | #define SvPVutf8_nolen(sv) \ |
983 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\ | |
984 | ? SvPVX(sv) : sv_2pvutf8_nolen(sv)) | |
70401c6b | 985 | |
baca2b92 DM |
986 | /* ----*/ |
987 | ||
5bc28da9 NIS |
988 | #define SvPVbyte(sv, lp) \ |
989 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ | |
990 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) | |
70401c6b | 991 | |
5bc28da9 NIS |
992 | #define SvPVbyte_force(sv, lp) \ |
993 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \ | |
994 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp)) | |
995 | ||
5bc28da9 NIS |
996 | #define SvPVbyte_nolen(sv) \ |
997 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\ | |
998 | ? SvPVX(sv) : sv_2pvbyte_nolen(sv)) | |
70401c6b | 999 | |
1fa8b10d | 1000 | |
baca2b92 DM |
1001 | |
1002 | /* define FOOx(): idempotent versions of FOO(). If possible, use a local | |
1003 | * var to evaluate the arg once; failing that, use a global if possible; | |
1004 | * failing that, call a function to do the work | |
1005 | */ | |
1006 | ||
1007 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) | |
1008 | #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp) | |
1009 | #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp) | |
1010 | ||
5b7ea690 | 1011 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC) |
baca2b92 | 1012 | |
a80f87c4 GS |
1013 | # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); }) |
1014 | # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); }) | |
1015 | # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); }) | |
1016 | # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); }) | |
5bc28da9 NIS |
1017 | # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); }) |
1018 | # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); }) | |
a80f87c4 | 1019 | # define SvTRUE(sv) ( \ |
8990e307 LW |
1020 | !sv \ |
1021 | ? 0 \ | |
1022 | : SvPOK(sv) \ | |
a80f87c4 GS |
1023 | ? (({XPV *nxpv = (XPV*)SvANY(sv); \ |
1024 | nxpv && \ | |
c2f1de04 | 1025 | (nxpv->xpv_cur > 1 || \ |
a80f87c4 | 1026 | (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \ |
79072805 LW |
1027 | ? 1 \ |
1028 | : 0) \ | |
1029 | : \ | |
1030 | SvIOK(sv) \ | |
463ee0b2 | 1031 | ? SvIVX(sv) != 0 \ |
79072805 | 1032 | : SvNOK(sv) \ |
463ee0b2 LW |
1033 | ? SvNVX(sv) != 0.0 \ |
1034 | : sv_2bool(sv) ) | |
a80f87c4 | 1035 | # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); }) |
baca2b92 | 1036 | |
a80f87c4 | 1037 | #else /* __GNUC__ */ |
baca2b92 DM |
1038 | |
1039 | # ifdef USE_5005THREADS | |
1040 | # define SvIVx(sv) sv_iv(sv) | |
1041 | # define SvUVx(sv) sv_uv(sv) | |
1042 | # define SvNVx(sv) sv_nv(sv) | |
1043 | # define SvPVx(sv, lp) sv_pvn(sv, &lp) | |
1044 | # define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp) | |
1045 | # define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp) | |
1046 | # define SvTRUE(sv) SvTRUEx(sv) | |
1047 | # define SvTRUEx(sv) sv_true(sv) | |
1048 | ||
1049 | # else /* USE_5005THREADS */ | |
1050 | ||
a80f87c4 GS |
1051 | /* These inlined macros use globals, which will require a thread |
1052 | * declaration in user code, so we avoid them under threads */ | |
1053 | ||
baca2b92 DM |
1054 | # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv)) |
1055 | # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) | |
1056 | # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv)) | |
1057 | # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp)) | |
1058 | # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp)) | |
1059 | # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp)) | |
1060 | # define SvTRUE(sv) ( \ | |
a80f87c4 GS |
1061 | !sv \ |
1062 | ? 0 \ | |
1063 | : SvPOK(sv) \ | |
6b88bc9c | 1064 | ? ((PL_Xpv = (XPV*)SvANY(sv)) && \ |
c2f1de04 | 1065 | (PL_Xpv->xpv_cur > 1 || \ |
6b88bc9c | 1066 | (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \ |
a80f87c4 GS |
1067 | ? 1 \ |
1068 | : 0) \ | |
1069 | : \ | |
1070 | SvIOK(sv) \ | |
1071 | ? SvIVX(sv) != 0 \ | |
1072 | : SvNOK(sv) \ | |
1073 | ? SvNVX(sv) != 0.0 \ | |
1074 | : sv_2bool(sv) ) | |
baca2b92 DM |
1075 | # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv)) |
1076 | # endif /* USE_5005THREADS */ | |
1077 | #endif /* __GNU__ */ | |
1078 | ||
1079 | ||
1080 | /* flag values for sv_*_flags functions */ | |
1081 | #define SV_IMMEDIATE_UNREF 1 | |
1082 | #define SV_GMAGIC 2 | |
6563884d JH |
1083 | #define SV_COW_DROP_PV 4 /* Unused in Perl 5.8.x */ |
1084 | #define SV_UTF8_NO_ENCODING 8 | |
baca2b92 DM |
1085 | |
1086 | /* all these 'functions' are now just macros */ | |
1087 | ||
1088 | #define sv_pv(sv) SvPV_nolen(sv) | |
1089 | #define sv_pvutf8(sv) SvPVutf8_nolen(sv) | |
1090 | #define sv_pvbyte(sv) SvPVbyte_nolen(sv) | |
1091 | ||
1092 | #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0) | |
1093 | #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0) | |
1094 | #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0) | |
1095 | #define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC) | |
1096 | #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0) | |
1097 | #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC) | |
1098 | #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0) | |
1099 | #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC) | |
1100 | #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC) | |
1101 | #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0) | |
1102 | #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC) | |
1103 | #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC) | |
1104 | ||
79072805 | 1105 | |
954c1994 GS |
1106 | /* |
1107 | =for apidoc Am|SV*|newRV_inc|SV* sv | |
1108 | ||
1109 | Creates an RV wrapper for an SV. The reference count for the original SV is | |
1110 | incremented. | |
1111 | ||
1112 | =cut | |
1113 | */ | |
1114 | ||
5f05dabc | 1115 | #define newRV_inc(sv) newRV(sv) |
5f05dabc | 1116 | |
ef50df4b | 1117 | /* the following macros update any magic values this sv is associated with */ |
79072805 | 1118 | |
954c1994 | 1119 | /* |
ccfc67b7 JH |
1120 | =head1 Magical Functions |
1121 | ||
954c1994 GS |
1122 | =for apidoc Am|void|SvGETMAGIC|SV* sv |
1123 | Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its | |
1124 | argument more than once. | |
1125 | ||
1126 | =for apidoc Am|void|SvSETMAGIC|SV* sv | |
1127 | Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its | |
1128 | argument more than once. | |
1129 | ||
1130 | =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv | |
1131 | Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments | |
1132 | more than once. | |
1133 | ||
1134 | =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv | |
1135 | Calls a non-destructive version of C<sv_setsv> if dsv is not the same as | |
1136 | ssv. May evaluate arguments more than once. | |
1137 | ||
645c22ef DM |
1138 | =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv |
1139 | Like C<SvSetSV>, but does any set magic required afterwards. | |
1140 | ||
1141 | =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv | |
1142 | Like C<SvSetMagicSV>, but does any set magic required afterwards. | |
1143 | ||
68795e93 NIS |
1144 | =for apidoc Am|void|SvSHARE|SV* sv |
1145 | Arranges for sv to be shared between threads if a suitable module | |
1146 | has been loaded. | |
1147 | ||
1148 | =for apidoc Am|void|SvLOCK|SV* sv | |
1149 | Arranges for a mutual exclusion lock to be obtained on sv if a suitable module | |
1150 | has been loaded. | |
1151 | ||
1152 | =for apidoc Am|void|SvUNLOCK|SV* sv | |
1153 | Releases a mutual exclusion lock on sv if a suitable module | |
1154 | has been loaded. | |
1155 | ||
ccfc67b7 JH |
1156 | =head1 SV Manipulation Functions |
1157 | ||
679ac26e | 1158 | =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len |
954c1994 GS |
1159 | Expands the character buffer in the SV so that it has room for the |
1160 | indicated number of bytes (remember to reserve space for an extra trailing | |
8cf8f3d1 | 1161 | NUL character). Calls C<sv_grow> to perform the expansion if necessary. |
954c1994 GS |
1162 | Returns a pointer to the character buffer. |
1163 | ||
1164 | =cut | |
1165 | */ | |
1166 | ||
68795e93 NIS |
1167 | #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv) |
1168 | #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv) | |
1169 | #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv) | |
1170 | ||
189b2af5 GS |
1171 | #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END |
1172 | #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END | |
79072805 | 1173 | |
54310121 | 1174 | #define SvSetSV_and(dst,src,finally) \ |
189b2af5 | 1175 | STMT_START { \ |
54310121 | 1176 | if ((dst) != (src)) { \ |
1177 | sv_setsv(dst, src); \ | |
1178 | finally; \ | |
189b2af5 GS |
1179 | } \ |
1180 | } STMT_END | |
54310121 | 1181 | #define SvSetSV_nosteal_and(dst,src,finally) \ |
189b2af5 | 1182 | STMT_START { \ |
8ebc5c01 | 1183 | if ((dst) != (src)) { \ |
1184 | U32 tMpF = SvFLAGS(src) & SVs_TEMP; \ | |
1185 | SvTEMP_off(src); \ | |
1186 | sv_setsv(dst, src); \ | |
1187 | SvFLAGS(src) |= tMpF; \ | |
54310121 | 1188 | finally; \ |
189b2af5 GS |
1189 | } \ |
1190 | } STMT_END | |
79072805 | 1191 | |
54310121 | 1192 | #define SvSetSV(dst,src) \ |
c9d716f7 | 1193 | SvSetSV_and(dst,src,/*nothing*/;) |
54310121 | 1194 | #define SvSetSV_nosteal(dst,src) \ |
c9d716f7 | 1195 | SvSetSV_nosteal_and(dst,src,/*nothing*/;) |
54310121 | 1196 | |
1197 | #define SvSetMagicSV(dst,src) \ | |
1198 | SvSetSV_and(dst,src,SvSETMAGIC(dst)) | |
1199 | #define SvSetMagicSV_nosteal(dst,src) \ | |
1200 | SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) | |
1201 | ||
1045810a | 1202 | #if !defined(SKIP_DEBUGGING) |
79072805 | 1203 | #define SvPEEK(sv) sv_peek(sv) |
3967c732 JD |
1204 | #else |
1205 | #define SvPEEK(sv) "" | |
1206 | #endif | |
79072805 | 1207 | |
3280af22 | 1208 | #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no) |
36477c24 | 1209 | |
3280af22 | 1210 | #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) |
54310121 | 1211 | |
79072805 LW |
1212 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) |
1213 | ||
933fea7f GS |
1214 | #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
1215 | #define Sv_Grow sv_grow | |
3d35f11b | 1216 | |
a0739874 DM |
1217 | #define CLONEf_COPY_STACKS 1 |
1218 | #define CLONEf_KEEP_PTR_TABLE 2 | |
c43294b8 | 1219 | #define CLONEf_CLONE_HOST 4 |
457d3ae8 | 1220 | #define CLONEf_JOIN_IN 8 |
a0739874 | 1221 | |
8cf8f3d1 | 1222 | struct clone_params { |
d2d73c3e AB |
1223 | AV* stashes; |
1224 | UV flags; | |
59b40662 | 1225 | PerlInterpreter *proto_perl; |
8cf8f3d1 | 1226 | }; |
b4cc2f95 JH |
1227 | |
1228 | #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) sv_force_normal(sv) |