diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | NEWS | 48 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | libguile/ChangeLog | 11 | ||||
-rw-r--r-- | libguile/gc-malloc.c | 43 | ||||
-rw-r--r-- | libguile/gc.h | 1 | ||||
-rw-r--r-- | libguile/ports.c | 4 | ||||
-rw-r--r-- | libguile/read.c | 77 |
8 files changed, 126 insertions, 63 deletions
@@ -1,3 +1,7 @@ +2002-08-05 Han-Wen Nienhuys <hanwen@cs.uu.nl> + + * configure.in: add snprintf + 2002-08-04 Han-Wen <hanwen@cs.uu.nl> * NEWS: add entries for GC and vector WB. @@ -8,29 +8,6 @@ Changes since the stable branch: * Changes to the standalone interpreter -** SCM_VELTS macros is now read-only. For writing, use the new macros -SCM_WRITABLE_VELTS, SCM_SET_VECTOR_LENGTH. The use of -SCM_WRITABLE_VELTS is discouraged, though. - -** Garbage collector rewrite. - -The garbage collector is cleaned up a lot, and now uses lazy -sweeping. This is reflected in the output of (gc-stats); since cells -are being freed when they are allocated, the cells-allocated field -stays roughly constant. - -For malloc related triggers, the behavior is changed. It uses the same -heuristic as the cell-triggered collections. It may be tuned with the -environment variables GUILE_MIN_YIELD_MALLOC. This is the percentage -for minimum yield of malloc related triggers; (default: 40) -GUILE_INIT_MALLOC_LIMIT is the trigger for doing a GC. The default is -200 kb. - -Debugging operations for the freelist have been deprecated, along with -the C variables that control garbage collection. The environment -variables GUILE_MAX_SEGMENT_SIZE, GUILE_INIT_SEGMENT_SIZE_2, -GUILE_INIT_SEGMENT_SIZE_1, and GUILE_MIN_YIELD_2 should be used. - ** New command line option `--no-debug'. Specifying `--no-debug' on the command line will keep the debugging @@ -126,6 +103,29 @@ during evaluation, but prior to evaluation. * Changes to the C interface +** The SCM_VELTS macros now returns a read-only vector. For writing, +use the new macros SCM_WRITABLE_VELTS, SCM_SET_VECTOR_LENGTH. The use +of SCM_WRITABLE_VELTS is discouraged, though. + +** Garbage collector rewrite. + +The garbage collector is cleaned up a lot, and now uses lazy +sweeping. This is reflected in the output of (gc-stats); since cells +are being freed when they are allocated, the cells-allocated field +stays roughly constant. + +For malloc related triggers, the behavior is changed. It uses the same +heuristic as the cell-triggered collections. It may be tuned with the +environment variables GUILE_MIN_YIELD_MALLOC. This is the percentage +for minimum yield of malloc related triggers. The default is 40. +GUILE_INIT_MALLOC_LIMIT sets the initial trigger for doing a GC. The +default is 200 kb. + +Debugging operations for the freelist have been deprecated, along with +the C variables that control garbage collection. The environment +variables GUILE_MAX_SEGMENT_SIZE, GUILE_INIT_SEGMENT_SIZE_2, +GUILE_INIT_SEGMENT_SIZE_1, and GUILE_MIN_YIELD_2 should be used. + ** The struct scm_cell has been renamed to scm_t_cell This is in accordance to Guile's naming scheme for types. Note that @@ -143,7 +143,7 @@ The new functions are more symmetrical and do not need cooperation from smob free routines, among other improvements. The new functions are scm_malloc, scm_realloc, scm_strdup, -scm_strndup, scm_gc_malloc, scm_gc_realloc, scm_gc_free, +scm_strndup, scm_gc_malloc, scm_gc_calloc, scm_gc_realloc, scm_gc_free, scm_gc_register_collectable_memory, and scm_gc_unregister_collectable_memory. Refer to the manual for more details and for upgrading instructions. diff --git a/configure.in b/configure.in index 787f2429c..01f1a1b5a 100644 --- a/configure.in +++ b/configure.in @@ -276,6 +276,7 @@ AC_CHECK_FUNCS(gethostbyname) if test $ac_cv_func_gethostbyname = no; then AC_CHECK_LIB(nsl, gethostbyname) fi + AC_CHECK_FUNCS(connect) if test $ac_cv_func_connect = no; then AC_CHECK_LIB(socket, connect) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 0c0c8042f..ccef7d069 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,14 @@ +2002-08-05 Han-Wen Nienhuys <hanwen@cs.uu.nl> + + * read.c (INPUT_ERROR): Prepare for file:line:column error + messages for errors in scm_lreadr() and friends. + +2002-08-04 Han-Wen Nienhuys <hanwen@cs.uu.nl> + + * gc-malloc.c (scm_malloc): use scm_realloc() (simplifies + implementation). + (scm_gc_calloc): new function + 2002-08-04 Han-Wen <hanwen@cs.uu.nl> * ports.c (scm_new_port_table_entry): init port entry to 0 diff --git a/libguile/gc-malloc.c b/libguile/gc-malloc.c index a1d8f2dc8..2720ed8d8 100644 --- a/libguile/gc-malloc.c +++ b/libguile/gc-malloc.c @@ -113,33 +113,6 @@ scm_gc_init_malloc (void) */ void * -scm_malloc (size_t size) -{ - void *ptr; - - if (size == 0) - return NULL; - - SCM_SYSCALL (ptr = malloc (size)); - if (ptr) - return ptr; - - scm_i_sweep_all_segments ("malloc"); - SCM_SYSCALL (ptr = malloc (size)); - if (ptr) - return ptr; - - scm_igc ("malloc"); - scm_i_sweep_all_segments ("malloc/gc"); - - SCM_SYSCALL (ptr = malloc (size)); - if (ptr) - return ptr; - - scm_memory_error ("malloc"); -} - -void * scm_realloc (void *mem, size_t size) { void *ptr; @@ -164,6 +137,13 @@ scm_realloc (void *mem, size_t size) scm_memory_error ("realloc"); } +void * +scm_malloc (size_t sz) +{ + return scm_realloc (NULL, sz); +} + + char * scm_strndup (const char *str, size_t n) { @@ -269,6 +249,15 @@ scm_gc_malloc (size_t size, const char *what) } void * +scm_gc_calloc (size_t size, const char *what) +{ + void *ptr = scm_gc_malloc (size, what); + memset (ptr, 0x0, size); + return ptr; +} + + +void * scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what) { /* XXX - see scm_gc_malloc. */ diff --git a/libguile/gc.h b/libguile/gc.h index 1e688d65a..bce48debd 100644 --- a/libguile/gc.h +++ b/libguile/gc.h @@ -337,6 +337,7 @@ SCM_API void scm_gc_register_collectable_memory (void *mem, size_t size, const char *what); SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what); +SCM_API void *scm_gc_calloc (size_t size, const char *what); SCM_API void *scm_gc_malloc (size_t size, const char *what); SCM_API void *scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what); diff --git a/libguile/ports.c b/libguile/ports.c index 70f402651..b93fa9d8d 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -456,9 +456,7 @@ scm_t_port * scm_new_port_table_entry (void) #define FUNC_NAME "scm_new_port_table_entry" { - scm_t_port *entry = (scm_t_port *) scm_gc_malloc (sizeof (scm_t_port), "port"); - memset (entry, 0x0, sizeof (scm_t_port)); - + scm_t_port *entry = (scm_t_port *) scm_gc_calloc (sizeof (scm_t_port), "port"); if (scm_port_table_size == scm_port_table_room) { /* initial malloc is in gc.c. this doesn't use scm_gc_malloc etc., diff --git a/libguile/read.c b/libguile/read.c index f829cd535..6b85d0fc8 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -75,6 +75,65 @@ scm_t_option scm_read_opts[] = { "Style of keyword recognition: #f or 'prefix."} }; +/* + Give meaningful error messages for errors + + We use the format + + MESSAGE + This happened in .... + + This is not standard GNU format, but the test-suite likes the real + message to be in front. + + Hmmm. + + Maybe this is a kludge? Perhaps we should throw (list EXPR FILENAME + LINENO COLUMNO), and have the exception handler sort out the error + message?Where does the handler live, what are the conventions for + the expression argument of the handler? How does this work for an + error message like + +Backtrace: +In standard input: + 4: 0* [list ... + +standard input:4:1: While evaluating arguments to list in expression (list a b):standard input:4:1: Unbound variable: a +ABORT: (unbound-variable) + + + + In any case, we would have to assemble that information anyway. + */ + + +#if 0 + +#ifndef HAVE_SNPRINTF +#define snprintf sprintf +/* + should warn about buffer overflow? + */ +#endif + +#define INPUT_ERROR(port, message, arg) { \ + char s[1024];\ + int fn_found = SCM_STRINGP (SCM_FILENAME(port));\ + char *fn = "";\ + if (fn_found)\ + fn = SCM_STRING_CHARS(SCM_FILENAME(port));\ + snprintf (s, 1024, "%s\nThis happened in %s%s%s line %d column %d", message, \ + fn_found ? "`" : "", \ + fn,\ + fn_found ? "'" : "", \ + SCM_LINUM(port) + 1, SCM_COL(port) + 1); \ + SCM_MISC_ERROR(s, arg); \ + } +#else +#define INPUT_ERROR(port, message, arg) SCM_MISC_ERROR(message, arg) +#endif + + SCM_DEFINE (scm_read_options, "read-options-interface", 0, 1, 0, (SCM setting), "Option interface for the read options. Instead of using\n" @@ -300,7 +359,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy) ? scm_lreadrecparen (tok_buf, port, s_list, copy) : scm_lreadparen (tok_buf, port, s_list, copy); case ')': - SCM_MISC_ERROR ("unexpected \")\"", SCM_EOL); + INPUT_ERROR(port,"unexpected \")\"", SCM_EOL); goto tryagain; case '\'': @@ -430,7 +489,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy) if (scm_charnames[c] && (scm_casei_streq (scm_charnames[c], SCM_STRING_CHARS (*tok_buf)))) return SCM_MAKE_CHAR (scm_charnums[c]); - SCM_MISC_ERROR ("unknown # object", SCM_EOL); + INPUT_ERROR (port, "unknown # object", SCM_EOL); /* #:SYMBOL is a syntax for keywords supported in all contexts. */ case ':': @@ -460,8 +519,8 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy) } } unkshrp: - scm_misc_error (s_scm_read, "Unknown # object: ~S", - scm_list_1 (SCM_MAKE_CHAR (c))); + INPUT_ERROR (port, "Unknown # object: ~S", + scm_list_1 (SCM_MAKE_CHAR (c))); } case '"': @@ -469,7 +528,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy) while ('"' != (c = scm_getc (port))) { if (c == EOF) - SCM_MISC_ERROR ("end of file in string constant", SCM_EOL); + INPUT_ERROR (port, "end of file in string constant", SCM_EOL); while (j + 2 >= SCM_STRING_LENGTH (*tok_buf)) scm_grow_tok_buf (tok_buf); @@ -531,7 +590,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy) c = SCM_STRING_CHARS (*tok_buf)[1]; goto callshrp; } - SCM_MISC_ERROR ("unknown # object", SCM_EOL); + INPUT_ERROR (port, "unknown # object", SCM_EOL); } goto tok; @@ -662,7 +721,7 @@ scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy) ans = scm_lreadr (tok_buf, port, copy); closeit: if (')' != (c = scm_flush_ws (port, name))) - SCM_MISC_ERROR ("missing close paren", SCM_EOL); + INPUT_ERROR (port, "missing close paren", SCM_EOL); return ans; } ans = tl = scm_cons (tmp, SCM_EOL); @@ -702,7 +761,7 @@ scm_lreadrecparen (SCM *tok_buf, SCM port, char *name, SCM *copy) { ans = scm_lreadr (tok_buf, port, copy); if (')' != (c = scm_flush_ws (port, name))) - SCM_MISC_ERROR ("missing close paren", SCM_EOL); + INPUT_ERROR (port, "missing close paren", SCM_EOL); return ans; } /* Build the head of the list structure. */ @@ -726,7 +785,7 @@ scm_lreadrecparen (SCM *tok_buf, SCM port, char *name, SCM *copy) : tmp, SCM_EOL)); if (')' != (c = scm_flush_ws (port, name))) - SCM_MISC_ERROR ("missing close paren", SCM_EOL); + INPUT_ERROR (port, "missing close paren", SCM_EOL); goto exit; } |