Project

General

Profile

Feature #12026 ยป 0001-Support-warning-filters.patch

jeremyevans0 (Jeremy Evans), 01/26/2016 10:12 PM

View differences:

error.c
179 179
}
180 180

  
181 181
static void
182
rb_write_warning_str(VALUE str)
183
{
184
    VALUE filter = rb_gv_get("$WARNING_FILTER");
185
    if (RB_TYPE_P(filter, T_REGEXP) && !NIL_P(rb_reg_match(filter, str)))
186
	return;
187
    rb_write_error_str(str);
188
}
189

  
190
static void
182 191
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
183 192
{
184 193
    VALUE str;
185 194

  
186 195
    str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
187 196
    rb_str_cat2(str, "\n");
188
    rb_write_error_str(str);
197
    rb_write_warning_str(str);
189 198
}
190 199

  
191 200
void
......
243 252
    va_start(args, fmt);
244 253
    mesg = warning_string(0, fmt, args);
245 254
    va_end(args);
246
    rb_write_error_str(mesg);
255
    rb_write_warning_str(mesg);
247 256
}
248 257

  
249 258
void
......
257 266
    va_start(args, fmt);
258 267
    mesg = warning_string(enc, fmt, args);
259 268
    va_end(args);
260
    rb_write_error_str(mesg);
269
    rb_write_warning_str(mesg);
261 270
}
262 271

  
263 272
/* rb_warning() reports only in verbose mode */
......
272 281
    va_start(args, fmt);
273 282
    mesg = warning_string(0, fmt, args);
274 283
    va_end(args);
275
    rb_write_error_str(mesg);
284
    rb_write_warning_str(mesg);
276 285
}
277 286

  
278 287
#if 0
......
287 296
    va_start(args, fmt);
288 297
    mesg = warning_string(enc, fmt, args);
289 298
    va_end(args);
290
    rb_write_error_str(mesg);
299
    rb_write_warning_str(mesg);
291 300
}
292 301
#endif
293 302

  
......
2270 2279
    va_end(args);
2271 2280
    rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2272 2281
    rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2273
    rb_write_error_str(mesg);
2282
    rb_write_warning_str(mesg);
2274 2283
    errno = errno_save;
2275 2284
}
2276 2285

  
......
2290 2299
    va_end(args);
2291 2300
    rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2292 2301
    rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2293
    rb_write_error_str(mesg);
2302
    rb_write_warning_str(mesg);
2294 2303
    errno = errno_save;
2295 2304
}
2296 2305

  
......
2364 2373
Init_syserr(void)
2365 2374
{
2366 2375
    rb_eNOERROR = set_syserr(0, "NOERROR");
2376
    rb_gv_set("$WARNING_FILTER", Qnil);
2367 2377
#define defined_error(name, num) set_syserr((num), (name));
2368 2378
#define undefined_error(name) set_syserr(0, (name));
2369 2379
#include "known_errors.inc"
test/ruby/test_module.rb
1974 1974
    end
1975 1975
  end
1976 1976

  
1977
  def test_uninitialized_instance_variable_warning_filter
1978
    a = AttrTest.new
1979
    $WARNING_FILTER = /instance variable @ivar not initialized/
1980
    assert_warning '' do
1981
      assert_nil(a.ivar)
1982
    end
1983
  ensure
1984
    $WARNING_FILTER = nil
1985
  end
1986

  
1977 1987
  def test_uninitialized_attr
1978 1988
    a = AttrTest.new
1979 1989
    assert_warning '' do
1980
-