diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-13 21:19:43 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-13 21:19:43 -0800 |
commit | 1232f5dbf8e68f9c3a7fe77360c0b950ecff3eac (patch) | |
tree | 18cb4ab7caf1d2b42139f98c80691e641a76efdd /stream.c | |
parent | cc0f30f375914382e9e94e5bba26b14b2a734499 (diff) | |
download | txr-1232f5dbf8e68f9c3a7fe77360c0b950ecff3eac.tar.gz txr-1232f5dbf8e68f9c3a7fe77360c0b950ecff3eac.tar.bz2 txr-1232f5dbf8e68f9c3a7fe77360c0b950ecff3eac.zip |
Adding a debugger. This is an experimental prototype.
* Makefile (OBJS): New object file debug.o.
* dep.mk: Updated.
* match.c (h_fun): Use debug_begin and debug_end macros
to set up a debug frame for backtracing.
(match_line, match_files): Call debug_check to give debugger a chance
to instrument call.
(v_fun): Use debug_begin and debug_end macros to set up a debug frame
for backtracing. Call debug_check to give debugger a chance to
instrument call.
* stream.c (struct strm_ops): New function pointer, flush.
(stdio_maybe_write_error): Wrong word in error message corrected.
(stdio_flush): New static function.
(stdio_ops, pipe_ops): New function entered into tables.
(flush_stream): New function.
* stream.h (flush_stream): Declared.
* txr.c (help): New options documented.
(main): call to debug_init added. New debug options parsed and
opt_debugger set accordingly.
* unwind.c (uw_push_debug, uw_current_frame): New function.
* unwind.h (uw_frtype): New enumeration member UW_DBG.
(struct uw_debug): New frame variant.
(union uw_frame): New member, db.
(uw_push_debug, uw_current_frame): Declared,
* debug.c: New file.
* debug.h: New file.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -54,6 +54,7 @@ struct strm_ops { val (*get_char)(val); val (*get_byte)(val); val (*close)(val, val); + val (*flush)(val); }; static void common_destroy(val obj) @@ -103,7 +104,7 @@ static val stdio_maybe_write_error(val stream) { struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; if (h->f == 0) - uw_throwf(file_error_s, lit("error reading ~a: file closed"), stream, nao); + uw_throwf(file_error_s, lit("error writing ~a: file closed"), stream, nao); clearerr(h->f); uw_throwf(file_error_s, lit("error writing ~a: ~a/~s"), stream, num(errno), string_utf8(strerror(errno)), nao); @@ -141,6 +142,14 @@ static val stdio_put_char(val stream, val ch) ? t : stdio_maybe_write_error(stream); } +static val stdio_flush(val stream) +{ + struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; + if (fflush(h->f)) + stdio_maybe_write_error(stream); + return t; +} + static wchar_t *snarf_line(struct stdio_handle *h) { const size_t min_size = 512; @@ -233,7 +242,8 @@ static struct strm_ops stdio_ops = { stdio_get_line, stdio_get_char, stdio_get_byte, - stdio_close + stdio_close, + stdio_flush }; static val pipe_close(val stream, val throw_on_error) @@ -286,7 +296,8 @@ static struct strm_ops pipe_ops = { stdio_get_line, stdio_get_char, stdio_get_byte, - pipe_close + pipe_close, + stdio_flush, }; static void string_in_stream_mark(val stream) @@ -1051,6 +1062,18 @@ val put_line(val stream, val string) return (put_string(stream, string), put_char(stream, chr('\n'))); } +val flush_stream(val stream) +{ + type_check (stream, COBJ); + type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), + stream, nao)); + + { + struct strm_ops *ops = (struct strm_ops *) stream->co.ops; + return ops->flush ? ops->flush(stream) : t; + } +} + void stream_init(void) { protect(&std_input, &std_output, &std_error, (val *) 0); |