[Python-checkins] cpython: Issue #18408: Fix locale.localeconv(), handle PyDict_SetItemString() failure

victor.stinner python-checkins at python.org
Wed Jul 17 01:01:27 CEST 2013


http://hg.python.org/cpython/rev/7fe4a0c0e905
changeset:   84681:7fe4a0c0e905
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Jul 17 00:55:57 2013 +0200
summary:
  Issue #18408: Fix locale.localeconv(), handle PyDict_SetItemString() failure

files:
  Modules/_localemodule.c |  36 ++++++++++++++++------------
  1 files changed, 20 insertions(+), 16 deletions(-)


diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -147,26 +147,32 @@
     /* 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 @@
     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);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list