ruby-changes:26539
From: nobu <ko1@a...>
Date: Tue, 25 Dec 2012 13:38:33 +0900 (JST)
Subject: [ruby-changes:26539] nobu:r38590 (trunk): error.c: rb_write_error_str
nobu 2012-12-25 13:38:18 +0900 (Tue, 25 Dec 2012) New Revision: 38590 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38590 Log: 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. Modified files: trunk/ChangeLog trunk/error.c trunk/internal.h trunk/io.c trunk/load.c trunk/test/ruby/test_require.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38589) +++ ChangeLog (revision 38590) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 25 13:38:12 2012 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * node.h (NODE_OP_CDECL), compile.c (iseq_compile_each), Index: io.c =================================================================== --- io.c (revision 38589) +++ io.c (revision 38590) @@ -6980,6 +6980,23 @@ rb_write_error(const char *mesg) https://github.com/ruby/ruby/blob/trunk/io.c#L6980 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) { Index: load.c =================================================================== --- load.c (revision 38589) +++ load.c (revision 38590) @@ -663,6 +663,7 @@ load_lock(const char *ftptr) https://github.com/ruby/ruby/blob/trunk/load.c#L663 } 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)) { Index: error.c =================================================================== --- error.c (revision 38589) +++ error.c (revision 38590) @@ -115,7 +115,7 @@ compile_err_append(VALUE mesg) https://github.com/ruby/ruby/blob/trunk/error.c#L115 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 https://github.com/ruby/ruby/blob/trunk/error.c#L165 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 https://github.com/ruby/ruby/blob/trunk/error.c#L209 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 Index: internal.h =================================================================== --- internal.h (revision 38589) +++ internal.h (revision 38590) @@ -138,6 +138,7 @@ const char *ruby_get_inplace_mode(void); https://github.com/ruby/ruby/blob/trunk/internal.h#L138 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); Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 38589) +++ test/ruby/test_require.rb (revision 38590) @@ -384,6 +384,12 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L384 } 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L422 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/