Author: chromatic
Date: Tue Jun  5 19:12:10 2007
New Revision: 18832

Modified:
   trunk/src/gc/register.c
   trunk/src/objects.c
   trunk/src/stm/waitlist.c
   trunk/src/vtables.c

Changes in other areas also in this revision:
Modified:
   trunk/docs/pdds/pdd07_codingstd.pod

Log:
[GC] Use more mem_sys_*_zeroed (Mehmet Yavuz Selim Soyturk).

Document their assumptions about '\0' == NULL (Bernhard Schmalhofer).

See RT #43105.

Modified: trunk/src/gc/register.c
==============================================================================
--- trunk/src/gc/register.c     (original)
+++ trunk/src/gc/register.c     Tue Jun  5 19:12:10 2007
@@ -141,7 +141,6 @@
 void
 create_initial_context(Interp *interp)
 {
-    int i;
     static INTVAL num_regs[] ={32,32,32,32};
 
     /* Create some initial free_list slots. */
@@ -149,10 +148,8 @@
 #define INITIAL_FREE_SLOTS 8
     interp->ctx_mem.n_free_slots = INITIAL_FREE_SLOTS;
     interp->ctx_mem.free_list    =
-        (void **)mem_sys_allocate(INITIAL_FREE_SLOTS * sizeof (void *));
+        (void **)mem_sys_allocate_zeroed(INITIAL_FREE_SLOTS * sizeof (void *));
 
-    for (i = 0; i < INITIAL_FREE_SLOTS; ++i)
-        interp->ctx_mem.free_list[i] = NULL;
     /*
      * For now create context with 32 regs each. Some src tests (and maybe 
other
      * extenders) are assuming the presence of these registers

Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Tue Jun  5 19:12:10 2007
@@ -1317,7 +1317,7 @@
 PMC *
 Parrot_find_method_with_cache(Interp *interp, PMC *_class, STRING *method_name 
/*NN*/)
 {
-    UINTVAL type, bits, i;
+    UINTVAL type, bits;
 
     Caches           *mc;
     Meth_cache_entry *e, *old;
@@ -1337,26 +1337,20 @@
 
     if (type >= mc->mc_size) {
         if (mc->idx) {
-            mc->idx = (Meth_cache_entry ***)mem_sys_realloc(mc->idx,
-                sizeof (Meth_cache_entry ***) * (type + 1));
+            mc->idx = (Meth_cache_entry ***)mem_sys_realloc_zeroed(mc->idx,
+                sizeof (Meth_cache_entry ***) * (type + 1),
+                sizeof (Meth_cache_entry ***) * mc->mc_size);
         }
         else {
-            mc->idx = (Meth_cache_entry ***)mem_sys_allocate(
+            mc->idx = (Meth_cache_entry ***)mem_sys_allocate_zeroed(
                 sizeof (Meth_cache_entry ***) * (type + 1));
         }
-
-        for (i = mc->mc_size; i <= type; ++i)
-            mc->idx[i] = NULL;
-
         mc->mc_size = type + 1;
     }
 
     if (!mc->idx[type]) {
-        mc->idx[type] = (Meth_cache_entry **)mem_sys_allocate(
+        mc->idx[type] = (Meth_cache_entry **)mem_sys_allocate_zeroed(
             sizeof (Meth_cache_entry *) * TBL_SIZE);
-
-        for (i = 0; i < TBL_SIZE; ++i)
-            mc->idx[type][i] = NULL;
     }
 
     e   = mc->idx[type][bits];

Modified: trunk/src/stm/waitlist.c
==============================================================================
--- trunk/src/stm/waitlist.c    (original)
+++ trunk/src/stm/waitlist.c    Tue Jun  5 19:12:10 2007
@@ -41,12 +41,9 @@
     }
 
     if (thr->used_entries >= thr->entry_count) {
-        size_t i;
-        thr->entries = mem_sys_realloc(thr->entries,
-            sizeof (*thr->entries) * thr->entry_count * 2);
-        for (i = thr->entry_count; i < thr->entry_count * 2; ++i) {
-            thr->entries[i] = NULL;
-        }
+        thr->entries = mem_sys_realloc_zeroed(thr->entries,
+            sizeof (*thr->entries) * thr->entry_count * 2,
+            sizeof (*thr->entries) * thr->entry_count);
         thr->entry_count *= 2;
     }
 

Modified: trunk/src/vtables.c
==============================================================================
--- trunk/src/vtables.c (original)
+++ trunk/src/vtables.c Tue Jun  5 19:12:10 2007
@@ -90,13 +90,9 @@
        table and we could get bigger without blowing much memory
        */
     const INTVAL new_max = interp->n_vtable_alloced + 16;
-    const INTVAL new_size = new_max * sizeof (VTABLE *);
-    INTVAL i;
-    interp->vtables = (VTABLE **)mem_sys_realloc(interp->vtables, new_size);
-    /* Should set all the empty slots to the null PMC's
-       vtable pointer */
-    for (i = interp->n_vtable_max; i < new_max; ++i)
-        interp->vtables[i] = NULL;
+    const INTVAL new_size = new_max              * sizeof (VTABLE *);
+    const INTVAL old_size = interp->n_vtable_max * sizeof (VTABLE *);
+    interp->vtables = (VTABLE **)mem_sys_realloc_zeroed(interp->vtables, 
new_size, old_size);
     interp->n_vtable_alloced = new_max;
 }
 

Reply via email to