This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert Hash::Util's XS code to use typemaps for dereferencing.
[perl5.git] / ext / Hash-Util / Util.xs
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5
6 MODULE = Hash::Util             PACKAGE = Hash::Util
7
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             if (HeVAL(he) == &PL_sv_placeholder) {
26                 SvREFCNT_inc(key);
27                 av_push(placeholder, key);
28             } else {
29                 SvREFCNT_inc(key);
30                 av_push(keys, key);
31             }
32         }
33         XSRETURN(1);
34
35 void
36 hidden_ref_keys(hash)
37         HV *hash
38     PREINIT:
39         SV *key;
40         HE *he;
41     PPCODE:
42         (void)hv_iterinit(hash);
43         while((he = hv_iternext_flags(hash, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
44             key=hv_iterkeysv(he);
45             if (HeVAL(he) == &PL_sv_placeholder) {
46                 XPUSHs( key );
47             }
48         }
49
50 void
51 legal_ref_keys(hash)
52         HV *hash
53     PREINIT:
54         SV *key;
55         HE *he;
56     PPCODE:
57         (void)hv_iterinit(hash);
58         while((he = hv_iternext_flags(hash, HV_ITERNEXT_WANTPLACEHOLDERS))!= NULL) {
59             key=hv_iterkeysv(he);
60             XPUSHs( key );
61         }
62
63 void
64 hv_store(hash, key, val)
65         HV *hash
66         SV* key
67         SV* val
68     PROTOTYPE: \%$$
69     CODE:
70     {
71         SvREFCNT_inc(val);
72         if (!hv_store_ent(hash, key, val, 0)) {
73             SvREFCNT_dec(val);
74             XSRETURN_NO;
75         } else {
76             XSRETURN_YES;
77         }
78     }