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
VALUE rb_gv_set(const char*, VALUE);
VALUE rb_gv_get(const char*);
VALUE rb_gv_defined(const char *);
VALUE rb_iv_get(VALUE, const char*);
VALUE rb_iv_set(VALUE, const char*, VALUE);
spec/ruby/optional/capi/ext/globals_spec.c
}
#endif
#ifdef HAVE_RB_GV_DEFINED
static VALUE sb_gv_defined(VALUE self, VALUE var) {
return rb_gv_defined(StringValuePtr(var));
}
#endif
#ifdef HAVE_RB_STDIN
static VALUE global_spec_rb_stdin(VALUE self) {
return rb_stdin;
......
rb_define_method(cls, "sb_gv_set", sb_gv_set, 2);
#endif
#ifdef HAVE_RB_GV_DEFINED
rb_define_method(cls, "sb_gv_defined", sb_gv_defined, 1);
#endif
#ifdef HAVE_RB_STDIN
rb_define_method(cls, "rb_stdin", global_spec_rb_stdin, 0);
#endif
spec/ruby/optional/capi/ext/rubyspec.h
#define HAVE_RB_F_GLOBAL_VARIABLES 1
#define HAVE_RB_GV_GET 1
#define HAVE_RB_GV_SET 1
#define HAVE_RB_GV_DEFINED 1
#define HAVE_RB_RS 1
#define HAVE_RB_OUTPUT_RS 1
#define HAVE_RB_OUTPUT_FS 1
spec/ruby/optional/capi/globals_spec.rb
@f.sb_gv_get("\\").should == nil # rb_gv_get should change \ to $\
end
it "correctly checks if global value is defined" do
$THIS_IS_DEFINED = nil
@f.sb_gv_defined("$THIS_IS_DEFINED").should == true
@f.sb_gv_defined("$THIS_IS_NOT_DEFINED").should == false
end
it "returns $~" do
'a' =~ /a/
@f.sb_gv_get("$~").to_a.should == ['a']
variable.c
return rb_gvar_get(entry);
}
VALUE
rb_gv_defined(const char * name)
{
struct rb_global_entry *entry;
entry = rb_global_entry(global_id(name));
return rb_gvar_defined(entry);
}
MJIT_FUNC_EXPORTED VALUE
rb_gvar_defined(struct rb_global_entry *entry)
{
......
}
return 0;
}
/* vim: set sw=4 ts=8 sts=4: */
    (1-1/1)