Skip to content

Commit 50e4f93

Browse files
committed
Merge commit '93672d5771701f2218c7fa39e3d4f38c715e9d1a'
2 parents ed113b1 + 93672d5 commit 50e4f93

File tree

19 files changed

+115
-49
lines changed

19 files changed

+115
-49
lines changed

mruby_test/MITL

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 mruby developers
1+
Copyright (c) 2016 mruby developers
22

33
Permission is hereby granted, free of charge, to any person obtaining a
44
copy of this software and associated documentation files (the "Software"),

mruby_test/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ following command:
2626

2727
$ git clone https://github.com/mruby/mruby.git
2828

29+
You can also install and compile mruby using [ruby-install](https://github.com/postmodern/ruby-install), [ruby-build](https://github.com/rbenv/ruby-build) or [rvm](https://github.com/rvm/rvm).
30+
2931
## mruby home-page
3032

3133
The URL of the mruby home-page is: [http://www.mruby.org](http://www.mruby.org).
3234

3335
## Mailing list
3436

35-
We don't have mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
37+
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
3638

3739
## How to compile and install (mruby and gems)
3840

mruby_test/include/mruby.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
** mruby - An embeddable Ruby implementation
33
**
4-
** Copyright (c) mruby developers 2010-2015
4+
** Copyright (c) mruby developers 2010-2016
55
**
66
** Permission is hereby granted, free of charge, to any person obtaining
77
** a copy of this software and associated documentation files (the

mruby_test/mrbgems/mruby-compiler/core/parse.y

+1-1
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
13001300
}
13011301
| keyword_END '{' compstmt '}'
13021302
{
1303-
yyerror(p, "END not suported");
1303+
yyerror(p, "END not supported");
13041304
$$ = new_postexe(p, $3);
13051305
}
13061306
| command_asgn

mruby_test/mrbgems/mruby-kernel-ext/test/kernel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
assert_equal(26, Integer("0x1a"))
2323
assert_equal(930, Integer("0930", 10))
2424
assert_equal(7, Integer("111", 2))
25+
assert_equal(0, Integer("0"))
26+
assert_equal(0, Integer("00000"))
2527
assert_raise(TypeError) { Integer(nil) }
2628
end
2729

mruby_test/mrbgems/mruby-random/src/random.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ get_opt(mrb_state* mrb)
7979
mrb_get_args(mrb, "|o", &arg);
8080

8181
if (!mrb_nil_p(arg)) {
82-
if (!mrb_fixnum_p(arg)) {
82+
arg = mrb_check_convert_type(mrb, arg, MRB_TT_FIXNUM, "Fixnum", "to_int");
83+
if (mrb_nil_p(arg)) {
8384
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument type");
8485
}
85-
arg = mrb_check_convert_type(mrb, arg, MRB_TT_FIXNUM, "Fixnum", "to_int");
8686
if (mrb_fixnum(arg) < 0) {
8787
arg = mrb_fixnum_value(0 - mrb_fixnum(arg));
8888
}

mruby_test/mrbgems/mruby-string-ext/mrblib/string.rb

+23
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,29 @@ def ljust(idx, padstr = ' ')
287287
return newstr.slice(0,idx)
288288
end
289289

290+
##
291+
# call-seq:
292+
# str.rjust(integer, padstr=' ') -> new_str
293+
#
294+
# If <i>integer</i> is greater than the length of <i>str</i>, returns a new
295+
# <code>String</code> of length <i>integer</i> with <i>str</i> right justified
296+
# and padded with <i>padstr</i>; otherwise, returns <i>str</i>.
297+
#
298+
# "hello".rjust(4) #=> "hello"
299+
# "hello".rjust(20) #=> " hello"
300+
# "hello".rjust(20, '1234') #=> "123412341234123hello"
301+
def rjust(idx, padstr = ' ')
302+
if idx <= self.size
303+
return self
304+
end
305+
padsize = idx - self.size
306+
newstr = padstr.dup
307+
while newstr.size <= padsize
308+
newstr << padstr
309+
end
310+
return newstr.slice(0,padsize) + self
311+
end
312+
290313
# str.upto(other_str, exclusive=false) {|s| block } -> str
291314
# str.upto(other_str, exclusive=false) -> an_enumerator
292315
#

mruby_test/mrbgems/mruby-string-ext/test/string.rb

+7
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ def o.to_str
421421
assert_equal "hello", "hello".ljust(-3)
422422
end
423423

424+
assert('String#rjust') do
425+
assert_equal "hello", "hello".rjust(4)
426+
assert_equal " hello", "hello".rjust(20)
427+
assert_equal "123412341234123hello", "hello".rjust(20, '1234')
428+
assert_equal "hello", "hello".rjust(-3)
429+
end
430+
424431
assert('String#upto') do
425432
a = "aa"
426433
start = "aa"

mruby_test/mrblib/hash.rb

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def each_value(&block)
154154
#
155155
# ISO 15.2.13.4.23
156156
def replace(hash)
157+
raise TypeError, "can't convert argument into Hash" unless hash.respond_to?(:to_hash)
157158
self.clear
158159
hash = hash.to_hash
159160
hash.each_key{|k|

mruby_test/src/class.c

+45-35
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
466466
{
467467
char c;
468468
int i = 0;
469-
mrb_value *sp = mrb->c->stack + 1;
470469
va_list ap;
471470
int argc = mrb->c->ci->argc;
471+
int arg_i = 0;
472+
mrb_bool array_argv;
472473
mrb_bool opt = FALSE;
473474
mrb_bool given = TRUE;
474475

@@ -477,8 +478,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
477478
struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
478479

479480
argc = a->len;
480-
sp = a->ptr;
481+
array_argv = TRUE;
482+
} else {
483+
array_argv = FALSE;
481484
}
485+
486+
#define ARGV \
487+
(array_argv ? mrb_ary_ptr(mrb->c->stack[1])->ptr : (mrb->c->stack + 1))
488+
482489
while ((c = *format++)) {
483490
switch (c) {
484491
case '|': case '*': case '&': case '?':
@@ -502,7 +509,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
502509

503510
p = va_arg(ap, mrb_value*);
504511
if (i < argc) {
505-
*p = *sp++;
512+
*p = ARGV[arg_i++];
506513
i++;
507514
}
508515
}
@@ -515,7 +522,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
515522
if (i < argc) {
516523
mrb_value ss;
517524

518-
ss = *sp++;
525+
ss = ARGV[arg_i++];
519526
switch (mrb_type(ss)) {
520527
case MRB_TT_CLASS:
521528
case MRB_TT_MODULE:
@@ -537,14 +544,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
537544
p = va_arg(ap, mrb_value*);
538545
if (*format == '!') {
539546
format++;
540-
if (i < argc && mrb_nil_p(*sp)) {
541-
*p = *sp++;
547+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
548+
*p = ARGV[arg_i++];
542549
i++;
543550
break;
544551
}
545552
}
546553
if (i < argc) {
547-
*p = to_str(mrb, *sp++);
554+
*p = to_str(mrb, ARGV[arg_i++]);
548555
i++;
549556
}
550557
}
@@ -556,14 +563,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
556563
p = va_arg(ap, mrb_value*);
557564
if (*format == '!') {
558565
format++;
559-
if (i < argc && mrb_nil_p(*sp)) {
560-
*p = *sp++;
566+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
567+
*p = ARGV[arg_i++];
561568
i++;
562569
break;
563570
}
564571
}
565572
if (i < argc) {
566-
*p = to_ary(mrb, *sp++);
573+
*p = to_ary(mrb, ARGV[arg_i++]);
567574
i++;
568575
}
569576
}
@@ -575,14 +582,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
575582
p = va_arg(ap, mrb_value*);
576583
if (*format == '!') {
577584
format++;
578-
if (i < argc && mrb_nil_p(*sp)) {
579-
*p = *sp++;
585+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
586+
*p = ARGV[arg_i++];
580587
i++;
581588
break;
582589
}
583590
}
584591
if (i < argc) {
585-
*p = to_hash(mrb, *sp++);
592+
*p = to_hash(mrb, ARGV[arg_i++]);
586593
i++;
587594
}
588595
}
@@ -597,15 +604,15 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
597604
pl = va_arg(ap, mrb_int*);
598605
if (*format == '!') {
599606
format++;
600-
if (i < argc && mrb_nil_p(*sp)) {
607+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
601608
*ps = NULL;
602609
*pl = 0;
603610
i++;
604611
break;
605612
}
606613
}
607614
if (i < argc) {
608-
ss = to_str(mrb, *sp++);
615+
ss = to_str(mrb, ARGV[arg_i++]);
609616
*ps = RSTRING_PTR(ss);
610617
*pl = RSTRING_LEN(ss);
611618
i++;
@@ -620,14 +627,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
620627
ps = va_arg(ap, const char**);
621628
if (*format == '!') {
622629
format++;
623-
if (i < argc && mrb_nil_p(*sp)) {
630+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
624631
*ps = NULL;
625-
i++; sp++;
632+
i++; arg_i++;
626633
break;
627634
}
628635
}
629636
if (i < argc) {
630-
ss = to_str(mrb, *sp++);
637+
ss = to_str(mrb, ARGV[arg_i++]);
631638
*ps = mrb_string_value_cstr(mrb, &ss);
632639
i++;
633640
}
@@ -644,15 +651,15 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
644651
pl = va_arg(ap, mrb_int*);
645652
if (*format == '!') {
646653
format++;
647-
if (i < argc && mrb_nil_p(*sp)) {
654+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
648655
*pb = 0;
649656
*pl = 0;
650-
i++; sp++;
657+
i++; arg_i++;
651658
break;
652659
}
653660
}
654661
if (i < argc) {
655-
aa = to_ary(mrb, *sp++);
662+
aa = to_ary(mrb, ARGV[arg_i++]);
656663
a = mrb_ary_ptr(aa);
657664
*pb = a->ptr;
658665
*pl = a->len;
@@ -666,8 +673,8 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
666673

667674
p = va_arg(ap, mrb_float*);
668675
if (i < argc) {
669-
*p = mrb_to_flo(mrb, *sp);
670-
sp++;
676+
*p = mrb_to_flo(mrb, ARGV[arg_i]);
677+
arg_i++;
671678
i++;
672679
}
673680
}
@@ -678,13 +685,13 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
678685

679686
p = va_arg(ap, mrb_int*);
680687
if (i < argc) {
681-
switch (mrb_type(*sp)) {
688+
switch (mrb_type(ARGV[arg_i])) {
682689
case MRB_TT_FIXNUM:
683-
*p = mrb_fixnum(*sp);
690+
*p = mrb_fixnum(ARGV[arg_i]);
684691
break;
685692
case MRB_TT_FLOAT:
686693
{
687-
mrb_float f = mrb_float(*sp);
694+
mrb_float f = mrb_float(ARGV[arg_i]);
688695

689696
if (!FIXABLE(f)) {
690697
mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
@@ -696,10 +703,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
696703
mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion of String into Integer");
697704
break;
698705
default:
699-
*p = mrb_fixnum(mrb_Integer(mrb, *sp));
706+
*p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
700707
break;
701708
}
702-
sp++;
709+
arg_i++;
703710
i++;
704711
}
705712
}
@@ -709,7 +716,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
709716
mrb_bool *boolp = va_arg(ap, mrb_bool*);
710717

711718
if (i < argc) {
712-
mrb_value b = *sp++;
719+
mrb_value b = ARGV[arg_i++];
713720
*boolp = mrb_test(b);
714721
i++;
715722
}
@@ -723,7 +730,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
723730
if (i < argc) {
724731
mrb_value ss;
725732

726-
ss = *sp++;
733+
ss = ARGV[arg_i++];
727734
*symp = to_sym(mrb, ss);
728735
i++;
729736
}
@@ -738,14 +745,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
738745
type = va_arg(ap, struct mrb_data_type const*);
739746
if (*format == '!') {
740747
format++;
741-
if (i < argc && mrb_nil_p(*sp)) {
748+
if (i < argc && mrb_nil_p(ARGV[arg_i])) {
742749
*datap = 0;
743-
i++; sp++;
750+
i++; arg_i++;
744751
break;
745752
}
746753
}
747754
if (i < argc) {
748-
*datap = mrb_data_get_ptr(mrb, *sp++, type);
755+
*datap = mrb_data_get_ptr(mrb, ARGV[arg_i++], type);
749756
++i;
750757
}
751758
}
@@ -787,10 +794,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
787794
if (argc > i) {
788795
*pl = argc-i;
789796
if (*pl > 0) {
790-
*var = sp;
797+
*var = ARGV + arg_i;
791798
}
792799
i = argc;
793-
sp += *pl;
800+
arg_i += *pl;
794801
}
795802
else {
796803
*pl = 0;
@@ -803,6 +810,9 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
803810
break;
804811
}
805812
}
813+
814+
#undef ARGV
815+
806816
if (!c && argc > i) {
807817
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
808818
}

mruby_test/src/gc.c

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len)
215215
p2 = mrb_realloc_simple(mrb, p, len);
216216
if (!p2 && len) {
217217
if (mrb->gc.out_of_memory) {
218+
mrb_exc_raise(mrb, mrb_obj_value(mrb->nomem_err));
218219
/* mrb_panic(mrb); */
219220
}
220221
else {

mruby_test/src/string.c

+2
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, size_t len, int base, int b
21532153
break;
21542154
}
21552155
}
2156+
if (*(p - 1) == '0')
2157+
p--;
21562158
}
21572159
if (p == pend) {
21582160
if (badcheck) goto bad;

mruby_test/src/variable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym)
773773
klass = mrb_obj_iv_get(mrb, (struct RObject *)cls,
774774
mrb_intern_lit(mrb, "__attached__"));
775775
c = mrb_class_ptr(klass);
776-
if (c->tt == MRB_TT_CLASS) {
776+
if (c->tt == MRB_TT_CLASS || c->tt == MRB_TT_MODULE) {
777777
while (c) {
778778
if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
779779
return v;

0 commit comments

Comments
 (0)