]> git.vpit.fr Git - perl/modules/Lexical-Types.git/commitdiff
Move the run-time initializer call into a new lt_op_info_call() helper
authorVincent Pit <vince@profvince.com>
Fri, 6 Sep 2013 11:10:30 +0000 (13:10 +0200)
committerVincent Pit <vince@profvince.com>
Fri, 6 Sep 2013 11:10:30 +0000 (13:10 +0200)
Types.xs

index bf6c0bd4ec363d5a027562097985d8ecf23c75d4..faa8740d1e1b22742ef04fe049346d4a7a92bb9e 100644 (file)
--- a/Types.xs
+++ b/Types.xs
@@ -439,6 +439,61 @@ typedef struct {
  OP *(*old_pp)(pTHX);
 } lt_op_info;
 
+STATIC void lt_op_info_call(pTHX_ const lt_op_info *oi, SV *sv) {
+#define lt_op_info_call(O, S) lt_op_info_call(aTHX_ (O), (S))
+ SV *orig_pkg, *type_pkg, *type_meth;
+ int items;
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+#ifdef MULTIPLICITY
+ {
+  STRLEN op_len = oi->orig_pkg_len, tp_len = oi->type_pkg_len;
+  char *buf = oi->buf;
+  orig_pkg  = sv_2mortal(newSVpvn(buf, op_len));
+  SvREADONLY_on(orig_pkg);
+  buf      += op_len;
+  type_pkg  = sv_2mortal(newSVpvn(buf, tp_len));
+  SvREADONLY_on(type_pkg);
+  buf      += tp_len;
+  type_meth = sv_2mortal(newSVpvn(buf, oi->type_meth_len));
+  SvREADONLY_on(type_meth);
+ }
+#else /* MULTIPLICITY */
+ orig_pkg  = oi->orig_pkg;
+ type_pkg  = oi->type_pkg;
+ type_meth = oi->type_meth;
+#endif /* !MULTIPLICITY */
+
+ PUSHMARK(SP);
+ EXTEND(SP, 3);
+ PUSHs(type_pkg);
+ PUSHs(sv);
+ PUSHs(orig_pkg);
+ PUTBACK;
+
+ items = call_sv(type_meth, G_ARRAY | G_METHOD);
+
+ SPAGAIN;
+ switch (items) {
+  case 0:
+   break;
+  case 1:
+   sv_setsv(sv, POPs);
+   break;
+  default:
+   croak("Typed scalar initializer method should return zero or one scalar, but got %d", items);
+ }
+ PUTBACK;
+
+ FREETMPS;
+ LEAVE;
+
+ return;
+}
+
 STATIC void lt_map_store(pTHX_ const OP *o, SV *orig_pkg, SV *type_pkg, SV *type_meth, OP *(*old_pp)(pTHX)) {
 #define lt_map_store(O, OP, TP, TM, PP) lt_map_store(aTHX_ (O), (OP), (TP), (TM), (PP))
  lt_op_info *oi;
@@ -528,57 +583,8 @@ STATIC OP *lt_pp_padsv(pTHX) {
  lt_op_info oi;
 
  if (lt_map_fetch(PL_op, &oi)) {
-  SV *orig_pkg, *type_pkg, *type_meth;
-  int items;
-  dSP;
   dTARGET;
-
-  ENTER;
-  SAVETMPS;
-
-#ifdef MULTIPLICITY
-  {
-   STRLEN op_len = oi.orig_pkg_len, tp_len = oi.type_pkg_len;
-   char *buf = oi.buf;
-   orig_pkg  = sv_2mortal(newSVpvn(buf, op_len));
-   SvREADONLY_on(orig_pkg);
-   buf      += op_len;
-   type_pkg  = sv_2mortal(newSVpvn(buf, tp_len));
-   SvREADONLY_on(type_pkg);
-   buf      += tp_len;
-   type_meth = sv_2mortal(newSVpvn(buf, oi.type_meth_len));
-   SvREADONLY_on(type_meth);
-  }
-#else /* MULTIPLICITY */
-  orig_pkg  = oi.orig_pkg;
-  type_pkg  = oi.type_pkg;
-  type_meth = oi.type_meth;
-#endif /* !MULTIPLICITY */
-
-  PUSHMARK(SP);
-  EXTEND(SP, 3);
-  PUSHs(type_pkg);
-  PUSHTARG;
-  PUSHs(orig_pkg);
-  PUTBACK;
-
-  items = call_sv(type_meth, G_ARRAY | G_METHOD);
-
-  SPAGAIN;
-  switch (items) {
-   case 0:
-    break;
-   case 1:
-    sv_setsv(TARG, POPs);
-    break;
-   default:
-    croak("Typed scalar initializer method should return zero or one scalar, but got %d", items);
-  }
-  PUTBACK;
-
-  FREETMPS;
-  LEAVE;
-
+  lt_op_info_call(&oi, TARG);
   return oi.old_pp(aTHX);
  }