Skip to content
Snippets Groups Projects
Commit 422396ce authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

extmod/modbtree: Handle default value and error check.

parent a1eab98e
No related branches found
No related tags found
No related merge requests found
......@@ -92,8 +92,13 @@ STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) {
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
int res = __bt_get(self->db, &key, &val, 0);
if (res == RET_SPECIAL) {
return mp_const_none;
if (n_args > 2) {
return args[2];
} else {
return mp_const_none;
}
}
CHECK_ERROR(res);
return mp_obj_new_bytes(val.data, val.size);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_get_obj, 2, 3, btree_get);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment