diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-17 15:59:51 +1000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-17 15:59:51 +1000 |
commit | c610aba1ed57a30104a254ccd1f9fe07d02b1334 (patch) | |
tree | de690ad2f0b0f9cda831d66f026e5494a77882c5 /Modules/_gdbmmodule.c | |
parent | eb8ea265bac16844efebe4f42d3c674527a66988 (diff) | |
download | cpython-git-c610aba1ed57a30104a254ccd1f9fe07d02b1334.tar.gz |
Close #19282: Native context management in dbm
Diffstat (limited to 'Modules/_gdbmmodule.c')
-rw-r--r-- | Modules/_gdbmmodule.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 36c06d13b7..229e16e627 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -425,6 +425,20 @@ dbm_sync(dbmobject *dp, PyObject *unused) return Py_None; } +static PyObject * +dbm__enter__(PyObject *self, PyObject *args) +{ + Py_INCREF(self); + return self; +} + +static PyObject * +dbm__exit__(PyObject *self, PyObject *args) +{ + _Py_IDENTIFIER(close); + return _PyObject_CallMethodId(self, &PyId_close, NULL); +} + static PyMethodDef dbm_methods[] = { {"close", (PyCFunction)dbm_close, METH_NOARGS, dbm_close__doc__}, {"keys", (PyCFunction)dbm_keys, METH_NOARGS, dbm_keys__doc__}, @@ -434,6 +448,8 @@ static PyMethodDef dbm_methods[] = { {"sync", (PyCFunction)dbm_sync, METH_NOARGS, dbm_sync__doc__}, {"get", (PyCFunction)dbm_get, METH_VARARGS, dbm_get__doc__}, {"setdefault",(PyCFunction)dbm_setdefault,METH_VARARGS, dbm_setdefault__doc__}, + {"__enter__", dbm__enter__, METH_NOARGS, NULL}, + {"__exit__", dbm__exit__, METH_VARARGS, NULL}, {NULL, NULL} /* sentinel */ }; |