diff options
author | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:53:14 +0000 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:53:14 +0000 |
commit | c32079c5744c3e04e8ad816060f8e1eb8d9c9d66 (patch) | |
tree | 0d6fb510fbc039d6c5a1173ca40fcaa97632aa46 | |
parent | 19623cd392e1d68e27432f8ed664b506b78ce507 (diff) |
Import Upstream version 20120707
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | acinclude.m4 | 4 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | interpreter/Makefile.am | 60 | ||||
-rw-r--r-- | interpreter/icscanner.l | 30 | ||||
-rw-r--r-- | interpreter/lookup_symbols.c | 13 | ||||
-rw-r--r-- | interpreter/signals.c | 4 | ||||
-rw-r--r-- | interpreter/util/fauhdlstring.c | 27 | ||||
-rw-r--r-- | interpreter/util/fauhdlstring.h | 24 | ||||
-rw-r--r-- | interpreter/util/slset.c | 18 | ||||
-rw-r--r-- | interpreter/util/slset.h | 10 | ||||
-rw-r--r-- | lib/runtime.h | 8 | ||||
-rwxr-xr-x | tests/run-tests.py | 10 |
13 files changed, 148 insertions, 66 deletions
@@ -1,3 +1,7 @@ +2012/06/05 Stefan Potyra <sistpoty@ubuntu.com>: + * interpreter: Consistently use memory allocator / deallocator + callbacks. + 2011/08/12 Stefan Potyra <sistpoty@ubuntu.com>: * backend: Work in progress: Experimental C-backend. Not working yet. * intermediate code: ABI change: move types to separate section. diff --git a/acinclude.m4 b/acinclude.m4 index 72ca103..1ad2b53 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -6,7 +6,7 @@ AC_DEFUN([AC_PROG_CXX_OPTION], [ AC_MSG_CHECKING([whether $CXX supports $1]) ac_save_CXX="$CXX" CXX="$CXX $1" - AC_COMPILE_IFELSE(AC_LANG_PROGRAM(),[ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],[ AC_MSG_RESULT([yes]) ifelse($2, , [], [ CXX="$ac_save_CXX" @@ -26,7 +26,7 @@ AC_DEFUN([AC_PROG_CC_OPTION], [ AC_MSG_CHECKING([whether $CC supports $1]) ac_save_CC="$CC" CC="$CC $1" - AC_COMPILE_IFELSE(AC_LANG_PROGRAM(),[ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],[ AC_MSG_RESULT([yes]) ifelse($2, , [], [ CC="$ac_save_CC" diff --git a/configure.ac b/configure.ac index a881e66..8cc5dd8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # $Id: configure.ac 5078 2010-12-17 14:25:10Z potyra $ -AC_INIT(fauhdlc, 20110812) +AC_INIT(fauhdlc, 20120707) # don't spam / AC_CONFIG_AUX_DIR(scripts) AM_INIT_AUTOMAKE diff --git a/interpreter/Makefile.am b/interpreter/Makefile.am index 41cc5a8..ea2bfc9 100644 --- a/interpreter/Makefile.am +++ b/interpreter/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am 4909 2009-12-11 15:37:52Z potyra $ +# $Id: Makefile.am 5106 2012-02-17 21:09:23Z potyra $ INCLUDES=-I$(srcdir)/glue -I$(srcdir)/util -I$(top_srcdir)/util -I$(top_srcdir) @@ -10,34 +10,36 @@ CLEANFILES=icparser.h icparser.c icscanner.c bin_PROGRAMS=fauhdli lib_LIBRARIES=libfauhdli.a -libfauhdli_a_SOURCES=\ - icparser.y\ - icscanner.l\ - fauhdli.c\ - kernel.c\ - signals.c\ - vhdl_sched.c\ - lookup_symbols.c\ - trace.c\ - log.c\ - util/list.c\ - util/slset.c\ - ../util/mangle_names.c\ - glue/glue-log.c\ - glue/glue-main.c\ - \ - glue/glue-log.h\ - glue/glue-main.h\ - glue/glue-vhdl.h\ - icparser.h\ - kernel.h\ - fauhdli_private.h\ - log.h\ - lookup_symbols.h\ - signals.h\ - trace.h\ - util/list.h\ - util/slset.h\ +libfauhdli_a_SOURCES= \ + icparser.y \ + icscanner.l \ + fauhdli.c \ + kernel.c \ + signals.c \ + vhdl_sched.c \ + lookup_symbols.c \ + trace.c \ + log.c \ + util/fauhdlstring.c \ + util/list.c \ + util/slset.c \ + ../util/mangle_names.c \ + glue/glue-log.c \ + glue/glue-main.c \ + \ + glue/glue-log.h \ + glue/glue-main.h \ + glue/glue-vhdl.h \ + icparser.h \ + kernel.h \ + fauhdli_private.h \ + log.h \ + lookup_symbols.h \ + signals.h \ + trace.h \ + util/fauhdlstring.h \ + util/list.h \ + util/slset.h \ vhdl_sched.h include_HEADERS=\ diff --git a/interpreter/icscanner.l b/interpreter/icscanner.l index 759b18f..9e08add 100644 --- a/interpreter/icscanner.l +++ b/interpreter/icscanner.l @@ -1,5 +1,5 @@ -/* $Id: icscanner.l 4964 2010-10-18 12:55:39Z potyra $ - * vim:tabstop=8:shiftwidth=8:textwidth=72:encoding=utf8: +/* $Id: icscanner.l 5107 2012-02-17 21:12:33Z potyra $ + * vim:tabstop=8 shiftwidth=8 textwidth=72: * Scanner for intermediate code. * * Copyright (C) 2008-2009 FAUmachine Team <info@faumachine.org>. @@ -28,6 +28,7 @@ #include "fauhdli_private.h" #include "icparser.h" #include "glue-log.h" +#include "fauhdlstring.h" #define YY_DECL \ int yylex(\ @@ -77,13 +78,13 @@ a_spec {a_spec_int}|{a_spec_string} return t_AnnotateEqSym; } <ANNOTATION_SPEC>{a_name} { - yylval.text = strdup(yytext); - assert(yylval.text != NULL); + yylval.text = fauhdlstrdup(yytext, + instance->callbacks.malloc); return t_AnnotateName; } <ANNOTATION_SPEC>{a_string} { - yylval.text = strdup(&yytext[1]); - assert(yylval.text != NULL); + yylval.text = fauhdlstrdup(&yytext[1], + instance->callbacks.malloc); yylval.text[strlen(yylval.text) - 1] = '\0'; BEGIN(ANNOTATION); return t_AnnotateString; @@ -156,19 +157,19 @@ log { return t_LOG; } {register} { yylval.number = atol(&yytext[5]); return t_Register; } -{label} { yylval.text = strdup(yytext); - assert(yylval.text != NULL); +{label} { yylval.text = fauhdlstrdup(yytext, + instance->callbacks.malloc); /* drop trailing ":" */ yylval.text[strlen(yylval.text) - 1] = '\0'; return t_Label; } -{identifier} { yylval.text = strdup(yytext); - assert(yylval.text != NULL); +{identifier} { yylval.text = fauhdlstrdup(yytext, + instance->callbacks.malloc); return t_Identifier; } {reference} { /* remove quotes */ - yylval.text = strdup(&yytext[1]); - assert(yylval.text != NULL); + yylval.text = fauhdlstrdup(&yytext[1], + instance->callbacks.malloc); yylval.text[strlen(yylval.text) - 1] = '\0'; return t_Reference; } @@ -182,8 +183,9 @@ log { return t_LOG; } {pos_number} { yylval.univ_int = atoll(yytext); return t_PosNumber; } -{target} { yylval.text = strdup(&yytext[1]); - assert(yylval.text != NULL); +{target} { + yylval.text = fauhdlstrdup(&yytext[1], + instance->callbacks.malloc); return t_Target; } . { diff --git a/interpreter/lookup_symbols.c b/interpreter/lookup_symbols.c index 271d0c8..2457252 100644 --- a/interpreter/lookup_symbols.c +++ b/interpreter/lookup_symbols.c @@ -1,4 +1,4 @@ -/* $Id: lookup_symbols.c 4974 2010-10-18 17:10:52Z potyra $ +/* $Id: lookup_symbols.c 5108 2012-02-17 21:33:25Z potyra $ * Interpreter library: resolve labels/references. * * Copyright (C) 2008-2009 FAUmachine Team <info@faumachine.org>. @@ -14,6 +14,7 @@ #include <string.h> #include <stdbool.h> #include "glue-log.h" +#include "fauhdlstring.h" #define ARRAY_SIZE(t) (sizeof t / sizeof(t[0])) @@ -739,19 +740,23 @@ symbol_table_register_builtins( .elem_count = 1 }; - univ_int_t.name = strdup("universal_integer"); + /* FIXME we don't want to free these (const problem). */ + univ_int_t.name = fauhdlstrdup("universal_integer", + instance->callbacks.malloc); slset_add( instance->cleanup_ptrs, univ_int_t.name, symtab->callbacks->malloc); - univ_real_t.name = strdup("universal_real"); + univ_real_t.name = fauhdlstrdup("universal_real", + instance->callbacks.malloc); slset_add( instance->cleanup_ptrs, univ_real_t.name, symtab->callbacks->malloc); - base_pointer_t.name = strdup("__pointer__"); + base_pointer_t.name = fauhdlstrdup("__pointer__", + instance->callbacks.malloc); slset_add( instance->cleanup_ptrs, base_pointer_t.name, diff --git a/interpreter/signals.c b/interpreter/signals.c index 32a61c6..6f7017f 100644 --- a/interpreter/signals.c +++ b/interpreter/signals.c @@ -1,4 +1,4 @@ -/* $Id: signals.c 5075 2010-11-19 11:23:59Z potyra $ +/* $Id: signals.c 5110 2012-03-08 22:24:17Z potyra $ * * Signal/Driver handling related functions. * @@ -142,7 +142,7 @@ driver_update( t->sim_time = sim_time; t->val = val; - slset_truncate_at(driver->transactions, t, true); + slset_truncate_at(driver->transactions, t, true, callbacks->free); slset_add(driver->transactions, t, callbacks->malloc); } diff --git a/interpreter/util/fauhdlstring.c b/interpreter/util/fauhdlstring.c new file mode 100644 index 0000000..693fbc2 --- /dev/null +++ b/interpreter/util/fauhdlstring.c @@ -0,0 +1,27 @@ +/* $Id: fauhdlstring.c 5105 2012-02-17 21:08:43Z potyra $ + * + * Helper functions for strings. + * + * Copyright (C) 2012 FAUmachine Team <info@faumachine.org>. + * This program is free software. You can redistribute it and/or modify it + * under the terms of the GNU General Public License, either version 2 of + * the License, or (at your option) any later version. See COPYING. + */ + +#include "fauhdlstring.h" +#include <assert.h> +#include <string.h> + +char * +fauhdlstrdup(const char *src, void *(allocator)(size_t)) +{ + char *ret = NULL; + size_t len = strlen(src) + 1; + + ret = allocator(len); + assert(ret != NULL); + + memcpy(ret, src, len); + + return ret; +} diff --git a/interpreter/util/fauhdlstring.h b/interpreter/util/fauhdlstring.h new file mode 100644 index 0000000..46a0f33 --- /dev/null +++ b/interpreter/util/fauhdlstring.h @@ -0,0 +1,24 @@ +/* $Id: fauhdlstring.h 5105 2012-02-17 21:08:43Z potyra $ + * + * Helper functions for strings. + * + * Copyright (C) 2012 FAUmachine Team <info@faumachine.org>. + * This program is free software. You can redistribute it and/or modify it + * under the terms of the GNU General Public License, either version 2 of + * the License, or (at your option) any later version. See COPYING. + */ + + +#ifndef __FAUHDLSTRING_H +#define __FAUHDLSTRING_H + +#include <stdlib.h> + +/** duplicate string src using allocator to obtain memory. + * @param src null-terminated string to duplicate. + * @param allocator memory allocator (e.g. malloc). + * @return duplicated string. + */ +extern char *fauhdlstrdup(const char *src, void *(*allocator)(size_t)); + +#endif /* ! __FAUHDLSTRING_H */ diff --git a/interpreter/util/slset.c b/interpreter/util/slset.c index 1d1af9a..669afb1 100644 --- a/interpreter/util/slset.c +++ b/interpreter/util/slset.c @@ -1,4 +1,4 @@ -/* $Id: slset.c 4800 2009-10-02 13:36:20Z potyra $ +/* $Id: slset.c 5111 2012-03-08 22:26:15Z potyra $ * * Tiny implementation of a single linked set. * @@ -9,7 +9,6 @@ */ #include "slset.h" -#include <stdlib.h> #include <assert.h> #include <stdbool.h> #include <stdio.h> @@ -31,7 +30,7 @@ extern char _init; } #else /* ! DEBUG_MEM_FUNC */ -#define CHECK_FUNC_ADDR(fun_ptr) +#define CHECK_FUNC_ADDR(fun_ptr) /* nothing */ #endif /* DEBUG_MEM_FUNC */ static int @@ -239,7 +238,7 @@ slset_remove(struct slset *s, const void *data, void (*deallocator)(void *)) if (prev == i) { /* first element */ s->first = prev->next; - free(i); + deallocator(i); return; } @@ -272,7 +271,12 @@ slset_clear(struct slset *s, void (*deallocator)(void *)) } void -slset_truncate_at(struct slset *s, const void *data, bool del_data) +slset_truncate_at( + struct slset *s, + const void *data, + bool del_data, + void (*deallocator)(void *) +) { struct slset_entry *i; struct slset_entry *prev = NULL; @@ -305,10 +309,10 @@ slset_truncate_at(struct slset *s, const void *data, bool del_data) i = i->next; if (del_data) { - free(prev->data); + deallocator(prev->data); } - free(prev); + deallocator(prev); } } diff --git a/interpreter/util/slset.h b/interpreter/util/slset.h index 076d7eb..7d3876a 100644 --- a/interpreter/util/slset.h +++ b/interpreter/util/slset.h @@ -1,4 +1,4 @@ -/* $Id: slset.h 4800 2009-10-02 13:36:20Z potyra $ +/* $Id: slset.h 5110 2012-03-08 22:24:17Z potyra $ * * Structure for a single linked set. * @@ -128,9 +128,15 @@ slset_clear(struct slset *s, void (*deallocator)(void *)); * doesn't return -1 from the comparison function with data * as second argument. * @param del_data true, if the truncated data should be freed as well. + * @param deallocator function to free memory (e.g. free) */ extern void -slset_truncate_at(struct slset *s, const void *data, bool del_data); +slset_truncate_at( + struct slset *s, + const void *data, + bool del_data, + void (*deallocator)(void *) +); /** debugging function to print out the set. * @param s set in question. diff --git a/lib/runtime.h b/lib/runtime.h index ff9ad28..d647060 100644 --- a/lib/runtime.h +++ b/lib/runtime.h @@ -1,4 +1,4 @@ -/* $Id: runtime.h 5074 2010-10-28 16:36:05Z potyra $ +/* $Id: runtime.h 5110 2012-03-08 22:24:17Z potyra $ * * C-Code kernel / runtime library. * @@ -154,7 +154,7 @@ driver_update_int_after( t->sim_time = sim_time; t->val.univ_int = value; - slset_truncate_at(drv->transactions, t, true); + slset_truncate_at(drv->transactions, t, true, free); slset_add(drv->transactions, t, malloc); } @@ -171,7 +171,7 @@ driver_update_real_after( t->sim_time = sim_time; t->val.univ_real = value; - slset_truncate_at(drv->transactions, t, true); + slset_truncate_at(drv->transactions, t, true, free); slset_add(drv->transactions, t, malloc); } @@ -192,7 +192,7 @@ sched_create_process( proc->stack_frame = sf; do { ret = pthread_mutex_init(&proc->sleeping, NULL); - assert((ret == 0)|| (ret == EAGAIN)); + assert((ret == 0) || (ret == EAGAIN)); } while (ret == EAGAIN); slset_add(kernel->create_q, proc, malloc); diff --git a/tests/run-tests.py b/tests/run-tests.py index ac705ca..bfc5f67 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# $Id: run-tests.py 4325 2009-01-27 14:02:16Z potyra $ +# $Id: run-tests.py 5104 2012-02-17 21:07:47Z potyra $ # Run the test suite. # @@ -102,6 +102,9 @@ class InterpreteTC: ferr = file(self._get_file_name("err.out"), "w") if InterpreteTC.canUseValgrind(): + # Use the next lines for deep memory debugging. + #cmd = ["valgrind", "--leak-check=full", + # "--show-reachable=yes"] cmd = ["valgrind"] else: cmd = [] @@ -129,6 +132,11 @@ class InterpreteTC: fout = file(self._get_file_name("std.out"), "r") lines = ferr.readlines() ferr.close() + if InterpreteTC.canUseValgrind(): + # write valgrind info to separate file + vout = file(self._get_file_name("valgrind.err.out"), "w") + vout.writelines(lines) + vout.close() sim_fin_seen = False have_critical_errs = False have_mem_errors = False |