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
a165fce1
Commit
a165fce1
authored
Mar 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #937 from monaka/pr-remove-snprintf-from-localjump_error
Reduce a snprintf() call in localjump_error().
parents
ec70b2ab
15ac0e03
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
src/vm.c
src/vm.c
+19
-10
No files found.
src/vm.c
View file @
a165fce1
...
...
@@ -453,15 +453,24 @@ mrb_yield(mrb_state *mrb, mrb_value b, mrb_value v)
return
mrb_yield_internal
(
mrb
,
b
,
1
,
&
v
,
mrb
->
stack
[
0
],
p
->
target_class
);
}
typedef
enum
{
LOCALJUMP_ERROR_RETURN
=
0
,
LOCALJUMP_ERROR_BREAK
=
1
,
LOCALJUMP_ERROR_YIELD
=
2
}
localjump_error_kind
;
static
void
localjump_error
(
mrb_state
*
mrb
,
const
char
*
kind
)
localjump_error
(
mrb_state
*
mrb
,
localjump_error_kind
kind
)
{
char
buf
[
256
];
int
len
;
char
kind_str
[
3
][
7
]
=
{
"return"
,
"break"
,
"yield"
};
char
kind_str_len
[]
=
{
6
,
5
,
5
};
static
const
char
lead
[]
=
"unexpected "
;
mrb_value
msg
;
mrb_value
exc
;
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"unexpected %s"
,
kind
);
exc
=
mrb_exc_new
(
mrb
,
E_LOCALJUMP_ERROR
,
buf
,
len
);
msg
=
mrb_str_new
(
mrb
,
lead
,
sizeof
(
lead
)
-
1
);
mrb_str_buf_cat
(
mrb
,
msg
,
kind_str
[
kind
],
kind_str_len
[
kind
]);
exc
=
mrb_exc_new3
(
mrb
,
E_LOCALJUMP_ERROR
,
msg
);
mrb
->
exc
=
(
struct
RObject
*
)
mrb_object
(
exc
);
}
...
...
@@ -1218,12 +1227,12 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
struct
REnv
*
e
=
top_env
(
mrb
,
proc
);
if
(
e
->
cioff
<
0
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
}
ci
=
mrb
->
cibase
+
e
->
cioff
;
if
(
ci
==
mrb
->
cibase
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
}
mrb
->
ci
=
ci
;
...
...
@@ -1231,14 +1240,14 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
case
OP_R_NORMAL
:
if
(
ci
==
mrb
->
cibase
)
{
localjump_error
(
mrb
,
"return"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_RETURN
);
goto
L_RAISE
;
}
ci
=
mrb
->
ci
;
break
;
case
OP_R_BREAK
:
if
(
proc
->
env
->
cioff
<
0
)
{
localjump_error
(
mrb
,
"break"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_BREAK
);
goto
L_RAISE
;
}
ci
=
mrb
->
ci
=
mrb
->
cibase
+
proc
->
env
->
cioff
+
1
;
...
...
@@ -1350,7 +1359,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
else
{
struct
REnv
*
e
=
uvenv
(
mrb
,
lv
-
1
);
if
(
!
e
)
{
localjump_error
(
mrb
,
"yield"
);
localjump_error
(
mrb
,
LOCALJUMP_ERROR_YIELD
);
goto
L_RAISE
;
}
stack
=
e
->
stack
+
1
;
...
...
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