Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(48032)

Side by Side Diff: Python/bltinmodule.c

Issue 29296: convert print() to METH_FASTCALL
Patch Set: Created 2 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Built-in functions */ 1 /* Built-in functions */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 #include "node.h" 6 #include "node.h"
7 #include "code.h" 7 #include "code.h"
8 8
9 #include "asdl.h" 9 #include "asdl.h"
10 #include "ast.h" 10 #include "ast.h"
(...skipping 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 static PyObject * 1729 static PyObject *
1730 builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z) 1730 builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z)
1731 /*[clinic end generated code: output=50a14d5d130d404b input=653d57d38d41fc07]*/ 1731 /*[clinic end generated code: output=50a14d5d130d404b input=653d57d38d41fc07]*/
1732 { 1732 {
1733 return PyNumber_Power(x, y, z); 1733 return PyNumber_Power(x, y, z);
1734 } 1734 }
1735 1735
1736 1736
1737 /* AC: cannot convert yet, waiting for *args support */ 1737 /* AC: cannot convert yet, waiting for *args support */
1738 static PyObject * 1738 static PyObject *
1739 builtin_print(PyObject *self, PyObject *args, PyObject *kwds) 1739 builtin_print(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnam es)
1740 { 1740 {
1741 static char *kwlist[] = {"sep", "end", "file", "flush", 0}; 1741 static const char * const _keywords[] = {"sep", "end", "file", "flush", 0};
1742 static PyObject *dummy_args; 1742 static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0};
1743 PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; 1743 PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
1744 int i, err; 1744 int i, err;
1745 1745
1746 if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) 1746 if (kwnames != NULL &&
1747 !_PyArg_ParseStackAndKeywords(args + nargs, 0, kwnames, &_parser,
haypo 2017/01/17 17:55:44 You can pass NULL as the first parameter. Nice tr
1748 &sep, &end, &file, &flush)) {
1747 return NULL; 1749 return NULL;
1748 if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print", 1750 }
1749 kwlist, &sep, &end, &file, &flush)) 1751
1750 return NULL;
1751 if (file == NULL || file == Py_None) { 1752 if (file == NULL || file == Py_None) {
1752 file = _PySys_GetObjectId(&PyId_stdout); 1753 file = _PySys_GetObjectId(&PyId_stdout);
1753 if (file == NULL) { 1754 if (file == NULL) {
1754 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); 1755 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
1755 return NULL; 1756 return NULL;
1756 } 1757 }
1757 1758
1758 /* sys.stdout may be None when FILE* stdout isn't connected */ 1759 /* sys.stdout may be None when FILE* stdout isn't connected */
1759 if (file == Py_None) 1760 if (file == Py_None)
1760 Py_RETURN_NONE; 1761 Py_RETURN_NONE;
(...skipping 11 matching lines...) Expand all
1772 if (end == Py_None) { 1773 if (end == Py_None) {
1773 end = NULL; 1774 end = NULL;
1774 } 1775 }
1775 else if (end && !PyUnicode_Check(end)) { 1776 else if (end && !PyUnicode_Check(end)) {
1776 PyErr_Format(PyExc_TypeError, 1777 PyErr_Format(PyExc_TypeError,
1777 "end must be None or a string, not %.200s", 1778 "end must be None or a string, not %.200s",
1778 end->ob_type->tp_name); 1779 end->ob_type->tp_name);
1779 return NULL; 1780 return NULL;
1780 } 1781 }
1781 1782
1782 for (i = 0; i < PyTuple_Size(args); i++) { 1783 for (i = 0; i < nargs; i++) {
1783 if (i > 0) { 1784 if (i > 0) {
1784 if (sep == NULL) 1785 if (sep == NULL)
1785 err = PyFile_WriteString(" ", file); 1786 err = PyFile_WriteString(" ", file);
1786 else 1787 else
1787 err = PyFile_WriteObject(sep, file, 1788 err = PyFile_WriteObject(sep, file,
1788 Py_PRINT_RAW); 1789 Py_PRINT_RAW);
1789 if (err) 1790 if (err)
1790 return NULL; 1791 return NULL;
1791 } 1792 }
1792 err = PyFile_WriteObject(PyTuple_GetItem(args, i), file, 1793 err = PyFile_WriteObject(args[i], file, Py_PRINT_RAW);
1793 Py_PRINT_RAW);
1794 if (err) 1794 if (err)
1795 return NULL; 1795 return NULL;
1796 } 1796 }
1797 1797
1798 if (end == NULL) 1798 if (end == NULL)
1799 err = PyFile_WriteString("\n", file); 1799 err = PyFile_WriteString("\n", file);
1800 else 1800 else
1801 err = PyFile_WriteObject(end, file, Py_PRINT_RAW); 1801 err = PyFile_WriteObject(end, file, Py_PRINT_RAW);
1802 if (err) 1802 if (err)
1803 return NULL; 1803 return NULL;
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 BUILTIN_ISSUBCLASS_METHODDEF 2633 BUILTIN_ISSUBCLASS_METHODDEF
2634 {"iter", builtin_iter, METH_VARARGS, iter_doc}, 2634 {"iter", builtin_iter, METH_VARARGS, iter_doc},
2635 BUILTIN_LEN_METHODDEF 2635 BUILTIN_LEN_METHODDEF
2636 BUILTIN_LOCALS_METHODDEF 2636 BUILTIN_LOCALS_METHODDEF
2637 {"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEY WORDS, max_doc}, 2637 {"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEY WORDS, max_doc},
2638 {"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEY WORDS, min_doc}, 2638 {"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEY WORDS, min_doc},
2639 {"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc} , 2639 {"next", (PyCFunction)builtin_next, METH_VARARGS, next_doc} ,
2640 BUILTIN_OCT_METHODDEF 2640 BUILTIN_OCT_METHODDEF
2641 BUILTIN_ORD_METHODDEF 2641 BUILTIN_ORD_METHODDEF
2642 BUILTIN_POW_METHODDEF 2642 BUILTIN_POW_METHODDEF
2643 {"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEY WORDS, print_doc}, 2643 {"print", (PyCFunction)builtin_print, METH_FASTCALL, print_do c},
2644 BUILTIN_REPR_METHODDEF 2644 BUILTIN_REPR_METHODDEF
2645 {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEY WORDS, round_doc}, 2645 {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEY WORDS, round_doc},
2646 BUILTIN_SETATTR_METHODDEF 2646 BUILTIN_SETATTR_METHODDEF
2647 BUILTIN_SORTED_METHODDEF 2647 BUILTIN_SORTED_METHODDEF
2648 BUILTIN_SUM_METHODDEF 2648 BUILTIN_SUM_METHODDEF
2649 {"vars", builtin_vars, METH_VARARGS, vars_doc}, 2649 {"vars", builtin_vars, METH_VARARGS, vars_doc},
2650 {NULL, NULL}, 2650 {NULL, NULL},
2651 }; 2651 };
2652 2652
2653 PyDoc_STRVAR(builtin_doc, 2653 PyDoc_STRVAR(builtin_doc,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2735 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2736 Py_DECREF(debug); 2736 Py_DECREF(debug);
2737 return NULL; 2737 return NULL;
2738 } 2738 }
2739 Py_DECREF(debug); 2739 Py_DECREF(debug);
2740 2740
2741 return mod; 2741 return mod;
2742 #undef ADD_TO_ALL 2742 #undef ADD_TO_ALL
2743 #undef SETBUILTIN 2743 #undef SETBUILTIN
2744 } 2744 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+