Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 376 lines (326 sloc) 14.133 kb
a0d0e21 perl 5.000
Larry Wall authored
1 /* hv.h
7907280 perl 5.0 alpha 2
Larry Wall authored
2 *
4bb101f @jhi Fix up Larry's copyright statements to my best knowledge.
jhi authored
3 * Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999,
1d32597 @rgs Update copyrights.
rgs authored
4 * 2000, 2001, 2002, 2005, by Larry Wall and others
7907280 perl 5.0 alpha 2
Larry Wall authored
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
5cbe4ee hv.h Doc Patch
Mark Fisher authored
11 /* typedefs to eliminate some typing */
7907280 perl 5.0 alpha 2
Larry Wall authored
12 typedef struct he HE;
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
13 typedef struct hek HEK;
7907280 perl 5.0 alpha 2
Larry Wall authored
14
5cbe4ee hv.h Doc Patch
Mark Fisher authored
15 /* entry in hash value chain */
7907280 perl 5.0 alpha 2
Larry Wall authored
16 struct he {
5cbe4ee hv.h Doc Patch
Mark Fisher authored
17 HE *hent_next; /* next entry in chain */
18 HEK *hent_hek; /* hash key */
19 SV *hent_val; /* scalar value that was hashed */
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored
20 };
21
5cbe4ee hv.h Doc Patch
Mark Fisher authored
22 /* hash key -- defined separately for use as shared pointer */
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
23 struct hek {
5cbe4ee hv.h Doc Patch
Mark Fisher authored
24 U32 hek_hash; /* hash of key */
25 I32 hek_len; /* length of hash key */
26 char hek_key[1]; /* variable-length hash key */
e05949c @jhi Make shared hash keys to be \0-terminated:
jhi authored
27 /* the hash-key is \0-terminated */
1e54db1 @jhi It's UTF-8, not UTF8. (Note: not s/UTF-8/UTF8/,
jhi authored
28 /* after the \0 there is a byte for flags, such as whether the key
29 is UTF-8 */
7907280 perl 5.0 alpha 2
Larry Wall authored
30 };
31
cbae396 In the shared string table, store the HE and HEK next to each other
Nicholas Clark authored
32 struct shared_he {
33 struct he shared_he_he;
34 struct hek shared_he_hek;
35 };
bfcb351 Move hv_name, hv_eiter and hv_riter into a new aux structure.
Nicholas Clark authored
36
37 /* Subject to change.
38 Don't access this directly.
39 */
40 struct xpvhv_aux {
7423f6d Store the package name as a shared HEK.
Nicholas Clark authored
41 HEK *xhv_name; /* name, if a symbol table */
bfcb351 Move hv_name, hv_eiter and hv_riter into a new aux structure.
Nicholas Clark authored
42 HE *xhv_eiter; /* current entry of iterator */
43 I32 xhv_riter; /* current root of iterator */
44 };
45
5cbe4ee hv.h Doc Patch
Mark Fisher authored
46 /* hash structure: */
6ee623d [win32] integrate mainline
Gurusamy Sarathy authored
47 /* This structure must match the beginning of struct xpvmg in sv.h. */
7907280 perl 5.0 alpha 2
Larry Wall authored
48 struct xpvhv {
311a25d Change the IV to a union.
Nicholas Clark authored
49 NV xnv_nv; /* numeric value, if any */
463ee0b perl 5.0 alpha 4
Larry Wall authored
50 STRLEN xhv_fill; /* how full xhv_array currently is */
51 STRLEN xhv_max; /* subscript of last element of xhv_array */
e4305a6 Add a union in place of xnv_nv, which allows AVs and HVs to re-use
Nicholas Clark authored
52 union {
311a25d Change the IV to a union.
Nicholas Clark authored
53 IV xivu_iv; /* integer value or pv offset */
54 UV xivu_uv;
55 void * xivu_p1;
56 } xiv_u;
7907280 perl 5.0 alpha 2
Larry Wall authored
57 MAGIC* xmg_magic; /* magic for scalar array */
58 HV* xmg_stash; /* class package */
59 };
60
311a25d Change the IV to a union.
Nicholas Clark authored
61 #define xhv_keys xiv_u.xivu_iv
e4305a6 Add a union in place of xnv_nv, which allows AVs and HVs to re-use
Nicholas Clark authored
62
c5f87f5 Attempt 2 at a diet memory layout can go live.
Nicholas Clark authored
63 #if 0
5981343 create an "allocated" structure for PVs, PVAVs and PVHVs
Nicholas Clark authored
64 typedef struct xpvhv xpvhv_allocated;
9f1501b Don't allocate an IV slot where the type doesn't use the IV slot.
Nicholas Clark authored
65 #else
66 typedef struct {
67 STRLEN xhv_fill; /* how full xhv_array currently is */
68 STRLEN xhv_max; /* subscript of last element of xhv_array */
69 union {
311a25d Change the IV to a union.
Nicholas Clark authored
70 IV xivu_iv; /* integer value or pv offset */
71 UV xivu_uv;
72 void * xivu_p1;
73 } xiv_u;
9f1501b Don't allocate an IV slot where the type doesn't use the IV slot.
Nicholas Clark authored
74 MAGIC* xmg_magic; /* magic for scalar array */
75 HV* xmg_stash; /* class package */
76 } xpvhv_allocated;
77 #endif
e4305a6 Add a union in place of xnv_nv, which allows AVs and HVs to re-use
Nicholas Clark authored
78
5cbe4ee hv.h Doc Patch
Mark Fisher authored
79 /* hash a key */
5afd6d4 @jhi PERL_HASH() casting games so that our hashed data is "unsigned
jhi authored
80 /* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins
81 * from requirements by Colin Plumb.
82 * (http://burtleburtle.net/bob/hash/doobs.html) */
83 /* The use of a temporary pointer and the casting games
84 * is needed to serve the dual purposes of
85 * (a) the hashed data being interpreted as "unsigned char" (new since 5.8,
86 * a "char" can be either signed or signed, depending on the compiler)
87 * (b) catering for old code that uses a "char"
830b38b @jhi This should make Stas happy.
jhi authored
88 *
504f80c @jhi Bite the bullet and apply the hash randomisation patch.
jhi authored
89 * The "hash seed" feature was added in Perl 5.8.1 to perturb the results
90 * to avoid "algorithmic complexity attacks".
830b38b @jhi This should make Stas happy.
jhi authored
91 *
92 * If USE_HASH_SEED is defined, hash randomisation is done by default
93 * If USE_HASH_SEED_EXPLICIT is defined, hash randomisation is done
94 * only if the environment variable PERL_HASH_SEED is set.
95 * For maximal control, one can define PERL_HASH_SEED.
90ce55a Fix a typo
Nicholas Clark authored
96 * (see also perl.c:perl_parse()).
5afd6d4 @jhi PERL_HASH() casting games so that our hashed data is "unsigned
jhi authored
97 */
830b38b @jhi This should make Stas happy.
jhi authored
98 #ifndef PERL_HASH_SEED
99 # if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT)
100 # define PERL_HASH_SEED PL_hash_seed
101 # else
102 # define PERL_HASH_SEED 0
103 # endif
504f80c @jhi Bite the bullet and apply the hash randomisation patch.
jhi authored
104 #endif
bf6bd88 Add shared hash key support
Perl 5 Porters authored
105 #define PERL_HASH(hash,str,len) \
106 STMT_START { \
5afd6d4 @jhi PERL_HASH() casting games so that our hashed data is "unsigned
jhi authored
107 register const char *s_PeRlHaSh_tmp = str; \
108 register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \
bf6bd88 Add shared hash key support
Perl 5 Porters authored
109 register I32 i_PeRlHaSh = len; \
504f80c @jhi Bite the bullet and apply the hash randomisation patch.
jhi authored
110 register U32 hash_PeRlHaSh = PERL_HASH_SEED; \
a6fe520 RE: Biannual Competition to Improve Hashing Function
Mark Fisher authored
111 while (i_PeRlHaSh--) { \
112 hash_PeRlHaSh += *s_PeRlHaSh++; \
113 hash_PeRlHaSh += (hash_PeRlHaSh << 10); \
114 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \
115 } \
116 hash_PeRlHaSh += (hash_PeRlHaSh << 3); \
117 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \
4fee5c7 REALLY pedantic hv.h nit
Simon Cozens authored
118 (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \
bf6bd88 Add shared hash key support
Perl 5 Porters authored
119 } STMT_END
120
3d78eb9 Stas would prefer not to have MOD_PERL defines in perl.
Nicholas Clark authored
121 /* Only hv.c and mod_perl should be doing this. */
122 #ifdef PERL_HASH_INTERNAL_ACCESS
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
123 #define PERL_HASH_INTERNAL(hash,str,len) \
124 STMT_START { \
125 register const char *s_PeRlHaSh_tmp = str; \
126 register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \
127 register I32 i_PeRlHaSh = len; \
008fb0c s/new_hash/rehash/g (Stas suggested a better name)
Nicholas Clark authored
128 register U32 hash_PeRlHaSh = PL_rehash_seed; \
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
129 while (i_PeRlHaSh--) { \
130 hash_PeRlHaSh += *s_PeRlHaSh++; \
131 hash_PeRlHaSh += (hash_PeRlHaSh << 10); \
132 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \
133 } \
134 hash_PeRlHaSh += (hash_PeRlHaSh << 3); \
135 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \
136 (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \
137 } STMT_END
138 #endif
139
954c199 autogenerate API listing from comments in the source (from Benjamin
Gurusamy Sarathy authored
140 /*
ccfc67b @jhi Missed the =head1 additions.
jhi authored
141 =head1 Hash Manipulation Functions
142
954c199 autogenerate API listing from comments in the source (from Benjamin
Gurusamy Sarathy authored
143 =for apidoc AmU||HEf_SVKEY
144 This flag, used in the length slot of hash entries and magic structures,
d1be940 a few typo fixes
Jeffrey Friedl authored
145 specifies the structure contains an C<SV*> pointer where a C<char*> pointer
954c199 autogenerate API listing from comments in the source (from Benjamin
Gurusamy Sarathy authored
146 is to be expected. (For information only--not to be used).
147
ccfc67b @jhi Missed the =head1 additions.
jhi authored
148 =head1 Handy Values
149
954c199 autogenerate API listing from comments in the source (from Benjamin
Gurusamy Sarathy authored
150 =for apidoc AmU||Nullhv
151 Null HV pointer.
152
ccfc67b @jhi Missed the =head1 additions.
jhi authored
153 =head1 Hash Manipulation Functions
154
954c199 autogenerate API listing from comments in the source (from Benjamin
Gurusamy Sarathy authored
155 =for apidoc Am|char*|HvNAME|HV* stash
156 Returns the package name of a stash. See C<SvSTASH>, C<CvSTASH>.
157
158 =for apidoc Am|void*|HeKEY|HE* he
159 Returns the actual pointer stored in the key slot of the hash entry. The
160 pointer may be either C<char*> or C<SV*>, depending on the value of
161 C<HeKLEN()>. Can be assigned to. The C<HePV()> or C<HeSVKEY()> macros are
162 usually preferable for finding the value of a key.
163
164 =for apidoc Am|STRLEN|HeKLEN|HE* he
165 If this is negative, and amounts to C<HEf_SVKEY>, it indicates the entry
166 holds an C<SV*> key. Otherwise, holds the actual length of the key. Can
167 be assigned to. The C<HePV()> macro is usually preferable for finding key
168 lengths.
169
170 =for apidoc Am|SV*|HeVAL|HE* he
171 Returns the value slot (type C<SV*>) stored in the hash entry.
172
173 =for apidoc Am|U32|HeHASH|HE* he
174 Returns the computed hash stored in the hash entry.
175
176 =for apidoc Am|char*|HePV|HE* he|STRLEN len
177 Returns the key slot of the hash entry as a C<char*> value, doing any
178 necessary dereferencing of possibly C<SV*> keys. The length of the string
179 is placed in C<len> (this is a macro, so do I<not> use C<&len>). If you do
180 not care about what the length of the key is, you may use the global
181 variable C<PL_na>, though this is rather less efficient than using a local
182 variable. Remember though, that hash keys in perl are free to contain
183 embedded nulls, so using C<strlen()> or similar is not a good way to find
184 the length of hash keys. This is very similar to the C<SvPV()> macro
185 described elsewhere in this document.
186
187 =for apidoc Am|SV*|HeSVKEY|HE* he
188 Returns the key as an C<SV*>, or C<Nullsv> if the hash entry does not
189 contain an C<SV*> key.
190
191 =for apidoc Am|SV*|HeSVKEY_force|HE* he
192 Returns the key as an C<SV*>. Will create and return a temporary mortal
193 C<SV*> if the hash entry contains only a C<char*> key.
194
195 =for apidoc Am|SV*|HeSVKEY_set|HE* he|SV* sv
196 Sets the key to a given C<SV*>, taking care to set the appropriate flags to
197 indicate the presence of an C<SV*> key, and returns the same
198 C<SV*>.
199
200 =cut
201 */
bf6bd88 Add shared hash key support
Perl 5 Porters authored
202
bf5b86a Re: "Attempt to free non-existent shared string"? (with patch)
Gurusamy Sarathy authored
203 /* these hash entry flags ride on hent_klen (for use only in magic/tied HVs) */
d1be940 a few typo fixes
Jeffrey Friedl authored
204 #define HEf_SVKEY -2 /* hent_key is an SV* */
bf6bd88 Add shared hash key support
Perl 5 Porters authored
205
206
7907280 perl 5.0 alpha 2
Larry Wall authored
207 #define Nullhv Null(HV*)
339049b Rename the members of the SV head union to avoid pre-processor
Nicholas Clark authored
208 #define HvARRAY(hv) (*(HE***)&((hv)->sv_u.svu_array))
7907280 perl 5.0 alpha 2
Larry Wall authored
209 #define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill
463ee0b perl 5.0 alpha 4
Larry Wall authored
210 #define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max
b79f754 Store the xhv_aux structure after the main array.
Nicholas Clark authored
211 /* This quite intentionally does no flag checking first. That's your
212 responsibility. */
213 #define HvAUX(hv) ((struct xpvhv_aux*)&(HvARRAY(hv)[HvMAX(hv)+1]))
bfcb351 Move hv_name, hv_eiter and hv_riter into a new aux structure.
Nicholas Clark authored
214 #define HvRITER(hv) (*Perl_hv_riter_p(aTHX_ (HV*)(hv)))
215 #define HvEITER(hv) (*Perl_hv_eiter_p(aTHX_ (HV*)(hv)))
216 #define HvRITER_set(hv,r) Perl_hv_riter_set(aTHX_ (HV*)(hv), r)
217 #define HvEITER_set(hv,e) Perl_hv_eiter_set(aTHX_ (HV*)(hv), e)
b79f754 Store the xhv_aux structure after the main array.
Nicholas Clark authored
218 #define HvRITER_get(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_riter : -1)
219 #define HvEITER_get(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_eiter : 0)
7423f6d Store the package name as a shared HEK.
Nicholas Clark authored
220 #define HvNAME(hv) HvNAME_get(hv)
bfcb351 Move hv_name, hv_eiter and hv_riter into a new aux structure.
Nicholas Clark authored
221 /* FIXME - all of these should use a UTF8 aware API, which should also involve
222 getting the length. */
9b9d0b1 Get the HEK once only in the hot code (class method calls)
Nicholas Clark authored
223 /* This macro may go away without notice. */
b79f754 Store the xhv_aux structure after the main array.
Nicholas Clark authored
224 #define HvNAME_HEK(hv) (SvOOK(hv) ? HvAUX(hv)->xhv_name : 0)
225 #define HvNAME_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \
226 ? HEK_KEY(HvAUX(hv)->xhv_name) : 0)
227 #define HvNAMELEN_get(hv) ((SvOOK(hv) && (HvAUX(hv)->xhv_name)) \
228 ? HEK_LEN(HvAUX(hv)->xhv_name) : 0)
a0d0e21 perl 5.000
Larry Wall authored
229
8aacddc Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes
Nick Ing-Simmons authored
230 /* the number of keys (including any placeholers) */
231 #define XHvTOTALKEYS(xhv) ((xhv)->xhv_keys)
232
233 /*
234 * HvKEYS gets the number of keys that actually exist(), and is provided
235 * for backwards compatibility with old XS code. The core uses HvUSEDKEYS
236 * (keys, excluding placeholdes) and HvTOTALKEYS (including placeholders)
237 */
ca73285 Move placeholders into a new rhash magic type.
Nicholas Clark authored
238 #define HvKEYS(hv) HvUSEDKEYS(hv)
239 #define HvUSEDKEYS(hv) (HvTOTALKEYS(hv) - HvPLACEHOLDERS_get(hv))
8aacddc Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes
Nick Ing-Simmons authored
240 #define HvTOTALKEYS(hv) XHvTOTALKEYS((XPVHV*) SvANY(hv))
ca73285 Move placeholders into a new rhash magic type.
Nicholas Clark authored
241 #define HvPLACEHOLDERS(hv) (*Perl_hv_placeholders_p(aTHX_ (HV*)hv))
242 #define HvPLACEHOLDERS_get(hv) (SvMAGIC(hv) ? Perl_hv_placeholders_get(aTHX_ (HV*)hv) : 0)
243 #define HvPLACEHOLDERS_set(hv,p) Perl_hv_placeholders_set(aTHX_ (HV*)hv, p)
8aacddc Tidied version of Jeffrey Friedl's <jfriedl@yahoo.com> restricted hashes
Nick Ing-Simmons authored
244
bf6bd88 Add shared hash key support
Perl 5 Porters authored
245 #define HvSHAREKEYS(hv) (SvFLAGS(hv) & SVphv_SHAREKEYS)
246 #define HvSHAREKEYS_on(hv) (SvFLAGS(hv) |= SVphv_SHAREKEYS)
247 #define HvSHAREKEYS_off(hv) (SvFLAGS(hv) &= ~SVphv_SHAREKEYS)
248
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
249 /* This is an optimisation flag. It won't be set if all hash keys have a 0
250 * flag. Currently the only flags relate to utf8.
251 * Hence it won't be set if all keys are 8 bit only. It will be set if any key
252 * is utf8 (including 8 bit keys that were entered as utf8, and need upgrading
253 * when retrieved during iteration. It may still be set when there are no longer
254 * any utf8 keys.
fdcd69b Return 21533 (with modifications) having found the problem
Nicholas Clark authored
255 * See HVhek_ENABLEHVKFLAGS for the trigger.
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
256 */
257 #define HvHASKFLAGS(hv) (SvFLAGS(hv) & SVphv_HASKFLAGS)
258 #define HvHASKFLAGS_on(hv) (SvFLAGS(hv) |= SVphv_HASKFLAGS)
259 #define HvHASKFLAGS_off(hv) (SvFLAGS(hv) &= ~SVphv_HASKFLAGS)
574c802 @jhi If Unicode keys are entered to a hash, a bit is turned on.
jhi authored
260
bf5b86a Re: "Attempt to free non-existent shared string"? (with patch)
Gurusamy Sarathy authored
261 #define HvLAZYDEL(hv) (SvFLAGS(hv) & SVphv_LAZYDEL)
262 #define HvLAZYDEL_on(hv) (SvFLAGS(hv) |= SVphv_LAZYDEL)
263 #define HvLAZYDEL_off(hv) (SvFLAGS(hv) &= ~SVphv_LAZYDEL)
264
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
265 #define HvREHASH(hv) (SvFLAGS(hv) & SVphv_REHASH)
266 #define HvREHASH_on(hv) (SvFLAGS(hv) |= SVphv_REHASH)
267 #define HvREHASH_off(hv) (SvFLAGS(hv) &= ~SVphv_REHASH)
268
a0d0e21 perl 5.000
Larry Wall authored
269 /* Maybe amagical: */
270 /* #define HV_AMAGICmb(hv) (SvFLAGS(hv) & (SVpgv_badAM | SVpgv_AM)) */
271
272 #define HV_AMAGIC(hv) (SvFLAGS(hv) & SVpgv_AM)
273 #define HV_AMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_AM)
274 #define HV_AMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_AM)
275
276 /*
277 #define HV_AMAGICbad(hv) (SvFLAGS(hv) & SVpgv_badAM)
278 #define HV_badAMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_badAM)
279 #define HV_badAMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_badAM)
280 */
bf6bd88 Add shared hash key support
Perl 5 Porters authored
281
282 #define Nullhe Null(HE*)
283 #define HeNEXT(he) (he)->hent_next
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
284 #define HeKEY_hek(he) (he)->hent_hek
285 #define HeKEY(he) HEK_KEY(HeKEY_hek(he))
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored
286 #define HeKEY_sv(he) (*(SV**)HeKEY(he))
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
287 #define HeKLEN(he) HEK_LEN(HeKEY_hek(he))
da58a35 @jhi UTF-8 hash keys, patch from Inaba Hiroto.
jhi authored
288 #define HeKUTF8(he) HEK_UTF8(HeKEY_hek(he))
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
289 #define HeKWASUTF8(he) HEK_WASUTF8(HeKEY_hek(he))
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
290 #define HeKREHASH(he) HEK_REHASH(HeKEY_hek(he))
da58a35 @jhi UTF-8 hash keys, patch from Inaba Hiroto.
jhi authored
291 #define HeKLEN_UTF8(he) (HeKUTF8(he) ? -HeKLEN(he) : HeKLEN(he))
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
292 #define HeKFLAGS(he) HEK_FLAGS(HeKEY_hek(he))
bf6bd88 Add shared hash key support
Perl 5 Porters authored
293 #define HeVAL(he) (he)->hent_val
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
294 #define HeHASH(he) HEK_HASH(HeKEY_hek(he))
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored
295 #define HePV(he,lp) ((HeKLEN(he) == HEf_SVKEY) ? \
296 SvPV(HeKEY_sv(he),lp) : \
297 (((lp = HeKLEN(he)) >= 0) ? \
298 HeKEY(he) : Nullch))
299
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored
300 #define HeSVKEY(he) ((HeKEY(he) && \
301 HeKLEN(he) == HEf_SVKEY) ? \
302 HeKEY_sv(he) : Nullsv)
303
304 #define HeSVKEY_force(he) (HeKEY(he) ? \
305 ((HeKLEN(he) == HEf_SVKEY) ? \
306 HeKEY_sv(he) : \
79cb57f correct places that said newSVpv() when they meant newSVpvn()
Gurusamy Sarathy authored
307 sv_2mortal(newSVpvn(HeKEY(he), \
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored
308 HeKLEN(he)))) : \
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored
309 &PL_sv_undef)
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored
310 #define HeSVKEY_set(he,sv) ((HeKLEN(he) = HEf_SVKEY), (HeKEY_sv(he) = sv))
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored
311
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
312 #define Nullhek Null(HEK*)
71be2cb [inseparable changes from patch from perl5.003_13 to perl5.003_14]
Perl 5 Porters authored
313 #define HEK_BASESIZE STRUCT_OFFSET(HEK, hek_key[0])
ff68c71 [inseparable changes from patch from perl5.003_09 to perl5.003_10]
Perl 5 Porters authored
314 #define HEK_HASH(hek) (hek)->hek_hash
315 #define HEK_LEN(hek) (hek)->hek_len
316 #define HEK_KEY(hek) (hek)->hek_key
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
317 #define HEK_FLAGS(hek) (*((unsigned char *)(HEK_KEY(hek))+HEK_LEN(hek)+1))
318
319 #define HVhek_UTF8 0x01 /* Key is utf8 encoded. */
320 #define HVhek_WASUTF8 0x02 /* Key is bytes here, but was supplied as utf8. */
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
321 #define HVhek_REHASH 0x04 /* This key is in an hv using a custom HASH . */
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
322 #define HVhek_FREEKEY 0x100 /* Internal flag to say key is malloc()ed. */
e16e2ff [dodgy PATCH] Re: [Storable] utf8 keys started working!
Nicholas Clark authored
323 #define HVhek_PLACEHOLD 0x200 /* Internal flag to create placeholder.
324 * (may change, but Storable is a core module) */
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
325 #define HVhek_MASK 0xFF
326
fdcd69b Return 21533 (with modifications) having found the problem
Nicholas Clark authored
327 /* Which flags enable HvHASKFLAGS? Somewhat a hack on a hack, as
328 HVhek_REHASH is only needed because the rehash flag has to be duplicated
329 into all keys as hv_iternext has no access to the hash flags. At this
330 point Storable's tests get upset, because sometimes hashes are "keyed"
331 and sometimes not, depending on the order of data insertion, and whether
332 it triggered rehashing. So currently HVhek_REHAS is exempt.
333 */
334
335 #define HVhek_ENABLEHVKFLAGS (HVhek_MASK - HVhek_REHASH)
336
19692e8 Re: the dirty half dozen (Re: perl@15662)
Nicholas Clark authored
337 #define HEK_UTF8(hek) (HEK_FLAGS(hek) & HVhek_UTF8)
338 #define HEK_UTF8_on(hek) (HEK_FLAGS(hek) |= HVhek_UTF8)
339 #define HEK_UTF8_off(hek) (HEK_FLAGS(hek) &= ~HVhek_UTF8)
340 #define HEK_WASUTF8(hek) (HEK_FLAGS(hek) & HVhek_WASUTF8)
341 #define HEK_WASUTF8_on(hek) (HEK_FLAGS(hek) |= HVhek_WASUTF8)
342 #define HEK_WASUTF8_off(hek) (HEK_FLAGS(hek) &= ~HVhek_WASUTF8)
4b5190b Plan C for foiling the algorithmic complexity attack
Nicholas Clark authored
343 #define HEK_REHASH(hek) (HEK_FLAGS(hek) & HVhek_REHASH)
344 #define HEK_REHASH_on(hek) (HEK_FLAGS(hek) |= HVhek_REHASH)
d18c611 preliminary support for perl_clone() (still needs work in
Gurusamy Sarathy authored
345
5cbe4ee hv.h Doc Patch
Mark Fisher authored
346 /* calculate HV array allocation */
36768cf Default to allocating the correct size for the array in the HV.
Nicholas Clark authored
347 #ifndef PERL_USE_LARGE_HV_ALLOC
348 /* Default to allocating the correct size - default to assuming that malloc()
349 is not broken and is efficient at allocating blocks sized at powers-of-two.
350 */
d18c611 preliminary support for perl_clone() (still needs work in
Gurusamy Sarathy authored
351 # define PERL_HV_ARRAY_ALLOC_BYTES(size) ((size) * sizeof(HE*))
352 #else
353 # define MALLOC_OVERHEAD 16
354 # define PERL_HV_ARRAY_ALLOC_BYTES(size) \
355 (((size) < 64) \
356 ? (size) * sizeof(HE*) \
357 : (size) * sizeof(HE*) * 2 - MALLOC_OVERHEAD)
358 #endif
37d85e3 @jhi Make sharepvn a macro since all it does is a deref.
jhi authored
359
e16e2ff [dodgy PATCH] Re: [Storable] utf8 keys started working!
Nicholas Clark authored
360 /* Flags for hv_iternext_flags. */
361 #define HV_ITERNEXT_WANTPLACEHOLDERS 0x01 /* Don't skip placeholders. */
362
37d85e3 @jhi Make sharepvn a macro since all it does is a deref.
jhi authored
363 /* available as a function in hv.c */
364 #define Perl_sharepvn(sv, len, hash) HEK_KEY(share_hek(sv, len, hash))
365 #define sharepvn(sv, len, hash) Perl_sharepvn(sv, len, hash)
bfcb351 Move hv_name, hv_eiter and hv_riter into a new aux structure.
Nicholas Clark authored
366
367 /*
368 * Local variables:
369 * c-indentation-style: bsd
370 * c-basic-offset: 4
371 * indent-tabs-mode: t
372 * End:
373 *
374 * ex: set ts=8 sts=4 sw=4 noet:
375 */
Something went wrong with that request. Please try again.