Unverified Commit dc11e7f0 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4613 from...

Merge pull request #4613 from shuujii/change-second-argument-to-%l-of-mrb_vformat-to-size_t-from-mrb_int

Change second argument to `%l` of `mrb_vformat()` to `size_t` from `mrb_int`
parents f6c41c18 1e9cb74c
......@@ -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);
......
......@@ -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);
......
......@@ -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'
......
......@@ -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 '#<Class:#<Class:#<Hash:0x*>>>', ['%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,{}]]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment