From 29275c9331873900af43c6c817234fcdd358a659 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 17 Sep 2002 09:34:06 +0000 Subject: [PATCH] Deal with NULL fields in mkpwent. --- Modules/pwdmodule.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index cb139bb036..9134edc1b1 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -44,6 +44,17 @@ exception is raised if the entry asked for cannot be found."); static PyTypeObject StructPwdType; +static void +sets(PyObject *v, int i, char* val) +{ + if (val) + PyStructSequence_SET_ITEM(v, i, PyString_FromString(val)); + else { + PyStructSequence_SET_ITEM(v, i, Py_None); + Py_INCREF(Py_None); + } +} + static PyObject * mkpwent(struct passwd *p) { @@ -53,7 +64,7 @@ mkpwent(struct passwd *p) return NULL; #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val)) -#define SETS(i,val) PyStructSequence_SET_ITEM(v, i, PyString_FromString(val)) +#define SETS(i,val) sets(v, i, val) SETS(setIndex++, p->pw_name); SETS(setIndex++, p->pw_passwd); -- 2.50.0