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