diff options
| author | Larry Hastings <larry@hastings.org> | 2016-06-27 02:53:18 (GMT) | 
|---|---|---|
| committer | Larry Hastings <larry@hastings.org> | 2016-06-27 02:53:18 (GMT) | 
| commit | 1b329e791ae3a3a2989f05e8c2019b67b4e1a7df (patch) | |
| tree | 91e137c00f35f21a2c17b385f9746492b8347558 /Python/compile.c | |
| parent | 9bb200545970bb920c83124658cb89c7d295166d (diff) | |
| parent | 1e957d145fa1fc05ca1fbb9f135ab162c939ae14 (diff) | |
| download | cpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.zip cpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.tar.gz cpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.tar.bz2 | |
Merge.
Diffstat (limited to 'Python/compile.c')
| -rw-r--r-- | Python/compile.c | 38 | 
1 files changed, 21 insertions, 17 deletions
| diff --git a/Python/compile.c b/Python/compile.c index 1e720ea..ce510aa 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1494,6 +1494,9 @@ static int  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 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,          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 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,                             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 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,      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 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)      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 @@ compiler_lambda(struct compiler *c, expr_ty e)      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 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)      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 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)              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; @@ -3262,7 +3266,7 @@ compiler_call_helper(struct compiler *c,          code |= 2;          if (nsubkwargs > 1) {              /* Pack it all up */ -            int function_pos = n + (code & 1) + nkw + 1; +            int function_pos = n + (code & 1) + 2 * nkw + 1;              ADDOP_I(c, BUILD_MAP_UNPACK_WITH_CALL, nsubkwargs | (function_pos << 8));          }      } | 
