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.
MODIFY
mrbgems/mruby-test/vformat.c
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);

MODIFY
src/error.c
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);

MODIFY
tasks/toolchains/visualcpp.rake
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'

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.