diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-17 00:55:57 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-17 00:55:57 +0200 |
commit | d594f24fbc4c414abd7a9dc6d3f5a60f6b72a48f (patch) | |
tree | a19771ce5927e726a1c6b0ee29366dbf093bbc2a /Modules/_localemodule.c | |
parent | 74a7fa66639bf7960916e2862140dd2546d3c0c8 (diff) | |
download | cpython-git-d594f24fbc4c414abd7a9dc6d3f5a60f6b72a48f.tar.gz |
Issue #18408: Fix locale.localeconv(), handle PyDict_SetItemString() failure
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r-- | Modules/_localemodule.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index cc688ba140..b196749aec 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -147,26 +147,32 @@ PyLocale_localeconv(PyObject* self) /* hopefully, the localeconv result survives the C library calls involved herein */ +#define RESULT(key, obj)\ + do { \ + if (obj == NULL) \ + goto failed; \ + if (PyDict_SetItemString(result, key, obj) < 0) \ + goto failed; \ + Py_DECREF(obj); \ + } while (0) + #define RESULT_STRING(s)\ - x = PyUnicode_DecodeLocale(l->s, NULL); \ - if (!x) goto failed;\ - PyDict_SetItemString(result, #s, x);\ - Py_XDECREF(x) + do { \ + x = PyUnicode_DecodeLocale(l->s, NULL); \ + RESULT(#s, x); \ + } while (0) #define RESULT_INT(i)\ - x = PyLong_FromLong(l->i);\ - if (!x) goto failed;\ - PyDict_SetItemString(result, #i, x);\ - Py_XDECREF(x) + do { \ + x = PyLong_FromLong(l->i); \ + RESULT(#i, x); \ + } while (0) /* Numeric information */ RESULT_STRING(decimal_point); RESULT_STRING(thousands_sep); x = copy_grouping(l->grouping); - if (!x) - goto failed; - PyDict_SetItemString(result, "grouping", x); - Py_XDECREF(x); + RESULT("grouping", x); /* Monetary information */ RESULT_STRING(int_curr_symbol); @@ -174,10 +180,8 @@ PyLocale_localeconv(PyObject* self) RESULT_STRING(mon_decimal_point); RESULT_STRING(mon_thousands_sep); x = copy_grouping(l->mon_grouping); - if (!x) - goto failed; - PyDict_SetItemString(result, "mon_grouping", x); - Py_XDECREF(x); + RESULT("mon_grouping", x); + RESULT_STRING(positive_sign); RESULT_STRING(negative_sign); RESULT_INT(int_frac_digits); |