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