Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ddf95f84662e
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 04f38de0f064
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 26, 2014

  1. Copy the full SHA
    5c786dc View commit details
  2. Copy the full SHA
    04f38de View commit details
Showing with 104 additions and 3 deletions.
  1. +40 −0 spec/ruby/optional/capi/ext/globals_spec.c
  2. +4 −0 spec/ruby/optional/capi/ext/rubyspec.h
  3. +56 −0 spec/ruby/optional/capi/globals_spec.rb
  4. +4 −3 vm/include/capi/ruby/ruby.h
40 changes: 40 additions & 0 deletions spec/ruby/optional/capi/ext/globals_spec.c
Original file line number Diff line number Diff line change
@@ -67,6 +67,30 @@ static VALUE global_spec_rb_set_kcode(VALUE self, VALUE code) {
}
#endif

#ifdef HAVE_RB_STDIN
static VALUE global_spec_rb_stdin(VALUE self) {
return rb_stdin;
}
#endif

#ifdef HAVE_RB_STDOUT
static VALUE global_spec_rb_stdout(VALUE self) {
return rb_stdout;
}
#endif

#ifdef HAVE_RB_STDERR
static VALUE global_spec_rb_stderr(VALUE self) {
return rb_stderr;
}
#endif

#ifdef HAVE_RB_DEFOUT
static VALUE global_spec_rb_defout(VALUE self) {
return rb_defout;
}
#endif

#ifdef HAVE_RB_RS
static VALUE global_spec_rb_rs(VALUE self) {
return rb_rs;
@@ -137,6 +161,22 @@ void Init_globals_spec() {
rb_define_method(cls, "rb_set_kcode", global_spec_rb_set_kcode, 1);
#endif

#ifdef HAVE_RB_STDIN
rb_define_method(cls, "rb_stdin", global_spec_rb_stdin, 0);
#endif

#ifdef HAVE_RB_STDOUT
rb_define_method(cls, "rb_stdout", global_spec_rb_stdout, 0);
#endif

#ifdef HAVE_RB_STDERR
rb_define_method(cls, "rb_stderr", global_spec_rb_stderr, 0);
#endif

#ifdef HAVE_RB_DEFOUT
rb_define_method(cls, "rb_defout", global_spec_rb_defout, 0);
#endif

#ifdef HAVE_RB_RS
rb_define_method(cls, "rb_rs", global_spec_rb_rs, 0);
#endif
4 changes: 4 additions & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Original file line number Diff line number Diff line change
@@ -305,6 +305,10 @@
#ifdef RUBY_VERSION_IS_1_8_EX_1_9
#define HAVE_RB_SET_KCODE 1
#endif
#define HAVE_RB_STDERR 1
#define HAVE_RB_STDIN 1
#define HAVE_RB_STDOUT 1
#define HAVE_RB_DEFOUT 1

#define HAVE_RB_LASTLINE_SET 1
#define HAVE_RB_LASTLINE_GET 1
56 changes: 56 additions & 0 deletions spec/ruby/optional/capi/globals_spec.rb
Original file line number Diff line number Diff line change
@@ -72,6 +72,62 @@
end
end

context "rb_std streams" do
before :each do
@name = tmp("rb_std_streams")
@stream = new_io @name
end

after :each do
@stream.close
rm_r @name
end

describe "rb_stdin" do
after :each do
$stdin = STDIN
end

it "returns $stdin" do
$stdin = @stream
@f.rb_stdin.should equal($stdin)
end
end

describe "rb_stdout" do
after :each do
$stdout = STDOUT
end

it "returns $stdout" do
$stdout = @stream
@f.rb_stdout.should equal($stdout)
end
end

describe "rb_stderr" do
after :each do
$stderr = STDERR
end

it "returns $stderr" do
$stderr = @stream
@f.rb_stderr.should equal($stderr)
end
end

describe "rb_defout" do
after :each do
$stdout = STDOUT
end

it "returns $stdout" do
$stdout = @stream
@f.rb_defout.should equal($stdout)
end
end
end

describe "rb_default_rs" do
it "returns \\n" do
@f.rb_default_rs.should == "\n"
7 changes: 4 additions & 3 deletions vm/include/capi/ruby/ruby.h
Original file line number Diff line number Diff line change
@@ -335,9 +335,10 @@ struct RFile {
// Fake it out, just make the ptr be the val
// MRI checks also that it's not closed...
#define GetOpenFile(val, ptr) (ptr) = (capi_rio_struct(val))
#define rb_stdin rb_const_get(rb_cObject, rb_intern("STDIN"))
#define rb_stdout rb_const_get(rb_cObject, rb_intern("STDOUT"))
#define rb_stderr rb_const_get(rb_cObject, rb_intern("STDERR"))
#define rb_stdin rb_gv_get("$stdin")
#define rb_stdout rb_gv_get("$stdout")
#define rb_stderr rb_gv_get("$stderr")
#define rb_defout rb_gv_get("$stdout")

#define GetReadFile(ptr) (ptr->f)
#define GetWriteFile(ptr) (ptr->f)