[PATCH]: Add ggc_free to ggc-zone

Daniel Berlin dberlin@dberlin.org
Fri Jan 30 22:44:00 GMT 2004


Bootstrapped and regtested on i686-pc-linux-gnu

Index: ggc-zone.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-zone.c,v
retrieving revision 2.12
diff -u -3 -p -r2.12 ggc-zone.c
--- ggc-zone.c  21 Jan 2004 20:40:02 -0000      2.12
+++ ggc-zone.c  30 Jan 2004 22:38:46 -0000
@@ -734,6 +735,28 @@ ggc_alloc_zone (size_t size, struct allo
    return ggc_alloc_zone_1 (size, zone, -1);
  }

+/* Poison the chunk.  */
+#ifdef ENABLE_GC_CHECKING
+#define poison_chunk(CHUNK, SIZE) \
+  memset ((CHUNK)->u.data, 0xa5, (SIZE))
+#else
+#define poison_chunk(CHUNK, SIZE)
+#endif
+void
+ggc_free (void *p)
+{
+  struct alloc_chunk *chunk;
+
+  chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
+#ifdef ENABLE_GC_CHECKING
+  /* Poison the chunk.  */
+  poison_chunk (chunk, ggc_get_size (p));
+#endif
+  if (chunk->large)
+    free (p);
+  else
+    free_chunk (chunk, ggc_get_size (p), &main_zone);
+}
  /* If P is not marked, mark it and return false.  Otherwise return 
true.
     P must have been allocated by the GC allocator; it mustn't point to
     static objects, stack variables, or memory allocated with malloc.  
*/
@@ -931,13 +954,6 @@ ggc_pop_context (void)
    for (zone = G.zones; zone; zone = zone->next_zone)
      ggc_pop_context_1 (zone);
  }
-/* Poison the chunk.  */
-#ifdef ENABLE_GC_CHECKING
-#define poison_chunk(CHUNK, SIZE) \
-  memset ((CHUNK)->u.data, 0xa5, (SIZE))
-#else
-#define poison_chunk(CHUNK, SIZE)
-#endif

  /* Free all empty pages and objects within a page for a given zone  */
  



More information about the Gcc-patches mailing list