const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX);
-#define MOP_MI_SLOT 0
-#define MOP_MI_last 1
-
-#define MOP_mg_mi(mg) ((mg)->mg_obj)
+#define MOP_mg_obj(mg) ((mg)->mg_obj)
#define MOP_mg_vtbl(mg) ((const mop_instance_vtbl*)(mg)->mg_ptr)
#define MOP_mg_flags(mg) ((mg)->mg_private)
-#define MOP_mg_miav(mg) ((AV*)MOP_mg_mi(mg))
-
-#ifdef DEBUGGING
-#define MOP_mi_access(mi, a) *mop_debug_mi_access(aTHX_ (mi) , (a))
-SV** mop_debug_mi_access(pTHX_ AV* const mi, I32 const attr_ix);
-#else
-#define MOP_mi_access(mi, a) AvARRAY((mi))[(a)]
-#endif
-
-#define MOP_mi_slot(mi) MOP_mi_access((mi), MOP_MI_SLOT)
+#define MOP_mg_slot(mg) MOP_mg_obj(mg)
-#define MOP_mg_create_instance(mg) MOP_mg_vtbl(mg)->create_instance (aTHX_ MOP_mg_mi(mg))
-#define MOP_mg_has_slot(mg, o) MOP_mg_vtbl(mg)->has_slot (aTHX_ MOP_mg_mi(mg), (o))
-#define MOP_mg_get_slot(mg, o) MOP_mg_vtbl(mg)->get_slot (aTHX_ MOP_mg_mi(mg), (o))
-#define MOP_mg_set_slot(mg, o, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ MOP_mg_mi(mg), (o), (v))
-#define MOP_mg_delete_slot(mg, o) MOP_mg_vtbl(mg)->delete_slot (aTHX_ MOP_mg_mi(mg), (o))
-#define MOP_mg_weaken_slot(mg, o) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ MOP_mg_mi(mg), (o))
+#define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash))
+#define MOP_mg_has_slot(mg, o) MOP_mg_vtbl(mg)->has_slot (aTHX_ (o), MOP_mg_slot(mg))
+#define MOP_mg_get_slot(mg, o) MOP_mg_vtbl(mg)->get_slot (aTHX_ (o), MOP_mg_slot(mg))
+#define MOP_mg_set_slot(mg, o, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (o), MOP_mg_slot(mg), (v))
+#define MOP_mg_delete_slot(mg, o) MOP_mg_vtbl(mg)->delete_slot (aTHX_ (o), MOP_mg_slot(mg))
+#define MOP_mg_weaken_slot(mg, o) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ (o), MOP_mg_slot(mg))
/* Class::MOP::Method::Accessor stuff */
} STMT_END
static SV*
-mop_instance_create_instance(pTHX_ SV* const mi PERL_UNUSED_DECL) {
- return newRV_noinc((SV*)newHV());
+mop_instance_create_instance(pTHX_ HV* const stash) {
+ return sv_bless( newRV_noinc((SV*)newHV()), stash );
}
static bool
-mop_instance_has_slot(pTHX_ SV* const mi, SV* const instance) {
+mop_instance_has_slot(pTHX_ SV* const instance, SV* const slot) {
CHECK_INSTANCE(instance);
- return hv_exists_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0U);
+ return hv_exists_ent((HV*)SvRV(instance), slot, 0U);
}
static SV*
-mop_instance_get_slot(pTHX_ SV* const mi, SV* const instance) {
+mop_instance_get_slot(pTHX_ SV* const instance, SV* const slot) {
HE* he;
CHECK_INSTANCE(instance);
- he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U);
+ he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);
return he ? HeVAL(he) : NULL;
}
static SV*
-mop_instance_set_slot(pTHX_ SV* const mi, SV* const instance, SV* const value) {
+mop_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) {
HE* he;
SV* sv;
CHECK_INSTANCE(instance);
- he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), TRUE, 0U);
+ he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U);
sv = HeVAL(he);
sv_setsv_mg(sv, value);
return sv;
}
static SV*
-mop_instance_delete_slot(pTHX_ SV* const mi, SV* const instance) {
+mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) {
CHECK_INSTANCE(instance);
- return hv_delete_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0, 0U);
+ return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U);
}
static void
-mop_instance_weaken_slot(pTHX_ SV* const mi, SV* const instance) {
+mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) {
HE* he;
CHECK_INSTANCE(instance);
- he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U);
+ he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);
if(he){
sv_rvweaken(HeVAL(he));
}
mop_install_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSPROTO(accessor_impl), const mop_instance_vtbl* vtbl){
CV* const xsub = newXS((char*)fq_name, accessor_impl, __FILE__);
SV* const keysv = newSVpvn_share(key, keylen, 0U);
- AV* const meta = newAV();
MAGIC* mg;
if(!vtbl){
sv_2mortal((SV*)xsub);
}
- mg = sv_magicext((SV*)xsub, (SV*)meta, PERL_MAGIC_ext, &mop_accessor_vtbl, (char*)vtbl, 0);
- SvREFCNT_dec(meta); /* sv_magicext() increases refcnt in mg_obj */
-
- av_store(meta, MOP_MI_SLOT, keysv);
+ mg = sv_magicext((SV*)xsub, keysv, PERL_MAGIC_ext, &mop_accessor_vtbl, (char*)vtbl, 0);
+ SvREFCNT_dec(keysv); /* sv_magicext() increases refcnt in mg_obj */
/* NOTE:
* although we use MAGIC for gc, we also store mg to any slot for efficiency (gfx)
return self;
}
-#ifdef DEBUGGING
-SV**
-mop_debug_mi_access(pTHX_ AV* const mi, I32 const attr_ix){
- assert(mi);
- assert(SvTYPE(mi) == SVt_PVAV);
- assert(AvMAX(mi) >= attr_ix);
- return &AvARRAY(mi)[attr_ix];
-}
-#endif
-
XS(mop_xs_simple_accessor)
{
dVAR; dXSARGS;