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
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
067ae126
Commit
067ae126
authored
10 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
objclosure: Fix printing of generator closures.
The code previously assumed that only functions can be closed over.
parent
9b0b373e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objclosure.c
+3
-1
3 additions, 1 deletion
py/objclosure.c
tests/basics/generator_closure.py
+6
-0
6 additions, 0 deletions
tests/basics/generator_closure.py
with
9 additions
and
1 deletion
py/objclosure.c
+
3
−
1
View file @
067ae126
...
...
@@ -67,7 +67,9 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
STATIC
void
closure_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
)
{
mp_obj_closure_t
*
o
=
o_in
;
print
(
env
,
"<closure %s at %p, n_closed=%u "
,
mp_obj_fun_get_name
(
o
->
fun
),
o
,
o
->
n_closed
);
print
(
env
,
"<closure "
);
mp_obj_print_helper
(
print
,
env
,
o
->
fun
,
PRINT_REPR
);
print
(
env
,
" at %p, n_closed=%u "
,
o
,
o
->
n_closed
);
for
(
mp_uint_t
i
=
0
;
i
<
o
->
n_closed
;
i
++
)
{
if
(
o
->
closed
[
i
]
==
MP_OBJ_NULL
)
{
print
(
env
,
"(nil)"
);
...
...
This diff is collapsed.
Click to expand it.
tests/basics/generator_closure.py
+
6
−
0
View file @
067ae126
...
...
@@ -24,3 +24,9 @@ generator_of_generators = (((x, y) for x in range(2)) for y in range(3))
for
i
in
generator_of_generators
:
for
j
in
i
:
print
(
j
)
# test that printing of closed-over generators doesn't lead to segfaults
def
genc
():
foo
=
1
repr
(
lambda
:
(
yield
foo
))
genc
()
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