Project

General

Profile

Feature #15338 ยป 0001-Add-rb_gv_defined.patch

graywolf (Gray Wolf), 11/24/2018 08:21 PM

View differences:

include/ruby/ruby.h
1877 1877

  
1878 1878
VALUE rb_gv_set(const char*, VALUE);
1879 1879
VALUE rb_gv_get(const char*);
1880
VALUE rb_gv_defined(const char *);
1880 1881
VALUE rb_iv_get(VALUE, const char*);
1881 1882
VALUE rb_iv_set(VALUE, const char*, VALUE);
1882 1883

  
spec/ruby/optional/capi/ext/globals_spec.c
60 60
}
61 61
#endif
62 62

  
63
#ifdef HAVE_RB_GV_DEFINED
64
static VALUE sb_gv_defined(VALUE self, VALUE var) {
65
  return rb_gv_defined(StringValuePtr(var));
66
}
67
#endif
68

  
63 69
#ifdef HAVE_RB_STDIN
64 70
static VALUE global_spec_rb_stdin(VALUE self) {
65 71
  return rb_stdin;
......
153 159
  rb_define_method(cls, "sb_gv_set", sb_gv_set, 2);
154 160
#endif
155 161

  
162
#ifdef HAVE_RB_GV_DEFINED
163
  rb_define_method(cls, "sb_gv_defined", sb_gv_defined, 1);
164
#endif
165

  
156 166
#ifdef HAVE_RB_STDIN
157 167
  rb_define_method(cls, "rb_stdin", global_spec_rb_stdin, 0);
158 168
#endif
spec/ruby/optional/capi/ext/rubyspec.h
285 285
#define HAVE_RB_F_GLOBAL_VARIABLES         1
286 286
#define HAVE_RB_GV_GET                     1
287 287
#define HAVE_RB_GV_SET                     1
288
#define HAVE_RB_GV_DEFINED                 1
288 289
#define HAVE_RB_RS                         1
289 290
#define HAVE_RB_OUTPUT_RS                  1
290 291
#define HAVE_RB_OUTPUT_FS                  1
spec/ruby/optional/capi/globals_spec.rb
14 14
    @f.sb_gv_get("\\").should == nil # rb_gv_get should change \ to $\
15 15
  end
16 16

  
17
  it "correctly checks if global value is defined" do
18
    $THIS_IS_DEFINED = nil
19
    @f.sb_gv_defined("$THIS_IS_DEFINED").should == true
20
    @f.sb_gv_defined("$THIS_IS_NOT_DEFINED").should == false
21
  end
22

  
17 23
  it "returns $~" do
18 24
    'a' =~ /a/
19 25
    @f.sb_gv_get("$~").to_a.should == ['a']
variable.c
861 861
    return rb_gvar_get(entry);
862 862
}
863 863

  
864
VALUE
865
rb_gv_defined(const char * name)
866
{
867
    struct rb_global_entry *entry;
868

  
869
    entry = rb_global_entry(global_id(name));
870
    return rb_gvar_defined(entry);
871
}
872

  
864 873
MJIT_FUNC_EXPORTED VALUE
865 874
rb_gvar_defined(struct rb_global_entry *entry)
866 875
{
......
3367 3376
    }
3368 3377
    return 0;
3369 3378
}
3379

  
3380
/* vim: set sw=4 ts=8 sts=4: */
3370
-