1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

error.c: rb_write_error_str

* error.c (compile_err_append, compile_warn_print, warn_print): use
  rb_write_error_str() instead of writing to rb_stderr directly.
* io.c (rb_write_error_str): a stopgap measure not to unblock GVL.
  warning from require seems to still have race condition errors.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-12-25 04:38:18 +00:00
parent 5688e811bd
commit 320b49473e
6 changed files with 37 additions and 3 deletions

View file

@ -1,3 +1,11 @@
Tue Dec 25 13:38:12 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (compile_err_append, compile_warn_print, warn_print): use
rb_write_error_str() instead of writing to rb_stderr directly.
* io.c (rb_write_error_str): a stopgap measure not to unblock GVL.
warning from require seems to still have race condition errors.
Tue Dec 25 00:59:29 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* node.h (NODE_OP_CDECL), compile.c (iseq_compile_each),

View file

@ -115,7 +115,7 @@ compile_err_append(VALUE mesg)
th->errinfo = err;
}
rb_str_cat2(mesg, "\n");
rb_io_write(rb_stderr, mesg);
rb_write_error_str(mesg);
}
/* returned to the parser world */
@ -165,7 +165,7 @@ compile_warn_print(const char *file, int line, const char *fmt, va_list args)
str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
rb_str_cat2(str, "\n");
rb_io_write(rb_stderr, str);
rb_write_error_str(str);
}
void
@ -209,7 +209,7 @@ warn_print(const char *fmt, va_list args)
rb_str_cat2(str, "warning: ");
rb_str_vcatf(str, fmt, args);
rb_str_cat2(str, "\n");
rb_io_write(rb_stderr, str);
rb_write_error_str(str);
}
void

View file

@ -138,6 +138,7 @@ const char *ruby_get_inplace_mode(void);
void ruby_set_inplace_mode(const char *);
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
void rb_stdio_set_default_encoding(void);
void rb_write_error_str(VALUE mesg);
/* iseq.c */
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);

17
io.c
View file

@ -6980,6 +6980,23 @@ rb_write_error(const char *mesg)
rb_write_error2(mesg, strlen(mesg));
}
void
rb_write_error_str(VALUE mesg)
{
/* a stopgap measure for the time being */
if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
size_t len = (size_t)RSTRING_LEN(mesg);
if (fwrite(RSTRING_PTR(mesg), sizeof(char), len, stderr) < len) {
RB_GC_GUARD(mesg);
return;
}
}
else {
/* may unlock GVL, and */
rb_io_write(rb_stderr, mesg);
}
}
static void
must_respond_to(ID mid, VALUE val, ID id)
{

1
load.c
View file

@ -663,6 +663,7 @@ load_lock(const char *ftptr)
}
if (RTEST(ruby_verbose)) {
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
/* TODO: display to $stderr, not stderr in C */
rb_backtrace();
}
switch (rb_thread_shield_wait((VALUE)data)) {

View file

@ -384,6 +384,12 @@ class TestRequire < Test::Unit::TestCase
}
tmp.close
# "circular require" warnings to $stderr, but backtraces to stderr
# in C-level. And redirecting stderr to a pipe seems to change
# some blocking timings and causes a deadlock, so run in a
# separated process for the time being.
assert_separately(["-w", "-", path, bug5754], <<-'end;')
path, bug5754 = *ARGV
start = false
scratch = []
@ -416,6 +422,7 @@ class TestRequire < Test::Unit::TestCase
assert_equal(true, (t1_res ^ t2_res), bug5754 + " t1:#{t1_res} t2:#{t2_res}")
assert_equal([:pre, :post], scratch, bug5754)
end;
ensure
$".delete(path)
tmp.close(true) if tmp