This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add PERL_NO_GET_CONTEXT to Hash::Util
[perl5.git] / ext / Hash-Util / Util.xs
1 #define PERL_NO_GET_CONTEXT
2
3 #include "EXTERN.h"
4 #include "perl.h"
5 #include "XSUB.h"
6
7 MODULE = Hash::Util             PACKAGE = Hash::Util
8
9 void
10 all_keys(hash,keys,placeholder)
11         HV *hash
12         AV *keys
13         AV *placeholder
14     PROTOTYPE: \%\@\@
15     PREINIT:
16         SV *key;
17         HE *he;
18     PPCODE:
19         av_clear(keys);
20         av_clear(placeholder);
21
22         (void)hv_iterinit(hash);
23         while((he = hv_iternext_flags(hash, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
24             key=hv_iterkeysv(he);
25             av_push(HeVAL(he) == &PL_sv_placeholder ? placeholder : keys,
26                     SvREFCNT_inc(key));
27         }
28         XSRETURN(1);
29
30 void
31 hidden_ref_keys(hash)
32         HV *hash
33     ALIAS:
34         Hash::Util::legal_ref_keys = 1
35     PREINIT:
36         SV *key;
37         HE *he;
38     PPCODE:
39         (void)hv_iterinit(hash);
40         while((he = hv_iternext_flags(hash, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
41             key=hv_iterkeysv(he);
42             if (ix || HeVAL(he) == &PL_sv_placeholder) {
43                 XPUSHs( key );
44             }
45         }
46
47 void
48 hv_store(hash, key, val)
49         HV *hash
50         SV* key
51         SV* val
52     PROTOTYPE: \%$$
53     CODE:
54     {
55         SvREFCNT_inc(val);
56         if (!hv_store_ent(hash, key, val, 0)) {
57             SvREFCNT_dec(val);
58             XSRETURN_NO;
59         } else {
60             XSRETURN_YES;
61         }
62     }