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

Delta Between Two Patch Sets: Python/bltinmodule.c

Issue 19362: Documentation for len() fails to mention that it works on sets
Left Patch Set: Created 6 years, 4 months ago
Right Patch Set: Created 6 years 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/functions.rst ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 14 matching lines...) Expand all
25 const char *Py_FileSystemDefaultEncoding = "mbcs"; 25 const char *Py_FileSystemDefaultEncoding = "mbcs";
26 int Py_HasFileSystemDefaultEncoding = 1; 26 int Py_HasFileSystemDefaultEncoding = 1;
27 #elif defined(__APPLE__) 27 #elif defined(__APPLE__)
28 const char *Py_FileSystemDefaultEncoding = "utf-8"; 28 const char *Py_FileSystemDefaultEncoding = "utf-8";
29 int Py_HasFileSystemDefaultEncoding = 1; 29 int Py_HasFileSystemDefaultEncoding = 1;
30 #else 30 #else
31 const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */ 31 const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */
32 int Py_HasFileSystemDefaultEncoding = 0; 32 int Py_HasFileSystemDefaultEncoding = 0;
33 #endif 33 #endif
34 34
35 _Py_IDENTIFIER(__builtins__);
36 _Py_IDENTIFIER(__dict__);
37 _Py_IDENTIFIER(__prepare__);
38 _Py_IDENTIFIER(__round__);
39 _Py_IDENTIFIER(encoding);
40 _Py_IDENTIFIER(errors);
35 _Py_IDENTIFIER(fileno); 41 _Py_IDENTIFIER(fileno);
36 _Py_IDENTIFIER(flush); 42 _Py_IDENTIFIER(flush);
43 _Py_IDENTIFIER(metaclass);
44 _Py_IDENTIFIER(sort);
45 _Py_IDENTIFIER(stdin);
46 _Py_IDENTIFIER(stdout);
47 _Py_IDENTIFIER(stderr);
37 48
38 static PyObject * 49 static PyObject *
39 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) 50 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
40 { 51 {
41 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell; 52 PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell;
42 PyObject *cls = NULL; 53 PyObject *cls = NULL;
43 Py_ssize_t nargs; 54 Py_ssize_t nargs;
44 int isclass; 55 int isclass;
45 _Py_IDENTIFIER(__prepare__);
46 56
47 assert(args != NULL); 57 assert(args != NULL);
48 if (!PyTuple_Check(args)) { 58 if (!PyTuple_Check(args)) {
49 PyErr_SetString(PyExc_TypeError, 59 PyErr_SetString(PyExc_TypeError,
50 "__build_class__: args is not a tuple"); 60 "__build_class__: args is not a tuple");
51 return NULL; 61 return NULL;
52 } 62 }
53 nargs = PyTuple_GET_SIZE(args); 63 nargs = PyTuple_GET_SIZE(args);
54 if (nargs < 2) { 64 if (nargs < 2) {
55 PyErr_SetString(PyExc_TypeError, 65 PyErr_SetString(PyExc_TypeError,
(...skipping 19 matching lines...) Expand all
75 if (kwds == NULL) { 85 if (kwds == NULL) {
76 meta = NULL; 86 meta = NULL;
77 mkw = NULL; 87 mkw = NULL;
78 } 88 }
79 else { 89 else {
80 mkw = PyDict_Copy(kwds); /* Don't modify kwds passed in! */ 90 mkw = PyDict_Copy(kwds); /* Don't modify kwds passed in! */
81 if (mkw == NULL) { 91 if (mkw == NULL) {
82 Py_DECREF(bases); 92 Py_DECREF(bases);
83 return NULL; 93 return NULL;
84 } 94 }
85 meta = PyDict_GetItemString(mkw, "metaclass"); 95 meta = _PyDict_GetItemId(mkw, &PyId_metaclass);
86 if (meta != NULL) { 96 if (meta != NULL) {
87 Py_INCREF(meta); 97 Py_INCREF(meta);
88 if (PyDict_DelItemString(mkw, "metaclass") < 0) { 98 if (_PyDict_DelItemId(mkw, &PyId_metaclass) < 0) {
89 Py_DECREF(meta); 99 Py_DECREF(meta);
90 Py_DECREF(mkw); 100 Py_DECREF(mkw);
91 Py_DECREF(bases); 101 Py_DECREF(bases);
92 return NULL; 102 return NULL;
93 } 103 }
94 /* metaclass is explicitly given, check if it's indeed a class */ 104 /* metaclass is explicitly given, check if it's indeed a class */
95 isclass = PyType_Check(meta); 105 isclass = PyType_Check(meta);
96 } 106 }
97 } 107 }
98 if (meta == NULL) { 108 if (meta == NULL) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 343
334 static PyObject * 344 static PyObject *
335 builtin_bin(PyObject *self, PyObject *v) 345 builtin_bin(PyObject *self, PyObject *v)
336 { 346 {
337 return PyNumber_ToBase(v, 2); 347 return PyNumber_ToBase(v, 2);
338 } 348 }
339 349
340 PyDoc_STRVAR(bin_doc, 350 PyDoc_STRVAR(bin_doc,
341 "bin(number) -> string\n\ 351 "bin(number) -> string\n\
342 \n\ 352 \n\
343 Return the binary representation of an integer."); 353 Return the binary representation of an integer.\n\
354 \n\
355 >>> bin(2796202)\n\
356 '0b1010101010101010101010'\n\
357 ");
344 358
345 359
346 static PyObject * 360 static PyObject *
347 builtin_callable(PyObject *self, PyObject *v) 361 builtin_callable(PyObject *self, PyObject *v)
348 { 362 {
349 return PyBool_FromLong((long)PyCallable_Check(v)); 363 return PyBool_FromLong((long)PyCallable_Check(v));
350 } 364 }
351 365
352 PyDoc_STRVAR(callable_doc, 366 PyDoc_STRVAR(callable_doc,
353 "callable(object) -> bool\n\ 367 "callable(object) -> bool\n\
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 error: 688 error:
675 result = NULL; 689 result = NULL;
676 finally: 690 finally:
677 Py_DECREF(filename); 691 Py_DECREF(filename);
678 return result; 692 return result;
679 } 693 }
680 694
681 PyDoc_STRVAR(compile_doc, 695 PyDoc_STRVAR(compile_doc,
682 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\ 696 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\
683 \n\ 697 \n\
684 Compile the source string (a Python module, statement or expression)\n\ 698 Compile the source (a Python module, statement or expression)\n\
685 into a code object that can be executed by exec() or eval().\n\ 699 into a code object that can be executed by exec() or eval().\n\
686 The filename will be used for run-time error messages.\n\ 700 The filename will be used for run-time error messages.\n\
687 The mode must be 'exec' to compile a module, 'single' to compile a\n\ 701 The mode must be 'exec' to compile a module, 'single' to compile a\n\
688 single (interactive) statement, or 'eval' to compile an expression.\n\ 702 single (interactive) statement, or 'eval' to compile an expression.\n\
689 The flags argument, if present, controls which future statements influence\n\ 703 The flags argument, if present, controls which future statements influence\n\
690 the compilation of the code.\n\ 704 the compilation of the code.\n\
691 The dont_inherit argument, if non-zero, stops the compilation inheriting\n\ 705 The dont_inherit argument, if non-zero, stops the compilation inheriting\n\
692 the effects of any future statements in effect in the code calling\n\ 706 the effects of any future statements in effect in the code calling\n\
693 compile; if absent or zero these statements do influence the compilation,\n\ 707 compile; if absent or zero these statements do influence the compilation,\n\
694 in addition to any features explicitly specified."); 708 in addition to any features explicitly specified.");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 return NULL; 762 return NULL;
749 } 763 }
750 if (globals != Py_None && !PyDict_Check(globals)) { 764 if (globals != Py_None && !PyDict_Check(globals)) {
751 PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ? 765 PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ?
752 "globals must be a real dict; try eval(expr, {}, mapping)" 766 "globals must be a real dict; try eval(expr, {}, mapping)"
753 : "globals must be a dict"); 767 : "globals must be a dict");
754 return NULL; 768 return NULL;
755 } 769 }
756 if (globals == Py_None) { 770 if (globals == Py_None) {
757 globals = PyEval_GetGlobals(); 771 globals = PyEval_GetGlobals();
758 if (locals == Py_None) 772 if (locals == Py_None) {
759 locals = PyEval_GetLocals(); 773 locals = PyEval_GetLocals();
774 if (locals == NULL)
775 return NULL;
776 }
760 } 777 }
761 else if (locals == Py_None) 778 else if (locals == Py_None)
762 locals = globals; 779 locals = globals;
763 780
764 if (globals == NULL || locals == NULL) { 781 if (globals == NULL || locals == NULL) {
765 PyErr_SetString(PyExc_TypeError, 782 PyErr_SetString(PyExc_TypeError,
766 "eval must be given globals and locals " 783 "eval must be given globals and locals "
767 "when called without a frame"); 784 "when called without a frame");
768 return NULL; 785 return NULL;
769 } 786 }
770 787
771 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { 788 if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
772 if (PyDict_SetItemString(globals, "__builtins__", 789 if (_PyDict_SetItemId(globals, &PyId___builtins__,
773 PyEval_GetBuiltins()) != 0) 790 PyEval_GetBuiltins()) != 0)
774 return NULL; 791 return NULL;
775 } 792 }
776 793
777 if (PyCode_Check(cmd)) { 794 if (PyCode_Check(cmd)) {
778 if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) { 795 if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) {
779 PyErr_SetString(PyExc_TypeError, 796 PyErr_SetString(PyExc_TypeError,
780 "code object passed to eval() may not contain free variables"); 797 "code object passed to eval() may not contain free variables");
781 return NULL; 798 return NULL;
782 } 799 }
783 return PyEval_EvalCode(cmd, globals, locals); 800 return PyEval_EvalCode(cmd, globals, locals);
(...skipping 29 matching lines...) Expand all
813 PyObject *v; 830 PyObject *v;
814 PyObject *prog, *globals = Py_None, *locals = Py_None; 831 PyObject *prog, *globals = Py_None, *locals = Py_None;
815 832
816 if (!PyArg_UnpackTuple(args, "exec", 1, 3, &prog, &globals, &locals)) 833 if (!PyArg_UnpackTuple(args, "exec", 1, 3, &prog, &globals, &locals))
817 return NULL; 834 return NULL;
818 835
819 if (globals == Py_None) { 836 if (globals == Py_None) {
820 globals = PyEval_GetGlobals(); 837 globals = PyEval_GetGlobals();
821 if (locals == Py_None) { 838 if (locals == Py_None) {
822 locals = PyEval_GetLocals(); 839 locals = PyEval_GetLocals();
840 if (locals == NULL)
841 return NULL;
823 } 842 }
824 if (!globals || !locals) { 843 if (!globals || !locals) {
825 PyErr_SetString(PyExc_SystemError, 844 PyErr_SetString(PyExc_SystemError,
826 "globals and locals cannot be NULL"); 845 "globals and locals cannot be NULL");
827 return NULL; 846 return NULL;
828 } 847 }
829 } 848 }
830 else if (locals == Py_None) 849 else if (locals == Py_None)
831 locals = globals; 850 locals = globals;
832 851
833 if (!PyDict_Check(globals)) { 852 if (!PyDict_Check(globals)) {
834 PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.100s", 853 PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.100s",
835 globals->ob_type->tp_name); 854 globals->ob_type->tp_name);
836 return NULL; 855 return NULL;
837 } 856 }
838 if (!PyMapping_Check(locals)) { 857 if (!PyMapping_Check(locals)) {
839 PyErr_Format(PyExc_TypeError, 858 PyErr_Format(PyExc_TypeError,
840 "arg 3 must be a mapping or None, not %.100s", 859 "arg 3 must be a mapping or None, not %.100s",
841 locals->ob_type->tp_name); 860 locals->ob_type->tp_name);
842 return NULL; 861 return NULL;
843 } 862 }
844 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { 863 if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
845 if (PyDict_SetItemString(globals, "__builtins__", 864 if (_PyDict_SetItemId(globals, &PyId___builtins__,
846 PyEval_GetBuiltins()) != 0) 865 PyEval_GetBuiltins()) != 0)
847 return NULL; 866 return NULL;
848 } 867 }
849 868
850 if (PyCode_Check(prog)) { 869 if (PyCode_Check(prog)) {
851 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) { 870 if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {
852 PyErr_SetString(PyExc_TypeError, 871 PyErr_SetString(PyExc_TypeError,
853 "code object passed to exec() may not " 872 "code object passed to exec() may not "
854 "contain free variables"); 873 "contain free variables");
855 return NULL; 874 return NULL;
856 } 875 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 1273
1255 static PyObject * 1274 static PyObject *
1256 builtin_hex(PyObject *self, PyObject *v) 1275 builtin_hex(PyObject *self, PyObject *v)
1257 { 1276 {
1258 return PyNumber_ToBase(v, 16); 1277 return PyNumber_ToBase(v, 16);
1259 } 1278 }
1260 1279
1261 PyDoc_STRVAR(hex_doc, 1280 PyDoc_STRVAR(hex_doc,
1262 "hex(number) -> string\n\ 1281 "hex(number) -> string\n\
1263 \n\ 1282 \n\
1264 Return the hexadecimal representation of an integer."); 1283 Return the hexadecimal representation of an integer.\n\
1284 \n\
1285 >>> hex(3735928559)\n\
1286 '0xdeadbeef'\n\
1287 ");
1265 1288
1266 1289
1267 static PyObject * 1290 static PyObject *
1268 builtin_iter(PyObject *self, PyObject *args) 1291 builtin_iter(PyObject *self, PyObject *args)
1269 { 1292 {
1270 PyObject *v, *w = NULL; 1293 PyObject *v, *w = NULL;
1271 1294
1272 if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w)) 1295 if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w))
1273 return NULL; 1296 return NULL;
1274 if (w == NULL) 1297 if (w == NULL)
(...skipping 20 matching lines...) Expand all
1295 { 1318 {
1296 Py_ssize_t res; 1319 Py_ssize_t res;
1297 1320
1298 res = PyObject_Size(v); 1321 res = PyObject_Size(v);
1299 if (res < 0 && PyErr_Occurred()) 1322 if (res < 0 && PyErr_Occurred())
1300 return NULL; 1323 return NULL;
1301 return PyLong_FromSsize_t(res); 1324 return PyLong_FromSsize_t(res);
1302 } 1325 }
1303 1326
1304 PyDoc_STRVAR(len_doc, 1327 PyDoc_STRVAR(len_doc,
1305 "len(object) -> integer\n\ 1328 "len(module, object)\n\
1306 \n\ 1329 \n\
1307 Return the number of items of a sequence, a mapping, or a set."); 1330 Return the number of items of a sequence or collection.");
1308 1331
1309 1332
1310 static PyObject * 1333 static PyObject *
1311 builtin_locals(PyObject *self) 1334 builtin_locals(PyObject *self)
1312 { 1335 {
1313 PyObject *d; 1336 PyObject *d;
1314 1337
1315 d = PyEval_GetLocals(); 1338 d = PyEval_GetLocals();
1316 Py_XINCREF(d); 1339 Py_XINCREF(d);
1317 return d; 1340 return d;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 1477
1455 static PyObject * 1478 static PyObject *
1456 builtin_oct(PyObject *self, PyObject *v) 1479 builtin_oct(PyObject *self, PyObject *v)
1457 { 1480 {
1458 return PyNumber_ToBase(v, 8); 1481 return PyNumber_ToBase(v, 8);
1459 } 1482 }
1460 1483
1461 PyDoc_STRVAR(oct_doc, 1484 PyDoc_STRVAR(oct_doc,
1462 "oct(number) -> string\n\ 1485 "oct(number) -> string\n\
1463 \n\ 1486 \n\
1464 Return the octal representation of an integer."); 1487 Return the octal representation of an integer.\n\
1488 \n\
1489 >>> oct(342391)\n\
1490 '0o1234567'\n\
1491 ");
1465 1492
1466 1493
1467 static PyObject * 1494 static PyObject *
1468 builtin_ord(PyObject *self, PyObject* obj) 1495 builtin_ord(PyObject *self, PyObject* obj)
1469 { 1496 {
1470 long ord; 1497 long ord;
1471 Py_ssize_t size; 1498 Py_ssize_t size;
1472 1499
1473 if (PyBytes_Check(obj)) { 1500 if (PyBytes_Check(obj)) {
1474 size = PyBytes_GET_SIZE(obj); 1501 size = PyBytes_GET_SIZE(obj);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 static PyObject *dummy_args; 1567 static PyObject *dummy_args;
1541 PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; 1568 PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
1542 int i, err; 1569 int i, err;
1543 1570
1544 if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) 1571 if (dummy_args == NULL && !(dummy_args = PyTuple_New(0)))
1545 return NULL; 1572 return NULL;
1546 if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print", 1573 if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print",
1547 kwlist, &sep, &end, &file, &flush)) 1574 kwlist, &sep, &end, &file, &flush))
1548 return NULL; 1575 return NULL;
1549 if (file == NULL || file == Py_None) { 1576 if (file == NULL || file == Py_None) {
1550 file = PySys_GetObject("stdout"); 1577 file = _PySys_GetObjectId(&PyId_stdout);
1551 if (file == NULL) { 1578 if (file == NULL) {
1552 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); 1579 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
1553 return NULL; 1580 return NULL;
1554 } 1581 }
1555 1582
1556 /* sys.stdout may be None when FILE* stdout isn't connected */ 1583 /* sys.stdout may be None when FILE* stdout isn't connected */
1557 if (file == Py_None) 1584 if (file == Py_None)
1558 Py_RETURN_NONE; 1585 Py_RETURN_NONE;
1559 } 1586 }
1560 1587
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 err = PyFile_WriteObject(end, file, Py_PRINT_RAW); 1626 err = PyFile_WriteObject(end, file, Py_PRINT_RAW);
1600 if (err) 1627 if (err)
1601 return NULL; 1628 return NULL;
1602 1629
1603 if (flush != NULL) { 1630 if (flush != NULL) {
1604 PyObject *tmp; 1631 PyObject *tmp;
1605 int do_flush = PyObject_IsTrue(flush); 1632 int do_flush = PyObject_IsTrue(flush);
1606 if (do_flush == -1) 1633 if (do_flush == -1)
1607 return NULL; 1634 return NULL;
1608 else if (do_flush) { 1635 else if (do_flush) {
1609 tmp = PyObject_CallMethod(file, "flush", ""); 1636 tmp = _PyObject_CallMethodId(file, &PyId_flush, "");
1610 if (tmp == NULL) 1637 if (tmp == NULL)
1611 return NULL; 1638 return NULL;
1612 else 1639 else
1613 Py_DECREF(tmp); 1640 Py_DECREF(tmp);
1614 } 1641 }
1615 } 1642 }
1616 1643
1617 Py_RETURN_NONE; 1644 Py_RETURN_NONE;
1618 } 1645 }
1619 1646
1620 PyDoc_STRVAR(print_doc, 1647 PyDoc_STRVAR(print_doc,
1621 "print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\ 1648 "print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\
1622 \n\ 1649 \n\
1623 Prints the values to a stream, or to sys.stdout by default.\n\ 1650 Prints the values to a stream, or to sys.stdout by default.\n\
1624 Optional keyword arguments:\n\ 1651 Optional keyword arguments:\n\
1625 file: a file-like object (stream); defaults to the current sys.stdout.\n\ 1652 file: a file-like object (stream); defaults to the current sys.stdout.\n\
1626 sep: string inserted between values, default a space.\n\ 1653 sep: string inserted between values, default a space.\n\
1627 end: string appended after the last value, default a newline.\n\ 1654 end: string appended after the last value, default a newline.\n\
1628 flush: whether to forcibly flush the stream."); 1655 flush: whether to forcibly flush the stream.");
1629 1656
1630 1657
1631 static PyObject * 1658 static PyObject *
1632 builtin_input(PyObject *self, PyObject *args) 1659 builtin_input(PyObject *self, PyObject *args)
1633 { 1660 {
1634 PyObject *promptarg = NULL; 1661 PyObject *promptarg = NULL;
1635 PyObject *fin = PySys_GetObject("stdin"); 1662 PyObject *fin = _PySys_GetObjectId(&PyId_stdin);
1636 PyObject *fout = PySys_GetObject("stdout"); 1663 PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
1637 PyObject *ferr = PySys_GetObject("stderr"); 1664 PyObject *ferr = _PySys_GetObjectId(&PyId_stderr);
1638 PyObject *tmp; 1665 PyObject *tmp;
1639 long fd; 1666 long fd;
1640 int tty; 1667 int tty;
1641 1668
1642 /* Parse arguments */ 1669 /* Parse arguments */
1643 if (!PyArg_UnpackTuple(args, "input", 0, 1, &promptarg)) 1670 if (!PyArg_UnpackTuple(args, "input", 0, 1, &promptarg))
1644 return NULL; 1671 return NULL;
1645 1672
1646 /* Check that stdin/out/err are intact */ 1673 /* Check that stdin/out/err are intact */
1647 if (fin == NULL || fin == Py_None) { 1674 if (fin == NULL || fin == Py_None) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 /* If we're interactive, use (GNU) readline */ 1725 /* If we're interactive, use (GNU) readline */
1699 if (tty) { 1726 if (tty) {
1700 PyObject *po = NULL; 1727 PyObject *po = NULL;
1701 char *prompt; 1728 char *prompt;
1702 char *s = NULL; 1729 char *s = NULL;
1703 PyObject *stdin_encoding = NULL, *stdin_errors = NULL; 1730 PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
1704 PyObject *stdout_encoding = NULL, *stdout_errors = NULL; 1731 PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
1705 char *stdin_encoding_str, *stdin_errors_str; 1732 char *stdin_encoding_str, *stdin_errors_str;
1706 PyObject *result; 1733 PyObject *result;
1707 size_t len; 1734 size_t len;
1708 _Py_IDENTIFIER(encoding);
1709 _Py_IDENTIFIER(errors);
1710 1735
1711 stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding); 1736 stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding);
1712 stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors); 1737 stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors);
1713 if (!stdin_encoding || !stdin_errors) 1738 if (!stdin_encoding || !stdin_errors)
1714 /* stdin is a text stream, so it must have an 1739 /* stdin is a text stream, so it must have an
1715 encoding. */ 1740 encoding. */
1716 goto _readline_errors; 1741 goto _readline_errors;
1717 stdin_encoding_str = _PyUnicode_AsString(stdin_encoding); 1742 stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
1718 stdin_errors_str = _PyUnicode_AsString(stdin_errors); 1743 stdin_errors_str = _PyUnicode_AsString(stdin_errors);
1719 if (!stdin_encoding_str || !stdin_errors_str) 1744 if (!stdin_encoding_str || !stdin_errors_str)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 Return the canonical string representation of the object.\n\ 1853 Return the canonical string representation of the object.\n\
1829 For most object types, eval(repr(object)) == object."); 1854 For most object types, eval(repr(object)) == object.");
1830 1855
1831 1856
1832 static PyObject * 1857 static PyObject *
1833 builtin_round(PyObject *self, PyObject *args, PyObject *kwds) 1858 builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
1834 { 1859 {
1835 PyObject *ndigits = NULL; 1860 PyObject *ndigits = NULL;
1836 static char *kwlist[] = {"number", "ndigits", 0}; 1861 static char *kwlist[] = {"number", "ndigits", 0};
1837 PyObject *number, *round, *result; 1862 PyObject *number, *round, *result;
1838 _Py_IDENTIFIER(__round__);
1839 1863
1840 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", 1864 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round",
1841 kwlist, &number, &ndigits)) 1865 kwlist, &number, &ndigits))
1842 return NULL; 1866 return NULL;
1843 1867
1844 if (Py_TYPE(number)->tp_dict == NULL) { 1868 if (Py_TYPE(number)->tp_dict == NULL) {
1845 if (PyType_Ready(Py_TYPE(number)) < 0) 1869 if (PyType_Ready(Py_TYPE(number)) < 0)
1846 return NULL; 1870 return NULL;
1847 } 1871 }
1848 1872
(...skipping 22 matching lines...) Expand all
1871 same type as the number. ndigits may be negative."); 1895 same type as the number. ndigits may be negative.");
1872 1896
1873 1897
1874 static PyObject * 1898 static PyObject *
1875 builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) 1899 builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
1876 { 1900 {
1877 PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs; 1901 PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs;
1878 PyObject *callable; 1902 PyObject *callable;
1879 static char *kwlist[] = {"iterable", "key", "reverse", 0}; 1903 static char *kwlist[] = {"iterable", "key", "reverse", 0};
1880 int reverse; 1904 int reverse;
1881 _Py_IDENTIFIER(sort);
1882 1905
1883 /* args 1-3 should match listsort in Objects/listobject.c */ 1906 /* args 1-3 should match listsort in Objects/listobject.c */
1884 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted", 1907 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
1885 kwlist, &seq, &keyfunc, &reverse)) 1908 kwlist, &seq, &keyfunc, &reverse))
1886 return NULL; 1909 return NULL;
1887 1910
1888 newlist = PySequence_List(seq); 1911 newlist = PySequence_List(seq);
1889 if (newlist == NULL) 1912 if (newlist == NULL)
1890 return NULL; 1913 return NULL;
1891 1914
(...skipping 27 matching lines...) Expand all
1919 static PyObject * 1942 static PyObject *
1920 builtin_vars(PyObject *self, PyObject *args) 1943 builtin_vars(PyObject *self, PyObject *args)
1921 { 1944 {
1922 PyObject *v = NULL; 1945 PyObject *v = NULL;
1923 PyObject *d; 1946 PyObject *d;
1924 1947
1925 if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v)) 1948 if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v))
1926 return NULL; 1949 return NULL;
1927 if (v == NULL) { 1950 if (v == NULL) {
1928 d = PyEval_GetLocals(); 1951 d = PyEval_GetLocals();
1929 if (d == NULL) { 1952 if (d == NULL)
1930 if (!PyErr_Occurred()) 1953 return NULL;
1931 PyErr_SetString(PyExc_SystemError, 1954 Py_INCREF(d);
1932 "vars(): no locals!?");
1933 }
1934 else
1935 Py_INCREF(d);
1936 } 1955 }
1937 else { 1956 else {
1938 _Py_IDENTIFIER(__dict__);
1939 d = _PyObject_GetAttrId(v, &PyId___dict__); 1957 d = _PyObject_GetAttrId(v, &PyId___dict__);
1940 if (d == NULL) { 1958 if (d == NULL) {
1941 PyErr_SetString(PyExc_TypeError, 1959 PyErr_SetString(PyExc_TypeError,
1942 "vars() argument must have __dict__ attribute"); 1960 "vars() argument must have __dict__ attribute");
1943 return NULL; 1961 return NULL;
1944 } 1962 }
1945 } 1963 }
1946 return d; 1964 return d;
1947 } 1965 }
1948 1966
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2513 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2496 Py_XDECREF(debug); 2514 Py_XDECREF(debug);
2497 return NULL; 2515 return NULL;
2498 } 2516 }
2499 Py_XDECREF(debug); 2517 Py_XDECREF(debug);
2500 2518
2501 return mod; 2519 return mod;
2502 #undef ADD_TO_ALL 2520 #undef ADD_TO_ALL
2503 #undef SETBUILTIN 2521 #undef SETBUILTIN
2504 } 2522 }
LEFTRIGHT

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