X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xs-src%2FMouseAccessor.xs;h=b9aad70d2bd84a07284e489f61cc3408b0dbc9b7;hb=db6e462c5abe5f680851ab11c4d3cab3386595cf;hp=f93d25f8fc10e125cee029c3ccaf02a1a589fc35;hpb=a17f63138ec09db5e362700f2ac72da67f104786;p=gitmo%2FMouse.git diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index f93d25f..b9aad70 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -245,37 +245,6 @@ mouse_simple_accessor_generate(pTHX_ const char* const fq_name, const char* cons return xsub; } -XS(XS_Mouse_simple_accessor) -{ - dVAR; dXSARGS; - dMOUSE_self; - MAGIC* const mg = (MAGIC*)XSANY.any_ptr; - SV* value; - - if(items == 1){ /* reader */ - value = get_slot(self, MOUSE_mg_slot(mg)); - if(!value) { - if(MOUSE_mg_ptr(mg)){ - /* the default value must be a SV */ - assert(MOUSE_mg_len(mg) == HEf_SVKEY); - value = (SV*)MOUSE_mg_ptr(mg); - } - else{ - value = &PL_sv_undef; - } - } - } - else if(items == 2){ /* writer */ - value = set_slot(self, MOUSE_mg_slot(mg), ST(1)); - } - else { - croak("Expected exactly one or two argument for an accessor for '%"SVf"'", MOUSE_mg_slot(mg)); - } - - ST(0) = value; - XSRETURN(1); -} - XS(XS_Mouse_simple_reader) { dVAR; dXSARGS; @@ -288,7 +257,18 @@ XS(XS_Mouse_simple_reader) } value = get_slot(self, MOUSE_mg_slot(mg)); - ST(0) = value ? value : &PL_sv_undef; + if(!value) { + if(MOUSE_mg_ptr(mg)){ + /* the default value must be a SV */ + assert(MOUSE_mg_len(mg) == HEf_SVKEY); + value = (SV*)MOUSE_mg_ptr(mg); + } + else{ + value = &PL_sv_undef; + } + } + + ST(0) = value; XSRETURN(1); } @@ -384,7 +364,8 @@ mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const valu CHECK_INSTANCE(instance); he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U); sv = HeVAL(he); - sv_setsv_mg(sv, value); + sv_setsv(sv, value); + SvSETMAGIC(sv); return sv; }