Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into 2.2
* master:
  Fixes to assist building Rubinius under Alpine Linux (with musl).
  Changed "of the issue" to "if the issue"
  Contributing notes on version managers/releases
  Expand $PID in Metrics filename.
  Clean up log output of serial_debug/ic_debug
  Specify `superclass` in respect to `prepend`
  Fix correction to documentation for OnStack class.
  Fixed typ in the OnStack class
  Log class names for invalid ivars_ references
  Add a C-API "rb_hash_clear"
  Fix Range#bsearch for matching end value in find-minimum mode
  Fix String#split with 0 limit. Fixes #3474
  Add a String#split spec with 0 limit
  • Loading branch information
tak1n committed Oct 10, 2015
2 parents f56eacf + 2920c9e commit c1f479d
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 38 deletions.
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -27,6 +27,27 @@ Gist:
These two files contain the output of the compilation process and the various
configuration options used (e.g. compiler options).

### Version Managers

We can *not* help you with any issues that might be caused by a Ruby version
manager. In the event of any issues please try building from source instead to
see if the issue is caused by Rubinius itself or your version manager of choice.

Issues involving version managers will be closed if they can either not be
reproduced when building from source, or when the original report makes no
mention about the author having tried building from source.

Note that this only applies to the installation procedure. Problems with the
runtime can of course still be reported, even when using a version manager.

### Rubinius Versions

Rubinius releases quite often, at least more often than most other
implementations. As such we ask users to try out the latest version prior to
reporting an issue. This ensures we don't have to start digging through the
code, only to find out the problem has already been resolved in a more recent
release.

### Running Specs

MSpec provides several different scripts to run the specs under different
Expand Down
44 changes: 22 additions & 22 deletions kernel/common/range.rb
Expand Up @@ -51,47 +51,47 @@ def bsearch

last_true = nil

if max < 0 and min < 0
value = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end

while min < max
x = yield value
seeker = Proc.new do |current|
x = yield current

return value if x == 0
return current if x == 0

case x
when Numeric
if x > 0
min = value + 1
min = current + 1
else
max = value
max = current
end
when true
last_true = value
max = value
last_true = current
max = current
when false, nil
min = value + 1
min = current + 1
else
raise TypeError, "Range#bsearch block must return Numeric or boolean"
end
end

while min < max
if max < 0 and min < 0
value = min + (max - min) / 2
mid = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
mid = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end
mid = (min + max) / 2
end

seeker.call mid
end

if min == max
seeker.call min
end

if min < max
return @begin if value == start
return @begin.kind_of?(Float) ? value.to_f : value
return @begin if mid == start
return @begin.kind_of?(Float) ? mid.to_f : mid
end

if last_true
Expand Down
4 changes: 3 additions & 1 deletion kernel/common/splitter.rb
Expand Up @@ -32,7 +32,9 @@ def self.split(string, pattern, limit)
return [string.dup] if limit == 1
limited = true
else
tail_empty = true
if limit < 0
tail_empty = true
end
limited = false
end
end
Expand Down
2 changes: 1 addition & 1 deletion rakelib/platform.rake
Expand Up @@ -752,7 +752,7 @@ file 'runtime/platform.conf' => deps do |task|

Rubinius::FFI::Generators::Constants.new 'rbx.platform.signal' do |cg|
cg.include 'signal.h'
unless BUILD_CONFIG[:windows]
unless BUILD_CONFIG[:windows] or RUBY_PLATFORM.match(/linux-musl$/)
cg.include 'sys/signal.h'
end

Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/module/prepend_spec.rb
Expand Up @@ -6,6 +6,10 @@
Module.should have_public_instance_method(:prepend, true)
end

it "does not affect the superclass" do
Class.new { prepend Module.new }.superclass.should == Object
end

it "calls #prepend_features(self) in reversed order on each module" do
ScratchPad.record []

Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/string/split_spec.rb
Expand Up @@ -103,6 +103,12 @@
"a\x00a b".split(' ').should == ["a\x00a", "b"]
end

describe "when limit is zero" do
it "ignores leading and continuous whitespace when string is a single space" do
" now's the time ".split(' ', 0).should == ["now's", "the", "time"]
end
end

it "splits between characters when its argument is an empty string" do
"hi!".split("").should == ["h", "i", "!"]
"hi!".split("", -1).should == ["h", "i", "!", ""]
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby/optional/capi/ext/hash_spec.c
Expand Up @@ -40,6 +40,12 @@ VALUE hash_spec_rb_hash_aset(VALUE self, VALUE hash, VALUE key, VALUE val) {
}
#endif

#ifdef HAVE_RB_HASH_CLEAR
VALUE hash_spec_rb_hash_clear(VALUE self, VALUE hash) {
return rb_hash_clear(hash);
}
#endif

#ifdef HAVE_RB_HASH_DELETE
VALUE hash_spec_rb_hash_delete(VALUE self, VALUE hash, VALUE key) {
return rb_hash_delete(hash, key);
Expand Down Expand Up @@ -148,6 +154,10 @@ void Init_hash_spec() {
rb_define_method(cls, "rb_hash_aset", hash_spec_rb_hash_aset, 3);
#endif

#ifdef HAVE_RB_HASH_CLEAR
rb_define_method(cls, "rb_hash_clear", hash_spec_rb_hash_clear, 1);
#endif

#ifdef HAVE_RB_HASH_DELETE
rb_define_method(cls, "rb_hash_delete", hash_spec_rb_hash_delete, 2);
#endif
Expand Down
1 change: 1 addition & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Expand Up @@ -322,6 +322,7 @@
#define HAVE_RB_HASH_FREEZE 1
#define HAVE_RB_HASH_AREF 1
#define HAVE_RB_HASH_ASET 1
#define HAVE_RB_HASH_CLEAR 1
#define HAVE_RB_HASH_DELETE 1
#define HAVE_RB_HASH_DELETE_IF 1
#define HAVE_RB_HASH_FOREACH 1
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/optional/capi/hash_spec.rb
Expand Up @@ -91,6 +91,14 @@
end
end

describe "rb_hash_clear" do
it "returns self that cleared keys and values" do
hsh = { :key => 'value' }
@s.rb_hash_clear(hsh).should equal(hsh)
hsh.should == {}
end
end

describe "rb_hash_delete" do
it "removes the key and returns the value" do
hsh = {:chunky => 'bacon'}
Expand Down
1 change: 0 additions & 1 deletion spec/tags/ruby/core/range/bsearch_tags.txt

This file was deleted.

5 changes: 4 additions & 1 deletion vm/builtin/object.cpp
Expand Up @@ -137,7 +137,10 @@ namespace rubinius {
} else if(CompactLookupTable* clt = try_as<CompactLookupTable>(other->ivars())) {
ivars(state, clt->duplicate(state));
} else {
utilities::logger::warn("Object::copy_object: invalid ivars_ reference");
utilities::logger::warn(
"Object::copy_object: invalid ivars_ reference for %s",
other->class_object(state)->to_string(state, true).c_str()
);
};
}

Expand Down
25 changes: 18 additions & 7 deletions vm/builtin/system.cpp
Expand Up @@ -905,15 +905,21 @@ namespace rubinius {

if(state->shared().config.ic_debug) {
String* mod_name = mod->get_name(state);

if(mod_name->nil_p()) {
mod_name = String::create(state, "");
mod_name = String::create(state, "<unknown>");
}
std::cout << "[IC Increase serial for " << mod_name->c_str(state) << "]" << std::endl;

std::cout << "[IC Reset method cache for " << mod_name->c_str(state)
<< "#" << name->debug_str(state).c_str() << "]" << std::endl;
std::cerr << std::endl
<< "reset global/method cache for "
<< mod_name->c_str(state)
<< "#"
<< name->debug_str(state).c_str()
<< std::endl;

CallFrame* call_frame = calling_environment->previous;
call_frame->print_backtrace(state, 6, true);

call_frame->print_backtrace(state, std::cerr, 6, true);
}

return cTrue;
Expand Down Expand Up @@ -1338,9 +1344,14 @@ namespace rubinius {

Object* System::vm_inc_global_serial(STATE, CallFrame* calling_environment) {
if(state->shared().config.serial_debug) {
std::cout << "[Global serial increased from " << state->shared().global_serial() << "]" << std::endl;
calling_environment->print_backtrace(state, 6, true);
std::cerr << std::endl
<< "global serial increased from "
<< state->shared().global_serial()
<< std::endl;

calling_environment->print_backtrace(state, std::cerr, 6, true);
}

return Fixnum::from(state->shared().inc_global_serial(state));
}

Expand Down
4 changes: 4 additions & 0 deletions vm/capi/hash.cpp
Expand Up @@ -26,6 +26,10 @@ extern "C" {
return capi_fast_call(self, rb_intern("[]="), 2, key, value);
}

VALUE rb_hash_clear(VALUE self) {
return capi_fast_call(self, rb_intern("clear"), 0);
}

VALUE rb_hash_delete(VALUE self, VALUE key) {
return capi_fast_call(self, rb_intern("delete"), 1, key);
}
Expand Down
3 changes: 3 additions & 0 deletions vm/include/capi/ruby/ruby.h
Expand Up @@ -1453,6 +1453,9 @@ struct RTypedData {
/** Set the value associated with the key. */
VALUE rb_hash_aset(VALUE self, VALUE key, VALUE value);

/** Clear the Hash object */
VALUE rb_hash_clear(VALUE self);

/** Remove the key and return the associated value. */
VALUE rb_hash_delete(VALUE self, VALUE key);

Expand Down
8 changes: 6 additions & 2 deletions vm/metrics.cpp
Expand Up @@ -39,12 +39,16 @@ namespace rubinius {
using namespace utilities;

namespace metrics {
FileEmitter::FileEmitter(MetricsMap& map, std::string path)
FileEmitter::FileEmitter(STATE, MetricsMap& map, std::string path)
: MetricsEmitter()
, metrics_map_(map)
, path_(path)
, fd_(-1)
{
// TODO: Make this a proper feature of the config facility.
state->shared().env()->expand_config_value(
path_, "$PID", state->shared().pid.c_str());

initialize();
}

Expand Down Expand Up @@ -254,7 +258,7 @@ namespace rubinius {
state->shared().config.system_metrics_statsd_server.value,
state->shared().config.system_metrics_statsd_prefix.value);
} else if(state->shared().config.system_metrics_target.value.compare("none")) {
emitter_ = new FileEmitter(metrics_map_,
emitter_ = new FileEmitter(state, metrics_map_,
state->shared().config.system_metrics_target.value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/metrics.hpp
Expand Up @@ -299,7 +299,7 @@ namespace rubinius {
int fd_;

public:
FileEmitter(MetricsMap& map, std::string path);
FileEmitter(STATE, MetricsMap& map, std::string path);
virtual ~FileEmitter();

void send_metrics();
Expand Down
4 changes: 2 additions & 2 deletions vm/on_stack.hpp
Expand Up @@ -31,8 +31,8 @@ namespace rubinius {
// what we do is validate the type of o1, as expanded by the template,
// is an Object* or subclass.
//
// Thats what the static_cast<> here does. It will only compiled iff the
// type of o1 is Object* or a subclass.
// That's what the static_cast<> here does. It will be compiled if and
// only if the type of o1 is Object* or a subclass.
//
// When compiled though, because it's completely unused, it disappears, thus
// we've added a compile time type check.
Expand Down
1 change: 1 addition & 0 deletions vm/util/logger.cpp
Expand Up @@ -10,6 +10,7 @@
#include <time.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/file.h>

#include <zlib.h>

Expand Down

0 comments on commit c1f479d

Please sign in to comment.