Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
81de1f15
Commit
81de1f15
authored
Dec 12, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `mrb_num_args_error()` for "wrong number of arguments" error
To unify the style of messages.
parent
9c4c82ed
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
6 deletions
+20
-6
include/mruby.h
include/mruby.h
+1
-0
mrbgems/mruby-io/src/io.c
mrbgems/mruby-io/src/io.c
+1
-1
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
+1
-1
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+1
-1
src/error.c
src/error.c
+14
-1
src/hash.c
src/hash.c
+1
-1
src/kernel.c
src/kernel.c
+1
-1
No files found.
include/mruby.h
View file @
81de1f15
...
...
@@ -1232,6 +1232,7 @@ MRB_API mrb_noreturn void mrb_raise(mrb_state *mrb, struct RClass *c, const char
MRB_API
mrb_noreturn
void
mrb_raisef
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_name_error
(
mrb_state
*
mrb
,
mrb_sym
id
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_frozen_error
(
mrb_state
*
mrb
,
void
*
frozen_obj
);
MRB_API
mrb_noreturn
void
mrb_num_args_error
(
mrb_state
*
mrb
,
mrb_int
argc
,
int
min
,
int
max
);
MRB_API
void
mrb_warn
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
mrb_noreturn
void
mrb_bug
(
mrb_state
*
mrb
,
const
char
*
fmt
,
...);
MRB_API
void
mrb_print_backtrace
(
mrb_state
*
mrb
);
...
...
mrbgems/mruby-io/src/io.c
View file @
81de1f15
...
...
@@ -1060,7 +1060,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 (%i for 1..4)"
,
argc
);
mrb_
num_args_error
(
mrb
,
argc
,
1
,
4
);
}
timeout
=
mrb_nil_value
();
...
...
mrbgems/mruby-socket/src/socket.c
View file @
81de1f15
...
...
@@ -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 (%i for 3)"
,
argc
);
mrb_
num_args_error
(
mrb
,
argc
,
3
,
3
);
}
s
=
socket_fd
(
mrb
,
self
);
...
...
mrbgems/mruby-struct/src/struct.c
View file @
81de1f15
...
...
@@ -274,7 +274,7 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass)
name
=
mrb_nil_value
();
mrb_get_args
(
mrb
,
"*&"
,
&
argv
,
&
argc
,
&
b
);
if
(
argc
==
0
)
{
/* special case to avoid crash */
mrb_
raise
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments"
);
mrb_
num_args_error
(
mrb
,
argc
,
1
,
-
1
);
}
else
{
pargv
=
argv
;
...
...
src/error.c
View file @
81de1f15
...
...
@@ -530,7 +530,7 @@ exception_call:
break
;
default:
mrb_
raisef
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments (%i for 0..3)"
,
argc
);
mrb_
num_args_error
(
mrb
,
argc
,
0
,
3
);
break
;
}
if
(
argc
>
0
)
{
...
...
@@ -586,6 +586,19 @@ mrb_frozen_error(mrb_state *mrb, void *frozen_obj)
mrb_raisef
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen %t"
,
mrb_obj_value
(
frozen_obj
));
}
MRB_API
mrb_noreturn
void
mrb_num_args_error
(
mrb_state
*
mrb
,
mrb_int
argc
,
int
min
,
int
max
)
{
#define FMT(exp) "wrong number of arguments (given %i, expected " exp ")"
if
(
min
==
max
)
mrb_raisef
(
mrb
,
E_ARGUMENT_ERROR
,
FMT
(
"%d"
),
argc
,
min
);
else
if
(
max
<
0
)
mrb_raisef
(
mrb
,
E_ARGUMENT_ERROR
,
FMT
(
"%d+"
),
argc
,
min
);
else
mrb_raisef
(
mrb
,
E_ARGUMENT_ERROR
,
FMT
(
"%d..%d"
),
argc
,
min
,
max
);
#undef FMT
}
void
mrb_init_exception
(
mrb_state
*
mrb
)
{
...
...
src/hash.c
View file @
81de1f15
...
...
@@ -800,7 +800,7 @@ mrb_hash_init(mrb_state *mrb, mrb_value hash)
mrb_hash_modify
(
mrb
,
hash
);
if
(
!
mrb_nil_p
(
block
))
{
if
(
ifnone_p
)
{
mrb_
raise
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments"
);
mrb_
num_args_error
(
mrb
,
1
,
0
,
0
);
}
RHASH
(
hash
)
->
flags
|=
MRB_HASH_PROC_DEFAULT
;
ifnone
=
block
;
...
...
src/kernel.c
View file @
81de1f15
...
...
@@ -384,7 +384,7 @@ mrb_obj_extend(mrb_state *mrb, mrb_int argc, mrb_value *argv, mrb_value obj)
mrb_int
i
;
if
(
argc
==
0
)
{
mrb_
raise
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments (at least 1)"
);
mrb_
num_args_error
(
mrb
,
argc
,
1
,
-
1
);
}
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
mrb_check_type
(
mrb
,
argv
[
i
],
MRB_TT_MODULE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment