Add type_parameter() and __is_parameterized() to Meta::TypeConstraint
[gitmo/Mouse.git] / xs-src / MouseTypeConstraints.xs
index 08df0e8..605c923 100644 (file)
 
 typedef int (*check_fptr_t)(pTHX_ SV* const data, SV* const sv);
 
+/*
+    NOTE: mouse_tc_check() handles GETMAGIC
+*/
 int
 mouse_tc_check(pTHX_ SV* const tc_code, SV* const sv) {
     CV* const cv = (CV*)SvRV(tc_code);
     assert(SvTYPE(cv) == SVt_PVCV);
 
+    SvGETMAGIC(sv);
     if(CvXSUB(cv) == XS_Mouse_constraint_check){ /* built-in type constraints */
         MAGIC* const mg = (MAGIC*)CvXSUBANY(cv).any_ptr;
 
@@ -244,7 +248,6 @@ mouse_parameterized_ArrayRef(pTHX_ SV* const param, SV* const sv) {
         I32 i;
         for(i = 0; i < len; i++){
             SV* const value = *av_fetch(av, i, TRUE);
-            SvGETMAGIC(value);
             if(!mouse_tc_check(aTHX_ param, value)){
                 return FALSE;
             }
@@ -263,7 +266,6 @@ mouse_parameterized_HashRef(pTHX_ SV* const param, SV* const sv) {
         hv_iterinit(hv);
         while((he = hv_iternext(hv))){
             SV* const value = hv_iterval(hv, he);
-            SvGETMAGIC(value);
             if(!mouse_tc_check(aTHX_ param, value)){
                 hv_iterinit(hv); /* reset */
                 return FALSE;
@@ -657,10 +659,13 @@ BOOT:
     INSTALL_SIMPLE_READER(TypeConstraint, parent);
     INSTALL_SIMPLE_READER(TypeConstraint, message);
 
+    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 */
 
 void
 compile_type_constraint(SV* self)
@@ -736,6 +741,6 @@ CODE:
     else{
         check = newRV_inc((SV*)mouse_tc_generate(aTHX_ NULL, (check_fptr_t)mouse_types_check, (SV*)checks));
     }
-    set_slots(self, "compiled_type_constraint", check);
+    (void)set_slots(self, "compiled_type_constraint", check);
 }