| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "AutoXS.h" |
| 6 |
|
| |
| 7 |
|
| MODULE = Class::Accessor::Fast::XS PACKAGE = Class::Accessor::Fast::XS |
| 8 |
|
| |
| 9 |
|
| |
| 10 |
|
| void |
| 11 |
|
| _xs_ro_accessor(self, ...) |
| 12 |
|
| SV* self; |
| 13 |
|
| PROTOTYPE: DISABLE |
| 14 |
|
| ALIAS: |
| 15 |
|
| INIT: |
| 16 |
|
| /* Get the const hash key struct from the global storage */ |
| 17 |
|
| /* ix is the magic integer variable that is set by the perl guts for us. |
| 18 |
|
| * We uses it to identify the currently running alias of the accessor. Gollum! */ |
| 19 |
7 |
| const autoxs_hashkey readfrom = AutoXS_hashkeys[ix]; |
| 20 |
|
| HE* he; |
| 21 |
|
| PPCODE: |
| 22 |
7 |
▶ | if ( items > 1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items > 1 ) |
1 |
6 |
7 |
|
| 23 |
1 |
| croak("cannot alter readonly value"); |
| 24 |
|
| |
| 25 |
6 |
▶ | if ( he = hv_fetch_ent((HV *)SvRV(self), readfrom.key, 0, readfrom.hash) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( he = hv_fetch_ent((HV *)SvRV(self), readfrom.key, 0, readfrom.hash) ) |
5 |
1 |
6 |
|
| 26 |
5 |
| PUSHs(HeVAL(he)); |
| 27 |
|
| else |
| 28 |
1 |
| XSRETURN_UNDEF; |
| 29 |
|
| |
| 30 |
|
| void |
| 31 |
|
| _xs_wo_accessor(self, ...) |
| 32 |
|
| SV* self; |
| 33 |
|
| ALIAS: |
| 34 |
|
| INIT: |
| 35 |
|
| /* Get the const hash key struct from the global storage */ |
| 36 |
|
| /* ix is the magic integer variable that is set by the perl guts for us. |
| 37 |
|
| * We uses it to identify the currently running alias of the accessor. Gollum! */ |
| 38 |
|
| HE *res; |
| 39 |
|
| SV *newvalue; |
| 40 |
|
| IV i; |
| 41 |
5 |
| const autoxs_hashkey readfrom = AutoXS_hashkeys[ix]; |
| 42 |
|
| PPCODE: |
| 43 |
5 |
▶ | if ( items == 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items == 2 ) { |
3 |
2 |
5 |
|
| 44 |
3 |
| newvalue = newSVsv(ST(1)); |
| 45 |
2 |
▶ | } else if ( items > 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( items > 2 ) { |
1 |
1 |
2 |
|
| 46 |
1 |
| AV* tmp = newAV(); |
| 47 |
1 |
| av_extend(tmp, items-1); |
| 48 |
4 |
▶ | for(i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 1; i < items; i++) { |
3 |
1 |
4 |
|
| 49 |
3 |
| newvalue = newSVsv(ST(i)); |
| 50 |
3 |
▶ | if (!av_store(tmp, i - 1, newvalue)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av_store(tmp, i - 1, newvalue)) { |
0 |
3 |
3 |
|
| 51 |
0 |
| SvREFCNT_dec(newvalue); |
| 52 |
0 |
| croak("cannot store value in array"); |
| 53 |
|
| } |
| 54 |
|
| } |
| 55 |
1 |
| newvalue = newRV_noinc((SV*) tmp); |
| 56 |
|
| } else { |
| 57 |
1 |
| croak("cannot access writeonly value"); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
4 |
▶ | if (res = hv_store_ent((HV*)SvRV(self), readfrom.key, newvalue, readfrom.hash)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res = hv_store_ent((HV*)SvRV(self), readfrom.key, newvalue, readfrom.hash)) { |
4 |
0 |
4 |
|
| 61 |
4 |
| PUSHs(HeVAL(res)); |
| 62 |
|
| } else { |
| 63 |
0 |
| SvREFCNT_dec(newvalue); |
| 64 |
0 |
| croak("Failed to write new value to hash."); |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| void |
| 68 |
|
| _xs_accessor(self, ...) |
| 69 |
|
| SV* self; |
| 70 |
|
| ALIAS: |
| 71 |
|
| INIT: |
| 72 |
|
| HE *res; |
| 73 |
|
| SV *newvalue; |
| 74 |
|
| IV i; |
| 75 |
|
| /* Get the const hash key struct from the global storage */ |
| 76 |
|
| /* ix is the magic integer variable that is set by the perl guts for us. |
| 77 |
|
| * We uses it to identify the currently running alias of the accessor. Gollum! */ |
| 78 |
25 |
| const autoxs_hashkey readfrom = AutoXS_hashkeys[ix]; |
| 79 |
|
| PPCODE: |
| 80 |
25 |
▶ | if ( items == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items == 1 ) { |
18 |
7 |
25 |
|
| 81 |
18 |
| res = hv_fetch_ent((HV *)SvRV(self), readfrom.key, 0, readfrom.hash); |
| 82 |
18 |
▶ | if (res == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (res == NULL) |
5 |
13 |
18 |
|
| 83 |
5 |
| XSRETURN_UNDEF; |
| 84 |
|
| |
| 85 |
13 |
| PUSHs(HeVAL(res)); |
| 86 |
13 |
| XSRETURN(1); |
| 87 |
|
| } |
| 88 |
7 |
▶ | else if ( items == 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( items == 2 ) { |
5 |
2 |
7 |
|
| 89 |
5 |
| newvalue = newSVsv(ST(1)); |
| 90 |
|
| } |
| 91 |
|
| else { |
| 92 |
2 |
| AV* tmp = newAV(); |
| 93 |
2 |
| av_extend(tmp, items-1); |
| 94 |
7 |
▶ | for(i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 1; i < items; i++) { |
5 |
2 |
7 |
|
| 95 |
5 |
| newvalue = newSVsv(ST(i)); |
| 96 |
5 |
▶ | if (!av_store(tmp, i - 1, newvalue)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!av_store(tmp, i - 1, newvalue)) { |
0 |
5 |
5 |
|
| 97 |
0 |
| SvREFCNT_dec(newvalue); |
| 98 |
0 |
| croak("Cannot store value in array"); |
| 99 |
|
| } |
| 100 |
|
| } |
| 101 |
2 |
| newvalue = newRV_noinc((SV*) tmp); |
| 102 |
|
| } |
| 103 |
7 |
▶ | if (res = hv_store_ent((HV*)SvRV(self), readfrom.key, newvalue, readfrom.hash)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res = hv_store_ent((HV*)SvRV(self), readfrom.key, newvalue, readfrom.hash)) { |
7 |
0 |
7 |
|
| 104 |
7 |
| PUSHs(HeVAL(res)); |
| 105 |
|
| } else { |
| 106 |
0 |
| SvREFCNT_dec(newvalue); |
| 107 |
0 |
| croak("Failed to write new value to hash."); |
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
|
| void |
| 111 |
|
| xs_make_ro_accessor(name, key) |
| 112 |
|
| char* name; |
| 113 |
|
| char* key; |
| 114 |
|
| INIT: |
| 115 |
|
| autoxs_hashkey hashkey; |
| 116 |
|
| unsigned int len; |
| 117 |
|
| PPCODE: |
| 118 |
8 |
| char* file = __FILE__; |
| 119 |
8 |
| const unsigned int functionIndex = get_next_hashkey(); |
| 120 |
|
| { |
| 121 |
|
| CV * cv; |
| 122 |
|
| /* This code is very similar to what you get from using the ALIAS XS syntax. |
| 123 |
|
| * Except I took it from the generated C code. Hic sunt dragones, I suppose... */ |
| 124 |
8 |
| cv = newXS(name, XS_Class__Accessor__Fast__XS__xs_ro_accessor, file); |
| 125 |
8 |
▶ | if (cv == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cv == NULL) |
0 |
8 |
8 |
|
| 126 |
0 |
| croak("ARG! SOMETHING WENT REALLY WRONG!"); |
| 127 |
8 |
| XSANY.any_i32 = functionIndex; |
| 128 |
|
| |
| 129 |
|
| /* Precompute the hash of the key and store it in the global structure */ |
| 130 |
8 |
| len = strlen(key); |
| 131 |
8 |
| hashkey.key = newSVpvn(key, len); |
| 132 |
8 |
▶ | PERL_HASH(hashkey.hash, key, len); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_HASH(hashkey.hash, key, len); |
8 |
0 |
8 |
|
| 133 |
8 |
| AutoXS_hashkeys[functionIndex] = hashkey; |
| 134 |
|
| } |
| 135 |
|
| |
| 136 |
|
| void |
| 137 |
|
| xs_make_wo_accessor(name, key) |
| 138 |
|
| char* name; |
| 139 |
|
| char* key; |
| 140 |
|
| INIT: |
| 141 |
|
| autoxs_hashkey hashkey; |
| 142 |
|
| unsigned int len; |
| 143 |
|
| PPCODE: |
| 144 |
8 |
| char* file = __FILE__; |
| 145 |
8 |
| const unsigned int functionIndex = get_next_hashkey(); |
| 146 |
|
| { |
| 147 |
|
| CV * cv; |
| 148 |
|
| /* This code is very similar to what you get from using the ALIAS XS syntax. |
| 149 |
|
| * Except I took it from the generated C code. Hic sunt dragones, I suppose... */ |
| 150 |
8 |
| cv = newXS(name, XS_Class__Accessor__Fast__XS__xs_wo_accessor, file); |
| 151 |
8 |
▶ | if (cv == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cv == NULL) |
0 |
8 |
8 |
|
| 152 |
0 |
| croak("ARG! SOMETHING WENT REALLY WRONG!"); |
| 153 |
8 |
| XSANY.any_i32 = functionIndex; |
| 154 |
|
| |
| 155 |
|
| /* Precompute the hash of the key and store it in the global structure */ |
| 156 |
8 |
| len = strlen(key); |
| 157 |
8 |
| hashkey.key = newSVpvn(key, len); |
| 158 |
8 |
▶ | PERL_HASH(hashkey.hash, key, len); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_HASH(hashkey.hash, key, len); |
8 |
0 |
8 |
|
| 159 |
8 |
| AutoXS_hashkeys[functionIndex] = hashkey; |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
|
| void |
| 163 |
|
| xs_make_accessor(name, key) |
| 164 |
|
| char* name; |
| 165 |
|
| char* key; |
| 166 |
|
| INIT: |
| 167 |
|
| autoxs_hashkey hashkey; |
| 168 |
|
| unsigned int len; |
| 169 |
|
| PPCODE: |
| 170 |
11 |
| char* file = __FILE__; |
| 171 |
11 |
| const unsigned int functionIndex = get_next_hashkey(); |
| 172 |
|
| { |
| 173 |
|
| CV * cv; |
| 174 |
|
| /* This code is very similar to what you get from using the ALIAS XS syntax. |
| 175 |
|
| * Except I took it from the generated C code. Hic sunt dragones, I suppose... */ |
| 176 |
11 |
| cv = newXS(name, XS_Class__Accessor__Fast__XS__xs_accessor, file); |
| 177 |
11 |
▶ | if (cv == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cv == NULL) |
0 |
11 |
11 |
|
| 178 |
0 |
| croak("ARG! SOMETHING WENT REALLY WRONG!"); |
| 179 |
11 |
| XSANY.any_i32 = functionIndex; |
| 180 |
|
| |
| 181 |
|
| /* Precompute the hash of the key and store it in the global structure */ |
| 182 |
11 |
| len = strlen(key); |
| 183 |
11 |
| hashkey.key = newSVpvn(key, len); |
| 184 |
11 |
▶ | PERL_HASH(hashkey.hash, key, len); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_HASH(hashkey.hash, key, len); |
11 |
0 |
11 |
|
| 185 |
11 |
| AutoXS_hashkeys[functionIndex] = hashkey; |
| 186 |
|
| } |
| 187 |
|
| |