summaryrefslogtreecommitdiff
path: root/py/objdict.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-06-05 20:02:15 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-06-05 20:06:15 +0300
commit75ce9256b2c70bceee6ced26ac7c7bcbd1f1d7f4 (patch)
treee397a2e3c922a3e3290b022157296e232eb6b556 /py/objdict.c
parent1e82ef3ae8fd8c7570b3c2094fa8b129b354dcdd (diff)
objstr: Implement "%(key)s" % {} formatting for strings and dicts.
Also, make sure that args to "*" format specifiers are bounds-checked properly and don't lead for segfaults in case of mismatch.
Diffstat (limited to 'py/objdict.c')
-rw-r--r--py/objdict.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objdict.c b/py/objdict.c
index 8a0a08772..696aad80f 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -117,6 +117,17 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
}
+// TODO: Make sure this is inlined in dict_subscr() below.
+mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) {
+ mp_obj_dict_t *self = self_in;
+ mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP);
+ if (elem == NULL) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
+ } else {
+ return elem->value;
+ }
+}
+
STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (value == MP_OBJ_NULL) {
// delete