Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5b5562c1
Commit
5b5562c1
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Fix stack underflow with optimised for loop.
parent
049a01d1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/compile.c
+1
-1
1 addition, 1 deletion
py/compile.c
py/vm.c
+3
-3
3 additions, 3 deletions
py/vm.c
tests/basics/for_return.py
+7
-0
7 additions, 0 deletions
tests/basics/for_return.py
with
11 additions
and
4 deletions
py/compile.c
+
1
−
1
View file @
5b5562c1
...
@@ -1745,7 +1745,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
...
@@ -1745,7 +1745,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// And, if the loop never runs, the loop variable should never be assigned
// And, if the loop never runs, the loop variable should never be assigned
void
compile_for_stmt_optimised_range
(
compiler_t
*
comp
,
mp_parse_node_t
pn_var
,
mp_parse_node_t
pn_start
,
mp_parse_node_t
pn_end
,
mp_parse_node_t
pn_step
,
mp_parse_node_t
pn_body
,
mp_parse_node_t
pn_else
)
{
void
compile_for_stmt_optimised_range
(
compiler_t
*
comp
,
mp_parse_node_t
pn_var
,
mp_parse_node_t
pn_start
,
mp_parse_node_t
pn_end
,
mp_parse_node_t
pn_step
,
mp_parse_node_t
pn_body
,
mp_parse_node_t
pn_else
)
{
START_BREAK_CONTINUE_BLOCK
START_BREAK_CONTINUE_BLOCK
comp
->
break_label
|=
MP_EMIT_BREAK_FROM_FOR
;
// note that we don't need to pop anything when breaking from an optimise for loop
uint
top_label
=
comp_next_label
(
comp
);
uint
top_label
=
comp_next_label
(
comp
);
uint
entry_label
=
comp_next_label
(
comp
);
uint
entry_label
=
comp_next_label
(
comp
);
...
...
This diff is collapsed.
Click to expand it.
py/vm.c
+
3
−
3
View file @
5b5562c1
...
@@ -159,8 +159,8 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
...
@@ -159,8 +159,8 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
#if DETECT_VM_STACK_OVERFLOW
#if DETECT_VM_STACK_OVERFLOW
if
(
vm_return_kind
==
MP_VM_RETURN_NORMAL
)
{
if
(
vm_return_kind
==
MP_VM_RETURN_NORMAL
)
{
if
(
sp
!=
state
)
{
if
(
sp
<
state
)
{
printf
(
"
S
tack
misalign: %d
\n
"
,
sp
-
state
);
printf
(
"
VM s
tack
underflow: "
INT_FMT
"
\n
"
,
sp
-
state
);
assert
(
0
);
assert
(
0
);
}
}
}
}
...
@@ -178,7 +178,7 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
...
@@ -178,7 +178,7 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
}
}
}
}
if
(
overflow
)
{
if
(
overflow
)
{
printf
(
"VM stack overflow state=%p n_state+1=
%u
\n
"
,
state
,
n_state
);
printf
(
"VM stack overflow state=%p n_state+1=
"
UINT_FMT
"
\n
"
,
state
,
n_state
);
assert
(
0
);
assert
(
0
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/basics/for_return.py
0 → 100644
+
7
−
0
View file @
5b5562c1
# test returning from within a for loop
def
f
():
for
i
in
[
1
,
2
,
3
]:
return
i
print
(
f
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment