From: gfx Date: Tue, 25 Aug 2009 01:21:43 +0000 (+0900) Subject: Change XS Meta Instance API X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8615de1655abf7a4a1d715445bca5c79fff927c1;p=gitmo%2FClass-MOP.git Change XS Meta Instance API --- diff --git a/mop.h b/mop.h index 7778bf4..b3b5c7b 100644 --- a/mop.h +++ b/mop.h @@ -63,20 +63,19 @@ void mop_get_package_symbols(HV *stash, type_filter_t filter, get_package_symbol HV *mop_get_all_package_symbols (HV *stash, type_filter_t filter); -/* Class::MOP::Instance stuff */ +/* Class::MOP Magic stuff */ -/* MI: Meta Instance object of Class::MOP::Method */ +/* MG: MOP Magic object */ /* All the MOP_mg_* macros require MAGIC* mg for the first argument */ -/* All the MOP_mi_* macros require AV* mi for the first argument */ typedef struct { - SV* (*create_instance)(pTHX_ MAGIC* const mg); - bool (*has_slot) (pTHX_ MAGIC* const mg, SV* const instance); - SV* (*get_slot) (pTHX_ MAGIC* const mg, SV* const instance); - SV* (*set_slot) (pTHX_ MAGIC* const mg, SV* const instance, SV* const value); - SV* (*delete_slot) (pTHX_ MAGIC* const mg, SV* const instance); - void (*weaken_slot) (pTHX_ MAGIC* const mg, SV* const instance); + SV* (*create_instance)(pTHX_ SV* const mi); + bool (*has_slot) (pTHX_ SV* const mi, SV* const instance); + SV* (*get_slot) (pTHX_ SV* const mi, SV* const instance); + SV* (*set_slot) (pTHX_ SV* const mi, SV* const instance, SV* const value); + SV* (*delete_slot) (pTHX_ SV* const mi, SV* const instance); + void (*weaken_slot) (pTHX_ SV* const mi, SV* const instance); } mop_instance_vtbl; const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX); @@ -84,10 +83,12 @@ 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) ((AV*)(mg)->mg_obj) +#define MOP_mg_mi(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); @@ -96,14 +97,13 @@ SV** mop_debug_mi_access(pTHX_ AV* const mi, I32 const attr_ix); #endif #define MOP_mi_slot(mi) MOP_mi_access((mi), MOP_MI_SLOT) -#define MOP_mg_slot(mg) MOP_mi_slot(MOP_mg_mi(mg)) - -#define MOP_mg_create_instance(mg) MOP_mg_vtbl(mg)->create_instance (aTHX_ (mg)) -#define MOP_mg_has_slot(mg, o) MOP_mg_vtbl(mg)->has_slot (aTHX_ (mg), (o)) -#define MOP_mg_get_slot(mg, o) MOP_mg_vtbl(mg)->get_slot (aTHX_ (mg), (o)) -#define MOP_mg_set_slot(mg, o, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (mg), (o), (v)) -#define MOP_mg_delete_slot(mg, o) MOP_mg_vtbl(mg)->delete_slot (aTHX_ (mg), (o)) -#define MOP_mg_weaken_slot(mg, o) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ (mg), (o)) + +#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)) /* Class::MOP::Method::Accessor stuff */ diff --git a/xs/Instance.xs b/xs/Instance.xs index 997a831..c490093 100644 --- a/xs/Instance.xs +++ b/xs/Instance.xs @@ -10,46 +10,46 @@ } STMT_END static SV* -mop_instance_create_instance(pTHX_ MAGIC* const mg PERL_UNUSED_DECL) { +mop_instance_create_instance(pTHX_ SV* const mi PERL_UNUSED_DECL) { return newRV_noinc((SV*)newHV()); } static bool -mop_instance_has_slot(pTHX_ MAGIC* const mg, SV* const instance) { +mop_instance_has_slot(pTHX_ SV* const mi, SV* const instance) { CHECK_INSTANCE(instance); - return hv_exists_ent((HV*)SvRV(instance), MOP_mg_slot(mg), 0U); + return hv_exists_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0U); } static SV* -mop_instance_get_slot(pTHX_ MAGIC* const mg, SV* const instance) { +mop_instance_get_slot(pTHX_ SV* const mi, SV* const instance) { HE* he; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mg_slot(mg), FALSE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U); return he ? HeVAL(he) : NULL; } static SV* -mop_instance_set_slot(pTHX_ MAGIC* const mg, SV* const instance, SV* const value) { +mop_instance_set_slot(pTHX_ SV* const mi, SV* const instance, SV* const value) { HE* he; SV* sv; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mg_slot(mg), TRUE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), TRUE, 0U); sv = HeVAL(he); sv_setsv_mg(sv, value); return sv; } static SV* -mop_instance_delete_slot(pTHX_ MAGIC* const mg, SV* const instance) { +mop_instance_delete_slot(pTHX_ SV* const mi, SV* const instance) { CHECK_INSTANCE(instance); - return hv_delete_ent((HV*)SvRV(instance), MOP_mg_slot(mg), 0, 0U); + return hv_delete_ent((HV*)SvRV(instance), MOP_mi_slot(mi), 0, 0U); } static void -mop_instance_weaken_slot(pTHX_ MAGIC* const mg, SV* const instance) { +mop_instance_weaken_slot(pTHX_ SV* const mi, SV* const instance) { HE* he; CHECK_INSTANCE(instance); - he = hv_fetch_ent((HV*)SvRV(instance), MOP_mg_slot(mg), FALSE, 0U); + he = hv_fetch_ent((HV*)SvRV(instance), MOP_mi_slot(mi), FALSE, 0U); if(he){ sv_rvweaken(HeVAL(he)); } diff --git a/xs/MethodAccessor.xs b/xs/MethodAccessor.xs index 8e3a99e..e1114df 100644 --- a/xs/MethodAccessor.xs +++ b/xs/MethodAccessor.xs @@ -1,7 +1,19 @@ #include "mop.h" -static MGVTBL mop_accessor_vtbl; /* the MAGIC identity */ +static MGVTBL mop_accessor_vtbl = { /* the MAGIC identity */ + NULL, /* get */ + NULL, /* set */ + NULL, /* len */ + NULL, /* clear */ + NULL, /* free */ + NULL, /* copy */ + NULL, /* dup */ +#ifdef MGf_LOCAL + NULL, /* local */ +#endif +}; + MAGIC* mop_accessor_get_mg(pTHX_ CV* const xsub){