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


I send this to the list first, because it's probably not a final 
solution and people might have something better.

With this changes:

- tracing works now most of the time again
- "parrot befunge.pbc test.bef" doesn't loop anymore
- tests still succeed (but they barely cover DOD/GC related bugs)


Broken e.g.:
- parrot -d languages/perl6/examples/life.pbc
(only with LEA allocator, w/o -d it runs)

- parrot -t languages/perl6/examples/life.pbc
SIGSEGVs with both allocator schemes in/after DOD runs.

We still have DOD/GC related bugs.


Detailled list of changes:
embed.c:
- br0ken format in -d statistics

headers.c:
- set PMCs and Buffers initially to "live". This helps somwhat, that 
initially created objects are not killed immediately by a DOD run e.g. 
in midst of string_make

misc.c (again):
- copied one byte too much.

string.c:
- block GC/DOD in string_transcode. BTW is there any reason, that the 
default chartype is unicode? I.e. almost all the current mess starts out 
here - string-constants, read from packfile are considered unicode and 
the trans_coded numerous times in string_compare.

- set the C-String in string_to_cstring to immobile

trace.c:
- removed some SIGSEGVs due to printing strings e.g. for PerlArray or 
printing null strings.
- removed SIGSEGV related to width (when too small ~ULONG_MAX bytes 
where allocated).

res_lea.c:
- pad string

leo


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/39819/32240/ca3e48/gc-bugs.patch

--- parrot/embed.c      Fri Oct 11 10:00:38 2002
+++ parrot-leo/embed.c  Mon Oct 14 14:49:51 2002
@@ -356,16 +356,16 @@
          * about GC. */
         PIO_eprintf(interpreter, "\
 *** Parrot VM: Dumping GC info ***\n\
-\tTotal memory allocated: %p\n\
-\tTotal DOD runs:         %p\n\
-\tTotal collector runs:   %p\n\
-\tActive PMCs:            %p\n\
-\tActive buffers:         %p\n\
-\tTotal PMCs:             %p\n\
-\tTotal buffers:          %p\n\
+\tTotal memory allocated: %d\n\
+\tTotal DOD runs:         %d\n\
+\tTotal collector runs:   %d\n\
+\tActive PMCs:            %d\n\
+\tActive buffers:         %d\n\
+\tTotal PMCs:             %d\n\
+\tTotal buffers:          %d\n\
 \tSince last collection:\n\
-\t\tHeader allocations:   %p\n\
-\t\tMemory allocations:   %p\n\
+\t\tHeader allocations:   %d\n\
+\t\tMemory allocations:   %d\n\
 \n",
             interpreter->memory_allocated,
             interpreter->dod_runs,
--- parrot/headers.c    Sat Oct  5 13:30:19 2002
+++ parrot-leo/headers.c        Mon Oct 14 22:21:19 2002
@@ -62,7 +62,7 @@
     pmc = pool->free_list;
     pool->free_list = *(void **)pmc;
     
-    pmc->flags = 0;
+    pmc->flags = PMC_live_FLAG;
     /* Make sure it doesn't seem to be on the GC list */
     pmc->next_for_GC = NULL;
     
@@ -97,7 +97,6 @@
     ((Buffer *)buffer)->flags = BUFFER_on_free_list_FLAG;
     /* Use the right length */
     ((Buffer *)buffer)->buflen = 0;
-    ((Buffer *)buffer)->bufstart = 0;
 
     /* Copied from add_free_object */
     *(void **)buffer = pool->free_list;
@@ -121,7 +120,7 @@
     /* Don't let it point to garbage memory */
     buffer->bufstart = NULL;
     /* Clear the flagpole (especially BUFFER_on_free_list_FLAG) */
-    buffer->flags = 0;
+    buffer->flags = BUFFER_live_FLAG;
 #if GC_DEBUG
     buffer->version++;
 #endif
--- parrot/misc.c       Fri Oct 11 10:00:38 2002
+++ parrot-leo/misc.c   Sat Oct 12 13:11:01 2002
@@ -65,15 +65,22 @@
 Parrot_vsnprintf(struct Parrot_Interp *interpreter, char *targ,
                  size_t len, const char *pat, va_list args)
 {
-    STRING *ret = Parrot_vsprintf_c(interpreter, pat, args);
+    STRING *ret;
+    if (len == 0)
+        return;
+    len--;
+    if (len) {
+        ret = Parrot_vsprintf_c(interpreter, pat, args);
     string_transcode(interpreter, ret, NULL, NULL, &ret);
 
     if (len > ret->bufused) {
         len = ret->bufused;
     }
 
+        if (len)
     memcpy(targ, ret->strstart, len);
-    targ[len + 1] = 0;
+    }
+    targ[len] = 0;
 }
 
 STRING *
--- parrot/res_lea.c    Sat Oct  5 11:40:33 2002
+++ parrot-leo/res_lea.c        Mon Oct 14 20:39:22 2002
@@ -58,7 +58,7 @@
     if (size)
 #endif
     {
-#if 0
+#if 1
         pad = STRING_ALIGNMENT - 1;
         size = ((size + pad + 2) & ~pad) - 2;
 #endif
--- parrot/string.c     Fri Oct 11 10:00:40 2002
+++ parrot-leo/string.c Mon Oct 14 21:58:18 2002
@@ -354,6 +354,8 @@
          * encoding. So this seems to least bad compromise.
          */
     }
+    interpreter->GC_block_level++;
+    interpreter->DOD_block_level++;
 
     if (src->encoding == encoding && src->type == type) {
         dest = string_copy(interpreter, src);
@@ -361,11 +363,15 @@
         if (dest_ptr) {
             *dest_ptr = dest;
         }
+        interpreter->GC_block_level--;
+        interpreter->DOD_block_level--;
         return dest;
     }
 
     dest = string_make(interpreter, NULL, src->strlen * encoding->max_bytes,
                        encoding, 0, type);
+    interpreter->GC_block_level--;
+    interpreter->DOD_block_level--;
 
     if (src->type != dest->type) {
         transcoder1 = chartype_lookup_transcoder(src->type, dest->type);
@@ -1002,6 +1008,7 @@
         string_grow(interpreter, s, 1);
     }
 
+    s->flags |= BUFFER_immobile_FLAG;
     ((char *)s->strstart)[s->bufused] = 0;
     /* don't return local vars, return the right thing */
     return (char*)s->strstart;
--- parrot/trace.c      Mon Oct 14 10:54:00 2002
+++ parrot-leo/trace.c  Mon Oct 14 17:56:29 2002
@@ -22,8 +22,14 @@
 dump_pmc(struct Parrot_Interp *interpreter, PMC* pmc) {
     if(pmc) {
         if(pmc->vtable) {
-            PIO_eprintf(interpreter, "%S=PMC(%#p Str:\"%PS\" Num:%Pg Int:%Pd)",
-                pmc->vtable->name(interpreter, pmc), pmc, pmc, pmc, pmc);
+            if (pmc->vtable == Parrot_base_vtables + enum_class_PerlString) {
+            PIO_eprintf(interpreter, "%S=PMC(%#p Str:\"%PS\")",
+                pmc->vtable->name(interpreter, pmc), pmc, pmc);
+            }
+            else {
+            PIO_eprintf(interpreter, "%S=PMC(%#p Num:%Pg Int:%Pd)",
+                pmc->vtable->name(interpreter, pmc), pmc, pmc, pmc);
+            }
         }
         else {
             PIO_eprintf(interpreter, "PMC(NULL)");
@@ -129,8 +135,8 @@
                 escaped = PDB_escape(interpreter->code->const_table->
                                      constants[*(pc + i)]->string->strstart,
                                      interpreter->code->const_table->
-                                     constants[*(pc + i)]->string->strlen);
-                PIO_eprintf(interpreter, "\"%s\"", escaped);
+                                     constants[*(pc + i)]->string->bufused);
+                PIO_eprintf(interpreter, "\"%s\"", escaped ? escaped : "(null)");
                 break;
             case PARROT_ARG_KC:
                 trace_key_dump(interpreter, 
interpreter->code->const_table->constants[*(pc + i)]->key);
@@ -156,9 +162,9 @@
                     escaped = PDB_escape(interpreter->ctx.string_reg.
                                          registers[*(pc + i)]->strstart,
                                          interpreter->ctx.string_reg.
-                                         registers[*(pc + i)]->strlen);
+                                         registers[*(pc + i)]->bufused);
                     PIO_eprintf(interpreter, "S%vd=\"%s\"", *(pc + i),
-                            escaped);
+                            escaped ? escaped : "(null)");
                 }
                 else {
                     PIO_eprintf(interpreter, "S%vd=(null)", *(pc + i));
--- parrot/spf_render.c Mon Oct 14 10:54:00 2002
+++ parrot-leo/spf_render.c     Mon Oct 14 14:29:24 2002
@@ -131,6 +131,7 @@
             fill = cstr2pstr(" ");
         }
 
+        if (info->width > len - 1)
         string_repeat(interpreter, fill, info->width - (len - 1), &fill);
 
         if (info->flags & FLAG_MINUS) { /* left-align */

Reply via email to