2003-05-03 22:09:20 +00:00
|
|
|
|
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003 Free Software Foundation, Inc.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
*/
|
1999-12-12 02:36:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/_scm.h"
|
|
|
|
|
|
#include "libguile/smob.h"
|
|
|
|
|
|
#include "libguile/alist.h"
|
|
|
|
|
|
#include "libguile/eval.h"
|
|
|
|
|
|
#include "libguile/eq.h"
|
|
|
|
|
|
#include "libguile/dynwind.h"
|
|
|
|
|
|
#include "libguile/backtrace.h"
|
|
|
|
|
|
#include "libguile/debug.h"
|
|
|
|
|
|
#include "libguile/continuations.h"
|
|
|
|
|
|
#include "libguile/stackchk.h"
|
|
|
|
|
|
#include "libguile/stacks.h"
|
|
|
|
|
|
#include "libguile/fluids.h"
|
|
|
|
|
|
#include "libguile/ports.h"
|
2002-01-22 23:31:39 +00:00
|
|
|
|
#include "libguile/lang.h"
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/validate.h"
|
|
|
|
|
|
#include "libguile/throw.h"
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-09-28 00:01:40 +00:00
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
/* the jump buffer data structure */
|
2001-06-14 19:50:43 +00:00
|
|
|
|
static scm_t_bits tc16_jmpbuffer;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-12-08 17:32:56 +00:00
|
|
|
|
#define SCM_JMPBUFP(OBJ) SCM_TYP16_PREDICATE (tc16_jmpbuffer, OBJ)
|
2000-03-09 18:58:58 +00:00
|
|
|
|
|
2000-12-08 17:32:56 +00:00
|
|
|
|
#define JBACTIVE(OBJ) (SCM_CELL_WORD_0 (OBJ) & (1L << 16L))
|
2001-03-30 15:03:23 +00:00
|
|
|
|
#define ACTIVATEJB(x) \
|
|
|
|
|
|
(SCM_SET_CELL_WORD_0 ((x), (SCM_CELL_WORD_0 (x) | (1L << 16L))))
|
|
|
|
|
|
#define DEACTIVATEJB(x) \
|
|
|
|
|
|
(SCM_SET_CELL_WORD_0 ((x), (SCM_CELL_WORD_0 (x) & ~(1L << 16L))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-04-04 12:13:41 +00:00
|
|
|
|
#define JBJMPBUF(OBJ) ((jmp_buf *) SCM_CELL_WORD_1 (OBJ))
|
2002-07-20 14:08:34 +00:00
|
|
|
|
#define SETJBJMPBUF(x, v) (SCM_SET_CELL_WORD_1 ((x), (v)))
|
2001-06-14 19:50:43 +00:00
|
|
|
|
#define SCM_JBDFRAME(x) ((scm_t_debug_frame *) SCM_CELL_WORD_2 (x))
|
2002-07-20 14:08:34 +00:00
|
|
|
|
#define SCM_SETJBDFRAME(x, v) (SCM_SET_CELL_WORD_2 ((x), (v)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
static int
|
2001-06-07 21:12:19 +00:00
|
|
|
|
jmpbuffer_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_puts ("#<jmpbuffer ", port);
|
|
|
|
|
|
scm_puts (JBACTIVE(exp) ? "(active) " : "(inactive) ", port);
|
2000-04-04 12:13:41 +00:00
|
|
|
|
scm_intprint((long) JBJMPBUF (exp), 16, port);
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_putc ('>', port);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
return 1 ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
1999-12-12 02:36:16 +00:00
|
|
|
|
make_jmpbuf (void)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM answer;
|
1996-10-01 03:19:48 +00:00
|
|
|
|
SCM_REDEFER_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
2000-12-08 17:32:56 +00:00
|
|
|
|
SCM_NEWSMOB2 (answer, tc16_jmpbuffer, 0, 0);
|
1996-10-06 22:16:33 +00:00
|
|
|
|
SETJBJMPBUF(answer, (jmp_buf *)0);
|
|
|
|
|
|
DEACTIVATEJB(answer);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
1996-10-01 03:19:48 +00:00
|
|
|
|
SCM_REALLOW_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
return answer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
1997-04-11 03:54:56 +00:00
|
|
|
|
/* scm_internal_catch (the guts of catch) */
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
struct jmp_buf_and_retval /* use only on the stack, in scm_catch */
|
|
|
|
|
|
{
|
|
|
|
|
|
jmp_buf buf; /* must be first */
|
|
|
|
|
|
SCM throw_tag;
|
|
|
|
|
|
SCM retval;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
|
|
|
|
|
/* scm_internal_catch is the guts of catch. It handles all the
|
|
|
|
|
|
mechanics of setting up a catch target, invoking the catch body,
|
|
|
|
|
|
and perhaps invoking the handler if the body does a throw.
|
|
|
|
|
|
|
|
|
|
|
|
The function is designed to be usable from C code, but is general
|
|
|
|
|
|
enough to implement all the semantics Guile Scheme expects from
|
|
|
|
|
|
throw.
|
|
|
|
|
|
|
|
|
|
|
|
TAG is the catch tag. Typically, this is a symbol, but this
|
|
|
|
|
|
function doesn't actually care about that.
|
|
|
|
|
|
|
|
|
|
|
|
BODY is a pointer to a C function which runs the body of the catch;
|
|
|
|
|
|
this is the code you can throw from. We call it like this:
|
2000-03-12 19:58:56 +00:00
|
|
|
|
BODY (BODY_DATA)
|
1996-12-09 02:15:17 +00:00
|
|
|
|
where:
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
BODY_DATA is just the BODY_DATA argument we received; we pass it
|
|
|
|
|
|
through to BODY as its first argument. The caller can make
|
|
|
|
|
|
BODY_DATA point to anything useful that BODY might need.
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
|
|
|
|
|
HANDLER is a pointer to a C function to deal with a throw to TAG,
|
|
|
|
|
|
should one occur. We call it like this:
|
1997-05-14 16:59:16 +00:00
|
|
|
|
HANDLER (HANDLER_DATA, THROWN_TAG, THROW_ARGS)
|
1996-12-09 02:15:17 +00:00
|
|
|
|
where
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
HANDLER_DATA is the HANDLER_DATA argument we recevied; it's the
|
|
|
|
|
|
same idea as BODY_DATA above.
|
1997-05-14 16:59:16 +00:00
|
|
|
|
THROWN_TAG is the tag that the user threw to; usually this is
|
|
|
|
|
|
TAG, but it could be something else if TAG was #t (i.e., a
|
|
|
|
|
|
catch-all), or the user threw to a jmpbuf.
|
1996-12-09 02:15:17 +00:00
|
|
|
|
THROW_ARGS is the list of arguments the user passed to the THROW
|
1997-08-26 23:53:28 +00:00
|
|
|
|
function, after the tag.
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1997-02-07 22:38:20 +00:00
|
|
|
|
BODY_DATA is just a pointer we pass through to BODY. HANDLER_DATA
|
|
|
|
|
|
is just a pointer we pass through to HANDLER. We don't actually
|
|
|
|
|
|
use either of those pointers otherwise ourselves. The idea is
|
|
|
|
|
|
that, if our caller wants to communicate something to BODY or
|
|
|
|
|
|
HANDLER, it can pass a pointer to it as MUMBLE_DATA, which BODY and
|
|
|
|
|
|
HANDLER can then use. Think of it as a way to make BODY and
|
|
|
|
|
|
HANDLER closures, not just functions; MUMBLE_DATA points to the
|
|
|
|
|
|
enclosed variables.
|
|
|
|
|
|
|
|
|
|
|
|
Of course, it's up to the caller to make sure that any data a
|
|
|
|
|
|
MUMBLE_DATA needs is protected from GC. A common way to do this is
|
|
|
|
|
|
to make MUMBLE_DATA a pointer to data stored in an automatic
|
|
|
|
|
|
structure variable; since the collector must scan the stack for
|
|
|
|
|
|
references anyway, this assures that any references in MUMBLE_DATA
|
|
|
|
|
|
will be found. */
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
SCM
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_internal_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct jmp_buf_and_retval jbr;
|
|
|
|
|
|
SCM jmpbuf;
|
|
|
|
|
|
SCM answer;
|
|
|
|
|
|
|
1996-10-06 22:16:33 +00:00
|
|
|
|
jmpbuf = make_jmpbuf ();
|
1996-07-25 22:56:11 +00:00
|
|
|
|
answer = SCM_EOL;
|
|
|
|
|
|
scm_dynwinds = scm_acons (tag, jmpbuf, scm_dynwinds);
|
|
|
|
|
|
SETJBJMPBUF(jmpbuf, &jbr.buf);
|
1996-10-05 16:50:52 +00:00
|
|
|
|
SCM_SETJBDFRAME(jmpbuf, scm_last_debug_frame);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
if (setjmp (jbr.buf))
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM throw_tag;
|
|
|
|
|
|
SCM throw_args;
|
|
|
|
|
|
|
1996-10-01 03:19:48 +00:00
|
|
|
|
#ifdef STACK_CHECKING
|
|
|
|
|
|
scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
SCM_REDEFER_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
DEACTIVATEJB (jmpbuf);
|
|
|
|
|
|
scm_dynwinds = SCM_CDR (scm_dynwinds);
|
1996-10-01 03:19:48 +00:00
|
|
|
|
SCM_REALLOW_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
throw_args = jbr.retval;
|
|
|
|
|
|
throw_tag = jbr.throw_tag;
|
|
|
|
|
|
jbr.throw_tag = SCM_EOL;
|
|
|
|
|
|
jbr.retval = SCM_EOL;
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
answer = handler (handler_data, throw_tag, throw_args);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ACTIVATEJB (jmpbuf);
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
answer = body (body_data);
|
1996-10-01 03:19:48 +00:00
|
|
|
|
SCM_REDEFER_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
DEACTIVATEJB (jmpbuf);
|
|
|
|
|
|
scm_dynwinds = SCM_CDR (scm_dynwinds);
|
1996-10-01 03:19:48 +00:00
|
|
|
|
SCM_REALLOW_INTS;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
return answer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
/* scm_internal_lazy_catch (the guts of lazy catching) */
|
|
|
|
|
|
|
|
|
|
|
|
/* The smob tag for lazy_catch smobs. */
|
2001-06-14 19:50:43 +00:00
|
|
|
|
static scm_t_bits tc16_lazy_catch;
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
/* This is the structure we put on the wind list for a lazy catch. It
|
|
|
|
|
|
stores the handler function to call, and the data pointer to pass
|
|
|
|
|
|
through to it. It's not a Scheme closure, but it is a function
|
|
|
|
|
|
with data, so the term "closure" is appropriate in its broader
|
|
|
|
|
|
sense.
|
|
|
|
|
|
|
|
|
|
|
|
(We don't need anything like this in the "eager" catch code,
|
|
|
|
|
|
because the same C frame runs both the body and the handler.) */
|
|
|
|
|
|
struct lazy_catch {
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_catch_handler handler;
|
1997-04-11 03:54:56 +00:00
|
|
|
|
void *handler_data;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Strictly speaking, we could just pass a zero for our print
|
|
|
|
|
|
function, because we don't need to print them. They should never
|
|
|
|
|
|
appear in normal data structures, only in the wind list. However,
|
|
|
|
|
|
it might be nice for debugging someday... */
|
|
|
|
|
|
static int
|
2001-06-07 21:12:19 +00:00
|
|
|
|
lazy_catch_print (SCM closure, SCM port, scm_print_state *pstate SCM_UNUSED)
|
1997-04-11 03:54:56 +00:00
|
|
|
|
{
|
2000-04-04 12:13:41 +00:00
|
|
|
|
struct lazy_catch *c = (struct lazy_catch *) SCM_CELL_WORD_1 (closure);
|
1997-04-11 03:54:56 +00:00
|
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
|
|
|
|
sprintf (buf, "#<lazy-catch 0x%lx 0x%lx>",
|
|
|
|
|
|
(long) c->handler, (long) c->handler_data);
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_puts (buf, port);
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Given a pointer to a lazy catch structure, return a smob for it,
|
|
|
|
|
|
suitable for inclusion in the wind list. ("Ah yes, a Ch<43>teau
|
|
|
|
|
|
Gollombiere '72, non?"). */
|
|
|
|
|
|
static SCM
|
|
|
|
|
|
make_lazy_catch (struct lazy_catch *c)
|
|
|
|
|
|
{
|
1999-07-07 09:44:01 +00:00
|
|
|
|
SCM_RETURN_NEWSMOB (tc16_lazy_catch, c);
|
1997-04-11 03:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-12-08 17:32:56 +00:00
|
|
|
|
#define SCM_LAZY_CATCH_P(obj) (SCM_TYP16_PREDICATE (tc16_lazy_catch, obj))
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Exactly like scm_internal_catch, except:
|
|
|
|
|
|
- It does not unwind the stack (this is the major difference).
|
2001-05-19 02:01:12 +00:00
|
|
|
|
- The handler is not allowed to return. */
|
1997-04-11 03:54:56 +00:00
|
|
|
|
SCM
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_internal_lazy_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
|
1997-04-11 03:54:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM lazy_catch, answer;
|
|
|
|
|
|
struct lazy_catch c;
|
|
|
|
|
|
|
|
|
|
|
|
c.handler = handler;
|
|
|
|
|
|
c.handler_data = handler_data;
|
|
|
|
|
|
lazy_catch = make_lazy_catch (&c);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_REDEFER_INTS;
|
|
|
|
|
|
scm_dynwinds = scm_acons (tag, lazy_catch, scm_dynwinds);
|
|
|
|
|
|
SCM_REALLOW_INTS;
|
|
|
|
|
|
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
answer = (*body) (body_data);
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
SCM_REDEFER_INTS;
|
|
|
|
|
|
scm_dynwinds = SCM_CDR (scm_dynwinds);
|
|
|
|
|
|
SCM_REALLOW_INTS;
|
|
|
|
|
|
|
|
|
|
|
|
return answer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-08-13 14:54:49 +00:00
|
|
|
|
|
|
|
|
|
|
/* scm_internal_stack_catch
|
|
|
|
|
|
Use this one if you want debugging information to be stored in
|
2001-05-15 14:57:22 +00:00
|
|
|
|
scm_the_last_stack_fluid_var on error. */
|
1997-08-13 14:54:49 +00:00
|
|
|
|
|
|
|
|
|
|
static SCM
|
2001-06-07 21:12:19 +00:00
|
|
|
|
ss_handler (void *data SCM_UNUSED, SCM tag, SCM throw_args)
|
1997-08-13 14:54:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
/* Save the stack */
|
2001-05-15 14:57:22 +00:00
|
|
|
|
scm_fluid_set_x (SCM_VARIABLE_REF (scm_the_last_stack_fluid_var),
|
2000-05-18 08:47:52 +00:00
|
|
|
|
scm_make_stack (SCM_BOOL_T, SCM_EOL));
|
1997-08-13 14:54:49 +00:00
|
|
|
|
/* Throw the error */
|
|
|
|
|
|
return scm_throw (tag, throw_args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct cwss_data
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM tag;
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_catch_body body;
|
1997-08-13 14:54:49 +00:00
|
|
|
|
void *data;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
cwss_body (void *data)
|
1997-08-13 14:54:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct cwss_data *d = data;
|
|
|
|
|
|
return scm_internal_lazy_catch (d->tag, d->body, d->data, ss_handler, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_internal_stack_catch (SCM tag,
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_catch_body body,
|
1997-08-13 14:54:49 +00:00
|
|
|
|
void *body_data,
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_catch_handler handler,
|
1997-08-13 14:54:49 +00:00
|
|
|
|
void *handler_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct cwss_data d;
|
|
|
|
|
|
d.tag = tag;
|
|
|
|
|
|
d.body = body;
|
|
|
|
|
|
d.data = body_data;
|
|
|
|
|
|
return scm_internal_catch (tag, cwss_body, &d, handler, handler_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
1997-08-13 14:54:49 +00:00
|
|
|
|
/* body and handler functions for use with any of the above catch variants */
|
1997-04-11 03:54:56 +00:00
|
|
|
|
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
/* This is a body function you can pass to scm_internal_catch if you
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
want the body to be like Scheme's `catch' --- a thunk.
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
BODY_DATA is a pointer to a scm_body_thunk_data structure, which
|
|
|
|
|
|
contains the Scheme procedure to invoke as the body, and the tag
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
we're catching. */
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_body_thunk (void *body_data)
|
1996-12-09 02:15:17 +00:00
|
|
|
|
{
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
struct scm_body_thunk_data *c = (struct scm_body_thunk_data *) body_data;
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
2001-06-26 15:46:40 +00:00
|
|
|
|
return scm_call_0 (c->body_proc);
|
1996-12-09 02:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
/* This is a handler function you can pass to scm_internal_catch if
|
1997-08-26 23:53:28 +00:00
|
|
|
|
you want the handler to act like Scheme's catch: (throw TAG ARGS ...)
|
|
|
|
|
|
applies a handler procedure to (TAG ARGS ...).
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
If the user does a throw to this catch, this function runs a
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
handler procedure written in Scheme. HANDLER_DATA is a pointer to
|
|
|
|
|
|
an SCM variable holding the Scheme procedure object to invoke. It
|
1997-04-10 22:02:45 +00:00
|
|
|
|
ought to be a pointer to an automatic variable (i.e., one living on
|
|
|
|
|
|
the stack), or the procedure object should be otherwise protected
|
|
|
|
|
|
from GC. */
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_handle_by_proc (void *handler_data, SCM tag, SCM throw_args)
|
1996-12-09 02:15:17 +00:00
|
|
|
|
{
|
* throw.c (scm_internal_catch): Make body funcs and handler funcs
use separate data pointers, to allow them to be designed
independently and reused.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message):
Renamed from catch_body, catch_handler, and uncaught_throw; made
generically useful.
(struct scm_catch_body_data): Renamed from catch_body_data; moved
to throw.h.
(scm_catch): Use the above.
(scm_throw): Don't bother printing a message for an uncaught
throw; we establish a default handler in init.
* throw.h (scm_internal_catch): Prototype updated.
(scm_body_thunk, scm_handle_by_proc, scm_handle_by_message): New
decls.
(struct scm_body_thunk_data): New structure, used as data
argument to scm_body_thunk.
* init.c (struct main_func_closure): New structure, packaging up
the data to pass to the user's main function.
(scm_boot_guile): Create one. Pass it to scm_boot_guile_1.
(scm_boot_guile_1): Pass it through to invoke_main_func. Use
scm_internal_catch to establish a catch-all handler, using
scm_handle_by_message. This replaces the special-case code in
scm_throw.
(invoke_main_func): Body function for scm_internal_catch; invoke
the user's main function, using the main_func_closure pointer to
decide what to pass it.
* root.c (struct cwdr_body_data): Remove handler_proc member.
(cwdr): Use scm_handle_by_proc instead of cwdr_handler.
(cwdr_handler): Removed.
1996-12-21 04:48:21 +00:00
|
|
|
|
SCM *handler_proc_p = (SCM *) handler_data;
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
2001-06-26 15:46:40 +00:00
|
|
|
|
return scm_apply_1 (*handler_proc_p, tag, throw_args);
|
1996-12-09 02:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1997-10-02 15:05:57 +00:00
|
|
|
|
/* SCM_HANDLE_BY_PROC_CATCHING_ALL is like SCM_HANDLE_BY_PROC but
|
|
|
|
|
|
catches all throws that the handler might emit itself. The handler
|
|
|
|
|
|
used for these `secondary' throws is SCM_HANDLE_BY_MESSAGE_NO_EXIT. */
|
|
|
|
|
|
|
|
|
|
|
|
struct hbpca_data {
|
|
|
|
|
|
SCM proc;
|
|
|
|
|
|
SCM args;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
hbpca_body (void *body_data)
|
1997-10-02 15:05:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct hbpca_data *data = (struct hbpca_data *)body_data;
|
2001-06-26 15:46:40 +00:00
|
|
|
|
return scm_apply_0 (data->proc, data->args);
|
1997-10-02 15:05:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_handle_by_proc_catching_all (void *handler_data, SCM tag, SCM throw_args)
|
1997-10-02 15:05:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM *handler_proc_p = (SCM *) handler_data;
|
|
|
|
|
|
struct hbpca_data data;
|
|
|
|
|
|
data.proc = *handler_proc_p;
|
|
|
|
|
|
data.args = scm_cons (tag, throw_args);
|
|
|
|
|
|
|
|
|
|
|
|
return scm_internal_catch (SCM_BOOL_T,
|
|
|
|
|
|
hbpca_body, &data,
|
|
|
|
|
|
scm_handle_by_message_noexit, NULL);
|
|
|
|
|
|
}
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1997-06-23 04:34:34 +00:00
|
|
|
|
/* Derive the an exit status from the arguments to (quit ...). */
|
|
|
|
|
|
int
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_exit_status (SCM args)
|
1997-06-23 04:34:34 +00:00
|
|
|
|
{
|
2002-01-22 23:31:39 +00:00
|
|
|
|
if (!SCM_NULL_OR_NIL_P (args))
|
1997-06-23 04:34:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM cqa = SCM_CAR (args);
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_INUMP (cqa))
|
|
|
|
|
|
return (SCM_INUM (cqa));
|
|
|
|
|
|
else if (SCM_FALSEP (cqa))
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
1997-06-23 04:34:34 +00:00
|
|
|
|
static void
|
|
|
|
|
|
handler_message (void *handler_data, SCM tag, SCM args)
|
1996-10-05 16:50:52 +00:00
|
|
|
|
{
|
1997-04-10 22:02:45 +00:00
|
|
|
|
char *prog_name = (char *) handler_data;
|
1998-03-28 20:26:17 +00:00
|
|
|
|
SCM p = scm_cur_errp;
|
1996-12-09 02:15:17 +00:00
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
if (scm_ilength (args) >= 3)
|
|
|
|
|
|
{
|
2000-05-18 08:47:52 +00:00
|
|
|
|
SCM stack = scm_make_stack (SCM_BOOL_T, SCM_EOL);
|
1998-10-08 20:11:59 +00:00
|
|
|
|
SCM subr = SCM_CAR (args);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
SCM message = SCM_CADR (args);
|
1998-10-08 20:11:59 +00:00
|
|
|
|
SCM parts = SCM_CADDR (args);
|
|
|
|
|
|
SCM rest = SCM_CDDDR (args);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
1999-10-08 10:46:26 +00:00
|
|
|
|
if (SCM_BACKTRACE_P && SCM_NFALSEP (stack))
|
|
|
|
|
|
{
|
|
|
|
|
|
scm_puts ("Backtrace:\n", p);
|
|
|
|
|
|
scm_display_backtrace (stack, p, SCM_UNDEFINED, SCM_UNDEFINED);
|
|
|
|
|
|
scm_newline (p);
|
|
|
|
|
|
}
|
2001-01-24 15:58:46 +00:00
|
|
|
|
scm_i_display_error (stack, p, subr, message, parts, rest);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
1998-10-08 20:11:59 +00:00
|
|
|
|
if (! prog_name)
|
|
|
|
|
|
prog_name = "guile";
|
|
|
|
|
|
|
|
|
|
|
|
scm_puts (prog_name, p);
|
|
|
|
|
|
scm_puts (": ", p);
|
|
|
|
|
|
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_puts ("uncaught throw to ", p);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
scm_prin1 (tag, p, 0);
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_puts (": ", p);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
scm_prin1 (args, p, 1);
|
* Makefile.in: Rebuilt.
* Makefile.am (libguile_la_SOURCES): Removed extchrs.c,
mbstrings.c.
(modinclude_HEADERS): Removed extchrs.h, mbstrings.h.
* unif.c (scm_vector_set_length_x): Don't handle multibyte
strings.
* tag.c (scm_utag_mb_string, scm_utag_mb_substring): Removed.
(scm_tag): Don't handle multibyte strings.
* read.c: Don't include mbstrings.h.
(scm_lreadr): Don't handle multibyte ports.
* kw.c: Don't include mbstrings.h.
* init.c: Don't include mbstrings.h.
(scm_boot_guile_1): Don't init mbstrings module.
* hash.c (scm_hasher): Don't handle mbstrings.
* gscm.c (gscm_run_scm): Don't init mbstrings module.
* gc.c (scm_gc_mark): Don't handle mbstrings.
(scm_gc_sweep): Likewise.
* eval.c (SCM_CEVAL): Don't handle mbstrings.
* eq.c (scm_equal_p): Use SCM_TYP7S, not SCM_TYP7SD.
* tags.h (SCM_TYP7SD): Removed.
(SCM_TYP7D): Removed.
(scm_tc7_mb_string): Removed.
(scm_tc7_mb_substring): Removed.
* print.c (scm_iprin1): Handle char printing directly. Don't
handle mbstrings.
Don't include "mbstrings.h".
* symbols.c (scm_intern_obarray_soft, scm_string_to_symbol,
scm_string_to_obarray_symbol, msymbolize): Don't set symbol's
multi-byte flag.
Don't include "mbstrings.h".
* symbols.h (SCM_SYMBOL_MULTI_BYTE_STRINGP): Removed.
(SCM_SYMBOL_SLOTS): Define as 4.
(SCM_ROSTRINGP): Use SCM_TYP7S, not SCM_TYP7SD.
* arbiters.c, backtrace.c, debug.c, dynl.c, eval.c, fluids.c,
gc.c, gsubr.c, ioext.c, kw.c, mallocs.c, numbers.c, ports.c,
print.c, read.c, regex-posix.c, root.c, srcprop.c, stackchk.c,
struct.c, threads.c, throw.c, unif.c, variable.c: Use new
("gen"-less) I/O function names.
* ports.c (scm_add_to_port_table): Don't set port's
representation.
* ports.h (scm_port_representation_type): Removed.
(scm_string_representation_type): Removed.
(struct scm_port_table ): Removed representation field.
(SCM_PORT_REPRESENTATION): Removed.
(SCM_SET_PORT_REPRESENTATION): Removed.
* genio.h: Use new function names.
* genio.c: Don't include "extchrs.h".
(scm_gen_putc, scm_gen_puts, scm_gen_write, scm_get_getc):
Removed.
(scm_putc, scm_puts, scm_lfwrite): No longer static.
(scm_getc): No longer static; handle line and column changes.
(scm_ungetc): Renamed from scm_gen_ungetc.
(scm_do_read_line): Renamed from scm_gen_read_line.
* libguile.h: Don't include "extchrs.h" or "mbstrings.h"
* extchrs.h, extchrs.c, mbstrings.h, mbstrings.c: Removed.
1997-10-15 17:18:32 +00:00
|
|
|
|
scm_putc ('\n', p);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
}
|
1997-06-23 04:34:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This is a handler function to use if you want scheme to print a
|
|
|
|
|
|
message and die. Useful for dealing with throws to uncaught keys
|
|
|
|
|
|
at the top level.
|
|
|
|
|
|
|
|
|
|
|
|
At boot time, we establish a catch-all that uses this as its handler.
|
|
|
|
|
|
1) If the user wants something different, they can use (catch #t
|
|
|
|
|
|
...) to do what they like.
|
|
|
|
|
|
2) Outside the context of a read-eval-print loop, there isn't
|
|
|
|
|
|
anything else good to do; libguile should not assume the existence
|
|
|
|
|
|
of a read-eval-print loop.
|
|
|
|
|
|
3) Given that we shouldn't do anything complex, it's much more
|
|
|
|
|
|
robust to do it in C code.
|
|
|
|
|
|
|
|
|
|
|
|
HANDLER_DATA, if non-zero, is assumed to be a char * pointing to a
|
|
|
|
|
|
message header to print; if zero, we use "guile" instead. That
|
|
|
|
|
|
text is followed by a colon, then the message described by ARGS. */
|
|
|
|
|
|
|
2000-09-19 10:56:57 +00:00
|
|
|
|
/* Dirk:FIXME:: The name of the function should make clear that the
|
|
|
|
|
|
* application gets terminated.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
1997-06-23 04:34:34 +00:00
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_handle_by_message (void *handler_data, SCM tag, SCM args)
|
1997-06-23 04:34:34 +00:00
|
|
|
|
{
|
2000-12-08 17:08:34 +00:00
|
|
|
|
if (SCM_NFALSEP (scm_eq_p (tag, scm_str2symbol ("quit"))))
|
* ioext.c (scm_do_read_line): Rewritten to use memchr to find the
newline. A bit faster, and definitely hairier.
(scm_read_line): Count newlines here instead.
* strings.c (scm_take_str): New function.
(scm_take0str): Reimplement in terms of scm_take_str. * strings.h
(scm_take_str): New declaration. * ioext.c (scm_read_line): Use
scm_take_str, to avoid copying the string.
Add some simple-minded support for line buffered ports.
* ports.h (SCM_BUFLINE): New flag for ports.
* init.c (scm_init_standard_ports): Request line-buffering on
the standard output port.
* * ports.c (scm_mode_bits): Recognize 'l' as a request for line
buffering.
(scm_putc, scm_puts, scm_lfwrite): If the port is line-buffered,
and there's a newline to be written, flush the port.
* ports.c: (scm_lseek): clear buffers even if just reading current
position.
* fports.c (local_fclose): call local_fflush unconditionally.
(various): don't use the scm_must... memory procs.
* ports.h (scm_port): make read_pos a pointer to const.
strports.c: take care of rw_active and rw_randow.
fports.c: scm_fport_drain_input: removed. do it all in ports.c.
strports.c (scm_mkstrport): check that pos is reasonable.
ioext.c (scm_ftell, scm_fseek): use lseek.
(SCM_CLEAR_BUFFERS): macro deleted.
ioext.c (redirect_port: use ptob fflush, read_flush.
ports.h (scm_ptobfuns): add ftruncate.
ports.c (scm_newptob): set ftruncate.
adjust ptob tables.
* ports.c (scm_ftruncate): new procedure.
fports.c (local_ftrunate), strports.c (str_ftruncate): new procs.
strports.c (st_seek, st_grow_port): new procs.
fports.h (scm_port): change size types from int to off_t.
ports.c (scm_init_ports): initialise the seek symbols here
instead of in ioext.c.
strports.c (scm_call_with_output_string): start with an empty
string, so seek and ftruncate can be used.
* ports.h (scm_ptobfuns): add a read_flush procedure which is the
equivalent to fflush for the read buffer.
* ports.c (scm_newptob): set read_flush.
ports.c (void_port_ptob): set read_flush.
fports.c (local_read_flush): new proc. add to ptob.
strport.c (st_read_flush): likewise.
vport.c (sf_read_flush): likewise.
fports.h (struct scm_fport): remove random member. there's nothing
left but fdes. leaving it as a struct to allow for future changes.
fports.c: replace usage of scm_fport::random with scm_port::rw_random.
ports.c: (scm_putc, scm_puts, scm_lfwrite): call the read_flush
ptob proc if the read buffer is filled.
* ports.h (scm_port): add a rw_random member and replace
reading and writing members with rw_active member.
SCM_PORT_READ/SCM_PORT_WRITE: new values.
* ports.h (struct scm_port_table): add writing and reading members
to replace write_needs_seek: it isn't good enough for non-fports.
ports.c, ioext.c, fports.c: corresponding changes.
(struct scm_port_table): give it a typedef and rename to scm_port.
ports.c, fports.c, strports.c, vports.c, ioext.c, ports.h:
corresponding changes.
* ports.c (scm_newptob): bugfix: set seek member.
* * (scm_lseek): new procedure, using code from ioext.c:scm_fseek
and generalised to all port types.
* scmsigs.c (scm_init_scmsigs): set the SA_RESTART flag for all
signals (it was only being done for handlers installed from Scheme).
Otherwise (for example) SIGSTOP followed by SIGCONT on an interpreter
waiting for input caused an EINTR error from read.
* ports.h (struct scm_port_table): make all the char members
unsigned, so they convert to int without becoming negative if large.
* fports.c (scm_fdes_wait_for_input): forgot to check compilation
with threads enabled. rename this procedure to
fport_wait_for_input and take a port instead of a fdes.
use scm_fport_input_waiting_p instead of scm_fdes_waiting_p.
* readline.c (scm_readline): Applied a patch from Greg Harvey to
get readline support working again: use fdopen to get FILE objects.
* gc.c (scm_init_storage): install an atexit proc to flush the
ports.
(cleanup): the new proc. it sets a global variable which can be
checked by the ptob flush procs to avoid trying to throw
exceptions during exit. not very pleasant but it seems more reliable.
* fports.c (local_fflush): check terminating variable and if set
don't throw exception.
* CHECKME: that the atexit proc is installed if unexec used.
* throw.c (scm_handle_by_message): don't flush all ports here.
it still causes bus errors.
* fports.h (SCM_FPORT_CLEAR_BUFFERS): rename to SCM_CLEAR_BUFFERS
and move to ioext.c.
* fports.c (scm_fdes_waiting_p): merged into fport_input_waiting_p.
* ports.c (scm_char_ready_p): check the port buffer and call the
ptob entry if needed.
* ports.h (scm_ptobfuns): input_waiting_p added. change all the
ptob initialisers. use it in char-ready
* ioext.c (scm_do_read_line): moved from ports.c. make it static.
* vports.c (sfflush): modified to write a char (since softports
currently use shortbuf.)
* fports.c (scm_standard_stream_to_port): moved to init.c and
made static.
* init.c (scm_init_standard_ports): make stdout and stderr
unbuffered if connected to a terminal. with stdio they
were line-buffered by default.
* ports.h (scm_ptobfuns): change fflush return to void.
change flush proc definitions.
* strports.c (scm_call_with_output_string): get size from
buffer instead of port stream.
(scm_strprint_obj): likewise.
(st_flush): new proc.
* ports.h (struct scm_port_table): added write_end member,
as an optimisation. set it where write_buf_size is set.
* ports.h (struct scm_port_table): change stream from void *
back to SCM. SCM presumably must be large enough to hold a
pointer (and probably vice versa but who knows.)
(SCM_SSTREAM): deleted. change users back to SCM_STREAM.
(scm_puts): rewritten
* fports.c (local_ffwrite, local_fputs): removed.
* strports.c (stputc, stputs, stwrite): dyked out (FIXME)
* vports.c (sfputc, sfputs, sfwrite) likewise.
* ports.c (write_void_port, puts_void_port): removed.
(putc_void_port, getc_void_port, fgets_void_port): likewise.
* ports.c (scm_lfwrite): rewritten using fport.c version.
* fports.c (local_fputc): deleted.
* ports.c (scm_add_to_port_table): initialise write_needs_seek.
* ports.h (scm_ptobfuns): add seek function pointer.
* fports.c: set it to local_seek, new procedure.
* fports.h (SCM_MAYBE_DRAIN_INPUT): moved to ports.c.
use ptob for seek. take ptob instead of fport arg.
* ports.h (struct scm_port_table): new member write_needs_seek,
replaces reading member in fport struct.
* vports.c (sfgetc): store the getted char into the buffer.
rename to sf_fill_buffer and install it for fill-buffer in ptob.
the Scheme interface is still a procedure that gets a char.
(scm_make_soft_port): set up the port buffer (shortbuf).
* fports.c (local_fgetc, local_fgets): deleted.
* strports.c (stgetc): likewise.
* ports.c: scm_generic_fgets: likewise.
* ports.h (scm_ptobfuns): add fill_buffer.
* ports.c (scm_newptob): assign it.
* strports.c (scm_mkstrport): set up the buffer.
put just the string into the stream, not cons (pos stream).
(stfill_buffer): new proc.
* ports.h: fport buffer moved into port table: to be
used for all port types.
* throw.c (scm_handle_by_message): flush ports at exit.
* socket.c (scm_sock_fd_to_port): use scm_fdes_to_port.
(scm_getsockopt, scm_setsockopt, scm_shutdown, scm_connect,
scm_bind, scm_listen, scm_accept, scm_getsockname,
scm_getpeername, scm_recv, scm_send, scm_recvfrom,
scm_sendto,
use SCM_FPORT_FDES. use SCM_OPFPORTP not SCM_FPORTP.
* posix.c (scm_getgroups): use SCM_ALLOW/DEFER_INTS.
(scm_ttyname): use SCM_FPORT_FDES.
(scm_tcgetpgrp, scm_tcsetpgrp): likewise.
* ioext.c (scm_isatty_p): use SCM_FPORT_FDES.
(scm_fdes_to_ports): modified.
(scm_fdopen): use scm_fdes_to_port.
* ports.c (scm_init_ports): don't try to flush ports using
atexit(). it's too late, errors will cause SEGV.
* fports.c (scm_fport_buffer_add): new procedure.
* fports.h (SCM_FDES_RANDOM_P): new macro. use it in
scm_fdes_to_port and scm_redirect_port.
* ioext.c (scm_redirect_port): use setvbuf to set buffers in the
new port. reset fp->random.
* fports.c (scm_fdes_to_port), ports.c (scm_void_port),
filesys.c (scm_opendir):
restore defer interrupts while the port is constructed.
* (scm_setvbuf): if mode is _IOFBF and size is not supplied,
derive buffer size from fdes or use a default.
(scm_fdes_to_port): use setvbuf instead of creating the buffers
directly.
vports.c (various places): use SCM_SSTREAM.
strports.c: likewise.
* gdbint.c: likewise.
* ports.h (SCM_SSTREAM): new macro.
* fports.c (scm_input_waiting_p): use scm_return_first, since port
may be removed from the stack by the tail call to scm_fdes_waiting_p.
* fports.h (SCM_CLEAR_BUFFERS): new macro.
* ports.c (scm_force_output): call scm_fflush.
* print.c (scm_newline): don't check errno for EPIPE (it wouldn't
* reach this point.) don't flush port (if scm_cur_outp).
* fports.h (SCM_FPORT_FDES): new macro.
* vports.c (sfflush): don't need to set errno.
* ports.c: install scm_flush_all_ports to be run on exit.
ports.c fports.c ioext.c posix.c socket.c net_db.c filesys.c:
removed all uses of SCM_DEFER/ALLOW ints for now. they were mainly
just protecting errno. some may need to be put back.
* scmsigs.c (take_signal): save and restore errno while this
proc runs.
*fports.c (print_pipe_port, local_pclose, scm_pipob): deleted.
* open-pipe, close-pipe are emulated in (ice-9 popen)
ports.c (scm_ports_prehistory): don't init scm_pipob.
ports.h (scm_tc16_pipe): deleted.
posix.c (scm_open_pipe, scm_close_pipe): deleted.
* ioext.c (scm_primitive_move_to_fdes): use fport.
* fport.c (scm_fport_fill_buffer): flush write buffer if needed.
change arg type from scm_fport to SCM port.
fport.h (SCM_SETFDES): removed.
(SCM_MAYBE_DRAIN_INPUT): new macro.
* ioext.c (scm_dup_to_fdes): use SCM_FSTREAM.
(scm_ftell): always use lseek and account for the buffer.
(scm_fileno): use fport buffer.
(scm_fseek): clear fport buffers. always use lseek.
* posix.c (scm_pipe): use fport buffer.
* unif.c: include fports.h instead of genio.h.
* fports.c (scm_fdes_wait_for_input, scm_fport_fill_buffer): new
procedures.
(local_fgetc): use them.
(local_ffwrite): use buffer.
(local_fgets): use buffer.
(scm_setbuf0): deleted.
(scm_setvbuf): set the buffer.
(scm_setfileno): deleted.
(scm_evict_ports): set fdes directly.
* (scm_freopen): deleted. doesn't seem useful in Guile.
(scm_stdio_to_port): deleted.
fports.h (struct scm_fport): add shortbuf member to avoid separate
code for unbuffered ports.
(SCM_FPORTP, SCM_OPFPORTP, SCM_OPINFPORTP, SCM_OPOUTFPORTP): moved
from ports.h.
* genio.c, genio.h: move contents into ports.c, ports.h. The
division wasn't useful.
* fports.c, fports.h (scm_fport_drain_input): new procedure.
* ports.c (scm_drain_input): call scm_fport_drain_input.
* scm_fdes_waiting_p: new procedure.
* fports.c (scm_fdes_to_port): allocate read and/or write buffers.
(scm_input_waiting_p): check the buffer.
(local_fgetc, local_fflush, local_fputc): likewise.
* fports.h (scm_fport): read/write_buf,_pos,_buf_end,,_buf_size:
new members.
* init.c (scm_init_standard_ports): pass fdes instead of FILE *.
* * ports.c (scm_drain_input): new procedure.
ports.h: prototype.
* fports.c (FPORT_READ_SAFE, FPORT_WRITE_SAFE, FPORT_ALL_OKAY,
pre_read, pre_write): removed.
(local_fputc, local_fputs, local_ffwrite): use write, not stdio.
(scm_standard_stream_to_port): change first arg from FILE * to
int fdes.
(local_fflush): flush fdes, not FILE *.
* fports.h (SCM_NOFTELL): removed.
* genio.c, ports.c: don't include filesys.h.
* genio.c (scm_getc): don't use scm_internal_select if FPORT.
do it in fports.c:local_fgetc.
* genio.c: don't use SCM_SYSCALL when calling ptob procedures.
do it where it's needed in the port smobs.
* filesys.c (scm_input_waiting_p): moved to fports.c, stdio
buffer support removed. take SCM arg, not FILE *.
* filesys.h: prototype moved too.
* fports.c (scm_fdes_to_port): new procedure.
(local_fgetc): use read not fgetc.
(local_fclose): use close, not fclose.
(local_fgets): use read, not fgets
* fports.h: prototype for scm_fdes_to_port.
* fports.h (scm_fport): new struct.
* fports.c (scm_open_file): use open, not fopen.
#include fcntl.h
* ports.h (struct scm_port_table): change stream from SCM to void *.
* ports.c (scm_add_to_port_table): check for memory allocation error.
(scm_prinport): remove MSDOS hair.
(scm_void_port): set stream to 0 instead of SCM_BOOL_F.
(scm_close_port): don't throw errors: do it in fports.c.
1999-06-09 12:19:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
exit (scm_exit_status (args));
|
|
|
|
|
|
}
|
1997-06-23 04:34:34 +00:00
|
|
|
|
|
|
|
|
|
|
handler_message (handler_data, tag, args);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
exit (2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-06-23 04:34:34 +00:00
|
|
|
|
/* This is just like scm_handle_by_message, but it doesn't exit; it
|
|
|
|
|
|
just returns #f. It's useful in cases where you don't really know
|
|
|
|
|
|
enough about the body to handle things in a better way, but don't
|
|
|
|
|
|
want to let throws fall off the bottom of the wind list. */
|
|
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_handle_by_message_noexit (void *handler_data, SCM tag, SCM args)
|
1997-04-10 22:02:45 +00:00
|
|
|
|
{
|
1997-06-23 04:34:34 +00:00
|
|
|
|
handler_message (handler_data, tag, args);
|
|
|
|
|
|
|
|
|
|
|
|
return SCM_BOOL_F;
|
1996-10-05 16:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
1998-05-11 01:18:41 +00:00
|
|
|
|
SCM
|
2001-06-07 21:12:19 +00:00
|
|
|
|
scm_handle_by_throw (void *handler_data SCM_UNUSED, SCM tag, SCM args)
|
1998-05-11 01:18:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
scm_ithrow (tag, args, 1);
|
|
|
|
|
|
return SCM_UNSPECIFIED; /* never returns */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* the Scheme-visible CATCH and LAZY-CATCH functions */
|
|
|
|
|
|
|
2000-01-05 19:25:37 +00:00
|
|
|
|
SCM_DEFINE (scm_catch, "catch", 3, 0, 0,
|
2001-04-03 13:19:05 +00:00
|
|
|
|
(SCM key, SCM thunk, SCM handler),
|
* alist.c, chars.c, debug.c, dynl.c, dynwind.c, error.c, eval.c,
evalext.c, filesys.c, gc.c, hash.c, hashtab.c, ioext.c,
keywords.c, list.c, load.c, macros.c, net_db.c, numbers.c,
objprop.c, ports.c, posix.c, print.c, procprop.c, procs.c,
ramap.c, regex-posix.c, root.c, scmsigs.c, simpos.c, socket.c,
stacks.c, stime.c, strings.c, strop.c, strports.c, struct.c,
symbols.c, throw.c, unif.c, vectors.c, version.c, vports.c,
weaks.c: Converted docstrings to ANSI C format.
2000-01-18 11:24:03 +00:00
|
|
|
|
"Invoke @var{thunk} in the dynamic context of @var{handler} for\n"
|
2001-04-03 13:19:05 +00:00
|
|
|
|
"exceptions matching @var{key}. If thunk throws to the symbol\n"
|
|
|
|
|
|
"@var{key}, then @var{handler} is invoked this way:\n"
|
|
|
|
|
|
"@lisp\n"
|
* alist.c, chars.c, debug.c, dynl.c, dynwind.c, error.c, eval.c,
evalext.c, filesys.c, gc.c, hash.c, hashtab.c, ioext.c,
keywords.c, list.c, load.c, macros.c, net_db.c, numbers.c,
objprop.c, ports.c, posix.c, print.c, procprop.c, procs.c,
ramap.c, regex-posix.c, root.c, scmsigs.c, simpos.c, socket.c,
stacks.c, stime.c, strings.c, strop.c, strports.c, struct.c,
symbols.c, throw.c, unif.c, vectors.c, version.c, vports.c,
weaks.c: Converted docstrings to ANSI C format.
2000-01-18 11:24:03 +00:00
|
|
|
|
"(handler key args ...)\n"
|
2001-04-03 13:19:05 +00:00
|
|
|
|
"@end lisp\n"
|
|
|
|
|
|
"\n"
|
|
|
|
|
|
"@var{key} is a symbol or @code{#t}.\n"
|
|
|
|
|
|
"\n"
|
|
|
|
|
|
"@var{thunk} takes no arguments. If @var{thunk} returns\n"
|
|
|
|
|
|
"normally, that is the return value of @code{catch}.\n"
|
|
|
|
|
|
"\n"
|
|
|
|
|
|
"Handler is invoked outside the scope of its own @code{catch}.\n"
|
|
|
|
|
|
"If @var{handler} again throws to the same key, a new handler\n"
|
|
|
|
|
|
"from further up the call chain is invoked.\n"
|
|
|
|
|
|
"\n"
|
|
|
|
|
|
"If the key is @code{#t}, then a throw to @emph{any} symbol will\n"
|
|
|
|
|
|
"match this call to @code{catch}.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_catch
|
1997-04-10 22:02:45 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct scm_body_thunk_data c;
|
|
|
|
|
|
|
2001-04-03 13:19:05 +00:00
|
|
|
|
SCM_ASSERT (SCM_SYMBOLP (key) || SCM_EQ_P (key, SCM_BOOL_T),
|
|
|
|
|
|
key, SCM_ARG1, FUNC_NAME);
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
2001-04-03 13:19:05 +00:00
|
|
|
|
c.tag = key;
|
1997-04-10 22:02:45 +00:00
|
|
|
|
c.body_proc = thunk;
|
|
|
|
|
|
|
|
|
|
|
|
/* scm_internal_catch takes care of all the mechanics of setting up
|
2001-04-03 13:19:05 +00:00
|
|
|
|
a catch key; we tell it to call scm_body_thunk to run the body,
|
1997-04-10 22:02:45 +00:00
|
|
|
|
and scm_handle_by_proc to deal with any throws to this catch.
|
|
|
|
|
|
The former receives a pointer to c, telling it how to behave.
|
|
|
|
|
|
The latter receives a pointer to HANDLER, so it knows who to call. */
|
2001-04-03 13:19:05 +00:00
|
|
|
|
return scm_internal_catch (key,
|
1997-04-10 22:02:45 +00:00
|
|
|
|
scm_body_thunk, &c,
|
|
|
|
|
|
scm_handle_by_proc, &handler);
|
|
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:25:37 +00:00
|
|
|
|
SCM_DEFINE (scm_lazy_catch, "lazy-catch", 3, 0, 0,
|
2001-04-03 13:19:05 +00:00
|
|
|
|
(SCM key, SCM thunk, SCM handler),
|
2001-02-16 15:10:12 +00:00
|
|
|
|
"This behaves exactly like @code{catch}, except that it does\n"
|
2001-05-19 11:18:02 +00:00
|
|
|
|
"not unwind the stack before invoking @var{handler}.\n"
|
|
|
|
|
|
"The @var{handler} procedure is not allowed to return:\n"
|
|
|
|
|
|
"it must throw to another catch, or otherwise exit non-locally.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_lazy_catch
|
1996-10-05 16:50:52 +00:00
|
|
|
|
{
|
1997-02-07 22:38:20 +00:00
|
|
|
|
struct scm_body_thunk_data c;
|
|
|
|
|
|
|
2001-04-03 13:19:05 +00:00
|
|
|
|
SCM_ASSERT (SCM_SYMBOLP (key) || SCM_EQ_P (key, SCM_BOOL_T),
|
|
|
|
|
|
key, SCM_ARG1, FUNC_NAME);
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
2001-04-03 13:19:05 +00:00
|
|
|
|
c.tag = key;
|
1997-02-07 22:38:20 +00:00
|
|
|
|
c.body_proc = thunk;
|
|
|
|
|
|
|
|
|
|
|
|
/* scm_internal_lazy_catch takes care of all the mechanics of
|
2001-04-03 13:19:05 +00:00
|
|
|
|
setting up a lazy catch key; we tell it to call scm_body_thunk to
|
1997-02-07 22:38:20 +00:00
|
|
|
|
run the body, and scm_handle_by_proc to deal with any throws to
|
|
|
|
|
|
this catch. The former receives a pointer to c, telling it how
|
|
|
|
|
|
to behave. The latter receives a pointer to HANDLER, so it knows
|
|
|
|
|
|
who to call. */
|
2001-04-03 13:19:05 +00:00
|
|
|
|
return scm_internal_lazy_catch (key,
|
1997-02-07 22:38:20 +00:00
|
|
|
|
scm_body_thunk, &c,
|
|
|
|
|
|
scm_handle_by_proc, &handler);
|
1996-10-05 16:50:52 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
1997-04-10 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* throwing */
|
1996-09-28 00:01:40 +00:00
|
|
|
|
|
2000-01-05 19:25:37 +00:00
|
|
|
|
SCM_DEFINE (scm_throw, "throw", 1, 0, 1,
|
1999-12-12 02:36:16 +00:00
|
|
|
|
(SCM key, SCM args),
|
* alist.c, chars.c, debug.c, dynl.c, dynwind.c, error.c, eval.c,
evalext.c, filesys.c, gc.c, hash.c, hashtab.c, ioext.c,
keywords.c, list.c, load.c, macros.c, net_db.c, numbers.c,
objprop.c, ports.c, posix.c, print.c, procprop.c, procs.c,
ramap.c, regex-posix.c, root.c, scmsigs.c, simpos.c, socket.c,
stacks.c, stime.c, strings.c, strop.c, strports.c, struct.c,
symbols.c, throw.c, unif.c, vectors.c, version.c, vports.c,
weaks.c: Converted docstrings to ANSI C format.
2000-01-18 11:24:03 +00:00
|
|
|
|
"Invoke the catch form matching @var{key}, passing @var{args} to the\n"
|
|
|
|
|
|
"@var{handler}. \n\n"
|
|
|
|
|
|
"@var{key} is a symbol. It will match catches of the same symbol or of\n"
|
* eval.c (scm_promise_p), list.c (scm_append_x, scm_reverse_x),
symbols.c (scm_symbol_to_string), vports.c (scm_make_soft_port):
Change R4RS references to R5RS.
* guile-snarf.awk.in: Fixes so that (i) blank lines in the
docstring source are correctly reproduced in the output (ii)
we don't anymore get occasional trailing quotes. Also reorganized
and commented the code a little.
* scmsigs.c (scm_raise), throw.c (scm_throw): Docstring format
fixes.
* new-docstrings.texi, posix.texi, scheme-control.texi,
scheme-data.texi, scheme-debug.texi, scheme-evaluation.texi,
scheme-io.texi, scheme-memory.texi, scheme-procedures.texi:
Automatic docstring updates (mostly argument name updates and
blank lines).
* scheme-modules.texi: Change double hyphens to single.
* scheme-control.texi (Lazy Catch): Completed.
* posix.texi (Network Databases and Address Conversion): New
subsubsection `IPv6 Address Conversion'.
2001-05-04 21:54:00 +00:00
|
|
|
|
"@code{#t}.\n\n"
|
2001-04-22 22:16:07 +00:00
|
|
|
|
"If there is no handler at all, Guile prints an error and then exits.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_throw
|
1997-01-30 20:25:09 +00:00
|
|
|
|
{
|
2002-07-20 14:08:34 +00:00
|
|
|
|
SCM_VALIDATE_SYMBOL (1, key);
|
1997-01-30 20:25:09 +00:00
|
|
|
|
return scm_ithrow (key, args, 1);
|
|
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1997-01-30 20:25:09 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
SCM
|
2001-06-07 21:12:19 +00:00
|
|
|
|
scm_ithrow (SCM key, SCM args, int noreturn SCM_UNUSED)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
1998-10-15 14:35:35 +00:00
|
|
|
|
SCM jmpbuf = SCM_UNDEFINED;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
SCM wind_goal;
|
|
|
|
|
|
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
SCM dynpair = SCM_UNDEFINED;
|
|
|
|
|
|
SCM winds;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
/* Search the wind list for an appropriate catch.
|
|
|
|
|
|
"Waiter, please bring us the wind list." */
|
2000-09-19 10:56:57 +00:00
|
|
|
|
for (winds = scm_dynwinds; SCM_CONSP (winds); winds = SCM_CDR (winds))
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
{
|
|
|
|
|
|
dynpair = SCM_CAR (winds);
|
1999-12-16 20:48:05 +00:00
|
|
|
|
if (SCM_CONSP (dynpair))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
{
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
SCM this_key = SCM_CAR (dynpair);
|
1996-10-03 05:28:52 +00:00
|
|
|
|
|
2000-06-05 11:39:46 +00:00
|
|
|
|
if (SCM_EQ_P (this_key, SCM_BOOL_T) || SCM_EQ_P (this_key, key))
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
break;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
}
|
1996-09-28 00:01:40 +00:00
|
|
|
|
|
2000-09-03 20:31:10 +00:00
|
|
|
|
/* If we didn't find anything, print a message and abort the process
|
|
|
|
|
|
right here. If you don't want this, establish a catch-all around
|
|
|
|
|
|
any code that might throw up. */
|
2000-09-19 10:56:57 +00:00
|
|
|
|
if (SCM_NULLP (winds))
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
{
|
2000-09-03 20:31:10 +00:00
|
|
|
|
scm_handle_by_message (NULL, key, args);
|
|
|
|
|
|
abort ();
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
* throw.h: Removed jmpbuf arg in scm_catch_body_t.
* backtrace.c (display_error_body, display_backtrace_body),
coop-threads.c (scheme_body_bootstrip, c_body_bootstrip),
gh_eval.c (eval_str_wrapper, eval_file_wrapper), init.c
(invoke_main_func), root.c (cwdr_body), throw.c (cwss_body,
scm_body_thunk, hbpca_body): Removed the second jmpbuf arg on body
functions.
* throw.c (scm_internal_catch, scm_internal_lazy_catch): Bodies
don't receive the jmpbuf arg anylonger.
(scm_catch): Don't accept a #f tag.
(scm_throw): Check that key is a symbol.
(scm_ithrow): Don't take a jmpbuf as key. Don't check key arg.
1998-02-02 15:00:59 +00:00
|
|
|
|
|
2000-09-03 20:31:10 +00:00
|
|
|
|
/* If the wind list is malformed, bail. */
|
2000-09-19 10:56:57 +00:00
|
|
|
|
if (!SCM_CONSP (winds))
|
2000-09-03 20:31:10 +00:00
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
|
|
jmpbuf = SCM_CDR (dynpair);
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
for (wind_goal = scm_dynwinds;
|
2000-04-04 12:13:41 +00:00
|
|
|
|
!SCM_EQ_P (SCM_CDAR (wind_goal), jmpbuf);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
wind_goal = SCM_CDR (wind_goal))
|
|
|
|
|
|
;
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
/* Is a lazy catch? In wind list entries for lazy catches, the key
|
|
|
|
|
|
is bound to a lazy_catch smob, not a jmpbuf. */
|
|
|
|
|
|
if (SCM_LAZY_CATCH_P (jmpbuf))
|
1996-10-06 22:16:33 +00:00
|
|
|
|
{
|
2000-04-04 12:13:41 +00:00
|
|
|
|
struct lazy_catch *c = (struct lazy_catch *) SCM_CELL_WORD_1 (jmpbuf);
|
1996-11-06 15:05:00 +00:00
|
|
|
|
SCM handle, answer;
|
1997-02-07 22:38:20 +00:00
|
|
|
|
scm_dowinds (wind_goal, (scm_ilength (scm_dynwinds)
|
|
|
|
|
|
- scm_ilength (wind_goal)));
|
1996-10-06 22:16:33 +00:00
|
|
|
|
SCM_REDEFER_INTS;
|
1996-11-06 15:05:00 +00:00
|
|
|
|
handle = scm_dynwinds;
|
1996-10-06 22:16:33 +00:00
|
|
|
|
scm_dynwinds = SCM_CDR (scm_dynwinds);
|
|
|
|
|
|
SCM_REALLOW_INTS;
|
1997-02-07 22:38:20 +00:00
|
|
|
|
answer = (c->handler) (c->handler_data, key, args);
|
2001-05-19 02:01:12 +00:00
|
|
|
|
scm_misc_error ("throw", "lazy-catch handler did return.", SCM_EOL);
|
1996-10-06 22:16:33 +00:00
|
|
|
|
}
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
/* Otherwise, it's a normal catch. */
|
|
|
|
|
|
else if (SCM_JMPBUFP (jmpbuf))
|
1996-10-06 22:16:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct jmp_buf_and_retval * jbr;
|
1997-02-07 22:38:20 +00:00
|
|
|
|
scm_dowinds (wind_goal, (scm_ilength (scm_dynwinds)
|
|
|
|
|
|
- scm_ilength (wind_goal)));
|
1996-10-06 22:16:33 +00:00
|
|
|
|
jbr = (struct jmp_buf_and_retval *)JBJMPBUF (jmpbuf);
|
|
|
|
|
|
jbr->throw_tag = key;
|
|
|
|
|
|
jbr->retval = args;
|
2001-05-19 02:01:12 +00:00
|
|
|
|
scm_last_debug_frame = SCM_JBDFRAME (jmpbuf);
|
|
|
|
|
|
longjmp (*JBJMPBUF (jmpbuf), 1);
|
1996-10-06 22:16:33 +00:00
|
|
|
|
}
|
1997-02-07 22:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
/* Otherwise, it's some random piece of junk. */
|
|
|
|
|
|
else
|
|
|
|
|
|
abort ();
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_init_throw ()
|
|
|
|
|
|
{
|
2000-12-08 17:32:56 +00:00
|
|
|
|
tc16_jmpbuffer = scm_make_smob_type ("jmpbuffer", 0);
|
|
|
|
|
|
scm_set_smob_print (tc16_jmpbuffer, jmpbuffer_print);
|
|
|
|
|
|
|
|
|
|
|
|
tc16_lazy_catch = scm_make_smob_type ("lazy-catch", 0);
|
|
|
|
|
|
scm_set_smob_print (tc16_lazy_catch, lazy_catch_print);
|
|
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/throw.x"
|
1996-07-25 22:56:11 +00:00
|
|
|
|
}
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|