Visitar URL original
bpo-1635741: Port errno module to multiphase initialization by corona10 · Pull Request #19923 · python/cpython · GitHub
Skip to content
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
Next Next commit
bpo-1635741: Update
  • Loading branch information
corona10 committed May 6, 2020
commit 2b241ca23f81b7e5f9e452ffcdc6b7d9a25974cc
45 changes: 19 additions & 26 deletions Modules/errnomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,33 @@ static PyMethodDef errno_methods[] = {
/* Helper function doing the dictionary inserting */

static int
_add_errcode(PyObject *d, PyObject *de, const char *name, int code)
_add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str, int code_int)
{
PyObject *u = PyUnicode_FromString(name);
if (!u) {
PyObject *name = PyUnicode_FromString(name_str);
if (!name) {
return -1;
}

PyObject *v = PyLong_FromLong((long) code);
if (!v) {
Py_DECREF(u);
PyObject *code = PyLong_FromLong(code_int);
if (!code) {
Py_DECREF(name);
return -1;
}

/* Don't bother checking for errors; they'll be caught at the end
* of the module initialization function by the caller of
* initerrno().
*/
if (u && v) {
/* insert in modules dict */
if (PyDict_SetItem(d, u, v) < 0) {
Py_DECREF(u);
Py_DECREF(v);
return -1;
}
/* insert in errorcode dict */
if (PyDict_SetItem(de, v, u) < 0) {
Py_DECREF(u);
Py_DECREF(v);
return -1;
}
int ret = -1;
/* insert in modules dict */
if (PyDict_SetItem(module_dict, name, code) < 0) {
goto end;
}
Py_DECREF(u);
Py_DECREF(v);
return 0;
/* insert in errorcode dict */
if (PyDict_SetItem(error_dict, code, name) < 0) {
goto end;
}
ret = 0;
end:
Py_DECREF(name);
Py_DECREF(code);
return ret;
}

static int
Expand Down