# New Ticket Created by  Bram Geron 
# Please include the string:  [perl #43462]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43462 >


Firstly, there are some clearups in <clearups.patch>, I think they're
self-explanatory.

Secondly, I discovered that when you're using -D80, Parrot_free_context
prints out the name of the 'sub' that the context was made for. I think
we can't rely on the sub being there, as this example will show:

- Create closure A over main.
- Invoke closure A, creating context B.
  - Create closure C over closure A, storing a ref to context B (but not
    to closure A). Store it in a global var maybe.
- Exit closure A. There is one less reference to context B.
- Empty the global var holding closure C.
- Free closure C. Now context B can be freed too:
  [free  ctx 0x12345678 of sub '<accessing freed memory here>']

I got a segfault for it, but my test case is too large to attach and I
think it will be hard to get the size down. It isn't very legible anyway.

To solve this we can omit printing the sub name in Parrot_free_context.
A patch that does this is in <context.patch>. Using -D80 does become
less legible, but I think we prefer more correct behavior.

Thanks,
-- 
Bram Geron | GPG 0xE7B9E65E




commit 75f9702c205694f1a81a00d0cc0181ae04436c0d
Author: Bram Geron <[EMAIL PROTECTED]>
Date:   Thu Jun 28 17:23:46 2007 +0200

    some clearups

diff --git a/src/pmc/closure.pmc b/src/pmc/closure.pmc
index 40073ad..fac291a 100644
--- a/src/pmc/closure.pmc
+++ b/src/pmc/closure.pmc
@@ -203,7 +203,7 @@ Destroys the closure.  This is necessary in order to reclaim the context.
         struct Parrot_sub * sub = PMC_sub(SELF);
 #if CTX_LEAK_DEBUG
         if (Interp_debug_TEST(INTERP, PARROT_CTX_DESTROY_DEBUG_FLAG)) {
-            fprintf(stderr, "[destroy closure %p, context %p, refs=%d]\n",
+            fprintf(stderr, "[destroy closure %p, context %p with %d refs]\n",
                     (void *)SELF, (void *)sub->outer_ctx,
                     (sub->outer_ctx ? sub->outer_ctx->ref_count : 0));
         }
diff --git a/src/pmc/sub.pmc b/src/pmc/sub.pmc
index 58d4ca1..abc94f7 100644
--- a/src/pmc/sub.pmc
+++ b/src/pmc/sub.pmc
@@ -58,10 +58,10 @@ Initializes the subroutine.
      *                as some other sub has :outer(this)
      * - private2 ... tailcall invoked this Sub
      * - private3 ... pythonic coroutine generator flag
-     * - private4 ... :main (nee @MAIN)
-     * - private5 ... :load (nee @LOAD)
-     * - private6 ... :immediate (nee @IMMEDIATE)
-     * - private7 ... :postcomp (nee @POSTCOMP)
+     * - private4 ... :main (see @MAIN)
+     * - private5 ... :load (see @LOAD)
+     * - private6 ... :immediate (see @IMMEDIATE)
+     * - private7 ... :postcomp (see @POSTCOMP)
      *
      * see also the enum in include/parrot/sub.h
      *




diff --git a/src/gc/register.c b/src/gc/register.c
index b0e2a88..e71e745 100644
--- a/src/gc/register.c
+++ b/src/gc/register.c
@@ -472,13 +472,7 @@ Parrot_free_context(Interp *interp /*NN*/, struct Parrot_Context *ctxp /*NN*/, i
         if (   Interp_debug_TEST(interp, PARROT_CTX_DESTROY_DEBUG_FLAG)
             && ctxp->current_sub) {
             /* can't probably PIO_eprintf here */
-            const Parrot_sub * const doomed = PMC_sub(ctxp->current_sub);
-
-            fprintf(stderr, "[free  ctx %p of sub '%s']\n",
-                    (void *)ctxp,
-                    (doomed->name == (void*)0xdeadbeef
-                     ? "???"
-                     : (char*)doomed->name->strstart));
+            fprintf(stderr, "[free  ctx %p]\n", (void *)ctxp);
         }
 #endif
         ptr  = ctxp;
diff --git a/src/pmc/sub.pmc b/src/pmc/sub.pmc
index d57289d..58d4ca1 100644
--- a/src/pmc/sub.pmc
+++ b/src/pmc/sub.pmc
@@ -101,6 +101,9 @@ Destroys the subroutine.
                     n && n->strstart ? (char*)n->strstart : "???");
         }
 #endif
+#ifndef NDEBUG
+        sub->name = NULL; /* detect it more often when we illegally try to print sub->name, like when using -D80 */
+#endif
         mem_sys_free(sub);
         PMC_struct_val(SELF) = NULL;
     }




Reply via email to