This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Memoize - t/expmod_t.t and t/speed.t were CUSTOMIZED by 53379bfd2f and f0206e8198
[perl5.git] / av.h
1 /*    av.h
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000,
4  *    2001, 2002, 2005, 2006, 2007, 2008, by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 struct xpvav {
12     HV*         xmg_stash;      /* class package */
13     union _xmgu xmg_u;
14     SSize_t     xav_fill;       /* Index of last element present */
15     SSize_t     xav_max;        /* max index for which array has space */
16     SV**        xav_alloc;      /* pointer to beginning of C array of SVs */
17 };
18
19 /* SV*  xav_arylen; */
20
21 /* SVpav_REAL is set for all AVs whose xav_array contents are refcounted.
22  * Some things like "@_" and the scratchpad list do not set this, to
23  * indicate that they are cheating (for efficiency) by not refcounting
24  * the AV's contents.
25  * 
26  * SVpav_REIFY is only meaningful on such "fake" AVs (i.e. where SVpav_REAL
27  * is not set).  It indicates that the fake AV is capable of becoming
28  * real if the array needs to be modified in some way.  Functions that
29  * modify fake AVs check both flags to call av_reify() as appropriate.
30  *
31  * Note that the Perl stack has neither flag set. (Thus,
32  * items that go on the stack are never refcounted.)
33  *
34  * These internal details are subject to change any time.  AV
35  * manipulations external to perl should not care about any of this.
36  * GSAR 1999-09-10
37  */
38
39 /*
40 =for apidoc_section AV Handling
41
42 =for apidoc ADmnU||Nullav
43 Null AV pointer.
44
45 (deprecated - use C<(AV *)NULL> instead)
46
47 =for apidoc Am|SSize_t|AvFILL|AV* av
48 Same as C<L</av_top_index>> or C<L</av_tindex>>.
49
50 =for apidoc Cm|SSize_t|AvFILLp|AV* av
51
52 If the array C<av> is empty, this returns -1; otherwise it returns the maximum
53 value of the indices of all the array elements which are currently defined in
54 C<av>.  It does not handle magic, hence the C<p> private indication in its name.
55
56 =for apidoc Am|SV**|AvARRAY|AV* av
57 Returns a pointer to the AV's internal SV* array.
58
59 This is useful for doing pointer arithmetic on the array.
60 If all you need is to look up an array element, then prefer C<av_fetch>.
61
62 =cut
63 */
64
65 #ifndef PERL_CORE
66 #  define Nullav Null(AV*)
67 #endif
68
69 #define AvARRAY(av)     ((av)->sv_u.svu_array)
70 #define AvALLOC(av)     ((XPVAV*)  SvANY(av))->xav_alloc
71 #define AvMAX(av)       ((XPVAV*)  SvANY(av))->xav_max
72 #define AvFILLp(av)     ((XPVAV*)  SvANY(av))->xav_fill
73 #define AvARYLEN(av)    (*Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)))
74
75 #define AvREAL(av)      (SvFLAGS(av) & SVpav_REAL)
76 #define AvREAL_on(av)   (SvFLAGS(av) |= SVpav_REAL)
77 #define AvREAL_off(av)  (SvFLAGS(av) &= ~SVpav_REAL)
78 #define AvREAL_only(av) (AvREIFY_off(av), SvFLAGS(av) |= SVpav_REAL)
79 #define AvREIFY(av)     (SvFLAGS(av) & SVpav_REIFY)
80 #define AvREIFY_on(av)  (SvFLAGS(av) |= SVpav_REIFY)
81 #define AvREIFY_off(av) (SvFLAGS(av) &= ~SVpav_REIFY)
82 #define AvREIFY_only(av)        (AvREAL_off(av), SvFLAGS(av) |= SVpav_REIFY)
83
84
85 #define AvREALISH(av)   (SvFLAGS(av) & (SVpav_REAL|SVpav_REIFY))
86                                           
87 #define AvFILL(av)      ((SvRMAGICAL((const SV *) (av))) \
88                          ? mg_size(MUTABLE_SV(av)) : AvFILLp(av))
89 #define av_top_index(av) AvFILL(av)
90 #define av_tindex(av)    av_top_index(av)
91
92 /* Note that it doesn't make sense to do this:
93  *      SvGETMAGIC(av); IV x = av_tindex_nomg(av);
94  */
95 #   define av_top_index_skip_len_mg(av)                                     \
96                             (__ASSERT_(SvTYPE(av) == SVt_PVAV) AvFILLp(av))
97 #   define av_tindex_skip_len_mg(av)  av_top_index_skip_len_mg(av)
98
99 #define NEGATIVE_INDICES_VAR "NEGATIVE_INDICES"
100
101 /*
102 =for apidoc newAV
103
104 Creates a new AV.  The reference count is set to 1.
105
106 Perl equivalent: C<my @array;>.
107
108 =cut
109 */
110
111 #define newAV() MUTABLE_AV(newSV_type(SVt_PVAV))
112
113 /*
114  * ex: set ts=8 sts=4 sw=4 et:
115  */