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
|
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Hash::Util PACKAGE = Hash::Util
SV*
all_keys(hash,keys,placeholder)
SV* hash
SV* keys
SV* placeholder
PROTOTYPE: \%\@\@
PREINIT:
AV* av_k;
AV* av_p;
HV* hv;
SV *key;
HE *he;
CODE:
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
croak("First argument to all_keys() must be an HASH reference");
if (!SvROK(keys) || SvTYPE(SvRV(keys)) != SVt_PVAV)
croak("Second argument to all_keys() must be an ARRAY reference");
if (!SvROK(placeholder) || SvTYPE(SvRV(placeholder)) != SVt_PVAV)
croak("Third argument to all_keys() must be an ARRAY reference");
hv = (HV*)SvRV(hash);
av_k = (AV*)SvRV(keys);
av_p = (AV*)SvRV(placeholder);
av_clear(av_k);
av_clear(av_p);
(void)hv_iterinit(hv);
while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
key=hv_iterkeysv(he);
if (HeVAL(he) == &PL_sv_placeholder) {
SvREFCNT_inc(key);
av_push(av_p, key);
} else {
SvREFCNT_inc(key);
av_push(av_k, key);
}
}
RETVAL=hash;
void
hidden_ref_keys(hash)
SV* hash
PREINIT:
HV* hv;
SV *key;
HE *he;
PPCODE:
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
croak("First argument to hidden_keys() must be an HASH reference");
hv = (HV*)SvRV(hash);
(void)hv_iterinit(hv);
while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
key=hv_iterkeysv(he);
if (HeVAL(he) == &PL_sv_placeholder) {
XPUSHs( key );
}
}
void
legal_ref_keys(hash)
SV* hash
PREINIT:
HV* hv;
SV *key;
HE *he;
PPCODE:
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
croak("First argument to legal_keys() must be an HASH reference");
hv = (HV*)SvRV(hash);
(void)hv_iterinit(hv);
while((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
key=hv_iterkeysv(he);
XPUSHs( key );
}
SV*
hv_store(hvref, key, val)
SV* hvref
SV* key
SV* val
PROTOTYPE: \%$$
PREINIT:
HV* hv;
CODE:
{
if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV)
croak("First argument to alias_hv() must be a hash reference");
hv = (HV*)SvRV(hvref);
SvREFCNT_inc(val);
if (!hv_store_ent(hv, key, val, 0)) {
SvREFCNT_dec(val);
XSRETURN_NO;
} else {
XSRETURN_YES;
}
}
OUTPUT:
RETVAL
|