| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| |
| 3 |
|
| #ifdef __cplusplus |
| 4 |
|
| extern "C++" { |
| 5 |
|
| #include <algorithm> |
| 6 |
|
| } |
| 7 |
|
| #endif |
| 8 |
|
| |
| 9 |
|
| extern "C" { |
| 10 |
|
| #include "EXTERN.h" |
| 11 |
|
| #include "perl.h" |
| 12 |
|
| #include "XSUB.h" |
| 13 |
|
| } |
| 14 |
|
| |
| 15 |
|
| static MGVTBL sv_payload_marker; |
| 16 |
|
| static bool optimize_entersub = 1; |
| 17 |
|
| static int unstolen = 0; |
| 18 |
|
| |
| 19 |
|
| #include "xs/compat.h" |
| 20 |
|
| #include "xs/types.h" |
| 21 |
|
| #include "xs/accessors.h" |
| 22 |
|
| #include "xs/installer.h" |
| 23 |
|
| |
| 24 |
|
| static void |
| 25 |
460 |
| CAIXS_install_inherited_accessor(pTHX_ SV* full_name, SV* hash_key, SV* pkg_key, SV* read_cb, SV* write_cb, int opts) { |
| 26 |
|
| shared_keys* payload; |
| 27 |
460 |
▶ | bool need_cb = read_cb && write_cb; |
Branch: 2 branches
| Branch | True | False | Total |
| bool need_cb = read_cb && write_cb; |
14 |
446 |
460 |
| bool need_cb = read_cb && write_cb; |
14 |
0 |
14 |
|
| 28 |
|
| |
| 29 |
460 |
▶ | if (need_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_cb) { |
14 |
446 |
460 |
|
| 30 |
|
| assert(pkg_key != NULL); |
| 31 |
|
| |
| 32 |
14 |
▶ | if (opts & IsNamed) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (opts & IsNamed) { |
2 |
12 |
14 |
|
| 33 |
2 |
| payload = CAIXS_install_accessor<InheritedCbNamed>(aTHX_ full_name, (AccessorOpts)(opts & ~IsNamed)); |
| 34 |
|
| } else { |
| 35 |
12 |
| payload = CAIXS_install_accessor<InheritedCb>(aTHX_ full_name, (AccessorOpts)opts); |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
446 |
▶ | } else if (pkg_key != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (pkg_key != NULL) { |
440 |
6 |
446 |
|
| 39 |
440 |
| payload = CAIXS_install_accessor<Inherited>(aTHX_ full_name, (AccessorOpts)opts); |
| 40 |
|
| |
| 41 |
|
| } else { |
| 42 |
6 |
| payload = CAIXS_install_accessor<ObjectOnly>(aTHX_ full_name, (AccessorOpts)opts); |
| 43 |
|
| } |
| 44 |
|
| |
| 45 |
|
| STRLEN len; |
| 46 |
460 |
| const char* hash_key_buf = SvPV_const(hash_key, len); |
| 47 |
460 |
▶ | SV* s_hash_key = newSVpvn_share(hash_key_buf, SvUTF8(hash_key) ? -(I32)len : (I32)len, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* s_hash_key = newSVpvn_share(hash_key_buf, SvUTF8(hash_key) ? -(I32)len : (I32)len, 0); |
2 |
458 |
460 |
|
| 48 |
460 |
| payload->hash_key = s_hash_key; |
| 49 |
|
| |
| 50 |
460 |
▶ | if (pkg_key != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pkg_key != NULL) { |
454 |
6 |
460 |
|
| 51 |
454 |
| const char* pkg_key_buf = SvPV_const(pkg_key, len); |
| 52 |
454 |
▶ | SV* s_pkg_key = newSVpvn_share(pkg_key_buf, SvUTF8(pkg_key) ? -(I32)len : (I32)len, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* s_pkg_key = newSVpvn_share(pkg_key_buf, SvUTF8(pkg_key) ? -(I32)len : (I32)len, 0); |
2 |
452 |
454 |
|
| 53 |
454 |
| payload->pkg_key = s_pkg_key; |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
460 |
▶ | if (need_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_cb) { |
14 |
446 |
460 |
|
| 57 |
14 |
▶ | if (SvROK(read_cb) && SvTYPE(SvRV(read_cb)) == SVt_PVCV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(read_cb) && SvTYPE(SvRV(read_cb)) == SVt_PVCV) { |
12 |
2 |
14 |
| if (SvROK(read_cb) && SvTYPE(SvRV(read_cb)) == SVt_PVCV) { |
12 |
0 |
12 |
|
| 58 |
12 |
| payload->read_cb = SvREFCNT_inc_NN(SvRV(read_cb)); |
| 59 |
|
| } else { |
| 60 |
2 |
| payload->read_cb = NULL; |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
14 |
▶ | if (SvROK(write_cb) && SvTYPE(SvRV(write_cb)) == SVt_PVCV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(write_cb) && SvTYPE(SvRV(write_cb)) == SVt_PVCV) { |
9 |
5 |
14 |
| if (SvROK(write_cb) && SvTYPE(SvRV(write_cb)) == SVt_PVCV) { |
9 |
0 |
9 |
|
| 64 |
9 |
| payload->write_cb = SvREFCNT_inc_NN(SvRV(write_cb)); |
| 65 |
|
| } else { |
| 66 |
5 |
| payload->write_cb = NULL; |
| 67 |
|
| } |
| 68 |
|
| } |
| 69 |
460 |
| } |
| 70 |
|
| |
| 71 |
|
| static void |
| 72 |
427 |
| CAIXS_install_class_accessor(pTHX_ SV* full_name, SV* default_sv, bool is_varclass, int opts) { |
| 73 |
427 |
▶ | bool is_lazy = SvROK(default_sv) && SvTYPE(SvRV(default_sv)) == SVt_PVCV; |
Branch: 2 branches
| Branch | True | False | Total |
| bool is_lazy = SvROK(default_sv) && SvTYPE(SvRV(default_sv)) == SVt_PVCV; |
408 |
19 |
427 |
| bool is_lazy = SvROK(default_sv) && SvTYPE(SvRV(default_sv)) == SVt_PVCV; |
408 |
0 |
408 |
|
| 74 |
|
| |
| 75 |
|
| shared_keys* payload; |
| 76 |
427 |
▶ | if (is_lazy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_lazy) { |
408 |
19 |
427 |
|
| 77 |
408 |
| payload = CAIXS_install_accessor<LazyClass>(aTHX_ full_name, (AccessorOpts)opts); |
| 78 |
|
| |
| 79 |
|
| } else { |
| 80 |
19 |
| payload = CAIXS_install_accessor<PrivateClass>(aTHX_ full_name, (AccessorOpts)opts); |
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
427 |
▶ | if (is_varclass) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_varclass) { |
8 |
419 |
427 |
|
| 84 |
8 |
| GV* gv = gv_fetchsv(full_name, GV_ADD, SVt_PV); |
| 85 |
|
| assert(gv); |
| 86 |
|
| |
| 87 |
8 |
| payload->storage = GvSV(gv); |
| 88 |
|
| assert(payload->storage); |
| 89 |
|
| |
| 90 |
|
| /* We take ownership of this glob slot, so if someone changes the glob - they're in trouble */ |
| 91 |
8 |
| SvREFCNT_inc_simple_void_NN(payload->storage); |
| 92 |
|
| |
| 93 |
|
| } else { |
| 94 |
419 |
| payload->storage = newSV(0); |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
427 |
▶ | if (SvOK(default_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(default_sv)) { |
410 |
17 |
427 |
|
| 98 |
410 |
▶ | if (is_lazy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_lazy) { |
408 |
2 |
410 |
|
| 99 |
408 |
| payload->lazy_cb = SvREFCNT_inc_NN(SvRV(default_sv)); |
| 100 |
|
| |
| 101 |
|
| } else { |
| 102 |
2 |
| sv_setsv(payload->storage, default_sv); |
| 103 |
|
| } |
| 104 |
|
| } |
| 105 |
427 |
| } |
| 106 |
|
| |
| 107 |
|
| MODULE = Class::Accessor::Inherited::XS PACKAGE = Class::Accessor::Inherited::XS |
| 108 |
|
| PROTOTYPES: DISABLE |
| 109 |
|
| |
| 110 |
|
| BOOT: |
| 111 |
|
| { |
| 112 |
42 |
| SV** check_env = hv_fetch(GvHV(PL_envgv), "CAIXS_DISABLE_ENTERSUB", 22, 0); |
| 113 |
42 |
▶ | if (check_env && SvTRUE(*check_env)) optimize_entersub = 0; |
Branch: 3 branches
| Branch | True | False | Total |
| if (check_env && SvTRUE(*check_env)) optimize_entersub = 0; |
0 |
42 |
42 |
| if (check_env && SvTRUE(*check_env)) optimize_entersub = 0; |
0 |
0 |
0 |
| if (check_env && SvTRUE(*check_env)) optimize_entersub = 0; |
0 |
42 |
42 |
|
| 114 |
|
| #ifdef CAIX_OPTIMIZE_OPMETHOD |
| 115 |
|
| MUTEX_LOCK(&PL_my_ctx_mutex); |
| 116 |
42 |
| qsort(accessor_map, ACCESSOR_MAP_SIZE, sizeof(accessor_cb_pair_t), CAIXS_map_compare); |
| 117 |
|
| MUTEX_UNLOCK(&PL_my_ctx_mutex); |
| 118 |
|
| #endif |
| 119 |
42 |
| HV* stash = gv_stashpv("Class::Accessor::Inherited::XS", 0); |
| 120 |
42 |
| newCONSTSUB(stash, "BINARY_UNSAFE", CAIX_BINARY_UNSAFE_RESULT); |
| 121 |
42 |
| newCONSTSUB(stash, "OPTIMIZED_OPMETHOD", CAIX_OPTIMIZE_OPMETHOD_RESULT); |
| 122 |
|
| } |
| 123 |
|
| |
| 124 |
|
| void |
| 125 |
|
| install_object_accessor(SV* full_name, SV* hash_key, int opts) |
| 126 |
|
| PPCODE: |
| 127 |
|
| { |
| 128 |
6 |
| CAIXS_install_inherited_accessor(aTHX_ full_name, hash_key, NULL, NULL, NULL, opts); |
| 129 |
6 |
| XSRETURN_UNDEF; |
| 130 |
|
| } |
| 131 |
|
| |
| 132 |
|
| void |
| 133 |
|
| install_inherited_accessor(SV* full_name, SV* hash_key, SV* pkg_key, int opts) |
| 134 |
|
| PPCODE: |
| 135 |
|
| { |
| 136 |
440 |
| CAIXS_install_inherited_accessor(aTHX_ full_name, hash_key, pkg_key, NULL, NULL, opts); |
| 137 |
440 |
| XSRETURN_UNDEF; |
| 138 |
|
| } |
| 139 |
|
| |
| 140 |
|
| void |
| 141 |
|
| install_inherited_cb_accessor(SV* full_name, SV* hash_key, SV* pkg_key, SV* read_cb, SV* write_cb, int opts) |
| 142 |
|
| PPCODE: |
| 143 |
|
| { |
| 144 |
14 |
| CAIXS_install_inherited_accessor(aTHX_ full_name, hash_key, pkg_key, read_cb, write_cb, opts); |
| 145 |
14 |
| XSRETURN_UNDEF; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
|
| void |
| 149 |
|
| install_class_accessor(SV* full_name, SV* default_sv, SV* is_varclass, SV* opts) |
| 150 |
|
| PPCODE: |
| 151 |
|
| { |
| 152 |
427 |
| CAIXS_install_class_accessor(aTHX_ full_name, default_sv, SvTRUE(is_varclass), SvIV(opts)); |
| 153 |
427 |
| XSRETURN_UNDEF; |
| 154 |
|
| } |
| 155 |
|
| |
| 156 |
|
| void |
| 157 |
|
| install_constructor(SV* full_name) |
| 158 |
|
| PPCODE: |
| 159 |
|
| { |
| 160 |
3 |
| CAIXS_install_cv<Constructor, None>(aTHX_ full_name); |
| 161 |
3 |
| XSRETURN_UNDEF; |
| 162 |
|
| } |
| 163 |
|
| |
| 164 |
|
| MODULE = Class::Accessor::Inherited::XS PACKAGE = Class::Accessor::Inherited::XS::Constants |
| 165 |
|
| PROTOTYPES: DISABLE |
| 166 |
|
| |
| 167 |
|
| BOOT: |
| 168 |
|
| { |
| 169 |
42 |
| HV* stash = gv_stashpv("Class::Accessor::Inherited::XS::Constants", GV_ADD); |
| 170 |
42 |
| AV* exp = get_av("Class::Accessor::Inherited::XS::Constants::EXPORT", GV_ADD); |
| 171 |
|
| #define RGSTR(c) \ |
| 172 |
|
| newCONSTSUB(stash, #c , newSViv(c)); \ |
| 173 |
|
| av_push(exp, newSVpvn(#c, strlen(#c))); |
| 174 |
42 |
| RGSTR(None); |
| 175 |
42 |
| RGSTR(IsReadonly); |
| 176 |
42 |
| RGSTR(IsWeak); |
| 177 |
42 |
| RGSTR(IsNamed); |
| 178 |
|
| |
| 179 |
42 |
| AV* isa = get_av("Class::Accessor::Inherited::XS::Constants::ISA", GV_ADD); |
| 180 |
42 |
| av_push(isa, newSVpvs("Exporter")); |
| 181 |
|
| |
| 182 |
42 |
| hv_stores(get_hv("INC", GV_ADD), "Class/Accessor/Inherited/XS/Constants.pm", &PL_sv_yes); |
| 183 |
|
| } |
| 184 |
|
| |
| 185 |
|
| MODULE = Class::Accessor::Inherited::XS PACKAGE = Class::Accessor::Inherited::XS::Debug |
| 186 |
|
| PROTOTYPES: DISABLE |
| 187 |
|
| |
| 188 |
|
| void unstolen_count() |
| 189 |
|
| PPCODE: |
| 190 |
|
| { |
| 191 |
5 |
| XSRETURN_IV(unstolen); |
| 192 |
|
| } |