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