Project

General

Profile

Bug #11304 ยป global_variables_captures.patch

0x0dea (D.E. Akers), 06/24/2015 11:08 AM

View differences:

test/ruby/test_variable.rb
assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, [])
end
def test_global_variables_captures
'' =~ //
refute global_variables.include?(:$1)
'a' =~ /(.)/
assert global_variables.include?(:$1)
'ab' =~ /(.)(.)/
assert global_variables.include?(:$2)
end
def test_global_variable_poped
assert_nothing_raised {
EnvUtil.suppress_warning {
variable.c
**********************************************************************/
#include "internal.h"
#include "ruby/re.h"
#include "ruby/st.h"
#include "ruby/util.h"
#include "constant.h"
......
rb_f_global_variables(void)
{
VALUE ary = rb_ary_new();
char buf[2];
int i;
VALUE backref = rb_backref_get();
char buf[7];
int i, len;
st_foreach_safe(rb_global_tbl, gvar_i, ary);
if (RTEST(backref)) {
buf[0] = '$';
for (i = 1; i <= 9; ++i) {
buf[1] = (char)(i + '0');
rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2)));
for (i = 1; i < RMATCH_REGS(backref)->num_regs; ++i) {
len = snprintf(buf + 1, 6, "%d", i);
rb_ary_push(ary, ID2SYM(rb_intern2(buf, len + 1)));
}
}
return ary;
}
    (1-1/1)