]> granicus.if.org Git - python/commitdiff
Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted().
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 20 Jan 2017 06:35:18 +0000 (08:35 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 20 Jan 2017 06:35:18 +0000 (08:35 +0200)
1  2 
Misc/NEWS
Python/bltinmodule.c

diff --cc Misc/NEWS
Simple merge
index ab029ce0aa056378b0af4c2edd36d07e2f87f93c,8acdfc3222b2ccdc7ff3798694b766bdc77e1b67..6df8af47333cf6ff904aa525fba37341739ac0b9
@@@ -2121,20 -2116,20 +2121,20 @@@ PyDoc_STRVAR(builtin_sorted__doc__
  "reverse flag can be set to request the result in descending order.");
  
  #define BUILTIN_SORTED_METHODDEF    \
 -    {"sorted", (PyCFunction)builtin_sorted, METH_VARARGS|METH_KEYWORDS, builtin_sorted__doc__},
 +    {"sorted", (PyCFunction)builtin_sorted, METH_FASTCALL, builtin_sorted__doc__},
  
  static PyObject *
 -builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
 +builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
  {
 -    PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
 +    PyObject *newlist, *v, *seq, *keyfunc=NULL;
      PyObject *callable;
-     static const char * const kwlist[] = {"iterable", "key", "reverse", 0};
 -    static char *kwlist[] = {"", "key", "reverse", 0};
++    static const char * const kwlist[] = {"", "key", "reverse", 0};
 +    /* args 1-3 should match listsort in Objects/listobject.c */
 +    static _PyArg_Parser parser = {"O|Oi:sorted", kwlist, 0};
      int reverse;
 -    Py_ssize_t nargs;
  
 -    /* args 1-3 should match listsort in Objects/listobject.c */
 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
 -        kwlist, &seq, &keyfunc, &reverse))
 +    if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &parser,
 +                                      &seq, &keyfunc, &reverse))
          return NULL;
  
      newlist = PySequence_List(seq);
          return NULL;
      }
  
 -    assert(PyTuple_GET_SIZE(args) >= 1);
 -    newargs = &PyTuple_GET_ITEM(args, 1);
 -    nargs = PyTuple_GET_SIZE(args) - 1;
 -    v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);
++    assert(nargs >= 1);
 +    v = _PyObject_FastCallKeywords(callable, args + 1, nargs - 1, kwnames);
      Py_DECREF(callable);
      if (v == NULL) {
          Py_DECREF(newlist);