-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv.h
2144 lines (1813 loc) · 74.4 KB
/
sv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* sv.h
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
* 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifdef sv_flags
#undef sv_flags /* Convex has this in <signal.h> for sigvec() */
#endif
/*
=head1 SV Flags
=for apidoc AmU||svtype
An enum of flags for Perl types. These are found in the file B<sv.h>
in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
=for apidoc AmU||SVt_PV
Pointer type flag for scalars. See C<svtype>.
=for apidoc AmU||SVt_IV
Integer type flag for scalars. See C<svtype>.
=for apidoc AmU||SVt_NV
Double type flag for scalars. See C<svtype>.
=for apidoc AmU||SVt_PVMG
Type flag for blessed scalars. See C<svtype>.
=for apidoc AmU||SVt_PVAV
Type flag for arrays. See C<svtype>.
=for apidoc AmU||SVt_PVHV
Type flag for hashes. See C<svtype>.
=for apidoc AmU||SVt_PVCV
Type flag for code refs. See C<svtype>.
=cut
*/
typedef enum {
SVt_NULL, /* 0 */
SVt_BIND, /* 1 */
SVt_IV, /* 2 */
SVt_NV, /* 3 */
SVt_RV, /* 4 */
SVt_PV, /* 5 */
SVt_PVIV, /* 6 */
SVt_PVNV, /* 7 */
SVt_PVMG, /* 8 */
/* PVBM was here, before BIND replaced it. */
SVt_PVGV, /* 9 */
SVt_PVLV, /* 10 */
SVt_PVAV, /* 11 */
SVt_PVHV, /* 12 */
SVt_PVCV, /* 13 */
SVt_PVFM, /* 14 */
SVt_PVIO, /* 15 */
SVt_LAST /* keep last in enum. used to size arrays */
} svtype;
#ifndef PERL_CORE
/* Although Fast Boyer Moore tables are now being stored in PVGVs, for most
purposes eternal code wanting to consider PVBM probably needs to think of
PVMG instead. */
# define SVt_PVBM SVt_PVMG
#endif
/* There is collusion here with sv_clear - sv_clear exits early for SVt_NULL
and SVt_IV, so never reaches the clause at the end that uses
sv_type_details->body_size to determine whether to call safefree(). Hence
body_size can be set no-zero to record the size of PTEs and HEs, without
fear of bogus frees. */
#ifdef PERL_IN_SV_C
#define PTE_SVSLOT SVt_IV
#endif
#if defined(PERL_IN_HV_C) || defined(PERL_IN_XS_APITEST)
#define HE_SVSLOT SVt_NULL
#endif
#define PERL_ARENA_ROOTS_SIZE (SVt_LAST)
/* typedefs to eliminate some typing */
typedef struct he HE;
typedef struct hek HEK;
/* Using C's structural equivalence to help emulate C++ inheritance here... */
/* start with 2 sv-head building blocks */
#define _SV_HEAD(ptrtype) \
ptrtype sv_any; /* pointer to body */ \
U32 sv_refcnt; /* how many references to us */ \
U32 sv_flags /* what we are */
#define _SV_HEAD_UNION \
union { \
IV svu_iv; \
UV svu_uv; \
SV* svu_rv; /* pointer to another SV */ \
char* svu_pv; /* pointer to malloced string */ \
SV** svu_array; \
HE** svu_hash; \
GP* svu_gp; \
} sv_u
struct STRUCT_SV { /* struct sv { */
_SV_HEAD(void*);
_SV_HEAD_UNION;
#ifdef DEBUG_LEAKING_SCALARS
PERL_BITFIELD32 sv_debug_optype:9; /* the type of OP that allocated us */
PERL_BITFIELD32 sv_debug_inpad:1; /* was allocated in a pad for an OP */
PERL_BITFIELD32 sv_debug_cloned:1; /* was cloned for an ithread */
PERL_BITFIELD32 sv_debug_line:16; /* the line where we were allocated */
U32 sv_debug_serial; /* serial number of sv allocation */
char * sv_debug_file; /* the file where we were allocated */
#endif
};
struct gv {
_SV_HEAD(XPVGV*); /* pointer to xpvgv body */
_SV_HEAD_UNION;
};
struct cv {
_SV_HEAD(XPVCV*); /* pointer to xpvcv body */
_SV_HEAD_UNION;
};
struct av {
_SV_HEAD(XPVAV*); /* pointer to xpvav body */
_SV_HEAD_UNION;
};
struct hv {
_SV_HEAD(XPVHV*); /* pointer to xpvhv body */
_SV_HEAD_UNION;
};
struct io {
_SV_HEAD(XPVIO*); /* pointer to xpvio body */
_SV_HEAD_UNION;
};
#undef _SV_HEAD
#undef _SV_HEAD_UNION /* ensure no pollution */
/*
=head1 SV Manipulation Functions
=for apidoc Am|U32|SvREFCNT|SV* sv
Returns the value of the object's reference count.
=for apidoc Am|SV*|SvREFCNT_inc|SV* sv
Increments the reference count of the given SV.
All of the following SvREFCNT_inc* macros are optimized versions of
SvREFCNT_inc, and can be replaced with SvREFCNT_inc.
=for apidoc Am|SV*|SvREFCNT_inc_NN|SV* sv
Same as SvREFCNT_inc, but can only be used if you know I<sv>
is not NULL. Since we don't have to check the NULLness, it's faster
and smaller.
=for apidoc Am|void|SvREFCNT_inc_void|SV* sv
Same as SvREFCNT_inc, but can only be used if you don't need the
return value. The macro doesn't need to return a meaningful value.
=for apidoc Am|void|SvREFCNT_inc_void_NN|SV* sv
Same as SvREFCNT_inc, but can only be used if you don't need the return
value, and you know that I<sv> is not NULL. The macro doesn't need
to return a meaningful value, or check for NULLness, so it's smaller
and faster.
=for apidoc Am|SV*|SvREFCNT_inc_simple|SV* sv
Same as SvREFCNT_inc, but can only be used with expressions without side
effects. Since we don't have to store a temporary value, it's faster.
=for apidoc Am|SV*|SvREFCNT_inc_simple_NN|SV* sv
Same as SvREFCNT_inc_simple, but can only be used if you know I<sv>
is not NULL. Since we don't have to check the NULLness, it's faster
and smaller.
=for apidoc Am|void|SvREFCNT_inc_simple_void|SV* sv
Same as SvREFCNT_inc_simple, but can only be used if you don't need the
return value. The macro doesn't need to return a meaningful value.
=for apidoc Am|void|SvREFCNT_inc_simple_void_NN|SV* sv
Same as SvREFCNT_inc, but can only be used if you don't need the return
value, and you know that I<sv> is not NULL. The macro doesn't need
to return a meaningful value, or check for NULLness, so it's smaller
and faster.
=for apidoc Am|void|SvREFCNT_dec|SV* sv
Decrements the reference count of the given SV.
=for apidoc Am|svtype|SvTYPE|SV* sv
Returns the type of the SV. See C<svtype>.
=for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
perform the upgrade if necessary. See C<svtype>.
=cut
*/
#define SvANY(sv) (sv)->sv_any
#define SvFLAGS(sv) (sv)->sv_flags
#define SvREFCNT(sv) (sv)->sv_refcnt
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
# define SvREFCNT_inc(sv) \
({ \
SV * const _sv = MUTABLE_SV(sv); \
if (_sv) \
(SvREFCNT(_sv))++; \
_sv; \
})
# define SvREFCNT_inc_simple(sv) \
({ \
if (sv) \
(SvREFCNT(sv))++; \
MUTABLE_SV(sv); \
})
# define SvREFCNT_inc_NN(sv) \
({ \
SV * const _sv = MUTABLE_SV(sv); \
SvREFCNT(_sv)++; \
_sv; \
})
# define SvREFCNT_inc_void(sv) \
({ \
SV * const _sv = MUTABLE_SV(sv); \
if (_sv) \
(void)(SvREFCNT(_sv)++); \
})
#else
# define SvREFCNT_inc(sv) \
((PL_Sv=MUTABLE_SV(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL)
# define SvREFCNT_inc_simple(sv) \
((sv) ? (SvREFCNT(sv)++,MUTABLE_SV(sv)) : NULL)
# define SvREFCNT_inc_NN(sv) \
(PL_Sv=MUTABLE_SV(sv),++(SvREFCNT(PL_Sv)),PL_Sv)
# define SvREFCNT_inc_void(sv) \
(void)((PL_Sv=MUTABLE_SV(sv)) ? ++(SvREFCNT(PL_Sv)) : 0)
#endif
/* These guys don't need the curly blocks */
#define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END
#define SvREFCNT_inc_simple_NN(sv) (++(SvREFCNT(sv)),MUTABLE_SV(sv))
#define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT(MUTABLE_SV(sv)))
#define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT(MUTABLE_SV(sv)))
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
# define SvREFCNT_dec(sv) \
({ \
SV * const _sv = MUTABLE_SV(sv); \
if (_sv) { \
if (SvREFCNT(_sv)) { \
if (--(SvREFCNT(_sv)) == 0) \
Perl_sv_free2(aTHX_ _sv); \
} else { \
sv_free(_sv); \
} \
} \
})
#else
#define SvREFCNT_dec(sv) sv_free(MUTABLE_SV(sv))
#endif
#define SVTYPEMASK 0xff
#define SvTYPE(sv) ((svtype)((sv)->sv_flags & SVTYPEMASK))
/* Sadly there are some parts of the core that have pointers to already-freed
SV heads, and rely on being able to tell that they are now free. So mark
them all by using a consistent macro. */
#define SvIS_FREED(sv) ((sv)->sv_flags == SVTYPEMASK)
#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt), 1))
#define SVf_IOK 0x00000100 /* has valid public integer value */
#define SVf_NOK 0x00000200 /* has valid public numeric value */
#define SVf_POK 0x00000400 /* has valid public pointer value */
#define SVf_ROK 0x00000800 /* has a valid reference pointer */
#define SVp_IOK 0x00001000 /* has valid non-public integer value */
#define SVp_NOK 0x00002000 /* has valid non-public numeric value */
#define SVp_POK 0x00004000 /* has valid non-public pointer value */
#define SVp_SCREAM 0x00008000 /* has been studied? */
#define SVphv_CLONEABLE SVp_SCREAM /* PVHV (stashes) clone its objects */
#define SVpgv_GP SVp_SCREAM /* GV has a valid GP */
#define SVprv_PCS_IMPORTED SVp_SCREAM /* RV is a proxy for a constant
subroutine in another package. Set the
CvIMPORTED_CV_ON() if it needs to be
expanded to a real GV */
#define SVs_PADSTALE 0x00010000 /* lexical has gone out of scope */
#define SVpad_STATE 0x00010000 /* pad name is a "state" var */
#define SVs_PADTMP 0x00020000 /* in use as tmp */
#define SVpad_TYPED 0x00020000 /* pad name is a Typed Lexical */
#define SVs_PADMY 0x00040000 /* in use a "my" variable */
#define SVpad_OUR 0x00040000 /* pad name is "our" instead of "my" */
#define SVs_TEMP 0x00080000 /* string is stealable? */
#define SVs_OBJECT 0x00100000 /* is "blessed" */
#define SVs_GMG 0x00200000 /* has magical get method */
#define SVs_SMG 0x00400000 /* has magical set method */
#define SVs_RMG 0x00800000 /* has random magical methods */
#define SVf_FAKE 0x01000000 /* 0: glob or lexical is just a copy
1: SV head arena wasn't malloc()ed
2: in conjunction with SVf_READONLY
marks a shared hash key scalar
(SvLEN == 0) or a copy on write
string (SvLEN != 0) [SvIsCOW(sv)]
3: For PVCV, whether CvUNIQUE(cv)
refers to an eval or once only
[CvEVAL(cv), CvSPECIAL(cv)]
4: Whether the regexp pointer is in
fact an offset [SvREPADTMP(sv)]
5: On a pad name SV, that slot in the
frame AV is a REFCNT'ed reference
to a lexical from "outside". */
#define SVphv_REHASH SVf_FAKE /* 6: On a PVHV, hash values are being
recalculated */
#define SVf_OOK 0x02000000 /* has valid offset value. For a PVHV this
means that a hv_aux struct is present
after the main array */
#define SVf_BREAK 0x04000000 /* refcnt is artificially low - used by
SVs in final arena cleanup.
Set in S_regtry on PL_reg_curpm, so that
perl_destruct will skip it. */
#define SVf_READONLY 0x08000000 /* may not be modified */
#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
SVp_IOK|SVp_NOK|SVp_POK|SVpgv_GP)
#define PRIVSHIFT 4 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */
#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
/* Ensure this value does not clash with the GV_ADD* flags in gv.h: */
#define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded
This is also set on RVs whose overloaded
stringification is UTF-8. This might
only happen as a side effect of SvPV() */
/* Some private flags. */
/* PVAV could probably use 0x2000000 without conflict. I assume that PVFM can
be UTF-8 encoded, and PVCVs could well have UTF-8 prototypes. PVIOs haven't
been restructured, so sometimes get used as string buffers. */
/* PVHV */
#define SVphv_SHAREKEYS 0x20000000 /* PVHV keys live on shared string table */
/* PVNV, PVMG, presumably only inside pads */
#define SVpad_NAME 0x40000000 /* This SV is a name in the PAD, so
SVpad_TYPED, SVpad_OUR and SVpad_STATE
apply */
/* PVAV */
#define SVpav_REAL 0x40000000 /* free old entries */
/* PVHV */
#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
/* This is only set true on a PVGV when it's playing "PVBM", but is tested for
on any regular scalar (anything <= PVLV) */
#define SVpbm_VALID 0x40000000
/* ??? */
#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
/* IV, PVIV, PVNV, PVMG, PVGV and (I assume) PVLV */
/* Presumably IVs aren't stored in pads */
#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
/* PVAV */
#define SVpav_REIFY 0x80000000 /* can become real */
/* PVHV */
#define SVphv_HASKFLAGS 0x80000000 /* keys have flag byte after hash */
/* PVFM */
#define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
/* PVGV when SVpbm_VALID is true */
#define SVpbm_TAIL 0x80000000
/* RV upwards. However, SVf_ROK and SVp_IOK are exclusive */
#define SVprv_WEAKREF 0x80000000 /* Weak reference */
struct xpv {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
};
typedef struct {
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
} xpv_allocated;
struct xpviv {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
};
typedef struct {
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
} xpviv_allocated;
#define xiv_iv xiv_u.xivu_iv
struct xpvuv {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xuvu_iv;
UV xuvu_uv; /* unsigned value or pv offset */
void * xuvu_p1;
HEK * xivu_namehek;
} xuv_u;
};
#define xuv_uv xuv_u.xuvu_uv
struct xpvnv {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
};
/* These structure must match the beginning of struct xpvhv in hv.h. */
struct xpvmg {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
};
struct xpvlv {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek; /* GvNAME */
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
STRLEN xlv_targoff;
STRLEN xlv_targlen;
SV* xlv_targ;
char xlv_type; /* k=keys .=pos x=substr v=vec /=join/re
* y=alem/helem/iter t=tie T=tied HE */
};
/* This structure works in 3 ways - regular scalar, GV with GP, or fast
Boyer-Moore. */
struct xpvgv {
union {
NV xnv_nv;
HV * xgv_stash; /* The stash of this GV */
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* xgv_flags */
STRLEN xpv_len; /* 0 */
union {
IV xivu_iv;
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32; /* is this constant pattern being useful? */
HEK * xivu_namehek; /* GvNAME */
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
};
/* This structure must match XPVCV in cv.h */
typedef U16 cv_flags_t;
struct xpvfm {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* PVFMs use the pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
HV * xcv_stash;
union {
OP * xcv_start;
ANY xcv_xsubany;
} xcv_start_u;
union {
OP * xcv_root;
void (*xcv_xsub) (pTHX_ CV*);
} xcv_root_u;
GV * xcv_gv;
char * xcv_file;
AV * xcv_padlist;
CV * xcv_outside;
U32 xcv_outside_seq; /* the COP sequence (at the point of our
* compilation) in the lexically enclosing
* sub */
cv_flags_t xcv_flags;
IV xfm_lines;
};
typedef struct {
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* PVFMs use the pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
HV * xcv_stash;
union {
OP * xcv_start;
ANY xcv_xsubany;
} xcv_start_u;
union {
OP * xcv_root;
void (*xcv_xsub) (pTHX_ CV*);
} xcv_root_u;
GV * xcv_gv;
char * xcv_file;
AV * xcv_padlist;
CV * xcv_outside;
U32 xcv_outside_seq; /* the COP sequence (at the point of our
* compilation) in the lexically enclosing
* sub */
cv_flags_t xcv_flags;
IV xfm_lines;
} xpvfm_allocated;
struct xpvio {
union {
NV xnv_nv; /* numeric value, if any */
HV * xgv_stash;
struct {
U32 xlow;
U32 xhigh;
} xpad_cop_seq; /* used by pad.c for cop_sequence */
struct {
U32 xbm_previous; /* how many characters in string before rare? */
U8 xbm_flags;
U8 xbm_rare; /* rarest character in string */
} xbm_s; /* fields from PVBM */
} xnv_u;
STRLEN xpv_cur; /* length of svu_pv as a C string */
STRLEN xpv_len; /* allocated size */
union {
IV xivu_iv; /* integer value or pv offset */
UV xivu_uv;
void * xivu_p1;
I32 xivu_i32;
HEK * xivu_namehek;
} xiv_u;
union {
MAGIC* xmg_magic; /* linked list of magicalness */
HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */
} xmg_u;
HV* xmg_stash; /* class package */
PerlIO * xio_ifp; /* ifp and ofp are normally the same */
PerlIO * xio_ofp; /* but sockets need separate streams */
/* Cray addresses everything by word boundaries (64 bits) and
* code and data pointers cannot be mixed (which is exactly what
* Perl_filter_add() tries to do with the dirp), hence the following
* union trick (as suggested by Gurusamy Sarathy).
* For further information see Geir Johansen's problem report titled
[ID 20000612.002] Perl problem on Cray system
* The any pointer (known as IoANY()) will also be a good place
* to hang any IO disciplines to.
*/
union {
DIR * xiou_dirp; /* for opendir, readdir, etc */
void * xiou_any; /* for alignment */
} xio_dirpu;
IV xio_lines; /* $. */
IV xio_page; /* $% */
IV xio_page_len; /* $= */
IV xio_lines_left; /* $- */
char * xio_top_name; /* $^ */
GV * xio_top_gv; /* $^ */
char * xio_fmt_name; /* $~ */
GV * xio_fmt_gv; /* $~ */
char * xio_bottom_name;/* $^B */
GV * xio_bottom_gv; /* $^B */
char xio_type;
U8 xio_flags;
};
#define xio_dirp xio_dirpu.xiou_dirp
#define xio_any xio_dirpu.xiou_any
#define IOf_ARGV 1 /* this fp iterates over ARGV */
#define IOf_START 2 /* check for null ARGV and substitute '-' */
#define IOf_FLUSH 4 /* this fp wants a flush after write op */
#define IOf_DIDTOP 8 /* just did top of form */
#define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
#define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
#define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
/* The following macros define implementation-independent predicates on SVs. */
/*
=for apidoc Am|U32|SvNIOK|SV* sv
Returns a U32 value indicating whether the SV contains a number, integer or
double.
=for apidoc Am|U32|SvNIOKp|SV* sv
Returns a U32 value indicating whether the SV contains a number, integer or
double. Checks the B<private> setting. Use C<SvNIOK> instead.
=for apidoc Am|void|SvNIOK_off|SV* sv
Unsets the NV/IV status of an SV.
=for apidoc Am|U32|SvOK|SV* sv
Returns a U32 value indicating whether the value is defined. This is
only meaningful for scalars.
=for apidoc Am|U32|SvIOKp|SV* sv
Returns a U32 value indicating whether the SV contains an integer. Checks
the B<private> setting. Use C<SvIOK> instead.
=for apidoc Am|U32|SvNOKp|SV* sv
Returns a U32 value indicating whether the SV contains a double. Checks the
B<private> setting. Use C<SvNOK> instead.
=for apidoc Am|U32|SvPOKp|SV* sv
Returns a U32 value indicating whether the SV contains a character string.
Checks the B<private> setting. Use C<SvPOK> instead.
=for apidoc Am|U32|SvIOK|SV* sv
Returns a U32 value indicating whether the SV contains an integer.
=for apidoc Am|void|SvIOK_on|SV* sv
Tells an SV that it is an integer.
=for apidoc Am|void|SvIOK_off|SV* sv
Unsets the IV status of an SV.
=for apidoc Am|void|SvIOK_only|SV* sv
Tells an SV that it is an integer and disables all other OK bits.
=for apidoc Am|void|SvIOK_only_UV|SV* sv
Tells and SV that it is an unsigned integer and disables all other OK bits.
=for apidoc Am|bool|SvIOK_UV|SV* sv
Returns a boolean indicating whether the SV contains an unsigned integer.
=for apidoc Am|bool|SvUOK|SV* sv
Returns a boolean indicating whether the SV contains an unsigned integer.
=for apidoc Am|bool|SvIOK_notUV|SV* sv
Returns a boolean indicating whether the SV contains a signed integer.
=for apidoc Am|U32|SvNOK|SV* sv
Returns a U32 value indicating whether the SV contains a double.
=for apidoc Am|void|SvNOK_on|SV* sv
Tells an SV that it is a double.
=for apidoc Am|void|SvNOK_off|SV* sv
Unsets the NV status of an SV.
=for apidoc Am|void|SvNOK_only|SV* sv
Tells an SV that it is a double and disables all other OK bits.
=for apidoc Am|U32|SvPOK|SV* sv
Returns a U32 value indicating whether the SV contains a character
string.
=for apidoc Am|void|SvPOK_on|SV* sv
Tells an SV that it is a string.
=for apidoc Am|void|SvPOK_off|SV* sv
Unsets the PV status of an SV.
=for apidoc Am|void|SvPOK_only|SV* sv
Tells an SV that it is a string and disables all other OK bits.
Will also turn off the UTF-8 status.
=for apidoc Am|bool|SvVOK|SV* sv
Returns a boolean indicating whether the SV contains a v-string.
=for apidoc Am|U32|SvOOK|SV* sv
Returns a U32 indicating whether the SvIVX is a valid offset value for
the SvPVX. This hack is used internally to speed up removal of characters
from the beginning of a SvPV. When SvOOK is true, then the start of the
allocated string buffer is really (SvPVX - SvIVX).
=for apidoc Am|U32|SvROK|SV* sv
Tests if the SV is an RV.
=for apidoc Am|void|SvROK_on|SV* sv
Tells an SV that it is an RV.
=for apidoc Am|void|SvROK_off|SV* sv
Unsets the RV status of an SV.
=for apidoc Am|SV*|SvRV|SV* sv
Dereferences an RV to return the SV.
=for apidoc Am|IV|SvIVX|SV* sv
Returns the raw value in the SV's IV slot, without checks or conversions.
Only use when you are sure SvIOK is true. See also C<SvIV()>.
=for apidoc Am|UV|SvUVX|SV* sv
Returns the raw value in the SV's UV slot, without checks or conversions.
Only use when you are sure SvIOK is true. See also C<SvUV()>.
=for apidoc Am|NV|SvNVX|SV* sv
Returns the raw value in the SV's NV slot, without checks or conversions.
Only use when you are sure SvNOK is true. See also C<SvNV()>.
=for apidoc Am|char*|SvPVX|SV* sv
Returns a pointer to the physical string in the SV. The SV must contain a
string.
=for apidoc Am|STRLEN|SvCUR|SV* sv
Returns the length of the string which is in the SV. See C<SvLEN>.
=for apidoc Am|STRLEN|SvLEN|SV* sv
Returns the size of the string buffer in the SV, not including any part
attributable to C<SvOOK>. See C<SvCUR>.
=for apidoc Am|char*|SvEND|SV* sv
Returns a pointer to the last character in the string which is in the SV.
See C<SvCUR>. Access the character as *(SvEND(sv)).
=for apidoc Am|HV*|SvSTASH|SV* sv
Returns the stash of the SV.
=for apidoc Am|void|SvIV_set|SV* sv|IV val
Set the value of the IV pointer in sv to val. It is possible to perform
the same function of this macro with an lvalue assignment to C<SvIVX>.
With future Perls, however, it will be more efficient to use
C<SvIV_set> instead of the lvalue assignment to C<SvIVX>.
=for apidoc Am|void|SvNV_set|SV* sv|NV val
Set the value of the NV pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvPV_set|SV* sv|char* val
Set the value of the PV pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvUV_set|SV* sv|UV val
Set the value of the UV pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvRV_set|SV* sv|SV* val
Set the value of the RV pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvMAGIC_set|SV* sv|MAGIC* val
Set the value of the MAGIC pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvSTASH_set|SV* sv|HV* val
Set the value of the STASH pointer in sv to val. See C<SvIV_set>.
=for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
Set the current length of the string which is in the SV. See C<SvCUR>
and C<SvIV_set>.
=for apidoc Am|void|SvLEN_set|SV* sv|STRLEN len
Set the actual length of the string which is in the SV. See C<SvIV_set>.
=cut
*/
#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
SVp_IOK|SVp_NOK|SVf_IVisUV))
#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
#define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv));}),
#define assert_not_glob(sv) ({assert(!isGV_with_GP(sv));}),
#else
#define assert_not_ROK(sv)
#define assert_not_glob(sv)
#endif
#define SvOK(sv) ((SvTYPE(sv) == SVt_BIND) \
? (SvFLAGS(SvRV(sv)) & SVf_OK) \
: (SvFLAGS(sv) & SVf_OK))
#define SvOK_off(sv) (assert_not_ROK(sv) assert_not_glob(sv) \
SvFLAGS(sv) &= ~(SVf_OK| \
SVf_IVisUV|SVf_UTF8), \
SvOOK_off(sv))
#define SvOK_off_exc_UV(sv) (assert_not_ROK(sv) \
SvFLAGS(sv) &= ~(SVf_OK| \
SVf_UTF8), \
SvOOK_off(sv))
#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
#define SvIOKp_on(sv) (assert_not_glob(sv) SvRELEASE_IVX(sv), \
SvFLAGS(sv) |= SVp_IOK)
#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
#define SvNOKp_on(sv) (assert_not_glob(sv) SvFLAGS(sv) |= SVp_NOK)
#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
#define SvPOKp_on(sv) (assert_not_ROK(sv) assert_not_glob(sv) \
SvFLAGS(sv) |= SVp_POK)
#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
#define SvIOK_on(sv) (assert_not_glob(sv) SvRELEASE_IVX(sv), \
SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
#define SvIOK_only(sv) (SvOK_off(sv), \
SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
#define SvIOK_only_UV(sv) (assert_not_glob(sv) SvOK_off_exc_UV(sv), \
SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
#define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
== (SVf_IOK|SVf_IVisUV))
#define SvUOK(sv) SvIOK_UV(sv)
#define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
== SVf_IOK)
#define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
#define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
#define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
#define SvNOK_on(sv) (assert_not_glob(sv) \
SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
#define SvNOK_only(sv) (SvOK_off(sv), \
SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
/*
=for apidoc Am|U32|SvUTF8|SV* sv
Returns a U32 value indicating whether the SV contains UTF-8 encoded data.
Call this after SvPV() in case any call to string overloading updates the
internal flag.
=for apidoc Am|void|SvUTF8_on|SV *sv
Turn on the UTF-8 status of an SV (the data is not changed, just the flag).
Do not use frivolously.