Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-1635741: Port _dbm module to multiphase initialization #20848

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

Merged
merged 9 commits into from
Jun 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bpo-1635741: Update
  • Loading branch information
corona10 committed Jun 15, 2020
commit ae11a49dee419d5f97e86d9437debd2b7fea9a7c
22 changes: 12 additions & 10 deletions 22 Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ typedef struct {

#include "clinic/_dbmmodule.c.h"

#define check_dbmobject_open(v, err) \
if ((v)->di_dbm == NULL) { \
PyErr_SetString(err, "DBM object has already been closed"); \
return NULL; \
}
#define check_dbmobject_open(v, err) \
if ((v)->di_dbm == NULL) { \
PyErr_SetString(err, "DBM object has already been closed"); \
return NULL; \
}

static PyObject *
newdbmobject(_dbm_state *state, const char *file, int flags, int mode)
Expand Down Expand Up @@ -411,7 +411,8 @@ static PyType_Spec dbmtype_spec = {
.name = "_dbm.dbm",
.basicsize = sizeof(dbmobject),
// Calling PyType_GetModuleState() on a subclass is not safe.
// dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag which prevents to create a subclass.
// dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
corona10 marked this conversation as resolved.
Show resolved Hide resolved
.flags = Py_TPFLAGS_DEFAULT,
corona10 marked this conversation as resolved.
Show resolved Hide resolved
.slots = dbmtype_spec_slots,
Expand Down Expand Up @@ -454,7 +455,7 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
iflags = O_RDWR;
}
else if (strcmp(flags, "rw") == 0) {
/* B/W compat */
/* Backward compatibility */
iflags = O_RDWR|O_CREAT;
}
else if (strcmp(flags, "c") == 0) {
Expand Down Expand Up @@ -499,12 +500,13 @@ _dbm_exec(PyObject *module)
return -1;
}
state->dbm_error = PyErr_NewException("_dbm.error", PyExc_OSError, NULL);
corona10 marked this conversation as resolved.
Show resolved Hide resolved
if (state->dbm_error == NULL) {
return -1;
}
if (PyModule_AddStringConstant(module, "library", which_dbm) < 0) {
return -1;
}
Py_INCREF(state->dbm_error);
if (PyModule_AddObject(module, "error", state->dbm_error) < 0) {
Py_DECREF(state->dbm_error);
if (PyModule_AddType(module, (PyTypeObject *)state->dbm_error) < 0) {
return -1;
}
return 0;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.