]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blobdiff - Types.xs
Correct the refcount of the source SVs that aren't actually stored
[perl/modules/Lexical-Types.git] / Types.xs
index a01cc1525e7208324f0eb6ab243d6b5118124bf6..6a159bcdc2775cc517d8c11275237a197a934a0f 100644 (file)
--- a/Types.xs
+++ b/Types.xs
@@ -319,19 +319,19 @@ STATIC perl_mutex lt_op_map_mutex;
 #endif
 
 typedef struct {
-#if LT_MULTIPLICITY
+#ifdef MULTIPLICITY
  STRLEN buf_size, orig_pkg_len, type_pkg_len, type_meth_len;
  char *buf;
-#else /* LT_MULTIPLICITY */
+#else /* MULTIPLICITY */
  SV *orig_pkg;
  SV *type_pkg;
  SV *type_meth;
-#endif /* !LT_MULTIPLICITY */
+#endif /* !MULTIPLICITY */
  OP *(*pp_padsv)(pTHX);
 } lt_op_info;
 
-STATIC void lt_map_store(pPTBLMS_ const OP *o, SV *orig_pkg, SV *type_pkg, SV *type_meth, OP *(*pp_padsv)(pTHX)) {
-#define lt_map_store(O, OP, TP, TM, PP) lt_map_store(aPTBLMS_ (O), (OP), (TP), (TM), (PP))
+STATIC void lt_map_store(pTHX_ const OP *o, SV *orig_pkg, SV *type_pkg, SV *type_meth, OP *(*pp_padsv)(pTHX)) {
+#define lt_map_store(O, OP, TP, TM, PP) lt_map_store(aTHX_ (O), (OP), (TP), (TM), (PP))
  lt_op_info *oi;
 
 #ifdef USE_ITHREADS
@@ -341,18 +341,18 @@ STATIC void lt_map_store(pPTBLMS_ const OP *o, SV *orig_pkg, SV *type_pkg, SV *t
  if (!(oi = ptable_fetch(lt_op_map, o))) {
   oi = PerlMemShared_malloc(sizeof *oi);
   ptable_map_store(lt_op_map, o, oi);
-#if LT_MULTIPLICITY
+#ifdef MULTIPLICITY
   oi->buf      = NULL;
   oi->buf_size = 0;
-#else /* LT_MULTIPLICITY */
+#else /* MULTIPLICITY */
  } else {
   SvREFCNT_dec(oi->orig_pkg);
   SvREFCNT_dec(oi->type_pkg);
   SvREFCNT_dec(oi->type_meth);
-#endif /* !LT_MULTIPLICITY */
+#endif /* !MULTIPLICITY */
  }
 
-#if LT_MULTIPLICITY
+#ifdef MULTIPLICITY
  {
   STRLEN op_len       = SvCUR(orig_pkg);
   STRLEN tp_len       = SvCUR(type_pkg);
@@ -373,12 +373,15 @@ STATIC void lt_map_store(pPTBLMS_ const OP *o, SV *orig_pkg, SV *type_pkg, SV *t
   oi->orig_pkg_len  = op_len;
   oi->type_pkg_len  = tp_len;
   oi->type_meth_len = tm_len;
+  SvREFCNT_dec(orig_pkg);
+  SvREFCNT_dec(type_pkg);
+  SvREFCNT_dec(type_meth);
  }
-#else /* LT_MULTIPLICITY */
+#else /* MULTIPLICITY */
  oi->orig_pkg  = orig_pkg;
  oi->type_pkg  = type_pkg;
  oi->type_meth = type_meth;
-#endif /* !LT_MULTIPLICITY */
+#endif /* !MULTIPLICITY */
 
  oi->pp_padsv  = pp_padsv;
 
@@ -439,7 +442,7 @@ STATIC OP *lt_pp_padsv(pTHX) {
    ENTER;
    SAVETMPS;
 
-#if LT_MULTIPLICITY
+#ifdef MULTIPLICITY
    {
     STRLEN op_len = oi.orig_pkg_len, tp_len = oi.type_pkg_len;
     char *buf = oi.buf;
@@ -452,11 +455,11 @@ STATIC OP *lt_pp_padsv(pTHX) {
     type_meth = sv_2mortal(newSVpvn(buf, oi.type_meth_len));
     SvREADONLY_on(type_meth);
    }
-#else /* LT_MULTIPLICITY */
+#else /* MULTIPLICITY */
    orig_pkg  = oi.orig_pkg;
    type_pkg  = oi.type_pkg;
    type_meth = oi.type_meth;
-#endif /* !LT_MULTIPLICITY */
+#endif /* !MULTIPLICITY */
 
    PUSHMARK(SP);
    EXTEND(SP, 3);