1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 20:30:28 +02:00

(INPUT_ERROR): Prepare for file:line:column error

messages for errors in scm_lreadr() and friends.
This commit is contained in:
Han-Wen Nienhuys 2002-08-04 23:33:28 +00:00
parent f5f45abe9f
commit 39e8f371e2
8 changed files with 126 additions and 63 deletions

View file

@ -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> 2002-08-04 Han-Wen <hanwen@cs.uu.nl>
* NEWS: add entries for GC and vector WB. * NEWS: add entries for GC and vector WB.

48
NEWS
View file

@ -8,29 +8,6 @@ Changes since the stable branch:
* Changes to the standalone interpreter * 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'. ** New command line option `--no-debug'.
Specifying `--no-debug' on the command line will keep the debugging 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 * 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 ** The struct scm_cell has been renamed to scm_t_cell
This is in accordance to Guile's naming scheme for types. Note that 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. from smob free routines, among other improvements.
The new functions are scm_malloc, scm_realloc, scm_strdup, 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_register_collectable_memory, and
scm_gc_unregister_collectable_memory. Refer to the manual for more scm_gc_unregister_collectable_memory. Refer to the manual for more
details and for upgrading instructions. details and for upgrading instructions.

View file

@ -276,6 +276,7 @@ AC_CHECK_FUNCS(gethostbyname)
if test $ac_cv_func_gethostbyname = no; then if test $ac_cv_func_gethostbyname = no; then
AC_CHECK_LIB(nsl, gethostbyname) AC_CHECK_LIB(nsl, gethostbyname)
fi fi
AC_CHECK_FUNCS(connect) AC_CHECK_FUNCS(connect)
if test $ac_cv_func_connect = no; then if test $ac_cv_func_connect = no; then
AC_CHECK_LIB(socket, connect) AC_CHECK_LIB(socket, connect)

View file

@ -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> 2002-08-04 Han-Wen <hanwen@cs.uu.nl>
* ports.c (scm_new_port_table_entry): init port entry to 0 * ports.c (scm_new_port_table_entry): init port entry to 0

View file

@ -112,33 +112,6 @@ scm_gc_init_malloc (void)
/* Function for non-cell memory management. /* Function for non-cell memory management.
*/ */
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 * void *
scm_realloc (void *mem, size_t size) scm_realloc (void *mem, size_t size)
{ {
@ -164,6 +137,13 @@ scm_realloc (void *mem, size_t size)
scm_memory_error ("realloc"); scm_memory_error ("realloc");
} }
void *
scm_malloc (size_t sz)
{
return scm_realloc (NULL, sz);
}
char * char *
scm_strndup (const char *str, size_t n) scm_strndup (const char *str, size_t n)
{ {
@ -268,6 +248,15 @@ scm_gc_malloc (size_t size, const char *what)
return ptr; return ptr;
} }
void *
scm_gc_calloc (size_t size, const char *what)
{
void *ptr = scm_gc_malloc (size, what);
memset (ptr, 0x0, size);
return ptr;
}
void * void *
scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what) scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what)
{ {

View file

@ -337,6 +337,7 @@ SCM_API void scm_gc_register_collectable_memory (void *mem, size_t size,
const char *what); const char *what);
SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size, SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size,
const char *what); 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_malloc (size_t size, const char *what);
SCM_API void *scm_gc_realloc (void *mem, size_t old_size, SCM_API void *scm_gc_realloc (void *mem, size_t old_size,
size_t new_size, const char *what); size_t new_size, const char *what);

View file

@ -456,9 +456,7 @@ scm_t_port *
scm_new_port_table_entry (void) scm_new_port_table_entry (void)
#define FUNC_NAME "scm_new_port_table_entry" #define FUNC_NAME "scm_new_port_table_entry"
{ {
scm_t_port *entry = (scm_t_port *) scm_gc_malloc (sizeof (scm_t_port), "port"); scm_t_port *entry = (scm_t_port *) scm_gc_calloc (sizeof (scm_t_port), "port");
memset (entry, 0x0, sizeof (scm_t_port));
if (scm_port_table_size == scm_port_table_room) if (scm_port_table_size == scm_port_table_room)
{ {
/* initial malloc is in gc.c. this doesn't use scm_gc_malloc etc., /* initial malloc is in gc.c. this doesn't use scm_gc_malloc etc.,

View file

@ -75,6 +75,65 @@ scm_t_option scm_read_opts[] = {
"Style of keyword recognition: #f or 'prefix."} "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_DEFINE (scm_read_options, "read-options-interface", 0, 1, 0,
(SCM setting), (SCM setting),
"Option interface for the read options. Instead of using\n" "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_lreadrecparen (tok_buf, port, s_list, copy)
: scm_lreadparen (tok_buf, port, s_list, copy); : scm_lreadparen (tok_buf, port, s_list, copy);
case ')': case ')':
SCM_MISC_ERROR ("unexpected \")\"", SCM_EOL); INPUT_ERROR(port,"unexpected \")\"", SCM_EOL);
goto tryagain; goto tryagain;
case '\'': case '\'':
@ -430,7 +489,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
if (scm_charnames[c] if (scm_charnames[c]
&& (scm_casei_streq (scm_charnames[c], SCM_STRING_CHARS (*tok_buf)))) && (scm_casei_streq (scm_charnames[c], SCM_STRING_CHARS (*tok_buf))))
return SCM_MAKE_CHAR (scm_charnums[c]); 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. */ /* #:SYMBOL is a syntax for keywords supported in all contexts. */
case ':': case ':':
@ -460,8 +519,8 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
} }
} }
unkshrp: unkshrp:
scm_misc_error (s_scm_read, "Unknown # object: ~S", INPUT_ERROR (port, "Unknown # object: ~S",
scm_list_1 (SCM_MAKE_CHAR (c))); scm_list_1 (SCM_MAKE_CHAR (c)));
} }
case '"': case '"':
@ -469,7 +528,7 @@ scm_lreadr (SCM *tok_buf, SCM port, SCM *copy)
while ('"' != (c = scm_getc (port))) while ('"' != (c = scm_getc (port)))
{ {
if (c == EOF) 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)) while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
scm_grow_tok_buf (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]; c = SCM_STRING_CHARS (*tok_buf)[1];
goto callshrp; goto callshrp;
} }
SCM_MISC_ERROR ("unknown # object", SCM_EOL); INPUT_ERROR (port, "unknown # object", SCM_EOL);
} }
goto tok; goto tok;
@ -662,7 +721,7 @@ scm_lreadparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
ans = scm_lreadr (tok_buf, port, copy); ans = scm_lreadr (tok_buf, port, copy);
closeit: closeit:
if (')' != (c = scm_flush_ws (port, name))) 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; return ans;
} }
ans = tl = scm_cons (tmp, SCM_EOL); 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); ans = scm_lreadr (tok_buf, port, copy);
if (')' != (c = scm_flush_ws (port, name))) 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; return ans;
} }
/* Build the head of the list structure. */ /* Build the head of the list structure. */
@ -726,7 +785,7 @@ scm_lreadrecparen (SCM *tok_buf, SCM port, char *name, SCM *copy)
: tmp, : tmp,
SCM_EOL)); SCM_EOL));
if (')' != (c = scm_flush_ws (port, name))) 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; goto exit;
} }