Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into mcjit
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Feb 20, 2016
2 parents a596063 + 619c693 commit 0370512
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 41 deletions.
21 changes: 0 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ performance improvements, and help with documentation. Every contribution is
meaningful, so thank you for participating. That being said, here are a few
guidelines that we ask you to follow so we can successfully address your issue.

### Submitting Issues

Please include the following:

* The Rubinius version (`rbx -v`)
* Your OS (`uname -a`) RVM/rbenv/chruby/etc version or the commit hash from git
if you're building off of a clone
* Stack trace (preferably as a Gist, since they're easier to read.) If you can
add a failing spec, that's great!
* Please include the simplest possible reproduction you can. This last point is
vital to fixing issues.

If available, please also include the contents of the following files as a
Gist:

* `configure.log`
* `config.rb`

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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GEM
rubinius-toolset (~> 3)
rubinius-compiler (3.0)
rubinius-instructions (3.0)
rubinius-melbourne (3.1)
rubinius-melbourne (3.3)
rubinius-processor (3.0)
rubinius-toolset (3.0)

Expand Down
4 changes: 2 additions & 2 deletions gems_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rubinius-coverage-2.0.3.gem
rubinius-debugger-2.2.1.gem
rubinius-developer_tools-2.0.0.gem
rubinius-instructions-3.0.gem
rubinius-melbourne-3.1.gem
rubinius-melbourne-3.3.gem
rubinius-processor-3.0.gem
rubinius-profiler-2.0.2.gem
rubinius-toolset-3.0.gem
Expand Down Expand Up @@ -76,7 +76,7 @@ rubysl-openssl-2.8.0.gem
rubysl-open-uri-2.0.0.gem
rubysl-optparse-2.0.1.gem
rubysl-ostruct-2.1.0.gem
rubysl-pathname-2.1.0.gem
rubysl-pathname-2.3.gem
rubysl-prettyprint-2.0.3.gem
rubysl-prime-2.0.1.gem
rubysl-profile-2.0.0.gem
Expand Down
23 changes: 23 additions & 0 deletions issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Problem

Please describe the problem here, try to keep it brief and clear.

## How to Reproduce

Please keep this as simple as possible and provide either a set of steps or a
script/application to reproduce this problem (and remove this sentence).

## Configuration Details

* Output of `rbx -v`:
* Output of `uname -a`:
* Distribution name (in case of Linux/BSD):
* Contents of `config.rb` (as a Gist link):
* Contents of `configure.log` (as a Gist link):

## Stack Trace

Use https://gist.github.com/ and replace this sentence with a link to said Gist.
In case of a SEGV please also include the GDB stack trace, see
http://rubinius.com/doc/en/how-to/obtaining-gdb-backtraces/ for more
information.
8 changes: 8 additions & 0 deletions spec/core/mirror/string/byte_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
lambda { string_mirror("abc").byte_index(-1) }.should raise_error(ArgumentError)
end

it "returns nil if index is greater than string's length" do
string_mirror("abc").byte_index(4).should be_nil
end

with_feature :encoding do
it "returns the byte index of a multibyte character index" do
string_mirror("あそこ").byte_index(1).should == 3
end

it "returns nil if index is greater than string's length" do
string_mirror("あそこ").byte_index(4).should be_nil
end
end
end

Expand Down
44 changes: 27 additions & 17 deletions vm/builtin/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,30 +1723,40 @@ namespace rubinius {

return nil<Fixnum>();
} else if(Fixnum* index = try_as<Fixnum>(value)) {
OnigEncodingType* enc = encoding(state)->get_encoding();
uint8_t* p = byte_address();
uint8_t* e = p + total;
native_int i, k = index->to_native();
native_int k = index->to_native();

if(k < 0) {
Exception::argument_error(state, "character index is negative");
}

for(i = 0; i < k && p < e; i++) {
int c = Encoding::precise_mbclen(p, e, enc);

// If it's an invalid byte, just treat it as a single byte
if(!ONIGENC_MBCLEN_CHARFOUND_P(c)) {
++p;
if(byte_compatible_p(encoding_) || CBOOL(ascii_only_p(state))) {
if(k > total) {
return nil<Fixnum>();
} else {
p += ONIGENC_MBCLEN_CHARFOUND_LEN(c);
return index;
}
}

if(i < k) {
return nil<Fixnum>();
} else {
return Fixnum::from(p - byte_address());
OnigEncodingType* enc = encoding(state)->get_encoding();
uint8_t* p = byte_address();
uint8_t* e = p + total;
native_int i;

for(i = 0; i < k && p < e; i++) {
int c = Encoding::precise_mbclen(p, e, enc);

// If it's an invalid byte, just treat it as a single byte
if(!ONIGENC_MBCLEN_CHARFOUND_P(c)) {
++p;
} else {
p += ONIGENC_MBCLEN_CHARFOUND_LEN(c);
}
}

if(i < k) {
return nil<Fixnum>();
} else {
return Fixnum::from(p - byte_address());
}
}
}

Expand Down Expand Up @@ -1881,7 +1891,7 @@ namespace rubinius {

Object* String::valid_encoding_p(STATE) {
if(valid_encoding_->nil_p()) {
if(encoding(state) == Encoding::ascii8bit_encoding(state)) {
if(encoding(state) == Encoding::ascii8bit_encoding(state) || CBOOL(ascii_only_p(state))) {
valid_encoding(state, cTrue);
return valid_encoding_;
}
Expand Down

0 comments on commit 0370512

Please sign in to comment.