[svn:parrot] r41095 - trunk/src

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Sep 7 05:22:28 UTC 2009


Author: chromatic
Date: Mon Sep  7 05:22:27 2009
New Revision: 41095
URL: https://trac.parrot.org/parrot/changeset/41095

Log:
[src] Tidied code in src/pmc_freeze.c.  It's still scary, but at least it's
slightly more readable.

Modified:
   trunk/src/pmc_freeze.c

Modified: trunk/src/pmc_freeze.c
==============================================================================
--- trunk/src/pmc_freeze.c	Mon Sep  7 05:18:19 2009	(r41094)
+++ trunk/src/pmc_freeze.c	Mon Sep  7 05:22:27 2009	(r41095)
@@ -69,7 +69,7 @@
 
 PARROT_INLINE
 static void do_thaw(PARROT_INTERP,
-    ARGIN_NULLOK(PMC* pmc),
+    ARGIN_NULLOK(PMC *pmc),
     ARGIN(visit_info *info))
         __attribute__nonnull__(1)
         __attribute__nonnull__(3);
@@ -457,23 +457,26 @@
 {
     ASSERT_ARGS(str_append)
 
-    const size_t used = s->bufused;
-    const int need_free = (int)Buffer_buflen(s) - used - len;
-    /*
-     * grow by factor 1.5 or such
-     */
+    const size_t used      = s->bufused;
+    const int    need_free = (int)Buffer_buflen(s) - used - len;
+
+    /* grow by factor 1.5 or such */
     if (need_free <= 16) {
         size_t new_size = (size_t) (Buffer_buflen(s) * 1.5);
         if (new_size < Buffer_buflen(s) - need_free + 512)
             new_size = Buffer_buflen(s) - need_free + 512;
+
         Parrot_gc_reallocate_string_storage(interp, s, new_size);
         PARROT_ASSERT(Buffer_buflen(s) - used - len >= 15);
     }
+
     mem_sys_memcopy((void *)((ptrcast_t)s->strstart + used), b, len);
+
     s->bufused += len;
-    s->strlen += len;
+    s->strlen  += len;
 }
 
+
 /*
 
 =item C<static void push_ascii_integer(PARROT_INTERP, IMAGE_IO *io, INTVAL v)>
@@ -494,6 +497,7 @@
     str_append(interp, io->image, buffer, len);
 }
 
+
 /*
 
 =item C<static void push_ascii_number(PARROT_INTERP, const IMAGE_IO *io,
@@ -515,6 +519,7 @@
     str_append(interp, io->image, buffer, len);
 }
 
+
 /*
 
 =item C<static void push_ascii_string(PARROT_INTERP, IMAGE_IO *io, const STRING
@@ -536,9 +541,11 @@
 {
     ASSERT_ARGS(push_ascii_string)
     const UINTVAL length = Parrot_str_byte_length(interp, s);
-    char * const buffer = (char *)malloc(4*length); /* XXX Why 4?  What does that mean? */
-    char *cursor = buffer;
-    UINTVAL idx = 0;
+
+    /* XXX Why 4?  What does that mean? */
+    char  * const buffer = mem_allocate_n_typed(4 * length, char *);
+    char         *cursor = buffer;
+    UINTVAL       idx    = 0;
 
     /* temporary--write out in UTF-8 */
     for (idx = 0; idx < length; ++idx) {
@@ -551,6 +558,7 @@
     mem_sys_free(buffer);
 }
 
+
 /*
 
 =item C<static void push_ascii_pmc(PARROT_INTERP, IMAGE_IO *io, const PMC* v)>
@@ -571,6 +579,7 @@
     str_append(interp, io->image, buffer, len);
 }
 
+
 /*
 
 =item C<static INTVAL shift_ascii_integer(PARROT_INTERP, IMAGE_IO *io)>
@@ -586,20 +595,23 @@
 {
     ASSERT_ARGS(shift_ascii_integer)
 
-    char * const start = (char*)io->image->strstart;
-    char *p = start;
-    const INTVAL i = strtoul(p, &p, 10);
+    char * const start = (char *)io->image->strstart;
+    char        *p     = start;
+    const INTVAL i     = strtoul(p, &p, 10);
 
     ++p;
     PARROT_ASSERT(p <= start + io->image->bufused);
+
     io->image->strstart = p;
     io->image->bufused -= (p - start);
-    io->image->strlen -= (p - start);
+    io->image->strlen  -= (p - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
     return i;
 }
 
+
 /*
 
 =item C<static FLOATVAL shift_ascii_number(PARROT_INTERP, IMAGE_IO *io)>
@@ -615,20 +627,23 @@
 {
     ASSERT_ARGS(shift_ascii_number)
 
-    char * const start = (char*)io->image->strstart;
-    char *p = start;
-    const FLOATVAL f = (FLOATVAL) strtod(p, &p);
+    char * const   start = (char *)io->image->strstart;
+    char          *p     = start;
+    const FLOATVAL f     = (FLOATVAL) strtod(p, &p);
 
     ++p;
     PARROT_ASSERT(p <= start + io->image->bufused);
+
     io->image->strstart = p;
     io->image->bufused -= (p - start);
-    io->image->strlen -= (p - start);
+    io->image->strlen  -= (p - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
     return f;
 }
 
+
 /*
 
 =item C<static STRING* shift_ascii_string(PARROT_INTERP, IMAGE_IO *io)>
@@ -647,23 +662,27 @@
     ASSERT_ARGS(shift_ascii_string)
     STRING *s;
 
-    char * const start = (char*)io->image->strstart;
-    char *p = start;
+    char * const start = (char *)io->image->strstart;
+    char        *p     = start;
 
     while (*p != ' ')
         ++p;
+
     ++p;
     PARROT_ASSERT(p <= start + io->image->bufused);
+
     io->image->strstart = p;
     io->image->bufused -= (p - start);
-    io->image->strlen -= (p - start);
+    io->image->strlen  -= (p - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
+    /* probably should be UTF-8 */
     s = string_make(interp, start, p - start - 1, "iso-8859-1", 0);
-/*    s = string_make(interp, start, p - start - 1, "UTF-8", 0); */
 
     return s;
 }
 
+
 /*
 
 =item C<static PMC* shift_ascii_pmc(PARROT_INTERP, IMAGE_IO *io)>
@@ -681,19 +700,24 @@
 {
     ASSERT_ARGS(shift_ascii_pmc)
 
-    char * const start = (char*)io->image->strstart;
-    char *p = start;
-    const unsigned long i = strtoul(p, &p, 16);
+    char * const        start = (char *)io->image->strstart;
+    char               *p     = start;
+    const unsigned long i     = strtoul(p, &p, 16);
+
     ++p;
+
     PARROT_ASSERT(p <= start + io->image->bufused);
+
     io->image->strstart = p;
     io->image->bufused -= (p - start);
-    io->image->strlen -= (p - start);
+    io->image->strlen  -= (p - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
-    return (PMC*) i;
+    return (PMC *)i;
 }
 
+
 /*
 
 =back
@@ -705,7 +729,7 @@
 =item C<static void op_check_size(PARROT_INTERP, STRING *s, size_t len)>
 
 Checks the size of the "stream" buffer to see if it can accommodate
-C<len> more bytes. If not then the buffer is expanded.
+C<len> more bytes. If not, expands the buffer.
 
 =cut
 
@@ -716,12 +740,10 @@
 op_check_size(PARROT_INTERP, ARGIN(STRING *s), size_t len)
 {
     ASSERT_ARGS(op_check_size)
-    const size_t used = s->bufused;
-    const int need_free = (int)Buffer_buflen(s) - used - len;
+    const size_t used      = s->bufused;
+    const int    need_free = (int)Buffer_buflen(s) - used - len;
 
-    /*
-     * grow by factor 1.5 or such
-     */
+    /* grow by factor 1.5 or such */
     if (need_free <= 16) {
         size_t new_size = (size_t) (Buffer_buflen(s) * 1.5);
         if (new_size < Buffer_buflen(s) - need_free + 512)
@@ -729,11 +751,14 @@
         Parrot_gc_reallocate_string_storage(interp, s, new_size);
         PARROT_ASSERT(Buffer_buflen(s) - used - len >= 15);
     }
+
 #ifndef DISABLE_GC_DEBUG
     Parrot_gc_compact_memory_pool(interp);
 #endif
+
 }
 
+
 /*
 
 =item C<static void op_append(PARROT_INTERP, STRING *s, opcode_t b, size_t len)>
@@ -751,12 +776,15 @@
     char *str_pos;
 
     op_check_size(interp, s, len);
-    str_pos = s->strstart + s->bufused;
+
+    str_pos                  = s->strstart + s->bufused;
     *((opcode_t *)(str_pos)) = b;
+
     s->bufused += len;
-    s->strlen += len;
+    s->strlen  += len;
 }
 
+
 /*
 
 =item C<static void push_opcode_integer(PARROT_INTERP, IMAGE_IO *io, INTVAL v)>
@@ -777,6 +805,7 @@
     op_append(interp, io->image, (opcode_t)v, sizeof (opcode_t));
 }
 
+
 /*
 
 =item C<static void push_opcode_number(PARROT_INTERP, IMAGE_IO *io, FLOATVAL v)>
@@ -792,10 +821,10 @@
 {
     ASSERT_ARGS(push_opcode_number)
 
-    const size_t   len  = PF_size_number() * sizeof (opcode_t);
+    opcode_t      *ignored;
     STRING * const s    = io->image;
+    const size_t   len  = PF_size_number() * sizeof (opcode_t);
     const size_t   used = s->bufused;
-    opcode_t      *ignored;
 
     op_check_size(interp, s, len);
     ignored = PF_store_number((opcode_t *)((ptrcast_t)s->strstart + used), &v);
@@ -805,6 +834,7 @@
     s->strlen  += len;
 }
 
+
 /*
 
 =item C<static void push_opcode_string(PARROT_INTERP, IMAGE_IO *io, STRING *v)>
@@ -820,10 +850,10 @@
 {
     ASSERT_ARGS(push_opcode_string)
 
-    const size_t len = PF_size_string(v) * sizeof (opcode_t);
-    STRING * const s = io->image;
-    const size_t used = s->bufused;
     opcode_t      *ignored;
+    STRING * const s    = io->image;
+    const size_t   len  = PF_size_string(v) * sizeof (opcode_t);
+    const size_t   used = s->bufused;
 
     op_check_size(interp, s, len);
     ignored = PF_store_string((opcode_t *)((ptrcast_t)s->strstart + used), v);
@@ -833,6 +863,7 @@
     s->strlen += len;
 }
 
+
 /*
 
 =item C<static void push_opcode_pmc(PARROT_INTERP, IMAGE_IO *io, PMC* v)>
@@ -850,6 +881,7 @@
     op_append(interp, io->image, (opcode_t)v, sizeof (opcode_t));
 }
 
+
 /*
 
 =item C<static INTVAL shift_opcode_integer(PARROT_INTERP, IMAGE_IO *io)>
@@ -870,12 +902,14 @@
                                     (const opcode_t **)opcode);
 
     io->image->bufused -= ((char *)io->image->strstart - start);
-    io->image->strlen -= ((char *)io->image->strstart - start);
+    io->image->strlen  -= ((char *)io->image->strstart - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
     return i;
 }
 
+
 /*
 
 =item C<static PMC* shift_opcode_pmc(PARROT_INTERP, IMAGE_IO *io)>
@@ -898,6 +932,7 @@
     return (PMC *)i;
 }
 
+
 /*
 
 =item C<static FLOATVAL shift_opcode_number(PARROT_INTERP, IMAGE_IO *io)>
@@ -919,12 +954,14 @@
                                     (const opcode_t **)opcode);
 
     io->image->bufused -= ((char *)io->image->strstart - start);
-    io->image->strlen -= ((char *)io->image->strstart - start);
+    io->image->strlen  -= ((char *)io->image->strstart - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
     return f;
 }
 
+
 /*
 
 =item C<static STRING* shift_opcode_string(PARROT_INTERP, IMAGE_IO *io)>
@@ -949,12 +986,14 @@
 
     io->image->strstart = opcode;
     io->image->bufused -= (opcode - start);
-    io->image->strlen -= (opcode - start);
+    io->image->strlen  -= (opcode - start);
+
     PARROT_ASSERT((int)io->image->bufused >= 0);
 
     return s;
 }
 
+
 /*
 
 =back
@@ -1011,7 +1050,7 @@
 ft_init(PARROT_INTERP, ARGIN(visit_info *info))
 {
     ASSERT_ARGS(ft_init)
-    STRING *s = info->image;
+    STRING   *s = info->image;
     PackFile *pf;
 
     /* We want to store a 16-byte aligned header, but the actual
@@ -1020,23 +1059,24 @@
         (PACKFILE_HEADER_BYTES % 16 ?
          16 - PACKFILE_HEADER_BYTES % 16 : 0);
 
-    info->image_io = mem_allocate_typed(IMAGE_IO);
+    info->image_io         = mem_allocate_typed(IMAGE_IO);
+    info->image_io->image  = s = info->image;
 
-    info->image_io->image = s = info->image;
 #if FREEZE_ASCII
     info->image_io->vtable = &ascii_funcs;
 #else
     info->image_io->vtable = &opcode_funcs;
 #endif
+
     pf = info->image_io->pf = PackFile_new(interp, 0);
 
-    if (info->what == VISIT_FREEZE_NORMAL ||
-        info->what == VISIT_FREEZE_AT_DESTRUCT) {
+    if (info->what == VISIT_FREEZE_NORMAL
+    ||  info->what == VISIT_FREEZE_AT_DESTRUCT) {
 
         op_check_size(interp, s, header_length);
         mem_sys_memcopy(s->strstart, pf->header, PACKFILE_HEADER_BYTES);
         s->bufused += header_length;
-        s->strlen += header_length;
+        s->strlen  += header_length;
     }
     else {
         if (Parrot_str_byte_length(interp, s) < header_length) {
@@ -1055,18 +1095,21 @@
 
         mem_sys_memcopy(pf->header, s->strstart, PACKFILE_HEADER_BYTES);
         PackFile_assign_transforms(pf);
+
         s->bufused -= header_length;
-        s->strlen -= header_length;
+        s->strlen  -= header_length;
+
         LVALUE_CAST(char *, s->strstart) += header_length;
     }
 
-    info->last_type = -1;
-    info->id_list = pmc_new(interp, enum_class_Array);
-    info->id = 0;
+    info->last_type   = -1;
+    info->id_list     = pmc_new(interp, enum_class_Array);
+    info->id          = 0;
     info->extra_flags = EXTRA_IS_NULL;
-    info->container = NULL;
+    info->container   = NULL;
 }
 
+
 /*
 
 =item C<static void todo_list_init(PARROT_INTERP, visit_info *info)>
@@ -1081,9 +1124,10 @@
 todo_list_init(PARROT_INTERP, ARGOUT(visit_info *info))
 {
     ASSERT_ARGS(todo_list_init)
-    info->visit_pmc_now = visit_todo_list;
+    info->visit_pmc_now   = visit_todo_list;
     info->visit_pmc_later = add_pmc_todo_list;
-    /* we must use PMCs here, so that they get marked properly */
+
+    /* we must use PMCs here so that they get marked properly */
     info->todo = pmc_new(interp, enum_class_Array);
     info->seen = pmc_new(interp, enum_class_Hash);
     VTABLE_set_pointer(interp, info->seen, parrot_new_intval_hash(interp));
@@ -1111,36 +1155,42 @@
 {
     ASSERT_ARGS(freeze_pmc)
     IMAGE_IO * const io = info->image_io;
-    INTVAL type;
+    INTVAL           type;
 
     if (PMC_IS_NULL(pmc)) {
         /* NULL + seen bit */
         VTABLE_push_pmc(interp, io, (PMC*) 1);
         return;
     }
+
     type = pmc->vtable->base_type;
 
     if (PObj_is_object_TEST(pmc))
         type = enum_class_Object;
+
+    /* TODO: get rid of these magic numbers; they look like pointer tags */
     if (seen) {
         if (info->extra_flags) {
             id |= 3;
-            VTABLE_push_pmc(interp, io, (PMC*)id);
+            VTABLE_push_pmc(interp, io, (PMC *)id);
             VTABLE_push_integer(interp, io, info->extra_flags);
             return;
         }
+
         id |= 1;         /* mark bit 0 if this PMC is known */
     }
-    else if (type == info->last_type) {
+    else if (type == info->last_type)
         id |= 2;         /* mark bit 1 and don't write type */
-    }
+
     VTABLE_push_pmc(interp, io, (PMC*)id);
+
     if (! (id & 3)) {    /* else write type */
         VTABLE_push_integer(interp, io, type);
         info->last_type = type;
     }
 }
 
+
 /*
 
 =item C<static int thaw_pmc(PARROT_INTERP, visit_info *info, UINTVAL *id, INTVAL
@@ -1170,41 +1220,46 @@
         ARGOUT(UINTVAL *id), ARGOUT(INTVAL *type))
 {
     ASSERT_ARGS(thaw_pmc)
-    PMC *n;
-    IMAGE_IO * const io = info->image_io;
-    int seen = 0;
+    IMAGE_IO * const io   = info->image_io;
+    PMC             *n    = VTABLE_shift_pmc(interp, io);
+    int              seen = 0;
 
-    info->extra_flags = EXTRA_IS_NULL;
-    n = VTABLE_shift_pmc(interp, io);
+    info->extra_flags     = EXTRA_IS_NULL;
 
+    /* pmc has extra data */
     if (((UINTVAL) n & 3) == 3) {
-        /* pmc has extra data */
         info->extra_flags = VTABLE_shift_integer(interp, io);
     }
-    else if ((UINTVAL) n & 1) {     /* seen PMCs have bit 0 set */
+
+    /* seen PMCs have bit 0 set */
+    else if ((UINTVAL) n & 1) {
         seen = 1;
     }
-    else if ((UINTVAL) n & 2) {     /* prev PMC was same type */
+
+    /* prev PMC was same type */
+    else if ((UINTVAL) n & 2) {
         *type = info->last_type;
     }
-    else {                          /* type follows */
-        *type = VTABLE_shift_integer(interp, io);
+
+    /* type follows */
+    else {
+        *type           = VTABLE_shift_integer(interp, io);
         info->last_type = *type;
+
         if (*type <= 0)
             Parrot_ex_throw_from_c_args(interp, NULL, 1,
                 "Unknown PMC type to thaw %d", (int) *type);
 
-        if (*type >= interp->n_vtable_max ||
-            !interp->vtables[*type]) {
-            /* that ought to be a class */
+        /* that ought to be a class */
+        if (*type >= interp->n_vtable_max || !interp->vtables[*type])
             *type = enum_class_Class;
-        }
     }
 
-    *id = (UINTVAL) n;
+    *id = (UINTVAL)n;
     return seen;
 }
 
+
 /*
 
 =item C<static void do_action(PARROT_INTERP, PMC *pmc, visit_info *info, int
@@ -1213,7 +1268,8 @@
 Called from C<visit_next_for_GC()> and C<visit_todo_list()> to perform
 the action specified in C<< info->what >>.
 
-Currently only C<VISIT_FREEZE_NORMAL> is implemented.
+Currently only C<VISIT_FREEZE_NORMAL> and C<VISIT_FREEZE_AT_DESTRUCT> are
+implemented.
 
 =cut
 
@@ -1238,6 +1294,7 @@
     }
 }
 
+
 /*
 
 =item C<static PMC* thaw_create_pmc(PARROT_INTERP, const visit_info *info,
@@ -1265,14 +1322,17 @@
             pmc = constant_pmc_new_noinit(interp, type);
             break;
         default:
-            Parrot_ex_throw_from_c_args(interp, NULL, 1, "Illegal visit_next type");
+            Parrot_ex_throw_from_c_args(interp, NULL, 1,
+                "Illegal visit_next type");
     }
+
     return pmc;
 }
 
+
 /*
 
-=item C<static void do_thaw(PARROT_INTERP, PMC* pmc, visit_info *info)>
+=item C<static void do_thaw(PARROT_INTERP, PMC *pmc, visit_info *info)>
 
 Called by C<visit_todo_list_thaw()> to thaw and return a PMC.
 
@@ -1284,15 +1344,15 @@
 
 PARROT_INLINE
 static void
-do_thaw(PARROT_INTERP, ARGIN_NULLOK(PMC* pmc), ARGIN(visit_info *info))
+do_thaw(PARROT_INTERP, ARGIN_NULLOK(PMC *pmc), ARGIN(visit_info *info))
 {
     ASSERT_ARGS(do_thaw)
-    UINTVAL id;
-    INTVAL type;
-    PMC ** pos;
-    int must_have_seen;
-    type = 0; /* it's set below, avoid compiler warning. */
-    must_have_seen = thaw_pmc(interp, info, &id, &type);
+    PMC **pos;
+
+    /* set below, but avoid compiler warning */
+    UINTVAL id             = 0;
+    INTVAL  type           = 0;
+    int     must_have_seen = thaw_pmc(interp, info, &id, &type);
 
     id >>= 2;
 
@@ -1306,19 +1366,23 @@
         return;
     }
 
-    pos = (PMC **)list_get(interp, (List *)PMC_data(info->id_list), id, enum_type_PMC);
-    if (pos == (void*)-1)
+    pos = (PMC **)list_get(interp, (List *)PMC_data(info->id_list),
+        id, enum_type_PMC);
+
+    if (pos == (void *)-1)
         pos = NULL;
     else if (pos) {
-        pmc = *(PMC**)pos;
+        pmc = *(PMC **)pos;
         if (!pmc)
             pos = NULL;
     }
+
     if (pos) {
         if (info->extra_flags == EXTRA_IS_PROP_HASH) {
             interp->vtables[enum_class_default]->thaw(interp, pmc, info);
             return;
         }
+
         /* else maybe VTABLE_thaw ... but there is no other extra stuff */
 
 #if FREEZE_USE_NEXT_FOR_GC
@@ -1348,11 +1412,13 @@
     pmc = thaw_create_pmc(interp, info, type);
 
     VTABLE_thaw(interp, pmc, info);
+
     if (info->extra_flags == EXTRA_CLASS_EXISTS) {
-        pmc = (PMC *)info->extra;
-        info->extra = NULL;
+        pmc               = (PMC *)info->extra;
+        info->extra       = NULL;
         info->extra_flags = 0;
     }
+
     if (!info->thaw_result)
         info->thaw_result = pmc;
     else {
@@ -1361,6 +1427,7 @@
         }
         *info->thaw_ptr = pmc;
     }
+
     list_assign(interp, (List *)PMC_data(info->id_list), id, pmc, enum_type_PMC);
     /* remember nested aggregates depth first */
     list_unshift(interp, (List *)PMC_data(info->todo), pmc, enum_type_PMC);
@@ -1371,10 +1438,10 @@
 
 =item C<static UINTVAL id_from_pmc(PARROT_INTERP, PMC* pmc)>
 
-Find a PMC in an arena, and return an id (left-shifted 2 bits),
-based on its position.
+Finds a PMC in an arena and returns an id (left-shifted 2 bits), based on its
+position.
 
-If not found, throw an exception.
+If not found, throws an exception.
 
 =cut
 
@@ -1387,6 +1454,7 @@
     return Parrot_gc_get_pmc_index(interp, pmc) << 2;
 }
 
+
 /*
 
 =item C<static void add_pmc_next_for_GC(PARROT_INTERP, PMC *pmc, visit_info
@@ -1403,19 +1471,19 @@
 {
     ASSERT_ARGS(add_pmc_next_for_GC)
     PMC_next_for_GC(info->mark_ptr) = pmc;
-    info->mark_ptr = PMC_next_for_GC(pmc) = pmc;
+    info->mark_ptr                  = PMC_next_for_GC(pmc) = pmc;
 
 }
 
+
 /*
 
 =item C<static int next_for_GC_seen(PARROT_INTERP, PMC *pmc, visit_info *info,
 UINTVAL *id)>
 
-Remembers next child to visit via the C<next_for_GC pointer> generate a
-unique ID per PMC and freeze the ID (not the PMC address) so thaw the
-hash-lookup can be replaced by an array lookup then which is a lot
-faster.
+Remembers next child to visit via the C<next_for_GC pointer>. Generates a
+unique ID per PMC and freezes the ID (not the PMC address) so that in thaw, the
+hash-lookup can be replaced by an array lookup.
 
 =cut
 
@@ -1439,15 +1507,19 @@
         seen = 1;
         goto skip;
     }
+
     /* put pmc at the end of the list */
     PMC_next_for_GC(info->mark_ptr) = pmc;
+
     /* make end self-referential */
     info->mark_ptr = PMC_next_for_GC(pmc) = pmc;
+
 skip:
     *id = id_from_pmc(interp, pmc);
     return seen;
 }
 
+
 /*
 
 =item C<static void add_pmc_todo_list(PARROT_INTERP, PMC *pmc, visit_info
@@ -1466,14 +1538,15 @@
     list_push(interp, (List *)PMC_data(info->todo), pmc, enum_type_PMC);
 }
 
+
 /*
 
 =item C<static int todo_list_seen(PARROT_INTERP, PMC *pmc, visit_info *info,
 UINTVAL *id)>
 
-Returns true if the PMC was seen, otherwise it put it on the todo list,
-generates an ID (tag) for PMC, offset by 4 as are addresses, low bits
-are flags.
+Returns true if the PMC was seen, otherwise it put it on the todo list.
+Generates an ID (tag) for PMC, offset by 4 as are addresses.  Low bits are
+flags.
 
 =cut
 
@@ -1494,15 +1567,21 @@
         return 1;
     }
 
-    info->id += 4;      /* next id to freeze */
+    /* next id to freeze */
+    info->id += 4;
+
     *id = info->id;
+
     parrot_hash_put(interp,
-            (Hash *)VTABLE_get_pointer(interp, info->seen), pmc, (void*)*id);
+            (Hash *)VTABLE_get_pointer(interp, info->seen), pmc, (void *)*id);
+
     /* remember containers */
     list_unshift(interp, (List *)PMC_data(info->todo), pmc, enum_type_PMC);
+
     return 0;
 }
 
+
 /*
 
 =item C<static void visit_next_for_GC(PARROT_INTERP, PMC* pmc, visit_info*
@@ -1510,8 +1589,7 @@
 
 C<visit_child> callbacks:
 
-Checks if the PMC was seen, generate an ID for it if not, then do the
-appropriate action.
+Checks if the PMC was seen.  If not, generates an ID for it.
 
 =cut
 
@@ -1521,7 +1599,7 @@
 visit_next_for_GC(PARROT_INTERP, ARGIN(PMC* pmc), ARGIN(visit_info* info))
 {
     ASSERT_ARGS(visit_next_for_GC)
-    UINTVAL id;
+    UINTVAL   id;
     const int seen = next_for_GC_seen(interp, pmc, info, &id);
     UNUSED(seen);
 
@@ -1539,6 +1617,7 @@
     */
 }
 
+
 /*
 
 =item C<static void visit_todo_list(PARROT_INTERP, PMC* pmc, visit_info* info)>
@@ -1553,20 +1632,23 @@
 visit_todo_list(PARROT_INTERP, ARGIN_NULLOK(PMC* pmc), ARGIN(visit_info* info))
 {
     ASSERT_ARGS(visit_todo_list)
-    UINTVAL id;
-    int seen;
+    int     seen;
+    UINTVAL id = 0;
 
     if (PMC_IS_NULL(pmc)) {
         seen = 1;
-        id = 0;
+        id   = 0;
     }
     else
         seen = todo_list_seen(interp, pmc, info, &id);
+
     do_action(interp, pmc, info, seen, id);
+
     if (!seen)
         (info->visit_action)(interp, pmc, info);
 }
 
+
 /*
 
 =item C<static void visit_todo_list_thaw(PARROT_INTERP, PMC* old, visit_info*
@@ -1587,6 +1669,7 @@
     do_thaw(interp, old, info);
 }
 
+
 /*
 
 =item C<static void visit_loop_next_for_GC(PARROT_INTERP, PMC *current,
@@ -1609,7 +1692,7 @@
 
     while (current != prev) {
         VTABLE_visit(interp, current, info);
-        prev = current;
+        prev    = current;
         current = PMC_next_for_GC(current);
     }
 }
@@ -1649,7 +1732,7 @@
 
     /* can't cache upper limit, visit may append items */
 again:
-    while ((list_item = (PMC**)list_shift(interp, todo, enum_type_PMC))) {
+    while ((list_item = (PMC **)list_shift(interp, todo, enum_type_PMC))) {
         current = *list_item;
         if (!current)
             Parrot_ex_throw_from_c_args(interp, NULL, 1,
@@ -1713,8 +1796,8 @@
     STRING *hash  = CONST_STRING(interp, "hash");
     INTVAL  len;
 
-    if (!PMC_IS_NULL(pmc) && (VTABLE_does(interp, pmc, array) ||
-        VTABLE_does(interp, pmc, hash))) {
+    if (!PMC_IS_NULL(pmc)
+    && (VTABLE_does(interp, pmc, array) || VTABLE_does(interp, pmc, hash))) {
         const INTVAL items = VTABLE_elements(interp, pmc);
         /* TODO check e.g. first item of aggregate and estimate size */
         len = items * FREEZE_BYTES_PER_ITEM;
@@ -1725,6 +1808,7 @@
     info->image = Parrot_str_new_noinit(interp, enum_stringrep_one, len);
 }
 
+
 /*
 
 =item C<static PMC* run_thaw(PARROT_INTERP, STRING* image, visit_enum_type
@@ -1752,13 +1836,13 @@
 run_thaw(PARROT_INTERP, ARGIN(STRING* image), visit_enum_type what)
 {
     ASSERT_ARGS(run_thaw)
-    visit_info info;
-    int gc_block = 0;
-    const UINTVAL bufused = image->bufused;
+    visit_info    info;
+    int           gc_block = 0;
+    const UINTVAL bufused  = image->bufused;
 
     info.image = image;
     /*
-     * if we are thawing a lot of PMCs, its cheaper to do
+     * if we are thawing a lot of PMCs, it's cheaper to do
      * a GC run first and then block GC - the limit should be
      * chosen so that no more then one GC run would be triggered
      *
@@ -1774,35 +1858,40 @@
         gc_block = 1;
     }
 
-    info.what = what;   /* _NORMAL or _CONSTANTS */
+    /* _NORMAL or _CONSTANTS */
+    info.what = what;
+
     todo_list_init(interp, &info);
-    info.visit_pmc_now = visit_todo_list_thaw;
+    info.visit_pmc_now   = visit_todo_list_thaw;
     info.visit_pmc_later = add_pmc_todo_list;
 
     info.thaw_result = NULL;
-    /*
-     * run thaw loop
-     */
+
+    /* run thaw loop */
     visit_loop_todo_list(interp, NULL, &info);
+
     /*
-     * thaw does "consume" the image string by incrementing strstart
+     * thaw consumes the image string by incrementing strstart
      * and decrementing bufused - restore that
      */
     LVALUE_CAST(char *, image->strstart) -= bufused;
     image->bufused = bufused;
     image->strlen += bufused;
+
     PARROT_ASSERT(image->strstart >= (char *)Buffer_bufstart(image));
 
     if (gc_block) {
         Parrot_unblock_GC_mark(interp);
         Parrot_unblock_GC_sweep(interp);
     }
+
     PackFile_destroy(interp, info.image_io->pf);
     mem_sys_free(info.image_io);
     info.image_io = NULL;
     return info.thaw_result;
 }
 
+
 /*
 
 =back
@@ -1813,8 +1902,8 @@
 
 =item C<STRING* Parrot_freeze_at_destruct(PARROT_INTERP, PMC* pmc)>
 
-This function must not consume any resources (except the image itself).
-It uses the C<next_for_GC> pointer, so its not reentrant and must not be
+This function must not consume any resources (except the image itself).  It
+uses the C<next_for_GC> pointer, so it's not reentrant and must not be
 interrupted by a GC run.
 
 =cut
@@ -1832,11 +1921,13 @@
 
     Parrot_block_GC_mark(interp);
     Parrot_gc_cleanup_next_for_GC(interp);
-    info.what = VISIT_FREEZE_AT_DESTRUCT;
-    info.mark_ptr = pmc;
-    info.thaw_ptr = NULL;
-    info.visit_pmc_now = visit_next_for_GC;
+
+    info.what            = VISIT_FREEZE_AT_DESTRUCT;
+    info.mark_ptr        = pmc;
+    info.thaw_ptr        = NULL;
+    info.visit_pmc_now   = visit_next_for_GC;
     info.visit_pmc_later = add_pmc_next_for_GC;
+
     create_image(interp, pmc, &info);
     ft_init(interp, &info);
 
@@ -1848,9 +1939,10 @@
     return info.image;
 }
 
+
 /*
 
-=item C<STRING* Parrot_freeze(PARROT_INTERP, PMC* pmc)>
+=item C<STRING* Parrot_freeze(PARROT_INTERP, PMC *pmc)>
 
 Freeze using either method.
 
@@ -1862,7 +1954,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 STRING*
-Parrot_freeze(PARROT_INTERP, ARGIN(PMC* pmc))
+Parrot_freeze(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_freeze)
 #if FREEZE_USE_NEXT_FOR_GC
@@ -1891,11 +1983,12 @@
 #endif
 }
 
+
 /*
 
-=item C<PMC* Parrot_thaw(PARROT_INTERP, STRING* image)>
+=item C<PMC* Parrot_thaw(PARROT_INTERP, STRING *image)>
 
-Thaw a PMC, called from the C<thaw> opcode.
+Thaws a PMC.  Called from the C<thaw> opcode.
 
 =cut
 
@@ -1905,18 +1998,18 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 PMC*
-Parrot_thaw(PARROT_INTERP, ARGIN(STRING* image))
+Parrot_thaw(PARROT_INTERP, ARGIN(STRING *image))
 {
     ASSERT_ARGS(Parrot_thaw)
     return run_thaw(interp, image, VISIT_THAW_NORMAL);
 }
 
+
 /*
 
-=item C<PMC* Parrot_thaw_constants(PARROT_INTERP, STRING* image)>
+=item C<PMC* Parrot_thaw_constants(PARROT_INTERP, STRING *image)>
 
-Thaw the constants. This is used by PackFile for unpacking PMC
-constants.
+Thaws constants, used by PackFile for unpacking PMC constants.
 
 =cut
 
@@ -1926,19 +2019,19 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 PMC*
-Parrot_thaw_constants(PARROT_INTERP, ARGIN(STRING* image))
+Parrot_thaw_constants(PARROT_INTERP, ARGIN(STRING *image))
 {
     ASSERT_ARGS(Parrot_thaw_constants)
     return run_thaw(interp, image, VISIT_THAW_CONSTANTS);
 }
 
+
 /*
 
-=item C<PMC* Parrot_clone(PARROT_INTERP, PMC* pmc)>
+=item C<PMC* Parrot_clone(PARROT_INTERP, PMC *pmc)>
 
 There are for sure shortcuts to clone faster, e.g. always thaw the image
-immediately or use a special callback. But for now we just thaw a frozen
-PMC.
+immediately or use a special callback.  For now we just thaw a frozen PMC.
 
 =cut
 
@@ -1954,13 +2047,14 @@
     return VTABLE_clone(interp, pmc);
 }
 
+
 /*
 
 =back
 
 =head1 TODO
 
-The seen-hash version for freezing might go away sometimes.
+The seen-hash version for freezing might go away sometime.
 
 =head1 SEE ALSO
 


More information about the parrot-commits mailing list