1990-12-20 16:06:42 +01:00
|
|
|
|
/* Built-in functions */
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
#include "Python.h"
|
2021-03-18 14:57:49 +01:00
|
|
|
|
#include "pycore_ast.h" // _PyAST_Validate()
|
2021-10-12 08:38:19 +02:00
|
|
|
|
#include "pycore_call.h" // _PyObject_CallNoArgs()
|
2023-07-03 11:39:11 +02:00
|
|
|
|
#include "pycore_ceval.h" // _PyEval_Vector()
|
2021-03-24 00:51:50 +01:00
|
|
|
|
#include "pycore_compile.h" // _PyAST_Compile()
|
2023-03-22 15:49:51 +01:00
|
|
|
|
#include "pycore_long.h" // _PyLong_CompactValue
|
2023-07-03 11:39:11 +02:00
|
|
|
|
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
|
2020-06-22 18:02:49 +02:00
|
|
|
|
#include "pycore_object.h" // _Py_AddToAllObjects()
|
2020-06-22 17:27:35 +02:00
|
|
|
|
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
|
|
|
|
|
#include "pycore_pystate.h" // _PyThreadState_GET()
|
2023-08-29 04:18:52 +02:00
|
|
|
|
#include "pycore_pythonrun.h" // _Py_SourceAsString()
|
2023-08-24 22:02:09 +02:00
|
|
|
|
#include "pycore_sysmodule.h" // _PySys_GetAttr()
|
2020-06-22 17:27:35 +02:00
|
|
|
|
#include "pycore_tuple.h" // _PyTuple_FromArray()
|
1997-04-11 22:37:35 +02:00
|
|
|
|
|
2015-04-03 22:53:51 +02:00
|
|
|
|
#include "clinic/bltinmodule.c.h"
|
|
|
|
|
|
2023-09-30 22:06:45 +02:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
# include <unistd.h> // isatty()
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2017-12-14 23:32:56 +01:00
|
|
|
|
static PyObject*
|
2018-01-18 11:15:25 +01:00
|
|
|
|
update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
|
2017-12-14 23:32:56 +01:00
|
|
|
|
{
|
2018-01-18 11:15:25 +01:00
|
|
|
|
Py_ssize_t i, j;
|
2017-12-14 23:32:56 +01:00
|
|
|
|
PyObject *base, *meth, *new_base, *result, *new_bases = NULL;
|
|
|
|
|
assert(PyTuple_Check(bases));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nargs; i++) {
|
|
|
|
|
base = args[i];
|
|
|
|
|
if (PyType_Check(base)) {
|
|
|
|
|
if (new_bases) {
|
|
|
|
|
/* If we already have made a replacement, then we append every normal base,
|
|
|
|
|
otherwise just skip it. */
|
|
|
|
|
if (PyList_Append(new_bases, base) < 0) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-07-12 07:57:10 +02:00
|
|
|
|
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
|
2018-01-25 09:49:40 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
2017-12-14 23:32:56 +01:00
|
|
|
|
if (!meth) {
|
|
|
|
|
if (new_bases) {
|
|
|
|
|
if (PyList_Append(new_bases, base) < 0) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-02-11 17:46:57 +01:00
|
|
|
|
new_base = PyObject_CallOneArg(meth, bases);
|
2017-12-14 23:32:56 +01:00
|
|
|
|
Py_DECREF(meth);
|
|
|
|
|
if (!new_base) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (!PyTuple_Check(new_base)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"__mro_entries__ must return a tuple");
|
|
|
|
|
Py_DECREF(new_base);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (!new_bases) {
|
|
|
|
|
/* If this is a first successful replacement, create new_bases list and
|
|
|
|
|
copy previously encountered bases. */
|
|
|
|
|
if (!(new_bases = PyList_New(i))) {
|
2021-08-07 12:10:14 +02:00
|
|
|
|
Py_DECREF(new_base);
|
2017-12-14 23:32:56 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
|
base = args[j];
|
2022-11-10 11:23:36 +01:00
|
|
|
|
PyList_SET_ITEM(new_bases, j, Py_NewRef(base));
|
2017-12-14 23:32:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
j = PyList_GET_SIZE(new_bases);
|
|
|
|
|
if (PyList_SetSlice(new_bases, j, j, new_base) < 0) {
|
2021-08-07 12:10:14 +02:00
|
|
|
|
Py_DECREF(new_base);
|
2017-12-14 23:32:56 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(new_base);
|
|
|
|
|
}
|
|
|
|
|
if (!new_bases) {
|
|
|
|
|
return bases;
|
|
|
|
|
}
|
|
|
|
|
result = PyList_AsTuple(new_bases);
|
|
|
|
|
Py_DECREF(new_bases);
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
Py_XDECREF(new_bases);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/* AC: cannot convert yet, waiting for *args support */
|
2007-03-18 16:41:51 +01:00
|
|
|
|
static PyObject *
|
2017-12-15 12:11:11 +01:00
|
|
|
|
builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
2017-01-16 23:46:26 +01:00
|
|
|
|
PyObject *kwnames)
|
2007-03-18 16:41:51 +01:00
|
|
|
|
{
|
2021-08-07 12:10:14 +02:00
|
|
|
|
PyObject *func, *name, *winner, *prep;
|
|
|
|
|
PyObject *cls = NULL, *cell = NULL, *ns = NULL, *meta = NULL, *orig_bases = NULL;
|
|
|
|
|
PyObject *mkw = NULL, *bases = NULL;
|
2015-03-18 15:02:06 +01:00
|
|
|
|
int isclass = 0; /* initialize to prevent gcc warning */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
if (nargs < 2) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"__build_class__: not enough arguments");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-01-16 23:46:26 +01:00
|
|
|
|
func = args[0]; /* Better be callable */
|
2013-05-16 21:37:25 +02:00
|
|
|
|
if (!PyFunction_Check(func)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2014-08-05 21:01:10 +02:00
|
|
|
|
"__build_class__: func must be a function");
|
2013-05-16 21:37:25 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-01-16 23:46:26 +01:00
|
|
|
|
name = args[1];
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (!PyUnicode_Check(name)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"__build_class__: name is not a string");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-02-25 22:37:26 +01:00
|
|
|
|
orig_bases = _PyTuple_FromArray(args + 2, nargs - 2);
|
2017-12-14 23:32:56 +01:00
|
|
|
|
if (orig_bases == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
bases = update_bases(orig_bases, args + 2, nargs - 2);
|
|
|
|
|
if (bases == NULL) {
|
|
|
|
|
Py_DECREF(orig_bases);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2017-12-14 23:32:56 +01:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2017-01-16 23:46:26 +01:00
|
|
|
|
if (kwnames == NULL) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
meta = NULL;
|
|
|
|
|
mkw = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-01-16 23:46:26 +01:00
|
|
|
|
mkw = _PyStack_AsDict(args + nargs, kwnames);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (mkw == NULL) {
|
2021-08-07 12:10:14 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2017-01-16 23:46:26 +01:00
|
|
|
|
|
2024-03-07 10:21:08 +01:00
|
|
|
|
if (PyDict_Pop(mkw, &_Py_ID(metaclass), &meta) < 0) {
|
2023-11-27 18:52:54 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (meta != NULL) {
|
2011-10-23 14:04:16 +02:00
|
|
|
|
/* metaclass is explicitly given, check if it's indeed a class */
|
|
|
|
|
isclass = PyType_Check(meta);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (meta == NULL) {
|
2011-10-23 14:04:16 +02:00
|
|
|
|
/* if there are no bases, use type: */
|
|
|
|
|
if (PyTuple_GET_SIZE(bases) == 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
meta = (PyObject *) (&PyType_Type);
|
2011-10-23 14:04:16 +02:00
|
|
|
|
}
|
|
|
|
|
/* else get the type of the first base */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
else {
|
|
|
|
|
PyObject *base0 = PyTuple_GET_ITEM(bases, 0);
|
2020-02-07 02:24:48 +01:00
|
|
|
|
meta = (PyObject *)Py_TYPE(base0);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
Py_INCREF(meta);
|
2011-10-23 14:04:16 +02:00
|
|
|
|
isclass = 1; /* meta is really a class */
|
|
|
|
|
}
|
2011-10-23 14:36:42 +02:00
|
|
|
|
|
2011-10-23 14:04:16 +02:00
|
|
|
|
if (isclass) {
|
|
|
|
|
/* meta is really a class, so check for a more derived
|
|
|
|
|
metaclass, or possible metaclass conflicts: */
|
|
|
|
|
winner = (PyObject *)_PyType_CalculateMetaclass((PyTypeObject *)meta,
|
|
|
|
|
bases);
|
|
|
|
|
if (winner == NULL) {
|
2021-08-07 12:10:14 +02:00
|
|
|
|
goto error;
|
2011-10-23 14:04:16 +02:00
|
|
|
|
}
|
|
|
|
|
if (winner != meta) {
|
2022-11-22 13:39:11 +01:00
|
|
|
|
Py_SETREF(meta, Py_NewRef(winner));
|
2011-10-23 14:04:16 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2011-10-23 14:04:16 +02:00
|
|
|
|
/* else: meta is not a class, so we cannot do the metaclass
|
|
|
|
|
calculation, so we will use the explicitly given object as it is */
|
2023-07-12 07:57:10 +02:00
|
|
|
|
if (PyObject_GetOptionalAttr(meta, &_Py_ID(__prepare__), &prep) < 0) {
|
2018-01-25 09:49:40 +01:00
|
|
|
|
ns = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (prep == NULL) {
|
|
|
|
|
ns = PyDict_New();
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2016-08-22 23:33:13 +02:00
|
|
|
|
PyObject *pargs[2] = {name, bases};
|
2020-02-11 17:46:57 +01:00
|
|
|
|
ns = PyObject_VectorcallDict(prep, pargs, 2, mkw);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(prep);
|
|
|
|
|
}
|
|
|
|
|
if (ns == NULL) {
|
2021-08-07 12:10:14 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2017-09-27 16:04:37 +02:00
|
|
|
|
if (!PyMapping_Check(ns)) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"%.200s.__prepare__() must return a mapping, not %.200s",
|
|
|
|
|
isclass ? ((PyTypeObject *)meta)->tp_name : "<metaclass>",
|
|
|
|
|
Py_TYPE(ns)->tp_name);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2021-10-13 14:09:13 +02:00
|
|
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
2022-05-27 17:31:41 +02:00
|
|
|
|
EVAL_CALL_STAT_INC(EVAL_CALL_BUILD_CLASS);
|
2021-11-23 10:53:24 +01:00
|
|
|
|
cell = _PyEval_Vector(tstate, (PyFunctionObject *)func, ns, NULL, 0, NULL);
|
2016-12-05 07:47:55 +01:00
|
|
|
|
if (cell != NULL) {
|
2017-12-14 23:32:56 +01:00
|
|
|
|
if (bases != orig_bases) {
|
|
|
|
|
if (PyMapping_SetItemString(ns, "__orig_bases__", orig_bases) < 0) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-23 01:34:35 +02:00
|
|
|
|
PyObject *margs[3] = {name, bases, ns};
|
2020-02-11 17:46:57 +01:00
|
|
|
|
cls = PyObject_VectorcallDict(meta, margs, 3, mkw);
|
2016-12-05 07:47:55 +01:00
|
|
|
|
if (cls != NULL && PyType_Check(cls) && PyCell_Check(cell)) {
|
|
|
|
|
PyObject *cell_cls = PyCell_GET(cell);
|
|
|
|
|
if (cell_cls != cls) {
|
|
|
|
|
if (cell_cls == NULL) {
|
|
|
|
|
const char *msg =
|
|
|
|
|
"__class__ not set defining %.200R as %.200R. "
|
|
|
|
|
"Was __classcell__ propagated to type.__new__?";
|
2018-05-20 07:48:12 +02:00
|
|
|
|
PyErr_Format(PyExc_RuntimeError, msg, name, cls);
|
2016-12-05 07:47:55 +01:00
|
|
|
|
} else {
|
|
|
|
|
const char *msg =
|
|
|
|
|
"__class__ set to %.200R defining %.200R as %.200R";
|
|
|
|
|
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
|
|
|
|
|
}
|
2022-11-23 14:57:50 +01:00
|
|
|
|
Py_SETREF(cls, NULL);
|
2018-05-20 07:48:12 +02:00
|
|
|
|
goto error;
|
2016-12-05 07:47:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2016-12-05 07:47:55 +01:00
|
|
|
|
error:
|
|
|
|
|
Py_XDECREF(cell);
|
2021-08-07 12:10:14 +02:00
|
|
|
|
Py_XDECREF(ns);
|
|
|
|
|
Py_XDECREF(meta);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_XDECREF(mkw);
|
2017-12-14 23:32:56 +01:00
|
|
|
|
if (bases != orig_bases) {
|
|
|
|
|
Py_DECREF(orig_bases);
|
|
|
|
|
}
|
2021-08-07 12:10:14 +02:00
|
|
|
|
Py_DECREF(bases);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return cls;
|
2007-03-18 16:41:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(build_class_doc,
|
2019-10-13 17:35:41 +02:00
|
|
|
|
"__build_class__(func, name, /, *bases, [metaclass], **kwds) -> class\n\
|
2007-03-18 16:41:51 +01:00
|
|
|
|
\n\
|
|
|
|
|
Internal helper function used by the class statement.");
|
|
|
|
|
|
2022-03-11 17:46:55 +01:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
__import__ as builtin___import__
|
|
|
|
|
|
|
|
|
|
name: object
|
|
|
|
|
globals: object(c_default="NULL") = None
|
|
|
|
|
locals: object(c_default="NULL") = None
|
|
|
|
|
fromlist: object(c_default="NULL") = ()
|
|
|
|
|
level: int = 0
|
|
|
|
|
|
|
|
|
|
Import a module.
|
|
|
|
|
|
|
|
|
|
Because this function is meant for use by the Python
|
|
|
|
|
interpreter and not for general use, it is better to use
|
|
|
|
|
importlib.import_module() to programmatically import a module.
|
|
|
|
|
|
|
|
|
|
The globals argument is only used to determine the context;
|
|
|
|
|
they are not modified. The locals argument is unused. The fromlist
|
2022-10-03 21:09:03 +02:00
|
|
|
|
should be a list of names to emulate ``from name import ...``, or an
|
|
|
|
|
empty list to emulate ``import name``.
|
2022-03-11 17:46:55 +01:00
|
|
|
|
When importing a module from a package, note that __import__('A.B', ...)
|
|
|
|
|
returns package A when fromlist is empty, but its submodule B when
|
|
|
|
|
fromlist is not empty. The level argument is used to determine whether to
|
|
|
|
|
perform absolute or relative imports: 0 is absolute, while a positive number
|
|
|
|
|
is the number of parent directories to search relative to the current module.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2022-03-11 17:46:55 +01:00
|
|
|
|
builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals,
|
|
|
|
|
PyObject *locals, PyObject *fromlist, int level)
|
2022-10-03 21:09:03 +02:00
|
|
|
|
/*[clinic end generated code: output=4febeda88a0cd245 input=73f4b960ea5b9dd6]*/
|
1995-01-02 20:04:15 +01:00
|
|
|
|
{
|
2011-03-14 20:54:52 +01:00
|
|
|
|
return PyImport_ImportModuleLevelObject(name, globals, locals,
|
|
|
|
|
fromlist, level);
|
1995-01-02 20:04:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
abs as builtin_abs
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
x: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the absolute value of the argument.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_abs(PyObject *module, PyObject *x)
|
|
|
|
|
/*[clinic end generated code: output=b1b433b9e51356f5 input=bed4ca14e29c20d1]*/
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyNumber_Absolute(x);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
all as builtin_all
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
iterable: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return True if bool(x) is True for all values x in the iterable.
|
|
|
|
|
|
|
|
|
|
If the iterable is empty, return True.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
2005-03-11 07:49:40 +01:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_all(PyObject *module, PyObject *iterable)
|
|
|
|
|
/*[clinic end generated code: output=ca2a7127276f79b3 input=1a7c5d1bc3438a21]*/
|
2005-03-11 07:49:40 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *it, *item;
|
|
|
|
|
PyObject *(*iternext)(PyObject *);
|
|
|
|
|
int cmp;
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
it = PyObject_GetIter(iterable);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
iternext = *Py_TYPE(it)->tp_iternext;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
item = iternext(it);
|
|
|
|
|
if (item == NULL)
|
|
|
|
|
break;
|
|
|
|
|
cmp = PyObject_IsTrue(item);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
if (cmp < 0) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (cmp == 0) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if (PyErr_ExceptionMatches(PyExc_StopIteration))
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
Py_RETURN_TRUE;
|
2005-03-11 07:49:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
any as builtin_any
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
iterable: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return True if bool(x) is True for any x in the iterable.
|
|
|
|
|
|
|
|
|
|
If the iterable is empty, return False.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
2005-03-11 07:49:40 +01:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_any(PyObject *module, PyObject *iterable)
|
|
|
|
|
/*[clinic end generated code: output=fa65684748caa60e input=41d7451c23384f24]*/
|
2005-03-11 07:49:40 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *it, *item;
|
|
|
|
|
PyObject *(*iternext)(PyObject *);
|
|
|
|
|
int cmp;
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
it = PyObject_GetIter(iterable);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
iternext = *Py_TYPE(it)->tp_iternext;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
item = iternext(it);
|
|
|
|
|
if (item == NULL)
|
|
|
|
|
break;
|
|
|
|
|
cmp = PyObject_IsTrue(item);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
if (cmp < 0) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2015-10-09 06:42:47 +02:00
|
|
|
|
if (cmp > 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if (PyErr_ExceptionMatches(PyExc_StopIteration))
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
Py_RETURN_FALSE;
|
2005-03-11 07:49:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
ascii as builtin_ascii
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return an ASCII-only representation of an object.
|
|
|
|
|
|
|
|
|
|
As repr(), return a string containing a printable representation of an
|
|
|
|
|
object, but escape the non-ASCII characters in the string returned by
|
|
|
|
|
repr() using \\x, \\u or \\U escapes. This generates a string similar
|
|
|
|
|
to that returned by repr() in Python 2.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
2008-06-11 20:37:52 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_ascii(PyObject *module, PyObject *obj)
|
|
|
|
|
/*[clinic end generated code: output=6d37b3f0984c7eb9 input=4c62732e1b3a3cc9]*/
|
2008-06-11 20:37:52 +02:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyObject_ASCII(obj);
|
2008-06-11 20:37:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
bin as builtin_bin
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
number: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the binary representation of an integer.
|
|
|
|
|
|
|
|
|
|
>>> bin(2796202)
|
|
|
|
|
'0b1010101010101010101010'
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
Merged revisions 55817-55961 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines
PEP 3119 -- the abc module.
................
r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines
Implement part of PEP 3119 -- One Trick Ponies.
................
r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines
Different way to do one trick ponies, allowing registration (per PEP strawman).
................
r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines
Make sure that the magic looking for __hash__ (etc.) doesn't apply to
real subclasses of Hashable.
................
r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines
Add some more examples, e.g. generators and dict views.
................
r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines
keys() and items() *are* containers -- just values() isn't.
................
r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines
PEP 3127: new octal literals, binary literals.
................
r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines
Some octal literal fixes in Tools.
................
r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines
Tokenizer changes for PEP 3127.
................
r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines
Some docs for PEP 3127.
................
r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines
Missed a place in intobject.c. Is that used anymore anyway?
................
r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines
Merged revisions 55729-55868 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines
SF 1668596/1720897: distutils now copies data files
even if package_dir is empty.
This needs to be backported. I'm too tired tonight. It would be great
if someone backports this if the buildbots are ok with it. Otherwise,
I will try to get to it tomorrow.
........
r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines
Bug #1722484: remove docstrings again when running with -OO.
........
r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines
Fix wrong issue number.
........
r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines
Have configure raise an error when building on AtheOS. Code specific to AtheOS
will be removed in Python 2.7.
........
r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line
Update expected birthday of 2.6
........
r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines
Backout the original 'fix' to 1721309 which had no effect.
Different versions of Berkeley DB handle this differently.
The comments and bug report should have the details. Memory is allocated
in 4.4 (and presumably earlier), but not in 4.5. Thus
4.5 has the free error, but not earlier versions.
Mostly update comments, plus make the free conditional.
This fix was already applied to the 2.5 branch.
........
r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines
Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
of ``\s*``. This prevents patterns from "stealing" bits from other patterns in
order to make a match work.
Closes bug #1730389. Will be backported.
........
r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
from Linux's. Just fix the build for now but the code doesn't
support the complete capability of HCI on FreeBSD yet.
........
r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines
Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
reads a file that ends with incomplete sequence and sizehint argument
for .read() is specified.
........
r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines
Fix for Windows: close a temporary file before trying to delete it.
........
r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines
Patch by Tim Delany (missing DECREF). SF #1731330.
........
r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines
Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
........
r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines
FTP.ntransfercmd method now uses create_connection when passive,
using the timeout received in connection time.
........
r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines
Added an optional timeout parameter to function urllib2.urlopen,
with tests in test_urllib2net.py (must have network resource
enabled to execute them). Also modified test_urllib2.py because
testing mock classes must take it into acount. Docs are also
updated.
........
r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line
Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
........
r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido.
........
r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines
Make reindent.py executable.
........
r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines
Patch #1667860: Fix UnboundLocalError in urllib2.
........
r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line
Fixing changes to getbuildinfo.c that broke linux builds
........
r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line
Make this test work with older Python releases where struct has no 't' format character.
........
r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines
Bug #1733488: Fix compilation of bufferobject.c on AIX.
Will backport to 2.5.
........
r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
with small modifications.
........
r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
........
r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines
Fix wrong documentation, and correct the punktuation.
Closes [1700455].
........
r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line
Fix warnings by using proper function prototype.
........
r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines
Prevent expandtabs() on string and unicode objects from causing a segfault when
a large width is passed on 32-bit platforms. Found by Google.
It would be good for people to review this especially carefully and verify
I don't have an off by one error and there is no other way to cause overflow.
........
r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line
Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
........
r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines
Patch #1733960: Allow T_LONGLONG to accept ints.
Will backport to 2.5.
........
r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines
Fix Windows build.
........
r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines
Provide LLONG_MAX for S390.
........
r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines
First version of build scripts for Windows/AMD64 (no external
components are built yet, and 'kill_python' is disabled).
........
r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines
For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
modules in the ReleaseAMD64 configuration because they do not compile.
........
r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line
Need to set the environment variables, otherwise devenv.com is not found.
........
r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line
Revert commit 55855.
........
................
r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix the refleak counter on test_collections. The ABC metaclass creates
a registry which must be cleared on each run. Otherwise, there *seem*
to be refleaks when there really aren't any. (The class is held within
the registry even though it's no longer needed.)
................
r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line
These tests have been removed, so they are no longer needed here
................
r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines
Optimize access to True and False in the compiler (if True)
and the peepholer (LOAD_NAME True).
................
r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines
Remove __oct__ and __hex__ and use __index__ for converting
non-ints before formatting in a base.
Add a bin() builtin.
................
r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines
int(x, 0) does not "guess".
................
r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines
Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines
Get rid of unused imports and comment.
................
r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines
_Abstract.__new__ now requires either no arguments or __init__ overridden.
................
r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines
Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
needing to import _collections.so during the bootstrap (this will become
apparent in the next submit of os.py).
Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines
Rewrite the _Environ class to use the new collections ABCs.
................
r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines
Merged revisions 55869-55912 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line
Add Atul Varma for patch # 1667860
........
r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line
Ignore valgrind problems on Ubuntu from ld
........
r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines
Ignore config.status.lineno which seems new (new autoconf?)
........
r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent these tests from running on Win64 since they don\'t apply there either
........
r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow.
Will backport.
........
r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent hang if the port cannot be opened.
........
r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines
Add all of the distuils modules that don't seem to have explicit tests. :-(
Move an import in mworkscompiler so that this module can be imported on
any platform. Hopefully this works on all platforms.
........
r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines
SF #1734732, lower case the module names per PEP 8.
Will backport.
........
r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines
Not sure why this only fails sometimes on Unix machines. Better
to disable it and only import msvccompiler on Windows since that's
the only place it can work anyways.
........
r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines
Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.
Will backport
........
r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line
Reflow long line
........
r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines
Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
or "K" codes.
........
r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines
Added versionchanged flag to all the methods which received
a new optional timeout parameter, and a versionadded flag to
the socket.create_connection function.
........
................
r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines
New super() implementation, for PEP 3135 (though the PEP is not yet updated
to this design, and small tweaks may still be made later).
................
r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines
I'm guessing this module broke when Neal ripped out the types module --
it used 'list' both as a local variable and as the built-in list type.
Renamed the local variable since that was easier.
................
r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines
Change all occurrences of super(<thisclass>, <firstarg>) to super().
Seems to have worked, all the tests still pass.
Exception: test_descr and test_descrtut, which have tons of these
and are there to test the various usages.
................
r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line
Patch #1735485: remove StandardError from the exception hierarchy.
................
r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines
Merged revisions 55913-55950 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines
Apply patch #1734945 to support TurboLinux as distribution.
........
r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines
Add patch #1726668: Windows Vista support.
........
r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line
Checkout, but do not yet try to build, exernal sources.
........
r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
Set the /XP64 /RETAIL build enviroment in the makefile when building
ReleaseAMD64.
........
r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines
Revert this change, since it breaks the win32 build:
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
........
r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines
Specify the bufferoverflowU.lib to the makefile on the command line
(for ReleaseAMD64 builds).
........
r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines
Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
Build sqlite3.dll and bsddb.
........
r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines
Don't rebuild Berkeley DB if not needed (this was committed by accident).
........
r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines
Provide PY_LLONG_MAX on all systems having long long.
Will backport to 2.5.
........
................
r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines
Fix a compilation warning.
................
2007-06-13 20:07:49 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_bin(PyObject *module, PyObject *number)
|
|
|
|
|
/*[clinic end generated code: output=b6fc4ad5e649f4f7 input=53f8a0264bacaf90]*/
|
Merged revisions 55817-55961 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines
PEP 3119 -- the abc module.
................
r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines
Implement part of PEP 3119 -- One Trick Ponies.
................
r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines
Different way to do one trick ponies, allowing registration (per PEP strawman).
................
r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines
Make sure that the magic looking for __hash__ (etc.) doesn't apply to
real subclasses of Hashable.
................
r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines
Add some more examples, e.g. generators and dict views.
................
r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines
keys() and items() *are* containers -- just values() isn't.
................
r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines
PEP 3127: new octal literals, binary literals.
................
r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines
Some octal literal fixes in Tools.
................
r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines
Tokenizer changes for PEP 3127.
................
r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines
Some docs for PEP 3127.
................
r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines
Missed a place in intobject.c. Is that used anymore anyway?
................
r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines
Merged revisions 55729-55868 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines
SF 1668596/1720897: distutils now copies data files
even if package_dir is empty.
This needs to be backported. I'm too tired tonight. It would be great
if someone backports this if the buildbots are ok with it. Otherwise,
I will try to get to it tomorrow.
........
r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines
Bug #1722484: remove docstrings again when running with -OO.
........
r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines
Fix wrong issue number.
........
r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines
Have configure raise an error when building on AtheOS. Code specific to AtheOS
will be removed in Python 2.7.
........
r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line
Update expected birthday of 2.6
........
r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines
Backout the original 'fix' to 1721309 which had no effect.
Different versions of Berkeley DB handle this differently.
The comments and bug report should have the details. Memory is allocated
in 4.4 (and presumably earlier), but not in 4.5. Thus
4.5 has the free error, but not earlier versions.
Mostly update comments, plus make the free conditional.
This fix was already applied to the 2.5 branch.
........
r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines
Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
of ``\s*``. This prevents patterns from "stealing" bits from other patterns in
order to make a match work.
Closes bug #1730389. Will be backported.
........
r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
from Linux's. Just fix the build for now but the code doesn't
support the complete capability of HCI on FreeBSD yet.
........
r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines
Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
reads a file that ends with incomplete sequence and sizehint argument
for .read() is specified.
........
r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines
Fix for Windows: close a temporary file before trying to delete it.
........
r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines
Patch by Tim Delany (missing DECREF). SF #1731330.
........
r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines
Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
........
r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines
FTP.ntransfercmd method now uses create_connection when passive,
using the timeout received in connection time.
........
r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines
Added an optional timeout parameter to function urllib2.urlopen,
with tests in test_urllib2net.py (must have network resource
enabled to execute them). Also modified test_urllib2.py because
testing mock classes must take it into acount. Docs are also
updated.
........
r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line
Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
........
r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido.
........
r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines
Make reindent.py executable.
........
r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines
Patch #1667860: Fix UnboundLocalError in urllib2.
........
r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line
Fixing changes to getbuildinfo.c that broke linux builds
........
r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line
Make this test work with older Python releases where struct has no 't' format character.
........
r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines
Bug #1733488: Fix compilation of bufferobject.c on AIX.
Will backport to 2.5.
........
r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
with small modifications.
........
r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
........
r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines
Fix wrong documentation, and correct the punktuation.
Closes [1700455].
........
r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line
Fix warnings by using proper function prototype.
........
r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines
Prevent expandtabs() on string and unicode objects from causing a segfault when
a large width is passed on 32-bit platforms. Found by Google.
It would be good for people to review this especially carefully and verify
I don't have an off by one error and there is no other way to cause overflow.
........
r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line
Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
........
r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines
Patch #1733960: Allow T_LONGLONG to accept ints.
Will backport to 2.5.
........
r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines
Fix Windows build.
........
r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines
Provide LLONG_MAX for S390.
........
r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines
First version of build scripts for Windows/AMD64 (no external
components are built yet, and 'kill_python' is disabled).
........
r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines
For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
modules in the ReleaseAMD64 configuration because they do not compile.
........
r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line
Need to set the environment variables, otherwise devenv.com is not found.
........
r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line
Revert commit 55855.
........
................
r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix the refleak counter on test_collections. The ABC metaclass creates
a registry which must be cleared on each run. Otherwise, there *seem*
to be refleaks when there really aren't any. (The class is held within
the registry even though it's no longer needed.)
................
r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line
These tests have been removed, so they are no longer needed here
................
r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines
Optimize access to True and False in the compiler (if True)
and the peepholer (LOAD_NAME True).
................
r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines
Remove __oct__ and __hex__ and use __index__ for converting
non-ints before formatting in a base.
Add a bin() builtin.
................
r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines
int(x, 0) does not "guess".
................
r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines
Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines
Get rid of unused imports and comment.
................
r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines
_Abstract.__new__ now requires either no arguments or __init__ overridden.
................
r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines
Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
needing to import _collections.so during the bootstrap (this will become
apparent in the next submit of os.py).
Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines
Rewrite the _Environ class to use the new collections ABCs.
................
r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines
Merged revisions 55869-55912 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line
Add Atul Varma for patch # 1667860
........
r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line
Ignore valgrind problems on Ubuntu from ld
........
r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines
Ignore config.status.lineno which seems new (new autoconf?)
........
r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent these tests from running on Win64 since they don\'t apply there either
........
r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow.
Will backport.
........
r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent hang if the port cannot be opened.
........
r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines
Add all of the distuils modules that don't seem to have explicit tests. :-(
Move an import in mworkscompiler so that this module can be imported on
any platform. Hopefully this works on all platforms.
........
r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines
SF #1734732, lower case the module names per PEP 8.
Will backport.
........
r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines
Not sure why this only fails sometimes on Unix machines. Better
to disable it and only import msvccompiler on Windows since that's
the only place it can work anyways.
........
r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines
Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.
Will backport
........
r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line
Reflow long line
........
r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines
Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
or "K" codes.
........
r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines
Added versionchanged flag to all the methods which received
a new optional timeout parameter, and a versionadded flag to
the socket.create_connection function.
........
................
r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines
New super() implementation, for PEP 3135 (though the PEP is not yet updated
to this design, and small tweaks may still be made later).
................
r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines
I'm guessing this module broke when Neal ripped out the types module --
it used 'list' both as a local variable and as the built-in list type.
Renamed the local variable since that was easier.
................
r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines
Change all occurrences of super(<thisclass>, <firstarg>) to super().
Seems to have worked, all the tests still pass.
Exception: test_descr and test_descrtut, which have tons of these
and are there to test the various usages.
................
r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line
Patch #1735485: remove StandardError from the exception hierarchy.
................
r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines
Merged revisions 55913-55950 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines
Apply patch #1734945 to support TurboLinux as distribution.
........
r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines
Add patch #1726668: Windows Vista support.
........
r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line
Checkout, but do not yet try to build, exernal sources.
........
r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
Set the /XP64 /RETAIL build enviroment in the makefile when building
ReleaseAMD64.
........
r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines
Revert this change, since it breaks the win32 build:
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
........
r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines
Specify the bufferoverflowU.lib to the makefile on the command line
(for ReleaseAMD64 builds).
........
r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines
Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
Build sqlite3.dll and bsddb.
........
r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines
Don't rebuild Berkeley DB if not needed (this was committed by accident).
........
r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines
Provide PY_LLONG_MAX on all systems having long long.
Will backport to 2.5.
........
................
r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines
Fix a compilation warning.
................
2007-06-13 20:07:49 +02:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyNumber_ToBase(number, 2);
|
Merged revisions 55817-55961 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines
PEP 3119 -- the abc module.
................
r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines
Implement part of PEP 3119 -- One Trick Ponies.
................
r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines
Different way to do one trick ponies, allowing registration (per PEP strawman).
................
r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines
Make sure that the magic looking for __hash__ (etc.) doesn't apply to
real subclasses of Hashable.
................
r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines
Add some more examples, e.g. generators and dict views.
................
r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines
keys() and items() *are* containers -- just values() isn't.
................
r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines
PEP 3127: new octal literals, binary literals.
................
r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines
Some octal literal fixes in Tools.
................
r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines
Tokenizer changes for PEP 3127.
................
r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines
Some docs for PEP 3127.
................
r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines
Missed a place in intobject.c. Is that used anymore anyway?
................
r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines
Merged revisions 55729-55868 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines
SF 1668596/1720897: distutils now copies data files
even if package_dir is empty.
This needs to be backported. I'm too tired tonight. It would be great
if someone backports this if the buildbots are ok with it. Otherwise,
I will try to get to it tomorrow.
........
r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines
Bug #1722484: remove docstrings again when running with -OO.
........
r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines
Fix wrong issue number.
........
r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines
Have configure raise an error when building on AtheOS. Code specific to AtheOS
will be removed in Python 2.7.
........
r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line
Update expected birthday of 2.6
........
r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines
Backout the original 'fix' to 1721309 which had no effect.
Different versions of Berkeley DB handle this differently.
The comments and bug report should have the details. Memory is allocated
in 4.4 (and presumably earlier), but not in 4.5. Thus
4.5 has the free error, but not earlier versions.
Mostly update comments, plus make the free conditional.
This fix was already applied to the 2.5 branch.
........
r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines
Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
of ``\s*``. This prevents patterns from "stealing" bits from other patterns in
order to make a match work.
Closes bug #1730389. Will be backported.
........
r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
from Linux's. Just fix the build for now but the code doesn't
support the complete capability of HCI on FreeBSD yet.
........
r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines
Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
reads a file that ends with incomplete sequence and sizehint argument
for .read() is specified.
........
r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines
Fix for Windows: close a temporary file before trying to delete it.
........
r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines
Patch by Tim Delany (missing DECREF). SF #1731330.
........
r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines
Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
........
r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines
FTP.ntransfercmd method now uses create_connection when passive,
using the timeout received in connection time.
........
r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines
Added an optional timeout parameter to function urllib2.urlopen,
with tests in test_urllib2net.py (must have network resource
enabled to execute them). Also modified test_urllib2.py because
testing mock classes must take it into acount. Docs are also
updated.
........
r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line
Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
........
r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido.
........
r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines
Make reindent.py executable.
........
r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines
Patch #1667860: Fix UnboundLocalError in urllib2.
........
r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line
Fixing changes to getbuildinfo.c that broke linux builds
........
r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line
Make this test work with older Python releases where struct has no 't' format character.
........
r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines
Bug #1733488: Fix compilation of bufferobject.c on AIX.
Will backport to 2.5.
........
r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
with small modifications.
........
r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
........
r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines
Fix wrong documentation, and correct the punktuation.
Closes [1700455].
........
r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line
Fix warnings by using proper function prototype.
........
r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines
Prevent expandtabs() on string and unicode objects from causing a segfault when
a large width is passed on 32-bit platforms. Found by Google.
It would be good for people to review this especially carefully and verify
I don't have an off by one error and there is no other way to cause overflow.
........
r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line
Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
........
r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines
Patch #1733960: Allow T_LONGLONG to accept ints.
Will backport to 2.5.
........
r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines
Fix Windows build.
........
r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines
Provide LLONG_MAX for S390.
........
r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines
First version of build scripts for Windows/AMD64 (no external
components are built yet, and 'kill_python' is disabled).
........
r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines
For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
modules in the ReleaseAMD64 configuration because they do not compile.
........
r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line
Need to set the environment variables, otherwise devenv.com is not found.
........
r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line
Revert commit 55855.
........
................
r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix the refleak counter on test_collections. The ABC metaclass creates
a registry which must be cleared on each run. Otherwise, there *seem*
to be refleaks when there really aren't any. (The class is held within
the registry even though it's no longer needed.)
................
r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line
These tests have been removed, so they are no longer needed here
................
r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines
Optimize access to True and False in the compiler (if True)
and the peepholer (LOAD_NAME True).
................
r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines
Remove __oct__ and __hex__ and use __index__ for converting
non-ints before formatting in a base.
Add a bin() builtin.
................
r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines
int(x, 0) does not "guess".
................
r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines
Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines
Get rid of unused imports and comment.
................
r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines
_Abstract.__new__ now requires either no arguments or __init__ overridden.
................
r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines
Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
needing to import _collections.so during the bootstrap (this will become
apparent in the next submit of os.py).
Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines
Rewrite the _Environ class to use the new collections ABCs.
................
r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines
Merged revisions 55869-55912 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line
Add Atul Varma for patch # 1667860
........
r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line
Ignore valgrind problems on Ubuntu from ld
........
r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines
Ignore config.status.lineno which seems new (new autoconf?)
........
r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent these tests from running on Win64 since they don\'t apply there either
........
r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow.
Will backport.
........
r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent hang if the port cannot be opened.
........
r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines
Add all of the distuils modules that don't seem to have explicit tests. :-(
Move an import in mworkscompiler so that this module can be imported on
any platform. Hopefully this works on all platforms.
........
r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines
SF #1734732, lower case the module names per PEP 8.
Will backport.
........
r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines
Not sure why this only fails sometimes on Unix machines. Better
to disable it and only import msvccompiler on Windows since that's
the only place it can work anyways.
........
r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines
Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.
Will backport
........
r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line
Reflow long line
........
r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines
Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
or "K" codes.
........
r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines
Added versionchanged flag to all the methods which received
a new optional timeout parameter, and a versionadded flag to
the socket.create_connection function.
........
................
r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines
New super() implementation, for PEP 3135 (though the PEP is not yet updated
to this design, and small tweaks may still be made later).
................
r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines
I'm guessing this module broke when Neal ripped out the types module --
it used 'list' both as a local variable and as the built-in list type.
Renamed the local variable since that was easier.
................
r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines
Change all occurrences of super(<thisclass>, <firstarg>) to super().
Seems to have worked, all the tests still pass.
Exception: test_descr and test_descrtut, which have tons of these
and are there to test the various usages.
................
r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line
Patch #1735485: remove StandardError from the exception hierarchy.
................
r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines
Merged revisions 55913-55950 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines
Apply patch #1734945 to support TurboLinux as distribution.
........
r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines
Add patch #1726668: Windows Vista support.
........
r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line
Checkout, but do not yet try to build, exernal sources.
........
r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
Set the /XP64 /RETAIL build enviroment in the makefile when building
ReleaseAMD64.
........
r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines
Revert this change, since it breaks the win32 build:
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
........
r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines
Specify the bufferoverflowU.lib to the makefile on the command line
(for ReleaseAMD64 builds).
........
r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines
Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
Build sqlite3.dll and bsddb.
........
r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines
Don't rebuild Berkeley DB if not needed (this was committed by accident).
........
r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines
Provide PY_LLONG_MAX on all systems having long long.
Will backport to 2.5.
........
................
r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines
Fix a compilation warning.
................
2007-06-13 20:07:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
callable as builtin_callable
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return whether the object is callable (i.e., some kind of function).
|
|
|
|
|
|
|
|
|
|
Note that classes are callable, as are instances of classes with a
|
|
|
|
|
__call__() method.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
2010-11-27 23:00:11 +01:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_callable(PyObject *module, PyObject *obj)
|
|
|
|
|
/*[clinic end generated code: output=2b095d59d934cb7e input=1423bab99cc41f58]*/
|
2010-11-27 23:00:11 +01:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyBool_FromLong((long)PyCallable_Check(obj));
|
2010-11-27 23:00:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 18:11:18 +02:00
|
|
|
|
static PyObject *
|
2017-12-15 12:11:11 +01:00
|
|
|
|
builtin_breakpoint(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *keywords)
|
2017-10-05 18:11:18 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *hook = PySys_GetObject("breakpointhook");
|
|
|
|
|
|
|
|
|
|
if (hook == NULL) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "lost sys.breakpointhook");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-06-24 17:42:54 +02:00
|
|
|
|
|
|
|
|
|
if (PySys_Audit("builtins.breakpoint", "O", hook) < 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 18:11:18 +02:00
|
|
|
|
Py_INCREF(hook);
|
2020-02-11 17:46:57 +01:00
|
|
|
|
PyObject *retval = PyObject_Vectorcall(hook, args, nargs, keywords);
|
2017-10-05 18:11:18 +02:00
|
|
|
|
Py_DECREF(hook);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(breakpoint_doc,
|
2024-04-12 12:56:41 +02:00
|
|
|
|
"breakpoint($module, /, *args, **kws)\n\
|
2023-11-13 08:13:49 +01:00
|
|
|
|
--\n\
|
2017-10-05 18:11:18 +02:00
|
|
|
|
\n\
|
|
|
|
|
Call sys.breakpointhook(*args, **kws). sys.breakpointhook() must accept\n\
|
|
|
|
|
whatever arguments are passed.\n\
|
|
|
|
|
\n\
|
|
|
|
|
By default, this drops you into the pdb debugger.");
|
2010-11-27 23:00:11 +01:00
|
|
|
|
|
2008-03-13 01:19:26 +01:00
|
|
|
|
typedef struct {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_HEAD
|
|
|
|
|
PyObject *func;
|
|
|
|
|
PyObject *it;
|
2008-03-13 01:19:26 +01:00
|
|
|
|
} filterobject;
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2008-03-13 01:19:26 +01:00
|
|
|
|
filter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
1993-10-26 18:58:25 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *func, *seq;
|
|
|
|
|
PyObject *it;
|
|
|
|
|
filterobject *lz;
|
|
|
|
|
|
2021-09-12 12:27:50 +02:00
|
|
|
|
if ((type == &PyFilter_Type || type->tp_init == PyFilter_Type.tp_init) &&
|
|
|
|
|
!_PyArg_NoKeywords("filter", kwds))
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* Get iterator. */
|
|
|
|
|
it = PyObject_GetIter(seq);
|
|
|
|
|
if (it == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* create filterobject structure */
|
|
|
|
|
lz = (filterobject *)type->tp_alloc(type, 0);
|
|
|
|
|
if (lz == NULL) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2021-03-10 17:39:52 +01:00
|
|
|
|
|
|
|
|
|
lz->func = Py_NewRef(func);
|
|
|
|
|
lz->it = it;
|
|
|
|
|
|
|
|
|
|
return (PyObject *)lz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
filter_vectorcall(PyObject *type, PyObject * const*args,
|
|
|
|
|
size_t nargsf, PyObject *kwnames)
|
|
|
|
|
{
|
2022-01-21 23:30:17 +01:00
|
|
|
|
PyTypeObject *tp = _PyType_CAST(type);
|
2021-03-10 17:39:52 +01:00
|
|
|
|
if (tp == &PyFilter_Type && !_PyArg_NoKwnames("filter", kwnames)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
|
|
|
|
if (!_PyArg_CheckPositional("filter", nargs, 2, 2)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *it = PyObject_GetIter(args[1]);
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterobject *lz = (filterobject *)tp->tp_alloc(tp, 0);
|
|
|
|
|
|
|
|
|
|
if (lz == NULL) {
|
|
|
|
|
Py_DECREF(it);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lz->func = Py_NewRef(args[0]);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
lz->it = it;
|
|
|
|
|
|
|
|
|
|
return (PyObject *)lz;
|
2008-03-13 01:19:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
filter_dealloc(filterobject *lz)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_GC_UnTrack(lz);
|
2023-03-05 12:00:41 +01:00
|
|
|
|
Py_TRASHCAN_BEGIN(lz, filter_dealloc)
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_XDECREF(lz->func);
|
|
|
|
|
Py_XDECREF(lz->it);
|
|
|
|
|
Py_TYPE(lz)->tp_free(lz);
|
2023-03-05 12:00:41 +01:00
|
|
|
|
Py_TRASHCAN_END
|
2008-03-13 01:19:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
filter_traverse(filterobject *lz, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_VISIT(lz->it);
|
|
|
|
|
Py_VISIT(lz->func);
|
|
|
|
|
return 0;
|
2008-03-13 01:19:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
filter_next(filterobject *lz)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *item;
|
|
|
|
|
PyObject *it = lz->it;
|
|
|
|
|
long ok;
|
|
|
|
|
PyObject *(*iternext)(PyObject *);
|
2015-10-09 07:34:08 +02:00
|
|
|
|
int checktrue = lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
iternext = *Py_TYPE(it)->tp_iternext;
|
|
|
|
|
for (;;) {
|
|
|
|
|
item = iternext(it);
|
|
|
|
|
if (item == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2015-10-09 07:34:08 +02:00
|
|
|
|
if (checktrue) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
ok = PyObject_IsTrue(item);
|
|
|
|
|
} else {
|
|
|
|
|
PyObject *good;
|
2020-02-11 17:46:57 +01:00
|
|
|
|
good = PyObject_CallOneArg(lz->func, item);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (good == NULL) {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
ok = PyObject_IsTrue(good);
|
|
|
|
|
Py_DECREF(good);
|
|
|
|
|
}
|
2012-08-15 23:18:25 +02:00
|
|
|
|
if (ok > 0)
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return item;
|
|
|
|
|
Py_DECREF(item);
|
2012-08-15 23:18:25 +02:00
|
|
|
|
if (ok < 0)
|
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
1993-10-26 18:58:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 12:49:41 +02:00
|
|
|
|
static PyObject *
|
2018-04-29 20:59:33 +02:00
|
|
|
|
filter_reduce(filterobject *lz, PyObject *Py_UNUSED(ignored))
|
2012-04-03 12:49:41 +02:00
|
|
|
|
{
|
|
|
|
|
return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
|
|
|
|
|
|
|
|
|
static PyMethodDef filter_methods[] = {
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"__reduce__", _PyCFunction_CAST(filter_reduce), METH_NOARGS, reduce_doc},
|
2012-04-03 12:49:41 +02:00
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(filter_doc,
|
2023-11-13 08:13:49 +01:00
|
|
|
|
"filter(function, iterable, /)\n\
|
|
|
|
|
--\n\
|
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
Fix a place where floor division would be in order.
........
r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
Make map() and filter() identical to itertools.imap() and .ifilter(),
respectively.
I fixed two bootstrap issues, due to the dynamic import of itertools:
1. Starting python requires that map() and filter() are not used until
site.py has added build/lib.<arch> to sys.path.
2. Building python requires that setup.py and distutils and everything
they use is free of map() and filter() calls.
Beyond this, I only fixed the tests in test_builtin.py.
Others, please help fixing the remaining tests that are now broken!
The fixes are usually simple:
a. map(None, X) -> list(X)
b. map(F, X) -> list(map(F, X))
c. map(lambda x: F(x), X) -> [F(x) for x in X]
d. filter(F, X) -> list(filter(F, X))
e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
Someone, please also contribute a fixer for 2to3 to do this.
It can leave map()/filter() calls alone that are already
inside a list() or sorted() call or for-loop.
Only in rare cases have I seen code that depends on map() of lists
of different lengths going to the end of the longest, or on filter()
of a string or tuple returning an object of the same type; these
will need more thought to fix.
........
r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
Make it so that test_decimal fails instead of hangs, to help automated
test runners.
........
r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
Fix a few test cases after the map->imap change.
........
r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
Get a bunch more tests passing after converting map/filter to return iterators.
........
r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
Fix the remaining failing unit tests (at least on OSX).
Also tweaked urllib2 so it doesn't raise socket.gaierror when
all network interfaces are turned off.
........
2007-07-03 10:25:58 +02:00
|
|
|
|
\n\
|
2008-05-16 15:27:32 +02:00
|
|
|
|
Return an iterator yielding those items of iterable for which function(item)\n\
|
2008-03-13 01:19:26 +01:00
|
|
|
|
is true. If function is None, return the items that are true.");
|
|
|
|
|
|
|
|
|
|
PyTypeObject PyFilter_Type = {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"filter", /* tp_name */
|
|
|
|
|
sizeof(filterobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)filter_dealloc, /* tp_dealloc */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_vectorcall_offset */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_as_async */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
|
|
|
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
|
|
|
filter_doc, /* tp_doc */
|
|
|
|
|
(traverseproc)filter_traverse, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
PyObject_SelfIter, /* tp_iter */
|
|
|
|
|
(iternextfunc)filter_next, /* tp_iternext */
|
2012-04-03 12:49:41 +02:00
|
|
|
|
filter_methods, /* tp_methods */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_members */
|
|
|
|
|
0, /* tp_getset */
|
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
0, /* tp_init */
|
|
|
|
|
PyType_GenericAlloc, /* tp_alloc */
|
|
|
|
|
filter_new, /* tp_new */
|
|
|
|
|
PyObject_GC_Del, /* tp_free */
|
2021-03-10 17:39:52 +01:00
|
|
|
|
.tp_vectorcall = (vectorcallfunc)filter_vectorcall
|
2008-03-13 01:19:26 +01:00
|
|
|
|
};
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
format as builtin_format
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
value: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
format_spec: unicode(c_default="NULL") = ''
|
|
|
|
|
/
|
|
|
|
|
|
2022-10-04 00:28:02 +02:00
|
|
|
|
Return type(value).__format__(value, format_spec)
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
2022-10-04 00:28:02 +02:00
|
|
|
|
Many built-in types implement format_spec according to the
|
|
|
|
|
Format Specification Mini-language. See help('FORMATTING').
|
|
|
|
|
|
|
|
|
|
If type(value) does not supply a method named __format__
|
|
|
|
|
and format_spec is empty, then str(value) is returned.
|
|
|
|
|
See also help('SPECIALMETHODS').
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec)
|
2022-10-04 00:28:02 +02:00
|
|
|
|
/*[clinic end generated code: output=2f40bdfa4954b077 input=45ef3934b86d5624]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
2008-02-17 20:48:00 +01:00
|
|
|
|
return PyObject_Format(value, format_spec);
|
2007-08-25 04:26:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
chr as builtin_chr
|
|
|
|
|
|
2024-02-10 11:21:35 +01:00
|
|
|
|
i: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2024-02-10 11:21:35 +01:00
|
|
|
|
builtin_chr(PyObject *module, PyObject *i)
|
|
|
|
|
/*[clinic end generated code: output=d34f25b8035a9b10 input=f919867f0ba2f496]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
2024-02-10 11:21:35 +01:00
|
|
|
|
int overflow;
|
|
|
|
|
long v = PyLong_AsLongAndOverflow(i, &overflow);
|
|
|
|
|
if (v == -1 && PyErr_Occurred()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (overflow) {
|
|
|
|
|
v = overflow < 0 ? INT_MIN : INT_MAX;
|
|
|
|
|
/* Allow PyUnicode_FromOrdinal() to raise an exception */
|
|
|
|
|
}
|
|
|
|
|
#if SIZEOF_INT < SIZEOF_LONG
|
|
|
|
|
else if (v < INT_MIN) {
|
|
|
|
|
v = INT_MIN;
|
|
|
|
|
}
|
|
|
|
|
else if (v > INT_MAX) {
|
|
|
|
|
v = INT_MAX;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return PyUnicode_FromOrdinal(v);
|
2014-08-17 06:01:19 +02:00
|
|
|
|
}
|
2000-03-11 00:00:52 +01:00
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
compile as builtin_compile
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
source: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
filename: object(converter="PyUnicode_FSDecoder")
|
2015-05-30 10:09:35 +02:00
|
|
|
|
mode: str
|
|
|
|
|
flags: int = 0
|
2022-12-03 20:52:21 +01:00
|
|
|
|
dont_inherit: bool = False
|
2015-05-30 10:09:35 +02:00
|
|
|
|
optimize: int = -1
|
2019-06-12 02:52:16 +02:00
|
|
|
|
*
|
|
|
|
|
_feature_version as feature_version: int = -1
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Compile source into a code object that can be executed by exec() or eval().
|
|
|
|
|
|
|
|
|
|
The source code may represent a Python module, statement or expression.
|
|
|
|
|
The filename will be used for run-time error messages.
|
|
|
|
|
The mode must be 'exec' to compile a module, 'single' to compile a
|
|
|
|
|
single (interactive) statement, or 'eval' to compile an expression.
|
|
|
|
|
The flags argument, if present, controls which future statements influence
|
|
|
|
|
the compilation of the code.
|
2015-05-30 10:30:39 +02:00
|
|
|
|
The dont_inherit argument, if true, stops the compilation inheriting
|
2014-08-17 06:01:19 +02:00
|
|
|
|
the effects of any future statements in effect in the code calling
|
2015-05-30 10:30:39 +02:00
|
|
|
|
compile; if absent or false these statements do influence the compilation,
|
2014-08-17 06:01:19 +02:00
|
|
|
|
in addition to any features explicitly specified.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
|
|
|
|
|
const char *mode, int flags, int dont_inherit,
|
2019-03-07 21:38:08 +01:00
|
|
|
|
int optimize, int feature_version)
|
2022-12-03 20:52:21 +01:00
|
|
|
|
/*[clinic end generated code: output=b0c09c84f116d3d7 input=cc78e20e7c7682ba]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
2015-11-07 03:56:11 +01:00
|
|
|
|
PyObject *source_copy;
|
2015-02-03 00:25:42 +01:00
|
|
|
|
const char *str;
|
2014-08-17 06:01:19 +02:00
|
|
|
|
int compile_mode = -1;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
int is_ast;
|
2019-01-31 12:40:27 +01:00
|
|
|
|
int start[] = {Py_file_input, Py_eval_input, Py_single_input, Py_func_type_input};
|
2010-10-16 15:14:10 +02:00
|
|
|
|
PyObject *result;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2019-06-13 02:16:41 +02:00
|
|
|
|
PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
2014-08-17 06:01:19 +02:00
|
|
|
|
cf.cf_flags = flags | PyCF_SOURCE_IS_UTF8;
|
2019-03-07 21:38:08 +01:00
|
|
|
|
if (feature_version >= 0 && (flags & PyCF_ONLY_AST)) {
|
|
|
|
|
cf.cf_feature_version = feature_version;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (flags &
|
2020-04-22 18:09:03 +02:00
|
|
|
|
~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK))
|
2010-05-09 17:52:27 +02:00
|
|
|
|
{
|
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
|
"compile(): unrecognised flags");
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
/* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
|
|
|
|
|
|
2010-12-04 11:26:46 +01:00
|
|
|
|
if (optimize < -1 || optimize > 2) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
|
"compile(): invalid optimize value");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (!dont_inherit) {
|
|
|
|
|
PyEval_MergeCompilerFlags(&cf);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (strcmp(mode, "exec") == 0)
|
|
|
|
|
compile_mode = 0;
|
|
|
|
|
else if (strcmp(mode, "eval") == 0)
|
|
|
|
|
compile_mode = 1;
|
|
|
|
|
else if (strcmp(mode, "single") == 0)
|
|
|
|
|
compile_mode = 2;
|
2019-01-31 12:40:27 +01:00
|
|
|
|
else if (strcmp(mode, "func_type") == 0) {
|
|
|
|
|
if (!(flags & PyCF_ONLY_AST)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
|
"compile() mode 'func_type' requires flag PyCF_ONLY_AST");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
compile_mode = 3;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
else {
|
2019-01-31 12:40:27 +01:00
|
|
|
|
const char *msg;
|
|
|
|
|
if (flags & PyCF_ONLY_AST)
|
|
|
|
|
msg = "compile() mode must be 'exec', 'eval', 'single' or 'func_type'";
|
|
|
|
|
else
|
|
|
|
|
msg = "compile() mode must be 'exec', 'eval' or 'single'";
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, msg);
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
is_ast = PyAST_Check(source);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (is_ast == -1)
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (is_ast) {
|
2023-08-23 10:01:17 +02:00
|
|
|
|
if ((flags & PyCF_OPTIMIZED_AST) == PyCF_ONLY_AST) {
|
|
|
|
|
// return an un-optimized AST
|
2022-11-10 11:23:36 +01:00
|
|
|
|
result = Py_NewRef(source);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-23 10:01:17 +02:00
|
|
|
|
// Return an optimized AST or code object
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-08-23 10:01:17 +02:00
|
|
|
|
PyArena *arena = _PyArena_New();
|
|
|
|
|
if (arena == NULL) {
|
2011-08-09 23:15:04 +02:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
2023-08-23 10:01:17 +02:00
|
|
|
|
|
|
|
|
|
if (flags & PyCF_ONLY_AST) {
|
|
|
|
|
mod_ty mod = PyAST_obj2mod(source, arena, compile_mode);
|
|
|
|
|
if (mod == NULL || !_PyAST_Validate(mod)) {
|
|
|
|
|
_PyArena_Free(arena);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (_PyCompile_AstOptimize(mod, filename, &cf, optimize,
|
|
|
|
|
arena) < 0) {
|
|
|
|
|
_PyArena_Free(arena);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
result = PyAST_mod2obj(mod);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mod_ty mod = PyAST_obj2mod(source, arena, compile_mode);
|
|
|
|
|
if (mod == NULL || !_PyAST_Validate(mod)) {
|
|
|
|
|
_PyArena_Free(arena);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
result = (PyObject*)_PyAST_Compile(mod, filename,
|
|
|
|
|
&cf, optimize, arena);
|
|
|
|
|
}
|
2021-03-24 02:23:01 +01:00
|
|
|
|
_PyArena_Free(arena);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto finally;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 01:21:17 +02:00
|
|
|
|
str = _Py_SourceAsString(source, "compile", "string, bytes or AST", &cf, &source_copy);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (str == NULL)
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto error;
|
|
|
|
|
|
2024-05-07 02:12:39 +02:00
|
|
|
|
#ifdef Py_GIL_DISABLED
|
|
|
|
|
// gh-118527: Disable immortalization of code constants for explicit
|
|
|
|
|
// compile() calls to get consistent frozen outputs between the default
|
|
|
|
|
// and free-threaded builds.
|
2024-06-03 22:58:41 +02:00
|
|
|
|
// Subtract two to suppress immortalization (so that 1 -> -1)
|
2024-05-07 02:12:39 +02:00
|
|
|
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
2024-06-03 22:58:41 +02:00
|
|
|
|
_Py_atomic_add_int(&interp->gc.immortalize, -2);
|
2024-05-07 02:12:39 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);
|
2020-04-30 21:12:19 +02:00
|
|
|
|
|
2024-05-07 02:12:39 +02:00
|
|
|
|
#ifdef Py_GIL_DISABLED
|
2024-06-03 22:58:41 +02:00
|
|
|
|
_Py_atomic_add_int(&interp->gc.immortalize, 2);
|
2024-05-07 02:12:39 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-11-07 03:56:11 +01:00
|
|
|
|
Py_XDECREF(source_copy);
|
2010-10-16 15:14:10 +02:00
|
|
|
|
goto finally;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2010-10-16 15:14:10 +02:00
|
|
|
|
error:
|
|
|
|
|
result = NULL;
|
|
|
|
|
finally:
|
2013-08-26 22:28:21 +02:00
|
|
|
|
Py_DECREF(filename);
|
2010-10-16 15:14:10 +02:00
|
|
|
|
return result;
|
1993-03-30 19:46:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-08-21 02:54:10 +02:00
|
|
|
|
builtin_dir(PyObject *self, PyObject *args)
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *arg = NULL;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_UnpackTuple(args, "dir", 0, 1, &arg))
|
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyObject_Dir(arg);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyDoc_STRVAR(dir_doc,
|
|
|
|
|
"dir([object]) -> list of strings\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"If called without an argument, return the names in the current scope.\n"
|
|
|
|
|
"Else, return an alphabetized list of names comprising (some of) the attributes\n"
|
|
|
|
|
"of the given object, and of attributes reachable from it.\n"
|
|
|
|
|
"If the object supplies a method named __dir__, it will be used; otherwise\n"
|
|
|
|
|
"the default dir() logic is used and returns:\n"
|
|
|
|
|
" for a module object: the module's attributes.\n"
|
|
|
|
|
" for a class object: its attributes, and recursively the attributes\n"
|
|
|
|
|
" of its bases.\n"
|
|
|
|
|
" for any other object: its attributes, its class's attributes, and\n"
|
|
|
|
|
" recursively the attributes of its class's base classes.");
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
divmod as builtin_divmod
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
x: object
|
|
|
|
|
y: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
2016-04-28 21:39:50 +02:00
|
|
|
|
Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y)
|
|
|
|
|
/*[clinic end generated code: output=b06d8a5f6e0c745e input=175ad9c84ff41a85]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
return PyNumber_Divmod(x, y);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
eval as builtin_eval
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
source: object
|
2024-05-02 17:55:29 +02:00
|
|
|
|
/
|
2015-05-30 10:09:35 +02:00
|
|
|
|
globals: object = None
|
|
|
|
|
locals: object = None
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Evaluate the given source in the context of globals and locals.
|
|
|
|
|
|
|
|
|
|
The source may be a string representing a Python expression
|
|
|
|
|
or a code object as returned by compile().
|
|
|
|
|
The globals must be a dictionary and locals can be any mapping,
|
|
|
|
|
defaulting to the current globals and locals.
|
|
|
|
|
If only globals is given, locals defaults to it.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
|
2015-04-15 00:07:59 +02:00
|
|
|
|
PyObject *locals)
|
2024-05-02 17:55:29 +02:00
|
|
|
|
/*[clinic end generated code: output=0a0824aa70093116 input=7c7bce5299a89062]*/
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2023-07-06 01:05:02 +02:00
|
|
|
|
PyObject *result = NULL, *source_copy;
|
2015-02-03 00:21:08 +01:00
|
|
|
|
const char *str;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
if (locals != Py_None && !PyMapping_Check(locals)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "locals must be a mapping");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (globals != Py_None && !PyDict_Check(globals)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ?
|
|
|
|
|
"globals must be a real dict; try eval(expr, {}, mapping)"
|
|
|
|
|
: "globals must be a dict");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (globals == Py_None) {
|
|
|
|
|
globals = PyEval_GetGlobals();
|
2013-10-29 01:19:37 +01:00
|
|
|
|
if (locals == Py_None) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
locals = _PyEval_GetFrameLocals();
|
2013-10-29 01:19:37 +01:00
|
|
|
|
if (locals == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-07-06 01:05:02 +02:00
|
|
|
|
else {
|
|
|
|
|
Py_INCREF(locals);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else if (locals == Py_None)
|
2023-07-06 01:05:02 +02:00
|
|
|
|
locals = Py_NewRef(globals);
|
|
|
|
|
else {
|
|
|
|
|
Py_INCREF(locals);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
if (globals == NULL || locals == NULL) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"eval must be given globals and locals "
|
|
|
|
|
"when called without a frame");
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 21:39:07 +01:00
|
|
|
|
int r = PyDict_Contains(globals, &_Py_ID(__builtins__));
|
2020-10-26 11:47:57 +01:00
|
|
|
|
if (r == 0) {
|
2022-02-08 21:39:07 +01:00
|
|
|
|
r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins());
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2020-10-26 11:47:57 +01:00
|
|
|
|
if (r < 0) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2019-02-25 16:59:46 +01:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (PyCode_Check(source)) {
|
2019-05-23 17:45:22 +02:00
|
|
|
|
if (PySys_Audit("exec", "O", source) < 0) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2019-05-23 17:45:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2019-05-23 17:45:22 +02:00
|
|
|
|
"code object passed to eval() may not contain free variables");
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2023-07-06 01:05:02 +02:00
|
|
|
|
result = PyEval_EvalCode(source, globals, locals);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2023-07-06 01:05:02 +02:00
|
|
|
|
else {
|
|
|
|
|
PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
|
|
|
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
|
|
|
|
|
str = _Py_SourceAsString(source, "eval", "string, bytes or code", &cf, &source_copy);
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-07-06 01:05:02 +02:00
|
|
|
|
while (*str == ' ' || *str == '\t')
|
|
|
|
|
str++;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-07-06 01:05:02 +02:00
|
|
|
|
(void)PyEval_MergeCompilerFlags(&cf);
|
|
|
|
|
result = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);
|
|
|
|
|
Py_XDECREF(source_copy);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-07-06 01:05:02 +02:00
|
|
|
|
error:
|
|
|
|
|
Py_XDECREF(locals);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return result;
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
exec as builtin_exec
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
source: object
|
2024-05-02 17:55:29 +02:00
|
|
|
|
/
|
2015-05-30 10:09:35 +02:00
|
|
|
|
globals: object = None
|
|
|
|
|
locals: object = None
|
2022-05-06 19:09:35 +02:00
|
|
|
|
*
|
|
|
|
|
closure: object(c_default="NULL") = None
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Execute the given source in the context of globals and locals.
|
|
|
|
|
|
|
|
|
|
The source may be a string representing one or more Python statements
|
|
|
|
|
or a code object as returned by compile().
|
|
|
|
|
The globals must be a dictionary and locals can be any mapping,
|
|
|
|
|
defaulting to the current globals and locals.
|
|
|
|
|
If only globals is given, locals defaults to it.
|
2022-05-06 19:09:35 +02:00
|
|
|
|
The closure must be a tuple of cellvars, and can only be used
|
|
|
|
|
when source is a code object requiring exactly that many cellvars.
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
2022-05-06 19:09:35 +02:00
|
|
|
|
PyObject *locals, PyObject *closure)
|
2024-05-02 17:55:29 +02:00
|
|
|
|
/*[clinic end generated code: output=7579eb4e7646743d input=25e989b6d87a3a21]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *v;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
if (globals == Py_None) {
|
|
|
|
|
globals = PyEval_GetGlobals();
|
|
|
|
|
if (locals == Py_None) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
locals = _PyEval_GetFrameLocals();
|
2013-10-29 01:19:37 +01:00
|
|
|
|
if (locals == NULL)
|
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2023-07-06 01:05:02 +02:00
|
|
|
|
else {
|
|
|
|
|
Py_INCREF(locals);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (!globals || !locals) {
|
|
|
|
|
PyErr_SetString(PyExc_SystemError,
|
|
|
|
|
"globals and locals cannot be NULL");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-06 01:05:02 +02:00
|
|
|
|
else if (locals == Py_None) {
|
|
|
|
|
locals = Py_NewRef(globals);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Py_INCREF(locals);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
if (!PyDict_Check(globals)) {
|
2014-08-17 06:01:19 +02:00
|
|
|
|
PyErr_Format(PyExc_TypeError, "exec() globals must be a dict, not %.100s",
|
2020-02-07 02:24:48 +01:00
|
|
|
|
Py_TYPE(globals)->tp_name);
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (!PyMapping_Check(locals)) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
2014-08-17 06:01:19 +02:00
|
|
|
|
"locals must be a mapping or None, not %.100s",
|
2020-02-07 02:24:48 +01:00
|
|
|
|
Py_TYPE(locals)->tp_name);
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2022-02-08 21:39:07 +01:00
|
|
|
|
int r = PyDict_Contains(globals, &_Py_ID(__builtins__));
|
2020-10-26 11:47:57 +01:00
|
|
|
|
if (r == 0) {
|
2022-02-08 21:39:07 +01:00
|
|
|
|
r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins());
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2020-10-26 11:47:57 +01:00
|
|
|
|
if (r < 0) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2019-02-25 16:59:46 +01:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2022-05-06 19:09:35 +02:00
|
|
|
|
if (closure == Py_None) {
|
|
|
|
|
closure = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (PyCode_Check(source)) {
|
2022-05-06 19:09:35 +02:00
|
|
|
|
Py_ssize_t num_free = PyCode_GetNumFree((PyCodeObject *)source);
|
|
|
|
|
if (num_free == 0) {
|
|
|
|
|
if (closure) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"cannot use a closure with this code object");
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2022-05-06 19:09:35 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int closure_is_ok =
|
|
|
|
|
closure
|
|
|
|
|
&& PyTuple_CheckExact(closure)
|
|
|
|
|
&& (PyTuple_GET_SIZE(closure) == num_free);
|
|
|
|
|
if (closure_is_ok) {
|
|
|
|
|
for (Py_ssize_t i = 0; i < num_free; i++) {
|
|
|
|
|
PyObject *cell = PyTuple_GET_ITEM(closure, i);
|
|
|
|
|
if (!PyCell_Check(cell)) {
|
|
|
|
|
closure_is_ok = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!closure_is_ok) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"code object requires a closure of exactly length %zd",
|
|
|
|
|
num_free);
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2022-05-06 19:09:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 17:45:22 +02:00
|
|
|
|
if (PySys_Audit("exec", "O", source) < 0) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2019-05-23 17:45:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 19:09:35 +02:00
|
|
|
|
if (!closure) {
|
|
|
|
|
v = PyEval_EvalCode(source, globals, locals);
|
|
|
|
|
} else {
|
|
|
|
|
v = PyEval_EvalCodeEx(source, globals, locals,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
NULL,
|
|
|
|
|
closure);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-05-06 19:09:35 +02:00
|
|
|
|
if (closure != NULL) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"closure can only be used when source is a code object");
|
|
|
|
|
}
|
2015-11-07 03:56:11 +01:00
|
|
|
|
PyObject *source_copy;
|
2015-02-03 00:21:08 +01:00
|
|
|
|
const char *str;
|
2019-06-13 02:16:41 +02:00
|
|
|
|
PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
|
2019-05-29 01:21:17 +02:00
|
|
|
|
str = _Py_SourceAsString(source, "exec",
|
2015-11-07 03:56:11 +01:00
|
|
|
|
"string, bytes or code", &cf,
|
|
|
|
|
&source_copy);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (str == NULL)
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (PyEval_MergeCompilerFlags(&cf))
|
|
|
|
|
v = PyRun_StringFlags(str, Py_file_input, globals,
|
|
|
|
|
locals, &cf);
|
|
|
|
|
else
|
|
|
|
|
v = PyRun_String(str, Py_file_input, globals, locals);
|
2015-11-07 03:56:11 +01:00
|
|
|
|
Py_XDECREF(source_copy);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (v == NULL)
|
2023-07-06 01:05:02 +02:00
|
|
|
|
goto error;
|
|
|
|
|
Py_DECREF(locals);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(v);
|
|
|
|
|
Py_RETURN_NONE;
|
2023-07-06 01:05:02 +02:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
Py_XDECREF(locals);
|
|
|
|
|
return NULL;
|
2006-09-06 08:51:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-08-21 02:54:10 +02:00
|
|
|
|
builtin_getattr(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
1992-01-27 17:53:09 +01:00
|
|
|
|
{
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *v, *name, *result;
|
|
|
|
|
|
|
|
|
|
if (!_PyArg_CheckPositional("getattr", nargs, 2, 3))
|
|
|
|
|
return NULL;
|
2017-06-15 17:05:23 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
v = args[0];
|
|
|
|
|
name = args[1];
|
|
|
|
|
if (nargs > 2) {
|
|
|
|
|
if (PyObject_GetOptionalAttr(v, name, &result) == 0) {
|
|
|
|
|
PyObject *dflt = args[2];
|
|
|
|
|
return Py_NewRef(dflt);
|
2018-01-16 12:52:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-21 02:54:10 +02:00
|
|
|
|
result = PyObject_GetAttr(v, name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
return result;
|
1993-03-29 12:43:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyDoc_STRVAR(getattr_doc,
|
|
|
|
|
"getattr(object, name[, default]) -> value\n\
|
|
|
|
|
\n\
|
|
|
|
|
Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\
|
|
|
|
|
When a default argument is given, it is returned when the attribute doesn't\n\
|
|
|
|
|
exist; without it, an exception is raised in that case.");
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
globals as builtin_globals
|
|
|
|
|
|
|
|
|
|
Return the dictionary containing the current scope's global variables.
|
|
|
|
|
|
|
|
|
|
NOTE: Updates to this dictionary *will* affect name lookups in the current
|
|
|
|
|
global scope and vice-versa.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_globals_impl(PyObject *module)
|
|
|
|
|
/*[clinic end generated code: output=e5dd1527067b94d2 input=9327576f92bb48ba]*/
|
1995-07-08 00:43:42 +02:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *d;
|
1995-07-08 00:43:42 +02:00
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
d = PyEval_GetGlobals();
|
2022-11-10 11:23:36 +01:00
|
|
|
|
return Py_XNewRef(d);
|
1995-07-08 00:43:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
hasattr as builtin_hasattr
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
|
|
|
|
name: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return whether the object has an attribute with the given name.
|
|
|
|
|
|
|
|
|
|
This is done by calling getattr(obj, name) and catching AttributeError.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name)
|
|
|
|
|
/*[clinic end generated code: output=a7aff2090a4151e5 input=0faec9787d979542]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *v;
|
|
|
|
|
|
2023-07-12 07:57:10 +02:00
|
|
|
|
if (PyObject_GetOptionalAttr(obj, name, &v) < 0) {
|
2010-08-24 05:26:23 +02:00
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2018-01-25 09:49:40 +01:00
|
|
|
|
if (v == NULL) {
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(v);
|
2010-08-24 05:26:23 +02:00
|
|
|
|
Py_RETURN_TRUE;
|
1992-01-27 17:53:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/* AC: gdb's integration with CPython relies on builtin_id having
|
|
|
|
|
* the *exact* parameter names of "self" and "v", so we ensure we
|
|
|
|
|
* preserve those name rather than using the AC defaults.
|
|
|
|
|
*/
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
id as builtin_id
|
|
|
|
|
|
2016-05-05 15:21:35 +02:00
|
|
|
|
self: self(type="PyModuleDef *")
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj as v: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the identity of an object.
|
|
|
|
|
|
|
|
|
|
This is guaranteed to be unique among simultaneously existing objects.
|
|
|
|
|
(CPython uses the object's memory address.)
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-05-05 15:21:35 +02:00
|
|
|
|
builtin_id(PyModuleDef *self, PyObject *v)
|
|
|
|
|
/*[clinic end generated code: output=0aa640785f697f65 input=5a534136419631f4]*/
|
1993-03-30 19:46:03 +02:00
|
|
|
|
{
|
2019-05-23 17:45:22 +02:00
|
|
|
|
PyObject *id = PyLong_FromVoidPtr(v);
|
|
|
|
|
|
|
|
|
|
if (id && PySys_Audit("builtins.id", "O", id) < 0) {
|
|
|
|
|
Py_DECREF(id);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id;
|
1993-03-30 19:46:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2008-03-13 02:26:19 +01:00
|
|
|
|
/* map object ************************************************************/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_HEAD
|
|
|
|
|
PyObject *iters;
|
|
|
|
|
PyObject *func;
|
2008-03-13 02:26:19 +01:00
|
|
|
|
} mapobject;
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2008-03-13 02:26:19 +01:00
|
|
|
|
map_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
1993-10-26 18:58:25 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *it, *iters, *func;
|
|
|
|
|
mapobject *lz;
|
|
|
|
|
Py_ssize_t numargs, i;
|
|
|
|
|
|
2021-09-12 12:27:50 +02:00
|
|
|
|
if ((type == &PyMap_Type || type->tp_init == PyMap_Type.tp_init) &&
|
|
|
|
|
!_PyArg_NoKeywords("map", kwds))
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
numargs = PyTuple_Size(args);
|
|
|
|
|
if (numargs < 2) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"map() must have at least two arguments.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iters = PyTuple_New(numargs-1);
|
|
|
|
|
if (iters == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
for (i=1 ; i<numargs ; i++) {
|
|
|
|
|
/* Get iterator. */
|
|
|
|
|
it = PyObject_GetIter(PyTuple_GET_ITEM(args, i));
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
Py_DECREF(iters);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyTuple_SET_ITEM(iters, i-1, it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create mapobject structure */
|
|
|
|
|
lz = (mapobject *)type->tp_alloc(type, 0);
|
|
|
|
|
if (lz == NULL) {
|
|
|
|
|
Py_DECREF(iters);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
lz->iters = iters;
|
|
|
|
|
func = PyTuple_GET_ITEM(args, 0);
|
2021-03-22 11:01:14 +01:00
|
|
|
|
lz->func = Py_NewRef(func);
|
|
|
|
|
|
|
|
|
|
return (PyObject *)lz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
map_vectorcall(PyObject *type, PyObject * const*args,
|
|
|
|
|
size_t nargsf, PyObject *kwnames)
|
|
|
|
|
{
|
2022-01-21 23:30:17 +01:00
|
|
|
|
PyTypeObject *tp = _PyType_CAST(type);
|
2021-03-22 11:01:14 +01:00
|
|
|
|
if (tp == &PyMap_Type && !_PyArg_NoKwnames("map", kwnames)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
|
|
|
|
if (nargs < 2) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"map() must have at least two arguments.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *iters = PyTuple_New(nargs-1);
|
|
|
|
|
if (iters == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=1; i<nargs; i++) {
|
|
|
|
|
PyObject *it = PyObject_GetIter(args[i]);
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
Py_DECREF(iters);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyTuple_SET_ITEM(iters, i-1, it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapobject *lz = (mapobject *)tp->tp_alloc(tp, 0);
|
|
|
|
|
if (lz == NULL) {
|
|
|
|
|
Py_DECREF(iters);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
lz->iters = iters;
|
|
|
|
|
lz->func = Py_NewRef(args[0]);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
return (PyObject *)lz;
|
2008-03-13 02:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
map_dealloc(mapobject *lz)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_GC_UnTrack(lz);
|
|
|
|
|
Py_XDECREF(lz->iters);
|
|
|
|
|
Py_XDECREF(lz->func);
|
|
|
|
|
Py_TYPE(lz)->tp_free(lz);
|
2008-03-13 02:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
map_traverse(mapobject *lz, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_VISIT(lz->iters);
|
|
|
|
|
Py_VISIT(lz->func);
|
|
|
|
|
return 0;
|
2008-03-13 02:26:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
map_next(mapobject *lz)
|
|
|
|
|
{
|
2016-12-15 12:40:53 +01:00
|
|
|
|
PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
|
2016-08-24 01:45:13 +02:00
|
|
|
|
PyObject **stack;
|
|
|
|
|
PyObject *result = NULL;
|
2019-11-14 13:36:21 +01:00
|
|
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
2016-08-24 01:45:13 +02:00
|
|
|
|
|
2019-11-14 13:36:21 +01:00
|
|
|
|
const Py_ssize_t niters = PyTuple_GET_SIZE(lz->iters);
|
2016-08-24 01:45:13 +02:00
|
|
|
|
if (niters <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
|
|
|
|
|
stack = small_stack;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stack = PyMem_Malloc(niters * sizeof(stack[0]));
|
|
|
|
|
if (stack == NULL) {
|
2019-11-14 13:36:21 +01:00
|
|
|
|
_PyErr_NoMemory(tstate);
|
2016-08-24 01:45:13 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-24 00:54:47 +02:00
|
|
|
|
|
2019-11-14 13:36:21 +01:00
|
|
|
|
Py_ssize_t nargs = 0;
|
|
|
|
|
for (Py_ssize_t i=0; i < niters; i++) {
|
2015-08-18 09:20:20 +02:00
|
|
|
|
PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
|
2016-08-24 01:45:13 +02:00
|
|
|
|
PyObject *val = Py_TYPE(it)->tp_iternext(it);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (val == NULL) {
|
2016-08-24 01:45:13 +02:00
|
|
|
|
goto exit;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2016-08-24 01:45:13 +02:00
|
|
|
|
stack[i] = val;
|
|
|
|
|
nargs++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 13:36:21 +01:00
|
|
|
|
result = _PyObject_VectorcallTstate(tstate, lz->func, stack, nargs, NULL);
|
2016-08-24 01:45:13 +02:00
|
|
|
|
|
|
|
|
|
exit:
|
2019-11-14 13:36:21 +01:00
|
|
|
|
for (Py_ssize_t i=0; i < nargs; i++) {
|
2016-08-24 01:45:13 +02:00
|
|
|
|
Py_DECREF(stack[i]);
|
|
|
|
|
}
|
|
|
|
|
if (stack != small_stack) {
|
|
|
|
|
PyMem_Free(stack);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
return result;
|
1993-10-26 18:58:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 12:49:41 +02:00
|
|
|
|
static PyObject *
|
2018-04-29 20:59:33 +02:00
|
|
|
|
map_reduce(mapobject *lz, PyObject *Py_UNUSED(ignored))
|
2012-04-03 12:49:41 +02:00
|
|
|
|
{
|
|
|
|
|
Py_ssize_t numargs = PyTuple_GET_SIZE(lz->iters);
|
|
|
|
|
PyObject *args = PyTuple_New(numargs+1);
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
if (args == NULL)
|
|
|
|
|
return NULL;
|
2022-11-10 11:23:36 +01:00
|
|
|
|
PyTuple_SET_ITEM(args, 0, Py_NewRef(lz->func));
|
2012-04-03 12:49:41 +02:00
|
|
|
|
for (i = 0; i<numargs; i++){
|
|
|
|
|
PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
|
2022-11-10 11:23:36 +01:00
|
|
|
|
PyTuple_SET_ITEM(args, i+1, Py_NewRef(it));
|
2012-04-03 12:49:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Py_BuildValue("ON", Py_TYPE(lz), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMethodDef map_methods[] = {
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"__reduce__", _PyCFunction_CAST(map_reduce), METH_NOARGS, reduce_doc},
|
2012-04-03 12:49:41 +02:00
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(map_doc,
|
2024-06-15 07:33:09 +02:00
|
|
|
|
"map(function, iterable, /, *iterables)\n\
|
2023-11-13 08:13:49 +01:00
|
|
|
|
--\n\
|
1998-06-26 23:23:49 +02:00
|
|
|
|
\n\
|
2008-03-13 02:26:19 +01:00
|
|
|
|
Make an iterator that computes the function using arguments from\n\
|
2010-05-09 17:52:27 +02:00
|
|
|
|
each of the iterables. Stops when the shortest iterable is exhausted.");
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2008-03-13 02:26:19 +01:00
|
|
|
|
PyTypeObject PyMap_Type = {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"map", /* tp_name */
|
|
|
|
|
sizeof(mapobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)map_dealloc, /* tp_dealloc */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_vectorcall_offset */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_as_async */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
|
|
|
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
|
|
|
map_doc, /* tp_doc */
|
|
|
|
|
(traverseproc)map_traverse, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
PyObject_SelfIter, /* tp_iter */
|
|
|
|
|
(iternextfunc)map_next, /* tp_iternext */
|
2012-04-03 12:49:41 +02:00
|
|
|
|
map_methods, /* tp_methods */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_members */
|
|
|
|
|
0, /* tp_getset */
|
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
0, /* tp_init */
|
|
|
|
|
PyType_GenericAlloc, /* tp_alloc */
|
|
|
|
|
map_new, /* tp_new */
|
|
|
|
|
PyObject_GC_Del, /* tp_free */
|
2021-03-22 11:01:14 +01:00
|
|
|
|
.tp_vectorcall = (vectorcallfunc)map_vectorcall
|
2008-03-13 02:26:19 +01:00
|
|
|
|
};
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
|
2007-04-21 17:47:16 +02:00
|
|
|
|
static PyObject *
|
2023-08-21 02:54:10 +02:00
|
|
|
|
builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
2007-04-21 17:47:16 +02:00
|
|
|
|
{
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *it, *res;
|
|
|
|
|
|
|
|
|
|
if (!_PyArg_CheckPositional("next", nargs, 1, 2))
|
|
|
|
|
return NULL;
|
2017-06-15 17:05:23 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
it = args[0];
|
|
|
|
|
if (!PyIter_Check(it)) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
2011-11-07 01:37:52 +01:00
|
|
|
|
"'%.200s' object is not an iterator",
|
2023-08-21 02:54:10 +02:00
|
|
|
|
Py_TYPE(it)->tp_name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
res = (*Py_TYPE(it)->tp_iternext)(it);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (res != NULL) {
|
|
|
|
|
return res;
|
2023-08-21 02:54:10 +02:00
|
|
|
|
} else if (nargs > 1) {
|
|
|
|
|
PyObject *def = args[1];
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if(!PyErr_ExceptionMatches(PyExc_StopIteration))
|
|
|
|
|
return NULL;
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
2023-08-21 02:54:10 +02:00
|
|
|
|
return Py_NewRef(def);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
} else if (PyErr_Occurred()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
PyErr_SetNone(PyExc_StopIteration);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-04-21 17:47:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyDoc_STRVAR(next_doc,
|
|
|
|
|
"next(iterator[, default])\n\
|
|
|
|
|
\n\
|
|
|
|
|
Return the next item from the iterator. If default is given and the iterator\n\
|
|
|
|
|
is exhausted, it is returned instead of raising StopIteration.");
|
|
|
|
|
|
2007-04-21 17:47:16 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
setattr as builtin_setattr
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
|
|
|
|
name: object
|
|
|
|
|
value: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Sets the named attribute on the given object to the specified value.
|
|
|
|
|
|
2022-10-03 21:09:03 +02:00
|
|
|
|
setattr(x, 'y', v) is equivalent to ``x.y = v``
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
|
2015-04-15 00:07:59 +02:00
|
|
|
|
PyObject *value)
|
2022-10-03 21:09:03 +02:00
|
|
|
|
/*[clinic end generated code: output=dc2ce1d1add9acb4 input=5e26417f2e8598d4]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
if (PyObject_SetAttr(obj, name, value) != 0)
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2017-01-23 08:47:21 +01:00
|
|
|
|
Py_RETURN_NONE;
|
1992-01-27 17:53:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
delattr as builtin_delattr
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
|
|
|
|
name: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Deletes the named attribute from the given object.
|
|
|
|
|
|
2022-10-03 21:09:03 +02:00
|
|
|
|
delattr(x, 'y') is equivalent to ``del x.y``
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name)
|
2022-10-03 21:09:03 +02:00
|
|
|
|
/*[clinic end generated code: output=85134bc58dff79fa input=164865623abe7216]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
2023-07-11 11:38:22 +02:00
|
|
|
|
if (PyObject_DelAttr(obj, name) < 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2023-07-11 11:38:22 +02:00
|
|
|
|
}
|
2017-01-23 08:47:21 +01:00
|
|
|
|
Py_RETURN_NONE;
|
1994-08-29 14:53:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
hash as builtin_hash
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the hash value for the given object.
|
|
|
|
|
|
|
|
|
|
Two objects that compare equal must also have the same hash value, but the
|
|
|
|
|
reverse is not necessarily true.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_hash(PyObject *module, PyObject *obj)
|
|
|
|
|
/*[clinic end generated code: output=237668e9d7688db7 input=58c48be822bf9c54]*/
|
1993-03-29 12:43:31 +02:00
|
|
|
|
{
|
2010-10-17 22:54:53 +02:00
|
|
|
|
Py_hash_t x;
|
1995-01-02 20:04:15 +01:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
x = PyObject_Hash(obj);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (x == -1)
|
|
|
|
|
return NULL;
|
2010-10-17 22:54:53 +02:00
|
|
|
|
return PyLong_FromSsize_t(x);
|
1993-03-29 12:43:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
hex as builtin_hex
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
number: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the hexadecimal representation of an integer.
|
|
|
|
|
|
|
|
|
|
>>> hex(12648430)
|
|
|
|
|
'0xc0ffee'
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_hex(PyObject *module, PyObject *number)
|
|
|
|
|
/*[clinic end generated code: output=e46b612169099408 input=e645aff5fc7d540e]*/
|
1991-10-24 15:54:44 +01:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyNumber_ToBase(number, 16);
|
1991-10-24 15:54:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
|
2001-04-20 21:13:02 +02:00
|
|
|
|
static PyObject *
|
2023-08-21 02:54:10 +02:00
|
|
|
|
builtin_iter(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
2001-04-20 21:13:02 +02:00
|
|
|
|
{
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *v;
|
|
|
|
|
|
|
|
|
|
if (!_PyArg_CheckPositional("iter", nargs, 1, 2))
|
|
|
|
|
return NULL;
|
|
|
|
|
v = args[0];
|
|
|
|
|
if (nargs == 1)
|
|
|
|
|
return PyObject_GetIter(v);
|
|
|
|
|
if (!PyCallable_Check(v)) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2023-08-21 02:54:10 +02:00
|
|
|
|
"iter(v, w): v must be callable");
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *sentinel = args[1];
|
|
|
|
|
return PyCallIter_New(v, sentinel);
|
2001-04-20 21:13:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyDoc_STRVAR(iter_doc,
|
|
|
|
|
"iter(iterable) -> iterator\n\
|
|
|
|
|
iter(callable, sentinel) -> iterator\n\
|
|
|
|
|
\n\
|
|
|
|
|
Get an iterator from an object. In the first form, the argument must\n\
|
|
|
|
|
supply its own iterator, or be a sequence.\n\
|
|
|
|
|
In the second form, the callable is called until it returns the sentinel.");
|
|
|
|
|
|
2001-04-20 21:13:02 +02:00
|
|
|
|
|
2021-03-23 23:47:21 +01:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
aiter as builtin_aiter
|
|
|
|
|
|
|
|
|
|
async_iterable: object
|
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return an AsyncIterator for an AsyncIterable object.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
builtin_aiter(PyObject *module, PyObject *async_iterable)
|
|
|
|
|
/*[clinic end generated code: output=1bae108d86f7960e input=473993d0cacc7d23]*/
|
|
|
|
|
{
|
2021-09-07 12:52:30 +02:00
|
|
|
|
return PyObject_GetAIter(async_iterable);
|
2021-03-23 23:47:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *PyAnextAwaitable_New(PyObject *, PyObject *);
|
|
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
|
anext as builtin_anext
|
|
|
|
|
|
|
|
|
|
aiterator: object
|
|
|
|
|
default: object = NULL
|
|
|
|
|
/
|
|
|
|
|
|
2024-04-12 12:56:41 +02:00
|
|
|
|
Return the next item from the async iterator.
|
2021-06-22 23:00:51 +02:00
|
|
|
|
|
2024-04-12 12:56:41 +02:00
|
|
|
|
If default is given and the async iterator is exhausted,
|
|
|
|
|
it is returned instead of raising StopAsyncIteration.
|
2021-03-23 23:47:21 +01:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
builtin_anext_impl(PyObject *module, PyObject *aiterator,
|
|
|
|
|
PyObject *default_value)
|
2024-04-12 12:56:41 +02:00
|
|
|
|
/*[clinic end generated code: output=f02c060c163a81fa input=2900e4a370d39550]*/
|
2021-03-23 23:47:21 +01:00
|
|
|
|
{
|
|
|
|
|
PyTypeObject *t;
|
|
|
|
|
PyObject *awaitable;
|
|
|
|
|
|
|
|
|
|
t = Py_TYPE(aiterator);
|
|
|
|
|
if (t->tp_as_async == NULL || t->tp_as_async->am_anext == NULL) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"'%.200s' object is not an async iterator",
|
|
|
|
|
t->tp_name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
awaitable = (*t->tp_as_async->am_anext)(aiterator);
|
|
|
|
|
if (default_value == NULL) {
|
|
|
|
|
return awaitable;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 02:42:13 +01:00
|
|
|
|
PyObject* new_awaitable = PyAnextAwaitable_New(
|
|
|
|
|
awaitable, default_value);
|
|
|
|
|
Py_DECREF(awaitable);
|
|
|
|
|
return new_awaitable;
|
2021-03-23 23:47:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
len as builtin_len
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the number of items in a container.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_len(PyObject *module, PyObject *obj)
|
|
|
|
|
/*[clinic end generated code: output=fa7a270d314dfb6c input=bc55598da9e9c9b5]*/
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_ssize_t res;
|
1995-01-02 20:04:15 +01:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
res = PyObject_Size(obj);
|
2017-04-16 08:21:44 +02:00
|
|
|
|
if (res < 0) {
|
|
|
|
|
assert(PyErr_Occurred());
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2017-04-16 08:21:44 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyLong_FromSsize_t(res);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
locals as builtin_locals
|
|
|
|
|
|
|
|
|
|
Return a dictionary containing the current scope's local variables.
|
|
|
|
|
|
|
|
|
|
NOTE: Whether or not updates to this dictionary will affect name lookups in
|
|
|
|
|
the local scope and vice-versa is *implementation dependent* and not
|
|
|
|
|
covered by any backwards compatibility guarantees.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_locals_impl(PyObject *module)
|
|
|
|
|
/*[clinic end generated code: output=b46c94015ce11448 input=7874018d478d5c4b]*/
|
1995-07-08 00:43:42 +02:00
|
|
|
|
{
|
2023-07-06 01:05:02 +02:00
|
|
|
|
return _PyEval_GetFrameLocals();
|
1995-07-08 00:43:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-12-11 20:27:06 +01:00
|
|
|
|
min_max(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames, int op)
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2023-12-11 20:27:06 +01:00
|
|
|
|
PyObject *it = NULL, *item, *val, *maxitem, *maxval, *keyfunc=NULL;
|
|
|
|
|
PyObject *defaultval = NULL;
|
|
|
|
|
static const char * const keywords[] = {"key", "default", NULL};
|
|
|
|
|
static _PyArg_Parser _parser_min = {"|$OO:min", keywords, 0};
|
|
|
|
|
static _PyArg_Parser _parser_max = {"|$OO:max", keywords, 0};
|
|
|
|
|
const char *name = (op == Py_LT) ? "min" : "max";
|
|
|
|
|
_PyArg_Parser *_parser = (op == Py_LT) ? &_parser_min : &_parser_max;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-12-11 20:27:06 +01:00
|
|
|
|
if (nargs == 0) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "%s expected at least 1 argument, got 0", name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2020-01-10 17:31:43 +01:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2023-12-11 20:27:06 +01:00
|
|
|
|
if (kwnames != NULL && !_PyArg_ParseStackAndKeywords(args + nargs, 0, kwnames, _parser,
|
|
|
|
|
&keyfunc, &defaultval)) {
|
2013-06-25 07:43:02 +02:00
|
|
|
|
return NULL;
|
2023-12-11 20:27:06 +01:00
|
|
|
|
}
|
2013-06-25 07:43:02 +02:00
|
|
|
|
|
2023-12-11 20:27:06 +01:00
|
|
|
|
const int positional = nargs > 1; // False iff nargs == 1
|
2013-06-25 07:43:02 +02:00
|
|
|
|
if (positional && defaultval != NULL) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"Cannot specify a default for %s() with multiple "
|
|
|
|
|
"positional arguments", name);
|
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 20:27:06 +01:00
|
|
|
|
if (!positional) {
|
|
|
|
|
it = PyObject_GetIter(args[0]);
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 05:58:21 +02:00
|
|
|
|
if (keyfunc == Py_None) {
|
|
|
|
|
keyfunc = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
maxitem = NULL; /* the result */
|
|
|
|
|
maxval = NULL; /* the value associated with the result */
|
2023-12-11 20:27:06 +01:00
|
|
|
|
while (1) {
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
if (nargs-- <= 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
item = *args++;
|
|
|
|
|
Py_INCREF(item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
item = PyIter_Next(it);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
goto Fail_it;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* get the value from the key function */
|
|
|
|
|
if (keyfunc != NULL) {
|
2020-02-11 17:46:57 +01:00
|
|
|
|
val = PyObject_CallOneArg(keyfunc, item);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (val == NULL)
|
|
|
|
|
goto Fail_it_item;
|
|
|
|
|
}
|
|
|
|
|
/* no key function; the value is the item */
|
|
|
|
|
else {
|
2022-11-10 11:23:36 +01:00
|
|
|
|
val = Py_NewRef(item);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* maximum value and item are unset; set them */
|
|
|
|
|
if (maxval == NULL) {
|
|
|
|
|
maxitem = item;
|
|
|
|
|
maxval = val;
|
|
|
|
|
}
|
|
|
|
|
/* maximum value and item are set; update them as necessary */
|
|
|
|
|
else {
|
|
|
|
|
int cmp = PyObject_RichCompareBool(val, maxval, op);
|
|
|
|
|
if (cmp < 0)
|
|
|
|
|
goto Fail_it_item_and_val;
|
|
|
|
|
else if (cmp > 0) {
|
|
|
|
|
Py_DECREF(maxval);
|
|
|
|
|
Py_DECREF(maxitem);
|
|
|
|
|
maxval = val;
|
|
|
|
|
maxitem = item;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (maxval == NULL) {
|
|
|
|
|
assert(maxitem == NULL);
|
2013-06-25 07:43:02 +02:00
|
|
|
|
if (defaultval != NULL) {
|
2022-11-10 11:23:36 +01:00
|
|
|
|
maxitem = Py_NewRef(defaultval);
|
2013-06-25 07:43:02 +02:00
|
|
|
|
} else {
|
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
2023-01-08 14:51:20 +01:00
|
|
|
|
"%s() iterable argument is empty", name);
|
2013-06-25 07:43:02 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Py_DECREF(maxval);
|
2023-12-11 20:27:06 +01:00
|
|
|
|
Py_XDECREF(it);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return maxitem;
|
2004-12-03 09:30:39 +01:00
|
|
|
|
|
|
|
|
|
Fail_it_item_and_val:
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(val);
|
2004-12-03 09:30:39 +01:00
|
|
|
|
Fail_it_item:
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(item);
|
2004-12-03 09:30:39 +01:00
|
|
|
|
Fail_it:
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_XDECREF(maxval);
|
|
|
|
|
Py_XDECREF(maxitem);
|
2023-12-11 20:27:06 +01:00
|
|
|
|
Py_XDECREF(it);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/* AC: cannot convert yet, waiting for *args support */
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-12-11 20:27:06 +01:00
|
|
|
|
builtin_min(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2023-12-11 20:27:06 +01:00
|
|
|
|
return min_max(args, nargs, kwnames, Py_LT);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(min_doc,
|
2014-05-19 23:20:52 +02:00
|
|
|
|
"min(iterable, *[, default=obj, key=func]) -> value\n\
|
|
|
|
|
min(arg1, arg2, *args, *[, key=func]) -> value\n\
|
1998-06-26 23:23:49 +02:00
|
|
|
|
\n\
|
2014-05-19 23:20:52 +02:00
|
|
|
|
With a single iterable argument, return its smallest item. The\n\
|
|
|
|
|
default keyword-only argument specifies an object to return if\n\
|
|
|
|
|
the provided iterable is empty.\n\
|
2023-11-13 08:13:49 +01:00
|
|
|
|
With two or more positional arguments, return the smallest argument.");
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/* AC: cannot convert yet, waiting for *args support */
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-12-11 20:27:06 +01:00
|
|
|
|
builtin_max(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2023-12-11 20:27:06 +01:00
|
|
|
|
return min_max(args, nargs, kwnames, Py_GT);
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(max_doc,
|
2014-05-19 23:20:52 +02:00
|
|
|
|
"max(iterable, *[, default=obj, key=func]) -> value\n\
|
|
|
|
|
max(arg1, arg2, *args, *[, key=func]) -> value\n\
|
1998-06-26 23:23:49 +02:00
|
|
|
|
\n\
|
2014-05-19 23:20:52 +02:00
|
|
|
|
With a single iterable argument, return its biggest item. The\n\
|
|
|
|
|
default keyword-only argument specifies an object to return if\n\
|
|
|
|
|
the provided iterable is empty.\n\
|
2023-11-13 08:13:49 +01:00
|
|
|
|
With two or more positional arguments, return the largest argument.");
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
oct as builtin_oct
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
number: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the octal representation of an integer.
|
|
|
|
|
|
|
|
|
|
>>> oct(342391)
|
|
|
|
|
'0o1234567'
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_oct(PyObject *module, PyObject *number)
|
|
|
|
|
/*[clinic end generated code: output=40a34656b6875352 input=ad6b274af4016c72]*/
|
1991-10-24 15:54:44 +01:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyNumber_ToBase(number, 8);
|
1991-10-24 15:54:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
ord as builtin_ord
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
c: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the Unicode code point for a one-character string.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_ord(PyObject *module, PyObject *c)
|
|
|
|
|
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
|
1990-12-20 16:06:42 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
long ord;
|
|
|
|
|
Py_ssize_t size;
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (PyBytes_Check(c)) {
|
|
|
|
|
size = PyBytes_GET_SIZE(c);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (size == 1) {
|
2014-08-17 06:01:19 +02:00
|
|
|
|
ord = (long)((unsigned char)*PyBytes_AS_STRING(c));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyLong_FromLong(ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-17 06:01:19 +02:00
|
|
|
|
else if (PyUnicode_Check(c)) {
|
|
|
|
|
size = PyUnicode_GET_LENGTH(c);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (size == 1) {
|
2014-08-17 06:01:19 +02:00
|
|
|
|
ord = (long)PyUnicode_READ_CHAR(c, 0);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyLong_FromLong(ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-17 06:01:19 +02:00
|
|
|
|
else if (PyByteArray_Check(c)) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* XXX Hopefully this is temporary */
|
2014-08-17 06:01:19 +02:00
|
|
|
|
size = PyByteArray_GET_SIZE(c);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (size == 1) {
|
2014-08-17 06:01:19 +02:00
|
|
|
|
ord = (long)((unsigned char)*PyByteArray_AS_STRING(c));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyLong_FromLong(ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"ord() expected string of length 1, but " \
|
2020-02-07 02:24:48 +01:00
|
|
|
|
"%.200s found", Py_TYPE(c)->tp_name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"ord() expected a character, "
|
|
|
|
|
"but string of length %zd found",
|
|
|
|
|
size);
|
|
|
|
|
return NULL;
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
pow as builtin_pow
|
|
|
|
|
|
2019-09-21 06:28:49 +02:00
|
|
|
|
base: object
|
|
|
|
|
exp: object
|
|
|
|
|
mod: object = None
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
2019-09-21 21:57:44 +02:00
|
|
|
|
Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Some types, such as ints, are able to use a more efficient algorithm when
|
|
|
|
|
invoked using the three argument form.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2019-09-21 06:28:49 +02:00
|
|
|
|
builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp,
|
|
|
|
|
PyObject *mod)
|
2019-09-21 21:57:44 +02:00
|
|
|
|
/*[clinic end generated code: output=3ca1538221bbf15f input=435dbd48a12efb23]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
2019-09-21 06:28:49 +02:00
|
|
|
|
return PyNumber_Power(base, exp, mod);
|
2014-08-17 06:01:19 +02:00
|
|
|
|
}
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2021-07-16 17:43:02 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
print as builtin_print
|
|
|
|
|
|
|
|
|
|
*args: object
|
|
|
|
|
sep: object(c_default="Py_None") = ' '
|
|
|
|
|
string inserted between values, default a space.
|
|
|
|
|
end: object(c_default="Py_None") = '\n'
|
|
|
|
|
string appended after the last value, default a newline.
|
|
|
|
|
file: object = None
|
|
|
|
|
a file-like object (stream); defaults to the current sys.stdout.
|
|
|
|
|
flush: bool = False
|
|
|
|
|
whether to forcibly flush the stream.
|
|
|
|
|
|
|
|
|
|
Prints the values to a stream, or to sys.stdout by default.
|
|
|
|
|
|
|
|
|
|
[clinic start generated code]*/
|
2003-04-11 20:43:06 +02:00
|
|
|
|
|
2006-11-30 23:13:52 +01:00
|
|
|
|
static PyObject *
|
2021-07-16 17:43:02 +02:00
|
|
|
|
builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
|
|
|
|
|
PyObject *end, PyObject *file, int flush)
|
|
|
|
|
/*[clinic end generated code: output=3cfc0940f5bc237b input=c143c575d24fe665]*/
|
2006-11-30 23:13:52 +01:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
int i, err;
|
|
|
|
|
|
2021-07-16 17:43:02 +02:00
|
|
|
|
if (file == Py_None) {
|
2022-02-08 21:39:07 +01:00
|
|
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
|
|
|
file = _PySys_GetAttr(tstate, &_Py_ID(stdout));
|
2013-07-16 22:26:05 +02:00
|
|
|
|
if (file == NULL) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* sys.stdout may be None when FILE* stdout isn't connected */
|
2021-07-16 17:43:02 +02:00
|
|
|
|
if (file == Py_None) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_RETURN_NONE;
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sep == Py_None) {
|
|
|
|
|
sep = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (sep && !PyUnicode_Check(sep)) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"sep must be None or a string, not %.200s",
|
2020-02-07 02:24:48 +01:00
|
|
|
|
Py_TYPE(sep)->tp_name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (end == Py_None) {
|
|
|
|
|
end = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (end && !PyUnicode_Check(end)) {
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"end must be None or a string, not %.200s",
|
2020-02-07 02:24:48 +01:00
|
|
|
|
Py_TYPE(end)->tp_name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 17:43:02 +02:00
|
|
|
|
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (i > 0) {
|
2021-07-16 17:43:02 +02:00
|
|
|
|
if (sep == NULL) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
err = PyFile_WriteString(" ", file);
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
err = PyFile_WriteObject(sep, file, Py_PRINT_RAW);
|
|
|
|
|
}
|
|
|
|
|
if (err) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2021-07-16 17:43:02 +02:00
|
|
|
|
err = PyFile_WriteObject(PyTuple_GET_ITEM(args, i), file, Py_PRINT_RAW);
|
|
|
|
|
if (err) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 17:43:02 +02:00
|
|
|
|
if (end == NULL) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
err = PyFile_WriteString("\n", file);
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
err = PyFile_WriteObject(end, file, Py_PRINT_RAW);
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
|
|
|
|
if (err) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2019-09-01 11:16:51 +02:00
|
|
|
|
if (flush) {
|
2023-09-23 08:35:30 +02:00
|
|
|
|
if (_PyFile_Flush(file) < 0) {
|
2012-01-13 19:41:25 +01:00
|
|
|
|
return NULL;
|
2021-07-16 17:43:02 +02:00
|
|
|
|
}
|
2012-01-13 19:41:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_RETURN_NONE;
|
2006-11-30 23:13:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
input as builtin_input
|
|
|
|
|
|
2023-01-08 08:57:41 +01:00
|
|
|
|
prompt: object(c_default="NULL") = ""
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Read a string from standard input. The trailing newline is stripped.
|
|
|
|
|
|
|
|
|
|
The prompt string, if given, is printed to standard output without a
|
|
|
|
|
trailing newline before reading input.
|
|
|
|
|
|
|
|
|
|
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
|
|
|
|
|
On *nix systems, readline is used if available.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_input_impl(PyObject *module, PyObject *prompt)
|
2023-01-08 08:57:41 +01:00
|
|
|
|
/*[clinic end generated code: output=83db5a191e7a0d60 input=159c46d4ae40977e]*/
|
2007-02-26 17:59:55 +01:00
|
|
|
|
{
|
2022-02-08 21:39:07 +01:00
|
|
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
|
|
|
PyObject *fin = _PySys_GetAttr(
|
|
|
|
|
tstate, &_Py_ID(stdin));
|
|
|
|
|
PyObject *fout = _PySys_GetAttr(
|
|
|
|
|
tstate, &_Py_ID(stdout));
|
|
|
|
|
PyObject *ferr = _PySys_GetAttr(
|
|
|
|
|
tstate, &_Py_ID(stderr));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *tmp;
|
|
|
|
|
long fd;
|
|
|
|
|
int tty;
|
|
|
|
|
|
|
|
|
|
/* Check that stdin/out/err are intact */
|
|
|
|
|
if (fin == NULL || fin == Py_None) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
|
|
|
"input(): lost sys.stdin");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (fout == NULL || fout == Py_None) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
|
|
|
"input(): lost sys.stdout");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (ferr == NULL || ferr == Py_None) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
|
|
|
"input(): lost sys.stderr");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 17:45:22 +02:00
|
|
|
|
if (PySys_Audit("builtins.input", "O", prompt ? prompt : Py_None) < 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* First of all, flush stderr */
|
2023-09-23 08:35:30 +02:00
|
|
|
|
if (_PyFile_Flush(ferr) < 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_Clear();
|
2023-09-23 08:35:30 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
/* We should only use (GNU) readline if Python's sys.stdin and
|
|
|
|
|
sys.stdout are the same as C's stdin and stdout, because we
|
|
|
|
|
need to pass it those. */
|
2022-02-08 21:39:07 +01:00
|
|
|
|
tmp = PyObject_CallMethodNoArgs(fin, &_Py_ID(fileno));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (tmp == NULL) {
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
tty = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fd = PyLong_AsLong(tmp);
|
|
|
|
|
Py_DECREF(tmp);
|
|
|
|
|
if (fd < 0 && PyErr_Occurred())
|
|
|
|
|
return NULL;
|
|
|
|
|
tty = fd == fileno(stdin) && isatty(fd);
|
|
|
|
|
}
|
|
|
|
|
if (tty) {
|
2022-02-08 21:39:07 +01:00
|
|
|
|
tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(fileno));
|
2015-10-10 03:25:38 +02:00
|
|
|
|
if (tmp == NULL) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_Clear();
|
2015-10-10 03:25:38 +02:00
|
|
|
|
tty = 0;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
else {
|
|
|
|
|
fd = PyLong_AsLong(tmp);
|
|
|
|
|
Py_DECREF(tmp);
|
|
|
|
|
if (fd < 0 && PyErr_Occurred())
|
|
|
|
|
return NULL;
|
|
|
|
|
tty = fd == fileno(stdout) && isatty(fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we're interactive, use (GNU) readline */
|
|
|
|
|
if (tty) {
|
2011-11-06 00:34:26 +01:00
|
|
|
|
PyObject *po = NULL;
|
2017-11-11 12:06:26 +01:00
|
|
|
|
const char *promptstr;
|
2011-11-06 00:34:26 +01:00
|
|
|
|
char *s = NULL;
|
|
|
|
|
PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
|
|
|
|
|
PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
|
2016-11-20 09:16:47 +01:00
|
|
|
|
const char *stdin_encoding_str, *stdin_errors_str;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *result;
|
2011-02-23 13:07:37 +01:00
|
|
|
|
size_t len;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2017-03-12 12:50:36 +01:00
|
|
|
|
/* stdin is a text stream, so it must have an encoding. */
|
2022-02-08 21:39:07 +01:00
|
|
|
|
stdin_encoding = PyObject_GetAttr(fin, &_Py_ID(encoding));
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdin_encoding == NULL) {
|
|
|
|
|
tty = 0;
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
2022-02-08 21:39:07 +01:00
|
|
|
|
stdin_errors = PyObject_GetAttr(fin, &_Py_ID(errors));
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdin_errors == NULL) {
|
|
|
|
|
tty = 0;
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
|
|
|
|
if (!PyUnicode_Check(stdin_encoding) ||
|
|
|
|
|
!PyUnicode_Check(stdin_errors))
|
|
|
|
|
{
|
2017-03-12 12:50:36 +01:00
|
|
|
|
tty = 0;
|
2011-11-06 00:34:26 +01:00
|
|
|
|
goto _readline_errors;
|
2017-03-12 12:50:36 +01:00
|
|
|
|
}
|
2016-11-20 08:13:07 +01:00
|
|
|
|
stdin_encoding_str = PyUnicode_AsUTF8(stdin_encoding);
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdin_encoding_str == NULL) {
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
2016-11-20 08:13:07 +01:00
|
|
|
|
stdin_errors_str = PyUnicode_AsUTF8(stdin_errors);
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdin_errors_str == NULL) {
|
2011-11-06 00:34:26 +01:00
|
|
|
|
goto _readline_errors;
|
2023-06-11 12:20:43 +02:00
|
|
|
|
}
|
2023-09-23 08:35:30 +02:00
|
|
|
|
if (_PyFile_Flush(fout) < 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_Clear();
|
2023-09-23 08:35:30 +02:00
|
|
|
|
}
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (prompt != NULL) {
|
2011-11-06 00:34:26 +01:00
|
|
|
|
/* We have a prompt, encode it as stdout would */
|
2016-11-20 09:16:47 +01:00
|
|
|
|
const char *stdout_encoding_str, *stdout_errors_str;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *stringpo;
|
2022-02-08 21:39:07 +01:00
|
|
|
|
stdout_encoding = PyObject_GetAttr(fout, &_Py_ID(encoding));
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdout_encoding == NULL) {
|
|
|
|
|
tty = 0;
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
2022-02-08 21:39:07 +01:00
|
|
|
|
stdout_errors = PyObject_GetAttr(fout, &_Py_ID(errors));
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdout_errors == NULL) {
|
|
|
|
|
tty = 0;
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
|
|
|
|
if (!PyUnicode_Check(stdout_encoding) ||
|
|
|
|
|
!PyUnicode_Check(stdout_errors))
|
|
|
|
|
{
|
2017-03-12 12:50:36 +01:00
|
|
|
|
tty = 0;
|
2011-11-06 00:34:26 +01:00
|
|
|
|
goto _readline_errors;
|
2017-03-12 12:50:36 +01:00
|
|
|
|
}
|
2016-11-20 08:13:07 +01:00
|
|
|
|
stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding);
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdout_encoding_str == NULL) {
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
2016-11-20 08:13:07 +01:00
|
|
|
|
stdout_errors_str = PyUnicode_AsUTF8(stdout_errors);
|
2023-06-11 12:20:43 +02:00
|
|
|
|
if (stdout_errors_str == NULL) {
|
2011-11-06 00:34:26 +01:00
|
|
|
|
goto _readline_errors;
|
2023-06-11 12:20:43 +02:00
|
|
|
|
}
|
2014-08-17 06:01:19 +02:00
|
|
|
|
stringpo = PyObject_Str(prompt);
|
2011-11-06 00:34:26 +01:00
|
|
|
|
if (stringpo == NULL)
|
|
|
|
|
goto _readline_errors;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
po = PyUnicode_AsEncodedString(stringpo,
|
2011-11-06 00:34:26 +01:00
|
|
|
|
stdout_encoding_str, stdout_errors_str);
|
|
|
|
|
Py_CLEAR(stdout_encoding);
|
|
|
|
|
Py_CLEAR(stdout_errors);
|
|
|
|
|
Py_CLEAR(stringpo);
|
|
|
|
|
if (po == NULL)
|
|
|
|
|
goto _readline_errors;
|
2016-04-13 14:37:23 +02:00
|
|
|
|
assert(PyBytes_Check(po));
|
|
|
|
|
promptstr = PyBytes_AS_STRING(po);
|
2023-12-07 11:22:52 +01:00
|
|
|
|
if ((Py_ssize_t)strlen(promptstr) != PyBytes_GET_SIZE(po)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
|
"input: prompt string cannot contain null characters");
|
|
|
|
|
goto _readline_errors;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
po = NULL;
|
2014-08-17 06:01:19 +02:00
|
|
|
|
promptstr = "";
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2014-08-17 06:01:19 +02:00
|
|
|
|
s = PyOS_Readline(stdin, stdout, promptstr);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (s == NULL) {
|
2013-04-03 14:44:50 +02:00
|
|
|
|
PyErr_CheckSignals();
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (!PyErr_Occurred())
|
|
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
2011-11-06 00:34:26 +01:00
|
|
|
|
goto _readline_errors;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2011-02-23 13:07:37 +01:00
|
|
|
|
|
|
|
|
|
len = strlen(s);
|
|
|
|
|
if (len == 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_SetNone(PyExc_EOFError);
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
2011-02-23 13:07:37 +01:00
|
|
|
|
else {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (len > PY_SSIZE_T_MAX) {
|
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
|
"input: input too long");
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-02-23 13:07:37 +01:00
|
|
|
|
len--; /* strip trailing '\n' */
|
|
|
|
|
if (len != 0 && s[len-1] == '\r')
|
|
|
|
|
len--; /* strip trailing '\r' */
|
2011-11-06 00:34:26 +01:00
|
|
|
|
result = PyUnicode_Decode(s, len, stdin_encoding_str,
|
|
|
|
|
stdin_errors_str);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(stdin_encoding);
|
2011-11-06 00:34:26 +01:00
|
|
|
|
Py_DECREF(stdin_errors);
|
|
|
|
|
Py_XDECREF(po);
|
2020-12-01 09:56:42 +01:00
|
|
|
|
PyMem_Free(s);
|
2019-05-23 17:45:22 +02:00
|
|
|
|
|
|
|
|
|
if (result != NULL) {
|
|
|
|
|
if (PySys_Audit("builtins.input/result", "O", result) < 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return result;
|
2017-03-12 12:50:36 +01:00
|
|
|
|
|
2011-11-06 00:34:26 +01:00
|
|
|
|
_readline_errors:
|
|
|
|
|
Py_XDECREF(stdin_encoding);
|
|
|
|
|
Py_XDECREF(stdout_encoding);
|
|
|
|
|
Py_XDECREF(stdin_errors);
|
|
|
|
|
Py_XDECREF(stdout_errors);
|
|
|
|
|
Py_XDECREF(po);
|
2017-03-12 12:50:36 +01:00
|
|
|
|
if (tty)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
PyErr_Clear();
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fallback if we're not interactive */
|
2014-08-17 06:01:19 +02:00
|
|
|
|
if (prompt != NULL) {
|
|
|
|
|
if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0)
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-09-23 08:35:30 +02:00
|
|
|
|
if (_PyFile_Flush(fout) < 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_Clear();
|
2023-09-23 08:35:30 +02:00
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return PyFile_GetLine(fin, -1);
|
2007-02-26 17:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
repr as builtin_repr
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return the canonical string representation of the object.
|
|
|
|
|
|
|
|
|
|
For many object types, including most builtins, eval(repr(obj)) == obj.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_repr(PyObject *module, PyObject *obj)
|
|
|
|
|
/*[clinic end generated code: output=7ed3778c44fd0194 input=1c9e6d66d3e3be04]*/
|
1992-11-26 09:54:07 +01:00
|
|
|
|
{
|
2014-08-17 06:01:19 +02:00
|
|
|
|
return PyObject_Repr(obj);
|
1992-11-26 09:54:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2017-11-15 16:51:14 +01:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
round as builtin_round
|
|
|
|
|
|
|
|
|
|
number: object
|
2019-09-14 11:24:05 +02:00
|
|
|
|
ndigits: object = None
|
2017-11-15 16:51:14 +01:00
|
|
|
|
|
|
|
|
|
Round a number to a given precision in decimal digits.
|
|
|
|
|
|
|
|
|
|
The return value is an integer if ndigits is omitted or None. Otherwise
|
|
|
|
|
the return value has the same type as the number. ndigits may be negative.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2017-11-15 16:51:14 +01:00
|
|
|
|
builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits)
|
2019-09-14 11:24:05 +02:00
|
|
|
|
/*[clinic end generated code: output=ff0d9dd176c02ede input=275678471d7aca15]*/
|
1993-02-12 17:29:05 +01:00
|
|
|
|
{
|
2017-11-15 16:51:14 +01:00
|
|
|
|
PyObject *round, *result;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2022-02-08 21:39:07 +01:00
|
|
|
|
round = _PyObject_LookupSpecial(number, &_Py_ID(__round__));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (round == NULL) {
|
2013-04-13 23:19:01 +02:00
|
|
|
|
if (!PyErr_Occurred())
|
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
|
"type %.100s doesn't define __round__ method",
|
|
|
|
|
Py_TYPE(number)->tp_name);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 11:24:05 +02:00
|
|
|
|
if (ndigits == Py_None)
|
2021-10-12 00:42:23 +02:00
|
|
|
|
result = _PyObject_CallNoArgs(round);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
else
|
2020-02-11 17:46:57 +01:00
|
|
|
|
result = PyObject_CallOneArg(round, ndigits);
|
2013-04-13 23:19:01 +02:00
|
|
|
|
Py_DECREF(round);
|
|
|
|
|
return result;
|
1993-02-12 17:29:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*AC: we need to keep the kwds dict intact to easily call into the
|
|
|
|
|
* list.sort method, which isn't currently supported in AC. So we just use
|
|
|
|
|
* the initially generated signature with a custom implementation.
|
|
|
|
|
*/
|
|
|
|
|
/* [disabled clinic input]
|
|
|
|
|
sorted as builtin_sorted
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
iterable as seq: object
|
|
|
|
|
key as keyfunc: object = None
|
|
|
|
|
reverse: object = False
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Return a new list containing all items from the iterable in ascending order.
|
|
|
|
|
|
2016-08-26 06:11:50 +02:00
|
|
|
|
A custom key function can be supplied to customize the sort order, and the
|
2014-08-17 06:01:19 +02:00
|
|
|
|
reverse flag can be set to request the result in descending order.
|
|
|
|
|
[end disabled clinic input]*/
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(builtin_sorted__doc__,
|
2017-01-23 11:29:47 +01:00
|
|
|
|
"sorted($module, iterable, /, *, key=None, reverse=False)\n"
|
2014-08-17 06:01:19 +02:00
|
|
|
|
"--\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Return a new list containing all items from the iterable in ascending order.\n"
|
|
|
|
|
"\n"
|
2016-08-26 06:11:50 +02:00
|
|
|
|
"A custom key function can be supplied to customize the sort order, and the\n"
|
2014-08-17 06:01:19 +02:00
|
|
|
|
"reverse flag can be set to request the result in descending order.");
|
|
|
|
|
|
|
|
|
|
#define BUILTIN_SORTED_METHODDEF \
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"sorted", _PyCFunction_CAST(builtin_sorted), METH_FASTCALL | METH_KEYWORDS, builtin_sorted__doc__},
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
2003-12-17 21:43:33 +01:00
|
|
|
|
static PyObject *
|
2017-12-15 12:11:11 +01:00
|
|
|
|
builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2003-12-17 21:43:33 +01:00
|
|
|
|
{
|
2017-01-21 22:05:00 +01:00
|
|
|
|
PyObject *newlist, *v, *seq, *callable;
|
|
|
|
|
|
|
|
|
|
/* Keyword arguments are passed through list.sort() which will check
|
|
|
|
|
them. */
|
|
|
|
|
if (!_PyArg_UnpackStack(args, nargs, "sorted", 1, 1, &seq))
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
newlist = PySequence_List(seq);
|
|
|
|
|
if (newlist == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2022-02-08 21:39:07 +01:00
|
|
|
|
callable = PyObject_GetAttr(newlist, &_Py_ID(sort));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (callable == NULL) {
|
|
|
|
|
Py_DECREF(newlist);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-20 07:35:18 +01:00
|
|
|
|
assert(nargs >= 1);
|
2020-02-11 17:46:57 +01:00
|
|
|
|
v = PyObject_Vectorcall(callable, args + 1, nargs - 1, kwnames);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(callable);
|
|
|
|
|
if (v == NULL) {
|
|
|
|
|
Py_DECREF(newlist);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(v);
|
|
|
|
|
return newlist;
|
2003-12-17 21:43:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyObject *
|
2023-08-21 02:54:10 +02:00
|
|
|
|
builtin_vars(PyObject *self, PyObject *args)
|
1994-08-29 14:52:16 +02:00
|
|
|
|
{
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyObject *v = NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *d;
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (v == NULL) {
|
2023-07-06 01:05:02 +02:00
|
|
|
|
d = _PyEval_GetFrameLocals();
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-21 02:54:10 +02:00
|
|
|
|
if (PyObject_GetOptionalAttr(v, &_Py_ID(__dict__), &d) == 0) {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"vars() argument must have __dict__ attribute");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return d;
|
1994-08-29 14:52:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 02:54:10 +02:00
|
|
|
|
PyDoc_STRVAR(vars_doc,
|
|
|
|
|
"vars([object]) -> dictionary\n\
|
|
|
|
|
\n\
|
|
|
|
|
Without arguments, equivalent to locals().\n\
|
|
|
|
|
With an argument, equivalent to object.__dict__.");
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
2024-07-05 17:01:05 +02:00
|
|
|
|
/* Improved Kahan–Babuška algorithm by Arnold Neumaier
|
|
|
|
|
Neumaier, A. (1974), Rundungsfehleranalyse einiger Verfahren
|
|
|
|
|
zur Summation endlicher Summen. Z. angew. Math. Mech.,
|
|
|
|
|
54: 39-51. https://doi.org/10.1002/zamm.19740540106
|
|
|
|
|
https://en.wikipedia.org/wiki/Kahan_summation_algorithm#Further_enhancements
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
double hi; /* high-order bits for a running sum */
|
|
|
|
|
double lo; /* a running compensation for lost low-order bits */
|
|
|
|
|
} CompensatedSum;
|
|
|
|
|
|
|
|
|
|
static inline CompensatedSum
|
|
|
|
|
cs_from_double(double x)
|
|
|
|
|
{
|
|
|
|
|
return (CompensatedSum) {x};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline CompensatedSum
|
|
|
|
|
cs_add(CompensatedSum total, double x)
|
|
|
|
|
{
|
|
|
|
|
double t = total.hi + x;
|
|
|
|
|
if (fabs(total.hi) >= fabs(x)) {
|
|
|
|
|
total.lo += (total.hi - t) + x;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
total.lo += (x - t) + total.hi;
|
|
|
|
|
}
|
|
|
|
|
return (CompensatedSum) {t, total.lo};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline double
|
|
|
|
|
cs_to_double(CompensatedSum total)
|
|
|
|
|
{
|
|
|
|
|
/* Avoid losing the sign on a negative result,
|
|
|
|
|
and don't let adding the compensation convert
|
|
|
|
|
an infinite or overflowed sum to a NaN. */
|
|
|
|
|
if (total.lo && isfinite(total.lo)) {
|
|
|
|
|
return total.hi + total.lo;
|
|
|
|
|
}
|
|
|
|
|
return total.hi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
sum as builtin_sum
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
iterable: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
2018-09-12 19:54:06 +02:00
|
|
|
|
start: object(c_default="NULL") = 0
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
|
|
|
|
|
|
|
|
|
|
When the iterable is empty, return the start value.
|
|
|
|
|
This function is intended specifically for use with numeric values and may
|
|
|
|
|
reject non-numeric types.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
|
2018-09-12 19:54:06 +02:00
|
|
|
|
/*[clinic end generated code: output=df758cec7d1d302f input=162b50765250d222]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *result = start;
|
|
|
|
|
PyObject *temp, *item, *iter;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
iter = PyObject_GetIter(iterable);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (iter == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
result = PyLong_FromLong(0);
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* reject string values for 'start' parameter */
|
|
|
|
|
if (PyUnicode_Check(result)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"sum() can't sum strings [use ''.join(seq) instead]");
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-07-29 21:23:47 +02:00
|
|
|
|
if (PyBytes_Check(result)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
|
"sum() can't sum bytes [use b''.join(seq) instead]");
|
2011-07-30 05:43:45 +02:00
|
|
|
|
Py_DECREF(iter);
|
2011-07-29 21:23:47 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (PyByteArray_Check(result)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2011-07-29 21:24:29 +02:00
|
|
|
|
"sum() can't sum bytearray [use b''.join(seq) instead]");
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
Py_INCREF(result);
|
|
|
|
|
}
|
2003-04-22 10:12:33 +02:00
|
|
|
|
|
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 20:42:39 +01:00
|
|
|
|
#ifndef SLOW_SUM
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* Fast addition by keeping temporary sums in C instead of new Python objects.
|
|
|
|
|
Assumes all inputs are the same type. If the assumption fails, default
|
|
|
|
|
to the more general routine.
|
|
|
|
|
*/
|
|
|
|
|
if (PyLong_CheckExact(result)) {
|
|
|
|
|
int overflow;
|
2023-03-22 15:49:51 +01:00
|
|
|
|
Py_ssize_t i_result = PyLong_AsLongAndOverflow(result, &overflow);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* If this already overflowed, don't even enter the loop. */
|
|
|
|
|
if (overflow == 0) {
|
2022-11-23 14:57:50 +01:00
|
|
|
|
Py_SETREF(result, NULL);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
while(result == NULL) {
|
|
|
|
|
item = PyIter_Next(iter);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
if (PyErr_Occurred())
|
|
|
|
|
return NULL;
|
2023-03-23 11:37:04 +01:00
|
|
|
|
return PyLong_FromSsize_t(i_result);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2019-09-10 15:31:01 +02:00
|
|
|
|
if (PyLong_CheckExact(item) || PyBool_Check(item)) {
|
2023-03-22 15:49:51 +01:00
|
|
|
|
Py_ssize_t b;
|
2021-09-21 11:01:18 +02:00
|
|
|
|
overflow = 0;
|
|
|
|
|
/* Single digits are common, fast, and cannot overflow on unpacking. */
|
2023-03-22 15:49:51 +01:00
|
|
|
|
if (_PyLong_IsCompact((PyLongObject *)item)) {
|
|
|
|
|
b = _PyLong_CompactValue((PyLongObject *)item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
b = PyLong_AsLongAndOverflow(item, &overflow);
|
2021-09-21 11:01:18 +02:00
|
|
|
|
}
|
2019-05-05 13:26:23 +02:00
|
|
|
|
if (overflow == 0 &&
|
2024-07-13 12:40:44 +02:00
|
|
|
|
(i_result >= 0 ? (b <= PY_SSIZE_T_MAX - i_result)
|
|
|
|
|
: (b >= PY_SSIZE_T_MIN - i_result)))
|
2019-05-05 13:26:23 +02:00
|
|
|
|
{
|
|
|
|
|
i_result += b;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Either overflowed or is not an int. Restore real objects and process normally */
|
2023-03-23 11:37:04 +01:00
|
|
|
|
result = PyLong_FromSsize_t(i_result);
|
2013-07-26 22:49:26 +02:00
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
temp = PyNumber_Add(result, item);
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
result = temp;
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyFloat_CheckExact(result)) {
|
2024-07-05 17:01:05 +02:00
|
|
|
|
CompensatedSum re_sum = cs_from_double(PyFloat_AS_DOUBLE(result));
|
2022-11-23 14:57:50 +01:00
|
|
|
|
Py_SETREF(result, NULL);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
while(result == NULL) {
|
|
|
|
|
item = PyIter_Next(iter);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
if (PyErr_Occurred())
|
|
|
|
|
return NULL;
|
2024-07-05 17:01:05 +02:00
|
|
|
|
return PyFloat_FromDouble(cs_to_double(re_sum));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (PyFloat_CheckExact(item)) {
|
2024-07-05 17:01:05 +02:00
|
|
|
|
re_sum = cs_add(re_sum, PyFloat_AS_DOUBLE(item));
|
2022-04-19 20:02:19 +02:00
|
|
|
|
_Py_DECREF_SPECIALIZED(item, _PyFloat_ExactDealloc);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-09-10 15:31:01 +02:00
|
|
|
|
if (PyLong_Check(item)) {
|
2024-07-29 05:56:40 +02:00
|
|
|
|
double value = PyLong_AsDouble(item);
|
|
|
|
|
if (value != -1.0 || !PyErr_Occurred()) {
|
|
|
|
|
re_sum = cs_add(re_sum, value);
|
2024-07-05 17:01:05 +02:00
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-29 05:56:40 +02:00
|
|
|
|
else {
|
2024-07-29 18:10:25 +02:00
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(iter);
|
2024-07-29 05:56:40 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-07-05 17:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
result = PyFloat_FromDouble(cs_to_double(re_sum));
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
temp = PyNumber_Add(result, item);
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
result = temp;
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyComplex_CheckExact(result)) {
|
|
|
|
|
Py_complex z = PyComplex_AsCComplex(result);
|
|
|
|
|
CompensatedSum re_sum = cs_from_double(z.real);
|
|
|
|
|
CompensatedSum im_sum = cs_from_double(z.imag);
|
|
|
|
|
Py_SETREF(result, NULL);
|
|
|
|
|
while (result == NULL) {
|
|
|
|
|
item = PyIter_Next(iter);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return PyComplex_FromDoubles(cs_to_double(re_sum),
|
|
|
|
|
cs_to_double(im_sum));
|
|
|
|
|
}
|
|
|
|
|
if (PyComplex_CheckExact(item)) {
|
|
|
|
|
z = PyComplex_AsCComplex(item);
|
|
|
|
|
re_sum = cs_add(re_sum, z.real);
|
|
|
|
|
im_sum = cs_add(im_sum, z.imag);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (PyLong_Check(item)) {
|
2024-07-29 05:56:40 +02:00
|
|
|
|
double value = PyLong_AsDouble(item);
|
|
|
|
|
if (value != -1.0 || !PyErr_Occurred()) {
|
|
|
|
|
re_sum = cs_add(re_sum, value);
|
2024-07-05 17:01:05 +02:00
|
|
|
|
im_sum.hi += 0.0;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-29 05:56:40 +02:00
|
|
|
|
else {
|
2024-07-29 18:10:25 +02:00
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(iter);
|
2024-07-29 05:56:40 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
2024-07-05 17:01:05 +02:00
|
|
|
|
if (PyFloat_Check(item)) {
|
|
|
|
|
double value = PyFloat_AS_DOUBLE(item);
|
2024-07-29 05:56:40 +02:00
|
|
|
|
re_sum = cs_add(re_sum, value);
|
2024-07-05 17:01:05 +02:00
|
|
|
|
im_sum.hi += 0.0;
|
|
|
|
|
_Py_DECREF_SPECIALIZED(item, _PyFloat_ExactDealloc);
|
|
|
|
|
continue;
|
2022-12-23 23:35:58 +01:00
|
|
|
|
}
|
2024-07-05 17:01:05 +02:00
|
|
|
|
result = PyComplex_FromDoubles(cs_to_double(re_sum),
|
|
|
|
|
cs_to_double(im_sum));
|
2018-08-24 06:27:52 +02:00
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
temp = PyNumber_Add(result, item);
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
result = temp;
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 20:42:39 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
|
for(;;) {
|
|
|
|
|
item = PyIter_Next(iter);
|
|
|
|
|
if (item == NULL) {
|
|
|
|
|
/* error, or end-of-sequence */
|
|
|
|
|
if (PyErr_Occurred()) {
|
2022-11-23 14:57:50 +01:00
|
|
|
|
Py_SETREF(result, NULL);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* It's tempting to use PyNumber_InPlaceAdd instead of
|
|
|
|
|
PyNumber_Add here, to avoid quadratic running time
|
|
|
|
|
when doing 'sum(list_of_lists, [])'. However, this
|
|
|
|
|
would produce a change in behaviour: a snippet like
|
|
|
|
|
|
|
|
|
|
empty = []
|
|
|
|
|
sum([[x] for x in range(10)], empty)
|
|
|
|
|
|
2020-02-01 12:08:34 +01:00
|
|
|
|
would change the value of empty. In fact, using
|
|
|
|
|
in-place addition rather that binary addition for
|
|
|
|
|
any of the steps introduces subtle behavior changes:
|
2020-02-05 18:24:33 +01:00
|
|
|
|
|
2020-02-01 12:08:34 +01:00
|
|
|
|
https://bugs.python.org/issue18305 */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
temp = PyNumber_Add(result, item);
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
result = temp;
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Py_DECREF(iter);
|
|
|
|
|
return result;
|
2003-04-22 10:12:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
isinstance as builtin_isinstance
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
obj: object
|
|
|
|
|
class_or_tuple: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
|
|
|
|
Return whether an object is an instance of a class or of a subclass thereof.
|
|
|
|
|
|
|
|
|
|
A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
|
|
|
|
|
check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
|
|
|
|
|
or ...`` etc.
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_isinstance_impl(PyObject *module, PyObject *obj,
|
2015-04-15 00:07:59 +02:00
|
|
|
|
PyObject *class_or_tuple)
|
2016-07-07 16:35:15 +02:00
|
|
|
|
/*[clinic end generated code: output=6faf01472c13b003 input=ffa743db1daf7549]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
int retval;
|
1999-06-16 19:28:37 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
retval = PyObject_IsInstance(obj, class_or_tuple);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (retval < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
return PyBool_FromLong(retval);
|
1997-08-22 23:14:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/*[clinic input]
|
|
|
|
|
issubclass as builtin_issubclass
|
|
|
|
|
|
2015-05-30 10:09:35 +02:00
|
|
|
|
cls: object
|
|
|
|
|
class_or_tuple: object
|
2014-08-17 06:01:19 +02:00
|
|
|
|
/
|
|
|
|
|
|
2020-06-03 15:19:45 +02:00
|
|
|
|
Return whether 'cls' is derived from another class or is the same class.
|
2014-08-17 06:01:19 +02:00
|
|
|
|
|
|
|
|
|
A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to
|
|
|
|
|
check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)
|
2020-06-03 15:19:45 +02:00
|
|
|
|
or ...``.
|
2014-08-17 06:01:19 +02:00
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 16:35:15 +02:00
|
|
|
|
builtin_issubclass_impl(PyObject *module, PyObject *cls,
|
2015-04-15 00:07:59 +02:00
|
|
|
|
PyObject *class_or_tuple)
|
2020-06-03 15:19:45 +02:00
|
|
|
|
/*[clinic end generated code: output=358412410cd7a250 input=a24b9f3d58c370d6]*/
|
2014-08-17 06:01:19 +02:00
|
|
|
|
{
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
retval = PyObject_IsSubclass(cls, class_or_tuple);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (retval < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
return PyBool_FromLong(retval);
|
1997-08-22 23:14:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-13 03:09:15 +01:00
|
|
|
|
typedef struct {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_HEAD
|
2020-06-19 12:16:57 +02:00
|
|
|
|
Py_ssize_t tuplesize;
|
|
|
|
|
PyObject *ittuple; /* tuple of iterators */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *result;
|
2020-06-19 12:16:57 +02:00
|
|
|
|
int strict;
|
2008-03-13 03:09:15 +01:00
|
|
|
|
} zipobject;
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
2000-08-03 17:45:29 +02:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
zipobject *lz;
|
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
PyObject *ittuple; /* tuple of iterators */
|
|
|
|
|
PyObject *result;
|
2017-04-19 19:03:52 +02:00
|
|
|
|
Py_ssize_t tuplesize;
|
2020-06-19 12:16:57 +02:00
|
|
|
|
int strict = 0;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
2020-06-19 12:16:57 +02:00
|
|
|
|
if (kwds) {
|
|
|
|
|
PyObject *empty = PyTuple_New(0);
|
|
|
|
|
if (empty == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
static char *kwlist[] = {"strict", NULL};
|
|
|
|
|
int parsed = PyArg_ParseTupleAndKeywords(
|
|
|
|
|
empty, kwds, "|$p:zip", kwlist, &strict);
|
|
|
|
|
Py_DECREF(empty);
|
|
|
|
|
if (!parsed) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
/* args must be a tuple */
|
|
|
|
|
assert(PyTuple_Check(args));
|
2017-04-19 19:03:52 +02:00
|
|
|
|
tuplesize = PyTuple_GET_SIZE(args);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
/* obtain iterators */
|
|
|
|
|
ittuple = PyTuple_New(tuplesize);
|
|
|
|
|
if (ittuple == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
for (i=0; i < tuplesize; ++i) {
|
|
|
|
|
PyObject *item = PyTuple_GET_ITEM(args, i);
|
|
|
|
|
PyObject *it = PyObject_GetIter(item);
|
|
|
|
|
if (it == NULL) {
|
|
|
|
|
Py_DECREF(ittuple);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyTuple_SET_ITEM(ittuple, i, it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create a result holder */
|
|
|
|
|
result = PyTuple_New(tuplesize);
|
|
|
|
|
if (result == NULL) {
|
|
|
|
|
Py_DECREF(ittuple);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
for (i=0 ; i < tuplesize ; i++) {
|
2022-11-10 11:23:36 +01:00
|
|
|
|
PyTuple_SET_ITEM(result, i, Py_NewRef(Py_None));
|
2010-05-09 17:52:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create zipobject structure */
|
|
|
|
|
lz = (zipobject *)type->tp_alloc(type, 0);
|
|
|
|
|
if (lz == NULL) {
|
|
|
|
|
Py_DECREF(ittuple);
|
|
|
|
|
Py_DECREF(result);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
lz->ittuple = ittuple;
|
|
|
|
|
lz->tuplesize = tuplesize;
|
|
|
|
|
lz->result = result;
|
2020-06-19 12:16:57 +02:00
|
|
|
|
lz->strict = strict;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
return (PyObject *)lz;
|
2008-03-13 03:09:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
zip_dealloc(zipobject *lz)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject_GC_UnTrack(lz);
|
|
|
|
|
Py_XDECREF(lz->ittuple);
|
|
|
|
|
Py_XDECREF(lz->result);
|
|
|
|
|
Py_TYPE(lz)->tp_free(lz);
|
2008-03-13 03:09:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
zip_traverse(zipobject *lz, visitproc visit, void *arg)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_VISIT(lz->ittuple);
|
|
|
|
|
Py_VISIT(lz->result);
|
|
|
|
|
return 0;
|
2000-08-03 17:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-13 03:09:15 +01:00
|
|
|
|
static PyObject *
|
|
|
|
|
zip_next(zipobject *lz)
|
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
Py_ssize_t i;
|
|
|
|
|
Py_ssize_t tuplesize = lz->tuplesize;
|
|
|
|
|
PyObject *result = lz->result;
|
|
|
|
|
PyObject *it;
|
|
|
|
|
PyObject *item;
|
|
|
|
|
PyObject *olditem;
|
|
|
|
|
|
|
|
|
|
if (tuplesize == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (Py_REFCNT(result) == 1) {
|
|
|
|
|
Py_INCREF(result);
|
|
|
|
|
for (i=0 ; i < tuplesize ; i++) {
|
|
|
|
|
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
|
|
|
|
item = (*Py_TYPE(it)->tp_iternext)(it);
|
2013-04-06 21:52:34 +02:00
|
|
|
|
if (item == NULL) {
|
|
|
|
|
Py_DECREF(result);
|
2020-06-19 12:16:57 +02:00
|
|
|
|
if (lz->strict) {
|
|
|
|
|
goto check;
|
|
|
|
|
}
|
2013-04-06 21:52:34 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
olditem = PyTuple_GET_ITEM(result, i);
|
|
|
|
|
PyTuple_SET_ITEM(result, i, item);
|
|
|
|
|
Py_DECREF(olditem);
|
|
|
|
|
}
|
2020-12-05 04:45:57 +01:00
|
|
|
|
// bpo-42536: The GC may have untracked this result tuple. Since we're
|
|
|
|
|
// recycling it, make sure it's tracked again:
|
|
|
|
|
if (!_PyObject_GC_IS_TRACKED(result)) {
|
|
|
|
|
_PyObject_GC_TRACK(result);
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
} else {
|
|
|
|
|
result = PyTuple_New(tuplesize);
|
|
|
|
|
if (result == NULL)
|
2013-04-06 21:52:34 +02:00
|
|
|
|
return NULL;
|
2010-05-09 17:52:27 +02:00
|
|
|
|
for (i=0 ; i < tuplesize ; i++) {
|
|
|
|
|
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
|
|
|
|
item = (*Py_TYPE(it)->tp_iternext)(it);
|
2013-04-06 21:52:34 +02:00
|
|
|
|
if (item == NULL) {
|
|
|
|
|
Py_DECREF(result);
|
2020-06-19 12:16:57 +02:00
|
|
|
|
if (lz->strict) {
|
|
|
|
|
goto check;
|
|
|
|
|
}
|
2013-04-06 21:52:34 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyTuple_SET_ITEM(result, i, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2020-06-19 12:16:57 +02:00
|
|
|
|
check:
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
|
|
|
|
// next() on argument i raised an exception (not StopIteration)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
|
|
|
|
if (i) {
|
|
|
|
|
// ValueError: zip() argument 2 is shorter than argument 1
|
|
|
|
|
// ValueError: zip() argument 3 is shorter than arguments 1-2
|
|
|
|
|
const char* plural = i == 1 ? " " : "s 1-";
|
|
|
|
|
return PyErr_Format(PyExc_ValueError,
|
|
|
|
|
"zip() argument %d is shorter than argument%s%d",
|
|
|
|
|
i + 1, plural, i);
|
|
|
|
|
}
|
|
|
|
|
for (i = 1; i < tuplesize; i++) {
|
|
|
|
|
it = PyTuple_GET_ITEM(lz->ittuple, i);
|
|
|
|
|
item = (*Py_TYPE(it)->tp_iternext)(it);
|
|
|
|
|
if (item) {
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
const char* plural = i == 1 ? " " : "s 1-";
|
|
|
|
|
return PyErr_Format(PyExc_ValueError,
|
|
|
|
|
"zip() argument %d is longer than argument%s%d",
|
|
|
|
|
i + 1, plural, i);
|
|
|
|
|
}
|
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
|
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
|
|
|
|
// next() on argument i raised an exception (not StopIteration)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
|
|
|
|
// Argument i is exhausted. So far so good...
|
|
|
|
|
}
|
|
|
|
|
// All arguments are exhausted. Success!
|
|
|
|
|
return NULL;
|
2008-03-13 03:09:15 +01:00
|
|
|
|
}
|
2000-08-03 17:45:29 +02:00
|
|
|
|
|
2012-04-03 12:49:41 +02:00
|
|
|
|
static PyObject *
|
2018-04-29 20:59:33 +02:00
|
|
|
|
zip_reduce(zipobject *lz, PyObject *Py_UNUSED(ignored))
|
2012-04-03 12:49:41 +02:00
|
|
|
|
{
|
|
|
|
|
/* Just recreate the zip with the internal iterator tuple */
|
2020-06-19 12:16:57 +02:00
|
|
|
|
if (lz->strict) {
|
|
|
|
|
return PyTuple_Pack(3, Py_TYPE(lz), lz->ittuple, Py_True);
|
|
|
|
|
}
|
|
|
|
|
return PyTuple_Pack(2, Py_TYPE(lz), lz->ittuple);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
zip_setstate(zipobject *lz, PyObject *state)
|
|
|
|
|
{
|
|
|
|
|
int strict = PyObject_IsTrue(state);
|
|
|
|
|
if (strict < 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
lz->strict = strict;
|
|
|
|
|
Py_RETURN_NONE;
|
2012-04-03 12:49:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMethodDef zip_methods[] = {
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"__reduce__", _PyCFunction_CAST(zip_reduce), METH_NOARGS, reduce_doc},
|
|
|
|
|
{"__setstate__", _PyCFunction_CAST(zip_setstate), METH_O, setstate_doc},
|
2020-06-19 12:16:57 +02:00
|
|
|
|
{NULL} /* sentinel */
|
2012-04-03 12:49:41 +02:00
|
|
|
|
};
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(zip_doc,
|
2023-11-13 08:13:49 +01:00
|
|
|
|
"zip(*iterables, strict=False)\n\
|
|
|
|
|
--\n\
|
2020-05-15 23:26:00 +02:00
|
|
|
|
\n\
|
|
|
|
|
The zip object yields n-length tuples, where n is the number of iterables\n\
|
|
|
|
|
passed as positional arguments to zip(). The i-th element in every tuple\n\
|
|
|
|
|
comes from the i-th iterable argument to zip(). This continues until the\n\
|
2020-06-19 12:16:57 +02:00
|
|
|
|
shortest argument is exhausted.\n\
|
|
|
|
|
\n\
|
|
|
|
|
If strict is true and one of the arguments is exhausted before the others,\n\
|
2023-11-13 08:13:49 +01:00
|
|
|
|
raise a ValueError.\n\
|
|
|
|
|
\n\
|
|
|
|
|
>>> list(zip('abcdefg', range(3), range(4)))\n\
|
|
|
|
|
[('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]");
|
2008-03-13 03:09:15 +01:00
|
|
|
|
|
|
|
|
|
PyTypeObject PyZip_Type = {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
|
"zip", /* tp_name */
|
|
|
|
|
sizeof(zipobject), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
(destructor)zip_dealloc, /* tp_dealloc */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_vectorcall_offset */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
2019-05-31 04:13:39 +02:00
|
|
|
|
0, /* tp_as_async */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
|
|
|
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
|
|
|
zip_doc, /* tp_doc */
|
|
|
|
|
(traverseproc)zip_traverse, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
PyObject_SelfIter, /* tp_iter */
|
|
|
|
|
(iternextfunc)zip_next, /* tp_iternext */
|
2012-04-03 12:49:41 +02:00
|
|
|
|
zip_methods, /* tp_methods */
|
2010-05-09 17:52:27 +02:00
|
|
|
|
0, /* tp_members */
|
|
|
|
|
0, /* tp_getset */
|
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
0, /* tp_init */
|
|
|
|
|
PyType_GenericAlloc, /* tp_alloc */
|
|
|
|
|
zip_new, /* tp_new */
|
|
|
|
|
PyObject_GC_Del, /* tp_free */
|
2008-03-13 03:09:15 +01:00
|
|
|
|
};
|
2000-08-03 17:45:29 +02:00
|
|
|
|
|
|
|
|
|
|
1997-04-29 22:08:16 +02:00
|
|
|
|
static PyMethodDef builtin_methods[] = {
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"__build_class__", _PyCFunction_CAST(builtin___build_class__),
|
2017-07-03 20:20:15 +02:00
|
|
|
|
METH_FASTCALL | METH_KEYWORDS, build_class_doc},
|
2022-03-11 17:46:55 +01:00
|
|
|
|
BUILTIN___IMPORT___METHODDEF
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_ABS_METHODDEF
|
|
|
|
|
BUILTIN_ALL_METHODDEF
|
|
|
|
|
BUILTIN_ANY_METHODDEF
|
|
|
|
|
BUILTIN_ASCII_METHODDEF
|
|
|
|
|
BUILTIN_BIN_METHODDEF
|
2022-03-31 10:02:34 +02:00
|
|
|
|
{"breakpoint", _PyCFunction_CAST(builtin_breakpoint), METH_FASTCALL | METH_KEYWORDS, breakpoint_doc},
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_CALLABLE_METHODDEF
|
|
|
|
|
BUILTIN_CHR_METHODDEF
|
|
|
|
|
BUILTIN_COMPILE_METHODDEF
|
|
|
|
|
BUILTIN_DELATTR_METHODDEF
|
2023-08-21 02:54:10 +02:00
|
|
|
|
{"dir", builtin_dir, METH_VARARGS, dir_doc},
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_DIVMOD_METHODDEF
|
|
|
|
|
BUILTIN_EVAL_METHODDEF
|
|
|
|
|
BUILTIN_EXEC_METHODDEF
|
|
|
|
|
BUILTIN_FORMAT_METHODDEF
|
2023-08-21 02:54:10 +02:00
|
|
|
|
{"getattr", _PyCFunction_CAST(builtin_getattr), METH_FASTCALL, getattr_doc},
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_GLOBALS_METHODDEF
|
|
|
|
|
BUILTIN_HASATTR_METHODDEF
|
|
|
|
|
BUILTIN_HASH_METHODDEF
|
|
|
|
|
BUILTIN_HEX_METHODDEF
|
|
|
|
|
BUILTIN_ID_METHODDEF
|
|
|
|
|
BUILTIN_INPUT_METHODDEF
|
|
|
|
|
BUILTIN_ISINSTANCE_METHODDEF
|
|
|
|
|
BUILTIN_ISSUBCLASS_METHODDEF
|
2023-08-21 02:54:10 +02:00
|
|
|
|
{"iter", _PyCFunction_CAST(builtin_iter), METH_FASTCALL, iter_doc},
|
2021-03-23 23:47:21 +01:00
|
|
|
|
BUILTIN_AITER_METHODDEF
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_LEN_METHODDEF
|
|
|
|
|
BUILTIN_LOCALS_METHODDEF
|
2023-12-11 20:27:06 +01:00
|
|
|
|
{"max", _PyCFunction_CAST(builtin_max), METH_FASTCALL | METH_KEYWORDS, max_doc},
|
|
|
|
|
{"min", _PyCFunction_CAST(builtin_min), METH_FASTCALL | METH_KEYWORDS, min_doc},
|
2023-08-21 02:54:10 +02:00
|
|
|
|
{"next", _PyCFunction_CAST(builtin_next), METH_FASTCALL, next_doc},
|
2021-03-23 23:47:21 +01:00
|
|
|
|
BUILTIN_ANEXT_METHODDEF
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_OCT_METHODDEF
|
|
|
|
|
BUILTIN_ORD_METHODDEF
|
|
|
|
|
BUILTIN_POW_METHODDEF
|
2021-07-16 17:43:02 +02:00
|
|
|
|
BUILTIN_PRINT_METHODDEF
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_REPR_METHODDEF
|
2017-11-15 16:51:14 +01:00
|
|
|
|
BUILTIN_ROUND_METHODDEF
|
2014-08-17 06:01:19 +02:00
|
|
|
|
BUILTIN_SETATTR_METHODDEF
|
|
|
|
|
BUILTIN_SORTED_METHODDEF
|
|
|
|
|
BUILTIN_SUM_METHODDEF
|
2023-08-21 02:54:10 +02:00
|
|
|
|
{"vars", builtin_vars, METH_VARARGS, vars_doc},
|
2010-05-09 17:52:27 +02:00
|
|
|
|
{NULL, NULL},
|
1990-12-20 16:06:42 +01:00
|
|
|
|
};
|
|
|
|
|
|
2002-06-13 22:33:02 +02:00
|
|
|
|
PyDoc_STRVAR(builtin_doc,
|
2023-05-07 04:05:34 +02:00
|
|
|
|
"Built-in functions, types, exceptions, and other objects.\n\
|
1998-06-26 23:23:49 +02:00
|
|
|
|
\n\
|
2023-05-07 04:05:34 +02:00
|
|
|
|
This module provides direct access to all 'built-in'\n\
|
|
|
|
|
identifiers of Python; for example, builtins.len is\n\
|
|
|
|
|
the full name for the built-in function len().\n\
|
|
|
|
|
\n\
|
|
|
|
|
This module is not normally accessed explicitly by most\n\
|
|
|
|
|
applications, but can be useful in modules that provide\n\
|
|
|
|
|
objects with the same name as a built-in value, but in\n\
|
|
|
|
|
which the built-in of that name is also needed.");
|
1998-06-26 23:23:49 +02:00
|
|
|
|
|
2008-06-11 07:26:20 +02:00
|
|
|
|
static struct PyModuleDef builtinsmodule = {
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
|
"builtins",
|
|
|
|
|
builtin_doc,
|
|
|
|
|
-1, /* multiple "initialization" just copies the module dict. */
|
|
|
|
|
builtin_methods,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
2008-06-11 07:26:20 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1997-08-02 05:10:38 +02:00
|
|
|
|
PyObject *
|
2021-02-19 15:10:45 +01:00
|
|
|
|
_PyBuiltin_Init(PyInterpreterState *interp)
|
1997-08-02 05:10:38 +02:00
|
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
|
PyObject *mod, *dict, *debug;
|
2012-10-31 04:41:54 +01:00
|
|
|
|
|
2021-02-19 15:10:45 +01:00
|
|
|
|
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
2018-08-30 00:50:45 +02:00
|
|
|
|
|
2017-09-14 20:18:12 +02:00
|
|
|
|
mod = _PyModule_CreateInitialized(&builtinsmodule, PYTHON_API_VERSION);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (mod == NULL)
|
|
|
|
|
return NULL;
|
2024-05-03 17:30:55 +02:00
|
|
|
|
#ifdef Py_GIL_DISABLED
|
2024-05-06 18:59:36 +02:00
|
|
|
|
PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
|
2024-05-03 17:30:55 +02:00
|
|
|
|
#endif
|
2010-05-09 17:52:27 +02:00
|
|
|
|
dict = PyModule_GetDict(mod);
|
2001-09-13 23:37:17 +02:00
|
|
|
|
|
2003-03-23 18:52:28 +01:00
|
|
|
|
#ifdef Py_TRACE_REFS
|
2010-05-09 17:52:27 +02:00
|
|
|
|
/* "builtins" exposes a number of statically allocated objects
|
|
|
|
|
* that, before this code was added in 2.3, never showed up in
|
|
|
|
|
* the list of "all objects" maintained by Py_TRACE_REFS. As a
|
|
|
|
|
* result, programs leaking references to None and False (etc)
|
|
|
|
|
* couldn't be diagnosed by examining sys.getobjects(0).
|
|
|
|
|
*/
|
2023-08-31 18:33:34 +02:00
|
|
|
|
#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT))
|
2003-03-23 18:52:28 +01:00
|
|
|
|
#else
|
|
|
|
|
#define ADD_TO_ALL(OBJECT) (void)0
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-09-13 23:37:17 +02:00
|
|
|
|
#define SETBUILTIN(NAME, OBJECT) \
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \
|
|
|
|
|
return NULL; \
|
|
|
|
|
ADD_TO_ALL(OBJECT)
|
|
|
|
|
|
|
|
|
|
SETBUILTIN("None", Py_None);
|
|
|
|
|
SETBUILTIN("Ellipsis", Py_Ellipsis);
|
|
|
|
|
SETBUILTIN("NotImplemented", Py_NotImplemented);
|
|
|
|
|
SETBUILTIN("False", Py_False);
|
|
|
|
|
SETBUILTIN("True", Py_True);
|
|
|
|
|
SETBUILTIN("bool", &PyBool_Type);
|
|
|
|
|
SETBUILTIN("memoryview", &PyMemoryView_Type);
|
|
|
|
|
SETBUILTIN("bytearray", &PyByteArray_Type);
|
|
|
|
|
SETBUILTIN("bytes", &PyBytes_Type);
|
|
|
|
|
SETBUILTIN("classmethod", &PyClassMethod_Type);
|
|
|
|
|
SETBUILTIN("complex", &PyComplex_Type);
|
|
|
|
|
SETBUILTIN("dict", &PyDict_Type);
|
|
|
|
|
SETBUILTIN("enumerate", &PyEnum_Type);
|
|
|
|
|
SETBUILTIN("filter", &PyFilter_Type);
|
|
|
|
|
SETBUILTIN("float", &PyFloat_Type);
|
|
|
|
|
SETBUILTIN("frozenset", &PyFrozenSet_Type);
|
|
|
|
|
SETBUILTIN("property", &PyProperty_Type);
|
|
|
|
|
SETBUILTIN("int", &PyLong_Type);
|
|
|
|
|
SETBUILTIN("list", &PyList_Type);
|
|
|
|
|
SETBUILTIN("map", &PyMap_Type);
|
|
|
|
|
SETBUILTIN("object", &PyBaseObject_Type);
|
|
|
|
|
SETBUILTIN("range", &PyRange_Type);
|
|
|
|
|
SETBUILTIN("reversed", &PyReversed_Type);
|
|
|
|
|
SETBUILTIN("set", &PySet_Type);
|
|
|
|
|
SETBUILTIN("slice", &PySlice_Type);
|
|
|
|
|
SETBUILTIN("staticmethod", &PyStaticMethod_Type);
|
|
|
|
|
SETBUILTIN("str", &PyUnicode_Type);
|
|
|
|
|
SETBUILTIN("super", &PySuper_Type);
|
|
|
|
|
SETBUILTIN("tuple", &PyTuple_Type);
|
|
|
|
|
SETBUILTIN("type", &PyType_Type);
|
|
|
|
|
SETBUILTIN("zip", &PyZip_Type);
|
2018-08-30 00:50:45 +02:00
|
|
|
|
debug = PyBool_FromLong(config->optimization_level == 0);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
|
2016-06-18 08:44:03 +02:00
|
|
|
|
Py_DECREF(debug);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-06-18 08:44:03 +02:00
|
|
|
|
Py_DECREF(debug);
|
2010-05-09 17:52:27 +02:00
|
|
|
|
|
|
|
|
|
return mod;
|
2003-03-23 18:52:28 +01:00
|
|
|
|
#undef ADD_TO_ALL
|
2001-09-13 23:37:17 +02:00
|
|
|
|
#undef SETBUILTIN
|
1990-12-20 16:06:42 +01:00
|
|
|
|
}
|