[svn:parrot] r48838 - trunk/compilers/imcc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Sep 7 23:52:26 UTC 2010


Author: chromatic
Date: Tue Sep  7 23:52:26 2010
New Revision: 48838
URL: https://trac.parrot.org/parrot/changeset/48838

Log:
[IMCC] Plugged tailcall compilation memory leak.

Modified:
   trunk/compilers/imcc/pcc.c
   trunk/compilers/imcc/symreg.c
   trunk/compilers/imcc/symreg.h

Modified: trunk/compilers/imcc/pcc.c
==============================================================================
--- trunk/compilers/imcc/pcc.c	Tue Sep  7 23:48:07 2010	(r48837)
+++ trunk/compilers/imcc/pcc.c	Tue Sep  7 23:52:26 2010	(r48838)
@@ -749,7 +749,13 @@
         ins     = insINS(interp, unit, ins, "tailcall", regs, 1);
     }
 
+    /* don't leak this sub SymReg; it gets detached here */
+    if (regs[0]->pcc_sub)
+        free_pcc_sub(regs[0]->pcc_sub);
+
+    /* this register is always the symbol "self", global to this IMC_Unit */
     regs[0]->pcc_sub  = sub->pcc_sub;
+
     sub->pcc_sub      = NULL;
     ins->type        |= ITPCCSUB;
 }

Modified: trunk/compilers/imcc/symreg.c
==============================================================================
--- trunk/compilers/imcc/symreg.c	Tue Sep  7 23:48:07 2010	(r48837)
+++ trunk/compilers/imcc/symreg.c	Tue Sep  7 23:52:26 2010	(r48838)
@@ -1256,6 +1256,30 @@
 
 /*
 
+=item C<void free_pcc_sub(pcc_sub_t *sub)>
+
+Frees all memory of the given pcc_sub_t.
+
+=cut
+
+*/
+
+void
+free_pcc_sub(ARGMOD(pcc_sub_t *sub))
+{
+    ASSERT_ARGS(free_pcc_sub)
+
+    mem_sys_free(sub->multi);
+    mem_sys_free(sub->args);
+    mem_sys_free(sub->arg_flags);
+    mem_sys_free(sub->ret);
+    mem_sys_free(sub->ret_flags);
+    mem_sys_free(sub);
+}
+
+
+/*
+
 =item C<void free_sym(SymReg *r)>
 
 Frees all memory of the specified SymReg.  If it has a pcc_sub_t entry, frees
@@ -1271,14 +1295,8 @@
     ASSERT_ARGS(free_sym)
     pcc_sub_t * const sub = r->pcc_sub;
 
-    if (sub) {
-        mem_sys_free(sub->multi);
-        mem_sys_free(sub->args);
-        mem_sys_free(sub->arg_flags);
-        mem_sys_free(sub->ret);
-        mem_sys_free(sub->ret_flags);
-        mem_sys_free(sub);
-    }
+    if (sub)
+        free_pcc_sub(sub);
 
     if (r->set == 'K') {
         SymReg *key     = r->nextkey;

Modified: trunk/compilers/imcc/symreg.h
==============================================================================
--- trunk/compilers/imcc/symreg.h	Tue Sep  7 23:48:07 2010	(r48837)
+++ trunk/compilers/imcc/symreg.h	Tue Sep  7 23:52:26 2010	(r48838)
@@ -84,6 +84,45 @@
     Identifier *idents;
 };
 
+typedef enum {
+    P_NONE           = 0x00,                  /* 0<<0 */
+    P_NEED_LEX       = 0x01,                  /* 1<<0 */
+    P_VTABLE         = SUB_COMP_FLAG_VTABLE,  /* 1<<1 0x2 */
+    P_METHOD         = SUB_COMP_FLAG_METHOD,  /* 1<<2 0x4 */
+    P_ANON           = SUB_FLAG_PF_ANON,      /* 1<<3 0x8    - private3 */
+    P_MAIN           = SUB_FLAG_PF_MAIN,      /* 1<<4 0x10   - private4 */
+    P_LOAD           = SUB_FLAG_PF_LOAD,      /* 1<<5 0x20   - private5 */
+    P_IMMEDIATE      = SUB_FLAG_PF_IMMEDIATE, /* 1<<6 0x40   - private6 */
+    P_POSTCOMP       = SUB_FLAG_PF_POSTCOMP,  /* 1<<7 0x80   - private7 */
+    P_INIT           = SUB_COMP_FLAG_PF_INIT, /* 1<<10 0x400 - 10       */
+    P_NSENTRY        = SUB_COMP_FLAG_NSENTRY  /* 1<<11 0x800 - 11       */
+} pragma_enum_t;
+
+typedef struct pcc_sub_t {
+    SymReg *sub;
+    SymReg *cc;
+    SymReg **args;
+    SymReg **multi;
+    SymReg **ret;
+    SymReg *object;
+    int    *arg_flags;    /* :slurpy, :optional, ... */
+    int    *ret_flags;    /* :slurpy, :optional, ... */
+    int     nargs;
+    int     nret;
+    int     nmulti;
+    int     yield;
+    int     tailcall;
+    int     label;
+    INTVAL  pragma;
+} pcc_sub_t;
+
+enum uniq_t {
+    U_add_once,
+    U_add_uniq_label,
+    U_add_uniq_sub,
+    U_add_all
+};
+
 /* functions */
 
 /* HEADERIZER BEGIN: compilers/imcc/symreg.c */
@@ -195,6 +234,10 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
+void free_pcc_sub(ARGMOD(pcc_sub_t *sub))
+        __attribute__nonnull__(1)
+        FUNC_MODIFIES(*sub);
+
 void free_sym(ARGMOD(SymReg *r))
         __attribute__nonnull__(1)
         FUNC_MODIFIES(*r);
@@ -365,6 +408,8 @@
 #define ASSERT_ARGS_find_sym __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(name))
+#define ASSERT_ARGS_free_pcc_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(sub))
 #define ASSERT_ARGS_free_sym __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(r))
 #define ASSERT_ARGS_get_sym __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -422,45 +467,6 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: compilers/imcc/symreg.c */
 
-typedef enum {
-    P_NONE           = 0x00,                  /* 0<<0 */
-    P_NEED_LEX       = 0x01,                  /* 1<<0 */
-    P_VTABLE         = SUB_COMP_FLAG_VTABLE,  /* 1<<1 0x2 */
-    P_METHOD         = SUB_COMP_FLAG_METHOD,  /* 1<<2 0x4 */
-    P_ANON           = SUB_FLAG_PF_ANON,      /* 1<<3 0x8    - private3 */
-    P_MAIN           = SUB_FLAG_PF_MAIN,      /* 1<<4 0x10   - private4 */
-    P_LOAD           = SUB_FLAG_PF_LOAD,      /* 1<<5 0x20   - private5 */
-    P_IMMEDIATE      = SUB_FLAG_PF_IMMEDIATE, /* 1<<6 0x40   - private6 */
-    P_POSTCOMP       = SUB_FLAG_PF_POSTCOMP,  /* 1<<7 0x80   - private7 */
-    P_INIT           = SUB_COMP_FLAG_PF_INIT, /* 1<<10 0x400 - 10       */
-    P_NSENTRY        = SUB_COMP_FLAG_NSENTRY  /* 1<<11 0x800 - 11       */
-} pragma_enum_t;
-
-typedef struct pcc_sub_t {
-    SymReg *sub;
-    SymReg *cc;
-    SymReg **args;
-    SymReg **multi;
-    SymReg **ret;
-    SymReg *object;
-    int    *arg_flags;    /* :slurpy, :optional, ... */
-    int    *ret_flags;    /* :slurpy, :optional, ... */
-    int     nargs;
-    int     nret;
-    int     nmulti;
-    int     yield;
-    int     tailcall;
-    int     label;
-    INTVAL  pragma;
-} pcc_sub_t;
-
-enum uniq_t {
-    U_add_once,
-    U_add_uniq_label,
-    U_add_uniq_sub,
-    U_add_all
-};
-
 #endif /* PARROT_IMCC_SYMREG_H_GUARD */
 
 /*


More information about the parrot-commits mailing list