diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index 374eb169..201e20cd 100644 --- a/include/pocketpy/common.h +++ b/include/pocketpy/common.h @@ -21,7 +21,7 @@ #include #include -#define PK_VERSION "1.1.3" +#define PK_VERSION "1.1.4" #include "config.h" #include "export.h" diff --git a/include/pocketpy/dict.h b/include/pocketpy/dict.h index 56fc5262..b59899ab 100644 --- a/include/pocketpy/dict.h +++ b/include/pocketpy/dict.h @@ -49,7 +49,7 @@ struct Dict{ PyObject* try_get(PyObject* key) const; bool contains(PyObject* key) const; - void erase(PyObject* key); + bool erase(PyObject* key); void update(const Dict& other); template diff --git a/src/dict.cpp b/src/dict.cpp index 95f3dffe..f50c436d 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -102,10 +102,10 @@ namespace pkpy{ return ok; } - void Dict::erase(PyObject* key){ + bool Dict::erase(PyObject* key){ bool ok; int i; _probe(key, ok, i); - if(!ok) return; + if(!ok) return false; _items[i].first = nullptr; _items[i].second = nullptr; _size--; @@ -127,6 +127,7 @@ namespace pkpy{ } _nodes[i].prev = -1; _nodes[i].next = -1; + return true; } void Dict::update(const Dict& other){ diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index ba479a41..55b1b676 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -1077,8 +1077,8 @@ void init_builtins(VM* _vm) { _vm->bind__delitem__(_vm->tp_dict, [](VM* vm, PyObject* obj, PyObject* key) { Dict& self = _CAST(Dict&, obj); - if(!self.contains(key)) vm->KeyError(key); - self.erase(key); + bool ok = self.erase(key); + if(!ok) vm->KeyError(key); }); _vm->bind_method<1>("dict", "pop", [](VM* vm, ArgsView args) {