From 0cfee328281d98790e527f562eb2c89df51f6452 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 20 Jun 2012 22:25:46 +0000 Subject: * error.c (err_append): rename err_append() to compile_err_append() and move definition body. err_append() is used only by compiling. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 73 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'error.c') diff --git a/error.c b/error.c index eabc3c9eb3..a1987fec95 100644 --- a/error.c +++ b/error.c @@ -99,7 +99,42 @@ compile_snprintf(char *buf, long len, const char *file, int line, const char *fm } } -static void err_append(const char*, rb_encoding *); +static void +compile_err_append(const char *s, rb_encoding *enc) +{ + rb_thread_t *th = GET_THREAD(); + VALUE err = th->errinfo; + rb_block_t *prev_base_block = th->base_block; + th->base_block = 0; + /* base_block should be zero while normal Ruby execution */ + /* after this line, any Ruby code *can* run */ + + if (th->mild_compile_error) { + if (!RTEST(err)) { + err = rb_exc_new3(rb_eSyntaxError, + rb_enc_str_new(s, strlen(s), enc)); + th->errinfo = err; + } + else { + VALUE str = rb_obj_as_string(err); + + rb_str_cat2(str, "\n"); + rb_str_cat2(str, s); + th->errinfo = rb_exc_new3(rb_eSyntaxError, str); + } + } + else { + if (!RTEST(err)) { + err = rb_exc_new2(rb_eSyntaxError, "compile error"); + th->errinfo = err; + } + rb_write_error(s); + rb_write_error("\n"); + } + + /* returned to the parser world */ + th->base_block = prev_base_block; +} void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...) @@ -110,7 +145,7 @@ rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt va_start(args, fmt); compile_snprintf(buf, BUFSIZ, file, line, fmt, args); va_end(args); - err_append(buf, (rb_encoding *)enc); + compile_err_append(buf, (rb_encoding *)enc); } void @@ -122,7 +157,7 @@ rb_compile_error(const char *file, int line, const char *fmt, ...) va_start(args, fmt); compile_snprintf(buf, BUFSIZ, file, line, fmt, args); va_end(args); - err_append(buf, NULL); + compile_err_append(buf, NULL); } void @@ -134,7 +169,7 @@ rb_compile_error_append(const char *fmt, ...) va_start(args, fmt); vsnprintf(buf, BUFSIZ, fmt, args); va_end(args); - err_append(buf, NULL); + compile_err_append(buf, NULL); } static void @@ -1985,33 +2020,3 @@ Init_syserr(void) #undef defined_error #undef undefined_error } - -static void -err_append(const char *s, rb_encoding *enc) -{ - rb_thread_t *th = GET_THREAD(); - VALUE err = th->errinfo; - - if (th->mild_compile_error) { - if (!RTEST(err)) { - err = rb_exc_new3(rb_eSyntaxError, - rb_enc_str_new(s, strlen(s), enc)); - th->errinfo = err; - } - else { - VALUE str = rb_obj_as_string(err); - - rb_str_cat2(str, "\n"); - rb_str_cat2(str, s); - th->errinfo = rb_exc_new3(rb_eSyntaxError, str); - } - } - else { - if (!RTEST(err)) { - err = rb_exc_new2(rb_eSyntaxError, "compile error"); - th->errinfo = err; - } - rb_write_error(s); - rb_write_error("\n"); - } -} -- cgit v1.2.3