diff options
Diffstat (limited to 'Python/bltinmodule.c')
| -rw-r--r-- | Python/bltinmodule.c | 105 | 
1 files changed, 51 insertions, 54 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ef5a34c..763c2a2 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -52,51 +52,45 @@ _Py_IDENTIFIER(stderr);  /* AC: cannot convert yet, waiting for *args support */  static PyObject * -builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) +builtin___build_class__(PyObject *self, PyObject **args, Py_ssize_t nargs, +                        PyObject *kwnames)  {      PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns;      PyObject *cls = NULL, *cell = NULL; -    Py_ssize_t nargs;      int isclass = 0;   /* initialize to prevent gcc warning */ -    assert(args != NULL); -    if (!PyTuple_Check(args)) { -        PyErr_SetString(PyExc_TypeError, -                        "__build_class__: args is not a tuple"); -        return NULL; -    } -    nargs = PyTuple_GET_SIZE(args);      if (nargs < 2) {          PyErr_SetString(PyExc_TypeError,                          "__build_class__: not enough arguments");          return NULL;      } -    func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ +    func = args[0];   /* Better be callable */      if (!PyFunction_Check(func)) {          PyErr_SetString(PyExc_TypeError,                          "__build_class__: func must be a function");          return NULL;      } -    name = PyTuple_GET_ITEM(args, 1); +    name = args[1];      if (!PyUnicode_Check(name)) {          PyErr_SetString(PyExc_TypeError,                          "__build_class__: name is not a string");          return NULL;      } -    bases = PyTuple_GetSlice(args, 2, nargs); +    bases = _PyStack_AsTupleSlice(args, nargs, 2, nargs);      if (bases == NULL)          return NULL; -    if (kwds == NULL) { +    if (kwnames == NULL) {          meta = NULL;          mkw = NULL;      }      else { -        mkw = PyDict_Copy(kwds); /* Don't modify kwds passed in! */ +        mkw = _PyStack_AsDict(args + nargs, kwnames);          if (mkw == NULL) {              Py_DECREF(bases);              return NULL;          } +          meta = _PyDict_GetItemId(mkw, &PyId_metaclass);          if (meta != NULL) {              Py_INCREF(meta); @@ -999,14 +993,19 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,  /* AC: cannot convert yet, as needs PEP 457 group support in inspect */  static PyObject * -builtin_getattr(PyObject *self, PyObject *args) +builtin_getattr(PyObject *self, PyObject **args, Py_ssize_t nargs, +                PyObject *kwnames)  {      PyObject *v, *result, *dflt = NULL;      PyObject *name; -    if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt)) +    if (!_PyArg_UnpackStack(args, nargs, "getattr", 2, 3, &v, &name, &dflt))          return NULL; +    if (!_PyArg_NoStackKeywords("getattr", kwnames)) { +        return NULL; +    } +      if (!PyUnicode_Check(name)) {          PyErr_SetString(PyExc_TypeError,                          "getattr(): attribute name must be string"); @@ -1186,7 +1185,7 @@ map_traverse(mapobject *lz, visitproc visit, void *arg)  static PyObject *  map_next(mapobject *lz)  { -    PyObject *small_stack[5]; +    PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];      PyObject **stack;      Py_ssize_t niters, nargs, i;      PyObject *result = NULL; @@ -1304,13 +1303,19 @@ PyTypeObject PyMap_Type = {  /* AC: cannot convert yet, as needs PEP 457 group support in inspect */  static PyObject * -builtin_next(PyObject *self, PyObject *args) +builtin_next(PyObject *self, PyObject **args, Py_ssize_t nargs, +             PyObject *kwnames)  {      PyObject *it, *res;      PyObject *def = NULL; -    if (!PyArg_UnpackTuple(args, "next", 1, 2, &it, &def)) +    if (!_PyArg_UnpackStack(args, nargs, "next", 1, 2, &it, &def)) +        return NULL; + +    if (!_PyArg_NoStackKeywords("next", kwnames)) {          return NULL; +    } +      if (!PyIter_Check(it)) {          PyErr_Format(PyExc_TypeError,              "'%.200s' object is not an iterator", @@ -1364,8 +1369,7 @@ builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,  {      if (PyObject_SetAttr(obj, name, value) != 0)          return NULL; -    Py_INCREF(Py_None); -    return Py_None; +    Py_RETURN_NONE;  } @@ -1387,8 +1391,7 @@ builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name)  {      if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0)          return NULL; -    Py_INCREF(Py_None); -    return Py_None; +    Py_RETURN_NONE;  } @@ -1742,18 +1745,19 @@ builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z)  /* AC: cannot convert yet, waiting for *args support */  static PyObject * -builtin_print(PyObject *self, PyObject *args, PyObject *kwds) +builtin_print(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)  { -    static char *kwlist[] = {"sep", "end", "file", "flush", 0}; -    static PyObject *dummy_args; +    static const char * const _keywords[] = {"sep", "end", "file", "flush", 0}; +    static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0};      PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;      int i, err; -    if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) -        return NULL; -    if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print", -                                     kwlist, &sep, &end, &file, &flush)) +    if (kwnames != NULL && +            !_PyArg_ParseStackAndKeywords(args + nargs, 0, kwnames, &_parser, +                                          &sep, &end, &file, &flush)) {          return NULL; +    } +      if (file == NULL || file == Py_None) {          file = _PySys_GetObjectId(&PyId_stdout);          if (file == NULL) { @@ -1785,7 +1789,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)          return NULL;      } -    for (i = 0; i < PyTuple_Size(args); i++) { +    for (i = 0; i < nargs; i++) {          if (i > 0) {              if (sep == NULL)                  err = PyFile_WriteString(" ", file); @@ -1795,8 +1799,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)              if (err)                  return NULL;          } -        err = PyFile_WriteObject(PyTuple_GetItem(args, i), file, -                                 Py_PRINT_RAW); +        err = PyFile_WriteObject(args[i], file, Py_PRINT_RAW);          if (err)              return NULL;      } @@ -1923,7 +1926,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)          char *s = NULL;          PyObject *stdin_encoding = NULL, *stdin_errors = NULL;          PyObject *stdout_encoding = NULL, *stdout_errors = NULL; -        char *stdin_encoding_str, *stdin_errors_str; +        const char *stdin_encoding_str, *stdin_errors_str;          PyObject *result;          size_t len; @@ -1944,7 +1947,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)              Py_DECREF(tmp);          if (prompt != NULL) {              /* We have a prompt, encode it as stdout would */ -            char *stdout_encoding_str, *stdout_errors_str; +            const char *stdout_encoding_str, *stdout_errors_str;              PyObject *stringpo;              stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);              stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors); @@ -2074,7 +2077,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)      }      if (ndigits == NULL || ndigits == Py_None) -        result = PyObject_CallFunctionObjArgs(round, NULL); +        result = _PyObject_CallNoArg(round);      else          result = PyObject_CallFunctionObjArgs(round, ndigits, NULL);      Py_DECREF(round); @@ -2116,20 +2119,16 @@ 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 *callable; -    static char *kwlist[] = {"", "key", "reverse", 0}; -    int reverse; -    Py_ssize_t nargs; +    PyObject *newlist, *v, *seq, *callable; -    /* args 1-3 should match listsort in Objects/listobject.c */ -    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted", -        kwlist, &seq, &keyfunc, &reverse)) +    /* Keyword arguments are passed through list.sort() which will check +       them. */ +    if (!_PyArg_UnpackStack(args, nargs, "sorted", 1, 1, &seq))          return NULL;      newlist = PySequence_List(seq); @@ -2142,10 +2141,8 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)          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); @@ -2613,7 +2610,7 @@ PyTypeObject PyZip_Type = {  static PyMethodDef builtin_methods[] = {      {"__build_class__", (PyCFunction)builtin___build_class__, -     METH_VARARGS | METH_KEYWORDS, build_class_doc}, +     METH_FASTCALL, build_class_doc},      {"__import__",      (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc},      BUILTIN_ABS_METHODDEF      BUILTIN_ALL_METHODDEF @@ -2629,7 +2626,7 @@ static PyMethodDef builtin_methods[] = {      BUILTIN_EVAL_METHODDEF      BUILTIN_EXEC_METHODDEF      BUILTIN_FORMAT_METHODDEF -    {"getattr",         builtin_getattr,    METH_VARARGS, getattr_doc}, +    {"getattr",         (PyCFunction)builtin_getattr, METH_FASTCALL, getattr_doc},      BUILTIN_GLOBALS_METHODDEF      BUILTIN_HASATTR_METHODDEF      BUILTIN_HASH_METHODDEF @@ -2643,11 +2640,11 @@ static PyMethodDef builtin_methods[] = {      BUILTIN_LOCALS_METHODDEF      {"max",             (PyCFunction)builtin_max,        METH_VARARGS | METH_KEYWORDS, max_doc},      {"min",             (PyCFunction)builtin_min,        METH_VARARGS | METH_KEYWORDS, min_doc}, -    {"next",            (PyCFunction)builtin_next,       METH_VARARGS, next_doc}, +    {"next",            (PyCFunction)builtin_next,       METH_FASTCALL, next_doc},      BUILTIN_OCT_METHODDEF      BUILTIN_ORD_METHODDEF      BUILTIN_POW_METHODDEF -    {"print",           (PyCFunction)builtin_print,      METH_VARARGS | METH_KEYWORDS, print_doc}, +    {"print",           (PyCFunction)builtin_print,      METH_FASTCALL, print_doc},      BUILTIN_REPR_METHODDEF      {"round",           (PyCFunction)builtin_round,      METH_VARARGS | METH_KEYWORDS, round_doc},      BUILTIN_SETATTR_METHODDEF  | 
