-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
bpo-33901: Add _gdbm._GDBM_VERSION #7794
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, but it seems like most modules do the same: socktemodule.c: signalmodule.c: Note: PyModule_AddObject() is weird, it decrements the reference counter on success...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's documented to steal a reference, though from the implementation, only on success. Module init functions seem usually not written carefully about this kind error. @serhiy-storchaka
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you want to fix that, I would suggest to fix it in a different PR. Maybe even open a new bug to track that.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an open issue for this. It is not easy. You correctly use |
||
| 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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
from _gdbm import _GDBM_VERSION?