changeset 481:0f5c38ddf450

Remove MEM_DEBUG and now-useless tcc_free() wrapper. Now, would anyone like to explain what tok_str_free() is for?
author Rob Landley <rob@landley.net>
date Fri, 21 Sep 2007 02:43:28 -0500
parents 995cf196fe69
children 4bf62ce997e7
files tcc.c tcc.h tccasm.c tccelf.c
diffstat 4 files changed, 45 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Thu Sep 20 02:52:04 2007 -0500
+++ b/tcc.c	Fri Sep 21 02:43:28 2007 -0500
@@ -187,31 +187,10 @@
     return 1;
 }
 
-/* memory management */
-#ifdef MEM_DEBUG
-int mem_cur_size;
-int mem_max_size;
-#endif
-
-static inline void tcc_free(void *ptr)
-{
-#ifdef MEM_DEBUG
-    mem_cur_size -= malloc_usable_size(ptr);
-#endif
-    free(ptr);
-}
-
 static void *tcc_malloc(unsigned long size)
 {
-    void *ptr;
-    ptr = malloc(size);
-    if (!ptr && size)
-        error("memory full");
-#ifdef MEM_DEBUG
-    mem_cur_size += malloc_usable_size(ptr);
-    if (mem_cur_size > mem_max_size)
-        mem_max_size = mem_cur_size;
-#endif
+    void *ptr = malloc(size);
+    if (!ptr && size) error("memory full");
     return ptr;
 }
 
@@ -225,17 +204,8 @@
 
 static inline void *tcc_realloc(void *ptr, unsigned long size)
 {
-    void *ptr1;
-#ifdef MEM_DEBUG
-    mem_cur_size -= malloc_usable_size(ptr);
-#endif
-    ptr1 = realloc(ptr, size);
-#ifdef MEM_DEBUG
-    /* NOTE: count not correct if alloc error, but not critical */
-    mem_cur_size += malloc_usable_size(ptr1);
-    if (mem_cur_size > mem_max_size)
-        mem_max_size = mem_cur_size;
-#endif
+    void *ptr1 = realloc(ptr, size);
+    if (!ptr1 && size) error("memory full");
     return ptr1;
 }
 
@@ -247,9 +217,7 @@
     return ptr;
 }
 
-#define free(p) use_tcc_free(p)
 #define malloc(s) use_tcc_malloc(s)
-#define realloc(p, s) use_tcc_realloc(p, s)
 
 static void dynarray_add(void ***ptab, int *nb_ptr, void *data)
 {
@@ -342,8 +310,8 @@
 
 static void free_section(Section *s)
 {
-    tcc_free(s->data);
-    tcc_free(s);
+    free(s->data);
+    free(s);
 }
 
 /* realloc section and set its content to zero */
@@ -748,7 +716,7 @@
 /* free string and reset it to NULL */
 static void cstr_free(CString *cstr)
 {
-    tcc_free(cstr->data_allocated);
+    free(cstr->data_allocated);
     cstr_new(cstr);
 }
 
@@ -1029,7 +997,7 @@
 {
     total_lines += bf->line_num;
     close(bf->fd);
-    tcc_free(bf);
+    free(bf);
 }
 
 /* fill input buffer and peek next char */
@@ -1489,7 +1457,7 @@
 
 static void tok_str_free(int *str)
 {
-    tcc_free(str);
+    free(str);
 }
 
 static int *tok_str_realloc(TokenString *s)
@@ -8649,7 +8617,7 @@
     
     ret = tcc_compile(s);
     
-    tcc_free(buf);
+    free(buf);
 
     /* currently, no need to close */
     return ret;
@@ -8947,8 +8915,8 @@
     /* free tokens */
     n = tok_ident - TOK_IDENT;
     for(i = 0; i < n; i++)
-        tcc_free(table_ident[i]);
-    tcc_free(table_ident);
+        free(table_ident[i]);
+    free(table_ident);
 
     /* free all sections */
 
@@ -8960,32 +8928,32 @@
 
     for(i = 1; i < s1->nb_sections; i++)
         free_section(s1->sections[i]);
-    tcc_free(s1->sections);
+    free(s1->sections);
     
     /* free loaded dlls array */
     for(i = 0; i < s1->nb_loaded_dlls; i++)
-        tcc_free(s1->loaded_dlls[i]);
-    tcc_free(s1->loaded_dlls);
+        free(s1->loaded_dlls[i]);
+    free(s1->loaded_dlls);
 
     /* library paths */
     for(i = 0; i < s1->nb_library_paths; i++)
-        tcc_free(s1->library_paths[i]);
-    tcc_free(s1->library_paths);
+        free(s1->library_paths[i]);
+    free(s1->library_paths);
 
     /* cached includes */
     for(i = 0; i < s1->nb_cached_includes; i++)
-        tcc_free(s1->cached_includes[i]);
-    tcc_free(s1->cached_includes);
+        free(s1->cached_includes[i]);
+    free(s1->cached_includes);
 
     for(i = 0; i < s1->nb_include_paths; i++)
-        tcc_free(s1->include_paths[i]);
-    tcc_free(s1->include_paths);
+        free(s1->include_paths[i]);
+    free(s1->include_paths);
 
     for(i = 0; i < s1->nb_sysinclude_paths; i++)
-        tcc_free(s1->sysinclude_paths[i]);
-    tcc_free(s1->sysinclude_paths);
-
-    tcc_free(s1);
+        free(s1->sysinclude_paths[i]);
+    free(s1->sysinclude_paths);
+
+    free(s1);
 }
 
 int tcc_add_include_path(TCCState *s1, const char *pathname)
@@ -9827,7 +9795,7 @@
     }
 
     /* free all files */
-    tcc_free(files);
+    free(files);
 
     if (do_bench) {
         double total_time;
@@ -9861,11 +9829,6 @@
     if (!do_bounds_check)
         tcc_delete(s);
 
-#ifdef MEM_DEBUG
-    if (do_bench) {
-        printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
-    }
-#endif
     return ret;
 }
 
--- a/tcc.h	Thu Sep 20 02:52:04 2007 -0500
+++ b/tcc.h	Fri Sep 21 02:43:28 2007 -0500
@@ -67,8 +67,6 @@
 /* include file debug */
 //#define INC_DEBUG
 
-//#define MEM_DEBUG
-
 /* assembler debug */
 //#define ASM_DEBUG
 
--- a/tccasm.c	Thu Sep 20 02:52:04 2007 -0500
+++ b/tccasm.c	Fri Sep 21 02:43:28 2007 -0500
@@ -733,7 +733,7 @@
     parse_flags = saved_parse_flags;
     macro_ptr = saved_macro_ptr;
     file = saved_file;
-    tcc_free(bf);
+    free(bf);
 }
 
 /* find a constraint by its number or id (gcc 3 extended
@@ -985,7 +985,7 @@
     for(i=0;i<nb_operands;i++) {
         ASMOperand *op;
         op = &operands[i];
-        tcc_free(op->constraint);
+        free(op->constraint);
         vpop();
     }
     cstr_free(&astr1);
--- a/tccelf.c	Thu Sep 20 02:52:04 2007 -0500
+++ b/tccelf.c	Fri Sep 21 02:43:28 2007 -0500
@@ -361,7 +361,7 @@
     
     /* we copy the new symbols to the old */
     memcpy(s->data, new_syms, nb_syms * sizeof(Elf32_Sym));
-    tcc_free(new_syms);
+    free(new_syms);
 
     /* now we modify all the relocations */
     for(i = 1; i < s1->nb_sections; i++) {
@@ -379,7 +379,7 @@
         }
     }
     
-    tcc_free(old_to_new_syms);
+    free(old_to_new_syms);
 }
 
 /* relocate common symbols in the .bss section */
@@ -1759,10 +1759,10 @@
 
     ret = 0;
  the_end:
-    tcc_free(s1->symtab_to_dynsym);
-    tcc_free(section_order);
-    tcc_free(phdr);
-    tcc_free(s1->got_offsets);
+    free(s1->symtab_to_dynsym);
+    free(section_order);
+    free(phdr);
+    free(s1->got_offsets);
     return ret;
 }
 
@@ -2015,12 +2015,12 @@
     
     ret = 0;
  the_end:
-    tcc_free(symtab);
-    tcc_free(strtab);
-    tcc_free(old_to_new_syms);
-    tcc_free(sm_table);
-    tcc_free(strsec);
-    tcc_free(shdr);
+    free(symtab);
+    free(strtab);
+    free(old_to_new_syms);
+    free(sm_table);
+    free(strsec);
+    free(shdr);
     return ret;
 }
 
@@ -2081,7 +2081,7 @@
     } while(bound);
     ret = 0;
  the_end:
-    tcc_free(data);
+    free(data);
     return ret;
 }
 
@@ -2249,10 +2249,10 @@
     }
     ret = 0;
  the_end:
-    tcc_free(dynstr);
-    tcc_free(dynsym);
-    tcc_free(dynamic);
-    tcc_free(shdr);
+    free(dynstr);
+    free(dynsym);
+    free(dynamic);
+    free(shdr);
     return ret;
 }