Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-107122: Add clear method to dbm.ndbm module#107126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7a930a7d0f930c7a7e8263affdb72be54021d144405eb2b13File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :meth:`dbm.ndbm.clear` to :mod:`dbm.ndbm`. Patch By Dong-hee Na. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -414,6 +414,38 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key, | ||
| return default_value; | ||
| } | ||
| /*[clinic input] | ||
| _dbm.dbm.clear | ||
| cls: defining_class | ||
| / | ||
| Remove all items from the database. | ||
| [clinic start generated code]*/ | ||
| static PyObject * | ||
| _dbm_dbm_clear_impl(dbmobject *self, PyTypeObject *cls) | ||
| /*[clinic end generated code: output=8d126b9e1d01a434 input=43aa6ca1acb7f5f5]*/ | ||
| { | ||
| _dbm_state *state = PyType_GetModuleState(cls); | ||
| assert(state != NULL); | ||
| check_dbmobject_open(self, state->dbm_error); | ||
| datum key; | ||
| // Invalidate cache | ||
| self->di_size = -1; | ||
| while (1){ | ||
| key = dbm_firstkey(self->di_dbm); | ||
| if (key.dptr == NULL){ | ||
| break; | ||
| } | ||
| if (dbm_delete(self->di_dbm, key) < 0){ | ||
| dbm_clearerr(self->di_dbm); | ||
| PyErr_SetString(state->dbm_error, "cannot delete item from database"); | ||
corona10 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return NULL; | ||
| } | ||
| } | ||
| Py_RETURN_NONE; | ||
| } | ||
| static PyObject * | ||
| dbm__enter__(PyObject *self, PyObject *args) | ||
| { | ||
| @@ -431,6 +463,7 @@ static PyMethodDef dbm_methods[] ={ | ||
| _DBM_DBM_KEYS_METHODDEF | ||
| _DBM_DBM_GET_METHODDEF | ||
| _DBM_DBM_SETDEFAULT_METHODDEF | ||
| _DBM_DBM_CLEAR_METHODDEF | ||
| {"__enter__", dbm__enter__, METH_NOARGS, NULL}, | ||
| {"__exit__", dbm__exit__, METH_VARARGS, NULL}, | ||
| {NULL, NULL} /* sentinel */ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.