summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mruby.h1
-rw-r--r--src/array.c14
-rw-r--r--src/object.c13
-rw-r--r--src/time.c2
-rw-r--r--src/vm.c17
-rw-r--r--test/t/kernel.rb9
-rw-r--r--test/t/module.rb16
-rw-r--r--test/t/time.rb10
8 files changed, 48 insertions, 34 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 3063358f1..2f2f3753d 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -216,6 +216,7 @@ void mrb_p(mrb_state*, mrb_value);
mrb_int mrb_obj_id(mrb_value obj);
mrb_sym mrb_to_id(mrb_state *mrb, mrb_value name);
+int mrb_obj_eq(mrb_state*, mrb_value, mrb_value);
int mrb_obj_equal(mrb_state*, mrb_value, mrb_value);
int mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
diff --git a/src/array.c b/src/array.c
index 15b6df0f2..fa43bdd35 100644
--- a/src/array.c
+++ b/src/array.c
@@ -37,16 +37,13 @@ ary_new_capa(mrb_state *mrb, int capa)
mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
}
#endif
- if (capa < ARY_DEFAULT_LEN) {
- capa = ARY_DEFAULT_LEN;
- }
blen = capa * sizeof(mrb_value) ;
if (blen < capa) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
}
a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
- a->ptr = (mrb_value *)mrb_calloc(mrb, blen, 1);
+ a->ptr = (mrb_value *)mrb_malloc(mrb, blen);
a->aux.capa = capa;
a->len = 0;
@@ -859,9 +856,11 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self)
{
struct RArray *a = mrb_ary_ptr(self);
- a->len = 0;
ary_modify(mrb, a);
- ary_shrink_capa(mrb, a);
+ a->len = 0;
+ a->aux.capa = 0;
+ mrb_free(mrb, a->ptr);
+ a->ptr = 0;
return self;
}
@@ -1054,7 +1053,8 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
mrb_value ary2;
mrb_get_args(mrb, "o", &ary2);
- if (mrb_obj_equal(mrb, ary1,ary2)) return mrb_true_value();
+ if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
+ if (SPECIAL_CONST_P(ary2)) return mrb_false_value();
if (mrb_type(ary2) != MRB_TT_ARRAY) {
if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) {
return mrb_false_value();
diff --git a/src/object.c b/src/object.c
index 4c494101a..5130f3d54 100644
--- a/src/object.c
+++ b/src/object.c
@@ -47,17 +47,8 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE;
result = mrb_funcall(mrb, obj1, "==", 1, obj2);
- if (mrb_nil_p(result)) {
- return FALSE;
- }
- else {
- if (mrb_type(result) == MRB_TT_TRUE) {
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
+ if (mrb_test(result)) return TRUE;
+ return FALSE;
}
/*
diff --git a/src/time.c b/src/time.c
index 3dd56c6a9..085c4f30f 100644
--- a/src/time.c
+++ b/src/time.c
@@ -28,13 +28,11 @@
#ifdef _WIN32
/* Win32 platform do not provide gmtime_r/localtime_r; emulate them using gmtime_s/localtime_s */
-#if _MVC_VER
#define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL)
#define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tm) : NULL)
#else
#define NO_GMTIME_R
#endif
-#endif
/* timegm(3) */
/* mktime() creates tm structure for localtime; timegm() is for UTF time */
diff --git a/src/vm.c b/src/vm.c
index 256ae8ef4..75a4cd442 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1495,7 +1495,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_EQ) {
/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/
- OP_CMP(==);
+ int a = GETARG_A(i);
+ if (mrb_obj_eq(mrb, regs[a], regs[a+1])) {
+ SET_TRUE_VALUE(regs[a]);
+ }
+ else {
+ OP_CMP(==);
+ }
NEXT;
}
@@ -1525,14 +1531,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_ARRAY) {
/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
- int b = GETARG_B(i);
- int lim = b+GETARG_C(i);
- mrb_value ary = mrb_ary_new_capa(mrb, GETARG_C(i));
-
- while (b < lim) {
- mrb_ary_push(mrb, ary, regs[b++]);
- }
- regs[GETARG_A(i)] = ary;
+ regs[GETARG_A(i)] = mrb_ary_new_from_values(mrb, GETARG_C(i), &regs[GETARG_B(i)]);
mrb->arena_idx = ai;
NEXT;
}
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index 25404cd33..1342f0254 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -213,8 +213,8 @@ assert('Kernel#hash', '15.3.1.3.15') do
end
assert('Kernel#inspect', '15.3.1.3.17') do
- s = nil.inspect
- s.class == String and s == "nil"
+ s = inspect
+ s.class == String and s == "main"
end
assert('Kernel#instance_variables', '15.3.1.3.23') do
@@ -270,7 +270,7 @@ assert('Kernel#methods', '15.3.1.3.31') do
end
assert('Kernel#nil?', '15.3.1.3.32') do
- nil.nil? == true
+ nil? == false
end
assert('Kernel#object_id', '15.3.1.3.33') do
@@ -337,6 +337,5 @@ assert('Kernel#singleton_methods', '15.3.1.3.45') do
end
assert('Kernel#to_s', '15.3.1.3.46') do
- # TODO looks strange..
- nil.to_s == ''
+ to_s == '#<Object:0x0>'
end
diff --git a/test/t/module.rb b/test/t/module.rb
index 5b847e8b7..1827d5758 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -105,3 +105,19 @@ assert('Module#included_modules', '15.2.2.4.30') do
r = Test4includedModules2.included_modules
r.class == Array and r.include?(Test4includedModules)
end
+
+# Not ISO specified
+
+assert('Module#to_s') do
+ module Test4to_sModules
+ end
+
+ Test4to_sModules.to_s == 'Test4to_sModules'
+end
+
+assert('Module#inspect') do
+ module Test4to_sModules
+ end
+
+ Test4to_sModules.inspect == 'Test4to_sModules'
+end
diff --git a/test/t/time.rb b/test/t/time.rb
index 6140be1a8..ba4ceedc4 100644
--- a/test/t/time.rb
+++ b/test/t/time.rb
@@ -187,5 +187,15 @@ if Object.const_defined?(:Time)
assert('Time#zone', '15.2.19.7.33') do
Time.at(1300000000.0).utc.zone == 'UTC'
end
+
+ # Not ISO specified
+
+ assert('Time#to_s') do
+ Time.at(1300000000.0).utc.to_s == "Sun Mar 13 07:06:40 UTC 2011"
+ end
+
+ assert('Time#inspect') do
+ Time.at(1300000000.0).utc.inspect == "Sun Mar 13 07:06:40 UTC 2011"
+ end
end