diff options
author | shadchin <shadchin@yandex-team.com> | 2024-04-28 21:17:44 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2024-04-28 21:25:54 +0300 |
commit | a55d99a3eb72f90355bc146baeda18aa7eb97352 (patch) | |
tree | b17cfed786effe8b81bba022239d6729f716fbeb /contrib/tools/python3/Modules/pwdmodule.c | |
parent | 67bf49d08acf1277eff4c336021ac22d964bb4c4 (diff) | |
download | ydb-a55d99a3eb72f90355bc146baeda18aa7eb97352.tar.gz |
Update Python 3 to 3.12.3
7d09de7d8b99ea2be554ef0fc61276942ca9c2e1
Diffstat (limited to 'contrib/tools/python3/Modules/pwdmodule.c')
-rw-r--r-- | contrib/tools/python3/Modules/pwdmodule.c | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/contrib/tools/python3/Modules/pwdmodule.c b/contrib/tools/python3/Modules/pwdmodule.c index cc2e2a4389..920259a62c 100644 --- a/contrib/tools/python3/Modules/pwdmodule.c +++ b/contrib/tools/python3/Modules/pwdmodule.c @@ -63,53 +63,52 @@ static struct PyModuleDef pwdmodule; #define DEFAULT_BUFFER_SIZE 1024 -static void -sets(PyObject *v, int i, const char* val) -{ - if (val) { - PyObject *o = PyUnicode_DecodeFSDefault(val); - PyStructSequence_SET_ITEM(v, i, o); - } - else { - PyStructSequence_SET_ITEM(v, i, Py_None); - Py_INCREF(Py_None); - } -} - static PyObject * mkpwent(PyObject *module, struct passwd *p) { - int setIndex = 0; PyObject *v = PyStructSequence_New(get_pwd_state(module)->StructPwdType); - if (v == NULL) + if (v == NULL) { return NULL; + } + + int setIndex = 0; + +#define SET_STRING(VAL) \ + SET_RESULT((VAL) ? PyUnicode_DecodeFSDefault((VAL)) : Py_NewRef(Py_None)) -#define SETS(i,val) sets(v, i, val) +#define SET_RESULT(CALL) \ + do { \ + PyObject *item = (CALL); \ + if (item == NULL) { \ + goto error; \ + } \ + PyStructSequence_SET_ITEM(v, setIndex++, item); \ + } while(0) - SETS(setIndex++, p->pw_name); + SET_STRING(p->pw_name); #if defined(HAVE_STRUCT_PASSWD_PW_PASSWD) && !defined(__ANDROID__) - SETS(setIndex++, p->pw_passwd); + SET_STRING(p->pw_passwd); #else - SETS(setIndex++, ""); + SET_STRING(""); #endif - PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid)); - PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid)); + SET_RESULT(_PyLong_FromUid(p->pw_uid)); + SET_RESULT(_PyLong_FromGid(p->pw_gid)); #if defined(HAVE_STRUCT_PASSWD_PW_GECOS) - SETS(setIndex++, p->pw_gecos); + SET_STRING(p->pw_gecos); #else - SETS(setIndex++, ""); + SET_STRING(""); #endif - SETS(setIndex++, p->pw_dir); - SETS(setIndex++, p->pw_shell); - -#undef SETS + SET_STRING(p->pw_dir); + SET_STRING(p->pw_shell); - if (PyErr_Occurred()) { - Py_XDECREF(v); - return NULL; - } +#undef SET_STRING +#undef SET_RESULT return v; + +error: + Py_DECREF(v); + return NULL; } /*[clinic input] |