X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xs-src%2FMouseTypeConstraints.xs;h=3f0a3d304941f2a40cfb58ce2c5179a07775c821;hb=91ee66cbb155fe48f641868aebc1c6215446e2c0;hp=78ce1fd7059680d862ccb9ebf061a98e16e3f1f9;hpb=f6c81f00b84bc277a9151337f2a7cc275937f3b8;p=gitmo%2FMouse.git diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index 78ce1fd..3f0a3d3 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -12,6 +12,9 @@ typedef int (*check_fptr_t)(pTHX_ SV* const data, SV* const sv); +static +XSPROTO(XS_Mouse_constraint_check); + /* NOTE: mouse_tc_check() handles GETMAGIC */ @@ -55,8 +58,10 @@ mouse_tc_check(pTHX_ SV* const tc_code, SV* const sv) { } /* - The following type check functions return an integer, not a bool, to keep them simple, - so if you assign these return value to bool variable, you must use "expr ? TRUE : FALSE". + The following type check functions return an integer, not a bool, to keep + the code simple, + so if you assign these return value to a bool variable, you must use + "expr ? TRUE : FALSE". */ int @@ -70,21 +75,21 @@ mouse_tc_Bool(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { assert(sv); if(sv_true(sv)){ - if(SvIOKp(sv)){ + if(SvPOKp(sv)){ /* "1" */ + return SvCUR(sv) == 1 && SvPVX(sv)[0] == '1'; + } + else if(SvIOKp(sv)){ return SvIVX(sv) == 1; } else if(SvNOKp(sv)){ return SvNVX(sv) == 1.0; } - else if(SvPOKp(sv)){ /* "1" */ - return SvCUR(sv) == 1 && SvPVX(sv)[0] == '1'; - } else{ return FALSE; } } else{ - /* any false value must be boolean */ + /* any false value is a boolean */ return TRUE; } } @@ -120,7 +125,7 @@ S_nv_is_integer(pTHX_ NV const nv) { } else { char buf[64]; /* Must fit sprintf/Gconvert of longest NV */ - char* p; + const char* p; (void)Gconvert(nv, NV_DIG, 0, buf); p = &buf[0]; @@ -140,18 +145,16 @@ S_nv_is_integer(pTHX_ NV const nv) { int mouse_tc_Int(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { assert(sv); - if(SvIOKp(sv)){ + if(SvPOKp(sv)){ + int const num_type = grok_number(SvPVX(sv), SvCUR(sv), NULL); + return num_type && !(num_type & IS_NUMBER_NOT_INT); + } + else if(SvIOKp(sv)){ return TRUE; } else if(SvNOKp(sv)) { return S_nv_is_integer(aTHX_ SvNVX(sv)); } - else if(SvPOKp(sv)){ - int const num_type = grok_number(SvPVX(sv), SvCUR(sv), NULL); - if(num_type){ - return !(num_type & IS_NUMBER_NOT_INT); - } - } return FALSE; } @@ -162,7 +165,7 @@ mouse_tc_Str(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { } int -mouse_tc_ClassName(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv){ +mouse_tc_ClassName(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv){ assert(sv); return is_class_loaded(sv); } @@ -176,7 +179,7 @@ mouse_tc_RoleName(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { ENTER; SAVETMPS; - ok = is_an_instance_of("Mouse::Meta::Role", get_metaclass(sv)); + ok = is_an_instance_of("Mouse::Meta::Role", get_metaclass(sv)); FREETMPS; LEAVE; @@ -278,7 +281,7 @@ mouse_parameterized_ArrayRef(pTHX_ SV* const param, SV* const sv) { static int mouse_parameterized_HashRef(pTHX_ SV* const param, SV* const sv) { - if(mouse_tc_HashRef(aTHX_ NULL, sv)){ + if(IsHashRef(sv)){ HV* const hv = (HV*)SvRV(sv); HE* he; @@ -544,8 +547,8 @@ mouse_generate_can_predicate_for(pTHX_ SV* const methods, const char* const pred return mouse_tc_generate(aTHX_ predicate_name, (check_fptr_t)mouse_can_methods, (SV*)param); } - -XS(XS_Mouse_constraint_check) { +static +XSPROTO(XS_Mouse_constraint_check) { dVAR; dXSARGS; MAGIC* const mg = (MAGIC*)XSANY.any_ptr; @@ -561,8 +564,8 @@ XS(XS_Mouse_constraint_check) { XSRETURN(1); } -XS(XS_Mouse_TypeConstraint_fallback); /* -Wmissing-prototypes */ -XS(XS_Mouse_TypeConstraint_fallback) { +static +XSPROTO(XS_Mouse_TypeConstraint_fallback) { dXSARGS; PERL_UNUSED_VAR(cv); PERL_UNUSED_VAR(items); @@ -670,7 +673,6 @@ BOOT: INSTALL_SIMPLE_READER(TypeConstraint, type_parameter); INSTALL_SIMPLE_READER_WITH_KEY(TypeConstraint, _compiled_type_constraint, compiled_type_constraint); - INSTALL_SIMPLE_READER(TypeConstraint, _compiled_type_coercion); /* Mouse specific */ INSTALL_SIMPLE_PREDICATE_WITH_KEY(TypeConstraint, has_coercion, _compiled_type_coercion); INSTALL_SIMPLE_PREDICATE_WITH_KEY(TypeConstraint, __is_parameterized, type_parameter); /* Mouse specific */ @@ -694,7 +696,7 @@ BOOT: (SV*)gv_fetchpvs( MTC_CLASS "::(\"\"", GV_ADDMULTI, SVt_PVCV ), code_ref ); } - + /* '0+' => '_identity' */ { SV* const code_ref = sv_2mortal(newRV_inc( @@ -737,7 +739,7 @@ CODE: for(parent = get_slots(self, "parent"); parent; parent = get_slots(parent, "parent")){ check = get_slots(parent, "hand_optimized_type_constraint"); if(check && SvOK(check)){ - if(!mouse_tc_CodeRef(aTHX_ NULL, check)){ + if(!IsCodeRef(check)){ croak("Not a CODE reference"); } av_unshift(checks, 1); @@ -806,8 +808,9 @@ check(SV* self, SV* sv) CODE: { SV* const check = get_slots(self, "compiled_type_constraint"); - if(!(check && mouse_tc_CodeRef(aTHX_ NULL, check))){ - mouse_throw_error(self, check, "'%"SVf"' has no compiled type constraint", self); + if(!(check && IsCodeRef(check))){ + mouse_throw_error(self, check, + "'%"SVf"' has no compiled type constraint", self); } RETVAL = mouse_tc_check(aTHX_ check, sv) ? TRUE : FALSE; }