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