Author: petdance
Date: Thu May 31 18:29:41 2007
New Revision: 18714

Modified:
   trunk/include/parrot/register.h
   trunk/src/gc/dod.c
   trunk/src/gc/gc_gms.c
   trunk/src/gc/gc_ims.c
   trunk/src/gc/register.c
   trunk/src/gc/resources.c
   trunk/src/gc/smallobject.c
   trunk/src/headers.c
   trunk/src/mmd.c
   trunk/src/pmc/env.pmc

Log:
consted everything in src/gc, and some things that call it directly, too.

Modified: trunk/include/parrot/register.h
==============================================================================
--- trunk/include/parrot/register.h     (original)
+++ trunk/include/parrot/register.h     Thu May 31 18:29:41 2007
@@ -76,7 +76,7 @@
 struct Parrot_Context;        /* parrot/interpreter.h */
 
 struct Parrot_Context * Parrot_alloc_context(Interp *, INTVAL *n_regs_used);
-struct Parrot_Context * Parrot_dup_context(Interp *, struct Parrot_Context 
*old);
+struct Parrot_Context * Parrot_dup_context(Interp *, const struct 
Parrot_Context *old);
 PARROT_API struct Parrot_Context * Parrot_push_context(Interp *, INTVAL 
*n_regs_used);
 PARROT_API void   Parrot_pop_context(Interp *);
 PARROT_API void Parrot_free_context(Interp *, struct Parrot_Context *, int 
re_use);

Modified: trunk/src/gc/dod.c
==============================================================================
--- trunk/src/gc/dod.c  (original)
+++ trunk/src/gc/dod.c  Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2006, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -213,7 +213,7 @@
 int
 Parrot_dod_trace_root(Parrot_Interp interp, int trace_stack)
 {
-    Arenas           *arena_base = interp->arena_base;
+    Arenas           * const arena_base = interp->arena_base;
     parrot_context_t *ctx;
 
     /*
@@ -256,7 +256,7 @@
      * get created as constant PMCs.
      */
     for (i = 1; i < (unsigned int)interp->n_vtable_max; i++) {
-        VTABLE *vtable = interp->vtables[i];
+        const VTABLE * const vtable = interp->vtables[i];
         /*
          * XXX dynpmc groups have empty slots for abstract objects
          */
@@ -340,7 +340,6 @@
     const int     lazy_dod    = arena_base->lazy_dod;
     PMC          *current     = arena_base->dod_mark_start;
     PMC          *next;
-    INTVAL        i           = 0;
 
     const UINTVAL mask = PObj_data_is_PMC_array_FLAG | PObj_custom_mark_FLAG;
 
@@ -389,9 +388,10 @@
         if (bits) {
             if (bits == PObj_data_is_PMC_array_FLAG) {
                 /* malloced array of PMCs */
-                PMC **data = PMC_data_typed(current, PMC **);
+                PMC ** const data = PMC_data_typed(current, PMC **);
 
                 if (data) {
+                    int i;
                     for (i = 0; i < PMC_int_val(current); i++) {
                         if (data[i])
                             pobject_lives(interp, (PObj *)data[i]);
@@ -534,7 +534,7 @@
 void
 Parrot_dod_sweep(Parrot_Interp interp, Small_Object_Pool *pool)
 {
-    Arenas *arena_base    = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
     UINTVAL i, total_used = 0;
     UINTVAL object_size   = pool->object_size;
 
@@ -600,7 +600,7 @@
 
                 /* if object is a PMC and needs destroying */
                 if (PObj_is_PMC_TEST(b)) {
-                    PMC *p = (PMC*)b;
+                    PMC * const p = (PMC*)b;
 
                     /* then destroy it here
                      *
@@ -616,7 +616,7 @@
                         /* if the PMC has a PMC_EXT structure,
                          * return it to the pool/arena
                          */
-                        Small_Object_Pool *ext_pool = arena_base->pmc_ext_pool;
+                        Small_Object_Pool * const ext_pool = 
arena_base->pmc_ext_pool;
 
                         if (PObj_is_PMC_shared_TEST(p) && PMC_sync(p)) {
                             MUTEX_DESTROY(PMC_sync(p)->pmc_lock);
@@ -804,11 +804,11 @@
 static void
 clear_live_bits(Parrot_Interp interp, Small_Object_Pool * const pool) {
     Small_Object_Arena *arena;
-    UINTVAL             i;
     const UINTVAL       object_size = pool->object_size;
 
     for (arena = pool->last_Arena; arena; arena = arena->prev) {
         Buffer *b = (Buffer *)arena->start_objects;
+        UINTVAL i;
 
         for (i = 0; i < arena->used; i++) {
             PObj_live_CLEAR(b);
@@ -938,7 +938,7 @@
 void
 Parrot_dod_ms_run(Parrot_Interp interp, int flags)
 {
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
     /* XXX these should go into the interpreter */
     int total_free     = 0;

Modified: trunk/src/gc/gc_gms.c
==============================================================================
--- trunk/src/gc/gc_gms.c       (original)
+++ trunk/src/gc/gc_gms.c       Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2004, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -216,9 +216,8 @@
 static void
 parrot_gc_gms_deinit(Interp* interp)
 {
-    Arenas *arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
-    arena_base = interp->arena_base;
     /*
      * TODO free generations
      */
@@ -244,10 +243,8 @@
 void
 Parrot_gc_gms_init(Interp* interp)
 {
-    Arenas *arena_base;
-    Small_Object_Pool *pool;
+    Arenas * const arena_base = interp->arena_base;
 
-    arena_base = interp->arena_base;
     arena_base->gc_private = mem_sys_allocate_zeroed(sizeof (Gc_gms_private));
 
     /*
@@ -383,13 +380,10 @@
 static void
 gc_gms_alloc_objects(Interp *interp, Small_Object_Pool *pool)
 {
-    Small_Object_Arena *new_arena;
-    size_t size, real_size;
+    const size_t real_size = pool->object_size;
+    Small_Object_Arena * const new_arena = mem_internal_allocate(sizeof 
(Small_Object_Arena));
+    const size_t size = real_size * pool->objects_per_alloc;
 
-
-    real_size = pool->object_size;
-    new_arena = mem_internal_allocate(sizeof (Small_Object_Arena));
-    size = real_size * pool->objects_per_alloc;
     new_arena->start_objects = mem_internal_allocate(size);
     /* insert arena in list */
     Parrot_append_arena_in_pool(interp, pool, new_arena, size);
@@ -408,7 +402,6 @@
 static void
 gc_gms_more_objects(Interp *interp, Small_Object_Pool *pool)
 {
-    Small_Object_Arena *arena;
     if (pool->skip)
         pool->skip = 0;
     else if (pool->last_Arena) {
@@ -488,9 +481,8 @@
 static Gc_gms_gen *
 gc_gms_create_gen(Interp *interp, Small_Object_Pool *pool, size_t gen_no)
 {
-    Gc_gms_gen *gen;
+    Gc_gms_gen * const gen = mem_sys_allocate(sizeof (*gen));
 
-    gen = mem_sys_allocate(sizeof (*gen));
     gen->gen_no = gen_no;
     gen->pool = pool;
     gen->timely_destruct_obj_sofar = 0;
@@ -537,10 +529,7 @@
 gc_gms_find_gen(Interp *interp, Gc_gms_hdr *h, UINTVAL gen_no)
 {
     Gc_gms_gen *gen;
-    Small_Object_Pool *pool;
-    UINTVAL i;
-
-    pool = h->gen->pool;
+    Small_Object_Pool * const pool = h->gen->pool;
 
     for (gen = pool->first_gen; gen; gen = gen->next) {
         if (gen_no == gen->gen_no)
@@ -565,9 +554,8 @@
 {
     Gc_gms_gen *gen;
     Gc_gms_hdr *prev, *next;
-    Small_Object_Pool *pool;
+    Small_Object_Pool * const pool = h->gen->pool;
 
-    pool = h->gen->pool;
     /* unsnap from current generation */
     prev = h->prev;
     next = h->next;
@@ -636,30 +624,25 @@
 static void
 gc_gms_store_igp(Interp *interp, Gc_gms_hdr *h)
 {
-    Gc_gms_gen *gen;
-    Gc_gms_hdr_list *igp;
+    Gc_gms_gen * const gen = h->gen;
+    Gc_gms_hdr_list * const igp = &gen->igp;
 
-    gen = h->gen;
-    igp = &gen->igp;
     gc_gms_store_hdr_list(interp, igp, h);
 }
 
 static void
 gc_gms_clear_igp(Interp *interp, Gc_gms_gen *gen)
 {
-    Gc_gms_hdr_list *igp;
+    Gc_gms_hdr_list * const igp = &gen->igp;
 
-    igp = &gen->igp;
     gc_gms_clear_hdr_list(interp, igp);
 }
 
 void
 parrot_gc_gms_wb(Interp *interp, PMC *agg, void *old, void *new)
 {
-    Gc_gms_hdr *nh, *ah;
-
-    nh = PObj_to_GMSH(new);
-    ah = PObj_to_GMSH(agg);
+    Gc_gms_hdr * const nh = PObj_to_GMSH(new);
+    Gc_gms_hdr * const ah = PObj_to_GMSH(agg);
 
     /* if this may be an aggregate store it in IGP list, thus making
      * it a possible root for this generation
@@ -706,14 +689,13 @@
 gc_gms_merge_gen(Interp *interp, Small_Object_Pool *pool,
         int flag, Gc_gms_plan *plan)
 {
-    Gc_gms_gen *gen, *prev;
     Gc_gms_hdr *h;
 
     /* run through the blacks and set their generation pointer
      * to the previous generation
      */
-    gen = pool->last_gen;
-    prev = gen->prev;
+    Gc_gms_gen * const gen = pool->last_gen;
+    Gc_gms_gen * const prev = gen->prev;
 
     for (h = pool->black; h != pool->free_list; h = h->next) {
         h->gen = prev;
@@ -756,7 +738,7 @@
 static int
 set_gen_cb(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
-    Gc_gms_plan *plan = (Gc_gms_plan *)arg;
+    Gc_gms_plan * const plan = (Gc_gms_plan *)arg;
 
     if (plan->merge_gen)
         gc_gms_merge_gen(interp, pool, flag, plan);
@@ -861,10 +843,7 @@
 static void
 gc_gms_setto_gray(Interp *interp, Gc_gms_hdr *h, int priority)
 {
-    Small_Object_Pool *pool;
-    Gc_gms_hdr *next, *prev;
-
-    pool = h->gen->pool;
+    Small_Object_Pool * const pool = h->gen->pool;
     /*
      * TODO high_priority like in src/dod.c
      */
@@ -874,6 +853,8 @@
     if (pool->white == h && (!priority || pool->white == pool->gray))
         pool->white = h->next;
     else {
+        Gc_gms_hdr *next, *prev;
+
         prev = h->prev;
         next = h->next;
         if (h == pool->white)
@@ -928,10 +909,8 @@
 static void
 gc_gms_setto_black(Interp *interp, Gc_gms_hdr *h, int priority)
 {
-    Small_Object_Pool *pool;
-    Gc_gms_hdr *next, *prev;
+    Small_Object_Pool * const pool = h->gen->pool;
 
-    pool = h->gen->pool;
     /*
      * TODO high_priority like src/dod.c
      * TODO if h needs destructions insert in front of chain
@@ -946,6 +925,8 @@
         pool->gray = h->next;
     }
     else {
+        Gc_gms_hdr *next, *prev;
+
         prev = h->prev;
         next = h->next;
         if (h == pool->white) {
@@ -1032,7 +1013,7 @@
 static void
 gc_gms_init_mark(Interp *interp)
 {
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
     arena_base->dod_trace_ptr = NULL;
     arena_base->dod_mark_start = NULL;
@@ -1045,17 +1026,14 @@
 static int
 trace_igp_cb(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
-    Gc_gms_gen *gen;
-    Gc_gms_hdr_list *igp;
     Gc_gms_hdr_store *s;
-    Gc_gms_hdr **p, *h;
-
-    gen = pool->last_gen;
-    igp = &gen->igp;
+    Gc_gms_gen * const gen = pool->last_gen;
+    Gc_gms_hdr_list * const igp = &gen->igp;
 
     for (s = igp->first; s; s = s->next) {
+        Gc_gms_hdr **p;
         for (p = s->store; p < s->ptr; ++p) {
-            h = *p;
+            Gc_gms_hdr * const h = *p;
             pobject_lives(interp, GMSH_to_PObj(h));
         }
     }
@@ -1065,9 +1043,8 @@
 static int
 gc_gms_trace_root(Interp *interp, int trace_stack)
 {
-    int ret;
+    const int ret = Parrot_dod_trace_root(interp, trace_stack);
 
-    ret = Parrot_dod_trace_root(interp, trace_stack);
     if (ret == 0)
         return 0;
     Parrot_forall_header_pools(interp, POOL_ALL, 0, trace_igp_cb);
@@ -1098,16 +1075,15 @@
 static int
 trace_children_cb(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
-    Arenas *arena_base = interp->arena_base;
-    int lazy_dod = arena_base->lazy_dod;
-    UINTVAL mask = PObj_data_is_PMC_array_FLAG | PObj_custom_mark_FLAG;
+    Arenas * const arena_base = interp->arena_base;
+    const int lazy_dod = arena_base->lazy_dod;
+    const UINTVAL mask = PObj_data_is_PMC_array_FLAG | PObj_custom_mark_FLAG;
     Gc_gms_hdr *h;
-    PMC *current;
-    UINTVAL bits;
-    INTVAL i;
 
     for (h = pool->gray; h != pool->white;) {
-        current = (PMC*)GMSH_to_PObj(h);
+        PMC * const current = (PMC*)GMSH_to_PObj(h);
+        UINTVAL bits;
+
         if (lazy_dod && arena_base->num_early_PMCs_seen >=
                 arena_base->num_early_DOD_PMCs) {
             return 1;
@@ -1121,9 +1097,10 @@
         if (bits) {
             if (bits == PObj_data_is_PMC_array_FLAG) {
                 /* malloced array of PMCs */
-                PMC **data = PMC_data(current);
+                PMC ** const data = PMC_data(current);
 
                 if (data) {
+                    INTVAL i;
                     for (i = 0; i < PMC_int_val(current); i++) {
                         if (data[i]) {
                             pobject_lives(interp, (PObj *)data[i]);
@@ -1164,12 +1141,12 @@
 sweep_cb_pmc(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
     Gc_gms_hdr *h;
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
     /* TODO object stats */
 
     for (h = pool->white; h != pool->free_list; h = h->next) {
-        PMC *obj = (PMC*)GMSH_to_PObj(h);
+        PMC * const obj = (PMC*)GMSH_to_PObj(h);
         if (PObj_needs_early_DOD_TEST(obj))
             --arena_base->num_early_DOD_PMCs;
         if (PObj_active_destroy_TEST(obj))
@@ -1178,7 +1155,7 @@
             /* if the PMC has a PMC_EXT structure,
              * return it to the pool
              */
-            Small_Object_Pool *ext_pool = arena_base->pmc_ext_pool;
+            Small_Object_Pool * const ext_pool = arena_base->pmc_ext_pool;
             ext_pool->add_free_object(interp, ext_pool, obj->pmc_ext);
         }
 
@@ -1195,7 +1172,7 @@
     /* TODO object stats */
 
     for (h = pool->white; h != pool->free_list; h = h->next) {
-        PObj *obj = GMSH_to_PObj(h);
+        PObj * const obj = GMSH_to_PObj(h);
         /*
          * this is ugly, we still have to sweep all buffers
          */
@@ -1295,8 +1272,7 @@
 static void
 parrot_gc_gms_run(Interp *interp, int flags)
 {
-    int lazy;
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
     Gc_gms_private *g_gms;
 
     if (arena_base->DOD_block_level) {
@@ -1305,9 +1281,8 @@
     ++arena_base->DOD_block_level;
     g_gms = arena_base->gc_private;
     if (flags & DOD_finish_FLAG) {
-        Small_Object_Pool *pool;
+        Small_Object_Pool * const pool = arena_base->pmc_pool;
 
-        pool = arena_base->pmc_pool;
         pool->white = pool->marker.next;
         /* XXX need to sweep over objects that have finalizers only */
         Parrot_forall_header_pools(interp, POOL_PMC, 0, sweep_cb_pmc);
@@ -1339,13 +1314,14 @@
 static void
 gms_debug_verify(Interp *interp, Small_Object_Pool *pool, const char *action)
 {
-    Gc_gms_hdr *h, *next;
+    Gc_gms_hdr *h;
     int bf, gf, wf, ff;
-    size_t i, n;
+    size_t i;
+
+    const size_t n = pool->total_objects;
 
     bf = gf = wf = ff = 0;
 
-    n = pool->total_objects;
 
     for (i = 0, h = &pool->marker; i <= n + 10; ++i) {
         if (i && h == &pool->marker)

Modified: trunk/src/gc/gc_ims.c
==============================================================================
--- trunk/src/gc/gc_ims.c       (original)
+++ trunk/src/gc/gc_ims.c       Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2004, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -154,7 +154,7 @@
 =item to-space
 
 The work area of the collector. During marking live objects are "moved"
-from the from-space into the to-space. This is the same as the next_for_GC
+from the from-space into the to-space. This is the same as the text_for_GC
 list used in src/dod.c. The to-space is initially empty. During marking
 it gets greyed and finally all reachable objects are black.
 
@@ -433,7 +433,7 @@
 #if ! DISABLE_GC_DEBUG
     if (GC_DEBUG(interp)) {
         if (pool == interp->arena_base->pmc_pool) {
-            PMC *p    = (PMC *)to_add;
+            PMC * const p = (PMC *)to_add;
             p->vtable = interp->vtables[enum_class_Null];
         }
     }
@@ -502,9 +502,8 @@
 static void
 parrot_gc_ims_deinit(Interp* interp)
 {
-    Arenas *arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
-    arena_base = interp->arena_base;
     mem_sys_free(arena_base->gc_private);
     arena_base->gc_private = NULL;
 }
@@ -525,9 +524,8 @@
 void
 Parrot_gc_ims_init(Interp* interp)
 {
-    Arenas *arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
-    arena_base = interp->arena_base;
     arena_base->gc_private = mem_sys_allocate_zeroed(sizeof (Gc_ims_private));
     /*
      * set function hooks according to pdd09
@@ -556,9 +554,8 @@
 parrot_gc_ims_reinit(Interp* interp)
 {
     Gc_ims_private *g_ims;
-    Arenas *arena_base;
+    Arenas * const arena_base = interp->arena_base;
 
-    arena_base = interp->arena_base;
     arena_base->lazy_dod = 0;
     Parrot_dod_ms_run_init(interp);
     /*
@@ -588,14 +585,12 @@
 static void
 parrot_gc_ims_mark(Interp* interp)
 {
-    Gc_ims_private *g_ims;
     size_t todo;
-    Arenas *arena_base;
     double work_factor;
     PMC *next;
 
-    arena_base = (Arenas *)interp->arena_base;
-    g_ims      = (Gc_ims_private *)arena_base->gc_private;
+    Arenas * const arena_base    = (Arenas *)interp->arena_base;
+    Gc_ims_private * const g_ims = (Gc_ims_private *)arena_base->gc_private;
     /*
      * use statistics from the previous run
      */
@@ -631,7 +626,7 @@
 static int
 sweep_cb(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
-    int *n_obj = (int *) arg;
+    int * const n_obj = (int *) arg;
 
     Parrot_dod_sweep(interp, pool);
     if (interp->profile && (flag & POOL_PMC))
@@ -643,7 +638,7 @@
 static void
 parrot_gc_ims_sweep(Interp* interp)
 {
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
     Gc_ims_private *g_ims;
     size_t n_objects;
 
@@ -695,7 +690,7 @@
 static int
 collect_cb(Interp *interp, Small_Object_Pool *pool, int flag, void *arg)
 {
-    int check_only = (int)(INTVAL)arg;
+    const int check_only = (int)(INTVAL)arg;
     Memory_Pool *mem_pool;
     /*
      * check if there is an associated memory pool
@@ -731,7 +726,7 @@
 static int
 parrot_gc_ims_collect(Interp* interp, INTVAL check_only)
 {
-    Arenas *arena_base = interp->arena_base;
+    Arenas * const arena_base = interp->arena_base;
     Gc_ims_private *g_ims;
     int ret;
 
@@ -765,8 +760,8 @@
 static void
 parrot_gc_ims_run_increment(Interp* interp)
 {
-    Arenas *arena_base    = interp->arena_base;
-    Gc_ims_private *g_ims = (Gc_ims_private *)arena_base->gc_private;
+    Arenas * const arena_base    = interp->arena_base;
+    Gc_ims_private * const g_ims = (Gc_ims_private *)arena_base->gc_private;
 
     if (arena_base->DOD_block_level || g_ims->state == GC_IMS_DEAD) {
         return;
@@ -843,8 +838,8 @@
 parrot_gc_ims_run(Interp *interp, int flags)
 {
     int lazy;
-    Arenas *arena_base    = interp->arena_base;
-    Gc_ims_private *g_ims = (Gc_ims_private *)arena_base->gc_private;
+    Arenas * const arena_base    = interp->arena_base;
+    Gc_ims_private * const g_ims = (Gc_ims_private *)arena_base->gc_private;
 
     if (arena_base->DOD_block_level || g_ims->state == GC_IMS_DEAD) {
         return;

Modified: trunk/src/gc/register.c
==============================================================================
--- trunk/src/gc/register.c     (original)
+++ trunk/src/gc/register.c     Thu May 31 18:29:41 2007
@@ -116,12 +116,12 @@
 destroy_context(Interp *interp)
 {
     int slot;
-    struct Parrot_Context *context, *prev;
+    struct Parrot_Context *context;
 
     /* clear active contexts all the way back to the initial context */
     context = CONTEXT(interp->ctx);
     while (context) {
-        prev    = context->caller_ctx;
+        struct Parrot_Context * prev = context->caller_ctx;
         mem_sys_free(context);
         context = prev;
     }
@@ -253,7 +253,7 @@
 }
 
 static void
-init_context(Interp *interp, parrot_context_t *ctx, parrot_context_t *old)
+init_context(Interp *interp, parrot_context_t *ctx, const parrot_context_t 
*old)
 {
     ctx->ref_count = 0;                 /* TODO 1 - Exceptions !!! */
     ctx->current_results = NULL;
@@ -282,7 +282,7 @@
 }
 
 struct Parrot_Context *
-Parrot_dup_context(Interp *interp, struct Parrot_Context *old)
+Parrot_dup_context(Interp *interp, const struct Parrot_Context *old)
 {
     size_t diff;
     struct Parrot_Context *ctx;
@@ -422,9 +422,6 @@
 void
 Parrot_free_context(Interp *interp, parrot_context_t *ctxp, int re_use)
 {
-    void *ptr;
-    int slot;
-
     /*
      * The context structure has a reference count, initially 0.  This field is
      * incrementented when a continuation that points to it is created -- 
either
@@ -435,11 +432,13 @@
      *
      */
     if (re_use || --ctxp->ref_count == 0) {
+        void *ptr;
+        int slot;
+
 #ifndef NDEBUG
         if (Interp_debug_TEST(interp, PARROT_CTX_DESTROY_DEBUG_FLAG)) {
             /* can't probably PIO_eprintf here */
-            Parrot_sub *doomed;
-            doomed = PMC_sub(ctxp->current_sub);
+            const Parrot_sub * const doomed = PMC_sub(ctxp->current_sub);
 
             fprintf(stderr, "[free  ctx %p of sub '%s']\n",
                     (void *)ctxp,
@@ -571,11 +570,10 @@
 void
 mark_register_stack(Parrot_Interp interp, Stack_Chunk_t* chunk)
 {
-    struct Interp_Context ctx;
-    save_regs_t   *save_r;
-
     for (; ; chunk = chunk->prev) {
         int i;
+        save_regs_t   *save_r;
+        struct Interp_Context ctx;
 
         pobject_lives(interp, (PObj*)chunk);
         if (chunk == chunk->prev)

Modified: trunk/src/gc/resources.c
==============================================================================
--- trunk/src/gc/resources.c    (original)
+++ trunk/src/gc/resources.c    Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2006, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -245,7 +245,6 @@
     char         *cur_spot;      /* Where we're currently copying to */
 
     Small_Object_Arena *cur_buffer_arena;
-    Small_Object_Pool  *header_pool;
     INTVAL             *ref_count  = NULL;
     Arenas * const      arena_base = interp->arena_base;
 
@@ -314,7 +313,7 @@
 
     /* Run through all the Buffer header pools and copy */
     for (j = 0; j < (INTVAL)arena_base->num_sized; j++) {
-        header_pool = arena_base->sized_header_pools[j];
+        Small_Object_Pool * const header_pool = 
arena_base->sized_header_pools[j];
 
         if (header_pool == NULL)
             continue;
@@ -352,7 +351,7 @@
                     /* buffer has already been moved; just change the header */
                     if (PObj_COW_TEST(b) && *ref_count & Buffer_moved_FLAG) {
                         /* Find out who else references our data */
-                        Buffer *hdr = *(Buffer **)(PObj_bufstart(b));
+                        Buffer * const hdr = *(Buffer **)(PObj_bufstart(b));
 
                         assert(PObj_is_COWable_TEST(b));
 
@@ -375,7 +374,7 @@
                         cur_spot = aligned_mem(b, cur_spot);
 
                         if (PObj_is_COWable_TEST(b)) {
-                            INTVAL *new_ref_count = ((INTVAL*) cur_spot) - 1;
+                            INTVAL * const new_ref_count = ((INTVAL*) 
cur_spot) - 1;
                             *new_ref_count        = 2;
                         }
 
@@ -426,12 +425,12 @@
     /* Now we're done. We're already on the pool's free list, so let us be the
      * only one on the free list and free the rest */
     {
-        Memory_Block *cur_block, *next_block;
+        Memory_Block *cur_block;
 
         assert(new_block == pool->top_block);
         cur_block = new_block->prev;
         while (cur_block) {
-            next_block = cur_block->prev;
+            Memory_Block * const next_block = cur_block->prev;
             /* Note that we don't have it any more */
             arena_base->memory_allocated -= cur_block->size;
             /* We know the pool body and pool header are a single chunk, so
@@ -867,12 +866,11 @@
 static void merge_pools(Memory_Pool *dest, Memory_Pool *source)
 {
     Memory_Block *cur_block;
-    Memory_Block *next_block;
 
     cur_block = source->top_block;
 
     while (cur_block) {
-        next_block = cur_block->prev;
+        Memory_Block * const next_block = cur_block->prev;
 
         if (cur_block->free == cur_block->size) {
             mem_internal_free(cur_block);

Modified: trunk/src/gc/smallobject.c
==============================================================================
--- trunk/src/gc/smallobject.c  (original)
+++ trunk/src/gc/smallobject.c  Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2006, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -36,6 +36,8 @@
 
 Returns whether C<pool> contains C<*ptr>.
 
+XXX If ever there is a function that ought to be consted, this is it.
+
 =cut
 
 */
@@ -43,7 +45,7 @@
 INTVAL
 contained_in_pool(Interp *interp, Small_Object_Pool *pool, void *ptr)
 {
-    Small_Object_Arena *arena;
+    const Small_Object_Arena *arena;
 
     ptr = PObj_to_ARENA(ptr);
 
@@ -75,8 +77,7 @@
 Parrot_is_const_pmc(Parrot_Interp interp, PMC *pmc)
 {
     Small_Object_Pool * const pool = interp->arena_base->constant_pmc_pool;
-    int c;
-    c = contained_in_pool(interp, pool, pmc);
+    const int c = contained_in_pool(interp, pool, pmc);
 
     /* some paranoia first */
     assert(!!PObj_constant_TEST(pmc) == !!c);
@@ -243,12 +244,11 @@
 static void
 gc_ms_alloc_objects(Interp *interp, Small_Object_Pool *pool)
 {
-    Small_Object_Arena *new_arena;
     size_t size;
     UINTVAL start, end;
 
     /* Setup memory for the new objects */
-    new_arena = (Small_Object_Arena *)mem_internal_allocate(
+    Small_Object_Arena * const new_arena = (Small_Object_Arena 
*)mem_internal_allocate(
         sizeof (Small_Object_Arena));
     if (!new_arena)
         PANIC("Out of arena memory");
@@ -371,7 +371,6 @@
 Parrot_small_object_pool_merge(Interp *interp,
         Small_Object_Pool *dest, Small_Object_Pool *source) {
     Small_Object_Arena *cur_arena;
-    Small_Object_Arena *next_arena;
     void **free_list_end;
 
     /* XXX num_free_objects doesn't seem to be accounted correctly in, e.g.,
@@ -402,7 +401,8 @@
     cur_arena = source->last_Arena;
     while (cur_arena) {
         size_t total_objects;
-        next_arena = cur_arena->prev;
+        Small_Object_Arena * const next_arena = cur_arena->prev;
+
         cur_arena->next = cur_arena->prev = NULL;
 
         total_objects = cur_arena->total_objects;

Modified: trunk/src/headers.c
==============================================================================
--- trunk/src/headers.c (original)
+++ trunk/src/headers.c Thu May 31 18:29:41 2007
@@ -497,10 +497,10 @@
 */
 
 int
-is_buffer_ptr(Interp *interp, void *ptr)
+is_buffer_ptr(Interp *interp, void *ptr) /* XXX Const this */
 {
     UINTVAL i;
-    Arenas *arena_base = interp->arena_base;;
+    Arenas * const arena_base = interp->arena_base;
 
     for (i = 0; i < arena_base->num_sized; i++) {
         if (arena_base->sized_header_pools[i] &&
@@ -524,7 +524,7 @@
 */
 
 int
-is_pmc_ptr(Interp *interp, void *ptr)
+is_pmc_ptr(Interp *interp, void *ptr) /* XXX Const this */
 {
     return contained_in_pool(interp,
             interp->arena_base->pmc_pool, ptr);

Modified: trunk/src/mmd.c
==============================================================================
--- trunk/src/mmd.c     (original)
+++ trunk/src/mmd.c     Thu May 31 18:29:41 2007
@@ -162,9 +162,8 @@
 get_mmd_dispatcher(Interp *interp, PMC *left, PMC * right,
         INTVAL function, int *is_pmc)
 {
-    UINTVAL left_type, right_type;
-    left_type = VTABLE_type(interp, left);
-    right_type = VTABLE_type(interp, right);
+    const UINTVAL left_type = VTABLE_type(interp, left);
+    const UINTVAL right_type = VTABLE_type(interp, right);
     return get_mmd_dispatch_type(interp, function, left_type, right_type,
             is_pmc);
 }
@@ -266,7 +265,6 @@
         PMC *left, PMC *right, PMC *dest, INTVAL func_nr)
 {
     mmd_f_p_ppp real_function;
-    PMC *sub;
     int is_pmc;
 
     left = mmd_deref(interp, func_nr, left);
@@ -276,7 +274,7 @@
             left, right, func_nr, &is_pmc);
 
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         if (dest)
             return Parrot_runops_fromc_args(interp, sub, "PPPP",
                     left, right, dest);
@@ -326,7 +324,6 @@
         PMC *left, FLOATVAL right, PMC *dest, INTVAL func_nr)
 {
     mmd_f_p_pnp real_function;
-    PMC *sub;
     int is_pmc;
     UINTVAL left_type;
 
@@ -336,7 +333,7 @@
     real_function = (mmd_f_p_pnp)get_mmd_dispatch_type(interp,
             func_nr, left_type, enum_type_FLOATVAL, &is_pmc);
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         if (dest)
             return Parrot_runops_fromc_args(interp, sub, "PPNP",
                     left, right, dest);
@@ -354,7 +351,6 @@
         PMC *left, STRING *right, PMC *dest, INTVAL func_nr)
 {
     mmd_f_p_psp real_function;
-    PMC *sub;
     int is_pmc;
     UINTVAL left_type;
 
@@ -362,7 +358,7 @@
     real_function = (mmd_f_p_psp)get_mmd_dispatch_type(interp,
             func_nr, left_type, enum_type_STRING, &is_pmc);
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         if (dest)
             return Parrot_runops_fromc_args(interp, sub, "PPSP",
                     left, right, dest);
@@ -383,7 +379,6 @@
         PMC *left, PMC *right, INTVAL func_nr)
 {
     mmd_f_v_pp real_function;
-    PMC *sub;
     int is_pmc;
 
 
@@ -396,7 +391,7 @@
             left, right, func_nr, &is_pmc);
 
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         Parrot_runops_fromc_args(interp, sub, "vPP", left, right);
     }
     else {
@@ -409,7 +404,6 @@
         PMC *left, INTVAL right, INTVAL func_nr)
 {
     mmd_f_v_pi real_function;
-    PMC *sub;
     int is_pmc;
     UINTVAL left_type;
 
@@ -420,7 +414,7 @@
     real_function = (mmd_f_v_pi)get_mmd_dispatch_type(interp,
             func_nr, left_type, enum_type_INTVAL, &is_pmc);
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         Parrot_runops_fromc_args(interp, sub, "vPI", left, right);
     }
     else {
@@ -433,7 +427,6 @@
         PMC *left, FLOATVAL right, INTVAL func_nr)
 {
     mmd_f_v_pn real_function;
-    PMC *sub;
     int is_pmc;
     UINTVAL left_type;
 
@@ -444,7 +437,7 @@
     real_function = (mmd_f_v_pn)get_mmd_dispatch_type(interp,
             func_nr, left_type, enum_type_FLOATVAL, &is_pmc);
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         Parrot_runops_fromc_args(interp, sub, "vPN", left, right);
     }
     else {
@@ -457,7 +450,6 @@
         PMC *left, STRING *right, INTVAL func_nr)
 {
     mmd_f_v_ps real_function;
-    PMC *sub;
     int is_pmc;
     UINTVAL left_type;
 
@@ -468,7 +460,7 @@
     real_function = (mmd_f_v_ps)get_mmd_dispatch_type(interp,
             func_nr, left_type, enum_type_STRING, &is_pmc);
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         Parrot_runops_fromc_args(interp, sub, "vPS", left, right);
     }
     else {
@@ -494,7 +486,6 @@
         PMC *left, PMC *right, INTVAL func_nr)
 {
     mmd_f_i_pp real_function;
-    PMC *sub;
     int is_pmc;
     INTVAL ret;
 
@@ -505,7 +496,7 @@
             left, right, func_nr, &is_pmc);
 
     if (is_pmc) {
-        sub = (PMC*)real_function;
+        PMC * const sub = (PMC*)real_function;
         ret = Parrot_runops_fromc_args_reti(interp, sub, "IPP",
                 left, right);
     }
@@ -534,8 +525,8 @@
 mmd_add_function(Interp *interp,
         INTVAL func_nr, funcptr_t function)
 {
-    INTVAL i;
     if (func_nr >= (INTVAL)interp->n_binop_mmd_funcs) {
+        INTVAL i;
         if (interp->binop_mmd_funcs) {
             interp->binop_mmd_funcs =
                 (MMD_table *)mem_sys_realloc(interp->binop_mmd_funcs,
@@ -547,8 +538,9 @@
         }
 
         for (i = interp->n_binop_mmd_funcs; i <= func_nr; ++i)  {
-            MMD_table *table = interp->binop_mmd_funcs + i;
-            table->x = table->y = 0;
+            MMD_table * const table = interp->binop_mmd_funcs + i;
+            table->x = 0;
+            table->y = 0;
             table->mmd_funcs = NULL;
         }
         interp->n_binop_mmd_funcs = func_nr + 1;
@@ -633,7 +625,7 @@
 {
     funcptr_t *new_table;
     UINTVAL    new_size;
-    MMD_table *table = interp->binop_mmd_funcs + func_nr;
+    MMD_table * const table = interp->binop_mmd_funcs + func_nr;
 
     assert(table->x);
 
@@ -768,14 +760,13 @@
              INTVAL left_type, INTVAL right_type,
              PMC *sub)
 {
-    PMC *fake;
     if (sub->vtable->base_type == enum_class_NCI) {
         /* returned from mmdvt_find */
         mmd_register(interp, func_nr, left_type, right_type,
                 D2FPTR(PMC_struct_val(sub)));
     }
     else {
-        fake = (PMC*)((UINTVAL) sub | 1);
+        PMC * const fake = (PMC*)((UINTVAL) sub | 1);
         mmd_register(interp, func_nr, left_type, right_type, D2FPTR(fake));
     }
 }
@@ -825,7 +816,7 @@
            INTVAL left, INTVAL right) {
     int is_pmc;
     PMC *f;
-    funcptr_t func = get_mmd_dispatch_type(interp,
+    const funcptr_t func = get_mmd_dispatch_type(interp,
             func_nr, left, right, &is_pmc);
     if (func && is_pmc) {
         /* TODO if is_pmc == 2 a Bound_NCI is returned, which actually
@@ -854,9 +845,8 @@
 Parrot_MMD_search_default_infix(Interp *interp, STRING *meth,
         INTVAL left_type, INTVAL right_type)
 {
-    PMC* arg_tuple;
+    PMC* const arg_tuple = pmc_new(interp, enum_class_FixedIntegerArray);
 
-    arg_tuple = pmc_new(interp, enum_class_FixedIntegerArray);
     VTABLE_set_integer_native(interp, arg_tuple, 2);
     VTABLE_set_integer_keyed_int(interp, arg_tuple, 0, left_type);
     VTABLE_set_integer_keyed_int(interp, arg_tuple, 1, right_type);
@@ -917,16 +907,17 @@
 static PMC*
 mmd_arg_tuple_inline(Interp *interp, STRING *signature, va_list args)
 {
-    INTVAL sig_len, i, type;
-    PMC* arg_tuple, *arg;
+    INTVAL i;
+    PMC *arg;
+
+    PMC * const arg_tuple = pmc_new(interp, enum_class_FixedIntegerArray);
+    const INTVAL sig_len = string_length(interp, signature);
 
-    arg_tuple = pmc_new(interp, enum_class_FixedIntegerArray);
-    sig_len = string_length(interp, signature);
     if (!sig_len)
         return arg_tuple;
     VTABLE_set_integer_native(interp, arg_tuple, sig_len);
     for (i = 0; i < sig_len; ++i) {
-        type = string_index(interp, signature, i);
+        INTVAL type = string_index(interp, signature, i);
         switch (type) {
             case 'I':
                 VTABLE_set_integer_keyed_int(interp, arg_tuple,
@@ -961,7 +952,7 @@
 mmd_arg_tuple_func(Interp *interp)
 {
     INTVAL sig_len, i, type, idx;
-    PMC* arg_tuple, *arg;
+    PMC* arg;
     PMC* args_array;    /* from recent set_args opcode */
     opcode_t *args_op;
     PackFile_Constant **constants;
@@ -974,7 +965,8 @@
      * - dispatch in invoke - yeah ugly
      */
 
-    arg_tuple = pmc_new(interp, enum_class_ResizableIntegerArray);
+    PMC * const arg_tuple = pmc_new(interp, enum_class_ResizableIntegerArray);
+
     args_op = interp->current_args;
     if (!args_op)
         return arg_tuple;
@@ -1051,22 +1043,20 @@
 static PMC*
 mmd_search_default(Interp *interp, STRING *meth, PMC *arg_tuple)
 {
-    PMC *candidate_list, *pmc;
     INTVAL n;
-    STRING *_sub;
 
     /*
      * 2) create a list of matching functions
      */
-    candidate_list = mmd_search_scopes(interp, meth, arg_tuple);
+    PMC * const candidate_list = mmd_search_scopes(interp, meth, arg_tuple);
     /*
      * 3) if list is empty fail
      *    if the first found function is a plain Sub: finito
      */
     n = VTABLE_elements(interp, candidate_list);
     if (n == 1) {
-        pmc = VTABLE_get_pmc_keyed_int(interp, candidate_list, 0);
-        _sub = CONST_STRING(interp, "Sub");
+        PMC * const pmc = VTABLE_get_pmc_keyed_int(interp, candidate_list, 0);
+        STRING * const _sub = CONST_STRING(interp, "Sub");
 
         if (VTABLE_isa(interp, pmc, _sub)) {
             return pmc;
@@ -1092,8 +1082,7 @@
     /*
      * 6) Uff, return first one
      */
-    pmc = VTABLE_get_pmc_keyed_int(interp, candidate_list, 0);
-    return pmc;
+    return VTABLE_get_pmc_keyed_int(interp, candidate_list, 0);
 }
 
 /*
@@ -1269,7 +1258,7 @@
         mro = interp->vtables[type_call]->mro;
         m = VTABLE_elements(interp, mro);
         for (j = 0; j < m; ++j) {
-            PMC *cl = VTABLE_get_pmc_keyed_int(interp, mro, j);
+            const PMC * const cl = VTABLE_get_pmc_keyed_int(interp, mro, j);
             if (cl->vtable->base_type == type_sig)
                 break;
             ++dist;
@@ -1317,12 +1306,12 @@
 static void
 mmd_sort_candidates(Interp *interp, PMC *arg_tuple, PMC *cl)
 {
-    INTVAL i, n, d;
-    PMC *nci, *pmc, *sort;
+    INTVAL i;
+    PMC *nci;
     INTVAL *helper;
     PMC **data;
 
-    n = VTABLE_elements(interp, cl);
+    const INTVAL n = VTABLE_elements(interp, cl);
     /*
      * create a helper structure:
      * bits 0..15  = distance
@@ -1330,12 +1319,12 @@
      *
      * TODO use half of available INTVAL bits
      */
-    sort = pmc_new(interp, enum_class_FixedIntegerArray);
+    PMC * const sort = pmc_new(interp, enum_class_FixedIntegerArray);
     VTABLE_set_integer_native(interp, sort, n);
     helper = (INTVAL *)PMC_data(sort);
     for (i = 0; i < n; ++i) {
-        pmc = VTABLE_get_pmc_keyed_int(interp, cl, i);
-        d = mmd_distance(interp, pmc, arg_tuple);
+        PMC * const pmc = VTABLE_get_pmc_keyed_int(interp, cl, i);
+        const INTVAL d = mmd_distance(interp, pmc, arg_tuple);
         helper[i] = i << 16 | (d & 0xffff);
     }
     /*
@@ -1353,7 +1342,7 @@
      */
     data = (PMC **)PMC_data(cl);
     for (i = 0; i < n; ++i) {
-        INTVAL idx = helper[i] >> 16;
+        const INTVAL idx = helper[i] >> 16;
         /*
          * if the distance is big stop
          */
@@ -1384,12 +1373,9 @@
 static PMC*
 mmd_search_scopes(Interp *interp, STRING *meth, PMC *arg_tuple)
 {
-    PMC *candidate_list;
-    int stop;
-
-    candidate_list = pmc_new(interp, enum_class_ResizablePMCArray);
+    PMC * const candidate_list = pmc_new(interp, enum_class_ResizablePMCArray);
 
-    stop = mmd_search_cur_namespace(interp, meth, arg_tuple, candidate_list);
+    const int stop = mmd_search_cur_namespace(interp, meth, arg_tuple, 
candidate_list);
     if (stop)
         return candidate_list;
     mmd_search_builtin(interp, meth, arg_tuple, candidate_list);
@@ -1437,11 +1423,10 @@
 static int
 mmd_maybe_candidate(Interp *interp, PMC *pmc, PMC *arg_tuple, PMC *cl)
 {
-    STRING *_sub, *_multi_sub;
     INTVAL i, n;
 
-    _sub = CONST_STRING(interp, "Sub");
-    _multi_sub = CONST_STRING(interp, "MultiSub");
+    STRING * const _sub = CONST_STRING(interp, "Sub");
+    STRING * const _multi_sub = CONST_STRING(interp, "MultiSub");
 
     if (VTABLE_isa(interp, pmc, _sub)) {
         /* a plain sub stops outer searches */
@@ -1482,14 +1467,9 @@
 static int
 mmd_search_cur_namespace(Interp *interp, STRING *meth, PMC *arg_tuple, PMC *cl)
 {
-    PMC *pmc;
+    PMC * const pmc = Parrot_find_global_cur(interp, meth);
 
-    pmc = Parrot_find_global_cur(interp, meth);
-    if (pmc) {
-        if (mmd_maybe_candidate(interp, pmc, arg_tuple, cl))
-            return 1;
-    }
-    return 0;
+    return pmc && mmd_maybe_candidate(interp, pmc, arg_tuple, cl);
 }
 
 /*
@@ -1507,11 +1487,8 @@
 static PMC*
 mmd_get_ns(Interp *interp)
 {
-    STRING *ns_name;
-    PMC *ns;
-
-    ns_name = CONST_STRING(interp, "__parrot_core");
-    ns = Parrot_get_namespace_keyed_str(interp,
+    STRING * const ns_name = CONST_STRING(interp, "__parrot_core");
+    PMC * const ns = Parrot_get_namespace_keyed_str(interp,
                                         interp->root_namespace, ns_name);
     return ns;
 }
@@ -1519,11 +1496,8 @@
 static PMC*
 mmd_make_ns(Interp *interp)
 {
-    STRING *ns_name;
-    PMC *ns;
-
-    ns_name = CONST_STRING(interp, "__parrot_core");
-    ns = Parrot_make_namespace_keyed_str(interp,
+    STRING * const ns_name = CONST_STRING(interp, "__parrot_core");
+    PMC * const ns = Parrot_make_namespace_keyed_str(interp,
                                          interp->root_namespace, ns_name);
     return ns;
 }
@@ -1531,9 +1505,8 @@
 static void
 mmd_search_builtin(Interp *interp, STRING *meth, PMC *arg_tuple, PMC *cl)
 {
-    PMC *pmc, *ns;
-    ns = mmd_get_ns(interp);
-    pmc = Parrot_find_global_n(interp, ns, meth);
+    PMC * const ns = mmd_get_ns(interp);
+    PMC * const pmc = Parrot_find_global_n(interp, ns, meth);
     if (pmc)
         mmd_maybe_candidate(interp, pmc, arg_tuple, cl);
 }
@@ -1542,14 +1515,11 @@
 static PMC *
 mmd_create_builtin_multi_stub(Interp *interp, PMC* ns, INTVAL func_nr)
 {
-    const char *name;
-    STRING *s;
-    PMC *multi;
-
-    name = Parrot_MMD_method_name(interp, func_nr);
+    const char * name = Parrot_MMD_method_name(interp, func_nr);
     /* create in constant pool */
-    s = const_string(interp, name);
-    multi = constant_pmc_new(interp, enum_class_MultiSub);
+    STRING * const s = const_string(interp, name);
+    PMC * multi = constant_pmc_new(interp, enum_class_MultiSub);
+
     VTABLE_set_pmc_keyed_str(interp, ns, s, multi);
     return ns;
 }
@@ -1666,12 +1636,10 @@
 Parrot_mmd_register_table(Interp* interp, INTVAL type,
         const MMD_init *mmd_table, INTVAL n)
 {
+    MMD_table * const table = interp->binop_mmd_funcs;
+    PMC * const ns = mmd_make_ns(interp);
     INTVAL i;
-    MMD_table *table;
-    PMC *ns;
 
-    table = interp->binop_mmd_funcs;
-    ns = mmd_make_ns(interp);
     if ((INTVAL)table->x < type && type < enum_class_core_max) {
         /*
          * pre-allocate the function table

Modified: trunk/src/pmc/env.pmc
==============================================================================
--- trunk/src/pmc/env.pmc       (original)
+++ trunk/src/pmc/env.pmc       Thu May 31 18:29:41 2007
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
 $Id$
 
 =head1 NAME
@@ -88,7 +88,8 @@
 
     INTVAL elements() {
         INTVAL rv = 0;
-        while (environ[rv] != NULL) { rv++; }
+        while (environ[rv] != NULL)
+            rv++;
         return rv;
     }
 
@@ -130,9 +131,7 @@
 */
 
     STRING* get_string_keyed(PMC* key) {
-        int free_it = 0;
         STRING *retval;
-        char *keyname, *envp, *p, *val = NULL;
 
         switch (PObj_get_FLAGS(key) & KEY_type_FLAGS) {
             case KEY_integer_FLAG:
@@ -140,29 +139,26 @@
                     retval = string_from_cstring(interp, "", 0);
                 }
                 else {
-                    envp = environ[PMC_int_val(key)];
-                    p = strchr(envp, '=');
+                    const char * const envp = environ[PMC_int_val(key)];
+                    const char * const p = strchr(envp, '=');
                     retval = string_from_cstring(interp, envp, (p-envp));
                 }
                 break;
-            default:
-                keyname = string_to_cstring(interp,
+            default: {
+                char * const keyname = string_to_cstring(interp,
                     VTABLE_get_string(interp, key));
+                char *val = NULL;
+                int free_it = 0;
+
                 if (keyname) {
                     val = Parrot_getenv(keyname, &free_it);
                     string_cstring_free(keyname);
-                    if (val) {
-                        retval = string_from_cstring(interp, val, 0);
-                    }
-                    else {
-                        retval = string_from_cstring(interp, "", 0);
-                    }
-                }
-                else {
-                    retval = string_from_cstring(interp, "", 0);
                 }
-                if (free_it && val) mem_sys_free(val);
+                retval = string_from_cstring(interp, val ? val : "", 0);
+                if (free_it && val)
+                    mem_sys_free(val);
                 break;
+            }
         }
         return retval;
     }
@@ -178,7 +174,7 @@
 */
 
     PMC* get_pmc_keyed(PMC* key) {
-        char *keyname = string_to_cstring(INTERP,
+        char * const keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
         int free_it = 0;
         STRING *retval;
@@ -188,17 +184,10 @@
         if (keyname) {
             val = Parrot_getenv(keyname, &free_it);
             string_cstring_free(keyname);
-            if (val) {
-                retval = string_from_cstring(INTERP, val, 0);
-            }
-            else {
-                retval = string_from_cstring(INTERP, "", 0);
-            }
         }
-        else {
-            retval = string_from_cstring(INTERP, "", 0);
-        }
-        if (free_it && val) mem_sys_free(val);
+        retval = string_from_cstring(INTERP, val ? val : "", 0);
+        if (free_it && val)
+            mem_sys_free(val);
         return_pmc = pmc_new(INTERP, enum_class_String);
         VTABLE_set_string_native(INTERP, return_pmc, retval);
         return return_pmc;
@@ -215,9 +204,9 @@
 */
 
     void set_string_keyed(PMC* key, STRING* value) {
-        char *keyname = string_to_cstring(INTERP,
+        char * const keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
-        char *env_val = string_to_cstring(INTERP, value);
+        char * const env_val = string_to_cstring(INTERP, value);
 
         if (keyname && env_val)
             Parrot_setenv(keyname, env_val);
@@ -241,10 +230,10 @@
 */
 
     void set_pmc_keyed(PMC* key, PMC* value) {
-        char *keyname     = string_to_cstring(INTERP,
+        char * const keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
-        STRING *str_value = VTABLE_get_string(INTERP, value);
-        char   *env_val   = string_to_cstring(INTERP, str_value);
+        const STRING * const str_value = VTABLE_get_string(INTERP, value);
+        char * const env_val   = string_to_cstring(INTERP, str_value);
 
         if (keyname && env_val)
             Parrot_setenv(keyname, env_val);
@@ -267,15 +256,16 @@
 */
 
     INTVAL exists_keyed(PMC* key) {
-        char *keyname = string_to_cstring(INTERP,
+        char * const keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
-        int free_it;
 
         if (keyname) {
-            char *val = Parrot_getenv(keyname, &free_it);
+            int free_it;
+            char * const val = Parrot_getenv(keyname, &free_it);
             string_cstring_free(keyname);
             if (val) {
-                if (free_it) mem_sys_free(val);
+                if (free_it)
+                    mem_sys_free(val);
                 return 1;
             }
         }
@@ -294,14 +284,15 @@
 */
 
     void delete_keyed(PMC* key) {
-        char *keyname = string_to_cstring(INTERP,
+        char * const keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
         int free_it;
 
         if (keyname) {
-            char *val = Parrot_getenv(keyname, &free_it);
+            char * const val = Parrot_getenv(keyname, &free_it);
             if (val) {
-                if (free_it) mem_sys_free(val);
+                if (free_it)
+                    mem_sys_free(val);
                 Parrot_unsetenv(keyname);
             }
             string_cstring_free(keyname);

Reply via email to