don't use xstd** from benz

This commit is contained in:
Yuichi Nishiwaki 2015-05-28 00:14:10 +09:00
parent 1fe960716e
commit 7923f947d7
7 changed files with 28 additions and 26 deletions

View File

@ -555,7 +555,6 @@ analyze_quote(analyze_state *state, pic_value obj)
return pic_list2(pic, pic_obj_value(pic->sQUOTE), pic_list_ref(pic, obj, 1));
}
#define ARGC_ASSERT_GE(n, name) do { \
if (pic_length(pic, obj) < (n) + 1) { \
pic_errorf(pic, \
@ -573,7 +572,6 @@ analyze_quote(analyze_state *state, pic_value obj)
} \
} while (0)
static pic_value
analyze_add(analyze_state *state, pic_value obj, bool tailpos)
{
@ -730,7 +728,6 @@ analyze_call_with_values(analyze_state *state, pic_value obj, bool tailpos)
analyze(state, pic_list_ref(pic, obj, 1), false), \
analyze(state, pic_list_ref(pic, obj, 2), false))
static pic_value
analyze_node(analyze_state *state, pic_value obj, bool tailpos)
{

View File

@ -36,34 +36,27 @@ pic_get_backtrace(pic_state *pic)
}
void
pic_print_backtrace(pic_state *pic)
pic_print_backtrace(pic_state *pic, xFILE *file)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_str *trace;
assert(! pic_undef_p(pic->err));
if (! pic_error_p(pic->err)) {
trace = pic_format(pic, "raised: ~s", pic->err);
xfprintf(file, "raise: ");
pic_fwrite(pic, pic->err, file);
} else {
struct pic_error *e;
e = pic_error_ptr(pic->err);
if (e->type != pic_intern_cstr(pic, "")) {
trace = pic_format(pic, "~s ", pic_obj_value(e->type));
} else {
trace = pic_make_str(pic, NULL, 0);
pic_fwrite(pic, pic_obj_value(e->type), file);
xfprintf(file, " ");
}
trace = pic_str_cat(pic, trace, pic_format(pic, "error: ~s", pic_obj_value(e->msg)));
xfprintf(file, "error: ");
pic_fwrite(pic, pic_obj_value(e->msg), file);
xfprintf(file, "\n");
/* TODO: print error irritants */
trace = pic_str_cat(pic, trace, pic_make_str(pic, "\n", 1));
trace = pic_str_cat(pic, trace, e->stack);
xfputs(pic_str_cstr(pic, e->stack), file);
}
/* print! */
xfprintf(xstderr, "%s", pic_str_cstr(pic, trace));
pic_gc_arena_restore(pic, ai);
}

View File

@ -9,6 +9,7 @@
#include "picrin/data.h"
#include "picrin/string.h"
#include "picrin/error.h"
#include "picrin/port.h"
void
pic_panic(pic_state *pic, const char *msg)
@ -29,7 +30,7 @@ pic_warnf(pic_state *pic, const char *fmt, ...)
err_line = pic_xvformat(pic, fmt, ap);
va_end(ap);
fprintf(stderr, "warn: %s\n", pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line))));
xfprintf(pic_stderr(pic)->file, "warn: %s\n", pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line))));
}
void

View File

@ -224,7 +224,7 @@ PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);
void pic_warnf(pic_state *, const char *, ...);
const char *pic_errmsg(pic_state *);
pic_str *pic_get_backtrace(pic_state *);
void pic_print_backtrace(pic_state *);
void pic_print_backtrace(pic_state *, xFILE *);
/* obsoleted */
PIC_INLINE void pic_warn(pic_state *pic, const char *msg)

View File

@ -38,6 +38,16 @@ pic_stdout(pic_state *pic)
return pic_port_ptr(obj);
}
struct pic_port *
pic_stderr(pic_state *pic)
{
pic_value obj;
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-error-port", pic_nil_value());
return pic_port_ptr(obj);
}
struct pic_port *
pic_make_standard_port(pic_state *pic, xFILE *file, short dir)
{

View File

@ -406,7 +406,7 @@ display(pic_state *pic, pic_value obj, xFILE *file)
pic_value
pic_write(pic_state *pic, pic_value obj)
{
return pic_fwrite(pic, obj, xstdout);
return pic_fwrite(pic, obj, pic_stdout(pic)->file);
}
pic_value
@ -420,7 +420,7 @@ pic_fwrite(pic_state *pic, pic_value obj, xFILE *file)
pic_value
pic_display(pic_state *pic, pic_value obj)
{
return pic_fdisplay(pic, obj, xstdout);
return pic_fdisplay(pic, obj, pic_stdout(pic)->file);
}
pic_value
@ -434,6 +434,7 @@ pic_fdisplay(pic_state *pic, pic_value obj, xFILE *file)
void
pic_printf(pic_state *pic, const char *fmt, ...)
{
xFILE *file = pic_stdout(pic)->file;
va_list ap;
pic_str *str;
@ -443,8 +444,8 @@ pic_printf(pic_state *pic, const char *fmt, ...)
va_end(ap);
xprintf("%s", pic_str_cstr(pic, str));
xfflush(xstdout);
xfprintf(file, "%s", pic_str_cstr(pic, str));
xfflush(file);
}
static pic_value

View File

@ -65,7 +65,7 @@ main(int argc, char *argv[], char **envp)
pic_funcall(pic, PICRIN_MAIN, "main", pic_nil_value());
}
pic_catch {
pic_print_backtrace(pic);
pic_print_backtrace(pic, xstderr);
status = 1;
}