summaryrefslogtreecommitdiff
path: root/Modules/_gdbmmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-19 23:29:22 +0200
committerGitHub <noreply@github.com>2018-06-19 23:29:22 +0200
commit00f9edb98dd64e14daf5c44f303deca5cbc3cdeb (patch)
tree2389e3e854d72d5882ae3d64084bb2a19caf8554 /Modules/_gdbmmodule.c
parent06fe77a84bd29d51506ab2ff703ae585a6121af2 (diff)
downloadcpython-git-00f9edb98dd64e14daf5c44f303deca5cbc3cdeb.tar.gz
bpo-33901: Add _gdbm._GDBM_VERSION (GH-7794)
* Fix also PyInit__gdbm() to catch errors. * test.pythoninfo: add gdbm.version * test_dbm_gnu now logs GDBM_VERSION when run in verbose mode. * pythoninfo: rename function to collect_gdbm()
Diffstat (limited to 'Modules/_gdbmmodule.c')
-rw-r--r--Modules/_gdbmmodule.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index 9996d8c26f..a68cf02942 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -654,20 +654,43 @@ static struct PyModuleDef _gdbmmodule = {
PyMODINIT_FUNC
PyInit__gdbm(void) {
- PyObject *m, *d, *s;
+ PyObject *m;
if (PyType_Ready(&Dbmtype) < 0)
return NULL;
m = PyModule_Create(&_gdbmmodule);
- if (m == NULL)
+ if (m == NULL) {
return NULL;
- d = PyModule_GetDict(m);
+ }
+
DbmError = PyErr_NewException("_gdbm.error", PyExc_OSError, NULL);
- if (DbmError != NULL) {
- PyDict_SetItemString(d, "error", DbmError);
- s = PyUnicode_FromString(dbmmodule_open_flags);
- PyDict_SetItemString(d, "open_flags", s);
- Py_DECREF(s);
+ if (DbmError == NULL) {
+ goto error;
+ }
+ Py_INCREF(DbmError);
+ if (PyModule_AddObject(m, "error", DbmError) < 0) {
+ Py_DECREF(DbmError);
+ goto error;
+ }
+
+ if (PyModule_AddStringConstant(m, "open_flags",
+ dbmmodule_open_flags) < 0) {
+ goto error;
}
+
+ PyObject *obj = Py_BuildValue("iii", GDBM_VERSION_MAJOR,
+ GDBM_VERSION_MINOR, GDBM_VERSION_PATCH);
+ if (obj == NULL) {
+ goto error;
+ }
+ if (PyModule_AddObject(m, "_GDBM_VERSION", obj) < 0) {
+ Py_DECREF(obj);
+ goto error;
+ }
+
return m;
+
+error:
+ Py_DECREF(m);
+ return NULL;
}