[incremental] Patch: FYI: linemap -vs- free
Tom Tromey
tromey@redhat.com
Fri Apr 18 20:12:00 GMT 2008
I'm checking this in on the incremental-compiler branch.
When I added a realloc function to the line map I neglected to add a
free function. This isn't really needed -- gcc proper does not ever
call linemap_free -- but it is good to have internal consistency.
The trunk needs this as well, I'll do it sooner or later.
Tom
libcpp/ChangeLog:
2008-04-18 Tom Tromey <tromey@redhat.com>
* line-map.c (linemap_free): Use free function.
* include/line-map.h (line_map_free): New typedef.
(struct line_maps) <freer>: New field.
gcc/ChangeLog:
2008-04-18 Tom Tromey <tromey@redhat.com>
* toplev.c (free_for_line_map): New function.
(general_init): Use it.
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c (revision 132956)
+++ libcpp/line-map.c (working copy)
@@ -64,9 +64,11 @@
{
if (set->maps)
{
+ line_map_free free_fn = set->freer ? set->freer : free;
+
linemap_check_files_exited (set);
- free (set->maps);
+ (*free_fn) (set->maps);
}
}
Index: libcpp/include/line-map.h
===================================================================
--- libcpp/include/line-map.h (revision 132956)
+++ libcpp/include/line-map.h (working copy)
@@ -1,5 +1,5 @@
/* Map logical line numbers to (source file, line number) pairs.
- Copyright (C) 2001, 2003, 2004, 2007
+ Copyright (C) 2001, 2003, 2004, 2007, 2008
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -42,6 +42,9 @@
/* Memory allocation function typedef. Works like xrealloc. */
typedef void *(*line_map_realloc) (void *, size_t);
+/* Type of function used for freeing memory. Works like free. */
+typedef void (*line_map_free) (void *);
+
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
by the logical START_LOCATION. TO_LINE+L at column C is represented by
START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
@@ -102,6 +105,8 @@
/* If non-null, the allocator to use when resizing 'maps'. If null,
xrealloc is used. */
line_map_realloc reallocator;
+ /* Likewise, used for freeing. */
+ line_map_free freer;
};
/* Initialize a line map set. */
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c (revision 134400)
+++ gcc/toplev.c (working copy)
@@ -1716,6 +1716,13 @@
return ggc_realloc (ptr, len);
}
+/* A helper function used to release memory for cpp's line table. */
+static void
+free_for_line_map (void *mem ATTRIBUTE_UNUSED)
+{
+ /* Do nothing, the GC will handle it. */
+}
+
/* Initialization of the front end environment, before command line
options are parsed. Signal handlers, internationalization etc.
ARGV0 is main's argv[0]. */
@@ -1777,6 +1784,7 @@
line_table = GGC_NEW (struct line_maps);
linemap_init (line_table);
line_table->reallocator = realloc_for_line_map;
+ line_table->freer = free_for_line_map;
linemap_add (line_table, LC_RENAME, 0, 0, _("<built-in>"), 0);
loc = linemap_line_start (line_table, 0, 1);
gcc_assert (loc == BUILTINS_LOCATION);
More information about the Gcc-patches
mailing list