Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 851e7d5

Browse files
committed
Got rid of the errorstr dictionary, which is redundant now that
there's os.strerror() -- also, it would form a locale liability.
1 parent 4a1f39a commit 851e7d5

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

Modules/errnomodule.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,57 +54,45 @@ static PyMethodDef errno_methods[] = {
5454
/* Helper function doing the dictionary inserting */
5555

5656
static void
57-
inscode(d, e, c, name, code, comment)
58-
PyObject * d;
59-
PyObject * e;
60-
PyObject * c;
57+
_inscode(d, de, name, code)
58+
PyObject *d;
59+
PyObject *de;
6160
char *name;
6261
int code;
63-
char * comment;
6462
{
6563
PyObject *u;
6664
PyObject *v;
67-
PyObject *w;
68-
69-
#ifdef HAVE_STRERROR
70-
if (strerror(code) != NULL)
71-
comment = strerror(code);
72-
#endif
7365

7466
u = PyString_FromString(name);
7567
v = PyInt_FromLong((long) code);
76-
w = PyString_FromString(comment);
7768

78-
if (!u || !v || !w) {
69+
if (!u || !v) {
7970
/* Don't bother reporting this error */
8071
PyErr_Clear();
8172
}
8273
else {
8374
/* insert in modules dict */
8475
PyDict_SetItem(d, u, v);
85-
/* insert in errorstr dict */
86-
PyDict_SetItem(e, v, w);
8776
/* insert in errorcode dict */
88-
PyDict_SetItem(c, v, u);
77+
PyDict_SetItem(de, v, u);
8978
}
9079
Py_XDECREF(u);
9180
Py_XDECREF(v);
92-
Py_XDECREF(w);
9381
}
9482

9583
void
9684
initerrno()
9785
{
98-
PyObject *m, *d, *ds, *de;
86+
PyObject *m, *d, *de;
9987
m = Py_InitModule("errno", errno_methods);
10088
d = PyModule_GetDict(m);
101-
ds = PyDict_New();
102-
if (ds == NULL || PyDict_SetItemString(d,"errorstr",ds))
103-
Py_FatalError("can't initialize errno module");
10489
de = PyDict_New();
10590
if (de == NULL || PyDict_SetItemString(d,"errorcode",de))
10691
Py_FatalError("can't initialize errno module");
10792

93+
/* Macro so I don't have to edit each and every line below... */
94+
#define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code)
95+
10896
/*
10997
* The names and comments are borrowed from linux/include/errno.h,
11098
* which should be pretty all-inclusive

0 commit comments

Comments
 (0)