From 79a7f181507674a6e56846d1dc82fa97341ec544 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 16 Apr 2019 19:23:30 +0900 Subject: Avoid potential zero size array declaration; fix #4382 --- tasks/toolchains/clang.rake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tasks') diff --git a/tasks/toolchains/clang.rake b/tasks/toolchains/clang.rake index 2832dad5f..7d0fe6a45 100644 --- a/tasks/toolchains/clang.rake +++ b/tasks/toolchains/clang.rake @@ -3,7 +3,9 @@ MRuby::Toolchain.new(:clang) do |conf, _params| [conf.cc, conf.objc, conf.asm].each do |cc| cc.command = ENV['CC'] || 'clang' + cc.flags << '-Wzero-length-array' unless ENV['CFLAGS'] end conf.cxx.command = ENV['CXX'] || 'clang++' + conf.cxx.flags << '-Wzero-length-array' unless ENV['CXXFLAGS'] || ENV['CFLAGS'] conf.linker.command = ENV['LD'] || ENV['CXX'] || ENV['CC'] || 'clang' end -- cgit v1.2.3 From 1e9cb74cc6dd2fbe1b68edf3b73c7acfe7fc7831 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sat, 3 Aug 2019 17:46:11 +0900 Subject: Change second argument to `%l` of `mrb_vformat()` to `size_t` from `mrb_int` - `size_t` is more commonly used. - `len` argument of `mrb_str_new()` is `size_t`. NOTE: The test for `%l` is temporarily disabled because adding a new type to `mrbgems/mruby-test/vformat.c` causes an error (memory error?) on Visual Studio 2017 in AppVeyor. --- mrbgems/mruby-test/vformat.c | 7 +++++++ src/error.c | 7 ++++--- tasks/toolchains/visualcpp.rake | 2 +- test/t/vformat.rb | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'tasks') diff --git a/mrbgems/mruby-test/vformat.c b/mrbgems/mruby-test/vformat.c index e02383f77..6e0c2887f 100644 --- a/mrbgems/mruby-test/vformat.c +++ b/mrbgems/mruby-test/vformat.c @@ -14,6 +14,7 @@ typedef mrb_int mrb_float; int d; \ mrb_float f; \ mrb_int i; \ +/* size_t l; */\ mrb_sym n; \ char *s; \ struct RClass *C @@ -35,6 +36,7 @@ typedef enum { ARG_d, ARG_f, ARG_i, +/* ARG_l,*/ ARG_n, ARG_s, ARG_C, @@ -80,6 +82,7 @@ native_initialize(mrb_state *mrb, mrb_value self) case ARG_d: data.d = (int)mrb_fixnum(obj); break; case ARG_f: data.f = mrb_float(obj); break; case ARG_i: data.i = mrb_fixnum(obj); break; +/* case ARG_l: data.l = (size_t)mrb_fixnum(obj); break;*/ case ARG_n: data.n = mrb_symbol(obj); break; case ARG_s: data.s = (char*)mrb_malloc(mrb, RSTRING_LEN(obj) + 1); memcpy(data.s, RSTRING_PTR(obj), RSTRING_LEN(obj)); @@ -97,6 +100,7 @@ NATIVE_DEFINE_TYPE_FUNC(c) NATIVE_DEFINE_TYPE_FUNC(d) NATIVE_DEFINE_TYPE_FUNC(f) NATIVE_DEFINE_TYPE_FUNC(i) +/*NATIVE_DEFINE_TYPE_FUNC(l)*/ NATIVE_DEFINE_TYPE_FUNC(n) NATIVE_DEFINE_TYPE_FUNC(s) NATIVE_DEFINE_TYPE_FUNC(C) @@ -133,6 +137,7 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class, VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, d) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, f) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, i) : \ +/* VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, l) : */\ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, n) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, s) : \ VF_FORMAT2_COND_EXPR(fmt, vf_args, vf_args+1, C) : \ @@ -146,6 +151,7 @@ arg_from_obj(mrb_state *mrb, mrb_value obj, struct RClass *native_class, VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, d) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, f) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, i) : \ +/* VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, l) : */\ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, n) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, s) : \ VF_FORMAT_TYPED_COND_EXPR(fmt, n_arg, type_a, v1, C) : \ @@ -186,6 +192,7 @@ mrb_init_test_vformat(mrb_state *mrb) NATIVE_DEFINE_TYPE_METHOD(d); NATIVE_DEFINE_TYPE_METHOD(f); NATIVE_DEFINE_TYPE_METHOD(i); +/* NATIVE_DEFINE_TYPE_METHOD(l);*/ NATIVE_DEFINE_TYPE_METHOD(n); NATIVE_DEFINE_TYPE_METHOD(s); NATIVE_DEFINE_TYPE_METHOD(C); diff --git a/src/error.c b/src/error.c index 3ee137c95..0ca7f5917 100644 --- a/src/error.c +++ b/src/error.c @@ -285,7 +285,7 @@ mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg) * d | int | * f | mrb_float | * i | mrb_int | - * l | char*, mrb_int | Arguments are string and length. + * l | char*, size_t | Arguments are string and length. * n | mrb_sym | * s | char* | Argument is NUL terminated string. * t | mrb_value | Convert to type (class) of object. @@ -303,8 +303,9 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) { const char *chars, *p = format, *b = format, *e; char ch; + size_t len; + mrb_int i; struct RClass *cls; - mrb_int len, i; mrb_bool inspect = FALSE; mrb_value result = mrb_str_new_capa(mrb, 128), obj, str; int ai = mrb_gc_arena_save(mrb); @@ -335,7 +336,7 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) #endif case 'l': chars = va_arg(ap, char*); - len = va_arg(ap, mrb_int); + len = va_arg(ap, size_t); L_cat: if (inspect) { obj = mrb_str_new(mrb, chars, len); diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake index 6275059bb..9bf0f085e 100644 --- a/tasks/toolchains/visualcpp.rake +++ b/tasks/toolchains/visualcpp.rake @@ -2,7 +2,7 @@ MRuby::Toolchain.new(:visualcpp) do |conf, _params| conf.cc do |cc| cc.command = ENV['CC'] || 'cl.exe' # C4013: implicit function declaration - cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)] + cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /Zm2000 /MD /O2 /D_CRT_SECURE_NO_WARNINGS)] cc.defines = %w(MRB_STACK_EXTEND_DOUBLING) cc.option_include_path = '/I%s' cc.option_define = '/D%s' diff --git a/test/t/vformat.rb b/test/t/vformat.rb index e99616064..679f30407 100644 --- a/test/t/vformat.rb +++ b/test/t/vformat.rb @@ -41,7 +41,7 @@ assert('mrb_vformat') do assert_format '`t`: Fixnum', ['`t`: %t', 0] assert_format '`t`: Hash', ['`t`: %t', k: "value"] assert_format_pattern '#>>', ['%t', sclass({})] - assert_format 'string and length', ['string %l length', n.s('andante'), n.i(3)] +# assert_format 'string and length', ['string %l length', n.s('andante'), n.l(3)] assert_format '`n`: sym', ['`n`: %n', n.n(:sym)] assert_format '%C文字列%', ['%s', n.s('%C文字列%')] assert_format '`C`: Kernel module', ['`C`: %C module', n.C(Kernel)] @@ -65,7 +65,7 @@ assert('mrb_vformat') do assert_format 'percent: %', ['percent: %%'] assert_format '"I": inspect char', ['%!c: inspect char', n.c(?I)] assert_format '709: inspect mrb_int', ['%!d: inspect mrb_int', n.i(709)] - assert_format '"a\x00b\xff"', ['%!l', n.s("a\000b\xFFc\000d"), n.i(4)] +# assert_format '"a\x00b\xff"', ['%!l', n.s("a\000b\xFFc\000d"), n.l(4)] assert_format ':"&.": inspect symbol', ['%!n: inspect symbol', n.n(:'&.')] assert_format 'inspect "String"', ['inspect %!v', 'String'] assert_format 'inspect Array: [1, :x, {}]', ['inspect Array: %!v', [1,:x,{}]] -- cgit v1.2.3 From 334afb167c0a1fa478a53c3844f37c0f1fd866dd Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Mon, 5 Aug 2019 12:41:15 +0900 Subject: Use new specifiers/modifiers of `mrb_vfromat()` The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in my environment than before the introduction of new specifiers/modifiers (5116789a) with this change. ------------+-------------------+-------------------+-------- BINARY | BEFORE (5116789a) | AFTER (This PR) | RATIO ------------+-------------------+-------------------+-------- mruby | 593416 bytes | 593208 bytes | -0.04% libmruby.a | 769048 bytes | 767264 bytes | -0.23% ------------+-------------------+-------------------+-------- BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613, so I put it back. --- mrbgems/mruby-compiler/core/codegen.c | 2 +- mrbgems/mruby-compiler/core/parse.y | 2 +- mrbgems/mruby-complex/src/complex.c | 4 +-- mrbgems/mruby-eval/src/eval.c | 14 ++++----- mrbgems/mruby-io/src/file.c | 6 ++-- mrbgems/mruby-io/src/io.c | 20 +++++-------- mrbgems/mruby-io/test/mruby_io_test.c | 6 ++-- mrbgems/mruby-kernel-ext/src/kernel.c | 13 ++++---- mrbgems/mruby-math/src/math.c | 3 +- mrbgems/mruby-metaprog/src/metaprog.c | 11 +++---- mrbgems/mruby-method/src/method.c | 12 ++------ mrbgems/mruby-pack/src/pack.c | 13 ++++---- mrbgems/mruby-socket/src/socket.c | 8 ++--- mrbgems/mruby-sprintf/src/sprintf.c | 36 +++++++++++----------- mrbgems/mruby-string-ext/src/string.c | 11 ++++--- mrbgems/mruby-struct/src/struct.c | 28 ++++++++---------- mrbgems/mruby-time/src/time.c | 4 +-- src/array.c | 10 +++---- src/backtrace.c | 4 +-- src/class.c | 56 +++++++++++++++-------------------- src/error.c | 11 ++++--- src/etc.c | 12 ++++---- src/gc.c | 2 +- src/kernel.c | 8 ++--- src/numeric.c | 8 ++--- src/object.c | 37 ++++++----------------- src/proc.c | 4 +-- src/range.c | 2 +- src/string.c | 20 ++++++------- src/variable.c | 5 ++-- src/vm.c | 14 ++++----- tasks/toolchains/visualcpp.rake | 2 +- 32 files changed, 163 insertions(+), 225 deletions(-) (limited to 'tasks') diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index ed8fc3150..5cade970c 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -2373,7 +2373,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_value str; int sym; - str = mrb_format(mrb, "$%S", mrb_fixnum_value(nint(tree))); + str = mrb_format(mrb, "$%d", nint(tree)); sym = new_sym(s, mrb_intern_str(mrb, str)); genop_2(s, OP_GETGV, cursp(), sym); push(); diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index f6d543c5d..3a55c8e70 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -3831,7 +3831,7 @@ backref_error(parser_state *p, node *n) yyerror_c(p, "can't set variable $", (char)intn(n->cdr)); } else { - mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %S", mrb_fixnum_value(c)); + mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %d", c); } } diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index aa2afc2ce..a87b95dea 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -101,7 +101,7 @@ complex_to_f(mrb_state *mrb, mrb_value self) struct mrb_complex *p = complex_ptr(mrb, self); if (p->imaginary != 0) { - mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %S into Float", self); + mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self); } return mrb_float_value(mrb, p->real); @@ -113,7 +113,7 @@ complex_to_i(mrb_state *mrb, mrb_value self) struct mrb_complex *p = complex_ptr(mrb, self); if (p->imaginary != 0) { - mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %S into Float", self); + mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self); } return mrb_int_value(mrb, p->real); } diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c index 30534aaec..e8f1d3e95 100644 --- a/mrbgems/mruby-eval/src/eval.c +++ b/mrbgems/mruby-eval/src/eval.c @@ -254,15 +254,15 @@ create_proc_from_string(mrb_state *mrb, char *s, mrb_int len, mrb_value binding, mrb_value str; if (file) { - str = mrb_format(mrb, " file %S line %S: %S", - mrb_str_new_cstr(mrb, file), - mrb_fixnum_value(p->error_buffer[0].lineno), - mrb_str_new_cstr(mrb, p->error_buffer[0].message)); + str = mrb_format(mrb, "file %s line %d: %s", + file, + p->error_buffer[0].lineno, + p->error_buffer[0].message); } else { - str = mrb_format(mrb, " line %S: %S", - mrb_fixnum_value(p->error_buffer[0].lineno), - mrb_str_new_cstr(mrb, p->error_buffer[0].message)); + str = mrb_format(mrb, "line %d: %s", + p->error_buffer[0].lineno, + p->error_buffer[0].message); } mrb_parser_free(p); mrbc_context_free(mrb, cxt); diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c index 243f634b4..5e6c849f0 100644 --- a/mrbgems/mruby-io/src/file.c +++ b/mrbgems/mruby-io/src/file.c @@ -146,7 +146,7 @@ mrb_file_s_rename(mrb_state *mrb, mrb_value obj) #endif mrb_locale_free(src); mrb_locale_free(dst); - mrb_sys_fail(mrb, RSTRING_PTR(mrb_format(mrb, "(%S, %S)", from, to))); + mrb_sys_fail(mrb, RSTRING_PTR(mrb_format(mrb, "(%v, %v)", from, to))); } mrb_locale_free(src); mrb_locale_free(dst); @@ -307,7 +307,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) } home = pwd->pw_dir; if (!mrb_file_is_absolute_path(home)) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "non-absolute home of ~%S", username); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "non-absolute home of ~%v", username); } } home = mrb_locale_from_utf8(home, -1); @@ -398,7 +398,7 @@ mrb_file_s_symlink(mrb_state *mrb, mrb_value klass) if (symlink(src, dst) == -1) { mrb_locale_free(src); mrb_locale_free(dst); - mrb_sys_fail(mrb, mrb_str_to_cstr(mrb, mrb_format(mrb, "(%S, %S)", from, to))); + mrb_sys_fail(mrb, RSTRING_PTR(mrb_format(mrb, "(%v, %v)", from, to))); } mrb_locale_free(src); mrb_locale_free(dst); diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c index 99441f16b..a0b6c6780 100644 --- a/mrbgems/mruby-io/src/io.c +++ b/mrbgems/mruby-io/src/io.c @@ -127,7 +127,7 @@ mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode) flags |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE; break; default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %S", mrb_str_new_cstr(mrb, mode)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode); } while (*m) { @@ -141,7 +141,7 @@ mrb_io_modestr_to_flags(mrb_state *mrb, const char *mode) case ':': /* XXX: PASSTHROUGH*/ default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %S", mrb_str_new_cstr(mrb, mode)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal access mode %s", mode); } } @@ -191,8 +191,7 @@ mrb_fd_cloexec(mrb_state *mrb, int fd) flags = fcntl(fd, F_GETFD); if (flags == -1) { - mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%S, F_GETFD) failed: %S", - mrb_fixnum_value(fd), mrb_fixnum_value(errno)); + mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%d, F_GETFD) failed: %d", fd, errno); } if (fd <= 2) { flags2 = flags & ~FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */ @@ -202,8 +201,7 @@ mrb_fd_cloexec(mrb_state *mrb, int fd) } if (flags != flags2) { if (fcntl(fd, F_SETFD, flags2) == -1) { - mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%S, F_SETFD, %S) failed: %S", - mrb_fixnum_value(fd), mrb_fixnum_value(flags2), mrb_fixnum_value(errno)); + mrb_bug(mrb, "mrb_fd_cloexec: fcntl(%d, F_SETFD, %d) failed: %d", fd, flags2, errno); } } #endif @@ -381,7 +379,7 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass) CloseHandle(ifd[1]); CloseHandle(ofd[0]); CloseHandle(ofd[1]); - mrb_raisef(mrb, E_IO_ERROR, "command not found: %S", cmd); + mrb_raisef(mrb, E_IO_ERROR, "command not found: %v", cmd); } CloseHandle(pi.hThread); CloseHandle(ifd[0]); @@ -494,7 +492,7 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass) close(fd); } mrb_proc_exec(pname); - mrb_raisef(mrb, E_IO_ERROR, "command not found: %S", cmd); + mrb_raisef(mrb, E_IO_ERROR, "command not found: %v", cmd); _exit(127); } result = mrb_nil_value(); @@ -783,9 +781,7 @@ reopen: } } - emsg = mrb_format(mrb, "open %S", mrb_str_new_cstr(mrb, pathname)); - mrb_str_modify(mrb, mrb_str_ptr(emsg)); - mrb_sys_fail(mrb, RSTRING_PTR(emsg)); + mrb_sys_fail(mrb, RSTRING_PTR(mrb_format(mrb, "open %s", pathname))); } mrb_locale_free(fname); @@ -1068,7 +1064,7 @@ mrb_io_s_select(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "*", &argv, &argc); if (argc < 1 || argc > 4) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%S for 1..4)", mrb_fixnum_value(argc)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%i for 1..4)", argc); } timeout = mrb_nil_value(); diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c index 3312d6c7e..2c8a75fc9 100644 --- a/mrbgems/mruby-io/test/mruby_io_test.c +++ b/mrbgems/mruby-io/test/mruby_io_test.c @@ -136,9 +136,9 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self) sun0.sun_family = AF_UNIX; snprintf(sun0.sun_path, sizeof(sun0.sun_path), "%s", socketname); if (bind(fd3, (struct sockaddr *)&sun0, sizeof(sun0)) == -1) { - mrb_raisef(mrb, E_RUNTIME_ERROR, "can't bind AF_UNIX socket to %S: %S", - mrb_str_new_cstr(mrb, sun0.sun_path), - mrb_fixnum_value(errno)); + mrb_raisef(mrb, E_RUNTIME_ERROR, "can't bind AF_UNIX socket to %s: %d", + sun0.sun_path, + errno); } close(fd3); #endif diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c index 8e7e03c56..376751e10 100644 --- a/mrbgems/mruby-kernel-ext/src/kernel.c +++ b/mrbgems/mruby-kernel-ext/src/kernel.c @@ -31,22 +31,21 @@ mrb_f_caller(mrb_state *mrb, mrb_value self) } } else { - v = mrb_to_int(mrb, v); - lev = mrb_fixnum(v); + lev = mrb_int(mrb, v); if (lev < 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%S)", v); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%v)", v); } n = bt_len - lev; } break; case 2: - lev = mrb_fixnum(mrb_to_int(mrb, v)); - n = mrb_fixnum(mrb_to_int(mrb, length)); + lev = mrb_int(mrb, v); + n = mrb_int(mrb, length); if (lev < 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%S)", v); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%v)", v); } if (n < 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative size (%S)", length); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative size (%v)", length); } break; default: diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c index c6d4ca414..88b33771b 100644 --- a/mrbgems/mruby-math/src/math.c +++ b/mrbgems/mruby-math/src/math.c @@ -18,8 +18,7 @@ domain_error(mrb_state *mrb, const char *func) { struct RClass *math = mrb_module_get(mrb, "Math"); struct RClass *domainerror = mrb_class_get_under(mrb, math, "DomainError"); - mrb_value str = mrb_str_new_cstr(mrb, func); - mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %S", str); + mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %s", func); } /* math functions not provided by Microsoft Visual C++ 2012 or older */ diff --git a/mrbgems/mruby-metaprog/src/metaprog.c b/mrbgems/mruby-metaprog/src/metaprog.c index 62daa5227..97f53051f 100644 --- a/mrbgems/mruby-metaprog/src/metaprog.c +++ b/mrbgems/mruby-metaprog/src/metaprog.c @@ -414,7 +414,7 @@ check_cv_name_sym(mrb_state *mrb, mrb_sym id) mrb_int len; const char *name = mrb_sym2name_len(mrb, id, &len); if (!cv_name_p(mrb, name, len)) { - mrb_name_error(mrb, id, "'%S' is not allowed as a class variable name", mrb_sym2str(mrb, id)); + mrb_name_error(mrb, id, "'%n' is not allowed as a class variable name", id); } } @@ -454,12 +454,10 @@ mrb_mod_remove_cvar(mrb_state *mrb, mrb_value mod) if (!mrb_undef_p(val)) return val; if (mrb_cv_defined(mrb, mod, id)) { - mrb_name_error(mrb, id, "cannot remove %S for %S", - mrb_sym2str(mrb, id), mod); + mrb_name_error(mrb, id, "cannot remove %n for %v", id, mod); } - mrb_name_error(mrb, id, "class variable %S not defined for %S", - mrb_sym2str(mrb, id), mod); + mrb_name_error(mrb, id, "class variable %n not defined for %v", id, mod); /* not reached */ return mrb_nil_value(); @@ -622,8 +620,7 @@ remove_method(mrb_state *mrb, mrb_value mod, mrb_sym mid) } } - mrb_name_error(mrb, mid, "method '%S' not defined in %S", - mrb_sym2str(mrb, mid), mod); + mrb_name_error(mrb, mid, "method '%n' not defined in %v", mid, mod); } /* 15.2.2.4.41 */ diff --git a/mrbgems/mruby-method/src/method.c b/mrbgems/mruby-method/src/method.c index d94db1cb2..b5050368d 100644 --- a/mrbgems/mruby-method/src/method.c +++ b/mrbgems/mruby-method/src/method.c @@ -29,8 +29,7 @@ unbound_method_bind(mrb_state *mrb, mrb_value self) if (mrb_type(owner) == MRB_TT_SCLASS) { mrb_raise(mrb, E_TYPE_ERROR, "singleton method called for a different object"); } else { - const char *s = mrb_class_name(mrb, mrb_class_ptr(owner)); - mrb_raisef(mrb, E_TYPE_ERROR, "bind argument must be an instance of %S", mrb_str_new_static(mrb, s, strlen(s))); + mrb_raisef(mrb, E_TYPE_ERROR, "bind argument must be an instance of %v", owner); } } me = method_object_alloc(mrb, mrb_class_get(mrb, "Method")); @@ -289,7 +288,6 @@ static void mrb_search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, struct RProc **proc, mrb_bool unbound) { mrb_value ret; - const char *s; *owner = c; *proc = method_search_vm(mrb, owner, name); @@ -313,13 +311,7 @@ mrb_search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym return; name_error: - s = mrb_class_name(mrb, c); - mrb_raisef( - mrb, E_NAME_ERROR, - "undefined method '%S' for class '%S'", - mrb_sym2str(mrb, name), - mrb_str_new_static(mrb, s, strlen(s)) - ); + mrb_raisef(mrb, E_NAME_ERROR, "undefined method '%n' for class '%C'", name, c); } static mrb_value diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c index 9f091194b..159ba09ac 100644 --- a/mrbgems/mruby-pack/src/pack.c +++ b/mrbgems/mruby-pack/src/pack.c @@ -529,8 +529,8 @@ utf8_to_uv(mrb_state *mrb, const char *p, long *lenp) mrb_raise(mrb, E_ARGUMENT_ERROR, "malformed UTF-8 character"); } if (n > *lenp) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "malformed UTF-8 character (expected %S bytes, given %S bytes)", - mrb_fixnum_value(n), mrb_fixnum_value(*lenp)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "malformed UTF-8 character (expected %d bytes, given %d bytes)", + n, *lenp); } *lenp = n--; if (n != 0) { @@ -976,7 +976,7 @@ alias: case 4: t = 'L'; goto alias; case 8: t = 'Q'; goto alias; default: - mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %S", mrb_fixnum_value(sizeof(int))); + mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %d", (int)sizeof(int)); } break; case 'i': @@ -985,7 +985,7 @@ alias: case 4: t = 'l'; goto alias; case 8: t = 'q'; goto alias; default: - mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %S", mrb_fixnum_value(sizeof(int))); + mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %d", (int)sizeof(int)); } break; case 'L': @@ -1086,8 +1086,7 @@ alias: count = -1; } else if (ch == '_' || ch == '!' || ch == '<' || ch == '>') { if (strchr("sSiIlLqQ", (int)t) == NULL) { - char ch_str = (char)ch; - mrb_raisef(mrb, E_ARGUMENT_ERROR, "'%S' allowed only after types sSiIlLqQ", mrb_str_new(mrb, &ch_str, 1)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "'%c' allowed only after types sSiIlLqQ", ch); } if (ch == '_' || ch == '!') { flags |= PACK_FLAG_s; @@ -1156,7 +1155,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) #endif else if (type == PACK_TYPE_STRING) { if (!mrb_string_p(o)) { - mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S into String", mrb_class_path(mrb, mrb_obj_class(mrb, o))); + mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %T into String", o); } } diff --git a/mrbgems/mruby-socket/src/socket.c b/mrbgems/mruby-socket/src/socket.c index 9b06274dc..eaca27779 100644 --- a/mrbgems/mruby-socket/src/socket.c +++ b/mrbgems/mruby-socket/src/socket.c @@ -171,7 +171,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass) error = getaddrinfo(hostname, servname, &hints, &res0); if (error) { - mrb_raisef(mrb, E_SOCKET_ERROR, "getaddrinfo: %S", mrb_str_new_cstr(mrb, gai_strerror(error))); + mrb_raisef(mrb, E_SOCKET_ERROR, "getaddrinfo: %s", gai_strerror(error)); } mrb_cv_set(mrb, klass, mrb_intern_lit(mrb, "_lastai"), mrb_cptr_value(mrb, res0)); @@ -206,7 +206,7 @@ mrb_addrinfo_getnameinfo(mrb_state *mrb, mrb_value self) } error = getnameinfo((struct sockaddr *)RSTRING_PTR(sastr), (socklen_t)RSTRING_LEN(sastr), RSTRING_PTR(host), NI_MAXHOST, RSTRING_PTR(serv), NI_MAXSERV, (int)flags); if (error) { - mrb_raisef(mrb, E_SOCKET_ERROR, "getnameinfo: %S", mrb_str_new_cstr(mrb, gai_strerror(error))); + mrb_raisef(mrb, E_SOCKET_ERROR, "getnameinfo: %s", gai_strerror(error)); } ary = mrb_ary_new_capa(mrb, 2); mrb_str_resize(mrb, host, strlen(RSTRING_PTR(host))); @@ -476,7 +476,7 @@ mrb_basicsocket_setsockopt(mrb_state *mrb, mrb_value self) optname = mrb_fixnum(mrb_funcall(mrb, so, "optname", 0)); optval = mrb_funcall(mrb, so, "data", 0); } else { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%S for 3)", mrb_fixnum_value(argc)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%i for 3)", argc); } s = socket_fd(mrb, self); @@ -702,7 +702,7 @@ mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "S", &path); if ((size_t)RSTRING_LEN(path) > sizeof(sunp->sun_path) - 1) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "too long unix socket path (max: %S bytes)", mrb_fixnum_value(sizeof(sunp->sun_path) - 1)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "too long unix socket path (max: %d bytes)", (int)sizeof(sunp->sun_path) - 1); } s = mrb_str_buf_new(mrb, sizeof(struct sockaddr_un)); sunp = (struct sockaddr_un *)RSTRING_PTR(s); diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index 985ffe276..c8d51962e 100644 --- a/mrbgems/mruby-sprintf/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -81,7 +81,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) char d; if (base != 2) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %S", mrb_fixnum_value(base)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %d", base); } if (val == 0) { return mrb_str_new_lit(mrb, "0"); @@ -144,10 +144,10 @@ check_next_arg(mrb_state *mrb, int posarg, int nextarg) { switch (posarg) { case -1: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with numbered", mrb_fixnum_value(nextarg)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%d) mixed with numbered", nextarg); break; case -2: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%S) mixed with named", mrb_fixnum_value(nextarg)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "unnumbered(%d) mixed with named", nextarg); break; default: break; @@ -158,26 +158,26 @@ static void check_pos_arg(mrb_state *mrb, mrb_int posarg, mrb_int n) { if (posarg > 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after unnumbered(%S)", - mrb_fixnum_value(n), mrb_fixnum_value(posarg)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%i) after unnumbered(%i)", + n, posarg); } if (posarg == -2) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%S) after named", mrb_fixnum_value(n)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "numbered(%i) after named", n); } if (n < 1) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid index - %S$", mrb_fixnum_value(n)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid index - %i$", n); } } static void -check_name_arg(mrb_state *mrb, int posarg, const char *name, mrb_int len) +check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len) { if (posarg > 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after unnumbered(%S)", - mrb_str_new(mrb, (name), (len)), mrb_fixnum_value(posarg)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%l after unnumbered(%d)", + name, len, posarg); } if (posarg == -1) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%S after numbered", mrb_str_new(mrb, (name), (len))); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "named%l after numbered", name, len); } } @@ -580,7 +580,7 @@ mrb_str_format(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value fm retry: switch (*p) { default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "malformed format string - \\%%S", mrb_str_new(mrb, p, 1)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "malformed format string - %%%c", *p); break; case ' ': @@ -619,7 +619,7 @@ retry: GETNUM(n, width); if (*p == '$') { if (!mrb_undef_p(nextvalue)) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "value given twice - %S$", mrb_fixnum_value(n)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "value given twice - %i$", n); } nextvalue = GETPOSARG(n); p++; @@ -639,14 +639,14 @@ retry: for (; p < end && *p != term; ) p++; if (id) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "name%S after <%S>", - mrb_str_new(mrb, start, p - start + 1), mrb_sym2str(mrb, id)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "name%l after <%n>", + start, p - start + 1, id); } symname = mrb_str_new(mrb, start + 1, p - start - 1); id = mrb_intern_str(mrb, symname); - nextvalue = GETNAMEARG(mrb_symbol_value(id), start, (mrb_int)(p - start + 1)); + nextvalue = GETNAMEARG(mrb_symbol_value(id), start, p - start + 1); if (mrb_undef_p(nextvalue)) { - mrb_raisef(mrb, E_KEY_ERROR, "key%S not found", mrb_str_new(mrb, start, p - start + 1)); + mrb_raisef(mrb, E_KEY_ERROR, "key%l not found", start, p - start + 1); } if (term == '}') goto format_s; p++; @@ -1089,7 +1089,7 @@ retry: if (posarg >= 0 && nextarg < argc) { const char *mesg = "too many arguments for format string"; if (mrb_test(ruby_debug)) mrb_raise(mrb, E_ARGUMENT_ERROR, mesg); - if (mrb_test(ruby_verbose)) mrb_warn(mrb, "%S", mrb_str_new_cstr(mrb, mesg)); + if (mrb_test(ruby_verbose)) mrb_warn(mrb, "%s", mesg); } #endif mrb_str_resize(mrb, result, blen); diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c index 80b277444..a946140dd 100644 --- a/mrbgems/mruby-string-ext/src/string.c +++ b/mrbgems/mruby-string-ext/src/string.c @@ -40,7 +40,7 @@ int_chr_binary(mrb_state *mrb, mrb_value num) mrb_value str; if (cp < 0 || 0xff < cp) { - mrb_raisef(mrb, E_RANGE_ERROR, "%S out of char range", num); + mrb_raisef(mrb, E_RANGE_ERROR, "%v out of char range", num); } c = (char)cp; str = mrb_str_new(mrb, &c, 1); @@ -59,7 +59,7 @@ int_chr_utf8(mrb_state *mrb, mrb_value num) uint32_t ascii_flag = 0; if (cp < 0 || 0x10FFFF < cp) { - mrb_raisef(mrb, E_RANGE_ERROR, "%S out of char range", num); + mrb_raisef(mrb, E_RANGE_ERROR, "%v out of char range", num); } if (cp < 0x80) { utf8[0] = (char)cp; @@ -114,7 +114,7 @@ mrb_str_setbyte(mrb_state *mrb, mrb_value str) len = RSTRING_LEN(str); if (pos < -len || len <= pos) - mrb_raisef(mrb, E_INDEX_ERROR, "index %S out of string", mrb_fixnum_value(pos)); + mrb_raisef(mrb, E_INDEX_ERROR, "index %i out of string", pos); if (pos < 0) pos += len; @@ -583,8 +583,7 @@ str_tr(mrb_state *mrb, mrb_value str, mrb_value p1, mrb_value p2, mrb_bool squee continue; } if (c > 0x80) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "character (%S) out of range", - mrb_fixnum_value((mrb_int)c)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "character (%i) out of range", c); } lastch = c; s[i] = (char)c; @@ -956,7 +955,7 @@ mrb_int_chr(mrb_state *mrb, mrb_value num) } #endif else { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown encoding name - %S", enc); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown encoding name - %v", enc); } /* not reached */ return mrb_nil_value(); diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index e04fe13ad..ebe711ed3 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -66,8 +66,8 @@ struct_members(mrb_state *mrb, mrb_value s) } else { mrb_raisef(mrb, E_TYPE_ERROR, - "struct size differs (%S required %S given)", - mrb_fixnum_value(RARRAY_LEN(members)), mrb_fixnum_value(RSTRUCT_LEN(s))); + "struct size differs (%i required %i given)", + RARRAY_LEN(members), RSTRUCT_LEN(s)); } } return members; @@ -205,10 +205,10 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl mrb_to_str(mrb, name); id = mrb_obj_to_sym(mrb, name); if (!mrb_const_name_p(mrb, RSTRING_PTR(name), RSTRING_LEN(name))) { - mrb_name_error(mrb, id, "identifier %S needs to be constant", name); + mrb_name_error(mrb, id, "identifier %v needs to be constant", name); } if (mrb_const_defined_at(mrb, mrb_obj_value(klass), id)) { - mrb_warn(mrb, "redefining constant Struct::%S", name); + mrb_warn(mrb, "redefining constant Struct::%v", name); mrb_const_remove(mrb, mrb_obj_value(klass), id); } c = mrb_define_class_under(mrb, klass, RSTRING_PTR(name), klass); @@ -388,7 +388,7 @@ struct_aref_sym(mrb_state *mrb, mrb_value obj, mrb_sym id) return ptr[i]; } } - mrb_name_error(mrb, id, "no member '%S' in struct", mrb_sym2str(mrb, id)); + mrb_name_error(mrb, id, "no member '%n' in struct", id); return mrb_nil_value(); /* not reached */ } @@ -399,12 +399,10 @@ struct_aref_int(mrb_state *mrb, mrb_value s, mrb_int i) if (idx < 0) mrb_raisef(mrb, E_INDEX_ERROR, - "offset %S too small for struct(size:%S)", - mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); + "offset %i too small for struct(size:%i)", i, RSTRUCT_LEN(s)); if (RSTRUCT_LEN(s) <= idx) mrb_raisef(mrb, E_INDEX_ERROR, - "offset %S too large for struct(size:%S)", - mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); + "offset %i too large for struct(size:%i)", i, RSTRUCT_LEN(s)); return RSTRUCT_PTR(s)[idx]; } @@ -437,7 +435,7 @@ mrb_struct_aref(mrb_state *mrb, mrb_value s) mrb_value sym = mrb_check_intern_str(mrb, idx); if (mrb_nil_p(sym)) { - mrb_name_error(mrb, mrb_intern_str(mrb, idx), "no member '%S' in struct", idx); + mrb_name_error(mrb, mrb_intern_str(mrb, idx), "no member '%v' in struct", idx); } idx = sym; } @@ -465,7 +463,7 @@ mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val) return val; } } - mrb_name_error(mrb, id, "no member '%S' in struct", mrb_sym2str(mrb, id)); + mrb_name_error(mrb, id, "no member '%n' in struct", id); return val; /* not reach */ } @@ -504,7 +502,7 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s) mrb_value sym = mrb_check_intern_str(mrb, idx); if (mrb_nil_p(sym)) { - mrb_name_error(mrb, mrb_intern_str(mrb, idx), "no member '%S' in struct", idx); + mrb_name_error(mrb, mrb_intern_str(mrb, idx), "no member '%v' in struct", idx); } idx = sym; } @@ -516,13 +514,11 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s) if (i < 0) i = RSTRUCT_LEN(s) + i; if (i < 0) { mrb_raisef(mrb, E_INDEX_ERROR, - "offset %S too small for struct(size:%S)", - mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); + "offset %i too small for struct(size:%i)", i, RSTRUCT_LEN(s)); } if (RSTRUCT_LEN(s) <= i) { mrb_raisef(mrb, E_INDEX_ERROR, - "offset %S too large for struct(size:%S)", - mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); + "offset %i too large for struct(size:%i)", i, RSTRUCT_LEN(s)); } mrb_struct_modify(mrb, s); return RSTRUCT_PTR(s)[i] = val; diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 16461095c..9b0549bea 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -267,7 +267,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) return t; out_of_range: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", obj); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "%v out of Time range", obj); /* not reached */ if (usec) { *usec = 0; } @@ -293,7 +293,7 @@ time_update_datetime(mrb_state *mrb, struct mrb_time *self, int dealloc) mrb_sec sec = (mrb_sec)t; if (dealloc) mrb_free(mrb, self); - mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_sec_value(mrb, sec)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "%v out of Time range", mrb_sec_value(mrb, sec)); /* not reached */ return NULL; } diff --git a/src/array.c b/src/array.c index 8cf813743..06c23dcd3 100644 --- a/src/array.c +++ b/src/array.c @@ -668,7 +668,7 @@ mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val) if (n < 0) { n += len; if (n < 0) { - mrb_raisef(mrb, E_INDEX_ERROR, "index %S out of array", mrb_fixnum_value(n - len)); + mrb_raisef(mrb, E_INDEX_ERROR, "index %i out of array", n - len); } } if (len <= n) { @@ -700,7 +700,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val ary_modify(mrb, a); /* len check */ - if (len < 0) mrb_raisef(mrb, E_INDEX_ERROR, "negative length (%S)", mrb_fixnum_value(len)); + if (len < 0) mrb_raisef(mrb, E_INDEX_ERROR, "negative length (%i)", len); /* range check */ if (head < 0) { @@ -734,7 +734,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val } if (head >= alen) { if (head > ARY_MAX_SIZE - argc) { - mrb_raisef(mrb, E_INDEX_ERROR, "index %S too big", mrb_fixnum_value(head)); + mrb_raisef(mrb, E_INDEX_ERROR, "index %i too big", head); } len = head + argc; if (len > ARY_CAPA(a)) { @@ -750,7 +750,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val mrb_int newlen; if (alen - len > ARY_MAX_SIZE - argc) { - mrb_raisef(mrb, E_INDEX_ERROR, "index %S too big", mrb_fixnum_value(alen + argc - len)); + mrb_raisef(mrb, E_INDEX_ERROR, "index %i too big", alen + argc - len); } newlen = alen + argc - len; if (newlen > ARY_CAPA(a)) { @@ -934,7 +934,7 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self) mrb_ary_splice(mrb, self, i, len, v2); break; case MRB_RANGE_OUT: - mrb_raisef(mrb, E_RANGE_ERROR, "%S out of range", v1); + mrb_raisef(mrb, E_RANGE_ERROR, "%v out of range", v1); break; } return v2; diff --git a/src/backtrace.c b/src/backtrace.c index 991a67d00..c9a223e07 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -246,9 +246,7 @@ mrb_unpack_backtrace(mrb_state *mrb, mrb_value backtrace) mrb_value btline; if (entry->filename == NULL) continue; - btline = mrb_format(mrb, "%S:%S", - mrb_str_new_cstr(mrb, entry->filename), - mrb_fixnum_value(entry->lineno)); + btline = mrb_format(mrb, "%s:%d", entry->filename, entry->lineno); if (entry->method_id != 0) { mrb_str_cat_lit(mrb, btline, ":in "); mrb_str_cat_cstr(mrb, btline, mrb_sym2name(mrb, entry->method_id)); diff --git a/src/class.c b/src/class.c index 65d21ad4f..ff55de0e6 100644 --- a/src/class.c +++ b/src/class.c @@ -177,7 +177,7 @@ static void check_if_class_or_module(mrb_state *mrb, mrb_value obj) { if (!class_ptr_p(obj)) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class/module", mrb_inspect(mrb, obj)); + mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a class/module", obj); } } @@ -215,7 +215,7 @@ mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id) mrb_value old = mrb_const_get(mrb, outer, id); if (mrb_type(old) != MRB_TT_MODULE) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a module", mrb_inspect(mrb, old)); + mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a module", old); } return mrb_class_ptr(old); } @@ -248,9 +248,8 @@ define_class(mrb_state *mrb, mrb_sym name, struct RClass *super, struct RClass * c = class_from_sym(mrb, outer, name); MRB_CLASS_ORIGIN(c); if (super && mrb_class_real(c->super) != super) { - mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for Class %S (%S not %S)", - mrb_sym2str(mrb, name), - mrb_obj_value(c->super), mrb_obj_value(super)); + mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for Class %n (%C not %C)", + name, c->super, super); } return c; } @@ -265,7 +264,7 @@ MRB_API struct RClass* mrb_define_class_id(mrb_state *mrb, mrb_sym name, struct RClass *super) { if (!super) { - mrb_warn(mrb, "no super class for '%S', Object assumed", mrb_sym2str(mrb, name)); + mrb_warn(mrb, "no super class for '%n', Object assumed", name); } return define_class(mrb, name, super, mrb->object_class); } @@ -313,8 +312,7 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id if (!mrb_nil_p(super)) { if (mrb_type(super) != MRB_TT_CLASS) { - mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)", - mrb_inspect(mrb, super)); + mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%!v given)", super); } s = mrb_class_ptr(super); } @@ -326,13 +324,13 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id mrb_value old = mrb_const_get(mrb, outer, id); if (mrb_type(old) != MRB_TT_CLASS) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a class", mrb_inspect(mrb, old)); + mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a class", old); } c = mrb_class_ptr(old); if (s) { /* check super class */ if (mrb_class_real(c->super) != s) { - mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %S", old); + mrb_raisef(mrb, E_TYPE_ERROR, "superclass mismatch for class %v", old); } } return c; @@ -431,8 +429,7 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s #if 0 if (!super) { - mrb_warn(mrb, "no super class for '%S::%S', Object assumed", - mrb_obj_value(outer), mrb_sym2str(mrb, id)); + mrb_warn(mrb, "no super class for '%C::%n', Object assumed", outer, id); } #endif c = define_class(mrb, id, super, outer); @@ -489,8 +486,7 @@ mrb_notimplement(mrb_state *mrb) mrb_callinfo *ci = mrb->c->ci; if (ci->mid) { - mrb_value str = mrb_sym2str(mrb, ci->mid); - mrb_raisef(mrb, E_NOTIMP_ERROR, "%S() function is unimplemented on this machine", str); + mrb_raisef(mrb, E_NOTIMP_ERROR, "%n() function is unimplemented on this machine", ci->mid); } } @@ -505,7 +501,7 @@ mrb_notimplement_m(mrb_state *mrb, mrb_value self) #define CHECK_TYPE(mrb, val, t, c) do { \ if (mrb_type(val) != (t)) {\ - mrb_raisef(mrb, E_TYPE_ERROR, "expected %S", mrb_str_new_lit(mrb, c));\ + mrb_raisef(mrb, E_TYPE_ERROR, "expected %l", c, sizeof(c "")-1);\ }\ } while (0) @@ -669,7 +665,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ss = ARGV[arg_i++]; if (!class_ptr_p(ss)) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not class/module", ss); + mrb_raisef(mrb, E_TYPE_ERROR, "%v is not class/module", ss); } *p = ss; i++; @@ -816,7 +812,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) ss = ARGV[arg_i]; if (mrb_type(ss) != MRB_TT_ISTRUCT) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss); + mrb_raisef(mrb, E_TYPE_ERROR, "%v is not inline struct", ss); } *p = mrb_istruct_ptr(ss); arg_i++; @@ -964,7 +960,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) } break; default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %S", mrb_str_new(mrb, &c, 1)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %c", c); break; } } @@ -1357,8 +1353,7 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) if (mrb_string_p(inspect) && RSTRING_LEN(inspect) > 64) { inspect = mrb_any_to_s(mrb, mrb_obj_value(c)); } - mrb_name_error(mrb, mid, "undefined method '%S' for class %S", - mrb_sym2str(mrb, mid), inspect); + mrb_name_error(mrb, mid, "undefined method '%n' for class %v", mid, inspect); } return m; } @@ -1479,7 +1474,7 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv) if (ttype == 0) ttype = MRB_TT_OBJECT; if (ttype <= MRB_TT_CPTR) { - mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %S", cv); + mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %v", cv); } o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c); return mrb_obj_value(o); @@ -1706,7 +1701,7 @@ static void mrb_check_inheritable(mrb_state *mrb, struct RClass *super) { if (super->tt != MRB_TT_CLASS) { - mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%S given)", mrb_obj_value(super)); + mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%C given)", super); } if (super->tt == MRB_TT_SCLASS) { mrb_raise(mrb, E_TYPE_ERROR, "can't make subclass of singleton class"); @@ -1835,7 +1830,7 @@ void mrb_undef_method_id(mrb_state *mrb, struct RClass *c, mrb_sym a) { if (!mrb_obj_respond_to(mrb, c, a)) { - mrb_name_error(mrb, a, "undefined method '%S' for class '%S'", mrb_sym2str(mrb, a), mrb_obj_value(c)); + mrb_name_error(mrb, a, "undefined method '%n' for class '%C'", a, c); } else { mrb_method_t m; @@ -1878,7 +1873,7 @@ check_const_name_sym(mrb_state *mrb, mrb_sym id) mrb_int len; const char *name = mrb_sym2name_len(mrb, id, &len); if (!mrb_const_name_p(mrb, name, len)) { - mrb_name_error(mrb, id, "wrong constant name %S", mrb_sym2str(mrb, id)); + mrb_name_error(mrb, id, "wrong constant name %n", id); } } @@ -1935,7 +1930,7 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod) else { off = end + 2; if (off == len) { /* trailing "::" */ - mrb_name_error(mrb, id, "wrong constant name '%S'", path); + mrb_name_error(mrb, id, "wrong constant name '%v'", path); } } } @@ -1965,7 +1960,7 @@ mrb_mod_remove_const(mrb_state *mrb, mrb_value mod) check_const_name_sym(mrb, id); val = mrb_iv_remove(mrb, mod, id); if (mrb_undef_p(val)) { - mrb_name_error(mrb, id, "constant %S not defined", mrb_sym2str(mrb, id)); + mrb_name_error(mrb, id, "constant %n not defined", id); } return val; } @@ -1978,13 +1973,10 @@ mrb_mod_const_missing(mrb_state *mrb, mrb_value mod) mrb_get_args(mrb, "n", &sym); if (mrb_class_real(mrb_class_ptr(mod)) != mrb->object_class) { - mrb_name_error(mrb, sym, "uninitialized constant %S::%S", - mod, - mrb_sym2str(mrb, sym)); + mrb_name_error(mrb, sym, "uninitialized constant %v::%n", mod, sym); } else { - mrb_name_error(mrb, sym, "uninitialized constant %S", - mrb_sym2str(mrb, sym)); + mrb_name_error(mrb, sym, "uninitialized constant %n", sym); } /* not reached */ return mrb_nil_value(); @@ -2045,7 +2037,7 @@ mod_define_method(mrb_state *mrb, mrb_value self) /* ignored */ break; default: - mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %S (expected Proc)", mrb_obj_value(mrb_obj_class(mrb, proc))); + mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %T (expected Proc)", proc); break; } if (mrb_nil_p(blk)) { diff --git a/src/error.c b/src/error.c index 0ca7f5917..664da3fd6 100644 --- a/src/error.c +++ b/src/error.c @@ -151,14 +151,14 @@ exc_inspect(mrb_state *mrb, mrb_value exc) str = mrb_str_new_cstr(mrb, cname); if (mrb_string_p(file) && mrb_fixnum_p(line)) { if (append_mesg) { - str = mrb_format(mrb, "%S:%S: %S (%S)", file, line, mesg, str); + str = mrb_format(mrb, "%v:%v: %v (%v)", file, line, mesg, str); } else { - str = mrb_format(mrb, "%S:%S: %S", file, line, str); + str = mrb_format(mrb, "%v:%v: %v", file, line, str); } } else if (append_mesg) { - str = mrb_format(mrb, "%S: %S", str, mesg); + str = mrb_format(mrb, "%v: %v", str, mesg); } return str; } @@ -523,7 +523,7 @@ exception_call: break; default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%S for 0..3)", mrb_fixnum_value(argc)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%i for 0..3)", argc); break; } if (argc > 0) { @@ -576,8 +576,7 @@ mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, char const* fmt, MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj) { - mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %S", - mrb_obj_value(mrb_class(mrb, mrb_obj_value(frozen_obj)))); + mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %t", mrb_obj_value(frozen_obj)); } void diff --git a/src/etc.c b/src/etc.c index 18d2839d9..bf6586748 100644 --- a/src/etc.c +++ b/src/etc.c @@ -31,14 +31,12 @@ mrb_data_check_type(mrb_state *mrb, mrb_value obj, const mrb_data_type *type) const mrb_data_type *t2 = DATA_TYPE(obj); if (t2) { - mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %S (expected %S)", - mrb_str_new_cstr(mrb, t2->struct_name), mrb_str_new_cstr(mrb, type->struct_name)); + mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %s (expected %s)", + t2->struct_name, type->struct_name); } else { - struct RClass *c = mrb_class(mrb, obj); - - mrb_raisef(mrb, E_TYPE_ERROR, "uninitialized %S (expected %S)", - mrb_obj_value(c), mrb_str_new_cstr(mrb, type->struct_name)); + mrb_raisef(mrb, E_TYPE_ERROR, "uninitialized %t (expected %s)", + obj, type->struct_name); } } } @@ -67,7 +65,7 @@ mrb_obj_to_sym(mrb_state *mrb, mrb_value name) { if (mrb_symbol_p(name)) return mrb_symbol(name); if (mrb_string_p(name)) return mrb_intern_str(mrb, name); - mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a symbol nor a string", mrb_inspect(mrb, name)); + mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a symbol nor a string", name); return 0; /* not reached */ } diff --git a/src/gc.c b/src/gc.c index b05d929a1..a7a67ebfa 100644 --- a/src/gc.c +++ b/src/gc.c @@ -542,7 +542,7 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls) ttype != MRB_TT_ICLASS && ttype != MRB_TT_ENV && ttype != tt) { - mrb_raisef(mrb, E_TYPE_ERROR, "allocation failure of %S", mrb_obj_value(cls)); + mrb_raisef(mrb, E_TYPE_ERROR, "allocation failure of %C", cls); } } diff --git a/src/kernel.c b/src/kernel.c index f223be9fc..f0935a2f8 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -325,7 +325,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self) mrb_value clone; if (mrb_immediate_p(self)) { - mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %S", self); + mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %v", self); } if (mrb_type(self) == MRB_TT_SCLASS) { mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class"); @@ -366,7 +366,7 @@ mrb_obj_dup(mrb_state *mrb, mrb_value obj) mrb_value dup; if (mrb_immediate_p(obj)) { - mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %S", obj); + mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %v", obj); } if (mrb_type(obj) == MRB_TT_SCLASS) { mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class"); @@ -641,7 +641,7 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) mrb_iv_name_sym_check(mrb, sym); val = mrb_iv_remove(mrb, self, sym); if (mrb_undef_p(val)) { - mrb_name_error(mrb, sym, "instance variable %S not defined", mrb_sym2str(mrb, sym)); + mrb_name_error(mrb, sym, "instance variable %n not defined", sym); } return val; } @@ -649,7 +649,7 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args) { - mrb_no_method_error(mrb, name, args, "undefined method '%S'", mrb_sym2str(mrb, name)); + mrb_no_method_error(mrb, name, args, "undefined method '%n'", name); } /* 15.3.1.3.30 */ diff --git a/src/numeric.c b/src/numeric.c index b143b2f67..f96498106 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1257,7 +1257,7 @@ mrb_flo_to_fixnum(mrb_state *mrb, mrb_value x) z = (mrb_int)d; } else { - mrb_raisef(mrb, E_RANGE_ERROR, "number (%S) too big for integer", x); + mrb_raisef(mrb, E_RANGE_ERROR, "number (%v) too big for integer", x); } } return mrb_fixnum_value(z); @@ -1389,7 +1389,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base) mrb_int val = mrb_fixnum(x); if (base < 2 || 36 < base) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %S", mrb_fixnum_value(base)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid radix %i", base); } if (val == 0) { @@ -1501,9 +1501,7 @@ integral_cmp(mrb_state *mrb, mrb_value self) static void cmperr(mrb_state *mrb, mrb_value v1, mrb_value v2) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "comparison of %S with %S failed", - mrb_obj_value(mrb_class(mrb, v1)), - mrb_obj_value(mrb_class(mrb, v2))); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "comparison of %t with %t failed", v1, v2); } static mrb_value diff --git a/src/object.c b/src/object.c index 7c1879019..ee36da320 100644 --- a/src/object.c +++ b/src/object.c @@ -296,17 +296,6 @@ mrb_init_object(mrb_state *mrb) mrb_define_method(mrb, f, "inspect", false_to_s, MRB_ARGS_NONE()); } -static mrb_value -inspect_type(mrb_state *mrb, mrb_value val) -{ - if (mrb_type(val) == MRB_TT_FALSE || mrb_type(val) == MRB_TT_TRUE) { - return mrb_inspect(mrb, val); - } - else { - return mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, val)); - } -} - static mrb_value convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *method, mrb_bool raise) { @@ -315,7 +304,7 @@ convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *metho m = mrb_intern_cstr(mrb, method); if (!mrb_respond_to(mrb, val, m)) { if (raise) { - mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S into %S", inspect_type(mrb, val), mrb_str_new_cstr(mrb, tname)); + mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %Y into %s", val, tname); } return mrb_nil_value(); } @@ -330,8 +319,7 @@ mrb_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char if (mrb_type(val) == type) return val; v = convert_type(mrb, val, tname, method, TRUE); if (mrb_type(v) != type) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to %S by #%S", val, - mrb_str_new_cstr(mrb, tname), mrb_str_new_cstr(mrb, method)); + mrb_raisef(mrb, E_TYPE_ERROR, "%v cannot be converted to %s by #%s", val, tname, method); } return v; } @@ -405,13 +393,12 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) else { etype = mrb_obj_classname(mrb, x); } - mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %S (expected %S)", - mrb_str_new_cstr(mrb, etype), mrb_str_new_cstr(mrb, type->name)); + mrb_raisef(mrb, E_TYPE_ERROR, "wrong argument type %s (expected %s)", + etype, type->name); } type++; } - mrb_raisef(mrb, E_TYPE_ERROR, "unknown type %S (%S given)", - mrb_fixnum_value(t), mrb_fixnum_value(mrb_type(x))); + mrb_raisef(mrb, E_TYPE_ERROR, "unknown type %d (%d given)", t, mrb_type(x)); } } @@ -499,15 +486,12 @@ mrb_to_int(mrb_state *mrb, mrb_value val) { if (!mrb_fixnum_p(val)) { - mrb_value type; - #ifndef MRB_WITHOUT_FLOAT if (mrb_float_p(val)) { return mrb_flo_to_fixnum(mrb, val); } #endif - type = inspect_type(mrb, val); - mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S to Integer", type); + mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %Y to Integer", val); } return val; } @@ -598,8 +582,7 @@ MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str) { if (!mrb_string_p(str)) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to String", - inspect_type(mrb, str)); + mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to String", str); } return str; } @@ -615,8 +598,7 @@ MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value ary) { if (!mrb_array_p(ary)) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to Array", - inspect_type(mrb, ary)); + mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to Array", ary); } return ary; } @@ -632,8 +614,7 @@ MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash) { if (!mrb_hash_p(hash)) { - mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to Hash", - inspect_type(mrb, hash)); + mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to Hash", hash); } return hash; } diff --git a/src/proc.c b/src/proc.c index 094fff816..a0edf22bc 100644 --- a/src/proc.c +++ b/src/proc.c @@ -153,8 +153,8 @@ mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx) mrb_raise(mrb, E_TYPE_ERROR, "Can't get cfunc env from cfunc Proc without REnv."); } if (idx < 0 || MRB_ENV_STACK_LEN(e) <= idx) { - mrb_raisef(mrb, E_INDEX_ERROR, "Env index out of range: %S (expected: 0 <= index < %S)", - mrb_fixnum_value(idx), mrb_fixnum_value(MRB_ENV_STACK_LEN(e))); + mrb_raisef(mrb, E_INDEX_ERROR, "Env index out of range: %i (expected: 0 <= index < %i)", + idx, MRB_ENV_STACK_LEN(e)); } return e->stack[idx]; diff --git a/src/range.c b/src/range.c index c9dfb2b3c..28862d779 100644 --- a/src/range.c +++ b/src/range.c @@ -363,7 +363,7 @@ mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, con } } else { - mrb_raisef(mrb, E_TYPE_ERROR, "invalid values selector: %S", argv[i]); + mrb_raisef(mrb, E_TYPE_ERROR, "invalid values selector: %v", argv[i]); } } diff --git a/src/string.c b/src/string.c index ecbe21a22..71c6e126e 100644 --- a/src/string.c +++ b/src/string.c @@ -1226,7 +1226,7 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) static mrb_noreturn void str_out_of_index(mrb_state *mrb, mrb_value index) { - mrb_raisef(mrb, E_INDEX_ERROR, "index %S out of string", index); + mrb_raisef(mrb, E_INDEX_ERROR, "index %v out of string", index); } static mrb_value @@ -1286,7 +1286,7 @@ mrb_str_aset(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_ mrb_raise(mrb, E_INDEX_ERROR, "string not matched"); case STR_CHAR_RANGE: if (len < 0) { - mrb_raisef(mrb, E_INDEX_ERROR, "negative length %S", alen); + mrb_raisef(mrb, E_INDEX_ERROR, "negative length %v", alen); } charlen = RSTRING_CHAR_LEN(str); if (beg < 0) { beg += charlen; } @@ -1763,7 +1763,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) tmp = mrb_check_string_type(mrb, sub); if (mrb_nil_p(tmp)) { - mrb_raisef(mrb, E_TYPE_ERROR, "type mismatch: %S given", sub); + mrb_raisef(mrb, E_TYPE_ERROR, "type mismatch: %v given", sub); } sub = tmp; } @@ -2014,7 +2014,7 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str) tmp = mrb_check_string_type(mrb, sub); if (mrb_nil_p(tmp)) { - mrb_raisef(mrb, E_TYPE_ERROR, "type mismatch: %S given", sub); + mrb_raisef(mrb, E_TYPE_ERROR, "type mismatch: %v given", sub); } sub = tmp; } @@ -2265,7 +2265,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, break; default: if (base < 2 || 36 < base) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal radix %S", mrb_fixnum_value(base)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal radix %i", base); } break; } /* end of switch (base) { */ @@ -2325,8 +2325,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, else #endif { - mrb_raisef(mrb, E_RANGE_ERROR, "string (%S) too big for integer", - mrb_str_new(mrb, str, pend-str)); + mrb_raisef(mrb, E_RANGE_ERROR, "string (%l) too big for integer", str, pend-str); } } } @@ -2342,8 +2341,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, mrb_raise(mrb, E_ARGUMENT_ERROR, "string contains null byte"); /* not reached */ bad: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for number(%S)", - mrb_inspect(mrb, mrb_str_new(mrb, str, pend-str))); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for number(%!l)", str, pend-str); /* not reached */ return mrb_fixnum_value(0); } @@ -2419,7 +2417,7 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "|i", &base); if (base < 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal radix %S", mrb_fixnum_value(base)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "illegal radix %i", base); } return mrb_str_to_inum(mrb, self, base, FALSE); } @@ -2444,7 +2442,7 @@ mrb_cstr_to_dbl(mrb_state *mrb, const char * p, mrb_bool badcheck) if (p == end) { if (badcheck) { bad: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for float(%S)", mrb_str_new_cstr(mrb, p)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for float(%s)", p); /* not reached */ } return d; diff --git a/src/variable.c b/src/variable.c index e6f2f397e..32416da4e 100644 --- a/src/variable.c +++ b/src/variable.c @@ -446,7 +446,7 @@ MRB_API void mrb_iv_name_sym_check(mrb_state *mrb, mrb_sym iv_name) { if (!mrb_iv_name_sym_p(mrb, iv_name)) { - mrb_name_error(mrb, iv_name, "'%S' is not allowed as an instance variable name", mrb_sym2str(mrb, iv_name)); + mrb_name_error(mrb, iv_name, "'%n' is not allowed as an instance variable name", iv_name); } } @@ -654,8 +654,7 @@ mrb_mod_cv_get(mrb_state *mrb, struct RClass *c, mrb_sym sym) if (given) return v; } } - mrb_name_error(mrb, sym, "uninitialized class variable %S in %S", - mrb_sym2str(mrb, sym), mrb_obj_value(cls)); + mrb_name_error(mrb, sym, "uninitialized class variable %n in %C", sym, cls); /* not reached */ return mrb_nil_value(); } diff --git a/src/vm.c b/src/vm.c index 86262650e..12805a8e4 100644 --- a/src/vm.c +++ b/src/vm.c @@ -461,7 +461,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc stack_init(mrb); } if (argc < 0) { - mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative argc for funcall (%S)", mrb_fixnum_value(argc)); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative argc for funcall (%i)", argc); } c = mrb_class(mrb, self); m = mrb_method_search_vm(mrb, &c, mid); @@ -878,13 +878,11 @@ argnum_error(mrb_state *mrb, mrb_int num) } } if (mrb->c->ci->mid) { - str = mrb_format(mrb, "'%S': wrong number of arguments (%S for %S)", - mrb_sym2str(mrb, mrb->c->ci->mid), - mrb_fixnum_value(argc), mrb_fixnum_value(num)); + str = mrb_format(mrb, "'%n': wrong number of arguments (%i for %i)", + mrb->c->ci->mid, argc, num); } else { - str = mrb_format(mrb, "wrong number of arguments (%S for %S)", - mrb_fixnum_value(argc), mrb_fixnum_value(num)); + str = mrb_format(mrb, "wrong number of arguments (%i for %i)", argc, num); } exc = mrb_exc_new_str(mrb, E_ARGUMENT_ERROR, str); mrb_exc_set(mrb, exc); @@ -1868,7 +1866,7 @@ RETRY_TRY_BLOCK: mrb_value kdict = regs[mrb->c->ci->argc]; if (!mrb_hash_p(kdict) || !mrb_hash_key_p(mrb, kdict, k)) { - mrb_value str = mrb_format(mrb, "missing keyword: %S", k); + mrb_value str = mrb_format(mrb, "missing keyword: %v", k); mrb_exc_set(mrb, mrb_exc_new_str(mrb, E_ARGUMENT_ERROR, str)); goto L_RAISE; } @@ -1895,7 +1893,7 @@ RETRY_TRY_BLOCK: if (mrb_hash_p(kdict) && !mrb_hash_empty_p(mrb, kdict)) { mrb_value keys = mrb_hash_keys(mrb, kdict); mrb_value key1 = RARRAY_PTR(keys)[0]; - mrb_value str = mrb_format(mrb, "unknown keyword: %S", key1); + mrb_value str = mrb_format(mrb, "unknown keyword: %v", key1); mrb_exc_set(mrb, mrb_exc_new_str(mrb, E_ARGUMENT_ERROR, str)); goto L_RAISE; } diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake index 9bf0f085e..6275059bb 100644 --- a/tasks/toolchains/visualcpp.rake +++ b/tasks/toolchains/visualcpp.rake @@ -2,7 +2,7 @@ MRuby::Toolchain.new(:visualcpp) do |conf, _params| conf.cc do |cc| cc.command = ENV['CC'] || 'cl.exe' # C4013: implicit function declaration - cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /Zm2000 /MD /O2 /D_CRT_SECURE_NO_WARNINGS)] + cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)] cc.defines = %w(MRB_STACK_EXTEND_DOUBLING) cc.option_include_path = '/I%s' cc.option_define = '/D%s' -- cgit v1.2.3 From e1e96c0cf480930f33dcb4355f38244319ce0e37 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Mon, 26 Aug 2019 00:23:28 +0900 Subject: change doc directory and reduce warnings --- .gitignore | 2 +- Doxyfile | 36 +++++++----------------------------- Makefile | 4 +--- Makefile.doc | 15 --------------- Rakefile | 13 ++----------- include/mruby/value.h | 5 +++-- tasks/doc.rake | 38 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 52 insertions(+), 61 deletions(-) delete mode 100644 Makefile.doc create mode 100644 tasks/doc.rake (limited to 'tasks') diff --git a/.gitignore b/.gitignore index 0c9fc3fef..3e728356a 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,6 @@ tags /benchmark/*.png /doc/api -/doxygen/ +/doc/capi /src/y.tab.c diff --git a/Doxyfile b/Doxyfile index 9ee375f86..8724fe1ac 100644 --- a/Doxyfile +++ b/Doxyfile @@ -12,7 +12,7 @@ PROJECT_BRIEF = "mruby is the lightweight implementation of the Ruby la PROJECT_LOGO = doc/mruby_logo_red_icon.png -OUTPUT_DIRECTORY = doxygen +OUTPUT_DIRECTORY = doc/capi USE_MDFILE_AS_MAINPAGE = README.md @@ -49,6 +49,12 @@ EXTRACT_ALL = NO # Document MRB_INLINE functions EXTRACT_STATIC = YES +JAVADOC_AUTOBRIEF = YES +QT_AUTOBRIEF = NO + +QUIET = YES +WARN_IF_UNDOCUMENTED = NO + #=========================================================================== # BELOW THIS LINE IS CRUFT GENERATED BY doxygen -g # If you edit anything below this, bring it up here so its easier to read. @@ -174,22 +180,6 @@ STRIP_FROM_INC_PATH = SHORT_NAMES = NO -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as @@ -711,12 +701,6 @@ CITE_BIB_FILES = # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error (stderr) by doxygen. If WARNINGS is set to YES @@ -727,12 +711,6 @@ QUIET = NO WARNINGS = YES -# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some parameters diff --git a/Makefile b/Makefile index 191e07a93..4912f17e1 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,6 @@ # We provide a minimalistic version called minirake inside of our # codebase. --include Makefile.doc - RAKE = ruby ./minirake all : @@ -14,6 +12,6 @@ test : all $(RAKE) test .PHONY : test -clean : docsclean +clean : $(RAKE) clean .PHONY : clean diff --git a/Makefile.doc b/Makefile.doc deleted file mode 100644 index 02bfa55d6..000000000 --- a/Makefile.doc +++ /dev/null @@ -1,15 +0,0 @@ -SRCS=$(shell find src -name '*.c') -HEADERS=$(shell find include -name '*.h') -MDDOCS=$(shell find doc -name '*.md') - -doxygen : Doxyfile $(SRCS) $(HEADERS) $(MDDOCS) - doxygen Doxyfile - -docs : doxygen - -docserver : docs - firefox doxygen/html/index.html - -docsclean : - rm -rf doxygen -.PHONY : docserver docsclean diff --git a/Rakefile b/Rakefile index 079b1a41b..28e2d75c8 100644 --- a/Rakefile +++ b/Rakefile @@ -30,6 +30,7 @@ load "#{MRUBY_ROOT}/tasks/libmruby.rake" load "#{MRUBY_ROOT}/tasks/benchmark.rake" load "#{MRUBY_ROOT}/tasks/gitlab.rake" +load "#{MRUBY_ROOT}/tasks/doc.rake" def install_D(src, dst) opts = { :verbose => $verbose } @@ -150,19 +151,9 @@ task :clean do end desc "clean everything!" -task :deep_clean => ["clean"] do +task :deep_clean => ["clean", "clean_doc"] do MRuby.each_target do |t| FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose } end puts "Cleaned up mrbgems build folder" end - -desc 'generate document' -task :doc do - begin - sh "mrbdoc" - rescue - puts "ERROR: To generate documents, you should install yard-mruby gem." - puts " $ gem install yard-mruby" - end -end diff --git a/include/mruby/value.h b/include/mruby/value.h index 2ba0b3587..7dd3dbae2 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -15,16 +15,17 @@ MRB_BEGIN_DECL /** + * mruby Symbol. * @class mrb_sym - * @brief mruby Symbol * * You can create an mrb_sym by simply using mrb_str_intern() or mrb_intern_cstr() */ typedef uint32_t mrb_sym; /** + * mruby Boolean. * @class mrb_bool - * @brief mruby Boolean + * * * Used internally to represent boolean. Can be TRUE or FALSE. * Not to be confused with Ruby's boolean classes, which can be diff --git a/tasks/doc.rake b/tasks/doc.rake new file mode 100644 index 000000000..ab34b33b1 --- /dev/null +++ b/tasks/doc.rake @@ -0,0 +1,38 @@ +desc 'generate document' +task :doc => [:api_doc, :capi_doc] do + +end + +desc 'generate yard docs' +task :api_doc do + begin + sh "mrbdoc" + rescue + puts "ERROR: To generate yard documentation, you should install yard-mruby gem." + puts " $ gem install yard-mruby yard-coderay" + end +end + +desc 'generate doxygen docs' +task :capi_doc do + begin + sh "doxygen Doxyfile" + rescue + puts "ERROR: To generate C API documents, you need Doxygen." + puts " $ sudo apt-get install doxygen" + end +end + +desc 'clean all built docs' +task :clean_api_doc do + FileUtils.rm_rf 'doc/api' +end + +desc 'clean all built docs' +task :clean_capi_doc do + FileUtils.rm_rf 'doc/capi' +end + +desc 'clean all built docs' +task :clean_doc => [:clean_api_doc, :clean_capi_doc] do +end -- cgit v1.2.3 From 6375639917a913c542967b33be01003a2b67c144 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Mon, 26 Aug 2019 02:08:33 +0900 Subject: fix lots of warnings and make logo not so big --- README.md | 13 +++ doc/mruby_logo_red_icon.png | Bin 3755 -> 8561 bytes include/mruby.h | 236 ++++++++++++++++++++++++-------------------- include/mruby/error.h | 8 +- include/mruby/string.h | 115 +++++++++++---------- include/mruby/variable.h | 3 - src/class.c | 3 +- tasks/doc.rake | 10 ++ 8 files changed, 212 insertions(+), 176 deletions(-) (limited to 'tasks') diff --git a/README.md b/README.md index 863560ebc..ec3492530 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,19 @@ Or $ ruby ./minirake test +## Building documentation + +There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen) + +To build both of them, simply go + + rake doc + +You can also view them in your browser + + rake view_api + rake view_capi + ## How to customize mruby (mrbgems) mruby contains a package manager called *mrbgems*. To create extensions diff --git a/doc/mruby_logo_red_icon.png b/doc/mruby_logo_red_icon.png index 084908542..9006c84eb 100644 Binary files a/doc/mruby_logo_red_icon.png and b/doc/mruby_logo_red_icon.png differ diff --git a/include/mruby.h b/include/mruby.h index 87ccd8c05..52c233211 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -177,7 +177,16 @@ struct mrb_context { # define MRB_METHOD_CACHE_SIZE (1<<7) #endif -typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value); +/** + * Function pointer type for a function callable by mruby. + * + * The arguments to the function are stored on the mrb_state. To get them see mrb_get_args + * + * @param mrb The mruby state + * @param self The self object + * @return [mrb_value] The function's return value + */ +typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self); #ifdef MRB_METHOD_TABLE_INLINE typedef uintptr_t mrb_method_t; @@ -292,9 +301,9 @@ typedef struct mrb_state { * //free(TheAnimals); * } * - * @param [mrb_state *] mrb The current mruby state. - * @param [const char *] name The name of the defined class. - * @param [struct RClass *] super The new class parent. + * @param mrb The current mruby state. + * @param name The name of the defined class. + * @param super The new class parent. * @return [struct RClass *] Reference to the newly defined class. * @see mrb_define_class_under */ @@ -303,12 +312,12 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct /** * Defines a new module. * - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [const char *] char* The name of the module. + * @param mrb The current mruby state. + * @param name The name of the module. * @return [struct RClass *] Reference to the newly defined module. */ -MRB_API struct RClass *mrb_define_module(mrb_state *, const char*); -MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value); +MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name); +MRB_API mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value val); /** * Include a module in another class or module. @@ -317,11 +326,11 @@ MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value); * module B * include A * end - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [struct RClass *] RClass* A reference to module or a class. - * @param [struct RClass *] RClass* A reference to the module to be included. + * @param mrb The current mruby state. + * @param cla A reference to module or a class. + * @param included A reference to the module to be included. */ -MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*); +MRB_API void mrb_include_module(mrb_state *mrb, struct RClass *cla, struct RClass *included); /** * Prepends a module in another class or module. @@ -330,11 +339,11 @@ MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*); * module B * prepend A * end - * @param [mrb_state *] mrb_state* The current mruby state. - * @param [struct RClass *] RClass* A reference to module or a class. - * @param [struct RClass *] RClass* A reference to the module to be prepended. + * @param mrb The current mruby state. + * @param cla A reference to module or a class. + * @param prepended A reference to the module to be prepended. */ -MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); +MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClass *prepended); /** * Defines a global function in ruby. @@ -343,7 +352,6 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); * * Example: * - * !!!c * mrb_value example_method(mrb_state* mrb, mrb_value self) * { * puts("Executing example command!"); @@ -355,11 +363,11 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*); * mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE()); * } * - * @param [mrb_state *] mrb The MRuby state reference. - * @param [struct RClass *] cla The class pointer where the method will be defined. - * @param [const char *] name The name of the method being defined. - * @param [mrb_func_t] func The function pointer to the method definition. - * @param [mrb_aspec] aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The class pointer where the method will be defined. + * @param name The name of the method being defined. + * @param func The function pointer to the method definition. + * @param aspec The method parameters declaration. */ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec); @@ -382,14 +390,20 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n * foo = mrb_define_class(mrb, "Foo", mrb->object_class); * mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* The class where the class method will be defined. - * @param [const char *] char* The name of the class method being defined. - * @param [mrb_func_t] mrb_func_t The function pointer to the class method definition. - * @param [mrb_aspec] mrb_aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The class where the class method will be defined. + * @param name The name of the class method being defined. + * @param fun The function pointer to the class method definition. + * @param aspec The method parameters declaration. */ -MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *, mrb_func_t, mrb_aspec); -MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec); +MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); + +/** + * Defines a singleton method + * + * @see mrb_define_class_method + */ +MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); /** * Defines a module function. @@ -410,13 +424,13 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char * foo = mrb_define_module(mrb, "Foo"); * mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE()); * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* The module where the module function will be defined. - * @param [const char *] char* The name of the module function being defined. - * @param [mrb_func_t] mrb_func_t The function pointer to the module function definition. - * @param [mrb_aspec] mrb_aspec The method parameters declaration. + * @param mrb The MRuby state reference. + * @param cla The module where the module function will be defined. + * @param name The name of the module function being defined. + * @param fun The function pointer to the module function definition. + * @param aspec The method parameters declaration. */ -MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec); +MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec); /** * Defines a constant. @@ -439,12 +453,12 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, * mrb_value * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state *] mrb_state* The MRuby state reference. - * @param [struct RClass *] RClass* A class or module the constant is defined in. - * @param [const char *] name The name of the constant being defined. - * @param [mrb_value] mrb_value The value for the constant. + * @param mrb The MRuby state reference. + * @param cla A class or module the constant is defined in. + * @param name The name of the constant being defined. + * @param val The value for the constant. */ -MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value); +MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val); /** * Undefines a method. @@ -490,11 +504,11 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_ * * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state*] mrb_state* The mruby state reference. - * @param [struct RClass*] RClass* A class the method will be undefined from. - * @param [const char*] const char* The name of the method to be undefined. + * @param mrb The mruby state reference. + * @param cla The class the method will be undefined from. + * @param name The name of the method to be undefined. */ -MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*); +MRB_API void mrb_undef_method(mrb_state *mrb, struct RClass *cla, const char *name); MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym); /** @@ -530,11 +544,11 @@ MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym); * void * mrb_example_gem_final(mrb_state* mrb){ * } - * @param [mrb_state*] mrb_state* The mruby state reference. - * @param [RClass*] RClass* A class the class method will be undefined from. - * @param [const char*] const char* The name of the class method to be undefined. + * @param mrb The mruby state reference. + * @param cls A class the class method will be undefined from. + * @param name The name of the class method to be undefined. */ -MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); +MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name); /** * Initialize a new object instance of c class. @@ -558,10 +572,10 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*); * obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new * mrb_p(mrb, obj); // => Kernel#p * } - * @param [mrb_state*] mrb The current mruby state. - * @param [RClass*] c Reference to the class of the new object. - * @param [mrb_int] argc Number of arguments in argv - * @param [const mrb_value *] argv Array of mrb_value to initialize the object + * @param mrb The current mruby state. + * @param c Reference to the class of the new object. + * @param argc Number of arguments in argv + * @param argv Array of mrb_value to initialize the object * @return [mrb_value] The newly initialized object */ MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv); @@ -587,8 +601,8 @@ MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, mrb_int argc, const * mrb_p(mrb, obj); // => Kernel#p * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] super The super class or parent. + * @param mrb The current mruby state. + * @param super The super class or parent. * @return [struct RClass *] Reference to the new class. */ MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super); @@ -604,7 +618,7 @@ MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super); * example_module = mrb_module_new(mrb); * } * - * @param [mrb_state*] mrb The current mruby state. + * @param mrb The current mruby state. * @return [struct RClass *] Reference to the new module. */ MRB_API struct RClass * mrb_module_new(mrb_state *mrb); @@ -631,24 +645,24 @@ MRB_API struct RClass * mrb_module_new(mrb_state *mrb); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name A string representing the name of the class. + * @param mrb The current mruby state. + * @param name A string representing the name of the class. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name); /** * Gets a class. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name); /** * Gets a exception class. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name); @@ -677,35 +691,35 @@ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the outer class. - * @param [const char *] name A string representing the name of the inner class. + * @param mrb The current mruby state. + * @param outer The name of the outer class. + * @param name A string representing the name of the inner class. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name); /** * Gets a child class. - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the parent class. - * @param [const char *] name The name of the class. + * @param mrb The current mruby state. + * @param outer The name of the parent class. + * @param name The name of the class. * @return [struct RClass *] A reference to the class. */ MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name); /** * Gets a module. - * @param [mrb_state*] mrb The current mruby state. - * @param [const char *] name The name of the module. + * @param mrb The current mruby state. + * @param name The name of the module. * @return [struct RClass *] A reference to the module. */ MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name); /** * Gets a module defined under another module. - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer The name of the outer module. - * @param [const char *] name The name of the module. + * @param mrb The current mruby state. + * @param outer The name of the outer module. + * @param name The name of the module. * @return [struct RClass *] A reference to the module. */ MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name); @@ -719,8 +733,8 @@ MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value); * * Equivalent to: * Object#dup - * @param [mrb_state*] mrb The current mruby state. - * @param [mrb_value] obj Object to be duplicate. + * @param mrb The current mruby state. + * @param obj Object to be duplicate. * @return [mrb_value] The newly duplicated object. */ MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj); @@ -760,9 +774,9 @@ MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj); * } * } * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] c A reference to a class. - * @param [mrb_sym] mid A symbol referencing a method id. + * @param mrb The current mruby state. + * @param c A reference to a class. + * @param mid A symbol referencing a method id. * @return [mrb_bool] A boolean value. */ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid); @@ -770,10 +784,10 @@ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mi /** * Defines a new class under a given module * - * @param [mrb_state*] mrb The current mruby state. - * @param [struct RClass *] outer Reference to the module under which the new class will be defined - * @param [const char *] name The name of the defined class - * @param [struct RClass *] super The new class parent + * @param mrb The current mruby state. + * @param outer Reference to the module under which the new class will be defined + * @param name The name of the defined class + * @param super The new class parent * @return [struct RClass *] Reference to the newly defined class * @see mrb_define_class */ @@ -854,7 +868,7 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o * | `I` | inline struct | void * | | * | `&` | block | {mrb_value} | &! raises exception if no block given. | * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. | - * | | | optional | | After this spec following specs would be optional. | + * | \| | optional | | After this spec following specs would be optional. | * | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. | * * @see mrb_get_args @@ -865,7 +879,7 @@ typedef const char *mrb_args_format; * Retrieve arguments from mrb_state. * * @param mrb The current MRuby state. - * @param format [mrb_args_format] is a list of format specifiers + * @param format is a list of format specifiers * @param ... The passing variadic arguments must be a pointer of retrieving type. * @return the number of arguments retrieved. * @see mrb_args_format @@ -898,6 +912,8 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb); /** * Call existing ruby functions. * + * Example: + * * #include * #include * #include "mruby/compile.h" @@ -914,15 +930,16 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb); * mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); * fclose(fp); * mrb_close(mrb); - * } - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [mrb_value] mrb_value A reference to an mruby value. - * @param [const char*] const char* The name of the method. - * @param [mrb_int] mrb_int The number of arguments the method has. - * @param [...] ... Variadic values(not type safe!). - * @return [mrb_value] mrb_value mruby function value. + * } + * + * @param mrb The current mruby state. + * @param val A reference to an mruby value. + * @param name The name of the method. + * @param argc The number of arguments the method has. + * @param ... Variadic values(not type safe!). + * @return [mrb_value] mruby function value. */ -MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); +MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...); /** * Call existing ruby functions. This is basically the type safe version of mrb_funcall. * @@ -944,15 +961,15 @@ MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); * fclose(fp); * mrb_close(mrb); * } - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [mrb_value] mrb_value A reference to an mruby value. - * @param [mrb_sym] mrb_sym The symbol representing the method. - * @param [mrb_int] mrb_int The number of arguments the method has. - * @param [const mrb_value*] mrb_value* Pointer to the object. + * @param mrb The current mruby state. + * @param val A reference to an mruby value. + * @param name_sym The symbol representing the method. + * @param argc The number of arguments the method has. + * @param obj Pointer to the object. * @return [mrb_value] mrb_value mruby function value. * @see mrb_funcall */ -MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*); +MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name_sym, mrb_int argc, const mrb_value* obj); /** * Call existing ruby functions with a block. */ @@ -960,16 +977,19 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int /** * Create a symbol * + * Example: + * * # Ruby style: * :pizza # => :pizza * * // C style: * mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza - * @param [mrb_state*] mrb_state* The current mruby state. - * @param [const char*] const char* The name of the method. + * + * @param mrb The current mruby state. + * @param str The string to be symbolized * @return [mrb_sym] mrb_sym A symbol. */ -MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*); +MRB_API mrb_sym mrb_intern_cstr(mrb_state *mrb, const char* str); MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t); MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t); #define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, lit, mrb_strlen_lit(lit)) @@ -1220,31 +1240,31 @@ MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RC MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func); -/* +/** * Resume a Fiber * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv); -/* +/** * Yield a Fiber * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv); -/* +/** * Check if a Fiber is alive * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib); -/* +/** * FiberError reference * - * @mrbgem mruby-fiber + * Implemented in mruby-fiber */ #define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError")) MRB_API void mrb_stack_extend(mrb_state*, mrb_int); diff --git a/include/mruby/error.h b/include/mruby/error.h index 5aa8bbda9..15855f96e 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -69,14 +69,14 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val) /** * Protect * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state); /** * Ensure * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t ensure, mrb_value e_data); @@ -84,7 +84,7 @@ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data, /** * Rescue * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data); @@ -92,7 +92,7 @@ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data, /** * Rescue exception * - * @mrbgem mruby-error + * Implemented in the mruby-error mrbgem */ MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data, diff --git a/include/mruby/string.h b/include/mruby/string.h index 84a6c4665..fd078b9f3 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -136,9 +136,8 @@ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_i * Appends self to other. Returns self as a concatenated string. * * - * Example: + * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -160,32 +159,30 @@ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_i * // Concatenates str2 to str1. * mrb_str_concat(mrb, str1, str2); * - * // Prints new Concatenated Ruby string. - * mrb_p(mrb, str1); - * - * mrb_close(mrb); - * return 0; - * } + * // Prints new Concatenated Ruby string. + * mrb_p(mrb, str1); * + * mrb_close(mrb); + * return 0; + * } * - * Result: + * Result: * * => "abcdef" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] self String to concatenate. - * @param [mrb_value] other String to append to self. + * @param mrb The current mruby state. + * @param self String to concatenate. + * @param other String to append to self. * @return [mrb_value] Returns a new String appending other to self. */ -MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); +MRB_API void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other); /** * Adds two strings together. * * - * Example: + * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -212,41 +209,41 @@ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); * // Concatenates both Ruby strings. * c = mrb_str_plus(mrb, a, b); * - * // Prints new Concatenated Ruby string. - * mrb_p(mrb, c); + * // Prints new Concatenated Ruby string. + * mrb_p(mrb, c); * - * mrb_close(mrb); - * return 0; - * } + * mrb_close(mrb); + * return 0; + * } * * - * Result: + * Result: * * => "abc" # First string * => "def" # Second string * => "abcdef" # First & Second concatenated. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] a First string to concatenate. - * @param [mrb_value] b Second string to concatenate. + * @param mrb The current mruby state. + * @param a First string to concatenate. + * @param b Second string to concatenate. * @return [mrb_value] Returns a new String containing a concatenated to b. */ -MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); +MRB_API mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b); /** * Converts pointer into a Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [void*] p The pointer to convert to Ruby string. + * @param mrb The current mruby state. + * @param p The pointer to convert to Ruby string. * @return [mrb_value] Returns a new Ruby String. */ -MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*); +MRB_API mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p); /** * Returns an object as a Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] obj An object to return as a Ruby string. + * @param mrb The current mruby state. + * @param obj An object to return as a Ruby string. * @return [mrb_value] An object as a Ruby string. */ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); @@ -257,7 +254,6 @@ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); * * Example: * - * !!!c * int * main(int argc, * char **argv) @@ -282,11 +278,11 @@ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); * * Result: * - * => "Hello" + * => "Hello" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str The Ruby string to resize. - * @param [mrb_value] len The length. + * @param mrb The current mruby state. + * @param str The Ruby string to resize. + * @param len The length. * @return [mrb_value] An object as a Ruby string. */ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); @@ -294,9 +290,8 @@ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); /** * Returns a sub string. * - * Example: + * Example: * - * !!!c * int * main(int argc, * char const **argv) @@ -322,14 +317,14 @@ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); * return 0; * } * - * Result: + * Result: * * => "He" * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [mrb_int] beg The beginning point of the sub-string. - * @param [mrb_int] len The end point of the sub-string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param beg The beginning point of the sub-string. + * @param len The end point of the sub-string. * @return [mrb_value] An object as a Ruby sub-string. */ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); @@ -338,8 +333,8 @@ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb * Returns a Ruby string type. * * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. + * @param mrb The current mruby state. + * @param str Ruby string. * @return [mrb_value] A Ruby string. */ MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str); @@ -364,8 +359,8 @@ MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str); * Duplicates a string object. * * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. + * @param mrb The current mruby state. + * @param str Ruby string. * @return [mrb_value] Duplicated Ruby string. */ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); @@ -373,8 +368,8 @@ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); /** * Returns a symbol from a passed in Ruby string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] self Ruby string. + * @param mrb The current mruby state. + * @param self Ruby string. * @return [mrb_value] A symbol. */ MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); @@ -393,9 +388,9 @@ MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str); /** * Returns true if the strings match and false if the strings don't match. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str1 Ruby string to compare. - * @param [mrb_value] str2 Ruby string to compare. + * @param mrb The current mruby state. + * @param str1 Ruby string to compare. + * @param str2 Ruby string to compare. * @return [mrb_value] boolean value. */ MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); @@ -403,10 +398,10 @@ MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); /** * Returns a concatenated string comprised of a Ruby string and a C string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [const char *] ptr A C string. - * @param [size_t] len length of C string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param ptr A C string. + * @param len length of C string. * @return [mrb_value] A Ruby string. * @see mrb_str_cat_cstr */ @@ -415,9 +410,9 @@ MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, si /** * Returns a concatenated string comprised of a Ruby string and a C string. * - * @param [mrb_state] mrb The current mruby state. - * @param [mrb_value] str Ruby string. - * @param [const char *] ptr A C string. + * @param mrb The current mruby state. + * @param str Ruby string. + * @param ptr A C string. * @return [mrb_value] A Ruby string. * @see mrb_str_cat */ @@ -446,8 +441,8 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); * - Caller can modify returned string without affecting Ruby string * (e.g. it can be used for mkstemp(3)). * - * @param [mrb_state *] mrb The current mruby state. - * @param [mrb_value] str Ruby string. Must be an instance of String. + * @param mrb The current mruby state. + * @param str Ruby string. Must be an instance of String. * @return [char *] A newly allocated C string. */ MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); diff --git a/include/mruby/variable.h b/include/mruby/variable.h index 8ae33304d..6e918cf57 100644 --- a/include/mruby/variable.h +++ b/include/mruby/variable.h @@ -97,18 +97,15 @@ MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val); * * Example: * - * !!!ruby * # Ruby style * $value = nil * - * !!!c * // C style * mrb_sym sym = mrb_intern_lit(mrb, "$value"); * mrb_gv_remove(mrb, sym); * * @param mrb The mruby state reference * @param sym The name of the global variable - * @param val The value of the global variable */ MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym); diff --git a/src/class.c b/src/class.c index 43540dc3b..2be56a004 100644 --- a/src/class.c +++ b/src/class.c @@ -409,7 +409,7 @@ mrb_module_get(mrb_state *mrb, const char *name) /*! * Defines a class under the namespace of \a outer. * \param outer a class which contains the new class. - * \param id name of the new class + * \param name name of the new class * \param super a class from which the new class will derive. * NULL means \c Object class. * \return the created class @@ -1769,6 +1769,7 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b) /*! * Defines an alias of a method. + * \param mrb the mruby state * \param klass the class which the original method belongs to * \param name1 a new name for the method * \param name2 the original name of the method diff --git a/tasks/doc.rake b/tasks/doc.rake index ab34b33b1..4aec2d0a1 100644 --- a/tasks/doc.rake +++ b/tasks/doc.rake @@ -36,3 +36,13 @@ end desc 'clean all built docs' task :clean_doc => [:clean_api_doc, :clean_capi_doc] do end + +desc 'clean all built docs' +task :view_api => [:api_doc] do + sh 'xdg-open doc/api/index.html' +end + +desc 'clean all built docs' +task :view_capi => [:capi_doc] do + sh 'xdg-open doc/capi/html/index.html' +end -- cgit v1.2.3 From 07c6b7f0abcb937b79f23145be1edd34d85e65f6 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Thu, 12 Sep 2019 21:45:47 +0900 Subject: Refine `tasks/toolchains/(gcc|clang).rake` - Make sure to specify `-std=gnu99` for C compiler flag. - Make sure to specify `-Wzero-length-array` for C/C++ compiler flag (Clang). - Extract similar codes. --- tasks/toolchains/clang.rake | 10 +++------- tasks/toolchains/gcc.rake | 36 +++++++++++++++++------------------- 2 files changed, 20 insertions(+), 26 deletions(-) (limited to 'tasks') diff --git a/tasks/toolchains/clang.rake b/tasks/toolchains/clang.rake index 7d0fe6a45..b38f531b7 100644 --- a/tasks/toolchains/clang.rake +++ b/tasks/toolchains/clang.rake @@ -1,11 +1,7 @@ MRuby::Toolchain.new(:clang) do |conf, _params| - toolchain :gcc + toolchain :gcc, default_command: 'clang' - [conf.cc, conf.objc, conf.asm].each do |cc| - cc.command = ENV['CC'] || 'clang' - cc.flags << '-Wzero-length-array' unless ENV['CFLAGS'] + [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler| + compiler.flags.unshift('-Wzero-length-array') end - conf.cxx.command = ENV['CXX'] || 'clang++' - conf.cxx.flags << '-Wzero-length-array' unless ENV['CXXFLAGS'] || ENV['CFLAGS'] - conf.linker.command = ENV['LD'] || ENV['CXX'] || ENV['CC'] || 'clang' end diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index 663fef9e6..ca083a4b2 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -1,26 +1,24 @@ -MRuby::Toolchain.new(:gcc) do |conf, _params| - [conf.cc, conf.objc, conf.asm].each do |cc| - cc.command = ENV['CC'] || 'gcc' - cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement -Wwrite-strings -Wundef)] - cc.option_include_path = '-I%s' - cc.option_define = '-D%s' - cc.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' - cc.cxx_compile_flag = '-x c++ -std=c++03' - cc.cxx_exception_flag = '-fexceptions' - end +MRuby::Toolchain.new(:gcc) do |conf, params| + default_command = params[:default_command] || 'gcc' + compile_flags = %w(-g -O3 -Wall -Wundef -Werror-implicit-function-declaration) - [conf.cxx].each do |cxx| - cxx.command = ENV['CXX'] || 'g++' - cxx.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || %w(-g -O3 -Wall -Werror-implicit-function-declaration -Wundef)] - cxx.option_include_path = '-I%s' - cxx.option_define = '-D%s' - cxx.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' - cxx.cxx_compile_flag = '-x c++ -std=c++03' - cxx.cxx_exception_flag = '-fexceptions' + [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler| + if compiler == conf.cxx + compiler.command = ENV['CXX'] || default_command.sub(/cc|$/, '++') + compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compile_flags] + else + compiler.command = ENV['CC'] || default_command + compiler.flags = ['-std=gnu99', ENV['CFLAGS'] || [compile_flags, %w(-Wdeclaration-after-statement -Wwrite-strings)]] + end + compiler.option_include_path = '-I%s' + compiler.option_define = '-D%s' + compiler.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' + compiler.cxx_compile_flag = '-x c++ -std=c++03' + compiler.cxx_exception_flag = '-fexceptions' end conf.linker do |linker| - linker.command = ENV['LD'] || ENV['CXX'] || ENV['CC'] || 'gcc' + linker.command = ENV['LD'] || ENV['CXX'] || ENV['CC'] || default_command linker.flags = [ENV['LDFLAGS'] || %w()] linker.libraries = %w(m) linker.library_paths = [] -- cgit v1.2.3 From be76cec3422ddedbfce48768db5aec004e2f0aee Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 13 Sep 2019 17:14:37 +0900 Subject: Fix warnings for invalid C++ option with `enable_cxx_abi`; ref #3618, #4703 --- lib/mruby/build.rb | 2 +- lib/mruby/build/command.rb | 3 ++- tasks/toolchains/gcc.rake | 9 ++++++--- travis_config.rb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'tasks') diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 5bedfc0e6..375b2933a 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -162,7 +162,7 @@ module MRuby compilers.each { |c| c.defines += %w(MRB_ENABLE_CXX_EXCEPTION MRB_ENABLE_CXX_ABI) c.flags << c.cxx_compile_flag - c.flags.delete('-std=gnu99') + c.flags = c.flags.flatten - c.cxx_invalid_flags.flatten } linker.command = cxx.command if toolchains.find { |v| v == 'gcc' } @cxx_abi_enabled = true diff --git a/lib/mruby/build/command.rb b/lib/mruby/build/command.rb index a98f2ca7e..bff250c93 100644 --- a/lib/mruby/build/command.rb +++ b/lib/mruby/build/command.rb @@ -41,7 +41,7 @@ module MRuby class Command::Compiler < Command attr_accessor :flags, :include_paths, :defines, :source_exts attr_accessor :compile_options, :option_define, :option_include_path, :out_ext - attr_accessor :cxx_compile_flag, :cxx_exception_flag + attr_accessor :cxx_compile_flag, :cxx_exception_flag, :cxx_invalid_flags def initialize(build, source_exts=[]) super(build) @@ -53,6 +53,7 @@ module MRuby @option_include_path = '-I%s' @option_define = '-D%s' @compile_options = '%{flags} -o %{outfile} -c %{infile}' + @cxx_invalid_flags = [] end alias header_search_paths include_paths diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index ca083a4b2..1a28026bf 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -1,20 +1,23 @@ MRuby::Toolchain.new(:gcc) do |conf, params| default_command = params[:default_command] || 'gcc' - compile_flags = %w(-g -O3 -Wall -Wundef -Werror-implicit-function-declaration) + compiler_flags = %w(-g -O3 -Wall -Wundef) + c_mandatory_flags = %w(-std=gnu99) + cxx_invalid_flags = %w(-Wdeclaration-after-statement -Werror-implicit-function-declaration) [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler| if compiler == conf.cxx compiler.command = ENV['CXX'] || default_command.sub(/cc|$/, '++') - compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compile_flags] + compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compiler_flags] else compiler.command = ENV['CC'] || default_command - compiler.flags = ['-std=gnu99', ENV['CFLAGS'] || [compile_flags, %w(-Wdeclaration-after-statement -Wwrite-strings)]] + compiler.flags = [c_mandatory_flags, ENV['CFLAGS'] || [compiler_flags, cxx_invalid_flags, %w(-Wwrite-strings)]] end compiler.option_include_path = '-I%s' compiler.option_define = '-D%s' compiler.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' compiler.cxx_compile_flag = '-x c++ -std=c++03' compiler.cxx_exception_flag = '-fexceptions' + compiler.cxx_invalid_flags = c_mandatory_flags + cxx_invalid_flags end conf.linker do |linker| diff --git a/travis_config.rb b/travis_config.rb index 7a13ced72..94cd4aadc 100644 --- a/travis_config.rb +++ b/travis_config.rb @@ -40,7 +40,7 @@ MRuby::Build.new('cxx_abi') do |conf| toolchain :gcc conf.gembox 'full-core' - conf.cc.flags += %w(-Werror=declaration-after-statement -fpermissive) + conf.cc.flags += %w(-fpermissive) conf.compilers.each do |c| c.defines += %w(MRB_GC_FIXED_ARENA) end -- cgit v1.2.3 From 895ab2342edecbf7911ec9a8753d632f52f1e6ff Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 13 Sep 2019 21:28:23 +0900 Subject: Revert part of "Refine `tasks/toolchains/(gcc|clang).rake`" (07c6b7f0) `-Wzero-length-array` is not a mandatory option, so the original is better. --- tasks/toolchains/clang.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tasks') diff --git a/tasks/toolchains/clang.rake b/tasks/toolchains/clang.rake index b38f531b7..543cb73db 100644 --- a/tasks/toolchains/clang.rake +++ b/tasks/toolchains/clang.rake @@ -1,7 +1,8 @@ MRuby::Toolchain.new(:clang) do |conf, _params| toolchain :gcc, default_command: 'clang' - [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler| - compiler.flags.unshift('-Wzero-length-array') + [conf.cc, conf.objc, conf.asm].each do |cc| + cc.flags << '-Wzero-length-array' unless ENV['CFLAGS'] end + conf.cxx.flags << '-Wzero-length-array' unless ENV['CXXFLAGS'] || ENV['CFLAGS'] end -- cgit v1.2.3 From edd412966ef815fb9e2185c019a7128f9922c134 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 4 Oct 2019 09:31:54 +0900 Subject: Remove unused code to old Visual Studio in `tasks/toolchains/visualcpp.rake` --- tasks/toolchains/visualcpp.rake | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'tasks') diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake index 6275059bb..c5f295130 100644 --- a/tasks/toolchains/visualcpp.rake +++ b/tasks/toolchains/visualcpp.rake @@ -54,16 +54,4 @@ MRuby::Toolchain.new(:visualcpp) do |conf, _params| end conf.file_separator = '\\' - - # Unreliable detection and will result in invalid encoding errors for localized versions of Visual C++ - # if require 'open3' - # Open3.popen3 conf.cc.command do |_, _, e, _| - # if /Version (\d{2})\.\d{2}\.\d{5}/ =~ e.gets && $1.to_i <= 17 - # m = "# VS2010/2012 support will be dropped after the next release! #" - # h = "#" * m.length - # puts h, m, h - # end - # end - # end - end -- cgit v1.2.3