[Python-checkins] cpython (3.5): Issue #27301: Fixed incorrect return codes for errors in compile.c.

serhiy.storchaka python-checkins at python.org
Wed Jun 15 13:11:46 EDT 2016


https://hg.python.org/cpython/rev/51fe72949245
changeset:   102055:51fe72949245
branch:      3.5
parent:      102053:e9fb7970f8b0
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Jun 15 20:06:07 2016 +0300
summary:
  Issue #27301: Fixed incorrect return codes for errors in compile.c.

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


diff --git a/Python/compile.c b/Python/compile.c
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1494,6 +1494,9 @@
 compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
                               asdl_seq *kw_defaults)
 {
+    /* Return the number of defaults + 1.
+       Returns 0 on error.
+     */
     int i, default_count = 0;
     for (i = 0; i < asdl_seq_LEN(kwonlyargs); i++) {
         arg_ty arg = asdl_seq_GET(kwonlyargs, i);
@@ -1501,16 +1504,16 @@
         if (default_) {
             PyObject *mangled = _Py_Mangle(c->u->u_private, arg->arg);
             if (!mangled)
-                return -1;
+                return 0;
             ADDOP_O(c, LOAD_CONST, mangled, consts);
             Py_DECREF(mangled);
             if (!compiler_visit_expr(c, default_)) {
-                return -1;
+                return 0;
             }
             default_count++;
         }
     }
-    return default_count;
+    return default_count + 1;
 }
 
 static int
@@ -1554,17 +1557,17 @@
                            expr_ty returns)
 {
     /* Push arg annotations and a list of the argument names. Return the #
-       of items pushed. The expressions are evaluated out-of-order wrt the
+       of items pushed + 1. The expressions are evaluated out-of-order wrt the
        source code.
 
-       More than 2^16-1 annotations is a SyntaxError. Returns -1 on error.
+       More than 2^16-1 annotations is a SyntaxError. Returns 0 on error.
        */
     static identifier return_str;
     PyObject *names;
     Py_ssize_t len;
     names = PyList_New(0);
     if (!names)
-        return -1;
+        return 0;
 
     if (!compiler_visit_argannotations(c, args->args, names))
         goto error;
@@ -1614,11 +1617,11 @@
     Py_DECREF(names);
 
     /* We just checked that len <= 65535, see above */
-    return Py_SAFE_DOWNCAST(len, Py_ssize_t, int);
+    return Py_SAFE_DOWNCAST(len + 1, Py_ssize_t, int);
 
 error:
     Py_DECREF(names);
-    return -1;
+    return 0;
 }
 
 static int
@@ -1667,13 +1670,14 @@
     if (args->kwonlyargs) {
         int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,
                                                 args->kw_defaults);
-        if (res < 0)
+        if (res == 0)
             return 0;
-        kw_default_count = res;
+        kw_default_count = res - 1;
     }
     num_annotations = compiler_visit_annotations(c, args, returns);
-    if (num_annotations < 0)
+    if (num_annotations == 0)
         return 0;
+    num_annotations--;
     assert((num_annotations & 0xFFFF) == num_annotations);
 
     if (!compiler_enter_scope(c, name,
@@ -1889,8 +1893,8 @@
     if (args->kwonlyargs) {
         int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,
                                                 args->kw_defaults);
-        if (res < 0) return 0;
-        kw_default_count = res;
+        if (res == 0) return 0;
+        kw_default_count = res - 1;
     }
     if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA,
                               (void *)e, e->lineno))
@@ -2403,7 +2407,7 @@
     Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,
                                         PyUnicode_GET_LENGTH(name), 1);
     if (dot == -2)
-        return -1;
+        return 0;
     if (dot != -1) {
         /* Consume the base module name to get the first attribute */
         Py_ssize_t pos = dot + 1;
@@ -2412,12 +2416,12 @@
             dot = PyUnicode_FindChar(name, '.', pos,
                                      PyUnicode_GET_LENGTH(name), 1);
             if (dot == -2)
-                return -1;
+                return 0;
             attr = PyUnicode_Substring(name, pos,
                                        (dot != -1) ? dot :
                                        PyUnicode_GET_LENGTH(name));
             if (!attr)
-                return -1;
+                return 0;
             ADDOP_O(c, LOAD_ATTR, attr, names);
             Py_DECREF(attr);
             pos = dot + 1;

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


More information about the Python-checkins mailing list