| 1 | #ifndef MOUSE_H | ||
| 2 | #define MOUSE_H | ||
| 3 | |||
| 4 | /* used by 'ppport.h' Devel-PPPort */ | ||
| 5 | #define NEED_croak_xs_usage | ||
| 6 | #define NEED_gv_fetchpvn_flags | ||
| 7 | #define NEED_mg_findext | ||
| 8 | #define NEED_newSVpvn_flags | ||
| 9 | #define NEED_newSVpvn_share | ||
| 10 | #define NEED_SvRX | ||
| 11 | #define NEED_warner | ||
| 12 | #define NEED_grok_number | ||
| 13 | #define NEED_grok_numeric_radix | ||
| 14 | |||
| 15 | #define PERL_EUPXS_ALWAYS_EXPORT | ||
| 16 | |||
| 17 | #include "xshelper.h" | ||
| 18 | |||
| 19 | #ifndef mro_get_linear_isa | ||
| 20 | #define no_mro_get_linear_isa | ||
| 21 | #define mro_get_linear_isa(stash) mouse_mro_get_linear_isa(aTHX_ stash) | ||
| 22 | AV* mouse_mro_get_linear_isa(pTHX_ HV* const stash); | ||
| 23 | #define mro_method_changed_in(stash) ((void)++PL_sub_generation) | ||
| 24 | #endif /* !mro_get_linear_isa */ | ||
| 25 | |||
| 26 | #ifndef mro_get_pkg_gen | ||
| 27 | #ifdef no_mro_get_linear_isa | ||
| 28 | #define mro_get_pkg_gen(stash) ((void)stash, PL_sub_generation) | ||
| 29 | #else | ||
| 30 | #define mro_get_pkg_gen(stash) (HvAUX(stash)->xhv_mro_meta ? HvAUX(stash)->xhv_mro_meta->pkg_gen : (U32)0) | ||
| 31 | #endif /* !no_mro_get_linear_isa */ | ||
| 32 | #endif /* mro_get_package_gen */ | ||
| 33 | |||
| 34 | #ifndef GvCV_set | ||
| 35 | #define GvCV_set(gv, cv) (GvCV(gv) = (cv)) | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifndef PERL_STATIC_INLINE | ||
| 39 | #ifdef NOINLINE | ||
| 40 | #define PERL_STATIC_INLINE STATIC | ||
| 41 | #elif defined(_MSC_VER) | ||
| 42 | #define PERL_STATIC_INLINE STATIC __inline | ||
| 43 | #else | ||
| 44 | #define PERL_STATIC_INLINE STATIC inline | ||
| 45 | #endif | ||
| 46 | #endif | ||
| 47 | |||
| 48 | extern SV* mouse_package; | ||
| 49 | extern SV* mouse_methods; | ||
| 50 | extern SV* mouse_name; | ||
| 51 | extern SV* mouse_coerce; | ||
| 52 | |||
| 53 | void | ||
| 54 | mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const char* const fmt, ...) | ||
| 55 | __attribute__format__(__printf__, 3, 4); | ||
| 56 | |||
| 57 | #if PERL_VERSION_LT(5,14,0) | ||
| 58 | /* workaround RT #69939 */ | ||
| 59 | I32 | ||
| 60 | mouse_call_sv_safe(pTHX_ SV*, I32); | ||
| 61 | #else | ||
| 62 | #define mouse_call_sv_safe Perl_call_sv | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #define call_sv_safe(sv, flags) mouse_call_sv_safe(aTHX_ sv, flags) | ||
| 66 | #define call_method_safe(m, flags) mouse_call_sv_safe(aTHX_ newSVpvn_flags(m, strlen(m), SVs_TEMP), flags | G_METHOD) | ||
| 67 | #define call_method_safes(m, flags) mouse_call_sv_safe(aTHX_ newSVpvs_flags(m, SVs_TEMP), flags | G_METHOD) | ||
| 68 | |||
| 69 | |||
| 70 | #define is_class_loaded(sv) mouse_is_class_loaded(aTHX_ sv) | ||
| 71 | bool mouse_is_class_loaded(pTHX_ SV*); | ||
| 72 | |||
| 73 | #define is_an_instance_of(klass, sv) mouse_is_an_instance_of(aTHX_ gv_stashpvs(klass, GV_ADD), (sv)) | ||
| 74 | |||
| 75 | #define IsObject(sv) (SvROK(sv) && SvOBJECT(SvRV(sv))) | ||
| 76 | #define IsArrayRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVAV) | ||
| 77 | #define IsHashRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVHV) | ||
| 78 | #define IsCodeRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVCV) | ||
| 79 | |||
| 80 | #define mcall0(invocant, m) mouse_call0(aTHX_ (invocant), (m)) | ||
| 81 | #define mcall1(invocant, m, arg1) mouse_call1(aTHX_ (invocant), (m), (arg1)) | ||
| 82 | #define predicate_call(invocant, m) mouse_predicate_call(aTHX_ (invocant), (m)) | ||
| 83 | |||
| 84 | #define mcall0s(invocant, m) mcall0((invocant), sv_2mortal(newSVpvs_share(m))) | ||
| 85 | #define mcall1s(invocant, m, arg1) mcall1((invocant), sv_2mortal(newSVpvs_share(m)), (arg1)) | ||
| 86 | #define predicate_calls(invocant, m) predicate_call((invocant), sv_2mortal(newSVpvs_share(m))) | ||
| 87 | |||
| 88 | |||
| 89 | #define get_metaclass(name) mouse_get_metaclass(aTHX_ name) | ||
| 90 | |||
| 91 | SV* mouse_call0(pTHX_ SV *const self, SV *const method); | ||
| 92 | SV* mouse_call1(pTHX_ SV *const self, SV *const method, SV* const arg1); | ||
| 93 | int mouse_predicate_call(pTHX_ SV* const self, SV* const method); | ||
| 94 | |||
| 95 | SV* mouse_get_metaclass(pTHX_ SV* metaclass_name); | ||
| 96 | |||
| 97 | GV* mouse_stash_fetch(pTHX_ HV* const stash, const char* const name, I32 const namelen, I32 const create); | ||
| 98 | #define stash_fetch(s, n, l, c) mouse_stash_fetch(aTHX_ (s), (n), (l), (c)) | ||
| 99 | #define stash_fetchs(s, n, c) mouse_stash_fetch(aTHX_ (s), STR_WITH_LEN(n), (c)) | ||
| 100 | |||
| 101 | void mouse_install_sub(pTHX_ GV* const gv, SV* const code_ref); | ||
| 102 | |||
| 103 | void mouse_must_defined(pTHX_ SV* const value, const char* const name); | ||
| 104 | void mouse_must_ref(pTHX_ SV* const value, const char* const name, svtype const t); | ||
| 105 | |||
| 106 | #define must_defined(sv, name) mouse_must_defined(aTHX_ sv, name) | ||
| 107 | #define must_ref(sv, name, svt) mouse_must_ref(aTHX_ sv, name, svt) | ||
| 108 | |||
| 109 | #define MOUSEf_DIE_ON_FAIL 0x01 | ||
| 110 | MAGIC* mouse_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags); | ||
| 111 | |||
| 112 | /* MOUSE_av_at(av, ix) is the safer version of AvARRAY(av)[ix] if perl is compiled with -DDEBUGGING */ | ||
| 113 | #ifdef DEBUGGING | ||
| 114 | #define MOUSE_av_at(av, ix) mouse_av_at_safe(aTHX_ (av) , (ix)) | ||
| 115 | SV* mouse_av_at_safe(pTHX_ AV* const mi, I32 const ix); | ||
| 116 | #else | ||
| 117 | #define MOUSE_av_at(av, ix) \ | ||
| 118 | (AvARRAY(av)[ix] ? AvARRAY(av)[ix] : &PL_sv_undef) | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #define MOUSE_mg_obj(mg) ((mg)->mg_obj) | ||
| 122 | #define MOUSE_mg_ptr(mg) ((mg)->mg_ptr) | ||
| 123 | #define MOUSE_mg_len(mg) ((mg)->mg_len) | ||
| 124 | #define MOUSE_mg_flags(mg) ((mg)->mg_private) | ||
| 125 | #define MOUSE_mg_virtual(mg) ((mg)->mg_virtual) | ||
| 126 | |||
| 127 | #define MOUSE_mg_slot(mg) MOUSE_mg_obj(mg) | ||
| 128 | #define MOUSE_mg_xa(mg) ((AV*)MOUSE_mg_ptr(mg)) | ||
| 129 | |||
| 130 | 6883 | PERL_STATIC_INLINE MAGIC *MOUSE_get_magic(pTHX_ CV *cv, MGVTBL *vtbl) | |
| 131 | { | ||
| 132 | #ifndef MULTIPLICITY | ||
| 133 | PERL_UNUSED_ARG(vtbl); | ||
| 134 | 6883 | return (MAGIC*)(CvXSUBANY(cv).any_ptr); | |
| 135 | #else | ||
| 136 | return mg_findext((SV*)cv, PERL_MAGIC_ext, vtbl); | ||
| 137 | #endif | ||
| 138 | } | ||
| 139 | |||
| 140 | /* mouse_instance.xs stuff */ | ||
| 141 | SV* mouse_instance_create (pTHX_ HV* const stash); | ||
| 142 | SV* mouse_instance_clone (pTHX_ SV* const instance); | ||
| 143 | bool mouse_instance_has_slot (pTHX_ SV* const instance, SV* const slot); | ||
| 144 | SV* mouse_instance_get_slot (pTHX_ SV* const instance, SV* const slot); | ||
| 145 | SV* mouse_instance_set_slot (pTHX_ SV* const instance, SV* const slot, SV* const value); | ||
| 146 | SV* mouse_instance_delete_slot(pTHX_ SV* const instance, SV* const slot); | ||
| 147 | void mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot); | ||
| 148 | |||
| 149 | #define has_slot(self, key) mouse_instance_has_slot(aTHX_ self, key) | ||
| 150 | #define get_slot(self, key) mouse_instance_get_slot(aTHX_ self, key) | ||
| 151 | #define set_slot(self, key, value) mouse_instance_set_slot(aTHX_ self, key, value) | ||
| 152 | #define delete_slot(self, key) mouse_instance_delete_slot(aTHX_ self, key) | ||
| 153 | #define weaken_slot(self, key) mouse_instance_weaken_slot(aTHX_ self, key) | ||
| 154 | |||
| 155 | #define has_slots(self, key) has_slot(self, sv_2mortal(newSVpvs_share(key))) | ||
| 156 | #define get_slots(self, key) get_slot(self, sv_2mortal(newSVpvs_share(key))) | ||
| 157 | #define set_slots(self, key, value) set_slot(self, sv_2mortal(newSVpvs_share(key)), value) | ||
| 158 | |||
| 159 | /* mouse_simple_accessor.xs for meta object protocols */ | ||
| 160 | #define INSTALL_SIMPLE_READER(klass, name) \ | ||
| 161 | INSTALL_SIMPLE_READER_WITH_KEY(klass, name, name) | ||
| 162 | #define INSTALL_SIMPLE_READER_WITH_KEY(klass, name, key) \ | ||
| 163 | (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" \ | ||
| 164 | #name, #key, sizeof(#key)-1, XS_Mouse_simple_reader, NULL, 0) | ||
| 165 | |||
| 166 | #define INSTALL_CLASS_HOLDER_SV(klass, name, dsv) \ | ||
| 167 | (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" \ | ||
| 168 | #name, #name, sizeof(#name)-1, XS_Mouse_simple_reader, (dsv), HEf_SVKEY) | ||
| 169 | #define INSTALL_CLASS_HOLDER(klass, name, ds) \ | ||
| 170 | INSTALL_CLASS_HOLDER_SV(klass, name, newSVpvs(ds)) | ||
| 171 | |||
| 172 | #define INSTALL_SIMPLE_WRITER(klass, name) \ | ||
| 173 | NSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, name) | ||
| 174 | #define INSTALL_SIMPLE_WRITER_WITH_KEY(klass, name, key) \ | ||
| 175 | (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" \ | ||
| 176 | #name, #key, sizeof(#key)-1, XS_Mouse_simple_writer, NULL, 0) | ||
| 177 | |||
| 178 | #define INSTALL_SIMPLE_PREDICATE(klass, name) \ | ||
| 179 | INSTALL_SIMPLE_PREDICATE_WITH_KEY(klass, name, name) | ||
| 180 | #define INSTALL_SIMPLE_PREDICATE_WITH_KEY(klass, name, key) \ | ||
| 181 | (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::" #klass "::" \ | ||
| 182 | #name, #key, sizeof(#key)-1, XS_Mouse_simple_predicate, NULL, 0) | ||
| 183 | |||
| 184 | /* generate inhertiable class accessors for Mouse::Meta::Class */ | ||
| 185 | #define INSTALL_INHERITABLE_CLASS_ACCESSOR(name) \ | ||
| 186 | INSTALL_INHERITABLE_CLASS_ACCESSOR_WITH_KEY(name, name) | ||
| 187 | #define INSTALL_INHERITABLE_CLASS_ACCESSOR_WITH_KEY(name, key) \ | ||
| 188 | (void)mouse_simple_accessor_generate(aTHX_ "Mouse::Meta::Class::" #name,\ | ||
| 189 | #key, sizeof(#key)-1, XS_Mouse_inheritable_class_accessor, NULL, 0) | ||
| 190 | |||
| 191 | CV* mouse_simple_accessor_generate(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSUBADDR_t const accessor_impl, void* const dptr, I32 const dlen); | ||
| 192 | |||
| 193 | XS(XS_Mouse_simple_reader); | ||
| 194 | XS(XS_Mouse_simple_writer); | ||
| 195 | XS(XS_Mouse_simple_clearer); | ||
| 196 | XS(XS_Mouse_simple_predicate); | ||
| 197 | |||
| 198 | CV* mouse_accessor_generate(pTHX_ SV* const attr, XSUBADDR_t const accessor_impl); | ||
| 199 | |||
| 200 | XS(XS_Mouse_accessor); | ||
| 201 | XS(XS_Mouse_reader); | ||
| 202 | XS(XS_Mouse_writer); | ||
| 203 | |||
| 204 | XS(XS_Mouse_inheritable_class_accessor); | ||
| 205 | |||
| 206 | /* type constraints */ | ||
| 207 | |||
| 208 | int mouse_tc_check(pTHX_ SV* const tc, SV* const sv); | ||
| 209 | |||
| 210 | int mouse_tc_Any (pTHX_ SV*, SV* const sv); | ||
| 211 | int mouse_tc_Bool (pTHX_ SV*, SV* const sv); | ||
| 212 | int mouse_tc_Undef (pTHX_ SV*, SV* const sv); | ||
| 213 | int mouse_tc_Defined (pTHX_ SV*, SV* const sv); | ||
| 214 | int mouse_tc_Value (pTHX_ SV*, SV* const sv); | ||
| 215 | int mouse_tc_Num (pTHX_ SV*, SV* const sv); | ||
| 216 | int mouse_tc_Int (pTHX_ SV*, SV* const sv); | ||
| 217 | int mouse_tc_Str (pTHX_ SV*, SV* const sv); | ||
| 218 | int mouse_tc_ClassName (pTHX_ SV*, SV* const sv); | ||
| 219 | int mouse_tc_RoleName (pTHX_ SV*, SV* const sv); | ||
| 220 | int mouse_tc_Ref (pTHX_ SV*, SV* const sv); | ||
| 221 | int mouse_tc_ScalarRef (pTHX_ SV*, SV* const sv); | ||
| 222 | int mouse_tc_ArrayRef (pTHX_ SV*, SV* const sv); | ||
| 223 | int mouse_tc_HashRef (pTHX_ SV*, SV* const sv); | ||
| 224 | int mouse_tc_CodeRef (pTHX_ SV*, SV* const sv); | ||
| 225 | int mouse_tc_RegexpRef (pTHX_ SV*, SV* const sv); | ||
| 226 | int mouse_tc_GlobRef (pTHX_ SV*, SV* const sv); | ||
| 227 | int mouse_tc_FileHandle(pTHX_ SV*, SV* const sv); | ||
| 228 | int mouse_tc_Object (pTHX_ SV*, SV* const sv); | ||
| 229 | |||
| 230 | CV* mouse_generate_isa_predicate_for(pTHX_ SV* const klass, const char* const predicate_name); | ||
| 231 | CV* mouse_generate_can_predicate_for(pTHX_ SV* const klass, const char* const predicate_name); | ||
| 232 | |||
| 233 | int mouse_is_an_instance_of(pTHX_ HV* const stash, SV* const instance); | ||
| 234 | |||
| 235 | /* Mouse XS Attribute object */ | ||
| 236 | |||
| 237 | AV* mouse_get_xa(pTHX_ SV* const attr); | ||
| 238 | SV* mouse_xa_apply_type_constraint(pTHX_ AV* const xa, SV* value, U16 const flags); | ||
| 239 | SV* mouse_xa_set_default(pTHX_ AV* const xa, SV* const object); | ||
| 240 | |||
| 241 | enum mouse_xa_ix_t{ | ||
| 242 | MOUSE_XA_SLOT, /* for constructors, sync to mg_obj */ | ||
| 243 | MOUSE_XA_FLAGS, /* for constructors, sync to mg_private */ | ||
| 244 | MOUSE_XA_ATTRIBUTE, | ||
| 245 | MOUSE_XA_INIT_ARG, | ||
| 246 | MOUSE_XA_TC, | ||
| 247 | MOUSE_XA_TC_CODE, | ||
| 248 | |||
| 249 | MOUSE_XA_last | ||
| 250 | }; | ||
| 251 | |||
| 252 | #define MOUSE_xa_slot(m) MOUSE_av_at(m, MOUSE_XA_SLOT) | ||
| 253 | #define MOUSE_xa_flags(m) SvUVX( MOUSE_av_at(m, MOUSE_XA_FLAGS) ) | ||
| 254 | #define MOUSE_xa_attribute(m) MOUSE_av_at(m, MOUSE_XA_ATTRIBUTE) | ||
| 255 | #define MOUSE_xa_init_arg(m) MOUSE_av_at(m, MOUSE_XA_INIT_ARG) | ||
| 256 | #define MOUSE_xa_tc(m) MOUSE_av_at(m, MOUSE_XA_TC) | ||
| 257 | #define MOUSE_xa_tc_code(m) MOUSE_av_at(m, MOUSE_XA_TC_CODE) | ||
| 258 | |||
| 259 | enum mouse_xa_flags_t{ | ||
| 260 | MOUSEf_ATTR_HAS_TC = 0x0001, | ||
| 261 | MOUSEf_ATTR_HAS_DEFAULT = 0x0002, | ||
| 262 | MOUSEf_ATTR_HAS_BUILDER = 0x0004, | ||
| 263 | MOUSEf_ATTR_HAS_INITIALIZER = 0x0008, /* not used */ | ||
| 264 | MOUSEf_ATTR_HAS_TRIGGER = 0x0010, | ||
| 265 | |||
| 266 | MOUSEf_ATTR_IS_LAZY = 0x0020, | ||
| 267 | MOUSEf_ATTR_IS_WEAK_REF = 0x0040, | ||
| 268 | MOUSEf_ATTR_IS_REQUIRED = 0x0080, | ||
| 269 | |||
| 270 | MOUSEf_ATTR_SHOULD_COERCE = 0x0100, | ||
| 271 | |||
| 272 | MOUSEf_ATTR_SHOULD_AUTO_DEREF | ||
| 273 | = 0x0200, | ||
| 274 | MOUSEf_TC_IS_ARRAYREF = 0x0400, | ||
| 275 | MOUSEf_TC_IS_HASHREF = 0x0800, | ||
| 276 | |||
| 277 | MOUSEf_OTHER1 = 0x1000, | ||
| 278 | MOUSEf_OTHER2 = 0x2000, | ||
| 279 | MOUSEf_OTHER3 = 0x4000, | ||
| 280 | MOUSEf_OTHER4 = 0x8000, | ||
| 281 | |||
| 282 | MOUSEf_MOUSE_MASK = 0xFFFF /* not used */ | ||
| 283 | }; | ||
| 284 | |||
| 285 | /* Mouse::Meta::Class stuff */ | ||
| 286 | HV* mouse_get_namespace(pTHX_ SV* const meta); /* $meta->namespace */ | ||
| 287 | #endif /* !MOUSE_H */ |