X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2Fmouse_simple_accessor.xs;h=285f3cbb33ab689876d5fbf2c1dac9971f37f3da;hp=cf835fb2cff023828fbd1017219f8c951be49477;hb=935400114c35ad1b2481c48ff471e180e9c93d93;hpb=ef20630593cf958f60d61c37ca16f322d9516ef5 diff --git a/xs-src/mouse_simple_accessor.xs b/xs-src/mouse_simple_accessor.xs index cf835fb..285f3cb 100644 --- a/xs-src/mouse_simple_accessor.xs +++ b/xs-src/mouse_simple_accessor.xs @@ -1,14 +1,14 @@ -#include "mouse.h" - +#include "mouse.h" + static MGVTBL mouse_simple_accessor_vtbl; - + /* static MAGIC* mouse_accessor_get_mg(pTHX_ CV* const xsub){ return moose_mg_find(aTHX_ (SV*)xsub, &mouse_simple_accessor_vtbl, MOOSEf_DIE_ON_FAIL); -} -*/ - +} +*/ + CV* mouse_install_simple_accessor(pTHX_ const char* const fq_name, const char* const key, I32 const keylen, XSUBADDR_t const accessor_impl){ CV* const xsub = newXS((char*)fq_name, accessor_impl, __FILE__); @@ -24,13 +24,13 @@ mouse_install_simple_accessor(pTHX_ const char* const fq_name, const char* const SvREFCNT_dec(slot); /* sv_magicext() increases refcnt in mg_obj */ /* NOTE: - * although we use MAGIC for gc, we also store slot to CvXSUBANY slot for efficiency (gfx) + * although we use MAGIC for gc, we also store mg to CvXSUBANY for efficiency (gfx) */ - CvXSUBANY(xsub).any_ptr = (void*)slot; + CvXSUBANY(xsub).any_ptr = (void*)mg; return xsub; } - + SV* mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { SV* self; @@ -48,18 +48,18 @@ mouse_accessor_get_self(pTHX_ I32 const ax, I32 const items, CV* const cv) { croak("Cant call %s as a class method", GvNAME(CvGV(cv))); } return self; -} +} XS(mouse_xs_simple_reader) { - dVAR; dXSARGS; + dVAR; dXSARGS; dMOUSE_self; - SV* const slot = (SV*)XSANY.any_ptr; + SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr); SV* value; if (items != 1) { - croak("Expected exactly one argument"); + croak("Expected exactly one argument for a reader for '%"SVf"'", slot); } value = mouse_instance_get_slot(self, slot); @@ -72,27 +72,42 @@ XS(mouse_xs_simple_writer) { dVAR; dXSARGS; dMOUSE_self; - SV* const slot = (SV*)XSANY.any_ptr; - + SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr); + if (items != 2) { - croak("Expected exactly two argument"); + croak("Expected exactly two argument for a writer for '%"SVf"'", slot); } ST(0) = mouse_instance_set_slot(self, slot, ST(1)); XSRETURN(1); } +XS(mouse_xs_simple_clearer) +{ + dVAR; dXSARGS; + dMOUSE_self; + SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr); + SV* value; + + if (items != 1) { + croak("Expected exactly one argument for a clearer for '%"SVf"'", slot); + } + + value = mouse_instance_delete_slot(aTHX_ self, slot); + ST(0) = value ? value : &PL_sv_undef; + XSRETURN(1); +} XS(mouse_xs_simple_predicate) { dVAR; dXSARGS; dMOUSE_self; - SV* const slot = (SV*)XSANY.any_ptr; - + SV* const slot = MOUSE_mg_slot((MAGIC*)XSANY.any_ptr); + if (items != 1) { - croak("Expected exactly one argument"); + croak("Expected exactly one argument for a predicate for '%"SVf"'", slot); } ST(0) = boolSV( mouse_instance_has_slot(self, slot) ); XSRETURN(1); -} +}