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
88f3043e
Commit
88f3043e
authored
Jan 6, 2014
by
John R. Lenton
Browse files
Options
Downloads
Patches
Plain Diff
added a first pass of dict.update
parent
e3096172
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objdict.c
+28
-1
28 additions, 1 deletion
py/objdict.c
py/runtime.c
+2
-2
2 additions, 2 deletions
py/runtime.c
with
30 additions
and
3 deletions
py/objdict.c
+
28
−
1
View file @
88f3043e
...
...
@@ -157,7 +157,7 @@ static mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, bo
value
=
elem
->
value
;
if
(
pop
)
{
/* catch the leak (from mp_map_lookup_helper) */
m_free
(
elem
,
2
*
sizeof
(
mp_
obj
_t
));
m_free
(
elem
,
sizeof
(
mp_
map_elem
_t
));
}
}
if
(
set
)
{
...
...
@@ -220,6 +220,32 @@ static mp_obj_t dict_popitem(mp_obj_t self_in) {
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
dict_popitem_obj
,
dict_popitem
);
static
mp_obj_t
dict_update
(
mp_obj_t
self_in
,
mp_obj_t
iterable
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
dict_type
));
mp_obj_dict_t
*
self
=
self_in
;
/* TODO: check for the "keys" method */
mp_obj_t
iter
=
rt_getiter
(
iterable
);
mp_obj_t
next
=
NULL
;
while
((
next
=
rt_iternext
(
iter
))
!=
mp_const_stop_iteration
)
{
mp_obj_t
inneriter
=
rt_getiter
(
next
);
mp_obj_t
key
=
rt_iternext
(
inneriter
);
mp_obj_t
value
=
rt_iternext
(
inneriter
);
mp_obj_t
stop
=
rt_iternext
(
inneriter
);
if
(
key
==
mp_const_stop_iteration
||
value
==
mp_const_stop_iteration
||
stop
!=
mp_const_stop_iteration
)
{
nlr_jump
(
mp_obj_new_exception_msg
(
MP_QSTR_ValueError
,
"dictionary update sequence has the wrong length"
));
}
else
{
mp_map_lookup_helper
(
&
self
->
map
,
key
,
true
,
false
)
->
value
=
value
;
}
}
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
dict_update_obj
,
dict_update
);
/******************************************************************************/
/* dict constructors & etc */
...
...
@@ -238,6 +264,7 @@ const mp_obj_type_t dict_type = {
{
"pop"
,
&
dict_pop_obj
},
{
"popitem"
,
&
dict_popitem_obj
},
{
"setdefault"
,
&
dict_setdefault_obj
},
{
"update"
,
&
dict_update_obj
},
{
NULL
,
NULL
},
// end-of-list sentinel
},
};
...
...
This diff is collapsed.
Click to expand it.
py/runtime.c
+
2
−
2
View file @
88f3043e
...
...
@@ -859,13 +859,13 @@ mp_obj_t rt_getiter(mp_obj_t o_in) {
mp_obj_t
rt_iternext
(
mp_obj_t
o_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
o_in
))
{
nlr_jump
(
mp_obj_new_exception_msg
(
MP_QSTR_TypeError
,
"
?
'int' object is not itera
ble
"
));
nlr_jump
(
mp_obj_new_exception_msg
(
MP_QSTR_TypeError
,
"'int' object is not
an
itera
tor
"
));
}
else
{
mp_obj_base_t
*
o
=
o_in
;
if
(
o
->
type
->
iternext
!=
NULL
)
{
return
o
->
type
->
iternext
(
o_in
);
}
else
{
nlr_jump
(
mp_obj_new_exception_msg_1_arg
(
MP_QSTR_TypeError
,
"
?
'%s' object is not itera
ble
"
,
o
->
type
->
name
));
nlr_jump
(
mp_obj_new_exception_msg_1_arg
(
MP_QSTR_TypeError
,
"'%s' object is not
an
itera
tor
"
,
o
->
type
->
name
));
}
}
}
...
...
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