From: gfx Date: Sun, 6 Sep 2009 09:24:15 +0000 (+0900) Subject: Change the mop_instance_vtbl prototypes: they could receive meta instances in the... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b4d6eec6f597bfbb2466e89c1f163998f843ebc9;p=gitmo%2FClass-MOP.git Change the mop_instance_vtbl prototypes: they could receive meta instances in the future. --- diff --git a/mop.h b/mop.h index d2c630e..737a68c 100644 --- a/mop.h +++ b/mop.h @@ -97,25 +97,27 @@ AV* mop_class_get_all_attributes(pTHX_ SV* const metaclass); /* All the MOP_mg_* macros require MAGIC* mg for the first argument */ -typedef struct { - SV* (*create_instance)(pTHX_ HV* const stash); - SV* (*clone_instance) (pTHX_ SV* const instance); - 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; /* Class::MOP::Instance stuff */ -SV* mop_instance_create (pTHX_ HV* const stash); -SV* mop_instance_clone (pTHX_ SV* const instance); -bool mop_instance_has_slot (pTHX_ SV* const instance, SV* const slot); -SV* mop_instance_get_slot (pTHX_ SV* const instance, SV* const slot); -SV* mop_instance_set_slot (pTHX_ SV* const instance, SV* const slot, SV* const value); -SV* mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot); -void mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot); +/* SV* mi (meta instance) may not be used */ +typedef struct { + SV* (*create_instance)(pTHX_ SV* const mi, HV* const stash); + SV* (*clone_instance) (pTHX_ SV* const mi, SV* const instance); + bool (*has_slot) (pTHX_ SV* const mi, SV* const instance, SV* const slot); + SV* (*get_slot) (pTHX_ SV* const mi, SV* const instance, SV* const slot); + SV* (*set_slot) (pTHX_ SV* const mi, SV* const instance, SV* const slot, SV* const value); + SV* (*delete_slot) (pTHX_ SV* const mi, SV* const instance, SV* const slot); + void (*weaken_slot) (pTHX_ SV* const mi, SV* const instance, SV* const slot); +} mop_instance_vtbl; + +SV* mop_instance_create (pTHX_ SV* const mi, HV* const stash); +SV* mop_instance_clone (pTHX_ SV* const mi, SV* const instance); +bool mop_instance_has_slot (pTHX_ SV* const mi, SV* const instance, SV* const slot); +SV* mop_instance_get_slot (pTHX_ SV* const mi, SV* const instance, SV* const slot); +SV* mop_instance_set_slot (pTHX_ SV* const mi, SV* const instance, SV* const slot, SV* const value); +SV* mop_instance_delete_slot(pTHX_ SV* const mi, SV* const instance, SV* const slot); +void mop_instance_weaken_slot(pTHX_ SV* const mi, SV* const instance, SV* const slot); const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX); @@ -127,13 +129,13 @@ const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX); #define MOP_mg_obj_refcounted_on(mg) (void)((mg)->mg_flags |= MGf_REFCOUNTED); -#define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ (stash)) -#define MOP_mg_clone_instance(mg, o) MOP_mg_vtbl(mg)->clone_instance (aTHX_ (o)) -#define MOP_mg_has_slot(mg, o, slot) MOP_mg_vtbl(mg)->has_slot (aTHX_ (o), (slot)) -#define MOP_mg_get_slot(mg, o, slot) MOP_mg_vtbl(mg)->get_slot (aTHX_ (o), (slot)) -#define MOP_mg_set_slot(mg, o, slot, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ (o), (slot), (v)) -#define MOP_mg_delete_slot(mg, o, slot) MOP_mg_vtbl(mg)->delete_slot (aTHX_ (o), (slot)) -#define MOP_mg_weaken_slot(mg, o, slot) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ (o), (slot)) +#define MOP_mg_create_instance(mg, stash) MOP_mg_vtbl(mg)->create_instance (aTHX_ NULL, (stash)) +#define MOP_mg_clone_instance(mg, o) MOP_mg_vtbl(mg)->clone_instance (aTHX_ NULL, (o)) +#define MOP_mg_has_slot(mg, o, slot) MOP_mg_vtbl(mg)->has_slot (aTHX_ NULL, (o), (slot)) +#define MOP_mg_get_slot(mg, o, slot) MOP_mg_vtbl(mg)->get_slot (aTHX_ NULL, (o), (slot)) +#define MOP_mg_set_slot(mg, o, slot, v) MOP_mg_vtbl(mg)->set_slot (aTHX_ NULL, (o), (slot), (v)) +#define MOP_mg_delete_slot(mg, o, slot) MOP_mg_vtbl(mg)->delete_slot (aTHX_ NULL, (o), (slot)) +#define MOP_mg_weaken_slot(mg, o, slot) MOP_mg_vtbl(mg)->weaken_slot (aTHX_ NULL, (o), (slot)) /* Class::MOP::Attribute stuff */ diff --git a/xs/Attribute.xs b/xs/Attribute.xs index 13d75e6..3fbbc15 100644 --- a/xs/Attribute.xs +++ b/xs/Attribute.xs @@ -135,7 +135,7 @@ mop_attr_initialize_instance_slot(pTHX_ SV* const attr, const mop_instance_vtbl* call_method("set_initial_value", G_VOID | G_DISCARD); } else{ - vtbl->set_slot(aTHX_ instance, MOP_attr_slot(meta), value); + vtbl->set_slot(aTHX_ NULL, instance, MOP_attr_slot(meta), value); } } } diff --git a/xs/Instance.xs b/xs/Instance.xs index 4d095ef..d628b8f 100644 --- a/xs/Instance.xs +++ b/xs/Instance.xs @@ -7,13 +7,13 @@ } STMT_END SV* -mop_instance_create(pTHX_ HV* const stash) { +mop_instance_create(pTHX_ SV* const mi PERL_UNUSED_DECL, HV* const stash) { assert(stash); return sv_bless( newRV_noinc((SV*)newHV()), stash ); } SV* -mop_instance_clone(pTHX_ SV* const instance) { +mop_instance_clone(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance) { HV* proto; assert(instance); @@ -25,7 +25,7 @@ mop_instance_clone(pTHX_ SV* const instance) { bool -mop_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { +mop_instance_has_slot(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance, SV* const slot) { assert(instance); assert(slot); CHECK_INSTANCE(instance); @@ -33,7 +33,7 @@ mop_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { } SV* -mop_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { +mop_instance_get_slot(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance, SV* const slot) { HE* he; assert(instance); assert(slot); @@ -43,7 +43,7 @@ mop_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { } SV* -mop_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) { +mop_instance_set_slot(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance, SV* const slot, SV* const value) { HE* he; SV* sv; assert(instance); @@ -57,7 +57,7 @@ mop_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) } SV* -mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { +mop_instance_delete_slot(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance, SV* const slot) { assert(instance); assert(slot); CHECK_INSTANCE(instance); @@ -65,7 +65,7 @@ mop_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { } void -mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { +mop_instance_weaken_slot(pTHX_ SV* const mi PERL_UNUSED_DECL, SV* const instance, SV* const slot) { HE* he; assert(instance); assert(slot); @@ -76,7 +76,7 @@ mop_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { } } -static const mop_instance_vtbl mop_default_instance = { +static const mop_instance_vtbl mop_default_instance_vtbl = { mop_instance_create, mop_instance_clone, mop_instance_has_slot, @@ -89,7 +89,7 @@ static const mop_instance_vtbl mop_default_instance = { const mop_instance_vtbl* mop_get_default_instance_vtbl(pTHX){ - return &mop_default_instance; + return &mop_default_instance_vtbl; } MODULE = Class::MOP::Instance PACKAGE = Class::MOP::Instance @@ -111,7 +111,7 @@ CODE: /* $self->can("get_slot_value") == \&Class::MOP::Instance::get_slot_value */ code_ref = mop_call1(aTHX_ self, mop_can, method); if(SvROK(code_ref) && SvRV(code_ref) == (SV*)default_method){ - RETVAL = (void*)&mop_default_instance; + RETVAL = (void*)&mop_default_instance_vtbl; } else{ RETVAL = NULL; @@ -125,7 +125,7 @@ PREINIT: SV* class_name; CODE: class_name = mop_call0_pvs(self, "_class_name"); - RETVAL = mop_instance_create(aTHX_ gv_stashsv(class_name, TRUE)); + RETVAL = mop_instance_create(aTHX_ NULL, gv_stashsv(class_name, TRUE)); OUTPUT: RETVAL @@ -133,7 +133,7 @@ SV* clone_instance(SV* self, SV* instance) CODE: PERL_UNUSED_VAR(self); - RETVAL = mop_instance_clone(aTHX_ instance); + RETVAL = mop_instance_clone(aTHX_ NULL, instance); OUTPUT: RETVAL @@ -141,7 +141,7 @@ bool is_slot_initialized(SV* self, SV* instance, SV* slot) CODE: PERL_UNUSED_VAR(self); - RETVAL = mop_instance_has_slot(aTHX_ instance, slot); + RETVAL = mop_instance_has_slot(aTHX_ NULL, instance, slot); OUTPUT: RETVAL @@ -149,7 +149,7 @@ SV* get_slot_value(SV* self, SV* instance, SV* slot) CODE: PERL_UNUSED_VAR(self); - RETVAL = mop_instance_get_slot(aTHX_ instance, slot); + RETVAL = mop_instance_get_slot(aTHX_ NULL, instance, slot); RETVAL = RETVAL ? newSVsv(RETVAL) : &PL_sv_undef; OUTPUT: RETVAL @@ -158,7 +158,7 @@ SV* set_slot_value(SV* self, SV* instance, SV* slot, SV* value) CODE: PERL_UNUSED_VAR(self); - RETVAL = mop_instance_set_slot(aTHX_ instance, slot, value); + RETVAL = mop_instance_set_slot(aTHX_ NULL, instance, slot, value); SvREFCNT_inc_simple_void_NN(RETVAL); OUTPUT: RETVAL @@ -167,7 +167,7 @@ SV* deinitialize_slot(SV* self, SV* instance, SV* slot) CODE: PERL_UNUSED_VAR(self); - RETVAL = mop_instance_delete_slot(aTHX_ instance, slot); + RETVAL = mop_instance_delete_slot(aTHX_ NULL, instance, slot); if(RETVAL){ SvREFCNT_inc_simple_void_NN(RETVAL); } @@ -181,4 +181,4 @@ void weaken_slot_value(SV* self, SV* instance, SV* slot) CODE: PERL_UNUSED_VAR(self); - mop_instance_weaken_slot(aTHX_ instance, slot); + mop_instance_weaken_slot(aTHX_ NULL, instance, slot);