summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mruby/compile.h6
-rw-r--r--include/mruby/string.h5
-rw-r--r--mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h4
-rw-r--r--mrbgems/mruby-compiler/core/parse.y4
-rw-r--r--mrbgems/mruby-complex/mrblib/complex.rb22
-rw-r--r--mrbgems/mruby-eval/src/eval.c2
-rw-r--r--mrbgems/mruby-math/src/math.c4
-rw-r--r--mrbgems/mruby-pack/src/pack.c17
-rw-r--r--mrbgems/mruby-pack/test/pack.rb11
-rw-r--r--mrbgems/mruby-random/src/random.c4
-rw-r--r--mrbgems/mruby-range-ext/mrblib/range.rb5
-rw-r--r--mrbgems/mruby-range-ext/src/range.c23
-rw-r--r--mrbgems/mruby-range-ext/test/range.rb28
-rw-r--r--mrbgems/mruby-rational/mrblib/rational.rb41
-rw-r--r--mrbgems/mruby-struct/mrblib/struct.rb12
-rw-r--r--mrbgems/mruby-struct/test/struct.rb7
-rw-r--r--mrbgems/mruby-time/src/time.c4
-rw-r--r--mrblib/array.rb12
-rw-r--r--mrblib/hash.rb12
-rw-r--r--mrblib/kernel.rb2
-rw-r--r--src/backtrace.c2
-rw-r--r--src/string.c25
-rw-r--r--src/vm.c1
-rw-r--r--test/t/array.rb3
-rw-r--r--test/t/hash.rb2
-rw-r--r--test/t/string.rb55
26 files changed, 187 insertions, 126 deletions
diff --git a/include/mruby/compile.h b/include/mruby/compile.h
index 8f8f2ebd7..3b25ff526 100644
--- a/include/mruby/compile.h
+++ b/include/mruby/compile.h
@@ -24,7 +24,7 @@ typedef struct mrbc_context {
mrb_sym *syms;
int slen;
char *filename;
- short lineno;
+ uint16_t lineno;
int (*partial_hook)(struct mrb_parser_state*);
void *partial_data;
struct RClass *target_class;
@@ -67,7 +67,7 @@ enum mrb_lex_state_enum {
/* saved error message */
struct mrb_parser_message {
- int lineno;
+ uint16_t lineno;
int column;
char* message;
};
@@ -119,7 +119,7 @@ struct mrb_parser_state {
#endif
mrbc_context *cxt;
mrb_sym filename_sym;
- int lineno;
+ uint16_t lineno;
int column;
enum mrb_lex_state_enum lstate;
diff --git a/include/mruby/string.h b/include/mruby/string.h
index d648d856c..d17ac1c1d 100644
--- a/include/mruby/string.h
+++ b/include/mruby/string.h
@@ -107,7 +107,10 @@ MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_EMBED_LEN_SHIFT 6
void mrb_gc_free_str(mrb_state*, struct RString*);
-MRB_API void mrb_str_modify(mrb_state*, struct RString*);
+
+MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s);
+/* mrb_str_modify() with keeping ASCII flag if set */
+MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s);
/*
* Finds the index of a substring in a string
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h
index f17f9c57d..de2f90144 100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h
@@ -6,6 +6,10 @@
#ifndef MRDBCONF_H
#define MRDBCONF_H
+#ifndef MRB_ENABLE_DEBUG_HOOK
+# error Need 'MRB_ENABLE_DEBUG_HOOK' configuration in your 'build_config.rb'
+#endif
+
/* configuration options: */
/* maximum size for command buffer */
#define MAX_COMMAND_LINE 1024
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 96a9453b6..b7a7d315d 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -233,7 +233,7 @@ parser_strdup(parser_state *p, const char *s)
#define strdup(s) parser_strdup(p, s)
static void
-dump_int(short i, char *s)
+dump_int(uint16_t i, char *s)
{
char *p = s;
char *t = s;
@@ -5419,7 +5419,7 @@ parser_yylex(parser_state *p)
tokfix(p);
if (is_float) {
#ifdef MRB_WITHOUT_FLOAT
- yywarning(p, "floating point numbers are not supported");
+ yywarning_s(p, "floating point numbers are not supported", tok(p));
pylval.nd = new_int(p, "0", 10, 0);
return tINTEGER;
#else
diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb
index 0299e7675..1a6f7e92e 100644
--- a/mrbgems/mruby-complex/mrblib/complex.rb
+++ b/mrbgems/mruby-complex/mrblib/complex.rb
@@ -104,18 +104,18 @@ class Complex < Numeric
end
alias_method :imag, :imaginary
-end
-[Fixnum, Float].each do |cls|
- [:+, :-, :*, :/, :==].each do |op|
- cls.instance_exec do
- original_operator_name = "__original_operator_#{op}_complex"
- alias_method original_operator_name, op
- define_method op do |rhs|
- if rhs.is_a? Complex
- Complex(self).send(op, rhs)
- else
- send(original_operator_name, rhs)
+ [Fixnum, Float].each do |cls|
+ [:+, :-, :*, :/, :==].each do |op|
+ cls.instance_exec do
+ original_operator_name = "__original_operator_#{op}_complex"
+ alias_method original_operator_name, op
+ define_method op do |rhs|
+ if rhs.is_a? Complex
+ Complex(self).send(op, rhs)
+ else
+ send(original_operator_name, rhs)
+ end
end
end
end
diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c
index a3b211ba2..30534aaec 100644
--- a/mrbgems/mruby-eval/src/eval.c
+++ b/mrbgems/mruby-eval/src/eval.c
@@ -235,7 +235,7 @@ create_proc_from_string(mrb_state *mrb, char *s, mrb_int len, mrb_value binding,
}
cxt = mrbc_context_new(mrb);
- cxt->lineno = (short)line;
+ cxt->lineno = (uint16_t)line;
mrbc_filename(mrb, cxt, file ? file : "(eval)");
cxt->capture_errors = TRUE;
diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c
index caa16b789..35fcd0fa6 100644
--- a/mrbgems/mruby-math/src/math.c
+++ b/mrbgems/mruby-math/src/math.c
@@ -4,6 +4,10 @@
** See Copyright Notice in mruby.h
*/
+#ifdef MRB_WITHOUT_FLOAT
+# error Conflict 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
+#endif
+
#include <mruby.h>
#include <mruby/array.h>
diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c
index 46c0cc1fe..9f091194b 100644
--- a/mrbgems/mruby-pack/src/pack.c
+++ b/mrbgems/mruby-pack/src/pack.c
@@ -1002,7 +1002,7 @@ alias:
case 'm':
dir = PACK_DIR_BASE64;
type = PACK_TYPE_STRING;
- flags |= PACK_FLAG_WIDTH;
+ flags |= PACK_FLAG_WIDTH | PACK_FLAG_COUNT2;
break;
case 'N': /* = "L>" */
dir = PACK_DIR_LONG;
@@ -1196,7 +1196,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary)
default:
break;
}
- if (dir == PACK_DIR_STR) { /* always consumes 1 entry */
+ if (dir == PACK_DIR_STR || dir == PACK_DIR_BASE64) { /* always consumes 1 entry */
aidx++;
break;
}
@@ -1249,6 +1249,9 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single)
case PACK_DIR_STR:
srcidx += unpack_a(mrb, sptr, srclen - srcidx, result, count, flags);
break;
+ case PACK_DIR_BASE64:
+ srcidx += unpack_m(mrb, sptr, srclen - srcidx, result, flags);
+ break;
}
continue;
}
@@ -1275,9 +1278,6 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single)
case PACK_DIR_QUAD:
srcidx += unpack_q(mrb, sptr, srclen - srcidx, result, flags);
break;
- case PACK_DIR_BASE64:
- srcidx += unpack_m(mrb, sptr, srclen - srcidx, result, flags);
- break;
#ifndef MRB_WITHOUT_FLOAT
case PACK_DIR_FLOAT:
srcidx += unpack_float(mrb, sptr, srclen - srcidx, result, flags);
@@ -1299,7 +1299,12 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single)
if (single) break;
}
- if (single) return RARRAY_PTR(result)[0];
+ if (single) {
+ if (RARRAY_LEN(result) > 0) {
+ return RARRAY_PTR(result)[0];
+ }
+ return mrb_nil_value();
+ }
return result;
}
diff --git a/mrbgems/mruby-pack/test/pack.rb b/mrbgems/mruby-pack/test/pack.rb
index eb24e8d1f..68ef4165f 100644
--- a/mrbgems/mruby-pack/test/pack.rb
+++ b/mrbgems/mruby-pack/test/pack.rb
@@ -35,6 +35,17 @@ assert('"YWJ...".unpack("m") should "abc..xyzABC..XYZ"') do
assert_equal ary, "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWg==\n".unpack("m")
end
+assert('["A", "B"].pack') do
+ assert_equal "QQ==\n", ["A", "B"].pack("m50")
+ assert_equal ["A"], "QQ==\n".unpack("m50")
+ assert_equal "QQ==Qg==", ["A", "B"].pack("m0 m0")
+ assert_equal ["A", "B"], "QQ==Qg==".unpack("m10 m10")
+end
+
+assert('["abc..xyzABC..XYZ"].pack("m0")') do
+ assert_pack "m0", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWg==", ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"]
+end
+
# pack & unpack 'H'
assert('["3031"].pack("H*")') do
assert_pack "H*", "01", ["3031"]
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c
index 68209840a..99f2b02e4 100644
--- a/mrbgems/mruby-random/src/random.c
+++ b/mrbgems/mruby-random/src/random.c
@@ -4,6 +4,10 @@
** See Copyright Notice in mruby.h
*/
+#ifdef MRB_WITHOUT_FLOAT
+# error Conflict 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
+#endif
+
#include <mruby.h>
#include <mruby/variable.h>
#include <mruby/class.h>
diff --git a/mrbgems/mruby-range-ext/mrblib/range.rb b/mrbgems/mruby-range-ext/mrblib/range.rb
index a149a57dc..a213beb57 100644
--- a/mrbgems/mruby-range-ext/mrblib/range.rb
+++ b/mrbgems/mruby-range-ext/mrblib/range.rb
@@ -32,7 +32,7 @@ class Range
return super if block
# fast path for numerics
- if (val.kind_of?(Fixnum) || val.kind_of?(Float)) && (last.kind_of?(Fixnum) || last.kind_of?(Float))
+ if val.kind_of?(Numeric) && last.kind_of?(Numeric)
raise TypeError if exclude_end? && !last.kind_of?(Fixnum)
return nil if val > last
return nil if val == last && exclude_end?
@@ -52,8 +52,7 @@ class Range
return super if block
# fast path for numerics
- if (val.kind_of?(Fixnum) || val.kind_of?(Float)) && (last.kind_of?(Fixnum) || last.kind_of?(Float))
- raise TypeError if exclude_end? && !last.kind_of?(Fixnum)
+ if val.kind_of?(Numeric) && last.kind_of?(Numeric)
return nil if val > last
return nil if val == last && exclude_end?
diff --git a/mrbgems/mruby-range-ext/src/range.c b/mrbgems/mruby-range-ext/src/range.c
index 1f6690904..b8c76b796 100644
--- a/mrbgems/mruby-range-ext/src/range.c
+++ b/mrbgems/mruby-range-ext/src/range.c
@@ -106,6 +106,7 @@ range_last(mrb_state *mrb, mrb_value range)
* ('a'..'z').size #=> nil
*/
+#ifndef MRB_WITHOUT_FLOAT
static mrb_value
range_size(mrb_state *mrb, mrb_value range)
{
@@ -158,6 +159,28 @@ range_size(mrb_state *mrb, mrb_value range)
}
return mrb_nil_value();
}
+#else
+static mrb_value
+range_size(mrb_state *mrb, mrb_value range)
+{
+ struct RRange *r = mrb_range_ptr(mrb, range);
+ mrb_value beg, end;
+ mrb_int excl;
+
+ beg = RANGE_BEG(r);
+ end = RANGE_END(r);
+ excl = RANGE_EXCL(r) ? 0 : 1;
+
+ if (mrb_fixnum_p(beg) && mrb_fixnum_p(end)) {
+ mrb_int a = mrb_fixnum(beg);
+ mrb_int b = mrb_fixnum(end);
+ mrb_int c = b - a + excl;
+
+ return mrb_fixnum_value(c);
+ }
+ return mrb_nil_value();
+}
+#endif /* MRB_WITHOUT_FLOAT */
void
mrb_mruby_range_ext_gem_init(mrb_state* mrb)
diff --git a/mrbgems/mruby-range-ext/test/range.rb b/mrbgems/mruby-range-ext/test/range.rb
index b56d6b58e..e2c549d04 100644
--- a/mrbgems/mruby-range-ext/test/range.rb
+++ b/mrbgems/mruby-range-ext/test/range.rb
@@ -10,6 +10,8 @@ end
assert('Range#first') do
assert_equal 10, (10..20).first
assert_equal [10, 11, 12], (10..20).first(3)
+
+ skip unless Object.const_defined?(:Float)
assert_equal [0, 1, 2], (0..Float::INFINITY).first(3)
end
@@ -23,12 +25,14 @@ end
assert('Range#size') do
assert_equal 42, (1..42).size
assert_equal 41, (1...42).size
+ assert_nil ('a'..'z').size
+
+ skip unless Object.const_defined?(:Float)
assert_equal 6, (1...6.3).size
assert_equal 5, (1...6.0).size
assert_equal 5, (1.1...6).size
assert_equal 15, (1.0..15.9).size
assert_equal Float::INFINITY, (0..Float::INFINITY).size
- assert_nil ('a'..'z').size
end
assert('Range#max') do
@@ -37,12 +41,6 @@ assert('Range#max') do
assert_equal 9, (1...10).max
assert_equal 4294967295, (0...2**32).max
- # returns the maximum value in the Float range when called with no arguments
- assert_equal 908.1111, (303.20..908.1111).max
-
- # raises TypeError when called on an exclusive range and a non Integer value
- assert_raise(TypeError) { (303.20...908.1111).max }
-
# returns nil when the endpoint is less than the start point
assert_equal nil, (100..10).max
@@ -52,6 +50,14 @@ assert('Range#max') do
# returns the endpoint when the endpoint equals the start point and the range is inclusive
assert_equal 5, (5..5).max
+ skip unless Object.const_defined?(:Float)
+
+ # returns the maximum value in the Float range when called with no arguments
+ assert_equal 908.1111, (303.20..908.1111).max
+
+ # raises TypeError when called on an exclusive range and a non Integer value
+ assert_raise(TypeError) { (303.20...908.1111).max }
+
# returns nil when the endpoint is less than the start point in a Float range
assert_equal nil, (3003.20..908.1111).max
end
@@ -89,9 +95,6 @@ assert('Range#min') do
assert_equal 1, (1..10).min
assert_equal 1, (1...10).min
- # returns the minimum value in the Float range when called with no arguments
- assert_equal 303.20, (303.20..908.1111).min
-
# returns nil when the start point is greater than the endpoint
assert_equal nil, (100..10).min
@@ -101,6 +104,11 @@ assert('Range#min') do
# returns the endpoint when the endpoint equals the start point and the range is inclusive
assert_equal 5, (5..5).max
+ skip unless Object.const_defined?(:Float)
+
+ # returns the minimum value in the Float range when called with no arguments
+ assert_equal 303.20, (303.20..908.1111).min
+
# returns nil when the start point is greater than the endpoint in a Float range
assert_equal nil, (3003.20..908.1111).max
end
diff --git a/mrbgems/mruby-rational/mrblib/rational.rb b/mrbgems/mruby-rational/mrblib/rational.rb
index 93af72b96..c0b16a6ae 100644
--- a/mrbgems/mruby-rational/mrblib/rational.rb
+++ b/mrbgems/mruby-rational/mrblib/rational.rb
@@ -89,28 +89,29 @@ module Kernel
a, b = b, a % b until b == 0
Rational._new(numerator.div(a), denominator.div(a))
end
-end
-[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
- Fixnum.instance_eval do
- original_operator_name = "__original_operator_#{op}_rational"
- alias_method original_operator_name, op
- define_method op do |rhs|
- if rhs.is_a? Rational
- Rational(self).__send__(op, rhs)
- else
- __send__(original_operator_name, rhs)
+ [:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
+ Fixnum.instance_eval do
+ original_operator_name = "__original_operator_#{op}_rational"
+ alias_method original_operator_name, op
+ define_method op do |rhs|
+ if rhs.is_a? Rational
+ Rational(self).__send__(op, rhs)
+ else
+ __send__(original_operator_name, rhs)
+ end
end
end
- end
- Float.instance_eval do
- original_operator_name = "__original_operator_#{op}_rational"
- alias_method original_operator_name, op
- define_method op do |rhs|
- if rhs.is_a? Rational
- rhs = rhs.to_f
+ Float.instance_eval do
+ original_operator_name = "__original_operator_#{op}_rational"
+ alias_method original_operator_name, op
+ define_method op do |rhs|
+ if rhs.is_a? Rational
+ rhs = rhs.to_f
+ end
+ __send__(original_operator_name, rhs)
end
- __send__(original_operator_name, rhs)
- end
- end if Object.const_defined?(:Float)
+ end if Object.const_defined?(:Float)
+ end
end
+
diff --git a/mrbgems/mruby-struct/mrblib/struct.rb b/mrbgems/mruby-struct/mrblib/struct.rb
index c5b5354be..7682ac033 100644
--- a/mrbgems/mruby-struct/mrblib/struct.rb
+++ b/mrbgems/mruby-struct/mrblib/struct.rb
@@ -46,7 +46,9 @@ if Object.const_defined?(:Struct)
ary
end
- def _inspect
+ def _inspect(recur_list)
+ return "#<struct #{self.class}:...>" if recur_list[self.object_id]
+ recur_list[self.object_id] = true
name = self.class.to_s
if name[0] == "#"
str = "#<struct "
@@ -55,7 +57,7 @@ if Object.const_defined?(:Struct)
end
buf = []
self.each_pair do |k,v|
- buf.push [k.to_s + "=" + v._inspect]
+ buf.push [k.to_s + "=" + v._inspect(recur_list)]
end
str + buf.join(", ") + ">"
end
@@ -70,11 +72,7 @@ if Object.const_defined?(:Struct)
# 15.2.18.4.10(x)
#
def inspect
- begin
- self._inspect
- rescue SystemStackError
- "#<struct #{self.class.to_s}:...>"
- end
+ self._inspect({})
end
##
diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb
index 9f2ff1cdc..93930730b 100644
--- a/mrbgems/mruby-struct/test/struct.rb
+++ b/mrbgems/mruby-struct/test/struct.rb
@@ -116,9 +116,10 @@ assert('struct dup') do
end
assert('struct inspect') do
- c = Struct.new(:m1, :m2, :m3, :m4, :m5)
- cc = c.new(1,2,3,4,5)
- assert_equal "#<struct m1=1, m2=2, m3=3, m4=4, m5=5>", cc.inspect
+ c = Struct.new(:m1, :m2, :m3, :m4, :m5, :recur)
+ cc = c.new(1,2,3,4,5,nil)
+ cc.recur = cc
+ assert_equal "#<struct m1=1, m2=2, m3=3, m4=4, m5=5, recur=#<struct #{cc.class}:...>>", cc.inspect
end
assert('Struct#length, Struct#size') do
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 34376c286..4f0afd6c6 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -4,6 +4,10 @@
** See Copyright Notice in mruby.h
*/
+#ifdef MRB_WITHOUT_FLOAT
+# error Conflict 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
+#endif
+
#include <math.h>
#include <time.h>
#include <mruby.h>
diff --git a/mrblib/array.rb b/mrblib/array.rb
index d598efc77..2b080564c 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -83,13 +83,15 @@ class Array
self
end
- def _inspect
+ def _inspect(recur_list)
size = self.size
return "[]" if size == 0
+ return "[...]" if recur_list[self.object_id]
+ recur_list[self.object_id] = true
ary=[]
i=0
while i<size
- ary<<self[i].inspect
+ ary<<self[i]._inspect(recur_list)
i+=1
end
"["+ary.join(", ")+"]"
@@ -99,11 +101,7 @@ class Array
#
# ISO 15.2.12.5.31 (x)
def inspect
- begin
- self._inspect
- rescue SystemStackError
- "[...]"
- end
+ self._inspect({})
end
# ISO 15.2.12.5.32 (x)
alias to_s inspect
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 609883ecb..b49e987c7 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -186,15 +186,17 @@ class Hash
end
# internal method for Hash inspection
- def _inspect
+ def _inspect(recur_list)
return "{}" if self.size == 0
+ return "{...}" if recur_list[self.object_id]
+ recur_list[self.object_id] = true
ary=[]
keys=self.keys
size=keys.size
i=0
while i<size
k=keys[i]
- ary<<(k._inspect + "=>" + self[k]._inspect)
+ ary<<(k._inspect(recur_list) + "=>" + self[k]._inspect(recur_list))
i+=1
end
"{"+ary.join(", ")+"}"
@@ -204,11 +206,7 @@ class Hash
#
# ISO 15.2.13.4.30 (x)
def inspect
- begin
- self._inspect
- rescue SystemStackError
- "{...}"
- end
+ self._inspect({})
end
# ISO 15.2.13.4.31 (x)
alias to_s inspect
diff --git a/mrblib/kernel.rb b/mrblib/kernel.rb
index 4700684b6..7c3ea9420 100644
--- a/mrblib/kernel.rb
+++ b/mrblib/kernel.rb
@@ -40,7 +40,7 @@ module Kernel
end
# internal method for inspect
- def _inspect
+ def _inspect(_recur_list)
self.inspect
end
diff --git a/src/backtrace.c b/src/backtrace.c
index e4f5a3064..991a67d00 100644
--- a/src/backtrace.c
+++ b/src/backtrace.c
@@ -16,7 +16,7 @@
#include <mruby/data.h>
struct backtrace_location {
- int lineno;
+ int32_t lineno;
mrb_sym method_id;
const char *filename;
};
diff --git a/src/string.c b/src/string.c
index a6aa9d906..de8a15ba9 100644
--- a/src/string.c
+++ b/src/string.c
@@ -233,7 +233,9 @@ utf8len(const char* p, const char* e)
mrb_int len;
mrb_int i;
+ if ((unsigned char)*p < 0x80) return 1;
len = utf8len_codepage[(unsigned char)*p];
+ if (len == 1) return 1;
if (len > e - p) return 1;
for (i = 1; i < len; ++i)
if ((p[i] & 0xc0) != 0x80)
@@ -485,6 +487,7 @@ mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
s->as.heap.ptr += beg;
s->as.heap.len = len;
}
+ RSTR_COPY_ASCII_FLAG(s, orig);
return mrb_obj_value(s);
}
@@ -707,10 +710,9 @@ mrb_locale_from_utf8(const char *utf8, int len)
#endif
MRB_API void
-mrb_str_modify(mrb_state *mrb, struct RString *s)
+mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s)
{
mrb_check_frozen(mrb, s);
- RSTR_UNSET_ASCII_FLAG(s);
if (RSTR_SHARED_P(s)) {
mrb_shared_string *shared = s->as.heap.aux.shared;
@@ -768,6 +770,13 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
}
}
+MRB_API void
+mrb_str_modify(mrb_state *mrb, struct RString *s)
+{
+ mrb_str_modify_keep_ascii(mrb, s);
+ RSTR_UNSET_ASCII_FLAG(s);
+}
+
MRB_API mrb_value
mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
{
@@ -901,6 +910,7 @@ mrb_str_times(mrb_state *mrb, mrb_value self)
memcpy(p + n, p, len-n);
}
p[RSTR_LEN(str2)] = '\0';
+ RSTR_COPY_ASCII_FLAG(str2, mrb_str_ptr(self));
return mrb_obj_value(str2);
}
@@ -1339,7 +1349,7 @@ mrb_str_capitalize_bang(mrb_state *mrb, mrb_value str)
mrb_bool modify = FALSE;
struct RString *s = mrb_str_ptr(str);
- mrb_str_modify(mrb, s);
+ mrb_str_modify_keep_ascii(mrb, s);
if (RSTR_LEN(s) == 0 || !RSTR_PTR(s)) return mrb_nil_value();
p = RSTR_PTR(s); pend = RSTR_PTR(s) + RSTR_LEN(s);
if (ISLOWER(*p)) {
@@ -1398,7 +1408,7 @@ mrb_str_chomp_bang(mrb_state *mrb, mrb_value str)
struct RString *s = mrb_str_ptr(str);
argc = mrb_get_args(mrb, "|S", &rs);
- mrb_str_modify(mrb, s);
+ mrb_str_modify_keep_ascii(mrb, s);
len = RSTR_LEN(s);
if (argc == 0) {
if (len == 0) return mrb_nil_value();
@@ -1497,7 +1507,7 @@ mrb_str_chop_bang(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
- mrb_str_modify(mrb, s);
+ mrb_str_modify_keep_ascii(mrb, s);
if (RSTR_LEN(s) > 0) {
mrb_int len;
#ifdef MRB_UTF8_STRING
@@ -1566,7 +1576,7 @@ mrb_str_downcase_bang(mrb_state *mrb, mrb_value str)
mrb_bool modify = FALSE;
struct RString *s = mrb_str_ptr(str);
- mrb_str_modify(mrb, s);
+ mrb_str_modify_keep_ascii(mrb, s);
p = RSTR_PTR(s);
pend = RSTR_PTR(s) + RSTR_LEN(s);
while (p < pend) {
@@ -2536,7 +2546,7 @@ mrb_str_upcase_bang(mrb_state *mrb, mrb_value str)
char *p, *pend;
mrb_bool modify = FALSE;
- mrb_str_modify(mrb, s);
+ mrb_str_modify_keep_ascii(mrb, s);
p = RSTRING_PTR(str);
pend = RSTRING_END(str);
while (p < pend) {
@@ -2836,6 +2846,7 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str)
}
}
mrb_str_cat_lit(mrb, result, "\"");
+ RSTR_COPY_ASCII_FLAG(mrb_str_ptr(result), mrb_str_ptr(str));
return result;
}
diff --git a/src/vm.c b/src/vm.c
index 0a6d4af8d..86262650e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2834,6 +2834,7 @@ mrb_top_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int sta
return mrb_vm_run(mrb, proc, self, stack_keep);
}
if (mrb->c->ci == mrb->c->cibase) {
+ mrb->c->ci->env = NULL;
return mrb_vm_run(mrb, proc, self, stack_keep);
}
ci = cipush(mrb);
diff --git a/test/t/array.rb b/test/t/array.rb
index 3df99056f..eec31d751 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -346,11 +346,12 @@ end
assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
a = [2, 3, 4, 5]
+ a[4] = a
r1 = a.to_s
r2 = a.inspect
assert_equal(r2, r1)
- assert_equal("[2, 3, 4, 5]", r1)
+ assert_equal("[2, 3, 4, 5, [...]]", r1)
end
assert('Array#==', '15.2.12.5.33') do
diff --git a/test/t/hash.rb b/test/t/hash.rb
index 156991f4a..cd47d251d 100644
--- a/test/t/hash.rb
+++ b/test/t/hash.rb
@@ -352,11 +352,13 @@ end
assert('Hash#inspect') do
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
+ h["recur"] = h
ret = h.to_s
assert_include ret, '"c"=>300'
assert_include ret, '"a"=>100'
assert_include ret, '"d"=>400'
+ assert_include ret, '"recur"=>{...}'
end
assert('Hash#rehash') do
diff --git a/test/t/string.rb b/test/t/string.rb
index cf145f97e..46cbe6e2a 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -37,52 +37,37 @@ end
assert('String#*', '15.2.10.5.5') do
assert_equal 'aaaaa', 'a' * 5
assert_equal '', 'a' * 0
- assert_equal 'aa', 'a' * 2.1
assert_raise(ArgumentError) { 'a' * -1 }
+ assert_raise(TypeError) { 'a' * '1' }
+ assert_raise(TypeError) { 'a' * nil }
+
+ skip unless Object.const_defined?(:Float)
+ assert_equal 'aa', 'a' * 2.1
assert_raise(RangeError) { '' * 1e30 }
assert_raise(RangeError) { '' * Float::INFINITY }
assert_raise(RangeError) { '' * Float::NAN }
- assert_raise(TypeError) { 'a' * '1' }
- assert_raise(TypeError) { 'a' * nil }
end
+
assert('String#[]', '15.2.10.5.6') do
# length of args is 1
- a = 'abc'[0]
- b = 'abc'[-1]
- c = 'abc'[10]
- d = 'abc'[-10]
- e = 'abc'[1.1]
+ assert_equal 'a', 'abc'[0]
+ assert_equal 'c', 'abc'[-1]
+ assert_nil 'abc'[10]
+ assert_nil 'abc'[-10]
+ assert_equal 'b', 'abc'[1.1] if Object.const_defined?(:Float)
# length of args is 2
- a1 = 'abc'[0, -1]
- b1 = 'abc'[10, 0]
- c1 = 'abc'[-10, 0]
- d1 = 'abc'[0, 0]
- e1 = 'abc'[1, 2]
-
- # args is RegExp
- # It will be tested in mrbgems.
+ assert_nil 'abc'[0, -1]
+ assert_nil 'abc'[10, 0]
+ assert_nil 'abc'[-10, 0]
+ assert_equal '', 'abc'[0, 0]
+ assert_equal 'bc', 'abc'[1, 2]
# args is String
- a3 = 'abc'['bc']
- b3 = 'abc'['XX']
-
- assert_equal 'a', 'a'
- # assert_equal 'c', b
- # assert_nil c
- # assert_nil d
- # assert_equal 'b', e
- # assert_nil a1
- # assert_nil b1
- # assert_nil c1
- # assert_equal '', d1
- # assert_equal 'bc', e1
- # assert_equal 'bc', a3
- # assert_nil b3
-
- # assert_raise(TypeError) do
- # a[nil]
- # end
+ assert_equal 'bc', 'abc'['bc']
+ assert_nil 'abc'['XX']
+
+ assert_raise(TypeError) { 'abc'[nil] }
end
assert('String#[](UTF-8)', '15.2.10.5.6') do