summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/mruby-bin-mirb/tools/mirb/mirb.c14
-rw-r--r--mrbgems/mruby-bin-mruby/tools/mruby/mruby.c8
-rw-r--r--mrbgems/mruby-hash-ext/src/hash-ext.c3
-rw-r--r--mrbgems/mruby-numeric-ext/src/numeric_ext.c1
-rw-r--r--mrbgems/mruby-random/src/mt19937ar.c1
-rw-r--r--mrbgems/mruby-string-ext/src/string.c4
-rw-r--r--mrbgems/mruby-string-utf8/src/string.c34
-rw-r--r--mrbgems/mruby-string-utf8/test/string.rb16
-rw-r--r--mrbgems/mruby-struct/src/struct.c1
-rw-r--r--mrblib/init_mrblib.c3
-rw-r--r--src/array.c1
-rw-r--r--src/backtrace.c2
-rw-r--r--src/class.c4
-rw-r--r--src/dump.c3
-rw-r--r--src/error.c2
-rw-r--r--src/etc.c2
-rw-r--r--src/gc.c1
-rw-r--r--src/object.c2
-rw-r--r--src/state.c1
-rw-r--r--src/string.c10
-rw-r--r--src/symbol.c1
-rw-r--r--src/variable.c4
-rw-r--r--src/vm.c2
-rw-r--r--tasks/mrbgem_spec.rake18
-rw-r--r--tasks/mrbgems_test.rake2
-rw-r--r--test/init_mrbtest.c3
26 files changed, 79 insertions, 64 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
index 81eef7f82..5505e8e5e 100644
--- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
@@ -8,21 +8,17 @@
#include <stdlib.h>
#include <string.h>
-
-#include <mruby.h>
+#include "mruby.h"
#include "mruby/array.h"
-#include <mruby/proc.h>
-#include <mruby/data.h>
-#include <mruby/compile.h>
+#include "mruby/proc.h"
+#include "mruby/compile.h"
+#include "mruby/string.h"
+
#ifdef ENABLE_READLINE
#include <limits.h>
#include <readline/readline.h>
#include <readline/history.h>
-#endif
-#include <mruby/string.h>
-
-#ifdef ENABLE_READLINE
static const char *history_file_name = ".mirb_history";
char history_path[PATH_MAX];
#endif
diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
index ef0ac4978..54b2f8b65 100644
--- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -1,13 +1,11 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "mruby.h"
-#include "mruby/proc.h"
#include "mruby/array.h"
-#include "mruby/string.h"
#include "mruby/compile.h"
#include "mruby/dump.h"
#include "mruby/variable.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#ifndef ENABLE_STDIO
static void
diff --git a/mrbgems/mruby-hash-ext/src/hash-ext.c b/mrbgems/mruby-hash-ext/src/hash-ext.c
index 94518924e..c6e72f451 100644
--- a/mrbgems/mruby-hash-ext/src/hash-ext.c
+++ b/mrbgems/mruby-hash-ext/src/hash-ext.c
@@ -6,11 +6,8 @@
#include "mruby.h"
#include "mruby/array.h"
-#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/khash.h"
-#include "mruby/string.h"
-#include "mruby/variable.h"
/*
* call-seq:
diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
index bb6955b45..22c1668fa 100644
--- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c
+++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
@@ -1,6 +1,5 @@
#include <limits.h>
#include "mruby.h"
-#include "mruby/numeric.h"
static mrb_value
mrb_int_chr(mrb_state *mrb, mrb_value x)
diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c
index 3246909e8..41ed2c00d 100644
--- a/mrbgems/mruby-random/src/mt19937ar.c
+++ b/mrbgems/mruby-random/src/mt19937ar.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <stdio.h>
#include "mt19937ar.h"
/* Period parameters */
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c
index 6718e734a..f194bbc0e 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -1,7 +1,7 @@
-#include "mruby.h"
-#include "mruby/string.h"
#include <ctype.h>
#include <string.h>
+#include "mruby.h"
+#include "mruby/string.h"
static mrb_value
mrb_str_getbyte(mrb_state *mrb, mrb_value str)
diff --git a/mrbgems/mruby-string-utf8/src/string.c b/mrbgems/mruby-string-utf8/src/string.c
index 5379dd3aa..c377726a2 100644
--- a/mrbgems/mruby-string-utf8/src/string.c
+++ b/mrbgems/mruby-string-utf8/src/string.c
@@ -247,6 +247,38 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str)
return mrb_str_aref(mrb, str, a1);
}
+static mrb_value
+mrb_str_reverse_bang(mrb_state *mrb, mrb_value str)
+{
+ int utf8_len = mrb_utf8_strlen(str);
+ if (utf8_len > 1) {
+ int len = RSTRING_LEN(str);
+ char *buf = (char *)mrb_malloc(mrb, len);
+ unsigned char* p = (unsigned char*)buf;
+ unsigned char* e = (unsigned char*)buf + len;
+ unsigned char* r = (unsigned char*)RSTRING_END(str);
+
+ memcpy(buf, RSTRING_PTR(str), len);
+ mrb_str_modify(mrb, mrb_str_ptr(str));
+
+ while (p<e) {
+ int clen = utf8len(p);
+ r -= clen;
+ memcpy(r, p, clen);
+ p += clen;
+ }
+ mrb_free(mrb, buf);
+ }
+
+ return str;
+}
+
+static mrb_value
+mrb_str_reverse(mrb_state *mrb, mrb_value str)
+{
+ return mrb_str_reverse_bang(mrb, mrb_str_dup(mrb, str));
+}
+
void
mrb_mruby_string_utf8_gem_init(mrb_state* mrb)
{
@@ -255,6 +287,8 @@ mrb_mruby_string_utf8_gem_init(mrb_state* mrb)
mrb_define_method(mrb, s, "size", mrb_str_size, MRB_ARGS_NONE());
mrb_define_method(mrb, s, "[]", mrb_str_aref_m, MRB_ARGS_ANY());
mrb_define_method(mrb, s, "slice", mrb_str_aref_m, MRB_ARGS_ANY());
+ mrb_define_method(mrb, s, "reverse", mrb_str_reverse, MRB_ARGS_NONE());
+ mrb_define_method(mrb, s, "reverse!", mrb_str_reverse_bang, MRB_ARGS_NONE());
}
void
diff --git a/mrbgems/mruby-string-utf8/test/string.rb b/mrbgems/mruby-string-utf8/test/string.rb
index 4ee815a36..fc21c0a93 100644
--- a/mrbgems/mruby-string-utf8/test/string.rb
+++ b/mrbgems/mruby-string-utf8/test/string.rb
@@ -9,3 +9,19 @@ assert('String#[]') do
assert_equal "んに", "こんにちわ世界"[1,2]
assert_equal "世", "こんにちわ世界"["世"]
end
+
+assert('String#reverse', '15.2.10.5.29') do
+ a = 'こんにちわ世界!'
+ a.reverse
+
+ assert_equal 'こんにちわ世界!', a
+ assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse
+end
+
+assert('String#reverse!', '15.2.10.5.30') do
+ a = 'こんにちわ世界!'
+ a.reverse!
+
+ assert_equal '!界世わちにんこ', a
+ assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse!
+end
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 309684422..e6d3b0796 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -10,7 +10,6 @@
#include "mruby/array.h"
#include "mruby/string.h"
#include "mruby/class.h"
-#include "mruby/data.h"
#include "mruby/variable.h"
#define RSTRUCT_ARY(st) mrb_ary_ptr(st)
diff --git a/mrblib/init_mrblib.c b/mrblib/init_mrblib.c
index f65b185a3..dc902e9f9 100644
--- a/mrblib/init_mrblib.c
+++ b/mrblib/init_mrblib.c
@@ -1,8 +1,5 @@
#include "mruby.h"
#include "mruby/irep.h"
-#include "mruby/dump.h"
-#include "mruby/string.h"
-#include "mruby/proc.h"
extern const uint8_t mrblib_irep[];
diff --git a/src/array.c b/src/array.c
index 67351bb9b..0fcbffcd8 100644
--- a/src/array.c
+++ b/src/array.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <limits.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
diff --git a/src/backtrace.c b/src/backtrace.c
index 76b5961b9..8edc27776 100644
--- a/src/backtrace.c
+++ b/src/backtrace.c
@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
+#include <stdarg.h>
#include "mruby.h"
#include "mruby/variable.h"
#include "mruby/proc.h"
@@ -11,7 +12,6 @@
#include "mruby/string.h"
#include "mruby/class.h"
#include "mruby/debug.h"
-#include <stdarg.h>
typedef void (*output_stream_func)(mrb_state*, void*, int, const char*, ...);
diff --git a/src/class.c b/src/class.c
index d29089253..4f246655e 100644
--- a/src/class.c
+++ b/src/class.c
@@ -4,9 +4,9 @@
** See Copyright Notice in mruby.h
*/
-#include "mruby.h"
-#include <stdarg.h>
#include <ctype.h>
+#include <stdarg.h>
+#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/numeric.h"
diff --git a/src/dump.c b/src/dump.c
index 204e441d1..37cafb134 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -4,10 +4,9 @@
** See Copyright Notice in mruby.h
*/
+#include <ctype.h>
#include <string.h>
#include "mruby/dump.h"
-#include <ctype.h>
-
#include "mruby/string.h"
#include "mruby/irep.h"
#include "mruby/numeric.h"
diff --git a/src/error.c b/src/error.c
index ced50e3e1..68278f426 100644
--- a/src/error.c
+++ b/src/error.c
@@ -7,10 +7,8 @@
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
-#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
-#include "mruby/class.h"
#include "mruby/irep.h"
#include "mruby/proc.h"
#include "mruby/string.h"
diff --git a/src/etc.c b/src/etc.c
index 82394891f..8d19a1eab 100644
--- a/src/etc.c
+++ b/src/etc.c
@@ -6,8 +6,6 @@
#include "mruby.h"
#include "mruby/string.h"
-#include "error.h"
-#include "mruby/numeric.h"
#include "mruby/data.h"
#include "mruby/class.h"
diff --git a/src/gc.c b/src/gc.c
index 9245adbfb..63301d5cd 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include "mruby.h"
diff --git a/src/object.c b/src/object.c
index daa76a03f..ce7489070 100644
--- a/src/object.c
+++ b/src/object.c
@@ -5,11 +5,9 @@
*/
#include "mruby.h"
-#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
-#include "error.h"
mrb_bool
mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
diff --git a/src/state.c b/src/state.c
index f25d8c8bf..a8853fe72 100644
--- a/src/state.c
+++ b/src/state.c
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <string.h>
#include "mruby.h"
-#include "mruby/class.h"
#include "mruby/irep.h"
#include "mruby/variable.h"
#include "mruby/debug.h"
diff --git a/src/string.c b/src/string.c
index e8c37180d..7d0cdaf0d 100644
--- a/src/string.c
+++ b/src/string.c
@@ -107,16 +107,6 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
return str;
}
-static inline void
-str_mod_check(mrb_state *mrb, mrb_value str, char *p, mrb_int len)
-{
- struct RString *s = mrb_str_ptr(str);
-
- if (s->ptr != p || s->len != len) {
- mrb_raise(mrb, E_RUNTIME_ERROR, "string modified");
- }
-}
-
#define mrb_obj_alloc_string(mrb) ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class))
/* char offset to byte offset */
diff --git a/src/symbol.c b/src/symbol.c
index 4e78ade66..4d6a8eb7a 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -5,7 +5,6 @@
*/
#include <ctype.h>
-#include <limits.h>
#include <string.h>
#include "mruby.h"
#include "mruby/khash.h"
diff --git a/src/variable.c b/src/variable.c
index 921d465a2..5ced2dfbd 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -4,14 +4,12 @@
** See Copyright Notice in mruby.h
*/
+#include <ctype.h>
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/proc.h"
#include "mruby/string.h"
-#include "mruby/variable.h"
-#include "error.h"
-#include <ctype.h>
typedef int (iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*);
diff --git a/src/vm.c b/src/vm.c
index 69f01fe1e..a12763b33 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <string.h>
#include <setjmp.h>
#include <stddef.h>
#include <stdarg.h>
@@ -13,7 +12,6 @@
#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/irep.h"
-#include "mruby/numeric.h"
#include "mruby/proc.h"
#include "mruby/range.h"
#include "mruby/string.h"
diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake
index 70c44ed5e..e9caf1d3a 100644
--- a/tasks/mrbgem_spec.rake
+++ b/tasks/mrbgem_spec.rake
@@ -149,7 +149,7 @@ module MRuby
end
end # generate_gem_init
- def print_gem_init_header(f)
+ def print_gem_comment(f)
f.puts %Q[/*]
f.puts %Q[ * This file is loading the irep]
f.puts %Q[ * Ruby GEM code.]
@@ -158,15 +158,23 @@ module MRuby
f.puts %Q[ * This file was generated!]
f.puts %Q[ * All manual changes will get lost.]
f.puts %Q[ */]
+ end
+
+ def print_gem_init_header(f)
+ print_gem_comment(f)
+ f.puts %Q[#include <stdlib.h>] unless rbfiles.empty?
+ f.puts %Q[#include "mruby.h"]
+ f.puts %Q[#include "mruby/irep.h"] unless rbfiles.empty?
+ end
+
+ def print_gem_test_header(f)
+ print_gem_comment(f)
f.puts %Q[#include <stdlib.h>]
f.puts %Q[#include "mruby.h"]
+ f.puts %Q[#include "mruby/array.h"]
f.puts %Q[#include "mruby/irep.h"]
- f.puts %Q[#include "mruby/dump.h"]
f.puts %Q[#include "mruby/string.h"]
- f.puts %Q[#include "mruby/proc.h"]
f.puts %Q[#include "mruby/variable.h"]
- f.puts %Q[#include "mruby/array.h"]
- f.puts %Q[#include "mruby/hash.h"]
end
def version_ok?(req_versions)
diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake
index cf907a510..36c8e84b7 100644
--- a/tasks/mrbgems_test.rake
+++ b/tasks/mrbgems_test.rake
@@ -5,7 +5,7 @@ MRuby.each_target do
file test_rbobj => g.test_rbireps
file g.test_rbireps => [g.test_rbfiles].flatten + [g.build.mrbcfile] do |t|
open(t.name, 'w') do |f|
- g.print_gem_init_header(f)
+ g.print_gem_test_header(f)
test_preload = [g.dir, MRUBY_ROOT].map {|dir|
File.expand_path(g.test_preload, dir)
}.find {|file| File.exist?(file) }
diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c
index 3b8f9129e..8d01624f0 100644
--- a/test/init_mrbtest.c
+++ b/test/init_mrbtest.c
@@ -1,9 +1,6 @@
#include <stdlib.h>
#include "mruby.h"
#include "mruby/irep.h"
-#include "mruby/dump.h"
-#include "mruby/string.h"
-#include "mruby/proc.h"
extern const uint8_t mrbtest_irep[];