Project

General

Profile

Feature #12026 ยป 0001-Add-WARNING_PROCESSOR-for-processing-warnings.patch

jeremyevans0 (Jeremy Evans), 04/09/2016 10:26 PM

View differences:

error.c
43 43
VALUE rb_eEWOULDBLOCK;
44 44
VALUE rb_eEINPROGRESS;
45 45

  
46
static ID id_call;
47

  
46 48
extern const char ruby_description[];
47 49

  
48 50
static const char REPORTBUG_MSG[] =
......
136 138
}
137 139

  
138 140
static void
141
rb_write_warning_str(VALUE str)
142
{
143
    VALUE filter = rb_gv_get("$WARNING_PROCESSOR");
144
    if (NIL_P(filter)) {
145
      rb_write_error_str(str);
146
    } else {
147
      rb_funcall(filter, id_call, 1, str);
148
    }
149
}
150

  
151
static void
139 152
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
140 153
{
141 154
    VALUE str;
142 155

  
143 156
    str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
144 157
    rb_str_cat2(str, "\n");
145
    rb_write_error_str(str);
158
    rb_write_warning_str(str);
146 159
}
147 160

  
148 161
void
......
200 213
    va_start(args, fmt);
201 214
    mesg = warning_string(0, fmt, args);
202 215
    va_end(args);
203
    rb_write_error_str(mesg);
216
    rb_write_warning_str(mesg);
204 217
}
205 218

  
206 219
void
......
214 227
    va_start(args, fmt);
215 228
    mesg = warning_string(enc, fmt, args);
216 229
    va_end(args);
217
    rb_write_error_str(mesg);
230
    rb_write_warning_str(mesg);
218 231
}
219 232

  
220 233
/* rb_warning() reports only in verbose mode */
......
229 242
    va_start(args, fmt);
230 243
    mesg = warning_string(0, fmt, args);
231 244
    va_end(args);
232
    rb_write_error_str(mesg);
245
    rb_write_warning_str(mesg);
233 246
}
234 247

  
235 248
#if 0
......
244 257
    va_start(args, fmt);
245 258
    mesg = warning_string(enc, fmt, args);
246 259
    va_end(args);
247
    rb_write_error_str(mesg);
260
    rb_write_warning_str(mesg);
248 261
}
249 262
#endif
250 263

  
......
2000 2013
    rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
2001 2014

  
2002 2015
    rb_mErrno = rb_define_module("Errno");
2016
    rb_gv_set("$WARNING_PROCESSOR", Qnil);
2003 2017

  
2004 2018
    rb_define_global_function("warn", rb_warn_m, -1);
2005 2019

  
......
2015 2029
    id_Errno = rb_intern_const("Errno");
2016 2030
    id_errno = rb_intern_const("errno");
2017 2031
    id_i_path = rb_intern_const("@path");
2032
    id_call = rb_intern_const("call");
2018 2033
    id_iseq = rb_make_internal_id();
2019 2034
}
2020 2035

  
......
2238 2253
    va_end(args);
2239 2254
    rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2240 2255
    rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2241
    rb_write_error_str(mesg);
2256
    rb_write_warning_str(mesg);
2242 2257
    errno = errno_save;
2243 2258
}
2244 2259

  
......
2258 2273
    va_end(args);
2259 2274
    rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2260 2275
    rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2261
    rb_write_error_str(mesg);
2276
    rb_write_warning_str(mesg);
2262 2277
    errno = errno_save;
2263 2278
}
2264 2279

  
test/ruby/test_module.rb
1969 1969
    end
1970 1970
  end
1971 1971

  
1972
  def test_uninitialized_instance_variable_warning_processor
1973
    a = AttrTest.new
1974
    $WARNING_PROCESSOR = lambda do |str|
1975
      unless str =~ /instance variable @ivar not initialized/
1976
        $stderr << str
1977
      end
1978
    end
1979
    assert_warning '' do
1980
      assert_nil(a.ivar)
1981
    end
1982
    assert_warning /instance variable @ivar2 not initialized/ do
1983
      assert_nil(a.instance_variable_get(:@ivar2))
1984
    end
1985
  ensure
1986
    $WARNING_PROCESSOR = nil
1987
  end
1988

  
1972 1989
  def test_uninitialized_attr
1973 1990
    a = AttrTest.new
1974 1991
    assert_warning '' do