diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Objects | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Objects')
74 files changed, 15777 insertions, 15777 deletions
diff --git a/contrib/tools/python3/src/Objects/abstract.c b/contrib/tools/python3/src/Objects/abstract.c index fceef96250..a5cbb12ff8 100644 --- a/contrib/tools/python3/src/Objects/abstract.c +++ b/contrib/tools/python3/src/Objects/abstract.c @@ -1,12 +1,12 @@ /* Abstract Object Interface (many thanks to Jim Fulton) */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() +#include "pycore_pyerrors.h" +#include "pycore_pystate.h" // _PyThreadState_GET() #include <ctype.h> -#include <stddef.h> // offsetof() +#include <stddef.h> // offsetof() #include "longintrepr.h" @@ -16,7 +16,7 @@ static PyObject * type_error(const char *msg, PyObject *obj) { - PyErr_Format(PyExc_TypeError, msg, Py_TYPE(obj)->tp_name); + PyErr_Format(PyExc_TypeError, msg, Py_TYPE(obj)->tp_name); return NULL; } @@ -40,7 +40,7 @@ PyObject_Type(PyObject *o) return null_error(); } - v = (PyObject *)Py_TYPE(o); + v = (PyObject *)Py_TYPE(o); Py_INCREF(v); return v; } @@ -55,7 +55,7 @@ PyObject_Size(PyObject *o) return -1; } - m = Py_TYPE(o)->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_length) { Py_ssize_t len = m->sq_length(o); assert(len >= 0 || PyErr_Occurred()); @@ -152,16 +152,16 @@ PyObject_GetItem(PyObject *o, PyObject *key) return null_error(); } - m = Py_TYPE(o)->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_subscript) { PyObject *item = m->mp_subscript(o, key); assert((item != NULL) ^ (PyErr_Occurred() != NULL)); return item; } - ms = Py_TYPE(o)->tp_as_sequence; + ms = Py_TYPE(o)->tp_as_sequence; if (ms && ms->sq_item) { - if (_PyIndex_Check(key)) { + if (_PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); if (key_value == -1 && PyErr_Occurred()) @@ -175,19 +175,19 @@ PyObject_GetItem(PyObject *o, PyObject *key) } if (PyType_Check(o)) { - PyObject *meth, *result; + PyObject *meth, *result; _Py_IDENTIFIER(__class_getitem__); - - // Special case type[int], but disallow other types so str[int] fails - if ((PyTypeObject*)o == &PyType_Type) { - return Py_GenericAlias(o, key); - } - + + // Special case type[int], but disallow other types so str[int] fails + if ((PyTypeObject*)o == &PyType_Type) { + return Py_GenericAlias(o, key); + } + if (_PyObject_LookupAttrId(o, &PyId___class_getitem__, &meth) < 0) { return NULL; } if (meth) { - result = PyObject_CallOneArg(meth, key); + result = PyObject_CallOneArg(meth, key); Py_DECREF(meth); return result; } @@ -205,19 +205,19 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) null_error(); return -1; } - m = Py_TYPE(o)->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_ass_subscript) return m->mp_ass_subscript(o, key, value); - if (Py_TYPE(o)->tp_as_sequence) { - if (_PyIndex_Check(key)) { + if (Py_TYPE(o)->tp_as_sequence) { + if (_PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); if (key_value == -1 && PyErr_Occurred()) return -1; return PySequence_SetItem(o, key_value, value); } - else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { + else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -237,19 +237,19 @@ PyObject_DelItem(PyObject *o, PyObject *key) null_error(); return -1; } - m = Py_TYPE(o)->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_ass_subscript) return m->mp_ass_subscript(o, key, (PyObject*)NULL); - if (Py_TYPE(o)->tp_as_sequence) { - if (_PyIndex_Check(key)) { + if (Py_TYPE(o)->tp_as_sequence) { + if (_PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); if (key_value == -1 && PyErr_Occurred()) return -1; return PySequence_DelItem(o, key_value); } - else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { + else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -278,23 +278,23 @@ PyObject_DelItemString(PyObject *o, const char *key) return ret; } - -/* Return 1 if the getbuffer function is available, otherwise return 0. */ -int -PyObject_CheckBuffer(PyObject *obj) -{ - PyBufferProcs *tp_as_buffer = Py_TYPE(obj)->tp_as_buffer; - return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL); -} - - + +/* Return 1 if the getbuffer function is available, otherwise return 0. */ +int +PyObject_CheckBuffer(PyObject *obj) +{ + PyBufferProcs *tp_as_buffer = Py_TYPE(obj)->tp_as_buffer; + return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL); +} + + /* We release the buffer right after use of this function which could cause issues later on. Don't use these functions in new code. */ int PyObject_CheckReadBuffer(PyObject *obj) { - PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; + PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; Py_buffer view; if (pb == NULL || @@ -352,7 +352,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, null_error(); return -1; } - pb = Py_TYPE(obj)->tp_as_buffer; + pb = Py_TYPE(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL || ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) { @@ -372,7 +372,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; + PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, @@ -514,48 +514,48 @@ _Py_add_one_to_index_C(int nd, Py_ssize_t *index, const Py_ssize_t *shape) } } -Py_ssize_t -PyBuffer_SizeFromFormat(const char *format) -{ - PyObject *structmodule = NULL; - PyObject *calcsize = NULL; - PyObject *res = NULL; - PyObject *fmt = NULL; - Py_ssize_t itemsize = -1; - - structmodule = PyImport_ImportModule("struct"); - if (structmodule == NULL) { - return itemsize; - } - - calcsize = PyObject_GetAttrString(structmodule, "calcsize"); - if (calcsize == NULL) { - goto done; - } - - fmt = PyUnicode_FromString(format); - if (fmt == NULL) { - goto done; - } - - res = PyObject_CallFunctionObjArgs(calcsize, fmt, NULL); - if (res == NULL) { - goto done; - } - - itemsize = PyLong_AsSsize_t(res); - if (itemsize < 0) { - goto done; - } - -done: - Py_DECREF(structmodule); - Py_XDECREF(calcsize); - Py_XDECREF(fmt); - Py_XDECREF(res); - return itemsize; -} - +Py_ssize_t +PyBuffer_SizeFromFormat(const char *format) +{ + PyObject *structmodule = NULL; + PyObject *calcsize = NULL; + PyObject *res = NULL; + PyObject *fmt = NULL; + Py_ssize_t itemsize = -1; + + structmodule = PyImport_ImportModule("struct"); + if (structmodule == NULL) { + return itemsize; + } + + calcsize = PyObject_GetAttrString(structmodule, "calcsize"); + if (calcsize == NULL) { + goto done; + } + + fmt = PyUnicode_FromString(format); + if (fmt == NULL) { + goto done; + } + + res = PyObject_CallFunctionObjArgs(calcsize, fmt, NULL); + if (res == NULL) { + goto done; + } + + itemsize = PyLong_AsSsize_t(res); + if (itemsize < 0) { + goto done; + } + +done: + Py_DECREF(structmodule); + Py_XDECREF(calcsize); + Py_XDECREF(fmt); + Py_XDECREF(res); + return itemsize; +} + int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort) { @@ -798,7 +798,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* And call it. */ - result = PyObject_CallOneArg(meth, format_spec); + result = PyObject_CallOneArg(meth, format_spec); Py_DECREF(meth); if (result && !PyUnicode_Check(result)) { @@ -819,10 +819,10 @@ done: int PyNumber_Check(PyObject *o) { - return o && Py_TYPE(o)->tp_as_number && - (Py_TYPE(o)->tp_as_number->nb_index || - Py_TYPE(o)->tp_as_number->nb_int || - Py_TYPE(o)->tp_as_number->nb_float); + return o && Py_TYPE(o)->tp_as_number && + (Py_TYPE(o)->tp_as_number->nb_index || + Py_TYPE(o)->tp_as_number->nb_int || + Py_TYPE(o)->tp_as_number->nb_float); } /* Binary operators */ @@ -839,8 +839,8 @@ PyNumber_Check(PyObject *o) Order operations are tried until either a valid result or error: w.op(v,w)[*], v.op(v,w), w.op(v,w) - [*] only when Py_TYPE(v) != Py_TYPE(w) && Py_TYPE(w) is a subclass of - Py_TYPE(v) + [*] only when Py_TYPE(v) != Py_TYPE(w) && Py_TYPE(w) is a subclass of + Py_TYPE(v) */ static PyObject * @@ -850,16 +850,16 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot) binaryfunc slotv = NULL; binaryfunc slotw = NULL; - if (Py_TYPE(v)->tp_as_number != NULL) - slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot); - if (!Py_IS_TYPE(w, Py_TYPE(v)) && - Py_TYPE(w)->tp_as_number != NULL) { - slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot); + if (Py_TYPE(v)->tp_as_number != NULL) + slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot); + if (!Py_IS_TYPE(w, Py_TYPE(v)) && + Py_TYPE(w)->tp_as_number != NULL) { + slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot); if (slotw == slotv) slotw = NULL; } if (slotv) { - if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { + if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { x = slotw(v, w); if (x != Py_NotImplemented) return x; @@ -887,8 +887,8 @@ binop_type_error(PyObject *v, PyObject *w, const char *op_name) "unsupported operand type(s) for %.100s: " "'%.100s' and '%.100s'", op_name, - Py_TYPE(v)->tp_name, - Py_TYPE(w)->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } @@ -900,7 +900,7 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name) Py_DECREF(result); if (op_slot == NB_SLOT(nb_rshift) && - PyCFunction_CheckExact(v) && + PyCFunction_CheckExact(v) && strcmp(((PyCFunctionObject *)v)->m_ml->ml_name, "print") == 0) { PyErr_Format(PyExc_TypeError, @@ -908,8 +908,8 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name) "'%.100s' and '%.100s'. Did you mean \"print(<message>, " "file=<output_stream>)\"?", op_name, - Py_TYPE(v)->tp_name, - Py_TYPE(w)->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } @@ -939,17 +939,17 @@ ternary_op(PyObject *v, ternaryfunc slotw = NULL; ternaryfunc slotz = NULL; - mv = Py_TYPE(v)->tp_as_number; - mw = Py_TYPE(w)->tp_as_number; + mv = Py_TYPE(v)->tp_as_number; + mw = Py_TYPE(w)->tp_as_number; if (mv != NULL) slotv = NB_TERNOP(mv, op_slot); - if (!Py_IS_TYPE(w, Py_TYPE(v)) && mw != NULL) { + if (!Py_IS_TYPE(w, Py_TYPE(v)) && mw != NULL) { slotw = NB_TERNOP(mw, op_slot); if (slotw == slotv) slotw = NULL; } if (slotv) { - if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { + if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { x = slotw(v, w, z); if (x != Py_NotImplemented) return x; @@ -967,7 +967,7 @@ ternary_op(PyObject *v, return x; Py_DECREF(x); /* can't do it */ } - mz = Py_TYPE(z)->tp_as_number; + mz = Py_TYPE(z)->tp_as_number; if (mz != NULL) { slotz = NB_TERNOP(mz, op_slot); if (slotz == slotv || slotz == slotw) @@ -985,16 +985,16 @@ ternary_op(PyObject *v, PyExc_TypeError, "unsupported operand type(s) for ** or pow(): " "'%.100s' and '%.100s'", - Py_TYPE(v)->tp_name, - Py_TYPE(w)->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); else PyErr_Format( PyExc_TypeError, "unsupported operand type(s) for pow(): " "'%.100s', '%.100s', '%.100s'", - Py_TYPE(v)->tp_name, - Py_TYPE(w)->tp_name, - Py_TYPE(z)->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name, + Py_TYPE(z)->tp_name); return NULL; } @@ -1017,7 +1017,7 @@ PyNumber_Add(PyObject *v, PyObject *w) { PyObject *result = binary_op1(v, w, NB_SLOT(nb_add)); if (result == Py_NotImplemented) { - PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; Py_DECREF(result); if (m && m->sq_concat) { return (*m->sq_concat)(v, w); @@ -1031,7 +1031,7 @@ static PyObject * sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n) { Py_ssize_t count; - if (_PyIndex_Check(n)) { + if (_PyIndex_Check(n)) { count = PyNumber_AsSsize_t(n, PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) return NULL; @@ -1048,8 +1048,8 @@ PyNumber_Multiply(PyObject *v, PyObject *w) { PyObject *result = binary_op1(v, w, NB_SLOT(nb_multiply)); if (result == Py_NotImplemented) { - PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; - PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; + PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; Py_DECREF(result); if (mv && mv->sq_repeat) { return sequence_repeat(mv->sq_repeat, v, w); @@ -1111,7 +1111,7 @@ PyNumber_Power(PyObject *v, PyObject *w, PyObject *z) static PyObject * binary_iop1(PyObject *v, PyObject *w, const int iop_slot, const int op_slot) { - PyNumberMethods *mv = Py_TYPE(v)->tp_as_number; + PyNumberMethods *mv = Py_TYPE(v)->tp_as_number; if (mv != NULL) { binaryfunc slot = NB_BINOP(mv, iop_slot); if (slot) { @@ -1171,7 +1171,7 @@ PyNumber_InPlaceAdd(PyObject *v, PyObject *w) PyObject *result = binary_iop1(v, w, NB_SLOT(nb_inplace_add), NB_SLOT(nb_add)); if (result == Py_NotImplemented) { - PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; Py_DECREF(result); if (m != NULL) { binaryfunc f = NULL; @@ -1193,8 +1193,8 @@ PyNumber_InPlaceMultiply(PyObject *v, PyObject *w) NB_SLOT(nb_multiply)); if (result == Py_NotImplemented) { ssizeargfunc f = NULL; - PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; - PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; + PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; Py_DECREF(result); if (mv != NULL) { f = mv->sq_inplace_repeat; @@ -1232,8 +1232,8 @@ PyNumber_InPlaceRemainder(PyObject *v, PyObject *w) PyObject * PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z) { - if (Py_TYPE(v)->tp_as_number && - Py_TYPE(v)->tp_as_number->nb_inplace_power != NULL) { + if (Py_TYPE(v)->tp_as_number && + Py_TYPE(v)->tp_as_number->nb_inplace_power != NULL) { return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**="); } else { @@ -1253,7 +1253,7 @@ PyNumber_Negative(PyObject *o) return null_error(); } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_negative) return (*m->nb_negative)(o); @@ -1269,7 +1269,7 @@ PyNumber_Positive(PyObject *o) return null_error(); } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_positive) return (*m->nb_positive)(o); @@ -1285,7 +1285,7 @@ PyNumber_Invert(PyObject *o) return null_error(); } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_invert) return (*m->nb_invert)(o); @@ -1301,21 +1301,21 @@ PyNumber_Absolute(PyObject *o) return null_error(); } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_absolute) return m->nb_absolute(o); return type_error("bad operand type for abs(): '%.200s'", o); } - -int -PyIndex_Check(PyObject *obj) -{ - return _PyIndex_Check(obj); -} - - + +int +PyIndex_Check(PyObject *obj) +{ + return _PyIndex_Check(obj); +} + + /* Return a Python int from the object item. Raise TypeError if the result is not an int or if the object cannot be interpreted as an index. @@ -1332,19 +1332,19 @@ PyNumber_Index(PyObject *item) Py_INCREF(item); return item; } - if (!_PyIndex_Check(item)) { + if (!_PyIndex_Check(item)) { PyErr_Format(PyExc_TypeError, "'%.200s' object cannot be interpreted " - "as an integer", Py_TYPE(item)->tp_name); + "as an integer", Py_TYPE(item)->tp_name); return NULL; } - result = Py_TYPE(item)->tp_as_number->nb_index(item); + result = Py_TYPE(item)->tp_as_number->nb_index(item); if (!result || PyLong_CheckExact(result)) return result; if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, "__index__ returned non-int (type %.200s)", - Py_TYPE(result)->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } @@ -1353,7 +1353,7 @@ PyNumber_Index(PyObject *item) "__index__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(result)->tp_name)) { + Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } @@ -1398,7 +1398,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) /* Otherwise replace the error with caller's error object. */ PyErr_Format(err, "cannot fit '%.200s' into an index-sized integer", - Py_TYPE(item)->tp_name); + Py_TYPE(item)->tp_name); } finish: @@ -1424,21 +1424,21 @@ PyNumber_Long(PyObject *o) Py_INCREF(o); return o; } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_int) { /* This should include subclasses of int */ - result = _PyLong_FromNbInt(o); + result = _PyLong_FromNbInt(o); + if (result != NULL && !PyLong_CheckExact(result)) { + Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); + } + return result; + } + if (m && m->nb_index) { + result = _PyLong_FromNbIndexOrNbInt(o); if (result != NULL && !PyLong_CheckExact(result)) { Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); } return result; } - if (m && m->nb_index) { - result = _PyLong_FromNbIndexOrNbInt(o); - if (result != NULL && !PyLong_CheckExact(result)) { - Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); - } - return result; - } trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__); if (trunc_func) { result = _PyObject_CallNoArg(trunc_func); @@ -1452,16 +1452,16 @@ PyNumber_Long(PyObject *o) } /* __trunc__ is specified to return an Integral type, but int() needs to return an int. */ - m = Py_TYPE(result)->tp_as_number; - if (m == NULL || (m->nb_index == NULL && m->nb_int == NULL)) { + m = Py_TYPE(result)->tp_as_number; + if (m == NULL || (m->nb_index == NULL && m->nb_int == NULL)) { PyErr_Format( PyExc_TypeError, "__trunc__ returned non-Integral (type %.200s)", - Py_TYPE(result)->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } - Py_SETREF(result, _PyLong_FromNbIndexOrNbInt(result)); + Py_SETREF(result, _PyLong_FromNbIndexOrNbInt(result)); if (result != NULL && !PyLong_CheckExact(result)) { Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); } @@ -1519,7 +1519,7 @@ PyNumber_Float(PyObject *o) Py_INCREF(o); return o; } - m = Py_TYPE(o)->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_float) { /* This should include subclasses of float */ PyObject *res = m->nb_float(o); double val; @@ -1529,7 +1529,7 @@ PyNumber_Float(PyObject *o) if (!PyFloat_Check(res)) { PyErr_Format(PyExc_TypeError, "%.50s.__float__ returned non-float (type %.50s)", - Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name); + Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } @@ -1538,7 +1538,7 @@ PyNumber_Float(PyObject *o) "%.50s.__float__ returned non-float (type %.50s). " "The ability to return an instance of a strict subclass of float " "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name)) { + Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -1546,18 +1546,18 @@ PyNumber_Float(PyObject *o) Py_DECREF(res); return PyFloat_FromDouble(val); } - if (m && m->nb_index) { - PyObject *res = PyNumber_Index(o); - if (!res) { - return NULL; - } - double val = PyLong_AsDouble(res); - Py_DECREF(res); - if (val == -1.0 && PyErr_Occurred()) { - return NULL; - } - return PyFloat_FromDouble(val); - } + if (m && m->nb_index) { + PyObject *res = PyNumber_Index(o); + if (!res) { + return NULL; + } + double val = PyLong_AsDouble(res); + Py_DECREF(res); + if (val == -1.0 && PyErr_Occurred()) { + return NULL; + } + return PyFloat_FromDouble(val); + } if (PyFloat_Check(o)) { /* A float subclass with nb_float == NULL */ return PyFloat_FromDouble(PyFloat_AS_DOUBLE(o)); } @@ -1568,15 +1568,15 @@ PyNumber_Float(PyObject *o) PyObject * PyNumber_ToBase(PyObject *n, int base) { - if (!(base == 2 || base == 8 || base == 10 || base == 16)) { - PyErr_SetString(PyExc_SystemError, - "PyNumber_ToBase: base must be 2, 8, 10 or 16"); - return NULL; - } + if (!(base == 2 || base == 8 || base == 10 || base == 16)) { + PyErr_SetString(PyExc_SystemError, + "PyNumber_ToBase: base must be 2, 8, 10 or 16"); + return NULL; + } PyObject *index = PyNumber_Index(n); if (!index) return NULL; - PyObject *res = _PyLong_Format(index, base); + PyObject *res = _PyLong_Format(index, base); Py_DECREF(index); return res; } @@ -1589,8 +1589,8 @@ PySequence_Check(PyObject *s) { if (PyDict_Check(s)) return 0; - return Py_TYPE(s)->tp_as_sequence && - Py_TYPE(s)->tp_as_sequence->sq_item != NULL; + return Py_TYPE(s)->tp_as_sequence && + Py_TYPE(s)->tp_as_sequence->sq_item != NULL; } Py_ssize_t @@ -1603,17 +1603,17 @@ PySequence_Size(PyObject *s) return -1; } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_length) { Py_ssize_t len = m->sq_length(s); assert(len >= 0 || PyErr_Occurred()); return len; } - if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) { - type_error("%.200s is not a sequence", s); - return -1; - } + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) { + type_error("%.200s is not a sequence", s); + return -1; + } type_error("object of type '%.200s' has no len()", s); return -1; } @@ -1635,7 +1635,7 @@ PySequence_Concat(PyObject *s, PyObject *o) return null_error(); } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_concat) return m->sq_concat(s, o); @@ -1660,7 +1660,7 @@ PySequence_Repeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = Py_TYPE(o)->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_repeat) return m->sq_repeat(o, count); @@ -1690,7 +1690,7 @@ PySequence_InPlaceConcat(PyObject *s, PyObject *o) return null_error(); } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_inplace_concat) return m->sq_inplace_concat(s, o); if (m && m->sq_concat) @@ -1715,7 +1715,7 @@ PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = Py_TYPE(o)->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_inplace_repeat) return m->sq_inplace_repeat(o, count); if (m && m->sq_repeat) @@ -1745,7 +1745,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return null_error(); } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_item) { if (i < 0) { if (m->sq_length) { @@ -1760,9 +1760,9 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return m->sq_item(s, i); } - if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_subscript) { - return type_error("%.200s is not a sequence", s); - } + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_subscript) { + return type_error("%.200s is not a sequence", s); + } return type_error("'%.200s' object does not support indexing", s); } @@ -1775,7 +1775,7 @@ PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return null_error(); } - mp = Py_TYPE(s)->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_subscript) { PyObject *res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1799,7 +1799,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) return -1; } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1814,10 +1814,10 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) return m->sq_ass_item(s, i, o); } - if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { - type_error("%.200s is not a sequence", s); - return -1; - } + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { + type_error("%.200s is not a sequence", s); + return -1; + } type_error("'%.200s' object does not support item assignment", s); return -1; } @@ -1832,7 +1832,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) return -1; } - m = Py_TYPE(s)->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1847,10 +1847,10 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) return m->sq_ass_item(s, i, (PyObject *)NULL); } - if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { - type_error("%.200s is not a sequence", s); - return -1; - } + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { + type_error("%.200s is not a sequence", s); + return -1; + } type_error("'%.200s' object doesn't support item deletion", s); return -1; } @@ -1865,7 +1865,7 @@ PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o) return -1; } - mp = Py_TYPE(s)->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1890,7 +1890,7 @@ PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return -1; } - mp = Py_TYPE(s)->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -2058,9 +2058,9 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) it = PyObject_GetIter(seq); if (it == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - type_error("argument of type '%.200s' is not iterable", seq); - } + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + type_error("argument of type '%.200s' is not iterable", seq); + } return -1; } @@ -2074,7 +2074,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) break; } - cmp = PyObject_RichCompareBool(item, obj, Py_EQ); + cmp = PyObject_RichCompareBool(item, obj, Py_EQ); Py_DECREF(item); if (cmp < 0) goto Fail; @@ -2142,7 +2142,7 @@ int PySequence_Contains(PyObject *seq, PyObject *ob) { Py_ssize_t result; - PySequenceMethods *sqm = Py_TYPE(seq)->tp_as_sequence; + PySequenceMethods *sqm = Py_TYPE(seq)->tp_as_sequence; if (sqm != NULL && sqm->sq_contains != NULL) return (*sqm->sq_contains)(seq, ob); result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS); @@ -2168,8 +2168,8 @@ PySequence_Index(PyObject *s, PyObject *o) int PyMapping_Check(PyObject *o) { - return o && Py_TYPE(o)->tp_as_mapping && - Py_TYPE(o)->tp_as_mapping->mp_subscript; + return o && Py_TYPE(o)->tp_as_mapping && + Py_TYPE(o)->tp_as_mapping->mp_subscript; } Py_ssize_t @@ -2182,18 +2182,18 @@ PyMapping_Size(PyObject *o) return -1; } - m = Py_TYPE(o)->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_length) { Py_ssize_t len = m->mp_length(o); assert(len >= 0 || PyErr_Occurred()); return len; } - if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_length) { - type_error("%.200s is not a mapping", o); - return -1; - } - /* PyMapping_Size() can be called from PyObject_Size(). */ + if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_length) { + type_error("%.200s is not a mapping", o); + return -1; + } + /* PyMapping_Size() can be called from PyObject_Size(). */ type_error("object of type '%.200s' has no len()", o); return -1; } @@ -2279,7 +2279,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id) PyObject *it, *result, *meth_output; assert(o != NULL); - meth_output = _PyObject_CallMethodIdNoArgs(o, meth_id); + meth_output = _PyObject_CallMethodIdNoArgs(o, meth_id); if (meth_output == NULL || PyList_CheckExact(meth_output)) { return meth_output; } @@ -2289,7 +2289,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id) PyErr_Format(PyExc_TypeError, "%.200s.%U() returned a non-iterable (type %.200s)", Py_TYPE(o)->tp_name, - _PyUnicode_FromId(meth_id), + _PyUnicode_FromId(meth_id), Py_TYPE(meth_output)->tp_name); } Py_DECREF(meth_output); @@ -2392,16 +2392,16 @@ abstract_issubclass(PyObject *derived, PyObject *cls) int r = 0; while (1) { - if (derived == cls) { - Py_XDECREF(bases); /* See below comment */ + if (derived == cls) { + Py_XDECREF(bases); /* See below comment */ return 1; - } - /* Use XSETREF to drop bases reference *after* finishing with - derived; bases might be the only reference to it. - XSETREF is used instead of SETREF, because bases is NULL on the - first iteration of the loop. - */ - Py_XSETREF(bases, abstract_get_bases(derived)); + } + /* Use XSETREF to drop bases reference *after* finishing with + derived; bases might be the only reference to it. + XSETREF is used instead of SETREF, because bases is NULL on the + first iteration of the loop. + */ + Py_XSETREF(bases, abstract_get_bases(derived)); if (bases == NULL) { if (PyErr_Occurred()) return -1; @@ -2417,22 +2417,22 @@ abstract_issubclass(PyObject *derived, PyObject *cls) derived = PyTuple_GET_ITEM(bases, 0); continue; } - break; - } - assert(n >= 2); - if (Py_EnterRecursiveCall(" in __issubclass__")) { + break; + } + assert(n >= 2); + if (Py_EnterRecursiveCall(" in __issubclass__")) { Py_DECREF(bases); - return -1; + return -1; } - for (i = 0; i < n; i++) { - r = abstract_issubclass(PyTuple_GET_ITEM(bases, i), cls); - if (r != 0) { - break; - } - } - Py_LeaveRecursiveCall(); - Py_DECREF(bases); - return r; + for (i = 0; i < n; i++) { + r = abstract_issubclass(PyTuple_GET_ITEM(bases, i), cls); + if (r != 0) { + break; + } + } + Py_LeaveRecursiveCall(); + Py_DECREF(bases); + return r; } static int @@ -2450,7 +2450,7 @@ check_class(PyObject *cls, const char *error) } static int -object_isinstance(PyObject *inst, PyObject *cls) +object_isinstance(PyObject *inst, PyObject *cls) { PyObject *icls; int retval; @@ -2461,7 +2461,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (retval == 0) { retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls); if (icls != NULL) { - if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { + if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( (PyTypeObject *)icls, (PyTypeObject *)cls); @@ -2487,77 +2487,77 @@ object_isinstance(PyObject *inst, PyObject *cls) return retval; } -static int -object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls) +static int +object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls) { _Py_IDENTIFIER(__instancecheck__); /* Quick test for an exact match */ - if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) { + if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) { return 1; - } + } /* We know what type's __instancecheck__ does. */ if (PyType_CheckExact(cls)) { - return object_isinstance(inst, cls); + return object_isinstance(inst, cls); } if (PyTuple_Check(cls)) { - /* Not a general sequence -- that opens up the road to - recursion and stack overflow. */ - if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { - return -1; - } - Py_ssize_t n = PyTuple_GET_SIZE(cls); + /* Not a general sequence -- that opens up the road to + recursion and stack overflow. */ + if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { + return -1; + } + Py_ssize_t n = PyTuple_GET_SIZE(cls); int r = 0; - for (Py_ssize_t i = 0; i < n; ++i) { + for (Py_ssize_t i = 0; i < n; ++i) { PyObject *item = PyTuple_GET_ITEM(cls, i); - r = object_recursive_isinstance(tstate, inst, item); - if (r != 0) { + r = object_recursive_isinstance(tstate, inst, item); + if (r != 0) { /* either found it, or got an error */ break; - } + } } - _Py_LeaveRecursiveCall(tstate); + _Py_LeaveRecursiveCall(tstate); return r; } - PyObject *checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__); + PyObject *checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__); if (checker != NULL) { - if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { + if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { Py_DECREF(checker); - return -1; + return -1; } - - PyObject *res = PyObject_CallOneArg(checker, inst); - _Py_LeaveRecursiveCall(tstate); + + PyObject *res = PyObject_CallOneArg(checker, inst); + _Py_LeaveRecursiveCall(tstate); Py_DECREF(checker); - - if (res == NULL) { - return -1; + + if (res == NULL) { + return -1; } - int ok = PyObject_IsTrue(res); - Py_DECREF(res); - + int ok = PyObject_IsTrue(res); + Py_DECREF(res); + return ok; } - else if (_PyErr_Occurred(tstate)) { + else if (_PyErr_Occurred(tstate)) { return -1; - } - - /* cls has no __instancecheck__() method */ - return object_isinstance(inst, cls); -} - - -int -PyObject_IsInstance(PyObject *inst, PyObject *cls) -{ - PyThreadState *tstate = _PyThreadState_GET(); - return object_recursive_isinstance(tstate, inst, cls); -} - - + } + + /* cls has no __instancecheck__() method */ + return object_isinstance(inst, cls); +} + + +int +PyObject_IsInstance(PyObject *inst, PyObject *cls) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return object_recursive_isinstance(tstate, inst, cls); +} + + static int recursive_issubclass(PyObject *derived, PyObject *cls) { @@ -2576,8 +2576,8 @@ recursive_issubclass(PyObject *derived, PyObject *cls) return abstract_issubclass(derived, cls); } -static int -object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) +static int +object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) { _Py_IDENTIFIER(__subclasscheck__); PyObject *checker; @@ -2592,31 +2592,31 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) if (PyTuple_Check(cls)) { - if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { + if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { return -1; - } - Py_ssize_t n = PyTuple_GET_SIZE(cls); - int r = 0; - for (Py_ssize_t i = 0; i < n; ++i) { + } + Py_ssize_t n = PyTuple_GET_SIZE(cls); + int r = 0; + for (Py_ssize_t i = 0; i < n; ++i) { PyObject *item = PyTuple_GET_ITEM(cls, i); - r = object_issubclass(tstate, derived, item); + r = object_issubclass(tstate, derived, item); if (r != 0) /* either found it, or got an error */ break; } - _Py_LeaveRecursiveCall(tstate); + _Py_LeaveRecursiveCall(tstate); return r; } checker = _PyObject_LookupSpecial(cls, &PyId___subclasscheck__); if (checker != NULL) { int ok = -1; - if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { + if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { Py_DECREF(checker); return ok; } - PyObject *res = PyObject_CallOneArg(checker, derived); - _Py_LeaveRecursiveCall(tstate); + PyObject *res = PyObject_CallOneArg(checker, derived); + _Py_LeaveRecursiveCall(tstate); Py_DECREF(checker); if (res != NULL) { ok = PyObject_IsTrue(res); @@ -2624,27 +2624,27 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) } return ok; } - else if (_PyErr_Occurred(tstate)) { + else if (_PyErr_Occurred(tstate)) { return -1; - } - + } + /* Probably never reached anymore. */ return recursive_issubclass(derived, cls); } - + +int +PyObject_IsSubclass(PyObject *derived, PyObject *cls) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return object_issubclass(tstate, derived, cls); +} + + int -PyObject_IsSubclass(PyObject *derived, PyObject *cls) -{ - PyThreadState *tstate = _PyThreadState_GET(); - return object_issubclass(tstate, derived, cls); -} - - -int _PyObject_RealIsInstance(PyObject *inst, PyObject *cls) { - return object_isinstance(inst, cls); + return object_isinstance(inst, cls); } int @@ -2657,7 +2657,7 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls) PyObject * PyObject_GetIter(PyObject *o) { - PyTypeObject *t = Py_TYPE(o); + PyTypeObject *t = Py_TYPE(o); getiterfunc f; f = t->tp_iter; @@ -2672,7 +2672,7 @@ PyObject_GetIter(PyObject *o) PyErr_Format(PyExc_TypeError, "iter() returned non-iterator " "of type '%.100s'", - Py_TYPE(res)->tp_name); + Py_TYPE(res)->tp_name); Py_DECREF(res); res = NULL; } @@ -2680,14 +2680,14 @@ PyObject_GetIter(PyObject *o) } } -#undef PyIter_Check - -int PyIter_Check(PyObject *obj) -{ - return Py_TYPE(obj)->tp_iternext != NULL && - Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented; -} - +#undef PyIter_Check + +int PyIter_Check(PyObject *obj) +{ + return Py_TYPE(obj)->tp_iternext != NULL && + Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented; +} + /* Return next item. * If an error occurs, return NULL. PyErr_Occurred() will be true. * If the iteration terminates normally, return NULL and clear the @@ -2699,7 +2699,7 @@ PyObject * PyIter_Next(PyObject *iter) { PyObject *result; - result = (*Py_TYPE(iter)->tp_iternext)(iter); + result = (*Py_TYPE(iter)->tp_iternext)(iter); if (result == NULL && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) diff --git a/contrib/tools/python3/src/Objects/accu.c b/contrib/tools/python3/src/Objects/accu.c index f83c977d57..c8b5d382e3 100644 --- a/contrib/tools/python3/src/Objects/accu.c +++ b/contrib/tools/python3/src/Objects/accu.c @@ -1,7 +1,7 @@ /* Accumulator struct implementation */ #include "Python.h" -#include "pycore_accu.h" +#include "pycore_accu.h" static PyObject * join_list_unicode(PyObject *lst) diff --git a/contrib/tools/python3/src/Objects/boolobject.c b/contrib/tools/python3/src/Objects/boolobject.c index 72ce51bf1b..720835b98a 100644 --- a/contrib/tools/python3/src/Objects/boolobject.c +++ b/contrib/tools/python3/src/Objects/boolobject.c @@ -137,17 +137,17 @@ PyTypeObject PyBool_Type = { sizeof(struct _longobject), 0, 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ bool_repr, /* tp_repr */ &bool_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ diff --git a/contrib/tools/python3/src/Objects/bytearrayobject.c b/contrib/tools/python3/src/Objects/bytearrayobject.c index c1e504bed5..a1aa88086e 100644 --- a/contrib/tools/python3/src/Objects/bytearrayobject.c +++ b/contrib/tools/python3/src/Objects/bytearrayobject.c @@ -2,9 +2,9 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" -#include "pycore_object.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_bytes_methods.h" +#include "pycore_object.h" #include "bytesobject.h" #include "pystrhex.h" @@ -87,7 +87,7 @@ _canresize(PyByteArrayObject *self) PyObject * PyByteArray_FromObject(PyObject *input) { - return PyObject_CallOneArg((PyObject *)&PyByteArray_Type, input); + return PyObject_CallOneArg((PyObject *)&PyByteArray_Type, input); } static PyObject * @@ -146,7 +146,7 @@ PyByteArray_FromStringAndSize(const char *bytes, Py_ssize_t size) memcpy(new->ob_bytes, bytes, size); new->ob_bytes[size] = '\0'; /* Trailing null byte */ } - Py_SET_SIZE(new, size); + Py_SET_SIZE(new, size); new->ob_alloc = alloc; new->ob_start = new->ob_bytes; new->ob_exports = 0; @@ -204,7 +204,7 @@ PyByteArray_Resize(PyObject *self, Py_ssize_t requested_size) } else { /* Minor downsize; quick exit */ - Py_SET_SIZE(self, size); + Py_SET_SIZE(self, size); PyByteArray_AS_STRING(self)[size] = '\0'; /* Trailing null */ return 0; } @@ -244,7 +244,7 @@ PyByteArray_Resize(PyObject *self, Py_ssize_t requested_size) } obj->ob_bytes = obj->ob_start = sval; - Py_SET_SIZE(self, size); + Py_SET_SIZE(self, size); obj->ob_alloc = alloc; obj->ob_bytes[size] = '\0'; /* Trailing null byte */ @@ -273,9 +273,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b) result = (PyByteArrayObject *) \ PyByteArray_FromStringAndSize(NULL, va.len + vb.len); - // result->ob_bytes is NULL if result is an empty string: - // if va.len + vb.len equals zero. - if (result != NULL && result->ob_bytes != NULL) { + // result->ob_bytes is NULL if result is an empty string: + // if va.len + vb.len equals zero. + if (result != NULL && result->ob_bytes != NULL) { memcpy(result->ob_bytes, va.buf, va.len); memcpy(result->ob_bytes + va.len, vb.buf, vb.len); } @@ -329,7 +329,7 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count) PyByteArrayObject *result; Py_ssize_t mysize; Py_ssize_t size; - const char *buf; + const char *buf; if (count < 0) count = 0; @@ -338,14 +338,14 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count) return PyErr_NoMemory(); size = mysize * count; result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size); - buf = PyByteArray_AS_STRING(self); + buf = PyByteArray_AS_STRING(self); if (result != NULL && size != 0) { if (mysize == 1) - memset(result->ob_bytes, buf[0], size); + memset(result->ob_bytes, buf[0], size); else { Py_ssize_t i; for (i = 0; i < count; i++) - memcpy(result->ob_bytes + i*mysize, buf, mysize); + memcpy(result->ob_bytes + i*mysize, buf, mysize); } } return (PyObject *)result; @@ -393,7 +393,7 @@ bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i) static PyObject * bytearray_subscript(PyByteArrayObject *self, PyObject *index) { - if (_PyIndex_Check(index)) { + if (_PyIndex_Check(index)) { Py_ssize_t i = PyNumber_AsSsize_t(index, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) @@ -409,8 +409,8 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index) return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i])); } else if (PySlice_Check(index)) { - Py_ssize_t start, stop, step, slicelength, i; - size_t cur; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; if (PySlice_Unpack(index, &start, &stop, &step) < 0) { return NULL; } @@ -500,7 +500,7 @@ bytearray_setslice_linear(PyByteArrayObject *self, } /* memmove() removed bytes, the bytearray object cannot be restored in its previous state. */ - Py_SET_SIZE(self, Py_SIZE(self) + growth); + Py_SET_SIZE(self, Py_SIZE(self) + growth); res = -1; } buf = PyByteArray_AS_STRING(self); @@ -612,7 +612,7 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu char *buf, *bytes; buf = PyByteArray_AS_STRING(self); - if (_PyIndex_Check(index)) { + if (_PyIndex_Check(index)) { Py_ssize_t i = PyNumber_AsSsize_t(index, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) @@ -773,9 +773,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) if (arg == NULL) { if (encoding != NULL || errors != NULL) { PyErr_SetString(PyExc_TypeError, - encoding != NULL ? - "encoding without a string argument" : - "errors without a string argument"); + encoding != NULL ? + "encoding without a string argument" : + "errors without a string argument"); return -1; } return 0; @@ -804,14 +804,14 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) /* If it's not unicode, there can't be encoding or errors */ if (encoding != NULL || errors != NULL) { PyErr_SetString(PyExc_TypeError, - encoding != NULL ? - "encoding without a string argument" : - "errors without a string argument"); + encoding != NULL ? + "encoding without a string argument" : + "errors without a string argument"); return -1; } /* Is it an int? */ - if (_PyIndex_Check(arg)) { + if (_PyIndex_Check(arg)) { count = PyNumber_AsSsize_t(arg, PyExc_OverflowError); if (count == -1 && PyErr_Occurred()) { if (!PyErr_ExceptionMatches(PyExc_TypeError)) @@ -854,14 +854,14 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) /* Get the iterator */ it = PyObject_GetIter(arg); - if (it == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - PyErr_Format(PyExc_TypeError, - "cannot convert '%.200s' object to bytearray", - Py_TYPE(arg)->tp_name); - } + if (it == NULL) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(PyExc_TypeError, + "cannot convert '%.200s' object to bytearray", + Py_TYPE(arg)->tp_name); + } return -1; - } + } iternext = *Py_TYPE(it)->tp_iternext; /* Run the iterator to exhaustion */ @@ -888,7 +888,7 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) /* Append the byte */ if (Py_SIZE(self) + 1 < self->ob_alloc) { - Py_SET_SIZE(self, Py_SIZE(self) + 1); + Py_SET_SIZE(self, Py_SIZE(self) + 1); PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0'; } else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0) @@ -998,13 +998,13 @@ bytearray_repr(PyByteArrayObject *self) static PyObject * bytearray_str(PyObject *op) { - if (_Py_GetConfig()->bytes_warning) { - if (PyErr_WarnEx(PyExc_BytesWarning, - "str() on a bytearray instance", 1)) { - return NULL; + if (_Py_GetConfig()->bytes_warning) { + if (PyErr_WarnEx(PyExc_BytesWarning, + "str() on a bytearray instance", 1)) { + return NULL; } - } - return bytearray_repr((PyByteArrayObject*)op); + } + return bytearray_repr((PyByteArrayObject*)op); } static PyObject * @@ -1023,7 +1023,7 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op) if (rc < 0) return NULL; if (rc) { - if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) { + if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) { if (PyErr_WarnEx(PyExc_BytesWarning, "Comparison between bytearray and string", 1)) return NULL; @@ -1185,73 +1185,73 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *args) return _Py_bytes_endswith(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args); } -/*[clinic input] -bytearray.removeprefix as bytearray_removeprefix - - prefix: Py_buffer - / - -Return a bytearray with the given prefix string removed if present. - -If the bytearray starts with the prefix string, return -bytearray[len(prefix):]. Otherwise, return a copy of the original -bytearray. -[clinic start generated code]*/ - -static PyObject * -bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix) -/*[clinic end generated code: output=6cabc585e7f502e0 input=968aada38aedd262]*/ -{ - const char *self_start = PyByteArray_AS_STRING(self); - Py_ssize_t self_len = PyByteArray_GET_SIZE(self); - const char *prefix_start = prefix->buf; - Py_ssize_t prefix_len = prefix->len; - - if (self_len >= prefix_len - && memcmp(self_start, prefix_start, prefix_len) == 0) - { - return PyByteArray_FromStringAndSize(self_start + prefix_len, - self_len - prefix_len); - } - - return PyByteArray_FromStringAndSize(self_start, self_len); -} - /*[clinic input] -bytearray.removesuffix as bytearray_removesuffix - - suffix: Py_buffer - / - -Return a bytearray with the given suffix string removed if present. - -If the bytearray ends with the suffix string and that suffix is not -empty, return bytearray[:-len(suffix)]. Otherwise, return a copy of -the original bytearray. -[clinic start generated code]*/ - -static PyObject * -bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix) -/*[clinic end generated code: output=2bc8cfb79de793d3 input=c1827e810b2f6b99]*/ -{ - const char *self_start = PyByteArray_AS_STRING(self); - Py_ssize_t self_len = PyByteArray_GET_SIZE(self); - const char *suffix_start = suffix->buf; - Py_ssize_t suffix_len = suffix->len; - - if (self_len >= suffix_len - && memcmp(self_start + self_len - suffix_len, - suffix_start, suffix_len) == 0) - { - return PyByteArray_FromStringAndSize(self_start, - self_len - suffix_len); - } - - return PyByteArray_FromStringAndSize(self_start, self_len); -} - - -/*[clinic input] +bytearray.removeprefix as bytearray_removeprefix + + prefix: Py_buffer + / + +Return a bytearray with the given prefix string removed if present. + +If the bytearray starts with the prefix string, return +bytearray[len(prefix):]. Otherwise, return a copy of the original +bytearray. +[clinic start generated code]*/ + +static PyObject * +bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix) +/*[clinic end generated code: output=6cabc585e7f502e0 input=968aada38aedd262]*/ +{ + const char *self_start = PyByteArray_AS_STRING(self); + Py_ssize_t self_len = PyByteArray_GET_SIZE(self); + const char *prefix_start = prefix->buf; + Py_ssize_t prefix_len = prefix->len; + + if (self_len >= prefix_len + && memcmp(self_start, prefix_start, prefix_len) == 0) + { + return PyByteArray_FromStringAndSize(self_start + prefix_len, + self_len - prefix_len); + } + + return PyByteArray_FromStringAndSize(self_start, self_len); +} + +/*[clinic input] +bytearray.removesuffix as bytearray_removesuffix + + suffix: Py_buffer + / + +Return a bytearray with the given suffix string removed if present. + +If the bytearray ends with the suffix string and that suffix is not +empty, return bytearray[:-len(suffix)]. Otherwise, return a copy of +the original bytearray. +[clinic start generated code]*/ + +static PyObject * +bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix) +/*[clinic end generated code: output=2bc8cfb79de793d3 input=c1827e810b2f6b99]*/ +{ + const char *self_start = PyByteArray_AS_STRING(self); + Py_ssize_t self_len = PyByteArray_GET_SIZE(self); + const char *suffix_start = suffix->buf; + Py_ssize_t suffix_len = suffix->len; + + if (self_len >= suffix_len + && memcmp(self_start + self_len - suffix_len, + suffix_start, suffix_len) == 0) + { + return PyByteArray_FromStringAndSize(self_start, + self_len - suffix_len); + } + + return PyByteArray_FromStringAndSize(self_start, self_len); +} + + +/*[clinic input] bytearray.translate table: object @@ -1691,14 +1691,14 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) } it = PyObject_GetIter(iterable_of_ints); - if (it == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - PyErr_Format(PyExc_TypeError, - "can't extend bytearray with %.100s", - Py_TYPE(iterable_of_ints)->tp_name); - } + if (it == NULL) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(PyExc_TypeError, + "can't extend bytearray with %.100s", + Py_TYPE(iterable_of_ints)->tp_name); + } return NULL; - } + } /* Try to determine the length of the argument. 32 is arbitrary. */ buf_size = PyObject_LengthHint(iterable_of_ints, 32); @@ -1760,10 +1760,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) } Py_DECREF(bytearray_obj); - if (PyErr_Occurred()) { - return NULL; - } - + if (PyErr_Occurred()) { + return NULL; + } + Py_RETURN_NONE; } @@ -2015,7 +2015,7 @@ PyDoc_STRVAR(alloc_doc, Return the number of bytes actually allocated."); static PyObject * -bytearray_alloc(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) +bytearray_alloc(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(self->ob_alloc); } @@ -2080,41 +2080,41 @@ bytearray_fromhex_impl(PyTypeObject *type, PyObject *string) { PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type); if (type != &PyByteArray_Type && result != NULL) { - Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); + Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); } return result; } -/*[clinic input] -bytearray.hex - - sep: object = NULL - An optional single character or byte to separate hex bytes. - bytes_per_sep: int = 1 - How many bytes between separators. Positive values count from the - right, negative values count from the left. - -Create a str of hexadecimal numbers from a bytearray object. - -Example: ->>> value = bytearray([0xb9, 0x01, 0xef]) ->>> value.hex() -'b901ef' ->>> value.hex(':') -'b9:01:ef' ->>> value.hex(':', 2) -'b9:01ef' ->>> value.hex(':', -2) -'b901:ef' -[clinic start generated code]*/ - +/*[clinic input] +bytearray.hex + + sep: object = NULL + An optional single character or byte to separate hex bytes. + bytes_per_sep: int = 1 + How many bytes between separators. Positive values count from the + right, negative values count from the left. + +Create a str of hexadecimal numbers from a bytearray object. + +Example: +>>> value = bytearray([0xb9, 0x01, 0xef]) +>>> value.hex() +'b901ef' +>>> value.hex(':') +'b9:01:ef' +>>> value.hex(':', 2) +'b9:01ef' +>>> value.hex(':', -2) +'b901:ef' +[clinic start generated code]*/ + static PyObject * -bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep) -/*[clinic end generated code: output=29c4e5ef72c565a0 input=814c15830ac8c4b5]*/ +bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep) +/*[clinic end generated code: output=29c4e5ef72c565a0 input=814c15830ac8c4b5]*/ { char* argbuf = PyByteArray_AS_STRING(self); Py_ssize_t arglen = PyByteArray_GET_SIZE(self); - return _Py_strhex_with_sep(argbuf, arglen, sep, bytes_per_sep); + return _Py_strhex_with_sep(argbuf, arglen, sep, bytes_per_sep); } static PyObject * @@ -2124,9 +2124,9 @@ _common_reduce(PyByteArrayObject *self, int proto) _Py_IDENTIFIER(__dict__); char *buf; - if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) { - return NULL; - } + if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) { + return NULL; + } if (dict == NULL) { dict = Py_None; Py_INCREF(dict); @@ -2229,9 +2229,9 @@ bytearray_methods[] = { BYTEARRAY_REDUCE_EX_METHODDEF BYTEARRAY_SIZEOF_METHODDEF BYTEARRAY_APPEND_METHODDEF - {"capitalize", stringlib_capitalize, METH_NOARGS, + {"capitalize", stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, - STRINGLIB_CENTER_METHODDEF + STRINGLIB_CENTER_METHODDEF BYTEARRAY_CLEAR_METHODDEF BYTEARRAY_COPY_METHODDEF {"count", (PyCFunction)bytearray_count, METH_VARARGS, @@ -2239,45 +2239,45 @@ bytearray_methods[] = { BYTEARRAY_DECODE_METHODDEF {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, _Py_endswith__doc__}, - STRINGLIB_EXPANDTABS_METHODDEF + STRINGLIB_EXPANDTABS_METHODDEF BYTEARRAY_EXTEND_METHODDEF {"find", (PyCFunction)bytearray_find, METH_VARARGS, _Py_find__doc__}, BYTEARRAY_FROMHEX_METHODDEF - BYTEARRAY_HEX_METHODDEF + BYTEARRAY_HEX_METHODDEF {"index", (PyCFunction)bytearray_index, METH_VARARGS, _Py_index__doc__}, BYTEARRAY_INSERT_METHODDEF - {"isalnum", stringlib_isalnum, METH_NOARGS, + {"isalnum", stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, - {"isalpha", stringlib_isalpha, METH_NOARGS, + {"isalpha", stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, - {"isascii", stringlib_isascii, METH_NOARGS, + {"isascii", stringlib_isascii, METH_NOARGS, _Py_isascii__doc__}, - {"isdigit", stringlib_isdigit, METH_NOARGS, + {"isdigit", stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, - {"islower", stringlib_islower, METH_NOARGS, + {"islower", stringlib_islower, METH_NOARGS, _Py_islower__doc__}, - {"isspace", stringlib_isspace, METH_NOARGS, + {"isspace", stringlib_isspace, METH_NOARGS, _Py_isspace__doc__}, - {"istitle", stringlib_istitle, METH_NOARGS, + {"istitle", stringlib_istitle, METH_NOARGS, _Py_istitle__doc__}, - {"isupper", stringlib_isupper, METH_NOARGS, + {"isupper", stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, BYTEARRAY_JOIN_METHODDEF - STRINGLIB_LJUST_METHODDEF - {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, + STRINGLIB_LJUST_METHODDEF + {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, BYTEARRAY_LSTRIP_METHODDEF BYTEARRAY_MAKETRANS_METHODDEF BYTEARRAY_PARTITION_METHODDEF BYTEARRAY_POP_METHODDEF BYTEARRAY_REMOVE_METHODDEF BYTEARRAY_REPLACE_METHODDEF - BYTEARRAY_REMOVEPREFIX_METHODDEF - BYTEARRAY_REMOVESUFFIX_METHODDEF + BYTEARRAY_REMOVEPREFIX_METHODDEF + BYTEARRAY_REMOVESUFFIX_METHODDEF BYTEARRAY_REVERSE_METHODDEF {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, _Py_rfind__doc__}, {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, _Py_rindex__doc__}, - STRINGLIB_RJUST_METHODDEF + STRINGLIB_RJUST_METHODDEF BYTEARRAY_RPARTITION_METHODDEF BYTEARRAY_RSPLIT_METHODDEF BYTEARRAY_RSTRIP_METHODDEF @@ -2286,12 +2286,12 @@ bytearray_methods[] = { {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS , _Py_startswith__doc__}, BYTEARRAY_STRIP_METHODDEF - {"swapcase", stringlib_swapcase, METH_NOARGS, + {"swapcase", stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, - {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, + {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, BYTEARRAY_TRANSLATE_METHODDEF - {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, - STRINGLIB_ZFILL_METHODDEF + {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, + STRINGLIB_ZFILL_METHODDEF {NULL} }; @@ -2333,10 +2333,10 @@ PyTypeObject PyByteArray_Type = { sizeof(PyByteArrayObject), 0, (destructor)bytearray_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)bytearray_repr, /* tp_repr */ &bytearray_as_number, /* tp_as_number */ &bytearray_as_sequence, /* tp_as_sequence */ @@ -2418,7 +2418,7 @@ bytearrayiter_next(bytesiterobject *it) } static PyObject * -bytearrayiter_length_hint(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) +bytearrayiter_length_hint(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) { @@ -2434,14 +2434,14 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) +bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); } } @@ -2480,10 +2480,10 @@ PyTypeObject PyByteArrayIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)bytearrayiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/bytes_methods.c b/contrib/tools/python3/src/Objects/bytes_methods.c index 3f625b8a17..72daa1fdd5 100644 --- a/contrib/tools/python3/src/Objects/bytes_methods.c +++ b/contrib/tools/python3/src/Objects/bytes_methods.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_bytes_methods.h" PyDoc_STRVAR_shared(_Py_isspace__doc__, "B.isspace() -> bool\n\ @@ -13,7 +13,7 @@ PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; /* Shortcut for single character strings */ @@ -43,7 +43,7 @@ PyObject* _Py_bytes_isalpha(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; /* Shortcut for single character strings */ @@ -73,7 +73,7 @@ PyObject* _Py_bytes_isalnum(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; /* Shortcut for single character strings */ @@ -124,7 +124,7 @@ _Py_bytes_isascii(const char *cptr, Py_ssize_t len) /* Help allocation */ const char *_p = p; while (_p < aligned_end) { - unsigned long value = *(const unsigned long *) _p; + unsigned long value = *(const unsigned long *) _p; if (value & ASCII_CHAR_MASK) { Py_RETURN_FALSE; } @@ -155,7 +155,7 @@ PyObject* _Py_bytes_isdigit(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; /* Shortcut for single character strings */ @@ -185,7 +185,7 @@ PyObject* _Py_bytes_islower(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; int cased; @@ -219,7 +219,7 @@ PyObject* _Py_bytes_isupper(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; int cased; @@ -255,7 +255,7 @@ PyObject* _Py_bytes_istitle(const char *cptr, Py_ssize_t len) { const unsigned char *p - = (const unsigned char *) cptr; + = (const unsigned char *) cptr; const unsigned char *e; int cased, previous_is_cased; @@ -362,9 +362,9 @@ and the rest lower-cased."); void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len) { - if (len > 0) { - *result = Py_TOUPPER(*s); - _Py_bytes_lower(result + 1, s + 1, len - 1); + if (len > 0) { + *result = Py_TOUPPER(*s); + _Py_bytes_lower(result + 1, s + 1, len - 1); } } @@ -467,7 +467,7 @@ parse_args_finds_byte(const char *function_name, PyObject *args, return 1; } - if (!_PyIndex_Check(tmp_subobj)) { + if (!_PyIndex_Check(tmp_subobj)) { PyErr_Format(PyExc_TypeError, "argument should be integer or bytes-like object, " "not '%.200s'", @@ -744,7 +744,7 @@ tailmatch(const char *str, Py_ssize_t len, PyObject *substr, if (direction < 0) { /* startswith */ - if (start > len - slen) + if (start > len - slen) goto notfound; } else { /* endswith */ diff --git a/contrib/tools/python3/src/Objects/bytesobject.c b/contrib/tools/python3/src/Objects/bytesobject.c index d34ef53c48..25d9814dd6 100644 --- a/contrib/tools/python3/src/Objects/bytesobject.c +++ b/contrib/tools/python3/src/Objects/bytesobject.c @@ -3,10 +3,10 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" -#include "pycore_object.h" -#include "pycore_pymem.h" // PYMEM_CLEANBYTE +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_bytes_methods.h" +#include "pycore_object.h" +#include "pycore_pymem.h" // PYMEM_CLEANBYTE #include "pystrhex.h" #include <stddef.h> @@ -21,8 +21,8 @@ class bytes "PyBytesObject *" "&PyBytes_Type" static PyBytesObject *characters[UCHAR_MAX + 1]; static PyBytesObject *nullstring; -_Py_IDENTIFIER(__bytes__); - +_Py_IDENTIFIER(__bytes__); + /* PyBytesObject_SIZE gives the basic size of a string; any memory allocation for a string of length n should request PyBytesObject_SIZE + n bytes. @@ -963,8 +963,8 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, if (res == NULL) goto error; } -#ifndef NDEBUG - char *before = res; +#ifndef NDEBUG + char *before = res; #endif /* Write the sign if needed */ @@ -1029,7 +1029,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, } Py_XDECREF(temp); -#ifndef NDEBUG +#ifndef NDEBUG /* check that we computed the exact size for this write */ assert((res - before) == alloc); #endif @@ -1059,7 +1059,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, return NULL; } -/* Unescape a backslash-escaped string. */ +/* Unescape a backslash-escaped string. */ PyObject *_PyBytes_DecodeEscape(const char *s, Py_ssize_t len, const char *errors, @@ -1082,7 +1082,7 @@ PyObject *_PyBytes_DecodeEscape(const char *s, end = s + len; while (s < end) { if (*s != '\\') { - *p++ = *s++; + *p++ = *s++; continue; } @@ -1131,7 +1131,7 @@ PyObject *_PyBytes_DecodeEscape(const char *s, if (!errors || strcmp(errors, "strict") == 0) { PyErr_Format(PyExc_ValueError, - "invalid \\x escape at position %zd", + "invalid \\x escape at position %zd", s - 2 - (end - len)); goto failed; } @@ -1171,11 +1171,11 @@ PyObject *_PyBytes_DecodeEscape(const char *s, PyObject *PyBytes_DecodeEscape(const char *s, Py_ssize_t len, const char *errors, - Py_ssize_t Py_UNUSED(unicode), - const char *Py_UNUSED(recode_encoding)) + Py_ssize_t Py_UNUSED(unicode), + const char *Py_UNUSED(recode_encoding)) { const char* first_invalid_escape; - PyObject *result = _PyBytes_DecodeEscape(s, len, errors, + PyObject *result = _PyBytes_DecodeEscape(s, len, errors, &first_invalid_escape); if (result == NULL) return NULL; @@ -1264,14 +1264,14 @@ PyBytes_Repr(PyObject *obj, int smartquotes) Py_ssize_t i, length = Py_SIZE(op); Py_ssize_t newsize, squotes, dquotes; PyObject *v; - unsigned char quote; - const unsigned char *s; - Py_UCS1 *p; + unsigned char quote; + const unsigned char *s; + Py_UCS1 *p; /* Compute size of output string */ squotes = dquotes = 0; newsize = 3; /* b'' */ - s = (const unsigned char*)op->ob_sval; + s = (const unsigned char*)op->ob_sval; for (i = 0; i < length; i++) { Py_ssize_t incr = 1; switch(s[i]) { @@ -1341,11 +1341,11 @@ bytes_repr(PyObject *op) static PyObject * bytes_str(PyObject *op) { - if (_Py_GetConfig()->bytes_warning) { + if (_Py_GetConfig()->bytes_warning) { if (PyErr_WarnEx(PyExc_BytesWarning, - "str() on a bytes instance", 1)) { + "str() on a bytes instance", 1)) { return NULL; - } + } } return bytes_repr(op); } @@ -1498,7 +1498,7 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op) /* Make sure both arguments are strings. */ if (!(PyBytes_Check(a) && PyBytes_Check(b))) { - if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) { + if (_Py_GetConfig()->bytes_warning && (op == Py_EQ || op == Py_NE)) { rc = PyObject_IsInstance((PyObject*)a, (PyObject*)&PyUnicode_Type); if (!rc) @@ -1579,7 +1579,7 @@ bytes_hash(PyBytesObject *a) static PyObject* bytes_subscript(PyBytesObject* self, PyObject* item) { - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return NULL; @@ -1593,9 +1593,9 @@ bytes_subscript(PyBytesObject* self, PyObject* item) return PyLong_FromLong((unsigned char)self->ob_sval[i]); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength, i; - size_t cur; - const char* source_buf; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; + const char* source_buf; char* result_buf; PyObject* result; @@ -1860,7 +1860,7 @@ Py_LOCAL_INLINE(PyObject *) do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj) { Py_buffer vsep; - const char *s = PyBytes_AS_STRING(self); + const char *s = PyBytes_AS_STRING(self); Py_ssize_t len = PyBytes_GET_SIZE(self); char *sep; Py_ssize_t seplen; @@ -1900,7 +1900,7 @@ do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj) Py_LOCAL_INLINE(PyObject *) do_strip(PyBytesObject *self, int striptype) { - const char *s = PyBytes_AS_STRING(self); + const char *s = PyBytes_AS_STRING(self); Py_ssize_t len = PyBytes_GET_SIZE(self), i, j; i = 0; @@ -1930,7 +1930,7 @@ do_strip(PyBytesObject *self, int striptype) Py_LOCAL_INLINE(PyObject *) do_argstrip(PyBytesObject *self, int striptype, PyObject *bytes) { - if (bytes != Py_None) { + if (bytes != Py_None) { return do_xstrip(self, striptype, bytes); } return do_strip(self, striptype); @@ -2017,8 +2017,8 @@ bytes_translate_impl(PyBytesObject *self, PyObject *table, PyObject *deletechars) /*[clinic end generated code: output=43be3437f1956211 input=0ecdf159f654233c]*/ { - const char *input; - char *output; + const char *input; + char *output; Py_buffer table_view = {NULL, NULL}; Py_buffer del_table_view = {NULL, NULL}; const char *table_chars; @@ -2182,83 +2182,83 @@ bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new, /** End DALKE **/ -/*[clinic input] -bytes.removeprefix as bytes_removeprefix - - prefix: Py_buffer - / - -Return a bytes object with the given prefix string removed if present. - -If the bytes starts with the prefix string, return bytes[len(prefix):]. -Otherwise, return a copy of the original bytes. -[clinic start generated code]*/ - +/*[clinic input] +bytes.removeprefix as bytes_removeprefix + + prefix: Py_buffer + / + +Return a bytes object with the given prefix string removed if present. + +If the bytes starts with the prefix string, return bytes[len(prefix):]. +Otherwise, return a copy of the original bytes. +[clinic start generated code]*/ + +static PyObject * +bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix) +/*[clinic end generated code: output=f006865331a06ab6 input=0c93bac817a8502c]*/ +{ + const char *self_start = PyBytes_AS_STRING(self); + Py_ssize_t self_len = PyBytes_GET_SIZE(self); + const char *prefix_start = prefix->buf; + Py_ssize_t prefix_len = prefix->len; + + if (self_len >= prefix_len + && prefix_len > 0 + && memcmp(self_start, prefix_start, prefix_len) == 0) + { + return PyBytes_FromStringAndSize(self_start + prefix_len, + self_len - prefix_len); + } + + if (PyBytes_CheckExact(self)) { + Py_INCREF(self); + return (PyObject *)self; + } + + return PyBytes_FromStringAndSize(self_start, self_len); +} + +/*[clinic input] +bytes.removesuffix as bytes_removesuffix + + suffix: Py_buffer + / + +Return a bytes object with the given suffix string removed if present. + +If the bytes ends with the suffix string and that suffix is not empty, +return bytes[:-len(prefix)]. Otherwise, return a copy of the original +bytes. +[clinic start generated code]*/ + +static PyObject * +bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix) +/*[clinic end generated code: output=d887d308e3242eeb input=9f4e1da8c637bbf1]*/ +{ + const char *self_start = PyBytes_AS_STRING(self); + Py_ssize_t self_len = PyBytes_GET_SIZE(self); + const char *suffix_start = suffix->buf; + Py_ssize_t suffix_len = suffix->len; + + if (self_len >= suffix_len + && suffix_len > 0 + && memcmp(self_start + self_len - suffix_len, + suffix_start, suffix_len) == 0) + { + return PyBytes_FromStringAndSize(self_start, + self_len - suffix_len); + } + + if (PyBytes_CheckExact(self)) { + Py_INCREF(self); + return (PyObject *)self; + } + + return PyBytes_FromStringAndSize(self_start, self_len); +} + static PyObject * -bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix) -/*[clinic end generated code: output=f006865331a06ab6 input=0c93bac817a8502c]*/ -{ - const char *self_start = PyBytes_AS_STRING(self); - Py_ssize_t self_len = PyBytes_GET_SIZE(self); - const char *prefix_start = prefix->buf; - Py_ssize_t prefix_len = prefix->len; - - if (self_len >= prefix_len - && prefix_len > 0 - && memcmp(self_start, prefix_start, prefix_len) == 0) - { - return PyBytes_FromStringAndSize(self_start + prefix_len, - self_len - prefix_len); - } - - if (PyBytes_CheckExact(self)) { - Py_INCREF(self); - return (PyObject *)self; - } - - return PyBytes_FromStringAndSize(self_start, self_len); -} - -/*[clinic input] -bytes.removesuffix as bytes_removesuffix - - suffix: Py_buffer - / - -Return a bytes object with the given suffix string removed if present. - -If the bytes ends with the suffix string and that suffix is not empty, -return bytes[:-len(prefix)]. Otherwise, return a copy of the original -bytes. -[clinic start generated code]*/ - -static PyObject * -bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix) -/*[clinic end generated code: output=d887d308e3242eeb input=9f4e1da8c637bbf1]*/ -{ - const char *self_start = PyBytes_AS_STRING(self); - Py_ssize_t self_len = PyBytes_GET_SIZE(self); - const char *suffix_start = suffix->buf; - Py_ssize_t suffix_len = suffix->len; - - if (self_len >= suffix_len - && suffix_len > 0 - && memcmp(self_start + self_len - suffix_len, - suffix_start, suffix_len) == 0) - { - return PyBytes_FromStringAndSize(self_start, - self_len - suffix_len); - } - - if (PyBytes_CheckExact(self)) { - Py_INCREF(self); - return (PyObject *)self; - } - - return PyBytes_FromStringAndSize(self_start, self_len); -} - -static PyObject * bytes_startswith(PyBytesObject *self, PyObject *args) { return _Py_bytes_startswith(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args); @@ -2335,7 +2335,7 @@ bytes_fromhex_impl(PyTypeObject *type, PyObject *string) { PyObject *result = _PyBytes_FromHex(string, 0); if (type != &PyBytes_Type && result != NULL) { - Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); + Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); } return result; } @@ -2346,7 +2346,7 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray) char *buf; Py_ssize_t hexlen, invalid_char; unsigned int top, bot; - const Py_UCS1 *str, *end; + const Py_UCS1 *str, *end; _PyBytesWriter writer; _PyBytesWriter_Init(&writer); @@ -2358,7 +2358,7 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray) hexlen = PyUnicode_GET_LENGTH(string); if (!PyUnicode_IS_ASCII(string)) { - const void *data = PyUnicode_DATA(string); + const void *data = PyUnicode_DATA(string); unsigned int kind = PyUnicode_KIND(string); Py_ssize_t i; @@ -2417,40 +2417,40 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray) return NULL; } -/*[clinic input] -bytes.hex - - sep: object = NULL - An optional single character or byte to separate hex bytes. - bytes_per_sep: int = 1 - How many bytes between separators. Positive values count from the - right, negative values count from the left. - -Create a str of hexadecimal numbers from a bytes object. - -Example: ->>> value = b'\xb9\x01\xef' ->>> value.hex() -'b901ef' ->>> value.hex(':') -'b9:01:ef' ->>> value.hex(':', 2) -'b9:01ef' ->>> value.hex(':', -2) -'b901:ef' -[clinic start generated code]*/ - +/*[clinic input] +bytes.hex + + sep: object = NULL + An optional single character or byte to separate hex bytes. + bytes_per_sep: int = 1 + How many bytes between separators. Positive values count from the + right, negative values count from the left. + +Create a str of hexadecimal numbers from a bytes object. + +Example: +>>> value = b'\xb9\x01\xef' +>>> value.hex() +'b901ef' +>>> value.hex(':') +'b9:01:ef' +>>> value.hex(':', 2) +'b9:01ef' +>>> value.hex(':', -2) +'b901:ef' +[clinic start generated code]*/ + static PyObject * -bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep) -/*[clinic end generated code: output=1f134da504064139 input=f1238d3455990218]*/ +bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep) +/*[clinic end generated code: output=1f134da504064139 input=f1238d3455990218]*/ { - const char *argbuf = PyBytes_AS_STRING(self); + const char *argbuf = PyBytes_AS_STRING(self); Py_ssize_t arglen = PyBytes_GET_SIZE(self); - return _Py_strhex_with_sep(argbuf, arglen, sep, bytes_per_sep); + return _Py_strhex_with_sep(argbuf, arglen, sep, bytes_per_sep); } static PyObject * -bytes_getnewargs(PyBytesObject *v, PyObject *Py_UNUSED(ignored)) +bytes_getnewargs(PyBytesObject *v, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("(y#)", v->ob_sval, Py_SIZE(v)); } @@ -2459,48 +2459,48 @@ bytes_getnewargs(PyBytesObject *v, PyObject *Py_UNUSED(ignored)) static PyMethodDef bytes_methods[] = { {"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS}, - {"capitalize", stringlib_capitalize, METH_NOARGS, + {"capitalize", stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, - STRINGLIB_CENTER_METHODDEF + STRINGLIB_CENTER_METHODDEF {"count", (PyCFunction)bytes_count, METH_VARARGS, _Py_count__doc__}, BYTES_DECODE_METHODDEF {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, _Py_endswith__doc__}, - STRINGLIB_EXPANDTABS_METHODDEF + STRINGLIB_EXPANDTABS_METHODDEF {"find", (PyCFunction)bytes_find, METH_VARARGS, _Py_find__doc__}, BYTES_FROMHEX_METHODDEF - BYTES_HEX_METHODDEF + BYTES_HEX_METHODDEF {"index", (PyCFunction)bytes_index, METH_VARARGS, _Py_index__doc__}, - {"isalnum", stringlib_isalnum, METH_NOARGS, + {"isalnum", stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, - {"isalpha", stringlib_isalpha, METH_NOARGS, + {"isalpha", stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, - {"isascii", stringlib_isascii, METH_NOARGS, + {"isascii", stringlib_isascii, METH_NOARGS, _Py_isascii__doc__}, - {"isdigit", stringlib_isdigit, METH_NOARGS, + {"isdigit", stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, - {"islower", stringlib_islower, METH_NOARGS, + {"islower", stringlib_islower, METH_NOARGS, _Py_islower__doc__}, - {"isspace", stringlib_isspace, METH_NOARGS, + {"isspace", stringlib_isspace, METH_NOARGS, _Py_isspace__doc__}, - {"istitle", stringlib_istitle, METH_NOARGS, + {"istitle", stringlib_istitle, METH_NOARGS, _Py_istitle__doc__}, - {"isupper", stringlib_isupper, METH_NOARGS, + {"isupper", stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, BYTES_JOIN_METHODDEF - STRINGLIB_LJUST_METHODDEF - {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, + STRINGLIB_LJUST_METHODDEF + {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, BYTES_LSTRIP_METHODDEF BYTES_MAKETRANS_METHODDEF BYTES_PARTITION_METHODDEF BYTES_REPLACE_METHODDEF - BYTES_REMOVEPREFIX_METHODDEF - BYTES_REMOVESUFFIX_METHODDEF + BYTES_REMOVEPREFIX_METHODDEF + BYTES_REMOVESUFFIX_METHODDEF {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, _Py_rfind__doc__}, {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, _Py_rindex__doc__}, - STRINGLIB_RJUST_METHODDEF + STRINGLIB_RJUST_METHODDEF BYTES_RPARTITION_METHODDEF BYTES_RSPLIT_METHODDEF BYTES_RSTRIP_METHODDEF @@ -2509,12 +2509,12 @@ bytes_methods[] = { {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS, _Py_startswith__doc__}, BYTES_STRIP_METHODDEF - {"swapcase", stringlib_swapcase, METH_NOARGS, + {"swapcase", stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, - {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, + {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, BYTES_TRANSLATE_METHODDEF - {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, - STRINGLIB_ZFILL_METHODDEF + {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, + STRINGLIB_ZFILL_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -2557,9 +2557,9 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (x == NULL) { if (encoding != NULL || errors != NULL) { PyErr_SetString(PyExc_TypeError, - encoding != NULL ? - "encoding without a string argument" : - "errors without a string argument"); + encoding != NULL ? + "encoding without a string argument" : + "errors without a string argument"); return NULL; } return PyBytes_FromStringAndSize(NULL, 0); @@ -2614,7 +2614,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } /* Is it an integer? */ - if (_PyIndex_Check(x)) { + if (_PyIndex_Check(x)) { size = PyNumber_AsSsize_t(x, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { if (!PyErr_ExceptionMatches(PyExc_TypeError)) @@ -2840,7 +2840,7 @@ PyBytes_FromObject(PyObject *x) PyErr_Format(PyExc_TypeError, "cannot convert '%.200s' object to bytes", - Py_TYPE(x)->tp_name); + Py_TYPE(x)->tp_name); return NULL; } @@ -2887,11 +2887,11 @@ PyTypeObject PyBytes_Type = { "bytes", PyBytesObject_SIZE, sizeof(char), - 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)bytes_repr, /* tp_repr */ &bytes_as_number, /* tp_as_number */ &bytes_as_sequence, /* tp_as_sequence */ @@ -3026,12 +3026,12 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) return (*pv == NULL) ? -1 : 0; } /* XXX UNREF/NEWREF interface should be more symmetrical */ -#ifdef Py_REF_DEBUG - _Py_RefTotal--; -#endif -#ifdef Py_TRACE_REFS +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif +#ifdef Py_TRACE_REFS _Py_ForgetReference(v); -#endif +#endif *pv = (PyObject *) PyObject_REALLOC(v, PyBytesObject_SIZE + newsize); if (*pv == NULL) { @@ -3041,7 +3041,7 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) } _Py_NewReference(*pv); sv = (PyBytesObject *) *pv; - Py_SET_SIZE(sv, newsize); + Py_SET_SIZE(sv, newsize); sv->ob_sval[newsize] = '\0'; sv->ob_shash = -1; /* invalidate cached hash value */ return 0; @@ -3053,7 +3053,7 @@ error: } void -_PyBytes_Fini(void) +_PyBytes_Fini(void) { int i; for (i = 0; i < UCHAR_MAX + 1; i++) @@ -3110,7 +3110,7 @@ striter_next(striterobject *it) } static PyObject * -striter_len(striterobject *it, PyObject *Py_UNUSED(ignored)) +striter_len(striterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -3122,14 +3122,14 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) +striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); } } @@ -3170,10 +3170,10 @@ PyTypeObject PyBytesIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)striter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3231,9 +3231,9 @@ _PyBytesWriter_Init(_PyBytesWriter *writer) { /* Set all attributes before small_buffer to 0 */ memset(writer, 0, offsetof(_PyBytesWriter, small_buffer)); -#ifndef NDEBUG - memset(writer->small_buffer, PYMEM_CLEANBYTE, - sizeof(writer->small_buffer)); +#ifndef NDEBUG + memset(writer->small_buffer, PYMEM_CLEANBYTE, + sizeof(writer->small_buffer)); #endif } @@ -3263,18 +3263,18 @@ _PyBytesWriter_AsString(_PyBytesWriter *writer) Py_LOCAL_INLINE(Py_ssize_t) _PyBytesWriter_GetSize(_PyBytesWriter *writer, char *str) { - const char *start = _PyBytesWriter_AsString(writer); + const char *start = _PyBytesWriter_AsString(writer); assert(str != NULL); assert(str >= start); assert(str - start <= writer->allocated); return str - start; } -#ifndef NDEBUG -Py_LOCAL_INLINE(int) +#ifndef NDEBUG +Py_LOCAL_INLINE(int) _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str) { - const char *start, *end; + const char *start, *end; if (writer->use_small_buffer) { assert(writer->buffer == NULL); @@ -3303,8 +3303,8 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str) end = start + writer->allocated; assert(str != NULL); assert(start <= str && str <= end); - return 1; -} + return 1; +} #endif void* @@ -3312,7 +3312,7 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size) { Py_ssize_t allocated, pos; - assert(_PyBytesWriter_CheckConsistency(writer, str)); + assert(_PyBytesWriter_CheckConsistency(writer, str)); assert(writer->allocated < size); allocated = size; @@ -3361,15 +3361,15 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size) } writer->use_small_buffer = 0; -#ifndef NDEBUG - memset(writer->small_buffer, PYMEM_CLEANBYTE, - sizeof(writer->small_buffer)); +#ifndef NDEBUG + memset(writer->small_buffer, PYMEM_CLEANBYTE, + sizeof(writer->small_buffer)); #endif } writer->allocated = allocated; str = _PyBytesWriter_AsString(writer) + pos; - assert(_PyBytesWriter_CheckConsistency(writer, str)); + assert(_PyBytesWriter_CheckConsistency(writer, str)); return str; error: @@ -3382,7 +3382,7 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size) { Py_ssize_t new_min_size; - assert(_PyBytesWriter_CheckConsistency(writer, str)); + assert(_PyBytesWriter_CheckConsistency(writer, str)); assert(size >= 0); if (size == 0) { @@ -3415,7 +3415,7 @@ _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size) assert(size >= 0); writer->use_small_buffer = 1; -#ifndef NDEBUG +#ifndef NDEBUG writer->allocated = sizeof(writer->small_buffer) - 1; /* In debug mode, don't use the full small buffer because it is less efficient than bytes and bytearray objects to detect buffer underflow @@ -3443,7 +3443,7 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str) Py_ssize_t size; PyObject *result; - assert(_PyBytesWriter_CheckConsistency(writer, str)); + assert(_PyBytesWriter_CheckConsistency(writer, str)); size = _PyBytesWriter_GetSize(writer, str); if (size == 0 && !writer->use_bytearray) { diff --git a/contrib/tools/python3/src/Objects/call.c b/contrib/tools/python3/src/Objects/call.c index 84400176dd..87dc0dbbdb 100644 --- a/contrib/tools/python3/src/Objects/call.c +++ b/contrib/tools/python3/src/Objects/call.c @@ -1,75 +1,75 @@ #include "Python.h" -#include "pycore_call.h" -#include "pycore_ceval.h" // _PyEval_EvalFrame() -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" +#include "pycore_call.h" +#include "pycore_ceval.h" // _PyEval_EvalFrame() +#include "pycore_object.h" +#include "pycore_pyerrors.h" +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_tupleobject.h" #include "frameobject.h" -static PyObject *const * -_PyStack_UnpackDict(PyThreadState *tstate, - PyObject *const *args, Py_ssize_t nargs, - PyObject *kwargs, PyObject **p_kwnames); +static PyObject *const * +_PyStack_UnpackDict(PyThreadState *tstate, + PyObject *const *args, Py_ssize_t nargs, + PyObject *kwargs, PyObject **p_kwnames); + +static void +_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs, + PyObject *kwnames); -static void -_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs, - PyObject *kwnames); - static PyObject * -null_error(PyThreadState *tstate) +null_error(PyThreadState *tstate) { - if (!_PyErr_Occurred(tstate)) { - _PyErr_SetString(tstate, PyExc_SystemError, - "null argument to internal routine"); - } + if (!_PyErr_Occurred(tstate)) { + _PyErr_SetString(tstate, PyExc_SystemError, + "null argument to internal routine"); + } return NULL; } PyObject* -_Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable, - PyObject *result, const char *where) +_Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable, + PyObject *result, const char *where) { assert((callable != NULL) ^ (where != NULL)); if (result == NULL) { - if (!_PyErr_Occurred(tstate)) { + if (!_PyErr_Occurred(tstate)) { if (callable) - _PyErr_Format(tstate, PyExc_SystemError, - "%R returned NULL without setting an error", - callable); + _PyErr_Format(tstate, PyExc_SystemError, + "%R returned NULL without setting an error", + callable); else - _PyErr_Format(tstate, PyExc_SystemError, - "%s returned NULL without setting an error", - where); + _PyErr_Format(tstate, PyExc_SystemError, + "%s returned NULL without setting an error", + where); #ifdef Py_DEBUG - /* Ensure that the bug is caught in debug mode. - Py_FatalError() logs the SystemError exception raised above. */ + /* Ensure that the bug is caught in debug mode. + Py_FatalError() logs the SystemError exception raised above. */ Py_FatalError("a function returned NULL without setting an error"); #endif return NULL; } } else { - if (_PyErr_Occurred(tstate)) { + if (_PyErr_Occurred(tstate)) { Py_DECREF(result); if (callable) { - _PyErr_FormatFromCauseTstate( - tstate, PyExc_SystemError, - "%R returned a result with an error set", callable); + _PyErr_FormatFromCauseTstate( + tstate, PyExc_SystemError, + "%R returned a result with an error set", callable); } else { - _PyErr_FormatFromCauseTstate( - tstate, PyExc_SystemError, - "%s returned a result with an error set", where); + _PyErr_FormatFromCauseTstate( + tstate, PyExc_SystemError, + "%s returned a result with an error set", where); } #ifdef Py_DEBUG - /* Ensure that the bug is caught in debug mode. - Py_FatalError() logs the SystemError exception raised above. */ + /* Ensure that the bug is caught in debug mode. + Py_FatalError() logs the SystemError exception raised above. */ Py_FatalError("a function returned a result with an error set"); #endif return NULL; @@ -81,176 +81,176 @@ _Py_CheckFunctionResult(PyThreadState *tstate, PyObject *callable, /* --- Core PyObject call functions ------------------------------- */ -/* Call a callable Python object without any arguments */ +/* Call a callable Python object without any arguments */ +PyObject * +PyObject_CallNoArgs(PyObject *func) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyObject_CallNoArgTstate(tstate, func); +} + + PyObject * -PyObject_CallNoArgs(PyObject *func) +_PyObject_FastCallDictTstate(PyThreadState *tstate, PyObject *callable, + PyObject *const *args, size_t nargsf, + PyObject *kwargs) { - PyThreadState *tstate = _PyThreadState_GET(); - return _PyObject_CallNoArgTstate(tstate, func); -} - - -PyObject * -_PyObject_FastCallDictTstate(PyThreadState *tstate, PyObject *callable, - PyObject *const *args, size_t nargsf, - PyObject *kwargs) -{ - assert(callable != NULL); - - /* PyObject_VectorcallDict() must not be called with an exception set, + assert(callable != NULL); + + /* PyObject_VectorcallDict() must not be called with an exception set, because it can clear it (directly or indirectly) and so the caller loses its exception */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); assert(nargs >= 0); assert(nargs == 0 || args != NULL); assert(kwargs == NULL || PyDict_Check(kwargs)); - vectorcallfunc func = PyVectorcall_Function(callable); - if (func == NULL) { - /* Use tp_call instead */ - return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs); + vectorcallfunc func = PyVectorcall_Function(callable); + if (func == NULL) { + /* Use tp_call instead */ + return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs); } - - PyObject *res; - if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) { - res = func(callable, args, nargsf, NULL); + + PyObject *res; + if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) { + res = func(callable, args, nargsf, NULL); } else { - PyObject *kwnames; - PyObject *const *newargs; - newargs = _PyStack_UnpackDict(tstate, - args, nargs, - kwargs, &kwnames); - if (newargs == NULL) { + PyObject *kwnames; + PyObject *const *newargs; + newargs = _PyStack_UnpackDict(tstate, + args, nargs, + kwargs, &kwnames); + if (newargs == NULL) { return NULL; } - res = func(callable, newargs, - nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames); - _PyStack_UnpackDict_Free(newargs, nargs, kwnames); + res = func(callable, newargs, + nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames); + _PyStack_UnpackDict_Free(newargs, nargs, kwnames); } - return _Py_CheckFunctionResult(tstate, callable, res, NULL); + return _Py_CheckFunctionResult(tstate, callable, res, NULL); +} + + +PyObject * +PyObject_VectorcallDict(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwargs) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyObject_FastCallDictTstate(tstate, callable, args, nargsf, kwargs); } PyObject * -PyObject_VectorcallDict(PyObject *callable, PyObject *const *args, - size_t nargsf, PyObject *kwargs) +_PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable, + PyObject *const *args, Py_ssize_t nargs, + PyObject *keywords) { - PyThreadState *tstate = _PyThreadState_GET(); - return _PyObject_FastCallDictTstate(tstate, callable, args, nargsf, kwargs); -} - - -PyObject * -_PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable, - PyObject *const *args, Py_ssize_t nargs, - PyObject *keywords) -{ - assert(nargs >= 0); - assert(nargs == 0 || args != NULL); - assert(keywords == NULL || PyTuple_Check(keywords) || PyDict_Check(keywords)); - - /* Slow path: build a temporary tuple for positional arguments and a - * temporary dictionary for keyword arguments (if any) */ - ternaryfunc call = Py_TYPE(callable)->tp_call; - if (call == NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "'%.200s' object is not callable", - Py_TYPE(callable)->tp_name); - return NULL; - } - - PyObject *argstuple = _PyTuple_FromArray(args, nargs); - if (argstuple == NULL) { - return NULL; - } - - PyObject *kwdict; - if (keywords == NULL || PyDict_Check(keywords)) { - kwdict = keywords; + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + assert(keywords == NULL || PyTuple_Check(keywords) || PyDict_Check(keywords)); + + /* Slow path: build a temporary tuple for positional arguments and a + * temporary dictionary for keyword arguments (if any) */ + ternaryfunc call = Py_TYPE(callable)->tp_call; + if (call == NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "'%.200s' object is not callable", + Py_TYPE(callable)->tp_name); + return NULL; + } + + PyObject *argstuple = _PyTuple_FromArray(args, nargs); + if (argstuple == NULL) { + return NULL; + } + + PyObject *kwdict; + if (keywords == NULL || PyDict_Check(keywords)) { + kwdict = keywords; } else { - if (PyTuple_GET_SIZE(keywords)) { - assert(args != NULL); - kwdict = _PyStack_AsDict(args + nargs, keywords); + if (PyTuple_GET_SIZE(keywords)) { + assert(args != NULL); + kwdict = _PyStack_AsDict(args + nargs, keywords); if (kwdict == NULL) { Py_DECREF(argstuple); return NULL; } } else { - keywords = kwdict = NULL; + keywords = kwdict = NULL; } - } - - PyObject *result = NULL; - if (_Py_EnterRecursiveCall(tstate, " while calling a Python object") == 0) - { - result = call(callable, argstuple, kwdict); - _Py_LeaveRecursiveCall(tstate); - } - - Py_DECREF(argstuple); - if (kwdict != keywords) { - Py_DECREF(kwdict); - } - - return _Py_CheckFunctionResult(tstate, callable, result, NULL); -} - - -PyObject * -PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs) -{ - PyThreadState *tstate = _PyThreadState_GET(); - vectorcallfunc func; - - /* get vectorcallfunc as in PyVectorcall_Function, but without - * the Py_TPFLAGS_HAVE_VECTORCALL check */ - Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset; - if (offset <= 0) { - _PyErr_Format(tstate, PyExc_TypeError, - "'%.200s' object does not support vectorcall", - Py_TYPE(callable)->tp_name); - return NULL; - } - memcpy(&func, (char *) callable + offset, sizeof(func)); - if (func == NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "'%.200s' object does not support vectorcall", - Py_TYPE(callable)->tp_name); - return NULL; - } - - Py_ssize_t nargs = PyTuple_GET_SIZE(tuple); - - /* Fast path for no keywords */ - if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) { - return func(callable, _PyTuple_ITEMS(tuple), nargs, NULL); - } - - /* Convert arguments & call */ - PyObject *const *args; - PyObject *kwnames; - args = _PyStack_UnpackDict(tstate, - _PyTuple_ITEMS(tuple), nargs, - kwargs, &kwnames); - if (args == NULL) { - return NULL; - } - PyObject *result = func(callable, args, - nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames); - _PyStack_UnpackDict_Free(args, nargs, kwnames); - - return _Py_CheckFunctionResult(tstate, callable, result, NULL); + } + + PyObject *result = NULL; + if (_Py_EnterRecursiveCall(tstate, " while calling a Python object") == 0) + { + result = call(callable, argstuple, kwdict); + _Py_LeaveRecursiveCall(tstate); + } + + Py_DECREF(argstuple); + if (kwdict != keywords) { + Py_DECREF(kwdict); + } + + return _Py_CheckFunctionResult(tstate, callable, result, NULL); } PyObject * -_PyObject_Call(PyThreadState *tstate, PyObject *callable, - PyObject *args, PyObject *kwargs) +PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs) +{ + PyThreadState *tstate = _PyThreadState_GET(); + vectorcallfunc func; + + /* get vectorcallfunc as in PyVectorcall_Function, but without + * the Py_TPFLAGS_HAVE_VECTORCALL check */ + Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset; + if (offset <= 0) { + _PyErr_Format(tstate, PyExc_TypeError, + "'%.200s' object does not support vectorcall", + Py_TYPE(callable)->tp_name); + return NULL; + } + memcpy(&func, (char *) callable + offset, sizeof(func)); + if (func == NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "'%.200s' object does not support vectorcall", + Py_TYPE(callable)->tp_name); + return NULL; + } + + Py_ssize_t nargs = PyTuple_GET_SIZE(tuple); + + /* Fast path for no keywords */ + if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) { + return func(callable, _PyTuple_ITEMS(tuple), nargs, NULL); + } + + /* Convert arguments & call */ + PyObject *const *args; + PyObject *kwnames; + args = _PyStack_UnpackDict(tstate, + _PyTuple_ITEMS(tuple), nargs, + kwargs, &kwnames); + if (args == NULL) { + return NULL; + } + PyObject *result = func(callable, args, + nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames); + _PyStack_UnpackDict_Free(args, nargs, kwnames); + + return _Py_CheckFunctionResult(tstate, callable, result, NULL); +} + + +PyObject * +_PyObject_Call(PyThreadState *tstate, PyObject *callable, + PyObject *args, PyObject *kwargs) { ternaryfunc call; PyObject *result; @@ -258,76 +258,76 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable, /* PyObject_Call() must not be called with an exception set, because it can clear it (directly or indirectly) and so the caller loses its exception */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); assert(PyTuple_Check(args)); assert(kwargs == NULL || PyDict_Check(kwargs)); - if (PyVectorcall_Function(callable) != NULL) { - return PyVectorcall_Call(callable, args, kwargs); + if (PyVectorcall_Function(callable) != NULL) { + return PyVectorcall_Call(callable, args, kwargs); } else { - call = Py_TYPE(callable)->tp_call; + call = Py_TYPE(callable)->tp_call; if (call == NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "'%.200s' object is not callable", - Py_TYPE(callable)->tp_name); + _PyErr_Format(tstate, PyExc_TypeError, + "'%.200s' object is not callable", + Py_TYPE(callable)->tp_name); return NULL; } - if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { + if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { return NULL; - } + } result = (*call)(callable, args, kwargs); - _Py_LeaveRecursiveCall(tstate); + _Py_LeaveRecursiveCall(tstate); - return _Py_CheckFunctionResult(tstate, callable, result, NULL); + return _Py_CheckFunctionResult(tstate, callable, result, NULL); } } -PyObject * -PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs) -{ - PyThreadState *tstate = _PyThreadState_GET(); - return _PyObject_Call(tstate, callable, args, kwargs); -} - - -PyObject * -PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs) -{ - PyThreadState *tstate = _PyThreadState_GET(); - return _PyObject_Call(tstate, callable, args, kwargs); -} - - +PyObject * +PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyObject_Call(tstate, callable, args, kwargs); +} + + +PyObject * +PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyObject_Call(tstate, callable, args, kwargs); +} + + /* --- PyFunction call functions ---------------------------------- */ static PyObject* _Py_HOT_FUNCTION -function_code_fastcall(PyThreadState *tstate, PyCodeObject *co, - PyObject *const *args, Py_ssize_t nargs, +function_code_fastcall(PyThreadState *tstate, PyCodeObject *co, + PyObject *const *args, Py_ssize_t nargs, PyObject *globals) { - assert(tstate != NULL); - assert(globals != NULL); + assert(tstate != NULL); + assert(globals != NULL); /* XXX Perhaps we should create a specialized _PyFrame_New_NoTrack() that doesn't take locals, but does take builtins without sanity checking them. */ - PyFrameObject *f = _PyFrame_New_NoTrack(tstate, co, globals, NULL); + PyFrameObject *f = _PyFrame_New_NoTrack(tstate, co, globals, NULL); if (f == NULL) { return NULL; } - PyObject **fastlocals = f->f_localsplus; + PyObject **fastlocals = f->f_localsplus; - for (Py_ssize_t i = 0; i < nargs; i++) { + for (Py_ssize_t i = 0; i < nargs; i++) { Py_INCREF(*args); fastlocals[i] = *args++; } - PyObject *result = _PyEval_EvalFrame(tstate, f, 0); + PyObject *result = _PyEval_EvalFrame(tstate, f, 0); if (Py_REFCNT(f) > 1) { Py_DECREF(f); @@ -343,19 +343,19 @@ function_code_fastcall(PyThreadState *tstate, PyCodeObject *co, PyObject * -_PyFunction_Vectorcall(PyObject *func, PyObject* const* stack, - size_t nargsf, PyObject *kwnames) +_PyFunction_Vectorcall(PyObject *func, PyObject* const* stack, + size_t nargsf, PyObject *kwnames) { - assert(PyFunction_Check(func)); - assert(kwnames == NULL || PyTuple_CheckExact(kwnames)); + assert(PyFunction_Check(func)); + assert(kwnames == NULL || PyTuple_CheckExact(kwnames)); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); assert(nargs >= 0); - Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); - assert((nargs == 0 && nkwargs == 0) || stack != NULL); - /* kwnames must only contain strings and all keys must be unique */ + Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); + assert((nargs == 0 && nkwargs == 0) || stack != NULL); + /* kwnames must only contain strings and all keys must be unique */ - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *argdefs = PyFunction_GET_DEFAULTS(func); @@ -364,43 +364,43 @@ _PyFunction_Vectorcall(PyObject *func, PyObject* const* stack, (co->co_flags & ~PyCF_MASK) == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { if (argdefs == NULL && co->co_argcount == nargs) { - return function_code_fastcall(tstate, co, stack, nargs, globals); + return function_code_fastcall(tstate, co, stack, nargs, globals); } else if (nargs == 0 && argdefs != NULL && co->co_argcount == PyTuple_GET_SIZE(argdefs)) { /* function called with no arguments, but all parameters have a default value: use default values as arguments .*/ - stack = _PyTuple_ITEMS(argdefs); - return function_code_fastcall(tstate, co, - stack, PyTuple_GET_SIZE(argdefs), + stack = _PyTuple_ITEMS(argdefs); + return function_code_fastcall(tstate, co, + stack, PyTuple_GET_SIZE(argdefs), globals); } } - PyObject *kwdefs = PyFunction_GET_KW_DEFAULTS(func); - PyObject *closure = PyFunction_GET_CLOSURE(func); - PyObject *name = ((PyFunctionObject *)func) -> func_name; - PyObject *qualname = ((PyFunctionObject *)func) -> func_qualname; + PyObject *kwdefs = PyFunction_GET_KW_DEFAULTS(func); + PyObject *closure = PyFunction_GET_CLOSURE(func); + PyObject *name = ((PyFunctionObject *)func) -> func_name; + PyObject *qualname = ((PyFunctionObject *)func) -> func_qualname; - PyObject **d; - Py_ssize_t nd; + PyObject **d; + Py_ssize_t nd; if (argdefs != NULL) { - d = _PyTuple_ITEMS(argdefs); + d = _PyTuple_ITEMS(argdefs); nd = PyTuple_GET_SIZE(argdefs); - assert(nd <= INT_MAX); + assert(nd <= INT_MAX); } else { d = NULL; nd = 0; } - return _PyEval_EvalCode(tstate, - (PyObject*)co, globals, (PyObject *)NULL, - stack, nargs, - nkwargs ? _PyTuple_ITEMS(kwnames) : NULL, - stack + nargs, - nkwargs, 1, - d, (int)nd, kwdefs, - closure, name, qualname); + return _PyEval_EvalCode(tstate, + (PyObject*)co, globals, (PyObject *)NULL, + stack, nargs, + nkwargs ? _PyTuple_ITEMS(kwnames) : NULL, + stack + nargs, + nkwargs, 1, + d, (int)nd, kwdefs, + closure, name, qualname); } @@ -412,31 +412,31 @@ PyObject * PyEval_CallObjectWithKeywords(PyObject *callable, PyObject *args, PyObject *kwargs) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); #ifdef Py_DEBUG /* PyEval_CallObjectWithKeywords() must not be called with an exception set. It raises a new exception if parameters are invalid or if PyTuple_New() fails, and so the original exception is lost. */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); #endif if (args != NULL && !PyTuple_Check(args)) { - _PyErr_SetString(tstate, PyExc_TypeError, - "argument list must be a tuple"); + _PyErr_SetString(tstate, PyExc_TypeError, + "argument list must be a tuple"); return NULL; } if (kwargs != NULL && !PyDict_Check(kwargs)) { - _PyErr_SetString(tstate, PyExc_TypeError, - "keyword list must be a dictionary"); + _PyErr_SetString(tstate, PyExc_TypeError, + "keyword list must be a dictionary"); return NULL; } if (args == NULL) { - return _PyObject_FastCallDictTstate(tstate, callable, NULL, 0, kwargs); + return _PyObject_FastCallDictTstate(tstate, callable, NULL, 0, kwargs); } else { - return _PyObject_Call(tstate, callable, args, kwargs); + return _PyObject_Call(tstate, callable, args, kwargs); } } @@ -444,31 +444,31 @@ PyEval_CallObjectWithKeywords(PyObject *callable, PyObject * PyObject_CallObject(PyObject *callable, PyObject *args) { - PyThreadState *tstate = _PyThreadState_GET(); - assert(!_PyErr_Occurred(tstate)); - if (args == NULL) { - return _PyObject_CallNoArgTstate(tstate, callable); + PyThreadState *tstate = _PyThreadState_GET(); + assert(!_PyErr_Occurred(tstate)); + if (args == NULL) { + return _PyObject_CallNoArgTstate(tstate, callable); } - if (!PyTuple_Check(args)) { - _PyErr_SetString(tstate, PyExc_TypeError, - "argument list must be a tuple"); - return NULL; + if (!PyTuple_Check(args)) { + _PyErr_SetString(tstate, PyExc_TypeError, + "argument list must be a tuple"); + return NULL; } - return _PyObject_Call(tstate, callable, args, NULL); + return _PyObject_Call(tstate, callable, args, NULL); } /* Call callable(obj, *args, **kwargs). */ PyObject * -_PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable, +_PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable, PyObject *obj, PyObject *args, PyObject *kwargs) { - assert(PyTuple_Check(args)); - + assert(PyTuple_Check(args)); + PyObject *small_stack[_PY_FASTCALL_SMALL_STACK]; PyObject **stack; - Py_ssize_t argcount = PyTuple_GET_SIZE(args); + Py_ssize_t argcount = PyTuple_GET_SIZE(args); if (argcount + 1 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) { stack = small_stack; } @@ -483,12 +483,12 @@ _PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable, /* use borrowed references */ stack[0] = obj; memcpy(&stack[1], - _PyTuple_ITEMS(args), - argcount * sizeof(PyObject *)); + _PyTuple_ITEMS(args), + argcount * sizeof(PyObject *)); - PyObject *result = _PyObject_FastCallDictTstate(tstate, callable, - stack, argcount + 1, - kwargs); + PyObject *result = _PyObject_FastCallDictTstate(tstate, callable, + stack, argcount + 1, + kwargs); if (stack != small_stack) { PyMem_Free(stack); } @@ -499,8 +499,8 @@ _PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable, /* --- Call with a format string ---------------------------------- */ static PyObject * -_PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable, - const char *format, va_list va, int is_size_t) +_PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable, + const char *format, va_list va, int is_size_t) { PyObject* small_stack[_PY_FASTCALL_SMALL_STACK]; const Py_ssize_t small_stack_len = Py_ARRAY_LENGTH(small_stack); @@ -509,11 +509,11 @@ _PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable, PyObject *result; if (callable == NULL) { - return null_error(tstate); + return null_error(tstate); } if (!format || !*format) { - return _PyObject_CallNoArgTstate(tstate, callable); + return _PyObject_CallNoArgTstate(tstate, callable); } if (is_size_t) { @@ -534,14 +534,14 @@ _PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable, - PyObject_CallFunction(func, "(OOO)", arg1, arg2, arg3) calls func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */ PyObject *args = stack[0]; - result = _PyObject_VectorcallTstate(tstate, callable, - _PyTuple_ITEMS(args), - PyTuple_GET_SIZE(args), - NULL); + result = _PyObject_VectorcallTstate(tstate, callable, + _PyTuple_ITEMS(args), + PyTuple_GET_SIZE(args), + NULL); } else { - result = _PyObject_VectorcallTstate(tstate, callable, - stack, nargs, NULL); + result = _PyObject_VectorcallTstate(tstate, callable, + stack, nargs, NULL); } for (i = 0; i < nargs; ++i) { @@ -559,10 +559,10 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...) { va_list va; PyObject *result; - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); va_start(va, format); - result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0); + result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0); va_end(va); return result; @@ -577,10 +577,10 @@ PyEval_CallFunction(PyObject *callable, const char *format, ...) { va_list va; PyObject *result; - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); va_start(va, format); - result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0); + result = _PyObject_CallFunctionVa(tstate, callable, format, va, 0); va_end(va); return result; @@ -590,11 +590,11 @@ PyEval_CallFunction(PyObject *callable, const char *format, ...) PyObject * _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); - + PyThreadState *tstate = _PyThreadState_GET(); + va_list va; va_start(va, format); - PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va, 1); + PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va, 1); va_end(va); return result; @@ -602,37 +602,37 @@ _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) static PyObject* -callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_list va, int is_size_t) +callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_list va, int is_size_t) { assert(callable != NULL); if (!PyCallable_Check(callable)) { - _PyErr_Format(tstate, PyExc_TypeError, - "attribute of type '%.200s' is not callable", - Py_TYPE(callable)->tp_name); + _PyErr_Format(tstate, PyExc_TypeError, + "attribute of type '%.200s' is not callable", + Py_TYPE(callable)->tp_name); return NULL; } - return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t); + return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t); } PyObject * PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *callable = PyObject_GetAttrString(obj, name); - if (callable == NULL) { + PyObject *callable = PyObject_GetAttrString(obj, name); + if (callable == NULL) { return NULL; - } + } - va_list va; + va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 0); + PyObject *retval = callmethod(tstate, callable, format, va, 0); va_end(va); Py_DECREF(callable); @@ -646,19 +646,19 @@ PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...) PyObject * PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *callable = PyObject_GetAttrString(obj, name); - if (callable == NULL) { + PyObject *callable = PyObject_GetAttrString(obj, name); + if (callable == NULL) { return NULL; - } + } - va_list va; + va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 0); + PyObject *retval = callmethod(tstate, callable, format, va, 0); va_end(va); Py_DECREF(callable); @@ -670,19 +670,19 @@ PyObject * _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *callable = _PyObject_GetAttrId(obj, name); - if (callable == NULL) { + PyObject *callable = _PyObject_GetAttrId(obj, name); + if (callable == NULL) { return NULL; - } + } - va_list va; + va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 0); + PyObject *retval = callmethod(tstate, callable, format, va, 0); va_end(va); Py_DECREF(callable); @@ -694,19 +694,19 @@ PyObject * _PyObject_CallMethod_SizeT(PyObject *obj, const char *name, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *callable = PyObject_GetAttrString(obj, name); - if (callable == NULL) { + PyObject *callable = PyObject_GetAttrString(obj, name); + if (callable == NULL) { return NULL; - } + } - va_list va; + va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 1); + PyObject *retval = callmethod(tstate, callable, format, va, 1); va_end(va); Py_DECREF(callable); @@ -718,19 +718,19 @@ PyObject * _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name, const char *format, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *callable = _PyObject_GetAttrId(obj, name); + PyObject *callable = _PyObject_GetAttrId(obj, name); if (callable == NULL) { return NULL; } - va_list va; + va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 1); + PyObject *retval = callmethod(tstate, callable, format, va, 1); va_end(va); Py_DECREF(callable); @@ -741,8 +741,8 @@ _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name, /* --- Call with "..." arguments ---------------------------------- */ static PyObject * -object_vacall(PyThreadState *tstate, PyObject *base, - PyObject *callable, va_list vargs) +object_vacall(PyThreadState *tstate, PyObject *base, + PyObject *callable, va_list vargs) { PyObject *small_stack[_PY_FASTCALL_SMALL_STACK]; PyObject **stack; @@ -752,12 +752,12 @@ object_vacall(PyThreadState *tstate, PyObject *base, va_list countva; if (callable == NULL) { - return null_error(tstate); + return null_error(tstate); } /* Count the number of arguments */ va_copy(countva, vargs); - nargs = base ? 1 : 0; + nargs = base ? 1 : 0; while (1) { PyObject *arg = va_arg(countva, PyObject *); if (arg == NULL) { @@ -779,17 +779,17 @@ object_vacall(PyThreadState *tstate, PyObject *base, } } - i = 0; - if (base) { - stack[i++] = base; - } - - for (; i < nargs; ++i) { + i = 0; + if (base) { + stack[i++] = base; + } + + for (; i < nargs; ++i) { stack[i] = va_arg(vargs, PyObject *); } /* Call the function */ - result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL); + result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL); if (stack != small_stack) { PyMem_Free(stack); @@ -798,58 +798,58 @@ object_vacall(PyThreadState *tstate, PyObject *base, } -PyObject * -PyObject_VectorcallMethod(PyObject *name, PyObject *const *args, - size_t nargsf, PyObject *kwnames) -{ - assert(name != NULL); - assert(args != NULL); - assert(PyVectorcall_NARGS(nargsf) >= 1); - - PyThreadState *tstate = _PyThreadState_GET(); - PyObject *callable = NULL; - /* Use args[0] as "self" argument */ - int unbound = _PyObject_GetMethod(args[0], name, &callable); - if (callable == NULL) { - return NULL; - } - - if (unbound) { - /* We must remove PY_VECTORCALL_ARGUMENTS_OFFSET since - * that would be interpreted as allowing to change args[-1] */ - nargsf &= ~PY_VECTORCALL_ARGUMENTS_OFFSET; - } - else { - /* Skip "self". We can keep PY_VECTORCALL_ARGUMENTS_OFFSET since - * args[-1] in the onward call is args[0] here. */ - args++; - nargsf--; - } - PyObject *result = _PyObject_VectorcallTstate(tstate, callable, - args, nargsf, kwnames); - Py_DECREF(callable); - return result; -} - - PyObject * -PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...) +PyObject_VectorcallMethod(PyObject *name, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + assert(name != NULL); + assert(args != NULL); + assert(PyVectorcall_NARGS(nargsf) >= 1); + + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *callable = NULL; + /* Use args[0] as "self" argument */ + int unbound = _PyObject_GetMethod(args[0], name, &callable); + if (callable == NULL) { + return NULL; + } + + if (unbound) { + /* We must remove PY_VECTORCALL_ARGUMENTS_OFFSET since + * that would be interpreted as allowing to change args[-1] */ + nargsf &= ~PY_VECTORCALL_ARGUMENTS_OFFSET; + } + else { + /* Skip "self". We can keep PY_VECTORCALL_ARGUMENTS_OFFSET since + * args[-1] in the onward call is args[0] here. */ + args++; + nargsf--; + } + PyObject *result = _PyObject_VectorcallTstate(tstate, callable, + args, nargsf, kwnames); + Py_DECREF(callable); + return result; +} + + +PyObject * +PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...) { - PyThreadState *tstate = _PyThreadState_GET(); - if (obj == NULL || name == NULL) { - return null_error(tstate); + PyThreadState *tstate = _PyThreadState_GET(); + if (obj == NULL || name == NULL) { + return null_error(tstate); } - PyObject *callable = NULL; - int is_method = _PyObject_GetMethod(obj, name, &callable); + PyObject *callable = NULL; + int is_method = _PyObject_GetMethod(obj, name, &callable); if (callable == NULL) { return NULL; } - obj = is_method ? obj : NULL; + obj = is_method ? obj : NULL; - va_list vargs; + va_list vargs; va_start(vargs, name); - PyObject *result = object_vacall(tstate, obj, callable, vargs); + PyObject *result = object_vacall(tstate, obj, callable, vargs); va_end(vargs); Py_DECREF(callable); @@ -861,26 +861,26 @@ PyObject * _PyObject_CallMethodIdObjArgs(PyObject *obj, struct _Py_Identifier *name, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { - return null_error(tstate); + return null_error(tstate); } - PyObject *oname = _PyUnicode_FromId(name); /* borrowed */ - if (!oname) { - return NULL; - } - - PyObject *callable = NULL; - int is_method = _PyObject_GetMethod(obj, oname, &callable); + PyObject *oname = _PyUnicode_FromId(name); /* borrowed */ + if (!oname) { + return NULL; + } + + PyObject *callable = NULL; + int is_method = _PyObject_GetMethod(obj, oname, &callable); if (callable == NULL) { return NULL; } - obj = is_method ? obj : NULL; + obj = is_method ? obj : NULL; - va_list vargs; + va_list vargs; va_start(vargs, name); - PyObject *result = object_vacall(tstate, obj, callable, vargs); + PyObject *result = object_vacall(tstate, obj, callable, vargs); va_end(vargs); Py_DECREF(callable); @@ -891,12 +891,12 @@ _PyObject_CallMethodIdObjArgs(PyObject *obj, PyObject * PyObject_CallFunctionObjArgs(PyObject *callable, ...) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); va_list vargs; PyObject *result; va_start(vargs, callable); - result = object_vacall(tstate, NULL, callable, vargs); + result = object_vacall(tstate, NULL, callable, vargs); va_end(vargs); return result; @@ -932,98 +932,98 @@ _PyStack_AsDict(PyObject *const *values, PyObject *kwnames) } -/* Convert (args, nargs, kwargs: dict) into a (stack, nargs, kwnames: tuple). - - Allocate a new argument vector and keyword names tuple. Return the argument - vector; return NULL with exception set on error. Return the keyword names - tuple in *p_kwnames. - - This also checks that all keyword names are strings. If not, a TypeError is - raised. - - The newly allocated argument vector supports PY_VECTORCALL_ARGUMENTS_OFFSET. - - When done, you must call _PyStack_UnpackDict_Free(stack, nargs, kwnames) */ -static PyObject *const * -_PyStack_UnpackDict(PyThreadState *tstate, - PyObject *const *args, Py_ssize_t nargs, - PyObject *kwargs, PyObject **p_kwnames) +/* Convert (args, nargs, kwargs: dict) into a (stack, nargs, kwnames: tuple). + + Allocate a new argument vector and keyword names tuple. Return the argument + vector; return NULL with exception set on error. Return the keyword names + tuple in *p_kwnames. + + This also checks that all keyword names are strings. If not, a TypeError is + raised. + + The newly allocated argument vector supports PY_VECTORCALL_ARGUMENTS_OFFSET. + + When done, you must call _PyStack_UnpackDict_Free(stack, nargs, kwnames) */ +static PyObject *const * +_PyStack_UnpackDict(PyThreadState *tstate, + PyObject *const *args, Py_ssize_t nargs, + PyObject *kwargs, PyObject **p_kwnames) { assert(nargs >= 0); - assert(kwargs != NULL); - assert(PyDict_Check(kwargs)); - - Py_ssize_t nkwargs = PyDict_GET_SIZE(kwargs); - /* Check for overflow in the PyMem_Malloc() call below. The subtraction - * in this check cannot overflow: both maxnargs and nkwargs are - * non-negative signed integers, so their difference fits in the type. */ - Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1; - if (nargs > maxnargs - nkwargs) { - _PyErr_NoMemory(tstate); - return NULL; + assert(kwargs != NULL); + assert(PyDict_Check(kwargs)); + + Py_ssize_t nkwargs = PyDict_GET_SIZE(kwargs); + /* Check for overflow in the PyMem_Malloc() call below. The subtraction + * in this check cannot overflow: both maxnargs and nkwargs are + * non-negative signed integers, so their difference fits in the type. */ + Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1; + if (nargs > maxnargs - nkwargs) { + _PyErr_NoMemory(tstate); + return NULL; } - /* Add 1 to support PY_VECTORCALL_ARGUMENTS_OFFSET */ - PyObject **stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0])); + /* Add 1 to support PY_VECTORCALL_ARGUMENTS_OFFSET */ + PyObject **stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0])); if (stack == NULL) { - _PyErr_NoMemory(tstate); - return NULL; + _PyErr_NoMemory(tstate); + return NULL; } - PyObject *kwnames = PyTuple_New(nkwargs); + PyObject *kwnames = PyTuple_New(nkwargs); if (kwnames == NULL) { PyMem_Free(stack); - return NULL; + return NULL; } - stack++; /* For PY_VECTORCALL_ARGUMENTS_OFFSET */ - - /* Copy positional arguments */ - for (Py_ssize_t i = 0; i < nargs; i++) { - Py_INCREF(args[i]); - stack[i] = args[i]; - } + stack++; /* For PY_VECTORCALL_ARGUMENTS_OFFSET */ - PyObject **kwstack = stack + nargs; + /* Copy positional arguments */ + for (Py_ssize_t i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + stack[i] = args[i]; + } + + PyObject **kwstack = stack + nargs; /* This loop doesn't support lookup function mutating the dictionary to change its size. It's a deliberate choice for speed, this function is called in the performance critical hot code. */ - Py_ssize_t pos = 0, i = 0; - PyObject *key, *value; - unsigned long keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + Py_ssize_t pos = 0, i = 0; + PyObject *key, *value; + unsigned long keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; while (PyDict_Next(kwargs, &pos, &key, &value)) { - keys_are_strings &= Py_TYPE(key)->tp_flags; + keys_are_strings &= Py_TYPE(key)->tp_flags; Py_INCREF(key); - Py_INCREF(value); + Py_INCREF(value); PyTuple_SET_ITEM(kwnames, i, key); kwstack[i] = value; i++; } - /* keys_are_strings has the value Py_TPFLAGS_UNICODE_SUBCLASS if that - * flag is set for all keys. Otherwise, keys_are_strings equals 0. - * We do this check once at the end instead of inside the loop above - * because it simplifies the deallocation in the failing case. - * It happens to also make the loop above slightly more efficient. */ - if (!keys_are_strings) { - _PyErr_SetString(tstate, PyExc_TypeError, - "keywords must be strings"); - _PyStack_UnpackDict_Free(stack, nargs, kwnames); - return NULL; - } - + /* keys_are_strings has the value Py_TPFLAGS_UNICODE_SUBCLASS if that + * flag is set for all keys. Otherwise, keys_are_strings equals 0. + * We do this check once at the end instead of inside the loop above + * because it simplifies the deallocation in the failing case. + * It happens to also make the loop above slightly more efficient. */ + if (!keys_are_strings) { + _PyErr_SetString(tstate, PyExc_TypeError, + "keywords must be strings"); + _PyStack_UnpackDict_Free(stack, nargs, kwnames); + return NULL; + } + *p_kwnames = kwnames; - return stack; + return stack; +} + +static void +_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs, + PyObject *kwnames) +{ + Py_ssize_t n = PyTuple_GET_SIZE(kwnames) + nargs; + for (Py_ssize_t i = 0; i < n; i++) { + Py_DECREF(stack[i]); + } + PyMem_Free((PyObject **)stack - 1); + Py_DECREF(kwnames); } - -static void -_PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs, - PyObject *kwnames) -{ - Py_ssize_t n = PyTuple_GET_SIZE(kwnames) + nargs; - for (Py_ssize_t i = 0; i < n; i++) { - Py_DECREF(stack[i]); - } - PyMem_Free((PyObject **)stack - 1); - Py_DECREF(kwnames); -} diff --git a/contrib/tools/python3/src/Objects/capsule.c b/contrib/tools/python3/src/Objects/capsule.c index eaa34d1401..ed24cc1d6a 100644 --- a/contrib/tools/python3/src/Objects/capsule.c +++ b/contrib/tools/python3/src/Objects/capsule.c @@ -50,7 +50,7 @@ PyCapsule_New(void *pointer, const char *name, PyCapsule_Destructor destructor) return NULL; } - capsule = PyObject_New(PyCapsule, &PyCapsule_Type); + capsule = PyObject_New(PyCapsule, &PyCapsule_Type); if (capsule == NULL) { return NULL; } @@ -303,10 +303,10 @@ PyTypeObject PyCapsule_Type = { 0, /*tp_itemsize*/ /* methods */ capsule_dealloc, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ capsule_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ diff --git a/contrib/tools/python3/src/Objects/cellobject.c b/contrib/tools/python3/src/Objects/cellobject.c index ebc695be35..86a89f02e6 100644 --- a/contrib/tools/python3/src/Objects/cellobject.c +++ b/contrib/tools/python3/src/Objects/cellobject.c @@ -1,7 +1,7 @@ /* Cell object implementation */ #include "Python.h" -#include "pycore_object.h" +#include "pycore_object.h" PyObject * PyCell_New(PyObject *obj) @@ -18,37 +18,37 @@ PyCell_New(PyObject *obj) return (PyObject *)op; } -PyDoc_STRVAR(cell_new_doc, -"cell([contents])\n" -"--\n" -"\n" -"Create a new cell object.\n" -"\n" -" contents\n" -" the contents of the cell. If not specified, the cell will be empty,\n" -" and \n further attempts to access its cell_contents attribute will\n" -" raise a ValueError."); - - -static PyObject * -cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - PyObject *obj = NULL; - - if (!_PyArg_NoKeywords("cell", kwargs)) { - goto exit; - } - /* min = 0: we allow the cell to be empty */ - if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) { - goto exit; - } - return_value = PyCell_New(obj); - -exit: - return return_value; -} - +PyDoc_STRVAR(cell_new_doc, +"cell([contents])\n" +"--\n" +"\n" +"Create a new cell object.\n" +"\n" +" contents\n" +" the contents of the cell. If not specified, the cell will be empty,\n" +" and \n further attempts to access its cell_contents attribute will\n" +" raise a ValueError."); + + +static PyObject * +cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + PyObject *obj = NULL; + + if (!_PyArg_NoKeywords("cell", kwargs)) { + goto exit; + } + /* min = 0: we allow the cell to be empty */ + if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) { + goto exit; + } + return_value = PyCell_New(obj); + +exit: + return return_value; +} + PyObject * PyCell_Get(PyObject *op) { @@ -110,7 +110,7 @@ cell_repr(PyCellObject *op) return PyUnicode_FromFormat("<cell at %p: empty>", op); return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>", - op, Py_TYPE(op->ob_ref)->tp_name, + op, Py_TYPE(op->ob_ref)->tp_name, op->ob_ref); } @@ -160,10 +160,10 @@ PyTypeObject PyCell_Type = { sizeof(PyCellObject), 0, (destructor)cell_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)cell_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -175,7 +175,7 @@ PyTypeObject PyCell_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - cell_new_doc, /* tp_doc */ + cell_new_doc, /* tp_doc */ (traverseproc)cell_traverse, /* tp_traverse */ (inquiry)cell_clear, /* tp_clear */ cell_richcompare, /* tp_richcompare */ @@ -185,13 +185,13 @@ PyTypeObject PyCell_Type = { 0, /* tp_methods */ 0, /* tp_members */ cell_getsetlist, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - (newfunc)cell_new, /* tp_new */ - 0, /* tp_free */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)cell_new, /* tp_new */ + 0, /* tp_free */ }; diff --git a/contrib/tools/python3/src/Objects/classobject.c b/contrib/tools/python3/src/Objects/classobject.c index 0f05513cd0..af73be3d26 100644 --- a/contrib/tools/python3/src/Objects/classobject.c +++ b/contrib/tools/python3/src/Objects/classobject.c @@ -1,10 +1,10 @@ /* Class object implementation (dead now except for methods) */ #include "Python.h" -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "structmember.h" // PyMemberDef +#include "pycore_object.h" +#include "pycore_pyerrors.h" +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "structmember.h" // PyMemberDef #define TP_DESCR_GET(t) ((t)->tp_descr_get) @@ -31,65 +31,65 @@ PyMethod_Self(PyObject *im) return ((PyMethodObject *)im)->im_self; } - -static PyObject * -method_vectorcall(PyObject *method, PyObject *const *args, - size_t nargsf, PyObject *kwnames) -{ - assert(Py_IS_TYPE(method, &PyMethod_Type)); - - PyThreadState *tstate = _PyThreadState_GET(); - PyObject *self = PyMethod_GET_SELF(method); - PyObject *func = PyMethod_GET_FUNCTION(method); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - - PyObject *result; - if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) { - /* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */ - PyObject **newargs = (PyObject**)args - 1; - nargs += 1; - PyObject *tmp = newargs[0]; - newargs[0] = self; - result = _PyObject_VectorcallTstate(tstate, func, newargs, - nargs, kwnames); - newargs[0] = tmp; - } - else { - Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); - Py_ssize_t totalargs = nargs + nkwargs; - if (totalargs == 0) { - return _PyObject_VectorcallTstate(tstate, func, &self, 1, NULL); - } - - PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK]; - PyObject **newargs; - if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) { - newargs = newargs_stack; - } - else { - newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *)); - if (newargs == NULL) { - _PyErr_NoMemory(tstate); - return NULL; - } - } - /* use borrowed references */ - newargs[0] = self; - /* bpo-37138: since totalargs > 0, it's impossible that args is NULL. - * We need this, since calling memcpy() with a NULL pointer is - * undefined behaviour. */ - assert(args != NULL); - memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); - result = _PyObject_VectorcallTstate(tstate, func, - newargs, nargs+1, kwnames); - if (newargs != newargs_stack) { - PyMem_Free(newargs); - } - } - return result; -} - - + +static PyObject * +method_vectorcall(PyObject *method, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + assert(Py_IS_TYPE(method, &PyMethod_Type)); + + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *self = PyMethod_GET_SELF(method); + PyObject *func = PyMethod_GET_FUNCTION(method); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + + PyObject *result; + if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) { + /* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */ + PyObject **newargs = (PyObject**)args - 1; + nargs += 1; + PyObject *tmp = newargs[0]; + newargs[0] = self; + result = _PyObject_VectorcallTstate(tstate, func, newargs, + nargs, kwnames); + newargs[0] = tmp; + } + else { + Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); + Py_ssize_t totalargs = nargs + nkwargs; + if (totalargs == 0) { + return _PyObject_VectorcallTstate(tstate, func, &self, 1, NULL); + } + + PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK]; + PyObject **newargs; + if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) { + newargs = newargs_stack; + } + else { + newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *)); + if (newargs == NULL) { + _PyErr_NoMemory(tstate); + return NULL; + } + } + /* use borrowed references */ + newargs[0] = self; + /* bpo-37138: since totalargs > 0, it's impossible that args is NULL. + * We need this, since calling memcpy() with a NULL pointer is + * undefined behaviour. */ + assert(args != NULL); + memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); + result = _PyObject_VectorcallTstate(tstate, func, + newargs, nargs+1, kwnames); + if (newargs != newargs_stack) { + PyMem_Free(newargs); + } + } + return result; +} + + /* Method objects are used for bound instance methods returned by instancename.methodname. ClassName.methodname returns an ordinary function. @@ -102,22 +102,22 @@ PyMethod_New(PyObject *func, PyObject *self) PyErr_BadInternalCall(); return NULL; } - PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); - if (im == NULL) { - return NULL; + PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); + if (im == NULL) { + return NULL; } im->im_weakreflist = NULL; Py_INCREF(func); im->im_func = func; - Py_INCREF(self); + Py_INCREF(self); im->im_self = self; - im->vectorcall = method_vectorcall; + im->vectorcall = method_vectorcall; _PyObject_GC_TRACK(im); return (PyObject *)im; } static PyObject * -method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) +method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) { PyObject *self = PyMethod_GET_SELF(im); PyObject *func = PyMethod_GET_FUNCTION(im); @@ -144,9 +144,9 @@ static PyMethodDef method_methods[] = { #define MO_OFF(x) offsetof(PyMethodObject, x) static PyMemberDef method_memberlist[] = { - {"__func__", T_OBJECT, MO_OFF(im_func), READONLY, + {"__func__", T_OBJECT, MO_OFF(im_func), READONLY, "the function (or other callable) implementing a method"}, - {"__self__", T_OBJECT, MO_OFF(im_self), READONLY, + {"__self__", T_OBJECT, MO_OFF(im_self), READONLY, "the instance to which a method is bound"}, {NULL} /* Sentinel */ }; @@ -177,7 +177,7 @@ static PyObject * method_getattro(PyObject *obj, PyObject *name) { PyMethodObject *im = (PyMethodObject *)obj; - PyTypeObject *tp = Py_TYPE(obj); + PyTypeObject *tp = Py_TYPE(obj); PyObject *descr = NULL; { @@ -189,9 +189,9 @@ method_getattro(PyObject *obj, PyObject *name) } if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); + descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); if (f != NULL) - return f(descr, obj, (PyObject *)Py_TYPE(obj)); + return f(descr, obj, (PyObject *)Py_TYPE(obj)); else { Py_INCREF(descr); return descr; @@ -239,7 +239,7 @@ method_dealloc(PyMethodObject *im) PyObject_ClearWeakRefs((PyObject *)im); Py_DECREF(im->im_func); Py_XDECREF(im->im_self); - PyObject_GC_Del(im); + PyObject_GC_Del(im); } static PyObject * @@ -259,9 +259,9 @@ method_richcompare(PyObject *self, PyObject *other, int op) b = (PyMethodObject *)other; eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); if (eq == 1) { - eq = (a->im_self == b->im_self); + eq = (a->im_self == b->im_self); } - else if (eq < 0) + else if (eq < 0) return NULL; if (op == Py_EQ) res = eq ? Py_True : Py_False; @@ -303,7 +303,7 @@ static Py_hash_t method_hash(PyMethodObject *a) { Py_hash_t x, y; - x = _Py_HashPointer(a->im_self); + x = _Py_HashPointer(a->im_self); y = PyObject_Hash(a->im_func); if (y == -1) return -1; @@ -324,8 +324,8 @@ method_traverse(PyMethodObject *im, visitproc visit, void *arg) static PyObject * method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) { - Py_INCREF(meth); - return meth; + Py_INCREF(meth); + return meth; } PyTypeObject PyMethod_Type = { @@ -334,22 +334,22 @@ PyTypeObject PyMethod_Type = { sizeof(PyMethodObject), 0, (destructor)method_dealloc, /* tp_dealloc */ - offsetof(PyMethodObject, vectorcall), /* tp_vectorcall_offset */ + offsetof(PyMethodObject, vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)method_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)method_hash, /* tp_hash */ - PyVectorcall_Call, /* tp_call */ + PyVectorcall_Call, /* tp_call */ 0, /* tp_str */ method_getattro, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ method_doc, /* tp_doc */ (traverseproc)method_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -399,7 +399,7 @@ PyInstanceMethod_Function(PyObject *im) #define IMO_OFF(x) offsetof(PyInstanceMethodObject, x) static PyMemberDef instancemethod_memberlist[] = { - {"__func__", T_OBJECT, IMO_OFF(func), READONLY, + {"__func__", T_OBJECT, IMO_OFF(func), READONLY, "the function (or other callable) implementing a method"}, {NULL} /* Sentinel */ }; @@ -424,7 +424,7 @@ static PyGetSetDef instancemethod_getset[] = { static PyObject * instancemethod_getattro(PyObject *self, PyObject *name) { - PyTypeObject *tp = Py_TYPE(self); + PyTypeObject *tp = Py_TYPE(self); PyObject *descr = NULL; if (tp->tp_dict == NULL) { @@ -434,9 +434,9 @@ instancemethod_getattro(PyObject *self, PyObject *name) descr = _PyType_Lookup(tp, name); if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); + descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); if (f != NULL) - return f(descr, self, (PyObject *)Py_TYPE(self)); + return f(descr, self, (PyObject *)Py_TYPE(self)); else { Py_INCREF(descr); return descr; @@ -462,7 +462,7 @@ instancemethod_traverse(PyObject *self, visitproc visit, void *arg) { static PyObject * instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw) { - return PyObject_Call(PyInstanceMethod_GET_FUNCTION(self), arg, kw); + return PyObject_Call(PyInstanceMethod_GET_FUNCTION(self), arg, kw); } static PyObject * @@ -574,10 +574,10 @@ PyTypeObject PyInstanceMethod_Type = { sizeof(PyInstanceMethodObject), /* tp_basicsize */ 0, /* tp_itemsize */ instancemethod_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)instancemethod_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/clinic/bytearrayobject.c.h b/contrib/tools/python3/src/Objects/clinic/bytearrayobject.c.h index fcada9abad..35ba1ff3d5 100644 --- a/contrib/tools/python3/src/Objects/clinic/bytearrayobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/bytearrayobject.c.h @@ -38,86 +38,86 @@ bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) return bytearray_copy_impl(self); } -PyDoc_STRVAR(bytearray_removeprefix__doc__, -"removeprefix($self, prefix, /)\n" -"--\n" -"\n" -"Return a bytearray with the given prefix string removed if present.\n" -"\n" -"If the bytearray starts with the prefix string, return\n" -"bytearray[len(prefix):]. Otherwise, return a copy of the original\n" -"bytearray."); - -#define BYTEARRAY_REMOVEPREFIX_METHODDEF \ - {"removeprefix", (PyCFunction)bytearray_removeprefix, METH_O, bytearray_removeprefix__doc__}, - -static PyObject * -bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix); - -static PyObject * -bytearray_removeprefix(PyByteArrayObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_buffer prefix = {NULL, NULL}; - - if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&prefix, 'C')) { - _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg); - goto exit; - } - return_value = bytearray_removeprefix_impl(self, &prefix); - -exit: - /* Cleanup for prefix */ - if (prefix.obj) { - PyBuffer_Release(&prefix); - } - - return return_value; -} - -PyDoc_STRVAR(bytearray_removesuffix__doc__, -"removesuffix($self, suffix, /)\n" -"--\n" -"\n" -"Return a bytearray with the given suffix string removed if present.\n" -"\n" -"If the bytearray ends with the suffix string and that suffix is not\n" -"empty, return bytearray[:-len(suffix)]. Otherwise, return a copy of\n" -"the original bytearray."); - -#define BYTEARRAY_REMOVESUFFIX_METHODDEF \ - {"removesuffix", (PyCFunction)bytearray_removesuffix, METH_O, bytearray_removesuffix__doc__}, - -static PyObject * -bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix); - -static PyObject * -bytearray_removesuffix(PyByteArrayObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_buffer suffix = {NULL, NULL}; - - if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&suffix, 'C')) { - _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg); - goto exit; - } - return_value = bytearray_removesuffix_impl(self, &suffix); - -exit: - /* Cleanup for suffix */ - if (suffix.obj) { - PyBuffer_Release(&suffix); - } - - return return_value; -} - +PyDoc_STRVAR(bytearray_removeprefix__doc__, +"removeprefix($self, prefix, /)\n" +"--\n" +"\n" +"Return a bytearray with the given prefix string removed if present.\n" +"\n" +"If the bytearray starts with the prefix string, return\n" +"bytearray[len(prefix):]. Otherwise, return a copy of the original\n" +"bytearray."); + +#define BYTEARRAY_REMOVEPREFIX_METHODDEF \ + {"removeprefix", (PyCFunction)bytearray_removeprefix, METH_O, bytearray_removeprefix__doc__}, + +static PyObject * +bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix); + +static PyObject * +bytearray_removeprefix(PyByteArrayObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_buffer prefix = {NULL, NULL}; + + if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&prefix, 'C')) { + _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg); + goto exit; + } + return_value = bytearray_removeprefix_impl(self, &prefix); + +exit: + /* Cleanup for prefix */ + if (prefix.obj) { + PyBuffer_Release(&prefix); + } + + return return_value; +} + +PyDoc_STRVAR(bytearray_removesuffix__doc__, +"removesuffix($self, suffix, /)\n" +"--\n" +"\n" +"Return a bytearray with the given suffix string removed if present.\n" +"\n" +"If the bytearray ends with the suffix string and that suffix is not\n" +"empty, return bytearray[:-len(suffix)]. Otherwise, return a copy of\n" +"the original bytearray."); + +#define BYTEARRAY_REMOVESUFFIX_METHODDEF \ + {"removesuffix", (PyCFunction)bytearray_removesuffix, METH_O, bytearray_removesuffix__doc__}, + +static PyObject * +bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix); + +static PyObject * +bytearray_removesuffix(PyByteArrayObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_buffer suffix = {NULL, NULL}; + + if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&suffix, 'C')) { + _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg); + goto exit; + } + return_value = bytearray_removesuffix_impl(self, &suffix); + +exit: + /* Cleanup for suffix */ + if (suffix.obj) { + PyBuffer_Release(&suffix); + } + + return return_value; +} + PyDoc_STRVAR(bytearray_translate__doc__, "translate($self, table, /, delete=b\'\')\n" "--\n" @@ -131,7 +131,7 @@ PyDoc_STRVAR(bytearray_translate__doc__, "The remaining characters are mapped through the given translation table."); #define BYTEARRAY_TRANSLATE_METHODDEF \ - {"translate", (PyCFunction)(void(*)(void))bytearray_translate, METH_FASTCALL|METH_KEYWORDS, bytearray_translate__doc__}, + {"translate", (PyCFunction)(void(*)(void))bytearray_translate, METH_FASTCALL|METH_KEYWORDS, bytearray_translate__doc__}, static PyObject * bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, @@ -142,22 +142,22 @@ bytearray_translate(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "delete", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *table; PyObject *deletechars = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } - table = args[0]; - if (!noptargs) { - goto skip_optional_pos; - } - deletechars = args[1]; -skip_optional_pos: + table = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + deletechars = args[1]; +skip_optional_pos: return_value = bytearray_translate_impl(self, table, deletechars); exit: @@ -176,7 +176,7 @@ PyDoc_STRVAR(bytearray_maketrans__doc__, "The bytes objects frm and to must be of the same length."); #define BYTEARRAY_MAKETRANS_METHODDEF \ - {"maketrans", (PyCFunction)(void(*)(void))bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__}, + {"maketrans", (PyCFunction)(void(*)(void))bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__}, static PyObject * bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to); @@ -188,23 +188,23 @@ bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) Py_buffer frm = {NULL, NULL}; Py_buffer to = {NULL, NULL}; - if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { + if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&frm, 'C')) { + _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&to, 'C')) { + _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]); goto exit; } - if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&frm, 'C')) { - _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]); - goto exit; - } - if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&to, 'C')) { - _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]); - goto exit; - } return_value = bytearray_maketrans_impl(&frm, &to); exit: @@ -234,7 +234,7 @@ PyDoc_STRVAR(bytearray_replace__doc__, "replaced."); #define BYTEARRAY_REPLACE_METHODDEF \ - {"replace", (PyCFunction)(void(*)(void))bytearray_replace, METH_FASTCALL, bytearray_replace__doc__}, + {"replace", (PyCFunction)(void(*)(void))bytearray_replace, METH_FASTCALL, bytearray_replace__doc__}, static PyObject * bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old, @@ -248,44 +248,44 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar Py_buffer new = {NULL, NULL}; Py_ssize_t count = -1; - if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&old, 'C')) { + _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&new, 'C')) { + _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } - if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&old, 'C')) { - _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]); - goto exit; - } - if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&new, 'C')) { - _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]); - goto exit; - } - if (nargs < 3) { - goto skip_optional; - } - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - } -skip_optional: + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = bytearray_replace_impl(self, &old, &new, count); exit: @@ -316,7 +316,7 @@ PyDoc_STRVAR(bytearray_split__doc__, " -1 (the default value) means no limit."); #define BYTEARRAY_SPLIT_METHODDEF \ - {"split", (PyCFunction)(void(*)(void))bytearray_split, METH_FASTCALL|METH_KEYWORDS, bytearray_split__doc__}, + {"split", (PyCFunction)(void(*)(void))bytearray_split, METH_FASTCALL|METH_KEYWORDS, bytearray_split__doc__}, static PyObject * bytearray_split_impl(PyByteArrayObject *self, PyObject *sep, @@ -327,43 +327,43 @@ bytearray_split(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = bytearray_split_impl(self, sep, maxsplit); exit: @@ -420,7 +420,7 @@ PyDoc_STRVAR(bytearray_rsplit__doc__, "Splitting is done starting at the end of the bytearray and working to the front."); #define BYTEARRAY_RSPLIT_METHODDEF \ - {"rsplit", (PyCFunction)(void(*)(void))bytearray_rsplit, METH_FASTCALL|METH_KEYWORDS, bytearray_rsplit__doc__}, + {"rsplit", (PyCFunction)(void(*)(void))bytearray_rsplit, METH_FASTCALL|METH_KEYWORDS, bytearray_rsplit__doc__}, static PyObject * bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep, @@ -431,43 +431,43 @@ bytearray_rsplit(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = bytearray_rsplit_impl(self, sep, maxsplit); exit: @@ -504,7 +504,7 @@ PyDoc_STRVAR(bytearray_insert__doc__, " The item to be inserted."); #define BYTEARRAY_INSERT_METHODDEF \ - {"insert", (PyCFunction)(void(*)(void))bytearray_insert, METH_FASTCALL, bytearray_insert__doc__}, + {"insert", (PyCFunction)(void(*)(void))bytearray_insert, METH_FASTCALL, bytearray_insert__doc__}, static PyObject * bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item); @@ -516,29 +516,29 @@ bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg Py_ssize_t index; int item; - if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { + if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + index = ival; + } + if (!_getbytevalue(args[1], &item)) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; - } - if (!_getbytevalue(args[1], &item)) { - goto exit; - } return_value = bytearray_insert_impl(self, index, item); exit: @@ -566,7 +566,7 @@ bytearray_append(PyByteArrayObject *self, PyObject *arg) PyObject *return_value = NULL; int item; - if (!_getbytevalue(arg, &item)) { + if (!_getbytevalue(arg, &item)) { goto exit; } return_value = bytearray_append_impl(self, item); @@ -600,7 +600,7 @@ PyDoc_STRVAR(bytearray_pop__doc__, "If no index argument is given, will pop the last item."); #define BYTEARRAY_POP_METHODDEF \ - {"pop", (PyCFunction)(void(*)(void))bytearray_pop, METH_FASTCALL, bytearray_pop__doc__}, + {"pop", (PyCFunction)(void(*)(void))bytearray_pop, METH_FASTCALL, bytearray_pop__doc__}, static PyObject * bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index); @@ -611,30 +611,30 @@ bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t index = -1; - if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } - if (nargs < 1) { - goto skip_optional; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; - } -skip_optional: + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + index = ival; + } +skip_optional: return_value = bytearray_pop_impl(self, index); exit: @@ -662,7 +662,7 @@ bytearray_remove(PyByteArrayObject *self, PyObject *arg) PyObject *return_value = NULL; int value; - if (!_getbytevalue(arg, &value)) { + if (!_getbytevalue(arg, &value)) { goto exit; } return_value = bytearray_remove_impl(self, value); @@ -680,7 +680,7 @@ PyDoc_STRVAR(bytearray_strip__doc__, "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); #define BYTEARRAY_STRIP_METHODDEF \ - {"strip", (PyCFunction)(void(*)(void))bytearray_strip, METH_FASTCALL, bytearray_strip__doc__}, + {"strip", (PyCFunction)(void(*)(void))bytearray_strip, METH_FASTCALL, bytearray_strip__doc__}, static PyObject * bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes); @@ -691,14 +691,14 @@ bytearray_strip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytearray_strip_impl(self, bytes); exit: @@ -714,7 +714,7 @@ PyDoc_STRVAR(bytearray_lstrip__doc__, "If the argument is omitted or None, strip leading ASCII whitespace."); #define BYTEARRAY_LSTRIP_METHODDEF \ - {"lstrip", (PyCFunction)(void(*)(void))bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__}, + {"lstrip", (PyCFunction)(void(*)(void))bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__}, static PyObject * bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes); @@ -725,14 +725,14 @@ bytearray_lstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytearray_lstrip_impl(self, bytes); exit: @@ -748,7 +748,7 @@ PyDoc_STRVAR(bytearray_rstrip__doc__, "If the argument is omitted or None, strip trailing ASCII whitespace."); #define BYTEARRAY_RSTRIP_METHODDEF \ - {"rstrip", (PyCFunction)(void(*)(void))bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__}, + {"rstrip", (PyCFunction)(void(*)(void))bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__}, static PyObject * bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes); @@ -759,14 +759,14 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytearray_rstrip_impl(self, bytes); exit: @@ -789,7 +789,7 @@ PyDoc_STRVAR(bytearray_decode__doc__, " can handle UnicodeDecodeErrors."); #define BYTEARRAY_DECODE_METHODDEF \ - {"decode", (PyCFunction)(void(*)(void))bytearray_decode, METH_FASTCALL|METH_KEYWORDS, bytearray_decode__doc__}, + {"decode", (PyCFunction)(void(*)(void))bytearray_decode, METH_FASTCALL|METH_KEYWORDS, bytearray_decode__doc__}, static PyObject * bytearray_decode_impl(PyByteArrayObject *self, const char *encoding, @@ -800,51 +800,51 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg { PyObject *return_value = NULL; static const char * const _keywords[] = {"encoding", "errors", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; const char *encoding = NULL; const char *errors = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); + goto exit; + } + Py_ssize_t encoding_length; + encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + if (encoding == NULL) { + goto exit; + } + if (strlen(encoding) != (size_t)encoding_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); - goto exit; - } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); - if (encoding == NULL) { - goto exit; - } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); - goto exit; - } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); - if (errors == NULL) { - goto exit; - } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } -skip_optional_pos: + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } +skip_optional_pos: return_value = bytearray_decode_impl(self, encoding, errors); exit: @@ -874,7 +874,7 @@ PyDoc_STRVAR(bytearray_splitlines__doc__, "true."); #define BYTEARRAY_SPLITLINES_METHODDEF \ - {"splitlines", (PyCFunction)(void(*)(void))bytearray_splitlines, METH_FASTCALL|METH_KEYWORDS, bytearray_splitlines__doc__}, + {"splitlines", (PyCFunction)(void(*)(void))bytearray_splitlines, METH_FASTCALL|METH_KEYWORDS, bytearray_splitlines__doc__}, static PyObject * bytearray_splitlines_impl(PyByteArrayObject *self, int keepends); @@ -884,28 +884,28 @@ bytearray_splitlines(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t { PyObject *return_value = NULL; static const char * const _keywords[] = {"keepends", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int keepends = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - keepends = _PyLong_AsInt(args[0]); - if (keepends == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + keepends = _PyLong_AsInt(args[0]); + if (keepends == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: return_value = bytearray_splitlines_impl(self, keepends); exit: @@ -933,89 +933,89 @@ bytearray_fromhex(PyTypeObject *type, PyObject *arg) PyObject *return_value = NULL; PyObject *string; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("fromhex", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("fromhex", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - string = arg; + string = arg; return_value = bytearray_fromhex_impl(type, string); exit: return return_value; } -PyDoc_STRVAR(bytearray_hex__doc__, -"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" -"--\n" -"\n" -"Create a str of hexadecimal numbers from a bytearray object.\n" -"\n" -" sep\n" -" An optional single character or byte to separate hex bytes.\n" -" bytes_per_sep\n" -" How many bytes between separators. Positive values count from the\n" -" right, negative values count from the left.\n" -"\n" -"Example:\n" -">>> value = bytearray([0xb9, 0x01, 0xef])\n" -">>> value.hex()\n" -"\'b901ef\'\n" -">>> value.hex(\':\')\n" -"\'b9:01:ef\'\n" -">>> value.hex(\':\', 2)\n" -"\'b9:01ef\'\n" -">>> value.hex(\':\', -2)\n" -"\'b901:ef\'"); - -#define BYTEARRAY_HEX_METHODDEF \ - {"hex", (PyCFunction)(void(*)(void))bytearray_hex, METH_FASTCALL|METH_KEYWORDS, bytearray_hex__doc__}, - -static PyObject * -bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep); - -static PyObject * -bytearray_hex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - PyObject *sep = NULL; - int bytes_per_sep = 1; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - bytes_per_sep = _PyLong_AsInt(args[1]); - if (bytes_per_sep == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: - return_value = bytearray_hex_impl(self, sep, bytes_per_sep); - -exit: - return return_value; -} - +PyDoc_STRVAR(bytearray_hex__doc__, +"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" +"--\n" +"\n" +"Create a str of hexadecimal numbers from a bytearray object.\n" +"\n" +" sep\n" +" An optional single character or byte to separate hex bytes.\n" +" bytes_per_sep\n" +" How many bytes between separators. Positive values count from the\n" +" right, negative values count from the left.\n" +"\n" +"Example:\n" +">>> value = bytearray([0xb9, 0x01, 0xef])\n" +">>> value.hex()\n" +"\'b901ef\'\n" +">>> value.hex(\':\')\n" +"\'b9:01:ef\'\n" +">>> value.hex(\':\', 2)\n" +"\'b9:01ef\'\n" +">>> value.hex(\':\', -2)\n" +"\'b901:ef\'"); + +#define BYTEARRAY_HEX_METHODDEF \ + {"hex", (PyCFunction)(void(*)(void))bytearray_hex, METH_FASTCALL|METH_KEYWORDS, bytearray_hex__doc__}, + +static PyObject * +bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep); + +static PyObject * +bytearray_hex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + PyObject *sep = NULL; + int bytes_per_sep = 1; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + bytes_per_sep = _PyLong_AsInt(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: + return_value = bytearray_hex_impl(self, sep, bytes_per_sep); + +exit: + return return_value; +} + PyDoc_STRVAR(bytearray_reduce__doc__, "__reduce__($self, /)\n" "--\n" @@ -1041,7 +1041,7 @@ PyDoc_STRVAR(bytearray_reduce_ex__doc__, "Return state information for pickling."); #define BYTEARRAY_REDUCE_EX_METHODDEF \ - {"__reduce_ex__", (PyCFunction)(void(*)(void))bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__}, + {"__reduce_ex__", (PyCFunction)(void(*)(void))bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__}, static PyObject * bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto); @@ -1052,22 +1052,22 @@ bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n PyObject *return_value = NULL; int proto = 0; - if (!_PyArg_CheckPositional("__reduce_ex__", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("__reduce_ex__", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + proto = _PyLong_AsInt(args[0]); + if (proto == -1 && PyErr_Occurred()) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - proto = _PyLong_AsInt(args[0]); - if (proto == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional: +skip_optional: return_value = bytearray_reduce_ex_impl(self, proto); exit: @@ -1091,4 +1091,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=b2919f76709e48dc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b2919f76709e48dc input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/bytesobject.c.h b/contrib/tools/python3/src/Objects/clinic/bytesobject.c.h index eb176d83db..063a3777b4 100644 --- a/contrib/tools/python3/src/Objects/clinic/bytesobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/bytesobject.c.h @@ -17,7 +17,7 @@ PyDoc_STRVAR(bytes_split__doc__, " -1 (the default value) means no limit."); #define BYTES_SPLIT_METHODDEF \ - {"split", (PyCFunction)(void(*)(void))bytes_split, METH_FASTCALL|METH_KEYWORDS, bytes_split__doc__}, + {"split", (PyCFunction)(void(*)(void))bytes_split, METH_FASTCALL|METH_KEYWORDS, bytes_split__doc__}, static PyObject * bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit); @@ -27,43 +27,43 @@ bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = bytes_split_impl(self, sep, maxsplit); exit: @@ -95,13 +95,13 @@ bytes_partition(PyBytesObject *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer sep = {NULL, NULL}; - if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) { + if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&sep, 'C')) { + _PyArg_BadArgument("partition", "argument", "contiguous buffer", arg); goto exit; } - if (!PyBuffer_IsContiguous(&sep, 'C')) { - _PyArg_BadArgument("partition", "argument", "contiguous buffer", arg); - goto exit; - } return_value = bytes_partition_impl(self, &sep); exit: @@ -138,13 +138,13 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer sep = {NULL, NULL}; - if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) { + if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&sep, 'C')) { + _PyArg_BadArgument("rpartition", "argument", "contiguous buffer", arg); goto exit; } - if (!PyBuffer_IsContiguous(&sep, 'C')) { - _PyArg_BadArgument("rpartition", "argument", "contiguous buffer", arg); - goto exit; - } return_value = bytes_rpartition_impl(self, &sep); exit: @@ -173,7 +173,7 @@ PyDoc_STRVAR(bytes_rsplit__doc__, "Splitting is done starting at the end of the bytes and working to the front."); #define BYTES_RSPLIT_METHODDEF \ - {"rsplit", (PyCFunction)(void(*)(void))bytes_rsplit, METH_FASTCALL|METH_KEYWORDS, bytes_rsplit__doc__}, + {"rsplit", (PyCFunction)(void(*)(void))bytes_rsplit, METH_FASTCALL|METH_KEYWORDS, bytes_rsplit__doc__}, static PyObject * bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit); @@ -183,43 +183,43 @@ bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = bytes_rsplit_impl(self, sep, maxsplit); exit: @@ -250,7 +250,7 @@ PyDoc_STRVAR(bytes_strip__doc__, "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); #define BYTES_STRIP_METHODDEF \ - {"strip", (PyCFunction)(void(*)(void))bytes_strip, METH_FASTCALL, bytes_strip__doc__}, + {"strip", (PyCFunction)(void(*)(void))bytes_strip, METH_FASTCALL, bytes_strip__doc__}, static PyObject * bytes_strip_impl(PyBytesObject *self, PyObject *bytes); @@ -261,14 +261,14 @@ bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytes_strip_impl(self, bytes); exit: @@ -284,7 +284,7 @@ PyDoc_STRVAR(bytes_lstrip__doc__, "If the argument is omitted or None, strip leading ASCII whitespace."); #define BYTES_LSTRIP_METHODDEF \ - {"lstrip", (PyCFunction)(void(*)(void))bytes_lstrip, METH_FASTCALL, bytes_lstrip__doc__}, + {"lstrip", (PyCFunction)(void(*)(void))bytes_lstrip, METH_FASTCALL, bytes_lstrip__doc__}, static PyObject * bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes); @@ -295,14 +295,14 @@ bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytes_lstrip_impl(self, bytes); exit: @@ -318,7 +318,7 @@ PyDoc_STRVAR(bytes_rstrip__doc__, "If the argument is omitted or None, strip trailing ASCII whitespace."); #define BYTES_RSTRIP_METHODDEF \ - {"rstrip", (PyCFunction)(void(*)(void))bytes_rstrip, METH_FASTCALL, bytes_rstrip__doc__}, + {"rstrip", (PyCFunction)(void(*)(void))bytes_rstrip, METH_FASTCALL, bytes_rstrip__doc__}, static PyObject * bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes); @@ -329,14 +329,14 @@ bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *bytes = Py_None; - if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - bytes = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + bytes = args[0]; +skip_optional: return_value = bytes_rstrip_impl(self, bytes); exit: @@ -356,7 +356,7 @@ PyDoc_STRVAR(bytes_translate__doc__, "The remaining characters are mapped through the given translation table."); #define BYTES_TRANSLATE_METHODDEF \ - {"translate", (PyCFunction)(void(*)(void))bytes_translate, METH_FASTCALL|METH_KEYWORDS, bytes_translate__doc__}, + {"translate", (PyCFunction)(void(*)(void))bytes_translate, METH_FASTCALL|METH_KEYWORDS, bytes_translate__doc__}, static PyObject * bytes_translate_impl(PyBytesObject *self, PyObject *table, @@ -367,22 +367,22 @@ bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "delete", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *table; PyObject *deletechars = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } - table = args[0]; - if (!noptargs) { - goto skip_optional_pos; - } - deletechars = args[1]; -skip_optional_pos: + table = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + deletechars = args[1]; +skip_optional_pos: return_value = bytes_translate_impl(self, table, deletechars); exit: @@ -401,7 +401,7 @@ PyDoc_STRVAR(bytes_maketrans__doc__, "The bytes objects frm and to must be of the same length."); #define BYTES_MAKETRANS_METHODDEF \ - {"maketrans", (PyCFunction)(void(*)(void))bytes_maketrans, METH_FASTCALL|METH_STATIC, bytes_maketrans__doc__}, + {"maketrans", (PyCFunction)(void(*)(void))bytes_maketrans, METH_FASTCALL|METH_STATIC, bytes_maketrans__doc__}, static PyObject * bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to); @@ -413,23 +413,23 @@ bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) Py_buffer frm = {NULL, NULL}; Py_buffer to = {NULL, NULL}; - if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { - goto exit; - } - if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&frm, 'C')) { - _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]); - goto exit; - } - if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&to, 'C')) { - _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]); - goto exit; - } + if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&frm, 'C')) { + _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&to, 'C')) { + _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]); + goto exit; + } return_value = bytes_maketrans_impl(&frm, &to); exit: @@ -459,7 +459,7 @@ PyDoc_STRVAR(bytes_replace__doc__, "replaced."); #define BYTES_REPLACE_METHODDEF \ - {"replace", (PyCFunction)(void(*)(void))bytes_replace, METH_FASTCALL, bytes_replace__doc__}, + {"replace", (PyCFunction)(void(*)(void))bytes_replace, METH_FASTCALL, bytes_replace__doc__}, static PyObject * bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new, @@ -473,44 +473,44 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) Py_buffer new = {NULL, NULL}; Py_ssize_t count = -1; - if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { - goto exit; - } - if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&old, 'C')) { - _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]); - goto exit; - } - if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&new, 'C')) { - _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]); - goto exit; - } - if (nargs < 3) { - goto skip_optional; - } - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - } -skip_optional: + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&old, 'C')) { + _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&new, 'C')) { + _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = bytes_replace_impl(self, &old, &new, count); exit: @@ -526,85 +526,85 @@ exit: return return_value; } -PyDoc_STRVAR(bytes_removeprefix__doc__, -"removeprefix($self, prefix, /)\n" -"--\n" -"\n" -"Return a bytes object with the given prefix string removed if present.\n" -"\n" -"If the bytes starts with the prefix string, return bytes[len(prefix):].\n" -"Otherwise, return a copy of the original bytes."); - -#define BYTES_REMOVEPREFIX_METHODDEF \ - {"removeprefix", (PyCFunction)bytes_removeprefix, METH_O, bytes_removeprefix__doc__}, - -static PyObject * -bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix); - -static PyObject * -bytes_removeprefix(PyBytesObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_buffer prefix = {NULL, NULL}; - - if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&prefix, 'C')) { - _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg); - goto exit; - } - return_value = bytes_removeprefix_impl(self, &prefix); - -exit: - /* Cleanup for prefix */ - if (prefix.obj) { - PyBuffer_Release(&prefix); - } - - return return_value; -} - -PyDoc_STRVAR(bytes_removesuffix__doc__, -"removesuffix($self, suffix, /)\n" -"--\n" -"\n" -"Return a bytes object with the given suffix string removed if present.\n" -"\n" -"If the bytes ends with the suffix string and that suffix is not empty,\n" -"return bytes[:-len(prefix)]. Otherwise, return a copy of the original\n" -"bytes."); - -#define BYTES_REMOVESUFFIX_METHODDEF \ - {"removesuffix", (PyCFunction)bytes_removesuffix, METH_O, bytes_removesuffix__doc__}, - -static PyObject * -bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix); - -static PyObject * -bytes_removesuffix(PyBytesObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_buffer suffix = {NULL, NULL}; - - if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) { - goto exit; - } - if (!PyBuffer_IsContiguous(&suffix, 'C')) { - _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg); - goto exit; - } - return_value = bytes_removesuffix_impl(self, &suffix); - -exit: - /* Cleanup for suffix */ - if (suffix.obj) { - PyBuffer_Release(&suffix); - } - - return return_value; -} - +PyDoc_STRVAR(bytes_removeprefix__doc__, +"removeprefix($self, prefix, /)\n" +"--\n" +"\n" +"Return a bytes object with the given prefix string removed if present.\n" +"\n" +"If the bytes starts with the prefix string, return bytes[len(prefix):].\n" +"Otherwise, return a copy of the original bytes."); + +#define BYTES_REMOVEPREFIX_METHODDEF \ + {"removeprefix", (PyCFunction)bytes_removeprefix, METH_O, bytes_removeprefix__doc__}, + +static PyObject * +bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix); + +static PyObject * +bytes_removeprefix(PyBytesObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_buffer prefix = {NULL, NULL}; + + if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&prefix, 'C')) { + _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg); + goto exit; + } + return_value = bytes_removeprefix_impl(self, &prefix); + +exit: + /* Cleanup for prefix */ + if (prefix.obj) { + PyBuffer_Release(&prefix); + } + + return return_value; +} + +PyDoc_STRVAR(bytes_removesuffix__doc__, +"removesuffix($self, suffix, /)\n" +"--\n" +"\n" +"Return a bytes object with the given suffix string removed if present.\n" +"\n" +"If the bytes ends with the suffix string and that suffix is not empty,\n" +"return bytes[:-len(prefix)]. Otherwise, return a copy of the original\n" +"bytes."); + +#define BYTES_REMOVESUFFIX_METHODDEF \ + {"removesuffix", (PyCFunction)bytes_removesuffix, METH_O, bytes_removesuffix__doc__}, + +static PyObject * +bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix); + +static PyObject * +bytes_removesuffix(PyBytesObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_buffer suffix = {NULL, NULL}; + + if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&suffix, 'C')) { + _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg); + goto exit; + } + return_value = bytes_removesuffix_impl(self, &suffix); + +exit: + /* Cleanup for suffix */ + if (suffix.obj) { + PyBuffer_Release(&suffix); + } + + return return_value; +} + PyDoc_STRVAR(bytes_decode__doc__, "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" "--\n" @@ -621,7 +621,7 @@ PyDoc_STRVAR(bytes_decode__doc__, " can handle UnicodeDecodeErrors."); #define BYTES_DECODE_METHODDEF \ - {"decode", (PyCFunction)(void(*)(void))bytes_decode, METH_FASTCALL|METH_KEYWORDS, bytes_decode__doc__}, + {"decode", (PyCFunction)(void(*)(void))bytes_decode, METH_FASTCALL|METH_KEYWORDS, bytes_decode__doc__}, static PyObject * bytes_decode_impl(PyBytesObject *self, const char *encoding, @@ -632,51 +632,51 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj { PyObject *return_value = NULL; static const char * const _keywords[] = {"encoding", "errors", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; const char *encoding = NULL; const char *errors = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); - goto exit; - } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); - if (encoding == NULL) { - goto exit; - } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); - goto exit; - } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); - if (errors == NULL) { - goto exit; - } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } -skip_optional_pos: + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); + goto exit; + } + Py_ssize_t encoding_length; + encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + if (encoding == NULL) { + goto exit; + } + if (strlen(encoding) != (size_t)encoding_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); + goto exit; + } + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } +skip_optional_pos: return_value = bytes_decode_impl(self, encoding, errors); exit: @@ -693,7 +693,7 @@ PyDoc_STRVAR(bytes_splitlines__doc__, "true."); #define BYTES_SPLITLINES_METHODDEF \ - {"splitlines", (PyCFunction)(void(*)(void))bytes_splitlines, METH_FASTCALL|METH_KEYWORDS, bytes_splitlines__doc__}, + {"splitlines", (PyCFunction)(void(*)(void))bytes_splitlines, METH_FASTCALL|METH_KEYWORDS, bytes_splitlines__doc__}, static PyObject * bytes_splitlines_impl(PyBytesObject *self, int keepends); @@ -703,28 +703,28 @@ bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, P { PyObject *return_value = NULL; static const char * const _keywords[] = {"keepends", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int keepends = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - keepends = _PyLong_AsInt(args[0]); - if (keepends == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + keepends = _PyLong_AsInt(args[0]); + if (keepends == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: return_value = bytes_splitlines_impl(self, keepends); exit: @@ -752,86 +752,86 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg) PyObject *return_value = NULL; PyObject *string; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("fromhex", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("fromhex", "argument", "str", arg); goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - string = arg; + if (PyUnicode_READY(arg) == -1) { + goto exit; + } + string = arg; return_value = bytes_fromhex_impl(type, string); exit: return return_value; } - -PyDoc_STRVAR(bytes_hex__doc__, -"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" -"--\n" -"\n" -"Create a str of hexadecimal numbers from a bytes object.\n" -"\n" -" sep\n" -" An optional single character or byte to separate hex bytes.\n" -" bytes_per_sep\n" -" How many bytes between separators. Positive values count from the\n" -" right, negative values count from the left.\n" -"\n" -"Example:\n" -">>> value = b\'\\xb9\\x01\\xef\'\n" -">>> value.hex()\n" -"\'b901ef\'\n" -">>> value.hex(\':\')\n" -"\'b9:01:ef\'\n" -">>> value.hex(\':\', 2)\n" -"\'b9:01ef\'\n" -">>> value.hex(\':\', -2)\n" -"\'b901:ef\'"); - -#define BYTES_HEX_METHODDEF \ - {"hex", (PyCFunction)(void(*)(void))bytes_hex, METH_FASTCALL|METH_KEYWORDS, bytes_hex__doc__}, - -static PyObject * -bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep); - -static PyObject * -bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - PyObject *sep = NULL; - int bytes_per_sep = 1; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - bytes_per_sep = _PyLong_AsInt(args[1]); - if (bytes_per_sep == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: - return_value = bytes_hex_impl(self, sep, bytes_per_sep); - -exit: - return return_value; -} -/*[clinic end generated code: output=220388917d7bf751 input=a9049054013a1b77]*/ + +PyDoc_STRVAR(bytes_hex__doc__, +"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" +"--\n" +"\n" +"Create a str of hexadecimal numbers from a bytes object.\n" +"\n" +" sep\n" +" An optional single character or byte to separate hex bytes.\n" +" bytes_per_sep\n" +" How many bytes between separators. Positive values count from the\n" +" right, negative values count from the left.\n" +"\n" +"Example:\n" +">>> value = b\'\\xb9\\x01\\xef\'\n" +">>> value.hex()\n" +"\'b901ef\'\n" +">>> value.hex(\':\')\n" +"\'b9:01:ef\'\n" +">>> value.hex(\':\', 2)\n" +"\'b9:01ef\'\n" +">>> value.hex(\':\', -2)\n" +"\'b901:ef\'"); + +#define BYTES_HEX_METHODDEF \ + {"hex", (PyCFunction)(void(*)(void))bytes_hex, METH_FASTCALL|METH_KEYWORDS, bytes_hex__doc__}, + +static PyObject * +bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep); + +static PyObject * +bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + PyObject *sep = NULL; + int bytes_per_sep = 1; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + bytes_per_sep = _PyLong_AsInt(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: + return_value = bytes_hex_impl(self, sep, bytes_per_sep); + +exit: + return return_value; +} +/*[clinic end generated code: output=220388917d7bf751 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/codeobject.c.h b/contrib/tools/python3/src/Objects/clinic/codeobject.c.h index 9cddc72838..1dd82278cf 100644 --- a/contrib/tools/python3/src/Objects/clinic/codeobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/codeobject.c.h @@ -1,256 +1,256 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(code_replace__doc__, -"replace($self, /, *, co_argcount=-1, co_posonlyargcount=-1,\n" -" co_kwonlyargcount=-1, co_nlocals=-1, co_stacksize=-1,\n" -" co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n" -" co_names=None, co_varnames=None, co_freevars=None,\n" -" co_cellvars=None, co_filename=None, co_name=None,\n" -" co_lnotab=None)\n" -"--\n" -"\n" -"Return a copy of the code object with new values for the specified fields."); - -#define CODE_REPLACE_METHODDEF \ - {"replace", (PyCFunction)(void(*)(void))code_replace, METH_FASTCALL|METH_KEYWORDS, code_replace__doc__}, - -static PyObject * -code_replace_impl(PyCodeObject *self, int co_argcount, - int co_posonlyargcount, int co_kwonlyargcount, - int co_nlocals, int co_stacksize, int co_flags, - int co_firstlineno, PyBytesObject *co_code, - PyObject *co_consts, PyObject *co_names, - PyObject *co_varnames, PyObject *co_freevars, - PyObject *co_cellvars, PyObject *co_filename, - PyObject *co_name, PyBytesObject *co_lnotab); - -static PyObject * -code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_lnotab", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; - PyObject *argsbuf[16]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - int co_argcount = self->co_argcount; - int co_posonlyargcount = self->co_posonlyargcount; - int co_kwonlyargcount = self->co_kwonlyargcount; - int co_nlocals = self->co_nlocals; - int co_stacksize = self->co_stacksize; - int co_flags = self->co_flags; - int co_firstlineno = self->co_firstlineno; - PyBytesObject *co_code = (PyBytesObject *)self->co_code; - PyObject *co_consts = self->co_consts; - PyObject *co_names = self->co_names; - PyObject *co_varnames = self->co_varnames; - PyObject *co_freevars = self->co_freevars; - PyObject *co_cellvars = self->co_cellvars; - PyObject *co_filename = self->co_filename; - PyObject *co_name = self->co_name; - PyBytesObject *co_lnotab = (PyBytesObject *)self->co_lnotab; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_kwonly; - } - if (args[0]) { - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_argcount = _PyLong_AsInt(args[0]); - if (co_argcount == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[1]) { - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_posonlyargcount = _PyLong_AsInt(args[1]); - if (co_posonlyargcount == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[2]) { - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_kwonlyargcount = _PyLong_AsInt(args[2]); - if (co_kwonlyargcount == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[3]) { - if (PyFloat_Check(args[3])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_nlocals = _PyLong_AsInt(args[3]); - if (co_nlocals == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[4]) { - if (PyFloat_Check(args[4])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_stacksize = _PyLong_AsInt(args[4]); - if (co_stacksize == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[5]) { - if (PyFloat_Check(args[5])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_flags = _PyLong_AsInt(args[5]); - if (co_flags == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[6]) { - if (PyFloat_Check(args[6])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - co_firstlineno = _PyLong_AsInt(args[6]); - if (co_firstlineno == -1 && PyErr_Occurred()) { - goto exit; - } - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[7]) { - if (!PyBytes_Check(args[7])) { - _PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]); - goto exit; - } - co_code = (PyBytesObject *)args[7]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[8]) { - if (!PyTuple_Check(args[8])) { - _PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]); - goto exit; - } - co_consts = args[8]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[9]) { - if (!PyTuple_Check(args[9])) { - _PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]); - goto exit; - } - co_names = args[9]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[10]) { - if (!PyTuple_Check(args[10])) { - _PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]); - goto exit; - } - co_varnames = args[10]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[11]) { - if (!PyTuple_Check(args[11])) { - _PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]); - goto exit; - } - co_freevars = args[11]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[12]) { - if (!PyTuple_Check(args[12])) { - _PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]); - goto exit; - } - co_cellvars = args[12]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[13]) { - if (!PyUnicode_Check(args[13])) { - _PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]); - goto exit; - } - if (PyUnicode_READY(args[13]) == -1) { - goto exit; - } - co_filename = args[13]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (args[14]) { - if (!PyUnicode_Check(args[14])) { - _PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]); - goto exit; - } - if (PyUnicode_READY(args[14]) == -1) { - goto exit; - } - co_name = args[14]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (!PyBytes_Check(args[15])) { - _PyArg_BadArgument("replace", "argument 'co_lnotab'", "bytes", args[15]); - goto exit; - } - co_lnotab = (PyBytesObject *)args[15]; -skip_optional_kwonly: - return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_lnotab); - -exit: - return return_value; -} -/*[clinic end generated code: output=27fe34e82106b220 input=a9049054013a1b77]*/ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(code_replace__doc__, +"replace($self, /, *, co_argcount=-1, co_posonlyargcount=-1,\n" +" co_kwonlyargcount=-1, co_nlocals=-1, co_stacksize=-1,\n" +" co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n" +" co_names=None, co_varnames=None, co_freevars=None,\n" +" co_cellvars=None, co_filename=None, co_name=None,\n" +" co_lnotab=None)\n" +"--\n" +"\n" +"Return a copy of the code object with new values for the specified fields."); + +#define CODE_REPLACE_METHODDEF \ + {"replace", (PyCFunction)(void(*)(void))code_replace, METH_FASTCALL|METH_KEYWORDS, code_replace__doc__}, + +static PyObject * +code_replace_impl(PyCodeObject *self, int co_argcount, + int co_posonlyargcount, int co_kwonlyargcount, + int co_nlocals, int co_stacksize, int co_flags, + int co_firstlineno, PyBytesObject *co_code, + PyObject *co_consts, PyObject *co_names, + PyObject *co_varnames, PyObject *co_freevars, + PyObject *co_cellvars, PyObject *co_filename, + PyObject *co_name, PyBytesObject *co_lnotab); + +static PyObject * +code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_lnotab", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; + PyObject *argsbuf[16]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + int co_argcount = self->co_argcount; + int co_posonlyargcount = self->co_posonlyargcount; + int co_kwonlyargcount = self->co_kwonlyargcount; + int co_nlocals = self->co_nlocals; + int co_stacksize = self->co_stacksize; + int co_flags = self->co_flags; + int co_firstlineno = self->co_firstlineno; + PyBytesObject *co_code = (PyBytesObject *)self->co_code; + PyObject *co_consts = self->co_consts; + PyObject *co_names = self->co_names; + PyObject *co_varnames = self->co_varnames; + PyObject *co_freevars = self->co_freevars; + PyObject *co_cellvars = self->co_cellvars; + PyObject *co_filename = self->co_filename; + PyObject *co_name = self->co_name; + PyBytesObject *co_lnotab = (PyBytesObject *)self->co_lnotab; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_kwonly; + } + if (args[0]) { + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_argcount = _PyLong_AsInt(args[0]); + if (co_argcount == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[1]) { + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_posonlyargcount = _PyLong_AsInt(args[1]); + if (co_posonlyargcount == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[2]) { + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_kwonlyargcount = _PyLong_AsInt(args[2]); + if (co_kwonlyargcount == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[3]) { + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_nlocals = _PyLong_AsInt(args[3]); + if (co_nlocals == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[4]) { + if (PyFloat_Check(args[4])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_stacksize = _PyLong_AsInt(args[4]); + if (co_stacksize == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[5]) { + if (PyFloat_Check(args[5])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_flags = _PyLong_AsInt(args[5]); + if (co_flags == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[6]) { + if (PyFloat_Check(args[6])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + co_firstlineno = _PyLong_AsInt(args[6]); + if (co_firstlineno == -1 && PyErr_Occurred()) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[7]) { + if (!PyBytes_Check(args[7])) { + _PyArg_BadArgument("replace", "argument 'co_code'", "bytes", args[7]); + goto exit; + } + co_code = (PyBytesObject *)args[7]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[8]) { + if (!PyTuple_Check(args[8])) { + _PyArg_BadArgument("replace", "argument 'co_consts'", "tuple", args[8]); + goto exit; + } + co_consts = args[8]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[9]) { + if (!PyTuple_Check(args[9])) { + _PyArg_BadArgument("replace", "argument 'co_names'", "tuple", args[9]); + goto exit; + } + co_names = args[9]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[10]) { + if (!PyTuple_Check(args[10])) { + _PyArg_BadArgument("replace", "argument 'co_varnames'", "tuple", args[10]); + goto exit; + } + co_varnames = args[10]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[11]) { + if (!PyTuple_Check(args[11])) { + _PyArg_BadArgument("replace", "argument 'co_freevars'", "tuple", args[11]); + goto exit; + } + co_freevars = args[11]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[12]) { + if (!PyTuple_Check(args[12])) { + _PyArg_BadArgument("replace", "argument 'co_cellvars'", "tuple", args[12]); + goto exit; + } + co_cellvars = args[12]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[13]) { + if (!PyUnicode_Check(args[13])) { + _PyArg_BadArgument("replace", "argument 'co_filename'", "str", args[13]); + goto exit; + } + if (PyUnicode_READY(args[13]) == -1) { + goto exit; + } + co_filename = args[13]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (args[14]) { + if (!PyUnicode_Check(args[14])) { + _PyArg_BadArgument("replace", "argument 'co_name'", "str", args[14]); + goto exit; + } + if (PyUnicode_READY(args[14]) == -1) { + goto exit; + } + co_name = args[14]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (!PyBytes_Check(args[15])) { + _PyArg_BadArgument("replace", "argument 'co_lnotab'", "bytes", args[15]); + goto exit; + } + co_lnotab = (PyBytesObject *)args[15]; +skip_optional_kwonly: + return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_lnotab); + +exit: + return return_value; +} +/*[clinic end generated code: output=27fe34e82106b220 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/complexobject.c.h b/contrib/tools/python3/src/Objects/clinic/complexobject.c.h index 74f4d26d3a..8caa910d03 100644 --- a/contrib/tools/python3/src/Objects/clinic/complexobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/complexobject.c.h @@ -18,32 +18,32 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"real", "imag", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0}; - PyObject *argsbuf[2]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0}; + PyObject *argsbuf[2]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; PyObject *r = _PyLong_Zero; PyObject *i = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); + if (!fastargs) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (fastargs[0]) { - r = fastargs[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - i = fastargs[1]; -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (fastargs[0]) { + r = fastargs[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + i = fastargs[1]; +skip_optional_pos: return_value = complex_new_impl(type, r, i); exit: return return_value; } -/*[clinic end generated code: output=a0fe23fdbdc9b06b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a0fe23fdbdc9b06b input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/descrobject.c.h b/contrib/tools/python3/src/Objects/clinic/descrobject.c.h index 13a9e12fb1..d248b91bf4 100644 --- a/contrib/tools/python3/src/Objects/clinic/descrobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/descrobject.c.h @@ -10,17 +10,17 @@ mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"mapping", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "mappingproxy", 0}; - PyObject *argsbuf[1]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); + static _PyArg_Parser _parser = {NULL, _keywords, "mappingproxy", 0}; + PyObject *argsbuf[1]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *mapping; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); + if (!fastargs) { goto exit; } - mapping = fastargs[0]; + mapping = fastargs[0]; return_value = mappingproxy_new_impl(type, mapping); exit: @@ -73,46 +73,46 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "property", 0}; - PyObject *argsbuf[4]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "property", 0}; + PyObject *argsbuf[4]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; PyObject *fget = NULL; PyObject *fset = NULL; PyObject *fdel = NULL; PyObject *doc = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 4, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 4, 0, argsbuf); + if (!fastargs) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (fastargs[0]) { - fget = fastargs[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (fastargs[1]) { - fset = fastargs[1]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (fastargs[2]) { - fdel = fastargs[2]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - doc = fastargs[3]; -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (fastargs[0]) { + fget = fastargs[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (fastargs[1]) { + fset = fastargs[1]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (fastargs[2]) { + fdel = fastargs[2]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + doc = fastargs[3]; +skip_optional_pos: return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); exit: return return_value; } -/*[clinic end generated code: output=916624e717862abc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=916624e717862abc input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/dictobject.c.h b/contrib/tools/python3/src/Objects/clinic/dictobject.c.h index 51af72a2b8..7395e3bceb 100644 --- a/contrib/tools/python3/src/Objects/clinic/dictobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/dictobject.c.h @@ -9,7 +9,7 @@ PyDoc_STRVAR(dict_fromkeys__doc__, "Create a new dictionary with keys from iterable and values set to value."); #define DICT_FROMKEYS_METHODDEF \ - {"fromkeys", (PyCFunction)(void(*)(void))dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__}, + {"fromkeys", (PyCFunction)(void(*)(void))dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__}, static PyObject * dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value); @@ -21,15 +21,15 @@ dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs) PyObject *iterable; PyObject *value = Py_None; - if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) { goto exit; } - iterable = args[0]; - if (nargs < 2) { - goto skip_optional; - } - value = args[1]; -skip_optional: + iterable = args[0]; + if (nargs < 2) { + goto skip_optional; + } + value = args[1]; +skip_optional: return_value = dict_fromkeys_impl(type, iterable, value); exit: @@ -52,7 +52,7 @@ PyDoc_STRVAR(dict_get__doc__, "Return the value for key if key is in the dictionary, else default."); #define DICT_GET_METHODDEF \ - {"get", (PyCFunction)(void(*)(void))dict_get, METH_FASTCALL, dict_get__doc__}, + {"get", (PyCFunction)(void(*)(void))dict_get, METH_FASTCALL, dict_get__doc__}, static PyObject * dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value); @@ -64,15 +64,15 @@ dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *key; PyObject *default_value = Py_None; - if (!_PyArg_CheckPositional("get", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("get", nargs, 1, 2)) { goto exit; } - key = args[0]; - if (nargs < 2) { - goto skip_optional; - } - default_value = args[1]; -skip_optional: + key = args[0]; + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = dict_get_impl(self, key, default_value); exit: @@ -88,7 +88,7 @@ PyDoc_STRVAR(dict_setdefault__doc__, "Return the value for key if key is in the dictionary, else default."); #define DICT_SETDEFAULT_METHODDEF \ - {"setdefault", (PyCFunction)(void(*)(void))dict_setdefault, METH_FASTCALL, dict_setdefault__doc__}, + {"setdefault", (PyCFunction)(void(*)(void))dict_setdefault, METH_FASTCALL, dict_setdefault__doc__}, static PyObject * dict_setdefault_impl(PyDictObject *self, PyObject *key, @@ -101,93 +101,93 @@ dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *key; PyObject *default_value = Py_None; - if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) { goto exit; } - key = args[0]; - if (nargs < 2) { - goto skip_optional; - } - default_value = args[1]; -skip_optional: + key = args[0]; + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = dict_setdefault_impl(self, key, default_value); exit: return return_value; } - -PyDoc_STRVAR(dict_pop__doc__, -"pop($self, key, default=<unrepresentable>, /)\n" -"--\n" -"\n" -"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n" -"\n" -"If key is not found, default is returned if given, otherwise KeyError is raised"); - -#define DICT_POP_METHODDEF \ - {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__}, - -static PyObject * -dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value); - -static PyObject * -dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - PyObject *key; - PyObject *default_value = NULL; - - if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) { - goto exit; - } - key = args[0]; - if (nargs < 2) { - goto skip_optional; - } - default_value = args[1]; -skip_optional: - return_value = dict_pop_impl(self, key, default_value); - -exit: - return return_value; -} - -PyDoc_STRVAR(dict_popitem__doc__, -"popitem($self, /)\n" -"--\n" -"\n" -"Remove and return a (key, value) pair as a 2-tuple.\n" -"\n" -"Pairs are returned in LIFO (last-in, first-out) order.\n" -"Raises KeyError if the dict is empty."); - -#define DICT_POPITEM_METHODDEF \ - {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__}, - -static PyObject * -dict_popitem_impl(PyDictObject *self); - -static PyObject * -dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored)) -{ - return dict_popitem_impl(self); -} - -PyDoc_STRVAR(dict___reversed____doc__, -"__reversed__($self, /)\n" -"--\n" -"\n" -"Return a reverse iterator over the dict keys."); - -#define DICT___REVERSED___METHODDEF \ - {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__}, - -static PyObject * -dict___reversed___impl(PyDictObject *self); - -static PyObject * -dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored)) -{ - return dict___reversed___impl(self); -} -/*[clinic end generated code: output=4d98145508da8fa3 input=a9049054013a1b77]*/ + +PyDoc_STRVAR(dict_pop__doc__, +"pop($self, key, default=<unrepresentable>, /)\n" +"--\n" +"\n" +"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n" +"\n" +"If key is not found, default is returned if given, otherwise KeyError is raised"); + +#define DICT_POP_METHODDEF \ + {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__}, + +static PyObject * +dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value); + +static PyObject * +dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *key; + PyObject *default_value = NULL; + + if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) { + goto exit; + } + key = args[0]; + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: + return_value = dict_pop_impl(self, key, default_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(dict_popitem__doc__, +"popitem($self, /)\n" +"--\n" +"\n" +"Remove and return a (key, value) pair as a 2-tuple.\n" +"\n" +"Pairs are returned in LIFO (last-in, first-out) order.\n" +"Raises KeyError if the dict is empty."); + +#define DICT_POPITEM_METHODDEF \ + {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__}, + +static PyObject * +dict_popitem_impl(PyDictObject *self); + +static PyObject * +dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored)) +{ + return dict_popitem_impl(self); +} + +PyDoc_STRVAR(dict___reversed____doc__, +"__reversed__($self, /)\n" +"--\n" +"\n" +"Return a reverse iterator over the dict keys."); + +#define DICT___REVERSED___METHODDEF \ + {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__}, + +static PyObject * +dict___reversed___impl(PyDictObject *self); + +static PyObject * +dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored)) +{ + return dict___reversed___impl(self); +} +/*[clinic end generated code: output=4d98145508da8fa3 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/enumobject.c.h b/contrib/tools/python3/src/Objects/clinic/enumobject.c.h index a22fd43b04..09d4c87e15 100644 --- a/contrib/tools/python3/src/Objects/clinic/enumobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/enumobject.c.h @@ -25,24 +25,24 @@ enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"iterable", "start", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "enumerate", 0}; - PyObject *argsbuf[2]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "enumerate", 0}; + PyObject *argsbuf[2]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; PyObject *iterable; PyObject *start = 0; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); + if (!fastargs) { goto exit; } - iterable = fastargs[0]; - if (!noptargs) { - goto skip_optional_pos; - } - start = fastargs[1]; -skip_optional_pos: + iterable = fastargs[0]; + if (!noptargs) { + goto skip_optional_pos; + } + start = fastargs[1]; +skip_optional_pos: return_value = enum_new_impl(type, iterable, start); exit: @@ -68,13 +68,13 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("reversed", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) { + if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) { goto exit; } - seq = PyTuple_GET_ITEM(args, 0); + seq = PyTuple_GET_ITEM(args, 0); return_value = reversed_new_impl(type, seq); exit: return return_value; } -/*[clinic end generated code: output=e18c3fefcf914ec7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e18c3fefcf914ec7 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/floatobject.c.h b/contrib/tools/python3/src/Objects/clinic/floatobject.c.h index ae823cd0e4..b7554832b5 100644 --- a/contrib/tools/python3/src/Objects/clinic/floatobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/floatobject.c.h @@ -38,42 +38,42 @@ float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored)) return float___trunc___impl(self); } -PyDoc_STRVAR(float___floor____doc__, -"__floor__($self, /)\n" -"--\n" -"\n" -"Return the floor as an Integral."); - -#define FLOAT___FLOOR___METHODDEF \ - {"__floor__", (PyCFunction)float___floor__, METH_NOARGS, float___floor____doc__}, - -static PyObject * -float___floor___impl(PyObject *self); - -static PyObject * -float___floor__(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - return float___floor___impl(self); -} - -PyDoc_STRVAR(float___ceil____doc__, -"__ceil__($self, /)\n" -"--\n" -"\n" -"Return the ceiling as an Integral."); - -#define FLOAT___CEIL___METHODDEF \ - {"__ceil__", (PyCFunction)float___ceil__, METH_NOARGS, float___ceil____doc__}, - -static PyObject * -float___ceil___impl(PyObject *self); - -static PyObject * -float___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - return float___ceil___impl(self); -} - +PyDoc_STRVAR(float___floor____doc__, +"__floor__($self, /)\n" +"--\n" +"\n" +"Return the floor as an Integral."); + +#define FLOAT___FLOOR___METHODDEF \ + {"__floor__", (PyCFunction)float___floor__, METH_NOARGS, float___floor____doc__}, + +static PyObject * +float___floor___impl(PyObject *self); + +static PyObject * +float___floor__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return float___floor___impl(self); +} + +PyDoc_STRVAR(float___ceil____doc__, +"__ceil__($self, /)\n" +"--\n" +"\n" +"Return the ceiling as an Integral."); + +#define FLOAT___CEIL___METHODDEF \ + {"__ceil__", (PyCFunction)float___ceil__, METH_NOARGS, float___ceil____doc__}, + +static PyObject * +float___ceil___impl(PyObject *self); + +static PyObject * +float___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return float___ceil___impl(self); +} + PyDoc_STRVAR(float___round____doc__, "__round__($self, ndigits=None, /)\n" "--\n" @@ -83,7 +83,7 @@ PyDoc_STRVAR(float___round____doc__, "When an argument is passed, work like built-in round(x, ndigits)."); #define FLOAT___ROUND___METHODDEF \ - {"__round__", (PyCFunction)(void(*)(void))float___round__, METH_FASTCALL, float___round____doc__}, + {"__round__", (PyCFunction)(void(*)(void))float___round__, METH_FASTCALL, float___round____doc__}, static PyObject * float___round___impl(PyObject *self, PyObject *o_ndigits); @@ -92,16 +92,16 @@ static PyObject * float___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - PyObject *o_ndigits = Py_None; + PyObject *o_ndigits = Py_None; - if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - o_ndigits = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + o_ndigits = args[0]; +skip_optional: return_value = float___round___impl(self, o_ndigits); exit: @@ -212,14 +212,14 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("float", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) { + if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) { goto exit; } - if (PyTuple_GET_SIZE(args) < 1) { - goto skip_optional; - } - x = PyTuple_GET_ITEM(args, 0); -skip_optional: + if (PyTuple_GET_SIZE(args) < 1) { + goto skip_optional; + } + x = PyTuple_GET_ITEM(args, 0); +skip_optional: return_value = float_new_impl(type, x); exit: @@ -270,19 +270,19 @@ float___getformat__(PyTypeObject *type, PyObject *arg) PyObject *return_value = NULL; const char *typestr; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__getformat__", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__getformat__", "argument", "str", arg); + goto exit; + } + Py_ssize_t typestr_length; + typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length); + if (typestr == NULL) { + goto exit; + } + if (strlen(typestr) != (size_t)typestr_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } - Py_ssize_t typestr_length; - typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length); - if (typestr == NULL) { - goto exit; - } - if (strlen(typestr) != (size_t)typestr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = float___getformat___impl(type, typestr); exit: @@ -308,7 +308,7 @@ PyDoc_STRVAR(float___set_format____doc__, "This affects how floats are converted to and from binary strings."); #define FLOAT___SET_FORMAT___METHODDEF \ - {"__set_format__", (PyCFunction)(void(*)(void))float___set_format__, METH_FASTCALL|METH_CLASS, float___set_format____doc__}, + {"__set_format__", (PyCFunction)(void(*)(void))float___set_format__, METH_FASTCALL|METH_CLASS, float___set_format____doc__}, static PyObject * float___set_format___impl(PyTypeObject *type, const char *typestr, @@ -321,35 +321,35 @@ float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs const char *typestr; const char *fmt; - if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) { + if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("__set_format__", "argument 1", "str", args[0]); + goto exit; + } + Py_ssize_t typestr_length; + typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length); + if (typestr == NULL) { + goto exit; + } + if (strlen(typestr) != (size_t)typestr_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("__set_format__", "argument 2", "str", args[1]); + goto exit; + } + Py_ssize_t fmt_length; + fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length); + if (fmt == NULL) { + goto exit; + } + if (strlen(fmt) != (size_t)fmt_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("__set_format__", "argument 1", "str", args[0]); - goto exit; - } - Py_ssize_t typestr_length; - typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length); - if (typestr == NULL) { - goto exit; - } - if (strlen(typestr) != (size_t)typestr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("__set_format__", "argument 2", "str", args[1]); - goto exit; - } - Py_ssize_t fmt_length; - fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length); - if (fmt == NULL) { - goto exit; - } - if (strlen(fmt) != (size_t)fmt_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = float___set_format___impl(type, typestr, fmt); exit: @@ -374,17 +374,17 @@ float___format__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; PyObject *format_spec; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - format_spec = arg; + format_spec = arg; return_value = float___format___impl(self, format_spec); exit: return return_value; } -/*[clinic end generated code: output=25fbbe253f44e2df input=a9049054013a1b77]*/ +/*[clinic end generated code: output=25fbbe253f44e2df input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/funcobject.c.h b/contrib/tools/python3/src/Objects/clinic/funcobject.c.h index 736e2d5d49..17fb13fe08 100644 --- a/contrib/tools/python3/src/Objects/clinic/funcobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/funcobject.c.h @@ -28,51 +28,51 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "function", 0}; - PyObject *argsbuf[5]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2; + static _PyArg_Parser _parser = {NULL, _keywords, "function", 0}; + PyObject *argsbuf[5]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2; PyCodeObject *code; PyObject *globals; PyObject *name = Py_None; PyObject *defaults = Py_None; PyObject *closure = Py_None; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 5, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 5, 0, argsbuf); + if (!fastargs) { goto exit; } - if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) { - _PyArg_BadArgument("function", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]); - goto exit; - } - code = (PyCodeObject *)fastargs[0]; - if (!PyDict_Check(fastargs[1])) { - _PyArg_BadArgument("function", "argument 'globals'", "dict", fastargs[1]); - goto exit; - } - globals = fastargs[1]; - if (!noptargs) { - goto skip_optional_pos; - } - if (fastargs[2]) { - name = fastargs[2]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (fastargs[3]) { - defaults = fastargs[3]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - closure = fastargs[4]; -skip_optional_pos: + if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) { + _PyArg_BadArgument("function", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]); + goto exit; + } + code = (PyCodeObject *)fastargs[0]; + if (!PyDict_Check(fastargs[1])) { + _PyArg_BadArgument("function", "argument 'globals'", "dict", fastargs[1]); + goto exit; + } + globals = fastargs[1]; + if (!noptargs) { + goto skip_optional_pos; + } + if (fastargs[2]) { + name = fastargs[2]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (fastargs[3]) { + defaults = fastargs[3]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + closure = fastargs[4]; +skip_optional_pos: return_value = func_new_impl(type, code, globals, name, defaults, closure); exit: return return_value; } -/*[clinic end generated code: output=3d96afa3396e5c82 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3d96afa3396e5c82 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/listobject.c.h b/contrib/tools/python3/src/Objects/clinic/listobject.c.h index c8094ee3b9..ed137c95a8 100644 --- a/contrib/tools/python3/src/Objects/clinic/listobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/listobject.c.h @@ -9,7 +9,7 @@ PyDoc_STRVAR(list_insert__doc__, "Insert object before index."); #define LIST_INSERT_METHODDEF \ - {"insert", (PyCFunction)(void(*)(void))list_insert, METH_FASTCALL, list_insert__doc__}, + {"insert", (PyCFunction)(void(*)(void))list_insert, METH_FASTCALL, list_insert__doc__}, static PyObject * list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object); @@ -21,27 +21,27 @@ list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t index; PyObject *object; - if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { + if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; - } - object = args[1]; + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + index = ival; + } + object = args[1]; return_value = list_insert_impl(self, index, object); exit: @@ -111,7 +111,7 @@ PyDoc_STRVAR(list_pop__doc__, "Raises IndexError if list is empty or index is out of range."); #define LIST_POP_METHODDEF \ - {"pop", (PyCFunction)(void(*)(void))list_pop, METH_FASTCALL, list_pop__doc__}, + {"pop", (PyCFunction)(void(*)(void))list_pop, METH_FASTCALL, list_pop__doc__}, static PyObject * list_pop_impl(PyListObject *self, Py_ssize_t index); @@ -122,30 +122,30 @@ list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t index = -1; - if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } - if (nargs < 1) { - goto skip_optional; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - index = ival; - } -skip_optional: + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + index = ival; + } +skip_optional: return_value = list_pop_impl(self, index); exit: @@ -156,18 +156,18 @@ PyDoc_STRVAR(list_sort__doc__, "sort($self, /, *, key=None, reverse=False)\n" "--\n" "\n" -"Sort the list in ascending order and return None.\n" -"\n" -"The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n" -"order of two equal elements is maintained).\n" -"\n" -"If a key function is given, apply it once to each list item and sort them,\n" -"ascending or descending, according to their function values.\n" -"\n" -"The reverse flag can be set to sort in descending order."); +"Sort the list in ascending order and return None.\n" +"\n" +"The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n" +"order of two equal elements is maintained).\n" +"\n" +"If a key function is given, apply it once to each list item and sort them,\n" +"ascending or descending, according to their function values.\n" +"\n" +"The reverse flag can be set to sort in descending order."); #define LIST_SORT_METHODDEF \ - {"sort", (PyCFunction)(void(*)(void))list_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__}, + {"sort", (PyCFunction)(void(*)(void))list_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__}, static PyObject * list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse); @@ -177,35 +177,35 @@ list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "reverse", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *keyfunc = Py_None; int reverse = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_kwonly; - } - if (args[0]) { - keyfunc = args[0]; - if (!--noptargs) { - goto skip_optional_kwonly; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - reverse = _PyLong_AsInt(args[1]); - if (reverse == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_kwonly: + if (!noptargs) { + goto skip_optional_kwonly; + } + if (args[0]) { + keyfunc = args[0]; + if (!--noptargs) { + goto skip_optional_kwonly; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + reverse = _PyLong_AsInt(args[1]); + if (reverse == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_kwonly: return_value = list_sort_impl(self, keyfunc, reverse); exit: @@ -239,7 +239,7 @@ PyDoc_STRVAR(list_index__doc__, "Raises ValueError if the value is not present."); #define LIST_INDEX_METHODDEF \ - {"index", (PyCFunction)(void(*)(void))list_index, METH_FASTCALL, list_index__doc__}, + {"index", (PyCFunction)(void(*)(void))list_index, METH_FASTCALL, list_index__doc__}, static PyObject * list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start, @@ -253,23 +253,23 @@ list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t start = 0; Py_ssize_t stop = PY_SSIZE_T_MAX; - if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { + if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { goto exit; } - value = args[0]; - if (nargs < 2) { - goto skip_optional; - } - if (!_PyEval_SliceIndexNotNone(args[1], &start)) { - goto exit; - } - if (nargs < 3) { - goto skip_optional; - } - if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { - goto exit; - } -skip_optional: + value = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &start)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { + goto exit; + } +skip_optional: return_value = list_index_impl(self, value, start, stop); exit: @@ -314,18 +314,18 @@ list___init__(PyObject *self, PyObject *args, PyObject *kwargs) int return_value = -1; PyObject *iterable = NULL; - if (Py_IS_TYPE(self, &PyList_Type) && + if (Py_IS_TYPE(self, &PyList_Type) && !_PyArg_NoKeywords("list", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) { + if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) { goto exit; } - if (PyTuple_GET_SIZE(args) < 1) { - goto skip_optional; - } - iterable = PyTuple_GET_ITEM(args, 0); -skip_optional: + if (PyTuple_GET_SIZE(args) < 1) { + goto skip_optional; + } + iterable = PyTuple_GET_ITEM(args, 0); +skip_optional: return_value = list___init___impl((PyListObject *)self, iterable); exit: @@ -367,4 +367,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl(self); } -/*[clinic end generated code: output=1ff61490c091d165 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1ff61490c091d165 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/longobject.c.h b/contrib/tools/python3/src/Objects/clinic/longobject.c.h index 83db1f761a..27e8dfe935 100644 --- a/contrib/tools/python3/src/Objects/clinic/longobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/longobject.c.h @@ -10,29 +10,29 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"", "base", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "int", 0}; - PyObject *argsbuf[2]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "int", 0}; + PyObject *argsbuf[2]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; PyObject *x = NULL; PyObject *obase = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); + if (!fastargs) { goto exit; } - if (nargs < 1) { - goto skip_optional_posonly; - } - noptargs--; - x = fastargs[0]; -skip_optional_posonly: - if (!noptargs) { - goto skip_optional_pos; - } - obase = fastargs[1]; -skip_optional_pos: + if (nargs < 1) { + goto skip_optional_posonly; + } + noptargs--; + x = fastargs[0]; +skip_optional_posonly: + if (!noptargs) { + goto skip_optional_pos; + } + obase = fastargs[1]; +skip_optional_pos: return_value = long_new_impl(type, x, obase); exit: @@ -73,14 +73,14 @@ int___format__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; PyObject *format_spec; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "argument", "str", arg); goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - format_spec = arg; + if (PyUnicode_READY(arg) == -1) { + goto exit; + } + format_spec = arg; return_value = int___format___impl(self, format_spec); exit: @@ -138,34 +138,34 @@ int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored)) return int_bit_length_impl(self); } -PyDoc_STRVAR(int_as_integer_ratio__doc__, -"as_integer_ratio($self, /)\n" -"--\n" -"\n" -"Return integer ratio.\n" -"\n" -"Return a pair of integers, whose ratio is exactly equal to the original int\n" -"and with a positive denominator.\n" -"\n" -">>> (10).as_integer_ratio()\n" -"(10, 1)\n" -">>> (-10).as_integer_ratio()\n" -"(-10, 1)\n" -">>> (0).as_integer_ratio()\n" -"(0, 1)"); - -#define INT_AS_INTEGER_RATIO_METHODDEF \ - {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__}, - -static PyObject * -int_as_integer_ratio_impl(PyObject *self); - -static PyObject * -int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - return int_as_integer_ratio_impl(self); -} - +PyDoc_STRVAR(int_as_integer_ratio__doc__, +"as_integer_ratio($self, /)\n" +"--\n" +"\n" +"Return integer ratio.\n" +"\n" +"Return a pair of integers, whose ratio is exactly equal to the original int\n" +"and with a positive denominator.\n" +"\n" +">>> (10).as_integer_ratio()\n" +"(10, 1)\n" +">>> (-10).as_integer_ratio()\n" +"(-10, 1)\n" +">>> (0).as_integer_ratio()\n" +"(0, 1)"); + +#define INT_AS_INTEGER_RATIO_METHODDEF \ + {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__}, + +static PyObject * +int_as_integer_ratio_impl(PyObject *self); + +static PyObject * +int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return int_as_integer_ratio_impl(self); +} + PyDoc_STRVAR(int_to_bytes__doc__, "to_bytes($self, /, length, byteorder, *, signed=False)\n" "--\n" @@ -187,7 +187,7 @@ PyDoc_STRVAR(int_to_bytes__doc__, " is raised."); #define INT_TO_BYTES_METHODDEF \ - {"to_bytes", (PyCFunction)(void(*)(void))int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__}, + {"to_bytes", (PyCFunction)(void(*)(void))int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__}, static PyObject * int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, @@ -198,50 +198,50 @@ int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * { PyObject *return_value = NULL; static const char * const _keywords[] = {"length", "byteorder", "signed", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "to_bytes", 0}; - PyObject *argsbuf[3]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; + static _PyArg_Parser _parser = {NULL, _keywords, "to_bytes", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; Py_ssize_t length; PyObject *byteorder; int is_signed = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - length = ival; - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]); - goto exit; - } - if (PyUnicode_READY(args[1]) == -1) { - goto exit; - } - byteorder = args[1]; - if (!noptargs) { - goto skip_optional_kwonly; - } - is_signed = PyObject_IsTrue(args[2]); - if (is_signed < 0) { - goto exit; - } -skip_optional_kwonly: + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + length = ival; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + byteorder = args[1]; + if (!noptargs) { + goto skip_optional_kwonly; + } + is_signed = PyObject_IsTrue(args[2]); + if (is_signed < 0) { + goto exit; + } +skip_optional_kwonly: return_value = int_to_bytes_impl(self, length, byteorder, is_signed); exit: @@ -269,7 +269,7 @@ PyDoc_STRVAR(int_from_bytes__doc__, " Indicates whether two\'s complement is used to represent the integer."); #define INT_FROM_BYTES_METHODDEF \ - {"from_bytes", (PyCFunction)(void(*)(void))int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__}, + {"from_bytes", (PyCFunction)(void(*)(void))int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__}, static PyObject * int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, @@ -280,37 +280,37 @@ int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "from_bytes", 0}; - PyObject *argsbuf[3]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; + static _PyArg_Parser _parser = {NULL, _keywords, "from_bytes", 0}; + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; PyObject *bytes_obj; PyObject *byteorder; int is_signed = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + bytes_obj = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + byteorder = args[1]; + if (!noptargs) { + goto skip_optional_kwonly; + } + is_signed = PyObject_IsTrue(args[2]); + if (is_signed < 0) { goto exit; } - bytes_obj = args[0]; - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]); - goto exit; - } - if (PyUnicode_READY(args[1]) == -1) { - goto exit; - } - byteorder = args[1]; - if (!noptargs) { - goto skip_optional_kwonly; - } - is_signed = PyObject_IsTrue(args[2]); - if (is_signed < 0) { - goto exit; - } -skip_optional_kwonly: +skip_optional_kwonly: return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed); exit: return return_value; } -/*[clinic end generated code: output=77bc3b2615822cb8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=77bc3b2615822cb8 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/memoryobject.c.h b/contrib/tools/python3/src/Objects/clinic/memoryobject.c.h index 3cd265fb8d..75ac201126 100644 --- a/contrib/tools/python3/src/Objects/clinic/memoryobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/memoryobject.c.h @@ -1,74 +1,74 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(memoryview_hex__doc__, -"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" -"--\n" -"\n" -"Return the data in the buffer as a str of hexadecimal numbers.\n" -"\n" -" sep\n" -" An optional single character or byte to separate hex bytes.\n" -" bytes_per_sep\n" -" How many bytes between separators. Positive values count from the\n" -" right, negative values count from the left.\n" -"\n" -"Example:\n" -">>> value = memoryview(b\'\\xb9\\x01\\xef\')\n" -">>> value.hex()\n" -"\'b901ef\'\n" -">>> value.hex(\':\')\n" -"\'b9:01:ef\'\n" -">>> value.hex(\':\', 2)\n" -"\'b9:01ef\'\n" -">>> value.hex(\':\', -2)\n" -"\'b901:ef\'"); - -#define MEMORYVIEW_HEX_METHODDEF \ - {"hex", (PyCFunction)(void(*)(void))memoryview_hex, METH_FASTCALL|METH_KEYWORDS, memoryview_hex__doc__}, - -static PyObject * -memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep, - int bytes_per_sep); - -static PyObject * -memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - PyObject *sep = NULL; - int bytes_per_sep = 1; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - bytes_per_sep = _PyLong_AsInt(args[1]); - if (bytes_per_sep == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: - return_value = memoryview_hex_impl(self, sep, bytes_per_sep); - -exit: - return return_value; -} -/*[clinic end generated code: output=ee265a73f68b0077 input=a9049054013a1b77]*/ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(memoryview_hex__doc__, +"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n" +"--\n" +"\n" +"Return the data in the buffer as a str of hexadecimal numbers.\n" +"\n" +" sep\n" +" An optional single character or byte to separate hex bytes.\n" +" bytes_per_sep\n" +" How many bytes between separators. Positive values count from the\n" +" right, negative values count from the left.\n" +"\n" +"Example:\n" +">>> value = memoryview(b\'\\xb9\\x01\\xef\')\n" +">>> value.hex()\n" +"\'b901ef\'\n" +">>> value.hex(\':\')\n" +"\'b9:01:ef\'\n" +">>> value.hex(\':\', 2)\n" +"\'b9:01ef\'\n" +">>> value.hex(\':\', -2)\n" +"\'b901:ef\'"); + +#define MEMORYVIEW_HEX_METHODDEF \ + {"hex", (PyCFunction)(void(*)(void))memoryview_hex, METH_FASTCALL|METH_KEYWORDS, memoryview_hex__doc__}, + +static PyObject * +memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep, + int bytes_per_sep); + +static PyObject * +memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + PyObject *sep = NULL; + int bytes_per_sep = 1; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + bytes_per_sep = _PyLong_AsInt(args[1]); + if (bytes_per_sep == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: + return_value = memoryview_hex_impl(self, sep, bytes_per_sep); + +exit: + return return_value; +} +/*[clinic end generated code: output=ee265a73f68b0077 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/moduleobject.c.h b/contrib/tools/python3/src/Objects/clinic/moduleobject.c.h index ad659231fa..c1534eaee2 100644 --- a/contrib/tools/python3/src/Objects/clinic/moduleobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/moduleobject.c.h @@ -18,34 +18,34 @@ module___init__(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; static const char * const _keywords[] = {"name", "doc", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "module", 0}; - PyObject *argsbuf[2]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "module", 0}; + PyObject *argsbuf[2]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; PyObject *name; PyObject *doc = Py_None; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); + if (!fastargs) { goto exit; } - if (!PyUnicode_Check(fastargs[0])) { - _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]); - goto exit; - } - if (PyUnicode_READY(fastargs[0]) == -1) { - goto exit; - } - name = fastargs[0]; - if (!noptargs) { - goto skip_optional_pos; - } - doc = fastargs[1]; -skip_optional_pos: + if (!PyUnicode_Check(fastargs[0])) { + _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]); + goto exit; + } + if (PyUnicode_READY(fastargs[0]) == -1) { + goto exit; + } + name = fastargs[0]; + if (!noptargs) { + goto skip_optional_pos; + } + doc = fastargs[1]; +skip_optional_pos: return_value = module___init___impl((PyModuleObject *)self, name, doc); exit: return return_value; } -/*[clinic end generated code: output=680276bc3a496d7a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=680276bc3a496d7a input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/odictobject.c.h b/contrib/tools/python3/src/Objects/clinic/odictobject.c.h index 38b0e3b22a..f43bc14ce1 100644 --- a/contrib/tools/python3/src/Objects/clinic/odictobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/odictobject.c.h @@ -9,7 +9,7 @@ PyDoc_STRVAR(OrderedDict_fromkeys__doc__, "Create a new ordered dictionary with keys from iterable and values set to value."); #define ORDEREDDICT_FROMKEYS_METHODDEF \ - {"fromkeys", (PyCFunction)(void(*)(void))OrderedDict_fromkeys, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__}, + {"fromkeys", (PyCFunction)(void(*)(void))OrderedDict_fromkeys, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__}, static PyObject * OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value); @@ -19,22 +19,22 @@ OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs { PyObject *return_value = NULL; static const char * const _keywords[] = {"iterable", "value", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "fromkeys", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "fromkeys", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *seq; PyObject *value = Py_None; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } - seq = args[0]; - if (!noptargs) { - goto skip_optional_pos; - } - value = args[1]; -skip_optional_pos: + seq = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + value = args[1]; +skip_optional_pos: return_value = OrderedDict_fromkeys_impl(type, seq, value); exit: @@ -50,7 +50,7 @@ PyDoc_STRVAR(OrderedDict_setdefault__doc__, "Return the value for key if key is in the dictionary, else default."); #define ORDEREDDICT_SETDEFAULT_METHODDEF \ - {"setdefault", (PyCFunction)(void(*)(void))OrderedDict_setdefault, METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__}, + {"setdefault", (PyCFunction)(void(*)(void))OrderedDict_setdefault, METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__}, static PyObject * OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key, @@ -61,22 +61,22 @@ OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t na { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "default", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "setdefault", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "setdefault", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *key; PyObject *default_value = Py_None; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } - key = args[0]; - if (!noptargs) { - goto skip_optional_pos; - } - default_value = args[1]; -skip_optional_pos: + key = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + default_value = args[1]; +skip_optional_pos: return_value = OrderedDict_setdefault_impl(self, key, default_value); exit: @@ -92,7 +92,7 @@ PyDoc_STRVAR(OrderedDict_popitem__doc__, "Pairs are returned in LIFO order if last is true or FIFO order if false."); #define ORDEREDDICT_POPITEM_METHODDEF \ - {"popitem", (PyCFunction)(void(*)(void))OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__}, + {"popitem", (PyCFunction)(void(*)(void))OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__}, static PyObject * OrderedDict_popitem_impl(PyODictObject *self, int last); @@ -102,23 +102,23 @@ OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs { PyObject *return_value = NULL; static const char * const _keywords[] = {"last", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "popitem", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "popitem", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int last = 1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + last = PyObject_IsTrue(args[0]); + if (last < 0) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - last = PyObject_IsTrue(args[0]); - if (last < 0) { - goto exit; - } -skip_optional_pos: +skip_optional_pos: return_value = OrderedDict_popitem_impl(self, last); exit: @@ -134,7 +134,7 @@ PyDoc_STRVAR(OrderedDict_move_to_end__doc__, "Raise KeyError if the element does not exist."); #define ORDEREDDICT_MOVE_TO_END_METHODDEF \ - {"move_to_end", (PyCFunction)(void(*)(void))OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__}, + {"move_to_end", (PyCFunction)(void(*)(void))OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__}, static PyObject * OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last); @@ -144,28 +144,28 @@ OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t n { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "last", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "move_to_end", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "move_to_end", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; PyObject *key; int last = 1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { + goto exit; + } + key = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + last = PyObject_IsTrue(args[1]); + if (last < 0) { goto exit; } - key = args[0]; - if (!noptargs) { - goto skip_optional_pos; - } - last = PyObject_IsTrue(args[1]); - if (last < 0) { - goto exit; - } -skip_optional_pos: +skip_optional_pos: return_value = OrderedDict_move_to_end_impl(self, key, last); exit: return return_value; } -/*[clinic end generated code: output=8eb1296df9142908 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8eb1296df9142908 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/structseq.c.h b/contrib/tools/python3/src/Objects/clinic/structseq.c.h index c2c952fa2c..b3b4836543 100644 --- a/contrib/tools/python3/src/Objects/clinic/structseq.c.h +++ b/contrib/tools/python3/src/Objects/clinic/structseq.c.h @@ -10,27 +10,27 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"sequence", "dict", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "structseq", 0}; - PyObject *argsbuf[2]; - PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; + static _PyArg_Parser _parser = {NULL, _keywords, "structseq", 0}; + PyObject *argsbuf[2]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; PyObject *arg; PyObject *dict = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); - if (!fastargs) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf); + if (!fastargs) { goto exit; } - arg = fastargs[0]; - if (!noptargs) { - goto skip_optional_pos; - } - dict = fastargs[1]; -skip_optional_pos: + arg = fastargs[0]; + if (!noptargs) { + goto skip_optional_pos; + } + dict = fastargs[1]; +skip_optional_pos: return_value = structseq_new_impl(type, arg, dict); exit: return return_value; } -/*[clinic end generated code: output=ed3019acf49b656c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ed3019acf49b656c input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/tupleobject.c.h b/contrib/tools/python3/src/Objects/clinic/tupleobject.c.h index 1184a161a7..fe2fae42ee 100644 --- a/contrib/tools/python3/src/Objects/clinic/tupleobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/tupleobject.c.h @@ -11,7 +11,7 @@ PyDoc_STRVAR(tuple_index__doc__, "Raises ValueError if the value is not present."); #define TUPLE_INDEX_METHODDEF \ - {"index", (PyCFunction)(void(*)(void))tuple_index, METH_FASTCALL, tuple_index__doc__}, + {"index", (PyCFunction)(void(*)(void))tuple_index, METH_FASTCALL, tuple_index__doc__}, static PyObject * tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start, @@ -25,23 +25,23 @@ tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t start = 0; Py_ssize_t stop = PY_SSIZE_T_MAX; - if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { + if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { goto exit; } - value = args[0]; - if (nargs < 2) { - goto skip_optional; - } - if (!_PyEval_SliceIndexNotNone(args[1], &start)) { - goto exit; - } - if (nargs < 3) { - goto skip_optional; - } - if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { - goto exit; - } -skip_optional: + value = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &start)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { + goto exit; + } +skip_optional: return_value = tuple_index_impl(self, value, start, stop); exit: @@ -81,14 +81,14 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("tuple", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) { + if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) { goto exit; } - if (PyTuple_GET_SIZE(args) < 1) { - goto skip_optional; - } - iterable = PyTuple_GET_ITEM(args, 0); -skip_optional: + if (PyTuple_GET_SIZE(args) < 1) { + goto skip_optional; + } + iterable = PyTuple_GET_ITEM(args, 0); +skip_optional: return_value = tuple_new_impl(type, iterable); exit: @@ -111,4 +111,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored)) { return tuple___getnewargs___impl(self); } -/*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/typeobject.c.h b/contrib/tools/python3/src/Objects/clinic/typeobject.c.h index 3f0b9b604c..357eb44b12 100644 --- a/contrib/tools/python3/src/Objects/clinic/typeobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/typeobject.c.h @@ -166,15 +166,15 @@ object___reduce_ex__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; int protocol; - if (PyFloat_Check(arg)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + protocol = _PyLong_AsInt(arg); + if (protocol == -1 && PyErr_Occurred()) { goto exit; } - protocol = _PyLong_AsInt(arg); - if (protocol == -1 && PyErr_Occurred()) { - goto exit; - } return_value = object___reduce_ex___impl(self, protocol); exit: @@ -199,14 +199,14 @@ object___format__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; PyObject *format_spec; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - format_spec = arg; + format_spec = arg; return_value = object___format___impl(self, format_spec); exit: @@ -248,4 +248,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return object___dir___impl(self); } -/*[clinic end generated code: output=7a6d272d282308f3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7a6d272d282308f3 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/clinic/unicodeobject.c.h b/contrib/tools/python3/src/Objects/clinic/unicodeobject.c.h index 892d9ba134..cf81df4af6 100644 --- a/contrib/tools/python3/src/Objects/clinic/unicodeobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/unicodeobject.c.h @@ -71,7 +71,7 @@ PyDoc_STRVAR(unicode_center__doc__, "Padding is done using the specified fill character (default is a space)."); #define UNICODE_CENTER_METHODDEF \ - {"center", (PyCFunction)(void(*)(void))unicode_center, METH_FASTCALL, unicode_center__doc__}, + {"center", (PyCFunction)(void(*)(void))unicode_center, METH_FASTCALL, unicode_center__doc__}, static PyObject * unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar); @@ -83,33 +83,33 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (!convert_uc(args[1], &fillchar)) { - goto exit; - } -skip_optional: + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { + goto exit; + } +skip_optional: return_value = unicode_center_impl(self, width, fillchar); exit: @@ -132,7 +132,7 @@ PyDoc_STRVAR(unicode_encode__doc__, " codecs.register_error that can handle UnicodeEncodeErrors."); #define UNICODE_ENCODE_METHODDEF \ - {"encode", (PyCFunction)(void(*)(void))unicode_encode, METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__}, + {"encode", (PyCFunction)(void(*)(void))unicode_encode, METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__}, static PyObject * unicode_encode_impl(PyObject *self, const char *encoding, const char *errors); @@ -142,51 +142,51 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"encoding", "errors", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; const char *encoding = NULL; const char *errors = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]); - goto exit; - } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); - if (encoding == NULL) { - goto exit; - } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]); - goto exit; - } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); - if (errors == NULL) { - goto exit; - } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]); + goto exit; + } + Py_ssize_t encoding_length; + encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + if (encoding == NULL) { + goto exit; + } + if (strlen(encoding) != (size_t)encoding_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]); + goto exit; + } + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } +skip_optional_pos: return_value = unicode_encode_impl(self, encoding, errors); exit: @@ -202,7 +202,7 @@ PyDoc_STRVAR(unicode_expandtabs__doc__, "If tabsize is not given, a tab size of 8 characters is assumed."); #define UNICODE_EXPANDTABS_METHODDEF \ - {"expandtabs", (PyCFunction)(void(*)(void))unicode_expandtabs, METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__}, + {"expandtabs", (PyCFunction)(void(*)(void))unicode_expandtabs, METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__}, static PyObject * unicode_expandtabs_impl(PyObject *self, int tabsize); @@ -212,28 +212,28 @@ unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"tabsize", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int tabsize = 8; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - tabsize = _PyLong_AsInt(args[0]); - if (tabsize == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + tabsize = _PyLong_AsInt(args[0]); + if (tabsize == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: return_value = unicode_expandtabs_impl(self, tabsize); exit: @@ -456,8 +456,8 @@ PyDoc_STRVAR(unicode_isidentifier__doc__, "\n" "Return True if the string is a valid Python identifier, False otherwise.\n" "\n" -"Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n" -"such as \"def\" or \"class\"."); +"Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n" +"such as \"def\" or \"class\"."); #define UNICODE_ISIDENTIFIER_METHODDEF \ {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__}, @@ -515,7 +515,7 @@ PyDoc_STRVAR(unicode_ljust__doc__, "Padding is done using the specified fill character (default is a space)."); #define UNICODE_LJUST_METHODDEF \ - {"ljust", (PyCFunction)(void(*)(void))unicode_ljust, METH_FASTCALL, unicode_ljust__doc__}, + {"ljust", (PyCFunction)(void(*)(void))unicode_ljust, METH_FASTCALL, unicode_ljust__doc__}, static PyObject * unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar); @@ -527,33 +527,33 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (!convert_uc(args[1], &fillchar)) { - goto exit; - } -skip_optional: +skip_optional: return_value = unicode_ljust_impl(self, width, fillchar); exit: @@ -582,12 +582,12 @@ PyDoc_STRVAR(unicode_strip__doc__, "strip($self, chars=None, /)\n" "--\n" "\n" -"Return a copy of the string with leading and trailing whitespace removed.\n" +"Return a copy of the string with leading and trailing whitespace removed.\n" "\n" "If chars is given and not None, remove characters in chars instead."); #define UNICODE_STRIP_METHODDEF \ - {"strip", (PyCFunction)(void(*)(void))unicode_strip, METH_FASTCALL, unicode_strip__doc__}, + {"strip", (PyCFunction)(void(*)(void))unicode_strip, METH_FASTCALL, unicode_strip__doc__}, static PyObject * unicode_strip_impl(PyObject *self, PyObject *chars); @@ -598,14 +598,14 @@ unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *chars = Py_None; - if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - chars = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + chars = args[0]; +skip_optional: return_value = unicode_strip_impl(self, chars); exit: @@ -621,7 +621,7 @@ PyDoc_STRVAR(unicode_lstrip__doc__, "If chars is given and not None, remove characters in chars instead."); #define UNICODE_LSTRIP_METHODDEF \ - {"lstrip", (PyCFunction)(void(*)(void))unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__}, + {"lstrip", (PyCFunction)(void(*)(void))unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__}, static PyObject * unicode_lstrip_impl(PyObject *self, PyObject *chars); @@ -630,16 +630,16 @@ static PyObject * unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - PyObject *chars = Py_None; + PyObject *chars = Py_None; - if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - chars = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + chars = args[0]; +skip_optional: return_value = unicode_lstrip_impl(self, chars); exit: @@ -655,7 +655,7 @@ PyDoc_STRVAR(unicode_rstrip__doc__, "If chars is given and not None, remove characters in chars instead."); #define UNICODE_RSTRIP_METHODDEF \ - {"rstrip", (PyCFunction)(void(*)(void))unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__}, + {"rstrip", (PyCFunction)(void(*)(void))unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__}, static PyObject * unicode_rstrip_impl(PyObject *self, PyObject *chars); @@ -664,16 +664,16 @@ static PyObject * unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - PyObject *chars = Py_None; + PyObject *chars = Py_None; - if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { + if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) { goto exit; } - if (nargs < 1) { - goto skip_optional; - } - chars = args[0]; -skip_optional: + if (nargs < 1) { + goto skip_optional; + } + chars = args[0]; +skip_optional: return_value = unicode_rstrip_impl(self, chars); exit: @@ -694,7 +694,7 @@ PyDoc_STRVAR(unicode_replace__doc__, "replaced."); #define UNICODE_REPLACE_METHODDEF \ - {"replace", (PyCFunction)(void(*)(void))unicode_replace, METH_FASTCALL, unicode_replace__doc__}, + {"replace", (PyCFunction)(void(*)(void))unicode_replace, METH_FASTCALL, unicode_replace__doc__}, static PyObject * unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new, @@ -708,123 +708,123 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *new; Py_ssize_t count = -1; - if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("replace", "argument 1", "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + old = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("replace", "argument 2", "str", args[1]); goto exit; } - if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("replace", "argument 1", "str", args[0]); - goto exit; - } - if (PyUnicode_READY(args[0]) == -1) { - goto exit; - } - old = args[0]; - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("replace", "argument 2", "str", args[1]); - goto exit; - } - if (PyUnicode_READY(args[1]) == -1) { - goto exit; - } - new = args[1]; - if (nargs < 3) { - goto skip_optional; - } - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - count = ival; - } -skip_optional: + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + new = args[1]; + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = unicode_replace_impl(self, old, new, count); exit: return return_value; } -PyDoc_STRVAR(unicode_removeprefix__doc__, -"removeprefix($self, prefix, /)\n" -"--\n" -"\n" -"Return a str with the given prefix string removed if present.\n" -"\n" -"If the string starts with the prefix string, return string[len(prefix):].\n" -"Otherwise, return a copy of the original string."); - -#define UNICODE_REMOVEPREFIX_METHODDEF \ - {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__}, - -static PyObject * -unicode_removeprefix_impl(PyObject *self, PyObject *prefix); - -static PyObject * -unicode_removeprefix(PyObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *prefix; - - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("removeprefix", "argument", "str", arg); - goto exit; - } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - prefix = arg; - return_value = unicode_removeprefix_impl(self, prefix); - -exit: - return return_value; -} - -PyDoc_STRVAR(unicode_removesuffix__doc__, -"removesuffix($self, suffix, /)\n" -"--\n" -"\n" -"Return a str with the given suffix string removed if present.\n" -"\n" -"If the string ends with the suffix string and that suffix is not empty,\n" -"return string[:-len(suffix)]. Otherwise, return a copy of the original\n" -"string."); - -#define UNICODE_REMOVESUFFIX_METHODDEF \ - {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__}, - -static PyObject * -unicode_removesuffix_impl(PyObject *self, PyObject *suffix); - -static PyObject * -unicode_removesuffix(PyObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - PyObject *suffix; - - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("removesuffix", "argument", "str", arg); - goto exit; - } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - suffix = arg; - return_value = unicode_removesuffix_impl(self, suffix); - -exit: - return return_value; -} - +PyDoc_STRVAR(unicode_removeprefix__doc__, +"removeprefix($self, prefix, /)\n" +"--\n" +"\n" +"Return a str with the given prefix string removed if present.\n" +"\n" +"If the string starts with the prefix string, return string[len(prefix):].\n" +"Otherwise, return a copy of the original string."); + +#define UNICODE_REMOVEPREFIX_METHODDEF \ + {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__}, + +static PyObject * +unicode_removeprefix_impl(PyObject *self, PyObject *prefix); + +static PyObject * +unicode_removeprefix(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + PyObject *prefix; + + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("removeprefix", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { + goto exit; + } + prefix = arg; + return_value = unicode_removeprefix_impl(self, prefix); + +exit: + return return_value; +} + +PyDoc_STRVAR(unicode_removesuffix__doc__, +"removesuffix($self, suffix, /)\n" +"--\n" +"\n" +"Return a str with the given suffix string removed if present.\n" +"\n" +"If the string ends with the suffix string and that suffix is not empty,\n" +"return string[:-len(suffix)]. Otherwise, return a copy of the original\n" +"string."); + +#define UNICODE_REMOVESUFFIX_METHODDEF \ + {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__}, + +static PyObject * +unicode_removesuffix_impl(PyObject *self, PyObject *suffix); + +static PyObject * +unicode_removesuffix(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + PyObject *suffix; + + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("removesuffix", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { + goto exit; + } + suffix = arg; + return_value = unicode_removesuffix_impl(self, suffix); + +exit: + return return_value; +} + PyDoc_STRVAR(unicode_rjust__doc__, "rjust($self, width, fillchar=\' \', /)\n" "--\n" @@ -834,7 +834,7 @@ PyDoc_STRVAR(unicode_rjust__doc__, "Padding is done using the specified fill character (default is a space)."); #define UNICODE_RJUST_METHODDEF \ - {"rjust", (PyCFunction)(void(*)(void))unicode_rjust, METH_FASTCALL, unicode_rjust__doc__}, + {"rjust", (PyCFunction)(void(*)(void))unicode_rjust, METH_FASTCALL, unicode_rjust__doc__}, static PyObject * unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar); @@ -846,33 +846,33 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { + if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (!convert_uc(args[1], &fillchar)) { - goto exit; - } -skip_optional: +skip_optional: return_value = unicode_rjust_impl(self, width, fillchar); exit: @@ -894,7 +894,7 @@ PyDoc_STRVAR(unicode_split__doc__, " -1 (the default value) means no limit."); #define UNICODE_SPLIT_METHODDEF \ - {"split", (PyCFunction)(void(*)(void))unicode_split, METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__}, + {"split", (PyCFunction)(void(*)(void))unicode_split, METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__}, static PyObject * unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit); @@ -904,43 +904,43 @@ unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "split", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = unicode_split_impl(self, sep, maxsplit); exit: @@ -996,7 +996,7 @@ PyDoc_STRVAR(unicode_rsplit__doc__, "Splits are done starting at the end of the string and working to the front."); #define UNICODE_RSPLIT_METHODDEF \ - {"rsplit", (PyCFunction)(void(*)(void))unicode_rsplit, METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__}, + {"rsplit", (PyCFunction)(void(*)(void))unicode_rsplit, METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__}, static PyObject * unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit); @@ -1006,43 +1006,43 @@ unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"sep", "maxsplit", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; PyObject *sep = Py_None; Py_ssize_t maxsplit = -1; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (args[0]) { - sep = args[0]; - if (!--noptargs) { - goto skip_optional_pos; - } - } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - maxsplit = ival; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + sep = args[0]; + if (!--noptargs) { + goto skip_optional_pos; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + maxsplit = ival; + } +skip_optional_pos: return_value = unicode_rsplit_impl(self, sep, maxsplit); exit: @@ -1059,7 +1059,7 @@ PyDoc_STRVAR(unicode_splitlines__doc__, "true."); #define UNICODE_SPLITLINES_METHODDEF \ - {"splitlines", (PyCFunction)(void(*)(void))unicode_splitlines, METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__}, + {"splitlines", (PyCFunction)(void(*)(void))unicode_splitlines, METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__}, static PyObject * unicode_splitlines_impl(PyObject *self, int keepends); @@ -1069,28 +1069,28 @@ unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"keepends", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int keepends = 0; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - keepends = _PyLong_AsInt(args[0]); - if (keepends == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + keepends = _PyLong_AsInt(args[0]); + if (keepends == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: return_value = unicode_splitlines_impl(self, keepends); exit: @@ -1116,7 +1116,7 @@ unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored)) } PyDoc_STRVAR(unicode_maketrans__doc__, -"maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)\n" +"maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)\n" "--\n" "\n" "Return a translation table usable for str.translate().\n" @@ -1130,7 +1130,7 @@ PyDoc_STRVAR(unicode_maketrans__doc__, "must be a string, whose characters will be mapped to None in the result."); #define UNICODE_MAKETRANS_METHODDEF \ - {"maketrans", (PyCFunction)(void(*)(void))unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__}, + {"maketrans", (PyCFunction)(void(*)(void))unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__}, static PyObject * unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z); @@ -1143,33 +1143,33 @@ unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) PyObject *y = NULL; PyObject *z = NULL; - if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) { + if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) { + goto exit; + } + x = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + y = args[1]; + if (nargs < 3) { + goto skip_optional; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("maketrans", "argument 3", "str", args[2]); + goto exit; + } + if (PyUnicode_READY(args[2]) == -1) { goto exit; } - x = args[0]; - if (nargs < 2) { - goto skip_optional; - } - if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]); - goto exit; - } - if (PyUnicode_READY(args[1]) == -1) { - goto exit; - } - y = args[1]; - if (nargs < 3) { - goto skip_optional; - } - if (!PyUnicode_Check(args[2])) { - _PyArg_BadArgument("maketrans", "argument 3", "str", args[2]); - goto exit; - } - if (PyUnicode_READY(args[2]) == -1) { - goto exit; - } - z = args[2]; -skip_optional: + z = args[2]; +skip_optional: return_value = unicode_maketrans_impl(x, y, z); exit: @@ -1231,23 +1231,23 @@ unicode_zfill(PyObject *self, PyObject *arg) PyObject *return_value = NULL; Py_ssize_t width; - if (PyFloat_Check(arg)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } return_value = unicode_zfill_impl(self, width); exit: @@ -1272,14 +1272,14 @@ unicode___format__(PyObject *self, PyObject *arg) PyObject *return_value = NULL; PyObject *format_spec; - if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "argument", "str", arg); + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { goto exit; } - if (PyUnicode_READY(arg) == -1) { - goto exit; - } - format_spec = arg; + format_spec = arg; return_value = unicode___format___impl(self, format_spec); exit: @@ -1303,4 +1303,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=b91233f3722643be input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b91233f3722643be input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/codeobject.c b/contrib/tools/python3/src/Objects/codeobject.c index 9bc5a51c44..cb4fb68124 100644 --- a/contrib/tools/python3/src/Objects/codeobject.c +++ b/contrib/tools/python3/src/Objects/codeobject.c @@ -2,13 +2,13 @@ #include "Python.h" #include "code.h" -#include "opcode.h" -#include "structmember.h" // PyMemberDef -#include "pycore_code.h" -#include "pycore_interp.h" // PyInterpreterState.co_extra_freefuncs -#include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_tupleobject.h" -#include "clinic/codeobject.c.h" +#include "opcode.h" +#include "structmember.h" // PyMemberDef +#include "pycore_code.h" +#include "pycore_interp.h" // PyInterpreterState.co_extra_freefuncs +#include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_tupleobject.h" +#include "clinic/codeobject.c.h" /* Holder for co_extra information */ typedef struct { @@ -16,11 +16,11 @@ typedef struct { void *ce_extras[1]; } _PyCodeObjectExtra; -/*[clinic input] -class code "PyCodeObject *" "&PyCode_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78aa5d576683bb4b]*/ - +/*[clinic input] +class code "PyCodeObject *" "&PyCode_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78aa5d576683bb4b]*/ + /* all_name_chars(s): true iff s matches [a-zA-Z0-9_]* */ static int all_name_chars(PyObject *o) @@ -39,7 +39,7 @@ all_name_chars(PyObject *o) return 1; } -static int +static int intern_strings(PyObject *tuple) { Py_ssize_t i; @@ -47,88 +47,88 @@ intern_strings(PyObject *tuple) for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { PyObject *v = PyTuple_GET_ITEM(tuple, i); if (v == NULL || !PyUnicode_CheckExact(v)) { - PyErr_SetString(PyExc_SystemError, - "non-string found in code slot"); - return -1; + PyErr_SetString(PyExc_SystemError, + "non-string found in code slot"); + return -1; } - PyUnicode_InternInPlace(&_PyTuple_ITEMS(tuple)[i]); + PyUnicode_InternInPlace(&_PyTuple_ITEMS(tuple)[i]); } - return 0; + return 0; } /* Intern selected string constants */ static int -intern_string_constants(PyObject *tuple, int *modified) +intern_string_constants(PyObject *tuple, int *modified) { - for (Py_ssize_t i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { + for (Py_ssize_t i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { PyObject *v = PyTuple_GET_ITEM(tuple, i); if (PyUnicode_CheckExact(v)) { if (PyUnicode_READY(v) == -1) { - return -1; + return -1; } - + if (all_name_chars(v)) { PyObject *w = v; PyUnicode_InternInPlace(&v); if (w != v) { PyTuple_SET_ITEM(tuple, i, v); - if (modified) { - *modified = 1; - } + if (modified) { + *modified = 1; + } } } } else if (PyTuple_CheckExact(v)) { - if (intern_string_constants(v, NULL) < 0) { - return -1; - } + if (intern_string_constants(v, NULL) < 0) { + return -1; + } } else if (PyFrozenSet_CheckExact(v)) { PyObject *w = v; PyObject *tmp = PySequence_Tuple(v); if (tmp == NULL) { - return -1; + return -1; + } + int tmp_modified = 0; + if (intern_string_constants(tmp, &tmp_modified) < 0) { + Py_DECREF(tmp); + return -1; } - int tmp_modified = 0; - if (intern_string_constants(tmp, &tmp_modified) < 0) { - Py_DECREF(tmp); - return -1; - } - if (tmp_modified) { + if (tmp_modified) { v = PyFrozenSet_New(tmp); if (v == NULL) { - Py_DECREF(tmp); - return -1; + Py_DECREF(tmp); + return -1; } - - PyTuple_SET_ITEM(tuple, i, v); - Py_DECREF(w); - if (modified) { - *modified = 1; + + PyTuple_SET_ITEM(tuple, i, v); + Py_DECREF(w); + if (modified) { + *modified = 1; } } Py_DECREF(tmp); } } - return 0; + return 0; } PyCodeObject * -PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, - int nlocals, int stacksize, int flags, - PyObject *code, PyObject *consts, PyObject *names, - PyObject *varnames, PyObject *freevars, PyObject *cellvars, - PyObject *filename, PyObject *name, int firstlineno, - PyObject *lnotab) +PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, + int nlocals, int stacksize, int flags, + PyObject *code, PyObject *consts, PyObject *names, + PyObject *varnames, PyObject *freevars, PyObject *cellvars, + PyObject *filename, PyObject *name, int firstlineno, + PyObject *lnotab) { PyCodeObject *co; Py_ssize_t *cell2arg = NULL; Py_ssize_t i, n_cellvars, n_varnames, total_args; /* Check argument types */ - if (argcount < posonlyargcount || posonlyargcount < 0 || - kwonlyargcount < 0 || nlocals < 0 || - stacksize < 0 || flags < 0 || + if (argcount < posonlyargcount || posonlyargcount < 0 || + kwonlyargcount < 0 || nlocals < 0 || + stacksize < 0 || flags < 0 || code == NULL || !PyBytes_Check(code) || consts == NULL || !PyTuple_Check(consts) || names == NULL || !PyTuple_Check(names) || @@ -142,38 +142,38 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, return NULL; } - /* Ensure that strings are ready Unicode string */ - if (PyUnicode_READY(name) < 0) { + /* Ensure that strings are ready Unicode string */ + if (PyUnicode_READY(name) < 0) { + return NULL; + } + if (PyUnicode_READY(filename) < 0) { + return NULL; + } + + if (intern_strings(names) < 0) { + return NULL; + } + if (intern_strings(varnames) < 0) { + return NULL; + } + if (intern_strings(freevars) < 0) { + return NULL; + } + if (intern_strings(cellvars) < 0) { + return NULL; + } + if (intern_string_constants(consts, NULL) < 0) { + return NULL; + } + + /* Make sure that code is indexable with an int, this is + a long running assumption in ceval.c and many parts of + the interpreter. */ + if (PyBytes_GET_SIZE(code) > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, "co_code larger than INT_MAX"); return NULL; - } - if (PyUnicode_READY(filename) < 0) { - return NULL; - } - - if (intern_strings(names) < 0) { - return NULL; - } - if (intern_strings(varnames) < 0) { - return NULL; - } - if (intern_strings(freevars) < 0) { - return NULL; - } - if (intern_strings(cellvars) < 0) { - return NULL; - } - if (intern_string_constants(consts, NULL) < 0) { - return NULL; - } - - /* Make sure that code is indexable with an int, this is - a long running assumption in ceval.c and many parts of - the interpreter. */ - if (PyBytes_GET_SIZE(code) > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, "co_code larger than INT_MAX"); - return NULL; - } - + } + /* Check for any inner or outer closure references */ n_cellvars = PyTuple_GET_SIZE(cellvars); if (!n_cellvars && !PyTuple_GET_SIZE(freevars)) { @@ -186,7 +186,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, if (argcount <= n_varnames && kwonlyargcount <= n_varnames) { /* Never overflows. */ total_args = (Py_ssize_t)argcount + (Py_ssize_t)kwonlyargcount + - ((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0); + ((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0); } else { total_args = n_varnames + 1; @@ -228,14 +228,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, cell2arg = NULL; } } - co = PyObject_New(PyCodeObject, &PyCode_Type); + co = PyObject_New(PyCodeObject, &PyCode_Type); if (co == NULL) { if (cell2arg) PyMem_FREE(cell2arg); return NULL; } co->co_argcount = argcount; - co->co_posonlyargcount = posonlyargcount; + co->co_posonlyargcount = posonlyargcount; co->co_kwonlyargcount = kwonlyargcount; co->co_nlocals = nlocals; co->co_stacksize = stacksize; @@ -263,72 +263,72 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, co->co_zombieframe = NULL; co->co_weakreflist = NULL; co->co_extra = NULL; - - co->co_opcache_map = NULL; - co->co_opcache = NULL; - co->co_opcache_flag = 0; - co->co_opcache_size = 0; + + co->co_opcache_map = NULL; + co->co_opcache = NULL; + co->co_opcache_flag = 0; + co->co_opcache_size = 0; return co; } PyCodeObject * -PyCode_New(int argcount, int kwonlyargcount, - int nlocals, int stacksize, int flags, - PyObject *code, PyObject *consts, PyObject *names, - PyObject *varnames, PyObject *freevars, PyObject *cellvars, - PyObject *filename, PyObject *name, int firstlineno, - PyObject *lnotab) -{ - return PyCode_NewWithPosOnlyArgs(argcount, 0, kwonlyargcount, nlocals, - stacksize, flags, code, consts, names, - varnames, freevars, cellvars, filename, - name, firstlineno, lnotab); -} - -int -_PyCode_InitOpcache(PyCodeObject *co) -{ - Py_ssize_t co_size = PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT); - co->co_opcache_map = (unsigned char *)PyMem_Calloc(co_size, 1); - if (co->co_opcache_map == NULL) { - return -1; - } - - _Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code); - Py_ssize_t opts = 0; - - for (Py_ssize_t i = 0; i < co_size;) { - unsigned char opcode = _Py_OPCODE(opcodes[i]); - i++; // 'i' is now aligned to (next_instr - first_instr) - - // TODO: LOAD_METHOD, LOAD_ATTR - if (opcode == LOAD_GLOBAL) { - opts++; - co->co_opcache_map[i] = (unsigned char)opts; - if (opts > 254) { - break; - } - } - } - - if (opts) { - co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache)); - if (co->co_opcache == NULL) { - PyMem_FREE(co->co_opcache_map); - return -1; - } - } - else { - PyMem_FREE(co->co_opcache_map); - co->co_opcache_map = NULL; - co->co_opcache = NULL; - } - - co->co_opcache_size = (unsigned char)opts; - return 0; -} - -PyCodeObject * +PyCode_New(int argcount, int kwonlyargcount, + int nlocals, int stacksize, int flags, + PyObject *code, PyObject *consts, PyObject *names, + PyObject *varnames, PyObject *freevars, PyObject *cellvars, + PyObject *filename, PyObject *name, int firstlineno, + PyObject *lnotab) +{ + return PyCode_NewWithPosOnlyArgs(argcount, 0, kwonlyargcount, nlocals, + stacksize, flags, code, consts, names, + varnames, freevars, cellvars, filename, + name, firstlineno, lnotab); +} + +int +_PyCode_InitOpcache(PyCodeObject *co) +{ + Py_ssize_t co_size = PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT); + co->co_opcache_map = (unsigned char *)PyMem_Calloc(co_size, 1); + if (co->co_opcache_map == NULL) { + return -1; + } + + _Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code); + Py_ssize_t opts = 0; + + for (Py_ssize_t i = 0; i < co_size;) { + unsigned char opcode = _Py_OPCODE(opcodes[i]); + i++; // 'i' is now aligned to (next_instr - first_instr) + + // TODO: LOAD_METHOD, LOAD_ATTR + if (opcode == LOAD_GLOBAL) { + opts++; + co->co_opcache_map[i] = (unsigned char)opts; + if (opts > 254) { + break; + } + } + } + + if (opts) { + co->co_opcache = (_PyOpcache *)PyMem_Calloc(opts, sizeof(_PyOpcache)); + if (co->co_opcache == NULL) { + PyMem_FREE(co->co_opcache_map); + return -1; + } + } + else { + PyMem_FREE(co->co_opcache_map); + co->co_opcache_map = NULL; + co->co_opcache = NULL; + } + + co->co_opcache_size = (unsigned char)opts; + return 0; +} + +PyCodeObject * PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) { static PyObject *emptystring = NULL; @@ -353,9 +353,9 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) if (filename_ob == NULL) goto failed; - result = PyCode_NewWithPosOnlyArgs( - 0, /* argcount */ - 0, /* posonlyargcount */ + result = PyCode_NewWithPosOnlyArgs( + 0, /* argcount */ + 0, /* posonlyargcount */ 0, /* kwonlyargcount */ 0, /* nlocals */ 0, /* stacksize */ @@ -381,22 +381,22 @@ failed: #define OFF(x) offsetof(PyCodeObject, x) static PyMemberDef code_memberlist[] = { - {"co_argcount", T_INT, OFF(co_argcount), READONLY}, - {"co_posonlyargcount", T_INT, OFF(co_posonlyargcount), READONLY}, - {"co_kwonlyargcount", T_INT, OFF(co_kwonlyargcount), READONLY}, - {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, - {"co_stacksize",T_INT, OFF(co_stacksize), READONLY}, - {"co_flags", T_INT, OFF(co_flags), READONLY}, - {"co_code", T_OBJECT, OFF(co_code), READONLY}, - {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, - {"co_names", T_OBJECT, OFF(co_names), READONLY}, - {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, - {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, - {"co_cellvars", T_OBJECT, OFF(co_cellvars), READONLY}, - {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, - {"co_name", T_OBJECT, OFF(co_name), READONLY}, - {"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY}, - {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, + {"co_argcount", T_INT, OFF(co_argcount), READONLY}, + {"co_posonlyargcount", T_INT, OFF(co_posonlyargcount), READONLY}, + {"co_kwonlyargcount", T_INT, OFF(co_kwonlyargcount), READONLY}, + {"co_nlocals", T_INT, OFF(co_nlocals), READONLY}, + {"co_stacksize",T_INT, OFF(co_stacksize), READONLY}, + {"co_flags", T_INT, OFF(co_flags), READONLY}, + {"co_code", T_OBJECT, OFF(co_code), READONLY}, + {"co_consts", T_OBJECT, OFF(co_consts), READONLY}, + {"co_names", T_OBJECT, OFF(co_names), READONLY}, + {"co_varnames", T_OBJECT, OFF(co_varnames), READONLY}, + {"co_freevars", T_OBJECT, OFF(co_freevars), READONLY}, + {"co_cellvars", T_OBJECT, OFF(co_cellvars), READONLY}, + {"co_filename", T_OBJECT, OFF(co_filename), READONLY}, + {"co_name", T_OBJECT, OFF(co_name), READONLY}, + {"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY}, + {"co_lnotab", T_OBJECT, OFF(co_lnotab), READONLY}, {NULL} /* Sentinel */ }; @@ -425,7 +425,7 @@ validate_and_copy_tuple(PyObject *tup) PyExc_TypeError, "name tuples must contain only " "strings, not '%.500s'", - Py_TYPE(item)->tp_name); + Py_TYPE(item)->tp_name); Py_DECREF(newtuple); return NULL; } @@ -443,9 +443,9 @@ validate_and_copy_tuple(PyObject *tup) } PyDoc_STRVAR(code_doc, -"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n\ - flags, codestring, constants, names, varnames, filename, name,\n\ - firstlineno, lnotab[, freevars[, cellvars]])\n\ +"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n\ + flags, codestring, constants, names, varnames, filename, name,\n\ + firstlineno, lnotab[, freevars[, cellvars]])\n\ \n\ Create a code object. Not for the faint of heart."); @@ -453,7 +453,7 @@ static PyObject * code_new(PyTypeObject *type, PyObject *args, PyObject *kw) { int argcount; - int posonlyargcount; + int posonlyargcount; int kwonlyargcount; int nlocals; int stacksize; @@ -470,8 +470,8 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) int firstlineno; PyObject *lnotab; - if (!PyArg_ParseTuple(args, "iiiiiiSO!O!O!UUiS|O!O!:code", - &argcount, &posonlyargcount, &kwonlyargcount, + if (!PyArg_ParseTuple(args, "iiiiiiSO!O!O!UUiS|O!O!:code", + &argcount, &posonlyargcount, &kwonlyargcount, &nlocals, &stacksize, &flags, &code, &PyTuple_Type, &consts, @@ -483,12 +483,12 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) &PyTuple_Type, &cellvars)) return NULL; - if (PySys_Audit("code.__new__", "OOOiiiiii", - code, filename, name, argcount, posonlyargcount, - kwonlyargcount, nlocals, stacksize, flags) < 0) { - goto cleanup; - } - + if (PySys_Audit("code.__new__", "OOOiiiiii", + code, filename, name, argcount, posonlyargcount, + kwonlyargcount, nlocals, stacksize, flags) < 0) { + goto cleanup; + } + if (argcount < 0) { PyErr_SetString( PyExc_ValueError, @@ -496,13 +496,13 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) goto cleanup; } - if (posonlyargcount < 0) { - PyErr_SetString( - PyExc_ValueError, - "code: posonlyargcount must not be negative"); - goto cleanup; - } - + if (posonlyargcount < 0) { + PyErr_SetString( + PyExc_ValueError, + "code: posonlyargcount must not be negative"); + goto cleanup; + } + if (kwonlyargcount < 0) { PyErr_SetString( PyExc_ValueError, @@ -535,14 +535,14 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) if (ourcellvars == NULL) goto cleanup; - co = (PyObject *)PyCode_NewWithPosOnlyArgs(argcount, posonlyargcount, - kwonlyargcount, - nlocals, stacksize, flags, - code, consts, ournames, - ourvarnames, ourfreevars, - ourcellvars, filename, - name, firstlineno, lnotab); - cleanup: + co = (PyObject *)PyCode_NewWithPosOnlyArgs(argcount, posonlyargcount, + kwonlyargcount, + nlocals, stacksize, flags, + code, consts, ournames, + ourvarnames, ourfreevars, + ourcellvars, filename, + name, firstlineno, lnotab); + cleanup: Py_XDECREF(ournames); Py_XDECREF(ourvarnames); Py_XDECREF(ourfreevars); @@ -553,17 +553,17 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) static void code_dealloc(PyCodeObject *co) { - if (co->co_opcache != NULL) { - PyMem_FREE(co->co_opcache); - } - if (co->co_opcache_map != NULL) { - PyMem_FREE(co->co_opcache_map); - } - co->co_opcache_flag = 0; - co->co_opcache_size = 0; - + if (co->co_opcache != NULL) { + PyMem_FREE(co->co_opcache); + } + if (co->co_opcache_map != NULL) { + PyMem_FREE(co->co_opcache_map); + } + co->co_opcache_flag = 0; + co->co_opcache_size = 0; + if (co->co_extra != NULL) { - PyInterpreterState *interp = _PyInterpreterState_GET(); + PyInterpreterState *interp = _PyInterpreterState_GET(); _PyCodeObjectExtra *co_extra = co->co_extra; for (Py_ssize_t i = 0; i < co_extra->ce_size; i++) { @@ -596,7 +596,7 @@ code_dealloc(PyCodeObject *co) } static PyObject * -code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args)) +code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args)) { Py_ssize_t res = _PyObject_SIZE(Py_TYPE(co)); _PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra; @@ -608,83 +608,83 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args)) res += sizeof(_PyCodeObjectExtra) + (co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]); } - if (co->co_opcache != NULL) { - assert(co->co_opcache_map != NULL); - // co_opcache_map - res += PyBytes_GET_SIZE(co->co_code) / sizeof(_Py_CODEUNIT); - // co_opcache - res += co->co_opcache_size * sizeof(_PyOpcache); - } + if (co->co_opcache != NULL) { + assert(co->co_opcache_map != NULL); + // co_opcache_map + res += PyBytes_GET_SIZE(co->co_code) / sizeof(_Py_CODEUNIT); + // co_opcache + res += co->co_opcache_size * sizeof(_PyOpcache); + } return PyLong_FromSsize_t(res); } -/*[clinic input] -code.replace - - * - co_argcount: int(c_default="self->co_argcount") = -1 - co_posonlyargcount: int(c_default="self->co_posonlyargcount") = -1 - co_kwonlyargcount: int(c_default="self->co_kwonlyargcount") = -1 - co_nlocals: int(c_default="self->co_nlocals") = -1 - co_stacksize: int(c_default="self->co_stacksize") = -1 - co_flags: int(c_default="self->co_flags") = -1 - co_firstlineno: int(c_default="self->co_firstlineno") = -1 - co_code: PyBytesObject(c_default="(PyBytesObject *)self->co_code") = None - co_consts: object(subclass_of="&PyTuple_Type", c_default="self->co_consts") = None - co_names: object(subclass_of="&PyTuple_Type", c_default="self->co_names") = None - co_varnames: object(subclass_of="&PyTuple_Type", c_default="self->co_varnames") = None - co_freevars: object(subclass_of="&PyTuple_Type", c_default="self->co_freevars") = None - co_cellvars: object(subclass_of="&PyTuple_Type", c_default="self->co_cellvars") = None - co_filename: unicode(c_default="self->co_filename") = None - co_name: unicode(c_default="self->co_name") = None - co_lnotab: PyBytesObject(c_default="(PyBytesObject *)self->co_lnotab") = None - -Return a copy of the code object with new values for the specified fields. -[clinic start generated code]*/ - +/*[clinic input] +code.replace + + * + co_argcount: int(c_default="self->co_argcount") = -1 + co_posonlyargcount: int(c_default="self->co_posonlyargcount") = -1 + co_kwonlyargcount: int(c_default="self->co_kwonlyargcount") = -1 + co_nlocals: int(c_default="self->co_nlocals") = -1 + co_stacksize: int(c_default="self->co_stacksize") = -1 + co_flags: int(c_default="self->co_flags") = -1 + co_firstlineno: int(c_default="self->co_firstlineno") = -1 + co_code: PyBytesObject(c_default="(PyBytesObject *)self->co_code") = None + co_consts: object(subclass_of="&PyTuple_Type", c_default="self->co_consts") = None + co_names: object(subclass_of="&PyTuple_Type", c_default="self->co_names") = None + co_varnames: object(subclass_of="&PyTuple_Type", c_default="self->co_varnames") = None + co_freevars: object(subclass_of="&PyTuple_Type", c_default="self->co_freevars") = None + co_cellvars: object(subclass_of="&PyTuple_Type", c_default="self->co_cellvars") = None + co_filename: unicode(c_default="self->co_filename") = None + co_name: unicode(c_default="self->co_name") = None + co_lnotab: PyBytesObject(c_default="(PyBytesObject *)self->co_lnotab") = None + +Return a copy of the code object with new values for the specified fields. +[clinic start generated code]*/ + +static PyObject * +code_replace_impl(PyCodeObject *self, int co_argcount, + int co_posonlyargcount, int co_kwonlyargcount, + int co_nlocals, int co_stacksize, int co_flags, + int co_firstlineno, PyBytesObject *co_code, + PyObject *co_consts, PyObject *co_names, + PyObject *co_varnames, PyObject *co_freevars, + PyObject *co_cellvars, PyObject *co_filename, + PyObject *co_name, PyBytesObject *co_lnotab) +/*[clinic end generated code: output=25c8e303913bcace input=d9051bc8f24e6b28]*/ +{ +#define CHECK_INT_ARG(ARG) \ + if (ARG < 0) { \ + PyErr_SetString(PyExc_ValueError, \ + #ARG " must be a positive integer"); \ + return NULL; \ + } + + CHECK_INT_ARG(co_argcount); + CHECK_INT_ARG(co_posonlyargcount); + CHECK_INT_ARG(co_kwonlyargcount); + CHECK_INT_ARG(co_nlocals); + CHECK_INT_ARG(co_stacksize); + CHECK_INT_ARG(co_flags); + CHECK_INT_ARG(co_firstlineno); + +#undef CHECK_INT_ARG + + if (PySys_Audit("code.__new__", "OOOiiiiii", + co_code, co_filename, co_name, co_argcount, + co_posonlyargcount, co_kwonlyargcount, co_nlocals, + co_stacksize, co_flags) < 0) { + return NULL; + } + + return (PyObject *)PyCode_NewWithPosOnlyArgs( + co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, + co_stacksize, co_flags, (PyObject*)co_code, co_consts, co_names, + co_varnames, co_freevars, co_cellvars, co_filename, co_name, + co_firstlineno, (PyObject*)co_lnotab); +} + static PyObject * -code_replace_impl(PyCodeObject *self, int co_argcount, - int co_posonlyargcount, int co_kwonlyargcount, - int co_nlocals, int co_stacksize, int co_flags, - int co_firstlineno, PyBytesObject *co_code, - PyObject *co_consts, PyObject *co_names, - PyObject *co_varnames, PyObject *co_freevars, - PyObject *co_cellvars, PyObject *co_filename, - PyObject *co_name, PyBytesObject *co_lnotab) -/*[clinic end generated code: output=25c8e303913bcace input=d9051bc8f24e6b28]*/ -{ -#define CHECK_INT_ARG(ARG) \ - if (ARG < 0) { \ - PyErr_SetString(PyExc_ValueError, \ - #ARG " must be a positive integer"); \ - return NULL; \ - } - - CHECK_INT_ARG(co_argcount); - CHECK_INT_ARG(co_posonlyargcount); - CHECK_INT_ARG(co_kwonlyargcount); - CHECK_INT_ARG(co_nlocals); - CHECK_INT_ARG(co_stacksize); - CHECK_INT_ARG(co_flags); - CHECK_INT_ARG(co_firstlineno); - -#undef CHECK_INT_ARG - - if (PySys_Audit("code.__new__", "OOOiiiiii", - co_code, co_filename, co_name, co_argcount, - co_posonlyargcount, co_kwonlyargcount, co_nlocals, - co_stacksize, co_flags) < 0) { - return NULL; - } - - return (PyObject *)PyCode_NewWithPosOnlyArgs( - co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, - co_stacksize, co_flags, (PyObject*)co_code, co_consts, co_names, - co_varnames, co_freevars, co_cellvars, co_filename, co_name, - co_firstlineno, (PyObject*)co_lnotab); -} - -static PyObject * code_repr(PyCodeObject *co) { int lineno; @@ -708,21 +708,21 @@ _PyCode_ConstantKey(PyObject *op) { PyObject *key; - /* Py_None and Py_Ellipsis are singletons. */ + /* Py_None and Py_Ellipsis are singletons. */ if (op == Py_None || op == Py_Ellipsis || PyLong_CheckExact(op) || PyUnicode_CheckExact(op) /* code_richcompare() uses _PyCode_ConstantKey() internally */ - || PyCode_Check(op)) - { - /* Objects of these types are always different from object of other - * type and from tuples. */ - Py_INCREF(op); - key = op; - } - else if (PyBool_Check(op) || PyBytes_CheckExact(op)) { - /* Make booleans different from integers 0 and 1. - * Avoid BytesWarning from comparing bytes with strings. */ + || PyCode_Check(op)) + { + /* Objects of these types are always different from object of other + * type and from tuples. */ + Py_INCREF(op); + key = op; + } + else if (PyBool_Check(op) || PyBytes_CheckExact(op)) { + /* Make booleans different from integers 0 and 1. + * Avoid BytesWarning from comparing bytes with strings. */ key = PyTuple_Pack(2, Py_TYPE(op), op); } else if (PyFloat_CheckExact(op)) { @@ -851,11 +851,11 @@ code_richcompare(PyObject *self, PyObject *other, int op) cp = (PyCodeObject *)other; eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ); - if (!eq) goto unequal; + if (!eq) goto unequal; eq = co->co_argcount == cp->co_argcount; if (!eq) goto unequal; - eq = co->co_posonlyargcount == cp->co_posonlyargcount; - if (!eq) goto unequal; + eq = co->co_posonlyargcount == cp->co_posonlyargcount; + if (!eq) goto unequal; eq = co->co_kwonlyargcount == cp->co_kwonlyargcount; if (!eq) goto unequal; eq = co->co_nlocals == cp->co_nlocals; @@ -928,7 +928,7 @@ code_hash(PyCodeObject *co) h6 = PyObject_Hash(co->co_cellvars); if (h6 == -1) return -1; h = h0 ^ h1 ^ h2 ^ h3 ^ h4 ^ h5 ^ h6 ^ - co->co_argcount ^ co->co_posonlyargcount ^ co->co_kwonlyargcount ^ + co->co_argcount ^ co->co_posonlyargcount ^ co->co_kwonlyargcount ^ co->co_nlocals ^ co->co_flags; if (h == -1) h = -2; return h; @@ -938,7 +938,7 @@ code_hash(PyCodeObject *co) static struct PyMethodDef code_methods[] = { {"__sizeof__", (PyCFunction)code_sizeof, METH_NOARGS}, - CODE_REPLACE_METHODDEF + CODE_REPLACE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -948,10 +948,10 @@ PyTypeObject PyCode_Type = { sizeof(PyCodeObject), 0, (destructor)code_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)code_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1082,7 +1082,7 @@ _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra) int _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra) { - PyInterpreterState *interp = _PyInterpreterState_GET(); + PyInterpreterState *interp = _PyInterpreterState_GET(); if (!PyCode_Check(code) || index < 0 || index >= interp->co_extra_user_count) { diff --git a/contrib/tools/python3/src/Objects/complexobject.c b/contrib/tools/python3/src/Objects/complexobject.c index 71dc3abcf2..e09cc15fe8 100644 --- a/contrib/tools/python3/src/Objects/complexobject.c +++ b/contrib/tools/python3/src/Objects/complexobject.c @@ -6,7 +6,7 @@ /* Submitted by Jim Hugunin */ #include "Python.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef /*[clinic input] class complex "PyComplexObject *" "&PyComplex_Type" @@ -55,10 +55,10 @@ _Py_c_prod(Py_complex a, Py_complex b) return r; } -/* Avoid bad optimization on Windows ARM64 until the compiler is fixed */ -#ifdef _M_ARM64 -#pragma optimize("", off) -#endif +/* Avoid bad optimization on Windows ARM64 until the compiler is fixed */ +#ifdef _M_ARM64 +#pragma optimize("", off) +#endif Py_complex _Py_c_quot(Py_complex a, Py_complex b) { @@ -116,9 +116,9 @@ _Py_c_quot(Py_complex a, Py_complex b) } return r; } -#ifdef _M_ARM64 -#pragma optimize("", on) -#endif +#ifdef _M_ARM64 +#pragma optimize("", on) +#endif Py_complex _Py_c_pow(Py_complex a, Py_complex b) @@ -169,7 +169,7 @@ c_powu(Py_complex x, long n) static Py_complex c_powi(Py_complex x, long n) { - if (n > 0) + if (n > 0) return c_powu(x,n); else return _Py_c_quot(c_1, c_powu(x,-n)); @@ -289,7 +289,7 @@ try_complex_special_method(PyObject *op) if (!PyComplex_Check(res)) { PyErr_Format(PyExc_TypeError, "__complex__ returned non-complex (type %.200s)", - Py_TYPE(res)->tp_name); + Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } @@ -298,7 +298,7 @@ try_complex_special_method(PyObject *op) "__complex__ returned non-complex (type %.200s). " "The ability to return an instance of a strict subclass of complex " "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(res)->tp_name)) { + Py_TYPE(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -531,14 +531,14 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z) return NULL; } errno = 0; - // Check whether the exponent has a small integer value, and if so use - // a faster and more accurate algorithm. - if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) { - p = c_powi(a, (long)b.real); - } - else { - p = _Py_c_pow(a, b); - } + // Check whether the exponent has a small integer value, and if so use + // a faster and more accurate algorithm. + if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) { + p = c_powi(a, (long)b.real); + } + else { + p = _Py_c_pow(a, b); + } Py_ADJUST_ERANGE2(p.real, p.imag); if (errno == EDOM) { @@ -677,7 +677,7 @@ complex_float(PyObject *v) } static PyObject * -complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) +complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) { Py_complex c; c = ((PyComplexObject *)self)->cval; @@ -691,7 +691,7 @@ PyDoc_STRVAR(complex_conjugate_doc, "Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); static PyObject * -complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored)) +complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored)) { Py_complex c = v->cval; return Py_BuildValue("(dd)", c.real, c.imag); @@ -951,8 +951,8 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } - nbr = Py_TYPE(r)->tp_as_number; - if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) { + nbr = Py_TYPE(r)->tp_as_number; + if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) { PyErr_Format(PyExc_TypeError, "complex() first argument must be a string or a number, " "not '%.200s'", @@ -963,8 +963,8 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } if (i != NULL) { - nbi = Py_TYPE(i)->tp_as_number; - if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) { + nbi = Py_TYPE(i)->tp_as_number; + if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) { PyErr_Format(PyExc_TypeError, "complex() second argument must be a number, " "not '%.200s'", @@ -1020,7 +1020,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) /* The "imag" part really is entirely imaginary, and contributes nothing in the real direction. Just treat it as a double. */ - tmp = PyNumber_Float(i); + tmp = PyNumber_Float(i); if (tmp == NULL) return NULL; ci.real = PyFloat_AsDouble(tmp); @@ -1080,18 +1080,18 @@ PyTypeObject PyComplex_Type = { "complex", sizeof(PyComplexObject), 0, - 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)complex_repr, /* tp_repr */ &complex_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)complex_hash, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ diff --git a/contrib/tools/python3/src/Objects/descrobject.c b/contrib/tools/python3/src/Objects/descrobject.c index 833120df50..075a92d408 100644 --- a/contrib/tools/python3/src/Objects/descrobject.c +++ b/contrib/tools/python3/src/Objects/descrobject.c @@ -1,14 +1,14 @@ /* Descriptors -- a new, flexible way to describe attributes */ #include "Python.h" -#include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_object.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" -#include "structmember.h" // PyMemberDef - -_Py_IDENTIFIER(getattr); - +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() +#include "pycore_object.h" +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_tupleobject.h" +#include "structmember.h" // PyMemberDef + +_Py_IDENTIFIER(getattr); + /*[clinic input] class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type" class property "propertyobject *" "&PyProperty_Type" @@ -72,16 +72,16 @@ wrapperdescr_repr(PyWrapperDescrObject *descr) } static int -descr_check(PyDescrObject *descr, PyObject *obj) +descr_check(PyDescrObject *descr, PyObject *obj) { if (!PyObject_TypeCheck(obj, descr->d_type)) { PyErr_Format(PyExc_TypeError, - "descriptor '%V' for '%.100s' objects " - "doesn't apply to a '%.100s' object", + "descriptor '%V' for '%.100s' objects " + "doesn't apply to a '%.100s' object", descr_name((PyDescrObject *)descr), "?", descr->d_type->tp_name, - Py_TYPE(obj)->tp_name); - return -1; + Py_TYPE(obj)->tp_name); + return -1; } return 0; } @@ -92,11 +92,11 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) /* Ensure a valid type. Class methods ignore obj. */ if (type == NULL) { if (obj != NULL) - type = (PyObject *)Py_TYPE(obj); + type = (PyObject *)Py_TYPE(obj); else { /* Wot - no type?! */ PyErr_Format(PyExc_TypeError, - "descriptor '%V' for type '%.100s' " + "descriptor '%V' for type '%.100s' " "needs either an object or a type", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name); @@ -105,85 +105,85 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) } if (!PyType_Check(type)) { PyErr_Format(PyExc_TypeError, - "descriptor '%V' for type '%.100s' " - "needs a type, not a '%.100s' as arg 2", + "descriptor '%V' for type '%.100s' " + "needs a type, not a '%.100s' as arg 2", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - Py_TYPE(type)->tp_name); + Py_TYPE(type)->tp_name); return NULL; } if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) { PyErr_Format(PyExc_TypeError, - "descriptor '%V' requires a subtype of '%.100s' " - "but received '%.100s'", + "descriptor '%V' requires a subtype of '%.100s' " + "but received '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, ((PyTypeObject *)type)->tp_name); return NULL; } - PyTypeObject *cls = NULL; - if (descr->d_method->ml_flags & METH_METHOD) { - cls = descr->d_common.d_type; - } - return PyCMethod_New(descr->d_method, type, NULL, cls); + PyTypeObject *cls = NULL; + if (descr->d_method->ml_flags & METH_METHOD) { + cls = descr->d_common.d_type; + } + return PyCMethod_New(descr->d_method, type, NULL, cls); } static PyObject * method_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) { - if (obj == NULL) { - Py_INCREF(descr); - return (PyObject *)descr; - } - if (descr_check((PyDescrObject *)descr, obj) < 0) { - return NULL; - } - if (descr->d_method->ml_flags & METH_METHOD) { - if (PyType_Check(type)) { - return PyCMethod_New(descr->d_method, obj, NULL, descr->d_common.d_type); - } else { - PyErr_Format(PyExc_TypeError, - "descriptor '%V' needs a type, not '%s', as arg 2", - descr_name((PyDescrObject *)descr), - Py_TYPE(type)->tp_name); - return NULL; - } - } else { - return PyCFunction_NewEx(descr->d_method, obj, NULL); - } + if (obj == NULL) { + Py_INCREF(descr); + return (PyObject *)descr; + } + if (descr_check((PyDescrObject *)descr, obj) < 0) { + return NULL; + } + if (descr->d_method->ml_flags & METH_METHOD) { + if (PyType_Check(type)) { + return PyCMethod_New(descr->d_method, obj, NULL, descr->d_common.d_type); + } else { + PyErr_Format(PyExc_TypeError, + "descriptor '%V' needs a type, not '%s', as arg 2", + descr_name((PyDescrObject *)descr), + Py_TYPE(type)->tp_name); + return NULL; + } + } else { + return PyCFunction_NewEx(descr->d_method, obj, NULL); + } } static PyObject * member_get(PyMemberDescrObject *descr, PyObject *obj, PyObject *type) { - if (obj == NULL) { - Py_INCREF(descr); - return (PyObject *)descr; - } - if (descr_check((PyDescrObject *)descr, obj) < 0) { - return NULL; - } - - if (descr->d_member->flags & READ_RESTRICTED) { - if (PySys_Audit("object.__getattr__", "Os", - obj ? obj : Py_None, descr->d_member->name) < 0) { - return NULL; - } - } - + if (obj == NULL) { + Py_INCREF(descr); + return (PyObject *)descr; + } + if (descr_check((PyDescrObject *)descr, obj) < 0) { + return NULL; + } + + if (descr->d_member->flags & READ_RESTRICTED) { + if (PySys_Audit("object.__getattr__", "Os", + obj ? obj : Py_None, descr->d_member->name) < 0) { + return NULL; + } + } + return PyMember_GetOne((char *)obj, descr->d_member); } static PyObject * getset_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) { - if (obj == NULL) { - Py_INCREF(descr); - return (PyObject *)descr; - } - if (descr_check((PyDescrObject *)descr, obj) < 0) { - return NULL; - } + if (obj == NULL) { + Py_INCREF(descr); + return (PyObject *)descr; + } + if (descr_check((PyDescrObject *)descr, obj) < 0) { + return NULL; + } if (descr->d_getset->get != NULL) return descr->d_getset->get(obj, descr->d_getset->closure); PyErr_Format(PyExc_AttributeError, @@ -196,28 +196,28 @@ getset_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) static PyObject * wrapperdescr_get(PyWrapperDescrObject *descr, PyObject *obj, PyObject *type) { - if (obj == NULL) { - Py_INCREF(descr); - return (PyObject *)descr; - } - if (descr_check((PyDescrObject *)descr, obj) < 0) { - return NULL; - } + if (obj == NULL) { + Py_INCREF(descr); + return (PyObject *)descr; + } + if (descr_check((PyDescrObject *)descr, obj) < 0) { + return NULL; + } return PyWrapper_New((PyObject *)descr, obj); } static int -descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value) +descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value) { assert(obj != NULL); if (!PyObject_TypeCheck(obj, descr->d_type)) { PyErr_Format(PyExc_TypeError, "descriptor '%V' for '%.100s' objects " - "doesn't apply to a '%.100s' object", + "doesn't apply to a '%.100s' object", descr_name(descr), "?", descr->d_type->tp_name, - Py_TYPE(obj)->tp_name); - return -1; + Py_TYPE(obj)->tp_name); + return -1; } return 0; } @@ -225,22 +225,22 @@ descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value) static int member_set(PyMemberDescrObject *descr, PyObject *obj, PyObject *value) { - if (descr_setcheck((PyDescrObject *)descr, obj, value) < 0) { - return -1; - } + if (descr_setcheck((PyDescrObject *)descr, obj, value) < 0) { + return -1; + } return PyMember_SetOne((char *)obj, descr->d_member, value); } static int getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) { - if (descr_setcheck((PyDescrObject *)descr, obj, value) < 0) { - return -1; - } - if (descr->d_getset->set != NULL) { + if (descr_setcheck((PyDescrObject *)descr, obj, value) < 0) { + return -1; + } + if (descr->d_getset->set != NULL) { return descr->d_getset->set(obj, value, descr->d_getset->closure); - } + } PyErr_Format(PyExc_AttributeError, "attribute '%V' of '%.100s' objects is not writable", descr_name((PyDescrObject *)descr), "?", @@ -248,238 +248,238 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) return -1; } - -/* Vectorcall functions for each of the PyMethodDescr calling conventions. - * - * First, common helpers - */ -static inline int -method_check_args(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) + +/* Vectorcall functions for each of the PyMethodDescr calling conventions. + * + * First, common helpers + */ +static inline int +method_check_args(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - assert(!PyErr_Occurred()); + assert(!PyErr_Occurred()); if (nargs < 1) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - PyErr_Format(PyExc_TypeError, - "unbound method %U needs an argument", funcstr); - Py_DECREF(funcstr); - } - return -1; - } - PyObject *self = args[0]; - if (descr_check((PyDescrObject *)func, self) < 0) { - return -1; - } - if (kwnames && PyTuple_GET_SIZE(kwnames)) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - PyErr_Format(PyExc_TypeError, - "%U takes no keyword arguments", funcstr); - Py_DECREF(funcstr); - } - return -1; - } - return 0; -} - -typedef void (*funcptr)(void); - -static inline funcptr -method_enter_call(PyThreadState *tstate, PyObject *func) -{ - if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + PyErr_Format(PyExc_TypeError, + "unbound method %U needs an argument", funcstr); + Py_DECREF(funcstr); + } + return -1; + } + PyObject *self = args[0]; + if (descr_check((PyDescrObject *)func, self) < 0) { + return -1; + } + if (kwnames && PyTuple_GET_SIZE(kwnames)) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + PyErr_Format(PyExc_TypeError, + "%U takes no keyword arguments", funcstr); + Py_DECREF(funcstr); + } + return -1; + } + return 0; +} + +typedef void (*funcptr)(void); + +static inline funcptr +method_enter_call(PyThreadState *tstate, PyObject *func) +{ + if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { + return NULL; + } + return (funcptr)((PyMethodDescrObject *)func)->d_method->ml_meth; +} + +/* Now the actual vectorcall functions */ +static PyObject * +method_vectorcall_VARARGS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, kwnames)) { + return NULL; + } + PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1); + if (argstuple == NULL) { + return NULL; + } + PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); + if (meth == NULL) { + Py_DECREF(argstuple); + return NULL; + } + PyObject *result = meth(args[0], argstuple); + Py_DECREF(argstuple); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +method_vectorcall_VARARGS_KEYWORDS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, NULL)) { + return NULL; + } + PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1); + if (argstuple == NULL) { + return NULL; + } + PyObject *result = NULL; + /* Create a temporary dict for keyword arguments */ + PyObject *kwdict = NULL; + if (kwnames != NULL && PyTuple_GET_SIZE(kwnames) > 0) { + kwdict = _PyStack_AsDict(args + nargs, kwnames); + if (kwdict == NULL) { + goto exit; + } + } + PyCFunctionWithKeywords meth = (PyCFunctionWithKeywords) + method_enter_call(tstate, func); + if (meth == NULL) { + goto exit; + } + result = meth(args[0], argstuple, kwdict); + _Py_LeaveRecursiveCall(tstate); +exit: + Py_DECREF(argstuple); + Py_XDECREF(kwdict); + return result; +} + +static PyObject * +method_vectorcall_FASTCALL_KEYWORDS_METHOD( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, NULL)) { + return NULL; + } + PyCMethod meth = (PyCMethod) method_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(args[0], + ((PyMethodDescrObject *)func)->d_common.d_type, + args+1, nargs-1, kwnames); + Py_LeaveRecursiveCall(); + return result; +} + +static PyObject * +method_vectorcall_FASTCALL( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, kwnames)) { + return NULL; + } + _PyCFunctionFast meth = (_PyCFunctionFast) + method_enter_call(tstate, func); + if (meth == NULL) { return NULL; } - return (funcptr)((PyMethodDescrObject *)func)->d_method->ml_meth; -} - -/* Now the actual vectorcall functions */ -static PyObject * -method_vectorcall_VARARGS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, kwnames)) { - return NULL; - } - PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1); - if (argstuple == NULL) { - return NULL; - } - PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); - if (meth == NULL) { - Py_DECREF(argstuple); - return NULL; - } - PyObject *result = meth(args[0], argstuple); - Py_DECREF(argstuple); - _Py_LeaveRecursiveCall(tstate); + PyObject *result = meth(args[0], args+1, nargs-1); + _Py_LeaveRecursiveCall(tstate); return result; } -static PyObject * -method_vectorcall_VARARGS_KEYWORDS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, NULL)) { - return NULL; - } - PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1); - if (argstuple == NULL) { - return NULL; - } - PyObject *result = NULL; - /* Create a temporary dict for keyword arguments */ - PyObject *kwdict = NULL; - if (kwnames != NULL && PyTuple_GET_SIZE(kwnames) > 0) { - kwdict = _PyStack_AsDict(args + nargs, kwnames); - if (kwdict == NULL) { - goto exit; - } - } - PyCFunctionWithKeywords meth = (PyCFunctionWithKeywords) - method_enter_call(tstate, func); - if (meth == NULL) { - goto exit; - } - result = meth(args[0], argstuple, kwdict); - _Py_LeaveRecursiveCall(tstate); -exit: - Py_DECREF(argstuple); - Py_XDECREF(kwdict); - return result; -} - -static PyObject * -method_vectorcall_FASTCALL_KEYWORDS_METHOD( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, NULL)) { - return NULL; - } - PyCMethod meth = (PyCMethod) method_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(args[0], - ((PyMethodDescrObject *)func)->d_common.d_type, - args+1, nargs-1, kwnames); - Py_LeaveRecursiveCall(); - return result; -} - -static PyObject * -method_vectorcall_FASTCALL( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, kwnames)) { - return NULL; - } - _PyCFunctionFast meth = (_PyCFunctionFast) - method_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(args[0], args+1, nargs-1); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -method_vectorcall_FASTCALL_KEYWORDS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, NULL)) { - return NULL; - } - _PyCFunctionFastWithKeywords meth = (_PyCFunctionFastWithKeywords) - method_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(args[0], args+1, nargs-1, kwnames); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -method_vectorcall_NOARGS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, kwnames)) { - return NULL; - } - if (nargs != 1) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - PyErr_Format(PyExc_TypeError, - "%U takes no arguments (%zd given)", funcstr, nargs-1); - Py_DECREF(funcstr); - } +static PyObject * +method_vectorcall_FASTCALL_KEYWORDS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, NULL)) { return NULL; } - PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(args[0], NULL); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -method_vectorcall_O( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (method_check_args(func, args, nargs, kwnames)) { - return NULL; - } - if (nargs != 2) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - PyErr_Format(PyExc_TypeError, - "%U takes exactly one argument (%zd given)", - funcstr, nargs-1); - Py_DECREF(funcstr); - } + _PyCFunctionFastWithKeywords meth = (_PyCFunctionFastWithKeywords) + method_enter_call(tstate, func); + if (meth == NULL) { return NULL; } - PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(args[0], args[1]); - _Py_LeaveRecursiveCall(tstate); + PyObject *result = meth(args[0], args+1, nargs-1, kwnames); + _Py_LeaveRecursiveCall(tstate); return result; } - -/* Instances of classmethod_descriptor are unlikely to be called directly. - For one, the analogous class "classmethod" (for Python classes) is not - callable. Second, users are not likely to access a classmethod_descriptor - directly, since it means pulling it from the class __dict__. - - This is just an excuse to say that this doesn't need to be optimized: - we implement this simply by calling __get__ and then calling the result. -*/ +static PyObject * +method_vectorcall_NOARGS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, kwnames)) { + return NULL; + } + if (nargs != 1) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + PyErr_Format(PyExc_TypeError, + "%U takes no arguments (%zd given)", funcstr, nargs-1); + Py_DECREF(funcstr); + } + return NULL; + } + PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(args[0], NULL); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +method_vectorcall_O( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (method_check_args(func, args, nargs, kwnames)) { + return NULL; + } + if (nargs != 2) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + PyErr_Format(PyExc_TypeError, + "%U takes exactly one argument (%zd given)", + funcstr, nargs-1); + Py_DECREF(funcstr); + } + return NULL; + } + PyCFunction meth = (PyCFunction)method_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(args[0], args[1]); + _Py_LeaveRecursiveCall(tstate); + return result; +} + + +/* Instances of classmethod_descriptor are unlikely to be called directly. + For one, the analogous class "classmethod" (for Python classes) is not + callable. Second, users are not likely to access a classmethod_descriptor + directly, since it means pulling it from the class __dict__. + + This is just an excuse to say that this doesn't need to be optimized: + we implement this simply by calling __get__ and then calling the result. +*/ static PyObject * classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds) { - Py_ssize_t argc = PyTuple_GET_SIZE(args); + Py_ssize_t argc = PyTuple_GET_SIZE(args); if (argc < 1) { PyErr_Format(PyExc_TypeError, "descriptor '%V' of '%.100s' " @@ -488,15 +488,15 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyDescr_TYPE(descr)->tp_name); return NULL; } - PyObject *self = PyTuple_GET_ITEM(args, 0); - PyObject *bound = classmethod_get(descr, NULL, self); - if (bound == NULL) { + PyObject *self = PyTuple_GET_ITEM(args, 0); + PyObject *bound = classmethod_get(descr, NULL, self); + if (bound == NULL) { return NULL; } - PyObject *res = PyObject_VectorcallDict(bound, _PyTuple_ITEMS(args)+1, - argc-1, kwds); - Py_DECREF(bound); - return res; + PyObject *res = PyObject_VectorcallDict(bound, _PyTuple_ITEMS(args)+1, + argc-1, kwds); + Py_DECREF(bound); + return res; } Py_LOCAL_INLINE(PyObject *) @@ -545,7 +545,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - Py_TYPE(self)->tp_name); + Py_TYPE(self)->tp_name); return NULL; } @@ -610,7 +610,7 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored)) } static PyObject * -descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) +descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr), PyDescr_TYPE(descr), PyDescr_NAME(descr)); @@ -697,23 +697,23 @@ PyTypeObject PyMethodDescr_Type = { sizeof(PyMethodDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ - offsetof(PyMethodDescrObject, vectorcall), /* tp_vectorcall_offset */ + offsetof(PyMethodDescrObject, vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)method_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ - PyVectorcall_Call, /* tp_call */ + PyVectorcall_Call, /* 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_HAVE_VECTORCALL | - Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_VECTORCALL | + Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ 0, /* tp_doc */ descr_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -737,10 +737,10 @@ PyTypeObject PyClassMethodDescr_Type = { sizeof(PyMethodDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)method_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -774,10 +774,10 @@ PyTypeObject PyMemberDescr_Type = { sizeof(PyMemberDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)member_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -811,10 +811,10 @@ PyTypeObject PyGetSetDescr_Type = { sizeof(PyGetSetDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)getset_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -848,10 +848,10 @@ PyTypeObject PyWrapperDescr_Type = { sizeof(PyWrapperDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)wrapperdescr_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -862,8 +862,8 @@ PyTypeObject PyWrapperDescr_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ 0, /* tp_doc */ descr_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -904,46 +904,46 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name) PyObject * PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method) { - /* Figure out correct vectorcall function to use */ - vectorcallfunc vectorcall; - switch (method->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | - METH_O | METH_KEYWORDS | METH_METHOD)) - { - case METH_VARARGS: - vectorcall = method_vectorcall_VARARGS; - break; - case METH_VARARGS | METH_KEYWORDS: - vectorcall = method_vectorcall_VARARGS_KEYWORDS; - break; - case METH_FASTCALL: - vectorcall = method_vectorcall_FASTCALL; - break; - case METH_FASTCALL | METH_KEYWORDS: - vectorcall = method_vectorcall_FASTCALL_KEYWORDS; - break; - case METH_NOARGS: - vectorcall = method_vectorcall_NOARGS; - break; - case METH_O: - vectorcall = method_vectorcall_O; - break; - case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: - vectorcall = method_vectorcall_FASTCALL_KEYWORDS_METHOD; - break; - default: - PyErr_Format(PyExc_SystemError, - "%s() method: bad call flags", method->ml_name); - return NULL; - } - + /* Figure out correct vectorcall function to use */ + vectorcallfunc vectorcall; + switch (method->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | + METH_O | METH_KEYWORDS | METH_METHOD)) + { + case METH_VARARGS: + vectorcall = method_vectorcall_VARARGS; + break; + case METH_VARARGS | METH_KEYWORDS: + vectorcall = method_vectorcall_VARARGS_KEYWORDS; + break; + case METH_FASTCALL: + vectorcall = method_vectorcall_FASTCALL; + break; + case METH_FASTCALL | METH_KEYWORDS: + vectorcall = method_vectorcall_FASTCALL_KEYWORDS; + break; + case METH_NOARGS: + vectorcall = method_vectorcall_NOARGS; + break; + case METH_O: + vectorcall = method_vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + vectorcall = method_vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + default: + PyErr_Format(PyExc_SystemError, + "%s() method: bad call flags", method->ml_name); + return NULL; + } + PyMethodDescrObject *descr; descr = (PyMethodDescrObject *)descr_new(&PyMethodDescr_Type, type, method->ml_name); - if (descr != NULL) { + if (descr != NULL) { descr->d_method = method; - descr->vectorcall = vectorcall; - } + descr->vectorcall = vectorcall; + } return (PyObject *)descr; } @@ -1026,30 +1026,30 @@ static PyMappingMethods mappingproxy_as_mapping = { 0, /* mp_ass_subscript */ }; -static PyObject * -mappingproxy_or(PyObject *left, PyObject *right) -{ - if (PyObject_TypeCheck(left, &PyDictProxy_Type)) { - left = ((mappingproxyobject*)left)->mapping; - } - if (PyObject_TypeCheck(right, &PyDictProxy_Type)) { - right = ((mappingproxyobject*)right)->mapping; - } - return PyNumber_Or(left, right); -} - -static PyObject * -mappingproxy_ior(PyObject *self, PyObject *Py_UNUSED(other)) -{ - return PyErr_Format(PyExc_TypeError, - "'|=' is not supported by %s; use '|' instead", Py_TYPE(self)->tp_name); -} - -static PyNumberMethods mappingproxy_as_number = { - .nb_or = mappingproxy_or, - .nb_inplace_or = mappingproxy_ior, -}; - +static PyObject * +mappingproxy_or(PyObject *left, PyObject *right) +{ + if (PyObject_TypeCheck(left, &PyDictProxy_Type)) { + left = ((mappingproxyobject*)left)->mapping; + } + if (PyObject_TypeCheck(right, &PyDictProxy_Type)) { + right = ((mappingproxyobject*)right)->mapping; + } + return PyNumber_Or(left, right); +} + +static PyObject * +mappingproxy_ior(PyObject *self, PyObject *Py_UNUSED(other)) +{ + return PyErr_Format(PyExc_TypeError, + "'|=' is not supported by %s; use '|' instead", Py_TYPE(self)->tp_name); +} + +static PyNumberMethods mappingproxy_as_number = { + .nb_or = mappingproxy_or, + .nb_inplace_or = mappingproxy_ior, +}; + static int mappingproxy_contains(mappingproxyobject *pp, PyObject *key) { @@ -1073,64 +1073,64 @@ static PySequenceMethods mappingproxy_as_sequence = { }; static PyObject * -mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs) +mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs) { - /* newargs: mapping, key, default=None */ - PyObject *newargs[3]; - newargs[0] = pp->mapping; - newargs[2] = Py_None; + /* newargs: mapping, key, default=None */ + PyObject *newargs[3]; + newargs[0] = pp->mapping; + newargs[2] = Py_None; - if (!_PyArg_UnpackStack(args, nargs, "get", 1, 2, - &newargs[1], &newargs[2])) - { + if (!_PyArg_UnpackStack(args, nargs, "get", 1, 2, + &newargs[1], &newargs[2])) + { return NULL; - } - _Py_IDENTIFIER(get); - return _PyObject_VectorcallMethodId(&PyId_get, newargs, - 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, - NULL); + } + _Py_IDENTIFIER(get); + return _PyObject_VectorcallMethodId(&PyId_get, newargs, + 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, + NULL); } static PyObject * -mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) +mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(keys); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_keys); + return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_keys); } static PyObject * -mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) +mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(values); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_values); + return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_values); } static PyObject * -mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) +mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(items); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_items); + return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_items); } static PyObject * -mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) +mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(copy); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy); + return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy); +} + +static PyObject * +mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) +{ + _Py_IDENTIFIER(__reversed__); + return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__); } -static PyObject * -mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) -{ - _Py_IDENTIFIER(__reversed__); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__); -} - /* WARNING: mappingproxy methods must not give access to the underlying mapping */ static PyMethodDef mappingproxy_methods[] = { - {"get", (PyCFunction)(void(*)(void))mappingproxy_get, METH_FASTCALL, + {"get", (PyCFunction)(void(*)(void))mappingproxy_get, METH_FASTCALL, PyDoc_STR("D.get(k[,d]) -> D[k] if k in D, else d." " d defaults to None.")}, {"keys", (PyCFunction)mappingproxy_keys, METH_NOARGS, @@ -1141,10 +1141,10 @@ static PyMethodDef mappingproxy_methods[] = { PyDoc_STR("D.items() -> list of D's (key, value) pairs, as 2-tuples")}, {"copy", (PyCFunction)mappingproxy_copy, METH_NOARGS, PyDoc_STR("D.copy() -> a shallow copy of D")}, - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, - PyDoc_STR("See PEP 585")}, - {"__reversed__", (PyCFunction)mappingproxy_reversed, METH_NOARGS, - PyDoc_STR("D.__reversed__() -> reverse iterator")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, + PyDoc_STR("See PEP 585")}, + {"__reversed__", (PyCFunction)mappingproxy_reversed, METH_NOARGS, + PyDoc_STR("D.__reversed__() -> reverse iterator")}, {0} }; @@ -1257,51 +1257,51 @@ typedef struct { PyObject *self; } wrapperobject; -#define Wrapper_Check(v) Py_IS_TYPE(v, &_PyMethodWrapper_Type) +#define Wrapper_Check(v) Py_IS_TYPE(v, &_PyMethodWrapper_Type) static void wrapper_dealloc(wrapperobject *wp) { PyObject_GC_UnTrack(wp); - Py_TRASHCAN_BEGIN(wp, wrapper_dealloc) + Py_TRASHCAN_BEGIN(wp, wrapper_dealloc) Py_XDECREF(wp->descr); Py_XDECREF(wp->self); PyObject_GC_Del(wp); - Py_TRASHCAN_END + Py_TRASHCAN_END } static PyObject * wrapper_richcompare(PyObject *a, PyObject *b, int op) { - wrapperobject *wa, *wb; - int eq; + wrapperobject *wa, *wb; + int eq; assert(a != NULL && b != NULL); /* both arguments should be wrapperobjects */ - if ((op != Py_EQ && op != Py_NE) - || !Wrapper_Check(a) || !Wrapper_Check(b)) - { + if ((op != Py_EQ && op != Py_NE) + || !Wrapper_Check(a) || !Wrapper_Check(b)) + { Py_RETURN_NOTIMPLEMENTED; } - wa = (wrapperobject *)a; - wb = (wrapperobject *)b; - eq = (wa->descr == wb->descr && wa->self == wb->self); - if (eq == (op == Py_EQ)) { - Py_RETURN_TRUE; + wa = (wrapperobject *)a; + wb = (wrapperobject *)b; + eq = (wa->descr == wb->descr && wa->self == wb->self); + if (eq == (op == Py_EQ)) { + Py_RETURN_TRUE; + } + else { + Py_RETURN_FALSE; } - else { - Py_RETURN_FALSE; - } } static Py_hash_t wrapper_hash(wrapperobject *wp) { Py_hash_t x, y; - x = _Py_HashPointer(wp->self); - y = _Py_HashPointer(wp->descr); + x = _Py_HashPointer(wp->self); + y = _Py_HashPointer(wp->descr); x = x ^ y; if (x == -1) x = -2; @@ -1313,12 +1313,12 @@ wrapper_repr(wrapperobject *wp) { return PyUnicode_FromFormat("<method-wrapper '%s' of %s object at %p>", wp->descr->d_base->name, - Py_TYPE(wp->self)->tp_name, + Py_TYPE(wp->self)->tp_name, wp->self); } static PyObject * -wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) +wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr), wp->self, PyDescr_NAME(wp->descr)); @@ -1400,10 +1400,10 @@ PyTypeObject _PyMethodWrapper_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)wrapper_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)wrapper_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1555,7 +1555,7 @@ property_dealloc(PyObject *self) Py_XDECREF(gs->prop_set); Py_XDECREF(gs->prop_del); Py_XDECREF(gs->prop_doc); - Py_TYPE(self)->tp_free(self); + Py_TYPE(self)->tp_free(self); } static PyObject * @@ -1565,14 +1565,14 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type) Py_INCREF(self); return self; } - - propertyobject *gs = (propertyobject *)self; + + propertyobject *gs = (propertyobject *)self; if (gs->prop_get == NULL) { PyErr_SetString(PyExc_AttributeError, "unreadable attribute"); return NULL; } - - return PyObject_CallOneArg(gs->prop_get, obj); + + return PyObject_CallOneArg(gs->prop_get, obj); } static int @@ -1593,7 +1593,7 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value) return -1; } if (value == NULL) - res = PyObject_CallOneArg(func, obj); + res = PyObject_CallOneArg(func, obj); else res = PyObject_CallFunctionObjArgs(func, obj, value, NULL); if (res == NULL) @@ -1702,25 +1702,25 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && fget != NULL) { _Py_IDENTIFIER(__doc__); - PyObject *get_doc; - int rc = _PyObject_LookupAttrId(fget, &PyId___doc__, &get_doc); - if (rc <= 0) { - return rc; + PyObject *get_doc; + int rc = _PyObject_LookupAttrId(fget, &PyId___doc__, &get_doc); + if (rc <= 0) { + return rc; } - if (Py_IS_TYPE(self, &PyProperty_Type)) { - Py_XSETREF(self->prop_doc, get_doc); + if (Py_IS_TYPE(self, &PyProperty_Type)) { + Py_XSETREF(self->prop_doc, get_doc); } else { - /* If this is a property subclass, put __doc__ - in dict of the subclass instance instead, - otherwise it gets shadowed by __doc__ in the - class's dict. */ - int err = _PyObject_SetAttrId((PyObject *)self, &PyId___doc__, get_doc); - Py_DECREF(get_doc); - if (err < 0) - return -1; + /* If this is a property subclass, put __doc__ + in dict of the subclass instance instead, + otherwise it gets shadowed by __doc__ in the + class's dict. */ + int err = _PyObject_SetAttrId((PyObject *)self, &PyId___doc__, get_doc); + Py_DECREF(get_doc); + if (err < 0) + return -1; } - self->getter_doc = 1; + self->getter_doc = 1; } return 0; @@ -1791,12 +1791,12 @@ PyTypeObject PyDictProxy_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)mappingproxy_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)mappingproxy_repr, /* tp_repr */ - &mappingproxy_as_number, /* tp_as_number */ + &mappingproxy_as_number, /* tp_as_number */ &mappingproxy_as_sequence, /* tp_as_sequence */ &mappingproxy_as_mapping, /* tp_as_mapping */ 0, /* tp_hash */ @@ -1833,10 +1833,10 @@ PyTypeObject PyProperty_Type = { 0, /* tp_itemsize */ /* methods */ property_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/dictobject.c b/contrib/tools/python3/src/Objects/dictobject.c index fffe808bde..2ae122d323 100644 --- a/contrib/tools/python3/src/Objects/dictobject.c +++ b/contrib/tools/python3/src/Objects/dictobject.c @@ -39,7 +39,7 @@ Size of indices is dk_size. Type of each index in indices is vary on dk_size: * int32 for 2**16 <= dk_size <= 2**31 * int64 for 2**32 <= dk_size -dk_entries is array of PyDictKeyEntry. Its size is USABLE_FRACTION(dk_size). +dk_entries is array of PyDictKeyEntry. Its size is USABLE_FRACTION(dk_size). DK_ENTRIES(dk) can be used to get pointer to entries. NOTE: Since negative value is used for DKIX_EMPTY and DKIX_DUMMY, type of @@ -111,11 +111,11 @@ converting the dict to the combined table. #define PyDict_MINSIZE 8 #include "Python.h" -#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() -#include "pycore_object.h" -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() +#include "pycore_object.h" +#include "pycore_pystate.h" // _PyThreadState_GET() #include "dict-common.h" -#include "stringlib/eq.h" // unicode_eq() +#include "stringlib/eq.h" // unicode_eq() /*[clinic input] class dict "PyDictObject *" "&PyDict_Type" @@ -250,46 +250,46 @@ static uint64_t pydict_global_version = 0; #ifndef PyDict_MAXFREELIST #define PyDict_MAXFREELIST 80 #endif - -#if PyDict_MAXFREELIST > 0 + +#if PyDict_MAXFREELIST > 0 static PyDictObject *free_list[PyDict_MAXFREELIST]; static int numfree = 0; static PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST]; static int numfreekeys = 0; -#endif +#endif #include "clinic/dictobject.c.h" -void -_PyDict_ClearFreeList(void) +void +_PyDict_ClearFreeList(void) { -#if PyDict_MAXFREELIST > 0 +#if PyDict_MAXFREELIST > 0 while (numfree) { - PyDictObject *op = free_list[--numfree]; + PyDictObject *op = free_list[--numfree]; assert(PyDict_CheckExact(op)); PyObject_GC_Del(op); } while (numfreekeys) { PyObject_FREE(keys_free_list[--numfreekeys]); } -#endif +#endif } /* Print summary info about the state of the optimized allocator */ void _PyDict_DebugMallocStats(FILE *out) { -#if PyDict_MAXFREELIST > 0 +#if PyDict_MAXFREELIST > 0 _PyDebugAllocatorStats(out, "free PyDictObject", numfree, sizeof(PyDictObject)); -#endif +#endif } void -_PyDict_Fini(void) +_PyDict_Fini(void) { - _PyDict_ClearFreeList(); + _PyDict_ClearFreeList(); } #define DK_SIZE(dk) ((dk)->dk_size) @@ -311,52 +311,52 @@ _PyDict_Fini(void) #define DK_MASK(dk) (((dk)->dk_size)-1) #define IS_POWER_OF_2(x) (((x) & (x-1)) == 0) -static void free_keys_object(PyDictKeysObject *keys); - -static inline void -dictkeys_incref(PyDictKeysObject *dk) -{ -#ifdef Py_REF_DEBUG - _Py_RefTotal++; -#endif - dk->dk_refcnt++; -} - -static inline void -dictkeys_decref(PyDictKeysObject *dk) -{ - assert(dk->dk_refcnt > 0); -#ifdef Py_REF_DEBUG - _Py_RefTotal--; -#endif - if (--dk->dk_refcnt == 0) { - free_keys_object(dk); - } -} - +static void free_keys_object(PyDictKeysObject *keys); + +static inline void +dictkeys_incref(PyDictKeysObject *dk) +{ +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif + dk->dk_refcnt++; +} + +static inline void +dictkeys_decref(PyDictKeysObject *dk) +{ + assert(dk->dk_refcnt > 0); +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif + if (--dk->dk_refcnt == 0) { + free_keys_object(dk); + } +} + /* lookup indices. returns DKIX_EMPTY, DKIX_DUMMY, or ix >=0 */ static inline Py_ssize_t -dictkeys_get_index(const PyDictKeysObject *keys, Py_ssize_t i) +dictkeys_get_index(const PyDictKeysObject *keys, Py_ssize_t i) { Py_ssize_t s = DK_SIZE(keys); Py_ssize_t ix; if (s <= 0xff) { - const int8_t *indices = (const int8_t*)(keys->dk_indices); + const int8_t *indices = (const int8_t*)(keys->dk_indices); ix = indices[i]; } else if (s <= 0xffff) { - const int16_t *indices = (const int16_t*)(keys->dk_indices); + const int16_t *indices = (const int16_t*)(keys->dk_indices); ix = indices[i]; } #if SIZEOF_VOID_P > 4 else if (s > 0xffffffff) { - const int64_t *indices = (const int64_t*)(keys->dk_indices); + const int64_t *indices = (const int64_t*)(keys->dk_indices); ix = indices[i]; } #endif else { - const int32_t *indices = (const int32_t*)(keys->dk_indices); + const int32_t *indices = (const int32_t*)(keys->dk_indices); ix = indices[i]; } assert(ix >= DKIX_DUMMY); @@ -365,7 +365,7 @@ dictkeys_get_index(const PyDictKeysObject *keys, Py_ssize_t i) /* write to indices. */ static inline void -dictkeys_set_index(PyDictKeysObject *keys, Py_ssize_t i, Py_ssize_t ix) +dictkeys_set_index(PyDictKeysObject *keys, Py_ssize_t i, Py_ssize_t ix) { Py_ssize_t s = DK_SIZE(keys); @@ -458,81 +458,81 @@ static PyObject *empty_values[1] = { NULL }; /* Uncomment to check the dict content in _PyDict_CheckConsistency() */ /* #define DEBUG_PYDICT */ -#ifdef DEBUG_PYDICT -# define ASSERT_CONSISTENT(op) assert(_PyDict_CheckConsistency((PyObject *)(op), 1)) -#else -# define ASSERT_CONSISTENT(op) assert(_PyDict_CheckConsistency((PyObject *)(op), 0)) -#endif - - -int -_PyDict_CheckConsistency(PyObject *op, int check_content) -{ -#define CHECK(expr) \ - do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) - - assert(op != NULL); - CHECK(PyDict_Check(op)); - PyDictObject *mp = (PyDictObject *)op; - +#ifdef DEBUG_PYDICT +# define ASSERT_CONSISTENT(op) assert(_PyDict_CheckConsistency((PyObject *)(op), 1)) +#else +# define ASSERT_CONSISTENT(op) assert(_PyDict_CheckConsistency((PyObject *)(op), 0)) +#endif + + +int +_PyDict_CheckConsistency(PyObject *op, int check_content) +{ +#define CHECK(expr) \ + do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) + + assert(op != NULL); + CHECK(PyDict_Check(op)); + PyDictObject *mp = (PyDictObject *)op; + PyDictKeysObject *keys = mp->ma_keys; int splitted = _PyDict_HasSplitTable(mp); Py_ssize_t usable = USABLE_FRACTION(keys->dk_size); - CHECK(0 <= mp->ma_used && mp->ma_used <= usable); - CHECK(IS_POWER_OF_2(keys->dk_size)); - CHECK(0 <= keys->dk_usable && keys->dk_usable <= usable); - CHECK(0 <= keys->dk_nentries && keys->dk_nentries <= usable); - CHECK(keys->dk_usable + keys->dk_nentries <= usable); + CHECK(0 <= mp->ma_used && mp->ma_used <= usable); + CHECK(IS_POWER_OF_2(keys->dk_size)); + CHECK(0 <= keys->dk_usable && keys->dk_usable <= usable); + CHECK(0 <= keys->dk_nentries && keys->dk_nentries <= usable); + CHECK(keys->dk_usable + keys->dk_nentries <= usable); if (!splitted) { /* combined table */ - CHECK(keys->dk_refcnt == 1); - } - - if (check_content) { - PyDictKeyEntry *entries = DK_ENTRIES(keys); - Py_ssize_t i; - - for (i=0; i < keys->dk_size; i++) { - Py_ssize_t ix = dictkeys_get_index(keys, i); - CHECK(DKIX_DUMMY <= ix && ix <= usable); - } - - for (i=0; i < usable; i++) { - PyDictKeyEntry *entry = &entries[i]; - PyObject *key = entry->me_key; - - if (key != NULL) { - if (PyUnicode_CheckExact(key)) { - Py_hash_t hash = ((PyASCIIObject *)key)->hash; - CHECK(hash != -1); - CHECK(entry->me_hash == hash); - } - else { - /* test_dict fails if PyObject_Hash() is called again */ - CHECK(entry->me_hash != -1); - } - if (!splitted) { - CHECK(entry->me_value != NULL); - } + CHECK(keys->dk_refcnt == 1); + } + + if (check_content) { + PyDictKeyEntry *entries = DK_ENTRIES(keys); + Py_ssize_t i; + + for (i=0; i < keys->dk_size; i++) { + Py_ssize_t ix = dictkeys_get_index(keys, i); + CHECK(DKIX_DUMMY <= ix && ix <= usable); + } + + for (i=0; i < usable; i++) { + PyDictKeyEntry *entry = &entries[i]; + PyObject *key = entry->me_key; + + if (key != NULL) { + if (PyUnicode_CheckExact(key)) { + Py_hash_t hash = ((PyASCIIObject *)key)->hash; + CHECK(hash != -1); + CHECK(entry->me_hash == hash); + } + else { + /* test_dict fails if PyObject_Hash() is called again */ + CHECK(entry->me_hash != -1); + } + if (!splitted) { + CHECK(entry->me_value != NULL); + } } - - if (splitted) { - CHECK(entry->me_value == NULL); + + if (splitted) { + CHECK(entry->me_value == NULL); } } if (splitted) { - /* splitted table */ - for (i=0; i < mp->ma_used; i++) { - CHECK(mp->ma_values[i] != NULL); - } + /* splitted table */ + for (i=0; i < mp->ma_used; i++) { + CHECK(mp->ma_values[i] != NULL); + } } } - return 1; + return 1; -#undef CHECK +#undef CHECK } @@ -560,13 +560,13 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) es = sizeof(Py_ssize_t); } -#if PyDict_MAXFREELIST > 0 +#if PyDict_MAXFREELIST > 0 if (size == PyDict_MINSIZE && numfreekeys > 0) { dk = keys_free_list[--numfreekeys]; } - else -#endif - { + else +#endif + { dk = PyObject_MALLOC(sizeof(PyDictKeysObject) + es * size + sizeof(PyDictKeyEntry) * usable); @@ -575,10 +575,10 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) return NULL; } } -#ifdef Py_REF_DEBUG - _Py_RefTotal++; -#endif - dk->dk_refcnt = 1; +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif + dk->dk_refcnt = 1; dk->dk_size = size; dk->dk_usable = usable; dk->dk_lookup = lookdict_unicode_nodummy; @@ -597,12 +597,12 @@ free_keys_object(PyDictKeysObject *keys) Py_XDECREF(entries[i].me_key); Py_XDECREF(entries[i].me_value); } -#if PyDict_MAXFREELIST > 0 +#if PyDict_MAXFREELIST > 0 if (keys->dk_size == PyDict_MINSIZE && numfreekeys < PyDict_MAXFREELIST) { keys_free_list[numfreekeys++] = keys; return; } -#endif +#endif PyObject_FREE(keys); } @@ -615,22 +615,22 @@ new_dict(PyDictKeysObject *keys, PyObject **values) { PyDictObject *mp; assert(keys != NULL); -#if PyDict_MAXFREELIST > 0 +#if PyDict_MAXFREELIST > 0 if (numfree) { mp = free_list[--numfree]; assert (mp != NULL); - assert (Py_IS_TYPE(mp, &PyDict_Type)); + assert (Py_IS_TYPE(mp, &PyDict_Type)); _Py_NewReference((PyObject *)mp); } - else -#endif - { + else +#endif + { mp = PyObject_GC_New(PyDictObject, &PyDict_Type); if (mp == NULL) { - dictkeys_decref(keys); - if (values != empty_values) { - free_values(values); - } + dictkeys_decref(keys); + if (values != empty_values) { + free_values(values); + } return NULL; } } @@ -638,7 +638,7 @@ new_dict(PyDictKeysObject *keys, PyObject **values) mp->ma_values = values; mp->ma_used = 0; mp->ma_version_tag = DICT_NEXT_VERSION(); - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); return (PyObject *)mp; } @@ -652,7 +652,7 @@ new_dict_with_shared_keys(PyDictKeysObject *keys) size = USABLE_FRACTION(DK_SIZE(keys)); values = new_values(size); if (values == NULL) { - dictkeys_decref(keys); + dictkeys_decref(keys); return PyErr_NoMemory(); } for (i = 0; i < size; i++) { @@ -699,19 +699,19 @@ clone_combined_dict(PyDictObject *orig) return NULL; } new->ma_used = orig->ma_used; - ASSERT_CONSISTENT(new); + ASSERT_CONSISTENT(new); if (_PyObject_GC_IS_TRACKED(orig)) { /* Maintain tracking. */ _PyObject_GC_TRACK(new); } /* Since we copied the keys table we now have an extra reference - in the system. Manually call increment _Py_RefTotal to signal that - we have it now; calling dictkeys_incref would be an error as + in the system. Manually call increment _Py_RefTotal to signal that + we have it now; calling dictkeys_incref would be an error as keys->dk_refcnt is already set to 1 (after memcpy). */ -#ifdef Py_REF_DEBUG - _Py_RefTotal++; -#endif +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif return (PyObject *)new; } @@ -719,8 +719,8 @@ clone_combined_dict(PyDictObject *orig) PyObject * PyDict_New(void) { - dictkeys_incref(Py_EMPTY_KEYS); - return new_dict(Py_EMPTY_KEYS, empty_values); + dictkeys_incref(Py_EMPTY_KEYS); + return new_dict(Py_EMPTY_KEYS, empty_values); } /* Search index of hash table from offset of entry table */ @@ -732,7 +732,7 @@ lookdict_index(PyDictKeysObject *k, Py_hash_t hash, Py_ssize_t index) size_t i = (size_t)hash & mask; for (;;) { - Py_ssize_t ix = dictkeys_get_index(k, i); + Py_ssize_t ix = dictkeys_get_index(k, i); if (ix == index) { return i; } @@ -785,7 +785,7 @@ top: i = (size_t)hash & mask; for (;;) { - Py_ssize_t ix = dictkeys_get_index(dk, i); + Py_ssize_t ix = dictkeys_get_index(dk, i); if (ix == DKIX_EMPTY) { *value_addr = NULL; return ix; @@ -845,7 +845,7 @@ lookdict_unicode(PyDictObject *mp, PyObject *key, size_t i = (size_t)hash & mask; for (;;) { - Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); + Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); if (ix == DKIX_EMPTY) { *value_addr = NULL; return DKIX_EMPTY; @@ -888,7 +888,7 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key, size_t i = (size_t)hash & mask; for (;;) { - Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); + Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); assert (ix != DKIX_DUMMY); if (ix == DKIX_EMPTY) { *value_addr = NULL; @@ -933,7 +933,7 @@ lookdict_split(PyDictObject *mp, PyObject *key, size_t i = (size_t)hash & mask; for (;;) { - Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); + Py_ssize_t ix = dictkeys_get_index(mp->ma_keys, i); assert (ix != DKIX_DUMMY); if (ix == DKIX_EMPTY) { *value_addr = NULL; @@ -1025,11 +1025,11 @@ find_empty_slot(PyDictKeysObject *keys, Py_hash_t hash) const size_t mask = DK_MASK(keys); size_t i = hash & mask; - Py_ssize_t ix = dictkeys_get_index(keys, i); + Py_ssize_t ix = dictkeys_get_index(keys, i); for (size_t perturb = hash; ix >= 0;) { perturb >>= PERTURB_SHIFT; i = (i*5 + perturb + 1) & mask; - ix = dictkeys_get_index(keys, i); + ix = dictkeys_get_index(keys, i); } return i; } @@ -1086,7 +1086,7 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value) } Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash); ep = &DK_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries]; - dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries); + dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries); ep->me_key = key; ep->me_hash = hash; if (mp->ma_values) { @@ -1101,27 +1101,27 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value) mp->ma_keys->dk_usable--; mp->ma_keys->dk_nentries++; assert(mp->ma_keys->dk_usable >= 0); - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); return 0; } - if (old_value != value) { - if (_PyDict_HasSplitTable(mp)) { - mp->ma_values[ix] = value; - if (old_value == NULL) { - /* pending state */ - assert(ix == mp->ma_used); - mp->ma_used++; - } + if (old_value != value) { + if (_PyDict_HasSplitTable(mp)) { + mp->ma_values[ix] = value; + if (old_value == NULL) { + /* pending state */ + assert(ix == mp->ma_used); + mp->ma_used++; + } + } + else { + assert(old_value != NULL); + DK_ENTRIES(mp->ma_keys)[ix].me_value = value; } - else { - assert(old_value != NULL); - DK_ENTRIES(mp->ma_keys)[ix].me_value = value; - } - mp->ma_version_tag = DICT_NEXT_VERSION(); + mp->ma_version_tag = DICT_NEXT_VERSION(); } Py_XDECREF(old_value); /* which **CAN** re-enter (see issue #22653) */ - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); Py_DECREF(key); return 0; @@ -1131,41 +1131,41 @@ Fail: return -1; } -// Same to insertdict but specialized for ma_keys = Py_EMPTY_KEYS. -static int -insert_to_emptydict(PyDictObject *mp, PyObject *key, Py_hash_t hash, - PyObject *value) -{ - assert(mp->ma_keys == Py_EMPTY_KEYS); - - PyDictKeysObject *newkeys = new_keys_object(PyDict_MINSIZE); - if (newkeys == NULL) { - return -1; - } - if (!PyUnicode_CheckExact(key)) { - newkeys->dk_lookup = lookdict; - } - dictkeys_decref(Py_EMPTY_KEYS); - mp->ma_keys = newkeys; - mp->ma_values = NULL; - - Py_INCREF(key); - Py_INCREF(value); - MAINTAIN_TRACKING(mp, key, value); - - size_t hashpos = (size_t)hash & (PyDict_MINSIZE-1); - PyDictKeyEntry *ep = DK_ENTRIES(mp->ma_keys); - dictkeys_set_index(mp->ma_keys, hashpos, 0); - ep->me_key = key; - ep->me_hash = hash; - ep->me_value = value; - mp->ma_used++; - mp->ma_version_tag = DICT_NEXT_VERSION(); - mp->ma_keys->dk_usable--; - mp->ma_keys->dk_nentries++; - return 0; -} - +// Same to insertdict but specialized for ma_keys = Py_EMPTY_KEYS. +static int +insert_to_emptydict(PyDictObject *mp, PyObject *key, Py_hash_t hash, + PyObject *value) +{ + assert(mp->ma_keys == Py_EMPTY_KEYS); + + PyDictKeysObject *newkeys = new_keys_object(PyDict_MINSIZE); + if (newkeys == NULL) { + return -1; + } + if (!PyUnicode_CheckExact(key)) { + newkeys->dk_lookup = lookdict; + } + dictkeys_decref(Py_EMPTY_KEYS); + mp->ma_keys = newkeys; + mp->ma_values = NULL; + + Py_INCREF(key); + Py_INCREF(value); + MAINTAIN_TRACKING(mp, key, value); + + size_t hashpos = (size_t)hash & (PyDict_MINSIZE-1); + PyDictKeyEntry *ep = DK_ENTRIES(mp->ma_keys); + dictkeys_set_index(mp->ma_keys, hashpos, 0); + ep->me_key = key; + ep->me_hash = hash; + ep->me_value = value; + mp->ma_used++; + mp->ma_version_tag = DICT_NEXT_VERSION(); + mp->ma_keys->dk_usable--; + mp->ma_keys->dk_nentries++; + return 0; +} + /* Internal routine used by dictresize() to build a hashtable of entries. */ @@ -1176,11 +1176,11 @@ build_indices(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n) for (Py_ssize_t ix = 0; ix != n; ix++, ep++) { Py_hash_t hash = ep->me_hash; size_t i = hash & mask; - for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) { + for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) { perturb >>= PERTURB_SHIFT; i = mask & (i*5 + perturb + 1); } - dictkeys_set_index(keys, i, ix); + dictkeys_set_index(keys, i, ix); } } @@ -1249,7 +1249,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize) newentries[i].me_value = oldvalues[i]; } - dictkeys_decref(oldkeys); + dictkeys_decref(oldkeys); mp->ma_values = NULL; if (oldvalues != empty_values) { free_values(oldvalues); @@ -1270,19 +1270,19 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize) assert(oldkeys->dk_lookup != lookdict_split); assert(oldkeys->dk_refcnt == 1); -#ifdef Py_REF_DEBUG - _Py_RefTotal--; -#endif -#if PyDict_MAXFREELIST > 0 +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif +#if PyDict_MAXFREELIST > 0 if (oldkeys->dk_size == PyDict_MINSIZE && - numfreekeys < PyDict_MAXFREELIST) - { - keys_free_list[numfreekeys++] = oldkeys; + numfreekeys < PyDict_MAXFREELIST) + { + keys_free_list[numfreekeys++] = oldkeys; } - else -#endif - { - PyObject_FREE(oldkeys); + else +#endif + { + PyObject_FREE(oldkeys); } } @@ -1332,7 +1332,7 @@ make_keys_shared(PyObject *op) mp->ma_keys->dk_lookup = lookdict_split; mp->ma_values = values; } - dictkeys_incref(mp->ma_keys); + dictkeys_incref(mp->ma_keys); return mp->ma_keys; } @@ -1343,9 +1343,9 @@ _PyDict_NewPresized(Py_ssize_t minused) Py_ssize_t newsize; PyDictKeysObject *new_keys; - if (minused <= USABLE_FRACTION(PyDict_MINSIZE)) { - return PyDict_New(); - } + if (minused <= USABLE_FRACTION(PyDict_MINSIZE)) { + return PyDict_New(); + } /* There are no strict guarantee that returned dict can contain minused * items without resize. So we create medium size dict instead of very * large dict or MemoryError. @@ -1355,7 +1355,7 @@ _PyDict_NewPresized(Py_ssize_t minused) } else { Py_ssize_t minsize = ESTIMATE_SIZE(minused); - newsize = PyDict_MINSIZE*2; + newsize = PyDict_MINSIZE*2; while (newsize < minsize) { newsize <<= 1; } @@ -1402,9 +1402,9 @@ PyDict_GetItem(PyObject *op, PyObject *key) /* We can arrive here with a NULL tstate during initialization: try running "python -Wi" for an example related to string interning. Let's just hope that no exception occurs then... This must be - _PyThreadState_GET() and not PyThreadState_Get() because the latter - abort Python if tstate is NULL. */ - tstate = _PyThreadState_GET(); + _PyThreadState_GET() and not PyThreadState_Get() because the latter + abort Python if tstate is NULL. */ + tstate = _PyThreadState_GET(); if (tstate != NULL && tstate->curexc_type != NULL) { /* preserve the existing exception */ PyObject *err_type, *err_value, *err_tb; @@ -1486,24 +1486,24 @@ _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key) kv = _PyUnicode_FromId(key); /* borrowed */ if (kv == NULL) return NULL; - Py_hash_t hash = ((PyASCIIObject *) kv)->hash; - assert (hash != -1); /* interned strings have their hash value initialised */ - return _PyDict_GetItem_KnownHash(dp, kv, hash); -} - -PyObject * -_PyDict_GetItemStringWithError(PyObject *v, const char *key) -{ - PyObject *kv, *rv; - kv = PyUnicode_FromString(key); - if (kv == NULL) { - return NULL; - } - rv = PyDict_GetItemWithError(v, kv); - Py_DECREF(kv); - return rv; -} - + Py_hash_t hash = ((PyASCIIObject *) kv)->hash; + assert (hash != -1); /* interned strings have their hash value initialised */ + return _PyDict_GetItem_KnownHash(dp, kv, hash); +} + +PyObject * +_PyDict_GetItemStringWithError(PyObject *v, const char *key) +{ + PyObject *kv, *rv; + kv = PyUnicode_FromString(key); + if (kv == NULL) { + return NULL; + } + rv = PyDict_GetItemWithError(v, kv); + Py_DECREF(kv); + return rv; +} + /* Fast version of global value lookup (LOAD_GLOBAL). * Lookup in globals, then builtins. * @@ -1566,9 +1566,9 @@ PyDict_SetItem(PyObject *op, PyObject *key, PyObject *value) return -1; } - if (mp->ma_keys == Py_EMPTY_KEYS) { - return insert_to_emptydict(mp, key, hash, value); - } + if (mp->ma_keys == Py_EMPTY_KEYS) { + return insert_to_emptydict(mp, key, hash, value); + } /* insertdict() handles any resizing that might be necessary */ return insertdict(mp, key, hash, value); } @@ -1588,9 +1588,9 @@ _PyDict_SetItem_KnownHash(PyObject *op, PyObject *key, PyObject *value, assert(hash != -1); mp = (PyDictObject *)op; - if (mp->ma_keys == Py_EMPTY_KEYS) { - return insert_to_emptydict(mp, key, hash, value); - } + if (mp->ma_keys == Py_EMPTY_KEYS) { + return insert_to_emptydict(mp, key, hash, value); + } /* insertdict() handles any resizing that might be necessary */ return insertdict(mp, key, hash, value); } @@ -1608,7 +1608,7 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix, mp->ma_used--; mp->ma_version_tag = DICT_NEXT_VERSION(); ep = &DK_ENTRIES(mp->ma_keys)[ix]; - dictkeys_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); + dictkeys_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); ENSURE_ALLOWS_DELETIONS(mp); old_key = ep->me_key; ep->me_key = NULL; @@ -1616,7 +1616,7 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix, Py_DECREF(old_key); Py_DECREF(old_value); - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); return 0; } @@ -1739,7 +1739,7 @@ PyDict_Clear(PyObject *op) if (oldvalues == empty_values) return; /* Empty the dict... */ - dictkeys_incref(Py_EMPTY_KEYS); + dictkeys_incref(Py_EMPTY_KEYS); mp->ma_keys = Py_EMPTY_KEYS; mp->ma_values = empty_values; mp->ma_used = 0; @@ -1750,13 +1750,13 @@ PyDict_Clear(PyObject *op) for (i = 0; i < n; i++) Py_CLEAR(oldvalues[i]); free_values(oldvalues); - dictkeys_decref(oldkeys); + dictkeys_decref(oldkeys); } else { assert(oldkeys->dk_refcnt == 1); - dictkeys_decref(oldkeys); + dictkeys_decref(oldkeys); } - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); } /* Internal version of PyDict_Next that returns a hash value in addition @@ -1878,7 +1878,7 @@ _PyDict_Pop_KnownHash(PyObject *dict, PyObject *key, Py_hash_t hash, PyObject *d assert(old_value != NULL); mp->ma_used--; mp->ma_version_tag = DICT_NEXT_VERSION(); - dictkeys_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); + dictkeys_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); ep = &DK_ENTRIES(mp->ma_keys)[ix]; ENSURE_ALLOWS_DELETIONS(mp); old_key = ep->me_key; @@ -1886,7 +1886,7 @@ _PyDict_Pop_KnownHash(PyObject *dict, PyObject *key, Py_hash_t hash, PyObject *d ep->me_value = NULL; Py_DECREF(old_key); - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); return old_value; } @@ -2011,7 +2011,7 @@ dict_dealloc(PyDictObject *mp) /* bpo-31095: UnTrack is needed before calling any callbacks */ PyObject_GC_UnTrack(mp); - Py_TRASHCAN_BEGIN(mp, dict_dealloc) + Py_TRASHCAN_BEGIN(mp, dict_dealloc) if (values != NULL) { if (values != empty_values) { for (i = 0, n = mp->ma_keys->dk_nentries; i < n; i++) { @@ -2019,22 +2019,22 @@ dict_dealloc(PyDictObject *mp) } free_values(values); } - dictkeys_decref(keys); + dictkeys_decref(keys); } else if (keys != NULL) { assert(keys->dk_refcnt == 1); - dictkeys_decref(keys); + dictkeys_decref(keys); } -#if PyDict_MAXFREELIST > 0 - if (numfree < PyDict_MAXFREELIST && Py_IS_TYPE(mp, &PyDict_Type)) { +#if PyDict_MAXFREELIST > 0 + if (numfree < PyDict_MAXFREELIST && Py_IS_TYPE(mp, &PyDict_Type)) { free_list[numfree++] = mp; - } + } else -#endif - { +#endif + { Py_TYPE(mp)->tp_free((PyObject *)mp); - } - Py_TRASHCAN_END + } + Py_TRASHCAN_END } @@ -2150,7 +2150,7 @@ dict_subscript(PyDictObject *mp, PyObject *key) _Py_IDENTIFIER(__missing__); missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__); if (missing != NULL) { - res = PyObject_CallOneArg(missing, key); + res = PyObject_CallOneArg(missing, key); Py_DECREF(missing); return res; } @@ -2185,7 +2185,7 @@ dict_keys(PyDictObject *mp) PyObject *v; Py_ssize_t i, j; PyDictKeyEntry *ep; - Py_ssize_t n, offset; + Py_ssize_t n, offset; PyObject **value_ptr; again: @@ -2209,7 +2209,7 @@ dict_keys(PyDictObject *mp) value_ptr = &ep[0].me_value; offset = sizeof(PyDictKeyEntry); } - for (i = 0, j = 0; j < n; i++) { + for (i = 0, j = 0; j < n; i++) { if (*value_ptr != NULL) { PyObject *key = ep[i].me_key; Py_INCREF(key); @@ -2228,7 +2228,7 @@ dict_values(PyDictObject *mp) PyObject *v; Py_ssize_t i, j; PyDictKeyEntry *ep; - Py_ssize_t n, offset; + Py_ssize_t n, offset; PyObject **value_ptr; again: @@ -2252,7 +2252,7 @@ dict_values(PyDictObject *mp) value_ptr = &ep[0].me_value; offset = sizeof(PyDictKeyEntry); } - for (i = 0, j = 0; j < n; i++) { + for (i = 0, j = 0; j < n; i++) { PyObject *value = *value_ptr; value_ptr = (PyObject **)(((char *)value_ptr) + offset); if (value != NULL) { @@ -2270,7 +2270,7 @@ dict_items(PyDictObject *mp) { PyObject *v; Py_ssize_t i, j, n; - Py_ssize_t offset; + Py_ssize_t offset; PyObject *item, *key; PyDictKeyEntry *ep; PyObject **value_ptr; @@ -2309,7 +2309,7 @@ dict_items(PyDictObject *mp) value_ptr = &ep[0].me_value; offset = sizeof(PyDictKeyEntry); } - for (i = 0, j = 0; j < n; i++) { + for (i = 0, j = 0; j < n; i++) { PyObject *value = *value_ptr; value_ptr = (PyObject **)(((char *)value_ptr) + offset); if (value != NULL) { @@ -2343,26 +2343,26 @@ dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value) return _PyDict_FromKeys((PyObject *)type, iterable, value); } -/* Single-arg dict update; used by dict_update_common and operators. */ +/* Single-arg dict update; used by dict_update_common and operators. */ +static int +dict_update_arg(PyObject *self, PyObject *arg) +{ + if (PyDict_CheckExact(arg)) { + return PyDict_Merge(self, arg, 1); + } + _Py_IDENTIFIER(keys); + PyObject *func; + if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { + return -1; + } + if (func != NULL) { + Py_DECREF(func); + return PyDict_Merge(self, arg, 1); + } + return PyDict_MergeFromSeq2(self, arg, 1); +} + static int -dict_update_arg(PyObject *self, PyObject *arg) -{ - if (PyDict_CheckExact(arg)) { - return PyDict_Merge(self, arg, 1); - } - _Py_IDENTIFIER(keys); - PyObject *func; - if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { - return -1; - } - if (func != NULL) { - Py_DECREF(func); - return PyDict_Merge(self, arg, 1); - } - return PyDict_MergeFromSeq2(self, arg, 1); -} - -static int dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, const char *methname) { @@ -2373,7 +2373,7 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, result = -1; } else if (arg != NULL) { - result = dict_update_arg(self, arg); + result = dict_update_arg(self, arg); } if (result == 0 && kwds != NULL) { @@ -2458,21 +2458,21 @@ PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override) value = PySequence_Fast_GET_ITEM(fast, 1); Py_INCREF(key); Py_INCREF(value); - if (override) { - if (PyDict_SetItem(d, key, value) < 0) { + if (override) { + if (PyDict_SetItem(d, key, value) < 0) { Py_DECREF(key); Py_DECREF(value); goto Fail; } } - else if (PyDict_GetItemWithError(d, key) == NULL) { - if (PyErr_Occurred() || PyDict_SetItem(d, key, value) < 0) { - Py_DECREF(key); - Py_DECREF(value); - goto Fail; - } - } - + else if (PyDict_GetItemWithError(d, key) == NULL) { + if (PyErr_Occurred() || PyDict_SetItem(d, key, value) < 0) { + Py_DECREF(key); + Py_DECREF(value); + goto Fail; + } + } + Py_DECREF(key); Py_DECREF(value); Py_DECREF(fast); @@ -2480,7 +2480,7 @@ PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override) } i = 0; - ASSERT_CONSISTENT(d); + ASSERT_CONSISTENT(d); goto Return; Fail: Py_XDECREF(item); @@ -2596,19 +2596,19 @@ dict_merge(PyObject *a, PyObject *b, int override) return -1; for (key = PyIter_Next(iter); key; key = PyIter_Next(iter)) { - if (override != 1) { - if (PyDict_GetItemWithError(a, key) != NULL) { - if (override != 0) { - _PyErr_SetKeyError(key); - Py_DECREF(key); - Py_DECREF(iter); - return -1; - } + if (override != 1) { + if (PyDict_GetItemWithError(a, key) != NULL) { + if (override != 0) { + _PyErr_SetKeyError(key); + Py_DECREF(key); + Py_DECREF(iter); + return -1; + } + Py_DECREF(key); + continue; + } + else if (PyErr_Occurred()) { Py_DECREF(key); - continue; - } - else if (PyErr_Occurred()) { - Py_DECREF(key); Py_DECREF(iter); return -1; } @@ -2632,7 +2632,7 @@ dict_merge(PyObject *a, PyObject *b, int override) /* Iterator completed, via error */ return -1; } - ASSERT_CONSISTENT(a); + ASSERT_CONSISTENT(a); return 0; } @@ -2656,7 +2656,7 @@ _PyDict_MergeEx(PyObject *a, PyObject *b, int override) } static PyObject * -dict_copy(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) +dict_copy(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { return PyDict_Copy((PyObject*)mp); } @@ -2695,7 +2695,7 @@ PyDict_Copy(PyObject *o) split_copy->ma_keys = mp->ma_keys; split_copy->ma_used = mp->ma_used; split_copy->ma_version_tag = DICT_NEXT_VERSION(); - dictkeys_incref(mp->ma_keys); + dictkeys_incref(mp->ma_keys); for (i = 0, n = size; i < n; i++) { PyObject *value = mp->ma_values[i]; Py_XINCREF(value); @@ -2813,11 +2813,11 @@ dict_equal(PyDictObject *a, PyDictObject *b) return -1; return 0; } - Py_INCREF(bval); + Py_INCREF(bval); cmp = PyObject_RichCompareBool(aval, bval, Py_EQ); Py_DECREF(key); Py_DECREF(aval); - Py_DECREF(bval); + Py_DECREF(bval); if (cmp <= 0) /* error or not equal */ return cmp; } @@ -2932,12 +2932,12 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj) if (hash == -1) return NULL; } - if (mp->ma_keys == Py_EMPTY_KEYS) { - if (insert_to_emptydict(mp, key, hash, defaultobj) < 0) { - return NULL; - } - return defaultobj; - } + if (mp->ma_keys == Py_EMPTY_KEYS) { + if (insert_to_emptydict(mp, key, hash, defaultobj) < 0) { + return NULL; + } + return defaultobj; + } if (mp->ma_values != NULL && !PyUnicode_CheckExact(key)) { if (insertion_resize(mp) < 0) @@ -2968,7 +2968,7 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj) Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash); ep0 = DK_ENTRIES(mp->ma_keys); ep = &ep0[mp->ma_keys->dk_nentries]; - dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries); + dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries); Py_INCREF(key); Py_INCREF(value); MAINTAIN_TRACKING(mp, key, value); @@ -2998,7 +2998,7 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj) mp->ma_version_tag = DICT_NEXT_VERSION(); } - ASSERT_CONSISTENT(mp); + ASSERT_CONSISTENT(mp); return value; } @@ -3027,43 +3027,43 @@ dict_setdefault_impl(PyDictObject *self, PyObject *key, } static PyObject * -dict_clear(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) +dict_clear(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { PyDict_Clear((PyObject *)mp); Py_RETURN_NONE; } -/*[clinic input] -dict.pop - - key: object - default: object = NULL - / - -D.pop(k[,d]) -> v, remove specified key and return the corresponding value. - -If key is not found, default is returned if given, otherwise KeyError is raised -[clinic start generated code]*/ - +/*[clinic input] +dict.pop + + key: object + default: object = NULL + / + +D.pop(k[,d]) -> v, remove specified key and return the corresponding value. + +If key is not found, default is returned if given, otherwise KeyError is raised +[clinic start generated code]*/ + static PyObject * -dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value) -/*[clinic end generated code: output=3abb47b89f24c21c input=eeebec7812190348]*/ +dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value) +/*[clinic end generated code: output=3abb47b89f24c21c input=eeebec7812190348]*/ { - return _PyDict_Pop((PyObject*)self, key, default_value); + return _PyDict_Pop((PyObject*)self, key, default_value); } -/*[clinic input] -dict.popitem - -Remove and return a (key, value) pair as a 2-tuple. - -Pairs are returned in LIFO (last-in, first-out) order. -Raises KeyError if the dict is empty. -[clinic start generated code]*/ - +/*[clinic input] +dict.popitem + +Remove and return a (key, value) pair as a 2-tuple. + +Pairs are returned in LIFO (last-in, first-out) order. +Raises KeyError if the dict is empty. +[clinic start generated code]*/ + static PyObject * -dict_popitem_impl(PyDictObject *self) -/*[clinic end generated code: output=e65fcb04420d230d input=1c38a49f21f64941]*/ +dict_popitem_impl(PyDictObject *self) +/*[clinic end generated code: output=e65fcb04420d230d input=1c38a49f21f64941]*/ { Py_ssize_t i, j; PyDictKeyEntry *ep0, *ep; @@ -3081,43 +3081,43 @@ dict_popitem_impl(PyDictObject *self) res = PyTuple_New(2); if (res == NULL) return NULL; - if (self->ma_used == 0) { + if (self->ma_used == 0) { Py_DECREF(res); - PyErr_SetString(PyExc_KeyError, "popitem(): dictionary is empty"); + PyErr_SetString(PyExc_KeyError, "popitem(): dictionary is empty"); return NULL; } /* Convert split table to combined table */ - if (self->ma_keys->dk_lookup == lookdict_split) { - if (dictresize(self, DK_SIZE(self->ma_keys))) { + if (self->ma_keys->dk_lookup == lookdict_split) { + if (dictresize(self, DK_SIZE(self->ma_keys))) { Py_DECREF(res); return NULL; } } - ENSURE_ALLOWS_DELETIONS(self); + ENSURE_ALLOWS_DELETIONS(self); /* Pop last item */ - ep0 = DK_ENTRIES(self->ma_keys); - i = self->ma_keys->dk_nentries - 1; + ep0 = DK_ENTRIES(self->ma_keys); + i = self->ma_keys->dk_nentries - 1; while (i >= 0 && ep0[i].me_value == NULL) { i--; } assert(i >= 0); ep = &ep0[i]; - j = lookdict_index(self->ma_keys, ep->me_hash, i); + j = lookdict_index(self->ma_keys, ep->me_hash, i); assert(j >= 0); - assert(dictkeys_get_index(self->ma_keys, j) == i); - dictkeys_set_index(self->ma_keys, j, DKIX_DUMMY); + assert(dictkeys_get_index(self->ma_keys, j) == i); + dictkeys_set_index(self->ma_keys, j, DKIX_DUMMY); PyTuple_SET_ITEM(res, 0, ep->me_key); PyTuple_SET_ITEM(res, 1, ep->me_value); ep->me_key = NULL; ep->me_value = NULL; /* We can't dk_usable++ since there is DKIX_DUMMY in indices */ - self->ma_keys->dk_nentries = i; - self->ma_used--; - self->ma_version_tag = DICT_NEXT_VERSION(); - ASSERT_CONSISTENT(self); + self->ma_keys->dk_nentries = i; + self->ma_used--; + self->ma_version_tag = DICT_NEXT_VERSION(); + ASSERT_CONSISTENT(self); return res; } @@ -3190,38 +3190,38 @@ _PyDict_KeysSize(PyDictKeysObject *keys) } static PyObject * -dict_sizeof(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) +dict_sizeof(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(_PyDict_SizeOf(mp)); } -static PyObject * -dict_or(PyObject *self, PyObject *other) -{ - if (!PyDict_Check(self) || !PyDict_Check(other)) { - Py_RETURN_NOTIMPLEMENTED; - } - PyObject *new = PyDict_Copy(self); - if (new == NULL) { - return NULL; - } - if (dict_update_arg(new, other)) { - Py_DECREF(new); - return NULL; - } - return new; -} - -static PyObject * -dict_ior(PyObject *self, PyObject *other) -{ - if (dict_update_arg(self, other)) { - return NULL; - } - Py_INCREF(self); - return self; -} - +static PyObject * +dict_or(PyObject *self, PyObject *other) +{ + if (!PyDict_Check(self) || !PyDict_Check(other)) { + Py_RETURN_NOTIMPLEMENTED; + } + PyObject *new = PyDict_Copy(self); + if (new == NULL) { + return NULL; + } + if (dict_update_arg(new, other)) { + Py_DECREF(new); + return NULL; + } + return new; +} + +static PyObject * +dict_ior(PyObject *self, PyObject *other) +{ + if (dict_update_arg(self, other)) { + return NULL; + } + Py_INCREF(self); + return self; +} + PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]"); PyDoc_STRVAR(sizeof__doc__, @@ -3240,9 +3240,9 @@ PyDoc_STRVAR(copy__doc__, "D.copy() -> a shallow copy of D"); /* Forward */ -static PyObject *dictkeys_new(PyObject *, PyObject *); -static PyObject *dictitems_new(PyObject *, PyObject *); -static PyObject *dictvalues_new(PyObject *, PyObject *); +static PyObject *dictkeys_new(PyObject *, PyObject *); +static PyObject *dictitems_new(PyObject *, PyObject *); +static PyObject *dictvalues_new(PyObject *, PyObject *); PyDoc_STRVAR(keys__doc__, "D.keys() -> a set-like object providing a view on D's keys"); @@ -3253,29 +3253,29 @@ PyDoc_STRVAR(values__doc__, static PyMethodDef mapp_methods[] = { DICT___CONTAINS___METHODDEF - {"__getitem__", (PyCFunction)(void(*)(void))dict_subscript, METH_O | METH_COEXIST, + {"__getitem__", (PyCFunction)(void(*)(void))dict_subscript, METH_O | METH_COEXIST, getitem__doc__}, - {"__sizeof__", (PyCFunction)(void(*)(void))dict_sizeof, METH_NOARGS, + {"__sizeof__", (PyCFunction)(void(*)(void))dict_sizeof, METH_NOARGS, sizeof__doc__}, DICT_GET_METHODDEF DICT_SETDEFAULT_METHODDEF - DICT_POP_METHODDEF - DICT_POPITEM_METHODDEF - {"keys", dictkeys_new, METH_NOARGS, + DICT_POP_METHODDEF + DICT_POPITEM_METHODDEF + {"keys", dictkeys_new, METH_NOARGS, keys__doc__}, - {"items", dictitems_new, METH_NOARGS, + {"items", dictitems_new, METH_NOARGS, items__doc__}, - {"values", dictvalues_new, METH_NOARGS, + {"values", dictvalues_new, METH_NOARGS, values__doc__}, - {"update", (PyCFunction)(void(*)(void))dict_update, METH_VARARGS | METH_KEYWORDS, + {"update", (PyCFunction)(void(*)(void))dict_update, METH_VARARGS | METH_KEYWORDS, update__doc__}, DICT_FROMKEYS_METHODDEF {"clear", (PyCFunction)dict_clear, METH_NOARGS, clear__doc__}, {"copy", (PyCFunction)dict_copy, METH_NOARGS, copy__doc__}, - DICT___REVERSED___METHODDEF - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + DICT___REVERSED___METHODDEF + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -3328,11 +3328,11 @@ static PySequenceMethods dict_as_sequence = { 0, /* sq_inplace_repeat */ }; -static PyNumberMethods dict_as_number = { - .nb_or = dict_or, - .nb_inplace_or = dict_ior, -}; - +static PyNumberMethods dict_as_number = { + .nb_or = dict_or, + .nb_inplace_or = dict_ior, +}; + static PyObject * dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -3356,7 +3356,7 @@ dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_DECREF(self); return NULL; } - ASSERT_CONSISTENT(d); + ASSERT_CONSISTENT(d); return self; } @@ -3367,38 +3367,38 @@ dict_init(PyObject *self, PyObject *args, PyObject *kwds) } static PyObject * -dict_vectorcall(PyObject *type, PyObject * const*args, - size_t nargsf, PyObject *kwnames) -{ - assert(PyType_Check(type)); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_CheckPositional("dict", nargs, 0, 1)) { - return NULL; - } - - PyObject *self = dict_new((PyTypeObject *)type, NULL, NULL); - if (self == NULL) { - return NULL; - } - if (nargs == 1) { - if (dict_update_arg(self, args[0]) < 0) { - Py_DECREF(self); - return NULL; - } - args++; - } - if (kwnames != NULL) { - for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(kwnames); i++) { - if (PyDict_SetItem(self, PyTuple_GET_ITEM(kwnames, i), args[i]) < 0) { - Py_DECREF(self); - return NULL; - } - } - } - return self; -} - -static PyObject * +dict_vectorcall(PyObject *type, PyObject * const*args, + size_t nargsf, PyObject *kwnames) +{ + assert(PyType_Check(type)); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_CheckPositional("dict", nargs, 0, 1)) { + return NULL; + } + + PyObject *self = dict_new((PyTypeObject *)type, NULL, NULL); + if (self == NULL) { + return NULL; + } + if (nargs == 1) { + if (dict_update_arg(self, args[0]) < 0) { + Py_DECREF(self); + return NULL; + } + args++; + } + if (kwnames != NULL) { + for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(kwnames); i++) { + if (PyDict_SetItem(self, PyTuple_GET_ITEM(kwnames, i), args[i]) < 0) { + Py_DECREF(self); + return NULL; + } + } + } + return self; +} + +static PyObject * dict_iter(PyDictObject *dict) { return dictiter_new(dict, &PyDictIterKey_Type); @@ -3421,12 +3421,12 @@ PyTypeObject PyDict_Type = { sizeof(PyDictObject), 0, (destructor)dict_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)dict_repr, /* tp_repr */ - &dict_as_number, /* tp_as_number */ + &dict_as_number, /* tp_as_number */ &dict_as_sequence, /* tp_as_sequence */ &dict_as_mapping, /* tp_as_mapping */ PyObject_HashNotImplemented, /* tp_hash */ @@ -3456,7 +3456,7 @@ PyTypeObject PyDict_Type = { PyType_GenericAlloc, /* tp_alloc */ dict_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ - .tp_vectorcall = dict_vectorcall, + .tp_vectorcall = dict_vectorcall, }; PyObject * @@ -3549,37 +3549,37 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) { dictiterobject *di; di = PyObject_GC_New(dictiterobject, itertype); - if (di == NULL) { + if (di == NULL) { return NULL; - } + } Py_INCREF(dict); di->di_dict = dict; di->di_used = dict->ma_used; di->len = dict->ma_used; - if (itertype == &PyDictRevIterKey_Type || - itertype == &PyDictRevIterItem_Type || - itertype == &PyDictRevIterValue_Type) { - if (dict->ma_values) { - di->di_pos = dict->ma_used - 1; - } - else { - di->di_pos = dict->ma_keys->dk_nentries - 1; - } - } - else { - di->di_pos = 0; - } - if (itertype == &PyDictIterItem_Type || - itertype == &PyDictRevIterItem_Type) { + if (itertype == &PyDictRevIterKey_Type || + itertype == &PyDictRevIterItem_Type || + itertype == &PyDictRevIterValue_Type) { + if (dict->ma_values) { + di->di_pos = dict->ma_used - 1; + } + else { + di->di_pos = dict->ma_keys->dk_nentries - 1; + } + } + else { + di->di_pos = 0; + } + if (itertype == &PyDictIterItem_Type || + itertype == &PyDictRevIterItem_Type) { di->di_result = PyTuple_Pack(2, Py_None, Py_None); if (di->di_result == NULL) { Py_DECREF(di); return NULL; } } - else { + else { di->di_result = NULL; - } + } _PyObject_GC_TRACK(di); return (PyObject *)di; } @@ -3603,7 +3603,7 @@ dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) } static PyObject * -dictiter_len(dictiterobject *di, PyObject *Py_UNUSED(ignored)) +dictiter_len(dictiterobject *di, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used) @@ -3615,14 +3615,14 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)); +dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyMethodDef dictiter_methods[] = { - {"__length_hint__", (PyCFunction)(void(*)(void))dictiter_len, METH_NOARGS, + {"__length_hint__", (PyCFunction)(void(*)(void))dictiter_len, METH_NOARGS, length_hint_doc}, - {"__reduce__", (PyCFunction)(void(*)(void))dictiter_reduce, METH_NOARGS, + {"__reduce__", (PyCFunction)(void(*)(void))dictiter_reduce, METH_NOARGS, reduce_doc}, {NULL, NULL} /* sentinel */ }; @@ -3666,12 +3666,12 @@ dictiter_iternextkey(dictiterobject *di) goto fail; key = entry_ptr->me_key; } - // We found an element (key), but did not expect it - if (di->len == 0) { - PyErr_SetString(PyExc_RuntimeError, - "dictionary keys changed during iteration"); - goto fail; - } + // We found an element (key), but did not expect it + if (di->len == 0) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary keys changed during iteration"); + goto fail; + } di->di_pos = i+1; di->len--; Py_INCREF(key); @@ -3690,10 +3690,10 @@ PyTypeObject PyDictIterKey_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3753,12 +3753,12 @@ dictiter_iternextvalue(dictiterobject *di) goto fail; value = entry_ptr->me_value; } - // We found an element, but did not expect it - if (di->len == 0) { - PyErr_SetString(PyExc_RuntimeError, - "dictionary keys changed during iteration"); - goto fail; - } + // We found an element, but did not expect it + if (di->len == 0) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary keys changed during iteration"); + goto fail; + } di->di_pos = i+1; di->len--; Py_INCREF(value); @@ -3777,10 +3777,10 @@ PyTypeObject PyDictIterValue_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3842,12 +3842,12 @@ dictiter_iternextitem(dictiterobject *di) key = entry_ptr->me_key; value = entry_ptr->me_value; } - // We found an element, but did not expect it - if (di->len == 0) { - PyErr_SetString(PyExc_RuntimeError, - "dictionary keys changed during iteration"); - goto fail; - } + // We found an element, but did not expect it + if (di->len == 0) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary keys changed during iteration"); + goto fail; + } di->di_pos = i+1; di->len--; Py_INCREF(key); @@ -3861,11 +3861,11 @@ dictiter_iternextitem(dictiterobject *di) Py_INCREF(result); Py_DECREF(oldkey); Py_DECREF(oldvalue); - // 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); - } + // 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); + } } else { result = PyTuple_New(2); @@ -3889,10 +3889,10 @@ PyTypeObject PyDictIterItem_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3916,164 +3916,164 @@ PyTypeObject PyDictIterItem_Type = { }; -/* dictreviter */ - +/* dictreviter */ + static PyObject * -dictreviter_iternext(dictiterobject *di) +dictreviter_iternext(dictiterobject *di) { - PyDictObject *d = di->di_dict; + PyDictObject *d = di->di_dict; + + if (d == NULL) { + return NULL; + } + assert (PyDict_Check(d)); - if (d == NULL) { + if (di->di_used != d->ma_used) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary changed size during iteration"); + di->di_used = -1; /* Make this state sticky */ return NULL; - } - assert (PyDict_Check(d)); - - if (di->di_used != d->ma_used) { - PyErr_SetString(PyExc_RuntimeError, - "dictionary changed size during iteration"); - di->di_used = -1; /* Make this state sticky */ - return NULL; - } - - Py_ssize_t i = di->di_pos; - PyDictKeysObject *k = d->ma_keys; - PyObject *key, *value, *result; - - if (i < 0) { - goto fail; - } - if (d->ma_values) { - key = DK_ENTRIES(k)[i].me_key; - value = d->ma_values[i]; - assert (value != NULL); - } - else { - PyDictKeyEntry *entry_ptr = &DK_ENTRIES(k)[i]; - while (entry_ptr->me_value == NULL) { - if (--i < 0) { - goto fail; - } - entry_ptr--; - } - key = entry_ptr->me_key; - value = entry_ptr->me_value; - } - di->di_pos = i-1; - di->len--; - - if (Py_IS_TYPE(di, &PyDictRevIterKey_Type)) { - Py_INCREF(key); - return key; - } - else if (Py_IS_TYPE(di, &PyDictRevIterValue_Type)) { - Py_INCREF(value); - return value; - } - else if (Py_IS_TYPE(di, &PyDictRevIterItem_Type)) { - Py_INCREF(key); - Py_INCREF(value); - result = di->di_result; - if (Py_REFCNT(result) == 1) { - PyObject *oldkey = PyTuple_GET_ITEM(result, 0); - PyObject *oldvalue = PyTuple_GET_ITEM(result, 1); - PyTuple_SET_ITEM(result, 0, key); /* steals reference */ - PyTuple_SET_ITEM(result, 1, value); /* steals reference */ - Py_INCREF(result); - Py_DECREF(oldkey); - Py_DECREF(oldvalue); - // 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); - } - } - else { - result = PyTuple_New(2); - if (result == NULL) { + } + + Py_ssize_t i = di->di_pos; + PyDictKeysObject *k = d->ma_keys; + PyObject *key, *value, *result; + + if (i < 0) { + goto fail; + } + if (d->ma_values) { + key = DK_ENTRIES(k)[i].me_key; + value = d->ma_values[i]; + assert (value != NULL); + } + else { + PyDictKeyEntry *entry_ptr = &DK_ENTRIES(k)[i]; + while (entry_ptr->me_value == NULL) { + if (--i < 0) { + goto fail; + } + entry_ptr--; + } + key = entry_ptr->me_key; + value = entry_ptr->me_value; + } + di->di_pos = i-1; + di->len--; + + if (Py_IS_TYPE(di, &PyDictRevIterKey_Type)) { + Py_INCREF(key); + return key; + } + else if (Py_IS_TYPE(di, &PyDictRevIterValue_Type)) { + Py_INCREF(value); + return value; + } + else if (Py_IS_TYPE(di, &PyDictRevIterItem_Type)) { + Py_INCREF(key); + Py_INCREF(value); + result = di->di_result; + if (Py_REFCNT(result) == 1) { + PyObject *oldkey = PyTuple_GET_ITEM(result, 0); + PyObject *oldvalue = PyTuple_GET_ITEM(result, 1); + PyTuple_SET_ITEM(result, 0, key); /* steals reference */ + PyTuple_SET_ITEM(result, 1, value); /* steals reference */ + Py_INCREF(result); + Py_DECREF(oldkey); + Py_DECREF(oldvalue); + // 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); + } + } + else { + result = PyTuple_New(2); + if (result == NULL) { return NULL; } - PyTuple_SET_ITEM(result, 0, key); /* steals reference */ - PyTuple_SET_ITEM(result, 1, value); /* steals reference */ - } - return result; - } - else { - Py_UNREACHABLE(); - } - -fail: - di->di_dict = NULL; - Py_DECREF(d); - return NULL; -} - -PyTypeObject PyDictRevIterKey_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dict_reversekeyiterator", - sizeof(dictiterobject), - .tp_dealloc = (destructor)dictiter_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)dictiter_traverse, - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)dictreviter_iternext, - .tp_methods = dictiter_methods -}; - - -/*[clinic input] -dict.__reversed__ - -Return a reverse iterator over the dict keys. -[clinic start generated code]*/ - -static PyObject * -dict___reversed___impl(PyDictObject *self) -/*[clinic end generated code: output=e674483336d1ed51 input=23210ef3477d8c4d]*/ -{ - assert (PyDict_Check(self)); - return dictiter_new(self, &PyDictRevIterKey_Type); -} - -static PyObject * -dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) -{ - _Py_IDENTIFIER(iter); - /* copy the iterator state */ - dictiterobject tmp = *di; - Py_XINCREF(tmp.di_dict); - - PyObject *list = PySequence_List((PyObject*)&tmp); + PyTuple_SET_ITEM(result, 0, key); /* steals reference */ + PyTuple_SET_ITEM(result, 1, value); /* steals reference */ + } + return result; + } + else { + Py_UNREACHABLE(); + } + +fail: + di->di_dict = NULL; + Py_DECREF(d); + return NULL; +} + +PyTypeObject PyDictRevIterKey_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "dict_reversekeyiterator", + sizeof(dictiterobject), + .tp_dealloc = (destructor)dictiter_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_traverse = (traverseproc)dictiter_traverse, + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)dictreviter_iternext, + .tp_methods = dictiter_methods +}; + + +/*[clinic input] +dict.__reversed__ + +Return a reverse iterator over the dict keys. +[clinic start generated code]*/ + +static PyObject * +dict___reversed___impl(PyDictObject *self) +/*[clinic end generated code: output=e674483336d1ed51 input=23210ef3477d8c4d]*/ +{ + assert (PyDict_Check(self)); + return dictiter_new(self, &PyDictRevIterKey_Type); +} + +static PyObject * +dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) +{ + _Py_IDENTIFIER(iter); + /* copy the iterator state */ + dictiterobject tmp = *di; + Py_XINCREF(tmp.di_dict); + + PyObject *list = PySequence_List((PyObject*)&tmp); Py_XDECREF(tmp.di_dict); - if (list == NULL) { + if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); -} - -PyTypeObject PyDictRevIterItem_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dict_reverseitemiterator", - sizeof(dictiterobject), - .tp_dealloc = (destructor)dictiter_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)dictiter_traverse, - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)dictreviter_iternext, - .tp_methods = dictiter_methods -}; - -PyTypeObject PyDictRevIterValue_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dict_reversevalueiterator", - sizeof(dictiterobject), - .tp_dealloc = (destructor)dictiter_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)dictiter_traverse, - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)dictreviter_iternext, - .tp_methods = dictiter_methods -}; - + return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); +} + +PyTypeObject PyDictRevIterItem_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "dict_reverseitemiterator", + sizeof(dictiterobject), + .tp_dealloc = (destructor)dictiter_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_traverse = (traverseproc)dictiter_traverse, + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)dictreviter_iternext, + .tp_methods = dictiter_methods +}; + +PyTypeObject PyDictRevIterValue_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "dict_reversevalueiterator", + sizeof(dictiterobject), + .tp_dealloc = (destructor)dictiter_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_traverse = (traverseproc)dictiter_traverse, + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)dictreviter_iternext, + .tp_methods = dictiter_methods +}; + /***********************************************/ /* View objects for keys(), items(), values(). */ /***********************************************/ @@ -4117,7 +4117,7 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type) /* XXX Get rid of this restriction later */ PyErr_Format(PyExc_TypeError, "%s() requires a dict argument, not '%s'", - type->tp_name, Py_TYPE(dict)->tp_name); + type->tp_name, Py_TYPE(dict)->tp_name); return NULL; } dv = PyObject_GC_New(_PyDictViewObject, type); @@ -4276,34 +4276,34 @@ static PySequenceMethods dictkeys_as_sequence = { (objobjproc)dictkeys_contains, /* sq_contains */ }; -// Create an set object from dictviews object. -// Returns a new reference. -// This utility function is used by set operations. +// Create an set object from dictviews object. +// Returns a new reference. +// This utility function is used by set operations. +static PyObject* +dictviews_to_set(PyObject *self) +{ + PyObject *left = self; + if (PyDictKeys_Check(self)) { + // PySet_New() has fast path for the dict object. + PyObject *dict = (PyObject *)((_PyDictViewObject *)self)->dv_dict; + if (PyDict_CheckExact(dict)) { + left = dict; + } + } + return PySet_New(left); +} + static PyObject* -dictviews_to_set(PyObject *self) -{ - PyObject *left = self; - if (PyDictKeys_Check(self)) { - // PySet_New() has fast path for the dict object. - PyObject *dict = (PyObject *)((_PyDictViewObject *)self)->dv_dict; - if (PyDict_CheckExact(dict)) { - left = dict; - } - } - return PySet_New(left); -} - -static PyObject* -dictviews_sub(PyObject *self, PyObject *other) -{ - PyObject *result = dictviews_to_set(self); - if (result == NULL) { +dictviews_sub(PyObject *self, PyObject *other) +{ + PyObject *result = dictviews_to_set(self); + if (result == NULL) { return NULL; - } + } - _Py_IDENTIFIER(difference_update); - PyObject *tmp = _PyObject_CallMethodIdOneArg( - result, &PyId_difference_update, other); + _Py_IDENTIFIER(difference_update); + PyObject *tmp = _PyObject_CallMethodIdOneArg( + result, &PyId_difference_update, other); if (tmp == NULL) { Py_DECREF(result); return NULL; @@ -4313,103 +4313,103 @@ dictviews_sub(PyObject *self, PyObject *other) return result; } -static int -dictitems_contains(_PyDictViewObject *dv, PyObject *obj); - -PyObject * +static int +dictitems_contains(_PyDictViewObject *dv, PyObject *obj); + +PyObject * _PyDictView_Intersect(PyObject* self, PyObject *other) { - PyObject *result; - PyObject *it; - PyObject *key; - Py_ssize_t len_self; - int rv; - int (*dict_contains)(_PyDictViewObject *, PyObject *); - - /* Python interpreter swaps parameters when dict view - is on right side of & */ - if (!PyDictViewSet_Check(self)) { - PyObject *tmp = other; - other = self; - self = tmp; - } - - len_self = dictview_len((_PyDictViewObject *)self); - - /* if other is a set and self is smaller than other, - reuse set intersection logic */ - if (Py_IS_TYPE(other, &PySet_Type) && len_self <= PyObject_Size(other)) { - _Py_IDENTIFIER(intersection); - return _PyObject_CallMethodIdObjArgs(other, &PyId_intersection, self, NULL); - } - - /* if other is another dict view, and it is bigger than self, - swap them */ - if (PyDictViewSet_Check(other)) { - Py_ssize_t len_other = dictview_len((_PyDictViewObject *)other); - if (len_other > len_self) { - PyObject *tmp = other; - other = self; - self = tmp; - } - } - - /* at this point, two things should be true - 1. self is a dictview - 2. if other is a dictview then it is smaller than self */ - result = PySet_New(NULL); + PyObject *result; + PyObject *it; + PyObject *key; + Py_ssize_t len_self; + int rv; + int (*dict_contains)(_PyDictViewObject *, PyObject *); + + /* Python interpreter swaps parameters when dict view + is on right side of & */ + if (!PyDictViewSet_Check(self)) { + PyObject *tmp = other; + other = self; + self = tmp; + } + + len_self = dictview_len((_PyDictViewObject *)self); + + /* if other is a set and self is smaller than other, + reuse set intersection logic */ + if (Py_IS_TYPE(other, &PySet_Type) && len_self <= PyObject_Size(other)) { + _Py_IDENTIFIER(intersection); + return _PyObject_CallMethodIdObjArgs(other, &PyId_intersection, self, NULL); + } + + /* if other is another dict view, and it is bigger than self, + swap them */ + if (PyDictViewSet_Check(other)) { + Py_ssize_t len_other = dictview_len((_PyDictViewObject *)other); + if (len_other > len_self) { + PyObject *tmp = other; + other = self; + self = tmp; + } + } + + /* at this point, two things should be true + 1. self is a dictview + 2. if other is a dictview then it is smaller than self */ + result = PySet_New(NULL); if (result == NULL) return NULL; - it = PyObject_GetIter(other); - if (it == NULL) { + it = PyObject_GetIter(other); + if (it == NULL) { Py_DECREF(result); return NULL; } - if (PyDictKeys_Check(self)) { - dict_contains = dictkeys_contains; - } - /* else PyDictItems_Check(self) */ - else { - dict_contains = dictitems_contains; - } - - while ((key = PyIter_Next(it)) != NULL) { - rv = dict_contains((_PyDictViewObject *)self, key); - if (rv < 0) { - goto error; - } - if (rv) { - if (PySet_Add(result, key)) { - goto error; - } - } - Py_DECREF(key); - } - Py_DECREF(it); - if (PyErr_Occurred()) { - Py_DECREF(result); - return NULL; - } + if (PyDictKeys_Check(self)) { + dict_contains = dictkeys_contains; + } + /* else PyDictItems_Check(self) */ + else { + dict_contains = dictitems_contains; + } + + while ((key = PyIter_Next(it)) != NULL) { + rv = dict_contains((_PyDictViewObject *)self, key); + if (rv < 0) { + goto error; + } + if (rv) { + if (PySet_Add(result, key)) { + goto error; + } + } + Py_DECREF(key); + } + Py_DECREF(it); + if (PyErr_Occurred()) { + Py_DECREF(result); + return NULL; + } return result; - -error: - Py_DECREF(it); - Py_DECREF(result); - Py_DECREF(key); - return NULL; + +error: + Py_DECREF(it); + Py_DECREF(result); + Py_DECREF(key); + return NULL; } static PyObject* dictviews_or(PyObject* self, PyObject *other) { - PyObject *result = dictviews_to_set(self); - if (result == NULL) { + PyObject *result = dictviews_to_set(self); + if (result == NULL) { return NULL; - } + } - if (_PySet_Update(result, other) < 0) { + if (_PySet_Update(result, other) < 0) { Py_DECREF(result); return NULL; } @@ -4419,14 +4419,14 @@ dictviews_or(PyObject* self, PyObject *other) static PyObject* dictviews_xor(PyObject* self, PyObject *other) { - PyObject *result = dictviews_to_set(self); - if (result == NULL) { + PyObject *result = dictviews_to_set(self); + if (result == NULL) { return NULL; - } + } - _Py_IDENTIFIER(symmetric_difference_update); - PyObject *tmp = _PyObject_CallMethodIdOneArg( - result, &PyId_symmetric_difference_update, other); + _Py_IDENTIFIER(symmetric_difference_update); + PyObject *tmp = _PyObject_CallMethodIdOneArg( + result, &PyId_symmetric_difference_update, other); if (tmp == NULL) { Py_DECREF(result); return NULL; @@ -4509,16 +4509,16 @@ dictviews_isdisjoint(PyObject *self, PyObject *other) PyDoc_STRVAR(isdisjoint_doc, "Return True if the view and the given iterable have a null intersection."); -static PyObject* dictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); - -PyDoc_STRVAR(reversed_keys_doc, -"Return a reverse iterator over the dict keys."); - +static PyObject* dictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); + +PyDoc_STRVAR(reversed_keys_doc, +"Return a reverse iterator over the dict keys."); + static PyMethodDef dictkeys_methods[] = { {"isdisjoint", (PyCFunction)dictviews_isdisjoint, METH_O, isdisjoint_doc}, - {"__reversed__", (PyCFunction)(void(*)(void))dictkeys_reversed, METH_NOARGS, - reversed_keys_doc}, + {"__reversed__", (PyCFunction)(void(*)(void))dictkeys_reversed, METH_NOARGS, + reversed_keys_doc}, {NULL, NULL} /* sentinel */ }; @@ -4529,10 +4529,10 @@ PyTypeObject PyDictKeys_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictview_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)dictview_repr, /* tp_repr */ &dictviews_as_number, /* tp_as_number */ &dictkeys_as_sequence, /* tp_as_sequence */ @@ -4556,20 +4556,20 @@ PyTypeObject PyDictKeys_Type = { }; static PyObject * -dictkeys_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) +dictkeys_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictKeys_Type); } -static PyObject * -dictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) -{ - if (dv->dv_dict == NULL) { - Py_RETURN_NONE; - } - return dictiter_new(dv->dv_dict, &PyDictRevIterKey_Type); -} - +static PyObject * +dictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +{ + if (dv->dv_dict == NULL) { + Py_RETURN_NONE; + } + return dictiter_new(dv->dv_dict, &PyDictRevIterKey_Type); +} + /*** dict_items ***/ static PyObject * @@ -4599,7 +4599,7 @@ dictitems_contains(_PyDictViewObject *dv, PyObject *obj) return 0; } Py_INCREF(found); - result = PyObject_RichCompareBool(found, value, Py_EQ); + result = PyObject_RichCompareBool(found, value, Py_EQ); Py_DECREF(found); return result; } @@ -4615,16 +4615,16 @@ static PySequenceMethods dictitems_as_sequence = { (objobjproc)dictitems_contains, /* sq_contains */ }; -static PyObject* dictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); - -PyDoc_STRVAR(reversed_items_doc, -"Return a reverse iterator over the dict items."); - +static PyObject* dictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); + +PyDoc_STRVAR(reversed_items_doc, +"Return a reverse iterator over the dict items."); + static PyMethodDef dictitems_methods[] = { {"isdisjoint", (PyCFunction)dictviews_isdisjoint, METH_O, isdisjoint_doc}, - {"__reversed__", (PyCFunction)dictitems_reversed, METH_NOARGS, - reversed_items_doc}, + {"__reversed__", (PyCFunction)dictitems_reversed, METH_NOARGS, + reversed_items_doc}, {NULL, NULL} /* sentinel */ }; @@ -4635,10 +4635,10 @@ PyTypeObject PyDictItems_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictview_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)dictview_repr, /* tp_repr */ &dictviews_as_number, /* tp_as_number */ &dictitems_as_sequence, /* tp_as_sequence */ @@ -4662,20 +4662,20 @@ PyTypeObject PyDictItems_Type = { }; static PyObject * -dictitems_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) +dictitems_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictItems_Type); } -static PyObject * -dictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) -{ - if (dv->dv_dict == NULL) { - Py_RETURN_NONE; - } - return dictiter_new(dv->dv_dict, &PyDictRevIterItem_Type); -} - +static PyObject * +dictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +{ + if (dv->dv_dict == NULL) { + Py_RETURN_NONE; + } + return dictiter_new(dv->dv_dict, &PyDictRevIterItem_Type); +} + /*** dict_values ***/ static PyObject * @@ -4698,14 +4698,14 @@ static PySequenceMethods dictvalues_as_sequence = { (objobjproc)0, /* sq_contains */ }; -static PyObject* dictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); - -PyDoc_STRVAR(reversed_values_doc, -"Return a reverse iterator over the dict values."); - +static PyObject* dictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)); + +PyDoc_STRVAR(reversed_values_doc, +"Return a reverse iterator over the dict values."); + static PyMethodDef dictvalues_methods[] = { - {"__reversed__", (PyCFunction)dictvalues_reversed, METH_NOARGS, - reversed_values_doc}, + {"__reversed__", (PyCFunction)dictvalues_reversed, METH_NOARGS, + reversed_values_doc}, {NULL, NULL} /* sentinel */ }; @@ -4716,10 +4716,10 @@ PyTypeObject PyDictValues_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)dictview_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)dictview_repr, /* tp_repr */ 0, /* tp_as_number */ &dictvalues_as_sequence, /* tp_as_sequence */ @@ -4743,21 +4743,21 @@ PyTypeObject PyDictValues_Type = { }; static PyObject * -dictvalues_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) +dictvalues_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictValues_Type); } -static PyObject * -dictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) -{ - if (dv->dv_dict == NULL) { - Py_RETURN_NONE; - } - return dictiter_new(dv->dv_dict, &PyDictRevIterValue_Type); -} - - +static PyObject * +dictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +{ + if (dv->dv_dict == NULL) { + Py_RETURN_NONE; + } + return dictiter_new(dv->dv_dict, &PyDictRevIterValue_Type); +} + + /* Returns NULL if cannot allocate a new PyDictKeysObject, but does not set an error */ PyDictKeysObject * @@ -4786,7 +4786,7 @@ PyObject_GenericGetDict(PyObject *obj, void *context) if (dict == NULL) { PyTypeObject *tp = Py_TYPE(obj); if ((tp->tp_flags & Py_TPFLAGS_HEAPTYPE) && CACHED_KEYS(tp)) { - dictkeys_incref(CACHED_KEYS(tp)); + dictkeys_incref(CACHED_KEYS(tp)); *dictptr = dict = new_dict_with_shared_keys(CACHED_KEYS(tp)); } else { @@ -4810,7 +4810,7 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, assert(dictptr != NULL); dict = *dictptr; if (dict == NULL) { - dictkeys_incref(cached); + dictkeys_incref(cached); dict = new_dict_with_shared_keys(cached); if (dict == NULL) return -1; @@ -4822,7 +4822,7 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, // always converts dict to combined form. if ((cached = CACHED_KEYS(tp)) != NULL) { CACHED_KEYS(tp) = NULL; - dictkeys_decref(cached); + dictkeys_decref(cached); } } else { @@ -4851,7 +4851,7 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, else { CACHED_KEYS(tp) = NULL; } - dictkeys_decref(cached); + dictkeys_decref(cached); if (CACHED_KEYS(tp) == NULL && PyErr_Occurred()) return -1; } @@ -4876,5 +4876,5 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, void _PyDictKeys_DecRef(PyDictKeysObject *keys) { - dictkeys_decref(keys); + dictkeys_decref(keys); } diff --git a/contrib/tools/python3/src/Objects/enumobject.c b/contrib/tools/python3/src/Objects/enumobject.c index 9752d0046c..bdd0ea5f39 100644 --- a/contrib/tools/python3/src/Objects/enumobject.c +++ b/contrib/tools/python3/src/Objects/enumobject.c @@ -1,7 +1,7 @@ /* enumerate object */ #include "Python.h" -#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_object.h" // _PyObject_GC_TRACK() #include "clinic/enumobject.c.h" @@ -123,7 +123,7 @@ enum_next_long(enumobject *en, PyObject* next_item) } en->en_longindex = stepped_up; - if (Py_REFCNT(result) == 1) { + if (Py_REFCNT(result) == 1) { Py_INCREF(result); old_index = PyTuple_GET_ITEM(result, 0); old_item = PyTuple_GET_ITEM(result, 1); @@ -131,11 +131,11 @@ enum_next_long(enumobject *en, PyObject* next_item) PyTuple_SET_ITEM(result, 1, next_item); Py_DECREF(old_index); Py_DECREF(old_item); - // 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); - } + // 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); + } return result; } result = PyTuple_New(2); @@ -173,7 +173,7 @@ enum_next(enumobject *en) } en->en_index++; - if (Py_REFCNT(result) == 1) { + if (Py_REFCNT(result) == 1) { Py_INCREF(result); old_index = PyTuple_GET_ITEM(result, 0); old_item = PyTuple_GET_ITEM(result, 1); @@ -181,11 +181,11 @@ enum_next(enumobject *en) PyTuple_SET_ITEM(result, 1, next_item); Py_DECREF(old_index); Py_DECREF(old_item); - // 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); - } + // 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); + } return result; } result = PyTuple_New(2); @@ -200,7 +200,7 @@ enum_next(enumobject *en) } static PyObject * -enum_reduce(enumobject *en, PyObject *Py_UNUSED(ignored)) +enum_reduce(enumobject *en, PyObject *Py_UNUSED(ignored)) { if (en->en_longindex != NULL) return Py_BuildValue("O(OO)", Py_TYPE(en), en->en_sit, en->en_longindex); @@ -212,8 +212,8 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyMethodDef enum_methods[] = { {"__reduce__", (PyCFunction)enum_reduce, METH_NOARGS, reduce_doc}, - {"__class_getitem__", (PyCFunction)Py_GenericAlias, - METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -224,10 +224,10 @@ PyTypeObject PyEnum_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)enum_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -362,7 +362,7 @@ reversed_next(reversedobject *ro) } static PyObject * -reversed_len(reversedobject *ro, PyObject *Py_UNUSED(ignored)) +reversed_len(reversedobject *ro, PyObject *Py_UNUSED(ignored)) { Py_ssize_t position, seqsize; @@ -378,7 +378,7 @@ reversed_len(reversedobject *ro, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -reversed_reduce(reversedobject *ro, PyObject *Py_UNUSED(ignored)) +reversed_reduce(reversedobject *ro, PyObject *Py_UNUSED(ignored)) { if (ro->seq) return Py_BuildValue("O(O)n", Py_TYPE(ro), ro->seq, ro->index); @@ -421,10 +421,10 @@ PyTypeObject PyReversed_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)reversed_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/exceptions.c b/contrib/tools/python3/src/Objects/exceptions.c index 3ca2e688e7..e67ecfab85 100644 --- a/contrib/tools/python3/src/Objects/exceptions.c +++ b/contrib/tools/python3/src/Objects/exceptions.c @@ -6,10 +6,10 @@ #define PY_SSIZE_T_CLEAN #include <Python.h> -#include "pycore_initconfig.h" -#include "pycore_object.h" -#include "structmember.h" // PyMemberDef -#include "osdefs.h" // SEP +#include "pycore_initconfig.h" +#include "pycore_object.h" +#include "structmember.h" // PyMemberDef +#include "osdefs.h" // SEP /* Compatibility aliases */ @@ -126,7 +126,7 @@ BaseException_repr(PyBaseExceptionObject *self) /* Pickling support */ static PyObject * -BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored)) +BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored)) { if (self->args && self->dict) return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict); @@ -304,33 +304,33 @@ static PyGetSetDef BaseException_getset[] = { }; -static inline PyBaseExceptionObject* -_PyBaseExceptionObject_cast(PyObject *exc) -{ - assert(PyExceptionInstance_Check(exc)); - return (PyBaseExceptionObject *)exc; -} - - +static inline PyBaseExceptionObject* +_PyBaseExceptionObject_cast(PyObject *exc) +{ + assert(PyExceptionInstance_Check(exc)); + return (PyBaseExceptionObject *)exc; +} + + PyObject * -PyException_GetTraceback(PyObject *self) -{ - PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); +PyException_GetTraceback(PyObject *self) +{ + PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); Py_XINCREF(base_self->traceback); return base_self->traceback; } int -PyException_SetTraceback(PyObject *self, PyObject *tb) -{ - return BaseException_set_tb(_PyBaseExceptionObject_cast(self), tb, NULL); +PyException_SetTraceback(PyObject *self, PyObject *tb) +{ + return BaseException_set_tb(_PyBaseExceptionObject_cast(self), tb, NULL); } PyObject * -PyException_GetCause(PyObject *self) -{ - PyObject *cause = _PyBaseExceptionObject_cast(self)->cause; +PyException_GetCause(PyObject *self) +{ + PyObject *cause = _PyBaseExceptionObject_cast(self)->cause; Py_XINCREF(cause); return cause; } @@ -339,15 +339,15 @@ PyException_GetCause(PyObject *self) void PyException_SetCause(PyObject *self, PyObject *cause) { - PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); - base_self->suppress_context = 1; - Py_XSETREF(base_self->cause, cause); + PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); + base_self->suppress_context = 1; + Py_XSETREF(base_self->cause, cause); } PyObject * -PyException_GetContext(PyObject *self) -{ - PyObject *context = _PyBaseExceptionObject_cast(self)->context; +PyException_GetContext(PyObject *self) +{ + PyObject *context = _PyBaseExceptionObject_cast(self)->context; Py_XINCREF(context); return context; } @@ -356,18 +356,18 @@ PyException_GetContext(PyObject *self) void PyException_SetContext(PyObject *self, PyObject *context) { - Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context); + Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context); } -#undef PyExceptionClass_Name +#undef PyExceptionClass_Name + +const char * +PyExceptionClass_Name(PyObject *ob) +{ + assert(PyExceptionClass_Check(ob)); + return ((PyTypeObject*)ob)->tp_name; +} -const char * -PyExceptionClass_Name(PyObject *ob) -{ - assert(PyExceptionClass_Check(ob)); - return ((PyTypeObject*)ob)->tp_name; -} - static struct PyMemberDef BaseException_members[] = { {"__suppress_context__", T_BOOL, offsetof(PyBaseExceptionObject, suppress_context)}, @@ -381,10 +381,10 @@ static PyTypeObject _PyExc_BaseException = { sizeof(PyBaseExceptionObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)BaseException_dealloc, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ (reprfunc)BaseException_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ @@ -417,7 +417,7 @@ static PyTypeObject _PyExc_BaseException = { BaseException_new, /* tp_new */ }; /* the CPython API expects exceptions to be (PyObject *) - both a hold-over -from the previous implementation and also allowing Python objects to be used +from the previous implementation and also allowing Python objects to be used in the API */ PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException; @@ -738,7 +738,7 @@ ImportError_getstate(PyImportErrorObject *self) /* Pickling support */ static PyObject * -ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored)) +ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *res; PyObject *args; @@ -887,7 +887,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args, /* self->filename will remain Py_None otherwise */ if (filename && filename != Py_None) { - if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) && + if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) && PyNumber_Check(filename)) { /* BlockingIOError's 3rd argument can be the number of * characters written. @@ -988,7 +988,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (myerrno && PyLong_Check(myerrno) && errnomap && (PyObject *) type == PyExc_OSError) { PyObject *newtype; - newtype = PyDict_GetItemWithError(errnomap, myerrno); + newtype = PyDict_GetItemWithError(errnomap, myerrno); if (newtype) { assert(PyType_Check(newtype)); type = (PyTypeObject *) newtype; @@ -1148,7 +1148,7 @@ OSError_str(PyOSErrorObject *self) } static PyObject * -OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) +OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *args = self->args; PyObject *res = NULL, *tmp; @@ -1209,14 +1209,14 @@ OSError_written_get(PyOSErrorObject *self, void *context) static int OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context) { - if (arg == NULL) { - if (self->written == -1) { - PyErr_SetString(PyExc_AttributeError, "characters_written"); - return -1; - } - self->written = -1; - return 0; - } + if (arg == NULL) { + if (self->written == -1) { + PyErr_SetString(PyExc_AttributeError, "characters_written"); + return -1; + } + self->written = -1; + return 0; + } Py_ssize_t n; n = PyNumber_AsSsize_t(arg, PyExc_ValueError); if (n == -1 && PyErr_Occurred()) @@ -1391,7 +1391,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) * Only applies to SyntaxError instances, not to subclasses such * as TabError or IndentationError (see issue #31161) */ - if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) && + if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) && self->text && PyUnicode_Check(self->text) && _report_missing_parentheses(self) < 0) { return -1; @@ -1440,7 +1440,7 @@ my_basename(PyObject *name) { Py_ssize_t i, size, offset; int kind; - const void *data; + const void *data; if (PyUnicode_READY(name)) return NULL; @@ -1449,13 +1449,13 @@ my_basename(PyObject *name) size = PyUnicode_GET_LENGTH(name); offset = 0; for(i=0; i < size; i++) { - if (PyUnicode_READ(kind, data, i) == SEP) { + if (PyUnicode_READ(kind, data, i) == SEP) { offset = i + 1; - } + } } - if (offset != 0) { + if (offset != 0) { return PyUnicode_Substring(name, offset, size); - } + } else { Py_INCREF(name); return name; @@ -1773,9 +1773,9 @@ PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end) int -PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end) +PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end) { - return PyUnicodeEncodeError_GetEnd(exc, end); + return PyUnicodeEncodeError_GetEnd(exc, end); } @@ -2282,12 +2282,12 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyBaseExceptionObject *self; - /* If this is a subclass of MemoryError, don't use the freelist - * and just return a fresh object */ - if (type != (PyTypeObject *) PyExc_MemoryError) { + /* If this is a subclass of MemoryError, don't use the freelist + * and just return a fresh object */ + if (type != (PyTypeObject *) PyExc_MemoryError) { return BaseException_new(type, args, kwds); - } - + } + if (memerrors_freelist == NULL) return BaseException_new(type, args, kwds); /* Fetch object from freelist and revive it */ @@ -2307,15 +2307,15 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static void MemoryError_dealloc(PyBaseExceptionObject *self) { - BaseException_clear(self); - - if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) { - Py_TYPE(self)->tp_free((PyObject *)self); - return; - } - + BaseException_clear(self); + + if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) { + Py_TYPE(self)->tp_free((PyObject *)self); + return; + } + _PyObject_GC_UNTRACK(self); - + if (memerrors_numfree >= MEMERRORS_SAVE) Py_TYPE(self)->tp_free((PyObject *)self); else { @@ -2325,7 +2325,7 @@ MemoryError_dealloc(PyBaseExceptionObject *self) } } -static int +static int preallocate_memerrors(void) { /* We create enough MemoryErrors and then decref them, which will fill @@ -2335,14 +2335,14 @@ preallocate_memerrors(void) for (i = 0; i < MEMERRORS_SAVE; i++) { errors[i] = MemoryError_new((PyTypeObject *) PyExc_MemoryError, NULL, NULL); - if (!errors[i]) { - return -1; - } + if (!errors[i]) { + return -1; + } } for (i = 0; i < MEMERRORS_SAVE; i++) { Py_DECREF(errors[i]); } - return 0; + return 0; } static void @@ -2517,242 +2517,242 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning, #endif #endif /* MS_WINDOWS */ -PyStatus -_PyExc_Init(void) -{ -#define PRE_INIT(TYPE) \ - if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \ - if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \ - return _PyStatus_ERR("exceptions bootstrapping error."); \ - } \ - Py_INCREF(PyExc_ ## TYPE); \ - } - -#define ADD_ERRNO(TYPE, CODE) \ - do { \ - PyObject *_code = PyLong_FromLong(CODE); \ - assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \ - if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) { \ - Py_XDECREF(_code); \ - return _PyStatus_ERR("errmap insertion problem."); \ - } \ - Py_DECREF(_code); \ - } while (0) - - PRE_INIT(BaseException); - PRE_INIT(Exception); - PRE_INIT(TypeError); - PRE_INIT(StopAsyncIteration); - PRE_INIT(StopIteration); - PRE_INIT(GeneratorExit); - PRE_INIT(SystemExit); - PRE_INIT(KeyboardInterrupt); - PRE_INIT(ImportError); - PRE_INIT(ModuleNotFoundError); - PRE_INIT(OSError); - PRE_INIT(EOFError); - PRE_INIT(RuntimeError); - PRE_INIT(RecursionError); - PRE_INIT(NotImplementedError); - PRE_INIT(NameError); - PRE_INIT(UnboundLocalError); - PRE_INIT(AttributeError); - PRE_INIT(SyntaxError); - PRE_INIT(IndentationError); - PRE_INIT(TabError); - PRE_INIT(LookupError); - PRE_INIT(IndexError); - PRE_INIT(KeyError); - PRE_INIT(ValueError); - PRE_INIT(UnicodeError); - PRE_INIT(UnicodeEncodeError); - PRE_INIT(UnicodeDecodeError); - PRE_INIT(UnicodeTranslateError); - PRE_INIT(AssertionError); - PRE_INIT(ArithmeticError); - PRE_INIT(FloatingPointError); - PRE_INIT(OverflowError); - PRE_INIT(ZeroDivisionError); - PRE_INIT(SystemError); - PRE_INIT(ReferenceError); - PRE_INIT(MemoryError); - PRE_INIT(BufferError); - PRE_INIT(Warning); - PRE_INIT(UserWarning); - PRE_INIT(DeprecationWarning); - PRE_INIT(PendingDeprecationWarning); - PRE_INIT(SyntaxWarning); - PRE_INIT(RuntimeWarning); - PRE_INIT(FutureWarning); - PRE_INIT(ImportWarning); - PRE_INIT(UnicodeWarning); - PRE_INIT(BytesWarning); - PRE_INIT(ResourceWarning); - +PyStatus +_PyExc_Init(void) +{ +#define PRE_INIT(TYPE) \ + if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \ + if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \ + return _PyStatus_ERR("exceptions bootstrapping error."); \ + } \ + Py_INCREF(PyExc_ ## TYPE); \ + } + +#define ADD_ERRNO(TYPE, CODE) \ + do { \ + PyObject *_code = PyLong_FromLong(CODE); \ + assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \ + if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) { \ + Py_XDECREF(_code); \ + return _PyStatus_ERR("errmap insertion problem."); \ + } \ + Py_DECREF(_code); \ + } while (0) + + PRE_INIT(BaseException); + PRE_INIT(Exception); + PRE_INIT(TypeError); + PRE_INIT(StopAsyncIteration); + PRE_INIT(StopIteration); + PRE_INIT(GeneratorExit); + PRE_INIT(SystemExit); + PRE_INIT(KeyboardInterrupt); + PRE_INIT(ImportError); + PRE_INIT(ModuleNotFoundError); + PRE_INIT(OSError); + PRE_INIT(EOFError); + PRE_INIT(RuntimeError); + PRE_INIT(RecursionError); + PRE_INIT(NotImplementedError); + PRE_INIT(NameError); + PRE_INIT(UnboundLocalError); + PRE_INIT(AttributeError); + PRE_INIT(SyntaxError); + PRE_INIT(IndentationError); + PRE_INIT(TabError); + PRE_INIT(LookupError); + PRE_INIT(IndexError); + PRE_INIT(KeyError); + PRE_INIT(ValueError); + PRE_INIT(UnicodeError); + PRE_INIT(UnicodeEncodeError); + PRE_INIT(UnicodeDecodeError); + PRE_INIT(UnicodeTranslateError); + PRE_INIT(AssertionError); + PRE_INIT(ArithmeticError); + PRE_INIT(FloatingPointError); + PRE_INIT(OverflowError); + PRE_INIT(ZeroDivisionError); + PRE_INIT(SystemError); + PRE_INIT(ReferenceError); + PRE_INIT(MemoryError); + PRE_INIT(BufferError); + PRE_INIT(Warning); + PRE_INIT(UserWarning); + PRE_INIT(DeprecationWarning); + PRE_INIT(PendingDeprecationWarning); + PRE_INIT(SyntaxWarning); + PRE_INIT(RuntimeWarning); + PRE_INIT(FutureWarning); + PRE_INIT(ImportWarning); + PRE_INIT(UnicodeWarning); + PRE_INIT(BytesWarning); + PRE_INIT(ResourceWarning); + /* OSError subclasses */ - PRE_INIT(ConnectionError); - - PRE_INIT(BlockingIOError); - PRE_INIT(BrokenPipeError); - PRE_INIT(ChildProcessError); - PRE_INIT(ConnectionAbortedError); - PRE_INIT(ConnectionRefusedError); - PRE_INIT(ConnectionResetError); - PRE_INIT(FileExistsError); - PRE_INIT(FileNotFoundError); - PRE_INIT(IsADirectoryError); - PRE_INIT(NotADirectoryError); - PRE_INIT(InterruptedError); - PRE_INIT(PermissionError); - PRE_INIT(ProcessLookupError); - PRE_INIT(TimeoutError); - - if (preallocate_memerrors() < 0) { - return _PyStatus_ERR("Could not preallocate MemoryError object"); - } - - /* Add exceptions to errnomap */ + PRE_INIT(ConnectionError); + + PRE_INIT(BlockingIOError); + PRE_INIT(BrokenPipeError); + PRE_INIT(ChildProcessError); + PRE_INIT(ConnectionAbortedError); + PRE_INIT(ConnectionRefusedError); + PRE_INIT(ConnectionResetError); + PRE_INIT(FileExistsError); + PRE_INIT(FileNotFoundError); + PRE_INIT(IsADirectoryError); + PRE_INIT(NotADirectoryError); + PRE_INIT(InterruptedError); + PRE_INIT(PermissionError); + PRE_INIT(ProcessLookupError); + PRE_INIT(TimeoutError); + + if (preallocate_memerrors() < 0) { + return _PyStatus_ERR("Could not preallocate MemoryError object"); + } + + /* Add exceptions to errnomap */ if (!errnomap) { errnomap = PyDict_New(); - if (!errnomap) { - return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses"); - } + if (!errnomap) { + return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses"); + } } - ADD_ERRNO(BlockingIOError, EAGAIN); - ADD_ERRNO(BlockingIOError, EALREADY); - ADD_ERRNO(BlockingIOError, EINPROGRESS); - ADD_ERRNO(BlockingIOError, EWOULDBLOCK); - ADD_ERRNO(BrokenPipeError, EPIPE); + ADD_ERRNO(BlockingIOError, EAGAIN); + ADD_ERRNO(BlockingIOError, EALREADY); + ADD_ERRNO(BlockingIOError, EINPROGRESS); + ADD_ERRNO(BlockingIOError, EWOULDBLOCK); + ADD_ERRNO(BrokenPipeError, EPIPE); #ifdef ESHUTDOWN - ADD_ERRNO(BrokenPipeError, ESHUTDOWN); + ADD_ERRNO(BrokenPipeError, ESHUTDOWN); +#endif + ADD_ERRNO(ChildProcessError, ECHILD); + ADD_ERRNO(ConnectionAbortedError, ECONNABORTED); + ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED); + ADD_ERRNO(ConnectionResetError, ECONNRESET); + ADD_ERRNO(FileExistsError, EEXIST); + ADD_ERRNO(FileNotFoundError, ENOENT); + ADD_ERRNO(IsADirectoryError, EISDIR); + ADD_ERRNO(NotADirectoryError, ENOTDIR); + ADD_ERRNO(InterruptedError, EINTR); + ADD_ERRNO(PermissionError, EACCES); + ADD_ERRNO(PermissionError, EPERM); + ADD_ERRNO(ProcessLookupError, ESRCH); + ADD_ERRNO(TimeoutError, ETIMEDOUT); + + return _PyStatus_OK(); + +#undef PRE_INIT +#undef ADD_ERRNO +} + + +/* Add exception types to the builtins module */ +PyStatus +_PyBuiltins_AddExceptions(PyObject *bltinmod) +{ +#define POST_INIT(TYPE) \ + if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \ + return _PyStatus_ERR("Module dictionary insertion problem."); \ + } + +#define INIT_ALIAS(NAME, TYPE) \ + do { \ + Py_INCREF(PyExc_ ## TYPE); \ + Py_XDECREF(PyExc_ ## NAME); \ + PyExc_ ## NAME = PyExc_ ## TYPE; \ + if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \ + return _PyStatus_ERR("Module dictionary insertion problem."); \ + } \ + } while (0) + + PyObject *bdict; + + bdict = PyModule_GetDict(bltinmod); + if (bdict == NULL) { + return _PyStatus_ERR("exceptions bootstrapping error."); + } + + POST_INIT(BaseException); + POST_INIT(Exception); + POST_INIT(TypeError); + POST_INIT(StopAsyncIteration); + POST_INIT(StopIteration); + POST_INIT(GeneratorExit); + POST_INIT(SystemExit); + POST_INIT(KeyboardInterrupt); + POST_INIT(ImportError); + POST_INIT(ModuleNotFoundError); + POST_INIT(OSError); + INIT_ALIAS(EnvironmentError, OSError); + INIT_ALIAS(IOError, OSError); +#ifdef MS_WINDOWS + INIT_ALIAS(WindowsError, OSError); #endif - ADD_ERRNO(ChildProcessError, ECHILD); - ADD_ERRNO(ConnectionAbortedError, ECONNABORTED); - ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED); - ADD_ERRNO(ConnectionResetError, ECONNRESET); - ADD_ERRNO(FileExistsError, EEXIST); - ADD_ERRNO(FileNotFoundError, ENOENT); - ADD_ERRNO(IsADirectoryError, EISDIR); - ADD_ERRNO(NotADirectoryError, ENOTDIR); - ADD_ERRNO(InterruptedError, EINTR); - ADD_ERRNO(PermissionError, EACCES); - ADD_ERRNO(PermissionError, EPERM); - ADD_ERRNO(ProcessLookupError, ESRCH); - ADD_ERRNO(TimeoutError, ETIMEDOUT); - - return _PyStatus_OK(); - -#undef PRE_INIT -#undef ADD_ERRNO -} - - -/* Add exception types to the builtins module */ -PyStatus -_PyBuiltins_AddExceptions(PyObject *bltinmod) -{ -#define POST_INIT(TYPE) \ - if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \ - return _PyStatus_ERR("Module dictionary insertion problem."); \ - } - -#define INIT_ALIAS(NAME, TYPE) \ - do { \ - Py_INCREF(PyExc_ ## TYPE); \ - Py_XDECREF(PyExc_ ## NAME); \ - PyExc_ ## NAME = PyExc_ ## TYPE; \ - if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \ - return _PyStatus_ERR("Module dictionary insertion problem."); \ - } \ - } while (0) - - PyObject *bdict; - - bdict = PyModule_GetDict(bltinmod); - if (bdict == NULL) { - return _PyStatus_ERR("exceptions bootstrapping error."); - } - - POST_INIT(BaseException); - POST_INIT(Exception); - POST_INIT(TypeError); - POST_INIT(StopAsyncIteration); - POST_INIT(StopIteration); - POST_INIT(GeneratorExit); - POST_INIT(SystemExit); - POST_INIT(KeyboardInterrupt); - POST_INIT(ImportError); - POST_INIT(ModuleNotFoundError); - POST_INIT(OSError); - INIT_ALIAS(EnvironmentError, OSError); - INIT_ALIAS(IOError, OSError); -#ifdef MS_WINDOWS - INIT_ALIAS(WindowsError, OSError); -#endif - POST_INIT(EOFError); - POST_INIT(RuntimeError); - POST_INIT(RecursionError); - POST_INIT(NotImplementedError); - POST_INIT(NameError); - POST_INIT(UnboundLocalError); - POST_INIT(AttributeError); - POST_INIT(SyntaxError); - POST_INIT(IndentationError); - POST_INIT(TabError); - POST_INIT(LookupError); - POST_INIT(IndexError); - POST_INIT(KeyError); - POST_INIT(ValueError); - POST_INIT(UnicodeError); - POST_INIT(UnicodeEncodeError); - POST_INIT(UnicodeDecodeError); - POST_INIT(UnicodeTranslateError); - POST_INIT(AssertionError); - POST_INIT(ArithmeticError); - POST_INIT(FloatingPointError); - POST_INIT(OverflowError); - POST_INIT(ZeroDivisionError); - POST_INIT(SystemError); - POST_INIT(ReferenceError); - POST_INIT(MemoryError); - POST_INIT(BufferError); - POST_INIT(Warning); - POST_INIT(UserWarning); - POST_INIT(DeprecationWarning); - POST_INIT(PendingDeprecationWarning); - POST_INIT(SyntaxWarning); - POST_INIT(RuntimeWarning); - POST_INIT(FutureWarning); - POST_INIT(ImportWarning); - POST_INIT(UnicodeWarning); - POST_INIT(BytesWarning); - POST_INIT(ResourceWarning); - - /* OSError subclasses */ - POST_INIT(ConnectionError); - - POST_INIT(BlockingIOError); - POST_INIT(BrokenPipeError); - POST_INIT(ChildProcessError); - POST_INIT(ConnectionAbortedError); - POST_INIT(ConnectionRefusedError); - POST_INIT(ConnectionResetError); - POST_INIT(FileExistsError); - POST_INIT(FileNotFoundError); - POST_INIT(IsADirectoryError); - POST_INIT(NotADirectoryError); - POST_INIT(InterruptedError); - POST_INIT(PermissionError); - POST_INIT(ProcessLookupError); - POST_INIT(TimeoutError); - - return _PyStatus_OK(); - -#undef POST_INIT -#undef INIT_ALIAS -} - + POST_INIT(EOFError); + POST_INIT(RuntimeError); + POST_INIT(RecursionError); + POST_INIT(NotImplementedError); + POST_INIT(NameError); + POST_INIT(UnboundLocalError); + POST_INIT(AttributeError); + POST_INIT(SyntaxError); + POST_INIT(IndentationError); + POST_INIT(TabError); + POST_INIT(LookupError); + POST_INIT(IndexError); + POST_INIT(KeyError); + POST_INIT(ValueError); + POST_INIT(UnicodeError); + POST_INIT(UnicodeEncodeError); + POST_INIT(UnicodeDecodeError); + POST_INIT(UnicodeTranslateError); + POST_INIT(AssertionError); + POST_INIT(ArithmeticError); + POST_INIT(FloatingPointError); + POST_INIT(OverflowError); + POST_INIT(ZeroDivisionError); + POST_INIT(SystemError); + POST_INIT(ReferenceError); + POST_INIT(MemoryError); + POST_INIT(BufferError); + POST_INIT(Warning); + POST_INIT(UserWarning); + POST_INIT(DeprecationWarning); + POST_INIT(PendingDeprecationWarning); + POST_INIT(SyntaxWarning); + POST_INIT(RuntimeWarning); + POST_INIT(FutureWarning); + POST_INIT(ImportWarning); + POST_INIT(UnicodeWarning); + POST_INIT(BytesWarning); + POST_INIT(ResourceWarning); + + /* OSError subclasses */ + POST_INIT(ConnectionError); + + POST_INIT(BlockingIOError); + POST_INIT(BrokenPipeError); + POST_INIT(ChildProcessError); + POST_INIT(ConnectionAbortedError); + POST_INIT(ConnectionRefusedError); + POST_INIT(ConnectionResetError); + POST_INIT(FileExistsError); + POST_INIT(FileNotFoundError); + POST_INIT(IsADirectoryError); + POST_INIT(NotADirectoryError); + POST_INIT(InterruptedError); + POST_INIT(PermissionError); + POST_INIT(ProcessLookupError); + POST_INIT(TimeoutError); + + return _PyStatus_OK(); + +#undef POST_INIT +#undef INIT_ALIAS +} + void _PyExc_Fini(void) { @@ -2978,9 +2978,9 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start) */ static PyObject *print_prefix = NULL; static PyObject *exec_prefix = NULL; - Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match; + Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match; int kind = PyUnicode_KIND(self->text); - const void *data = PyUnicode_DATA(self->text); + const void *data = PyUnicode_DATA(self->text); /* Ignore leading whitespace */ while (start < text_len) { @@ -3001,12 +3001,12 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start) return -1; } } - match = PyUnicode_Tailmatch(self->text, print_prefix, - start, text_len, -1); - if (match == -1) { - return -1; - } - if (match) { + match = PyUnicode_Tailmatch(self->text, print_prefix, + start, text_len, -1); + if (match == -1) { + return -1; + } + if (match) { return _set_legacy_print_statement_msg(self, start); } @@ -3017,17 +3017,17 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start) return -1; } } - match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1); - if (match == -1) { - return -1; - } - if (match) { - PyObject *msg = PyUnicode_FromString("Missing parentheses in call " - "to 'exec'"); - if (msg == NULL) { - return -1; - } - Py_XSETREF(self->msg, msg); + match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1); + if (match == -1) { + return -1; + } + if (match) { + PyObject *msg = PyUnicode_FromString("Missing parentheses in call " + "to 'exec'"); + if (msg == NULL) { + return -1; + } + Py_XSETREF(self->msg, msg); return 1; } /* Fall back to the default error message */ diff --git a/contrib/tools/python3/src/Objects/fileobject.c b/contrib/tools/python3/src/Objects/fileobject.c index f2053a9986..1c6ecaf82c 100644 --- a/contrib/tools/python3/src/Objects/fileobject.c +++ b/contrib/tools/python3/src/Objects/fileobject.c @@ -2,7 +2,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_runtime.h" // _PyRuntime +#include "pycore_runtime.h" // _PyRuntime #if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER) /* clang MemorySanitizer doesn't yet understand getc_unlocked. */ @@ -25,8 +25,8 @@ extern "C" { #endif -_Py_IDENTIFIER(open); - +_Py_IDENTIFIER(open); + /* External C interface */ PyObject * @@ -35,13 +35,13 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c { PyObject *io, *stream; - /* import _io in case we are being used to open io.py */ - io = PyImport_ImportModule("_io"); + /* import _io in case we are being used to open io.py */ + io = PyImport_ImportModule("_io"); if (io == NULL) return NULL; - stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode, + stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode, buffering, encoding, errors, - newline, closefd ? Py_True : Py_False); + newline, closefd ? Py_True : Py_False); Py_DECREF(io); if (stream == NULL) return NULL; @@ -62,7 +62,7 @@ PyFile_GetLine(PyObject *f, int n) } if (n <= 0) { - result = _PyObject_CallMethodIdNoArgs(f, &PyId_readline); + result = _PyObject_CallMethodIdNoArgs(f, &PyId_readline); } else { result = _PyObject_CallMethodId(f, &PyId_readline, "i", n); @@ -76,7 +76,7 @@ PyFile_GetLine(PyObject *f, int n) } if (n < 0 && result != NULL && PyBytes_Check(result)) { - const char *s = PyBytes_AS_STRING(result); + const char *s = PyBytes_AS_STRING(result); Py_ssize_t len = PyBytes_GET_SIZE(result); if (len == 0) { Py_DECREF(result); @@ -85,7 +85,7 @@ PyFile_GetLine(PyObject *f, int n) "EOF when reading a line"); } else if (s[len-1] == '\n') { - if (Py_REFCNT(result) == 1) + if (Py_REFCNT(result) == 1) _PyBytes_Resize(&result, len-1); else { PyObject *v; @@ -137,7 +137,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) Py_DECREF(writer); return -1; } - result = PyObject_CallOneArg(writer, value); + result = PyObject_CallOneArg(writer, value); Py_DECREF(value); Py_DECREF(writer); if (result == NULL) @@ -186,10 +186,10 @@ PyObject_AsFileDescriptor(PyObject *o) if (PyLong_Check(o)) { fd = _PyLong_AsInt(o); } - else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) { - return -1; - } - else if (meth != NULL) { + else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) { + return -1; + } + else if (meth != NULL) { PyObject *fno = _PyObject_CallNoArg(meth); Py_DECREF(meth); if (fno == NULL) @@ -364,9 +364,9 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) Py_ssize_t n; int err; - /* The function can clear the current exception */ - assert(!PyErr_Occurred()); - + /* The function can clear the current exception */ + assert(!PyErr_Occurred()); + if (self->fd < 0) { /* fd might be invalid on Windows * I can't raise an exception here. It may lead to an @@ -375,11 +375,11 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) Py_RETURN_NONE; } - if (!PyArg_ParseTuple(args, "U", &unicode)) { + if (!PyArg_ParseTuple(args, "U", &unicode)) { return NULL; - } + } - /* Encode Unicode to UTF-8/surrogateescape */ + /* Encode Unicode to UTF-8/surrogateescape */ str = PyUnicode_AsUTF8AndSize(unicode, &n); if (str == NULL) { PyErr_Clear(); @@ -408,7 +408,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) } static PyObject * -stdprinter_fileno(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) +stdprinter_fileno(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong((long) self->fd); } @@ -421,13 +421,13 @@ stdprinter_repr(PyStdPrinter_Object *self) } static PyObject * -stdprinter_noop(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) +stdprinter_noop(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { Py_RETURN_NONE; } static PyObject * -stdprinter_isatty(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) +stdprinter_isatty(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { long res; if (self->fd < 0) { @@ -482,10 +482,10 @@ PyTypeObject PyStdPrinter_Type = { 0, /* tp_itemsize */ /* methods */ 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)stdprinter_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -519,71 +519,71 @@ PyTypeObject PyStdPrinter_Type = { }; -/* ************************** open_code hook *************************** - * The open_code hook allows embedders to override the method used to - * open files that are going to be used by the runtime to execute code - */ - -int -PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData) { - if (Py_IsInitialized() && - PySys_Audit("setopencodehook", NULL) < 0) { - return -1; - } - - if (_PyRuntime.open_code_hook) { - if (Py_IsInitialized()) { - PyErr_SetString(PyExc_SystemError, - "failed to change existing open_code hook"); - } - return -1; - } - - _PyRuntime.open_code_hook = hook; - _PyRuntime.open_code_userdata = userData; - return 0; -} - -PyObject * -PyFile_OpenCodeObject(PyObject *path) -{ - PyObject *iomod, *f = NULL; - - if (!PyUnicode_Check(path)) { - PyErr_Format(PyExc_TypeError, "'path' must be 'str', not '%.200s'", - Py_TYPE(path)->tp_name); - return NULL; - } - - Py_OpenCodeHookFunction hook = _PyRuntime.open_code_hook; - if (hook) { - f = hook(path, _PyRuntime.open_code_userdata); - } else { - iomod = PyImport_ImportModule("_io"); - if (iomod) { - f = _PyObject_CallMethodId(iomod, &PyId_open, "Os", - path, "rb"); - Py_DECREF(iomod); - } - } - - return f; -} - -PyObject * -PyFile_OpenCode(const char *utf8path) -{ - PyObject *pathobj = PyUnicode_FromString(utf8path); - PyObject *f; - if (!pathobj) { - return NULL; - } - f = PyFile_OpenCodeObject(pathobj); - Py_DECREF(pathobj); - return f; -} - - +/* ************************** open_code hook *************************** + * The open_code hook allows embedders to override the method used to + * open files that are going to be used by the runtime to execute code + */ + +int +PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData) { + if (Py_IsInitialized() && + PySys_Audit("setopencodehook", NULL) < 0) { + return -1; + } + + if (_PyRuntime.open_code_hook) { + if (Py_IsInitialized()) { + PyErr_SetString(PyExc_SystemError, + "failed to change existing open_code hook"); + } + return -1; + } + + _PyRuntime.open_code_hook = hook; + _PyRuntime.open_code_userdata = userData; + return 0; +} + +PyObject * +PyFile_OpenCodeObject(PyObject *path) +{ + PyObject *iomod, *f = NULL; + + if (!PyUnicode_Check(path)) { + PyErr_Format(PyExc_TypeError, "'path' must be 'str', not '%.200s'", + Py_TYPE(path)->tp_name); + return NULL; + } + + Py_OpenCodeHookFunction hook = _PyRuntime.open_code_hook; + if (hook) { + f = hook(path, _PyRuntime.open_code_userdata); + } else { + iomod = PyImport_ImportModule("_io"); + if (iomod) { + f = _PyObject_CallMethodId(iomod, &PyId_open, "Os", + path, "rb"); + Py_DECREF(iomod); + } + } + + return f; +} + +PyObject * +PyFile_OpenCode(const char *utf8path) +{ + PyObject *pathobj = PyUnicode_FromString(utf8path); + PyObject *f; + if (!pathobj) { + return NULL; + } + f = PyFile_OpenCodeObject(pathobj); + Py_DECREF(pathobj); + return f; +} + + #ifdef __cplusplus } #endif diff --git a/contrib/tools/python3/src/Objects/floatobject.c b/contrib/tools/python3/src/Objects/floatobject.c index a13501ad05..8538a051b1 100644 --- a/contrib/tools/python3/src/Objects/floatobject.c +++ b/contrib/tools/python3/src/Objects/floatobject.c @@ -4,7 +4,7 @@ for any kind of float exception without losing portability. */ #include "Python.h" -#include "pycore_dtoa.h" +#include "pycore_dtoa.h" #include <ctype.h> #include <float.h> @@ -44,7 +44,7 @@ static PyTypeObject FloatInfoType; PyDoc_STRVAR(floatinfo__doc__, "sys.float_info\n\ \n\ -A named tuple holding information about the float type. It contains low level\n\ +A named tuple holding information about the float type. It contains low level\n\ information about the precision and internal representation. Please study\n\ your system's :file:`float.h` for more information."); @@ -222,7 +222,7 @@ float_dealloc(PyFloatObject *op) return; } numfree++; - Py_SET_TYPE(op, (PyTypeObject *)free_list); + Py_SET_TYPE(op, (PyTypeObject *)free_list); free_list = op; } else @@ -247,17 +247,17 @@ PyFloat_AsDouble(PyObject *op) nb = Py_TYPE(op)->tp_as_number; if (nb == NULL || nb->nb_float == NULL) { - if (nb && nb->nb_index) { - PyObject *res = PyNumber_Index(op); - if (!res) { - return -1; - } - double val = PyLong_AsDouble(res); - Py_DECREF(res); - return val; - } + if (nb && nb->nb_index) { + PyObject *res = PyNumber_Index(op); + if (!res) { + return -1; + } + double val = PyLong_AsDouble(res); + Py_DECREF(res); + return val; + } PyErr_Format(PyExc_TypeError, "must be real number, not %.50s", - Py_TYPE(op)->tp_name); + Py_TYPE(op)->tp_name); return -1; } @@ -269,7 +269,7 @@ PyFloat_AsDouble(PyObject *op) if (!PyFloat_Check(res)) { PyErr_Format(PyExc_TypeError, "%.50s.__float__ returned non-float (type %.50s)", - Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name); + Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name); Py_DECREF(res); return -1; } @@ -277,7 +277,7 @@ PyFloat_AsDouble(PyObject *op) "%.50s.__float__ returned non-float (type %.50s). " "The ability to return an instance of a strict subclass of float " "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) { + Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) { Py_DECREF(res); return -1; } @@ -473,13 +473,13 @@ float_richcompare(PyObject *v, PyObject *w, int op) */ PyObject *temp; - temp = _PyLong_Lshift(ww, 1); + temp = _PyLong_Lshift(ww, 1); if (temp == NULL) goto Error; Py_DECREF(ww); ww = temp; - temp = _PyLong_Lshift(vv, 1); + temp = _PyLong_Lshift(vv, 1); if (temp == NULL) goto Error; Py_DECREF(vv); @@ -612,22 +612,22 @@ float_rem(PyObject *v, PyObject *w) return PyFloat_FromDouble(mod); } -static void -_float_div_mod(double vx, double wx, double *floordiv, double *mod) +static void +_float_div_mod(double vx, double wx, double *floordiv, double *mod) { - double div; - *mod = fmod(vx, wx); + double div; + *mod = fmod(vx, wx); /* fmod is typically exact, so vx-mod is *mathematically* an exact multiple of wx. But this is fp arithmetic, and fp vx - mod is an approximation; the result is that div may not be an exact integral value after the division, although it will always be very close to one. */ - div = (vx - *mod) / wx; - if (*mod) { + div = (vx - *mod) / wx; + if (*mod) { /* ensure the remainder has the same sign as the denominator */ - if ((wx < 0) != (*mod < 0)) { - *mod += wx; + if ((wx < 0) != (*mod < 0)) { + *mod += wx; div -= 1.0; } } @@ -635,49 +635,49 @@ _float_div_mod(double vx, double wx, double *floordiv, double *mod) /* the remainder is zero, and in the presence of signed zeroes fmod returns different results across platforms; ensure it has the same sign as the denominator. */ - *mod = copysign(0.0, wx); + *mod = copysign(0.0, wx); } /* snap quotient to nearest integral value */ if (div) { - *floordiv = floor(div); - if (div - *floordiv > 0.5) { - *floordiv += 1.0; - } + *floordiv = floor(div); + if (div - *floordiv > 0.5) { + *floordiv += 1.0; + } } else { /* div is zero - get the same sign as the true quotient */ - *floordiv = copysign(0.0, vx / wx); /* zero w/ sign of vx/wx */ - } -} - -static PyObject * -float_divmod(PyObject *v, PyObject *w) -{ - double vx, wx; - double mod, floordiv; - CONVERT_TO_DOUBLE(v, vx); - CONVERT_TO_DOUBLE(w, wx); - if (wx == 0.0) { - PyErr_SetString(PyExc_ZeroDivisionError, "float divmod()"); - return NULL; - } - _float_div_mod(vx, wx, &floordiv, &mod); + *floordiv = copysign(0.0, vx / wx); /* zero w/ sign of vx/wx */ + } +} + +static PyObject * +float_divmod(PyObject *v, PyObject *w) +{ + double vx, wx; + double mod, floordiv; + CONVERT_TO_DOUBLE(v, vx); + CONVERT_TO_DOUBLE(w, wx); + if (wx == 0.0) { + PyErr_SetString(PyExc_ZeroDivisionError, "float divmod()"); + return NULL; + } + _float_div_mod(vx, wx, &floordiv, &mod); return Py_BuildValue("(dd)", floordiv, mod); } static PyObject * float_floor_div(PyObject *v, PyObject *w) { - double vx, wx; - double mod, floordiv; - CONVERT_TO_DOUBLE(v, vx); - CONVERT_TO_DOUBLE(w, wx); - if (wx == 0.0) { - PyErr_SetString(PyExc_ZeroDivisionError, "float floor division by zero"); - return NULL; - } - _float_div_mod(vx, wx, &floordiv, &mod); - return PyFloat_FromDouble(floordiv); + double vx, wx; + double mod, floordiv; + CONVERT_TO_DOUBLE(v, vx); + CONVERT_TO_DOUBLE(w, wx); + if (wx == 0.0) { + PyErr_SetString(PyExc_ZeroDivisionError, "float floor division by zero"); + return NULL; + } + _float_div_mod(vx, wx, &floordiv, &mod); + return PyFloat_FromDouble(floordiv); } /* determine whether x is an odd integer or not; assumes that @@ -862,37 +862,37 @@ static PyObject * float___trunc___impl(PyObject *self) /*[clinic end generated code: output=dd3e289dd4c6b538 input=591b9ba0d650fdff]*/ { - return PyLong_FromDouble(PyFloat_AS_DOUBLE(self)); -} - -/*[clinic input] -float.__floor__ - -Return the floor as an Integral. -[clinic start generated code]*/ - -static PyObject * -float___floor___impl(PyObject *self) -/*[clinic end generated code: output=e0551dbaea8c01d1 input=77bb13eb12e268df]*/ -{ - double x = PyFloat_AS_DOUBLE(self); - return PyLong_FromDouble(floor(x)); + return PyLong_FromDouble(PyFloat_AS_DOUBLE(self)); +} + +/*[clinic input] +float.__floor__ + +Return the floor as an Integral. +[clinic start generated code]*/ + +static PyObject * +float___floor___impl(PyObject *self) +/*[clinic end generated code: output=e0551dbaea8c01d1 input=77bb13eb12e268df]*/ +{ + double x = PyFloat_AS_DOUBLE(self); + return PyLong_FromDouble(floor(x)); +} + +/*[clinic input] +float.__ceil__ + +Return the ceiling as an Integral. +[clinic start generated code]*/ + +static PyObject * +float___ceil___impl(PyObject *self) +/*[clinic end generated code: output=a2fd8858f73736f9 input=79e41ae94aa0a516]*/ +{ + double x = PyFloat_AS_DOUBLE(self); + return PyLong_FromDouble(ceil(x)); } -/*[clinic input] -float.__ceil__ - -Return the ceiling as an Integral. -[clinic start generated code]*/ - -static PyObject * -float___ceil___impl(PyObject *self) -/*[clinic end generated code: output=a2fd8858f73736f9 input=79e41ae94aa0a516]*/ -{ - double x = PyFloat_AS_DOUBLE(self); - return PyLong_FromDouble(ceil(x)); -} - /* double_round: rounds a finite double to the closest multiple of 10**-ndigits; here ndigits is within reasonable bounds (typically, -308 <= ndigits <= 323). Returns a Python float, or sets a Python error and @@ -1012,7 +1012,7 @@ double_round(double x, int ndigits) { /*[clinic input] float.__round__ - ndigits as o_ndigits: object = None + ndigits as o_ndigits: object = None / Return the Integral closest to x, rounding half toward even. @@ -1022,13 +1022,13 @@ When an argument is passed, work like built-in round(x, ndigits). static PyObject * float___round___impl(PyObject *self, PyObject *o_ndigits) -/*[clinic end generated code: output=374c36aaa0f13980 input=fc0fe25924fbc9ed]*/ +/*[clinic end generated code: output=374c36aaa0f13980 input=fc0fe25924fbc9ed]*/ { double x, rounded; Py_ssize_t ndigits; x = PyFloat_AsDouble(self); - if (o_ndigits == Py_None) { + if (o_ndigits == Py_None) { /* single-argument round or with None ndigits: * round to nearest integer */ rounded = round(x); @@ -1443,8 +1443,8 @@ float_fromhex(PyTypeObject *type, PyObject *string) bits lsb, lsb-2, lsb-3, lsb-4, ... is 1. */ if ((digit & half_eps) != 0) { round_up = 0; - if ((digit & (3*half_eps-1)) != 0 || (half_eps == 8 && - key_digit+1 < ndigits && (HEX_DIGIT(key_digit+1) & 1) != 0)) + if ((digit & (3*half_eps-1)) != 0 || (half_eps == 8 && + key_digit+1 < ndigits && (HEX_DIGIT(key_digit+1) & 1) != 0)) round_up = 1; else for (i = key_digit-1; i >= 0; i--) @@ -1471,7 +1471,7 @@ float_fromhex(PyTypeObject *type, PyObject *string) goto parse_error; result = PyFloat_FromDouble(negate ? -x : x); if (type != &PyFloat_Type && result != NULL) { - Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); + Py_SETREF(result, PyObject_CallOneArg((PyObject *)type, result)); } return result; @@ -1694,8 +1694,8 @@ float___getformat___impl(PyTypeObject *type, const char *typestr) case ieee_big_endian_format: return PyUnicode_FromString("IEEE, big-endian"); default: - PyErr_SetString(PyExc_RuntimeError, - "insane float_format or double_format"); + PyErr_SetString(PyExc_RuntimeError, + "insane float_format or double_format"); return NULL; } } @@ -1816,8 +1816,8 @@ float___format___impl(PyObject *self, PyObject *format_spec) static PyMethodDef float_methods[] = { FLOAT_CONJUGATE_METHODDEF FLOAT___TRUNC___METHODDEF - FLOAT___FLOOR___METHODDEF - FLOAT___CEIL___METHODDEF + FLOAT___FLOOR___METHODDEF + FLOAT___CEIL___METHODDEF FLOAT___ROUND___METHODDEF FLOAT_AS_INTEGER_RATIO_METHODDEF FLOAT_FROMHEX_METHODDEF @@ -1885,17 +1885,17 @@ PyTypeObject PyFloat_Type = { sizeof(PyFloatObject), 0, (destructor)float_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)float_repr, /* tp_repr */ &float_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)float_hash, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ @@ -1971,18 +1971,18 @@ _PyFloat_Init(void) /* Init float info */ if (FloatInfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) { + if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) { return 0; - } + } } return 1; } -void -_PyFloat_ClearFreeList(void) +void +_PyFloat_ClearFreeList(void) { PyFloatObject *f = free_list, *next; - for (; f; f = next) { + for (; f; f = next) { next = (PyFloatObject*) Py_TYPE(f); PyObject_FREE(f); } @@ -1991,9 +1991,9 @@ _PyFloat_ClearFreeList(void) } void -_PyFloat_Fini(void) +_PyFloat_Fini(void) { - _PyFloat_ClearFreeList(); + _PyFloat_ClearFreeList(); } /* Print summary info about the state of the optimized allocator */ @@ -2291,7 +2291,7 @@ _PyFloat_Pack8(double x, unsigned char *p, int le) flo = 0; ++fhi; if (fhi >> 28) { - /* And it also propagated out of the next 28 bits. */ + /* And it also propagated out of the next 28 bits. */ fhi = 0; ++e; if (e >= 2047) diff --git a/contrib/tools/python3/src/Objects/frameobject.c b/contrib/tools/python3/src/Objects/frameobject.c index acd0e52f0d..4ae17bcfc2 100644 --- a/contrib/tools/python3/src/Objects/frameobject.c +++ b/contrib/tools/python3/src/Objects/frameobject.c @@ -1,19 +1,19 @@ /* Frame object implementation */ #include "Python.h" -#include "pycore_object.h" -#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() +#include "pycore_object.h" +#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() #include "code.h" #include "frameobject.h" #include "opcode.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef #define OFF(x) offsetof(PyFrameObject, x) static PyMemberDef frame_memberlist[] = { {"f_back", T_OBJECT, OFF(f_back), READONLY}, - {"f_code", T_OBJECT, OFF(f_code), READONLY|READ_RESTRICTED}, + {"f_code", T_OBJECT, OFF(f_code), READONLY|READ_RESTRICTED}, {"f_builtins", T_OBJECT, OFF(f_builtins), READONLY}, {"f_globals", T_OBJECT, OFF(f_globals), READONLY}, {"f_lasti", T_INT, OFF(f_lasti), READONLY}, @@ -34,13 +34,13 @@ frame_getlocals(PyFrameObject *f, void *closure) int PyFrame_GetLineNumber(PyFrameObject *f) { - assert(f != NULL); - if (f->f_trace) { + assert(f != NULL); + if (f->f_trace) { return f->f_lineno; - } - else { + } + else { return PyCode_Addr2Line(f->f_code, f->f_lasti); - } + } } static PyObject * @@ -49,266 +49,266 @@ frame_getlineno(PyFrameObject *f, void *closure) return PyLong_FromLong(PyFrame_GetLineNumber(f)); } - -/* Given the index of the effective opcode, - scan back to construct the oparg with EXTENDED_ARG */ -static unsigned int -get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i) -{ - _Py_CODEUNIT word; - unsigned int oparg = _Py_OPARG(codestr[i]); - if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) { - oparg |= _Py_OPARG(word) << 8; - if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) { - oparg |= _Py_OPARG(word) << 16; - if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) { - oparg |= _Py_OPARG(word) << 24; - } - } - } - return oparg; -} - -typedef enum kind { - With = 1, - Loop = 2, - Try = 3, - Except = 4, -} Kind; - -#define BITS_PER_BLOCK 3 - -static inline int64_t -push_block(int64_t stack, Kind kind) -{ - assert(stack < ((int64_t)1)<<(BITS_PER_BLOCK*CO_MAXBLOCKS)); - return (stack << BITS_PER_BLOCK) | kind; -} - -static inline int64_t -pop_block(int64_t stack) -{ - assert(stack > 0); - return stack >> BITS_PER_BLOCK; -} - -static inline Kind -top_block(int64_t stack) -{ - return stack & ((1<<BITS_PER_BLOCK)-1); -} - -static int64_t * -markblocks(PyCodeObject *code_obj, int len) -{ - const _Py_CODEUNIT *code = - (const _Py_CODEUNIT *)PyBytes_AS_STRING(code_obj->co_code); - int64_t *blocks = PyMem_New(int64_t, len+1); - int i, j, opcode; - - if (blocks == NULL) { - PyErr_NoMemory(); - return NULL; - } - memset(blocks, -1, (len+1)*sizeof(int64_t)); - blocks[0] = 0; - int todo = 1; - while (todo) { - todo = 0; - for (i = 0; i < len; i++) { - int64_t block_stack = blocks[i]; - int64_t except_stack; - if (block_stack == -1) { - continue; - } - opcode = _Py_OPCODE(code[i]); - switch (opcode) { - case JUMP_IF_FALSE_OR_POP: - case JUMP_IF_TRUE_OR_POP: - case POP_JUMP_IF_FALSE: - case POP_JUMP_IF_TRUE: - case JUMP_IF_NOT_EXC_MATCH: - j = get_arg(code, i) / sizeof(_Py_CODEUNIT); - assert(j < len); - if (blocks[j] == -1 && j < i) { - todo = 1; - } - assert(blocks[j] == -1 || blocks[j] == block_stack); - blocks[j] = block_stack; - blocks[i+1] = block_stack; - break; - case JUMP_ABSOLUTE: - j = get_arg(code, i) / sizeof(_Py_CODEUNIT); - assert(j < len); - if (blocks[j] == -1 && j < i) { - todo = 1; - } - assert(blocks[j] == -1 || blocks[j] == block_stack); - blocks[j] = block_stack; - break; - case SETUP_FINALLY: - j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; - assert(j < len); - except_stack = push_block(block_stack, Except); - assert(blocks[j] == -1 || blocks[j] == except_stack); - blocks[j] = except_stack; - block_stack = push_block(block_stack, Try); - blocks[i+1] = block_stack; - break; - case SETUP_WITH: - case SETUP_ASYNC_WITH: - j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; - assert(j < len); - except_stack = push_block(block_stack, Except); - assert(blocks[j] == -1 || blocks[j] == except_stack); - blocks[j] = except_stack; - block_stack = push_block(block_stack, With); - blocks[i+1] = block_stack; - break; - case JUMP_FORWARD: - j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; - assert(j < len); - assert(blocks[j] == -1 || blocks[j] == block_stack); - blocks[j] = block_stack; - break; - case GET_ITER: - case GET_AITER: - block_stack = push_block(block_stack, Loop); - blocks[i+1] = block_stack; - break; - case FOR_ITER: - blocks[i+1] = block_stack; - block_stack = pop_block(block_stack); - j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; - assert(j < len); - assert(blocks[j] == -1 || blocks[j] == block_stack); - blocks[j] = block_stack; - break; - case POP_BLOCK: - case POP_EXCEPT: - block_stack = pop_block(block_stack); - blocks[i+1] = block_stack; - break; - case END_ASYNC_FOR: - block_stack = pop_block(pop_block(block_stack)); - blocks[i+1] = block_stack; - break; - case RETURN_VALUE: - case RAISE_VARARGS: - case RERAISE: - /* End of block */ - break; - default: - blocks[i+1] = block_stack; - - } - } - } - return blocks; -} - -static int -compatible_block_stack(int64_t from_stack, int64_t to_stack) -{ - if (to_stack < 0) { - return 0; - } - while(from_stack > to_stack) { - from_stack = pop_block(from_stack); - } - return from_stack == to_stack; -} - -static const char * -explain_incompatible_block_stack(int64_t to_stack) -{ - Kind target_kind = top_block(to_stack); - switch(target_kind) { - case Except: - return "can't jump into an 'except' block as there's no exception"; - case Try: - return "can't jump into the body of a try statement"; - case With: - return "can't jump into the body of a with statement"; - case Loop: - return "can't jump into the body of a for loop"; - default: - Py_UNREACHABLE(); - } -} - -static int * -marklines(PyCodeObject *code, int len) -{ - int *linestarts = PyMem_New(int, len); - if (linestarts == NULL) { - return NULL; - } - Py_ssize_t size = PyBytes_GET_SIZE(code->co_lnotab) / 2; - unsigned char *p = (unsigned char*)PyBytes_AS_STRING(code->co_lnotab); - int line = code->co_firstlineno; - int addr = 0; - int index = 0; - while (--size >= 0) { - addr += *p++; - if (index*2 < addr) { - linestarts[index++] = line; - } - while (index*2 < addr) { - linestarts[index++] = -1; - if (index >= len) { - break; - } - } - line += (signed char)*p; - p++; - } - if (index < len) { - linestarts[index++] = line; - } - while (index < len) { - linestarts[index++] = -1; - } - assert(index == len); - return linestarts; -} - -static int -first_line_not_before(int *lines, int len, int line) -{ - int result = INT_MAX; - for (int i = 0; i < len; i++) { - if (lines[i] < result && lines[i] >= line) { - result = lines[i]; - } - } - if (result == INT_MAX) { - return -1; - } - return result; -} - -static void -frame_stack_pop(PyFrameObject *f) -{ - PyObject *v = (*--f->f_stacktop); - Py_DECREF(v); -} - -static void -frame_block_unwind(PyFrameObject *f) -{ - assert(f->f_iblock > 0); - f->f_iblock--; - PyTryBlock *b = &f->f_blockstack[f->f_iblock]; - intptr_t delta = (f->f_stacktop - f->f_valuestack) - b->b_level; - while (delta > 0) { - frame_stack_pop(f); - delta--; - } -} - - + +/* Given the index of the effective opcode, + scan back to construct the oparg with EXTENDED_ARG */ +static unsigned int +get_arg(const _Py_CODEUNIT *codestr, Py_ssize_t i) +{ + _Py_CODEUNIT word; + unsigned int oparg = _Py_OPARG(codestr[i]); + if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) { + oparg |= _Py_OPARG(word) << 8; + if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) { + oparg |= _Py_OPARG(word) << 16; + if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) { + oparg |= _Py_OPARG(word) << 24; + } + } + } + return oparg; +} + +typedef enum kind { + With = 1, + Loop = 2, + Try = 3, + Except = 4, +} Kind; + +#define BITS_PER_BLOCK 3 + +static inline int64_t +push_block(int64_t stack, Kind kind) +{ + assert(stack < ((int64_t)1)<<(BITS_PER_BLOCK*CO_MAXBLOCKS)); + return (stack << BITS_PER_BLOCK) | kind; +} + +static inline int64_t +pop_block(int64_t stack) +{ + assert(stack > 0); + return stack >> BITS_PER_BLOCK; +} + +static inline Kind +top_block(int64_t stack) +{ + return stack & ((1<<BITS_PER_BLOCK)-1); +} + +static int64_t * +markblocks(PyCodeObject *code_obj, int len) +{ + const _Py_CODEUNIT *code = + (const _Py_CODEUNIT *)PyBytes_AS_STRING(code_obj->co_code); + int64_t *blocks = PyMem_New(int64_t, len+1); + int i, j, opcode; + + if (blocks == NULL) { + PyErr_NoMemory(); + return NULL; + } + memset(blocks, -1, (len+1)*sizeof(int64_t)); + blocks[0] = 0; + int todo = 1; + while (todo) { + todo = 0; + for (i = 0; i < len; i++) { + int64_t block_stack = blocks[i]; + int64_t except_stack; + if (block_stack == -1) { + continue; + } + opcode = _Py_OPCODE(code[i]); + switch (opcode) { + case JUMP_IF_FALSE_OR_POP: + case JUMP_IF_TRUE_OR_POP: + case POP_JUMP_IF_FALSE: + case POP_JUMP_IF_TRUE: + case JUMP_IF_NOT_EXC_MATCH: + j = get_arg(code, i) / sizeof(_Py_CODEUNIT); + assert(j < len); + if (blocks[j] == -1 && j < i) { + todo = 1; + } + assert(blocks[j] == -1 || blocks[j] == block_stack); + blocks[j] = block_stack; + blocks[i+1] = block_stack; + break; + case JUMP_ABSOLUTE: + j = get_arg(code, i) / sizeof(_Py_CODEUNIT); + assert(j < len); + if (blocks[j] == -1 && j < i) { + todo = 1; + } + assert(blocks[j] == -1 || blocks[j] == block_stack); + blocks[j] = block_stack; + break; + case SETUP_FINALLY: + j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; + assert(j < len); + except_stack = push_block(block_stack, Except); + assert(blocks[j] == -1 || blocks[j] == except_stack); + blocks[j] = except_stack; + block_stack = push_block(block_stack, Try); + blocks[i+1] = block_stack; + break; + case SETUP_WITH: + case SETUP_ASYNC_WITH: + j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; + assert(j < len); + except_stack = push_block(block_stack, Except); + assert(blocks[j] == -1 || blocks[j] == except_stack); + blocks[j] = except_stack; + block_stack = push_block(block_stack, With); + blocks[i+1] = block_stack; + break; + case JUMP_FORWARD: + j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; + assert(j < len); + assert(blocks[j] == -1 || blocks[j] == block_stack); + blocks[j] = block_stack; + break; + case GET_ITER: + case GET_AITER: + block_stack = push_block(block_stack, Loop); + blocks[i+1] = block_stack; + break; + case FOR_ITER: + blocks[i+1] = block_stack; + block_stack = pop_block(block_stack); + j = get_arg(code, i) / sizeof(_Py_CODEUNIT) + i + 1; + assert(j < len); + assert(blocks[j] == -1 || blocks[j] == block_stack); + blocks[j] = block_stack; + break; + case POP_BLOCK: + case POP_EXCEPT: + block_stack = pop_block(block_stack); + blocks[i+1] = block_stack; + break; + case END_ASYNC_FOR: + block_stack = pop_block(pop_block(block_stack)); + blocks[i+1] = block_stack; + break; + case RETURN_VALUE: + case RAISE_VARARGS: + case RERAISE: + /* End of block */ + break; + default: + blocks[i+1] = block_stack; + + } + } + } + return blocks; +} + +static int +compatible_block_stack(int64_t from_stack, int64_t to_stack) +{ + if (to_stack < 0) { + return 0; + } + while(from_stack > to_stack) { + from_stack = pop_block(from_stack); + } + return from_stack == to_stack; +} + +static const char * +explain_incompatible_block_stack(int64_t to_stack) +{ + Kind target_kind = top_block(to_stack); + switch(target_kind) { + case Except: + return "can't jump into an 'except' block as there's no exception"; + case Try: + return "can't jump into the body of a try statement"; + case With: + return "can't jump into the body of a with statement"; + case Loop: + return "can't jump into the body of a for loop"; + default: + Py_UNREACHABLE(); + } +} + +static int * +marklines(PyCodeObject *code, int len) +{ + int *linestarts = PyMem_New(int, len); + if (linestarts == NULL) { + return NULL; + } + Py_ssize_t size = PyBytes_GET_SIZE(code->co_lnotab) / 2; + unsigned char *p = (unsigned char*)PyBytes_AS_STRING(code->co_lnotab); + int line = code->co_firstlineno; + int addr = 0; + int index = 0; + while (--size >= 0) { + addr += *p++; + if (index*2 < addr) { + linestarts[index++] = line; + } + while (index*2 < addr) { + linestarts[index++] = -1; + if (index >= len) { + break; + } + } + line += (signed char)*p; + p++; + } + if (index < len) { + linestarts[index++] = line; + } + while (index < len) { + linestarts[index++] = -1; + } + assert(index == len); + return linestarts; +} + +static int +first_line_not_before(int *lines, int len, int line) +{ + int result = INT_MAX; + for (int i = 0; i < len; i++) { + if (lines[i] < result && lines[i] >= line) { + result = lines[i]; + } + } + if (result == INT_MAX) { + return -1; + } + return result; +} + +static void +frame_stack_pop(PyFrameObject *f) +{ + PyObject *v = (*--f->f_stacktop); + Py_DECREF(v); +} + +static void +frame_block_unwind(PyFrameObject *f) +{ + assert(f->f_iblock > 0); + f->f_iblock--; + PyTryBlock *b = &f->f_blockstack[f->f_iblock]; + intptr_t delta = (f->f_stacktop - f->f_valuestack) - b->b_level; + while (delta > 0) { + frame_stack_pop(f); + delta--; + } +} + + /* Setter for f_lineno - you can set f_lineno from within a trace function in * order to jump to a given line of code, subject to some restrictions. Most * lines are OK to jump to because they don't make any assumptions about the @@ -319,11 +319,11 @@ frame_block_unwind(PyFrameObject *f) * o Lines with an 'except' statement on them can't be jumped to, because * they expect an exception to be on the top of the stack. * o Lines that live in a 'finally' block can't be jumped from or to, since - * we cannot be sure which state the interpreter was in or would be in - * during execution of the finally block. - * o 'try', 'with' and 'async with' blocks can't be jumped into because - * the blockstack needs to be set up before their code runs. - * o 'for' and 'async for' loops can't be jumped into because the + * we cannot be sure which state the interpreter was in or would be in + * during execution of the finally block. + * o 'try', 'with' and 'async with' blocks can't be jumped into because + * the blockstack needs to be set up before their code runs. + * o 'for' and 'async for' loops can't be jumped into because the * iterator needs to be on the stack. * o Jumps cannot be made from within a trace function invoked with a * 'return' or 'exception' event since the eval loop has been exited at @@ -372,18 +372,18 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } - int new_lineno; - - /* Fail if the line falls outside the code block and - select first line with actual code. */ - int overflow; - long l_new_lineno = PyLong_AsLongAndOverflow(p_new_lineno, &overflow); + int new_lineno; + + /* Fail if the line falls outside the code block and + select first line with actual code. */ + int overflow; + long l_new_lineno = PyLong_AsLongAndOverflow(p_new_lineno, &overflow); if (overflow #if SIZEOF_LONG > SIZEOF_INT || l_new_lineno > INT_MAX || l_new_lineno < INT_MIN #endif - ) { + ) { PyErr_SetString(PyExc_ValueError, "lineno out of range"); return -1; @@ -392,92 +392,92 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore if (new_lineno < f->f_code->co_firstlineno) { PyErr_Format(PyExc_ValueError, - "line %d comes before the current code block", - new_lineno); + "line %d comes before the current code block", + new_lineno); return -1; } - /* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this - * should never overflow. */ - int len = (int)(PyBytes_GET_SIZE(f->f_code->co_code) / sizeof(_Py_CODEUNIT)); - int *lines = marklines(f->f_code, len); - if (lines == NULL) { + /* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this + * should never overflow. */ + int len = (int)(PyBytes_GET_SIZE(f->f_code->co_code) / sizeof(_Py_CODEUNIT)); + int *lines = marklines(f->f_code, len); + if (lines == NULL) { return -1; } - new_lineno = first_line_not_before(lines, len, new_lineno); - if (new_lineno < 0) { - PyErr_Format(PyExc_ValueError, - "line %d comes after the current code block", - (int)l_new_lineno); - PyMem_Free(lines); + new_lineno = first_line_not_before(lines, len, new_lineno); + if (new_lineno < 0) { + PyErr_Format(PyExc_ValueError, + "line %d comes after the current code block", + (int)l_new_lineno); + PyMem_Free(lines); return -1; } - int64_t *blocks = markblocks(f->f_code, len); - if (blocks == NULL) { - PyMem_Free(lines); + int64_t *blocks = markblocks(f->f_code, len); + if (blocks == NULL) { + PyMem_Free(lines); return -1; } - int64_t target_block_stack = -1; - int64_t best_block_stack = -1; - int best_addr = -1; - int64_t start_block_stack = blocks[f->f_lasti/sizeof(_Py_CODEUNIT)]; - const char *msg = "cannot find bytecode for specified line"; - for (int i = 0; i < len; i++) { - if (lines[i] == new_lineno) { - target_block_stack = blocks[i]; - if (compatible_block_stack(start_block_stack, target_block_stack)) { - msg = NULL; - if (target_block_stack > best_block_stack) { - best_block_stack = target_block_stack; - best_addr = i*sizeof(_Py_CODEUNIT); - } + int64_t target_block_stack = -1; + int64_t best_block_stack = -1; + int best_addr = -1; + int64_t start_block_stack = blocks[f->f_lasti/sizeof(_Py_CODEUNIT)]; + const char *msg = "cannot find bytecode for specified line"; + for (int i = 0; i < len; i++) { + if (lines[i] == new_lineno) { + target_block_stack = blocks[i]; + if (compatible_block_stack(start_block_stack, target_block_stack)) { + msg = NULL; + if (target_block_stack > best_block_stack) { + best_block_stack = target_block_stack; + best_addr = i*sizeof(_Py_CODEUNIT); + } } - else if (msg) { - if (target_block_stack >= 0) { - msg = explain_incompatible_block_stack(target_block_stack); + else if (msg) { + if (target_block_stack >= 0) { + msg = explain_incompatible_block_stack(target_block_stack); + } + else { + msg = "code may be unreachable."; } - else { - msg = "code may be unreachable."; - } } } - } - PyMem_Free(blocks); - PyMem_Free(lines); - if (msg != NULL) { - PyErr_SetString(PyExc_ValueError, msg); - return -1; - } - - /* Unwind block stack. */ - while (start_block_stack > best_block_stack) { - Kind kind = top_block(start_block_stack); - switch(kind) { - case Loop: - frame_stack_pop(f); - break; - case Try: - frame_block_unwind(f); - break; - case With: - frame_block_unwind(f); - // Pop the exit function - frame_stack_pop(f); - break; - case Except: - PyErr_SetString(PyExc_ValueError, - "can't jump out of an 'except' block"); - return -1; + } + PyMem_Free(blocks); + PyMem_Free(lines); + if (msg != NULL) { + PyErr_SetString(PyExc_ValueError, msg); + return -1; + } + + /* Unwind block stack. */ + while (start_block_stack > best_block_stack) { + Kind kind = top_block(start_block_stack); + switch(kind) { + case Loop: + frame_stack_pop(f); + break; + case Try: + frame_block_unwind(f); + break; + case With: + frame_block_unwind(f); + // Pop the exit function + frame_stack_pop(f); + break; + case Except: + PyErr_SetString(PyExc_ValueError, + "can't jump out of an 'except' block"); + return -1; } - start_block_stack = pop_block(start_block_stack); + start_block_stack = pop_block(start_block_stack); } /* Finally set the new f_lineno and f_lasti and return OK. */ f->f_lineno = new_lineno; - f->f_lasti = best_addr; + f->f_lasti = best_addr; return 0; } @@ -558,13 +558,13 @@ static PyGetSetDef frame_getsetlist[] = { free_list. Else programs creating lots of cyclic trash involving frames could provoke free_list into growing without bound. */ -/* max value for numfree */ -#define PyFrame_MAXFREELIST 200 +/* max value for numfree */ +#define PyFrame_MAXFREELIST 200 -#if PyFrame_MAXFREELIST > 0 +#if PyFrame_MAXFREELIST > 0 static PyFrameObject *free_list = NULL; static int numfree = 0; /* number of frames currently in free_list */ -#endif +#endif static void _Py_HOT_FUNCTION frame_dealloc(PyFrameObject *f) @@ -575,7 +575,7 @@ frame_dealloc(PyFrameObject *f) if (_PyObject_GC_IS_TRACKED(f)) _PyObject_GC_UNTRACK(f); - Py_TRASHCAN_BEGIN(f, frame_dealloc); + Py_TRASHCAN_BEGIN(f, frame_dealloc); /* Kill all local variables */ valuestack = f->f_valuestack; for (p = f->f_localsplus; p < valuestack; p++) @@ -594,33 +594,33 @@ frame_dealloc(PyFrameObject *f) Py_CLEAR(f->f_trace); co = f->f_code; - if (co->co_zombieframe == NULL) { + if (co->co_zombieframe == NULL) { co->co_zombieframe = f; - } -#if PyFrame_MAXFREELIST > 0 + } +#if PyFrame_MAXFREELIST > 0 else if (numfree < PyFrame_MAXFREELIST) { ++numfree; f->f_back = free_list; free_list = f; } -#endif - else { +#endif + else { PyObject_GC_Del(f); - } + } Py_DECREF(co); - Py_TRASHCAN_END; + Py_TRASHCAN_END; +} + +static inline Py_ssize_t +frame_nslots(PyFrameObject *frame) +{ + PyCodeObject *code = frame->f_code; + return (code->co_nlocals + + PyTuple_GET_SIZE(code->co_cellvars) + + PyTuple_GET_SIZE(code->co_freevars)); } -static inline Py_ssize_t -frame_nslots(PyFrameObject *frame) -{ - PyCodeObject *code = frame->f_code; - return (code->co_nlocals - + PyTuple_GET_SIZE(code->co_cellvars) - + PyTuple_GET_SIZE(code->co_freevars)); -} - static int frame_traverse(PyFrameObject *f, visitproc visit, void *arg) { @@ -632,16 +632,16 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) Py_VISIT(f->f_trace); /* locals */ - PyObject **fastlocals = f->f_localsplus; - for (Py_ssize_t i = frame_nslots(f); --i >= 0; ++fastlocals) { + PyObject **fastlocals = f->f_localsplus; + for (Py_ssize_t i = frame_nslots(f); --i >= 0; ++fastlocals) { Py_VISIT(*fastlocals); - } + } /* stack */ if (f->f_stacktop != NULL) { - for (PyObject **p = f->f_valuestack; p < f->f_stacktop; p++) { + for (PyObject **p = f->f_valuestack; p < f->f_stacktop; p++) { Py_VISIT(*p); - } + } } return 0; } @@ -654,29 +654,29 @@ frame_tp_clear(PyFrameObject *f) * frame may also point to this frame, believe itself to still be * active, and try cleaning up this frame again. */ - PyObject **oldtop = f->f_stacktop; + PyObject **oldtop = f->f_stacktop; f->f_stacktop = NULL; f->f_executing = 0; Py_CLEAR(f->f_trace); /* locals */ - PyObject **fastlocals = f->f_localsplus; - for (Py_ssize_t i = frame_nslots(f); --i >= 0; ++fastlocals) { + PyObject **fastlocals = f->f_localsplus; + for (Py_ssize_t i = frame_nslots(f); --i >= 0; ++fastlocals) { Py_CLEAR(*fastlocals); - } + } /* stack */ if (oldtop != NULL) { - for (PyObject **p = f->f_valuestack; p < oldtop; p++) { + for (PyObject **p = f->f_valuestack; p < oldtop; p++) { Py_CLEAR(*p); - } + } } return 0; } static PyObject * -frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) +frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { if (f->f_executing) { PyErr_SetString(PyExc_RuntimeError, @@ -695,14 +695,14 @@ PyDoc_STRVAR(clear__doc__, "F.clear(): clear most references held by the frame"); static PyObject * -frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) +frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res, extras, ncells, nfrees; - PyCodeObject *code = f->f_code; - ncells = PyTuple_GET_SIZE(code->co_cellvars); - nfrees = PyTuple_GET_SIZE(code->co_freevars); - extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; + PyCodeObject *code = f->f_code; + ncells = PyTuple_GET_SIZE(code->co_cellvars); + nfrees = PyTuple_GET_SIZE(code->co_freevars); + extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; /* subtract one as it is already included in PyFrameObject */ res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *); @@ -716,10 +716,10 @@ static PyObject * frame_repr(PyFrameObject *f) { int lineno = PyFrame_GetLineNumber(f); - PyCodeObject *code = f->f_code; + PyCodeObject *code = f->f_code; return PyUnicode_FromFormat( "<frame at %p, file %R, line %d, code %S>", - f, code->co_filename, lineno, code->co_name); + f, code->co_filename, lineno, code->co_name); } static PyMethodDef frame_methods[] = { @@ -736,10 +736,10 @@ PyTypeObject PyFrame_Type = { sizeof(PyFrameObject), sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)frame_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -767,127 +767,127 @@ PyTypeObject PyFrame_Type = { _Py_IDENTIFIER(__builtins__); -static inline PyFrameObject* -frame_alloc(PyCodeObject *code) +static inline PyFrameObject* +frame_alloc(PyCodeObject *code) { PyFrameObject *f; - f = code->co_zombieframe; - if (f != NULL) { - code->co_zombieframe = NULL; - _Py_NewReference((PyObject *)f); - assert(f->f_code == code); - return f; - } - - Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars); - Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars); - Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; -#if PyFrame_MAXFREELIST > 0 - if (free_list == NULL) + f = code->co_zombieframe; + if (f != NULL) { + code->co_zombieframe = NULL; + _Py_NewReference((PyObject *)f); + assert(f->f_code == code); + return f; + } + + Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars); + Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars); + Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; +#if PyFrame_MAXFREELIST > 0 + if (free_list == NULL) #endif - { - f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); - if (f == NULL) { - return NULL; + { + f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); + if (f == NULL) { + return NULL; } - } -#if PyFrame_MAXFREELIST > 0 - else { - assert(numfree > 0); - --numfree; - f = free_list; - free_list = free_list->f_back; - if (Py_SIZE(f) < extras) { - PyFrameObject *new_f = PyObject_GC_Resize(PyFrameObject, f, extras); - if (new_f == NULL) { - PyObject_GC_Del(f); - return NULL; - } - f = new_f; + } +#if PyFrame_MAXFREELIST > 0 + else { + assert(numfree > 0); + --numfree; + f = free_list; + free_list = free_list->f_back; + if (Py_SIZE(f) < extras) { + PyFrameObject *new_f = PyObject_GC_Resize(PyFrameObject, f, extras); + if (new_f == NULL) { + PyObject_GC_Del(f); + return NULL; + } + f = new_f; } - _Py_NewReference((PyObject *)f); - } -#endif - - f->f_code = code; - extras = code->co_nlocals + ncells + nfrees; - f->f_valuestack = f->f_localsplus + extras; - for (Py_ssize_t i=0; i<extras; i++) { - f->f_localsplus[i] = NULL; - } - f->f_locals = NULL; - f->f_trace = NULL; - return f; -} - - -static inline PyObject * -frame_get_builtins(PyFrameObject *back, PyObject *globals) -{ - PyObject *builtins; - - if (back != NULL && back->f_globals == globals) { + _Py_NewReference((PyObject *)f); + } +#endif + + f->f_code = code; + extras = code->co_nlocals + ncells + nfrees; + f->f_valuestack = f->f_localsplus + extras; + for (Py_ssize_t i=0; i<extras; i++) { + f->f_localsplus[i] = NULL; + } + f->f_locals = NULL; + f->f_trace = NULL; + return f; +} + + +static inline PyObject * +frame_get_builtins(PyFrameObject *back, PyObject *globals) +{ + PyObject *builtins; + + if (back != NULL && back->f_globals == globals) { /* If we share the globals, we share the builtins. Save a lookup and a call. */ builtins = back->f_builtins; assert(builtins != NULL); Py_INCREF(builtins); - return builtins; - } - - builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__); - if (builtins != NULL && PyModule_Check(builtins)) { - builtins = PyModule_GetDict(builtins); - assert(builtins != NULL); - } - if (builtins != NULL) { - Py_INCREF(builtins); - return builtins; - } - - if (PyErr_Occurred()) { - return NULL; - } - - /* No builtins! Make up a minimal one. - Give them 'None', at least. */ - builtins = PyDict_New(); - if (builtins == NULL) { - return NULL; - } - if (PyDict_SetItemString(builtins, "None", Py_None) < 0) { - Py_DECREF(builtins); - return NULL; - } - return builtins; -} - - -PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code, - PyObject *globals, PyObject *locals) -{ -#ifdef Py_DEBUG - if (code == NULL || globals == NULL || !PyDict_Check(globals) || - (locals != NULL && !PyMapping_Check(locals))) { - PyErr_BadInternalCall(); - return NULL; - } -#endif - - PyFrameObject *back = tstate->frame; - PyObject *builtins = frame_get_builtins(back, globals); - if (builtins == NULL) { - return NULL; - } - - PyFrameObject *f = frame_alloc(code); - if (f == NULL) { - Py_DECREF(builtins); - return NULL; - } - + return builtins; + } + + builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__); + if (builtins != NULL && PyModule_Check(builtins)) { + builtins = PyModule_GetDict(builtins); + assert(builtins != NULL); + } + if (builtins != NULL) { + Py_INCREF(builtins); + return builtins; + } + + if (PyErr_Occurred()) { + return NULL; + } + + /* No builtins! Make up a minimal one. + Give them 'None', at least. */ + builtins = PyDict_New(); + if (builtins == NULL) { + return NULL; + } + if (PyDict_SetItemString(builtins, "None", Py_None) < 0) { + Py_DECREF(builtins); + return NULL; + } + return builtins; +} + + +PyFrameObject* _Py_HOT_FUNCTION +_PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code, + PyObject *globals, PyObject *locals) +{ +#ifdef Py_DEBUG + if (code == NULL || globals == NULL || !PyDict_Check(globals) || + (locals != NULL && !PyMapping_Check(locals))) { + PyErr_BadInternalCall(); + return NULL; + } +#endif + + PyFrameObject *back = tstate->frame; + PyObject *builtins = frame_get_builtins(back, globals); + if (builtins == NULL) { + return NULL; + } + + PyFrameObject *f = frame_alloc(code); + if (f == NULL) { + Py_DECREF(builtins); + return NULL; + } + f->f_stacktop = f->f_valuestack; f->f_builtins = builtins; Py_XINCREF(back); @@ -922,8 +922,8 @@ _PyFrame_New_NoTrack(PyThreadState *tstate, PyCodeObject *code, f->f_trace_opcodes = 0; f->f_trace_lines = 1; - assert(f->f_code != NULL); - + assert(f->f_code != NULL); + return f; } @@ -944,9 +944,9 @@ void PyFrame_BlockSetup(PyFrameObject *f, int type, int handler, int level) { PyTryBlock *b; - if (f->f_iblock >= CO_MAXBLOCKS) { - Py_FatalError("block stack overflow"); - } + if (f->f_iblock >= CO_MAXBLOCKS) { + Py_FatalError("block stack overflow"); + } b = &f->f_blockstack[f->f_iblock++]; b->b_type = type; b->b_level = level; @@ -957,9 +957,9 @@ PyTryBlock * PyFrame_BlockPop(PyFrameObject *f) { PyTryBlock *b; - if (f->f_iblock <= 0) { - Py_FatalError("block stack underflow"); - } + if (f->f_iblock <= 0) { + Py_FatalError("block stack underflow"); + } b = &f->f_blockstack[--f->f_iblock]; return b; } @@ -1176,10 +1176,10 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) } /* Clear out the free list */ -void -_PyFrame_ClearFreeList(void) +void +_PyFrame_ClearFreeList(void) { -#if PyFrame_MAXFREELIST > 0 +#if PyFrame_MAXFREELIST > 0 while (free_list != NULL) { PyFrameObject *f = free_list; free_list = free_list->f_back; @@ -1187,43 +1187,43 @@ _PyFrame_ClearFreeList(void) --numfree; } assert(numfree == 0); -#endif +#endif } void -_PyFrame_Fini(void) +_PyFrame_Fini(void) { - _PyFrame_ClearFreeList(); + _PyFrame_ClearFreeList(); } /* Print summary info about the state of the optimized allocator */ void _PyFrame_DebugMallocStats(FILE *out) { -#if PyFrame_MAXFREELIST > 0 +#if PyFrame_MAXFREELIST > 0 _PyDebugAllocatorStats(out, "free PyFrameObject", numfree, sizeof(PyFrameObject)); -#endif +#endif } - -PyCodeObject * -PyFrame_GetCode(PyFrameObject *frame) -{ - assert(frame != NULL); - PyCodeObject *code = frame->f_code; - assert(code != NULL); - Py_INCREF(code); - return code; -} - - -PyFrameObject* -PyFrame_GetBack(PyFrameObject *frame) -{ - assert(frame != NULL); - PyFrameObject *back = frame->f_back; - Py_XINCREF(back); - return back; -} + +PyCodeObject * +PyFrame_GetCode(PyFrameObject *frame) +{ + assert(frame != NULL); + PyCodeObject *code = frame->f_code; + assert(code != NULL); + Py_INCREF(code); + return code; +} + + +PyFrameObject* +PyFrame_GetBack(PyFrameObject *frame) +{ + assert(frame != NULL); + PyFrameObject *back = frame->f_back; + Py_XINCREF(back); + return back; +} diff --git a/contrib/tools/python3/src/Objects/funcobject.c b/contrib/tools/python3/src/Objects/funcobject.c index 5b792dc3ed..2c60275d90 100644 --- a/contrib/tools/python3/src/Objects/funcobject.c +++ b/contrib/tools/python3/src/Objects/funcobject.c @@ -2,10 +2,10 @@ /* Function object implementation */ #include "Python.h" -#include "pycore_object.h" -#include "pycore_tupleobject.h" +#include "pycore_object.h" +#include "pycore_tupleobject.h" #include "code.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef PyObject * PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) @@ -20,23 +20,23 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname return NULL; } - /* __module__: If module name is in globals, use it. - Otherwise, use None. */ - module = PyDict_GetItemWithError(globals, __name__); - if (module) { - Py_INCREF(module); - } - else if (PyErr_Occurred()) { - return NULL; - } - + /* __module__: If module name is in globals, use it. + Otherwise, use None. */ + module = PyDict_GetItemWithError(globals, __name__); + if (module) { + Py_INCREF(module); + } + else if (PyErr_Occurred()) { + return NULL; + } + op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); - if (op == NULL) { - Py_XDECREF(module); + if (op == NULL) { + Py_XDECREF(module); return NULL; - } - /* Note: No failures from this point on, since func_dealloc() does not - expect a partially-created object. */ + } + /* Note: No failures from this point on, since func_dealloc() does not + expect a partially-created object. */ op->func_weakreflist = NULL; Py_INCREF(code); @@ -48,8 +48,8 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname op->func_defaults = NULL; /* No default arguments */ op->func_kwdefaults = NULL; /* No keyword only defaults */ op->func_closure = NULL; - op->vectorcall = _PyFunction_Vectorcall; - op->func_module = module; + op->vectorcall = _PyFunction_Vectorcall; + op->func_module = module; consts = ((PyCodeObject *)code)->co_consts; if (PyTuple_Size(consts) >= 1) { @@ -197,7 +197,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure) else { PyErr_Format(PyExc_SystemError, "expected tuple for closure, got '%.100s'", - Py_TYPE(closure)->tp_name); + Py_TYPE(closure)->tp_name); return -1; } Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); @@ -240,20 +240,20 @@ PyFunction_SetAnnotations(PyObject *op, PyObject *annotations) #define OFF(x) offsetof(PyFunctionObject, x) static PyMemberDef func_memberlist[] = { - {"__closure__", T_OBJECT, OFF(func_closure), READONLY}, - {"__doc__", T_OBJECT, OFF(func_doc), 0}, - {"__globals__", T_OBJECT, OFF(func_globals), READONLY}, - {"__module__", T_OBJECT, OFF(func_module), 0}, + {"__closure__", T_OBJECT, OFF(func_closure), READONLY}, + {"__doc__", T_OBJECT, OFF(func_doc), 0}, + {"__globals__", T_OBJECT, OFF(func_globals), READONLY}, + {"__module__", T_OBJECT, OFF(func_module), 0}, {NULL} /* Sentinel */ }; static PyObject * func_get_code(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", op, "__code__") < 0) { - return NULL; - } - + if (PySys_Audit("object.__getattr__", "Os", op, "__code__") < 0) { + return NULL; + } + Py_INCREF(op->func_code); return op->func_code; } @@ -270,12 +270,12 @@ func_set_code(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored)) "__code__ must be set to a code object"); return -1; } - - if (PySys_Audit("object.__setattr__", "OsO", - op, "__code__", value) < 0) { - return -1; - } - + + if (PySys_Audit("object.__setattr__", "OsO", + op, "__code__", value) < 0) { + return -1; + } + nfree = PyCode_GetNumFree((PyCodeObject *)value); nclosure = (op->func_closure == NULL ? 0 : PyTuple_GET_SIZE(op->func_closure)); @@ -339,9 +339,9 @@ func_set_qualname(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored static PyObject * func_get_defaults(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", op, "__defaults__") < 0) { - return NULL; - } + if (PySys_Audit("object.__getattr__", "Os", op, "__defaults__") < 0) { + return NULL; + } if (op->func_defaults == NULL) { Py_RETURN_NONE; } @@ -361,16 +361,16 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored "__defaults__ must be set to a tuple object"); return -1; } - if (value) { - if (PySys_Audit("object.__setattr__", "OsO", - op, "__defaults__", value) < 0) { - return -1; - } - } else if (PySys_Audit("object.__delattr__", "Os", - op, "__defaults__") < 0) { - return -1; - } - + if (value) { + if (PySys_Audit("object.__setattr__", "OsO", + op, "__defaults__", value) < 0) { + return -1; + } + } else if (PySys_Audit("object.__delattr__", "Os", + op, "__defaults__") < 0) { + return -1; + } + Py_XINCREF(value); Py_XSETREF(op->func_defaults, value); return 0; @@ -379,10 +379,10 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored static PyObject * func_get_kwdefaults(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", - op, "__kwdefaults__") < 0) { - return NULL; - } + if (PySys_Audit("object.__getattr__", "Os", + op, "__kwdefaults__") < 0) { + return NULL; + } if (op->func_kwdefaults == NULL) { Py_RETURN_NONE; } @@ -402,16 +402,16 @@ func_set_kwdefaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignor "__kwdefaults__ must be set to a dict object"); return -1; } - if (value) { - if (PySys_Audit("object.__setattr__", "OsO", - op, "__kwdefaults__", value) < 0) { - return -1; - } - } else if (PySys_Audit("object.__delattr__", "Os", - op, "__kwdefaults__") < 0) { - return -1; - } - + if (value) { + if (PySys_Audit("object.__setattr__", "OsO", + op, "__kwdefaults__", value) < 0) { + return -1; + } + } else if (PySys_Audit("object.__delattr__", "Os", + op, "__kwdefaults__") < 0) { + return -1; + } + Py_XINCREF(value); Py_XSETREF(op->func_kwdefaults, value); return 0; @@ -540,13 +540,13 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, if (!PyCell_Check(o)) { return PyErr_Format(PyExc_TypeError, "arg 5 (closure) expected cell, found %s", - Py_TYPE(o)->tp_name); + Py_TYPE(o)->tp_name); } } } - if (PySys_Audit("function.__new__", "O", code) < 0) { - return NULL; - } + if (PySys_Audit("function.__new__", "O", code) < 0) { + return NULL; + } newfunc = (PyFunctionObject *)PyFunction_New((PyObject *)code, globals); @@ -569,31 +569,31 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, return (PyObject *)newfunc; } -static int -func_clear(PyFunctionObject *op) -{ - Py_CLEAR(op->func_code); - Py_CLEAR(op->func_globals); - Py_CLEAR(op->func_module); - Py_CLEAR(op->func_name); - Py_CLEAR(op->func_defaults); - Py_CLEAR(op->func_kwdefaults); - Py_CLEAR(op->func_doc); - Py_CLEAR(op->func_dict); - Py_CLEAR(op->func_closure); - Py_CLEAR(op->func_annotations); - Py_CLEAR(op->func_qualname); - return 0; -} - +static int +func_clear(PyFunctionObject *op) +{ + Py_CLEAR(op->func_code); + Py_CLEAR(op->func_globals); + Py_CLEAR(op->func_module); + Py_CLEAR(op->func_name); + Py_CLEAR(op->func_defaults); + Py_CLEAR(op->func_kwdefaults); + Py_CLEAR(op->func_doc); + Py_CLEAR(op->func_dict); + Py_CLEAR(op->func_closure); + Py_CLEAR(op->func_annotations); + Py_CLEAR(op->func_qualname); + return 0; +} + static void func_dealloc(PyFunctionObject *op) { _PyObject_GC_UNTRACK(op); - if (op->func_weakreflist != NULL) { + if (op->func_weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject *) op); - } - (void)func_clear(op); + } + (void)func_clear(op); PyObject_GC_Del(op); } @@ -638,26 +638,26 @@ PyTypeObject PyFunction_Type = { sizeof(PyFunctionObject), 0, (destructor)func_dealloc, /* tp_dealloc */ - offsetof(PyFunctionObject, vectorcall), /* tp_vectorcall_offset */ + offsetof(PyFunctionObject, vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)func_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ - PyVectorcall_Call, /* tp_call */ + PyVectorcall_Call, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_HAVE_VECTORCALL | - Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_VECTORCALL | + Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ func_new__doc__, /* tp_doc */ (traverseproc)func_traverse, /* tp_traverse */ - (inquiry)func_clear, /* tp_clear */ + (inquiry)func_clear, /* tp_clear */ 0, /* tp_richcompare */ offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */ 0, /* tp_iter */ @@ -740,10 +740,10 @@ cm_descr_get(PyObject *self, PyObject *obj, PyObject *type) } if (type == NULL) type = (PyObject *)(Py_TYPE(obj)); - if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL) { - return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type, - NULL); - } + if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL) { + return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type, + NULL); + } return PyMethod_New(cm->cm_callable, type); } @@ -817,10 +817,10 @@ PyTypeObject PyClassMethod_Type = { sizeof(classmethod), 0, (destructor)cm_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -877,8 +877,8 @@ PyClassMethod_New(PyObject *callable) ... It can be called either on the class (e.g. C.f()) or on an instance - (e.g. C().f()). Both the class and the instance are ignored, and - neither is passed implicitly as the first argument to the method. + (e.g. C().f()). Both the class and the instance are ignored, and + neither is passed implicitly as the first argument to the method. Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see class methods above. @@ -985,8 +985,8 @@ To declare a static method, use this idiom:\n\ ...\n\ \n\ It can be called either on the class (e.g. C.f()) or on an instance\n\ -(e.g. C().f()). Both the class and the instance are ignored, and\n\ -neither is passed implicitly as the first argument to the method.\n\ +(e.g. C().f()). Both the class and the instance are ignored, and\n\ +neither is passed implicitly as the first argument to the method.\n\ \n\ Static methods in Python are similar to those found in Java or C++.\n\ For a more advanced concept, see the classmethod builtin."); @@ -997,10 +997,10 @@ PyTypeObject PyStaticMethod_Type = { sizeof(staticmethod), 0, (destructor)sm_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/genericaliasobject.c b/contrib/tools/python3/src/Objects/genericaliasobject.c index 44b974ec26..acbb01cfef 100644 --- a/contrib/tools/python3/src/Objects/genericaliasobject.c +++ b/contrib/tools/python3/src/Objects/genericaliasobject.c @@ -1,655 +1,655 @@ -// types.GenericAlias -- used to represent e.g. list[int]. - -#include "Python.h" -#include "pycore_object.h" -#include "structmember.h" // PyMemberDef - -typedef struct { - PyObject_HEAD - PyObject *origin; - PyObject *args; - PyObject *parameters; - PyObject* weakreflist; -} gaobject; - -static void -ga_dealloc(PyObject *self) -{ - gaobject *alias = (gaobject *)self; - - _PyObject_GC_UNTRACK(self); - if (alias->weakreflist != NULL) { - PyObject_ClearWeakRefs((PyObject *)alias); - } - Py_XDECREF(alias->origin); - Py_XDECREF(alias->args); - Py_XDECREF(alias->parameters); - self->ob_type->tp_free(self); -} - -static int -ga_traverse(PyObject *self, visitproc visit, void *arg) -{ - gaobject *alias = (gaobject *)self; - Py_VISIT(alias->origin); - Py_VISIT(alias->args); - Py_VISIT(alias->parameters); - return 0; -} - -static int -ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) -{ - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(__qualname__); - _Py_IDENTIFIER(__origin__); - _Py_IDENTIFIER(__args__); - PyObject *qualname = NULL; - PyObject *module = NULL; - PyObject *r = NULL; - PyObject *tmp; - int err; - - if (p == Py_Ellipsis) { - // The Ellipsis object - r = PyUnicode_FromString("..."); - goto done; - } - - if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { - goto done; - } - if (tmp != NULL) { - Py_DECREF(tmp); - if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { - goto done; - } - if (tmp != NULL) { - Py_DECREF(tmp); - // It looks like a GenericAlias - goto use_repr; - } - } - - if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) { - goto done; - } - if (qualname == NULL) { - goto use_repr; - } - if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) { - goto done; - } - if (module == NULL || module == Py_None) { - goto use_repr; - } - - // Looks like a class - if (PyUnicode_Check(module) && - _PyUnicode_EqualToASCIIString(module, "builtins")) - { - // builtins don't need a module name - r = PyObject_Str(qualname); - goto done; - } - else { - r = PyUnicode_FromFormat("%S.%S", module, qualname); - goto done; - } - -use_repr: - r = PyObject_Repr(p); - -done: - Py_XDECREF(qualname); - Py_XDECREF(module); - if (r == NULL) { - // error if any of the above PyObject_Repr/PyUnicode_From* fail - err = -1; - } - else { - err = _PyUnicodeWriter_WriteStr(writer, r); - Py_DECREF(r); - } - return err; -} - -static PyObject * -ga_repr(PyObject *self) -{ - gaobject *alias = (gaobject *)self; - Py_ssize_t len = PyTuple_GET_SIZE(alias->args); - - _PyUnicodeWriter writer; - _PyUnicodeWriter_Init(&writer); - - if (ga_repr_item(&writer, alias->origin) < 0) { - goto error; - } - if (_PyUnicodeWriter_WriteASCIIString(&writer, "[", 1) < 0) { - goto error; - } - for (Py_ssize_t i = 0; i < len; i++) { - if (i > 0) { - if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { - goto error; - } - } - PyObject *p = PyTuple_GET_ITEM(alias->args, i); - if (ga_repr_item(&writer, p) < 0) { - goto error; - } - } - if (len == 0) { - // for something like tuple[()] we should print a "()" - if (_PyUnicodeWriter_WriteASCIIString(&writer, "()", 2) < 0) { - goto error; - } - } - if (_PyUnicodeWriter_WriteASCIIString(&writer, "]", 1) < 0) { - goto error; - } - return _PyUnicodeWriter_Finish(&writer); -error: - _PyUnicodeWriter_Dealloc(&writer); - return NULL; -} - -// isinstance(obj, TypeVar) without importing typing.py. -// Returns -1 for errors. -static int -is_typevar(PyObject *obj) -{ - PyTypeObject *type = Py_TYPE(obj); - if (strcmp(type->tp_name, "TypeVar") != 0) { - return 0; - } - PyObject *module = PyObject_GetAttrString((PyObject *)type, "__module__"); - if (module == NULL) { - return -1; - } - int res = PyUnicode_Check(module) - && _PyUnicode_EqualToASCIIString(module, "typing"); - Py_DECREF(module); - return res; -} - -// Index of item in self[:len], or -1 if not found (self is a tuple) -static Py_ssize_t -tuple_index(PyObject *self, Py_ssize_t len, PyObject *item) -{ - for (Py_ssize_t i = 0; i < len; i++) { - if (PyTuple_GET_ITEM(self, i) == item) { - return i; - } - } - return -1; -} - -static int -tuple_add(PyObject *self, Py_ssize_t len, PyObject *item) -{ - if (tuple_index(self, len, item) < 0) { - Py_INCREF(item); - PyTuple_SET_ITEM(self, len, item); - return 1; - } - return 0; -} - -static PyObject * -make_parameters(PyObject *args) -{ - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t len = nargs; - PyObject *parameters = PyTuple_New(len); - if (parameters == NULL) - return NULL; - Py_ssize_t iparam = 0; - for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { - PyObject *t = PyTuple_GET_ITEM(args, iarg); - int typevar = is_typevar(t); - if (typevar < 0) { - Py_DECREF(parameters); - return NULL; - } - if (typevar) { - iparam += tuple_add(parameters, iparam, t); - } - else { - _Py_IDENTIFIER(__parameters__); - PyObject *subparams; - if (_PyObject_LookupAttrId(t, &PyId___parameters__, &subparams) < 0) { - Py_DECREF(parameters); - return NULL; - } - if (subparams && PyTuple_Check(subparams)) { - Py_ssize_t len2 = PyTuple_GET_SIZE(subparams); - Py_ssize_t needed = len2 - 1 - (iarg - iparam); - if (needed > 0) { - len += needed; - if (_PyTuple_Resize(¶meters, len) < 0) { - Py_DECREF(subparams); - Py_DECREF(parameters); - return NULL; - } - } - for (Py_ssize_t j = 0; j < len2; j++) { - PyObject *t2 = PyTuple_GET_ITEM(subparams, j); - iparam += tuple_add(parameters, iparam, t2); - } - } - Py_XDECREF(subparams); - } - } - if (iparam < len) { - if (_PyTuple_Resize(¶meters, iparam) < 0) { - Py_XDECREF(parameters); - return NULL; - } - } - return parameters; -} - -/* If obj is a generic alias, substitute type variables params - with substitutions argitems. For example, if obj is list[T], - params is (T, S), and argitems is (str, int), return list[str]. - If obj doesn't have a __parameters__ attribute or that's not - a non-empty tuple, return a new reference to obj. */ -static PyObject * -subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) -{ - _Py_IDENTIFIER(__parameters__); - PyObject *subparams; - if (_PyObject_LookupAttrId(obj, &PyId___parameters__, &subparams) < 0) { - return NULL; - } - if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { - Py_ssize_t nparams = PyTuple_GET_SIZE(params); - Py_ssize_t nsubargs = PyTuple_GET_SIZE(subparams); - PyObject *subargs = PyTuple_New(nsubargs); - if (subargs == NULL) { - Py_DECREF(subparams); - return NULL; - } - for (Py_ssize_t i = 0; i < nsubargs; ++i) { - PyObject *arg = PyTuple_GET_ITEM(subparams, i); - Py_ssize_t iparam = tuple_index(params, nparams, arg); - if (iparam >= 0) { - arg = argitems[iparam]; - } - Py_INCREF(arg); - PyTuple_SET_ITEM(subargs, i, arg); - } - - obj = PyObject_GetItem(obj, subargs); - - Py_DECREF(subargs); - } - else { - Py_INCREF(obj); - } - Py_XDECREF(subparams); - return obj; -} - -static PyObject * -ga_getitem(PyObject *self, PyObject *item) -{ - gaobject *alias = (gaobject *)self; - // do a lookup for __parameters__ so it gets populated (if not already) - if (alias->parameters == NULL) { - alias->parameters = make_parameters(alias->args); - if (alias->parameters == NULL) { - return NULL; - } - } - Py_ssize_t nparams = PyTuple_GET_SIZE(alias->parameters); - if (nparams == 0) { - return PyErr_Format(PyExc_TypeError, - "There are no type variables left in %R", - self); - } - int is_tuple = PyTuple_Check(item); - Py_ssize_t nitems = is_tuple ? PyTuple_GET_SIZE(item) : 1; - PyObject **argitems = is_tuple ? &PyTuple_GET_ITEM(item, 0) : &item; - if (nitems != nparams) { - return PyErr_Format(PyExc_TypeError, - "Too %s arguments for %R", - nitems > nparams ? "many" : "few", - self); - } - /* Replace all type variables (specified by alias->parameters) - with corresponding values specified by argitems. - t = list[T]; t[int] -> newargs = [int] - t = dict[str, T]; t[int] -> newargs = [str, int] - t = dict[T, list[S]]; t[str, int] -> newargs = [str, list[int]] - */ - Py_ssize_t nargs = PyTuple_GET_SIZE(alias->args); - PyObject *newargs = PyTuple_New(nargs); - if (newargs == NULL) { - return NULL; - } - for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { - PyObject *arg = PyTuple_GET_ITEM(alias->args, iarg); - int typevar = is_typevar(arg); - if (typevar < 0) { - Py_DECREF(newargs); - return NULL; - } - if (typevar) { - Py_ssize_t iparam = tuple_index(alias->parameters, nparams, arg); - assert(iparam >= 0); - arg = argitems[iparam]; - Py_INCREF(arg); - } - else { - arg = subs_tvars(arg, alias->parameters, argitems); - if (arg == NULL) { - Py_DECREF(newargs); - return NULL; - } - } - PyTuple_SET_ITEM(newargs, iarg, arg); - } - - PyObject *res = Py_GenericAlias(alias->origin, newargs); - - Py_DECREF(newargs); - return res; -} - -static PyMappingMethods ga_as_mapping = { - .mp_subscript = ga_getitem, -}; - -static Py_hash_t -ga_hash(PyObject *self) -{ - gaobject *alias = (gaobject *)self; - // TODO: Hash in the hash for the origin - Py_hash_t h0 = PyObject_Hash(alias->origin); - if (h0 == -1) { - return -1; - } - Py_hash_t h1 = PyObject_Hash(alias->args); - if (h1 == -1) { - return -1; - } - return h0 ^ h1; -} - -static PyObject * -ga_call(PyObject *self, PyObject *args, PyObject *kwds) -{ - gaobject *alias = (gaobject *)self; - PyObject *obj = PyObject_Call(alias->origin, args, kwds); - if (obj != NULL) { - if (PyObject_SetAttrString(obj, "__orig_class__", self) < 0) { - if (!PyErr_ExceptionMatches(PyExc_AttributeError) && - !PyErr_ExceptionMatches(PyExc_TypeError)) - { - Py_DECREF(obj); - return NULL; - } - PyErr_Clear(); - } - } - return obj; -} - -static const char* const attr_exceptions[] = { - "__origin__", - "__args__", - "__parameters__", - "__mro_entries__", - "__reduce_ex__", // needed so we don't look up object.__reduce_ex__ - "__reduce__", - "__copy__", - "__deepcopy__", - NULL, -}; - -static PyObject * -ga_getattro(PyObject *self, PyObject *name) -{ - gaobject *alias = (gaobject *)self; - if (PyUnicode_Check(name)) { - for (const char * const *p = attr_exceptions; ; p++) { - if (*p == NULL) { - return PyObject_GetAttr(alias->origin, name); - } - if (_PyUnicode_EqualToASCIIString(name, *p)) { - break; - } - } - } - return PyObject_GenericGetAttr(self, name); -} - -static PyObject * -ga_richcompare(PyObject *a, PyObject *b, int op) -{ - if (!PyObject_TypeCheck(a, &Py_GenericAliasType) || - !PyObject_TypeCheck(b, &Py_GenericAliasType) || - (op != Py_EQ && op != Py_NE)) - { - Py_RETURN_NOTIMPLEMENTED; - } - - if (op == Py_NE) { - PyObject *eq = ga_richcompare(a, b, Py_EQ); - if (eq == NULL) - return NULL; - Py_DECREF(eq); - if (eq == Py_True) { - Py_RETURN_FALSE; - } - else { - Py_RETURN_TRUE; - } - } - - gaobject *aa = (gaobject *)a; - gaobject *bb = (gaobject *)b; - int eq = PyObject_RichCompareBool(aa->origin, bb->origin, Py_EQ); - if (eq < 0) { - return NULL; - } - if (!eq) { - Py_RETURN_FALSE; - } - return PyObject_RichCompare(aa->args, bb->args, Py_EQ); -} - -static PyObject * -ga_mro_entries(PyObject *self, PyObject *args) -{ - gaobject *alias = (gaobject *)self; - return PyTuple_Pack(1, alias->origin); -} - -static PyObject * -ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - PyErr_SetString(PyExc_TypeError, - "isinstance() argument 2 cannot be a parameterized generic"); - return NULL; -} - -static PyObject * -ga_subclasscheck(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - PyErr_SetString(PyExc_TypeError, - "issubclass() argument 2 cannot be a parameterized generic"); - return NULL; -} - -static PyObject * -ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - gaobject *alias = (gaobject *)self; - return Py_BuildValue("O(OO)", Py_TYPE(alias), - alias->origin, alias->args); -} - -static PyObject * -ga_dir(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - gaobject *alias = (gaobject *)self; - PyObject *dir = PyObject_Dir(alias->origin); - if (dir == NULL) { - return NULL; - } - - PyObject *dir_entry = NULL; - for (const char * const *p = attr_exceptions; ; p++) { - if (*p == NULL) { - break; - } - else { - dir_entry = PyUnicode_FromString(*p); - if (dir_entry == NULL) { - goto error; - } - int contains = PySequence_Contains(dir, dir_entry); - if (contains < 0) { - goto error; - } - if (contains == 0 && PyList_Append(dir, dir_entry) < 0) { - goto error; - } - - Py_CLEAR(dir_entry); - } - } - return dir; - -error: - Py_DECREF(dir); - Py_XDECREF(dir_entry); - return NULL; -} - -static PyMethodDef ga_methods[] = { - {"__mro_entries__", ga_mro_entries, METH_O}, - {"__instancecheck__", ga_instancecheck, METH_O}, - {"__subclasscheck__", ga_subclasscheck, METH_O}, - {"__reduce__", ga_reduce, METH_NOARGS}, - {"__dir__", ga_dir, METH_NOARGS}, - {0} -}; - -static PyMemberDef ga_members[] = { - {"__origin__", T_OBJECT, offsetof(gaobject, origin), READONLY}, - {"__args__", T_OBJECT, offsetof(gaobject, args), READONLY}, - {0} -}; - -static PyObject * -ga_parameters(PyObject *self, void *unused) -{ - gaobject *alias = (gaobject *)self; - if (alias->parameters == NULL) { - alias->parameters = make_parameters(alias->args); - if (alias->parameters == NULL) { - return NULL; - } - } - Py_INCREF(alias->parameters); - return alias->parameters; -} - -static PyGetSetDef ga_properties[] = { - {"__parameters__", ga_parameters, (setter)NULL, "Type variables in the GenericAlias.", NULL}, - {0} -}; - -/* A helper function to create GenericAlias' args tuple and set its attributes. - * Returns 1 on success, 0 on failure. - */ -static inline int -setup_ga(gaobject *alias, PyObject *origin, PyObject *args) { - if (!PyTuple_Check(args)) { - args = PyTuple_Pack(1, args); - if (args == NULL) { - return 0; - } - } - else { - Py_INCREF(args); - } - - Py_INCREF(origin); - alias->origin = origin; - alias->args = args; - alias->parameters = NULL; - alias->weakreflist = NULL; - return 1; -} - -static PyObject * -ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - if (!_PyArg_NoKeywords("GenericAlias", kwds)) { - return NULL; - } - if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) { - return NULL; - } - PyObject *origin = PyTuple_GET_ITEM(args, 0); - PyObject *arguments = PyTuple_GET_ITEM(args, 1); - gaobject *self = (gaobject *)type->tp_alloc(type, 0); - if (self == NULL) { - return NULL; - } - if (!setup_ga(self, origin, arguments)) { - Py_DECREF(self); - return NULL; - } - return (PyObject *)self; -} - -// TODO: -// - argument clinic? -// - __doc__? -// - cache? -PyTypeObject Py_GenericAliasType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "types.GenericAlias", - .tp_doc = "Represent a PEP 585 generic type\n" - "\n" - "E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).", - .tp_basicsize = sizeof(gaobject), - .tp_dealloc = ga_dealloc, - .tp_repr = ga_repr, - .tp_as_mapping = &ga_as_mapping, - .tp_hash = ga_hash, - .tp_call = ga_call, - .tp_getattro = ga_getattro, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, - .tp_traverse = ga_traverse, - .tp_richcompare = ga_richcompare, - .tp_weaklistoffset = offsetof(gaobject, weakreflist), - .tp_methods = ga_methods, - .tp_members = ga_members, - .tp_alloc = PyType_GenericAlloc, - .tp_new = ga_new, - .tp_free = PyObject_GC_Del, - .tp_getset = ga_properties, -}; - -PyObject * -Py_GenericAlias(PyObject *origin, PyObject *args) -{ - gaobject *alias = (gaobject*) PyType_GenericAlloc( - (PyTypeObject *)&Py_GenericAliasType, 0); - if (alias == NULL) { - return NULL; - } - if (!setup_ga(alias, origin, args)) { - Py_DECREF(alias); - return NULL; - } - return (PyObject *)alias; -} +// types.GenericAlias -- used to represent e.g. list[int]. + +#include "Python.h" +#include "pycore_object.h" +#include "structmember.h" // PyMemberDef + +typedef struct { + PyObject_HEAD + PyObject *origin; + PyObject *args; + PyObject *parameters; + PyObject* weakreflist; +} gaobject; + +static void +ga_dealloc(PyObject *self) +{ + gaobject *alias = (gaobject *)self; + + _PyObject_GC_UNTRACK(self); + if (alias->weakreflist != NULL) { + PyObject_ClearWeakRefs((PyObject *)alias); + } + Py_XDECREF(alias->origin); + Py_XDECREF(alias->args); + Py_XDECREF(alias->parameters); + self->ob_type->tp_free(self); +} + +static int +ga_traverse(PyObject *self, visitproc visit, void *arg) +{ + gaobject *alias = (gaobject *)self; + Py_VISIT(alias->origin); + Py_VISIT(alias->args); + Py_VISIT(alias->parameters); + return 0; +} + +static int +ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) +{ + _Py_IDENTIFIER(__module__); + _Py_IDENTIFIER(__qualname__); + _Py_IDENTIFIER(__origin__); + _Py_IDENTIFIER(__args__); + PyObject *qualname = NULL; + PyObject *module = NULL; + PyObject *r = NULL; + PyObject *tmp; + int err; + + if (p == Py_Ellipsis) { + // The Ellipsis object + r = PyUnicode_FromString("..."); + goto done; + } + + if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { + goto done; + } + if (tmp != NULL) { + Py_DECREF(tmp); + if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { + goto done; + } + if (tmp != NULL) { + Py_DECREF(tmp); + // It looks like a GenericAlias + goto use_repr; + } + } + + if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) { + goto done; + } + if (qualname == NULL) { + goto use_repr; + } + if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) { + goto done; + } + if (module == NULL || module == Py_None) { + goto use_repr; + } + + // Looks like a class + if (PyUnicode_Check(module) && + _PyUnicode_EqualToASCIIString(module, "builtins")) + { + // builtins don't need a module name + r = PyObject_Str(qualname); + goto done; + } + else { + r = PyUnicode_FromFormat("%S.%S", module, qualname); + goto done; + } + +use_repr: + r = PyObject_Repr(p); + +done: + Py_XDECREF(qualname); + Py_XDECREF(module); + if (r == NULL) { + // error if any of the above PyObject_Repr/PyUnicode_From* fail + err = -1; + } + else { + err = _PyUnicodeWriter_WriteStr(writer, r); + Py_DECREF(r); + } + return err; +} + +static PyObject * +ga_repr(PyObject *self) +{ + gaobject *alias = (gaobject *)self; + Py_ssize_t len = PyTuple_GET_SIZE(alias->args); + + _PyUnicodeWriter writer; + _PyUnicodeWriter_Init(&writer); + + if (ga_repr_item(&writer, alias->origin) < 0) { + goto error; + } + if (_PyUnicodeWriter_WriteASCIIString(&writer, "[", 1) < 0) { + goto error; + } + for (Py_ssize_t i = 0; i < len; i++) { + if (i > 0) { + if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { + goto error; + } + } + PyObject *p = PyTuple_GET_ITEM(alias->args, i); + if (ga_repr_item(&writer, p) < 0) { + goto error; + } + } + if (len == 0) { + // for something like tuple[()] we should print a "()" + if (_PyUnicodeWriter_WriteASCIIString(&writer, "()", 2) < 0) { + goto error; + } + } + if (_PyUnicodeWriter_WriteASCIIString(&writer, "]", 1) < 0) { + goto error; + } + return _PyUnicodeWriter_Finish(&writer); +error: + _PyUnicodeWriter_Dealloc(&writer); + return NULL; +} + +// isinstance(obj, TypeVar) without importing typing.py. +// Returns -1 for errors. +static int +is_typevar(PyObject *obj) +{ + PyTypeObject *type = Py_TYPE(obj); + if (strcmp(type->tp_name, "TypeVar") != 0) { + return 0; + } + PyObject *module = PyObject_GetAttrString((PyObject *)type, "__module__"); + if (module == NULL) { + return -1; + } + int res = PyUnicode_Check(module) + && _PyUnicode_EqualToASCIIString(module, "typing"); + Py_DECREF(module); + return res; +} + +// Index of item in self[:len], or -1 if not found (self is a tuple) +static Py_ssize_t +tuple_index(PyObject *self, Py_ssize_t len, PyObject *item) +{ + for (Py_ssize_t i = 0; i < len; i++) { + if (PyTuple_GET_ITEM(self, i) == item) { + return i; + } + } + return -1; +} + +static int +tuple_add(PyObject *self, Py_ssize_t len, PyObject *item) +{ + if (tuple_index(self, len, item) < 0) { + Py_INCREF(item); + PyTuple_SET_ITEM(self, len, item); + return 1; + } + return 0; +} + +static PyObject * +make_parameters(PyObject *args) +{ + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t len = nargs; + PyObject *parameters = PyTuple_New(len); + if (parameters == NULL) + return NULL; + Py_ssize_t iparam = 0; + for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { + PyObject *t = PyTuple_GET_ITEM(args, iarg); + int typevar = is_typevar(t); + if (typevar < 0) { + Py_DECREF(parameters); + return NULL; + } + if (typevar) { + iparam += tuple_add(parameters, iparam, t); + } + else { + _Py_IDENTIFIER(__parameters__); + PyObject *subparams; + if (_PyObject_LookupAttrId(t, &PyId___parameters__, &subparams) < 0) { + Py_DECREF(parameters); + return NULL; + } + if (subparams && PyTuple_Check(subparams)) { + Py_ssize_t len2 = PyTuple_GET_SIZE(subparams); + Py_ssize_t needed = len2 - 1 - (iarg - iparam); + if (needed > 0) { + len += needed; + if (_PyTuple_Resize(¶meters, len) < 0) { + Py_DECREF(subparams); + Py_DECREF(parameters); + return NULL; + } + } + for (Py_ssize_t j = 0; j < len2; j++) { + PyObject *t2 = PyTuple_GET_ITEM(subparams, j); + iparam += tuple_add(parameters, iparam, t2); + } + } + Py_XDECREF(subparams); + } + } + if (iparam < len) { + if (_PyTuple_Resize(¶meters, iparam) < 0) { + Py_XDECREF(parameters); + return NULL; + } + } + return parameters; +} + +/* If obj is a generic alias, substitute type variables params + with substitutions argitems. For example, if obj is list[T], + params is (T, S), and argitems is (str, int), return list[str]. + If obj doesn't have a __parameters__ attribute or that's not + a non-empty tuple, return a new reference to obj. */ +static PyObject * +subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) +{ + _Py_IDENTIFIER(__parameters__); + PyObject *subparams; + if (_PyObject_LookupAttrId(obj, &PyId___parameters__, &subparams) < 0) { + return NULL; + } + if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { + Py_ssize_t nparams = PyTuple_GET_SIZE(params); + Py_ssize_t nsubargs = PyTuple_GET_SIZE(subparams); + PyObject *subargs = PyTuple_New(nsubargs); + if (subargs == NULL) { + Py_DECREF(subparams); + return NULL; + } + for (Py_ssize_t i = 0; i < nsubargs; ++i) { + PyObject *arg = PyTuple_GET_ITEM(subparams, i); + Py_ssize_t iparam = tuple_index(params, nparams, arg); + if (iparam >= 0) { + arg = argitems[iparam]; + } + Py_INCREF(arg); + PyTuple_SET_ITEM(subargs, i, arg); + } + + obj = PyObject_GetItem(obj, subargs); + + Py_DECREF(subargs); + } + else { + Py_INCREF(obj); + } + Py_XDECREF(subparams); + return obj; +} + +static PyObject * +ga_getitem(PyObject *self, PyObject *item) +{ + gaobject *alias = (gaobject *)self; + // do a lookup for __parameters__ so it gets populated (if not already) + if (alias->parameters == NULL) { + alias->parameters = make_parameters(alias->args); + if (alias->parameters == NULL) { + return NULL; + } + } + Py_ssize_t nparams = PyTuple_GET_SIZE(alias->parameters); + if (nparams == 0) { + return PyErr_Format(PyExc_TypeError, + "There are no type variables left in %R", + self); + } + int is_tuple = PyTuple_Check(item); + Py_ssize_t nitems = is_tuple ? PyTuple_GET_SIZE(item) : 1; + PyObject **argitems = is_tuple ? &PyTuple_GET_ITEM(item, 0) : &item; + if (nitems != nparams) { + return PyErr_Format(PyExc_TypeError, + "Too %s arguments for %R", + nitems > nparams ? "many" : "few", + self); + } + /* Replace all type variables (specified by alias->parameters) + with corresponding values specified by argitems. + t = list[T]; t[int] -> newargs = [int] + t = dict[str, T]; t[int] -> newargs = [str, int] + t = dict[T, list[S]]; t[str, int] -> newargs = [str, list[int]] + */ + Py_ssize_t nargs = PyTuple_GET_SIZE(alias->args); + PyObject *newargs = PyTuple_New(nargs); + if (newargs == NULL) { + return NULL; + } + for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { + PyObject *arg = PyTuple_GET_ITEM(alias->args, iarg); + int typevar = is_typevar(arg); + if (typevar < 0) { + Py_DECREF(newargs); + return NULL; + } + if (typevar) { + Py_ssize_t iparam = tuple_index(alias->parameters, nparams, arg); + assert(iparam >= 0); + arg = argitems[iparam]; + Py_INCREF(arg); + } + else { + arg = subs_tvars(arg, alias->parameters, argitems); + if (arg == NULL) { + Py_DECREF(newargs); + return NULL; + } + } + PyTuple_SET_ITEM(newargs, iarg, arg); + } + + PyObject *res = Py_GenericAlias(alias->origin, newargs); + + Py_DECREF(newargs); + return res; +} + +static PyMappingMethods ga_as_mapping = { + .mp_subscript = ga_getitem, +}; + +static Py_hash_t +ga_hash(PyObject *self) +{ + gaobject *alias = (gaobject *)self; + // TODO: Hash in the hash for the origin + Py_hash_t h0 = PyObject_Hash(alias->origin); + if (h0 == -1) { + return -1; + } + Py_hash_t h1 = PyObject_Hash(alias->args); + if (h1 == -1) { + return -1; + } + return h0 ^ h1; +} + +static PyObject * +ga_call(PyObject *self, PyObject *args, PyObject *kwds) +{ + gaobject *alias = (gaobject *)self; + PyObject *obj = PyObject_Call(alias->origin, args, kwds); + if (obj != NULL) { + if (PyObject_SetAttrString(obj, "__orig_class__", self) < 0) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError) && + !PyErr_ExceptionMatches(PyExc_TypeError)) + { + Py_DECREF(obj); + return NULL; + } + PyErr_Clear(); + } + } + return obj; +} + +static const char* const attr_exceptions[] = { + "__origin__", + "__args__", + "__parameters__", + "__mro_entries__", + "__reduce_ex__", // needed so we don't look up object.__reduce_ex__ + "__reduce__", + "__copy__", + "__deepcopy__", + NULL, +}; + +static PyObject * +ga_getattro(PyObject *self, PyObject *name) +{ + gaobject *alias = (gaobject *)self; + if (PyUnicode_Check(name)) { + for (const char * const *p = attr_exceptions; ; p++) { + if (*p == NULL) { + return PyObject_GetAttr(alias->origin, name); + } + if (_PyUnicode_EqualToASCIIString(name, *p)) { + break; + } + } + } + return PyObject_GenericGetAttr(self, name); +} + +static PyObject * +ga_richcompare(PyObject *a, PyObject *b, int op) +{ + if (!PyObject_TypeCheck(a, &Py_GenericAliasType) || + !PyObject_TypeCheck(b, &Py_GenericAliasType) || + (op != Py_EQ && op != Py_NE)) + { + Py_RETURN_NOTIMPLEMENTED; + } + + if (op == Py_NE) { + PyObject *eq = ga_richcompare(a, b, Py_EQ); + if (eq == NULL) + return NULL; + Py_DECREF(eq); + if (eq == Py_True) { + Py_RETURN_FALSE; + } + else { + Py_RETURN_TRUE; + } + } + + gaobject *aa = (gaobject *)a; + gaobject *bb = (gaobject *)b; + int eq = PyObject_RichCompareBool(aa->origin, bb->origin, Py_EQ); + if (eq < 0) { + return NULL; + } + if (!eq) { + Py_RETURN_FALSE; + } + return PyObject_RichCompare(aa->args, bb->args, Py_EQ); +} + +static PyObject * +ga_mro_entries(PyObject *self, PyObject *args) +{ + gaobject *alias = (gaobject *)self; + return PyTuple_Pack(1, alias->origin); +} + +static PyObject * +ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyErr_SetString(PyExc_TypeError, + "isinstance() argument 2 cannot be a parameterized generic"); + return NULL; +} + +static PyObject * +ga_subclasscheck(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyErr_SetString(PyExc_TypeError, + "issubclass() argument 2 cannot be a parameterized generic"); + return NULL; +} + +static PyObject * +ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + gaobject *alias = (gaobject *)self; + return Py_BuildValue("O(OO)", Py_TYPE(alias), + alias->origin, alias->args); +} + +static PyObject * +ga_dir(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + gaobject *alias = (gaobject *)self; + PyObject *dir = PyObject_Dir(alias->origin); + if (dir == NULL) { + return NULL; + } + + PyObject *dir_entry = NULL; + for (const char * const *p = attr_exceptions; ; p++) { + if (*p == NULL) { + break; + } + else { + dir_entry = PyUnicode_FromString(*p); + if (dir_entry == NULL) { + goto error; + } + int contains = PySequence_Contains(dir, dir_entry); + if (contains < 0) { + goto error; + } + if (contains == 0 && PyList_Append(dir, dir_entry) < 0) { + goto error; + } + + Py_CLEAR(dir_entry); + } + } + return dir; + +error: + Py_DECREF(dir); + Py_XDECREF(dir_entry); + return NULL; +} + +static PyMethodDef ga_methods[] = { + {"__mro_entries__", ga_mro_entries, METH_O}, + {"__instancecheck__", ga_instancecheck, METH_O}, + {"__subclasscheck__", ga_subclasscheck, METH_O}, + {"__reduce__", ga_reduce, METH_NOARGS}, + {"__dir__", ga_dir, METH_NOARGS}, + {0} +}; + +static PyMemberDef ga_members[] = { + {"__origin__", T_OBJECT, offsetof(gaobject, origin), READONLY}, + {"__args__", T_OBJECT, offsetof(gaobject, args), READONLY}, + {0} +}; + +static PyObject * +ga_parameters(PyObject *self, void *unused) +{ + gaobject *alias = (gaobject *)self; + if (alias->parameters == NULL) { + alias->parameters = make_parameters(alias->args); + if (alias->parameters == NULL) { + return NULL; + } + } + Py_INCREF(alias->parameters); + return alias->parameters; +} + +static PyGetSetDef ga_properties[] = { + {"__parameters__", ga_parameters, (setter)NULL, "Type variables in the GenericAlias.", NULL}, + {0} +}; + +/* A helper function to create GenericAlias' args tuple and set its attributes. + * Returns 1 on success, 0 on failure. + */ +static inline int +setup_ga(gaobject *alias, PyObject *origin, PyObject *args) { + if (!PyTuple_Check(args)) { + args = PyTuple_Pack(1, args); + if (args == NULL) { + return 0; + } + } + else { + Py_INCREF(args); + } + + Py_INCREF(origin); + alias->origin = origin; + alias->args = args; + alias->parameters = NULL; + alias->weakreflist = NULL; + return 1; +} + +static PyObject * +ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + if (!_PyArg_NoKeywords("GenericAlias", kwds)) { + return NULL; + } + if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) { + return NULL; + } + PyObject *origin = PyTuple_GET_ITEM(args, 0); + PyObject *arguments = PyTuple_GET_ITEM(args, 1); + gaobject *self = (gaobject *)type->tp_alloc(type, 0); + if (self == NULL) { + return NULL; + } + if (!setup_ga(self, origin, arguments)) { + Py_DECREF(self); + return NULL; + } + return (PyObject *)self; +} + +// TODO: +// - argument clinic? +// - __doc__? +// - cache? +PyTypeObject Py_GenericAliasType = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + .tp_name = "types.GenericAlias", + .tp_doc = "Represent a PEP 585 generic type\n" + "\n" + "E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).", + .tp_basicsize = sizeof(gaobject), + .tp_dealloc = ga_dealloc, + .tp_repr = ga_repr, + .tp_as_mapping = &ga_as_mapping, + .tp_hash = ga_hash, + .tp_call = ga_call, + .tp_getattro = ga_getattro, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + .tp_traverse = ga_traverse, + .tp_richcompare = ga_richcompare, + .tp_weaklistoffset = offsetof(gaobject, weakreflist), + .tp_methods = ga_methods, + .tp_members = ga_members, + .tp_alloc = PyType_GenericAlloc, + .tp_new = ga_new, + .tp_free = PyObject_GC_Del, + .tp_getset = ga_properties, +}; + +PyObject * +Py_GenericAlias(PyObject *origin, PyObject *args) +{ + gaobject *alias = (gaobject*) PyType_GenericAlloc( + (PyTypeObject *)&Py_GenericAliasType, 0); + if (alias == NULL) { + return NULL; + } + if (!setup_ga(alias, origin, args)) { + Py_DECREF(alias); + return NULL; + } + return (PyObject *)alias; +} diff --git a/contrib/tools/python3/src/Objects/genobject.c b/contrib/tools/python3/src/Objects/genobject.c index 12dbd7889b..5ba4de82ea 100644 --- a/contrib/tools/python3/src/Objects/genobject.c +++ b/contrib/tools/python3/src/Objects/genobject.c @@ -1,22 +1,22 @@ /* Generator object implementation */ #include "Python.h" -#include "pycore_ceval.h" // _PyEval_EvalFrame() -#include "pycore_object.h" -#include "pycore_pyerrors.h" // _PyErr_ClearExcState() -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_ceval.h" // _PyEval_EvalFrame() +#include "pycore_object.h" +#include "pycore_pyerrors.h" // _PyErr_ClearExcState() +#include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef #include "opcode.h" static PyObject *gen_close(PyGenObject *, PyObject *); static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *); static PyObject *async_gen_athrow_new(PyAsyncGenObject *, PyObject *); -static const char *NON_INIT_CORO_MSG = "can't send non-None value to a " +static const char *NON_INIT_CORO_MSG = "can't send non-None value to a " "just-started coroutine"; -static const char *ASYNC_GEN_IGNORED_EXIT_MSG = +static const char *ASYNC_GEN_IGNORED_EXIT_MSG = "async generator ignored GeneratorExit"; static inline int @@ -59,7 +59,7 @@ _PyGen_Finalize(PyObject *self) /* Save the current exception, if any. */ PyErr_Fetch(&error_type, &error_value, &error_traceback); - res = PyObject_CallOneArg(finalizer, self); + res = PyObject_CallOneArg(finalizer, self); if (res == NULL) { PyErr_WriteUnraisable(self); @@ -132,14 +132,14 @@ gen_dealloc(PyGenObject *gen) Py_CLEAR(gen->gi_code); Py_CLEAR(gen->gi_name); Py_CLEAR(gen->gi_qualname); - _PyErr_ClearExcState(&gen->gi_exc_state); + _PyErr_ClearExcState(&gen->gi_exc_state); PyObject_GC_Del(gen); } static PyObject * gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyFrameObject *f = gen->gi_frame; PyObject *result; @@ -206,13 +206,13 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) gen->gi_running = 1; gen->gi_exc_state.previous_item = tstate->exc_info; tstate->exc_info = &gen->gi_exc_state; - - if (exc) { - assert(_PyErr_Occurred(tstate)); - _PyErr_ChainStackItem(NULL); - } - - result = _PyEval_EvalFrame(tstate, f, exc); + + if (exc) { + assert(_PyErr_Occurred(tstate)); + _PyErr_ChainStackItem(NULL); + } + + result = _PyEval_EvalFrame(tstate, f, exc); tstate->exc_info = gen->gi_exc_state.previous_item; gen->gi_exc_state.previous_item = NULL; gen->gi_running = 0; @@ -247,7 +247,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) if (PyCoro_CheckExact(gen)) { msg = "coroutine raised StopIteration"; } - else if (PyAsyncGen_CheckExact(gen)) { + else if (PyAsyncGen_CheckExact(gen)) { msg = "async generator raised StopIteration"; } _PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg); @@ -266,7 +266,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) if (!result || f->f_stacktop == NULL) { /* generator can't be rerun, so release the frame */ /* first clean reference cycle through stored exception traceback */ - _PyErr_ClearExcState(&gen->gi_exc_state); + _PyErr_ClearExcState(&gen->gi_exc_state); gen->gi_frame->f_gen = NULL; gen->gi_frame = NULL; Py_DECREF(f); @@ -414,21 +414,21 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, } if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { /* `yf` is a generator or a coroutine. */ - PyThreadState *tstate = _PyThreadState_GET(); - PyFrameObject *f = tstate->frame; - + PyThreadState *tstate = _PyThreadState_GET(); + PyFrameObject *f = tstate->frame; + gen->gi_running = 1; - /* Since we are fast-tracking things by skipping the eval loop, - we need to update the current frame so the stack trace - will be reported correctly to the user. */ - /* XXX We should probably be updating the current frame - somewhere in ceval.c. */ - tstate->frame = gen->gi_frame; + /* Since we are fast-tracking things by skipping the eval loop, + we need to update the current frame so the stack trace + will be reported correctly to the user. */ + /* XXX We should probably be updating the current frame + somewhere in ceval.c. */ + tstate->frame = gen->gi_frame; /* Close the generator that we are currently iterating with 'yield from' or awaiting on with 'await'. */ ret = _gen_throw((PyGenObject *)yf, close_on_genexit, typ, val, tb); - tstate->frame = f; + tstate->frame = f; gen->gi_running = 0; } else { /* `yf` is an iterator or a coroutine-like object. */ @@ -565,7 +565,7 @@ _PyGen_SetStopIterationValue(PyObject *value) return 0; } /* Construct an exception instance manually with - * PyObject_CallOneArg and pass it to PyErr_SetObject. + * PyObject_CallOneArg and pass it to PyErr_SetObject. * * We do this to handle a situation when "value" is a tuple, in which * case PyErr_SetObject would set the value of StopIteration to @@ -573,7 +573,7 @@ _PyGen_SetStopIterationValue(PyObject *value) * * (See PyErr_SetObject/_PyErr_CreateException code for details.) */ - e = PyObject_CallOneArg(PyExc_StopIteration, value); + e = PyObject_CallOneArg(PyExc_StopIteration, value); if (e == NULL) { return -1; } @@ -711,9 +711,9 @@ static PyGetSetDef gen_getsetlist[] = { }; static PyMemberDef gen_memberlist[] = { - {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), READONLY|READ_RESTRICTED}, + {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), READONLY|READ_RESTRICTED}, {"gi_running", T_BOOL, offsetof(PyGenObject, gi_running), READONLY}, - {"gi_code", T_OBJECT, offsetof(PyGenObject, gi_code), READONLY|READ_RESTRICTED}, + {"gi_code", T_OBJECT, offsetof(PyGenObject, gi_code), READONLY|READ_RESTRICTED}, {NULL} /* Sentinel */ }; @@ -731,7 +731,7 @@ PyTypeObject PyGen_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_as_async */ @@ -745,7 +745,7 @@ PyTypeObject PyGen_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ 0, /* tp_doc */ (traverseproc)gen_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -931,9 +931,9 @@ static PyGetSetDef coro_getsetlist[] = { }; static PyMemberDef coro_memberlist[] = { - {"cr_frame", T_OBJECT, offsetof(PyCoroObject, cr_frame), READONLY|READ_RESTRICTED}, + {"cr_frame", T_OBJECT, offsetof(PyCoroObject, cr_frame), READONLY|READ_RESTRICTED}, {"cr_running", T_BOOL, offsetof(PyCoroObject, cr_running), READONLY}, - {"cr_code", T_OBJECT, offsetof(PyCoroObject, cr_code), READONLY|READ_RESTRICTED}, + {"cr_code", T_OBJECT, offsetof(PyCoroObject, cr_code), READONLY|READ_RESTRICTED}, {"cr_origin", T_OBJECT, offsetof(PyCoroObject, cr_origin), READONLY}, {NULL} /* Sentinel */ }; @@ -969,7 +969,7 @@ PyTypeObject PyCoro_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ &coro_as_async, /* tp_as_async */ @@ -983,7 +983,7 @@ PyTypeObject PyCoro_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ 0, /* tp_doc */ (traverseproc)gen_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -1066,7 +1066,7 @@ PyTypeObject _PyCoroWrapper_Type = { sizeof(PyCoroWrapper), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)coro_wrapper_dealloc, /* destructor tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_as_async */ @@ -1119,11 +1119,11 @@ compute_cr_origin(int origin_depth) } frame = PyEval_GetFrame(); for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = frame->f_code; - PyObject *frameinfo = Py_BuildValue("OiO", - code->co_filename, - PyFrame_GetLineNumber(frame), - code->co_name); + PyCodeObject *code = frame->f_code; + PyObject *frameinfo = Py_BuildValue("OiO", + code->co_filename, + PyFrame_GetLineNumber(frame), + code->co_name); if (!frameinfo) { Py_DECREF(cr_origin); return NULL; @@ -1143,7 +1143,7 @@ PyCoro_New(PyFrameObject *f, PyObject *name, PyObject *qualname) return NULL; } - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); int origin_depth = tstate->coroutine_origin_tracking_depth; if (origin_depth == 0) { @@ -1218,10 +1218,10 @@ static PyAsyncGenASend *ag_asend_freelist[_PyAsyncGen_MAXFREELIST]; static int ag_asend_freelist_free = 0; #define _PyAsyncGenWrappedValue_CheckExact(o) \ - Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type) + Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type) #define PyAsyncGenASend_CheckExact(o) \ - Py_IS_TYPE(o, &_PyAsyncGenASend_Type) + Py_IS_TYPE(o, &_PyAsyncGenASend_Type) static int @@ -1253,7 +1253,7 @@ async_gen_init_hooks(PyAsyncGenObject *o) o->ag_hooks_inited = 1; - tstate = _PyThreadState_GET(); + tstate = _PyThreadState_GET(); finalizer = tstate->async_gen_finalizer; if (finalizer) { @@ -1266,7 +1266,7 @@ async_gen_init_hooks(PyAsyncGenObject *o) PyObject *res; Py_INCREF(firstiter); - res = PyObject_CallOneArg(firstiter, (PyObject *)o); + res = PyObject_CallOneArg(firstiter, (PyObject *)o); Py_DECREF(firstiter); if (res == NULL) { return 1; @@ -1328,12 +1328,12 @@ static PyGetSetDef async_gen_getsetlist[] = { }; static PyMemberDef async_gen_memberlist[] = { - {"ag_frame", T_OBJECT, offsetof(PyAsyncGenObject, ag_frame), - READONLY|READ_RESTRICTED}, - {"ag_running", T_BOOL, offsetof(PyAsyncGenObject, ag_running_async), - READONLY}, - {"ag_code", T_OBJECT, offsetof(PyAsyncGenObject, ag_code), - READONLY|READ_RESTRICTED}, + {"ag_frame", T_OBJECT, offsetof(PyAsyncGenObject, ag_frame), + READONLY|READ_RESTRICTED}, + {"ag_running", T_BOOL, offsetof(PyAsyncGenObject, ag_running_async), + READONLY}, + {"ag_code", T_OBJECT, offsetof(PyAsyncGenObject, ag_code), + READONLY|READ_RESTRICTED}, {NULL} /* Sentinel */ }; @@ -1350,8 +1350,8 @@ static PyMethodDef async_gen_methods[] = { {"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc}, {"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc}, {"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc}, - {"__class_getitem__", (PyCFunction)Py_GenericAlias, - METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* Sentinel */ }; @@ -1370,7 +1370,7 @@ PyTypeObject PyAsyncGen_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ &async_gen_as_async, /* tp_as_async */ @@ -1384,7 +1384,7 @@ PyTypeObject PyAsyncGen_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ 0, /* tp_doc */ (traverseproc)async_gen_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -1428,13 +1428,13 @@ PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname) o->ag_finalizer = NULL; o->ag_closed = 0; o->ag_hooks_inited = 0; - o->ag_running_async = 0; + o->ag_running_async = 0; return (PyObject*)o; } -void -_PyAsyncGen_ClearFreeLists(void) +void +_PyAsyncGen_ClearFreeLists(void) { while (ag_value_freelist_free) { _PyAsyncGenWrappedValue *o; @@ -1446,15 +1446,15 @@ _PyAsyncGen_ClearFreeLists(void) while (ag_asend_freelist_free) { PyAsyncGenASend *o; o = ag_asend_freelist[--ag_asend_freelist_free]; - assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type)); + assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type)); PyObject_GC_Del(o); } } void -_PyAsyncGen_Fini(void) +_PyAsyncGen_Fini(void) { - _PyAsyncGen_ClearFreeLists(); + _PyAsyncGen_ClearFreeLists(); } @@ -1472,7 +1472,7 @@ async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result) gen->ag_closed = 1; } - gen->ag_running_async = 0; + gen->ag_running_async = 0; return NULL; } @@ -1480,7 +1480,7 @@ async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result) /* async yield */ _PyGen_SetStopIterationValue(((_PyAsyncGenWrappedValue*)result)->agw_val); Py_DECREF(result); - gen->ag_running_async = 0; + gen->ag_running_async = 0; return NULL; } @@ -1520,27 +1520,27 @@ async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg) PyObject *result; if (o->ags_state == AWAITABLE_STATE_CLOSED) { - PyErr_SetString( - PyExc_RuntimeError, - "cannot reuse already awaited __anext__()/asend()"); + PyErr_SetString( + PyExc_RuntimeError, + "cannot reuse already awaited __anext__()/asend()"); return NULL; } if (o->ags_state == AWAITABLE_STATE_INIT) { - if (o->ags_gen->ag_running_async) { - PyErr_SetString( - PyExc_RuntimeError, - "anext(): asynchronous generator is already running"); - return NULL; - } - + if (o->ags_gen->ag_running_async) { + PyErr_SetString( + PyExc_RuntimeError, + "anext(): asynchronous generator is already running"); + return NULL; + } + if (arg == NULL || arg == Py_None) { arg = o->ags_sendval; } o->ags_state = AWAITABLE_STATE_ITER; } - o->ags_gen->ag_running_async = 1; + o->ags_gen->ag_running_async = 1; result = gen_send_ex((PyGenObject*)o->ags_gen, arg, 0, 0); result = async_gen_unwrap_value(o->ags_gen, result); @@ -1565,9 +1565,9 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *args) PyObject *result; if (o->ags_state == AWAITABLE_STATE_CLOSED) { - PyErr_SetString( - PyExc_RuntimeError, - "cannot reuse already awaited __anext__()/asend()"); + PyErr_SetString( + PyExc_RuntimeError, + "cannot reuse already awaited __anext__()/asend()"); return NULL; } @@ -1612,7 +1612,7 @@ PyTypeObject _PyAsyncGenASend_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)async_gen_asend_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ &async_gen_asend_as_async, /* tp_as_async */ @@ -1709,7 +1709,7 @@ PyTypeObject _PyAsyncGenWrappedValue_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)async_gen_wrapped_val_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_as_async */ @@ -1799,38 +1799,38 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) PyFrameObject *f = gen->gi_frame; PyObject *retval; - if (o->agt_state == AWAITABLE_STATE_CLOSED) { - PyErr_SetString( - PyExc_RuntimeError, - "cannot reuse already awaited aclose()/athrow()"); - return NULL; - } - - if (f == NULL || f->f_stacktop == NULL) { - o->agt_state = AWAITABLE_STATE_CLOSED; + if (o->agt_state == AWAITABLE_STATE_CLOSED) { + PyErr_SetString( + PyExc_RuntimeError, + "cannot reuse already awaited aclose()/athrow()"); + return NULL; + } + + if (f == NULL || f->f_stacktop == NULL) { + o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; } if (o->agt_state == AWAITABLE_STATE_INIT) { - if (o->agt_gen->ag_running_async) { - o->agt_state = AWAITABLE_STATE_CLOSED; - if (o->agt_args == NULL) { - PyErr_SetString( - PyExc_RuntimeError, - "aclose(): asynchronous generator is already running"); - } - else { - PyErr_SetString( - PyExc_RuntimeError, - "athrow(): asynchronous generator is already running"); - } - return NULL; - } - + if (o->agt_gen->ag_running_async) { + o->agt_state = AWAITABLE_STATE_CLOSED; + if (o->agt_args == NULL) { + PyErr_SetString( + PyExc_RuntimeError, + "aclose(): asynchronous generator is already running"); + } + else { + PyErr_SetString( + PyExc_RuntimeError, + "athrow(): asynchronous generator is already running"); + } + return NULL; + } + if (o->agt_gen->ag_closed) { - o->agt_state = AWAITABLE_STATE_CLOSED; - PyErr_SetNone(PyExc_StopAsyncIteration); + o->agt_state = AWAITABLE_STATE_CLOSED; + PyErr_SetNone(PyExc_StopAsyncIteration); return NULL; } @@ -1840,7 +1840,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) } o->agt_state = AWAITABLE_STATE_ITER; - o->agt_gen->ag_running_async = 1; + o->agt_gen->ag_running_async = 1; if (o->agt_args == NULL) { /* aclose() mode */ @@ -1899,24 +1899,24 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) } yield_close: - o->agt_gen->ag_running_async = 0; - o->agt_state = AWAITABLE_STATE_CLOSED; + o->agt_gen->ag_running_async = 0; + o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetString( PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG); return NULL; check_error: - o->agt_gen->ag_running_async = 0; - o->agt_state = AWAITABLE_STATE_CLOSED; - if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || - PyErr_ExceptionMatches(PyExc_GeneratorExit)) - { + o->agt_gen->ag_running_async = 0; + o->agt_state = AWAITABLE_STATE_CLOSED; + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || + PyErr_ExceptionMatches(PyExc_GeneratorExit)) + { if (o->agt_args == NULL) { /* when aclose() is called we don't want to propagate - StopAsyncIteration or GeneratorExit; just raise - StopIteration, signalling that this 'aclose()' await - is done. - */ + StopAsyncIteration or GeneratorExit; just raise + StopIteration, signalling that this 'aclose()' await + is done. + */ PyErr_Clear(); PyErr_SetNone(PyExc_StopIteration); } @@ -1931,9 +1931,9 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args) PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { - PyErr_SetString( - PyExc_RuntimeError, - "cannot reuse already awaited aclose()/athrow()"); + PyErr_SetString( + PyExc_RuntimeError, + "cannot reuse already awaited aclose()/athrow()"); return NULL; } @@ -1943,23 +1943,23 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args) } else { /* aclose() mode */ if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) { - o->agt_gen->ag_running_async = 0; - o->agt_state = AWAITABLE_STATE_CLOSED; + o->agt_gen->ag_running_async = 0; + o->agt_state = AWAITABLE_STATE_CLOSED; Py_DECREF(retval); PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG); return NULL; } - if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || - PyErr_ExceptionMatches(PyExc_GeneratorExit)) - { - /* when aclose() is called we don't want to propagate - StopAsyncIteration or GeneratorExit; just raise - StopIteration, signalling that this 'aclose()' await - is done. - */ - PyErr_Clear(); - PyErr_SetNone(PyExc_StopIteration); - } + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || + PyErr_ExceptionMatches(PyExc_GeneratorExit)) + { + /* when aclose() is called we don't want to propagate + StopAsyncIteration or GeneratorExit; just raise + StopIteration, signalling that this 'aclose()' await + is done. + */ + PyErr_Clear(); + PyErr_SetNone(PyExc_StopIteration); + } return retval; } } @@ -2002,7 +2002,7 @@ PyTypeObject _PyAsyncGenAThrow_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)async_gen_athrow_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ &async_gen_athrow_as_async, /* tp_as_async */ diff --git a/contrib/tools/python3/src/Objects/interpreteridobject.c b/contrib/tools/python3/src/Objects/interpreteridobject.c index ded247f9a4..39bde97269 100644 --- a/contrib/tools/python3/src/Objects/interpreteridobject.c +++ b/contrib/tools/python3/src/Objects/interpreteridobject.c @@ -1,288 +1,288 @@ -/* InterpreterID object */ - -#include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_interp.h" // _PyInterpreterState_LookUpID() -#include "interpreteridobject.h" - - -typedef struct interpid { - PyObject_HEAD - int64_t id; -} interpid; - -static interpid * -newinterpid(PyTypeObject *cls, int64_t id, int force) -{ - PyInterpreterState *interp = _PyInterpreterState_LookUpID(id); - if (interp == NULL) { - if (force) { - PyErr_Clear(); - } - else { - return NULL; - } - } - - interpid *self = PyObject_New(interpid, cls); - if (self == NULL) { - return NULL; - } - self->id = id; - - if (interp != NULL) { - _PyInterpreterState_IDIncref(interp); - } - return self; -} - -static int -interp_id_converter(PyObject *arg, void *ptr) -{ - int64_t id; - if (PyObject_TypeCheck(arg, &_PyInterpreterID_Type)) { - id = ((interpid *)arg)->id; - } - else if (_PyIndex_Check(arg)) { - id = PyLong_AsLongLong(arg); - if (id == -1 && PyErr_Occurred()) { - return 0; - } - if (id < 0) { - PyErr_Format(PyExc_ValueError, - "interpreter ID must be a non-negative int, got %R", arg); - return 0; - } - } - else { - PyErr_Format(PyExc_TypeError, - "interpreter ID must be an int, got %.100s", - Py_TYPE(arg)->tp_name); - return 0; - } - *(int64_t *)ptr = id; - return 1; -} - -static PyObject * -interpid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds) -{ - static char *kwlist[] = {"id", "force", NULL}; - int64_t id; - int force = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, - "O&|$p:InterpreterID.__init__", kwlist, - interp_id_converter, &id, &force)) { - return NULL; - } - - return (PyObject *)newinterpid(cls, id, force); -} - -static void -interpid_dealloc(PyObject *v) -{ - int64_t id = ((interpid *)v)->id; - PyInterpreterState *interp = _PyInterpreterState_LookUpID(id); - if (interp != NULL) { - _PyInterpreterState_IDDecref(interp); - } - else { - // already deleted - PyErr_Clear(); - } - Py_TYPE(v)->tp_free(v); -} - -static PyObject * -interpid_repr(PyObject *self) -{ - PyTypeObject *type = Py_TYPE(self); - const char *name = _PyType_Name(type); - interpid *id = (interpid *)self; - return PyUnicode_FromFormat("%s(%" PRId64 ")", name, id->id); -} - -static PyObject * -interpid_str(PyObject *self) -{ - interpid *id = (interpid *)self; - return PyUnicode_FromFormat("%" PRId64 "", id->id); -} - -static PyObject * -interpid_int(PyObject *self) -{ - interpid *id = (interpid *)self; - return PyLong_FromLongLong(id->id); -} - -static PyNumberMethods interpid_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ - 0, /* nb_bool */ - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - 0, /* nb_or */ - (unaryfunc)interpid_int, /* nb_int */ - 0, /* nb_reserved */ - 0, /* nb_float */ - - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - - 0, /* nb_floor_divide */ - 0, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ - - (unaryfunc)interpid_int, /* nb_index */ -}; - -static Py_hash_t -interpid_hash(PyObject *self) -{ - interpid *id = (interpid *)self; - PyObject *obj = PyLong_FromLongLong(id->id); - if (obj == NULL) { - return -1; - } - Py_hash_t hash = PyObject_Hash(obj); - Py_DECREF(obj); - return hash; -} - -static PyObject * -interpid_richcompare(PyObject *self, PyObject *other, int op) -{ - if (op != Py_EQ && op != Py_NE) { - Py_RETURN_NOTIMPLEMENTED; - } - - if (!PyObject_TypeCheck(self, &_PyInterpreterID_Type)) { - Py_RETURN_NOTIMPLEMENTED; - } - - interpid *id = (interpid *)self; - int equal; - if (PyObject_TypeCheck(other, &_PyInterpreterID_Type)) { - interpid *otherid = (interpid *)other; - equal = (id->id == otherid->id); - } - else if (PyLong_CheckExact(other)) { - /* Fast path */ - int overflow; - long long otherid = PyLong_AsLongLongAndOverflow(other, &overflow); - if (otherid == -1 && PyErr_Occurred()) { - return NULL; - } - equal = !overflow && (otherid >= 0) && (id->id == otherid); - } - else if (PyNumber_Check(other)) { - PyObject *pyid = PyLong_FromLongLong(id->id); - if (pyid == NULL) { - return NULL; - } - PyObject *res = PyObject_RichCompare(pyid, other, op); - Py_DECREF(pyid); - return res; - } - else { - Py_RETURN_NOTIMPLEMENTED; - } - - if ((op == Py_EQ && equal) || (op == Py_NE && !equal)) { - Py_RETURN_TRUE; - } - Py_RETURN_FALSE; -} - -PyDoc_STRVAR(interpid_doc, -"A interpreter ID identifies a interpreter and may be used as an int."); - -PyTypeObject _PyInterpreterID_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "InterpreterID", /* tp_name */ - sizeof(interpid), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)interpid_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - (reprfunc)interpid_repr, /* tp_repr */ - &interpid_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - interpid_hash, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)interpid_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - interpid_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - interpid_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 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 */ - 0, /* tp_alloc */ - interpid_new, /* tp_new */ -}; - -PyObject *_PyInterpreterID_New(int64_t id) -{ - return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0); -} - -PyObject * -_PyInterpreterState_GetIDObject(PyInterpreterState *interp) -{ - if (_PyInterpreterState_IDInitref(interp) != 0) { - return NULL; - }; - int64_t id = PyInterpreterState_GetID(interp); - if (id < 0) { - return NULL; - } - return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0); -} - -PyInterpreterState * -_PyInterpreterID_LookUp(PyObject *requested_id) -{ - int64_t id; - if (!interp_id_converter(requested_id, &id)) { - return NULL; - } - return _PyInterpreterState_LookUpID(id); -} +/* InterpreterID object */ + +#include "Python.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_interp.h" // _PyInterpreterState_LookUpID() +#include "interpreteridobject.h" + + +typedef struct interpid { + PyObject_HEAD + int64_t id; +} interpid; + +static interpid * +newinterpid(PyTypeObject *cls, int64_t id, int force) +{ + PyInterpreterState *interp = _PyInterpreterState_LookUpID(id); + if (interp == NULL) { + if (force) { + PyErr_Clear(); + } + else { + return NULL; + } + } + + interpid *self = PyObject_New(interpid, cls); + if (self == NULL) { + return NULL; + } + self->id = id; + + if (interp != NULL) { + _PyInterpreterState_IDIncref(interp); + } + return self; +} + +static int +interp_id_converter(PyObject *arg, void *ptr) +{ + int64_t id; + if (PyObject_TypeCheck(arg, &_PyInterpreterID_Type)) { + id = ((interpid *)arg)->id; + } + else if (_PyIndex_Check(arg)) { + id = PyLong_AsLongLong(arg); + if (id == -1 && PyErr_Occurred()) { + return 0; + } + if (id < 0) { + PyErr_Format(PyExc_ValueError, + "interpreter ID must be a non-negative int, got %R", arg); + return 0; + } + } + else { + PyErr_Format(PyExc_TypeError, + "interpreter ID must be an int, got %.100s", + Py_TYPE(arg)->tp_name); + return 0; + } + *(int64_t *)ptr = id; + return 1; +} + +static PyObject * +interpid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"id", "force", NULL}; + int64_t id; + int force = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, + "O&|$p:InterpreterID.__init__", kwlist, + interp_id_converter, &id, &force)) { + return NULL; + } + + return (PyObject *)newinterpid(cls, id, force); +} + +static void +interpid_dealloc(PyObject *v) +{ + int64_t id = ((interpid *)v)->id; + PyInterpreterState *interp = _PyInterpreterState_LookUpID(id); + if (interp != NULL) { + _PyInterpreterState_IDDecref(interp); + } + else { + // already deleted + PyErr_Clear(); + } + Py_TYPE(v)->tp_free(v); +} + +static PyObject * +interpid_repr(PyObject *self) +{ + PyTypeObject *type = Py_TYPE(self); + const char *name = _PyType_Name(type); + interpid *id = (interpid *)self; + return PyUnicode_FromFormat("%s(%" PRId64 ")", name, id->id); +} + +static PyObject * +interpid_str(PyObject *self) +{ + interpid *id = (interpid *)self; + return PyUnicode_FromFormat("%" PRId64 "", id->id); +} + +static PyObject * +interpid_int(PyObject *self) +{ + interpid *id = (interpid *)self; + return PyLong_FromLongLong(id->id); +} + +static PyNumberMethods interpid_as_number = { + 0, /* nb_add */ + 0, /* nb_subtract */ + 0, /* nb_multiply */ + 0, /* nb_remainder */ + 0, /* nb_divmod */ + 0, /* nb_power */ + 0, /* nb_negative */ + 0, /* nb_positive */ + 0, /* nb_absolute */ + 0, /* nb_bool */ + 0, /* nb_invert */ + 0, /* nb_lshift */ + 0, /* nb_rshift */ + 0, /* nb_and */ + 0, /* nb_xor */ + 0, /* nb_or */ + (unaryfunc)interpid_int, /* nb_int */ + 0, /* nb_reserved */ + 0, /* nb_float */ + + 0, /* nb_inplace_add */ + 0, /* nb_inplace_subtract */ + 0, /* nb_inplace_multiply */ + 0, /* nb_inplace_remainder */ + 0, /* nb_inplace_power */ + 0, /* nb_inplace_lshift */ + 0, /* nb_inplace_rshift */ + 0, /* nb_inplace_and */ + 0, /* nb_inplace_xor */ + 0, /* nb_inplace_or */ + + 0, /* nb_floor_divide */ + 0, /* nb_true_divide */ + 0, /* nb_inplace_floor_divide */ + 0, /* nb_inplace_true_divide */ + + (unaryfunc)interpid_int, /* nb_index */ +}; + +static Py_hash_t +interpid_hash(PyObject *self) +{ + interpid *id = (interpid *)self; + PyObject *obj = PyLong_FromLongLong(id->id); + if (obj == NULL) { + return -1; + } + Py_hash_t hash = PyObject_Hash(obj); + Py_DECREF(obj); + return hash; +} + +static PyObject * +interpid_richcompare(PyObject *self, PyObject *other, int op) +{ + if (op != Py_EQ && op != Py_NE) { + Py_RETURN_NOTIMPLEMENTED; + } + + if (!PyObject_TypeCheck(self, &_PyInterpreterID_Type)) { + Py_RETURN_NOTIMPLEMENTED; + } + + interpid *id = (interpid *)self; + int equal; + if (PyObject_TypeCheck(other, &_PyInterpreterID_Type)) { + interpid *otherid = (interpid *)other; + equal = (id->id == otherid->id); + } + else if (PyLong_CheckExact(other)) { + /* Fast path */ + int overflow; + long long otherid = PyLong_AsLongLongAndOverflow(other, &overflow); + if (otherid == -1 && PyErr_Occurred()) { + return NULL; + } + equal = !overflow && (otherid >= 0) && (id->id == otherid); + } + else if (PyNumber_Check(other)) { + PyObject *pyid = PyLong_FromLongLong(id->id); + if (pyid == NULL) { + return NULL; + } + PyObject *res = PyObject_RichCompare(pyid, other, op); + Py_DECREF(pyid); + return res; + } + else { + Py_RETURN_NOTIMPLEMENTED; + } + + if ((op == Py_EQ && equal) || (op == Py_NE && !equal)) { + Py_RETURN_TRUE; + } + Py_RETURN_FALSE; +} + +PyDoc_STRVAR(interpid_doc, +"A interpreter ID identifies a interpreter and may be used as an int."); + +PyTypeObject _PyInterpreterID_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "InterpreterID", /* tp_name */ + sizeof(interpid), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)interpid_dealloc, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_as_async */ + (reprfunc)interpid_repr, /* tp_repr */ + &interpid_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + interpid_hash, /* tp_hash */ + 0, /* tp_call */ + (reprfunc)interpid_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + interpid_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + interpid_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 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 */ + 0, /* tp_alloc */ + interpid_new, /* tp_new */ +}; + +PyObject *_PyInterpreterID_New(int64_t id) +{ + return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0); +} + +PyObject * +_PyInterpreterState_GetIDObject(PyInterpreterState *interp) +{ + if (_PyInterpreterState_IDInitref(interp) != 0) { + return NULL; + }; + int64_t id = PyInterpreterState_GetID(interp); + if (id < 0) { + return NULL; + } + return (PyObject *)newinterpid(&_PyInterpreterID_Type, id, 0); +} + +PyInterpreterState * +_PyInterpreterID_LookUp(PyObject *requested_id) +{ + int64_t id; + if (!interp_id_converter(requested_id, &id)) { + return NULL; + } + return _PyInterpreterState_LookUpID(id); +} diff --git a/contrib/tools/python3/src/Objects/iterobject.c b/contrib/tools/python3/src/Objects/iterobject.c index fcb96c6201..6cac41ad53 100644 --- a/contrib/tools/python3/src/Objects/iterobject.c +++ b/contrib/tools/python3/src/Objects/iterobject.c @@ -1,7 +1,7 @@ /* Iterator objects */ #include "Python.h" -#include "pycore_object.h" +#include "pycore_object.h" typedef struct { PyObject_HEAD @@ -9,8 +9,8 @@ typedef struct { PyObject *it_seq; /* Set to NULL when iterator is exhausted */ } seqiterobject; -_Py_IDENTIFIER(iter); - +_Py_IDENTIFIER(iter); + PyObject * PySeqIter_New(PyObject *seq) { @@ -79,7 +79,7 @@ iter_iternext(PyObject *iterator) } static PyObject * -iter_len(seqiterobject *it, PyObject *Py_UNUSED(ignored)) +iter_len(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t seqsize, len; @@ -102,13 +102,13 @@ iter_len(seqiterobject *it, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) +iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -143,10 +143,10 @@ PyTypeObject PySeqIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)iter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -241,13 +241,13 @@ calliter_iternext(calliterobject *it) } static PyObject * -calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) +calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_callable != NULL && it->it_sentinel != NULL) - return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter), it->it_callable, it->it_sentinel); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); } static PyMethodDef calliter_methods[] = { @@ -262,10 +262,10 @@ PyTypeObject PyCallIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)calliter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/listobject.c b/contrib/tools/python3/src/Objects/listobject.c index cbbd65e4af..1e868b43c0 100644 --- a/contrib/tools/python3/src/Objects/listobject.c +++ b/contrib/tools/python3/src/Objects/listobject.c @@ -1,10 +1,10 @@ /* List object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_object.h" -#include "pycore_tupleobject.h" -#include "pycore_accu.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_object.h" +#include "pycore_tupleobject.h" +#include "pycore_accu.h" #ifdef STDC_HEADERS #include <stddef.h> @@ -45,7 +45,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize) */ if (allocated >= newsize && newsize >= (allocated >> 1)) { assert(self->ob_item != NULL || newsize == 0); - Py_SET_SIZE(self, newsize); + Py_SET_SIZE(self, newsize); return 0; } @@ -54,17 +54,17 @@ list_resize(PyListObject *self, Py_ssize_t newsize) * enough to give linear-time amortized behavior over a long * sequence of appends() in the presence of a poorly-performing * system realloc(). - * Add padding to make the allocated size multiple of 4. - * The growth pattern is: 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, ... + * Add padding to make the allocated size multiple of 4. + * The growth pattern is: 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, ... * Note: new_allocated won't overflow because the largest possible value * is PY_SSIZE_T_MAX * (9 / 8) + 6 which always fits in a size_t. */ - new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3; - /* Do not overallocate if the new size is closer to overalocated size - * than to the old size. - */ - if (newsize - Py_SIZE(self) > (Py_ssize_t)(new_allocated - newsize)) - new_allocated = ((size_t)newsize + 3) & ~(size_t)3; + new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3; + /* Do not overallocate if the new size is closer to overalocated size + * than to the old size. + */ + if (newsize - Py_SIZE(self) > (Py_ssize_t)(new_allocated - newsize)) + new_allocated = ((size_t)newsize + 3) & ~(size_t)3; if (newsize == 0) new_allocated = 0; @@ -75,49 +75,49 @@ list_resize(PyListObject *self, Py_ssize_t newsize) return -1; } self->ob_item = items; - Py_SET_SIZE(self, newsize); + Py_SET_SIZE(self, newsize); self->allocated = new_allocated; return 0; } -static int -list_preallocate_exact(PyListObject *self, Py_ssize_t size) -{ - assert(self->ob_item == NULL); - assert(size > 0); - - PyObject **items = PyMem_New(PyObject*, size); - if (items == NULL) { - PyErr_NoMemory(); - return -1; - } - self->ob_item = items; - self->allocated = size; - return 0; -} - +static int +list_preallocate_exact(PyListObject *self, Py_ssize_t size) +{ + assert(self->ob_item == NULL); + assert(size > 0); + + PyObject **items = PyMem_New(PyObject*, size); + if (items == NULL) { + PyErr_NoMemory(); + return -1; + } + self->ob_item = items; + self->allocated = size; + return 0; +} + /* Empty list reuse scheme to save calls to malloc and free */ #ifndef PyList_MAXFREELIST -# define PyList_MAXFREELIST 80 +# define PyList_MAXFREELIST 80 #endif - + static PyListObject *free_list[PyList_MAXFREELIST]; static int numfree = 0; -void -_PyList_ClearFreeList(void) +void +_PyList_ClearFreeList(void) { while (numfree) { - PyListObject *op = free_list[--numfree]; + PyListObject *op = free_list[--numfree]; assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } } void -_PyList_Fini(void) +_PyList_Fini(void) { - _PyList_ClearFreeList(); + _PyList_ClearFreeList(); } /* Print summary info about the state of the optimized allocator */ @@ -156,30 +156,30 @@ PyList_New(Py_ssize_t size) return PyErr_NoMemory(); } } - Py_SET_SIZE(op, size); + Py_SET_SIZE(op, size); op->allocated = size; _PyObject_GC_TRACK(op); return (PyObject *) op; } -static PyObject * -list_new_prealloc(Py_ssize_t size) -{ - assert(size > 0); - PyListObject *op = (PyListObject *) PyList_New(0); - if (op == NULL) { - return NULL; - } - assert(op->ob_item == NULL); - op->ob_item = PyMem_New(PyObject *, size); - if (op->ob_item == NULL) { - Py_DECREF(op); - return PyErr_NoMemory(); - } - op->allocated = size; - return (PyObject *) op; -} - +static PyObject * +list_new_prealloc(Py_ssize_t size) +{ + assert(size > 0); + PyListObject *op = (PyListObject *) PyList_New(0); + if (op == NULL) { + return NULL; + } + assert(op->ob_item == NULL); + op->ob_item = PyMem_New(PyObject *, size); + if (op->ob_item == NULL) { + Py_DECREF(op); + return PyErr_NoMemory(); + } + op->allocated = size; + return (PyObject *) op; +} + Py_ssize_t PyList_Size(PyObject *op) { @@ -191,19 +191,19 @@ PyList_Size(PyObject *op) return Py_SIZE(op); } -static inline int -valid_index(Py_ssize_t i, Py_ssize_t limit) -{ - /* The cast to size_t lets us use just a single comparison - to check whether i is in the range: 0 <= i < limit. - - See: Section 14.2 "Bounds Checking" in the Agner Fog - optimization manual found at: - https://www.agner.org/optimize/optimizing_cpp.pdf - */ - return (size_t) i < (size_t) limit; -} - +static inline int +valid_index(Py_ssize_t i, Py_ssize_t limit) +{ + /* The cast to size_t lets us use just a single comparison + to check whether i is in the range: 0 <= i < limit. + + See: Section 14.2 "Bounds Checking" in the Agner Fog + optimization manual found at: + https://www.agner.org/optimize/optimizing_cpp.pdf + */ + return (size_t) i < (size_t) limit; +} + static PyObject *indexerr = NULL; PyObject * @@ -213,7 +213,7 @@ PyList_GetItem(PyObject *op, Py_ssize_t i) PyErr_BadInternalCall(); return NULL; } - if (!valid_index(i, Py_SIZE(op))) { + if (!valid_index(i, Py_SIZE(op))) { if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); @@ -236,7 +236,7 @@ PyList_SetItem(PyObject *op, Py_ssize_t i, PyErr_BadInternalCall(); return -1; } - if (!valid_index(i, Py_SIZE(op))) { + if (!valid_index(i, Py_SIZE(op))) { Py_XDECREF(newitem); PyErr_SetString(PyExc_IndexError, "list assignment index out of range"); @@ -326,7 +326,7 @@ list_dealloc(PyListObject *op) { Py_ssize_t i; PyObject_GC_UnTrack(op); - Py_TRASHCAN_BEGIN(op, list_dealloc) + Py_TRASHCAN_BEGIN(op, list_dealloc) if (op->ob_item != NULL) { /* Do it backwards, for Christian Tismer. There's a simple test case where somehow this reduces @@ -342,7 +342,7 @@ list_dealloc(PyListObject *op) free_list[numfree++] = op; else Py_TYPE(op)->tp_free((PyObject *)op); - Py_TRASHCAN_END + Py_TRASHCAN_END } static PyObject * @@ -410,23 +410,23 @@ list_length(PyListObject *a) static int list_contains(PyListObject *a, PyObject *el) { - PyObject *item; + PyObject *item; Py_ssize_t i; int cmp; - for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) { - item = PyList_GET_ITEM(a, i); - Py_INCREF(item); - cmp = PyObject_RichCompareBool(item, el, Py_EQ); - Py_DECREF(item); - } + for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) { + item = PyList_GET_ITEM(a, i); + Py_INCREF(item); + cmp = PyObject_RichCompareBool(item, el, Py_EQ); + Py_DECREF(item); + } return cmp; } static PyObject * list_item(PyListObject *a, Py_ssize_t i) { - if (!valid_index(i, Py_SIZE(a))) { + if (!valid_index(i, Py_SIZE(a))) { if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); @@ -447,10 +447,10 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh) PyObject **src, **dest; Py_ssize_t i, len; len = ihigh - ilow; - if (len <= 0) { - return PyList_New(0); - } - np = (PyListObject *) list_new_prealloc(len); + if (len <= 0) { + return PyList_New(0); + } + np = (PyListObject *) list_new_prealloc(len); if (np == NULL) return NULL; @@ -461,7 +461,7 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh) Py_INCREF(v); dest[i] = v; } - Py_SET_SIZE(np, len); + Py_SET_SIZE(np, len); return (PyObject *)np; } @@ -472,18 +472,18 @@ PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh) PyErr_BadInternalCall(); return NULL; } - if (ilow < 0) { - ilow = 0; - } - else if (ilow > Py_SIZE(a)) { - ilow = Py_SIZE(a); - } - if (ihigh < ilow) { - ihigh = ilow; - } - else if (ihigh > Py_SIZE(a)) { - ihigh = Py_SIZE(a); - } + if (ilow < 0) { + ilow = 0; + } + else if (ilow > Py_SIZE(a)) { + ilow = Py_SIZE(a); + } + if (ihigh < ilow) { + ihigh = ilow; + } + else if (ihigh > Py_SIZE(a)) { + ihigh = Py_SIZE(a); + } return list_slice((PyListObject *)a, ilow, ihigh); } @@ -497,17 +497,17 @@ list_concat(PyListObject *a, PyObject *bb) if (!PyList_Check(bb)) { PyErr_Format(PyExc_TypeError, "can only concatenate list (not \"%.200s\") to list", - Py_TYPE(bb)->tp_name); + Py_TYPE(bb)->tp_name); return NULL; } #define b ((PyListObject *)bb) if (Py_SIZE(a) > PY_SSIZE_T_MAX - Py_SIZE(b)) return PyErr_NoMemory(); size = Py_SIZE(a) + Py_SIZE(b); - if (size == 0) { - return PyList_New(0); - } - np = (PyListObject *) list_new_prealloc(size); + if (size == 0) { + return PyList_New(0); + } + np = (PyListObject *) list_new_prealloc(size); if (np == NULL) { return NULL; } @@ -525,7 +525,7 @@ list_concat(PyListObject *a, PyObject *bb) Py_INCREF(v); dest[i] = v; } - Py_SET_SIZE(np, size); + Py_SET_SIZE(np, size); return (PyObject *)np; #undef b } @@ -545,30 +545,30 @@ list_repeat(PyListObject *a, Py_ssize_t n) size = Py_SIZE(a) * n; if (size == 0) return PyList_New(0); - np = (PyListObject *) list_new_prealloc(size); + np = (PyListObject *) list_new_prealloc(size); if (np == NULL) return NULL; if (Py_SIZE(a) == 1) { - items = np->ob_item; + items = np->ob_item; elem = a->ob_item[0]; for (i = 0; i < n; i++) { items[i] = elem; Py_INCREF(elem); } } - else { - p = np->ob_item; - items = a->ob_item; - for (i = 0; i < n; i++) { - for (j = 0; j < Py_SIZE(a); j++) { - *p = items[j]; - Py_INCREF(*p); - p++; - } + else { + p = np->ob_item; + items = a->ob_item; + for (i = 0; i < n; i++) { + for (j = 0; j < Py_SIZE(a); j++) { + *p = items[j]; + Py_INCREF(*p); + p++; + } } } - Py_SET_SIZE(np, size); + Py_SET_SIZE(np, size); return (PyObject *) np; } @@ -581,7 +581,7 @@ _list_clear(PyListObject *a) /* Because XDECREF can recursively invoke operations on this list, we make it empty first. */ i = Py_SIZE(a); - Py_SET_SIZE(a, 0); + Py_SET_SIZE(a, 0); a->ob_item = NULL; a->allocated = 0; while (--i >= 0) { @@ -759,7 +759,7 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n) static int list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v) { - if (!valid_index(i, Py_SIZE(a))) { + if (!valid_index(i, Py_SIZE(a))) { PyErr_SetString(PyExc_IndexError, "list assignment index out of range"); return -1; @@ -899,7 +899,7 @@ list_extend(PyListObject *self, PyObject *iterable) it = PyObject_GetIter(iterable); if (it == NULL) return NULL; - iternext = *Py_TYPE(it)->tp_iternext; + iternext = *Py_TYPE(it)->tp_iternext; /* Guess a result list size. */ n = PyObject_LengthHint(iterable, 8); @@ -920,7 +920,7 @@ list_extend(PyListObject *self, PyObject *iterable) if (list_resize(self, mn) < 0) goto error; /* Make the list sane again. */ - Py_SET_SIZE(self, m); + Py_SET_SIZE(self, m); } /* Run iterator to exhaustion. */ @@ -938,7 +938,7 @@ list_extend(PyListObject *self, PyObject *iterable) if (Py_SIZE(self) < self->allocated) { /* steals ref */ PyList_SET_ITEM(self, Py_SIZE(self), item); - Py_SET_SIZE(self, Py_SIZE(self) + 1); + Py_SET_SIZE(self, Py_SIZE(self) + 1); } else { int status = app1(self, item); @@ -1006,7 +1006,7 @@ list_pop_impl(PyListObject *self, Py_ssize_t index) } if (index < 0) index += Py_SIZE(self); - if (!valid_index(index, Py_SIZE(self))) { + if (!valid_index(index, Py_SIZE(self))) { PyErr_SetString(PyExc_IndexError, "pop index out of range"); return NULL; } @@ -1186,7 +1186,7 @@ struct s_MergeState { /* This function is used by unsafe_object_compare to optimize comparisons * when we know our list is type-homogeneous but we can't assume anything else. - * In the pre-sort check it is set equal to Py_TYPE(key)->tp_richcompare */ + * In the pre-sort check it is set equal to Py_TYPE(key)->tp_richcompare */ PyObject *(*key_richcompare)(PyObject *, PyObject *, int); /* This function is used by unsafe_tuple_compare to compare the first elements @@ -1355,7 +1355,7 @@ gallop_left(MergeState *ms, PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_ while (ofs < maxofs) { IFLT(a[ofs], key) { lastofs = ofs; - assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); + assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); ofs = (ofs << 1) + 1; } else /* key <= a[hint + ofs] */ @@ -1377,7 +1377,7 @@ gallop_left(MergeState *ms, PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_ break; /* key <= a[hint - ofs] */ lastofs = ofs; - assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); + assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); ofs = (ofs << 1) + 1; } if (ofs > maxofs) @@ -1444,7 +1444,7 @@ gallop_right(MergeState *ms, PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize while (ofs < maxofs) { IFLT(key, *(a-ofs)) { lastofs = ofs; - assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); + assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); ofs = (ofs << 1) + 1; } else /* a[hint - ofs] <= key */ @@ -1467,7 +1467,7 @@ gallop_right(MergeState *ms, PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize break; /* a[hint + ofs] <= key */ lastofs = ofs; - assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); + assert(ofs <= (PY_SSIZE_T_MAX - 1) / 2); ofs = (ofs << 1) + 1; } if (ofs > maxofs) @@ -2012,7 +2012,7 @@ safe_object_compare(PyObject *v, PyObject *w, MergeState *ms) return PyObject_RichCompareBool(v, w, Py_LT); } -/* Homogeneous compare: safe for any two comparable objects of the same type. +/* Homogeneous compare: safe for any two comparable objects of the same type. * (ms->key_richcompare is set to ob_type->tp_richcompare in the * pre-sort check.) */ @@ -2022,7 +2022,7 @@ unsafe_object_compare(PyObject *v, PyObject *w, MergeState *ms) PyObject *res_obj; int res; /* No assumptions, because we check first: */ - if (Py_TYPE(v)->tp_richcompare != ms->key_richcompare) + if (Py_TYPE(v)->tp_richcompare != ms->key_richcompare) return PyObject_RichCompareBool(v, w, Py_LT); assert(ms->key_richcompare != NULL); @@ -2059,8 +2059,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */ - assert(Py_IS_TYPE(v, &PyUnicode_Type)); - assert(Py_IS_TYPE(w, &PyUnicode_Type)); + assert(Py_IS_TYPE(v, &PyUnicode_Type)); + assert(Py_IS_TYPE(w, &PyUnicode_Type)); assert(PyUnicode_KIND(v) == PyUnicode_KIND(w)); assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND); @@ -2082,8 +2082,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms) PyLongObject *vl, *wl; sdigit v0, w0; int res; /* Modified from Objects/longobject.c:long_compare, assuming: */ - assert(Py_IS_TYPE(v, &PyLong_Type)); - assert(Py_IS_TYPE(w, &PyLong_Type)); + assert(Py_IS_TYPE(v, &PyLong_Type)); + assert(Py_IS_TYPE(w, &PyLong_Type)); assert(Py_ABS(Py_SIZE(v)) <= 1); assert(Py_ABS(Py_SIZE(w)) <= 1); @@ -2110,8 +2110,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/floatobject.c:float_richcompare, assuming: */ - assert(Py_IS_TYPE(v, &PyFloat_Type)); - assert(Py_IS_TYPE(w, &PyFloat_Type)); + assert(Py_IS_TYPE(v, &PyFloat_Type)); + assert(Py_IS_TYPE(w, &PyFloat_Type)); res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w); assert(res == PyObject_RichCompareBool(v, w, Py_LT)); @@ -2132,8 +2132,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms) int k; /* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */ - assert(Py_IS_TYPE(v, &PyTuple_Type)); - assert(Py_IS_TYPE(w, &PyTuple_Type)); + assert(Py_IS_TYPE(v, &PyTuple_Type)); + assert(Py_IS_TYPE(w, &PyTuple_Type)); assert(Py_SIZE(v) > 0); assert(Py_SIZE(w) > 0); @@ -2172,20 +2172,20 @@ list.sort key as keyfunc: object = None reverse: bool(accept={int}) = False -Sort the list in ascending order and return None. - -The sort is in-place (i.e. the list itself is modified) and stable (i.e. the -order of two equal elements is maintained). - -If a key function is given, apply it once to each list item and sort them, -ascending or descending, according to their function values. - -The reverse flag can be set to sort in descending order. +Sort the list in ascending order and return None. + +The sort is in-place (i.e. the list itself is modified) and stable (i.e. the +order of two equal elements is maintained). + +If a key function is given, apply it once to each list item and sort them, +ascending or descending, according to their function values. + +The reverse flag can be set to sort in descending order. [clinic start generated code]*/ static PyObject * list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) -/*[clinic end generated code: output=57b9f9c5e23fbe42 input=cb56cd179a713060]*/ +/*[clinic end generated code: output=57b9f9c5e23fbe42 input=cb56cd179a713060]*/ { MergeState ms; Py_ssize_t nremaining; @@ -2211,7 +2211,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) saved_ob_size = Py_SIZE(self); saved_ob_item = self->ob_item; saved_allocated = self->allocated; - Py_SET_SIZE(self, 0); + Py_SET_SIZE(self, 0); self->ob_item = NULL; self->allocated = -1; /* any operation will reset it to >= 0 */ @@ -2233,7 +2233,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) } for (i = 0; i < saved_ob_size ; i++) { - keys[i] = PyObject_CallOneArg(keyfunc, saved_ob_item[i]); + keys[i] = PyObject_CallOneArg(keyfunc, saved_ob_item[i]); if (keys[i] == NULL) { for (i=i-1 ; i>=0 ; i--) Py_DECREF(keys[i]); @@ -2254,12 +2254,12 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) * set ms appropriately. */ if (saved_ob_size > 1) { /* Assume the first element is representative of the whole list. */ - int keys_are_in_tuples = (Py_IS_TYPE(lo.keys[0], &PyTuple_Type) && + int keys_are_in_tuples = (Py_IS_TYPE(lo.keys[0], &PyTuple_Type) && Py_SIZE(lo.keys[0]) > 0); PyTypeObject* key_type = (keys_are_in_tuples ? - Py_TYPE(PyTuple_GET_ITEM(lo.keys[0], 0)) : - Py_TYPE(lo.keys[0])); + Py_TYPE(PyTuple_GET_ITEM(lo.keys[0], 0)) : + Py_TYPE(lo.keys[0])); int keys_are_all_same_type = 1; int strings_are_latin = 1; @@ -2269,7 +2269,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) for (i=0; i < saved_ob_size; i++) { if (keys_are_in_tuples && - !(Py_IS_TYPE(lo.keys[i], &PyTuple_Type) && Py_SIZE(lo.keys[i]) != 0)) { + !(Py_IS_TYPE(lo.keys[i], &PyTuple_Type) && Py_SIZE(lo.keys[i]) != 0)) { keys_are_in_tuples = 0; keys_are_all_same_type = 0; break; @@ -2282,29 +2282,29 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) PyTuple_GET_ITEM(lo.keys[i], 0) : lo.keys[i]); - if (!Py_IS_TYPE(key, key_type)) { + if (!Py_IS_TYPE(key, key_type)) { keys_are_all_same_type = 0; - /* If keys are in tuple we must loop over the whole list to make - sure all items are tuples */ - if (!keys_are_in_tuples) { - break; - } + /* If keys are in tuple we must loop over the whole list to make + sure all items are tuples */ + if (!keys_are_in_tuples) { + break; + } } - if (keys_are_all_same_type) { - if (key_type == &PyLong_Type && - ints_are_bounded && - Py_ABS(Py_SIZE(key)) > 1) { - + if (keys_are_all_same_type) { + if (key_type == &PyLong_Type && + ints_are_bounded && + Py_ABS(Py_SIZE(key)) > 1) { + ints_are_bounded = 0; - } - else if (key_type == &PyUnicode_Type && - strings_are_latin && - PyUnicode_KIND(key) != PyUnicode_1BYTE_KIND) { - - strings_are_latin = 0; - } - } + } + else if (key_type == &PyUnicode_Type && + strings_are_latin && + PyUnicode_KIND(key) != PyUnicode_1BYTE_KIND) { + + strings_are_latin = 0; + } + } } /* Choose the best compare, given what we now know about the keys. */ @@ -2333,12 +2333,12 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) if (keys_are_in_tuples) { /* Make sure we're not dealing with tuples of tuples * (remember: here, key_type refers list [key[0] for key in keys]) */ - if (key_type == &PyTuple_Type) { + if (key_type == &PyTuple_Type) { ms.tuple_elem_compare = safe_object_compare; - } - else { + } + else { ms.tuple_elem_compare = ms.key_compare; - } + } ms.key_compare = unsafe_tuple_compare; } @@ -2428,7 +2428,7 @@ fail: keyfunc_fail: final_ob_item = self->ob_item; i = Py_SIZE(self); - Py_SET_SIZE(self, saved_ob_size); + Py_SET_SIZE(self, saved_ob_size); self->ob_item = saved_ob_item; self->allocated = saved_allocated; if (final_ob_item != NULL) { @@ -2495,7 +2495,7 @@ PyList_AsTuple(PyObject *v) PyErr_BadInternalCall(); return NULL; } - return _PyTuple_FromArray(((PyListObject *)v)->ob_item, Py_SIZE(v)); + return _PyTuple_FromArray(((PyListObject *)v)->ob_item, Py_SIZE(v)); } /*[clinic input] @@ -2529,10 +2529,10 @@ list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start, stop = 0; } for (i = start; i < stop && i < Py_SIZE(self); i++) { - PyObject *obj = self->ob_item[i]; - Py_INCREF(obj); - int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); - Py_DECREF(obj); + PyObject *obj = self->ob_item[i]; + Py_INCREF(obj); + int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); + Py_DECREF(obj); if (cmp > 0) return PyLong_FromSsize_t(i); else if (cmp < 0) @@ -2559,14 +2559,14 @@ list_count(PyListObject *self, PyObject *value) Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *obj = self->ob_item[i]; - if (obj == value) { - count++; - continue; - } - Py_INCREF(obj); - int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); - Py_DECREF(obj); + PyObject *obj = self->ob_item[i]; + if (obj == value) { + count++; + continue; + } + Py_INCREF(obj); + int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); + Py_DECREF(obj); if (cmp > 0) count++; else if (cmp < 0) @@ -2593,10 +2593,10 @@ list_remove(PyListObject *self, PyObject *value) Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *obj = self->ob_item[i]; - Py_INCREF(obj); - int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); - Py_DECREF(obj); + PyObject *obj = self->ob_item[i]; + Py_INCREF(obj); + int cmp = PyObject_RichCompareBool(obj, value, Py_EQ); + Py_DECREF(obj); if (cmp > 0) { if (list_ass_slice(self, i, i+1, (PyObject *)NULL) == 0) @@ -2642,17 +2642,17 @@ list_richcompare(PyObject *v, PyObject *w, int op) /* Search for the first index where items are different */ for (i = 0; i < Py_SIZE(vl) && i < Py_SIZE(wl); i++) { - PyObject *vitem = vl->ob_item[i]; - PyObject *witem = wl->ob_item[i]; - if (vitem == witem) { - continue; - } - - Py_INCREF(vitem); - Py_INCREF(witem); - int k = PyObject_RichCompareBool(vitem, witem, Py_EQ); - Py_DECREF(vitem); - Py_DECREF(witem); + PyObject *vitem = vl->ob_item[i]; + PyObject *witem = wl->ob_item[i]; + if (vitem == witem) { + continue; + } + + Py_INCREF(vitem); + Py_INCREF(witem); + int k = PyObject_RichCompareBool(vitem, witem, Py_EQ); + Py_DECREF(vitem); + Py_DECREF(witem); if (k < 0) return NULL; if (!k) @@ -2703,19 +2703,19 @@ list___init___impl(PyListObject *self, PyObject *iterable) (void)_list_clear(self); } if (iterable != NULL) { - if (_PyObject_HasLen(iterable)) { - Py_ssize_t iter_len = PyObject_Size(iterable); - if (iter_len == -1) { - if (!PyErr_ExceptionMatches(PyExc_TypeError)) { - return -1; - } - PyErr_Clear(); - } - if (iter_len > 0 && self->ob_item == NULL - && list_preallocate_exact(self, iter_len)) { - return -1; - } - } + if (_PyObject_HasLen(iterable)) { + Py_ssize_t iter_len = PyObject_Size(iterable); + if (iter_len == -1) { + if (!PyErr_ExceptionMatches(PyExc_TypeError)) { + return -1; + } + PyErr_Clear(); + } + if (iter_len > 0 && self->ob_item == NULL + && list_preallocate_exact(self, iter_len)) { + return -1; + } + } PyObject *rv = list_extend(self, iterable); if (rv == NULL) return -1; @@ -2724,33 +2724,33 @@ list___init___impl(PyListObject *self, PyObject *iterable) return 0; } -static PyObject * -list_vectorcall(PyObject *type, PyObject * const*args, - size_t nargsf, PyObject *kwnames) -{ - if (!_PyArg_NoKwnames("list", kwnames)) { - return NULL; - } - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_CheckPositional("list", nargs, 0, 1)) { - return NULL; - } - - assert(PyType_Check(type)); - PyObject *list = PyType_GenericAlloc((PyTypeObject *)type, 0); - if (list == NULL) { - return NULL; - } - if (nargs) { - if (list___init___impl((PyListObject *)list, args[0])) { - Py_DECREF(list); - return NULL; - } - } - return list; -} - - +static PyObject * +list_vectorcall(PyObject *type, PyObject * const*args, + size_t nargsf, PyObject *kwnames) +{ + if (!_PyArg_NoKwnames("list", kwnames)) { + return NULL; + } + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_CheckPositional("list", nargs, 0, 1)) { + return NULL; + } + + assert(PyType_Check(type)); + PyObject *list = PyType_GenericAlloc((PyTypeObject *)type, 0); + if (list == NULL) { + return NULL; + } + if (nargs) { + if (list___init___impl((PyListObject *)list, args[0])) { + Py_DECREF(list); + return NULL; + } + } + return list; +} + + /*[clinic input] list.__sizeof__ @@ -2785,7 +2785,7 @@ static PyMethodDef list_methods[] = { LIST_COUNT_METHODDEF LIST_REVERSE_METHODDEF LIST_SORT_METHODDEF - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -2805,7 +2805,7 @@ static PySequenceMethods list_as_sequence = { static PyObject * list_subscript(PyListObject* self, PyObject* item) { - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) @@ -2815,8 +2815,8 @@ list_subscript(PyListObject* self, PyObject* item) return list_item(self, i); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength, i; - size_t cur; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; PyObject* result; PyObject* it; PyObject **src, **dest; @@ -2834,7 +2834,7 @@ list_subscript(PyListObject* self, PyObject* item) return list_slice(self, start, stop); } else { - result = list_new_prealloc(slicelength); + result = list_new_prealloc(slicelength); if (!result) return NULL; src = self->ob_item; @@ -2845,14 +2845,14 @@ list_subscript(PyListObject* self, PyObject* item) Py_INCREF(it); dest[i] = it; } - Py_SET_SIZE(result, slicelength); + Py_SET_SIZE(result, slicelength); return result; } } else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - Py_TYPE(item)->tp_name); + Py_TYPE(item)->tp_name); return NULL; } } @@ -2860,7 +2860,7 @@ list_subscript(PyListObject* self, PyObject* item) static int list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) { - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return -1; @@ -2938,7 +2938,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) sizeof(PyObject *)); } - Py_SET_SIZE(self, Py_SIZE(self) - slicelength); + Py_SET_SIZE(self, Py_SIZE(self) - slicelength); res = list_resize(self, Py_SIZE(self)); for (i = 0; i < slicelength; i++) { @@ -2952,8 +2952,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) /* assign slice */ PyObject *ins, *seq; PyObject **garbage, **seqitems, **selfitems; - Py_ssize_t i; - size_t cur; + Py_ssize_t i; + size_t cur; /* protect against a[::-1] = a */ if (self == (PyListObject*)value) { @@ -3015,7 +3015,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - Py_TYPE(item)->tp_name); + Py_TYPE(item)->tp_name); return -1; } } @@ -3032,10 +3032,10 @@ PyTypeObject PyList_Type = { sizeof(PyListObject), 0, (destructor)list_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)list_repr, /* tp_repr */ 0, /* tp_as_number */ &list_as_sequence, /* tp_as_sequence */ @@ -3067,7 +3067,7 @@ PyTypeObject PyList_Type = { PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ - .tp_vectorcall = list_vectorcall, + .tp_vectorcall = list_vectorcall, }; /*********************** List Iterator **************************/ @@ -3081,9 +3081,9 @@ typedef struct { static void listiter_dealloc(listiterobject *); static int listiter_traverse(listiterobject *, visitproc, void *); static PyObject *listiter_next(listiterobject *); -static PyObject *listiter_len(listiterobject *, PyObject *); +static PyObject *listiter_len(listiterobject *, PyObject *); static PyObject *listiter_reduce_general(void *_it, int forward); -static PyObject *listiter_reduce(listiterobject *, PyObject *); +static PyObject *listiter_reduce(listiterobject *, PyObject *); static PyObject *listiter_setstate(listiterobject *, PyObject *state); PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); @@ -3104,10 +3104,10 @@ PyTypeObject PyListIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)listiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3190,7 +3190,7 @@ listiter_next(listiterobject *it) } static PyObject * -listiter_len(listiterobject *it, PyObject *Py_UNUSED(ignored)) +listiter_len(listiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len; if (it->it_seq) { @@ -3202,7 +3202,7 @@ listiter_len(listiterobject *it, PyObject *Py_UNUSED(ignored)) } static PyObject * -listiter_reduce(listiterobject *it, PyObject *Py_UNUSED(ignored)) +listiter_reduce(listiterobject *it, PyObject *Py_UNUSED(ignored)) { return listiter_reduce_general(it, 1); } @@ -3234,8 +3234,8 @@ typedef struct { static void listreviter_dealloc(listreviterobject *); static int listreviter_traverse(listreviterobject *, visitproc, void *); static PyObject *listreviter_next(listreviterobject *); -static PyObject *listreviter_len(listreviterobject *, PyObject *); -static PyObject *listreviter_reduce(listreviterobject *, PyObject *); +static PyObject *listreviter_len(listreviterobject *, PyObject *); +static PyObject *listreviter_reduce(listreviterobject *, PyObject *); static PyObject *listreviter_setstate(listreviterobject *, PyObject *); static PyMethodDef listreviter_methods[] = { @@ -3252,10 +3252,10 @@ PyTypeObject PyListRevIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)listreviter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3344,7 +3344,7 @@ listreviter_next(listreviterobject *it) } static PyObject * -listreviter_len(listreviterobject *it, PyObject *Py_UNUSED(ignored)) +listreviter_len(listreviterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = it->it_index + 1; if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len) @@ -3353,7 +3353,7 @@ listreviter_len(listreviterobject *it, PyObject *Py_UNUSED(ignored)) } static PyObject * -listreviter_reduce(listreviterobject *it, PyObject *Py_UNUSED(ignored)) +listreviter_reduce(listreviterobject *it, PyObject *Py_UNUSED(ignored)) { return listiter_reduce_general(it, 0); } @@ -3379,25 +3379,25 @@ listreviter_setstate(listreviterobject *it, PyObject *state) static PyObject * listiter_reduce_general(void *_it, int forward) { - _Py_IDENTIFIER(iter); - _Py_IDENTIFIER(reversed); + _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(reversed); PyObject *list; /* the objects are not the same, index is of different types! */ if (forward) { listiterobject *it = (listiterobject *)_it; if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); } else { listreviterobject *it = (listreviterobject *)_it; if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed), it->it_seq, it->it_index); } /* empty iterator, create an empty list */ list = PyList_New(0); if (list == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); } diff --git a/contrib/tools/python3/src/Objects/longobject.c b/contrib/tools/python3/src/Objects/longobject.c index 567cfd1a91..cf13b2c430 100644 --- a/contrib/tools/python3/src/Objects/longobject.c +++ b/contrib/tools/python3/src/Objects/longobject.c @@ -3,8 +3,8 @@ /* XXX The functional organization of this file is terrible */ #include "Python.h" -#include "pycore_interp.h" // _PY_NSMALLPOSINTS -#include "pycore_pystate.h" // _Py_IsMainInterpreter() +#include "pycore_interp.h" // _PY_NSMALLPOSINTS +#include "pycore_pystate.h" // _Py_IsMainInterpreter() #include "longintrepr.h" #include <float.h> @@ -17,8 +17,8 @@ class int "PyObject *" "&PyLong_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec0275e3422a36e3]*/ -#define NSMALLPOSINTS _PY_NSMALLPOSINTS -#define NSMALLNEGINTS _PY_NSMALLNEGINTS +#define NSMALLPOSINTS _PY_NSMALLPOSINTS +#define NSMALLNEGINTS _PY_NSMALLNEGINTS _Py_IDENTIFIER(little); _Py_IDENTIFIER(big); @@ -33,15 +33,15 @@ PyObject *_PyLong_Zero = NULL; PyObject *_PyLong_One = NULL; #if NSMALLNEGINTS + NSMALLPOSINTS > 0 -#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS) -#define IS_SMALL_UINT(ival) ((ival) < NSMALLPOSINTS) +#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS) +#define IS_SMALL_UINT(ival) ((ival) < NSMALLPOSINTS) static PyObject * get_small_int(sdigit ival) { - assert(IS_SMALL_INT(ival)); - PyThreadState *tstate = _PyThreadState_GET(); - PyObject *v = (PyObject*)tstate->interp->small_ints[ival + NSMALLNEGINTS]; + assert(IS_SMALL_INT(ival)); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *v = (PyObject*)tstate->interp->small_ints[ival + NSMALLNEGINTS]; Py_INCREF(v); return v; } @@ -51,7 +51,7 @@ maybe_small_long(PyLongObject *v) { if (v && Py_ABS(Py_SIZE(v)) <= 1) { sdigit ival = MEDIUM_VALUE(v); - if (IS_SMALL_INT(ival)) { + if (IS_SMALL_INT(ival)) { Py_DECREF(v); return (PyLongObject *)get_small_int(ival); } @@ -59,9 +59,9 @@ maybe_small_long(PyLongObject *v) return v; } #else -#define IS_SMALL_INT(ival) 0 -#define IS_SMALL_UINT(ival) 0 -#define get_small_int(ival) (Py_UNREACHABLE(), NULL) +#define IS_SMALL_INT(ival) 0 +#define IS_SMALL_UINT(ival) 0 +#define get_small_int(ival) (Py_UNREACHABLE(), NULL) #define maybe_small_long(val) (val) #endif @@ -74,7 +74,7 @@ _PyLong_Negate(PyLongObject **x_p) x = (PyLongObject *)*x_p; if (Py_REFCNT(x) == 1) { - Py_SET_SIZE(x, -Py_SIZE(x)); + Py_SET_SIZE(x, -Py_SIZE(x)); return; } @@ -113,9 +113,9 @@ long_normalize(PyLongObject *v) while (i > 0 && v->ob_digit[i-1] == 0) --i; - if (i != j) { - Py_SET_SIZE(v, (Py_SIZE(v) < 0) ? -(i) : i); - } + if (i != j) { + Py_SET_SIZE(v, (Py_SIZE(v) < 0) ? -(i) : i); + } return v; } @@ -124,7 +124,7 @@ long_normalize(PyLongObject *v) nb_int slot is not available or the result of the call to nb_int returns something not of type int. */ -PyObject * +PyObject * _PyLong_FromNbInt(PyObject *integral) { PyNumberMethods *nb; @@ -133,7 +133,7 @@ _PyLong_FromNbInt(PyObject *integral) /* Fast path for the case that we already have an int. */ if (PyLong_CheckExact(integral)) { Py_INCREF(integral); - return integral; + return integral; } nb = Py_TYPE(integral)->tp_as_number; @@ -148,11 +148,11 @@ _PyLong_FromNbInt(PyObject *integral) of exact type int. */ result = nb->nb_int(integral); if (!result || PyLong_CheckExact(result)) - return result; + return result; if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, "__int__ returned non-int (type %.200s)", - Py_TYPE(result)->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } @@ -161,81 +161,81 @@ _PyLong_FromNbInt(PyObject *integral) "__int__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(result)->tp_name)) { + Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } - return result; + return result; } -/* Convert the given object to a PyLongObject using the nb_index or - nb_int slots, if available (the latter is deprecated). - Raise TypeError if either nb_index and nb_int slots are not - available or the result of the call to nb_index or nb_int - returns something not of type int. - Should be replaced with PyNumber_Index after the end of the - deprecation period. -*/ -PyObject * -_PyLong_FromNbIndexOrNbInt(PyObject *integral) -{ - PyNumberMethods *nb; - PyObject *result; - - /* Fast path for the case that we already have an int. */ - if (PyLong_CheckExact(integral)) { - Py_INCREF(integral); - return integral; - } - - nb = Py_TYPE(integral)->tp_as_number; - if (nb == NULL || (nb->nb_index == NULL && nb->nb_int == NULL)) { - PyErr_Format(PyExc_TypeError, - "an integer is required (got type %.200s)", - Py_TYPE(integral)->tp_name); - return NULL; - } - - if (nb->nb_index) { - /* Convert using the nb_index slot, which should return something - of exact type int. */ - result = nb->nb_index(integral); - if (!result || PyLong_CheckExact(result)) - return result; - if (!PyLong_Check(result)) { - PyErr_Format(PyExc_TypeError, - "__index__ returned non-int (type %.200s)", - Py_TYPE(result)->tp_name); - Py_DECREF(result); - return NULL; - } - /* Issue #17576: warn if 'result' not of exact type int. */ - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "__index__ returned non-int (type %.200s). " - "The ability to return an instance of a strict subclass of int " - "is deprecated, and may be removed in a future version of Python.", - Py_TYPE(result)->tp_name)) - { - Py_DECREF(result); - return NULL; - } - return result; - } - - result = _PyLong_FromNbInt(integral); - if (result && PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "an integer is required (got type %.200s). " - "Implicit conversion to integers using __int__ is deprecated, " - "and may be removed in a future version of Python.", - Py_TYPE(integral)->tp_name)) - { - Py_DECREF(result); - return NULL; - } - return result; -} - - +/* Convert the given object to a PyLongObject using the nb_index or + nb_int slots, if available (the latter is deprecated). + Raise TypeError if either nb_index and nb_int slots are not + available or the result of the call to nb_index or nb_int + returns something not of type int. + Should be replaced with PyNumber_Index after the end of the + deprecation period. +*/ +PyObject * +_PyLong_FromNbIndexOrNbInt(PyObject *integral) +{ + PyNumberMethods *nb; + PyObject *result; + + /* Fast path for the case that we already have an int. */ + if (PyLong_CheckExact(integral)) { + Py_INCREF(integral); + return integral; + } + + nb = Py_TYPE(integral)->tp_as_number; + if (nb == NULL || (nb->nb_index == NULL && nb->nb_int == NULL)) { + PyErr_Format(PyExc_TypeError, + "an integer is required (got type %.200s)", + Py_TYPE(integral)->tp_name); + return NULL; + } + + if (nb->nb_index) { + /* Convert using the nb_index slot, which should return something + of exact type int. */ + result = nb->nb_index(integral); + if (!result || PyLong_CheckExact(result)) + return result; + if (!PyLong_Check(result)) { + PyErr_Format(PyExc_TypeError, + "__index__ returned non-int (type %.200s)", + Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; + } + /* Issue #17576: warn if 'result' not of exact type int. */ + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__index__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) + { + Py_DECREF(result); + return NULL; + } + return result; + } + + result = _PyLong_FromNbInt(integral); + if (result && PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "an integer is required (got type %.200s). " + "Implicit conversion to integers using __int__ is deprecated, " + "and may be removed in a future version of Python.", + Py_TYPE(integral)->tp_name)) + { + Py_DECREF(result); + return NULL; + } + return result; +} + + /* Allocate a new int object with size digits. Return NULL and set exception if we run out of memory. */ @@ -277,16 +277,16 @@ _PyLong_Copy(PyLongObject *src) i = -(i); if (i < 2) { sdigit ival = MEDIUM_VALUE(src); - if (IS_SMALL_INT(ival)) { - return get_small_int(ival); - } + if (IS_SMALL_INT(ival)) { + return get_small_int(ival); + } } result = _PyLong_New(i); if (result != NULL) { - Py_SET_SIZE(result, Py_SIZE(src)); - while (--i >= 0) { + Py_SET_SIZE(result, Py_SIZE(src)); + while (--i >= 0) { result->ob_digit[i] = src->ob_digit[i]; - } + } } return (PyObject *)result; } @@ -302,9 +302,9 @@ PyLong_FromLong(long ival) int ndigits = 0; int sign; - if (IS_SMALL_INT(ival)) { - return get_small_int((sdigit)ival); - } + if (IS_SMALL_INT(ival)) { + return get_small_int((sdigit)ival); + } if (ival < 0) { /* negate: can't write this as abs_ival = -ival since that @@ -321,7 +321,7 @@ PyLong_FromLong(long ival) if (!(abs_ival >> PyLong_SHIFT)) { v = _PyLong_New(1); if (v) { - Py_SET_SIZE(v, sign); + Py_SET_SIZE(v, sign); v->ob_digit[0] = Py_SAFE_DOWNCAST( abs_ival, unsigned long, digit); } @@ -333,7 +333,7 @@ PyLong_FromLong(long ival) if (!(abs_ival >> 2*PyLong_SHIFT)) { v = _PyLong_New(2); if (v) { - Py_SET_SIZE(v, 2 * sign); + Py_SET_SIZE(v, 2 * sign); v->ob_digit[0] = Py_SAFE_DOWNCAST( abs_ival & PyLong_MASK, unsigned long, digit); v->ob_digit[1] = Py_SAFE_DOWNCAST( @@ -352,7 +352,7 @@ PyLong_FromLong(long ival) v = _PyLong_New(ndigits); if (v != NULL) { digit *p = v->ob_digit; - Py_SET_SIZE(v, ndigits * sign); + Py_SET_SIZE(v, ndigits * sign); t = abs_ival; while (t) { *p++ = Py_SAFE_DOWNCAST( @@ -363,74 +363,74 @@ PyLong_FromLong(long ival) return (PyObject *)v; } -#define PYLONG_FROM_UINT(INT_TYPE, ival) \ - do { \ - if (IS_SMALL_UINT(ival)) { \ - return get_small_int((sdigit)(ival)); \ - } \ - /* Count the number of Python digits. */ \ - Py_ssize_t ndigits = 0; \ - INT_TYPE t = (ival); \ - while (t) { \ - ++ndigits; \ - t >>= PyLong_SHIFT; \ - } \ - PyLongObject *v = _PyLong_New(ndigits); \ - if (v == NULL) { \ - return NULL; \ - } \ - digit *p = v->ob_digit; \ - while ((ival)) { \ - *p++ = (digit)((ival) & PyLong_MASK); \ - (ival) >>= PyLong_SHIFT; \ - } \ - return (PyObject *)v; \ - } while(0) - +#define PYLONG_FROM_UINT(INT_TYPE, ival) \ + do { \ + if (IS_SMALL_UINT(ival)) { \ + return get_small_int((sdigit)(ival)); \ + } \ + /* Count the number of Python digits. */ \ + Py_ssize_t ndigits = 0; \ + INT_TYPE t = (ival); \ + while (t) { \ + ++ndigits; \ + t >>= PyLong_SHIFT; \ + } \ + PyLongObject *v = _PyLong_New(ndigits); \ + if (v == NULL) { \ + return NULL; \ + } \ + digit *p = v->ob_digit; \ + while ((ival)) { \ + *p++ = (digit)((ival) & PyLong_MASK); \ + (ival) >>= PyLong_SHIFT; \ + } \ + return (PyObject *)v; \ + } while(0) + /* Create a new int object from a C unsigned long int */ PyObject * PyLong_FromUnsignedLong(unsigned long ival) { - PYLONG_FROM_UINT(unsigned long, ival); -} - -/* Create a new int object from a C unsigned long long int. */ - -PyObject * -PyLong_FromUnsignedLongLong(unsigned long long ival) -{ - PYLONG_FROM_UINT(unsigned long long, ival); + PYLONG_FROM_UINT(unsigned long, ival); +} + +/* Create a new int object from a C unsigned long long int. */ + +PyObject * +PyLong_FromUnsignedLongLong(unsigned long long ival) +{ + PYLONG_FROM_UINT(unsigned long long, ival); +} + +/* Create a new int object from a C size_t. */ + +PyObject * +PyLong_FromSize_t(size_t ival) +{ + PYLONG_FROM_UINT(size_t, ival); } -/* Create a new int object from a C size_t. */ - -PyObject * -PyLong_FromSize_t(size_t ival) -{ - PYLONG_FROM_UINT(size_t, ival); -} - /* Create a new int object from a C double */ PyObject * PyLong_FromDouble(double dval) { - /* Try to get out cheap if this fits in a long. When a finite value of real - * floating type is converted to an integer type, the value is truncated - * toward zero. If the value of the integral part cannot be represented by - * the integer type, the behavior is undefined. Thus, we must check that - * value is in range (LONG_MIN - 1, LONG_MAX + 1). If a long has more bits - * of precision than a double, casting LONG_MIN - 1 to double may yield an - * approximation, but LONG_MAX + 1 is a power of two and can be represented - * as double exactly (assuming FLT_RADIX is 2 or 16), so for simplicity - * check against [-(LONG_MAX + 1), LONG_MAX + 1). - */ - const double int_max = (unsigned long)LONG_MAX + 1; - if (-int_max < dval && dval < int_max) { - return PyLong_FromLong((long)dval); - } - + /* Try to get out cheap if this fits in a long. When a finite value of real + * floating type is converted to an integer type, the value is truncated + * toward zero. If the value of the integral part cannot be represented by + * the integer type, the behavior is undefined. Thus, we must check that + * value is in range (LONG_MIN - 1, LONG_MAX + 1). If a long has more bits + * of precision than a double, casting LONG_MIN - 1 to double may yield an + * approximation, but LONG_MAX + 1 is a power of two and can be represented + * as double exactly (assuming FLT_RADIX is 2 or 16), so for simplicity + * check against [-(LONG_MAX + 1), LONG_MAX + 1). + */ + const double int_max = (unsigned long)LONG_MAX + 1; + if (-int_max < dval && dval < int_max) { + return PyLong_FromLong((long)dval); + } + PyLongObject *v; double frac; int i, ndig, expo, neg; @@ -450,7 +450,7 @@ PyLong_FromDouble(double dval) dval = -dval; } frac = frexp(dval, &expo); /* dval = frac*2**expo; 0.0 <= frac < 1.0 */ - assert(expo > 0); + assert(expo > 0); ndig = (expo-1) / PyLong_SHIFT + 1; /* Number of 'digits' in result */ v = _PyLong_New(ndig); if (v == NULL) @@ -462,9 +462,9 @@ PyLong_FromDouble(double dval) frac = frac - (double)bits; frac = ldexp(frac, PyLong_SHIFT); } - if (neg) { - Py_SET_SIZE(v, -(Py_SIZE(v))); - } + if (neg) { + Py_SET_SIZE(v, -(Py_SIZE(v))); + } return (PyObject *)v; } @@ -511,7 +511,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); + v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); if (v == NULL) return -1; do_decref = 1; @@ -791,7 +791,7 @@ PyLong_AsUnsignedLongMask(PyObject *op) return _PyLong_AsUnsignedLongMask(op); } - lo = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(op); + lo = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(op); if (lo == NULL) return (unsigned long)-1; @@ -828,7 +828,7 @@ _PyLong_NumBits(PyObject *vv) if ((size_t)(ndigits - 1) > SIZE_MAX / (size_t)PyLong_SHIFT) goto Overflow; result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT; - msd_bits = _Py_bit_length(msd); + msd_bits = _Py_bit_length(msd); if (SIZE_MAX - msd_bits < result) goto Overflow; result += msd_bits; @@ -948,7 +948,7 @@ _PyLong_FromByteArray(const unsigned char* bytes, size_t n, } } - Py_SET_SIZE(v, is_signed ? -idigit : idigit); + Py_SET_SIZE(v, is_signed ? -idigit : idigit); return (PyObject *)long_normalize(v); } @@ -1137,7 +1137,7 @@ PyLong_AsVoidPtr(PyObject *vv) * rewritten to use the newer PyLong_{As,From}ByteArray API. */ -#define PY_ABS_LLONG_MIN (0-(unsigned long long)LLONG_MIN) +#define PY_ABS_LLONG_MIN (0-(unsigned long long)LLONG_MIN) /* Create a new int object from a C long long int. */ @@ -1150,10 +1150,10 @@ PyLong_FromLongLong(long long ival) int ndigits = 0; int negative = 0; - if (IS_SMALL_INT(ival)) { - return get_small_int((sdigit)ival); - } - + if (IS_SMALL_INT(ival)) { + return get_small_int((sdigit)ival); + } + if (ival < 0) { /* avoid signed overflow on negation; see comments in PyLong_FromLong above. */ @@ -1176,7 +1176,7 @@ PyLong_FromLongLong(long long ival) v = _PyLong_New(ndigits); if (v != NULL) { digit *p = v->ob_digit; - Py_SET_SIZE(v, negative ? -ndigits : ndigits); + Py_SET_SIZE(v, negative ? -ndigits : ndigits); t = abs_ival; while (t) { *p++ = (digit)(t & PyLong_MASK); @@ -1197,10 +1197,10 @@ PyLong_FromSsize_t(Py_ssize_t ival) int ndigits = 0; int negative = 0; - if (IS_SMALL_INT(ival)) { - return get_small_int((sdigit)ival); - } - + if (IS_SMALL_INT(ival)) { + return get_small_int((sdigit)ival); + } + if (ival < 0) { /* avoid signed overflow when ival = SIZE_T_MIN */ abs_ival = (size_t)(-1-ival)+1; @@ -1219,7 +1219,7 @@ PyLong_FromSsize_t(Py_ssize_t ival) v = _PyLong_New(ndigits); if (v != NULL) { digit *p = v->ob_digit; - Py_SET_SIZE(v, negative ? -ndigits : ndigits); + Py_SET_SIZE(v, negative ? -ndigits : ndigits); t = abs_ival; while (t) { *p++ = (digit)(t & PyLong_MASK); @@ -1249,7 +1249,7 @@ PyLong_AsLongLong(PyObject *vv) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); + v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); if (v == NULL) return -1; do_decref = 1; @@ -1329,7 +1329,7 @@ _PyLong_AsUnsignedLongLongMask(PyObject *vv) if (vv == NULL || !PyLong_Check(vv)) { PyErr_BadInternalCall(); - return (unsigned long long) -1; + return (unsigned long long) -1; } v = (PyLongObject *)vv; switch(Py_SIZE(v)) { @@ -1357,14 +1357,14 @@ PyLong_AsUnsignedLongLongMask(PyObject *op) if (op == NULL) { PyErr_BadInternalCall(); - return (unsigned long long)-1; + return (unsigned long long)-1; } if (PyLong_Check(op)) { return _PyLong_AsUnsignedLongLongMask(op); } - lo = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(op); + lo = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(op); if (lo == NULL) return (unsigned long long)-1; @@ -1404,7 +1404,7 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); + v = (PyLongObject *)_PyLong_FromNbIndexOrNbInt(vv); if (v == NULL) return -1; do_decref = 1; @@ -1441,11 +1441,11 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow) /* Haven't lost any bits, but casting to long requires extra * care (see comment above). */ - if (x <= (unsigned long long)LLONG_MAX) { + if (x <= (unsigned long long)LLONG_MAX) { res = (long long)x * sign; } else if (sign < 0 && x == PY_ABS_LLONG_MIN) { - res = LLONG_MIN; + res = LLONG_MIN; } else { *overflow = sign; @@ -1459,102 +1459,102 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow) return res; } -int -_PyLong_UnsignedShort_Converter(PyObject *obj, void *ptr) -{ - unsigned long uval; - - if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { - PyErr_SetString(PyExc_ValueError, "value must be positive"); - return 0; - } - uval = PyLong_AsUnsignedLong(obj); - if (uval == (unsigned long)-1 && PyErr_Occurred()) - return 0; - if (uval > USHRT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large for C unsigned short"); - return 0; - } - - *(unsigned short *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned short); - return 1; -} - -int -_PyLong_UnsignedInt_Converter(PyObject *obj, void *ptr) -{ - unsigned long uval; - - if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { - PyErr_SetString(PyExc_ValueError, "value must be positive"); - return 0; - } - uval = PyLong_AsUnsignedLong(obj); - if (uval == (unsigned long)-1 && PyErr_Occurred()) - return 0; - if (uval > UINT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "Python int too large for C unsigned int"); - return 0; - } - - *(unsigned int *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned int); - return 1; -} - -int -_PyLong_UnsignedLong_Converter(PyObject *obj, void *ptr) -{ - unsigned long uval; - - if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { - PyErr_SetString(PyExc_ValueError, "value must be positive"); - return 0; - } - uval = PyLong_AsUnsignedLong(obj); - if (uval == (unsigned long)-1 && PyErr_Occurred()) - return 0; - - *(unsigned long *)ptr = uval; - return 1; -} - -int -_PyLong_UnsignedLongLong_Converter(PyObject *obj, void *ptr) -{ - unsigned long long uval; - - if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { - PyErr_SetString(PyExc_ValueError, "value must be positive"); - return 0; - } - uval = PyLong_AsUnsignedLongLong(obj); - if (uval == (unsigned long long)-1 && PyErr_Occurred()) - return 0; - - *(unsigned long long *)ptr = uval; - return 1; -} - -int -_PyLong_Size_t_Converter(PyObject *obj, void *ptr) -{ - size_t uval; - - if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { - PyErr_SetString(PyExc_ValueError, "value must be positive"); - return 0; - } - uval = PyLong_AsSize_t(obj); - if (uval == (size_t)-1 && PyErr_Occurred()) - return 0; - - *(size_t *)ptr = uval; - return 1; -} - - +int +_PyLong_UnsignedShort_Converter(PyObject *obj, void *ptr) +{ + unsigned long uval; + + if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { + PyErr_SetString(PyExc_ValueError, "value must be positive"); + return 0; + } + uval = PyLong_AsUnsignedLong(obj); + if (uval == (unsigned long)-1 && PyErr_Occurred()) + return 0; + if (uval > USHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "Python int too large for C unsigned short"); + return 0; + } + + *(unsigned short *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned short); + return 1; +} + +int +_PyLong_UnsignedInt_Converter(PyObject *obj, void *ptr) +{ + unsigned long uval; + + if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { + PyErr_SetString(PyExc_ValueError, "value must be positive"); + return 0; + } + uval = PyLong_AsUnsignedLong(obj); + if (uval == (unsigned long)-1 && PyErr_Occurred()) + return 0; + if (uval > UINT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "Python int too large for C unsigned int"); + return 0; + } + + *(unsigned int *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned int); + return 1; +} + +int +_PyLong_UnsignedLong_Converter(PyObject *obj, void *ptr) +{ + unsigned long uval; + + if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { + PyErr_SetString(PyExc_ValueError, "value must be positive"); + return 0; + } + uval = PyLong_AsUnsignedLong(obj); + if (uval == (unsigned long)-1 && PyErr_Occurred()) + return 0; + + *(unsigned long *)ptr = uval; + return 1; +} + +int +_PyLong_UnsignedLongLong_Converter(PyObject *obj, void *ptr) +{ + unsigned long long uval; + + if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { + PyErr_SetString(PyExc_ValueError, "value must be positive"); + return 0; + } + uval = PyLong_AsUnsignedLongLong(obj); + if (uval == (unsigned long long)-1 && PyErr_Occurred()) + return 0; + + *(unsigned long long *)ptr = uval; + return 1; +} + +int +_PyLong_Size_t_Converter(PyObject *obj, void *ptr) +{ + size_t uval; + + if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) { + PyErr_SetString(PyExc_ValueError, "value must be positive"); + return 0; + } + uval = PyLong_AsSize_t(obj); + if (uval == (size_t)-1 && PyErr_Occurred()) + return 0; + + *(size_t *)ptr = uval; + return 1; +} + + #define CHECK_BINOP(v,w) \ do { \ if (!PyLong_Check(v) || !PyLong_Check(w)) \ @@ -1938,7 +1938,7 @@ long_format_binary(PyObject *aa, int base, int alternate, return -1; } size_a_in_bits = (size_a - 1) * PyLong_SHIFT + - _Py_bit_length(a->ob_digit[size_a - 1]); + _Py_bit_length(a->ob_digit[size_a - 1]); /* Allow 1 character for a '-' sign. */ sz = negative + (size_a_in_bits + (bits - 1)) / bits; } @@ -2243,7 +2243,7 @@ PyLong_FromString(const char *str, char **pend, int base) "int() arg 2 must be >= 2 and <= 36"); return NULL; } - while (*str != '\0' && Py_ISSPACE(*str)) { + while (*str != '\0' && Py_ISSPACE(*str)) { str++; } if (*str == '+') { @@ -2461,7 +2461,7 @@ digit beyond the first. if (z == NULL) { return NULL; } - Py_SET_SIZE(z, 0); + Py_SET_SIZE(z, 0); /* `convwidth` consecutive input digits are treated as a single * digit in base `convmultmax`. @@ -2511,7 +2511,7 @@ digit beyond the first. assert(c < PyLong_BASE); if (Py_SIZE(z) < size_z) { *pz = (digit)c; - Py_SET_SIZE(z, Py_SIZE(z) + 1); + Py_SET_SIZE(z, Py_SIZE(z) + 1); } else { PyLongObject *tmp; @@ -2550,9 +2550,9 @@ digit beyond the first. goto onError; } if (sign < 0) { - Py_SET_SIZE(z, -(Py_SIZE(z))); + Py_SET_SIZE(z, -(Py_SIZE(z))); } - while (*str && Py_ISSPACE(*str)) { + while (*str && Py_ISSPACE(*str)) { str++; } if (*str != '\0') { @@ -2758,7 +2758,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem) /* normalize: shift w1 left so that its top digit is >= PyLong_BASE/2. shift v1 left by the same amount. Results go into w and v. */ - d = PyLong_SHIFT - _Py_bit_length(w1->ob_digit[size_w-1]); + d = PyLong_SHIFT - _Py_bit_length(w1->ob_digit[size_w-1]); carry = v_lshift(w->ob_digit, w1->ob_digit, size_w, d); assert(carry == 0); carry = v_lshift(v->ob_digit, v1->ob_digit, size_v, d); @@ -2866,8 +2866,8 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e) { Py_ssize_t a_size, a_bits, shift_digits, shift_bits, x_size; /* See below for why x_digits is always large enough. */ - digit rem; - digit x_digits[2 + (DBL_MANT_DIG + 1) / PyLong_SHIFT] = {0,}; + digit rem; + digit x_digits[2 + (DBL_MANT_DIG + 1) / PyLong_SHIFT] = {0,}; double dx; /* Correction term for round-half-to-even rounding. For a digit x, "x + half_even_correction[x & 7]" gives x rounded to the nearest @@ -2880,7 +2880,7 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e) *e = 0; return 0.0; } - a_bits = _Py_bit_length(a->ob_digit[a_size-1]); + a_bits = _Py_bit_length(a->ob_digit[a_size-1]); /* The following is an overflow-free version of the check "if ((a_size - 1) * PyLong_SHIFT + a_bits > PY_SSIZE_T_MAX) ..." */ if (a_size >= (PY_SSIZE_T_MAX - 1) / PyLong_SHIFT + 1 && @@ -2917,7 +2917,7 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e) if (a_bits <= DBL_MANT_DIG + 2) { shift_digits = (DBL_MANT_DIG + 2 - a_bits) / PyLong_SHIFT; shift_bits = (DBL_MANT_DIG + 2 - a_bits) % PyLong_SHIFT; - x_size = shift_digits; + x_size = shift_digits; rem = v_lshift(x_digits + x_size, a->ob_digit, a_size, (int)shift_bits); x_size += a_size; @@ -3005,32 +3005,32 @@ PyLong_AsDouble(PyObject *v) /* Methods */ -/* if a < b, return a negative number - if a == b, return 0 - if a > b, return a positive number */ - -static Py_ssize_t +/* if a < b, return a negative number + if a == b, return 0 + if a > b, return a positive number */ + +static Py_ssize_t long_compare(PyLongObject *a, PyLongObject *b) { - Py_ssize_t sign = Py_SIZE(a) - Py_SIZE(b); - if (sign == 0) { + Py_ssize_t sign = Py_SIZE(a) - Py_SIZE(b); + if (sign == 0) { Py_ssize_t i = Py_ABS(Py_SIZE(a)); - sdigit diff = 0; - while (--i >= 0) { - diff = (sdigit) a->ob_digit[i] - (sdigit) b->ob_digit[i]; - if (diff) { - break; - } + sdigit diff = 0; + while (--i >= 0) { + diff = (sdigit) a->ob_digit[i] - (sdigit) b->ob_digit[i]; + if (diff) { + break; + } } - sign = Py_SIZE(a) < 0 ? -diff : diff; + sign = Py_SIZE(a) < 0 ? -diff : diff; } - return sign; + return sign; } static PyObject * long_richcompare(PyObject *self, PyObject *other, int op) { - Py_ssize_t result; + Py_ssize_t result; CHECK_BINOP(self, other); if (self == other) result = 0; @@ -3182,9 +3182,9 @@ x_sub(PyLongObject *a, PyLongObject *b) } assert(borrow == 0); if (sign < 0) { - Py_SET_SIZE(z, -Py_SIZE(z)); + Py_SET_SIZE(z, -Py_SIZE(z)); } - return maybe_small_long(long_normalize(z)); + return maybe_small_long(long_normalize(z)); } static PyObject * @@ -3206,7 +3206,7 @@ long_add(PyLongObject *a, PyLongObject *b) That also means z is not an element of small_ints, so negating it in-place is safe. */ assert(Py_REFCNT(z) == 1); - Py_SET_SIZE(z, -(Py_SIZE(z))); + Py_SET_SIZE(z, -(Py_SIZE(z))); } } else @@ -3232,15 +3232,15 @@ long_sub(PyLongObject *a, PyLongObject *b) return PyLong_FromLong(MEDIUM_VALUE(a) - MEDIUM_VALUE(b)); } if (Py_SIZE(a) < 0) { - if (Py_SIZE(b) < 0) { - z = x_sub(b, a); - } - else { + if (Py_SIZE(b) < 0) { + z = x_sub(b, a); + } + else { z = x_add(a, b); - if (z != NULL) { - assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1); - Py_SET_SIZE(z, -(Py_SIZE(z))); - } + if (z != NULL) { + assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1); + Py_SET_SIZE(z, -(Py_SIZE(z))); + } } } else { @@ -3632,7 +3632,7 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b) /* Multiply the next slice of b by a. */ memcpy(bslice->ob_digit, b->ob_digit + nbdone, nbtouse * sizeof(digit)); - Py_SET_SIZE(bslice, nbtouse); + Py_SET_SIZE(bslice, nbtouse); product = k_mul(a, bslice); if (product == NULL) goto fail; @@ -3973,8 +3973,8 @@ long_true_divide(PyObject *v, PyObject *w) /* Extreme underflow */ goto underflow_or_zero; /* Next line is now safe from overflowing a Py_ssize_t */ - diff = diff * PyLong_SHIFT + _Py_bit_length(a->ob_digit[a_size - 1]) - - _Py_bit_length(b->ob_digit[b_size - 1]); + diff = diff * PyLong_SHIFT + _Py_bit_length(a->ob_digit[a_size - 1]) - + _Py_bit_length(b->ob_digit[b_size - 1]); /* Now diff = a_bits - b_bits. */ if (diff > DBL_MAX_EXP) goto overflow; @@ -4050,7 +4050,7 @@ long_true_divide(PyObject *v, PyObject *w) } x_size = Py_ABS(Py_SIZE(x)); assert(x_size > 0); /* result of division is never zero */ - x_bits = (x_size-1)*PyLong_SHIFT+_Py_bit_length(x->ob_digit[x_size-1]); + x_bits = (x_size-1)*PyLong_SHIFT+_Py_bit_length(x->ob_digit[x_size-1]); /* The number of extra bits that have to be rounded away. */ extra_bits = Py_MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG; @@ -4117,8 +4117,8 @@ long_divmod(PyObject *a, PyObject *b) } z = PyTuple_New(2); if (z != NULL) { - PyTuple_SET_ITEM(z, 0, (PyObject *) div); - PyTuple_SET_ITEM(z, 1, (PyObject *) mod); + PyTuple_SET_ITEM(z, 0, (PyObject *) div); + PyTuple_SET_ITEM(z, 1, (PyObject *) mod); } else { Py_DECREF(div); @@ -4127,98 +4127,98 @@ long_divmod(PyObject *a, PyObject *b) return z; } - -/* Compute an inverse to a modulo n, or raise ValueError if a is not - invertible modulo n. Assumes n is positive. The inverse returned - is whatever falls out of the extended Euclidean algorithm: it may - be either positive or negative, but will be smaller than n in - absolute value. - - Pure Python equivalent for long_invmod: - - def invmod(a, n): - b, c = 1, 0 - while n: - q, r = divmod(a, n) - a, b, c, n = n, c, b - q*c, r - - # at this point a is the gcd of the original inputs - if a == 1: - return b - raise ValueError("Not invertible") -*/ - -static PyLongObject * -long_invmod(PyLongObject *a, PyLongObject *n) -{ - PyLongObject *b, *c; - - /* Should only ever be called for positive n */ - assert(Py_SIZE(n) > 0); - - b = (PyLongObject *)PyLong_FromLong(1L); - if (b == NULL) { - return NULL; - } - c = (PyLongObject *)PyLong_FromLong(0L); - if (c == NULL) { - Py_DECREF(b); - return NULL; - } - Py_INCREF(a); - Py_INCREF(n); - - /* references now owned: a, b, c, n */ - while (Py_SIZE(n) != 0) { - PyLongObject *q, *r, *s, *t; - - if (l_divmod(a, n, &q, &r) == -1) { - goto Error; - } - Py_DECREF(a); - a = n; - n = r; - t = (PyLongObject *)long_mul(q, c); - Py_DECREF(q); - if (t == NULL) { - goto Error; - } - s = (PyLongObject *)long_sub(b, t); - Py_DECREF(t); - if (s == NULL) { - goto Error; - } - Py_DECREF(b); - b = c; - c = s; - } - /* references now owned: a, b, c, n */ - - Py_DECREF(c); - Py_DECREF(n); - if (long_compare(a, (PyLongObject *)_PyLong_One)) { - /* a != 1; we don't have an inverse. */ - Py_DECREF(a); - Py_DECREF(b); - PyErr_SetString(PyExc_ValueError, - "base is not invertible for the given modulus"); - return NULL; - } - else { - /* a == 1; b gives an inverse modulo n */ - Py_DECREF(a); - return b; - } - - Error: - Py_DECREF(a); - Py_DECREF(b); - Py_DECREF(c); - Py_DECREF(n); - return NULL; -} - - + +/* Compute an inverse to a modulo n, or raise ValueError if a is not + invertible modulo n. Assumes n is positive. The inverse returned + is whatever falls out of the extended Euclidean algorithm: it may + be either positive or negative, but will be smaller than n in + absolute value. + + Pure Python equivalent for long_invmod: + + def invmod(a, n): + b, c = 1, 0 + while n: + q, r = divmod(a, n) + a, b, c, n = n, c, b - q*c, r + + # at this point a is the gcd of the original inputs + if a == 1: + return b + raise ValueError("Not invertible") +*/ + +static PyLongObject * +long_invmod(PyLongObject *a, PyLongObject *n) +{ + PyLongObject *b, *c; + + /* Should only ever be called for positive n */ + assert(Py_SIZE(n) > 0); + + b = (PyLongObject *)PyLong_FromLong(1L); + if (b == NULL) { + return NULL; + } + c = (PyLongObject *)PyLong_FromLong(0L); + if (c == NULL) { + Py_DECREF(b); + return NULL; + } + Py_INCREF(a); + Py_INCREF(n); + + /* references now owned: a, b, c, n */ + while (Py_SIZE(n) != 0) { + PyLongObject *q, *r, *s, *t; + + if (l_divmod(a, n, &q, &r) == -1) { + goto Error; + } + Py_DECREF(a); + a = n; + n = r; + t = (PyLongObject *)long_mul(q, c); + Py_DECREF(q); + if (t == NULL) { + goto Error; + } + s = (PyLongObject *)long_sub(b, t); + Py_DECREF(t); + if (s == NULL) { + goto Error; + } + Py_DECREF(b); + b = c; + c = s; + } + /* references now owned: a, b, c, n */ + + Py_DECREF(c); + Py_DECREF(n); + if (long_compare(a, (PyLongObject *)_PyLong_One)) { + /* a != 1; we don't have an inverse. */ + Py_DECREF(a); + Py_DECREF(b); + PyErr_SetString(PyExc_ValueError, + "base is not invertible for the given modulus"); + return NULL; + } + else { + /* a == 1; b gives an inverse modulo n */ + Py_DECREF(a); + return b; + } + + Error: + Py_DECREF(a); + Py_DECREF(b); + Py_DECREF(c); + Py_DECREF(n); + return NULL; +} + + /* pow(v, w, x) */ static PyObject * long_pow(PyObject *v, PyObject *w, PyObject *x) @@ -4252,14 +4252,14 @@ long_pow(PyObject *v, PyObject *w, PyObject *x) Py_RETURN_NOTIMPLEMENTED; } - if (Py_SIZE(b) < 0 && c == NULL) { - /* if exponent is negative and there's no modulus: - return a float. This works because we know + if (Py_SIZE(b) < 0 && c == NULL) { + /* if exponent is negative and there's no modulus: + return a float. This works because we know that this calls float_pow() which converts its arguments to double. */ - Py_DECREF(a); - Py_DECREF(b); - return PyFloat_Type.tp_as_number->nb_power(v, w, x); + Py_DECREF(a); + Py_DECREF(b); + return PyFloat_Type.tp_as_number->nb_power(v, w, x); } if (c) { @@ -4294,27 +4294,27 @@ long_pow(PyObject *v, PyObject *w, PyObject *x) goto Done; } - /* if exponent is negative, negate the exponent and - replace the base with a modular inverse */ - if (Py_SIZE(b) < 0) { - temp = (PyLongObject *)_PyLong_Copy(b); - if (temp == NULL) - goto Error; - Py_DECREF(b); - b = temp; - temp = NULL; - _PyLong_Negate(&b); - if (b == NULL) - goto Error; - - temp = long_invmod(a, c); - if (temp == NULL) - goto Error; - Py_DECREF(a); - a = temp; - temp = NULL; - } - + /* if exponent is negative, negate the exponent and + replace the base with a modular inverse */ + if (Py_SIZE(b) < 0) { + temp = (PyLongObject *)_PyLong_Copy(b); + if (temp == NULL) + goto Error; + Py_DECREF(b); + b = temp; + temp = NULL; + _PyLong_Negate(&b); + if (b == NULL) + goto Error; + + temp = long_invmod(a, c); + if (temp == NULL) + goto Error; + Py_DECREF(a); + a = temp; + temp = NULL; + } + /* Reduce base by modulus in some cases: 1. If base < 0. Forcing the base non-negative makes things easier. 2. If base is obviously larger than the modulus. The "small @@ -4449,7 +4449,7 @@ long_neg(PyLongObject *v) return PyLong_FromLong(-MEDIUM_VALUE(v)); z = (PyLongObject *)_PyLong_Copy(v); if (z != NULL) - Py_SET_SIZE(z, -(Py_SIZE(v))); + Py_SET_SIZE(z, -(Py_SIZE(v))); return (PyObject *)z; } @@ -4470,9 +4470,9 @@ long_bool(PyLongObject *v) /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */ static int -divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift) +divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift) { - assert(PyLong_Check(shiftby)); + assert(PyLong_Check(shiftby)); assert(Py_SIZE(shiftby) >= 0); Py_ssize_t lshiftby = PyLong_AsSsize_t((PyObject *)shiftby); if (lshiftby >= 0) { @@ -4484,7 +4484,7 @@ divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift) be that PyLong_AsSsize_t raised an OverflowError. */ assert(PyErr_ExceptionMatches(PyExc_OverflowError)); PyErr_Clear(); - PyLongObject *wordshift_obj = divrem1((PyLongObject *)shiftby, PyLong_SHIFT, remshift); + PyLongObject *wordshift_obj = divrem1((PyLongObject *)shiftby, PyLong_SHIFT, remshift); if (wordshift_obj == NULL) { return -1; } @@ -4502,11 +4502,11 @@ divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift) } static PyObject * -long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) +long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) { PyLongObject *z = NULL; - Py_ssize_t newsize, hishift, i, j; - digit lomask, himask; + Py_ssize_t newsize, hishift, i, j; + digit lomask, himask; if (Py_SIZE(a) < 0) { /* Right shifting negative numbers is harder */ @@ -4514,7 +4514,7 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) a1 = (PyLongObject *) long_invert(a); if (a1 == NULL) return NULL; - a2 = (PyLongObject *) long_rshift1(a1, wordshift, remshift); + a2 = (PyLongObject *) long_rshift1(a1, wordshift, remshift); Py_DECREF(a1); if (a2 == NULL) return NULL; @@ -4525,14 +4525,14 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) newsize = Py_SIZE(a) - wordshift; if (newsize <= 0) return PyLong_FromLong(0); - hishift = PyLong_SHIFT - remshift; + hishift = PyLong_SHIFT - remshift; lomask = ((digit)1 << hishift) - 1; himask = PyLong_MASK ^ lomask; z = _PyLong_New(newsize); if (z == NULL) return NULL; for (i = 0, j = wordshift; i < newsize; i++, j++) { - z->ob_digit[i] = (a->ob_digit[j] >> remshift) & lomask; + z->ob_digit[i] = (a->ob_digit[j] >> remshift) & lomask; if (i+1 < newsize) z->ob_digit[i] |= (a->ob_digit[j+1] << hishift) & himask; } @@ -4542,9 +4542,9 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) } static PyObject * -long_rshift(PyObject *a, PyObject *b) +long_rshift(PyObject *a, PyObject *b) { - Py_ssize_t wordshift; + Py_ssize_t wordshift; digit remshift; CHECK_BINOP(a, b); @@ -4558,33 +4558,33 @@ long_rshift(PyObject *a, PyObject *b) } if (divmod_shift(b, &wordshift, &remshift) < 0) return NULL; - return long_rshift1((PyLongObject *)a, wordshift, remshift); -} - -/* Return a >> shiftby. */ -PyObject * -_PyLong_Rshift(PyObject *a, size_t shiftby) -{ - Py_ssize_t wordshift; - digit remshift; - - assert(PyLong_Check(a)); - if (Py_SIZE(a) == 0) { - return PyLong_FromLong(0); - } - wordshift = shiftby / PyLong_SHIFT; - remshift = shiftby % PyLong_SHIFT; - return long_rshift1((PyLongObject *)a, wordshift, remshift); -} - -static PyObject * -long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) -{ - /* This version due to Tim Peters */ - PyLongObject *z = NULL; - Py_ssize_t oldsize, newsize, i, j; - twodigits accum; - + return long_rshift1((PyLongObject *)a, wordshift, remshift); +} + +/* Return a >> shiftby. */ +PyObject * +_PyLong_Rshift(PyObject *a, size_t shiftby) +{ + Py_ssize_t wordshift; + digit remshift; + + assert(PyLong_Check(a)); + if (Py_SIZE(a) == 0) { + return PyLong_FromLong(0); + } + wordshift = shiftby / PyLong_SHIFT; + remshift = shiftby % PyLong_SHIFT; + return long_rshift1((PyLongObject *)a, wordshift, remshift); +} + +static PyObject * +long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) +{ + /* This version due to Tim Peters */ + PyLongObject *z = NULL; + Py_ssize_t oldsize, newsize, i, j; + twodigits accum; + oldsize = Py_ABS(Py_SIZE(a)); newsize = oldsize + wordshift; if (remshift) @@ -4594,7 +4594,7 @@ long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) return NULL; if (Py_SIZE(a) < 0) { assert(Py_REFCNT(z) == 1); - Py_SET_SIZE(z, -Py_SIZE(z)); + Py_SET_SIZE(z, -Py_SIZE(z)); } for (i = 0; i < wordshift; i++) z->ob_digit[i] = 0; @@ -4612,42 +4612,42 @@ long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift) return (PyObject *) maybe_small_long(z); } -static PyObject * -long_lshift(PyObject *a, PyObject *b) -{ - Py_ssize_t wordshift; - digit remshift; - - CHECK_BINOP(a, b); - - if (Py_SIZE(b) < 0) { - PyErr_SetString(PyExc_ValueError, "negative shift count"); - return NULL; - } - if (Py_SIZE(a) == 0) { - return PyLong_FromLong(0); - } - if (divmod_shift(b, &wordshift, &remshift) < 0) - return NULL; - return long_lshift1((PyLongObject *)a, wordshift, remshift); -} - -/* Return a << shiftby. */ -PyObject * -_PyLong_Lshift(PyObject *a, size_t shiftby) -{ - Py_ssize_t wordshift; - digit remshift; - - assert(PyLong_Check(a)); - if (Py_SIZE(a) == 0) { - return PyLong_FromLong(0); - } - wordshift = shiftby / PyLong_SHIFT; - remshift = shiftby % PyLong_SHIFT; - return long_lshift1((PyLongObject *)a, wordshift, remshift); -} - +static PyObject * +long_lshift(PyObject *a, PyObject *b) +{ + Py_ssize_t wordshift; + digit remshift; + + CHECK_BINOP(a, b); + + if (Py_SIZE(b) < 0) { + PyErr_SetString(PyExc_ValueError, "negative shift count"); + return NULL; + } + if (Py_SIZE(a) == 0) { + return PyLong_FromLong(0); + } + if (divmod_shift(b, &wordshift, &remshift) < 0) + return NULL; + return long_lshift1((PyLongObject *)a, wordshift, remshift); +} + +/* Return a << shiftby. */ +PyObject * +_PyLong_Lshift(PyObject *a, size_t shiftby) +{ + Py_ssize_t wordshift; + digit remshift; + + assert(PyLong_Check(a)); + if (Py_SIZE(a) == 0) { + return PyLong_FromLong(0); + } + wordshift = shiftby / PyLong_SHIFT; + remshift = shiftby % PyLong_SHIFT; + return long_lshift1((PyLongObject *)a, wordshift, remshift); +} + /* Compute two's complement of digit vector a[0:m], writing result to z[0:m]. The digit vector a need not be normalized, but should not be entirely zero. a and z may point to the same digit vector. */ @@ -4738,7 +4738,7 @@ long_bitwise(PyLongObject *a, size_z = negb ? size_b : size_a; break; default: - Py_UNREACHABLE(); + Py_UNREACHABLE(); } /* We allow an extra digit if z is negative, to make sure that @@ -4765,7 +4765,7 @@ long_bitwise(PyLongObject *a, z->ob_digit[i] = a->ob_digit[i] ^ b->ob_digit[i]; break; default: - Py_UNREACHABLE(); + Py_UNREACHABLE(); } /* Copy any remaining digits of a, inverting if necessary. */ @@ -4778,7 +4778,7 @@ long_bitwise(PyLongObject *a, /* Complement result if negative. */ if (negz) { - Py_SET_SIZE(z, -(Py_SIZE(z))); + Py_SET_SIZE(z, -(Py_SIZE(z))); z->ob_digit[size_z] = PyLong_MASK; v_complement(z->ob_digit, z->ob_digit, size_z+1); } @@ -4865,7 +4865,7 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg) alloc_b = Py_SIZE(b); /* reduce until a fits into 2 digits */ while ((size_a = Py_SIZE(a)) > 2) { - nbits = _Py_bit_length(a->ob_digit[size_a-1]); + nbits = _Py_bit_length(a->ob_digit[size_a-1]); /* extract top 2*PyLong_SHIFT bits of a into x, along with corresponding bits of b into y */ size_b = Py_SIZE(b); @@ -4925,9 +4925,9 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg) T = -A; A = -B; B = T; T = -C; C = -D; D = T; } - if (c != NULL) { - Py_SET_SIZE(c, size_a); - } + if (c != NULL) { + Py_SET_SIZE(c, size_a); + } else if (Py_REFCNT(a) == 1) { Py_INCREF(a); c = a; @@ -4939,13 +4939,13 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg) goto error; } - if (d != NULL) { - Py_SET_SIZE(d, size_a); - } + if (d != NULL) { + Py_SET_SIZE(d, size_a); + } else if (Py_REFCNT(b) == 1 && size_a <= alloc_b) { Py_INCREF(b); d = b; - Py_SET_SIZE(d, size_a); + Py_SET_SIZE(d, size_a); } else { alloc_b = size_a; @@ -5001,7 +5001,7 @@ simple: /* a fits into a long, so b must too */ x = PyLong_AsLong((PyObject *)a); y = PyLong_AsLong((PyObject *)b); -#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT +#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT x = PyLong_AsLongLong((PyObject *)a); y = PyLong_AsLongLong((PyObject *)b); #else @@ -5020,7 +5020,7 @@ simple: } #if LONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT return PyLong_FromLong(x); -#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT +#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT return PyLong_FromLongLong(x); #else # error "_PyLong_GCD" @@ -5086,7 +5086,7 @@ long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase) if (PyUnicode_Check(x)) return PyLong_FromUnicodeObject(x, (int)base); else if (PyByteArray_Check(x) || PyBytes_Check(x)) { - const char *string; + const char *string; if (PyByteArray_Check(x)) string = PyByteArray_AS_STRING(x); else @@ -5125,10 +5125,10 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase) return NULL; } assert(PyLong_Check(newobj)); - Py_SET_SIZE(newobj, Py_SIZE(tmp)); - for (i = 0; i < n; i++) { + Py_SET_SIZE(newobj, Py_SIZE(tmp)); + for (i = 0; i < n; i++) { newobj->ob_digit[i] = tmp->ob_digit[i]; - } + } Py_DECREF(tmp); return (PyObject *)newobj; } @@ -5145,14 +5145,14 @@ int___getnewargs___impl(PyObject *self) } static PyObject * -long_get0(PyObject *Py_UNUSED(self), void *Py_UNUSED(context)) -{ +long_get0(PyObject *Py_UNUSED(self), void *Py_UNUSED(context)) +{ return PyLong_FromLong(0L); } static PyObject * -long_get1(PyObject *Py_UNUSED(self), void *Py_UNUSED(ignored)) -{ +long_get1(PyObject *Py_UNUSED(self), void *Py_UNUSED(ignored)) +{ return PyLong_FromLong(1L); } @@ -5192,8 +5192,8 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b) { PyLongObject *quo = NULL, *rem = NULL; PyObject *twice_rem, *result, *temp; - int quo_is_odd, quo_is_neg; - Py_ssize_t cmp; + int quo_is_odd, quo_is_neg; + Py_ssize_t cmp; /* Equivalent Python code: @@ -5386,7 +5386,7 @@ int_bit_length_impl(PyObject *self) return PyLong_FromLong(0); msd = ((PyLongObject *)self)->ob_digit[ndigits-1]; - msd_bits = _Py_bit_length(msd); + msd_bits = _Py_bit_length(msd); if (ndigits <= PY_SSIZE_T_MAX/PyLong_SHIFT) return PyLong_FromSsize_t((ndigits-1)*PyLong_SHIFT + msd_bits); @@ -5422,35 +5422,35 @@ int_bit_length_impl(PyObject *self) return NULL; } - -/*[clinic input] -int.as_integer_ratio - -Return integer ratio. - -Return a pair of integers, whose ratio is exactly equal to the original int -and with a positive denominator. - ->>> (10).as_integer_ratio() -(10, 1) ->>> (-10).as_integer_ratio() -(-10, 1) ->>> (0).as_integer_ratio() -(0, 1) -[clinic start generated code]*/ - + +/*[clinic input] +int.as_integer_ratio + +Return integer ratio. + +Return a pair of integers, whose ratio is exactly equal to the original int +and with a positive denominator. + +>>> (10).as_integer_ratio() +(10, 1) +>>> (-10).as_integer_ratio() +(-10, 1) +>>> (0).as_integer_ratio() +(0, 1) +[clinic start generated code]*/ + static PyObject * -int_as_integer_ratio_impl(PyObject *self) -/*[clinic end generated code: output=e60803ae1cc8621a input=55ce3058e15de393]*/ +int_as_integer_ratio_impl(PyObject *self) +/*[clinic end generated code: output=e60803ae1cc8621a input=55ce3058e15de393]*/ { - PyObject *ratio_tuple; - PyObject *numerator = long_long(self); - if (numerator == NULL) { - return NULL; - } - ratio_tuple = PyTuple_Pack(2, numerator, _PyLong_One); - Py_DECREF(numerator); - return ratio_tuple; + PyObject *ratio_tuple; + PyObject *numerator = long_long(self); + if (numerator == NULL) { + return NULL; + } + ratio_tuple = PyTuple_Pack(2, numerator, _PyLong_One); + Py_DECREF(numerator); + return ratio_tuple; } /*[clinic input] @@ -5562,30 +5562,30 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, Py_DECREF(bytes); if (long_obj != NULL && type != &PyLong_Type) { - Py_SETREF(long_obj, PyObject_CallOneArg((PyObject *)type, long_obj)); + Py_SETREF(long_obj, PyObject_CallOneArg((PyObject *)type, long_obj)); } return long_obj; } -static PyObject * -long_long_meth(PyObject *self, PyObject *Py_UNUSED(ignored)) -{ - return long_long(self); -} - +static PyObject * +long_long_meth(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return long_long(self); +} + static PyMethodDef long_methods[] = { - {"conjugate", long_long_meth, METH_NOARGS, + {"conjugate", long_long_meth, METH_NOARGS, "Returns self, the complex conjugate of any int."}, INT_BIT_LENGTH_METHODDEF INT_TO_BYTES_METHODDEF INT_FROM_BYTES_METHODDEF - INT_AS_INTEGER_RATIO_METHODDEF - {"__trunc__", long_long_meth, METH_NOARGS, + INT_AS_INTEGER_RATIO_METHODDEF + {"__trunc__", long_long_meth, METH_NOARGS, "Truncating an Integral returns itself."}, - {"__floor__", long_long_meth, METH_NOARGS, + {"__floor__", long_long_meth, METH_NOARGS, "Flooring an Integral returns itself."}, - {"__ceil__", long_long_meth, METH_NOARGS, + {"__ceil__", long_long_meth, METH_NOARGS, "Ceiling of an Integral returns itself."}, {"__round__", (PyCFunction)long_round, METH_VARARGS, "Rounding an Integral returns itself.\n" @@ -5598,19 +5598,19 @@ static PyMethodDef long_methods[] = { static PyGetSetDef long_getset[] = { {"real", - (getter)long_long_meth, (setter)NULL, + (getter)long_long_meth, (setter)NULL, "the real part of a complex number", NULL}, {"imag", - long_get0, (setter)NULL, + long_get0, (setter)NULL, "the imaginary part of a complex number", NULL}, {"numerator", - (getter)long_long_meth, (setter)NULL, + (getter)long_long_meth, (setter)NULL, "the numerator of a rational number in lowest terms", NULL}, {"denominator", - long_get1, (setter)NULL, + long_get1, (setter)NULL, "the denominator of a rational number in lowest terms", NULL}, {NULL} /* Sentinel */ @@ -5640,12 +5640,12 @@ static PyNumberMethods long_as_number = { long_divmod, /*nb_divmod*/ long_pow, /*nb_power*/ (unaryfunc)long_neg, /*nb_negative*/ - long_long, /*tp_positive*/ + long_long, /*tp_positive*/ (unaryfunc)long_abs, /*tp_absolute*/ (inquiry)long_bool, /*tp_bool*/ (unaryfunc)long_invert, /*nb_invert*/ long_lshift, /*nb_lshift*/ - long_rshift, /*nb_rshift*/ + long_rshift, /*nb_rshift*/ long_and, /*nb_and*/ long_xor, /*nb_xor*/ long_or, /*nb_or*/ @@ -5674,18 +5674,18 @@ PyTypeObject PyLong_Type = { "int", /* tp_name */ offsetof(PyLongObject, ob_digit), /* tp_basicsize */ sizeof(digit), /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ long_to_decimal_string, /* tp_repr */ &long_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)long_hash, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ @@ -5717,7 +5717,7 @@ static PyTypeObject Int_InfoType; PyDoc_STRVAR(int_info__doc__, "sys.int_info\n\ \n\ -A named tuple that holds information about Python's\n\ +A named tuple that holds information about Python's\n\ internal representation of integers. The attributes are read only."); static PyStructSequence_Field int_info_fields[] = { @@ -5753,58 +5753,58 @@ PyLong_GetInfo(void) } int -_PyLong_Init(PyThreadState *tstate) +_PyLong_Init(PyThreadState *tstate) { #if NSMALLNEGINTS + NSMALLPOSINTS > 0 - for (Py_ssize_t i=0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { - sdigit ival = (sdigit)i - NSMALLNEGINTS; - int size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1); + for (Py_ssize_t i=0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { + sdigit ival = (sdigit)i - NSMALLNEGINTS; + int size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1); - PyLongObject *v = _PyLong_New(1); - if (!v) { - return -1; - } + PyLongObject *v = _PyLong_New(1); + if (!v) { + return -1; + } - Py_SET_SIZE(v, size); + Py_SET_SIZE(v, size); v->ob_digit[0] = (digit)abs(ival); - - tstate->interp->small_ints[i] = v; + + tstate->interp->small_ints[i] = v; } #endif - if (_Py_IsMainInterpreter(tstate)) { - _PyLong_Zero = PyLong_FromLong(0); - if (_PyLong_Zero == NULL) { + if (_Py_IsMainInterpreter(tstate)) { + _PyLong_Zero = PyLong_FromLong(0); + if (_PyLong_Zero == NULL) { + return 0; + } + + _PyLong_One = PyLong_FromLong(1); + if (_PyLong_One == NULL) { return 0; - } - - _PyLong_One = PyLong_FromLong(1); - if (_PyLong_One == NULL) { - return 0; - } - - /* initialize int_info */ - if (Int_InfoType.tp_name == NULL) { - if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) { - return 0; - } - } + } + + /* initialize int_info */ + if (Int_InfoType.tp_name == NULL) { + if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) { + return 0; + } + } } return 1; } void -_PyLong_Fini(PyThreadState *tstate) +_PyLong_Fini(PyThreadState *tstate) { - if (_Py_IsMainInterpreter(tstate)) { - Py_CLEAR(_PyLong_One); - Py_CLEAR(_PyLong_Zero); - } - + if (_Py_IsMainInterpreter(tstate)) { + Py_CLEAR(_PyLong_One); + Py_CLEAR(_PyLong_Zero); + } + #if NSMALLNEGINTS + NSMALLPOSINTS > 0 - for (Py_ssize_t i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { - Py_CLEAR(tstate->interp->small_ints[i]); + for (Py_ssize_t i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { + Py_CLEAR(tstate->interp->small_ints[i]); } #endif } diff --git a/contrib/tools/python3/src/Objects/memoryobject.c b/contrib/tools/python3/src/Objects/memoryobject.c index 61a9c7ed23..682bbe8a61 100644 --- a/contrib/tools/python3/src/Objects/memoryobject.c +++ b/contrib/tools/python3/src/Objects/memoryobject.c @@ -1,28 +1,28 @@ -/* - * Memoryview object implementation - * -------------------------------- - * - * This implementation is a complete rewrite contributed by Stefan Krah in - * Python 3.3. Substantial credit goes to Antoine Pitrou (who had already - * fortified and rewritten the previous implementation) and Nick Coghlan - * (who came up with the idea of the ManagedBuffer) for analyzing the complex - * ownership rules. - * - */ +/* + * Memoryview object implementation + * -------------------------------- + * + * This implementation is a complete rewrite contributed by Stefan Krah in + * Python 3.3. Substantial credit goes to Antoine Pitrou (who had already + * fortified and rewritten the previous implementation) and Nick Coghlan + * (who came up with the idea of the ManagedBuffer) for analyzing the complex + * ownership rules. + * + */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_object.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_object.h" #include "pystrhex.h" #include <stddef.h> -/*[clinic input] -class memoryview "PyMemoryViewObject *" "&PyMemoryView_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e2e49d2192835219]*/ +/*[clinic input] +class memoryview "PyMemoryViewObject *" "&PyMemoryView_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e2e49d2192835219]*/ + +#include "clinic/memoryobject.c.h" -#include "clinic/memoryobject.c.h" - /****************************************************************************/ /* ManagedBuffer Object */ /****************************************************************************/ @@ -156,10 +156,10 @@ PyTypeObject _PyManagedBuffer_Type = { sizeof(_PyManagedBufferObject), 0, (destructor)mbuf_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1057,8 +1057,8 @@ _memory_release(PyMemoryViewObject *self) return -1; } - PyErr_SetString(PyExc_SystemError, - "_memory_release(): negative export count"); + PyErr_SetString(PyExc_SystemError, + "_memory_release(): negative export count"); return -1; } @@ -1415,21 +1415,21 @@ error: return NULL; } -static PyObject * -memory_toreadonly(PyMemoryViewObject *self, PyObject *noargs) -{ - CHECK_RELEASED(self); - /* Even if self is already readonly, we still need to create a new - * object for .release() to work correctly. - */ - self = (PyMemoryViewObject *) mbuf_add_view(self->mbuf, &self->view); - if (self != NULL) { - self->view.readonly = 1; - }; - return (PyObject *) self; -} - - +static PyObject * +memory_toreadonly(PyMemoryViewObject *self, PyObject *noargs) +{ + CHECK_RELEASED(self); + /* Even if self is already readonly, we still need to create a new + * object for .release() to work correctly. + */ + self = (PyMemoryViewObject *) mbuf_add_view(self->mbuf, &self->view); + if (self != NULL) { + self->view.readonly = 1; + }; + return (PyObject *) self; +} + + /**************************************************************************/ /* getbuffer */ /**************************************************************************/ @@ -1691,8 +1691,8 @@ unpack_single(const char *ptr, const char *fmt) switch (fmt[0]) { /* signed integers and fast path for 'B' */ - case 'B': uc = *((const unsigned char *)ptr); goto convert_uc; - case 'b': ld = *((const signed char *)ptr); goto convert_ld; + case 'B': uc = *((const unsigned char *)ptr); goto convert_uc; + case 'b': ld = *((const signed char *)ptr); goto convert_ld; case 'h': UNPACK_SINGLE(ld, ptr, short); goto convert_ld; case 'i': UNPACK_SINGLE(ld, ptr, int); goto convert_ld; case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld; @@ -1972,7 +1972,7 @@ struct_get_unpacker(const char *fmt, Py_ssize_t itemsize) if (format == NULL) goto error; - structobj = PyObject_CallOneArg(Struct, format); + structobj = PyObject_CallOneArg(Struct, format); if (structobj == NULL) goto error; @@ -2011,7 +2011,7 @@ struct_unpack_single(const char *ptr, struct unpacker *x) PyObject *v; memcpy(x->item, ptr, x->itemsize); - v = PyObject_CallOneArg(x->unpack_from, x->mview); + v = PyObject_CallOneArg(x->unpack_from, x->mview); if (v == NULL) return NULL; @@ -2136,39 +2136,39 @@ memory_tolist(PyMemoryViewObject *mv, PyObject *noargs) } static PyObject * -memory_tobytes(PyMemoryViewObject *self, PyObject *args, PyObject *kwds) +memory_tobytes(PyMemoryViewObject *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"order", NULL}; + static char *kwlist[] = {"order", NULL}; Py_buffer *src = VIEW_ADDR(self); - char *order = NULL; - char ord = 'C'; - PyObject *bytes; + char *order = NULL; + char ord = 'C'; + PyObject *bytes; CHECK_RELEASED(self); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|z", kwlist, &order)) { - return NULL; - } - - if (order) { - if (strcmp(order, "F") == 0) { - ord = 'F'; - } - else if (strcmp(order, "A") == 0) { - ord = 'A'; - } - else if (strcmp(order, "C") != 0) { - PyErr_SetString(PyExc_ValueError, - "order must be 'C', 'F' or 'A'"); - return NULL; - } - } - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|z", kwlist, &order)) { + return NULL; + } + + if (order) { + if (strcmp(order, "F") == 0) { + ord = 'F'; + } + else if (strcmp(order, "A") == 0) { + ord = 'A'; + } + else if (strcmp(order, "C") != 0) { + PyErr_SetString(PyExc_ValueError, + "order must be 'C', 'F' or 'A'"); + return NULL; + } + } + bytes = PyBytes_FromStringAndSize(NULL, src->len); if (bytes == NULL) return NULL; - if (PyBuffer_ToContiguous(PyBytes_AS_STRING(bytes), src, src->len, ord) < 0) { + if (PyBuffer_ToContiguous(PyBytes_AS_STRING(bytes), src, src->len, ord) < 0) { Py_DECREF(bytes); return NULL; } @@ -2176,33 +2176,33 @@ memory_tobytes(PyMemoryViewObject *self, PyObject *args, PyObject *kwds) return bytes; } -/*[clinic input] -memoryview.hex - - sep: object = NULL - An optional single character or byte to separate hex bytes. - bytes_per_sep: int = 1 - How many bytes between separators. Positive values count from the - right, negative values count from the left. - -Return the data in the buffer as a str of hexadecimal numbers. - -Example: ->>> value = memoryview(b'\xb9\x01\xef') ->>> value.hex() -'b901ef' ->>> value.hex(':') -'b9:01:ef' ->>> value.hex(':', 2) -'b9:01ef' ->>> value.hex(':', -2) -'b901:ef' -[clinic start generated code]*/ - +/*[clinic input] +memoryview.hex + + sep: object = NULL + An optional single character or byte to separate hex bytes. + bytes_per_sep: int = 1 + How many bytes between separators. Positive values count from the + right, negative values count from the left. + +Return the data in the buffer as a str of hexadecimal numbers. + +Example: +>>> value = memoryview(b'\xb9\x01\xef') +>>> value.hex() +'b901ef' +>>> value.hex(':') +'b9:01:ef' +>>> value.hex(':', 2) +'b9:01ef' +>>> value.hex(':', -2) +'b901:ef' +[clinic start generated code]*/ + static PyObject * -memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep, - int bytes_per_sep) -/*[clinic end generated code: output=430ca760f94f3ca7 input=539f6a3a5fb56946]*/ +memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep, + int bytes_per_sep) +/*[clinic end generated code: output=430ca760f94f3ca7 input=539f6a3a5fb56946]*/ { Py_buffer *src = VIEW_ADDR(self); PyObject *bytes; @@ -2211,21 +2211,21 @@ memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep, CHECK_RELEASED(self); if (MV_C_CONTIGUOUS(self->flags)) { - return _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep); + return _Py_strhex_with_sep(src->buf, src->len, sep, bytes_per_sep); } - bytes = PyBytes_FromStringAndSize(NULL, src->len); + bytes = PyBytes_FromStringAndSize(NULL, src->len); if (bytes == NULL) return NULL; - if (PyBuffer_ToContiguous(PyBytes_AS_STRING(bytes), src, src->len, 'C') < 0) { - Py_DECREF(bytes); - return NULL; - } - - ret = _Py_strhex_with_sep( - PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes), - sep, bytes_per_sep); + if (PyBuffer_ToContiguous(PyBytes_AS_STRING(bytes), src, src->len, 'C') < 0) { + Py_DECREF(bytes); + return NULL; + } + + ret = _Py_strhex_with_sep( + PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes), + sep, bytes_per_sep); Py_DECREF(bytes); return ret; @@ -2420,9 +2420,9 @@ is_multiindex(PyObject *key) size = PyTuple_GET_SIZE(key); for (i = 0; i < size; i++) { PyObject *x = PyTuple_GET_ITEM(key, i); - if (!_PyIndex_Check(x)) { + if (!_PyIndex_Check(x)) { return 0; - } + } } return 1; } @@ -2459,7 +2459,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key) } } - if (_PyIndex_Check(key)) { + if (_PyIndex_Check(key)) { Py_ssize_t index; index = PyNumber_AsSsize_t(key, PyExc_IndexError); if (index == -1 && PyErr_Occurred()) @@ -2530,7 +2530,7 @@ memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value) } } - if (_PyIndex_Check(key)) { + if (_PyIndex_Check(key)) { Py_ssize_t index; if (1 < view->ndim) { PyErr_SetString(PyExc_NotImplementedError, @@ -2694,8 +2694,8 @@ unpack_cmp(const char *p, const char *q, char fmt, switch (fmt) { /* signed integers and fast path for 'B' */ - case 'B': return *((const unsigned char *)p) == *((const unsigned char *)q); - case 'b': return *((const signed char *)p) == *((const signed char *)q); + case 'B': return *((const unsigned char *)p) == *((const unsigned char *)q); + case 'b': return *((const signed char *)p) == *((const signed char *)q); case 'h': CMP_SINGLE(p, q, short); return equal; case 'i': CMP_SINGLE(p, q, int); return equal; case 'l': CMP_SINGLE(p, q, long); return equal; @@ -3127,13 +3127,13 @@ PyDoc_STRVAR(memory_release_doc, \n\ Release the underlying buffer exposed by the memoryview object."); PyDoc_STRVAR(memory_tobytes_doc, -"tobytes($self, /, order=None)\n--\n\ +"tobytes($self, /, order=None)\n--\n\ \n\ -Return the data in the buffer as a byte string. Order can be {'C', 'F', 'A'}.\n\ -When order is 'C' or 'F', the data of the original array is converted to C or\n\ -Fortran order. For contiguous views, 'A' returns an exact copy of the physical\n\ -memory. In particular, in-memory Fortran order is preserved. For non-contiguous\n\ -views, the data is converted to C first. order=None is the same as order='C'."); +Return the data in the buffer as a byte string. Order can be {'C', 'F', 'A'}.\n\ +When order is 'C' or 'F', the data of the original array is converted to C or\n\ +Fortran order. For contiguous views, 'A' returns an exact copy of the physical\n\ +memory. In particular, in-memory Fortran order is preserved. For non-contiguous\n\ +views, the data is converted to C first. order=None is the same as order='C'."); PyDoc_STRVAR(memory_tolist_doc, "tolist($self, /)\n--\n\ \n\ @@ -3142,18 +3142,18 @@ PyDoc_STRVAR(memory_cast_doc, "cast($self, /, format, *, shape)\n--\n\ \n\ Cast a memoryview to a new format or shape."); -PyDoc_STRVAR(memory_toreadonly_doc, -"toreadonly($self, /)\n--\n\ -\n\ -Return a readonly version of the memoryview."); +PyDoc_STRVAR(memory_toreadonly_doc, +"toreadonly($self, /)\n--\n\ +\n\ +Return a readonly version of the memoryview."); static PyMethodDef memory_methods[] = { {"release", (PyCFunction)memory_release, METH_NOARGS, memory_release_doc}, - {"tobytes", (PyCFunction)(void(*)(void))memory_tobytes, METH_VARARGS|METH_KEYWORDS, memory_tobytes_doc}, - MEMORYVIEW_HEX_METHODDEF + {"tobytes", (PyCFunction)(void(*)(void))memory_tobytes, METH_VARARGS|METH_KEYWORDS, memory_tobytes_doc}, + MEMORYVIEW_HEX_METHODDEF {"tolist", (PyCFunction)memory_tolist, METH_NOARGS, memory_tolist_doc}, - {"cast", (PyCFunction)(void(*)(void))memory_cast, METH_VARARGS|METH_KEYWORDS, memory_cast_doc}, - {"toreadonly", (PyCFunction)memory_toreadonly, METH_NOARGS, memory_toreadonly_doc}, + {"cast", (PyCFunction)(void(*)(void))memory_cast, METH_VARARGS|METH_KEYWORDS, memory_cast_doc}, + {"toreadonly", (PyCFunction)memory_toreadonly, METH_NOARGS, memory_toreadonly_doc}, {"__enter__", memory_enter, METH_NOARGS, NULL}, {"__exit__", memory_exit, METH_VARARGS, NULL}, {NULL, NULL} @@ -3166,10 +3166,10 @@ PyTypeObject PyMemoryView_Type = { offsetof(PyMemoryViewObject, ob_array), /* tp_basicsize */ sizeof(Py_ssize_t), /* tp_itemsize */ (destructor)memory_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)memory_repr, /* tp_repr */ 0, /* tp_as_number */ &memory_as_sequence, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/methodobject.c b/contrib/tools/python3/src/Objects/methodobject.c index bae0664d8d..2df63cfdf6 100644 --- a/contrib/tools/python3/src/Objects/methodobject.c +++ b/contrib/tools/python3/src/Objects/methodobject.c @@ -2,33 +2,33 @@ /* Method object implementation */ #include "Python.h" -#include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "structmember.h" // PyMemberDef +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() +#include "pycore_object.h" +#include "pycore_pyerrors.h" +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "structmember.h" // PyMemberDef /* undefine macro trampoline to PyCFunction_NewEx */ #undef PyCFunction_New -/* undefine macro trampoline to PyCMethod_New */ -#undef PyCFunction_NewEx - -/* Forward declarations */ -static PyObject * cfunction_vectorcall_FASTCALL( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); -static PyObject * cfunction_vectorcall_FASTCALL_KEYWORDS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); -static PyObject * cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); -static PyObject * cfunction_vectorcall_NOARGS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); -static PyObject * cfunction_vectorcall_O( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); -static PyObject * cfunction_call( - PyObject *func, PyObject *args, PyObject *kwargs); - - -PyObject * +/* undefine macro trampoline to PyCMethod_New */ +#undef PyCFunction_NewEx + +/* Forward declarations */ +static PyObject * cfunction_vectorcall_FASTCALL( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * cfunction_vectorcall_FASTCALL_KEYWORDS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * cfunction_vectorcall_NOARGS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * cfunction_vectorcall_O( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * cfunction_call( + PyObject *func, PyObject *args, PyObject *kwargs); + + +PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self) { return PyCFunction_NewEx(ml, self, NULL); @@ -37,80 +37,80 @@ PyCFunction_New(PyMethodDef *ml, PyObject *self) PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) { - return PyCMethod_New(ml, self, module, NULL); -} - -PyObject * -PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls) -{ - /* Figure out correct vectorcall function to use */ - vectorcallfunc vectorcall; - switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | - METH_O | METH_KEYWORDS | METH_METHOD)) - { - case METH_VARARGS: - case METH_VARARGS | METH_KEYWORDS: - /* For METH_VARARGS functions, it's more efficient to use tp_call - * instead of vectorcall. */ - vectorcall = NULL; - break; - case METH_FASTCALL: - vectorcall = cfunction_vectorcall_FASTCALL; - break; - case METH_FASTCALL | METH_KEYWORDS: - vectorcall = cfunction_vectorcall_FASTCALL_KEYWORDS; - break; - case METH_NOARGS: - vectorcall = cfunction_vectorcall_NOARGS; - break; - case METH_O: - vectorcall = cfunction_vectorcall_O; - break; - case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: - vectorcall = cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD; - break; - default: - PyErr_Format(PyExc_SystemError, - "%s() method: bad call flags", ml->ml_name); - return NULL; - } - - PyCFunctionObject *op = NULL; - - if (ml->ml_flags & METH_METHOD) { - if (!cls) { - PyErr_SetString(PyExc_SystemError, - "attempting to create PyCMethod with a METH_METHOD " - "flag but no class"); - return NULL; - } - PyCMethodObject *om = PyObject_GC_New(PyCMethodObject, &PyCMethod_Type); - if (om == NULL) { - return NULL; - } - Py_INCREF(cls); - om->mm_class = cls; - op = (PyCFunctionObject *)om; - } else { - if (cls) { - PyErr_SetString(PyExc_SystemError, - "attempting to create PyCFunction with class " - "but no METH_METHOD flag"); - return NULL; - } + return PyCMethod_New(ml, self, module, NULL); +} + +PyObject * +PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls) +{ + /* Figure out correct vectorcall function to use */ + vectorcallfunc vectorcall; + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | + METH_O | METH_KEYWORDS | METH_METHOD)) + { + case METH_VARARGS: + case METH_VARARGS | METH_KEYWORDS: + /* For METH_VARARGS functions, it's more efficient to use tp_call + * instead of vectorcall. */ + vectorcall = NULL; + break; + case METH_FASTCALL: + vectorcall = cfunction_vectorcall_FASTCALL; + break; + case METH_FASTCALL | METH_KEYWORDS: + vectorcall = cfunction_vectorcall_FASTCALL_KEYWORDS; + break; + case METH_NOARGS: + vectorcall = cfunction_vectorcall_NOARGS; + break; + case METH_O: + vectorcall = cfunction_vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + vectorcall = cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + default: + PyErr_Format(PyExc_SystemError, + "%s() method: bad call flags", ml->ml_name); + return NULL; + } + + PyCFunctionObject *op = NULL; + + if (ml->ml_flags & METH_METHOD) { + if (!cls) { + PyErr_SetString(PyExc_SystemError, + "attempting to create PyCMethod with a METH_METHOD " + "flag but no class"); + return NULL; + } + PyCMethodObject *om = PyObject_GC_New(PyCMethodObject, &PyCMethod_Type); + if (om == NULL) { + return NULL; + } + Py_INCREF(cls); + om->mm_class = cls; + op = (PyCFunctionObject *)om; + } else { + if (cls) { + PyErr_SetString(PyExc_SystemError, + "attempting to create PyCFunction with class " + "but no METH_METHOD flag"); + return NULL; + } op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type); - if (op == NULL) { + if (op == NULL) { return NULL; - } + } } - + op->m_weakreflist = NULL; op->m_ml = ml; Py_XINCREF(self); op->m_self = self; Py_XINCREF(module); op->m_module = module; - op->vectorcall = vectorcall; + op->vectorcall = vectorcall; _PyObject_GC_TRACK(op); return (PyObject *)op; } @@ -145,39 +145,39 @@ PyCFunction_GetFlags(PyObject *op) return PyCFunction_GET_FLAGS(op); } -PyTypeObject * -PyCMethod_GetClass(PyObject *op) -{ - if (!PyCFunction_Check(op)) { - PyErr_BadInternalCall(); - return NULL; - } - return PyCFunction_GET_CLASS(op); -} - +PyTypeObject * +PyCMethod_GetClass(PyObject *op) +{ + if (!PyCFunction_Check(op)) { + PyErr_BadInternalCall(); + return NULL; + } + return PyCFunction_GET_CLASS(op); +} + /* Methods (the standard built-in methods, that is) */ static void meth_dealloc(PyCFunctionObject *m) { - // The Py_TRASHCAN mechanism requires that we be able to - // call PyObject_GC_UnTrack twice on an object. - PyObject_GC_UnTrack(m); - Py_TRASHCAN_BEGIN(m, meth_dealloc); + // The Py_TRASHCAN mechanism requires that we be able to + // call PyObject_GC_UnTrack twice on an object. + PyObject_GC_UnTrack(m); + Py_TRASHCAN_BEGIN(m, meth_dealloc); if (m->m_weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject*) m); } - // Dereference class before m_self: PyCFunction_GET_CLASS accesses - // PyMethodDef m_ml, which could be kept alive by m_self - Py_XDECREF(PyCFunction_GET_CLASS(m)); + // Dereference class before m_self: PyCFunction_GET_CLASS accesses + // PyMethodDef m_ml, which could be kept alive by m_self + Py_XDECREF(PyCFunction_GET_CLASS(m)); Py_XDECREF(m->m_self); Py_XDECREF(m->m_module); - PyObject_GC_Del(m); - Py_TRASHCAN_END; + PyObject_GC_Del(m); + Py_TRASHCAN_END; } static PyObject * -meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) +meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(getattr); @@ -249,7 +249,7 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure) static int meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg) { - Py_VISIT(PyCFunction_GET_CLASS(m)); + Py_VISIT(PyCFunction_GET_CLASS(m)); Py_VISIT(m->m_self); Py_VISIT(m->m_module); return 0; @@ -279,7 +279,7 @@ static PyGetSetDef meth_getsets [] = { #define OFF(x) offsetof(PyCFunctionObject, x) static PyMemberDef meth_members[] = { - {"__module__", T_OBJECT, OFF(m_module), 0}, + {"__module__", T_OBJECT, OFF(m_module), 0}, {NULL} }; @@ -291,7 +291,7 @@ meth_repr(PyCFunctionObject *m) m->m_ml->ml_name); return PyUnicode_FromFormat("<built-in method %s of %s object at %p>", m->m_ml->ml_name, - Py_TYPE(m->m_self)->tp_name, + Py_TYPE(m->m_self)->tp_name, m->m_self); } @@ -325,7 +325,7 @@ static Py_hash_t meth_hash(PyCFunctionObject *a) { Py_hash_t x, y; - x = _Py_HashPointer(a->m_self); + x = _Py_HashPointer(a->m_self); y = _Py_HashPointer((void*)(a->m_ml->ml_meth)); x ^= y; if (x == -1) @@ -340,22 +340,22 @@ PyTypeObject PyCFunction_Type = { sizeof(PyCFunctionObject), 0, (destructor)meth_dealloc, /* tp_dealloc */ - offsetof(PyCFunctionObject, vectorcall), /* tp_vectorcall_offset */ + offsetof(PyCFunctionObject, vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)meth_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ (hashfunc)meth_hash, /* tp_hash */ - cfunction_call, /* tp_call */ + cfunction_call, /* 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_HAVE_VECTORCALL, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ 0, /* tp_doc */ (traverseproc)meth_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -370,186 +370,186 @@ PyTypeObject PyCFunction_Type = { 0, /* tp_dict */ }; -PyTypeObject PyCMethod_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "builtin_method", - .tp_basicsize = sizeof(PyCMethodObject), - .tp_base = &PyCFunction_Type, -}; - -/* Vectorcall functions for each of the PyCFunction calling conventions, - * except for METH_VARARGS (possibly combined with METH_KEYWORDS) which - * doesn't use vectorcall. - * - * First, common helpers - */ - -static inline int -cfunction_check_kwargs(PyThreadState *tstate, PyObject *func, PyObject *kwnames) -{ - assert(!_PyErr_Occurred(tstate)); - assert(PyCFunction_Check(func)); - if (kwnames && PyTuple_GET_SIZE(kwnames)) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "%U takes no keyword arguments", funcstr); - Py_DECREF(funcstr); - } - return -1; - } - return 0; -} - -typedef void (*funcptr)(void); - -static inline funcptr -cfunction_enter_call(PyThreadState *tstate, PyObject *func) -{ - if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { - return NULL; - } - return (funcptr)PyCFunction_GET_FUNCTION(func); -} - -/* Now the actual vectorcall functions */ -static PyObject * -cfunction_vectorcall_FASTCALL( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - if (cfunction_check_kwargs(tstate, func, kwnames)) { - return NULL; - } - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - _PyCFunctionFast meth = (_PyCFunctionFast) - cfunction_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(PyCFunction_GET_SELF(func), args, nargs); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -cfunction_vectorcall_FASTCALL_KEYWORDS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - _PyCFunctionFastWithKeywords meth = (_PyCFunctionFastWithKeywords) - cfunction_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(PyCFunction_GET_SELF(func), args, nargs, kwnames); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - PyTypeObject *cls = PyCFunction_GET_CLASS(func); - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - PyCMethod meth = (PyCMethod)cfunction_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(PyCFunction_GET_SELF(func), cls, args, nargs, kwnames); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -cfunction_vectorcall_NOARGS( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - if (cfunction_check_kwargs(tstate, func, kwnames)) { - return NULL; - } - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (nargs != 0) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "%U takes no arguments (%zd given)", funcstr, nargs); - Py_DECREF(funcstr); - } - return NULL; - } - PyCFunction meth = (PyCFunction)cfunction_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(PyCFunction_GET_SELF(func), NULL); - _Py_LeaveRecursiveCall(tstate); - return result; -} - -static PyObject * -cfunction_vectorcall_O( - PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) -{ - PyThreadState *tstate = _PyThreadState_GET(); - if (cfunction_check_kwargs(tstate, func, kwnames)) { - return NULL; - } - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (nargs != 1) { - PyObject *funcstr = _PyObject_FunctionStr(func); - if (funcstr != NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "%U takes exactly one argument (%zd given)", funcstr, nargs); - Py_DECREF(funcstr); - } - return NULL; - } - PyCFunction meth = (PyCFunction)cfunction_enter_call(tstate, func); - if (meth == NULL) { - return NULL; - } - PyObject *result = meth(PyCFunction_GET_SELF(func), args[0]); - _Py_LeaveRecursiveCall(tstate); - return result; -} - - -static PyObject * -cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs) -{ - assert(kwargs == NULL || PyDict_Check(kwargs)); - - PyThreadState *tstate = _PyThreadState_GET(); - assert(!_PyErr_Occurred(tstate)); - - int flags = PyCFunction_GET_FLAGS(func); - if (!(flags & METH_VARARGS)) { - /* If this is not a METH_VARARGS function, delegate to vectorcall */ - return PyVectorcall_Call(func, args, kwargs); - } - - /* For METH_VARARGS, we cannot use vectorcall as the vectorcall pointer - * is NULL. This is intentional, since vectorcall would be slower. */ - PyCFunction meth = PyCFunction_GET_FUNCTION(func); - PyObject *self = PyCFunction_GET_SELF(func); - - PyObject *result; - if (flags & METH_KEYWORDS) { - result = (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, args, kwargs); - } - else { - if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) { - _PyErr_Format(tstate, PyExc_TypeError, - "%.200s() takes no keyword arguments", - ((PyCFunctionObject*)func)->m_ml->ml_name); - return NULL; - } - result = meth(self, args); - } - return _Py_CheckFunctionResult(tstate, func, result, NULL); -} +PyTypeObject PyCMethod_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + .tp_name = "builtin_method", + .tp_basicsize = sizeof(PyCMethodObject), + .tp_base = &PyCFunction_Type, +}; + +/* Vectorcall functions for each of the PyCFunction calling conventions, + * except for METH_VARARGS (possibly combined with METH_KEYWORDS) which + * doesn't use vectorcall. + * + * First, common helpers + */ + +static inline int +cfunction_check_kwargs(PyThreadState *tstate, PyObject *func, PyObject *kwnames) +{ + assert(!_PyErr_Occurred(tstate)); + assert(PyCFunction_Check(func)); + if (kwnames && PyTuple_GET_SIZE(kwnames)) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "%U takes no keyword arguments", funcstr); + Py_DECREF(funcstr); + } + return -1; + } + return 0; +} + +typedef void (*funcptr)(void); + +static inline funcptr +cfunction_enter_call(PyThreadState *tstate, PyObject *func) +{ + if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { + return NULL; + } + return (funcptr)PyCFunction_GET_FUNCTION(func); +} + +/* Now the actual vectorcall functions */ +static PyObject * +cfunction_vectorcall_FASTCALL( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (cfunction_check_kwargs(tstate, func, kwnames)) { + return NULL; + } + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + _PyCFunctionFast meth = (_PyCFunctionFast) + cfunction_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(PyCFunction_GET_SELF(func), args, nargs); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +cfunction_vectorcall_FASTCALL_KEYWORDS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + _PyCFunctionFastWithKeywords meth = (_PyCFunctionFastWithKeywords) + cfunction_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(PyCFunction_GET_SELF(func), args, nargs, kwnames); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +cfunction_vectorcall_FASTCALL_KEYWORDS_METHOD( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + PyTypeObject *cls = PyCFunction_GET_CLASS(func); + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyCMethod meth = (PyCMethod)cfunction_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(PyCFunction_GET_SELF(func), cls, args, nargs, kwnames); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +cfunction_vectorcall_NOARGS( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (cfunction_check_kwargs(tstate, func, kwnames)) { + return NULL; + } + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (nargs != 0) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "%U takes no arguments (%zd given)", funcstr, nargs); + Py_DECREF(funcstr); + } + return NULL; + } + PyCFunction meth = (PyCFunction)cfunction_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(PyCFunction_GET_SELF(func), NULL); + _Py_LeaveRecursiveCall(tstate); + return result; +} + +static PyObject * +cfunction_vectorcall_O( + PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (cfunction_check_kwargs(tstate, func, kwnames)) { + return NULL; + } + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (nargs != 1) { + PyObject *funcstr = _PyObject_FunctionStr(func); + if (funcstr != NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "%U takes exactly one argument (%zd given)", funcstr, nargs); + Py_DECREF(funcstr); + } + return NULL; + } + PyCFunction meth = (PyCFunction)cfunction_enter_call(tstate, func); + if (meth == NULL) { + return NULL; + } + PyObject *result = meth(PyCFunction_GET_SELF(func), args[0]); + _Py_LeaveRecursiveCall(tstate); + return result; +} + + +static PyObject * +cfunction_call(PyObject *func, PyObject *args, PyObject *kwargs) +{ + assert(kwargs == NULL || PyDict_Check(kwargs)); + + PyThreadState *tstate = _PyThreadState_GET(); + assert(!_PyErr_Occurred(tstate)); + + int flags = PyCFunction_GET_FLAGS(func); + if (!(flags & METH_VARARGS)) { + /* If this is not a METH_VARARGS function, delegate to vectorcall */ + return PyVectorcall_Call(func, args, kwargs); + } + + /* For METH_VARARGS, we cannot use vectorcall as the vectorcall pointer + * is NULL. This is intentional, since vectorcall would be slower. */ + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + + PyObject *result; + if (flags & METH_KEYWORDS) { + result = (*(PyCFunctionWithKeywords)(void(*)(void))meth)(self, args, kwargs); + } + else { + if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) { + _PyErr_Format(tstate, PyExc_TypeError, + "%.200s() takes no keyword arguments", + ((PyCFunctionObject*)func)->m_ml->ml_name); + return NULL; + } + result = meth(self, args); + } + return _Py_CheckFunctionResult(tstate, func, result, NULL); +} diff --git a/contrib/tools/python3/src/Objects/moduleobject.c b/contrib/tools/python3/src/Objects/moduleobject.c index 2707fbed52..ee4ed97588 100644 --- a/contrib/tools/python3/src/Objects/moduleobject.c +++ b/contrib/tools/python3/src/Objects/moduleobject.c @@ -2,16 +2,16 @@ /* Module object implementation */ #include "Python.h" -#include "pycore_interp.h" // PyInterpreterState.importlib -#include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "structmember.h" // PyMemberDef +#include "pycore_interp.h" // PyInterpreterState.importlib +#include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "structmember.h" // PyMemberDef static Py_ssize_t max_module_number; -_Py_IDENTIFIER(__doc__); -_Py_IDENTIFIER(__name__); -_Py_IDENTIFIER(__spec__); - +_Py_IDENTIFIER(__doc__); +_Py_IDENTIFIER(__name__); +_Py_IDENTIFIER(__spec__); + typedef struct { PyObject_HEAD PyObject *md_dict; @@ -42,8 +42,8 @@ PyModuleDef_Init(struct PyModuleDef* def) return NULL; if (def->m_base.m_index == 0) { max_module_number++; - Py_SET_REFCNT(def, 1); - Py_SET_TYPE(def, &PyModuleDef_Type); + Py_SET_REFCNT(def, 1); + Py_SET_TYPE(def, &PyModuleDef_Type); def->m_base.m_index = max_module_number; } return (PyObject*)def; @@ -165,11 +165,11 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions) PyObject * PyModule_Create2(struct PyModuleDef* module, int module_api_version) { - if (!_PyImport_IsInitialized(_PyInterpreterState_GET())) { - PyErr_SetString(PyExc_SystemError, - "Python import machinery not initialized"); - return NULL; - } + if (!_PyImport_IsInitialized(_PyInterpreterState_GET())) { + PyErr_SetString(PyExc_SystemError, + "Python import machinery not initialized"); + return NULL; + } return _PyModule_CreateInitialized(module, module_api_version); } @@ -573,24 +573,24 @@ _PyModule_ClearDict(PyObject *d) Py_ssize_t pos; PyObject *key, *value; - int verbose = _Py_GetConfig()->verbose; - + int verbose = _Py_GetConfig()->verbose; + /* First, clear only names starting with a single underscore */ pos = 0; while (PyDict_Next(d, &pos, &key, &value)) { if (value != Py_None && PyUnicode_Check(key)) { if (PyUnicode_READ_CHAR(key, 0) == '_' && PyUnicode_READ_CHAR(key, 1) != '_') { - if (verbose > 1) { + if (verbose > 1) { const char *s = PyUnicode_AsUTF8(key); if (s != NULL) PySys_WriteStderr("# clear[1] %s\n", s); else PyErr_Clear(); } - if (PyDict_SetItem(d, key, Py_None) != 0) { - PyErr_WriteUnraisable(NULL); - } + if (PyDict_SetItem(d, key, Py_None) != 0) { + PyErr_WriteUnraisable(NULL); + } } } } @@ -602,16 +602,16 @@ _PyModule_ClearDict(PyObject *d) if (PyUnicode_READ_CHAR(key, 0) != '_' || !_PyUnicode_EqualToASCIIString(key, "__builtins__")) { - if (verbose > 1) { + if (verbose > 1) { const char *s = PyUnicode_AsUTF8(key); if (s != NULL) PySys_WriteStderr("# clear[2] %s\n", s); else PyErr_Clear(); } - if (PyDict_SetItem(d, key, Py_None) != 0) { - PyErr_WriteUnraisable(NULL); - } + if (PyDict_SetItem(d, key, Py_None) != 0) { + PyErr_WriteUnraisable(NULL); + } } } } @@ -660,20 +660,20 @@ module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc) static void module_dealloc(PyModuleObject *m) { - int verbose = _Py_GetConfig()->verbose; - + int verbose = _Py_GetConfig()->verbose; + PyObject_GC_UnTrack(m); - if (verbose && m->md_name) { - PySys_FormatStderr("# destroy %U\n", m->md_name); + if (verbose && m->md_name) { + PySys_FormatStderr("# destroy %U\n", m->md_name); } if (m->md_weaklist != NULL) PyObject_ClearWeakRefs((PyObject *) m); - /* bpo-39824: Don't call m_free() if m_size > 0 and md_state=NULL */ - if (m->md_def && m->md_def->m_free - && (m->md_def->m_size <= 0 || m->md_state != NULL)) - { + /* bpo-39824: Don't call m_free() if m_size > 0 and md_state=NULL */ + if (m->md_def && m->md_def->m_free + && (m->md_def->m_size <= 0 || m->md_state != NULL)) + { m->md_def->m_free(m); - } + } Py_XDECREF(m->md_dict); Py_XDECREF(m->md_name); if (m->md_state != NULL) @@ -684,32 +684,32 @@ module_dealloc(PyModuleObject *m) static PyObject * module_repr(PyModuleObject *m) { - PyInterpreterState *interp = _PyInterpreterState_GET(); + PyInterpreterState *interp = _PyInterpreterState_GET(); return PyObject_CallMethod(interp->importlib, "_module_repr", "O", m); } -/* Check if the "_initializing" attribute of the module spec is set to true. - Clear the exception and return 0 if spec is NULL. - */ -int -_PyModuleSpec_IsInitializing(PyObject *spec) -{ - if (spec != NULL) { - _Py_IDENTIFIER(_initializing); - PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing); - if (value != NULL) { - int initializing = PyObject_IsTrue(value); - Py_DECREF(value); - if (initializing >= 0) { - return initializing; - } - } - } - PyErr_Clear(); - return 0; -} - +/* Check if the "_initializing" attribute of the module spec is set to true. + Clear the exception and return 0 if spec is NULL. + */ +int +_PyModuleSpec_IsInitializing(PyObject *spec) +{ + if (spec != NULL) { + _Py_IDENTIFIER(_initializing); + PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing); + if (value != NULL) { + int initializing = PyObject_IsTrue(value); + Py_DECREF(value); + if (initializing >= 0) { + return initializing; + } + } + } + PyErr_Clear(); + return 0; +} + static PyObject* module_getattro(PyModuleObject *m, PyObject *name) { @@ -723,27 +723,27 @@ module_getattro(PyModuleObject *m, PyObject *name) _Py_IDENTIFIER(__getattr__); getattr = _PyDict_GetItemId(m->md_dict, &PyId___getattr__); if (getattr) { - return PyObject_CallOneArg(getattr, name); + return PyObject_CallOneArg(getattr, name); } mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__); if (mod_name && PyUnicode_Check(mod_name)) { - Py_INCREF(mod_name); - PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__); - Py_XINCREF(spec); - if (_PyModuleSpec_IsInitializing(spec)) { - PyErr_Format(PyExc_AttributeError, - "partially initialized " - "module '%U' has no attribute '%U' " - "(most likely due to a circular import)", - mod_name, name); - } - else { - PyErr_Format(PyExc_AttributeError, - "module '%U' has no attribute '%U'", - mod_name, name); - } - Py_XDECREF(spec); - Py_DECREF(mod_name); + Py_INCREF(mod_name); + PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__); + Py_XINCREF(spec); + if (_PyModuleSpec_IsInitializing(spec)) { + PyErr_Format(PyExc_AttributeError, + "partially initialized " + "module '%U' has no attribute '%U' " + "(most likely due to a circular import)", + mod_name, name); + } + else { + PyErr_Format(PyExc_AttributeError, + "module '%U' has no attribute '%U'", + mod_name, name); + } + Py_XDECREF(spec); + Py_DECREF(mod_name); return NULL; } } @@ -755,10 +755,10 @@ module_getattro(PyModuleObject *m, PyObject *name) static int module_traverse(PyModuleObject *m, visitproc visit, void *arg) { - /* bpo-39824: Don't call m_traverse() if m_size > 0 and md_state=NULL */ - if (m->md_def && m->md_def->m_traverse - && (m->md_def->m_size <= 0 || m->md_state != NULL)) - { + /* bpo-39824: Don't call m_traverse() if m_size > 0 and md_state=NULL */ + if (m->md_def && m->md_def->m_traverse + && (m->md_def->m_size <= 0 || m->md_state != NULL)) + { int res = m->md_def->m_traverse((PyObject*)m, visit, arg); if (res) return res; @@ -770,17 +770,17 @@ module_traverse(PyModuleObject *m, visitproc visit, void *arg) static int module_clear(PyModuleObject *m) { - /* bpo-39824: Don't call m_clear() if m_size > 0 and md_state=NULL */ - if (m->md_def && m->md_def->m_clear - && (m->md_def->m_size <= 0 || m->md_state != NULL)) - { + /* bpo-39824: Don't call m_clear() if m_size > 0 and md_state=NULL */ + if (m->md_def && m->md_def->m_clear + && (m->md_def->m_size <= 0 || m->md_state != NULL)) + { int res = m->md_def->m_clear((PyObject*)m); - if (PyErr_Occurred()) { - PySys_FormatStderr("Exception ignored in m_clear of module%s%V\n", - m->md_name ? " " : "", - m->md_name, ""); - PyErr_WriteUnraisable(NULL); - } + if (PyErr_Occurred()) { + PySys_FormatStderr("Exception ignored in m_clear of module%s%V\n", + m->md_name ? " " : "", + m->md_name, ""); + PyErr_WriteUnraisable(NULL); + } if (res) return res; } @@ -792,17 +792,17 @@ static PyObject * module_dir(PyObject *self, PyObject *args) { _Py_IDENTIFIER(__dict__); - _Py_IDENTIFIER(__dir__); + _Py_IDENTIFIER(__dir__); PyObject *result = NULL; PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); if (dict != NULL) { if (PyDict_Check(dict)) { - PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__); + PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__); if (dirfunc) { result = _PyObject_CallNoArg(dirfunc); } - else if (!PyErr_Occurred()) { + else if (!PyErr_Occurred()) { result = PyDict_Keys(dict); } } @@ -831,10 +831,10 @@ PyTypeObject PyModule_Type = { sizeof(PyModuleObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)module_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)module_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/namespaceobject.c b/contrib/tools/python3/src/Objects/namespaceobject.c index 556dfe326a..fa37ed250d 100644 --- a/contrib/tools/python3/src/Objects/namespaceobject.c +++ b/contrib/tools/python3/src/Objects/namespaceobject.c @@ -1,7 +1,7 @@ // namespace object implementation #include "Python.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef typedef struct { @@ -72,8 +72,8 @@ namespace_repr(PyObject *ns) PyObject *separator, *pairsrepr, *repr = NULL; const char * name; - name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "namespace" - : Py_TYPE(ns)->tp_name; + name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "namespace" + : Py_TYPE(ns)->tp_name; i = Py_ReprEnter(ns); if (i != 0) { @@ -100,9 +100,9 @@ namespace_repr(PyObject *ns) if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) { PyObject *value, *item; - value = PyDict_GetItemWithError(d, key); + value = PyDict_GetItemWithError(d, key); if (value != NULL) { - item = PyUnicode_FromFormat("%U=%R", key, value); + item = PyUnicode_FromFormat("%U=%R", key, value); if (item == NULL) { loop_error = 1; } @@ -111,9 +111,9 @@ namespace_repr(PyObject *ns) Py_DECREF(item); } } - else if (PyErr_Occurred()) { - loop_error = 1; - } + else if (PyErr_Occurred()) { + loop_error = 1; + } } Py_DECREF(key); @@ -174,7 +174,7 @@ namespace_richcompare(PyObject *self, PyObject *other, int op) PyDoc_STRVAR(namespace_reduce__doc__, "Return state information for pickling"); static PyObject * -namespace_reduce(_PyNamespaceObject *ns, PyObject *Py_UNUSED(ignored)) +namespace_reduce(_PyNamespaceObject *ns, PyObject *Py_UNUSED(ignored)) { PyObject *result, *args = PyTuple_New(0); @@ -205,10 +205,10 @@ PyTypeObject _PyNamespace_Type = { sizeof(_PyNamespaceObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)namespace_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)namespace_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/object.c b/contrib/tools/python3/src/Objects/object.c index 2b5c2fe73b..623ee52eb1 100644 --- a/contrib/tools/python3/src/Objects/object.c +++ b/contrib/tools/python3/src/Objects/object.c @@ -2,53 +2,53 @@ /* Generic object operations; and implementation of None */ #include "Python.h" -#include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_context.h" -#include "pycore_initconfig.h" -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pylifecycle.h" -#include "pycore_pymem.h" // _PyMem_IsPtrFreed() -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() +#include "pycore_context.h" +#include "pycore_initconfig.h" +#include "pycore_object.h" +#include "pycore_pyerrors.h" +#include "pycore_pylifecycle.h" +#include "pycore_pymem.h" // _PyMem_IsPtrFreed() +#include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "interpreteridobject.h" +#include "interpreteridobject.h" #ifdef __cplusplus extern "C" { #endif -/* Defined in tracemalloc.c */ -extern void _PyMem_DumpTraceback(int fd, const void *ptr); - +/* Defined in tracemalloc.c */ +extern void _PyMem_DumpTraceback(int fd, const void *ptr); + _Py_IDENTIFIER(Py_Repr); _Py_IDENTIFIER(__bytes__); _Py_IDENTIFIER(__dir__); _Py_IDENTIFIER(__isabstractmethod__); - -int -_PyObject_CheckConsistency(PyObject *op, int check_content) -{ -#define CHECK(expr) \ - do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) - - CHECK(!_PyObject_IsFreed(op)); - CHECK(Py_REFCNT(op) >= 1); - - _PyType_CheckConsistency(Py_TYPE(op)); - - if (PyUnicode_Check(op)) { - _PyUnicode_CheckConsistency(op, check_content); - } - else if (PyDict_Check(op)) { - _PyDict_CheckConsistency(op, check_content); - } - return 1; - -#undef CHECK -} - - + +int +_PyObject_CheckConsistency(PyObject *op, int check_content) +{ +#define CHECK(expr) \ + do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) + + CHECK(!_PyObject_IsFreed(op)); + CHECK(Py_REFCNT(op) >= 1); + + _PyType_CheckConsistency(Py_TYPE(op)); + + if (PyUnicode_Check(op)) { + _PyUnicode_CheckConsistency(op, check_content); + } + else if (PyDict_Check(op)) { + _PyDict_CheckConsistency(op, check_content); + } + return 1; + +#undef CHECK +} + + #ifdef Py_REF_DEBUG Py_ssize_t _Py_RefTotal; @@ -59,7 +59,7 @@ _Py_GetRefTotal(void) Py_ssize_t total = _Py_RefTotal; o = _PySet_Dummy; if (o != NULL) - total -= Py_REFCNT(o); + total -= Py_REFCNT(o); return total; } @@ -102,7 +102,7 @@ _Py_AddToAllObjects(PyObject *op, int force) /* If it's initialized memory, op must be in or out of * the list unambiguously. */ - _PyObject_ASSERT(op, (op->_ob_prev == NULL) == (op->_ob_next == NULL)); + _PyObject_ASSERT(op, (op->_ob_prev == NULL) == (op->_ob_next == NULL)); } #endif if (force || op->_ob_prev == NULL) { @@ -117,10 +117,10 @@ _Py_AddToAllObjects(PyObject *op, int force) #ifdef Py_REF_DEBUG /* Log a fatal error; doesn't return. */ void -_Py_NegativeRefcount(const char *filename, int lineno, PyObject *op) +_Py_NegativeRefcount(const char *filename, int lineno, PyObject *op) { - _PyObject_AssertFailed(op, NULL, "object has negative ref count", - filename, lineno, __func__); + _PyObject_AssertFailed(op, NULL, "object has negative ref count", + filename, lineno, __func__); } #endif /* Py_REF_DEBUG */ @@ -140,34 +140,34 @@ Py_DecRef(PyObject *o) PyObject * PyObject_Init(PyObject *op, PyTypeObject *tp) { - /* Any changes should be reflected in PyObject_INIT() macro */ - if (op == NULL) { + /* Any changes should be reflected in PyObject_INIT() macro */ + if (op == NULL) { return PyErr_NoMemory(); - } - - return PyObject_INIT(op, tp); + } + + return PyObject_INIT(op, tp); } PyVarObject * PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size) { - /* Any changes should be reflected in PyObject_INIT_VAR() macro */ - if (op == NULL) { + /* Any changes should be reflected in PyObject_INIT_VAR() macro */ + if (op == NULL) { return (PyVarObject *) PyErr_NoMemory(); - } - - return PyObject_INIT_VAR(op, tp, size); + } + + return PyObject_INIT_VAR(op, tp, size); } PyObject * _PyObject_New(PyTypeObject *tp) { - PyObject *op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp)); - if (op == NULL) { + PyObject *op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp)); + if (op == NULL) { return PyErr_NoMemory(); - } - PyObject_INIT(op, tp); - return op; + } + PyObject_INIT(op, tp); + return op; } PyVarObject * @@ -186,56 +186,56 @@ PyObject_CallFinalizer(PyObject *self) { PyTypeObject *tp = Py_TYPE(self); - if (tp->tp_finalize == NULL) + if (tp->tp_finalize == NULL) return; /* tp_finalize should only be called once. */ - if (_PyType_IS_GC(tp) && _PyGC_FINALIZED(self)) + if (_PyType_IS_GC(tp) && _PyGC_FINALIZED(self)) return; tp->tp_finalize(self); - if (_PyType_IS_GC(tp)) { - _PyGC_SET_FINALIZED(self); - } + if (_PyType_IS_GC(tp)) { + _PyGC_SET_FINALIZED(self); + } } int PyObject_CallFinalizerFromDealloc(PyObject *self) { - if (Py_REFCNT(self) != 0) { - _PyObject_ASSERT_FAILED_MSG(self, - "PyObject_CallFinalizerFromDealloc called " - "on object with a non-zero refcount"); - } + if (Py_REFCNT(self) != 0) { + _PyObject_ASSERT_FAILED_MSG(self, + "PyObject_CallFinalizerFromDealloc called " + "on object with a non-zero refcount"); + } /* Temporarily resurrect the object. */ - Py_SET_REFCNT(self, 1); + Py_SET_REFCNT(self, 1); PyObject_CallFinalizer(self); - _PyObject_ASSERT_WITH_MSG(self, - Py_REFCNT(self) > 0, - "refcount is too small"); - - /* Undo the temporary resurrection; can't use DECREF here, it would - * cause a recursive call. */ - Py_SET_REFCNT(self, Py_REFCNT(self) - 1); - if (Py_REFCNT(self) == 0) { + _PyObject_ASSERT_WITH_MSG(self, + Py_REFCNT(self) > 0, + "refcount is too small"); + + /* Undo the temporary resurrection; can't use DECREF here, it would + * cause a recursive call. */ + Py_SET_REFCNT(self, Py_REFCNT(self) - 1); + if (Py_REFCNT(self) == 0) { return 0; /* this is the normal path out */ - } + } /* tp_finalize resurrected it! Make it look like the original Py_DECREF - * never happened. */ - Py_ssize_t refcnt = Py_REFCNT(self); + * never happened. */ + Py_ssize_t refcnt = Py_REFCNT(self); _Py_NewReference(self); - Py_SET_REFCNT(self, refcnt); - - _PyObject_ASSERT(self, - (!_PyType_IS_GC(Py_TYPE(self)) - || _PyObject_GC_IS_TRACKED(self))); - /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased - _Py_RefTotal, so we need to undo that. */ -#ifdef Py_REF_DEBUG - _Py_RefTotal--; + Py_SET_REFCNT(self, refcnt); + + _PyObject_ASSERT(self, + (!_PyType_IS_GC(Py_TYPE(self)) + || _PyObject_GC_IS_TRACKED(self))); + /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased + _Py_RefTotal, so we need to undo that. */ +#ifdef Py_REF_DEBUG + _Py_RefTotal--; #endif return -1; } @@ -259,14 +259,14 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) Py_END_ALLOW_THREADS } else { - if (Py_REFCNT(op) <= 0) { + if (Py_REFCNT(op) <= 0) { /* XXX(twouters) cast refcount to long until %zd is universally available */ Py_BEGIN_ALLOW_THREADS fprintf(fp, "<refcnt %ld at %p>", - (long)Py_REFCNT(op), (void *)op); + (long)Py_REFCNT(op), (void *)op); Py_END_ALLOW_THREADS - } + } else { PyObject *s; if (flags & Py_PRINT_RAW) @@ -294,7 +294,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) else { PyErr_Format(PyExc_TypeError, "str() or repr() returned '%.100s'", - Py_TYPE(s)->tp_name); + Py_TYPE(s)->tp_name); ret = -1; } Py_XDECREF(s); @@ -317,29 +317,29 @@ _Py_BreakPoint(void) } -/* Heuristic checking if the object memory is uninitialized or deallocated. - Rely on the debug hooks on Python memory allocators: - see _PyMem_IsPtrFreed(). +/* Heuristic checking if the object memory is uninitialized or deallocated. + Rely on the debug hooks on Python memory allocators: + see _PyMem_IsPtrFreed(). The function can be used to prevent segmentation fault on dereferencing - pointers like 0xDDDDDDDDDDDDDDDD. */ + pointers like 0xDDDDDDDDDDDDDDDD. */ int _PyObject_IsFreed(PyObject *op) { - if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(Py_TYPE(op))) { + if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(Py_TYPE(op))) { return 1; } - /* ignore op->ob_ref: its value can have be modified + /* ignore op->ob_ref: its value can have be modified by Py_INCREF() and Py_DECREF(). */ #ifdef Py_TRACE_REFS - if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) { - return 1; - } - if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) { - return 1; - } + if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) { + return 1; + } + if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) { + return 1; + } #endif - return 0; + return 0; } @@ -350,38 +350,38 @@ _PyObject_Dump(PyObject* op) if (_PyObject_IsFreed(op)) { /* It seems like the object memory has been freed: don't access it to prevent a segmentation fault. */ - fprintf(stderr, "<object at %p is freed>\n", op); - fflush(stderr); + fprintf(stderr, "<object at %p is freed>\n", op); + fflush(stderr); return; } - /* first, write fields which are the least likely to crash */ - fprintf(stderr, "object address : %p\n", (void *)op); - /* XXX(twouters) cast refcount to long until %zd is - universally available */ - fprintf(stderr, "object refcount : %ld\n", (long)Py_REFCNT(op)); - fflush(stderr); - - PyTypeObject *type = Py_TYPE(op); - fprintf(stderr, "object type : %p\n", type); - fprintf(stderr, "object type name: %s\n", - type==NULL ? "NULL" : type->tp_name); - - /* the most dangerous part */ - fprintf(stderr, "object repr : "); + /* first, write fields which are the least likely to crash */ + fprintf(stderr, "object address : %p\n", (void *)op); + /* XXX(twouters) cast refcount to long until %zd is + universally available */ + fprintf(stderr, "object refcount : %ld\n", (long)Py_REFCNT(op)); fflush(stderr); - PyGILState_STATE gil = PyGILState_Ensure(); - PyObject *error_type, *error_value, *error_traceback; + PyTypeObject *type = Py_TYPE(op); + fprintf(stderr, "object type : %p\n", type); + fprintf(stderr, "object type name: %s\n", + type==NULL ? "NULL" : type->tp_name); + + /* the most dangerous part */ + fprintf(stderr, "object repr : "); + fflush(stderr); + + PyGILState_STATE gil = PyGILState_Ensure(); + PyObject *error_type, *error_value, *error_traceback; PyErr_Fetch(&error_type, &error_value, &error_traceback); - + (void)PyObject_Print(op, stderr, 0); fflush(stderr); - + PyErr_Restore(error_type, error_value, error_traceback); - PyGILState_Release(gil); + PyGILState_Release(gil); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); fflush(stderr); } @@ -401,39 +401,39 @@ PyObject_Repr(PyObject *v) return PyUnicode_FromString("<NULL>"); if (Py_TYPE(v)->tp_repr == NULL) return PyUnicode_FromFormat("<%s object at %p>", - Py_TYPE(v)->tp_name, v); + Py_TYPE(v)->tp_name, v); - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); #ifdef Py_DEBUG /* PyObject_Repr() must not be called with an exception set, because it can clear it (directly or indirectly) and so the caller loses its exception */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); #endif /* It is possible for a type to have a tp_repr representation that loops infinitely. */ - if (_Py_EnterRecursiveCall(tstate, - " while getting the repr of an object")) { + if (_Py_EnterRecursiveCall(tstate, + " while getting the repr of an object")) { return NULL; - } - res = (*Py_TYPE(v)->tp_repr)(v); - _Py_LeaveRecursiveCall(tstate); - - if (res == NULL) { + } + res = (*Py_TYPE(v)->tp_repr)(v); + _Py_LeaveRecursiveCall(tstate); + + if (res == NULL) { return NULL; - } + } if (!PyUnicode_Check(res)) { - _PyErr_Format(tstate, PyExc_TypeError, - "__repr__ returned non-string (type %.200s)", - Py_TYPE(res)->tp_name); + _PyErr_Format(tstate, PyExc_TypeError, + "__repr__ returned non-string (type %.200s)", + Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } #ifndef Py_DEBUG - if (PyUnicode_READY(res) < 0) { + if (PyUnicode_READY(res) < 0) { return NULL; - } + } #endif return res; } @@ -463,36 +463,36 @@ PyObject_Str(PyObject *v) if (Py_TYPE(v)->tp_str == NULL) return PyObject_Repr(v); - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); #ifdef Py_DEBUG /* PyObject_Str() must not be called with an exception set, because it can clear it (directly or indirectly) and so the caller loses its exception */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); #endif /* It is possible for a type to have a tp_str representation that loops infinitely. */ - if (_Py_EnterRecursiveCall(tstate, " while getting the str of an object")) { + if (_Py_EnterRecursiveCall(tstate, " while getting the str of an object")) { return NULL; - } + } res = (*Py_TYPE(v)->tp_str)(v); - _Py_LeaveRecursiveCall(tstate); - - if (res == NULL) { + _Py_LeaveRecursiveCall(tstate); + + if (res == NULL) { return NULL; - } + } if (!PyUnicode_Check(res)) { - _PyErr_Format(tstate, PyExc_TypeError, - "__str__ returned non-string (type %.200s)", - Py_TYPE(res)->tp_name); + _PyErr_Format(tstate, PyExc_TypeError, + "__str__ returned non-string (type %.200s)", + Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } #ifndef Py_DEBUG - if (PyUnicode_READY(res) < 0) { + if (PyUnicode_READY(res) < 0) { return NULL; - } + } #endif assert(_PyUnicode_CheckConsistency(res, 1)); return res; @@ -558,68 +558,68 @@ PyObject_Bytes(PyObject *v) return PyBytes_FromObject(v); } - -/* -def _PyObject_FunctionStr(x): - try: - qualname = x.__qualname__ - except AttributeError: - return str(x) - try: - mod = x.__module__ - if mod is not None and mod != 'builtins': - return f"{x.__module__}.{qualname}()" - except AttributeError: - pass - return qualname -*/ -PyObject * -_PyObject_FunctionStr(PyObject *x) -{ - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(__qualname__); - _Py_IDENTIFIER(builtins); - assert(!PyErr_Occurred()); - PyObject *qualname; - int ret = _PyObject_LookupAttrId(x, &PyId___qualname__, &qualname); - if (qualname == NULL) { - if (ret < 0) { - return NULL; - } - return PyObject_Str(x); - } - PyObject *module; - PyObject *result = NULL; - ret = _PyObject_LookupAttrId(x, &PyId___module__, &module); - if (module != NULL && module != Py_None) { - PyObject *builtinsname = _PyUnicode_FromId(&PyId_builtins); - if (builtinsname == NULL) { - goto done; - } - ret = PyObject_RichCompareBool(module, builtinsname, Py_NE); - if (ret < 0) { - // error - goto done; - } - if (ret > 0) { - result = PyUnicode_FromFormat("%S.%S()", module, qualname); - goto done; - } - } - else if (ret < 0) { - goto done; - } - result = PyUnicode_FromFormat("%S()", qualname); -done: - Py_DECREF(qualname); - Py_XDECREF(module); - return result; -} - + +/* +def _PyObject_FunctionStr(x): + try: + qualname = x.__qualname__ + except AttributeError: + return str(x) + try: + mod = x.__module__ + if mod is not None and mod != 'builtins': + return f"{x.__module__}.{qualname}()" + except AttributeError: + pass + return qualname +*/ +PyObject * +_PyObject_FunctionStr(PyObject *x) +{ + _Py_IDENTIFIER(__module__); + _Py_IDENTIFIER(__qualname__); + _Py_IDENTIFIER(builtins); + assert(!PyErr_Occurred()); + PyObject *qualname; + int ret = _PyObject_LookupAttrId(x, &PyId___qualname__, &qualname); + if (qualname == NULL) { + if (ret < 0) { + return NULL; + } + return PyObject_Str(x); + } + PyObject *module; + PyObject *result = NULL; + ret = _PyObject_LookupAttrId(x, &PyId___module__, &module); + if (module != NULL && module != Py_None) { + PyObject *builtinsname = _PyUnicode_FromId(&PyId_builtins); + if (builtinsname == NULL) { + goto done; + } + ret = PyObject_RichCompareBool(module, builtinsname, Py_NE); + if (ret < 0) { + // error + goto done; + } + if (ret > 0) { + result = PyUnicode_FromFormat("%S.%S()", module, qualname); + goto done; + } + } + else if (ret < 0) { + goto done; + } + result = PyUnicode_FromFormat("%S()", qualname); +done: + Py_DECREF(qualname); + Py_XDECREF(module); + return result; +} + /* For Python 3.0.1 and later, the old three-way comparison has been completely removed in favour of rich comparisons. PyObject_Compare() and PyObject_Cmp() are gone, and the builtin cmp function no longer exists. - The old tp_compare slot has been renamed to tp_as_async, and should no + The old tp_compare slot has been renamed to tp_as_async, and should no longer be used. Use tp_richcompare instead. See (*) below for practical amendments. @@ -654,28 +654,28 @@ static const char * const opstrings[] = {"<", "<=", "==", "!=", ">", ">="}; /* Perform a rich comparison, raising TypeError when the requested comparison operator is not supported. */ static PyObject * -do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) +do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) { richcmpfunc f; PyObject *res; int checked_reverse_op = 0; - if (!Py_IS_TYPE(v, Py_TYPE(w)) && - PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) && - (f = Py_TYPE(w)->tp_richcompare) != NULL) { + if (!Py_IS_TYPE(v, Py_TYPE(w)) && + PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) && + (f = Py_TYPE(w)->tp_richcompare) != NULL) { checked_reverse_op = 1; res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if ((f = Py_TYPE(v)->tp_richcompare) != NULL) { + if ((f = Py_TYPE(v)->tp_richcompare) != NULL) { res = (*f)(v, w, op); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if (!checked_reverse_op && (f = Py_TYPE(w)->tp_richcompare) != NULL) { + if (!checked_reverse_op && (f = Py_TYPE(w)->tp_richcompare) != NULL) { res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; @@ -691,11 +691,11 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) res = (v != w) ? Py_True : Py_False; break; default: - _PyErr_Format(tstate, PyExc_TypeError, - "'%s' not supported between instances of '%.100s' and '%.100s'", - opstrings[op], - Py_TYPE(v)->tp_name, - Py_TYPE(w)->tp_name); + _PyErr_Format(tstate, PyExc_TypeError, + "'%s' not supported between instances of '%.100s' and '%.100s'", + opstrings[op], + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } Py_INCREF(res); @@ -708,20 +708,20 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) PyObject * PyObject_RichCompare(PyObject *v, PyObject *w, int op) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); assert(Py_LT <= op && op <= Py_GE); if (v == NULL || w == NULL) { - if (!_PyErr_Occurred(tstate)) { + if (!_PyErr_Occurred(tstate)) { PyErr_BadInternalCall(); - } + } return NULL; } - if (_Py_EnterRecursiveCall(tstate, " in comparison")) { + if (_Py_EnterRecursiveCall(tstate, " in comparison")) { return NULL; - } - PyObject *res = do_richcompare(tstate, v, w, op); - _Py_LeaveRecursiveCall(tstate); + } + PyObject *res = do_richcompare(tstate, v, w, op); + _Py_LeaveRecursiveCall(tstate); return res; } @@ -883,7 +883,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); return NULL; } if (tp->tp_getattro != NULL) @@ -908,7 +908,7 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); *result = NULL; return -1; } @@ -984,7 +984,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); return -1; } Py_INCREF(name); @@ -997,16 +997,16 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) } if (tp->tp_setattr != NULL) { const char *name_str = PyUnicode_AsUTF8(name); - if (name_str == NULL) { - Py_DECREF(name); + if (name_str == NULL) { + Py_DECREF(name); return -1; - } + } err = (*tp->tp_setattr)(v, (char *)name_str, value); Py_DECREF(name); return err; } Py_DECREF(name); - _PyObject_ASSERT(name, Py_REFCNT(name) >= 1); + _PyObject_ASSERT(name, Py_REFCNT(name) >= 1); if (tp->tp_getattr == NULL && tp->tp_getattro == NULL) PyErr_Format(PyExc_TypeError, "'%.100s' object has no attributes " @@ -1036,15 +1036,15 @@ _PyObject_GetDictPtr(PyObject *obj) if (dictoffset == 0) return NULL; if (dictoffset < 0) { - Py_ssize_t tsize = Py_SIZE(obj); - if (tsize < 0) { + Py_ssize_t tsize = Py_SIZE(obj); + if (tsize < 0) { tsize = -tsize; - } - size_t size = _PyObject_VAR_SIZE(tp, tsize); + } + size_t size = _PyObject_VAR_SIZE(tp, tsize); dictoffset += (long)size; - _PyObject_ASSERT(obj, dictoffset > 0); - _PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0); + _PyObject_ASSERT(obj, dictoffset > 0); + _PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0); } return (PyObject **) ((char *)obj + dictoffset); } @@ -1105,12 +1105,12 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) descr = _PyType_Lookup(tp, name); if (descr != NULL) { Py_INCREF(descr); - if (_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) { + if (_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) { meth_found = 1; } else { - f = Py_TYPE(descr)->tp_descr_get; + f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - *method = f(descr, obj, (PyObject *)Py_TYPE(obj)); + *method = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); return 0; } @@ -1120,7 +1120,7 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) dictptr = _PyObject_GetDictPtr(obj); if (dictptr != NULL && (dict = *dictptr) != NULL) { Py_INCREF(dict); - attr = PyDict_GetItemWithError(dict, name); + attr = PyDict_GetItemWithError(dict, name); if (attr != NULL) { Py_INCREF(attr); *method = attr; @@ -1128,13 +1128,13 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) Py_XDECREF(descr); return 0; } - else { - Py_DECREF(dict); - if (PyErr_Occurred()) { - Py_XDECREF(descr); - return 0; - } - } + else { + Py_DECREF(dict); + if (PyErr_Occurred()) { + Py_XDECREF(descr); + return 0; + } + } } if (meth_found) { @@ -1181,7 +1181,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); return NULL; } Py_INCREF(name); @@ -1196,9 +1196,9 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, f = NULL; if (descr != NULL) { Py_INCREF(descr); - f = Py_TYPE(descr)->tp_descr_get; + f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - res = f(descr, obj, (PyObject *)Py_TYPE(obj)); + res = f(descr, obj, (PyObject *)Py_TYPE(obj)); if (res == NULL && suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); @@ -1212,16 +1212,16 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, dictoffset = tp->tp_dictoffset; if (dictoffset != 0) { if (dictoffset < 0) { - Py_ssize_t tsize = Py_SIZE(obj); - if (tsize < 0) { + Py_ssize_t tsize = Py_SIZE(obj); + if (tsize < 0) { tsize = -tsize; - } - size_t size = _PyObject_VAR_SIZE(tp, tsize); - _PyObject_ASSERT(obj, size <= PY_SSIZE_T_MAX); + } + size_t size = _PyObject_VAR_SIZE(tp, tsize); + _PyObject_ASSERT(obj, size <= PY_SSIZE_T_MAX); dictoffset += (Py_ssize_t)size; - _PyObject_ASSERT(obj, dictoffset > 0); - _PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0); + _PyObject_ASSERT(obj, dictoffset > 0); + _PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0); } dictptr = (PyObject **) ((char *)obj + dictoffset); dict = *dictptr; @@ -1229,23 +1229,23 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, } if (dict != NULL) { Py_INCREF(dict); - res = PyDict_GetItemWithError(dict, name); + res = PyDict_GetItemWithError(dict, name); if (res != NULL) { Py_INCREF(res); Py_DECREF(dict); goto done; } - else { - Py_DECREF(dict); - if (PyErr_Occurred()) { - if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } - else { - goto done; - } - } - } + else { + Py_DECREF(dict); + if (PyErr_Occurred()) { + if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } + else { + goto done; + } + } + } } if (f != NULL) { @@ -1293,7 +1293,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); return -1; } @@ -1306,21 +1306,21 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (descr != NULL) { Py_INCREF(descr); - f = Py_TYPE(descr)->tp_descr_set; + f = Py_TYPE(descr)->tp_descr_set; if (f != NULL) { res = f(descr, obj, value); goto done; } } - /* XXX [Steve Dower] These are really noisy - worth it? */ - /*if (PyType_Check(obj) || PyModule_Check(obj)) { - if (value && PySys_Audit("object.__setattr__", "OOO", obj, name, value) < 0) - return -1; - if (!value && PySys_Audit("object.__delattr__", "OO", obj, name) < 0) - return -1; - }*/ - + /* XXX [Steve Dower] These are really noisy - worth it? */ + /*if (PyType_Check(obj) || PyModule_Check(obj)) { + if (value && PySys_Audit("object.__setattr__", "OOO", obj, name, value) < 0) + return -1; + if (!value && PySys_Audit("object.__delattr__", "OO", obj, name) < 0) + return -1; + }*/ + if (dict == NULL) { dictptr = _PyObject_GetDictPtr(obj); if (dictptr == NULL) { @@ -1399,15 +1399,15 @@ PyObject_IsTrue(PyObject *v) return 0; if (v == Py_None) return 0; - else if (Py_TYPE(v)->tp_as_number != NULL && - Py_TYPE(v)->tp_as_number->nb_bool != NULL) - res = (*Py_TYPE(v)->tp_as_number->nb_bool)(v); - else if (Py_TYPE(v)->tp_as_mapping != NULL && - Py_TYPE(v)->tp_as_mapping->mp_length != NULL) - res = (*Py_TYPE(v)->tp_as_mapping->mp_length)(v); - else if (Py_TYPE(v)->tp_as_sequence != NULL && - Py_TYPE(v)->tp_as_sequence->sq_length != NULL) - res = (*Py_TYPE(v)->tp_as_sequence->sq_length)(v); + else if (Py_TYPE(v)->tp_as_number != NULL && + Py_TYPE(v)->tp_as_number->nb_bool != NULL) + res = (*Py_TYPE(v)->tp_as_number->nb_bool)(v); + else if (Py_TYPE(v)->tp_as_mapping != NULL && + Py_TYPE(v)->tp_as_mapping->mp_length != NULL) + res = (*Py_TYPE(v)->tp_as_mapping->mp_length)(v); + else if (Py_TYPE(v)->tp_as_sequence != NULL && + Py_TYPE(v)->tp_as_sequence->sq_length != NULL) + res = (*Py_TYPE(v)->tp_as_sequence->sq_length)(v); else return 1; /* if it is negative, it should be either -1 or -2 */ @@ -1434,7 +1434,7 @@ PyCallable_Check(PyObject *x) { if (x == NULL) return 0; - return Py_TYPE(x)->tp_call != NULL; + return Py_TYPE(x)->tp_call != NULL; } @@ -1474,7 +1474,7 @@ _dir_object(PyObject *obj) PyObject *result, *sorted; PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__); - assert(obj != NULL); + assert(obj != NULL); if (dirfunc == NULL) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "object does not provide __dir__"); @@ -1521,7 +1521,7 @@ none_repr(PyObject *op) } /* ARGUSED */ -static void _Py_NO_RETURN +static void _Py_NO_RETURN none_dealloc(PyObject* ignore) { /* This should never get called, but we also don't want to SEGV if @@ -1589,10 +1589,10 @@ PyTypeObject _PyNone_Type = { 0, 0, none_dealloc, /*tp_dealloc*/ /*never called*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ none_repr, /*tp_repr*/ &none_as_number, /*tp_as_number*/ 0, /*tp_as_sequence*/ @@ -1639,13 +1639,13 @@ NotImplemented_repr(PyObject *op) } static PyObject * -NotImplemented_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) +NotImplemented_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) { return PyUnicode_FromString("NotImplemented"); } static PyMethodDef notimplemented_methods[] = { - {"__reduce__", NotImplemented_reduce, METH_NOARGS, NULL}, + {"__reduce__", NotImplemented_reduce, METH_NOARGS, NULL}, {NULL, NULL} }; @@ -1659,7 +1659,7 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) Py_RETURN_NOTIMPLEMENTED; } -static void _Py_NO_RETURN +static void _Py_NO_RETURN notimplemented_dealloc(PyObject* ignore) { /* This should never get called, but we also don't want to SEGV if @@ -1668,34 +1668,34 @@ notimplemented_dealloc(PyObject* ignore) Py_FatalError("deallocating NotImplemented"); } -static int -notimplemented_bool(PyObject *v) -{ - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "NotImplemented should not be used in a boolean context", - 1) < 0) - { - return -1; - } - return 1; -} - -static PyNumberMethods notimplemented_as_number = { - .nb_bool = notimplemented_bool, -}; - +static int +notimplemented_bool(PyObject *v) +{ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "NotImplemented should not be used in a boolean context", + 1) < 0) + { + return -1; + } + return 1; +} + +static PyNumberMethods notimplemented_as_number = { + .nb_bool = notimplemented_bool, +}; + PyTypeObject _PyNotImplemented_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "NotImplementedType", 0, 0, notimplemented_dealloc, /*tp_dealloc*/ /*never called*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ - NotImplemented_repr, /*tp_repr*/ - ¬implemented_as_number, /*tp_as_number*/ + 0, /*tp_as_async*/ + NotImplemented_repr, /*tp_repr*/ + ¬implemented_as_number, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ @@ -1730,138 +1730,138 @@ PyObject _Py_NotImplementedStruct = { 1, &_PyNotImplemented_Type }; -PyStatus -_PyTypes_Init(void) -{ - PyStatus status = _PyTypes_InitSlotDefs(); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - -#define INIT_TYPE(TYPE, NAME) \ - do { \ - if (PyType_Ready(TYPE) < 0) { \ - return _PyStatus_ERR("Can't initialize " NAME " type"); \ - } \ - } while (0) - - INIT_TYPE(&PyBaseObject_Type, "object"); - INIT_TYPE(&PyType_Type, "type"); - INIT_TYPE(&_PyWeakref_RefType, "weakref"); - INIT_TYPE(&_PyWeakref_CallableProxyType, "callable weakref proxy"); - INIT_TYPE(&_PyWeakref_ProxyType, "weakref proxy"); - INIT_TYPE(&PyLong_Type, "int"); - INIT_TYPE(&PyBool_Type, "bool"); - INIT_TYPE(&PyByteArray_Type, "bytearray"); - INIT_TYPE(&PyBytes_Type, "str"); - INIT_TYPE(&PyList_Type, "list"); - INIT_TYPE(&_PyNone_Type, "None"); - INIT_TYPE(&_PyNotImplemented_Type, "NotImplemented"); - INIT_TYPE(&PyTraceBack_Type, "traceback"); - INIT_TYPE(&PySuper_Type, "super"); - INIT_TYPE(&PyRange_Type, "range"); - INIT_TYPE(&PyDict_Type, "dict"); - INIT_TYPE(&PyDictKeys_Type, "dict keys"); - INIT_TYPE(&PyDictValues_Type, "dict values"); - INIT_TYPE(&PyDictItems_Type, "dict items"); - INIT_TYPE(&PyDictRevIterKey_Type, "reversed dict keys"); - INIT_TYPE(&PyDictRevIterValue_Type, "reversed dict values"); - INIT_TYPE(&PyDictRevIterItem_Type, "reversed dict items"); - INIT_TYPE(&PyODict_Type, "OrderedDict"); - INIT_TYPE(&PyODictKeys_Type, "odict_keys"); - INIT_TYPE(&PyODictItems_Type, "odict_items"); - INIT_TYPE(&PyODictValues_Type, "odict_values"); - INIT_TYPE(&PyODictIter_Type, "odict_keyiterator"); - INIT_TYPE(&PySet_Type, "set"); - INIT_TYPE(&PyUnicode_Type, "str"); - INIT_TYPE(&PySlice_Type, "slice"); - INIT_TYPE(&PyStaticMethod_Type, "static method"); - INIT_TYPE(&PyComplex_Type, "complex"); - INIT_TYPE(&PyFloat_Type, "float"); - INIT_TYPE(&PyFrozenSet_Type, "frozenset"); - INIT_TYPE(&PyProperty_Type, "property"); - INIT_TYPE(&_PyManagedBuffer_Type, "managed buffer"); - INIT_TYPE(&PyMemoryView_Type, "memoryview"); - INIT_TYPE(&PyTuple_Type, "tuple"); - INIT_TYPE(&PyEnum_Type, "enumerate"); - INIT_TYPE(&PyReversed_Type, "reversed"); - INIT_TYPE(&PyStdPrinter_Type, "StdPrinter"); - INIT_TYPE(&PyCode_Type, "code"); - INIT_TYPE(&PyFrame_Type, "frame"); - INIT_TYPE(&PyCFunction_Type, "builtin function"); - INIT_TYPE(&PyCMethod_Type, "builtin method"); - INIT_TYPE(&PyMethod_Type, "method"); - INIT_TYPE(&PyFunction_Type, "function"); - INIT_TYPE(&PyDictProxy_Type, "dict proxy"); - INIT_TYPE(&PyGen_Type, "generator"); - INIT_TYPE(&PyGetSetDescr_Type, "get-set descriptor"); - INIT_TYPE(&PyWrapperDescr_Type, "wrapper"); - INIT_TYPE(&_PyMethodWrapper_Type, "method wrapper"); - INIT_TYPE(&PyEllipsis_Type, "ellipsis"); - INIT_TYPE(&PyMemberDescr_Type, "member descriptor"); - INIT_TYPE(&_PyNamespace_Type, "namespace"); - INIT_TYPE(&PyCapsule_Type, "capsule"); - INIT_TYPE(&PyLongRangeIter_Type, "long range iterator"); - INIT_TYPE(&PyCell_Type, "cell"); - INIT_TYPE(&PyInstanceMethod_Type, "instance method"); - INIT_TYPE(&PyClassMethodDescr_Type, "class method descr"); - INIT_TYPE(&PyMethodDescr_Type, "method descr"); - INIT_TYPE(&PyCallIter_Type, "call iter"); - INIT_TYPE(&PySeqIter_Type, "sequence iterator"); - INIT_TYPE(&PyPickleBuffer_Type, "pickle.PickleBuffer"); - INIT_TYPE(&PyCoro_Type, "coroutine"); - INIT_TYPE(&_PyCoroWrapper_Type, "coroutine wrapper"); - INIT_TYPE(&_PyInterpreterID_Type, "interpreter ID"); - return _PyStatus_OK(); - -#undef INIT_TYPE +PyStatus +_PyTypes_Init(void) +{ + PyStatus status = _PyTypes_InitSlotDefs(); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + +#define INIT_TYPE(TYPE, NAME) \ + do { \ + if (PyType_Ready(TYPE) < 0) { \ + return _PyStatus_ERR("Can't initialize " NAME " type"); \ + } \ + } while (0) + + INIT_TYPE(&PyBaseObject_Type, "object"); + INIT_TYPE(&PyType_Type, "type"); + INIT_TYPE(&_PyWeakref_RefType, "weakref"); + INIT_TYPE(&_PyWeakref_CallableProxyType, "callable weakref proxy"); + INIT_TYPE(&_PyWeakref_ProxyType, "weakref proxy"); + INIT_TYPE(&PyLong_Type, "int"); + INIT_TYPE(&PyBool_Type, "bool"); + INIT_TYPE(&PyByteArray_Type, "bytearray"); + INIT_TYPE(&PyBytes_Type, "str"); + INIT_TYPE(&PyList_Type, "list"); + INIT_TYPE(&_PyNone_Type, "None"); + INIT_TYPE(&_PyNotImplemented_Type, "NotImplemented"); + INIT_TYPE(&PyTraceBack_Type, "traceback"); + INIT_TYPE(&PySuper_Type, "super"); + INIT_TYPE(&PyRange_Type, "range"); + INIT_TYPE(&PyDict_Type, "dict"); + INIT_TYPE(&PyDictKeys_Type, "dict keys"); + INIT_TYPE(&PyDictValues_Type, "dict values"); + INIT_TYPE(&PyDictItems_Type, "dict items"); + INIT_TYPE(&PyDictRevIterKey_Type, "reversed dict keys"); + INIT_TYPE(&PyDictRevIterValue_Type, "reversed dict values"); + INIT_TYPE(&PyDictRevIterItem_Type, "reversed dict items"); + INIT_TYPE(&PyODict_Type, "OrderedDict"); + INIT_TYPE(&PyODictKeys_Type, "odict_keys"); + INIT_TYPE(&PyODictItems_Type, "odict_items"); + INIT_TYPE(&PyODictValues_Type, "odict_values"); + INIT_TYPE(&PyODictIter_Type, "odict_keyiterator"); + INIT_TYPE(&PySet_Type, "set"); + INIT_TYPE(&PyUnicode_Type, "str"); + INIT_TYPE(&PySlice_Type, "slice"); + INIT_TYPE(&PyStaticMethod_Type, "static method"); + INIT_TYPE(&PyComplex_Type, "complex"); + INIT_TYPE(&PyFloat_Type, "float"); + INIT_TYPE(&PyFrozenSet_Type, "frozenset"); + INIT_TYPE(&PyProperty_Type, "property"); + INIT_TYPE(&_PyManagedBuffer_Type, "managed buffer"); + INIT_TYPE(&PyMemoryView_Type, "memoryview"); + INIT_TYPE(&PyTuple_Type, "tuple"); + INIT_TYPE(&PyEnum_Type, "enumerate"); + INIT_TYPE(&PyReversed_Type, "reversed"); + INIT_TYPE(&PyStdPrinter_Type, "StdPrinter"); + INIT_TYPE(&PyCode_Type, "code"); + INIT_TYPE(&PyFrame_Type, "frame"); + INIT_TYPE(&PyCFunction_Type, "builtin function"); + INIT_TYPE(&PyCMethod_Type, "builtin method"); + INIT_TYPE(&PyMethod_Type, "method"); + INIT_TYPE(&PyFunction_Type, "function"); + INIT_TYPE(&PyDictProxy_Type, "dict proxy"); + INIT_TYPE(&PyGen_Type, "generator"); + INIT_TYPE(&PyGetSetDescr_Type, "get-set descriptor"); + INIT_TYPE(&PyWrapperDescr_Type, "wrapper"); + INIT_TYPE(&_PyMethodWrapper_Type, "method wrapper"); + INIT_TYPE(&PyEllipsis_Type, "ellipsis"); + INIT_TYPE(&PyMemberDescr_Type, "member descriptor"); + INIT_TYPE(&_PyNamespace_Type, "namespace"); + INIT_TYPE(&PyCapsule_Type, "capsule"); + INIT_TYPE(&PyLongRangeIter_Type, "long range iterator"); + INIT_TYPE(&PyCell_Type, "cell"); + INIT_TYPE(&PyInstanceMethod_Type, "instance method"); + INIT_TYPE(&PyClassMethodDescr_Type, "class method descr"); + INIT_TYPE(&PyMethodDescr_Type, "method descr"); + INIT_TYPE(&PyCallIter_Type, "call iter"); + INIT_TYPE(&PySeqIter_Type, "sequence iterator"); + INIT_TYPE(&PyPickleBuffer_Type, "pickle.PickleBuffer"); + INIT_TYPE(&PyCoro_Type, "coroutine"); + INIT_TYPE(&_PyCoroWrapper_Type, "coroutine wrapper"); + INIT_TYPE(&_PyInterpreterID_Type, "interpreter ID"); + return _PyStatus_OK(); + +#undef INIT_TYPE } void _Py_NewReference(PyObject *op) { - if (_Py_tracemalloc_config.tracing) { - _PyTraceMalloc_NewReference(op); - } -#ifdef Py_REF_DEBUG - _Py_RefTotal++; -#endif - Py_SET_REFCNT(op, 1); -#ifdef Py_TRACE_REFS + if (_Py_tracemalloc_config.tracing) { + _PyTraceMalloc_NewReference(op); + } +#ifdef Py_REF_DEBUG + _Py_RefTotal++; +#endif + Py_SET_REFCNT(op, 1); +#ifdef Py_TRACE_REFS _Py_AddToAllObjects(op, 1); -#endif +#endif } - -#ifdef Py_TRACE_REFS + +#ifdef Py_TRACE_REFS void _Py_ForgetReference(PyObject *op) { - if (Py_REFCNT(op) < 0) { - _PyObject_ASSERT_FAILED_MSG(op, "negative refcnt"); - } - + if (Py_REFCNT(op) < 0) { + _PyObject_ASSERT_FAILED_MSG(op, "negative refcnt"); + } + if (op == &refchain || - op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) - { - _PyObject_ASSERT_FAILED_MSG(op, "invalid object chain"); + op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) + { + _PyObject_ASSERT_FAILED_MSG(op, "invalid object chain"); } - + #ifdef SLOW_UNREF_CHECK - PyObject *p; + PyObject *p; for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) { - if (p == op) { + if (p == op) { break; - } + } + } + if (p == &refchain) { + /* Not found */ + _PyObject_ASSERT_FAILED_MSG(op, + "object not found in the objects list"); } - if (p == &refchain) { - /* Not found */ - _PyObject_ASSERT_FAILED_MSG(op, - "object not found in the objects list"); - } #endif - + op->_ob_next->_ob_prev = op->_ob_prev; op->_ob_prev->_ob_next = op->_ob_next; op->_ob_next = op->_ob_prev = NULL; @@ -1876,7 +1876,7 @@ _Py_PrintReferences(FILE *fp) PyObject *op; fprintf(fp, "Remaining objects:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) { - fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", (void *)op, Py_REFCNT(op)); + fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", (void *)op, Py_REFCNT(op)); if (PyObject_Print(op, fp, 0) != 0) PyErr_Clear(); putc('\n', fp); @@ -1892,8 +1892,8 @@ _Py_PrintReferenceAddresses(FILE *fp) PyObject *op; fprintf(fp, "Remaining object addresses:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) - fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", (void *)op, - Py_REFCNT(op), Py_TYPE(op)->tp_name); + fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", (void *)op, + Py_REFCNT(op), Py_TYPE(op)->tp_name); } PyObject * @@ -1911,7 +1911,7 @@ _Py_GetObjects(PyObject *self, PyObject *args) return NULL; for (i = 0; (n == 0 || i < n) && op != &refchain; i++) { while (op == self || op == args || op == res || op == t || - (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) { + (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) { op = op->_ob_next; if (op == &refchain) return res; @@ -1966,11 +1966,11 @@ Py_ReprEnter(PyObject *obj) early on startup. */ if (dict == NULL) return 0; - list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); + list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); if (list == NULL) { - if (PyErr_Occurred()) { - return -1; - } + if (PyErr_Occurred()) { + return -1; + } list = PyList_New(0); if (list == NULL) return -1; @@ -2002,7 +2002,7 @@ Py_ReprLeave(PyObject *obj) if (dict == NULL) goto finally; - list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); + list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); if (list == NULL || !PyList_Check(list)) goto finally; @@ -2029,43 +2029,43 @@ finally: void _PyTrash_deposit_object(PyObject *op) { - PyThreadState *tstate = _PyThreadState_GET(); - struct _gc_runtime_state *gcstate = &tstate->interp->gc; - - _PyObject_ASSERT(op, _PyObject_IS_GC(op)); - _PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op)); - _PyObject_ASSERT(op, Py_REFCNT(op) == 0); - _PyGCHead_SET_PREV(_Py_AS_GC(op), gcstate->trash_delete_later); - gcstate->trash_delete_later = op; + PyThreadState *tstate = _PyThreadState_GET(); + struct _gc_runtime_state *gcstate = &tstate->interp->gc; + + _PyObject_ASSERT(op, _PyObject_IS_GC(op)); + _PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op)); + _PyObject_ASSERT(op, Py_REFCNT(op) == 0); + _PyGCHead_SET_PREV(_Py_AS_GC(op), gcstate->trash_delete_later); + gcstate->trash_delete_later = op; } /* The equivalent API, using per-thread state recursion info */ void _PyTrash_thread_deposit_object(PyObject *op) { - PyThreadState *tstate = _PyThreadState_GET(); - _PyObject_ASSERT(op, _PyObject_IS_GC(op)); - _PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op)); - _PyObject_ASSERT(op, Py_REFCNT(op) == 0); - _PyGCHead_SET_PREV(_Py_AS_GC(op), tstate->trash_delete_later); + PyThreadState *tstate = _PyThreadState_GET(); + _PyObject_ASSERT(op, _PyObject_IS_GC(op)); + _PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op)); + _PyObject_ASSERT(op, Py_REFCNT(op) == 0); + _PyGCHead_SET_PREV(_Py_AS_GC(op), tstate->trash_delete_later); tstate->trash_delete_later = op; } -/* Deallocate all the objects in the _PyTrash_delete_later list. Called when +/* Deallocate all the objects in the _PyTrash_delete_later list. Called when * the call-stack unwinds again. */ void _PyTrash_destroy_chain(void) { - PyThreadState *tstate = _PyThreadState_GET(); - struct _gc_runtime_state *gcstate = &tstate->interp->gc; - - while (gcstate->trash_delete_later) { - PyObject *op = gcstate->trash_delete_later; + PyThreadState *tstate = _PyThreadState_GET(); + struct _gc_runtime_state *gcstate = &tstate->interp->gc; + + while (gcstate->trash_delete_later) { + PyObject *op = gcstate->trash_delete_later; destructor dealloc = Py_TYPE(op)->tp_dealloc; - gcstate->trash_delete_later = - (PyObject*) _PyGCHead_PREV(_Py_AS_GC(op)); + gcstate->trash_delete_later = + (PyObject*) _PyGCHead_PREV(_Py_AS_GC(op)); /* Call the deallocator directly. This used to try to * fool Py_DECREF into calling it indirectly, but @@ -2073,10 +2073,10 @@ _PyTrash_destroy_chain(void) * assorted non-release builds calling Py_DECREF again ends * up distorting allocation statistics. */ - _PyObject_ASSERT(op, Py_REFCNT(op) == 0); - ++gcstate->trash_delete_nesting; + _PyObject_ASSERT(op, Py_REFCNT(op) == 0); + ++gcstate->trash_delete_nesting; (*dealloc)(op); - --gcstate->trash_delete_nesting; + --gcstate->trash_delete_nesting; } } @@ -2084,7 +2084,7 @@ _PyTrash_destroy_chain(void) void _PyTrash_thread_destroy_chain(void) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); /* We need to increase trash_delete_nesting here, otherwise, _PyTrash_thread_destroy_chain will be called recursively and then possibly crash. An example that may crash without @@ -2103,7 +2103,7 @@ _PyTrash_thread_destroy_chain(void) destructor dealloc = Py_TYPE(op)->tp_dealloc; tstate->trash_delete_later = - (PyObject*) _PyGCHead_PREV(_Py_AS_GC(op)); + (PyObject*) _PyGCHead_PREV(_Py_AS_GC(op)); /* Call the deallocator directly. This used to try to * fool Py_DECREF into calling it indirectly, but @@ -2111,112 +2111,112 @@ _PyTrash_thread_destroy_chain(void) * assorted non-release builds calling Py_DECREF again ends * up distorting allocation statistics. */ - _PyObject_ASSERT(op, Py_REFCNT(op) == 0); + _PyObject_ASSERT(op, Py_REFCNT(op) == 0); (*dealloc)(op); assert(tstate->trash_delete_nesting == 1); } --tstate->trash_delete_nesting; } - -int -_PyTrash_begin(PyThreadState *tstate, PyObject *op) -{ - if (tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) { - /* Store the object (to be deallocated later) and jump past - * Py_TRASHCAN_END, skipping the body of the deallocator */ - _PyTrash_thread_deposit_object(op); - return 1; - } - ++tstate->trash_delete_nesting; - return 0; -} - - -void -_PyTrash_end(PyThreadState *tstate) -{ - --tstate->trash_delete_nesting; - if (tstate->trash_delete_later && tstate->trash_delete_nesting <= 0) { - _PyTrash_thread_destroy_chain(); - } -} - - -void _Py_NO_RETURN -_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg, - const char *file, int line, const char *function) -{ - fprintf(stderr, "%s:%d: ", file, line); - if (function) { - fprintf(stderr, "%s: ", function); - } - fflush(stderr); - - if (expr) { - fprintf(stderr, "Assertion \"%s\" failed", expr); - } - else { - fprintf(stderr, "Assertion failed"); - } - fflush(stderr); - - if (msg) { - fprintf(stderr, ": %s", msg); - } - fprintf(stderr, "\n"); - fflush(stderr); - - if (_PyObject_IsFreed(obj)) { - /* It seems like the object memory has been freed: - don't access it to prevent a segmentation fault. */ - fprintf(stderr, "<object at %p is freed>\n", obj); - fflush(stderr); - } - else { - /* Display the traceback where the object has been allocated. - Do it before dumping repr(obj), since repr() is more likely - to crash than dumping the traceback. */ - void *ptr; - PyTypeObject *type = Py_TYPE(obj); - if (_PyType_IS_GC(type)) { - ptr = (void *)((char *)obj - sizeof(PyGC_Head)); - } - else { - ptr = (void *)obj; - } - _PyMem_DumpTraceback(fileno(stderr), ptr); - - /* This might succeed or fail, but we're about to abort, so at least - try to provide any extra info we can: */ - _PyObject_Dump(obj); - - fprintf(stderr, "\n"); - fflush(stderr); - } - - Py_FatalError("_PyObject_AssertFailed"); -} - - + +int +_PyTrash_begin(PyThreadState *tstate, PyObject *op) +{ + if (tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) { + /* Store the object (to be deallocated later) and jump past + * Py_TRASHCAN_END, skipping the body of the deallocator */ + _PyTrash_thread_deposit_object(op); + return 1; + } + ++tstate->trash_delete_nesting; + return 0; +} + + +void +_PyTrash_end(PyThreadState *tstate) +{ + --tstate->trash_delete_nesting; + if (tstate->trash_delete_later && tstate->trash_delete_nesting <= 0) { + _PyTrash_thread_destroy_chain(); + } +} + + +void _Py_NO_RETURN +_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg, + const char *file, int line, const char *function) +{ + fprintf(stderr, "%s:%d: ", file, line); + if (function) { + fprintf(stderr, "%s: ", function); + } + fflush(stderr); + + if (expr) { + fprintf(stderr, "Assertion \"%s\" failed", expr); + } + else { + fprintf(stderr, "Assertion failed"); + } + fflush(stderr); + + if (msg) { + fprintf(stderr, ": %s", msg); + } + fprintf(stderr, "\n"); + fflush(stderr); + + if (_PyObject_IsFreed(obj)) { + /* It seems like the object memory has been freed: + don't access it to prevent a segmentation fault. */ + fprintf(stderr, "<object at %p is freed>\n", obj); + fflush(stderr); + } + else { + /* Display the traceback where the object has been allocated. + Do it before dumping repr(obj), since repr() is more likely + to crash than dumping the traceback. */ + void *ptr; + PyTypeObject *type = Py_TYPE(obj); + if (_PyType_IS_GC(type)) { + ptr = (void *)((char *)obj - sizeof(PyGC_Head)); + } + else { + ptr = (void *)obj; + } + _PyMem_DumpTraceback(fileno(stderr), ptr); + + /* This might succeed or fail, but we're about to abort, so at least + try to provide any extra info we can: */ + _PyObject_Dump(obj); + + fprintf(stderr, "\n"); + fflush(stderr); + } + + Py_FatalError("_PyObject_AssertFailed"); +} + + void _Py_Dealloc(PyObject *op) { - destructor dealloc = Py_TYPE(op)->tp_dealloc; -#ifdef Py_TRACE_REFS - _Py_ForgetReference(op); -#endif - (*dealloc)(op); -} - - -PyObject ** -PyObject_GET_WEAKREFS_LISTPTR(PyObject *op) -{ - return _PyObject_GET_WEAKREFS_LISTPTR(op); -} - - + destructor dealloc = Py_TYPE(op)->tp_dealloc; +#ifdef Py_TRACE_REFS + _Py_ForgetReference(op); +#endif + (*dealloc)(op); +} + + +PyObject ** +PyObject_GET_WEAKREFS_LISTPTR(PyObject *op) +{ + return _PyObject_GET_WEAKREFS_LISTPTR(op); +} + + #ifdef __cplusplus } #endif diff --git a/contrib/tools/python3/src/Objects/obmalloc.c b/contrib/tools/python3/src/Objects/obmalloc.c index 1bff84b232..9f8e0d114f 100644 --- a/contrib/tools/python3/src/Objects/obmalloc.c +++ b/contrib/tools/python3/src/Objects/obmalloc.c @@ -1,5 +1,5 @@ #include "Python.h" -#include "pycore_pymem.h" // _PyTraceMalloc_Config +#include "pycore_pymem.h" // _PyTraceMalloc_Config #include <stdbool.h> @@ -25,14 +25,14 @@ static void* _PyMem_DebugRealloc(void *ctx, void *ptr, size_t size); static void _PyMem_DebugFree(void *ctx, void *p); static void _PyObject_DebugDumpAddress(const void *p); -static void _PyMem_DebugCheckAddress(const char *func, char api_id, const void *p); +static void _PyMem_DebugCheckAddress(const char *func, char api_id, const void *p); static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain); #if defined(__has_feature) /* Clang */ # if __has_feature(address_sanitizer) /* is ASAN enabled? */ -# define _Py_NO_SANITIZE_ADDRESS \ - __attribute__((no_sanitize("address"))) +# define _Py_NO_SANITIZE_ADDRESS \ + __attribute__((no_sanitize("address"))) # endif # if __has_feature(thread_sanitizer) /* is TSAN enabled? */ # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) @@ -42,18 +42,18 @@ static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain); # endif #elif defined(__GNUC__) # if defined(__SANITIZE_ADDRESS__) /* GCC 4.8+, is ASAN enabled? */ -# define _Py_NO_SANITIZE_ADDRESS \ - __attribute__((no_sanitize_address)) +# define _Py_NO_SANITIZE_ADDRESS \ + __attribute__((no_sanitize_address)) # endif - // TSAN is supported since GCC 5.1, but __SANITIZE_THREAD__ macro + // TSAN is supported since GCC 5.1, but __SANITIZE_THREAD__ macro // is provided only since GCC 7. -# if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1) +# if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1) # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) # endif #endif -#ifndef _Py_NO_SANITIZE_ADDRESS -# define _Py_NO_SANITIZE_ADDRESS +#ifndef _Py_NO_SANITIZE_ADDRESS +# define _Py_NO_SANITIZE_ADDRESS #endif #ifndef _Py_NO_SANITIZE_THREAD # define _Py_NO_SANITIZE_THREAD @@ -81,12 +81,12 @@ static void* _PyObject_Realloc(void *ctx, void *ptr, size_t size); #endif -/* bpo-35053: Declare tracemalloc configuration here rather than - Modules/_tracemalloc.c because _tracemalloc can be compiled as dynamic - library, whereas _Py_NewReference() requires it. */ -struct _PyTraceMalloc_Config _Py_tracemalloc_config = _PyTraceMalloc_Config_INIT; - - +/* bpo-35053: Declare tracemalloc configuration here rather than + Modules/_tracemalloc.c because _tracemalloc can be compiled as dynamic + library, whereas _Py_NewReference() requires it. */ +struct _PyTraceMalloc_Config _Py_tracemalloc_config = _PyTraceMalloc_Config_INIT; + + static void * _PyMem_RawMalloc(void *ctx, size_t size) { @@ -268,65 +268,65 @@ _PyMem_SetDefaultAllocator(PyMemAllocatorDomain domain, int -_PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator) +_PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator) { - if (name == NULL || *name == '\0') { + if (name == NULL || *name == '\0') { /* PYTHONMALLOC is empty or is not set or ignored (-E/-I command line - nameions): use default memory allocators */ - *allocator = PYMEM_ALLOCATOR_DEFAULT; - } - else if (strcmp(name, "default") == 0) { - *allocator = PYMEM_ALLOCATOR_DEFAULT; - } - else if (strcmp(name, "debug") == 0) { - *allocator = PYMEM_ALLOCATOR_DEBUG; - } -#ifdef WITH_PYMALLOC - else if (strcmp(name, "pymalloc") == 0) { - *allocator = PYMEM_ALLOCATOR_PYMALLOC; - } - else if (strcmp(name, "pymalloc_debug") == 0) { - *allocator = PYMEM_ALLOCATOR_PYMALLOC_DEBUG; - } -#endif - else if (strcmp(name, "malloc") == 0) { - *allocator = PYMEM_ALLOCATOR_MALLOC; - } - else if (strcmp(name, "malloc_debug") == 0) { - *allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG; - } - else { - /* unknown allocator */ - return -1; - } - return 0; -} - - -int -_PyMem_SetupAllocators(PyMemAllocatorName allocator) -{ - switch (allocator) { - case PYMEM_ALLOCATOR_NOT_SET: - /* do nothing */ - break; - - case PYMEM_ALLOCATOR_DEFAULT: + nameions): use default memory allocators */ + *allocator = PYMEM_ALLOCATOR_DEFAULT; + } + else if (strcmp(name, "default") == 0) { + *allocator = PYMEM_ALLOCATOR_DEFAULT; + } + else if (strcmp(name, "debug") == 0) { + *allocator = PYMEM_ALLOCATOR_DEBUG; + } +#ifdef WITH_PYMALLOC + else if (strcmp(name, "pymalloc") == 0) { + *allocator = PYMEM_ALLOCATOR_PYMALLOC; + } + else if (strcmp(name, "pymalloc_debug") == 0) { + *allocator = PYMEM_ALLOCATOR_PYMALLOC_DEBUG; + } +#endif + else if (strcmp(name, "malloc") == 0) { + *allocator = PYMEM_ALLOCATOR_MALLOC; + } + else if (strcmp(name, "malloc_debug") == 0) { + *allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG; + } + else { + /* unknown allocator */ + return -1; + } + return 0; +} + + +int +_PyMem_SetupAllocators(PyMemAllocatorName allocator) +{ + switch (allocator) { + case PYMEM_ALLOCATOR_NOT_SET: + /* do nothing */ + break; + + case PYMEM_ALLOCATOR_DEFAULT: (void)_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, NULL); (void)_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_MEM, NULL); (void)_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_OBJ, NULL); - break; - - case PYMEM_ALLOCATOR_DEBUG: + break; + + case PYMEM_ALLOCATOR_DEBUG: (void)pymem_set_default_allocator(PYMEM_DOMAIN_RAW, 1, NULL); (void)pymem_set_default_allocator(PYMEM_DOMAIN_MEM, 1, NULL); (void)pymem_set_default_allocator(PYMEM_DOMAIN_OBJ, 1, NULL); - break; - + break; + #ifdef WITH_PYMALLOC - case PYMEM_ALLOCATOR_PYMALLOC: - case PYMEM_ALLOCATOR_PYMALLOC_DEBUG: - { + case PYMEM_ALLOCATOR_PYMALLOC: + case PYMEM_ALLOCATOR_PYMALLOC_DEBUG: + { PyMemAllocatorEx malloc_alloc = MALLOC_ALLOC; PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &malloc_alloc); @@ -334,28 +334,28 @@ _PyMem_SetupAllocators(PyMemAllocatorName allocator) PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &pymalloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &pymalloc); - if (allocator == PYMEM_ALLOCATOR_PYMALLOC_DEBUG) { + if (allocator == PYMEM_ALLOCATOR_PYMALLOC_DEBUG) { PyMem_SetupDebugHooks(); } - break; + break; } #endif - - case PYMEM_ALLOCATOR_MALLOC: - case PYMEM_ALLOCATOR_MALLOC_DEBUG: - { + + case PYMEM_ALLOCATOR_MALLOC: + case PYMEM_ALLOCATOR_MALLOC_DEBUG: + { PyMemAllocatorEx malloc_alloc = MALLOC_ALLOC; PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &malloc_alloc); PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &malloc_alloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &malloc_alloc); - if (allocator == PYMEM_ALLOCATOR_MALLOC_DEBUG) { + if (allocator == PYMEM_ALLOCATOR_MALLOC_DEBUG) { PyMem_SetupDebugHooks(); } - break; + break; } - - default: + + default: /* unknown allocator */ return -1; } @@ -371,7 +371,7 @@ pymemallocator_eq(PyMemAllocatorEx *a, PyMemAllocatorEx *b) const char* -_PyMem_GetCurrentAllocatorName(void) +_PyMem_GetCurrentAllocatorName(void) { PyMemAllocatorEx malloc_alloc = MALLOC_ALLOC; #ifdef WITH_PYMALLOC @@ -714,17 +714,17 @@ PyObject_Free(void *ptr) the valgrind checks */ #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) # define UNLIKELY(value) __builtin_expect((value), 0) -# define LIKELY(value) __builtin_expect((value), 1) +# define LIKELY(value) __builtin_expect((value), 1) #else # define UNLIKELY(value) (value) -# define LIKELY(value) (value) +# define LIKELY(value) (value) #endif -#ifdef WITH_PYMALLOC - -#ifdef WITH_VALGRIND -#include <valgrind/valgrind.h> - +#ifdef WITH_PYMALLOC + +#ifdef WITH_VALGRIND +#include <valgrind/valgrind.h> + /* -1 indicates that we haven't checked that we're running on valgrind yet. */ static int running_on_valgrind = -1; #endif @@ -836,20 +836,20 @@ static int running_on_valgrind = -1; /* * Alignment of addresses returned to the user. 8-bytes alignment works - * on most current architectures (with 32-bit or 64-bit address buses). + * on most current architectures (with 32-bit or 64-bit address buses). * The alignment value is also used for grouping small requests in size * classes spaced ALIGNMENT bytes apart. * * You shouldn't change this unless you know what you are doing. */ - -#if SIZEOF_VOID_P > 4 -#define ALIGNMENT 16 /* must be 2^N */ -#define ALIGNMENT_SHIFT 4 -#else + +#if SIZEOF_VOID_P > 4 +#define ALIGNMENT 16 /* must be 2^N */ +#define ALIGNMENT_SHIFT 4 +#else #define ALIGNMENT 8 /* must be 2^N */ #define ALIGNMENT_SHIFT 3 -#endif +#endif /* Return the number of bytes in size class I, as a uint. */ #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT) @@ -920,11 +920,11 @@ static int running_on_valgrind = -1; #define POOL_SIZE SYSTEM_PAGE_SIZE /* must be 2^N */ #define POOL_SIZE_MASK SYSTEM_PAGE_SIZE_MASK -#define MAX_POOLS_IN_ARENA (ARENA_SIZE / POOL_SIZE) -#if MAX_POOLS_IN_ARENA * POOL_SIZE != ARENA_SIZE -# error "arena size not an exact multiple of pool size" -#endif - +#define MAX_POOLS_IN_ARENA (ARENA_SIZE / POOL_SIZE) +#if MAX_POOLS_IN_ARENA * POOL_SIZE != ARENA_SIZE +# error "arena size not an exact multiple of pool size" +#endif + /* * -- End of tunable settings section -- */ @@ -1162,18 +1162,18 @@ usable_arenas Note that an arena_object associated with an arena all of whose pools are currently in use isn't on either list. - -Changed in Python 3.8: keeping usable_arenas sorted by number of free pools -used to be done by one-at-a-time linear search when an arena's number of -free pools changed. That could, overall, consume time quadratic in the -number of arenas. That didn't really matter when there were only a few -hundred arenas (typical!), but could be a timing disaster when there were -hundreds of thousands. See bpo-37029. - -Now we have a vector of "search fingers" to eliminate the need to search: -nfp2lasta[nfp] returns the last ("rightmost") arena in usable_arenas -with nfp free pools. This is NULL if and only if there is no arena with -nfp free pools in usable_arenas. + +Changed in Python 3.8: keeping usable_arenas sorted by number of free pools +used to be done by one-at-a-time linear search when an arena's number of +free pools changed. That could, overall, consume time quadratic in the +number of arenas. That didn't really matter when there were only a few +hundred arenas (typical!), but could be a timing disaster when there were +hundreds of thousands. See bpo-37029. + +Now we have a vector of "search fingers" to eliminate the need to search: +nfp2lasta[nfp] returns the last ("rightmost") arena in usable_arenas +with nfp free pools. This is NULL if and only if there is no arena with +nfp free pools in usable_arenas. */ /* Array of objects used to track chunks of memory (arenas). */ @@ -1191,9 +1191,9 @@ static struct arena_object* unused_arena_objects = NULL; */ static struct arena_object* usable_arenas = NULL; -/* nfp2lasta[nfp] is the last arena in usable_arenas with nfp free pools */ -static struct arena_object* nfp2lasta[MAX_POOLS_IN_ARENA + 1] = { NULL }; - +/* nfp2lasta[nfp] is the last arena in usable_arenas with nfp free pools */ +static struct arena_object* nfp2lasta[MAX_POOLS_IN_ARENA + 1] = { NULL }; + /* How many arena_objects do we initially allocate? * 16 = can allocate 16 arenas = 16 * ARENA_SIZE = 4MB before growing the * `arenas` vector. @@ -1208,29 +1208,29 @@ static size_t ntimes_arena_allocated = 0; /* High water mark (max value ever seen) for narenas_currently_allocated. */ static size_t narenas_highwater = 0; -static Py_ssize_t raw_allocated_blocks; +static Py_ssize_t raw_allocated_blocks; Py_ssize_t _Py_GetAllocatedBlocks(void) { - Py_ssize_t n = raw_allocated_blocks; - /* add up allocated blocks for used pools */ - for (uint i = 0; i < maxarenas; ++i) { - /* Skip arenas which are not allocated. */ - if (arenas[i].address == 0) { - continue; - } - - uintptr_t base = (uintptr_t)_Py_ALIGN_UP(arenas[i].address, POOL_SIZE); - - /* visit every pool in the arena */ - assert(base <= (uintptr_t) arenas[i].pool_address); - for (; base < (uintptr_t) arenas[i].pool_address; base += POOL_SIZE) { - poolp p = (poolp)base; - n += p->ref.count; - } - } - return n; + Py_ssize_t n = raw_allocated_blocks; + /* add up allocated blocks for used pools */ + for (uint i = 0; i < maxarenas; ++i) { + /* Skip arenas which are not allocated. */ + if (arenas[i].address == 0) { + continue; + } + + uintptr_t base = (uintptr_t)_Py_ALIGN_UP(arenas[i].address, POOL_SIZE); + + /* visit every pool in the arena */ + assert(base <= (uintptr_t) arenas[i].pool_address); + for (; base < (uintptr_t) arenas[i].pool_address; base += POOL_SIZE) { + poolp p = (poolp)base; + n += p->ref.count; + } + } + return n; } @@ -1320,7 +1320,7 @@ new_arena(void) /* pool_address <- first pool-aligned address in the arena nfreepools <- number of whole pools that fit after alignment */ arenaobj->pool_address = (block*)arenaobj->address; - arenaobj->nfreepools = MAX_POOLS_IN_ARENA; + arenaobj->nfreepools = MAX_POOLS_IN_ARENA; excess = (uint)(arenaobj->address & POOL_SIZE_MASK); if (excess != 0) { --arenaobj->nfreepools; @@ -1407,7 +1407,7 @@ obmalloc controls. Since this test is needed at every entry point, it's extremely desirable that it be this fast. */ -static bool _Py_NO_SANITIZE_ADDRESS +static bool _Py_NO_SANITIZE_ADDRESS _Py_NO_SANITIZE_THREAD _Py_NO_SANITIZE_MEMORY address_in_range(void *p, poolp pool) @@ -1426,76 +1426,76 @@ address_in_range(void *p, poolp pool) /*==========================================================================*/ -// Called when freelist is exhausted. Extend the freelist if there is -// space for a block. Otherwise, remove this pool from usedpools. -static void -pymalloc_pool_extend(poolp pool, uint size) -{ - if (UNLIKELY(pool->nextoffset <= pool->maxnextoffset)) { - /* There is room for another block. */ - pool->freeblock = (block*)pool + pool->nextoffset; - pool->nextoffset += INDEX2SIZE(size); - *(block **)(pool->freeblock) = NULL; - return; - } - - /* Pool is full, unlink from used pools. */ - poolp next; - next = pool->nextpool; - pool = pool->prevpool; - next->prevpool = pool; - pool->nextpool = next; -} - -/* called when pymalloc_alloc can not allocate a block from usedpool. - * This function takes new pool and allocate a block from it. - */ -static void* -allocate_from_new_pool(uint size) +// Called when freelist is exhausted. Extend the freelist if there is +// space for a block. Otherwise, remove this pool from usedpools. +static void +pymalloc_pool_extend(poolp pool, uint size) +{ + if (UNLIKELY(pool->nextoffset <= pool->maxnextoffset)) { + /* There is room for another block. */ + pool->freeblock = (block*)pool + pool->nextoffset; + pool->nextoffset += INDEX2SIZE(size); + *(block **)(pool->freeblock) = NULL; + return; + } + + /* Pool is full, unlink from used pools. */ + poolp next; + next = pool->nextpool; + pool = pool->prevpool; + next->prevpool = pool; + pool->nextpool = next; +} + +/* called when pymalloc_alloc can not allocate a block from usedpool. + * This function takes new pool and allocate a block from it. + */ +static void* +allocate_from_new_pool(uint size) { /* There isn't a pool of the right size class immediately * available: use a free pool. */ - if (UNLIKELY(usable_arenas == NULL)) { + if (UNLIKELY(usable_arenas == NULL)) { /* No arena has a free pool: allocate a new arena. */ #ifdef WITH_MEMORY_LIMITS if (narenas_currently_allocated >= MAX_ARENAS) { - return NULL; + return NULL; } #endif usable_arenas = new_arena(); if (usable_arenas == NULL) { - return NULL; + return NULL; } - usable_arenas->nextarena = usable_arenas->prevarena = NULL; - assert(nfp2lasta[usable_arenas->nfreepools] == NULL); - nfp2lasta[usable_arenas->nfreepools] = usable_arenas; + usable_arenas->nextarena = usable_arenas->prevarena = NULL; + assert(nfp2lasta[usable_arenas->nfreepools] == NULL); + nfp2lasta[usable_arenas->nfreepools] = usable_arenas; } assert(usable_arenas->address != 0); - /* This arena already had the smallest nfreepools value, so decreasing - * nfreepools doesn't change that, and we don't need to rearrange the - * usable_arenas list. However, if the arena becomes wholly allocated, - * we need to remove its arena_object from usable_arenas. - */ - assert(usable_arenas->nfreepools > 0); - if (nfp2lasta[usable_arenas->nfreepools] == usable_arenas) { - /* It's the last of this size, so there won't be any. */ - nfp2lasta[usable_arenas->nfreepools] = NULL; - } - /* If any free pools will remain, it will be the new smallest. */ - if (usable_arenas->nfreepools > 1) { - assert(nfp2lasta[usable_arenas->nfreepools - 1] == NULL); - nfp2lasta[usable_arenas->nfreepools - 1] = usable_arenas; - } - + /* This arena already had the smallest nfreepools value, so decreasing + * nfreepools doesn't change that, and we don't need to rearrange the + * usable_arenas list. However, if the arena becomes wholly allocated, + * we need to remove its arena_object from usable_arenas. + */ + assert(usable_arenas->nfreepools > 0); + if (nfp2lasta[usable_arenas->nfreepools] == usable_arenas) { + /* It's the last of this size, so there won't be any. */ + nfp2lasta[usable_arenas->nfreepools] = NULL; + } + /* If any free pools will remain, it will be the new smallest. */ + if (usable_arenas->nfreepools > 1) { + assert(nfp2lasta[usable_arenas->nfreepools - 1] == NULL); + nfp2lasta[usable_arenas->nfreepools - 1] = usable_arenas; + } + /* Try to get a cached free pool. */ - poolp pool = usable_arenas->freepools; - if (LIKELY(pool != NULL)) { + poolp pool = usable_arenas->freepools; + if (LIKELY(pool != NULL)) { /* Unlink from cached pools. */ usable_arenas->freepools = pool->nextpool; - usable_arenas->nfreepools--; - if (UNLIKELY(usable_arenas->nfreepools == 0)) { + usable_arenas->nfreepools--; + if (UNLIKELY(usable_arenas->nfreepools == 0)) { /* Wholly allocated: remove. */ assert(usable_arenas->freepools == NULL); assert(usable_arenas->nextarena == NULL || @@ -1518,133 +1518,133 @@ allocate_from_new_pool(uint size) (block*)usable_arenas->address + ARENA_SIZE - POOL_SIZE); } - } - else { - /* Carve off a new pool. */ - assert(usable_arenas->nfreepools > 0); - assert(usable_arenas->freepools == NULL); - pool = (poolp)usable_arenas->pool_address; - assert((block*)pool <= (block*)usable_arenas->address + - ARENA_SIZE - POOL_SIZE); - pool->arenaindex = (uint)(usable_arenas - arenas); - assert(&arenas[pool->arenaindex] == usable_arenas); - pool->szidx = DUMMY_SIZE_IDX; - usable_arenas->pool_address += POOL_SIZE; - --usable_arenas->nfreepools; - - if (usable_arenas->nfreepools == 0) { - assert(usable_arenas->nextarena == NULL || - usable_arenas->nextarena->prevarena == - usable_arenas); - /* Unlink the arena: it is completely allocated. */ - usable_arenas = usable_arenas->nextarena; - if (usable_arenas != NULL) { - usable_arenas->prevarena = NULL; - assert(usable_arenas->address != 0); - } + } + else { + /* Carve off a new pool. */ + assert(usable_arenas->nfreepools > 0); + assert(usable_arenas->freepools == NULL); + pool = (poolp)usable_arenas->pool_address; + assert((block*)pool <= (block*)usable_arenas->address + + ARENA_SIZE - POOL_SIZE); + pool->arenaindex = (uint)(usable_arenas - arenas); + assert(&arenas[pool->arenaindex] == usable_arenas); + pool->szidx = DUMMY_SIZE_IDX; + usable_arenas->pool_address += POOL_SIZE; + --usable_arenas->nfreepools; + + if (usable_arenas->nfreepools == 0) { + assert(usable_arenas->nextarena == NULL || + usable_arenas->nextarena->prevarena == + usable_arenas); + /* Unlink the arena: it is completely allocated. */ + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) { + usable_arenas->prevarena = NULL; + assert(usable_arenas->address != 0); + } } - } - - /* Frontlink to used pools. */ - block *bp; - poolp next = usedpools[size + size]; /* == prev */ - pool->nextpool = next; - pool->prevpool = next; - next->nextpool = pool; - next->prevpool = pool; - pool->ref.count = 1; - if (pool->szidx == size) { - /* Luckily, this pool last contained blocks - * of the same size class, so its header - * and free list are already initialized. + } + + /* Frontlink to used pools. */ + block *bp; + poolp next = usedpools[size + size]; /* == prev */ + pool->nextpool = next; + pool->prevpool = next; + next->nextpool = pool; + next->prevpool = pool; + pool->ref.count = 1; + if (pool->szidx == size) { + /* Luckily, this pool last contained blocks + * of the same size class, so its header + * and free list are already initialized. + */ + bp = pool->freeblock; + assert(bp != NULL); + pool->freeblock = *(block **)bp; + return bp; + } + /* + * Initialize the pool header, set up the free list to + * contain just the second block, and return the first + * block. + */ + pool->szidx = size; + size = INDEX2SIZE(size); + bp = (block *)pool + POOL_OVERHEAD; + pool->nextoffset = POOL_OVERHEAD + (size << 1); + pool->maxnextoffset = POOL_SIZE - size; + pool->freeblock = bp + size; + *(block **)(pool->freeblock) = NULL; + return bp; +} + +/* pymalloc allocator + + Return a pointer to newly allocated memory if pymalloc allocated memory. + + Return NULL if pymalloc failed to allocate the memory block: on bigger + requests, on error in the code below (as a last chance to serve the request) + or when the max memory limit has been reached. +*/ +static inline void* +pymalloc_alloc(void *ctx, size_t nbytes) +{ +#ifdef WITH_VALGRIND + if (UNLIKELY(running_on_valgrind == -1)) { + running_on_valgrind = RUNNING_ON_VALGRIND; + } + if (UNLIKELY(running_on_valgrind)) { + return NULL; + } +#endif + + if (UNLIKELY(nbytes == 0)) { + return NULL; + } + if (UNLIKELY(nbytes > SMALL_REQUEST_THRESHOLD)) { + return NULL; + } + + uint size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT; + poolp pool = usedpools[size + size]; + block *bp; + + if (LIKELY(pool != pool->nextpool)) { + /* + * There is a used pool for this size class. + * Pick up the head block of its free list. */ - bp = pool->freeblock; - assert(bp != NULL); - pool->freeblock = *(block **)bp; - return bp; - } - /* - * Initialize the pool header, set up the free list to - * contain just the second block, and return the first - * block. - */ - pool->szidx = size; - size = INDEX2SIZE(size); - bp = (block *)pool + POOL_OVERHEAD; - pool->nextoffset = POOL_OVERHEAD + (size << 1); - pool->maxnextoffset = POOL_SIZE - size; - pool->freeblock = bp + size; - *(block **)(pool->freeblock) = NULL; - return bp; -} - -/* pymalloc allocator - - Return a pointer to newly allocated memory if pymalloc allocated memory. - - Return NULL if pymalloc failed to allocate the memory block: on bigger - requests, on error in the code below (as a last chance to serve the request) - or when the max memory limit has been reached. -*/ -static inline void* -pymalloc_alloc(void *ctx, size_t nbytes) -{ -#ifdef WITH_VALGRIND - if (UNLIKELY(running_on_valgrind == -1)) { - running_on_valgrind = RUNNING_ON_VALGRIND; - } - if (UNLIKELY(running_on_valgrind)) { - return NULL; - } -#endif - - if (UNLIKELY(nbytes == 0)) { - return NULL; - } - if (UNLIKELY(nbytes > SMALL_REQUEST_THRESHOLD)) { - return NULL; - } - - uint size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT; - poolp pool = usedpools[size + size]; - block *bp; - - if (LIKELY(pool != pool->nextpool)) { - /* - * There is a used pool for this size class. - * Pick up the head block of its free list. - */ - ++pool->ref.count; - bp = pool->freeblock; - assert(bp != NULL); - - if (UNLIKELY((pool->freeblock = *(block **)bp) == NULL)) { - // Reached the end of the free list, try to extend it. - pymalloc_pool_extend(pool, size); + ++pool->ref.count; + bp = pool->freeblock; + assert(bp != NULL); + + if (UNLIKELY((pool->freeblock = *(block **)bp) == NULL)) { + // Reached the end of the free list, try to extend it. + pymalloc_pool_extend(pool, size); } } - else { - /* There isn't a pool of the right size class immediately - * available: use a free pool. - */ - bp = allocate_from_new_pool(size); - } + else { + /* There isn't a pool of the right size class immediately + * available: use a free pool. + */ + bp = allocate_from_new_pool(size); + } - return (void *)bp; + return (void *)bp; } static void * _PyObject_Malloc(void *ctx, size_t nbytes) { - void* ptr = pymalloc_alloc(ctx, nbytes); - if (LIKELY(ptr != NULL)) { + void* ptr = pymalloc_alloc(ctx, nbytes); + if (LIKELY(ptr != NULL)) { return ptr; } ptr = PyMem_RawMalloc(nbytes); if (ptr != NULL) { - raw_allocated_blocks++; + raw_allocated_blocks++; } return ptr; } @@ -1656,77 +1656,77 @@ _PyObject_Calloc(void *ctx, size_t nelem, size_t elsize) assert(elsize == 0 || nelem <= (size_t)PY_SSIZE_T_MAX / elsize); size_t nbytes = nelem * elsize; - void* ptr = pymalloc_alloc(ctx, nbytes); - if (LIKELY(ptr != NULL)) { + void* ptr = pymalloc_alloc(ctx, nbytes); + if (LIKELY(ptr != NULL)) { memset(ptr, 0, nbytes); return ptr; } ptr = PyMem_RawCalloc(nelem, elsize); if (ptr != NULL) { - raw_allocated_blocks++; + raw_allocated_blocks++; } return ptr; } -static void -insert_to_usedpool(poolp pool) +static void +insert_to_usedpool(poolp pool) { - assert(pool->ref.count > 0); /* else the pool is empty */ + assert(pool->ref.count > 0); /* else the pool is empty */ - uint size = pool->szidx; - poolp next = usedpools[size + size]; - poolp prev = next->prevpool; + uint size = pool->szidx; + poolp next = usedpools[size + size]; + poolp prev = next->prevpool; - /* insert pool before next: prev <-> pool <-> next */ - pool->nextpool = next; - pool->prevpool = prev; - next->prevpool = pool; - prev->nextpool = pool; -} + /* insert pool before next: prev <-> pool <-> next */ + pool->nextpool = next; + pool->prevpool = prev; + next->prevpool = pool; + prev->nextpool = pool; +} -static void -insert_to_freepool(poolp pool) -{ - poolp next = pool->nextpool; - poolp prev = pool->prevpool; +static void +insert_to_freepool(poolp pool) +{ + poolp next = pool->nextpool; + poolp prev = pool->prevpool; next->prevpool = prev; prev->nextpool = next; /* Link the pool to freepools. This is a singly-linked * list, and pool->prevpool isn't used there. */ - struct arena_object *ao = &arenas[pool->arenaindex]; + struct arena_object *ao = &arenas[pool->arenaindex]; pool->nextpool = ao->freepools; ao->freepools = pool; - uint nf = ao->nfreepools; - /* If this is the rightmost arena with this number of free pools, - * nfp2lasta[nf] needs to change. Caution: if nf is 0, there - * are no arenas in usable_arenas with that value. - */ - struct arena_object* lastnf = nfp2lasta[nf]; - assert((nf == 0 && lastnf == NULL) || - (nf > 0 && - lastnf != NULL && - lastnf->nfreepools == nf && - (lastnf->nextarena == NULL || - nf < lastnf->nextarena->nfreepools))); - if (lastnf == ao) { /* it is the rightmost */ - struct arena_object* p = ao->prevarena; - nfp2lasta[nf] = (p != NULL && p->nfreepools == nf) ? p : NULL; - } - ao->nfreepools = ++nf; + uint nf = ao->nfreepools; + /* If this is the rightmost arena with this number of free pools, + * nfp2lasta[nf] needs to change. Caution: if nf is 0, there + * are no arenas in usable_arenas with that value. + */ + struct arena_object* lastnf = nfp2lasta[nf]; + assert((nf == 0 && lastnf == NULL) || + (nf > 0 && + lastnf != NULL && + lastnf->nfreepools == nf && + (lastnf->nextarena == NULL || + nf < lastnf->nextarena->nfreepools))); + if (lastnf == ao) { /* it is the rightmost */ + struct arena_object* p = ao->prevarena; + nfp2lasta[nf] = (p != NULL && p->nfreepools == nf) ? p : NULL; + } + ao->nfreepools = ++nf; /* All the rest is arena management. We just freed * a pool, and there are 4 cases for arena mgmt: * 1. If all the pools are free, return the arena to - * the system free(). Except if this is the last - * arena in the list, keep it to avoid thrashing: - * keeping one wholly free arena in the list avoids - * pathological cases where a simple loop would - * otherwise provoke needing to allocate and free an - * arena on every iteration. See bpo-37257. + * the system free(). Except if this is the last + * arena in the list, keep it to avoid thrashing: + * keeping one wholly free arena in the list avoids + * pathological cases where a simple loop would + * otherwise provoke needing to allocate and free an + * arena on every iteration. See bpo-37257. * 2. If this is the only free pool in the arena, * add the arena back to the `usable_arenas` list. * 3. If the "next" arena has a smaller count of free @@ -1735,7 +1735,7 @@ insert_to_freepool(poolp pool) * nfreepools. * 4. Else there's nothing more to do. */ - if (nf == ao->ntotalpools && ao->nextarena != NULL) { + if (nf == ao->ntotalpools && ao->nextarena != NULL) { /* Case 1. First unlink ao from usable_arenas. */ assert(ao->prevarena == NULL || @@ -1774,7 +1774,7 @@ insert_to_freepool(poolp pool) ao->address = 0; /* mark unassociated */ --narenas_currently_allocated; - return; + return; } if (nf == 1) { @@ -1789,11 +1789,11 @@ insert_to_freepool(poolp pool) usable_arenas->prevarena = ao; usable_arenas = ao; assert(usable_arenas->address != 0); - if (nfp2lasta[1] == NULL) { - nfp2lasta[1] = ao; - } + if (nfp2lasta[1] == NULL) { + nfp2lasta[1] = ao; + } - return; + return; } /* If this arena is now out of order, we need to keep @@ -1803,23 +1803,23 @@ insert_to_freepool(poolp pool) * a few un-scientific tests, it seems like this * approach allowed a lot more memory to be freed. */ - /* If this is the only arena with nf, record that. */ - if (nfp2lasta[nf] == NULL) { - nfp2lasta[nf] = ao; - } /* else the rightmost with nf doesn't change */ - /* If this was the rightmost of the old size, it remains in place. */ - if (ao == lastnf) { + /* If this is the only arena with nf, record that. */ + if (nfp2lasta[nf] == NULL) { + nfp2lasta[nf] = ao; + } /* else the rightmost with nf doesn't change */ + /* If this was the rightmost of the old size, it remains in place. */ + if (ao == lastnf) { /* Case 4. Nothing to do. */ - return; - } - /* If ao were the only arena in the list, the last block would have - * gotten us out. - */ - assert(ao->nextarena != NULL); - - /* Case 3: We have to move the arena towards the end of the list, - * because it has more free pools than the arena to its right. It needs - * to move to follow lastnf. + return; + } + /* If ao were the only arena in the list, the last block would have + * gotten us out. + */ + assert(ao->nextarena != NULL); + + /* Case 3: We have to move the arena towards the end of the list, + * because it has more free pools than the arena to its right. It needs + * to move to follow lastnf. * First unlink ao from usable_arenas. */ if (ao->prevarena != NULL) { @@ -1833,78 +1833,78 @@ insert_to_freepool(poolp pool) usable_arenas = ao->nextarena; } ao->nextarena->prevarena = ao->prevarena; - /* And insert after lastnf. */ - ao->prevarena = lastnf; - ao->nextarena = lastnf->nextarena; + /* And insert after lastnf. */ + ao->prevarena = lastnf; + ao->nextarena = lastnf->nextarena; if (ao->nextarena != NULL) { ao->nextarena->prevarena = ao; } - lastnf->nextarena = ao; + lastnf->nextarena = ao; /* Verify that the swaps worked. */ assert(ao->nextarena == NULL || nf <= ao->nextarena->nfreepools); assert(ao->prevarena == NULL || nf > ao->prevarena->nfreepools); assert(ao->nextarena == NULL || ao->nextarena->prevarena == ao); assert((usable_arenas == ao && ao->prevarena == NULL) || ao->prevarena->nextarena == ao); -} - -/* Free a memory block allocated by pymalloc_alloc(). - Return 1 if it was freed. - Return 0 if the block was not allocated by pymalloc_alloc(). */ -static inline int -pymalloc_free(void *ctx, void *p) -{ - assert(p != NULL); - -#ifdef WITH_VALGRIND - if (UNLIKELY(running_on_valgrind > 0)) { - return 0; - } -#endif - - poolp pool = POOL_ADDR(p); - if (UNLIKELY(!address_in_range(p, pool))) { - return 0; - } - /* We allocated this address. */ - - /* Link p to the start of the pool's freeblock list. Since - * the pool had at least the p block outstanding, the pool - * wasn't empty (so it's already in a usedpools[] list, or - * was full and is in no list -- it's not in the freeblocks - * list in any case). - */ - assert(pool->ref.count > 0); /* else it was empty */ - block *lastfree = pool->freeblock; - *(block **)p = lastfree; - pool->freeblock = (block *)p; - pool->ref.count--; - - if (UNLIKELY(lastfree == NULL)) { - /* Pool was full, so doesn't currently live in any list: - * link it to the front of the appropriate usedpools[] list. - * This mimics LRU pool usage for new allocations and - * targets optimal filling when several pools contain - * blocks of the same size class. - */ - insert_to_usedpool(pool); - return 1; - } - - /* freeblock wasn't NULL, so the pool wasn't full, - * and the pool is in a usedpools[] list. - */ - if (LIKELY(pool->ref.count != 0)) { - /* pool isn't empty: leave it in usedpools */ - return 1; - } - - /* Pool is now empty: unlink from usedpools, and - * link to the front of freepools. This ensures that - * previously freed pools will be allocated later - * (being not referenced, they are perhaps paged out). - */ - insert_to_freepool(pool); +} + +/* Free a memory block allocated by pymalloc_alloc(). + Return 1 if it was freed. + Return 0 if the block was not allocated by pymalloc_alloc(). */ +static inline int +pymalloc_free(void *ctx, void *p) +{ + assert(p != NULL); + +#ifdef WITH_VALGRIND + if (UNLIKELY(running_on_valgrind > 0)) { + return 0; + } +#endif + + poolp pool = POOL_ADDR(p); + if (UNLIKELY(!address_in_range(p, pool))) { + return 0; + } + /* We allocated this address. */ + + /* Link p to the start of the pool's freeblock list. Since + * the pool had at least the p block outstanding, the pool + * wasn't empty (so it's already in a usedpools[] list, or + * was full and is in no list -- it's not in the freeblocks + * list in any case). + */ + assert(pool->ref.count > 0); /* else it was empty */ + block *lastfree = pool->freeblock; + *(block **)p = lastfree; + pool->freeblock = (block *)p; + pool->ref.count--; + + if (UNLIKELY(lastfree == NULL)) { + /* Pool was full, so doesn't currently live in any list: + * link it to the front of the appropriate usedpools[] list. + * This mimics LRU pool usage for new allocations and + * targets optimal filling when several pools contain + * blocks of the same size class. + */ + insert_to_usedpool(pool); + return 1; + } + + /* freeblock wasn't NULL, so the pool wasn't full, + * and the pool is in a usedpools[] list. + */ + if (LIKELY(pool->ref.count != 0)) { + /* pool isn't empty: leave it in usedpools */ + return 1; + } + + /* Pool is now empty: unlink from usedpools, and + * link to the front of freepools. This ensures that + * previously freed pools will be allocated later + * (being not referenced, they are perhaps paged out). + */ + insert_to_freepool(pool); return 1; } @@ -1917,10 +1917,10 @@ _PyObject_Free(void *ctx, void *p) return; } - if (UNLIKELY(!pymalloc_free(ctx, p))) { + if (UNLIKELY(!pymalloc_free(ctx, p))) { /* pymalloc didn't allocate this address */ PyMem_RawFree(p); - raw_allocated_blocks--; + raw_allocated_blocks--; } } @@ -2031,10 +2031,10 @@ _Py_GetAllocatedBlocks(void) * it wraps a real allocator, adding extra debugging info to the memory blocks. */ -/* Uncomment this define to add the "serialno" field */ -/* #define PYMEM_DEBUG_SERIALNO */ +/* Uncomment this define to add the "serialno" field */ +/* #define PYMEM_DEBUG_SERIALNO */ -#ifdef PYMEM_DEBUG_SERIALNO +#ifdef PYMEM_DEBUG_SERIALNO static size_t serialno = 0; /* incremented on each debug {m,re}alloc */ /* serialno is always incremented via calling this routine. The point is @@ -2045,16 +2045,16 @@ bumpserialno(void) { ++serialno; } -#endif +#endif #define SST SIZEOF_SIZE_T -#ifdef PYMEM_DEBUG_SERIALNO -# define PYMEM_DEBUG_EXTRA_BYTES 4 * SST -#else -# define PYMEM_DEBUG_EXTRA_BYTES 3 * SST -#endif - +#ifdef PYMEM_DEBUG_SERIALNO +# define PYMEM_DEBUG_EXTRA_BYTES 4 * SST +#else +# define PYMEM_DEBUG_EXTRA_BYTES 3 * SST +#endif + /* Read sizeof(size_t) bytes at p as a big-endian size_t. */ static size_t read_size_t(const void *p) @@ -2083,7 +2083,7 @@ write_size_t(void *p, size_t n) } } -/* Let S = sizeof(size_t). The debug malloc asks for 4 * S extra bytes and +/* Let S = sizeof(size_t). The debug malloc asks for 4 * S extra bytes and fills them with useful stuff, here calling the underlying malloc's result p: p[0: S] @@ -2092,14 +2092,14 @@ p[0: S] p[S] API ID. See PEP 445. This is a character, but seems undocumented. p[S+1: 2*S] - Copies of PYMEM_FORBIDDENBYTE. Used to catch under- writes and reads. + Copies of PYMEM_FORBIDDENBYTE. Used to catch under- writes and reads. p[2*S: 2*S+n] - The requested memory, filled with copies of PYMEM_CLEANBYTE. + The requested memory, filled with copies of PYMEM_CLEANBYTE. Used to catch reference to uninitialized memory. &p[2*S] is returned. Note that this is 8-byte aligned if pymalloc handled the request itself. p[2*S+n: 2*S+n+S] - Copies of PYMEM_FORBIDDENBYTE. Used to catch over- writes and reads. + Copies of PYMEM_FORBIDDENBYTE. Used to catch over- writes and reads. p[2*S+n+S: 2*S+n+2*S] A serial number, incremented by 1 on each call to _PyMem_DebugMalloc and _PyMem_DebugRealloc. @@ -2107,9 +2107,9 @@ p[2*S+n+S: 2*S+n+2*S] If "bad memory" is detected later, the serial number gives an excellent way to set a breakpoint on the next run, to capture the instant at which this block was passed out. - -If PYMEM_DEBUG_SERIALNO is not defined (default), the debug malloc only asks -for 3 * S extra bytes, and omits the last serialno field. + +If PYMEM_DEBUG_SERIALNO is not defined (default), the debug malloc only asks +for 3 * S extra bytes, and omits the last serialno field. */ static void * @@ -2119,25 +2119,25 @@ _PyMem_DebugRawAlloc(int use_calloc, void *ctx, size_t nbytes) uint8_t *p; /* base address of malloc'ed pad block */ uint8_t *data; /* p + 2*SST == pointer to data bytes */ uint8_t *tail; /* data + nbytes == pointer to tail pad bytes */ - size_t total; /* nbytes + PYMEM_DEBUG_EXTRA_BYTES */ + size_t total; /* nbytes + PYMEM_DEBUG_EXTRA_BYTES */ - if (nbytes > (size_t)PY_SSIZE_T_MAX - PYMEM_DEBUG_EXTRA_BYTES) { + if (nbytes > (size_t)PY_SSIZE_T_MAX - PYMEM_DEBUG_EXTRA_BYTES) { /* integer overflow: can't represent total as a Py_ssize_t */ return NULL; } - total = nbytes + PYMEM_DEBUG_EXTRA_BYTES; + total = nbytes + PYMEM_DEBUG_EXTRA_BYTES; /* Layout: [SSSS IFFF CCCC...CCCC FFFF NNNN] - ^--- p ^--- data ^--- tail + ^--- p ^--- data ^--- tail S: nbytes stored as size_t I: API identifier (1 byte) F: Forbidden bytes (size_t - 1 bytes before, size_t bytes after) C: Clean bytes used later to store actual data - N: Serial number stored as size_t + N: Serial number stored as size_t + + If PYMEM_DEBUG_SERIALNO is not defined (default), the last NNNN field + is omitted. */ - If PYMEM_DEBUG_SERIALNO is not defined (default), the last NNNN field - is omitted. */ - if (use_calloc) { p = (uint8_t *)api->alloc.calloc(api->alloc.ctx, 1, total); } @@ -2149,25 +2149,25 @@ _PyMem_DebugRawAlloc(int use_calloc, void *ctx, size_t nbytes) } data = p + 2*SST; -#ifdef PYMEM_DEBUG_SERIALNO +#ifdef PYMEM_DEBUG_SERIALNO bumpserialno(); -#endif +#endif /* at p, write size (SST bytes), id (1 byte), pad (SST-1 bytes) */ write_size_t(p, nbytes); p[SST] = (uint8_t)api->api_id; - memset(p + SST + 1, PYMEM_FORBIDDENBYTE, SST-1); + memset(p + SST + 1, PYMEM_FORBIDDENBYTE, SST-1); if (nbytes > 0 && !use_calloc) { - memset(data, PYMEM_CLEANBYTE, nbytes); + memset(data, PYMEM_CLEANBYTE, nbytes); } /* at tail, write pad (SST bytes) and serialno (SST bytes) */ tail = data + nbytes; - memset(tail, PYMEM_FORBIDDENBYTE, SST); -#ifdef PYMEM_DEBUG_SERIALNO + memset(tail, PYMEM_FORBIDDENBYTE, SST); +#ifdef PYMEM_DEBUG_SERIALNO write_size_t(tail + SST, serialno); -#endif +#endif return data; } @@ -2190,7 +2190,7 @@ _PyMem_DebugRawCalloc(void *ctx, size_t nelem, size_t elsize) /* The debug free first checks the 2*SST bytes on each end for sanity (in particular, that the FORBIDDENBYTEs with the api ID are still intact). - Then fills the original bytes with PYMEM_DEADBYTE. + Then fills the original bytes with PYMEM_DEADBYTE. Then calls the underlying free. */ static void @@ -2205,10 +2205,10 @@ _PyMem_DebugRawFree(void *ctx, void *p) uint8_t *q = (uint8_t *)p - 2*SST; /* address returned from malloc */ size_t nbytes; - _PyMem_DebugCheckAddress(__func__, api->api_id, p); + _PyMem_DebugCheckAddress(__func__, api->api_id, p); nbytes = read_size_t(q); - nbytes += PYMEM_DEBUG_EXTRA_BYTES; - memset(q, PYMEM_DEADBYTE, nbytes); + nbytes += PYMEM_DEBUG_EXTRA_BYTES; + memset(q, PYMEM_DEADBYTE, nbytes); api->alloc.free(api->alloc.ctx, q); } @@ -2230,62 +2230,62 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) #define ERASED_SIZE 64 uint8_t save[2*ERASED_SIZE]; /* A copy of erased bytes. */ - _PyMem_DebugCheckAddress(__func__, api->api_id, p); + _PyMem_DebugCheckAddress(__func__, api->api_id, p); data = (uint8_t *)p; head = data - 2*SST; original_nbytes = read_size_t(head); - if (nbytes > (size_t)PY_SSIZE_T_MAX - PYMEM_DEBUG_EXTRA_BYTES) { + if (nbytes > (size_t)PY_SSIZE_T_MAX - PYMEM_DEBUG_EXTRA_BYTES) { /* integer overflow: can't represent total as a Py_ssize_t */ return NULL; } - total = nbytes + PYMEM_DEBUG_EXTRA_BYTES; + total = nbytes + PYMEM_DEBUG_EXTRA_BYTES; tail = data + original_nbytes; -#ifdef PYMEM_DEBUG_SERIALNO - size_t block_serialno = read_size_t(tail + SST); -#endif +#ifdef PYMEM_DEBUG_SERIALNO + size_t block_serialno = read_size_t(tail + SST); +#endif /* Mark the header, the trailer, ERASED_SIZE bytes at the begin and ERASED_SIZE bytes at the end as dead and save the copy of erased bytes. */ if (original_nbytes <= sizeof(save)) { memcpy(save, data, original_nbytes); - memset(data - 2 * SST, PYMEM_DEADBYTE, - original_nbytes + PYMEM_DEBUG_EXTRA_BYTES); + memset(data - 2 * SST, PYMEM_DEADBYTE, + original_nbytes + PYMEM_DEBUG_EXTRA_BYTES); } else { memcpy(save, data, ERASED_SIZE); - memset(head, PYMEM_DEADBYTE, ERASED_SIZE + 2 * SST); + memset(head, PYMEM_DEADBYTE, ERASED_SIZE + 2 * SST); memcpy(&save[ERASED_SIZE], tail - ERASED_SIZE, ERASED_SIZE); - memset(tail - ERASED_SIZE, PYMEM_DEADBYTE, - ERASED_SIZE + PYMEM_DEBUG_EXTRA_BYTES - 2 * SST); + memset(tail - ERASED_SIZE, PYMEM_DEADBYTE, + ERASED_SIZE + PYMEM_DEBUG_EXTRA_BYTES - 2 * SST); } /* Resize and add decorations. */ r = (uint8_t *)api->alloc.realloc(api->alloc.ctx, head, total); if (r == NULL) { - /* if realloc() failed: rewrite header and footer which have - just been erased */ + /* if realloc() failed: rewrite header and footer which have + just been erased */ nbytes = original_nbytes; } else { head = r; -#ifdef PYMEM_DEBUG_SERIALNO +#ifdef PYMEM_DEBUG_SERIALNO bumpserialno(); block_serialno = serialno; -#endif +#endif } - data = head + 2*SST; + data = head + 2*SST; write_size_t(head, nbytes); head[SST] = (uint8_t)api->api_id; - memset(head + SST + 1, PYMEM_FORBIDDENBYTE, SST-1); + memset(head + SST + 1, PYMEM_FORBIDDENBYTE, SST-1); tail = data + nbytes; - memset(tail, PYMEM_FORBIDDENBYTE, SST); -#ifdef PYMEM_DEBUG_SERIALNO + memset(tail, PYMEM_FORBIDDENBYTE, SST); +#ifdef PYMEM_DEBUG_SERIALNO write_size_t(tail + SST, block_serialno); -#endif +#endif /* Restore saved bytes. */ if (original_nbytes <= sizeof(save)) { @@ -2305,35 +2305,35 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) } if (nbytes > original_nbytes) { - /* growing: mark new extra memory clean */ - memset(data + original_nbytes, PYMEM_CLEANBYTE, - nbytes - original_nbytes); + /* growing: mark new extra memory clean */ + memset(data + original_nbytes, PYMEM_CLEANBYTE, + nbytes - original_nbytes); } return data; } -static inline void -_PyMem_DebugCheckGIL(const char *func) +static inline void +_PyMem_DebugCheckGIL(const char *func) { - if (!PyGILState_Check()) { - _Py_FatalErrorFunc(func, - "Python memory allocator called " - "without holding the GIL"); - } + if (!PyGILState_Check()) { + _Py_FatalErrorFunc(func, + "Python memory allocator called " + "without holding the GIL"); + } } static void * _PyMem_DebugMalloc(void *ctx, size_t nbytes) { - _PyMem_DebugCheckGIL(__func__); + _PyMem_DebugCheckGIL(__func__); return _PyMem_DebugRawMalloc(ctx, nbytes); } static void * _PyMem_DebugCalloc(void *ctx, size_t nelem, size_t elsize) { - _PyMem_DebugCheckGIL(__func__); + _PyMem_DebugCheckGIL(__func__); return _PyMem_DebugRawCalloc(ctx, nelem, elsize); } @@ -2341,7 +2341,7 @@ _PyMem_DebugCalloc(void *ctx, size_t nelem, size_t elsize) static void _PyMem_DebugFree(void *ctx, void *ptr) { - _PyMem_DebugCheckGIL(__func__); + _PyMem_DebugCheckGIL(__func__); _PyMem_DebugRawFree(ctx, ptr); } @@ -2349,7 +2349,7 @@ _PyMem_DebugFree(void *ctx, void *ptr) static void * _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes) { - _PyMem_DebugCheckGIL(__func__); + _PyMem_DebugCheckGIL(__func__); return _PyMem_DebugRawRealloc(ctx, ptr, nbytes); } @@ -2359,10 +2359,10 @@ _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes) * The API id, is also checked. */ static void -_PyMem_DebugCheckAddress(const char *func, char api, const void *p) +_PyMem_DebugCheckAddress(const char *func, char api, const void *p) { - assert(p != NULL); - + assert(p != NULL); + const uint8_t *q = (const uint8_t *)p; size_t nbytes; const uint8_t *tail; @@ -2372,11 +2372,11 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p) /* Check the API id */ id = (char)q[-SST]; if (id != api) { - _PyObject_DebugDumpAddress(p); - _Py_FatalErrorFormat(func, - "bad ID: Allocated using API '%c', " - "verified using API '%c'", - id, api); + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFormat(func, + "bad ID: Allocated using API '%c', " + "verified using API '%c'", + id, api); } /* Check the stuff at the start of p first: if there's underwrite @@ -2384,18 +2384,18 @@ _PyMem_DebugCheckAddress(const char *func, char api, const void *p) * the tail could lead to a segfault then. */ for (i = SST-1; i >= 1; --i) { - if (*(q-i) != PYMEM_FORBIDDENBYTE) { - _PyObject_DebugDumpAddress(p); - _Py_FatalErrorFunc(func, "bad leading pad byte"); + if (*(q-i) != PYMEM_FORBIDDENBYTE) { + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFunc(func, "bad leading pad byte"); } } nbytes = read_size_t(q - 2*SST); tail = q + nbytes; for (i = 0; i < SST; ++i) { - if (tail[i] != PYMEM_FORBIDDENBYTE) { - _PyObject_DebugDumpAddress(p); - _Py_FatalErrorFunc(func, "bad trailing pad byte"); + if (tail[i] != PYMEM_FORBIDDENBYTE) { + _PyObject_DebugDumpAddress(p); + _Py_FatalErrorFunc(func, "bad trailing pad byte"); } } } @@ -2406,7 +2406,7 @@ _PyObject_DebugDumpAddress(const void *p) { const uint8_t *q = (const uint8_t *)p; const uint8_t *tail; - size_t nbytes; + size_t nbytes; int i; int ok; char id; @@ -2427,7 +2427,7 @@ _PyObject_DebugDumpAddress(const void *p) fprintf(stderr, " The %d pad bytes at p-%d are ", SST-1, SST-1); ok = 1; for (i = 1; i <= SST-1; ++i) { - if (*(q-i) != PYMEM_FORBIDDENBYTE) { + if (*(q-i) != PYMEM_FORBIDDENBYTE) { ok = 0; break; } @@ -2436,11 +2436,11 @@ _PyObject_DebugDumpAddress(const void *p) fputs("FORBIDDENBYTE, as expected.\n", stderr); else { fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", - PYMEM_FORBIDDENBYTE); + PYMEM_FORBIDDENBYTE); for (i = SST-1; i >= 1; --i) { const uint8_t byte = *(q-i); fprintf(stderr, " at p-%d: 0x%02x", i, byte); - if (byte != PYMEM_FORBIDDENBYTE) + if (byte != PYMEM_FORBIDDENBYTE) fputs(" *** OUCH", stderr); fputc('\n', stderr); } @@ -2452,10 +2452,10 @@ _PyObject_DebugDumpAddress(const void *p) } tail = q + nbytes; - fprintf(stderr, " The %d pad bytes at tail=%p are ", SST, (void *)tail); + fprintf(stderr, " The %d pad bytes at tail=%p are ", SST, (void *)tail); ok = 1; for (i = 0; i < SST; ++i) { - if (tail[i] != PYMEM_FORBIDDENBYTE) { + if (tail[i] != PYMEM_FORBIDDENBYTE) { ok = 0; break; } @@ -2464,22 +2464,22 @@ _PyObject_DebugDumpAddress(const void *p) fputs("FORBIDDENBYTE, as expected.\n", stderr); else { fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", - PYMEM_FORBIDDENBYTE); + PYMEM_FORBIDDENBYTE); for (i = 0; i < SST; ++i) { const uint8_t byte = tail[i]; fprintf(stderr, " at tail+%d: 0x%02x", i, byte); - if (byte != PYMEM_FORBIDDENBYTE) + if (byte != PYMEM_FORBIDDENBYTE) fputs(" *** OUCH", stderr); fputc('\n', stderr); } } -#ifdef PYMEM_DEBUG_SERIALNO - size_t serial = read_size_t(tail + SST); +#ifdef PYMEM_DEBUG_SERIALNO + size_t serial = read_size_t(tail + SST); fprintf(stderr, " The block was made by call #%" PY_FORMAT_SIZE_T "u to debug malloc/realloc.\n", serial); -#endif +#endif if (nbytes > 0) { i = 0; @@ -2705,11 +2705,11 @@ _PyObject_DebugMallocStats(FILE *out) quantization += p * ((POOL_SIZE - POOL_OVERHEAD) % size); } fputc('\n', out); -#ifdef PYMEM_DEBUG_SERIALNO - if (_PyMem_DebugEnabled()) { +#ifdef PYMEM_DEBUG_SERIALNO + if (_PyMem_DebugEnabled()) { (void)printone(out, "# times object malloc called", serialno); - } -#endif + } +#endif (void)printone(out, "# arenas allocated total", ntimes_arena_allocated); (void)printone(out, "# arenas reclaimed", ntimes_arena_allocated - narenas); (void)printone(out, "# arenas highwater mark", narenas_highwater); diff --git a/contrib/tools/python3/src/Objects/odictobject.c b/contrib/tools/python3/src/Objects/odictobject.c index f7afabbea0..f3980aba93 100644 --- a/contrib/tools/python3/src/Objects/odictobject.c +++ b/contrib/tools/python3/src/Objects/odictobject.c @@ -465,8 +465,8 @@ later: */ #include "Python.h" -#include "pycore_object.h" -#include <stddef.h> // offsetof() +#include "pycore_object.h" +#include <stddef.h> // offsetof() #include "dict-common.h" #include <stddef.h> @@ -525,8 +525,8 @@ struct _odictnode { #define _odict_FOREACH(od, node) \ for (node = _odict_FIRST(od); node != NULL; node = _odictnode_NEXT(node)) -_Py_IDENTIFIER(items); - +_Py_IDENTIFIER(items); + /* Return the index into the hash table, regardless of a valid node. */ static Py_ssize_t _odict_get_index_raw(PyODictObject *od, PyObject *key, Py_hash_t hash) @@ -851,57 +851,57 @@ static PyMappingMethods odict_as_mapping = { /* ---------------------------------------------- - * OrderedDict number methods - */ - -static int mutablemapping_update_arg(PyObject*, PyObject*); - -static PyObject * -odict_or(PyObject *left, PyObject *right) -{ - PyTypeObject *type; - PyObject *other; - if (PyODict_Check(left)) { - type = Py_TYPE(left); - other = right; - } - else { - type = Py_TYPE(right); - other = left; - } - if (!PyDict_Check(other)) { - Py_RETURN_NOTIMPLEMENTED; - } - PyObject *new = PyObject_CallOneArg((PyObject*)type, left); - if (!new) { - return NULL; - } - if (mutablemapping_update_arg(new, right) < 0) { - Py_DECREF(new); - return NULL; - } - return new; -} - -static PyObject * -odict_inplace_or(PyObject *self, PyObject *other) -{ - if (mutablemapping_update_arg(self, other) < 0) { - return NULL; - } - Py_INCREF(self); - return self; -} - -/* tp_as_number */ - -static PyNumberMethods odict_as_number = { - .nb_or = odict_or, - .nb_inplace_or = odict_inplace_or, -}; - - -/* ---------------------------------------------- + * OrderedDict number methods + */ + +static int mutablemapping_update_arg(PyObject*, PyObject*); + +static PyObject * +odict_or(PyObject *left, PyObject *right) +{ + PyTypeObject *type; + PyObject *other; + if (PyODict_Check(left)) { + type = Py_TYPE(left); + other = right; + } + else { + type = Py_TYPE(right); + other = left; + } + if (!PyDict_Check(other)) { + Py_RETURN_NOTIMPLEMENTED; + } + PyObject *new = PyObject_CallOneArg((PyObject*)type, left); + if (!new) { + return NULL; + } + if (mutablemapping_update_arg(new, right) < 0) { + Py_DECREF(new); + return NULL; + } + return new; +} + +static PyObject * +odict_inplace_or(PyObject *self, PyObject *other) +{ + if (mutablemapping_update_arg(self, other) < 0) { + return NULL; + } + Py_INCREF(self); + return self; +} + +/* tp_as_number */ + +static PyNumberMethods odict_as_number = { + .nb_or = odict_or, + .nb_inplace_or = odict_inplace_or, +}; + + +/* ---------------------------------------------- * OrderedDict methods */ @@ -930,7 +930,7 @@ OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value) PyDoc_STRVAR(odict_sizeof__doc__, ""); static PyObject * -odict_sizeof(PyODictObject *od, PyObject *Py_UNUSED(ignored)) +odict_sizeof(PyODictObject *od, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res = _PyDict_SizeOf((PyDictObject *)od); res += sizeof(_ODictNode *) * od->od_fast_nodes_size; /* od_fast_nodes */ @@ -945,7 +945,7 @@ odict_sizeof(PyODictObject *od, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(odict_reduce__doc__, "Return state information for pickling"); static PyObject * -odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) +odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(__dict__); PyObject *dict = NULL, *result = NULL; @@ -971,7 +971,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) if (args == NULL) goto Done; - items = _PyObject_CallMethodIdNoArgs((PyObject *)od, &PyId_items); + items = _PyObject_CallMethodIdNoArgs((PyObject *)od, &PyId_items); if (items == NULL) goto Done; @@ -1188,21 +1188,21 @@ OrderedDict_popitem_impl(PyODictObject *self, int last) /* MutableMapping.keys() does not have a docstring. */ PyDoc_STRVAR(odict_keys__doc__, ""); -static PyObject * odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ +static PyObject * odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* values() */ /* MutableMapping.values() does not have a docstring. */ PyDoc_STRVAR(odict_values__doc__, ""); -static PyObject * odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ +static PyObject * odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* items() */ /* MutableMapping.items() does not have a docstring. */ PyDoc_STRVAR(odict_items__doc__, ""); -static PyObject * odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ +static PyObject * odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* update() */ @@ -1236,7 +1236,7 @@ static int _PyODict_SetItem_KnownHash(PyObject *, PyObject *, PyObject *, PyDoc_STRVAR(odict_copy__doc__, "od.copy() -> a shallow copy of od"); static PyObject * -odict_copy(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) +odict_copy(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { _ODictNode *node; PyObject *od_copy; @@ -1290,13 +1290,13 @@ PyDoc_STRVAR(odict_reversed__doc__, "od.__reversed__() <==> reversed(od)"); #define _odict_ITER_REVERSED 1 #define _odict_ITER_KEYS 2 #define _odict_ITER_VALUES 4 -#define _odict_ITER_ITEMS (_odict_ITER_KEYS|_odict_ITER_VALUES) +#define _odict_ITER_ITEMS (_odict_ITER_KEYS|_odict_ITER_VALUES) /* forward */ static PyObject * odictiter_new(PyODictObject *, int); static PyObject * -odict_reversed(PyODictObject *od, PyObject *Py_UNUSED(ignored)) +odict_reversed(PyODictObject *od, PyObject *Py_UNUSED(ignored)) { return odictiter_new(od, _odict_ITER_KEYS|_odict_ITER_REVERSED); } @@ -1363,16 +1363,16 @@ static PyMethodDef odict_methods[] = { {"__reduce__", (PyCFunction)odict_reduce, METH_NOARGS, odict_reduce__doc__}, ORDEREDDICT_SETDEFAULT_METHODDEF - {"pop", (PyCFunction)(void(*)(void))odict_pop, + {"pop", (PyCFunction)(void(*)(void))odict_pop, METH_VARARGS | METH_KEYWORDS, odict_pop__doc__}, ORDEREDDICT_POPITEM_METHODDEF - {"keys", odictkeys_new, METH_NOARGS, + {"keys", odictkeys_new, METH_NOARGS, odict_keys__doc__}, - {"values", odictvalues_new, METH_NOARGS, + {"values", odictvalues_new, METH_NOARGS, odict_values__doc__}, - {"items", odictitems_new, METH_NOARGS, + {"items", odictitems_new, METH_NOARGS, odict_items__doc__}, - {"update", (PyCFunction)(void(*)(void))odict_update, METH_VARARGS | METH_KEYWORDS, + {"update", (PyCFunction)(void(*)(void))odict_update, METH_VARARGS | METH_KEYWORDS, odict_update__doc__}, {"clear", (PyCFunction)odict_clear, METH_NOARGS, odict_clear__doc__}, @@ -1409,7 +1409,7 @@ static void odict_dealloc(PyODictObject *self) { PyObject_GC_UnTrack(self); - Py_TRASHCAN_BEGIN(self, odict_dealloc) + Py_TRASHCAN_BEGIN(self, odict_dealloc) Py_XDECREF(self->od_inst_dict); if (self->od_weakreflist != NULL) @@ -1418,7 +1418,7 @@ odict_dealloc(PyODictObject *self) _odict_clear_nodes(self); PyDict_Type.tp_dealloc((PyObject *)self); - Py_TRASHCAN_END + Py_TRASHCAN_END } /* tp_repr */ @@ -1468,13 +1468,13 @@ odict_repr(PyODictObject *self) } count++; } - if (count < PyList_GET_SIZE(pieces)) { - Py_SET_SIZE(pieces, count); - } + if (count < PyList_GET_SIZE(pieces)) { + Py_SET_SIZE(pieces, count); + } } else { - PyObject *items = _PyObject_CallMethodIdNoArgs((PyObject *)self, - &PyId_items); + PyObject *items = _PyObject_CallMethodIdNoArgs((PyObject *)self, + &PyId_items); if (items == NULL) goto Done; pieces = PySequence_List(items); @@ -1578,7 +1578,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds) if (len == -1) return -1; if (len > 1) { - const char *msg = "expected at most 1 arguments, got %zd"; + const char *msg = "expected at most 1 arguments, got %zd"; PyErr_Format(PyExc_TypeError, msg, len); return -1; } @@ -1601,12 +1601,12 @@ PyTypeObject PyODict_Type = { sizeof(PyODictObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)odict_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)odict_repr, /* tp_repr */ - &odict_as_number, /* tp_as_number */ + &odict_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ &odict_as_mapping, /* tp_as_mapping */ 0, /* tp_hash */ @@ -1709,7 +1709,7 @@ odictiter_dealloc(odictiterobject *di) _PyObject_GC_UNTRACK(di); Py_XDECREF(di->di_odict); Py_XDECREF(di->di_current); - if ((di->kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { + if ((di->kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { Py_DECREF(di->di_result); } PyObject_GC_Del(di); @@ -1818,11 +1818,11 @@ odictiter_iternext(odictiterobject *di) Py_INCREF(result); Py_DECREF(PyTuple_GET_ITEM(result, 0)); /* borrowed */ Py_DECREF(PyTuple_GET_ITEM(result, 1)); /* borrowed */ - // 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); - } + // 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); + } } else { result = PyTuple_New(2); @@ -1850,7 +1850,7 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling"); static PyObject * odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); /* copy the iterator state */ odictiterobject tmp = *di; Py_XINCREF(tmp.di_odict); @@ -1863,7 +1863,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); } static PyMethodDef odictiter_methods[] = { @@ -1878,10 +1878,10 @@ PyTypeObject PyODictIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)odictiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1915,16 +1915,16 @@ odictiter_new(PyODictObject *od, int kind) if (di == NULL) return NULL; - if ((kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { + if ((kind & _odict_ITER_ITEMS) == _odict_ITER_ITEMS) { di->di_result = PyTuple_Pack(2, Py_None, Py_None); if (di->di_result == NULL) { Py_DECREF(di); return NULL; } } - else { + else { di->di_result = NULL; - } + } di->kind = kind; node = reversed ? _odict_LAST(od) : _odict_FIRST(od); @@ -1952,7 +1952,7 @@ odictkeys_iter(_PyDictViewObject *dv) } static PyObject * -odictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +odictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -1972,10 +1972,10 @@ PyTypeObject PyODictKeys_Type = { 0, /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -2001,7 +2001,7 @@ PyTypeObject PyODictKeys_Type = { }; static PyObject * -odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)) +odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictKeys_Type); } @@ -2019,7 +2019,7 @@ odictitems_iter(_PyDictViewObject *dv) } static PyObject * -odictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +odictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -2039,10 +2039,10 @@ PyTypeObject PyODictItems_Type = { 0, /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -2068,7 +2068,7 @@ PyTypeObject PyODictItems_Type = { }; static PyObject * -odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)) +odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictItems_Type); } @@ -2086,7 +2086,7 @@ odictvalues_iter(_PyDictViewObject *dv) } static PyObject * -odictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) +odictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -2106,10 +2106,10 @@ PyTypeObject PyODictValues_Type = { 0, /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -2135,7 +2135,7 @@ PyTypeObject PyODictValues_Type = { }; static PyObject * -odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)) +odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictValues_Type); } @@ -2246,79 +2246,79 @@ Done: return 0; } -static int -mutablemapping_update_arg(PyObject *self, PyObject *arg) +static int +mutablemapping_update_arg(PyObject *self, PyObject *arg) { int res = 0; - if (PyDict_CheckExact(arg)) { - PyObject *items = PyDict_Items(arg); - if (items == NULL) { - return -1; - } - res = mutablemapping_add_pairs(self, items); - Py_DECREF(items); - return res; - } + if (PyDict_CheckExact(arg)) { + PyObject *items = PyDict_Items(arg); + if (items == NULL) { + return -1; + } + res = mutablemapping_add_pairs(self, items); + Py_DECREF(items); + return res; + } _Py_IDENTIFIER(keys); - PyObject *func; - if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { - return -1; - } - if (func != NULL) { - PyObject *keys = _PyObject_CallNoArg(func); - Py_DECREF(func); - if (keys == NULL) { - return -1; - } - PyObject *iterator = PyObject_GetIter(keys); - Py_DECREF(keys); - if (iterator == NULL) { - return -1; - } - PyObject *key; - while (res == 0 && (key = PyIter_Next(iterator))) { - PyObject *value = PyObject_GetItem(arg, key); - if (value != NULL) { - res = PyObject_SetItem(self, key, value); - Py_DECREF(value); - } - else { - res = -1; - } - Py_DECREF(key); - } - Py_DECREF(iterator); - if (res != 0 || PyErr_Occurred()) { - return -1; - } - return 0; - } - if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) { - return -1; - } - if (func != NULL) { - PyObject *items = _PyObject_CallNoArg(func); - Py_DECREF(func); - if (items == NULL) { - return -1; - } - res = mutablemapping_add_pairs(self, items); - Py_DECREF(items); - return res; - } - res = mutablemapping_add_pairs(self, arg); - return res; -} - -static PyObject * -mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) -{ - int res; + PyObject *func; + if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { + return -1; + } + if (func != NULL) { + PyObject *keys = _PyObject_CallNoArg(func); + Py_DECREF(func); + if (keys == NULL) { + return -1; + } + PyObject *iterator = PyObject_GetIter(keys); + Py_DECREF(keys); + if (iterator == NULL) { + return -1; + } + PyObject *key; + while (res == 0 && (key = PyIter_Next(iterator))) { + PyObject *value = PyObject_GetItem(arg, key); + if (value != NULL) { + res = PyObject_SetItem(self, key, value); + Py_DECREF(value); + } + else { + res = -1; + } + Py_DECREF(key); + } + Py_DECREF(iterator); + if (res != 0 || PyErr_Occurred()) { + return -1; + } + return 0; + } + if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) { + return -1; + } + if (func != NULL) { + PyObject *items = _PyObject_CallNoArg(func); + Py_DECREF(func); + if (items == NULL) { + return -1; + } + res = mutablemapping_add_pairs(self, items); + Py_DECREF(items); + return res; + } + res = mutablemapping_add_pairs(self, arg); + return res; +} + +static PyObject * +mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) +{ + int res; /* first handle args, if any */ assert(args == NULL || PyTuple_Check(args)); - Py_ssize_t len = (args != NULL) ? PyTuple_GET_SIZE(args) : 0; + Py_ssize_t len = (args != NULL) ? PyTuple_GET_SIZE(args) : 0; if (len > 1) { - const char *msg = "update() takes at most 1 positional argument (%zd given)"; + const char *msg = "update() takes at most 1 positional argument (%zd given)"; PyErr_Format(PyExc_TypeError, msg, len); return NULL; } @@ -2327,9 +2327,9 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *other = PyTuple_GET_ITEM(args, 0); /* borrowed reference */ assert(other != NULL); Py_INCREF(other); - res = mutablemapping_update_arg(self, other); - Py_DECREF(other); - if (res < 0) { + res = mutablemapping_update_arg(self, other); + Py_DECREF(other); + if (res < 0) { return NULL; } } diff --git a/contrib/tools/python3/src/Objects/picklebufobject.c b/contrib/tools/python3/src/Objects/picklebufobject.c index 2db5036ebe..a135e5575e 100644 --- a/contrib/tools/python3/src/Objects/picklebufobject.c +++ b/contrib/tools/python3/src/Objects/picklebufobject.c @@ -1,219 +1,219 @@ -/* PickleBuffer object implementation */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include <stddef.h> - -typedef struct { - PyObject_HEAD - /* The view exported by the original object */ - Py_buffer view; - PyObject *weakreflist; -} PyPickleBufferObject; - -/* C API */ - -PyObject * -PyPickleBuffer_FromObject(PyObject *base) -{ - PyTypeObject *type = &PyPickleBuffer_Type; - PyPickleBufferObject *self; - - self = (PyPickleBufferObject *) type->tp_alloc(type, 0); - if (self == NULL) { - return NULL; - } - self->view.obj = NULL; - self->weakreflist = NULL; - if (PyObject_GetBuffer(base, &self->view, PyBUF_FULL_RO) < 0) { - Py_DECREF(self); - return NULL; - } - return (PyObject *) self; -} - -const Py_buffer * -PyPickleBuffer_GetBuffer(PyObject *obj) -{ - PyPickleBufferObject *self = (PyPickleBufferObject *) obj; - - if (!PyPickleBuffer_Check(obj)) { - PyErr_Format(PyExc_TypeError, - "expected PickleBuffer, %.200s found", - Py_TYPE(obj)->tp_name); - return NULL; - } - if (self->view.obj == NULL) { - PyErr_SetString(PyExc_ValueError, - "operation forbidden on released PickleBuffer object"); - return NULL; - } - return &self->view; -} - -int -PyPickleBuffer_Release(PyObject *obj) -{ - PyPickleBufferObject *self = (PyPickleBufferObject *) obj; - - if (!PyPickleBuffer_Check(obj)) { - PyErr_Format(PyExc_TypeError, - "expected PickleBuffer, %.200s found", - Py_TYPE(obj)->tp_name); - return -1; - } - PyBuffer_Release(&self->view); - return 0; -} - -static PyObject * -picklebuf_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyPickleBufferObject *self; - PyObject *base; - char *keywords[] = {"", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:PickleBuffer", - keywords, &base)) { - return NULL; - } - - self = (PyPickleBufferObject *) type->tp_alloc(type, 0); - if (self == NULL) { - return NULL; - } - self->view.obj = NULL; - self->weakreflist = NULL; - if (PyObject_GetBuffer(base, &self->view, PyBUF_FULL_RO) < 0) { - Py_DECREF(self); - return NULL; - } - return (PyObject *) self; -} - -static int -picklebuf_traverse(PyPickleBufferObject *self, visitproc visit, void *arg) -{ - Py_VISIT(self->view.obj); - return 0; -} - -static int -picklebuf_clear(PyPickleBufferObject *self) -{ - PyBuffer_Release(&self->view); - return 0; -} - -static void -picklebuf_dealloc(PyPickleBufferObject *self) -{ - PyObject_GC_UnTrack(self); - if (self->weakreflist != NULL) - PyObject_ClearWeakRefs((PyObject *) self); - PyBuffer_Release(&self->view); - Py_TYPE(self)->tp_free((PyObject *) self); -} - -/* Buffer API */ - -static int -picklebuf_getbuf(PyPickleBufferObject *self, Py_buffer *view, int flags) -{ - if (self->view.obj == NULL) { - PyErr_SetString(PyExc_ValueError, - "operation forbidden on released PickleBuffer object"); - return -1; - } - return PyObject_GetBuffer(self->view.obj, view, flags); -} - -static void -picklebuf_releasebuf(PyPickleBufferObject *self, Py_buffer *view) -{ - /* Since our bf_getbuffer redirects to the original object, this - * implementation is never called. It only exists to signal that - * buffers exported by PickleBuffer have non-trivial releasing - * behaviour (see check in Python/getargs.c). - */ -} - -static PyBufferProcs picklebuf_as_buffer = { - .bf_getbuffer = (getbufferproc) picklebuf_getbuf, - .bf_releasebuffer = (releasebufferproc) picklebuf_releasebuf, -}; - -/* Methods */ - -static PyObject * -picklebuf_raw(PyPickleBufferObject *self, PyObject *Py_UNUSED(ignored)) -{ - if (self->view.obj == NULL) { - PyErr_SetString(PyExc_ValueError, - "operation forbidden on released PickleBuffer object"); - return NULL; - } - if (self->view.suboffsets != NULL - || !PyBuffer_IsContiguous(&self->view, 'A')) { - PyErr_SetString(PyExc_BufferError, - "cannot extract raw buffer from non-contiguous buffer"); - return NULL; - } - PyObject *m = PyMemoryView_FromObject((PyObject *) self); - if (m == NULL) { - return NULL; - } - PyMemoryViewObject *mv = (PyMemoryViewObject *) m; - assert(mv->view.suboffsets == NULL); - /* Mutate memoryview instance to make it a "raw" memoryview */ - mv->view.format = "B"; - mv->view.ndim = 1; - mv->view.itemsize = 1; - /* shape = (length,) */ - mv->view.shape = &mv->view.len; - /* strides = (1,) */ - mv->view.strides = &mv->view.itemsize; - /* Fix memoryview state flags */ - /* XXX Expose memoryobject.c's init_flags() instead? */ - mv->flags = _Py_MEMORYVIEW_C | _Py_MEMORYVIEW_FORTRAN; - return m; -} - -PyDoc_STRVAR(picklebuf_raw_doc, -"raw($self, /)\n--\n\ -\n\ -Return a memoryview of the raw memory underlying this buffer.\n\ -Will raise BufferError is the buffer isn't contiguous."); - -static PyObject * -picklebuf_release(PyPickleBufferObject *self, PyObject *Py_UNUSED(ignored)) -{ - PyBuffer_Release(&self->view); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(picklebuf_release_doc, -"release($self, /)\n--\n\ -\n\ -Release the underlying buffer exposed by the PickleBuffer object."); - -static PyMethodDef picklebuf_methods[] = { - {"raw", (PyCFunction) picklebuf_raw, METH_NOARGS, picklebuf_raw_doc}, - {"release", (PyCFunction) picklebuf_release, METH_NOARGS, picklebuf_release_doc}, - {NULL, NULL} -}; - -PyTypeObject PyPickleBuffer_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pickle.PickleBuffer", - .tp_doc = "Wrapper for potentially out-of-band buffers", - .tp_basicsize = sizeof(PyPickleBufferObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_new = picklebuf_new, - .tp_dealloc = (destructor) picklebuf_dealloc, - .tp_traverse = (traverseproc) picklebuf_traverse, - .tp_clear = (inquiry) picklebuf_clear, - .tp_weaklistoffset = offsetof(PyPickleBufferObject, weakreflist), - .tp_as_buffer = &picklebuf_as_buffer, - .tp_methods = picklebuf_methods, -}; +/* PickleBuffer object implementation */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include <stddef.h> + +typedef struct { + PyObject_HEAD + /* The view exported by the original object */ + Py_buffer view; + PyObject *weakreflist; +} PyPickleBufferObject; + +/* C API */ + +PyObject * +PyPickleBuffer_FromObject(PyObject *base) +{ + PyTypeObject *type = &PyPickleBuffer_Type; + PyPickleBufferObject *self; + + self = (PyPickleBufferObject *) type->tp_alloc(type, 0); + if (self == NULL) { + return NULL; + } + self->view.obj = NULL; + self->weakreflist = NULL; + if (PyObject_GetBuffer(base, &self->view, PyBUF_FULL_RO) < 0) { + Py_DECREF(self); + return NULL; + } + return (PyObject *) self; +} + +const Py_buffer * +PyPickleBuffer_GetBuffer(PyObject *obj) +{ + PyPickleBufferObject *self = (PyPickleBufferObject *) obj; + + if (!PyPickleBuffer_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "expected PickleBuffer, %.200s found", + Py_TYPE(obj)->tp_name); + return NULL; + } + if (self->view.obj == NULL) { + PyErr_SetString(PyExc_ValueError, + "operation forbidden on released PickleBuffer object"); + return NULL; + } + return &self->view; +} + +int +PyPickleBuffer_Release(PyObject *obj) +{ + PyPickleBufferObject *self = (PyPickleBufferObject *) obj; + + if (!PyPickleBuffer_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "expected PickleBuffer, %.200s found", + Py_TYPE(obj)->tp_name); + return -1; + } + PyBuffer_Release(&self->view); + return 0; +} + +static PyObject * +picklebuf_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyPickleBufferObject *self; + PyObject *base; + char *keywords[] = {"", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:PickleBuffer", + keywords, &base)) { + return NULL; + } + + self = (PyPickleBufferObject *) type->tp_alloc(type, 0); + if (self == NULL) { + return NULL; + } + self->view.obj = NULL; + self->weakreflist = NULL; + if (PyObject_GetBuffer(base, &self->view, PyBUF_FULL_RO) < 0) { + Py_DECREF(self); + return NULL; + } + return (PyObject *) self; +} + +static int +picklebuf_traverse(PyPickleBufferObject *self, visitproc visit, void *arg) +{ + Py_VISIT(self->view.obj); + return 0; +} + +static int +picklebuf_clear(PyPickleBufferObject *self) +{ + PyBuffer_Release(&self->view); + return 0; +} + +static void +picklebuf_dealloc(PyPickleBufferObject *self) +{ + PyObject_GC_UnTrack(self); + if (self->weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) self); + PyBuffer_Release(&self->view); + Py_TYPE(self)->tp_free((PyObject *) self); +} + +/* Buffer API */ + +static int +picklebuf_getbuf(PyPickleBufferObject *self, Py_buffer *view, int flags) +{ + if (self->view.obj == NULL) { + PyErr_SetString(PyExc_ValueError, + "operation forbidden on released PickleBuffer object"); + return -1; + } + return PyObject_GetBuffer(self->view.obj, view, flags); +} + +static void +picklebuf_releasebuf(PyPickleBufferObject *self, Py_buffer *view) +{ + /* Since our bf_getbuffer redirects to the original object, this + * implementation is never called. It only exists to signal that + * buffers exported by PickleBuffer have non-trivial releasing + * behaviour (see check in Python/getargs.c). + */ +} + +static PyBufferProcs picklebuf_as_buffer = { + .bf_getbuffer = (getbufferproc) picklebuf_getbuf, + .bf_releasebuffer = (releasebufferproc) picklebuf_releasebuf, +}; + +/* Methods */ + +static PyObject * +picklebuf_raw(PyPickleBufferObject *self, PyObject *Py_UNUSED(ignored)) +{ + if (self->view.obj == NULL) { + PyErr_SetString(PyExc_ValueError, + "operation forbidden on released PickleBuffer object"); + return NULL; + } + if (self->view.suboffsets != NULL + || !PyBuffer_IsContiguous(&self->view, 'A')) { + PyErr_SetString(PyExc_BufferError, + "cannot extract raw buffer from non-contiguous buffer"); + return NULL; + } + PyObject *m = PyMemoryView_FromObject((PyObject *) self); + if (m == NULL) { + return NULL; + } + PyMemoryViewObject *mv = (PyMemoryViewObject *) m; + assert(mv->view.suboffsets == NULL); + /* Mutate memoryview instance to make it a "raw" memoryview */ + mv->view.format = "B"; + mv->view.ndim = 1; + mv->view.itemsize = 1; + /* shape = (length,) */ + mv->view.shape = &mv->view.len; + /* strides = (1,) */ + mv->view.strides = &mv->view.itemsize; + /* Fix memoryview state flags */ + /* XXX Expose memoryobject.c's init_flags() instead? */ + mv->flags = _Py_MEMORYVIEW_C | _Py_MEMORYVIEW_FORTRAN; + return m; +} + +PyDoc_STRVAR(picklebuf_raw_doc, +"raw($self, /)\n--\n\ +\n\ +Return a memoryview of the raw memory underlying this buffer.\n\ +Will raise BufferError is the buffer isn't contiguous."); + +static PyObject * +picklebuf_release(PyPickleBufferObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyBuffer_Release(&self->view); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(picklebuf_release_doc, +"release($self, /)\n--\n\ +\n\ +Release the underlying buffer exposed by the PickleBuffer object."); + +static PyMethodDef picklebuf_methods[] = { + {"raw", (PyCFunction) picklebuf_raw, METH_NOARGS, picklebuf_raw_doc}, + {"release", (PyCFunction) picklebuf_release, METH_NOARGS, picklebuf_release_doc}, + {NULL, NULL} +}; + +PyTypeObject PyPickleBuffer_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "pickle.PickleBuffer", + .tp_doc = "Wrapper for potentially out-of-band buffers", + .tp_basicsize = sizeof(PyPickleBufferObject), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_new = picklebuf_new, + .tp_dealloc = (destructor) picklebuf_dealloc, + .tp_traverse = (traverseproc) picklebuf_traverse, + .tp_clear = (inquiry) picklebuf_clear, + .tp_weaklistoffset = offsetof(PyPickleBufferObject, weakreflist), + .tp_as_buffer = &picklebuf_as_buffer, + .tp_methods = picklebuf_methods, +}; diff --git a/contrib/tools/python3/src/Objects/rangeobject.c b/contrib/tools/python3/src/Objects/rangeobject.c index 0eed2f0c0d..d7076ac824 100644 --- a/contrib/tools/python3/src/Objects/rangeobject.c +++ b/contrib/tools/python3/src/Objects/rangeobject.c @@ -1,9 +1,9 @@ /* Range object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_tupleobject.h" -#include "structmember.h" // PyMemberDef +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_tupleobject.h" +#include "structmember.h" // PyMemberDef /* Support objects whose length is > PY_SSIZE_T_MAX. @@ -20,8 +20,8 @@ typedef struct { PyObject *length; } rangeobject; -_Py_IDENTIFIER(iter); - +_Py_IDENTIFIER(iter); + /* Helper function for validating step. Always returns a new reference or NULL on error. */ @@ -73,57 +73,57 @@ make_range_object(PyTypeObject *type, PyObject *start, range(0, 5, -1) */ static PyObject * -range_from_array(PyTypeObject *type, PyObject *const *args, Py_ssize_t num_args) +range_from_array(PyTypeObject *type, PyObject *const *args, Py_ssize_t num_args) { rangeobject *obj; PyObject *start = NULL, *stop = NULL, *step = NULL; - switch (num_args) { - case 3: - step = args[2]; - /* fallthrough */ - case 2: - /* Convert borrowed refs to owned refs */ - start = PyNumber_Index(args[0]); - if (!start) { - return NULL; - } - stop = PyNumber_Index(args[1]); - if (!stop) { - Py_DECREF(start); - return NULL; - } - step = validate_step(step); /* Caution, this can clear exceptions */ - if (!step) { - Py_DECREF(start); - Py_DECREF(stop); - return NULL; - } - break; - case 1: - stop = PyNumber_Index(args[0]); - if (!stop) { - return NULL; - } - Py_INCREF(_PyLong_Zero); - start = _PyLong_Zero; - Py_INCREF(_PyLong_One); - step = _PyLong_One; - break; - case 0: - PyErr_SetString(PyExc_TypeError, - "range expected at least 1 argument, got 0"); + switch (num_args) { + case 3: + step = args[2]; + /* fallthrough */ + case 2: + /* Convert borrowed refs to owned refs */ + start = PyNumber_Index(args[0]); + if (!start) { + return NULL; + } + stop = PyNumber_Index(args[1]); + if (!stop) { + Py_DECREF(start); + return NULL; + } + step = validate_step(step); /* Caution, this can clear exceptions */ + if (!step) { + Py_DECREF(start); + Py_DECREF(stop); + return NULL; + } + break; + case 1: + stop = PyNumber_Index(args[0]); + if (!stop) { + return NULL; + } + Py_INCREF(_PyLong_Zero); + start = _PyLong_Zero; + Py_INCREF(_PyLong_One); + step = _PyLong_One; + break; + case 0: + PyErr_SetString(PyExc_TypeError, + "range expected at least 1 argument, got 0"); return NULL; - default: - PyErr_Format(PyExc_TypeError, - "range expected at most 3 arguments, got %zd", - num_args); + default: + PyErr_Format(PyExc_TypeError, + "range expected at most 3 arguments, got %zd", + num_args); return NULL; } obj = make_range_object(type, start, stop, step); - if (obj != NULL) { + if (obj != NULL) { return (PyObject *) obj; - } + } /* Failed to create object, release attributes */ Py_DECREF(start); @@ -132,27 +132,27 @@ range_from_array(PyTypeObject *type, PyObject *const *args, Py_ssize_t num_args) return NULL; } -static PyObject * -range_new(PyTypeObject *type, PyObject *args, PyObject *kw) -{ - if (!_PyArg_NoKeywords("range", kw)) - return NULL; - - return range_from_array(type, _PyTuple_ITEMS(args), PyTuple_GET_SIZE(args)); -} - - -static PyObject * -range_vectorcall(PyTypeObject *type, PyObject *const *args, - size_t nargsf, PyObject *kwnames) -{ - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_NoKwnames("range", kwnames)) { - return NULL; - } - return range_from_array(type, args, nargs); -} - +static PyObject * +range_new(PyTypeObject *type, PyObject *args, PyObject *kw) +{ + if (!_PyArg_NoKeywords("range", kw)) + return NULL; + + return range_from_array(type, _PyTuple_ITEMS(args), PyTuple_GET_SIZE(args)); +} + + +static PyObject * +range_vectorcall(PyTypeObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_NoKwnames("range", kwnames)) { + return NULL; + } + return range_from_array(type, args, nargs); +} + PyDoc_STRVAR(range_doc, "range(stop) -> range object\n\ range(start, stop[, step]) -> range object\n\ @@ -632,7 +632,7 @@ range_reduce(rangeobject *r, PyObject *args) static PyObject * range_subscript(rangeobject* self, PyObject* item) { - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { PyObject *i, *result; i = PyNumber_Index(item); if (!i) @@ -646,7 +646,7 @@ range_subscript(rangeobject* self, PyObject* item) } PyErr_Format(PyExc_TypeError, "range indices must be integers or slices, not %.200s", - Py_TYPE(item)->tp_name); + Py_TYPE(item)->tp_name); return NULL; } @@ -668,7 +668,7 @@ static PyNumberMethods range_as_number = { }; static PyObject * range_iter(PyObject *seq); -static PyObject * range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)); +static PyObject * range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(reverse_doc, "Return a reverse iterator."); @@ -677,11 +677,11 @@ PyDoc_STRVAR(count_doc, "rangeobject.count(value) -> integer -- return number of occurrences of value"); PyDoc_STRVAR(index_doc, -"rangeobject.index(value) -> integer -- return index of value.\n" +"rangeobject.index(value) -> integer -- return index of value.\n" "Raise ValueError if the value is not present."); static PyMethodDef range_methods[] = { - {"__reversed__", range_reverse, METH_NOARGS, reverse_doc}, + {"__reversed__", range_reverse, METH_NOARGS, reverse_doc}, {"__reduce__", (PyCFunction)range_reduce, METH_VARARGS}, {"count", (PyCFunction)range_count, METH_O, count_doc}, {"index", (PyCFunction)range_index, METH_O, index_doc}, @@ -701,10 +701,10 @@ PyTypeObject PyRange_Type = { sizeof(rangeobject), /* Basic object size */ 0, /* Item size for varobject */ (destructor)range_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)range_repr, /* tp_repr */ &range_as_number, /* tp_as_number */ &range_as_sequence, /* tp_as_sequence */ @@ -734,7 +734,7 @@ PyTypeObject PyRange_Type = { 0, /* tp_init */ 0, /* tp_alloc */ range_new, /* tp_new */ - .tp_vectorcall = (vectorcallfunc)range_vectorcall + .tp_vectorcall = (vectorcallfunc)range_vectorcall }; /*********************** range Iterator **************************/ @@ -764,7 +764,7 @@ rangeiter_next(rangeiterobject *r) } static PyObject * -rangeiter_len(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) +rangeiter_len(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong(r->len - r->index); } @@ -773,7 +773,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) +rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) { PyObject *start=NULL, *stop=NULL, *step=NULL; PyObject *range; @@ -793,8 +793,8 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) if (range == NULL) goto err; /* return the result */ - return Py_BuildValue("N(N)l", _PyEval_GetBuiltinId(&PyId_iter), - range, r->index); + return Py_BuildValue("N(N)l", _PyEval_GetBuiltinId(&PyId_iter), + range, r->index); err: Py_XDECREF(start); Py_XDECREF(stop); @@ -837,10 +837,10 @@ PyTypeObject PyRangeIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)PyObject_Del, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -895,14 +895,14 @@ get_len_of_range(long lo, long hi, long step) is not representable as a C long, OverflowError is raised. */ static PyObject * -fast_range_iter(long start, long stop, long step, long len) +fast_range_iter(long start, long stop, long step, long len) { rangeiterobject *it = PyObject_New(rangeiterobject, &PyRangeIter_Type); if (it == NULL) return NULL; it->start = start; it->step = step; - it->len = len; + it->len = len; it->index = 0; return (PyObject *)it; } @@ -922,7 +922,7 @@ longrangeiter_len(longrangeiterobject *r, PyObject *no_args) } static PyObject * -longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) +longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) { PyObject *product, *stop=NULL; PyObject *range; @@ -947,8 +947,8 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) } /* return the result */ - return Py_BuildValue("N(N)O", _PyEval_GetBuiltinId(&PyId_iter), - range, r->index); + return Py_BuildValue("N(N)O", _PyEval_GetBuiltinId(&PyId_iter), + range, r->index); } static PyObject * @@ -1031,10 +1031,10 @@ PyTypeObject PyLongRangeIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)longrangeiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1063,7 +1063,7 @@ range_iter(PyObject *seq) rangeobject *r = (rangeobject *)seq; longrangeiterobject *it; long lstart, lstop, lstep; - unsigned long ulen; + unsigned long ulen; assert(PyRange_Check(seq)); @@ -1084,22 +1084,22 @@ range_iter(PyObject *seq) PyErr_Clear(); goto long_range; } - ulen = get_len_of_range(lstart, lstop, lstep); - if (ulen > (unsigned long)LONG_MAX) { + ulen = get_len_of_range(lstart, lstop, lstep); + if (ulen > (unsigned long)LONG_MAX) { goto long_range; } - /* check for potential overflow of lstart + ulen * lstep */ - if (ulen) { - if (lstep > 0) { - if (lstop > LONG_MAX - (lstep - 1)) - goto long_range; - } - else { - if (lstop < LONG_MIN + (-1 - lstep)) - goto long_range; - } - } - return fast_range_iter(lstart, lstop, lstep, (long)ulen); + /* check for potential overflow of lstart + ulen * lstep */ + if (ulen) { + if (lstep > 0) { + if (lstop > LONG_MAX - (lstep - 1)) + goto long_range; + } + else { + if (lstop < LONG_MIN + (-1 - lstep)) + goto long_range; + } + } + return fast_range_iter(lstart, lstop, lstep, (long)ulen); long_range: it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type); @@ -1118,7 +1118,7 @@ range_iter(PyObject *seq) } static PyObject * -range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)) +range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)) { rangeobject *range = (rangeobject*) seq; longrangeiterobject *it; @@ -1185,7 +1185,7 @@ range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)) new_stop = lstart - lstep; new_start = (long)(new_stop + ulen * lstep); - return fast_range_iter(new_start, new_stop, -lstep, (long)ulen); + return fast_range_iter(new_start, new_stop, -lstep, (long)ulen); long_range: it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type); diff --git a/contrib/tools/python3/src/Objects/setobject.c b/contrib/tools/python3/src/Objects/setobject.c index c458205a16..4bd5777f96 100644 --- a/contrib/tools/python3/src/Objects/setobject.c +++ b/contrib/tools/python3/src/Objects/setobject.c @@ -32,8 +32,8 @@ */ #include "Python.h" -#include "pycore_object.h" // _PyObject_GC_UNTRACK() -#include <stddef.h> // offsetof() +#include "pycore_object.h" // _PyObject_GC_UNTRACK() +#include <stddef.h> // offsetof() /* Object used as dummy key to fill deleted entries */ static PyObject _dummy_struct; @@ -57,41 +57,41 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash) { setentry *table; setentry *entry; - size_t perturb = hash; + size_t perturb = hash; size_t mask = so->mask; size_t i = (size_t)hash & mask; /* Unsigned for defined overflow behavior */ - int probes; + int probes; int cmp; while (1) { - entry = &so->table[i]; - probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0; - do { - if (entry->hash == 0 && entry->key == NULL) + entry = &so->table[i]; + probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0; + do { + if (entry->hash == 0 && entry->key == NULL) return entry; - if (entry->hash == hash) { - PyObject *startkey = entry->key; - assert(startkey != dummy); - if (startkey == key) + if (entry->hash == hash) { + PyObject *startkey = entry->key; + assert(startkey != dummy); + if (startkey == key) + return entry; + if (PyUnicode_CheckExact(startkey) + && PyUnicode_CheckExact(key) + && _PyUnicode_EQ(startkey, key)) + return entry; + table = so->table; + Py_INCREF(startkey); + cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); + Py_DECREF(startkey); + if (cmp < 0) + return NULL; + if (table != so->table || entry->key != startkey) + return set_lookkey(so, key, hash); + if (cmp > 0) return entry; - if (PyUnicode_CheckExact(startkey) - && PyUnicode_CheckExact(key) - && _PyUnicode_EQ(startkey, key)) - return entry; - table = so->table; - Py_INCREF(startkey); - cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); - Py_DECREF(startkey); - if (cmp < 0) - return NULL; - if (table != so->table || entry->key != startkey) - return set_lookkey(so, key, hash); - if (cmp > 0) - return entry; - mask = so->mask; + mask = so->mask; } - entry++; - } while (probes--); + entry++; + } while (probes--); perturb >>= PERTURB_SHIFT; i = (i * 5 + 1 + perturb) & mask; } @@ -107,7 +107,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash) size_t perturb; size_t mask; size_t i; /* Unsigned for defined overflow behavior */ - int probes; + int probes; int cmp; /* Pre-increment is necessary to prevent arbitrary code in the rich @@ -121,34 +121,34 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash) perturb = hash; while (1) { - entry = &so->table[i]; - probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0; - do { - if (entry->hash == 0 && entry->key == NULL) - goto found_unused; - if (entry->hash == hash) { - PyObject *startkey = entry->key; - assert(startkey != dummy); - if (startkey == key) - goto found_active; - if (PyUnicode_CheckExact(startkey) - && PyUnicode_CheckExact(key) - && _PyUnicode_EQ(startkey, key)) - goto found_active; - table = so->table; - Py_INCREF(startkey); - cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); - Py_DECREF(startkey); - if (cmp > 0) - goto found_active; - if (cmp < 0) - goto comparison_error; - if (table != so->table || entry->key != startkey) - goto restart; - mask = so->mask; + entry = &so->table[i]; + probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0; + do { + if (entry->hash == 0 && entry->key == NULL) + goto found_unused; + if (entry->hash == hash) { + PyObject *startkey = entry->key; + assert(startkey != dummy); + if (startkey == key) + goto found_active; + if (PyUnicode_CheckExact(startkey) + && PyUnicode_CheckExact(key) + && _PyUnicode_EQ(startkey, key)) + goto found_active; + table = so->table; + Py_INCREF(startkey); + cmp = PyObject_RichCompareBool(startkey, key, Py_EQ); + Py_DECREF(startkey); + if (cmp > 0) + goto found_active; + if (cmp < 0) + goto comparison_error; + if (table != so->table || entry->key != startkey) + goto restart; + mask = so->mask; } - entry++; - } while (probes--); + entry++; + } while (probes--); perturb >>= PERTURB_SHIFT; i = (i * 5 + 1 + perturb) & mask; } @@ -173,7 +173,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash) /* Internal routine used by set_table_resize() to insert an item which is -known to be absent from the set. Besides the performance benefit, +known to be absent from the set. Besides the performance benefit, there is also safety benefit since using set_add_entry() risks making a callback in the middle of a set_table_resize(), see issue 1456209. The caller is responsible for updating the key's reference count and @@ -473,7 +473,7 @@ set_dealloc(PySetObject *so) /* bpo-31095: UnTrack is needed before calling any callbacks */ PyObject_GC_UnTrack(so); - Py_TRASHCAN_BEGIN(so, set_dealloc) + Py_TRASHCAN_BEGIN(so, set_dealloc) if (so->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) so); @@ -486,7 +486,7 @@ set_dealloc(PySetObject *so) if (so->table != so->smalltable) PyMem_DEL(so->table); Py_TYPE(so)->tp_free(so); - Py_TRASHCAN_END + Py_TRASHCAN_END } static PyObject * @@ -522,7 +522,7 @@ set_repr(PySetObject *so) goto done; listrepr = tmp; - if (!Py_IS_TYPE(so, &PySet_Type)) + if (!Py_IS_TYPE(so, &PySet_Type)) result = PyUnicode_FromFormat("%s({%U})", Py_TYPE(so)->tp_name, listrepr); @@ -613,27 +613,27 @@ set_merge(PySetObject *so, PyObject *otherset) } static PyObject * -set_pop(PySetObject *so, PyObject *Py_UNUSED(ignored)) +set_pop(PySetObject *so, PyObject *Py_UNUSED(ignored)) { /* Make sure the search finger is in bounds */ - setentry *entry = so->table + (so->finger & so->mask); - setentry *limit = so->table + so->mask; + setentry *entry = so->table + (so->finger & so->mask); + setentry *limit = so->table + so->mask; PyObject *key; if (so->used == 0) { PyErr_SetString(PyExc_KeyError, "pop from an empty set"); return NULL; } - while (entry->key == NULL || entry->key==dummy) { - entry++; - if (entry > limit) - entry = so->table; + while (entry->key == NULL || entry->key==dummy) { + entry++; + if (entry > limit) + entry = so->table; } key = entry->key; entry->key = dummy; entry->hash = -1; so->used--; - so->finger = entry - so->table + 1; /* next place to start */ + so->finger = entry - so->table + 1; /* next place to start */ return key; } @@ -741,7 +741,7 @@ setiter_traverse(setiterobject *si, visitproc visit, void *arg) } static PyObject * -setiter_len(setiterobject *si, PyObject *Py_UNUSED(ignored)) +setiter_len(setiterobject *si, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (si->si_set != NULL && si->si_used == si->si_set->used) @@ -754,20 +754,20 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject *setiter_iternext(setiterobject *si); static PyObject * -setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) +setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); /* copy the iterator state */ - setiterobject tmp = *si; + setiterobject tmp = *si; Py_XINCREF(tmp.si_set); /* iterate the temporary into a list */ - PyObject *list = PySequence_List((PyObject*)&tmp); + PyObject *list = PySequence_List((PyObject*)&tmp); Py_XDECREF(tmp.si_set); - if (list == NULL) { + if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -823,10 +823,10 @@ PyTypeObject PySetIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)setiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -938,7 +938,7 @@ PyDoc_STRVAR(update_doc, static PyObject * make_new_set(PyTypeObject *type, PyObject *iterable) { - assert(PyType_Check(type)); + assert(PyType_Check(type)); PySetObject *so; so = (PySetObject *)type->tp_alloc(type, 0); @@ -979,68 +979,68 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable) static PyObject *emptyfrozenset = NULL; static PyObject * -make_new_frozenset(PyTypeObject *type, PyObject *iterable) +make_new_frozenset(PyTypeObject *type, PyObject *iterable) { - if (type != &PyFrozenSet_Type) { + if (type != &PyFrozenSet_Type) { return make_new_set(type, iterable); - } + } if (iterable != NULL) { if (PyFrozenSet_CheckExact(iterable)) { - /* frozenset(f) is idempotent */ + /* frozenset(f) is idempotent */ Py_INCREF(iterable); return iterable; } - PyObject *res = make_new_set((PyTypeObject *)type, iterable); - if (res == NULL || PySet_GET_SIZE(res) != 0) { - return res; - } - /* If the created frozenset is empty, return the empty frozenset singleton instead */ - Py_DECREF(res); - } - - // The empty frozenset is a singleton - if (emptyfrozenset == NULL) { - emptyfrozenset = make_new_set((PyTypeObject *)type, NULL); - } + PyObject *res = make_new_set((PyTypeObject *)type, iterable); + if (res == NULL || PySet_GET_SIZE(res) != 0) { + return res; + } + /* If the created frozenset is empty, return the empty frozenset singleton instead */ + Py_DECREF(res); + } + + // The empty frozenset is a singleton + if (emptyfrozenset == NULL) { + emptyfrozenset = make_new_set((PyTypeObject *)type, NULL); + } Py_XINCREF(emptyfrozenset); return emptyfrozenset; } static PyObject * -frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *iterable = NULL; - - if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset", kwds)) { - return NULL; - } - - if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) { - return NULL; - } - - return make_new_frozenset(type, iterable); -} - -static PyObject * -frozenset_vectorcall(PyObject *type, PyObject * const*args, - size_t nargsf, PyObject *kwnames) -{ - if (!_PyArg_NoKwnames("frozenset", kwnames)) { - return NULL; - } - - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_CheckPositional("frozenset", nargs, 0, 1)) { - return NULL; - } - - PyObject *iterable = (nargs ? args[0] : NULL); - return make_new_frozenset((PyTypeObject *)type, iterable); -} - -static PyObject * +frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *iterable = NULL; + + if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset", kwds)) { + return NULL; + } + + if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) { + return NULL; + } + + return make_new_frozenset(type, iterable); +} + +static PyObject * +frozenset_vectorcall(PyObject *type, PyObject * const*args, + size_t nargsf, PyObject *kwnames) +{ + if (!_PyArg_NoKwnames("frozenset", kwnames)) { + return NULL; + } + + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_CheckPositional("frozenset", nargs, 0, 1)) { + return NULL; + } + + PyObject *iterable = (nargs ? args[0] : NULL); + return make_new_frozenset((PyTypeObject *)type, iterable); +} + +static PyObject * set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { return make_new_set(type, NULL); @@ -1093,25 +1093,25 @@ set_swap_bodies(PySetObject *a, PySetObject *b) } static PyObject * -set_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) +set_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) { return make_new_set_basetype(Py_TYPE(so), (PyObject *)so); } static PyObject * -frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) +frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) { if (PyFrozenSet_CheckExact(so)) { Py_INCREF(so); return (PyObject *)so; } - return set_copy(so, NULL); + return set_copy(so, NULL); } PyDoc_STRVAR(copy_doc, "Return a shallow copy of a set."); static PyObject * -set_clear(PySetObject *so, PyObject *Py_UNUSED(ignored)) +set_clear(PySetObject *so, PyObject *Py_UNUSED(ignored)) { set_clear_internal(so); Py_RETURN_NONE; @@ -1126,7 +1126,7 @@ set_union(PySetObject *so, PyObject *args) PyObject *other; Py_ssize_t i; - result = (PySetObject *)set_copy(so, NULL); + result = (PySetObject *)set_copy(so, NULL); if (result == NULL) return NULL; @@ -1155,7 +1155,7 @@ set_or(PySetObject *so, PyObject *other) if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) Py_RETURN_NOTIMPLEMENTED; - result = (PySetObject *)set_copy(so, NULL); + result = (PySetObject *)set_copy(so, NULL); if (result == NULL) return NULL; if ((PyObject *)so == other) @@ -1188,7 +1188,7 @@ set_intersection(PySetObject *so, PyObject *other) int rv; if ((PyObject *)so == other) - return set_copy(so, NULL); + return set_copy(so, NULL); result = (PySetObject *)make_new_set_basetype(Py_TYPE(so), NULL); if (result == NULL) @@ -1261,7 +1261,7 @@ set_intersection_multi(PySetObject *so, PyObject *args) PyObject *result = (PyObject *)so; if (PyTuple_GET_SIZE(args) == 0) - return set_copy(so, NULL); + return set_copy(so, NULL); Py_INCREF(so); for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) { @@ -1408,25 +1408,25 @@ set_difference_update_internal(PySetObject *so, PyObject *other) setentry *entry; Py_ssize_t pos = 0; - /* Optimization: When the other set is more than 8 times - larger than the base set, replace the other set with - intersection of the two sets. - */ - if ((PySet_GET_SIZE(other) >> 3) > PySet_GET_SIZE(so)) { - other = set_intersection(so, other); - if (other == NULL) - return -1; - } else { - Py_INCREF(other); - } - + /* Optimization: When the other set is more than 8 times + larger than the base set, replace the other set with + intersection of the two sets. + */ + if ((PySet_GET_SIZE(other) >> 3) > PySet_GET_SIZE(so)) { + other = set_intersection(so, other); + if (other == NULL) + return -1; + } else { + Py_INCREF(other); + } + while (set_next((PySetObject *)other, &pos, &entry)) - if (set_discard_entry(so, entry->key, entry->hash) < 0) { - Py_DECREF(other); + if (set_discard_entry(so, entry->key, entry->hash) < 0) { + Py_DECREF(other); return -1; - } - - Py_DECREF(other); + } + + Py_DECREF(other); } else { PyObject *key, *it; it = PyObject_GetIter(other); @@ -1472,7 +1472,7 @@ set_copy_and_difference(PySetObject *so, PyObject *other) { PyObject *result; - result = set_copy(so, NULL); + result = set_copy(so, NULL); if (result == NULL) return NULL; if (set_difference_update_internal((PySetObject *) result, other) == 0) @@ -1556,7 +1556,7 @@ set_difference_multi(PySetObject *so, PyObject *args) PyObject *result, *other; if (PyTuple_GET_SIZE(args) == 0) - return set_copy(so, NULL); + return set_copy(so, NULL); other = PyTuple_GET_ITEM(args, 0); result = set_difference(so, other); @@ -1607,7 +1607,7 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other) int rv; if ((PyObject *)so == other) - return set_clear(so, NULL); + return set_clear(so, NULL); if (PyDict_CheckExact(other)) { PyObject *value; @@ -1904,7 +1904,7 @@ PyDoc_STRVAR(discard_doc, If the element is not a member, do nothing."); static PyObject * -set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) +set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) { PyObject *keys=NULL, *args=NULL, *result=NULL, *dict=NULL; _Py_IDENTIFIER(__dict__); @@ -1915,9 +1915,9 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - if (_PyObject_LookupAttrId((PyObject *)so, &PyId___dict__, &dict) < 0) { - goto done; - } + if (_PyObject_LookupAttrId((PyObject *)so, &PyId___dict__, &dict) < 0) { + goto done; + } if (dict == NULL) { dict = Py_None; Py_INCREF(dict); @@ -1931,7 +1931,7 @@ done: } static PyObject * -set_sizeof(PySetObject *so, PyObject *Py_UNUSED(ignored)) +set_sizeof(PySetObject *so, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; @@ -1959,28 +1959,28 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds) return set_update_internal(self, iterable); } -static PyObject* -set_vectorcall(PyObject *type, PyObject * const*args, - size_t nargsf, PyObject *kwnames) -{ - assert(PyType_Check(type)); - - if (!_PyArg_NoKwnames("set", kwnames)) { - return NULL; - } - - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_CheckPositional("set", nargs, 0, 1)) { - return NULL; - } - - if (nargs) { - return make_new_set((PyTypeObject *)type, args[0]); - } - - return make_new_set((PyTypeObject *)type, NULL); -} - +static PyObject* +set_vectorcall(PyObject *type, PyObject * const*args, + size_t nargsf, PyObject *kwnames) +{ + assert(PyType_Check(type)); + + if (!_PyArg_NoKwnames("set", kwnames)) { + return NULL; + } + + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_CheckPositional("set", nargs, 0, 1)) { + return NULL; + } + + if (nargs) { + return make_new_set((PyTypeObject *)type, args[0]); + } + + return make_new_set((PyTypeObject *)type, NULL); +} + static PySequenceMethods set_as_sequence = { set_len, /* sq_length */ 0, /* sq_concat */ @@ -1995,7 +1995,7 @@ static PySequenceMethods set_as_sequence = { /* set object ********************************************************/ #ifdef Py_DEBUG -static PyObject *test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored)); +static PyObject *test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(test_c_api_doc, "Exercises C API. Returns True.\n\ All is well if assertions don't fail."); @@ -2046,7 +2046,7 @@ static PyMethodDef set_methods[] = { union_doc}, {"update", (PyCFunction)set_update, METH_VARARGS, update_doc}, - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -2095,10 +2095,10 @@ PyTypeObject PySet_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)set_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)set_repr, /* tp_repr */ &set_as_number, /* tp_as_number */ &set_as_sequence, /* tp_as_sequence */ @@ -2130,7 +2130,7 @@ PyTypeObject PySet_Type = { PyType_GenericAlloc, /* tp_alloc */ set_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ - .tp_vectorcall = set_vectorcall, + .tp_vectorcall = set_vectorcall, }; /* frozenset object ********************************************************/ @@ -2159,7 +2159,7 @@ static PyMethodDef frozenset_methods[] = { symmetric_difference_doc}, {"union", (PyCFunction)set_union, METH_VARARGS, union_doc}, - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -2195,10 +2195,10 @@ PyTypeObject PyFrozenSet_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)set_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)set_repr, /* tp_repr */ &frozenset_as_number, /* tp_as_number */ &set_as_sequence, /* tp_as_sequence */ @@ -2230,7 +2230,7 @@ PyTypeObject PyFrozenSet_Type = { PyType_GenericAlloc, /* tp_alloc */ frozenset_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ - .tp_vectorcall = frozenset_vectorcall, + .tp_vectorcall = frozenset_vectorcall, }; @@ -2300,7 +2300,7 @@ PySet_Add(PyObject *anyset, PyObject *key) } void -_PySet_Fini(void) +_PySet_Fini(void) { Py_CLEAR(emptyfrozenset); } @@ -2328,7 +2328,7 @@ PySet_Pop(PyObject *set) PyErr_BadInternalCall(); return NULL; } - return set_pop((PySetObject *)set, NULL); + return set_pop((PySetObject *)set, NULL); } int @@ -2357,7 +2357,7 @@ PyObject *_PySet_Dummy = dummy; } while(0) static PyObject * -test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored)) +test_c_api(PySetObject *so, PyObject *Py_UNUSED(ignored)) { Py_ssize_t count; const char *s; @@ -2494,7 +2494,7 @@ dummy_repr(PyObject *op) return PyUnicode_FromString("<dummy key>"); } -static void _Py_NO_RETURN +static void _Py_NO_RETURN dummy_dealloc(PyObject* ignore) { Py_FatalError("deallocating <dummy key>"); @@ -2506,10 +2506,10 @@ static PyTypeObject _PySetDummy_Type = { 0, 0, dummy_dealloc, /*tp_dealloc*/ /*never called*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ dummy_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ diff --git a/contrib/tools/python3/src/Objects/sliceobject.c b/contrib/tools/python3/src/Objects/sliceobject.c index a92a4f65fd..391711f711 100644 --- a/contrib/tools/python3/src/Objects/sliceobject.c +++ b/contrib/tools/python3/src/Objects/sliceobject.c @@ -14,9 +14,9 @@ this type and there is exactly one in existence. */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_object.h" -#include "structmember.h" // PyMemberDef +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_object.h" +#include "structmember.h" // PyMemberDef static PyObject * ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) @@ -36,13 +36,13 @@ ellipsis_repr(PyObject *op) } static PyObject * -ellipsis_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) +ellipsis_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) { return PyUnicode_FromString("Ellipsis"); } static PyMethodDef ellipsis_methods[] = { - {"__reduce__", ellipsis_reduce, METH_NOARGS, NULL}, + {"__reduce__", ellipsis_reduce, METH_NOARGS, NULL}, {NULL, NULL} }; @@ -52,10 +52,10 @@ PyTypeObject PyEllipsis_Type = { 0, /* tp_basicsize */ 0, /* tp_itemsize */ 0, /*never called*/ /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ ellipsis_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -99,8 +99,8 @@ PyObject _Py_EllipsisObject = { * created and then deleted again */ static PySliceObject *slice_cache = NULL; - -void _PySlice_Fini(void) + +void _PySlice_Fini(void) { PySliceObject *obj = slice_cache; if (obj != NULL) { @@ -353,7 +353,7 @@ static PyMemberDef slice_members[] = { static PyObject* evaluate_slice_index(PyObject *v) { - if (_PyIndex_Check(v)) { + if (_PyIndex_Check(v)) { return PyNumber_Index(v); } else { @@ -547,7 +547,7 @@ S. Out of bounds indices are clipped in a manner consistent with the\n\ handling of normal slices."); static PyObject * -slice_reduce(PySliceObject* self, PyObject *Py_UNUSED(ignored)) +slice_reduce(PySliceObject* self, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step); } @@ -625,10 +625,10 @@ PyTypeObject PySlice_Type = { sizeof(PySliceObject), /* Basic object size */ 0, /* Item size for varobject */ (destructor)slice_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)slice_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/stringlib/asciilib.h b/contrib/tools/python3/src/Objects/stringlib/asciilib.h index 23c954ba73..e69a2c076e 100644 --- a/contrib/tools/python3/src/Objects/stringlib/asciilib.h +++ b/contrib/tools/python3/src/Objects/stringlib/asciilib.h @@ -18,7 +18,7 @@ #define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL #define STRINGLIB_STR PyUnicode_1BYTE_DATA #define STRINGLIB_LEN PyUnicode_GET_LENGTH -#define STRINGLIB_NEW(STR,LEN) _PyUnicode_FromASCII((const char*)(STR),(LEN)) +#define STRINGLIB_NEW(STR,LEN) _PyUnicode_FromASCII((const char*)(STR),(LEN)) #define STRINGLIB_CHECK PyUnicode_Check #define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact diff --git a/contrib/tools/python3/src/Objects/stringlib/clinic/transmogrify.h.h b/contrib/tools/python3/src/Objects/stringlib/clinic/transmogrify.h.h index a3fca6a710..8a3a060f12 100644 --- a/contrib/tools/python3/src/Objects/stringlib/clinic/transmogrify.h.h +++ b/contrib/tools/python3/src/Objects/stringlib/clinic/transmogrify.h.h @@ -1,277 +1,277 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(stringlib_expandtabs__doc__, -"expandtabs($self, /, tabsize=8)\n" -"--\n" -"\n" -"Return a copy where all tab characters are expanded using spaces.\n" -"\n" -"If tabsize is not given, a tab size of 8 characters is assumed."); - -#define STRINGLIB_EXPANDTABS_METHODDEF \ - {"expandtabs", (PyCFunction)(void(*)(void))stringlib_expandtabs, METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__}, - -static PyObject * -stringlib_expandtabs_impl(PyObject *self, int tabsize); - -static PyObject * -stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"tabsize", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - int tabsize = 8; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - tabsize = _PyLong_AsInt(args[0]); - if (tabsize == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional_pos: - return_value = stringlib_expandtabs_impl(self, tabsize); - -exit: - return return_value; -} - -PyDoc_STRVAR(stringlib_ljust__doc__, -"ljust($self, width, fillchar=b\' \', /)\n" -"--\n" -"\n" -"Return a left-justified string of length width.\n" -"\n" -"Padding is done using the specified fill character."); - -#define STRINGLIB_LJUST_METHODDEF \ - {"ljust", (PyCFunction)(void(*)(void))stringlib_ljust, METH_FASTCALL, stringlib_ljust__doc__}, - -static PyObject * -stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar); - -static PyObject * -stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t width; - char fillchar = ' '; - - if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { - goto exit; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { - fillchar = PyBytes_AS_STRING(args[1])[0]; - } - else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { - fillchar = PyByteArray_AS_STRING(args[1])[0]; - } - else { - _PyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]); - goto exit; - } -skip_optional: - return_value = stringlib_ljust_impl(self, width, fillchar); - -exit: - return return_value; -} - -PyDoc_STRVAR(stringlib_rjust__doc__, -"rjust($self, width, fillchar=b\' \', /)\n" -"--\n" -"\n" -"Return a right-justified string of length width.\n" -"\n" -"Padding is done using the specified fill character."); - -#define STRINGLIB_RJUST_METHODDEF \ - {"rjust", (PyCFunction)(void(*)(void))stringlib_rjust, METH_FASTCALL, stringlib_rjust__doc__}, - -static PyObject * -stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar); - -static PyObject * -stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t width; - char fillchar = ' '; - - if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { - goto exit; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { - fillchar = PyBytes_AS_STRING(args[1])[0]; - } - else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { - fillchar = PyByteArray_AS_STRING(args[1])[0]; - } - else { - _PyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]); - goto exit; - } -skip_optional: - return_value = stringlib_rjust_impl(self, width, fillchar); - -exit: - return return_value; -} - -PyDoc_STRVAR(stringlib_center__doc__, -"center($self, width, fillchar=b\' \', /)\n" -"--\n" -"\n" -"Return a centered string of length width.\n" -"\n" -"Padding is done using the specified fill character."); - -#define STRINGLIB_CENTER_METHODDEF \ - {"center", (PyCFunction)(void(*)(void))stringlib_center, METH_FASTCALL, stringlib_center__doc__}, - -static PyObject * -stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar); - -static PyObject * -stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t width; - char fillchar = ' '; - - if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { - goto exit; - } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - if (nargs < 2) { - goto skip_optional; - } - if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { - fillchar = PyBytes_AS_STRING(args[1])[0]; - } - else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { - fillchar = PyByteArray_AS_STRING(args[1])[0]; - } - else { - _PyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]); - goto exit; - } -skip_optional: - return_value = stringlib_center_impl(self, width, fillchar); - -exit: - return return_value; -} - -PyDoc_STRVAR(stringlib_zfill__doc__, -"zfill($self, width, /)\n" -"--\n" -"\n" -"Pad a numeric string with zeros on the left, to fill a field of the given width.\n" -"\n" -"The original string is never truncated."); - -#define STRINGLIB_ZFILL_METHODDEF \ - {"zfill", (PyCFunction)stringlib_zfill, METH_O, stringlib_zfill__doc__}, - -static PyObject * -stringlib_zfill_impl(PyObject *self, Py_ssize_t width); - -static PyObject * -stringlib_zfill(PyObject *self, PyObject *arg) -{ - PyObject *return_value = NULL; - Py_ssize_t width; - - if (PyFloat_Check(arg)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } - { - Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); - if (iobj != NULL) { - ival = PyLong_AsSsize_t(iobj); - Py_DECREF(iobj); - } - if (ival == -1 && PyErr_Occurred()) { - goto exit; - } - width = ival; - } - return_value = stringlib_zfill_impl(self, width); - -exit: - return return_value; -} -/*[clinic end generated code: output=15be047aef999b4e input=a9049054013a1b77]*/ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_expandtabs__doc__, +"expandtabs($self, /, tabsize=8)\n" +"--\n" +"\n" +"Return a copy where all tab characters are expanded using spaces.\n" +"\n" +"If tabsize is not given, a tab size of 8 characters is assumed."); + +#define STRINGLIB_EXPANDTABS_METHODDEF \ + {"expandtabs", (PyCFunction)(void(*)(void))stringlib_expandtabs, METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__}, + +static PyObject * +stringlib_expandtabs_impl(PyObject *self, int tabsize); + +static PyObject * +stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"tabsize", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + int tabsize = 8; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + tabsize = _PyLong_AsInt(args[0]); + if (tabsize == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional_pos: + return_value = stringlib_expandtabs_impl(self, tabsize); + +exit: + return return_value; +} + +PyDoc_STRVAR(stringlib_ljust__doc__, +"ljust($self, width, fillchar=b\' \', /)\n" +"--\n" +"\n" +"Return a left-justified string of length width.\n" +"\n" +"Padding is done using the specified fill character."); + +#define STRINGLIB_LJUST_METHODDEF \ + {"ljust", (PyCFunction)(void(*)(void))stringlib_ljust, METH_FASTCALL, stringlib_ljust__doc__}, + +static PyObject * +stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar); + +static PyObject * +stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + Py_ssize_t width; + char fillchar = ' '; + + if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]); + goto exit; + } +skip_optional: + return_value = stringlib_ljust_impl(self, width, fillchar); + +exit: + return return_value; +} + +PyDoc_STRVAR(stringlib_rjust__doc__, +"rjust($self, width, fillchar=b\' \', /)\n" +"--\n" +"\n" +"Return a right-justified string of length width.\n" +"\n" +"Padding is done using the specified fill character."); + +#define STRINGLIB_RJUST_METHODDEF \ + {"rjust", (PyCFunction)(void(*)(void))stringlib_rjust, METH_FASTCALL, stringlib_rjust__doc__}, + +static PyObject * +stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar); + +static PyObject * +stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + Py_ssize_t width; + char fillchar = ' '; + + if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]); + goto exit; + } +skip_optional: + return_value = stringlib_rjust_impl(self, width, fillchar); + +exit: + return return_value; +} + +PyDoc_STRVAR(stringlib_center__doc__, +"center($self, width, fillchar=b\' \', /)\n" +"--\n" +"\n" +"Return a centered string of length width.\n" +"\n" +"Padding is done using the specified fill character."); + +#define STRINGLIB_CENTER_METHODDEF \ + {"center", (PyCFunction)(void(*)(void))stringlib_center, METH_FASTCALL, stringlib_center__doc__}, + +static PyObject * +stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar); + +static PyObject * +stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + Py_ssize_t width; + char fillchar = ' '; + + if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[0]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]); + goto exit; + } +skip_optional: + return_value = stringlib_center_impl(self, width, fillchar); + +exit: + return return_value; +} + +PyDoc_STRVAR(stringlib_zfill__doc__, +"zfill($self, width, /)\n" +"--\n" +"\n" +"Pad a numeric string with zeros on the left, to fill a field of the given width.\n" +"\n" +"The original string is never truncated."); + +#define STRINGLIB_ZFILL_METHODDEF \ + {"zfill", (PyCFunction)stringlib_zfill, METH_O, stringlib_zfill__doc__}, + +static PyObject * +stringlib_zfill_impl(PyObject *self, Py_ssize_t width); + +static PyObject * +stringlib_zfill(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_ssize_t width; + + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + width = ival; + } + return_value = stringlib_zfill_impl(self, width); + +exit: + return return_value; +} +/*[clinic end generated code: output=15be047aef999b4e input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/stringlib/codecs.h b/contrib/tools/python3/src/Objects/stringlib/codecs.h index 742be90abd..9b2a29ba3b 100644 --- a/contrib/tools/python3/src/Objects/stringlib/codecs.h +++ b/contrib/tools/python3/src/Objects/stringlib/codecs.h @@ -4,8 +4,8 @@ # error "codecs.h is specific to Unicode" #endif -#include "pycore_byteswap.h" // _Py_bswap32() - +#include "pycore_byteswap.h" // _Py_bswap32() + /* Mask to quickly check whether a C 'long' contains a non-ASCII, UTF8-encoded char. */ #if (SIZEOF_LONG == 8) @@ -48,7 +48,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end, /* Read a whole long at a time (either 4 or 8 bytes), and do a fast unrolled copy if it only contains ASCII characters. */ - unsigned long value = *(const unsigned long *) _s; + unsigned long value = *(const unsigned long *) _s; if (value & ASCII_CHAR_MASK) break; #if PY_LITTLE_ENDIAN @@ -155,7 +155,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end, /* Decoding UTF-8 sequences in range \xED\xA0\x80-\xED\xBF\xBF will result in surrogates in range D800-DFFF. Surrogates are not valid UTF-8 so they are rejected. - See https://www.unicode.org/versions/Unicode5.2.0/ch03.pdf + See https://www.unicode.org/versions/Unicode5.2.0/ch03.pdf (table 3-7) and http://www.rfc-editor.org/rfc/rfc3629.txt */ goto InvalidContinuation1; } @@ -209,7 +209,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end, goto InvalidContinuation1; } else if (ch == 0xF4 && ch2 >= 0x90) { /* invalid sequence - \xF4\x90\x80\x80- -- 110000- overflow */ + \xF4\x90\x80\x80- -- 110000- overflow */ goto InvalidContinuation1; } if (!IS_CONTINUATION_BYTE(ch3)) { @@ -258,12 +258,12 @@ InvalidContinuation3: /* UTF-8 encoder specialized for a Unicode kind to avoid the slow PyUnicode_READ() macro. Delete some parts of the code depending on the kind: UCS-1 strings don't need to handle surrogates for example. */ -Py_LOCAL_INLINE(char *) -STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, - PyObject *unicode, - const STRINGLIB_CHAR *data, +Py_LOCAL_INLINE(char *) +STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, + PyObject *unicode, + const STRINGLIB_CHAR *data, Py_ssize_t size, - _Py_error_handler error_handler, + _Py_error_handler error_handler, const char *errors) { Py_ssize_t i; /* index into data of next input character */ @@ -284,12 +284,12 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, assert(size >= 0); if (size > PY_SSIZE_T_MAX / max_char_size) { /* integer overflow */ - PyErr_NoMemory(); - return NULL; + PyErr_NoMemory(); + return NULL; } - _PyBytesWriter_Init(writer); - p = _PyBytesWriter_Alloc(writer, size * max_char_size); + _PyBytesWriter_Init(writer); + p = _PyBytesWriter_Alloc(writer, size * max_char_size); if (p == NULL) return NULL; @@ -315,7 +315,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, Py_ssize_t startpos, endpos, newpos; Py_ssize_t k; if (error_handler == _Py_ERROR_UNKNOWN) { - error_handler = _Py_GetErrorHandler(errors); + error_handler = _Py_GetErrorHandler(errors); } startpos = i-1; @@ -325,7 +325,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, endpos++; /* Only overallocate the buffer if it's not the last write */ - writer->overallocate = (endpos < size); + writer->overallocate = (endpos < size); switch (error_handler) { @@ -349,8 +349,8 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, case _Py_ERROR_BACKSLASHREPLACE: /* subtract preallocated bytes */ - writer->min_size -= max_char_size * (endpos - startpos); - p = backslashreplace(writer, p, + writer->min_size -= max_char_size * (endpos - startpos); + p = backslashreplace(writer, p, unicode, startpos, endpos); if (p == NULL) goto error; @@ -359,8 +359,8 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, case _Py_ERROR_XMLCHARREFREPLACE: /* subtract preallocated bytes */ - writer->min_size -= max_char_size * (endpos - startpos); - p = xmlcharrefreplace(writer, p, + writer->min_size -= max_char_size * (endpos - startpos); + p = xmlcharrefreplace(writer, p, unicode, startpos, endpos); if (p == NULL) goto error; @@ -389,10 +389,10 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, goto error; /* subtract preallocated bytes */ - writer->min_size -= max_char_size * (newpos - startpos); + writer->min_size -= max_char_size * (newpos - startpos); if (PyBytes_Check(rep)) { - p = _PyBytesWriter_WriteBytes(writer, p, + p = _PyBytesWriter_WriteBytes(writer, p, PyBytes_AS_STRING(rep), PyBytes_GET_SIZE(rep)); } @@ -408,7 +408,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, goto error; } - p = _PyBytesWriter_WriteBytes(writer, p, + p = _PyBytesWriter_WriteBytes(writer, p, PyUnicode_DATA(rep), PyUnicode_GET_LENGTH(rep)); } @@ -422,7 +422,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, /* If overallocation was disabled, ensure that it was the last write. Otherwise, we missed an optimization */ - assert(writer->overallocate || i == size); + assert(writer->overallocate || i == size); } else #if STRINGLIB_SIZEOF_CHAR > 2 @@ -451,7 +451,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer, Py_XDECREF(error_handler_obj); Py_XDECREF(exc); #endif - return p; + return p; #if STRINGLIB_SIZEOF_CHAR > 1 error: @@ -516,7 +516,7 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e, /* Fast path for runs of in-range non-surrogate chars. */ const unsigned char *_q = q; while (_q < aligned_end) { - unsigned long block = * (const unsigned long *) _q; + unsigned long block = * (const unsigned long *) _q; if (native_ordering) { /* Can use buffer directly */ if (block & FAST_CHAR_MASK) @@ -574,8 +574,8 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e, } /* UTF-16 code pair: */ - if (!Py_UNICODE_IS_HIGH_SURROGATE(ch)) - goto IllegalEncoding; + if (!Py_UNICODE_IS_HIGH_SURROGATE(ch)) + goto IllegalEncoding; if (q >= e) goto UnexpectedEnd; ch2 = (q[ihi] << 8) | q[ilo]; @@ -734,28 +734,28 @@ STRINGLIB(utf16_encode)(const STRINGLIB_CHAR *in, #endif } -static inline uint32_t -STRINGLIB(SWAB4)(STRINGLIB_CHAR ch) -{ - uint32_t word = ch; +static inline uint32_t +STRINGLIB(SWAB4)(STRINGLIB_CHAR ch) +{ + uint32_t word = ch; #if STRINGLIB_SIZEOF_CHAR == 1 - /* high bytes are zero */ - return (word << 24); + /* high bytes are zero */ + return (word << 24); #elif STRINGLIB_SIZEOF_CHAR == 2 - /* high bytes are zero */ - return ((word & 0x00FFu) << 24) | ((word & 0xFF00u) << 8); + /* high bytes are zero */ + return ((word & 0x00FFu) << 24) | ((word & 0xFF00u) << 8); #else - return _Py_bswap32(word); + return _Py_bswap32(word); #endif -} - +} + Py_LOCAL_INLINE(Py_ssize_t) STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in, Py_ssize_t len, - uint32_t **outptr, + uint32_t **outptr, int native_ordering) { - uint32_t *out = *outptr; + uint32_t *out = *outptr; const STRINGLIB_CHAR *end = in + len; if (native_ordering) { const STRINGLIB_CHAR *unrolled_end = in + _Py_SIZE_ROUND_DOWN(len, 4); @@ -796,10 +796,10 @@ STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in, (in[3] ^ 0xd800) & 0xf800) == 0) break; #endif - out[0] = STRINGLIB(SWAB4)(in[0]); - out[1] = STRINGLIB(SWAB4)(in[1]); - out[2] = STRINGLIB(SWAB4)(in[2]); - out[3] = STRINGLIB(SWAB4)(in[3]); + out[0] = STRINGLIB(SWAB4)(in[0]); + out[1] = STRINGLIB(SWAB4)(in[1]); + out[2] = STRINGLIB(SWAB4)(in[2]); + out[3] = STRINGLIB(SWAB4)(in[3]); in += 4; out += 4; } while (in < end) { @@ -810,7 +810,7 @@ STRINGLIB(utf32_encode)(const STRINGLIB_CHAR *in, goto fail; } #endif - *out++ = STRINGLIB(SWAB4)(ch); + *out++ = STRINGLIB(SWAB4)(ch); } } *outptr = out; diff --git a/contrib/tools/python3/src/Objects/stringlib/ctype.h b/contrib/tools/python3/src/Objects/stringlib/ctype.h index b11d38eb06..9b319b07d1 100644 --- a/contrib/tools/python3/src/Objects/stringlib/ctype.h +++ b/contrib/tools/python3/src/Objects/stringlib/ctype.h @@ -2,52 +2,52 @@ # error "ctype.h only compatible with byte-wise strings" #endif -#include "pycore_bytes_methods.h" +#include "pycore_bytes_methods.h" static PyObject* -stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isascii(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isascii(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_islower(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_islower(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isupper(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_isupper(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } @@ -56,7 +56,7 @@ stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored)) /* functions that return a new object partially translated by ctype funcs: */ static PyObject* -stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -68,7 +68,7 @@ stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject* -stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -80,7 +80,7 @@ stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject* -stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -92,7 +92,7 @@ stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject* -stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -104,7 +104,7 @@ stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored)) } static PyObject* -stringlib_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored)) +stringlib_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); diff --git a/contrib/tools/python3/src/Objects/stringlib/eq.h b/contrib/tools/python3/src/Objects/stringlib/eq.h index a3cec94e23..9c1058b86c 100644 --- a/contrib/tools/python3/src/Objects/stringlib/eq.h +++ b/contrib/tools/python3/src/Objects/stringlib/eq.h @@ -6,11 +6,11 @@ Py_LOCAL_INLINE(int) unicode_eq(PyObject *aa, PyObject *bb) { - assert(PyUnicode_Check(aa)); - assert(PyUnicode_Check(bb)); - assert(PyUnicode_IS_READY(aa)); - assert(PyUnicode_IS_READY(bb)); - + assert(PyUnicode_Check(aa)); + assert(PyUnicode_Check(bb)); + assert(PyUnicode_IS_READY(aa)); + assert(PyUnicode_IS_READY(bb)); + PyUnicodeObject *a = (PyUnicodeObject *)aa; PyUnicodeObject *b = (PyUnicodeObject *)bb; diff --git a/contrib/tools/python3/src/Objects/stringlib/fastsearch.h b/contrib/tools/python3/src/Objects/stringlib/fastsearch.h index 7c31649eba..56a4467d35 100644 --- a/contrib/tools/python3/src/Objects/stringlib/fastsearch.h +++ b/contrib/tools/python3/src/Objects/stringlib/fastsearch.h @@ -52,7 +52,7 @@ STRINGLIB(find_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch) return (p - s); return -1; #else - /* use memchr if we can choose a needle without too many likely + /* use memchr if we can choose a needle without too many likely false positives */ const STRINGLIB_CHAR *s1, *e1; unsigned char needle = ch & 0xff; @@ -111,7 +111,7 @@ STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch) return (p - s); return -1; #else - /* use memrchr if we can choose a needle without too many likely + /* use memrchr if we can choose a needle without too many likely false positives */ const STRINGLIB_CHAR *s1; Py_ssize_t n1; diff --git a/contrib/tools/python3/src/Objects/stringlib/find_max_char.h b/contrib/tools/python3/src/Objects/stringlib/find_max_char.h index 2e6bb63b86..f4e0a7761d 100644 --- a/contrib/tools/python3/src/Objects/stringlib/find_max_char.h +++ b/contrib/tools/python3/src/Objects/stringlib/find_max_char.h @@ -28,7 +28,7 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) /* Help register allocation */ const unsigned char *_p = p; while (_p < aligned_end) { - unsigned long value = *(const unsigned long *) _p; + unsigned long value = *(const unsigned long *) _p; if (value & UCS1_ASCII_CHAR_MASK) return 255; _p += SIZEOF_LONG; diff --git a/contrib/tools/python3/src/Objects/stringlib/join.h b/contrib/tools/python3/src/Objects/stringlib/join.h index 5573924a49..53bcbdea7a 100644 --- a/contrib/tools/python3/src/Objects/stringlib/join.h +++ b/contrib/tools/python3/src/Objects/stringlib/join.h @@ -7,8 +7,8 @@ Py_LOCAL_INLINE(PyObject *) STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) { - const char *sepstr = STRINGLIB_STR(sep); - Py_ssize_t seplen = STRINGLIB_LEN(sep); + const char *sepstr = STRINGLIB_STR(sep); + Py_ssize_t seplen = STRINGLIB_LEN(sep); PyObject *res = NULL; char *p; Py_ssize_t seqlen = 0; @@ -18,9 +18,9 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) Py_buffer *buffers = NULL; #define NB_STATIC_BUFFERS 10 Py_buffer static_buffers[NB_STATIC_BUFFERS]; -#define GIL_THRESHOLD 1048576 - int drop_gil = 1; - PyThreadState *save = NULL; +#define GIL_THRESHOLD 1048576 + int drop_gil = 1; + PyThreadState *save = NULL; seq = PySequence_Fast(iterable, "can only join an iterable"); if (seq == NULL) { @@ -68,21 +68,21 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) buffers[i].buf = PyBytes_AS_STRING(item); buffers[i].len = PyBytes_GET_SIZE(item); } - else { - if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) { - PyErr_Format(PyExc_TypeError, - "sequence item %zd: expected a bytes-like object, " - "%.80s found", - i, Py_TYPE(item)->tp_name); - goto error; - } - /* If the backing objects are mutable, then dropping the GIL - * opens up race conditions where another thread tries to modify - * the object which we hold a buffer on it. Such code has data - * races anyway, but this is a conservative approach that avoids - * changing the behaviour of that data race. - */ - drop_gil = 0; + else { + if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) { + PyErr_Format(PyExc_TypeError, + "sequence item %zd: expected a bytes-like object, " + "%.80s found", + i, Py_TYPE(item)->tp_name); + goto error; + } + /* If the backing objects are mutable, then dropping the GIL + * opens up race conditions where another thread tries to modify + * the object which we hold a buffer on it. Such code has data + * races anyway, but this is a conservative approach that avoids + * changing the behaviour of that data race. + */ + drop_gil = 0; } nbufs = i + 1; /* for error cleanup */ itemlen = buffers[i].len; @@ -114,12 +114,12 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) /* Catenate everything. */ p = STRINGLIB_STR(res); - if (sz < GIL_THRESHOLD) { - drop_gil = 0; /* Benefits are likely outweighed by the overheads */ - } - if (drop_gil) { - save = PyEval_SaveThread(); - } + if (sz < GIL_THRESHOLD) { + drop_gil = 0; /* Benefits are likely outweighed by the overheads */ + } + if (drop_gil) { + save = PyEval_SaveThread(); + } if (!seplen) { /* fast path */ for (i = 0; i < nbufs; i++) { @@ -129,23 +129,23 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) p += n; } } - else { - for (i = 0; i < nbufs; i++) { - Py_ssize_t n; - char *q; - if (i) { - memcpy(p, sepstr, seplen); - p += seplen; - } - n = buffers[i].len; - q = buffers[i].buf; - memcpy(p, q, n); - p += n; + else { + for (i = 0; i < nbufs; i++) { + Py_ssize_t n; + char *q; + if (i) { + memcpy(p, sepstr, seplen); + p += seplen; + } + n = buffers[i].len; + q = buffers[i].buf; + memcpy(p, q, n); + p += n; } } - if (drop_gil) { - PyEval_RestoreThread(save); - } + if (drop_gil) { + PyEval_RestoreThread(save); + } goto done; error: @@ -160,4 +160,4 @@ done: } #undef NB_STATIC_BUFFERS -#undef GIL_THRESHOLD +#undef GIL_THRESHOLD diff --git a/contrib/tools/python3/src/Objects/stringlib/localeutil.h b/contrib/tools/python3/src/Objects/stringlib/localeutil.h index 48ec1c0a4c..bd16e0a172 100644 --- a/contrib/tools/python3/src/Objects/stringlib/localeutil.h +++ b/contrib/tools/python3/src/Objects/stringlib/localeutil.h @@ -77,6 +77,6 @@ InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos, *buffer_pos -= n_zeros; enum PyUnicode_Kind kind = PyUnicode_KIND(writer->buffer); void *data = PyUnicode_DATA(writer->buffer); - unicode_fill(kind, data, '0', *buffer_pos, n_zeros); + unicode_fill(kind, data, '0', *buffer_pos, n_zeros); } } diff --git a/contrib/tools/python3/src/Objects/stringlib/split.h b/contrib/tools/python3/src/Objects/stringlib/split.h index 4511518ed7..068047f987 100644 --- a/contrib/tools/python3/src/Objects/stringlib/split.h +++ b/contrib/tools/python3/src/Objects/stringlib/split.h @@ -48,7 +48,7 @@ /* Always force the list to the expected size. */ -#define FIX_PREALLOC_SIZE(list) Py_SET_SIZE(list, count) +#define FIX_PREALLOC_SIZE(list) Py_SET_SIZE(list, count) Py_LOCAL_INLINE(PyObject *) STRINGLIB(split_whitespace)(PyObject* str_obj, diff --git a/contrib/tools/python3/src/Objects/stringlib/transmogrify.h b/contrib/tools/python3/src/Objects/stringlib/transmogrify.h index 207d50c710..e1165ea38e 100644 --- a/contrib/tools/python3/src/Objects/stringlib/transmogrify.h +++ b/contrib/tools/python3/src/Objects/stringlib/transmogrify.h @@ -5,13 +5,13 @@ /* the more complicated methods. parts of these should be pulled out into the shared code in bytes_methods.c to cut down on duplicate code bloat. */ -/*[clinic input] -class B "PyObject *" "&PyType_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2935558188d97c76]*/ - -#include "clinic/transmogrify.h.h" - +/*[clinic input] +class B "PyObject *" "&PyType_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2935558188d97c76]*/ + +#include "clinic/transmogrify.h.h" + static inline PyObject * return_self(PyObject *self) { @@ -24,19 +24,19 @@ return_self(PyObject *self) return STRINGLIB_NEW(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } -/*[clinic input] -B.expandtabs as stringlib_expandtabs - - tabsize: int = 8 - -Return a copy where all tab characters are expanded using spaces. - -If tabsize is not given, a tab size of 8 characters is assumed. -[clinic start generated code]*/ - -static PyObject * -stringlib_expandtabs_impl(PyObject *self, int tabsize) -/*[clinic end generated code: output=069cb7fae72e4c2b input=3c6d3b12aa3ccbea]*/ +/*[clinic input] +B.expandtabs as stringlib_expandtabs + + tabsize: int = 8 + +Return a copy where all tab characters are expanded using spaces. + +If tabsize is not given, a tab size of 8 characters is assumed. +[clinic start generated code]*/ + +static PyObject * +stringlib_expandtabs_impl(PyObject *self, int tabsize) +/*[clinic end generated code: output=069cb7fae72e4c2b input=3c6d3b12aa3ccbea]*/ { const char *e, *p; char *q; @@ -131,21 +131,21 @@ pad(PyObject *self, Py_ssize_t left, Py_ssize_t right, char fill) return u; } -/*[clinic input] -B.ljust as stringlib_ljust - - width: Py_ssize_t - fillchar: char = b' ' - / - -Return a left-justified string of length width. - -Padding is done using the specified fill character. -[clinic start generated code]*/ - +/*[clinic input] +B.ljust as stringlib_ljust + + width: Py_ssize_t + fillchar: char = b' ' + / + +Return a left-justified string of length width. + +Padding is done using the specified fill character. +[clinic start generated code]*/ + static PyObject * -stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar) -/*[clinic end generated code: output=c79ca173c5ff8337 input=eff2d014bc7d80df]*/ +stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: output=c79ca173c5ff8337 input=eff2d014bc7d80df]*/ { if (STRINGLIB_LEN(self) >= width) { return return_self(self); @@ -155,21 +155,21 @@ stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar) } -/*[clinic input] -B.rjust as stringlib_rjust - - width: Py_ssize_t - fillchar: char = b' ' - / - -Return a right-justified string of length width. - -Padding is done using the specified fill character. -[clinic start generated code]*/ - +/*[clinic input] +B.rjust as stringlib_rjust + + width: Py_ssize_t + fillchar: char = b' ' + / + +Return a right-justified string of length width. + +Padding is done using the specified fill character. +[clinic start generated code]*/ + static PyObject * -stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar) -/*[clinic end generated code: output=7df5d728a5439570 input=218b0bd31308955d]*/ +stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: output=7df5d728a5439570 input=218b0bd31308955d]*/ { if (STRINGLIB_LEN(self) >= width) { return return_self(self); @@ -179,21 +179,21 @@ stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar) } -/*[clinic input] -B.center as stringlib_center - - width: Py_ssize_t - fillchar: char = b' ' - / - -Return a centered string of length width. - -Padding is done using the specified fill character. -[clinic start generated code]*/ - +/*[clinic input] +B.center as stringlib_center + + width: Py_ssize_t + fillchar: char = b' ' + / + +Return a centered string of length width. + +Padding is done using the specified fill character. +[clinic start generated code]*/ + static PyObject * -stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar) -/*[clinic end generated code: output=d8da2e055288b4c2 input=3776fd278765d89b]*/ +stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: output=d8da2e055288b4c2 input=3776fd278765d89b]*/ { Py_ssize_t marg, left; @@ -207,20 +207,20 @@ stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar) return pad(self, left, marg - left, fillchar); } -/*[clinic input] -B.zfill as stringlib_zfill - - width: Py_ssize_t - / - -Pad a numeric string with zeros on the left, to fill a field of the given width. - -The original string is never truncated. -[clinic start generated code]*/ - +/*[clinic input] +B.zfill as stringlib_zfill + + width: Py_ssize_t + / + +Pad a numeric string with zeros on the left, to fill a field of the given width. + +The original string is never truncated. +[clinic start generated code]*/ + static PyObject * -stringlib_zfill_impl(PyObject *self, Py_ssize_t width) -/*[clinic end generated code: output=0b3c684a7f1b2319 input=2da6d7b8e9bcb19a]*/ +stringlib_zfill_impl(PyObject *self, Py_ssize_t width) +/*[clinic end generated code: output=0b3c684a7f1b2319 input=2da6d7b8e9bcb19a]*/ { Py_ssize_t fill; PyObject *s; @@ -680,13 +680,13 @@ stringlib_replace(PyObject *self, const char *to_s, Py_ssize_t to_len, Py_ssize_t maxcount) { - if (STRINGLIB_LEN(self) < from_len) { - /* nothing to do; return the original bytes */ - return return_self(self); - } + if (STRINGLIB_LEN(self) < from_len) { + /* nothing to do; return the original bytes */ + return return_self(self); + } if (maxcount < 0) { maxcount = PY_SSIZE_T_MAX; - } else if (maxcount == 0) { + } else if (maxcount == 0) { /* nothing to do; return the original bytes */ return return_self(self); } diff --git a/contrib/tools/python3/src/Objects/stringlib/unicode_format.h b/contrib/tools/python3/src/Objects/stringlib/unicode_format.h index 21787b3270..b526ad21b8 100644 --- a/contrib/tools/python3/src/Objects/stringlib/unicode_format.h +++ b/contrib/tools/python3/src/Objects/stringlib/unicode_format.h @@ -440,13 +440,13 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs, /* look up in args */ obj = PySequence_GetItem(args, index); - if (obj == NULL) { - PyErr_Format(PyExc_IndexError, - "Replacement index %zd out of range for positional " - "args tuple", - index); - goto error; - } + if (obj == NULL) { + PyErr_Format(PyExc_IndexError, + "Replacement index %zd out of range for positional " + "args tuple", + index); + goto error; + } } /* iterate over the rest of the field_name */ @@ -828,7 +828,7 @@ output_markup(SubString *field_name, SubString *format_spec, tmp = NULL; } - /* if needed, recursively compute the format_spec */ + /* if needed, recursively compute the format_spec */ if (format_spec_needs_expanding) { tmp = build_string(format_spec, args, kwargs, recursion_depth-1, auto_number); @@ -1071,10 +1071,10 @@ static PyTypeObject PyFormatterIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)formatteriter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1207,10 +1207,10 @@ static PyTypeObject PyFieldNameIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)fieldnameiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/structseq.c b/contrib/tools/python3/src/Objects/structseq.c index 509abac580..5a493c91e8 100644 --- a/contrib/tools/python3/src/Objects/structseq.c +++ b/contrib/tools/python3/src/Objects/structseq.c @@ -1,16 +1,16 @@ -/* Implementation helper: a struct that looks like a tuple. - See timemodule and posixmodule for example uses. - - The structseq helper is considered an internal CPython implementation - detail. Docs for modules using structseqs should call them - "named tuples" (be sure to include a space between the two - words and add a link back to the term in Docs/glossary.rst). -*/ - +/* Implementation helper: a struct that looks like a tuple. + See timemodule and posixmodule for example uses. + + The structseq helper is considered an internal CPython implementation + detail. Docs for modules using structseqs should call them + "named tuples" (be sure to include a space between the two + words and add a link back to the term in Docs/glossary.rst). +*/ + #include "Python.h" -#include "pycore_tupleobject.h" -#include "pycore_object.h" -#include "structmember.h" // PyMemberDef +#include "pycore_tupleobject.h" +#include "pycore_object.h" +#include "structmember.h" // PyMemberDef static const char visible_length_key[] = "n_sequence_fields"; static const char real_length_key[] = "n_fields"; @@ -18,7 +18,7 @@ static const char unnamed_fields_key[] = "n_unnamed_fields"; /* Fields with this name have only a field index, not a field name. They are only allowed for indices < n_visible_fields. */ -const char * const PyStructSequence_UnnamedField = "unnamed field"; +const char * const PyStructSequence_UnnamedField = "unnamed field"; _Py_IDENTIFIER(n_sequence_fields); _Py_IDENTIFIER(n_fields); _Py_IDENTIFIER(n_unnamed_fields); @@ -47,7 +47,7 @@ PyStructSequence_New(PyTypeObject *type) return NULL; /* Hack the size of the variable object, so invisible fields don't appear to Python code. */ - Py_SET_SIZE(obj, VISIBLE_SIZE_TP(type)); + Py_SET_SIZE(obj, VISIBLE_SIZE_TP(type)); for (i = 0; i < size; i++) obj->ob_item[i] = NULL; @@ -66,37 +66,37 @@ PyStructSequence_GetItem(PyObject* op, Py_ssize_t i) return PyStructSequence_GET_ITEM(op, i); } - -static int -structseq_traverse(PyStructSequence *obj, visitproc visit, void *arg) -{ - if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HEAPTYPE) { - Py_VISIT(Py_TYPE(obj)); - } - Py_ssize_t i, size; - size = REAL_SIZE(obj); - for (i = 0; i < size; ++i) { - Py_VISIT(obj->ob_item[i]); - } - return 0; -} - + +static int +structseq_traverse(PyStructSequence *obj, visitproc visit, void *arg) +{ + if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HEAPTYPE) { + Py_VISIT(Py_TYPE(obj)); + } + Py_ssize_t i, size; + size = REAL_SIZE(obj); + for (i = 0; i < size; ++i) { + Py_VISIT(obj->ob_item[i]); + } + return 0; +} + static void structseq_dealloc(PyStructSequence *obj) { Py_ssize_t i, size; - PyTypeObject *tp; - PyObject_GC_UnTrack(obj); + PyTypeObject *tp; + PyObject_GC_UnTrack(obj); - tp = (PyTypeObject *) Py_TYPE(obj); + tp = (PyTypeObject *) Py_TYPE(obj); size = REAL_SIZE(obj); for (i = 0; i < size; ++i) { Py_XDECREF(obj->ob_item[i]); } PyObject_GC_Del(obj); - if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) { - Py_DECREF(tp); - } + if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) { + Py_DECREF(tp); + } } /*[clinic input] @@ -110,12 +110,12 @@ class structseq "PyStructSequence *" "NULL" @classmethod structseq.__new__ as structseq_new sequence as arg: object - dict: object(c_default="NULL") = {} + dict: object(c_default="NULL") = {} [clinic start generated code]*/ static PyObject * structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict) -/*[clinic end generated code: output=baa082e788b171da input=90532511101aa3fb]*/ +/*[clinic end generated code: output=baa082e788b171da input=90532511101aa3fb]*/ { PyObject *ob; PyStructSequence *res = NULL; @@ -189,7 +189,7 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict) } Py_DECREF(arg); - _PyObject_GC_TRACK(res); + _PyObject_GC_TRACK(res); return (PyObject*) res; } @@ -198,89 +198,89 @@ static PyObject * structseq_repr(PyStructSequence *obj) { PyTypeObject *typ = Py_TYPE(obj); - _PyUnicodeWriter writer; - - /* Write "typename(" */ - PyObject *type_name = PyUnicode_DecodeUTF8(typ->tp_name, - strlen(typ->tp_name), - NULL); - if (type_name == NULL) { - return NULL; - } - - _PyUnicodeWriter_Init(&writer); - writer.overallocate = 1; - /* count 5 characters per item: "x=1, " */ - writer.min_length = (PyUnicode_GET_LENGTH(type_name) + 1 - + VISIBLE_SIZE(obj) * 5 + 1); - - if (_PyUnicodeWriter_WriteStr(&writer, type_name) < 0) { - Py_DECREF(type_name); - goto error; - } - Py_DECREF(type_name); - - if (_PyUnicodeWriter_WriteChar(&writer, '(') < 0) { - goto error; - } - - for (Py_ssize_t i=0; i < VISIBLE_SIZE(obj); i++) { - if (i > 0) { - /* Write ", " */ - if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { - goto error; - } - } - - /* Write "name=repr" */ - const char *name_utf8 = typ->tp_members[i].name; - if (name_utf8 == NULL) { - PyErr_Format(PyExc_SystemError, "In structseq_repr(), member %zd name is NULL" + _PyUnicodeWriter writer; + + /* Write "typename(" */ + PyObject *type_name = PyUnicode_DecodeUTF8(typ->tp_name, + strlen(typ->tp_name), + NULL); + if (type_name == NULL) { + return NULL; + } + + _PyUnicodeWriter_Init(&writer); + writer.overallocate = 1; + /* count 5 characters per item: "x=1, " */ + writer.min_length = (PyUnicode_GET_LENGTH(type_name) + 1 + + VISIBLE_SIZE(obj) * 5 + 1); + + if (_PyUnicodeWriter_WriteStr(&writer, type_name) < 0) { + Py_DECREF(type_name); + goto error; + } + Py_DECREF(type_name); + + if (_PyUnicodeWriter_WriteChar(&writer, '(') < 0) { + goto error; + } + + for (Py_ssize_t i=0; i < VISIBLE_SIZE(obj); i++) { + if (i > 0) { + /* Write ", " */ + if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { + goto error; + } + } + + /* Write "name=repr" */ + const char *name_utf8 = typ->tp_members[i].name; + if (name_utf8 == NULL) { + PyErr_Format(PyExc_SystemError, "In structseq_repr(), member %zd name is NULL" " for type %.500s", i, typ->tp_name); - goto error; + goto error; } - - PyObject *name = PyUnicode_DecodeUTF8(name_utf8, strlen(name_utf8), NULL); - if (name == NULL) { - goto error; + + PyObject *name = PyUnicode_DecodeUTF8(name_utf8, strlen(name_utf8), NULL); + if (name == NULL) { + goto error; } - if (_PyUnicodeWriter_WriteStr(&writer, name) < 0) { - Py_DECREF(name); - goto error; - } - Py_DECREF(name); - - if (_PyUnicodeWriter_WriteChar(&writer, '=') < 0) { - goto error; + if (_PyUnicodeWriter_WriteStr(&writer, name) < 0) { + Py_DECREF(name); + goto error; } - - PyObject *value = PyStructSequence_GET_ITEM(obj, i); - assert(value != NULL); - PyObject *repr = PyObject_Repr(value); - if (repr == NULL) { - goto error; - } - if (_PyUnicodeWriter_WriteStr(&writer, repr) < 0) { + Py_DECREF(name); + + if (_PyUnicodeWriter_WriteChar(&writer, '=') < 0) { + goto error; + } + + PyObject *value = PyStructSequence_GET_ITEM(obj, i); + assert(value != NULL); + PyObject *repr = PyObject_Repr(value); + if (repr == NULL) { + goto error; + } + if (_PyUnicodeWriter_WriteStr(&writer, repr) < 0) { Py_DECREF(repr); - goto error; + goto error; } - Py_DECREF(repr); + Py_DECREF(repr); } - - if (_PyUnicodeWriter_WriteChar(&writer, ')') < 0) { - goto error; + + if (_PyUnicodeWriter_WriteChar(&writer, ')') < 0) { + goto error; } - return _PyUnicodeWriter_Finish(&writer); - -error: - _PyUnicodeWriter_Dealloc(&writer); - return NULL; + return _PyUnicodeWriter_Finish(&writer); + +error: + _PyUnicodeWriter_Dealloc(&writer); + return NULL; } - + static PyObject * -structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) +structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) { PyObject* tup = NULL; PyObject* dict = NULL; @@ -290,7 +290,7 @@ structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) n_fields = REAL_SIZE(self); n_visible_fields = VISIBLE_SIZE(self); n_unnamed_fields = UNNAMED_FIELDS(self); - tup = _PyTuple_FromArray(self->ob_item, n_visible_fields); + tup = _PyTuple_FromArray(self->ob_item, n_visible_fields); if (!tup) goto error; @@ -298,7 +298,7 @@ structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) if (!dict) goto error; - for (i = n_visible_fields; i < n_fields; i++) { + for (i = n_visible_fields; i < n_fields; i++) { const char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name; if (PyDict_SetItemString(dict, n, self->ob_item[i]) < 0) goto error; @@ -322,119 +322,119 @@ static PyMethodDef structseq_methods[] = { {NULL, NULL} }; -static Py_ssize_t -count_members(PyStructSequence_Desc *desc, Py_ssize_t *n_unnamed_members) { - Py_ssize_t i; - - *n_unnamed_members = 0; - for (i = 0; desc->fields[i].name != NULL; ++i) { - if (desc->fields[i].name == PyStructSequence_UnnamedField) { - (*n_unnamed_members)++; - } - } - return i; -} - -static int -initialize_structseq_dict(PyStructSequence_Desc *desc, PyObject* dict, - Py_ssize_t n_members, Py_ssize_t n_unnamed_members) { - PyObject *v; - -#define SET_DICT_FROM_SIZE(key, value) \ - do { \ - v = PyLong_FromSsize_t(value); \ - if (v == NULL) { \ - return -1; \ - } \ - if (PyDict_SetItemString(dict, key, v) < 0) { \ - Py_DECREF(v); \ - return -1; \ - } \ - Py_DECREF(v); \ - } while (0) - - SET_DICT_FROM_SIZE(visible_length_key, desc->n_in_sequence); - SET_DICT_FROM_SIZE(real_length_key, n_members); - SET_DICT_FROM_SIZE(unnamed_fields_key, n_unnamed_members); - return 0; -} - -static void -initialize_members(PyStructSequence_Desc *desc, PyMemberDef* members, - Py_ssize_t n_members) { - Py_ssize_t i, k; - - for (i = k = 0; i < n_members; ++i) { - if (desc->fields[i].name == PyStructSequence_UnnamedField) { - continue; - } - - /* The names and docstrings in these MemberDefs are statically */ - /* allocated so it is expected that they'll outlive the MemberDef */ - members[k].name = desc->fields[i].name; - members[k].type = T_OBJECT; - members[k].offset = offsetof(PyStructSequence, ob_item) - + i * sizeof(PyObject*); - members[k].flags = READONLY; - members[k].doc = desc->fields[i].doc; - k++; - } - members[k].name = NULL; -} - +static Py_ssize_t +count_members(PyStructSequence_Desc *desc, Py_ssize_t *n_unnamed_members) { + Py_ssize_t i; + + *n_unnamed_members = 0; + for (i = 0; desc->fields[i].name != NULL; ++i) { + if (desc->fields[i].name == PyStructSequence_UnnamedField) { + (*n_unnamed_members)++; + } + } + return i; +} + +static int +initialize_structseq_dict(PyStructSequence_Desc *desc, PyObject* dict, + Py_ssize_t n_members, Py_ssize_t n_unnamed_members) { + PyObject *v; + +#define SET_DICT_FROM_SIZE(key, value) \ + do { \ + v = PyLong_FromSsize_t(value); \ + if (v == NULL) { \ + return -1; \ + } \ + if (PyDict_SetItemString(dict, key, v) < 0) { \ + Py_DECREF(v); \ + return -1; \ + } \ + Py_DECREF(v); \ + } while (0) + + SET_DICT_FROM_SIZE(visible_length_key, desc->n_in_sequence); + SET_DICT_FROM_SIZE(real_length_key, n_members); + SET_DICT_FROM_SIZE(unnamed_fields_key, n_unnamed_members); + return 0; +} + +static void +initialize_members(PyStructSequence_Desc *desc, PyMemberDef* members, + Py_ssize_t n_members) { + Py_ssize_t i, k; + + for (i = k = 0; i < n_members; ++i) { + if (desc->fields[i].name == PyStructSequence_UnnamedField) { + continue; + } + + /* The names and docstrings in these MemberDefs are statically */ + /* allocated so it is expected that they'll outlive the MemberDef */ + members[k].name = desc->fields[i].name; + members[k].type = T_OBJECT; + members[k].offset = offsetof(PyStructSequence, ob_item) + + i * sizeof(PyObject*); + members[k].flags = READONLY; + members[k].doc = desc->fields[i].doc; + k++; + } + members[k].name = NULL; +} + int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc) { - PyMemberDef *members; - Py_ssize_t n_members, n_unnamed_members; + PyMemberDef *members; + Py_ssize_t n_members, n_unnamed_members; #ifdef Py_TRACE_REFS /* if the type object was chained, unchain it first before overwriting its storage */ if (type->ob_base.ob_base._ob_next) { - _Py_ForgetReference((PyObject *)type); + _Py_ForgetReference((PyObject *)type); } #endif - /* PyTypeObject has already been initialized */ - if (Py_REFCNT(type) != 0) { - PyErr_BadInternalCall(); - return -1; - } + /* PyTypeObject has already been initialized */ + if (Py_REFCNT(type) != 0) { + PyErr_BadInternalCall(); + return -1; + } type->tp_name = desc->name; - type->tp_basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); - type->tp_itemsize = sizeof(PyObject *); - type->tp_dealloc = (destructor)structseq_dealloc; - type->tp_repr = (reprfunc)structseq_repr; + type->tp_basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); + type->tp_itemsize = sizeof(PyObject *); + type->tp_dealloc = (destructor)structseq_dealloc; + type->tp_repr = (reprfunc)structseq_repr; type->tp_doc = desc->doc; - type->tp_base = &PyTuple_Type; - type->tp_methods = structseq_methods; - type->tp_new = structseq_new; - type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; - type->tp_traverse = (traverseproc) structseq_traverse; - - n_members = count_members(desc, &n_unnamed_members); - members = PyMem_NEW(PyMemberDef, n_members - n_unnamed_members + 1); + type->tp_base = &PyTuple_Type; + type->tp_methods = structseq_methods; + type->tp_new = structseq_new; + type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; + type->tp_traverse = (traverseproc) structseq_traverse; + + n_members = count_members(desc, &n_unnamed_members); + members = PyMem_NEW(PyMemberDef, n_members - n_unnamed_members + 1); if (members == NULL) { PyErr_NoMemory(); return -1; } - initialize_members(desc, members, n_members); + initialize_members(desc, members, n_members); type->tp_members = members; - if (PyType_Ready(type) < 0) { - PyMem_FREE(members); + if (PyType_Ready(type) < 0) { + PyMem_FREE(members); return -1; - } + } Py_INCREF(type); - if (initialize_structseq_dict( - desc, type->tp_dict, n_members, n_unnamed_members) < 0) { - PyMem_FREE(members); - Py_DECREF(type); - return -1; - } + if (initialize_structseq_dict( + desc, type->tp_dict, n_members, n_unnamed_members) < 0) { + PyMem_FREE(members); + Py_DECREF(type); + return -1; + } return 0; } @@ -445,68 +445,68 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc) (void)PyStructSequence_InitType2(type, desc); } -PyTypeObject * +PyTypeObject * PyStructSequence_NewType(PyStructSequence_Desc *desc) { - PyMemberDef *members; - PyObject *bases; - PyTypeObject *type; - PyType_Slot slots[8]; - PyType_Spec spec; - Py_ssize_t n_members, n_unnamed_members; - - /* Initialize MemberDefs */ - n_members = count_members(desc, &n_unnamed_members); - members = PyMem_NEW(PyMemberDef, n_members - n_unnamed_members + 1); - if (members == NULL) { - PyErr_NoMemory(); + PyMemberDef *members; + PyObject *bases; + PyTypeObject *type; + PyType_Slot slots[8]; + PyType_Spec spec; + Py_ssize_t n_members, n_unnamed_members; + + /* Initialize MemberDefs */ + n_members = count_members(desc, &n_unnamed_members); + members = PyMem_NEW(PyMemberDef, n_members - n_unnamed_members + 1); + if (members == NULL) { + PyErr_NoMemory(); return NULL; - } - initialize_members(desc, members, n_members); - - /* Initialize Slots */ - slots[0] = (PyType_Slot){Py_tp_dealloc, (destructor)structseq_dealloc}; - slots[1] = (PyType_Slot){Py_tp_repr, (reprfunc)structseq_repr}; - slots[2] = (PyType_Slot){Py_tp_methods, structseq_methods}; - slots[3] = (PyType_Slot){Py_tp_new, structseq_new}; - slots[4] = (PyType_Slot){Py_tp_members, members}; - slots[5] = (PyType_Slot){Py_tp_traverse, (traverseproc)structseq_traverse}; - if (desc->doc) { - slots[6] = (PyType_Slot){Py_tp_doc, (void *)desc->doc}; - slots[7] = (PyType_Slot){0, 0}; - } - else { - slots[6] = (PyType_Slot){0, 0}; - } - - /* Initialize Spec */ - /* The name in this PyType_Spec is statically allocated so it is */ - /* expected that it'll outlive the PyType_Spec */ - spec.name = desc->name; - spec.basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); - spec.itemsize = sizeof(PyObject *); - spec.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; - spec.slots = slots; - - bases = PyTuple_Pack(1, &PyTuple_Type); - if (bases == NULL) { - PyMem_FREE(members); + } + initialize_members(desc, members, n_members); + + /* Initialize Slots */ + slots[0] = (PyType_Slot){Py_tp_dealloc, (destructor)structseq_dealloc}; + slots[1] = (PyType_Slot){Py_tp_repr, (reprfunc)structseq_repr}; + slots[2] = (PyType_Slot){Py_tp_methods, structseq_methods}; + slots[3] = (PyType_Slot){Py_tp_new, structseq_new}; + slots[4] = (PyType_Slot){Py_tp_members, members}; + slots[5] = (PyType_Slot){Py_tp_traverse, (traverseproc)structseq_traverse}; + if (desc->doc) { + slots[6] = (PyType_Slot){Py_tp_doc, (void *)desc->doc}; + slots[7] = (PyType_Slot){0, 0}; + } + else { + slots[6] = (PyType_Slot){0, 0}; + } + + /* Initialize Spec */ + /* The name in this PyType_Spec is statically allocated so it is */ + /* expected that it'll outlive the PyType_Spec */ + spec.name = desc->name; + spec.basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); + spec.itemsize = sizeof(PyObject *); + spec.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; + spec.slots = slots; + + bases = PyTuple_Pack(1, &PyTuple_Type); + if (bases == NULL) { + PyMem_FREE(members); + return NULL; + } + type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, bases); + Py_DECREF(bases); + PyMem_FREE(members); + if (type == NULL) { return NULL; } - type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, bases); - Py_DECREF(bases); - PyMem_FREE(members); - if (type == NULL) { - return NULL; - } - - if (initialize_structseq_dict( - desc, type->tp_dict, n_members, n_unnamed_members) < 0) { - Py_DECREF(type); - return NULL; - } - - return type; + + if (initialize_structseq_dict( + desc, type->tp_dict, n_members, n_unnamed_members) < 0) { + Py_DECREF(type); + return NULL; + } + + return type; } int _PyStructSequence_Init(void) diff --git a/contrib/tools/python3/src/Objects/tupleobject.c b/contrib/tools/python3/src/Objects/tupleobject.c index e6a3b5ab57..9092c9f8be 100644 --- a/contrib/tools/python3/src/Objects/tupleobject.c +++ b/contrib/tools/python3/src/Objects/tupleobject.c @@ -2,10 +2,10 @@ /* Tuple object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_accu.h" -#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() -#include "pycore_object.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_accu.h" +#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() +#include "pycore_object.h" /*[clinic input] class tuple "PyTupleObject *" "&PyTuple_Type" @@ -30,10 +30,10 @@ static PyTupleObject *free_list[PyTuple_MAXSAVESIZE]; static int numfree[PyTuple_MAXSAVESIZE]; #endif -static inline void -tuple_gc_track(PyTupleObject *op) +static inline void +tuple_gc_track(PyTupleObject *op) { - _PyObject_GC_TRACK(op); + _PyObject_GC_TRACK(op); } /* Print summary info about the state of the optimized allocator */ @@ -53,16 +53,16 @@ _PyTuple_DebugMallocStats(FILE *out) #endif } -/* Allocate an uninitialized tuple object. Before making it public following - steps must be done: - - initialize its items - - call tuple_gc_track() on it - Because the empty tuple is always reused and it's already tracked by GC, - this function must not be called with size == 0 (unless from PyTuple_New() - which wraps this function). -*/ -static PyTupleObject * -tuple_alloc(Py_ssize_t size) +/* Allocate an uninitialized tuple object. Before making it public following + steps must be done: + - initialize its items + - call tuple_gc_track() on it + Because the empty tuple is always reused and it's already tracked by GC, + this function must not be called with size == 0 (unless from PyTuple_New() + which wraps this function). +*/ +static PyTupleObject * +tuple_alloc(Py_ssize_t size) { PyTupleObject *op; if (size < 0) { @@ -71,7 +71,7 @@ tuple_alloc(Py_ssize_t size) } #if PyTuple_MAXSAVESIZE > 0 if (size < PyTuple_MAXSAVESIZE && (op = free_list[size]) != NULL) { - assert(size != 0); + assert(size != 0); free_list[size] = (PyTupleObject *) op->ob_item[0]; numfree[size]--; /* Inline PyObject_InitVar */ @@ -85,35 +85,35 @@ tuple_alloc(Py_ssize_t size) #endif { /* Check for overflow */ - if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyTupleObject) - - sizeof(PyObject *))) / sizeof(PyObject *)) { - return (PyTupleObject *)PyErr_NoMemory(); + if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyTupleObject) - + sizeof(PyObject *))) / sizeof(PyObject *)) { + return (PyTupleObject *)PyErr_NoMemory(); } op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL; } - return op; -} - -PyObject * -PyTuple_New(Py_ssize_t size) -{ - PyTupleObject *op; -#if PyTuple_MAXSAVESIZE > 0 - if (size == 0 && free_list[0]) { - op = free_list[0]; - Py_INCREF(op); - return (PyObject *) op; - } -#endif - op = tuple_alloc(size); - if (op == NULL) { - return NULL; - } - for (Py_ssize_t i = 0; i < size; i++) { + return op; +} + +PyObject * +PyTuple_New(Py_ssize_t size) +{ + PyTupleObject *op; +#if PyTuple_MAXSAVESIZE > 0 + if (size == 0 && free_list[0]) { + op = free_list[0]; + Py_INCREF(op); + return (PyObject *) op; + } +#endif + op = tuple_alloc(size); + if (op == NULL) { + return NULL; + } + for (Py_ssize_t i = 0; i < size; i++) { op->ob_item[i] = NULL; - } + } #if PyTuple_MAXSAVESIZE > 0 if (size == 0) { free_list[0] = op; @@ -121,7 +121,7 @@ PyTuple_New(Py_ssize_t size) Py_INCREF(op); /* extra INCREF so that this is never freed */ } #endif - tuple_gc_track(op); + tuple_gc_track(op); return (PyObject *) op; } @@ -154,7 +154,7 @@ int PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem) { PyObject **p; - if (!PyTuple_Check(op) || Py_REFCNT(op) != 1) { + if (!PyTuple_Check(op) || Py_REFCNT(op) != 1) { Py_XDECREF(newitem); PyErr_BadInternalCall(); return -1; @@ -200,25 +200,25 @@ PyTuple_Pack(Py_ssize_t n, ...) PyObject **items; va_list vargs; - if (n == 0) { - return PyTuple_New(0); - } - + if (n == 0) { + return PyTuple_New(0); + } + va_start(vargs, n); - PyTupleObject *result = tuple_alloc(n); + PyTupleObject *result = tuple_alloc(n); if (result == NULL) { va_end(vargs); return NULL; } - items = result->ob_item; + items = result->ob_item; for (i = 0; i < n; i++) { o = va_arg(vargs, PyObject *); Py_INCREF(o); items[i] = o; } va_end(vargs); - tuple_gc_track(result); - return (PyObject *)result; + tuple_gc_track(result); + return (PyObject *)result; } @@ -230,7 +230,7 @@ tupledealloc(PyTupleObject *op) Py_ssize_t i; Py_ssize_t len = Py_SIZE(op); PyObject_GC_UnTrack(op); - Py_TRASHCAN_BEGIN(op, tupledealloc) + Py_TRASHCAN_BEGIN(op, tupledealloc) if (len > 0) { i = len; while (--i >= 0) @@ -238,7 +238,7 @@ tupledealloc(PyTupleObject *op) #if PyTuple_MAXSAVESIZE > 0 if (len < PyTuple_MAXSAVESIZE && numfree[len] < PyTuple_MAXFREELIST && - Py_IS_TYPE(op, &PyTuple_Type)) + Py_IS_TYPE(op, &PyTuple_Type)) { op->ob_item[0] = (PyObject *) free_list[len]; numfree[len]++; @@ -248,10 +248,10 @@ tupledealloc(PyTupleObject *op) #endif } Py_TYPE(op)->tp_free((PyObject *)op); -#if PyTuple_MAXSAVESIZE > 0 +#if PyTuple_MAXSAVESIZE > 0 done: -#endif - Py_TRASHCAN_END +#endif + Py_TRASHCAN_END } static PyObject * @@ -327,59 +327,59 @@ error: } -/* Hash for tuples. This is a slightly simplified version of the xxHash - non-cryptographic hash: - - we do not use any parallellism, there is only 1 accumulator. - - we drop the final mixing since this is just a permutation of the - output space: it does not help against collisions. - - at the end, we mangle the length with a single constant. - For the xxHash specification, see - https://github.com/Cyan4973/xxHash/blob/master/doc/xxhash_spec.md - - Below are the official constants from the xxHash specification. Optimizing - compilers should emit a single "rotate" instruction for the - _PyHASH_XXROTATE() expansion. If that doesn't happen for some important - platform, the macro could be changed to expand to a platform-specific rotate - spelling instead. +/* Hash for tuples. This is a slightly simplified version of the xxHash + non-cryptographic hash: + - we do not use any parallellism, there is only 1 accumulator. + - we drop the final mixing since this is just a permutation of the + output space: it does not help against collisions. + - at the end, we mangle the length with a single constant. + For the xxHash specification, see + https://github.com/Cyan4973/xxHash/blob/master/doc/xxhash_spec.md + + Below are the official constants from the xxHash specification. Optimizing + compilers should emit a single "rotate" instruction for the + _PyHASH_XXROTATE() expansion. If that doesn't happen for some important + platform, the macro could be changed to expand to a platform-specific rotate + spelling instead. */ -#if SIZEOF_PY_UHASH_T > 4 -#define _PyHASH_XXPRIME_1 ((Py_uhash_t)11400714785074694791ULL) -#define _PyHASH_XXPRIME_2 ((Py_uhash_t)14029467366897019727ULL) -#define _PyHASH_XXPRIME_5 ((Py_uhash_t)2870177450012600261ULL) -#define _PyHASH_XXROTATE(x) ((x << 31) | (x >> 33)) /* Rotate left 31 bits */ -#else -#define _PyHASH_XXPRIME_1 ((Py_uhash_t)2654435761UL) -#define _PyHASH_XXPRIME_2 ((Py_uhash_t)2246822519UL) -#define _PyHASH_XXPRIME_5 ((Py_uhash_t)374761393UL) -#define _PyHASH_XXROTATE(x) ((x << 13) | (x >> 19)) /* Rotate left 13 bits */ -#endif - -/* Tests have shown that it's not worth to cache the hash value, see - https://bugs.python.org/issue9685 */ +#if SIZEOF_PY_UHASH_T > 4 +#define _PyHASH_XXPRIME_1 ((Py_uhash_t)11400714785074694791ULL) +#define _PyHASH_XXPRIME_2 ((Py_uhash_t)14029467366897019727ULL) +#define _PyHASH_XXPRIME_5 ((Py_uhash_t)2870177450012600261ULL) +#define _PyHASH_XXROTATE(x) ((x << 31) | (x >> 33)) /* Rotate left 31 bits */ +#else +#define _PyHASH_XXPRIME_1 ((Py_uhash_t)2654435761UL) +#define _PyHASH_XXPRIME_2 ((Py_uhash_t)2246822519UL) +#define _PyHASH_XXPRIME_5 ((Py_uhash_t)374761393UL) +#define _PyHASH_XXROTATE(x) ((x << 13) | (x >> 19)) /* Rotate left 13 bits */ +#endif + +/* Tests have shown that it's not worth to cache the hash value, see + https://bugs.python.org/issue9685 */ static Py_hash_t tuplehash(PyTupleObject *v) { - Py_ssize_t i, len = Py_SIZE(v); - PyObject **item = v->ob_item; - - Py_uhash_t acc = _PyHASH_XXPRIME_5; - for (i = 0; i < len; i++) { - Py_uhash_t lane = PyObject_Hash(item[i]); - if (lane == (Py_uhash_t)-1) { + Py_ssize_t i, len = Py_SIZE(v); + PyObject **item = v->ob_item; + + Py_uhash_t acc = _PyHASH_XXPRIME_5; + for (i = 0; i < len; i++) { + Py_uhash_t lane = PyObject_Hash(item[i]); + if (lane == (Py_uhash_t)-1) { return -1; - } - acc += lane * _PyHASH_XXPRIME_2; - acc = _PyHASH_XXROTATE(acc); - acc *= _PyHASH_XXPRIME_1; - } - - /* Add input length, mangled to keep the historical value of hash(()). */ - acc += len ^ (_PyHASH_XXPRIME_5 ^ 3527539UL); - - if (acc == (Py_uhash_t)-1) { - return 1546275796; - } - return acc; + } + acc += lane * _PyHASH_XXPRIME_2; + acc = _PyHASH_XXROTATE(acc); + acc *= _PyHASH_XXPRIME_1; + } + + /* Add input length, mangled to keep the historical value of hash(()). */ + acc += len ^ (_PyHASH_XXPRIME_5 ^ 3527539UL); + + if (acc == (Py_uhash_t)-1) { + return 1546275796; + } + return acc; } static Py_ssize_t @@ -395,7 +395,7 @@ tuplecontains(PyTupleObject *a, PyObject *el) int cmp; for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) - cmp = PyObject_RichCompareBool(PyTuple_GET_ITEM(a, i), el, Py_EQ); + cmp = PyObject_RichCompareBool(PyTuple_GET_ITEM(a, i), el, Py_EQ); return cmp; } @@ -410,27 +410,27 @@ tupleitem(PyTupleObject *a, Py_ssize_t i) return a->ob_item[i]; } -PyObject * -_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) -{ - if (n == 0) { - return PyTuple_New(0); - } - - PyTupleObject *tuple = tuple_alloc(n); - if (tuple == NULL) { - return NULL; - } - PyObject **dst = tuple->ob_item; - for (Py_ssize_t i = 0; i < n; i++) { - PyObject *item = src[i]; - Py_INCREF(item); - dst[i] = item; - } - tuple_gc_track(tuple); - return (PyObject *)tuple; -} - +PyObject * +_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + if (n == 0) { + return PyTuple_New(0); + } + + PyTupleObject *tuple = tuple_alloc(n); + if (tuple == NULL) { + return NULL; + } + PyObject **dst = tuple->ob_item; + for (Py_ssize_t i = 0; i < n; i++) { + PyObject *item = src[i]; + Py_INCREF(item); + dst[i] = item; + } + tuple_gc_track(tuple); + return (PyObject *)tuple; +} + static PyObject * tupleslice(PyTupleObject *a, Py_ssize_t ilow, Py_ssize_t ihigh) @@ -445,7 +445,7 @@ tupleslice(PyTupleObject *a, Py_ssize_t ilow, Py_INCREF(a); return (PyObject *)a; } - return _PyTuple_FromArray(a->ob_item + ilow, ihigh - ilow); + return _PyTuple_FromArray(a->ob_item + ilow, ihigh - ilow); } PyObject * @@ -483,11 +483,11 @@ tupleconcat(PyTupleObject *a, PyObject *bb) if (Py_SIZE(a) > PY_SSIZE_T_MAX - Py_SIZE(b)) return PyErr_NoMemory(); size = Py_SIZE(a) + Py_SIZE(b); - if (size == 0) { - return PyTuple_New(0); - } - - np = tuple_alloc(size); + if (size == 0) { + return PyTuple_New(0); + } + + np = tuple_alloc(size); if (np == NULL) { return NULL; } @@ -505,7 +505,7 @@ tupleconcat(PyTupleObject *a, PyObject *bb) Py_INCREF(v); dest[i] = v; } - tuple_gc_track(np); + tuple_gc_track(np); return (PyObject *)np; #undef b } @@ -525,13 +525,13 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n) return (PyObject *)a; } } - if (Py_SIZE(a) == 0 || n <= 0) { - return PyTuple_New(0); - } + if (Py_SIZE(a) == 0 || n <= 0) { + return PyTuple_New(0); + } if (n > PY_SSIZE_T_MAX / Py_SIZE(a)) return PyErr_NoMemory(); size = Py_SIZE(a) * n; - np = tuple_alloc(size); + np = tuple_alloc(size); if (np == NULL) return NULL; p = np->ob_item; @@ -543,7 +543,7 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n) p++; } } - tuple_gc_track(np); + tuple_gc_track(np); return (PyObject *) np; } @@ -709,25 +709,25 @@ tuple_new_impl(PyTypeObject *type, PyObject *iterable) } static PyObject * -tuple_vectorcall(PyObject *type, PyObject * const*args, - size_t nargsf, PyObject *kwnames) -{ - if (!_PyArg_NoKwnames("tuple", kwnames)) { - return NULL; - } - - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - if (!_PyArg_CheckPositional("tuple", nargs, 0, 1)) { - return NULL; - } - - if (nargs) { - return tuple_new_impl((PyTypeObject *)type, args[0]); - } - return PyTuple_New(0); -} - -static PyObject * +tuple_vectorcall(PyObject *type, PyObject * const*args, + size_t nargsf, PyObject *kwnames) +{ + if (!_PyArg_NoKwnames("tuple", kwnames)) { + return NULL; + } + + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + if (!_PyArg_CheckPositional("tuple", nargs, 0, 1)) { + return NULL; + } + + if (nargs) { + return tuple_new_impl((PyTypeObject *)type, args[0]); + } + return PyTuple_New(0); +} + +static PyObject * tuple_subtype_new(PyTypeObject *type, PyObject *iterable) { PyObject *tmp, *newobj, *item; @@ -739,10 +739,10 @@ tuple_subtype_new(PyTypeObject *type, PyObject *iterable) return NULL; assert(PyTuple_Check(tmp)); newobj = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp)); - if (newobj == NULL) { - Py_DECREF(tmp); + if (newobj == NULL) { + Py_DECREF(tmp); return NULL; - } + } for (i = 0; i < n; i++) { item = PyTuple_GET_ITEM(tmp, i); Py_INCREF(item); @@ -766,7 +766,7 @@ static PySequenceMethods tuple_as_sequence = { static PyObject* tuplesubscript(PyTupleObject* self, PyObject* item) { - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return NULL; @@ -775,8 +775,8 @@ tuplesubscript(PyTupleObject* self, PyObject* item) return tupleitem(self, i); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength, i; - size_t cur; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; PyObject* it; PyObject **src, **dest; @@ -796,11 +796,11 @@ tuplesubscript(PyTupleObject* self, PyObject* item) return (PyObject *)self; } else { - PyTupleObject* result = tuple_alloc(slicelength); + PyTupleObject* result = tuple_alloc(slicelength); if (!result) return NULL; src = self->ob_item; - dest = result->ob_item; + dest = result->ob_item; for (cur = start, i = 0; i < slicelength; cur += step, i++) { it = src[cur]; @@ -808,8 +808,8 @@ tuplesubscript(PyTupleObject* self, PyObject* item) dest[i] = it; } - tuple_gc_track(result); - return (PyObject *)result; + tuple_gc_track(result); + return (PyObject *)result; } } else { @@ -835,7 +835,7 @@ static PyMethodDef tuple_methods[] = { TUPLE___GETNEWARGS___METHODDEF TUPLE_INDEX_METHODDEF TUPLE_COUNT_METHODDEF - {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} /* sentinel */ }; @@ -853,10 +853,10 @@ PyTypeObject PyTuple_Type = { sizeof(PyTupleObject) - sizeof(PyObject *), sizeof(PyObject *), (destructor)tupledealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)tuplerepr, /* tp_repr */ 0, /* tp_as_number */ &tuple_as_sequence, /* tp_as_sequence */ @@ -888,7 +888,7 @@ PyTypeObject PyTuple_Type = { 0, /* tp_alloc */ tuple_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ - .tp_vectorcall = tuple_vectorcall, + .tp_vectorcall = tuple_vectorcall, }; /* The following function breaks the notion that tuples are immutable: @@ -907,7 +907,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) Py_ssize_t oldsize; v = (PyTupleObject *) *pv; - if (v == NULL || !Py_IS_TYPE(v, &PyTuple_Type) || + if (v == NULL || !Py_IS_TYPE(v, &PyTuple_Type) || (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) { *pv = 0; Py_XDECREF(v); @@ -928,15 +928,15 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) } /* XXX UNREF/NEWREF interface should be more symmetrical */ -#ifdef Py_REF_DEBUG - _Py_RefTotal--; -#endif - if (_PyObject_GC_IS_TRACKED(v)) { +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif + if (_PyObject_GC_IS_TRACKED(v)) { _PyObject_GC_UNTRACK(v); - } -#ifdef Py_TRACE_REFS + } +#ifdef Py_TRACE_REFS _Py_ForgetReference((PyObject *) v); -#endif +#endif /* DECREF items deleted by shrinkage */ for (i = newsize; i < oldsize; i++) { Py_CLEAR(v->ob_item[i]); @@ -957,33 +957,33 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) return 0; } -void -_PyTuple_ClearFreeList(void) +void +_PyTuple_ClearFreeList(void) { #if PyTuple_MAXSAVESIZE > 0 - for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) { - PyTupleObject *p = free_list[i]; + for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) { + PyTupleObject *p = free_list[i]; free_list[i] = NULL; numfree[i] = 0; while (p) { - PyTupleObject *q = p; + PyTupleObject *q = p; p = (PyTupleObject *)(p->ob_item[0]); PyObject_GC_Del(q); } } - // the empty tuple singleton is only cleared by _PyTuple_Fini() + // the empty tuple singleton is only cleared by _PyTuple_Fini() #endif } void -_PyTuple_Fini(void) +_PyTuple_Fini(void) { #if PyTuple_MAXSAVESIZE > 0 /* empty tuples are used all over the place and applications may * rely on the fact that an empty tuple is a singleton. */ Py_CLEAR(free_list[0]); - _PyTuple_ClearFreeList(); + _PyTuple_ClearFreeList(); #endif } @@ -1035,7 +1035,7 @@ tupleiter_next(tupleiterobject *it) } static PyObject * -tupleiter_len(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) +tupleiter_len(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -1046,14 +1046,14 @@ tupleiter_len(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) +tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); } static PyObject * @@ -1089,10 +1089,10 @@ PyTypeObject PyTupleIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)tupleiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/typeobject.c b/contrib/tools/python3/src/Objects/typeobject.c index b42eeb27ff..1cdf80bfcf 100644 --- a/contrib/tools/python3/src/Objects/typeobject.c +++ b/contrib/tools/python3/src/Objects/typeobject.c @@ -1,13 +1,13 @@ /* Type object implementation */ #include "Python.h" -#include "pycore_call.h" -#include "pycore_initconfig.h" -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_call.h" +#include "pycore_initconfig.h" +#include "pycore_object.h" +#include "pycore_pyerrors.h" +#include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef #include <ctype.h> @@ -19,9 +19,9 @@ class object "PyObject *" "&PyBaseObject_Type" #include "clinic/typeobject.c.h" -#define MCACHE - -#ifdef MCACHE +#define MCACHE + +#ifdef MCACHE /* Support type attribute cache */ /* The cache can keep references to the names alive for longer than @@ -50,7 +50,7 @@ struct method_cache_entry { static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP]; static unsigned int next_version_tag = 0; -#endif +#endif #define MCACHE_STATS 0 @@ -60,8 +60,8 @@ static size_t method_cache_misses = 0; static size_t method_cache_collisions = 0; #endif -#define INTERN_NAME_STRINGS - +#define INTERN_NAME_STRINGS + /* alphabetical order */ _Py_IDENTIFIER(__abstractmethods__); _Py_IDENTIFIER(__class__); @@ -80,7 +80,7 @@ _Py_IDENTIFIER(__new__); _Py_IDENTIFIER(__set_name__); _Py_IDENTIFIER(__setitem__); _Py_IDENTIFIER(builtins); -_Py_IDENTIFIER(mro); +_Py_IDENTIFIER(mro); static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -88,12 +88,12 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); static void clear_slotdefs(void); -static PyObject * -lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound); - -static int -slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value); - +static PyObject * +lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound); + +static int +slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value); + /* * finds the beginning of the docstring's introspection signature. * if present, returns a pointer pointing to the first '('. @@ -130,7 +130,7 @@ find_signature(const char *name, const char *doc) #define SIGNATURE_END_MARKER ")\n--\n\n" #define SIGNATURE_END_MARKER_LENGTH 6 /* - * skips past the end of the docstring's introspection signature. + * skips past the end of the docstring's introspection signature. * (assumes doc starts with a valid signature prefix.) */ static const char * @@ -147,27 +147,27 @@ skip_signature(const char *doc) return NULL; } -int +int _PyType_CheckConsistency(PyTypeObject *type) { -#define CHECK(expr) \ - do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0) - - CHECK(!_PyObject_IsFreed((PyObject *)type)); - +#define CHECK(expr) \ + do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0) + + CHECK(!_PyObject_IsFreed((PyObject *)type)); + if (!(type->tp_flags & Py_TPFLAGS_READY)) { - /* don't check static types before PyType_Ready() */ + /* don't check static types before PyType_Ready() */ return 1; } - CHECK(Py_REFCNT(type) >= 1); - CHECK(PyType_Check(type)); - - CHECK(!(type->tp_flags & Py_TPFLAGS_READYING)); - CHECK(type->tp_dict != NULL); - + CHECK(Py_REFCNT(type) >= 1); + CHECK(PyType_Check(type)); + + CHECK(!(type->tp_flags & Py_TPFLAGS_READYING)); + CHECK(type->tp_dict != NULL); + return 1; -#undef CHECK +#undef CHECK } static const char * @@ -220,7 +220,7 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d unsigned int PyType_ClearCache(void) { -#ifdef MCACHE +#ifdef MCACHE Py_ssize_t i; unsigned int cur_version_tag = next_version_tag - 1; @@ -245,9 +245,9 @@ PyType_ClearCache(void) /* mark all version tags as invalid */ PyType_Modified(&PyBaseObject_Type); return cur_version_tag; -#else - return 0; -#endif +#else + return 0; +#endif } void @@ -267,8 +267,8 @@ PyType_Modified(PyTypeObject *type) Invariants: - Py_TPFLAGS_VALID_VERSION_TAG is never set if - Py_TPFLAGS_HAVE_VERSION_TAG is not set (in case of a - bizarre MRO, see type_mro_modified()). + Py_TPFLAGS_HAVE_VERSION_TAG is not set (in case of a + bizarre MRO, see type_mro_modified()). - before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type, it must first be set on all super types. @@ -282,7 +282,7 @@ PyType_Modified(PyTypeObject *type) PyObject *raw, *ref; Py_ssize_t i; - if (!_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) + if (!_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) return; raw = type->tp_subclasses; @@ -309,34 +309,34 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { Unset HAVE_VERSION_TAG and VALID_VERSION_TAG if the type has a custom MRO that includes a type which is not officially - super type, or if the type implements its own mro() method. + super type, or if the type implements its own mro() method. Called from mro_internal, which will subsequently be called on each subclass when their mro is recursively updated. */ Py_ssize_t i, n; - int custom = !Py_IS_TYPE(type, &PyType_Type); - int unbound; - PyObject *mro_meth = NULL; - PyObject *type_mro_meth = NULL; + int custom = !Py_IS_TYPE(type, &PyType_Type); + int unbound; + PyObject *mro_meth = NULL; + PyObject *type_mro_meth = NULL; - if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) + if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) return; - if (custom) { - mro_meth = lookup_maybe_method( - (PyObject *)type, &PyId_mro, &unbound); - if (mro_meth == NULL) - goto clear; - type_mro_meth = lookup_maybe_method( - (PyObject *)&PyType_Type, &PyId_mro, &unbound); - if (type_mro_meth == NULL) - goto clear; - if (mro_meth != type_mro_meth) - goto clear; - Py_XDECREF(mro_meth); - Py_XDECREF(type_mro_meth); - } + if (custom) { + mro_meth = lookup_maybe_method( + (PyObject *)type, &PyId_mro, &unbound); + if (mro_meth == NULL) + goto clear; + type_mro_meth = lookup_maybe_method( + (PyObject *)&PyType_Type, &PyId_mro, &unbound); + if (type_mro_meth == NULL) + goto clear; + if (mro_meth != type_mro_meth) + goto clear; + Py_XDECREF(mro_meth); + Py_XDECREF(type_mro_meth); + } n = PyTuple_GET_SIZE(bases); for (i = 0; i < n; i++) { PyObject *b = PyTuple_GET_ITEM(bases, i); @@ -345,20 +345,20 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { assert(PyType_Check(b)); cls = (PyTypeObject *)b; - if (!_PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) || + if (!_PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) || !PyType_IsSubtype(type, cls)) { - goto clear; + goto clear; } } - return; - clear: - Py_XDECREF(mro_meth); - Py_XDECREF(type_mro_meth); - type->tp_flags &= ~(Py_TPFLAGS_HAVE_VERSION_TAG| - Py_TPFLAGS_VALID_VERSION_TAG); + return; + clear: + Py_XDECREF(mro_meth); + Py_XDECREF(type_mro_meth); + type->tp_flags &= ~(Py_TPFLAGS_HAVE_VERSION_TAG| + Py_TPFLAGS_VALID_VERSION_TAG); } -#ifdef MCACHE +#ifdef MCACHE static int assign_version_tag(PyTypeObject *type) { @@ -370,11 +370,11 @@ assign_version_tag(PyTypeObject *type) Py_ssize_t i, n; PyObject *bases; - if (_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) + if (_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) return 1; - if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) + if (!_PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG)) return 0; - if (!_PyType_HasFeature(type, Py_TPFLAGS_READY)) + if (!_PyType_HasFeature(type, Py_TPFLAGS_READY)) return 0; type->tp_version_tag = next_version_tag++; @@ -405,17 +405,17 @@ assign_version_tag(PyTypeObject *type) type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG; return 1; } -#endif +#endif static PyMemberDef type_members[] = { {"__basicsize__", T_PYSSIZET, offsetof(PyTypeObject,tp_basicsize),READONLY}, {"__itemsize__", T_PYSSIZET, offsetof(PyTypeObject, tp_itemsize), READONLY}, - {"__flags__", T_ULONG, offsetof(PyTypeObject, tp_flags), READONLY}, - {"__weakrefoffset__", T_PYSSIZET, + {"__flags__", T_ULONG, offsetof(PyTypeObject, tp_flags), READONLY}, + {"__weakrefoffset__", T_PYSSIZET, offsetof(PyTypeObject, tp_weaklistoffset), READONLY}, {"__base__", T_OBJECT, offsetof(PyTypeObject, tp_base), READONLY}, - {"__dictoffset__", T_PYSSIZET, + {"__dictoffset__", T_PYSSIZET, offsetof(PyTypeObject, tp_dictoffset), READONLY}, {"__mro__", T_OBJECT, offsetof(PyTypeObject, tp_mro), READONLY}, {0} @@ -434,19 +434,19 @@ check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *nam "can't delete %s.%s", type->tp_name, name); return 0; } - - if (PySys_Audit("object.__setattr__", "OsO", - type, name, value) < 0) { - return 0; - } - + + if (PySys_Audit("object.__setattr__", "OsO", + type, name, value) < 0) { + return 0; + } + return 1; } const char * _PyType_Name(PyTypeObject *type) { - assert(type->tp_name != NULL); + assert(type->tp_name != NULL); const char *s = strrchr(type->tp_name, '.'); if (s == NULL) { s = type->tp_name; @@ -541,11 +541,11 @@ type_module(PyTypeObject *type, void *context) PyObject *mod; if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { - mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__); + mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__); if (mod == NULL) { - if (!PyErr_Occurred()) { - PyErr_Format(PyExc_AttributeError, "__module__"); - } + if (!PyErr_Occurred()) { + PyErr_Format(PyExc_AttributeError, "__module__"); + } return NULL; } Py_INCREF(mod); @@ -584,13 +584,13 @@ type_abstractmethods(PyTypeObject *type, void *context) /* type itself has an __abstractmethods__ descriptor (this). Don't return that. */ if (type != &PyType_Type) - mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___abstractmethods__); + mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___abstractmethods__); if (!mod) { - if (!PyErr_Occurred()) { - PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__); - if (message) - PyErr_SetObject(PyExc_AttributeError, message); - } + if (!PyErr_Occurred()) { + PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__); + if (message) + PyErr_SetObject(PyExc_AttributeError, message); + } return NULL; } Py_INCREF(mod); @@ -862,12 +862,12 @@ type_get_doc(PyTypeObject *type, void *context) if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) { return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc); } - result = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__); + result = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__); if (result == NULL) { - if (!PyErr_Occurred()) { - result = Py_None; - Py_INCREF(result); - } + if (!PyErr_Occurred()) { + result = Py_None; + Py_INCREF(result); + } } else if (Py_TYPE(result)->tp_descr_get) { result = Py_TYPE(result)->tp_descr_get(result, NULL, @@ -972,47 +972,47 @@ static PyObject * type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obj; - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); #ifdef Py_DEBUG /* type_call() must not be called with an exception set, because it can clear it (directly or indirectly) and so the caller loses its exception */ - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); #endif - /* Special case: type(x) should return Py_TYPE(x) */ - /* We only want type itself to accept the one-argument form (#27157) */ - if (type == &PyType_Type) { - assert(args != NULL && PyTuple_Check(args)); - assert(kwds == NULL || PyDict_Check(kwds)); - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - - if (nargs == 1 && (kwds == NULL || !PyDict_GET_SIZE(kwds))) { - obj = (PyObject *) Py_TYPE(PyTuple_GET_ITEM(args, 0)); - Py_INCREF(obj); - return obj; - } - - /* SF bug 475327 -- if that didn't trigger, we need 3 - arguments. But PyArg_ParseTuple in type_new may give - a msg saying type() needs exactly 3. */ - if (nargs != 3) { - PyErr_SetString(PyExc_TypeError, - "type() takes 1 or 3 arguments"); - return NULL; - } - } - - if (type->tp_new == NULL) { - _PyErr_Format(tstate, PyExc_TypeError, - "cannot create '%.100s' instances", - type->tp_name); - return NULL; - } - + /* Special case: type(x) should return Py_TYPE(x) */ + /* We only want type itself to accept the one-argument form (#27157) */ + if (type == &PyType_Type) { + assert(args != NULL && PyTuple_Check(args)); + assert(kwds == NULL || PyDict_Check(kwds)); + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + + if (nargs == 1 && (kwds == NULL || !PyDict_GET_SIZE(kwds))) { + obj = (PyObject *) Py_TYPE(PyTuple_GET_ITEM(args, 0)); + Py_INCREF(obj); + return obj; + } + + /* SF bug 475327 -- if that didn't trigger, we need 3 + arguments. But PyArg_ParseTuple in type_new may give + a msg saying type() needs exactly 3. */ + if (nargs != 3) { + PyErr_SetString(PyExc_TypeError, + "type() takes 1 or 3 arguments"); + return NULL; + } + } + + if (type->tp_new == NULL) { + _PyErr_Format(tstate, PyExc_TypeError, + "cannot create '%.100s' instances", + type->tp_name); + return NULL; + } + obj = type->tp_new(type, args, kwds); - obj = _Py_CheckFunctionResult(tstate, (PyObject*)type, obj, NULL); + obj = _Py_CheckFunctionResult(tstate, (PyObject*)type, obj, NULL); if (obj == NULL) return NULL; @@ -1025,12 +1025,12 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) if (type->tp_init != NULL) { int res = type->tp_init(obj, args, kwds); if (res < 0) { - assert(_PyErr_Occurred(tstate)); + assert(_PyErr_Occurred(tstate)); Py_DECREF(obj); obj = NULL; } else { - assert(!_PyErr_Occurred(tstate)); + assert(!_PyErr_Occurred(tstate)); } } return obj; @@ -1043,29 +1043,29 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) const size_t size = _PyObject_VAR_SIZE(type, nitems+1); /* note that we need to add one, for the sentinel */ - if (_PyType_IS_GC(type)) { + if (_PyType_IS_GC(type)) { obj = _PyObject_GC_Malloc(size); - } - else { + } + else { obj = (PyObject *)PyObject_MALLOC(size); - } + } - if (obj == NULL) { + if (obj == NULL) { return PyErr_NoMemory(); - } + } memset(obj, '\0', size); - if (type->tp_itemsize == 0) { + if (type->tp_itemsize == 0) { (void)PyObject_INIT(obj, type); - } - else { + } + else { (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems); - } + } - if (_PyType_IS_GC(type)) { + if (_PyType_IS_GC(type)) { _PyObject_GC_TRACK(obj); - } + } return obj; } @@ -1125,16 +1125,16 @@ subtype_traverse(PyObject *self, visitproc visit, void *arg) Py_VISIT(*dictptr); } - if (type->tp_flags & Py_TPFLAGS_HEAPTYPE - && (!basetraverse || !(base->tp_flags & Py_TPFLAGS_HEAPTYPE))) { + if (type->tp_flags & Py_TPFLAGS_HEAPTYPE + && (!basetraverse || !(base->tp_flags & Py_TPFLAGS_HEAPTYPE))) { /* For a heaptype, the instances count as references to the type. Traverse the type so the collector - can find cycles involving this link. - Skip this visit if basetraverse belongs to a heap type: in that - case, basetraverse will visit the type when we call it later. - */ + can find cycles involving this link. + Skip this visit if basetraverse belongs to a heap type: in that + case, basetraverse will visit the type when we call it later. + */ Py_VISIT(type); - } + } if (basetraverse) return basetraverse(self, visit, arg); @@ -1200,14 +1200,14 @@ subtype_dealloc(PyObject *self) /* Extract the type; we expect it to be a heap type */ type = Py_TYPE(self); - _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); + _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); /* Test whether the type has GC exactly once */ - if (!_PyType_IS_GC(type)) { - /* A non GC dynamic type allows certain simplifications: - there's no need to call clear_slots(), or DECREF the dict, - or clear weakrefs. */ + if (!_PyType_IS_GC(type)) { + /* A non GC dynamic type allows certain simplifications: + there's no need to call clear_slots(), or DECREF the dict, + or clear weakrefs. */ /* Maybe call finalizer; exit early if resurrected */ if (type->tp_finalize) { @@ -1216,9 +1216,9 @@ subtype_dealloc(PyObject *self) } if (type->tp_del) { type->tp_del(self); - if (Py_REFCNT(self) > 0) { + if (Py_REFCNT(self) > 0) { return; - } + } } /* Find the nearest base with a different tp_dealloc */ @@ -1231,22 +1231,22 @@ subtype_dealloc(PyObject *self) /* Extract the type again; tp_del may have changed it */ type = Py_TYPE(self); - // Don't read type memory after calling basedealloc() since basedealloc() - // can deallocate the type and free its memory. - int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE - && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE)); - + // Don't read type memory after calling basedealloc() since basedealloc() + // can deallocate the type and free its memory. + int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE + && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE)); + /* Call the base tp_dealloc() */ assert(basedealloc); basedealloc(self); - /* Can't reference self beyond this point. It's possible tp_del switched - our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about - reference counting. Only decref if the base type is not already a heap - allocated type. Otherwise, basedealloc should have decref'd it already */ - if (type_needs_decref) { - Py_DECREF(type); - } + /* Can't reference self beyond this point. It's possible tp_del switched + our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about + reference counting. Only decref if the base type is not already a heap + allocated type. Otherwise, basedealloc should have decref'd it already */ + if (type_needs_decref) { + Py_DECREF(type); + } /* Done */ return; @@ -1257,7 +1257,7 @@ subtype_dealloc(PyObject *self) /* UnTrack and re-Track around the trashcan macro, alas */ /* See explanation at end of function for full disclosure */ PyObject_GC_UnTrack(self); - Py_TRASHCAN_BEGIN(self, subtype_dealloc); + Py_TRASHCAN_BEGIN(self, subtype_dealloc); /* Find the nearest base with a different tp_dealloc */ base = type; @@ -1291,7 +1291,7 @@ subtype_dealloc(PyObject *self) if (type->tp_del) { _PyObject_GC_TRACK(self); type->tp_del(self); - if (Py_REFCNT(self) > 0) { + if (Py_REFCNT(self) > 0) { /* Resurrected */ goto endlabel; } @@ -1305,7 +1305,7 @@ subtype_dealloc(PyObject *self) if (type->tp_weaklistoffset && !base->tp_weaklistoffset) { /* Modeled after GET_WEAKREFS_LISTPTR() */ PyWeakReference **list = (PyWeakReference **) \ - _PyObject_GET_WEAKREFS_LISTPTR(self); + _PyObject_GET_WEAKREFS_LISTPTR(self); while (*list) _PyWeakref_ClearRef(*list); } @@ -1338,28 +1338,28 @@ subtype_dealloc(PyObject *self) /* Call the base tp_dealloc(); first retrack self if * basedealloc knows about gc. */ - if (_PyType_IS_GC(base)) { + if (_PyType_IS_GC(base)) { _PyObject_GC_TRACK(self); - } - - // Don't read type memory after calling basedealloc() since basedealloc() - // can deallocate the type and free its memory. - int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE - && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE)); - + } + + // Don't read type memory after calling basedealloc() since basedealloc() + // can deallocate the type and free its memory. + int type_needs_decref = (type->tp_flags & Py_TPFLAGS_HEAPTYPE + && !(base->tp_flags & Py_TPFLAGS_HEAPTYPE)); + assert(basedealloc); basedealloc(self); /* Can't reference self beyond this point. It's possible tp_del switched our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about - reference counting. Only decref if the base type is not already a heap - allocated type. Otherwise, basedealloc should have decref'd it already */ - if (type_needs_decref) { - Py_DECREF(type); - } + reference counting. Only decref if the base type is not already a heap + allocated type. Otherwise, basedealloc should have decref'd it already */ + if (type_needs_decref) { + Py_DECREF(type); + } endlabel: - Py_TRASHCAN_END + Py_TRASHCAN_END /* Explanation of the weirdness around the trashcan macros: @@ -1434,7 +1434,7 @@ PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) return 0; } else - /* a is not completely initialized yet; follow tp_base */ + /* a is not completely initialized yet; follow tp_base */ return type_is_subtype_base_chain(a, b); } @@ -1477,7 +1477,7 @@ lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound) return NULL; } - if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) { + if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) { /* Avoid temporary PyMethodObject */ *unbound = 1; Py_INCREF(res); @@ -1500,77 +1500,77 @@ lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound) { PyObject *res = lookup_maybe_method(self, attrid, unbound); if (res == NULL && !PyErr_Occurred()) { - PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid)); + PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid)); } return res; } - -static inline PyObject* -vectorcall_unbound(PyThreadState *tstate, int unbound, PyObject *func, - PyObject *const *args, Py_ssize_t nargs) + +static inline PyObject* +vectorcall_unbound(PyThreadState *tstate, int unbound, PyObject *func, + PyObject *const *args, Py_ssize_t nargs) { - size_t nargsf = nargs; - if (!unbound) { - /* Skip self argument, freeing up args[0] to use for - * PY_VECTORCALL_ARGUMENTS_OFFSET */ - args++; - nargsf = nargsf - 1 + PY_VECTORCALL_ARGUMENTS_OFFSET; + size_t nargsf = nargs; + if (!unbound) { + /* Skip self argument, freeing up args[0] to use for + * PY_VECTORCALL_ARGUMENTS_OFFSET */ + args++; + nargsf = nargsf - 1 + PY_VECTORCALL_ARGUMENTS_OFFSET; } - return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL); + return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL); } static PyObject* call_unbound_noarg(int unbound, PyObject *func, PyObject *self) { if (unbound) { - return PyObject_CallOneArg(func, self); + return PyObject_CallOneArg(func, self); } else { return _PyObject_CallNoArg(func); } } -/* A variation of PyObject_CallMethod* that uses lookup_method() - instead of PyObject_GetAttrString(). - - args is an argument vector of length nargs. The first element in this - vector is the special object "self" which is used for the method lookup */ +/* A variation of PyObject_CallMethod* that uses lookup_method() + instead of PyObject_GetAttrString(). + + args is an argument vector of length nargs. The first element in this + vector is the special object "self" which is used for the method lookup */ static PyObject * -vectorcall_method(_Py_Identifier *name, - PyObject *const *args, Py_ssize_t nargs) +vectorcall_method(_Py_Identifier *name, + PyObject *const *args, Py_ssize_t nargs) { - assert(nargs >= 1); - - PyThreadState *tstate = _PyThreadState_GET(); + assert(nargs >= 1); + + PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *self = args[0]; - PyObject *func = lookup_method(self, name, &unbound); + PyObject *self = args[0]; + PyObject *func = lookup_method(self, name, &unbound); if (func == NULL) { return NULL; } - PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs); + PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs); Py_DECREF(func); return retval; } -/* Clone of vectorcall_method() that returns NotImplemented - * when the lookup fails. */ +/* Clone of vectorcall_method() that returns NotImplemented + * when the lookup fails. */ static PyObject * -vectorcall_maybe(PyThreadState *tstate, _Py_Identifier *name, - PyObject *const *args, Py_ssize_t nargs) +vectorcall_maybe(PyThreadState *tstate, _Py_Identifier *name, + PyObject *const *args, Py_ssize_t nargs) { - assert(nargs >= 1); - + assert(nargs >= 1); + int unbound; - PyObject *self = args[0]; - PyObject *func = lookup_maybe_method(self, name, &unbound); + PyObject *self = args[0]; + PyObject *func = lookup_maybe_method(self, name, &unbound); if (func == NULL) { if (!PyErr_Occurred()) Py_RETURN_NOTIMPLEMENTED; return NULL; } - PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs); + PyObject *retval = vectorcall_unbound(tstate, unbound, func, args, nargs); Py_DECREF(func); return retval; } @@ -1619,8 +1619,8 @@ tail_contains(PyObject *tuple, int whence, PyObject *o) static PyObject * class_name(PyObject *cls) { - PyObject *name; - if (_PyObject_LookupAttrId(cls, &PyId___name__, &name) == 0) { + PyObject *name; + if (_PyObject_LookupAttrId(cls, &PyId___name__, &name) == 0) { name = PyObject_Repr(cls); } return name; @@ -1640,14 +1640,14 @@ check_duplicates(PyObject *tuple) if (PyTuple_GET_ITEM(tuple, j) == o) { o = class_name(o); if (o != NULL) { - if (PyUnicode_Check(o)) { - PyErr_Format(PyExc_TypeError, - "duplicate base class %U", o); - } - else { - PyErr_SetString(PyExc_TypeError, - "duplicate base class"); - } + if (PyUnicode_Check(o)) { + PyErr_Format(PyExc_TypeError, + "duplicate base class %U", o); + } + else { + PyErr_SetString(PyExc_TypeError, + "duplicate base class"); + } Py_DECREF(o); } return -1; @@ -1692,20 +1692,20 @@ consistent method resolution\norder (MRO) for bases"); i = 0; while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) { PyObject *name = class_name(k); - const char *name_str = NULL; + const char *name_str = NULL; if (name != NULL) { - if (PyUnicode_Check(name)) { - name_str = PyUnicode_AsUTF8(name); - } - else { + if (PyUnicode_Check(name)) { + name_str = PyUnicode_AsUTF8(name); + } + else { name_str = "?"; - } - } - if (name_str == NULL) { - Py_XDECREF(name); - Py_DECREF(set); - return; - } + } + } + if (name_str == NULL) { + Py_XDECREF(name); + Py_DECREF(set); + return; + } off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", name_str); Py_XDECREF(name); if (--n && (size_t)(off+1) < sizeof(buf)) { @@ -1948,7 +1948,7 @@ mro_invoke(PyTypeObject *type) { PyObject *mro_result; PyObject *new_mro; - const int custom = !Py_IS_TYPE(type, &PyType_Type); + const int custom = !Py_IS_TYPE(type, &PyType_Type); if (custom) { int unbound; @@ -2068,7 +2068,7 @@ best_base(PyObject *bases) if (PyType_Ready(base_i) < 0) return NULL; } - if (!_PyType_HasFeature(base_i, Py_TPFLAGS_BASETYPE)) { + if (!_PyType_HasFeature(base_i, Py_TPFLAGS_BASETYPE)) { PyErr_Format(PyExc_TypeError, "type '%.100s' is not an acceptable base type", base_i->tp_name); @@ -2248,19 +2248,19 @@ subtype_getweakref(PyObject *obj, void *context) { PyObject **weaklistptr; PyObject *result; - PyTypeObject *type = Py_TYPE(obj); + PyTypeObject *type = Py_TYPE(obj); - if (type->tp_weaklistoffset == 0) { + if (type->tp_weaklistoffset == 0) { PyErr_SetString(PyExc_AttributeError, "This object has no __weakref__"); return NULL; } - _PyObject_ASSERT((PyObject *)type, - type->tp_weaklistoffset > 0); - _PyObject_ASSERT((PyObject *)type, - ((type->tp_weaklistoffset + sizeof(PyObject *)) - <= (size_t)(type->tp_basicsize))); - weaklistptr = (PyObject **)((char *)obj + type->tp_weaklistoffset); + _PyObject_ASSERT((PyObject *)type, + type->tp_weaklistoffset > 0); + _PyObject_ASSERT((PyObject *)type, + ((type->tp_weaklistoffset + sizeof(PyObject *)) + <= (size_t)(type->tp_basicsize))); + weaklistptr = (PyObject **)((char *)obj + type->tp_weaklistoffset); if (*weaklistptr == NULL) result = Py_None; else @@ -2464,16 +2464,16 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; /* Check for a __slots__ sequence variable in dict, and count it */ - slots = _PyDict_GetItemIdWithError(dict, &PyId___slots__); + slots = _PyDict_GetItemIdWithError(dict, &PyId___slots__); nslots = 0; add_dict = 0; add_weak = 0; may_add_dict = base->tp_dictoffset == 0; may_add_weak = base->tp_weaklistoffset == 0 && base->tp_itemsize == 0; if (slots == NULL) { - if (PyErr_Occurred()) { - goto error; - } + if (PyErr_Occurred()) { + goto error; + } if (may_add_dict) { add_dict++; } @@ -2550,7 +2550,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; } PyList_SET_ITEM(newslots, j, tmp); - if (PyDict_GetItemWithError(dict, tmp)) { + if (PyDict_GetItemWithError(dict, tmp)) { /* CPython inserts __qualname__ and __classcell__ (when needed) into the namespace when creating a class. They will be deleted below so won't act as class variables. */ @@ -2563,10 +2563,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; } } - else if (PyErr_Occurred()) { - Py_DECREF(newslots); - goto error; - } + else if (PyErr_Occurred()) { + Py_DECREF(newslots); + goto error; + } j++; } assert(j == nslots - add_dict - add_weak); @@ -2620,10 +2620,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) slots = NULL; /* Initialize tp_flags */ - // All heap types need GC, since we can create a reference cycle by storing - // an instance on one of its parents: + // All heap types need GC, since we can create a reference cycle by storing + // an instance on one of its parents: type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | - Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC; + Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC; /* Initialize essential fields */ type->tp_as_async = &et->as_async; @@ -2651,28 +2651,28 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) type->tp_dict = dict; /* Set __module__ in the dict */ - if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) { - if (PyErr_Occurred()) { - goto error; - } + if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) { + if (PyErr_Occurred()) { + goto error; + } tmp = PyEval_GetGlobals(); if (tmp != NULL) { - tmp = _PyDict_GetItemIdWithError(tmp, &PyId___name__); + tmp = _PyDict_GetItemIdWithError(tmp, &PyId___name__); if (tmp != NULL) { if (_PyDict_SetItemId(dict, &PyId___module__, tmp) < 0) goto error; } - else if (PyErr_Occurred()) { - goto error; - } + else if (PyErr_Occurred()) { + goto error; + } } } /* Set ht_qualname to dict['__qualname__'] if available, else to __name__. The __qualname__ accessor will look for ht_qualname. */ - qualname = _PyDict_GetItemIdWithError(dict, &PyId___qualname__); + qualname = _PyDict_GetItemIdWithError(dict, &PyId___qualname__); if (qualname != NULL) { if (!PyUnicode_Check(qualname)) { PyErr_Format(PyExc_TypeError, @@ -2681,23 +2681,23 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; } } - else if (PyErr_Occurred()) { - goto error; - } + else if (PyErr_Occurred()) { + goto error; + } et->ht_qualname = qualname ? qualname : et->ht_name; Py_INCREF(et->ht_qualname); if (qualname != NULL && _PyDict_DelItemId(dict, &PyId___qualname__) < 0) goto error; - /* Set ht_module */ - et->ht_module = NULL; - + /* Set ht_module */ + et->ht_module = NULL; + /* Set tp_doc to a copy of dict['__doc__'], if the latter is there and is a string. The __doc__ accessor will first look for tp_doc; if that fails, it will still look into __dict__. */ { - PyObject *doc = _PyDict_GetItemIdWithError(dict, &PyId___doc__); + PyObject *doc = _PyDict_GetItemIdWithError(dict, &PyId___doc__); if (doc != NULL && PyUnicode_Check(doc)) { Py_ssize_t len; const char *doc_str; @@ -2716,14 +2716,14 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) memcpy(tp_doc, doc_str, len + 1); type->tp_doc = tp_doc; } - else if (doc == NULL && PyErr_Occurred()) { - goto error; - } + else if (doc == NULL && PyErr_Occurred()) { + goto error; + } } /* Special-case __new__: if it's a plain function, make it a static function */ - tmp = _PyDict_GetItemIdWithError(dict, &PyId___new__); + tmp = _PyDict_GetItemIdWithError(dict, &PyId___new__); if (tmp != NULL && PyFunction_Check(tmp)) { tmp = PyStaticMethod_New(tmp); if (tmp == NULL) @@ -2734,13 +2734,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) } Py_DECREF(tmp); } - else if (tmp == NULL && PyErr_Occurred()) { - goto error; - } + else if (tmp == NULL && PyErr_Occurred()) { + goto error; + } /* Special-case __init_subclass__ and __class_getitem__: if they are plain functions, make them classmethods */ - tmp = _PyDict_GetItemIdWithError(dict, &PyId___init_subclass__); + tmp = _PyDict_GetItemIdWithError(dict, &PyId___init_subclass__); if (tmp != NULL && PyFunction_Check(tmp)) { tmp = PyClassMethod_New(tmp); if (tmp == NULL) @@ -2751,11 +2751,11 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) } Py_DECREF(tmp); } - else if (tmp == NULL && PyErr_Occurred()) { - goto error; - } + else if (tmp == NULL && PyErr_Occurred()) { + goto error; + } - tmp = _PyDict_GetItemIdWithError(dict, &PyId___class_getitem__); + tmp = _PyDict_GetItemIdWithError(dict, &PyId___class_getitem__); if (tmp != NULL && PyFunction_Check(tmp)) { tmp = PyClassMethod_New(tmp); if (tmp == NULL) @@ -2766,9 +2766,9 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) } Py_DECREF(tmp); } - else if (tmp == NULL && PyErr_Occurred()) { - goto error; - } + else if (tmp == NULL && PyErr_Occurred()) { + goto error; + } /* Add descriptors for custom slots from __slots__, or for __dict__ */ mp = PyHeapType_GET_MEMBERS(et); @@ -2825,12 +2825,12 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) /* Always override allocation strategy to use regular heap */ type->tp_alloc = PyType_GenericAlloc; - type->tp_free = PyObject_GC_Del; - type->tp_traverse = subtype_traverse; - type->tp_clear = subtype_clear; + type->tp_free = PyObject_GC_Del; + type->tp_traverse = subtype_traverse; + type->tp_clear = subtype_clear; /* store type in class' cell if one is supplied */ - cell = _PyDict_GetItemIdWithError(dict, &PyId___classcell__); + cell = _PyDict_GetItemIdWithError(dict, &PyId___classcell__); if (cell != NULL) { /* At least one method requires a reference to its defining class */ if (!PyCell_Check(cell)) { @@ -2840,13 +2840,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) goto error; } PyCell_Set(cell, (PyObject *) type); - if (_PyDict_DelItemId(dict, &PyId___classcell__) < 0) { - goto error; - } + if (_PyDict_DelItemId(dict, &PyId___classcell__) < 0) { + goto error; + } + } + else if (PyErr_Occurred()) { + goto error; } - else if (PyErr_Occurred()) { - goto error; - } /* Initialize the rest */ if (PyType_Ready(type) < 0) @@ -2884,52 +2884,52 @@ static const short slotoffsets[] = { PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { - return PyType_FromModuleAndSpec(NULL, spec, bases); -} - -PyObject * -PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) -{ - PyHeapTypeObject *res; - PyObject *modname; + return PyType_FromModuleAndSpec(NULL, spec, bases); +} + +PyObject * +PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) +{ + PyHeapTypeObject *res; + PyObject *modname; PyTypeObject *type, *base; - - const PyType_Slot *slot; - Py_ssize_t nmembers, weaklistoffset, dictoffset, vectorcalloffset; - char *res_start; - - nmembers = weaklistoffset = dictoffset = vectorcalloffset = 0; - for (slot = spec->slots; slot->slot; slot++) { - if (slot->slot == Py_tp_members) { - nmembers = 0; - for (const PyMemberDef *memb = slot->pfunc; memb->name != NULL; memb++) { - nmembers++; - if (strcmp(memb->name, "__weaklistoffset__") == 0) { - // The PyMemberDef must be a Py_ssize_t and readonly - assert(memb->type == T_PYSSIZET); - assert(memb->flags == READONLY); - weaklistoffset = memb->offset; - } - if (strcmp(memb->name, "__dictoffset__") == 0) { - // The PyMemberDef must be a Py_ssize_t and readonly - assert(memb->type == T_PYSSIZET); - assert(memb->flags == READONLY); - dictoffset = memb->offset; - } - if (strcmp(memb->name, "__vectorcalloffset__") == 0) { - // The PyMemberDef must be a Py_ssize_t and readonly - assert(memb->type == T_PYSSIZET); - assert(memb->flags == READONLY); - vectorcalloffset = memb->offset; - } - } - } - } - - res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, nmembers); + + const PyType_Slot *slot; + Py_ssize_t nmembers, weaklistoffset, dictoffset, vectorcalloffset; + char *res_start; + + nmembers = weaklistoffset = dictoffset = vectorcalloffset = 0; + for (slot = spec->slots; slot->slot; slot++) { + if (slot->slot == Py_tp_members) { + nmembers = 0; + for (const PyMemberDef *memb = slot->pfunc; memb->name != NULL; memb++) { + nmembers++; + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + // The PyMemberDef must be a Py_ssize_t and readonly + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + weaklistoffset = memb->offset; + } + if (strcmp(memb->name, "__dictoffset__") == 0) { + // The PyMemberDef must be a Py_ssize_t and readonly + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + dictoffset = memb->offset; + } + if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + // The PyMemberDef must be a Py_ssize_t and readonly + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + vectorcalloffset = memb->offset; + } + } + } + } + + res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, nmembers); if (res == NULL) return NULL; - res_start = (char*)res; + res_start = (char*)res; if (spec->name == NULL) { PyErr_SetString(PyExc_SystemError, @@ -2938,9 +2938,9 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set the type name and qualname */ - const char *s = strrchr(spec->name, '.'); + const char *s = strrchr(spec->name, '.'); if (s == NULL) - s = spec->name; + s = spec->name; else s++; @@ -2954,9 +2954,9 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) Py_INCREF(res->ht_qualname); type->tp_name = spec->name; - Py_XINCREF(module); - res->ht_module = module; - + Py_XINCREF(module); + res->ht_module = module; + /* Adjust for empty tuple bases */ if (!bases) { base = &PyBaseObject_Type; @@ -2968,38 +2968,38 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) bases = slot->pfunc; } } - if (!bases) { + if (!bases) { bases = PyTuple_Pack(1, base); - if (!bases) - goto fail; - } - else if (!PyTuple_Check(bases)) { - PyErr_SetString(PyExc_SystemError, "Py_tp_bases is not a tuple"); + if (!bases) + goto fail; + } + else if (!PyTuple_Check(bases)) { + PyErr_SetString(PyExc_SystemError, "Py_tp_bases is not a tuple"); goto fail; - } - else { - Py_INCREF(bases); - } - } - else if (!PyTuple_Check(bases)) { - PyErr_SetString(PyExc_SystemError, "bases is not a tuple"); - goto fail; - } - else { + } + else { + Py_INCREF(bases); + } + } + else if (!PyTuple_Check(bases)) { + PyErr_SetString(PyExc_SystemError, "bases is not a tuple"); + goto fail; + } + else { Py_INCREF(bases); - } + } /* Calculate best base, and check that all bases are type objects */ base = best_base(bases); if (base == NULL) { - Py_DECREF(bases); + Py_DECREF(bases); goto fail; } - if (!_PyType_HasFeature(base, Py_TPFLAGS_BASETYPE)) { + if (!_PyType_HasFeature(base, Py_TPFLAGS_BASETYPE)) { PyErr_Format(PyExc_TypeError, "type '%.100s' is not an acceptable base type", base->tp_name); - Py_DECREF(bases); + Py_DECREF(bases); goto fail; } @@ -3023,34 +3023,34 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyErr_SetString(PyExc_RuntimeError, "invalid slot offset"); goto fail; } - else if (slot->slot == Py_tp_base || slot->slot == Py_tp_bases) { + else if (slot->slot == Py_tp_base || slot->slot == Py_tp_bases) { /* Processed above */ continue; - } - else if (slot->slot == Py_tp_doc) { - /* For the docstring slot, which usually points to a static string - literal, we need to make a copy */ + } + else if (slot->slot == Py_tp_doc) { + /* For the docstring slot, which usually points to a static string + literal, we need to make a copy */ const char *old_doc = _PyType_DocWithoutSignature(type->tp_name, slot->pfunc); size_t len = strlen(old_doc)+1; char *tp_doc = PyObject_MALLOC(len); if (tp_doc == NULL) { - type->tp_doc = NULL; + type->tp_doc = NULL; PyErr_NoMemory(); goto fail; } memcpy(tp_doc, old_doc, len); type->tp_doc = tp_doc; } - else if (slot->slot == Py_tp_members) { - /* Move the slots to the heap type itself */ - size_t len = Py_TYPE(type)->tp_itemsize * nmembers; - memcpy(PyHeapType_GET_MEMBERS(res), slot->pfunc, len); - type->tp_members = PyHeapType_GET_MEMBERS(res); - } - else { - /* Copy other slots directly */ - *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; - } + else if (slot->slot == Py_tp_members) { + /* Move the slots to the heap type itself */ + size_t len = Py_TYPE(type)->tp_itemsize * nmembers; + memcpy(PyHeapType_GET_MEMBERS(res), slot->pfunc, len); + type->tp_members = PyHeapType_GET_MEMBERS(res); + } + else { + /* Copy other slots directly */ + *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; + } } if (type->tp_dealloc == NULL) { /* It's a heap type, so needs the heap types' dealloc. @@ -3059,10 +3059,10 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) type->tp_dealloc = subtype_dealloc; } - if (vectorcalloffset) { - type->tp_vectorcall_offset = vectorcalloffset; - } - + if (vectorcalloffset) { + type->tp_vectorcall_offset = vectorcalloffset; + } + if (PyType_Ready(type) < 0) goto fail; @@ -3070,40 +3070,40 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) res->ht_cached_keys = _PyDict_NewKeysForClass(); } - if (weaklistoffset) { - type->tp_weaklistoffset = weaklistoffset; - if (PyDict_DelItemString((PyObject *)type->tp_dict, "__weaklistoffset__") < 0) - goto fail; - } - if (dictoffset) { - type->tp_dictoffset = dictoffset; - if (PyDict_DelItemString((PyObject *)type->tp_dict, "__dictoffset__") < 0) - goto fail; - } - + if (weaklistoffset) { + type->tp_weaklistoffset = weaklistoffset; + if (PyDict_DelItemString((PyObject *)type->tp_dict, "__weaklistoffset__") < 0) + goto fail; + } + if (dictoffset) { + type->tp_dictoffset = dictoffset; + if (PyDict_DelItemString((PyObject *)type->tp_dict, "__dictoffset__") < 0) + goto fail; + } + /* Set type.__module__ */ - if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__) == NULL) { - if (PyErr_Occurred()) { + if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__) == NULL) { + if (PyErr_Occurred()) { goto fail; } - s = strrchr(spec->name, '.'); - if (s != NULL) { - int err; - modname = PyUnicode_FromStringAndSize( - spec->name, (Py_ssize_t)(s - spec->name)); - if (modname == NULL) { - goto fail; - } - err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); - Py_DECREF(modname); - if (err != 0) - goto fail; - } else { - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "builtin type %.200s has no __module__ attribute", - spec->name)) - goto fail; - } + s = strrchr(spec->name, '.'); + if (s != NULL) { + int err; + modname = PyUnicode_FromStringAndSize( + spec->name, (Py_ssize_t)(s - spec->name)); + if (modname == NULL) { + goto fail; + } + err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); + Py_DECREF(modname); + if (err != 0) + goto fail; + } else { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "builtin type %.200s has no __module__ attribute", + spec->name)) + goto fail; + } } return (PyObject*)res; @@ -3119,18 +3119,18 @@ PyType_FromSpec(PyType_Spec *spec) return PyType_FromSpecWithBases(spec, NULL); } -/* private in 3.10 and 3.9.8+; public in 3.11 */ -PyObject * -_PyType_GetQualName(PyTypeObject *type) -{ - return type_qualname(type, NULL); -} - - +/* private in 3.10 and 3.9.8+; public in 3.11 */ +PyObject * +_PyType_GetQualName(PyTypeObject *type) +{ + return type_qualname(type, NULL); +} + + void * PyType_GetSlot(PyTypeObject *type, int slot) { - if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE) || slot < 0) { + if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE) || slot < 0) { PyErr_BadInternalCall(); return NULL; } @@ -3141,40 +3141,40 @@ PyType_GetSlot(PyTypeObject *type, int slot) return *(void**)(((char*)type) + slotoffsets[slot]); } -PyObject * -PyType_GetModule(PyTypeObject *type) -{ - assert(PyType_Check(type)); - if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) { - PyErr_Format( - PyExc_TypeError, - "PyType_GetModule: Type '%s' is not a heap type", - type->tp_name); - return NULL; - } - - PyHeapTypeObject* et = (PyHeapTypeObject*)type; - if (!et->ht_module) { - PyErr_Format( - PyExc_TypeError, - "PyType_GetModule: Type '%s' has no associated module", - type->tp_name); - return NULL; - } - return et->ht_module; - -} - -void * -PyType_GetModuleState(PyTypeObject *type) -{ - PyObject *m = PyType_GetModule(type); - if (m == NULL) { - return NULL; - } - return PyModule_GetState(m); -} - +PyObject * +PyType_GetModule(PyTypeObject *type) +{ + assert(PyType_Check(type)); + if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) { + PyErr_Format( + PyExc_TypeError, + "PyType_GetModule: Type '%s' is not a heap type", + type->tp_name); + return NULL; + } + + PyHeapTypeObject* et = (PyHeapTypeObject*)type; + if (!et->ht_module) { + PyErr_Format( + PyExc_TypeError, + "PyType_GetModule: Type '%s' has no associated module", + type->tp_name); + return NULL; + } + return et->ht_module; + +} + +void * +PyType_GetModuleState(PyTypeObject *type) +{ + PyObject *m = PyType_GetModule(type); + if (m == NULL) { + return NULL; + } + return PyModule_GetState(m); +} + /* Internal API to look for a name through the MRO, bypassing the method cache. This returns a borrowed reference, and might set an exception. 'error' is set to: -1: error with exception; 1: error without exception; 0: ok */ @@ -3245,11 +3245,11 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) PyObject *res; int error; -#ifdef MCACHE +#ifdef MCACHE if (MCACHE_CACHEABLE_NAME(name) && - _PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) { + _PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) { /* fast path */ - unsigned int h = MCACHE_HASH_METHOD(type, name); + unsigned int h = MCACHE_HASH_METHOD(type, name); if (method_cache[h].version == type->tp_version_tag && method_cache[h].name == name) { #if MCACHE_STATS @@ -3258,7 +3258,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) return method_cache[h].value; } } -#endif +#endif /* We may end up clearing live exceptions below, so make sure it's ours. */ assert(!PyErr_Occurred()); @@ -3280,9 +3280,9 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) return NULL; } -#ifdef MCACHE +#ifdef MCACHE if (MCACHE_CACHEABLE_NAME(name) && assign_version_tag(type)) { - unsigned int h = MCACHE_HASH_METHOD(type, name); + unsigned int h = MCACHE_HASH_METHOD(type, name); method_cache[h].version = type->tp_version_tag; method_cache[h].value = res; /* borrowed */ Py_INCREF(name); @@ -3295,7 +3295,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name) #endif Py_SETREF(method_cache[h].name, name); } -#endif +#endif return res; } @@ -3309,24 +3309,24 @@ _PyType_LookupId(PyTypeObject *type, struct _Py_Identifier *name) return _PyType_Lookup(type, oname); } -/* Check if the "readied" PyUnicode name - is a double-underscore special name. */ -static int -is_dunder_name(PyObject *name) -{ - Py_ssize_t length = PyUnicode_GET_LENGTH(name); - int kind = PyUnicode_KIND(name); - /* Special names contain at least "__x__" and are always ASCII. */ - if (length > 4 && kind == PyUnicode_1BYTE_KIND) { - const Py_UCS1 *characters = PyUnicode_1BYTE_DATA(name); - return ( - ((characters[length-2] == '_') && (characters[length-1] == '_')) && - ((characters[0] == '_') && (characters[1] == '_')) - ); - } - return 0; -} - +/* Check if the "readied" PyUnicode name + is a double-underscore special name. */ +static int +is_dunder_name(PyObject *name) +{ + Py_ssize_t length = PyUnicode_GET_LENGTH(name); + int kind = PyUnicode_KIND(name); + /* Special names contain at least "__x__" and are always ASCII. */ + if (length > 4 && kind == PyUnicode_1BYTE_KIND) { + const Py_UCS1 *characters = PyUnicode_1BYTE_DATA(name); + return ( + ((characters[length-2] == '_') && (characters[length-1] == '_')) && + ((characters[0] == '_') && (characters[1] == '_')) + ); + } + return 0; +} + /* This is similar to PyObject_GenericGetAttr(), but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ static PyObject * @@ -3340,7 +3340,7 @@ type_getattro(PyTypeObject *type, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - Py_TYPE(name)->tp_name); + Py_TYPE(name)->tp_name); return NULL; } @@ -3438,17 +3438,17 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value) if (name == NULL) return -1; } -#ifdef INTERN_NAME_STRINGS +#ifdef INTERN_NAME_STRINGS if (!PyUnicode_CHECK_INTERNED(name)) { - PyUnicode_InternInPlace(&name); - if (!PyUnicode_CHECK_INTERNED(name)) { - PyErr_SetString(PyExc_MemoryError, - "Out of memory interning an attribute name"); - Py_DECREF(name); - return -1; - } + PyUnicode_InternInPlace(&name); + if (!PyUnicode_CHECK_INTERNED(name)) { + PyErr_SetString(PyExc_MemoryError, + "Out of memory interning an attribute name"); + Py_DECREF(name); + return -1; + } } -#endif +#endif } else { /* Will fail in _PyObject_GenericSetAttrWithDict. */ @@ -3456,16 +3456,16 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value) } res = _PyObject_GenericSetAttrWithDict((PyObject *)type, name, value, NULL); if (res == 0) { - /* Clear the VALID_VERSION flag of 'type' and all its - subclasses. This could possibly be unified with the - update_subclasses() recursion in update_slot(), but carefully: - they each have their own conditions on which to stop - recursing into subclasses. */ - PyType_Modified(type); - - if (is_dunder_name(name)) { - res = update_slot(type, name); - } + /* Clear the VALID_VERSION flag of 'type' and all its + subclasses. This could possibly be unified with the + update_subclasses() recursion in update_slot(), but carefully: + they each have their own conditions on which to stop + recursing into subclasses. */ + PyType_Modified(type); + + if (is_dunder_name(name)) { + res = update_slot(type, name); + } assert(_PyType_CheckConsistency(type)); } Py_DECREF(name); @@ -3482,7 +3482,7 @@ type_dealloc(PyTypeObject *type) PyObject *tp, *val, *tb; /* Assert this is a heap-allocated type object */ - _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); + _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); _PyObject_GC_UNTRACK(type); PyErr_Fetch(&tp, &val, &tb); remove_all_subclasses(type, type->tp_bases); @@ -3502,10 +3502,10 @@ type_dealloc(PyTypeObject *type) Py_XDECREF(et->ht_name); Py_XDECREF(et->ht_qualname); Py_XDECREF(et->ht_slots); - if (et->ht_cached_keys) { + if (et->ht_cached_keys) { _PyDictKeys_DecRef(et->ht_cached_keys); - } - Py_XDECREF(et->ht_module); + } + Py_XDECREF(et->ht_module); Py_TYPE(type)->tp_free((PyObject *)type); } @@ -3569,10 +3569,10 @@ merge_class_dict(PyObject *dict, PyObject *aclass) assert(aclass); /* Merge in the type's dict (if any). */ - if (_PyObject_LookupAttrId(aclass, &PyId___dict__, &classdict) < 0) { - return -1; - } - if (classdict != NULL) { + if (_PyObject_LookupAttrId(aclass, &PyId___dict__, &classdict) < 0) { + return -1; + } + if (classdict != NULL) { int status = PyDict_Update(dict, classdict); Py_DECREF(classdict); if (status < 0) @@ -3580,17 +3580,17 @@ merge_class_dict(PyObject *dict, PyObject *aclass) } /* Recursively merge in the base types' (if any) dicts. */ - if (_PyObject_LookupAttrId(aclass, &PyId___bases__, &bases) < 0) { - return -1; - } - if (bases != NULL) { + if (_PyObject_LookupAttrId(aclass, &PyId___bases__, &bases) < 0) { + return -1; + } + if (bases != NULL) { /* We have no guarantee that bases is a real tuple */ Py_ssize_t i, n; n = PySequence_Size(bases); /* This better be right */ - if (n < 0) { - Py_DECREF(bases); - return -1; - } + if (n < 0) { + Py_DECREF(bases); + return -1; + } else { for (i = 0; i < n; i++) { int status; @@ -3661,7 +3661,7 @@ type___sizeof___impl(PyTypeObject *self) static PyMethodDef type_methods[] = { TYPE_MRO_METHODDEF TYPE___SUBCLASSES___METHODDEF - {"__prepare__", (PyCFunction)(void(*)(void))type_prepare, + {"__prepare__", (PyCFunction)(void(*)(void))type_prepare, METH_FASTCALL | METH_KEYWORDS | METH_CLASS, PyDoc_STR("__prepare__() -> dict\n" "used to create the namespace for the class statement")}, @@ -3674,7 +3674,7 @@ static PyMethodDef type_methods[] = { PyDoc_STRVAR(type_doc, "type(object) -> the object's type\n" -"type(name, bases, dict, **kwds) -> a new type"); +"type(name, bases, dict, **kwds) -> a new type"); static int type_traverse(PyTypeObject *type, visitproc visit, void *arg) @@ -3683,9 +3683,9 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg) for heaptypes. */ if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { char msg[200]; - sprintf(msg, "type_traverse() called on non-heap type '%.100s'", + sprintf(msg, "type_traverse() called on non-heap type '%.100s'", type->tp_name); - _PyObject_ASSERT_FAILED_MSG((PyObject *)type, msg); + _PyObject_ASSERT_FAILED_MSG((PyObject *)type, msg); } Py_VISIT(type->tp_dict); @@ -3693,7 +3693,7 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg) Py_VISIT(type->tp_mro); Py_VISIT(type->tp_bases); Py_VISIT(type->tp_base); - Py_VISIT(((PyHeapTypeObject *)type)->ht_module); + Py_VISIT(((PyHeapTypeObject *)type)->ht_module); /* There's no need to visit type->tp_subclasses or ((PyHeapTypeObject *)type)->ht_slots, because they can't be involved @@ -3709,19 +3709,19 @@ type_clear(PyTypeObject *type) PyDictKeysObject *cached_keys; /* Because of type_is_gc(), the collector only calls this for heaptypes. */ - _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); + _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); /* We need to invalidate the method cache carefully before clearing the dict, so that other objects caught in a reference cycle don't start calling destroyed methods. - Otherwise, the we need to clear tp_mro, which is + Otherwise, the we need to clear tp_mro, which is part of a hard cycle (its first element is the class itself) that won't be broken otherwise (it's a tuple and tuples don't have a - tp_clear handler). - We also need to clear ht_module, if present: the module usually holds a - reference to its class. None of the other fields need to be - + tp_clear handler). + We also need to clear ht_module, if present: the module usually holds a + reference to its class. None of the other fields need to be + cleared, and here's why: tp_cache: @@ -3746,11 +3746,11 @@ type_clear(PyTypeObject *type) ((PyHeapTypeObject *)type)->ht_cached_keys = NULL; _PyDictKeys_DecRef(cached_keys); } - if (type->tp_dict) { + if (type->tp_dict) { PyDict_Clear(type->tp_dict); - } - Py_CLEAR(((PyHeapTypeObject *)type)->ht_module); - + } + Py_CLEAR(((PyHeapTypeObject *)type)->ht_module); + Py_CLEAR(type->tp_mro); return 0; @@ -3768,10 +3768,10 @@ PyTypeObject PyType_Type = { sizeof(PyHeapTypeObject), /* tp_basicsize */ sizeof(PyMemberDef), /* tp_itemsize */ (destructor)type_dealloc, /* tp_dealloc */ - offsetof(PyTypeObject, tp_vectorcall), /* tp_vectorcall_offset */ + offsetof(PyTypeObject, tp_vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)type_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -3783,8 +3783,8 @@ PyTypeObject PyType_Type = { (setattrofunc)type_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS | - Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ + Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS | + Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ type_doc, /* tp_doc */ (traverseproc)type_traverse, /* tp_traverse */ (inquiry)type_clear, /* tp_clear */ @@ -3898,46 +3898,46 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) { - PyObject *abstract_methods; - PyObject *sorted_methods; - PyObject *joined; + PyObject *abstract_methods; + PyObject *sorted_methods; + PyObject *joined; PyObject *comma; _Py_static_string(comma_id, ", "); - Py_ssize_t method_count; + Py_ssize_t method_count; /* Compute ", ".join(sorted(type.__abstractmethods__)) into joined. */ abstract_methods = type_abstractmethods(type, NULL); if (abstract_methods == NULL) - return NULL; - sorted_methods = PySequence_List(abstract_methods); - Py_DECREF(abstract_methods); + return NULL; + sorted_methods = PySequence_List(abstract_methods); + Py_DECREF(abstract_methods); if (sorted_methods == NULL) - return NULL; - if (PyList_Sort(sorted_methods)) { - Py_DECREF(sorted_methods); - return NULL; - } + return NULL; + if (PyList_Sort(sorted_methods)) { + Py_DECREF(sorted_methods); + return NULL; + } comma = _PyUnicode_FromId(&comma_id); - if (comma == NULL) { - Py_DECREF(sorted_methods); - return NULL; - } + if (comma == NULL) { + Py_DECREF(sorted_methods); + return NULL; + } joined = PyUnicode_Join(comma, sorted_methods); - method_count = PyObject_Length(sorted_methods); - Py_DECREF(sorted_methods); + method_count = PyObject_Length(sorted_methods); + Py_DECREF(sorted_methods); if (joined == NULL) - return NULL; - if (method_count == -1) - return NULL; + return NULL; + if (method_count == -1) + return NULL; PyErr_Format(PyExc_TypeError, "Can't instantiate abstract class %s " - "with abstract method%s %U", + "with abstract method%s %U", type->tp_name, - method_count > 1 ? "s" : "", + method_count > 1 ? "s" : "", joined); - Py_DECREF(joined); + Py_DECREF(joined); return NULL; } return type->tp_alloc(type, 0); @@ -4007,12 +4007,12 @@ object_richcompare(PyObject *self, PyObject *other, int op) case Py_NE: /* By default, __ne__() delegates to __eq__() and inverts the result, unless the latter returns NotImplemented. */ - if (Py_TYPE(self)->tp_richcompare == NULL) { + if (Py_TYPE(self)->tp_richcompare == NULL) { res = Py_NotImplemented; Py_INCREF(res); break; } - res = (*Py_TYPE(self)->tp_richcompare)(self, other, Py_EQ); + res = (*Py_TYPE(self)->tp_richcompare)(self, other, Py_EQ); if (res != NULL && res != Py_NotImplemented) { int ok = PyObject_IsTrue(res); Py_DECREF(res); @@ -4150,11 +4150,11 @@ object_set_class(PyObject *self, PyObject *value, void *closure) Py_TYPE(value)->tp_name); return -1; } - if (PySys_Audit("object.__setattr__", "OsO", - self, "__class__", value) < 0) { - return -1; - } - + if (PySys_Audit("object.__setattr__", "OsO", + self, "__class__", value) < 0) { + return -1; + } + newto = (PyTypeObject *)value; /* In versions of CPython prior to 3.5, the code in compatible_for_assignment was not set up to correctly check for memory @@ -4216,10 +4216,10 @@ object_set_class(PyObject *self, PyObject *value, void *closure) } if (compatible_for_assignment(oldto, newto, "__class__")) { - if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE) { + if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE) { Py_INCREF(newto); - } - Py_SET_TYPE(self, newto); + } + Py_SET_TYPE(self, newto); if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE) Py_DECREF(oldto); return 0; @@ -4306,8 +4306,8 @@ _PyType_GetSlotNames(PyTypeObject *cls) /* Use _slotnames function from the copyreg module to find the slots by this class and its bases. This function will cache the result in __slotnames__. */ - slotnames = _PyObject_CallMethodIdOneArg(copyreg, &PyId__slotnames, - (PyObject *)cls); + slotnames = _PyObject_CallMethodIdOneArg(copyreg, &PyId__slotnames, + (PyObject *)cls); Py_DECREF(copyreg); if (slotnames == NULL) return NULL; @@ -4335,9 +4335,9 @@ _PyObject_GetState(PyObject *obj, int required) if (getstate == NULL) { PyObject *slotnames; - if (required && Py_TYPE(obj)->tp_itemsize) { + if (required && Py_TYPE(obj)->tp_itemsize) { PyErr_Format(PyExc_TypeError, - "cannot pickle '%.200s' object", + "cannot pickle '%.200s' object", Py_TYPE(obj)->tp_name); return NULL; } @@ -4368,17 +4368,17 @@ _PyObject_GetState(PyObject *obj, int required) assert(slotnames == Py_None || PyList_Check(slotnames)); if (required) { Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize; - if (Py_TYPE(obj)->tp_dictoffset) + if (Py_TYPE(obj)->tp_dictoffset) basicsize += sizeof(PyObject *); - if (Py_TYPE(obj)->tp_weaklistoffset) + if (Py_TYPE(obj)->tp_weaklistoffset) basicsize += sizeof(PyObject *); if (slotnames != Py_None) basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames); - if (Py_TYPE(obj)->tp_basicsize > basicsize) { + if (Py_TYPE(obj)->tp_basicsize > basicsize) { Py_DECREF(slotnames); Py_DECREF(state); PyErr_Format(PyExc_TypeError, - "cannot pickle '%.200s' object", + "cannot pickle '%.200s' object", Py_TYPE(obj)->tp_name); return NULL; } @@ -4586,7 +4586,7 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems, PyObject *items; _Py_IDENTIFIER(items); - items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items); + items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items); if (items == NULL) { Py_CLEAR(*listitems); return -1; @@ -4615,7 +4615,7 @@ reduce_newobj(PyObject *obj) if (Py_TYPE(obj)->tp_new == NULL) { PyErr_Format(PyExc_TypeError, - "cannot pickle '%.200s' object", + "cannot pickle '%.200s' object", Py_TYPE(obj)->tp_name); return NULL; } @@ -4774,10 +4774,10 @@ object___reduce_ex___impl(PyObject *self, int protocol) &PyId___reduce__); } - if (_PyObject_LookupAttrId(self, &PyId___reduce__, &reduce) < 0) { - return NULL; - } - if (reduce != NULL) { + if (_PyObject_LookupAttrId(self, &PyId___reduce__, &reduce) < 0) { + return NULL; + } + if (reduce != NULL) { PyObject *cls, *clsreduce; int override; @@ -4845,7 +4845,7 @@ object___format___impl(PyObject *self, PyObject *format_spec) if (PyUnicode_GET_LENGTH(format_spec) > 0) { PyErr_Format(PyExc_TypeError, "unsupported format string passed to %.200s.__format__", - Py_TYPE(self)->tp_name); + Py_TYPE(self)->tp_name); return NULL; } return PyObject_Str(self); @@ -4864,10 +4864,10 @@ object___sizeof___impl(PyObject *self) Py_ssize_t res, isize; res = 0; - isize = Py_TYPE(self)->tp_itemsize; + isize = Py_TYPE(self)->tp_itemsize; if (isize > 0) res = Py_SIZE(self) * isize; - res += Py_TYPE(self)->tp_basicsize; + res += Py_TYPE(self)->tp_basicsize; return PyLong_FromSsize_t(res); } @@ -4890,9 +4890,9 @@ object___dir___impl(PyObject *self) PyObject *itsclass = NULL; /* Get __dict__ (which may or may not be a real dict...) */ - if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { - return NULL; - } + if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { + return NULL; + } if (dict == NULL) { dict = PyDict_New(); } @@ -4911,13 +4911,13 @@ object___dir___impl(PyObject *self) goto error; /* Merge in attrs reachable from its class. */ - if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) { + if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) { + goto error; + } + /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no + __class__ exists? */ + if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0) goto error; - } - /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no - __class__ exists? */ - if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0) - goto error; result = PyDict_Keys(dict); /* fall through */ @@ -4940,11 +4940,11 @@ static PyMethodDef object_methods[] = { {0} }; -PyDoc_STRVAR(object_doc, -"object()\n--\n\n" -"The base class of the class hierarchy.\n\n" -"When called, it accepts no arguments and returns a new featureless\n" -"instance that has no instance attributes and cannot be given any.\n"); +PyDoc_STRVAR(object_doc, +"object()\n--\n\n" +"The base class of the class hierarchy.\n\n" +"When called, it accepts no arguments and returns a new featureless\n" +"instance that has no instance attributes and cannot be given any.\n"); PyTypeObject PyBaseObject_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) @@ -4952,10 +4952,10 @@ PyTypeObject PyBaseObject_Type = { sizeof(PyObject), /* tp_basicsize */ 0, /* tp_itemsize */ object_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ object_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -4967,7 +4967,7 @@ PyTypeObject PyBaseObject_Type = { PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - object_doc, /* tp_doc */ + object_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ object_richcompare, /* tp_richcompare */ @@ -4995,7 +4995,7 @@ static int add_methods(PyTypeObject *type, PyMethodDef *meth) { PyObject *dict = type->tp_dict; - PyObject *name; + PyObject *name; for (; meth->ml_name != NULL; meth++) { PyObject *descr; @@ -5010,7 +5010,7 @@ add_methods(PyTypeObject *type, PyMethodDef *meth) descr = PyDescr_NewClassMethod(type, meth); } else if (meth->ml_flags & METH_STATIC) { - PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL); + PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL); if (cfunc == NULL) return -1; descr = PyStaticMethod_New(cfunc); @@ -5022,37 +5022,37 @@ add_methods(PyTypeObject *type, PyMethodDef *meth) } if (descr == NULL) return -1; - + if (isdescr) { - name = PyDescr_NAME(descr); + name = PyDescr_NAME(descr); } else { - name = PyUnicode_FromString(meth->ml_name); - if (name == NULL) { - Py_DECREF(descr); - return -1; - } - } - - if (!(meth->ml_flags & METH_COEXIST)) { - if (PyDict_GetItemWithError(dict, name)) { - if (!isdescr) { - Py_DECREF(name); - } - Py_DECREF(descr); - continue; - } - else if (PyErr_Occurred()) { - if (!isdescr) { - Py_DECREF(name); - } - return -1; - } - } - err = PyDict_SetItem(dict, name, descr); - if (!isdescr) { - Py_DECREF(name); - } + name = PyUnicode_FromString(meth->ml_name); + if (name == NULL) { + Py_DECREF(descr); + return -1; + } + } + + if (!(meth->ml_flags & METH_COEXIST)) { + if (PyDict_GetItemWithError(dict, name)) { + if (!isdescr) { + Py_DECREF(name); + } + Py_DECREF(descr); + continue; + } + else if (PyErr_Occurred()) { + if (!isdescr) { + Py_DECREF(name); + } + return -1; + } + } + err = PyDict_SetItem(dict, name, descr); + if (!isdescr) { + Py_DECREF(name); + } Py_DECREF(descr); if (err < 0) return -1; @@ -5066,18 +5066,18 @@ add_members(PyTypeObject *type, PyMemberDef *memb) PyObject *dict = type->tp_dict; for (; memb->name != NULL; memb++) { - PyObject *descr = PyDescr_NewMember(type, memb); + PyObject *descr = PyDescr_NewMember(type, memb); if (descr == NULL) return -1; - - if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) { - Py_DECREF(descr); - continue; - } - else if (PyErr_Occurred()) { - Py_DECREF(descr); - return -1; - } + + if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) { + Py_DECREF(descr); + continue; + } + else if (PyErr_Occurred()) { + Py_DECREF(descr); + return -1; + } if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) { Py_DECREF(descr); return -1; @@ -5093,18 +5093,18 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp) PyObject *dict = type->tp_dict; for (; gsp->name != NULL; gsp++) { - PyObject *descr = PyDescr_NewGetSet(type, gsp); + PyObject *descr = PyDescr_NewGetSet(type, gsp); if (descr == NULL) return -1; - - if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) { - Py_DECREF(descr); - continue; - } - else if (PyErr_Occurred()) { - Py_DECREF(descr); - return -1; - } + + if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) { + Py_DECREF(descr); + continue; + } + else if (PyErr_Occurred()) { + Py_DECREF(descr); + return -1; + } if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) { Py_DECREF(descr); return -1; @@ -5118,7 +5118,7 @@ static void inherit_special(PyTypeObject *type, PyTypeObject *base) { - /* Copying tp_traverse and tp_clear is connected to the GC flags */ + /* Copying tp_traverse and tp_clear is connected to the GC flags */ if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) && (base->tp_flags & Py_TPFLAGS_HAVE_GC) && (!type->tp_traverse && !type->tp_clear)) { @@ -5313,22 +5313,22 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base) } COPYSLOT(tp_repr); /* tp_hash see tp_richcompare */ - { - /* Always inherit tp_vectorcall_offset to support PyVectorcall_Call(). - * If Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall - * won't be used automatically. */ - COPYSLOT(tp_vectorcall_offset); - - /* Inherit Py_TPFLAGS_HAVE_VECTORCALL for non-heap types - * if tp_call is not overridden */ - if (!type->tp_call && - (base->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) && - !(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) - { - type->tp_flags |= Py_TPFLAGS_HAVE_VECTORCALL; - } - COPYSLOT(tp_call); - } + { + /* Always inherit tp_vectorcall_offset to support PyVectorcall_Call(). + * If Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall + * won't be used automatically. */ + COPYSLOT(tp_vectorcall_offset); + + /* Inherit Py_TPFLAGS_HAVE_VECTORCALL for non-heap types + * if tp_call is not overridden */ + if (!type->tp_call && + (base->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) && + !(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) + { + type->tp_flags |= Py_TPFLAGS_HAVE_VECTORCALL; + } + COPYSLOT(tp_call); + } COPYSLOT(tp_str); { /* Copy comparison-related slots only when @@ -5347,21 +5347,21 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base) } { COPYSLOT(tp_descr_get); - /* Inherit Py_TPFLAGS_METHOD_DESCRIPTOR if tp_descr_get was inherited, - * but only for extension types */ - if (base->tp_descr_get && - type->tp_descr_get == base->tp_descr_get && - !(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && - (base->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR)) - { - type->tp_flags |= Py_TPFLAGS_METHOD_DESCRIPTOR; - } + /* Inherit Py_TPFLAGS_METHOD_DESCRIPTOR if tp_descr_get was inherited, + * but only for extension types */ + if (base->tp_descr_get && + type->tp_descr_get == base->tp_descr_get && + !(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && + (base->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR)) + { + type->tp_flags |= Py_TPFLAGS_METHOD_DESCRIPTOR; + } COPYSLOT(tp_descr_set); COPYSLOT(tp_dictoffset); COPYSLOT(tp_init); COPYSLOT(tp_alloc); COPYSLOT(tp_is_gc); - COPYSLOT(tp_finalize); + COPYSLOT(tp_finalize); if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) == (base->tp_flags & Py_TPFLAGS_HAVE_GC)) { /* They agree about gc. */ @@ -5396,23 +5396,23 @@ PyType_Ready(PyTypeObject *type) assert(_PyType_CheckConsistency(type)); return 0; } - _PyObject_ASSERT((PyObject *)type, - (type->tp_flags & Py_TPFLAGS_READYING) == 0); - - /* Consistency checks for PEP 590: - * - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get - * - Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and - * tp_vectorcall_offset > 0 - * To avoid mistakes, we require this before inheriting. - */ - if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) { - _PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL); - } - if (type->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) { - _PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0); - _PyObject_ASSERT((PyObject *)type, type->tp_call != NULL); - } - + _PyObject_ASSERT((PyObject *)type, + (type->tp_flags & Py_TPFLAGS_READYING) == 0); + + /* Consistency checks for PEP 590: + * - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get + * - Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and + * tp_vectorcall_offset > 0 + * To avoid mistakes, we require this before inheriting. + */ + if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) { + _PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL); + } + if (type->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) { + _PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0); + _PyObject_ASSERT((PyObject *)type, type->tp_call != NULL); + } + type->tp_flags |= Py_TPFLAGS_READYING; #ifdef Py_TRACE_REFS @@ -5454,9 +5454,9 @@ PyType_Ready(PyTypeObject *type) NULL when type is &PyBaseObject_Type, and we know its ob_type is not NULL (it's initialized to &PyType_Type). But coverity doesn't know that. */ - if (Py_IS_TYPE(type, NULL) && base != NULL) { - Py_SET_TYPE(type, Py_TYPE(base)); - } + if (Py_IS_TYPE(type, NULL) && base != NULL) { + Py_SET_TYPE(type, Py_TYPE(base)); + } /* Initialize tp_bases */ bases = type->tp_bases; @@ -5529,7 +5529,7 @@ PyType_Ready(PyTypeObject *type) } /* Sanity check for tp_free. */ - if (_PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) && + if (_PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) && (type->tp_free == NULL || type->tp_free == PyObject_Del)) { /* This base class needs to call tp_free, but doesn't have * one, or its tp_free is for non-gc'ed objects. @@ -5544,10 +5544,10 @@ PyType_Ready(PyTypeObject *type) /* if the type dictionary doesn't contain a __doc__, set it from the tp_doc slot. */ - if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__) == NULL) { - if (PyErr_Occurred()) { - goto error; - } + if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__) == NULL) { + if (PyErr_Occurred()) { + goto error; + } if (type->tp_doc != NULL) { const char *old_doc = _PyType_DocWithoutSignature(type->tp_name, type->tp_doc); @@ -5573,12 +5573,12 @@ PyType_Ready(PyTypeObject *type) This signals that __hash__ is not inherited. */ if (type->tp_hash == NULL) { - if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___hash__) == NULL) { - if (PyErr_Occurred() || - _PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0) - { + if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___hash__) == NULL) { + if (PyErr_Occurred() || + _PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0) + { goto error; - } + } type->tp_hash = PyObject_HashNotImplemented; } } @@ -5707,7 +5707,7 @@ check_num_args(PyObject *ob, int n) return 1; PyErr_Format( PyExc_TypeError, - "expected %d argument%s, got %zd", n, n == 1 ? "" : "s", PyTuple_GET_SIZE(ob)); + "expected %d argument%s, got %zd", n, n == 1 ? "" : "s", PyTuple_GET_SIZE(ob)); return 0; } @@ -5730,7 +5730,7 @@ wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped) res = (*func)(self); if (res == -1 && PyErr_Occurred()) return NULL; - return PyLong_FromSsize_t(res); + return PyLong_FromSsize_t(res); } static PyObject * @@ -5966,51 +5966,51 @@ wrap_delitem(PyObject *self, PyObject *args, void *wrapped) } /* Helper to check for object.__setattr__ or __delattr__ applied to a type. - This is called the Carlo Verre hack after its discoverer. See - https://mail.python.org/pipermail/python-dev/2003-April/034535.html - */ + This is called the Carlo Verre hack after its discoverer. See + https://mail.python.org/pipermail/python-dev/2003-April/034535.html + */ static int hackcheck(PyObject *self, setattrofunc func, const char *what) { PyTypeObject *type = Py_TYPE(self); - PyObject *mro = type->tp_mro; - if (!mro) { - /* Probably ok not to check the call in this case. */ - return 1; - } - assert(PyTuple_Check(mro)); - - /* Find the (base) type that defined the type's slot function. */ - PyTypeObject *defining_type = type; - Py_ssize_t i; - for (i = PyTuple_GET_SIZE(mro) - 1; i >= 0; i--) { - PyTypeObject *base = (PyTypeObject*) PyTuple_GET_ITEM(mro, i); - if (base->tp_setattro == slot_tp_setattro) { - /* Ignore Python classes: - they never define their own C-level setattro. */ - } - else if (base->tp_setattro == type->tp_setattro) { - defining_type = base; - break; - } - } - - /* Reject calls that jump over intermediate C-level overrides. */ - for (PyTypeObject *base = defining_type; base; base = base->tp_base) { - if (base->tp_setattro == func) { - /* 'func' is the right slot function to call. */ - break; - } - else if (base->tp_setattro != slot_tp_setattro) { - /* 'base' is not a Python class and overrides 'func'. - Its tp_setattro should be called instead. */ - PyErr_Format(PyExc_TypeError, - "can't apply this %s to %s object", - what, - type->tp_name); - return 0; - } - } + PyObject *mro = type->tp_mro; + if (!mro) { + /* Probably ok not to check the call in this case. */ + return 1; + } + assert(PyTuple_Check(mro)); + + /* Find the (base) type that defined the type's slot function. */ + PyTypeObject *defining_type = type; + Py_ssize_t i; + for (i = PyTuple_GET_SIZE(mro) - 1; i >= 0; i--) { + PyTypeObject *base = (PyTypeObject*) PyTuple_GET_ITEM(mro, i); + if (base->tp_setattro == slot_tp_setattro) { + /* Ignore Python classes: + they never define their own C-level setattro. */ + } + else if (base->tp_setattro == type->tp_setattro) { + defining_type = base; + break; + } + } + + /* Reject calls that jump over intermediate C-level overrides. */ + for (PyTypeObject *base = defining_type; base; base = base->tp_base) { + if (base->tp_setattro == func) { + /* 'func' is the right slot function to call. */ + break; + } + else if (base->tp_setattro != slot_tp_setattro) { + /* 'base' is not a Python class and overrides 'func'. + Its tp_setattro should be called instead. */ + PyErr_Format(PyExc_TypeError, + "can't apply this %s to %s object", + what, + type->tp_name); + return 0; + } + } return 1; } @@ -6192,12 +6192,12 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds) PyTypeObject *type, *subtype, *staticbase; PyObject *arg0, *res; - if (self == NULL || !PyType_Check(self)) { - PyErr_Format(PyExc_SystemError, - "__new__() called with non-type 'self'"); - return NULL; - } - + if (self == NULL || !PyType_Check(self)) { + PyErr_Format(PyExc_SystemError, + "__new__() called with non-type 'self'"); + return NULL; + } + type = (PyTypeObject *)self; if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) { PyErr_Format(PyExc_TypeError, @@ -6250,7 +6250,7 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds) } static struct PyMethodDef tp_new_methoddef[] = { - {"__new__", (PyCFunction)(void(*)(void))tp_new_wrapper, METH_VARARGS|METH_KEYWORDS, + {"__new__", (PyCFunction)(void(*)(void))tp_new_wrapper, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("__new__($type, *args, **kwargs)\n--\n\n" "Create and return a new object. " "See help(type) for accurate signature.")}, @@ -6262,10 +6262,10 @@ add_tp_new_wrapper(PyTypeObject *type) { PyObject *func; - if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___new__) != NULL) + if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___new__) != NULL) return 0; - if (PyErr_Occurred()) - return -1; + if (PyErr_Occurred()) + return -1; func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL); if (func == NULL) return -1; @@ -6284,18 +6284,18 @@ add_tp_new_wrapper(PyTypeObject *type) static PyObject * \ FUNCNAME(PyObject *self) \ { \ - PyObject* stack[1] = {self}; \ + PyObject* stack[1] = {self}; \ _Py_static_string(id, OPSTR); \ - return vectorcall_method(&id, stack, 1); \ + return vectorcall_method(&id, stack, 1); \ } #define SLOT1(FUNCNAME, OPSTR, ARG1TYPE) \ static PyObject * \ FUNCNAME(PyObject *self, ARG1TYPE arg1) \ { \ - PyObject* stack[2] = {self, arg1}; \ + PyObject* stack[2] = {self, arg1}; \ _Py_static_string(id, OPSTR); \ - return vectorcall_method(&id, stack, 2); \ + return vectorcall_method(&id, stack, 2); \ } /* Boolean helper for SLOT1BINFULL(). @@ -6306,18 +6306,18 @@ method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *nam PyObject *a, *b; int ok; - if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(right)), name, &b) < 0) { - return -1; - } + if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(right)), name, &b) < 0) { + return -1; + } if (b == NULL) { /* If right doesn't have it, it's not overloaded */ return 0; } - if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(left)), name, &a) < 0) { - Py_DECREF(b); - return -1; - } + if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(left)), name, &a) < 0) { + Py_DECREF(b); + return -1; + } if (a == NULL) { Py_DECREF(b); /* If right has it but left doesn't, it's overloaded */ @@ -6335,43 +6335,43 @@ method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *nam static PyObject * \ FUNCNAME(PyObject *self, PyObject *other) \ { \ - PyObject* stack[2]; \ - PyThreadState *tstate = _PyThreadState_GET(); \ + PyObject* stack[2]; \ + PyThreadState *tstate = _PyThreadState_GET(); \ _Py_static_string(op_id, OPSTR); \ _Py_static_string(rop_id, ROPSTR); \ - int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ + int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ Py_TYPE(other)->tp_as_number != NULL && \ Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ if (Py_TYPE(self)->tp_as_number != NULL && \ Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \ PyObject *r; \ - if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \ - int ok = method_is_overloaded(self, other, &rop_id); \ - if (ok < 0) { \ - return NULL; \ - } \ - if (ok) { \ - stack[0] = other; \ - stack[1] = self; \ - r = vectorcall_maybe(tstate, &rop_id, stack, 2); \ - if (r != Py_NotImplemented) \ - return r; \ - Py_DECREF(r); \ - do_other = 0; \ - } \ + if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \ + int ok = method_is_overloaded(self, other, &rop_id); \ + if (ok < 0) { \ + return NULL; \ + } \ + if (ok) { \ + stack[0] = other; \ + stack[1] = self; \ + r = vectorcall_maybe(tstate, &rop_id, stack, 2); \ + if (r != Py_NotImplemented) \ + return r; \ + Py_DECREF(r); \ + do_other = 0; \ + } \ } \ - stack[0] = self; \ - stack[1] = other; \ - r = vectorcall_maybe(tstate, &op_id, stack, 2); \ + stack[0] = self; \ + stack[1] = other; \ + r = vectorcall_maybe(tstate, &op_id, stack, 2); \ if (r != Py_NotImplemented || \ - Py_IS_TYPE(other, Py_TYPE(self))) \ + Py_IS_TYPE(other, Py_TYPE(self))) \ return r; \ Py_DECREF(r); \ } \ if (do_other) { \ - stack[0] = other; \ - stack[1] = self; \ - return vectorcall_maybe(tstate, &rop_id, stack, 2); \ + stack[0] = other; \ + stack[1] = self; \ + return vectorcall_maybe(tstate, &rop_id, stack, 2); \ } \ Py_RETURN_NOTIMPLEMENTED; \ } @@ -6382,8 +6382,8 @@ FUNCNAME(PyObject *self, PyObject *other) \ static Py_ssize_t slot_sq_length(PyObject *self) { - PyObject* stack[1] = {self}; - PyObject *res = vectorcall_method(&PyId___len__, stack, 1); + PyObject* stack[1] = {self}; + PyObject *res = vectorcall_method(&PyId___len__, stack, 1); Py_ssize_t len; if (res == NULL) @@ -6414,8 +6414,8 @@ slot_sq_item(PyObject *self, Py_ssize_t i) if (ival == NULL) { return NULL; } - PyObject *stack[2] = {self, ival}; - PyObject *retval = vectorcall_method(&PyId___getitem__, stack, 2); + PyObject *stack[2] = {self, ival}; + PyObject *retval = vectorcall_method(&PyId___getitem__, stack, 2); Py_DECREF(ival); return retval; } @@ -6423,7 +6423,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i) static int slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) { - PyObject *stack[3]; + PyObject *stack[3]; PyObject *res; PyObject *index_obj; @@ -6432,14 +6432,14 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) return -1; } - stack[0] = self; - stack[1] = index_obj; + stack[0] = self; + stack[1] = index_obj; if (value == NULL) { - res = vectorcall_method(&PyId___delitem__, stack, 2); + res = vectorcall_method(&PyId___delitem__, stack, 2); } else { - stack[2] = value; - res = vectorcall_method(&PyId___setitem__, stack, 3); + stack[2] = value; + res = vectorcall_method(&PyId___setitem__, stack, 3); } Py_DECREF(index_obj); @@ -6453,7 +6453,7 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) static int slot_sq_contains(PyObject *self, PyObject *value) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *res; int result = -1, unbound; _Py_IDENTIFIER(__contains__); @@ -6467,8 +6467,8 @@ slot_sq_contains(PyObject *self, PyObject *value) return -1; } if (func != NULL) { - PyObject *args[2] = {self, value}; - res = vectorcall_unbound(tstate, unbound, func, args, 2); + PyObject *args[2] = {self, value}; + res = vectorcall_unbound(tstate, unbound, func, args, 2); Py_DECREF(func); if (res != NULL) { result = PyObject_IsTrue(res); @@ -6490,17 +6490,17 @@ SLOT1(slot_mp_subscript, "__getitem__", PyObject *) static int slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) { - PyObject *stack[3]; + PyObject *stack[3]; PyObject *res; - stack[0] = self; - stack[1] = key; + stack[0] = self; + stack[1] = key; if (value == NULL) { - res = vectorcall_method(&PyId___delitem__, stack, 2); + res = vectorcall_method(&PyId___delitem__, stack, 2); } else { - stack[2] = value; - res = vectorcall_method(&PyId___setitem__, stack, 3); + stack[2] = value; + res = vectorcall_method(&PyId___setitem__, stack, 3); } if (res == NULL) @@ -6533,8 +6533,8 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) slot_nb_power, so check before calling self.__pow__. */ if (Py_TYPE(self)->tp_as_number != NULL && Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { - PyObject* stack[3] = {self, other, modulus}; - return vectorcall_method(&PyId___pow__, stack, 3); + PyObject* stack[3] = {self, other, modulus}; + return vectorcall_method(&PyId___pow__, stack, 3); } Py_RETURN_NOTIMPLEMENTED; } @@ -6601,8 +6601,8 @@ static PyObject * slot_nb_index(PyObject *self) { _Py_IDENTIFIER(__index__); - PyObject *stack[1] = {self}; - return vectorcall_method(&PyId___index__, stack, 1); + PyObject *stack[1] = {self}; + return vectorcall_method(&PyId___index__, stack, 1); } @@ -6624,9 +6624,9 @@ SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *) static PyObject * slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) { - PyObject *stack[2] = {self, arg1}; + PyObject *stack[2] = {self, arg1}; _Py_IDENTIFIER(__ipow__); - return vectorcall_method(&PyId___ipow__, stack, 2); + return vectorcall_method(&PyId___ipow__, stack, 2); } SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *) SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *) @@ -6710,21 +6710,21 @@ slot_tp_hash(PyObject *self) static PyObject * slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); _Py_IDENTIFIER(__call__); int unbound; - + PyObject *meth = lookup_method(self, &PyId___call__, &unbound); - if (meth == NULL) { + if (meth == NULL) { return NULL; - } + } - PyObject *res; + PyObject *res; if (unbound) { - res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds); + res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds); } else { - res = _PyObject_Call(tstate, meth, args, kwds); + res = _PyObject_Call(tstate, meth, args, kwds); } Py_DECREF(meth); @@ -6745,8 +6745,8 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * slot_tp_getattro(PyObject *self, PyObject *name) { - PyObject *stack[2] = {self, name}; - return vectorcall_method(&PyId___getattribute__, stack, 2); + PyObject *stack[2] = {self, name}; + return vectorcall_method(&PyId___getattribute__, stack, 2); } static PyObject * @@ -6762,7 +6762,7 @@ call_attribute(PyObject *self, PyObject *attr, PyObject *name) else attr = descr; } - res = PyObject_CallOneArg(attr, name); + res = PyObject_CallOneArg(attr, name); Py_XDECREF(descr); return res; } @@ -6793,7 +6793,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) needed, with call_attribute. */ getattribute = _PyType_LookupId(tp, &PyId___getattribute__); if (getattribute == NULL || - (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && + (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && ((PyWrapperDescrObject *)getattribute)->d_wrapped == (void *)PyObject_GenericGetAttr)) res = PyObject_GenericGetAttr(self, name); @@ -6813,19 +6813,19 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) static int slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) { - PyObject *stack[3]; + PyObject *stack[3]; PyObject *res; _Py_IDENTIFIER(__delattr__); _Py_IDENTIFIER(__setattr__); - stack[0] = self; - stack[1] = name; + stack[0] = self; + stack[1] = name; if (value == NULL) { - res = vectorcall_method(&PyId___delattr__, stack, 2); + res = vectorcall_method(&PyId___delattr__, stack, 2); } else { - stack[2] = value; - res = vectorcall_method(&PyId___setattr__, stack, 3); + stack[2] = value; + res = vectorcall_method(&PyId___setattr__, stack, 3); } if (res == NULL) return -1; @@ -6834,28 +6834,28 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) } static _Py_Identifier name_op[] = { - _Py_static_string_init("__lt__"), - _Py_static_string_init("__le__"), - _Py_static_string_init("__eq__"), - _Py_static_string_init("__ne__"), - _Py_static_string_init("__gt__"), - _Py_static_string_init("__ge__"), + _Py_static_string_init("__lt__"), + _Py_static_string_init("__le__"), + _Py_static_string_init("__eq__"), + _Py_static_string_init("__ne__"), + _Py_static_string_init("__gt__"), + _Py_static_string_init("__ge__"), }; static PyObject * slot_tp_richcompare(PyObject *self, PyObject *other, int op) { - PyThreadState *tstate = _PyThreadState_GET(); - + PyThreadState *tstate = _PyThreadState_GET(); + int unbound; - PyObject *func = lookup_maybe_method(self, &name_op[op], &unbound); + PyObject *func = lookup_maybe_method(self, &name_op[op], &unbound); if (func == NULL) { PyErr_Clear(); Py_RETURN_NOTIMPLEMENTED; } - PyObject *stack[2] = {self, other}; - PyObject *res = vectorcall_unbound(tstate, unbound, func, stack, 2); + PyObject *stack[2] = {self, other}; + PyObject *res = vectorcall_unbound(tstate, unbound, func, stack, 2); Py_DECREF(func); return res; } @@ -6898,8 +6898,8 @@ static PyObject * slot_tp_iternext(PyObject *self) { _Py_IDENTIFIER(__next__); - PyObject *stack[1] = {self}; - return vectorcall_method(&PyId___next__, stack, 1); + PyObject *stack[1] = {self}; + return vectorcall_method(&PyId___next__, stack, 1); } static PyObject * @@ -6927,19 +6927,19 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) static int slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) { - PyObject* stack[3]; + PyObject* stack[3]; PyObject *res; _Py_IDENTIFIER(__delete__); _Py_IDENTIFIER(__set__); - stack[0] = self; - stack[1] = target; + stack[0] = self; + stack[1] = target; if (value == NULL) { - res = vectorcall_method(&PyId___delete__, stack, 2); + res = vectorcall_method(&PyId___delete__, stack, 2); } else { - stack[2] = value; - res = vectorcall_method(&PyId___set__, stack, 3); + stack[2] = value; + res = vectorcall_method(&PyId___set__, stack, 3); } if (res == NULL) return -1; @@ -6950,21 +6950,21 @@ slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) static int slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) { - PyThreadState *tstate = _PyThreadState_GET(); - + PyThreadState *tstate = _PyThreadState_GET(); + _Py_IDENTIFIER(__init__); int unbound; PyObject *meth = lookup_method(self, &PyId___init__, &unbound); - if (meth == NULL) { - return -1; - } - + if (meth == NULL) { + return -1; + } + PyObject *res; if (unbound) { - res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds); + res = _PyObject_Call_Prepend(tstate, meth, self, args, kwds); } else { - res = _PyObject_Call(tstate, meth, args, kwds); + res = _PyObject_Call(tstate, meth, args, kwds); } Py_DECREF(meth); if (res == NULL) @@ -6983,7 +6983,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *result; func = _PyObject_GetAttrId((PyObject *)type, &PyId___new__); @@ -6991,7 +6991,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } - result = _PyObject_Call_Prepend(tstate, func, (PyObject *)type, args, kwds); + result = _PyObject_Call_Prepend(tstate, func, (PyObject *)type, args, kwds); Py_DECREF(func); return result; } @@ -7087,8 +7087,8 @@ which incorporates the additional structures used for numbers, sequences and mappings. Note that multiple names may map to the same slot (e.g. __eq__, __ne__ etc. all map to tp_richcompare) and one name may map to multiple slots (e.g. __str__ affects tp_str as well as tp_repr). The table is terminated with -an all-zero entry. (This table is further initialized in -_PyTypes_InitSlotDefs().) +an all-zero entry. (This table is further initialized in +_PyTypes_InitSlotDefs().) */ typedef struct wrapperbase slotdef; @@ -7256,7 +7256,7 @@ static slotdef slotdefs[] = { IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder, wrap_binaryfunc, "%="), IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power, - wrap_ternaryfunc, "**="), + wrap_ternaryfunc, "**="), IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift, wrap_binaryfunc, "<<="), IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift, @@ -7396,9 +7396,9 @@ resolve_slotdups(PyTypeObject *type, PyObject *name) *pp = NULL; } - /* Look in all slots of the type matching the name. If exactly one of these - has a filled-in slot, return a pointer to that slot. - Otherwise, return NULL. */ + /* Look in all slots of the type matching the name. If exactly one of these + has a filled-in slot, return a pointer to that slot. + Otherwise, return NULL. */ res = NULL; for (pp = ptrs; *pp; pp++) { ptr = slotptr(type, (*pp)->offset); @@ -7411,61 +7411,61 @@ resolve_slotdups(PyTypeObject *type, PyObject *name) return res; } - -/* Common code for update_slots_callback() and fixup_slot_dispatchers(). - * - * This is meant to set a "slot" like type->tp_repr or - * type->tp_as_sequence->sq_concat by looking up special methods like - * __repr__ or __add__. The opposite (adding special methods from slots) is - * done by add_operators(), called from PyType_Ready(). Since update_one_slot() - * calls PyType_Ready() if needed, the special methods are already in place. - * - * The special methods corresponding to each slot are defined in the "slotdef" - * array. Note that one slot may correspond to multiple special methods and vice - * versa. For example, tp_richcompare uses 6 methods __lt__, ..., __ge__ and - * tp_as_number->nb_add uses __add__ and __radd__. In the other direction, - * __add__ is used by the number and sequence protocols and __getitem__ by the - * sequence and mapping protocols. This causes a lot of complications. - * - * In detail, update_one_slot() does the following: - * - * First of all, if the slot in question does not exist, return immediately. - * This can happen for example if it's tp_as_number->nb_add but tp_as_number - * is NULL. - * - * For the given slot, we loop over all the special methods with a name - * corresponding to that slot (for example, for tp_descr_set, this would be - * __set__ and __delete__) and we look up these names in the MRO of the type. - * If we don't find any special method, the slot is set to NULL (regardless of - * what was in the slot before). - * - * Suppose that we find exactly one special method. If it's a wrapper_descriptor - * (i.e. a special method calling a slot, for example str.__repr__ which calls - * the tp_repr for the 'str' class) with the correct name ("__repr__" for - * tp_repr), for the right class, calling the right wrapper C function (like - * wrap_unaryfunc for tp_repr), then the slot is set to the slot that the - * wrapper_descriptor originally wrapped. For example, a class inheriting - * from 'str' and not redefining __repr__ will have tp_repr set to the tp_repr - * of 'str'. - * In all other cases where the special method exists, the slot is set to a - * wrapper calling the special method. There is one exception: if the special - * method is a wrapper_descriptor with the correct name but the type has - * precisely one slot set for that name and that slot is not the one that we - * are updating, then NULL is put in the slot (this exception is the only place - * in update_one_slot() where the *existing* slots matter). - * - * When there are multiple special methods for the same slot, the above is - * applied for each special method. As long as the results agree, the common - * resulting slot is applied. If the results disagree, then a wrapper for - * the special methods is installed. This is always safe, but less efficient - * because it uses method lookup instead of direct C calls. - * - * There are some further special cases for specific slots, like supporting - * __hash__ = None for tp_hash and special code for tp_new. - * - * When done, return a pointer to the next slotdef with a different offset, - * because that's convenient for fixup_slot_dispatchers(). This function never - * sets an exception: if an internal error happens (unlikely), it's ignored. */ + +/* Common code for update_slots_callback() and fixup_slot_dispatchers(). + * + * This is meant to set a "slot" like type->tp_repr or + * type->tp_as_sequence->sq_concat by looking up special methods like + * __repr__ or __add__. The opposite (adding special methods from slots) is + * done by add_operators(), called from PyType_Ready(). Since update_one_slot() + * calls PyType_Ready() if needed, the special methods are already in place. + * + * The special methods corresponding to each slot are defined in the "slotdef" + * array. Note that one slot may correspond to multiple special methods and vice + * versa. For example, tp_richcompare uses 6 methods __lt__, ..., __ge__ and + * tp_as_number->nb_add uses __add__ and __radd__. In the other direction, + * __add__ is used by the number and sequence protocols and __getitem__ by the + * sequence and mapping protocols. This causes a lot of complications. + * + * In detail, update_one_slot() does the following: + * + * First of all, if the slot in question does not exist, return immediately. + * This can happen for example if it's tp_as_number->nb_add but tp_as_number + * is NULL. + * + * For the given slot, we loop over all the special methods with a name + * corresponding to that slot (for example, for tp_descr_set, this would be + * __set__ and __delete__) and we look up these names in the MRO of the type. + * If we don't find any special method, the slot is set to NULL (regardless of + * what was in the slot before). + * + * Suppose that we find exactly one special method. If it's a wrapper_descriptor + * (i.e. a special method calling a slot, for example str.__repr__ which calls + * the tp_repr for the 'str' class) with the correct name ("__repr__" for + * tp_repr), for the right class, calling the right wrapper C function (like + * wrap_unaryfunc for tp_repr), then the slot is set to the slot that the + * wrapper_descriptor originally wrapped. For example, a class inheriting + * from 'str' and not redefining __repr__ will have tp_repr set to the tp_repr + * of 'str'. + * In all other cases where the special method exists, the slot is set to a + * wrapper calling the special method. There is one exception: if the special + * method is a wrapper_descriptor with the correct name but the type has + * precisely one slot set for that name and that slot is not the one that we + * are updating, then NULL is put in the slot (this exception is the only place + * in update_one_slot() where the *existing* slots matter). + * + * When there are multiple special methods for the same slot, the above is + * applied for each special method. As long as the results agree, the common + * resulting slot is applied. If the results disagree, then a wrapper for + * the special methods is installed. This is always safe, but less efficient + * because it uses method lookup instead of direct C calls. + * + * There are some further special cases for specific slots, like supporting + * __hash__ = None for tp_hash and special code for tp_new. + * + * When done, return a pointer to the next slotdef with a different offset, + * because that's convenient for fixup_slot_dispatchers(). This function never + * sets an exception: if an internal error happens (unlikely), it's ignored. */ static slotdef * update_one_slot(PyTypeObject *type, slotdef *p) { @@ -7490,7 +7490,7 @@ update_one_slot(PyTypeObject *type, slotdef *p) descr = find_name_in_mro(type, p->name_strobj, &error); if (descr == NULL) { if (error == -1) { - /* It is unlikely but not impossible that there has been an exception + /* It is unlikely but not impossible that there has been an exception during lookup. Since this function originally expected no errors, we ignore them here in order to keep up the interface. */ PyErr_Clear(); @@ -7500,32 +7500,32 @@ update_one_slot(PyTypeObject *type, slotdef *p) } continue; } - if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) && + if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) && ((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) { void **tptr = resolve_slotdups(type, p->name_strobj); if (tptr == NULL || tptr == ptr) generic = p->function; d = (PyWrapperDescrObject *)descr; - if ((specific == NULL || specific == d->d_wrapped) && - d->d_base->wrapper == p->wrapper && + if ((specific == NULL || specific == d->d_wrapped) && + d->d_base->wrapper == p->wrapper && PyType_IsSubtype(type, PyDescr_TYPE(d))) { - specific = d->d_wrapped; + specific = d->d_wrapped; + } + else { + /* We cannot use the specific slot function because either + - it is not unique: there are multiple methods for this + slot and they conflict + - the signature is wrong (as checked by the ->wrapper + comparison above) + - it's wrapping the wrong class + */ + use_generic = 1; } - else { - /* We cannot use the specific slot function because either - - it is not unique: there are multiple methods for this - slot and they conflict - - the signature is wrong (as checked by the ->wrapper - comparison above) - - it's wrapping the wrong class - */ - use_generic = 1; - } - } - else if (Py_IS_TYPE(descr, &PyCFunction_Type) && + } + else if (Py_IS_TYPE(descr, &PyCFunction_Type) && PyCFunction_GET_FUNCTION(descr) == - (PyCFunction)(void(*)(void))tp_new_wrapper && + (PyCFunction)(void(*)(void))tp_new_wrapper && ptr == (void**)&type->tp_new) { /* The __new__ wrapper is not a wrapper descriptor, @@ -7579,36 +7579,36 @@ update_slots_callback(PyTypeObject *type, void *data) static int slotdefs_initialized = 0; /* Initialize the slotdefs table by adding interned string objects for the names. */ -PyStatus -_PyTypes_InitSlotDefs(void) +PyStatus +_PyTypes_InitSlotDefs(void) { - if (slotdefs_initialized) { - return _PyStatus_OK(); - } + if (slotdefs_initialized) { + return _PyStatus_OK(); + } - for (slotdef *p = slotdefs; p->name; p++) { + for (slotdef *p = slotdefs; p->name; p++) { /* Slots must be ordered by their offset in the PyHeapTypeObject. */ assert(!p[1].name || p->offset <= p[1].offset); -#ifdef INTERN_NAME_STRINGS +#ifdef INTERN_NAME_STRINGS p->name_strobj = PyUnicode_InternFromString(p->name); - if (!p->name_strobj || !PyUnicode_CHECK_INTERNED(p->name_strobj)) { - return _PyStatus_NO_MEMORY(); - } -#else - p->name_strobj = PyUnicode_FromString(p->name); - if (!p->name_strobj) { - return _PyStatus_NO_MEMORY(); - } -#endif + if (!p->name_strobj || !PyUnicode_CHECK_INTERNED(p->name_strobj)) { + return _PyStatus_NO_MEMORY(); + } +#else + p->name_strobj = PyUnicode_FromString(p->name); + if (!p->name_strobj) { + return _PyStatus_NO_MEMORY(); + } +#endif } slotdefs_initialized = 1; - return _PyStatus_OK(); + return _PyStatus_OK(); } -/* Undo _PyTypes_InitSlotDefs(), releasing the interned strings. */ +/* Undo _PyTypes_InitSlotDefs(), releasing the interned strings. */ static void clear_slotdefs(void) { - for (slotdef *p = slotdefs; p->name; p++) { + for (slotdef *p = slotdefs; p->name; p++) { Py_CLEAR(p->name_strobj); } slotdefs_initialized = 0; @@ -7624,11 +7624,11 @@ update_slot(PyTypeObject *type, PyObject *name) int offset; assert(PyUnicode_CheckExact(name)); -#ifdef INTERN_NAME_STRINGS +#ifdef INTERN_NAME_STRINGS assert(PyUnicode_CHECK_INTERNED(name)); -#endif +#endif - assert(slotdefs_initialized); + assert(slotdefs_initialized); pp = ptrs; for (p = slotdefs; p->name; p++) { if (p->name_strobj == name) @@ -7656,7 +7656,7 @@ fixup_slot_dispatchers(PyTypeObject *type) { slotdef *p; - assert(slotdefs_initialized); + assert(slotdefs_initialized); for (p = slotdefs; p->name; ) p = update_one_slot(type, p); } @@ -7666,10 +7666,10 @@ update_all_slots(PyTypeObject* type) { slotdef *p; - /* Clear the VALID_VERSION flag of 'type' and all its subclasses. */ - PyType_Modified(type); - - assert(slotdefs_initialized); + /* Clear the VALID_VERSION flag of 'type' and all its subclasses. */ + PyType_Modified(type); + + assert(slotdefs_initialized); for (p = slotdefs; p->name; p++) { /* update_slot returns int but can't actually fail */ update_slot(type, p->name_strobj); @@ -7696,7 +7696,7 @@ set_names(PyTypeObject *type) _PyErr_FormatFromCause(PyExc_RuntimeError, "Error calling __set_name__ on '%.100s' instance %R " "in '%.100s'", - Py_TYPE(value)->tp_name, key, type->tp_name); + Py_TYPE(value)->tp_name, key, type->tp_name); Py_DECREF(names_to_set); return -1; } @@ -7732,7 +7732,7 @@ init_subclass(PyTypeObject *type, PyObject *kwds) } - result = PyObject_VectorcallDict(func, NULL, 0, kwds); + result = PyObject_VectorcallDict(func, NULL, 0, kwds); Py_DECREF(func); if (result == NULL) { return -1; @@ -7777,14 +7777,14 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *name, assert(PyType_Check(subclass)); /* Avoid recursing down into unaffected classes */ dict = subclass->tp_dict; - if (dict != NULL && PyDict_Check(dict)) { - if (PyDict_GetItemWithError(dict, name) != NULL) { - continue; - } - if (PyErr_Occurred()) { - return -1; - } - } + if (dict != NULL && PyDict_Check(dict)) { + if (PyDict_GetItemWithError(dict, name) != NULL) { + continue; + } + if (PyErr_Occurred()) { + return -1; + } + } if (update_subclasses(subclass, name, callback, data) < 0) return -1; } @@ -7829,18 +7829,18 @@ add_operators(PyTypeObject *type) PyObject *descr; void **ptr; - assert(slotdefs_initialized); + assert(slotdefs_initialized); for (p = slotdefs; p->name; p++) { if (p->wrapper == NULL) continue; ptr = slotptr(type, p->offset); if (!ptr || !*ptr) continue; - if (PyDict_GetItemWithError(dict, p->name_strobj)) + if (PyDict_GetItemWithError(dict, p->name_strobj)) continue; - if (PyErr_Occurred()) { - return -1; - } + if (PyErr_Occurred()) { + return -1; + } if (*ptr == (void *)PyObject_HashNotImplemented) { /* Classes may prevent the inheritance of the tp_hash slot by storing PyObject_HashNotImplemented in it. Make it @@ -7950,7 +7950,7 @@ super_getattro(PyObject *self, PyObject *name) goto skip; /* keep a strong reference to mro because starttype->tp_mro can be - replaced during PyDict_GetItemWithError(dict, name) */ + replaced during PyDict_GetItemWithError(dict, name) */ Py_INCREF(mro); do { PyObject *res, *tmp, *dict; @@ -7962,7 +7962,7 @@ super_getattro(PyObject *self, PyObject *name) dict = ((PyTypeObject *)tmp)->tp_dict; assert(dict != NULL && PyDict_Check(dict)); - res = PyDict_GetItemWithError(dict, name); + res = PyDict_GetItemWithError(dict, name); if (res != NULL) { Py_INCREF(res); @@ -7980,10 +7980,10 @@ super_getattro(PyObject *self, PyObject *name) Py_DECREF(mro); return res; } - else if (PyErr_Occurred()) { - Py_DECREF(mro); - return NULL; - } + else if (PyErr_Occurred()) { + Py_DECREF(mro); + return NULL; + } i++; } while (i < n); @@ -8026,9 +8026,9 @@ supercheck(PyTypeObject *type, PyObject *obj) /* Try the slow way */ PyObject *class_attr; - if (_PyObject_LookupAttrId(obj, &PyId___class__, &class_attr) < 0) { - return NULL; - } + if (_PyObject_LookupAttrId(obj, &PyId___class__, &class_attr) < 0) { + return NULL; + } if (class_attr != NULL && PyType_Check(class_attr) && (PyTypeObject *)class_attr != Py_TYPE(obj)) @@ -8038,7 +8038,7 @@ supercheck(PyTypeObject *type, PyObject *obj) if (ok) return (PyTypeObject *)class_attr; } - Py_XDECREF(class_attr); + Py_XDECREF(class_attr); } PyErr_SetString(PyExc_TypeError, @@ -8058,7 +8058,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) Py_INCREF(self); return self; } - if (!Py_IS_TYPE(su, &PySuper_Type)) + if (!Py_IS_TYPE(su, &PySuper_Type)) /* If su is an instance of a (strict) subclass of super, call its type */ return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su), @@ -8082,83 +8082,83 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) } static int -super_init_without_args(PyFrameObject *f, PyCodeObject *co, - PyTypeObject **type_p, PyObject **obj_p) -{ - if (co->co_argcount == 0) { - PyErr_SetString(PyExc_RuntimeError, - "super(): no arguments"); - return -1; - } - - PyObject *obj = f->f_localsplus[0]; - Py_ssize_t i, n; - if (obj == NULL && co->co_cell2arg) { - /* The first argument might be a cell. */ - n = PyTuple_GET_SIZE(co->co_cellvars); - for (i = 0; i < n; i++) { - if (co->co_cell2arg[i] == 0) { - PyObject *cell = f->f_localsplus[co->co_nlocals + i]; - assert(PyCell_Check(cell)); - obj = PyCell_GET(cell); - break; - } - } - } - if (obj == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "super(): arg[0] deleted"); - return -1; - } - - if (co->co_freevars == NULL) { - n = 0; - } - else { - assert(PyTuple_Check(co->co_freevars)); - n = PyTuple_GET_SIZE(co->co_freevars); - } - - PyTypeObject *type = NULL; - for (i = 0; i < n; i++) { - PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); - assert(PyUnicode_Check(name)); - if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { - Py_ssize_t index = co->co_nlocals + - PyTuple_GET_SIZE(co->co_cellvars) + i; - PyObject *cell = f->f_localsplus[index]; - if (cell == NULL || !PyCell_Check(cell)) { - PyErr_SetString(PyExc_RuntimeError, - "super(): bad __class__ cell"); - return -1; - } - type = (PyTypeObject *) PyCell_GET(cell); - if (type == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "super(): empty __class__ cell"); - return -1; - } - if (!PyType_Check(type)) { - PyErr_Format(PyExc_RuntimeError, - "super(): __class__ is not a type (%s)", - Py_TYPE(type)->tp_name); - return -1; - } - break; - } - } - if (type == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "super(): __class__ cell not found"); - return -1; - } - - *type_p = type; - *obj_p = obj; - return 0; -} - -static int +super_init_without_args(PyFrameObject *f, PyCodeObject *co, + PyTypeObject **type_p, PyObject **obj_p) +{ + if (co->co_argcount == 0) { + PyErr_SetString(PyExc_RuntimeError, + "super(): no arguments"); + return -1; + } + + PyObject *obj = f->f_localsplus[0]; + Py_ssize_t i, n; + if (obj == NULL && co->co_cell2arg) { + /* The first argument might be a cell. */ + n = PyTuple_GET_SIZE(co->co_cellvars); + for (i = 0; i < n; i++) { + if (co->co_cell2arg[i] == 0) { + PyObject *cell = f->f_localsplus[co->co_nlocals + i]; + assert(PyCell_Check(cell)); + obj = PyCell_GET(cell); + break; + } + } + } + if (obj == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "super(): arg[0] deleted"); + return -1; + } + + if (co->co_freevars == NULL) { + n = 0; + } + else { + assert(PyTuple_Check(co->co_freevars)); + n = PyTuple_GET_SIZE(co->co_freevars); + } + + PyTypeObject *type = NULL; + for (i = 0; i < n; i++) { + PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i); + assert(PyUnicode_Check(name)); + if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { + Py_ssize_t index = co->co_nlocals + + PyTuple_GET_SIZE(co->co_cellvars) + i; + PyObject *cell = f->f_localsplus[index]; + if (cell == NULL || !PyCell_Check(cell)) { + PyErr_SetString(PyExc_RuntimeError, + "super(): bad __class__ cell"); + return -1; + } + type = (PyTypeObject *) PyCell_GET(cell); + if (type == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "super(): empty __class__ cell"); + return -1; + } + if (!PyType_Check(type)) { + PyErr_Format(PyExc_RuntimeError, + "super(): __class__ is not a type (%s)", + Py_TYPE(type)->tp_name); + return -1; + } + break; + } + } + if (type == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "super(): __class__ cell not found"); + return -1; + } + + *type_p = type; + *obj_p = obj; + return 0; +} + +static int super_init(PyObject *self, PyObject *args, PyObject *kwds) { superobject *su = (superobject *)self; @@ -8174,20 +8174,20 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) if (type == NULL) { /* Call super(), without args -- fill in from __class__ and first local variable on the stack. */ - PyThreadState *tstate = _PyThreadState_GET(); - PyFrameObject *frame = PyThreadState_GetFrame(tstate); - if (frame == NULL) { + PyThreadState *tstate = _PyThreadState_GET(); + PyFrameObject *frame = PyThreadState_GetFrame(tstate); + if (frame == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no current frame"); return -1; } - - PyCodeObject *code = PyFrame_GetCode(frame); - int res = super_init_without_args(frame, code, &type, &obj); - Py_DECREF(frame); - Py_DECREF(code); - - if (res < 0) { + + PyCodeObject *code = PyFrame_GetCode(frame); + int res = super_init_without_args(frame, code, &type, &obj); + Py_DECREF(frame); + Py_DECREF(code); + + if (res < 0) { return -1; } } @@ -8241,10 +8241,10 @@ PyTypeObject PySuper_Type = { 0, /* tp_itemsize */ /* methods */ super_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ super_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/contrib/tools/python3/src/Objects/typeslots.inc b/contrib/tools/python3/src/Objects/typeslots.inc index 62d0a2210f..ffc9bb2e1c 100644 --- a/contrib/tools/python3/src/Objects/typeslots.inc +++ b/contrib/tools/python3/src/Objects/typeslots.inc @@ -1,6 +1,6 @@ /* Generated by typeslots.py */ -offsetof(PyHeapTypeObject, as_buffer.bf_getbuffer), -offsetof(PyHeapTypeObject, as_buffer.bf_releasebuffer), +offsetof(PyHeapTypeObject, as_buffer.bf_getbuffer), +offsetof(PyHeapTypeObject, as_buffer.bf_releasebuffer), offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript), offsetof(PyHeapTypeObject, as_mapping.mp_length), offsetof(PyHeapTypeObject, as_mapping.mp_subscript), diff --git a/contrib/tools/python3/src/Objects/unicodeobject.c b/contrib/tools/python3/src/Objects/unicodeobject.c index 6ee20925e9..7767d140e6 100644 --- a/contrib/tools/python3/src/Objects/unicodeobject.c +++ b/contrib/tools/python3/src/Objects/unicodeobject.c @@ -40,15 +40,15 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" -#include "pycore_fileutils.h" -#include "pycore_initconfig.h" -#include "pycore_interp.h" // PyInterpreterState.fs_codec -#include "pycore_object.h" -#include "pycore_pathconfig.h" -#include "pycore_pylifecycle.h" -#include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_bytes_methods.h" +#include "pycore_fileutils.h" +#include "pycore_initconfig.h" +#include "pycore_interp.h" // PyInterpreterState.fs_codec +#include "pycore_object.h" +#include "pycore_pathconfig.h" +#include "pycore_pylifecycle.h" +#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "ucnhash.h" #include "stringlib/eq.h" @@ -56,15 +56,15 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <windows.h> #endif -#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION -#include "pycore_fileutils.h" // _Py_LocaleUsesNonUnicodeWchar() -#endif - -/* Uncomment to display statistics on interned strings at exit when - using Valgrind or Insecure++. */ -/* #define INTERNED_STATS 1 */ - - +#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION +#include "pycore_fileutils.h" // _Py_LocaleUsesNonUnicodeWchar() +#endif + +/* Uncomment to display statistics on interned strings at exit when + using Valgrind or Insecure++. */ +/* #define INTERNED_STATS 1 */ + + /*[clinic input] class str "PyObject *" "&PyUnicode_Type" [clinic start generated code]*/ @@ -97,8 +97,8 @@ NOTE: In the interpreter's initialization phase, some globals are currently extern "C" { #endif -// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111). -// The value must be the same in fileutils.c. +// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111). +// The value must be the same in fileutils.c. #define MAX_UNICODE 0x10ffff #ifdef Py_DEBUG @@ -125,13 +125,13 @@ extern "C" { _PyUnicode_UTF8_LENGTH(op)) #define _PyUnicode_WSTR(op) \ (((PyASCIIObject*)(op))->wstr) - -/* Don't use deprecated macro of unicodeobject.h */ -#undef PyUnicode_WSTR_LENGTH -#define PyUnicode_WSTR_LENGTH(op) \ - (PyUnicode_IS_COMPACT_ASCII(op) ? \ - ((PyASCIIObject*)op)->length : \ - ((PyCompactUnicodeObject*)op)->wstr_length) + +/* Don't use deprecated macro of unicodeobject.h */ +#undef PyUnicode_WSTR_LENGTH +#define PyUnicode_WSTR_LENGTH(op) \ + (PyUnicode_IS_COMPACT_ASCII(op) ? \ + ((PyASCIIObject*)op)->length : \ + ((PyCompactUnicodeObject*)op)->wstr_length) #define _PyUnicode_WSTR_LENGTH(op) \ (((PyCompactUnicodeObject*)(op))->wstr_length) #define _PyUnicode_LENGTH(op) \ @@ -186,8 +186,8 @@ extern "C" { #define _PyUnicode_CONVERT_BYTES(from_type, to_type, begin, end, to) \ do { \ to_type *_to = (to_type *)(to); \ - const from_type *_iter = (const from_type *)(begin);\ - const from_type *_end = (const from_type *)(end);\ + const from_type *_iter = (const from_type *)(begin);\ + const from_type *_end = (const from_type *)(end);\ Py_ssize_t n = (_end) - (_iter); \ const from_type *_unrolled_end = \ _iter + _Py_SIZE_ROUND_DOWN(n, 4); \ @@ -210,8 +210,8 @@ extern "C" { # define OVERALLOCATE_FACTOR 4 #endif -#define INTERNED_STRINGS - +#define INTERNED_STRINGS + /* This dictionary holds all interned unicode strings. Note that references to strings in this dictionary are *not* counted in the string's ob_refcnt. When the interned string reaches a refcnt of 0 the string deallocation @@ -220,9 +220,9 @@ extern "C" { Another way to look at this is that to say that the actual reference count of a string is: s->ob_refcnt + (s->state ? 2 : 0) */ -#ifdef INTERNED_STRINGS +#ifdef INTERNED_STRINGS static PyObject *interned = NULL; -#endif +#endif /* The empty Unicode object is shared to improve performance. */ static PyObject *unicode_empty = NULL; @@ -246,64 +246,64 @@ static PyObject *unicode_empty = NULL; return unicode_empty; \ } while (0) -static inline void -unicode_fill(enum PyUnicode_Kind kind, void *data, Py_UCS4 value, - Py_ssize_t start, Py_ssize_t length) -{ - assert(0 <= start); - assert(kind != PyUnicode_WCHAR_KIND); - switch (kind) { - case PyUnicode_1BYTE_KIND: { - assert(value <= 0xff); - Py_UCS1 ch = (unsigned char)value; - Py_UCS1 *to = (Py_UCS1 *)data + start; - memset(to, ch, length); - break; - } - case PyUnicode_2BYTE_KIND: { - assert(value <= 0xffff); - Py_UCS2 ch = (Py_UCS2)value; - Py_UCS2 *to = (Py_UCS2 *)data + start; - const Py_UCS2 *end = to + length; - for (; to < end; ++to) *to = ch; - break; - } - case PyUnicode_4BYTE_KIND: { - assert(value <= MAX_UNICODE); - Py_UCS4 ch = value; - Py_UCS4 * to = (Py_UCS4 *)data + start; - const Py_UCS4 *end = to + length; - for (; to < end; ++to) *to = ch; - break; - } - default: Py_UNREACHABLE(); - } -} +static inline void +unicode_fill(enum PyUnicode_Kind kind, void *data, Py_UCS4 value, + Py_ssize_t start, Py_ssize_t length) +{ + assert(0 <= start); + assert(kind != PyUnicode_WCHAR_KIND); + switch (kind) { + case PyUnicode_1BYTE_KIND: { + assert(value <= 0xff); + Py_UCS1 ch = (unsigned char)value; + Py_UCS1 *to = (Py_UCS1 *)data + start; + memset(to, ch, length); + break; + } + case PyUnicode_2BYTE_KIND: { + assert(value <= 0xffff); + Py_UCS2 ch = (Py_UCS2)value; + Py_UCS2 *to = (Py_UCS2 *)data + start; + const Py_UCS2 *end = to + length; + for (; to < end; ++to) *to = ch; + break; + } + case PyUnicode_4BYTE_KIND: { + assert(value <= MAX_UNICODE); + Py_UCS4 ch = value; + Py_UCS4 * to = (Py_UCS4 *)data + start; + const Py_UCS4 *end = to + length; + for (; to < end; ++to) *to = ch; + break; + } + default: Py_UNREACHABLE(); + } +} /* Forward declaration */ static inline int _PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch); -static inline void -_PyUnicodeWriter_InitWithBuffer(_PyUnicodeWriter *writer, PyObject *buffer); -static PyObject * -unicode_encode_utf8(PyObject *unicode, _Py_error_handler error_handler, - const char *errors); -static PyObject * -unicode_decode_utf8(const char *s, Py_ssize_t size, - _Py_error_handler error_handler, const char *errors, - Py_ssize_t *consumed); +static inline void +_PyUnicodeWriter_InitWithBuffer(_PyUnicodeWriter *writer, PyObject *buffer); +static PyObject * +unicode_encode_utf8(PyObject *unicode, _Py_error_handler error_handler, + const char *errors); +static PyObject * +unicode_decode_utf8(const char *s, Py_ssize_t size, + _Py_error_handler error_handler, const char *errors, + Py_ssize_t *consumed); /* List of static strings. */ static _Py_Identifier *static_strings = NULL; -#define LATIN1_SINGLETONS - -#ifdef LATIN1_SINGLETONS +#define LATIN1_SINGLETONS + +#ifdef LATIN1_SINGLETONS /* Single character Unicode strings in the Latin-1 range are being shared as well. */ static PyObject *unicode_latin1[256] = {NULL}; -#endif +#endif /* Fast detection of the most frequent whitespace characters */ const unsigned char _Py_ascii_whitespace[] = { @@ -394,8 +394,8 @@ static int convert_uc(PyObject *obj, void *addr); #include "clinic/unicodeobject.c.h" -_Py_error_handler -_Py_GetErrorHandler(const char *errors) +_Py_error_handler +_Py_GetErrorHandler(const char *errors) { if (errors == NULL || strcmp(errors, "strict") == 0) { return _Py_ERROR_STRICT; @@ -421,83 +421,83 @@ _Py_GetErrorHandler(const char *errors) return _Py_ERROR_OTHER; } - -static _Py_error_handler -get_error_handler_wide(const wchar_t *errors) -{ - if (errors == NULL || wcscmp(errors, L"strict") == 0) { - return _Py_ERROR_STRICT; - } - if (wcscmp(errors, L"surrogateescape") == 0) { - return _Py_ERROR_SURROGATEESCAPE; - } - if (wcscmp(errors, L"replace") == 0) { - return _Py_ERROR_REPLACE; - } - if (wcscmp(errors, L"ignore") == 0) { - return _Py_ERROR_IGNORE; - } - if (wcscmp(errors, L"backslashreplace") == 0) { - return _Py_ERROR_BACKSLASHREPLACE; - } - if (wcscmp(errors, L"surrogatepass") == 0) { - return _Py_ERROR_SURROGATEPASS; - } - if (wcscmp(errors, L"xmlcharrefreplace") == 0) { - return _Py_ERROR_XMLCHARREFREPLACE; - } - return _Py_ERROR_OTHER; -} - - -static inline int -unicode_check_encoding_errors(const char *encoding, const char *errors) -{ - if (encoding == NULL && errors == NULL) { - return 0; - } - - PyInterpreterState *interp = _PyInterpreterState_GET(); -#ifndef Py_DEBUG - /* In release mode, only check in development mode (-X dev) */ - if (!_PyInterpreterState_GetConfig(interp)->dev_mode) { - return 0; - } -#else - /* Always check in debug mode */ -#endif - - /* Avoid calling _PyCodec_Lookup() and PyCodec_LookupError() before the - codec registry is ready: before_PyUnicode_InitEncodings() is called. */ - if (!interp->unicode.fs_codec.encoding) { - return 0; - } - - /* Disable checks during Python finalization. For example, it allows to - call _PyObject_Dump() during finalization for debugging purpose. */ - if (interp->finalizing) { - return 0; - } - - if (encoding != NULL) { - PyObject *handler = _PyCodec_Lookup(encoding); - if (handler == NULL) { - return -1; - } - Py_DECREF(handler); - } - - if (errors != NULL) { - PyObject *handler = PyCodec_LookupError(errors); - if (handler == NULL) { - return -1; - } - Py_DECREF(handler); - } - return 0; -} - - + +static _Py_error_handler +get_error_handler_wide(const wchar_t *errors) +{ + if (errors == NULL || wcscmp(errors, L"strict") == 0) { + return _Py_ERROR_STRICT; + } + if (wcscmp(errors, L"surrogateescape") == 0) { + return _Py_ERROR_SURROGATEESCAPE; + } + if (wcscmp(errors, L"replace") == 0) { + return _Py_ERROR_REPLACE; + } + if (wcscmp(errors, L"ignore") == 0) { + return _Py_ERROR_IGNORE; + } + if (wcscmp(errors, L"backslashreplace") == 0) { + return _Py_ERROR_BACKSLASHREPLACE; + } + if (wcscmp(errors, L"surrogatepass") == 0) { + return _Py_ERROR_SURROGATEPASS; + } + if (wcscmp(errors, L"xmlcharrefreplace") == 0) { + return _Py_ERROR_XMLCHARREFREPLACE; + } + return _Py_ERROR_OTHER; +} + + +static inline int +unicode_check_encoding_errors(const char *encoding, const char *errors) +{ + if (encoding == NULL && errors == NULL) { + return 0; + } + + PyInterpreterState *interp = _PyInterpreterState_GET(); +#ifndef Py_DEBUG + /* In release mode, only check in development mode (-X dev) */ + if (!_PyInterpreterState_GetConfig(interp)->dev_mode) { + return 0; + } +#else + /* Always check in debug mode */ +#endif + + /* Avoid calling _PyCodec_Lookup() and PyCodec_LookupError() before the + codec registry is ready: before_PyUnicode_InitEncodings() is called. */ + if (!interp->unicode.fs_codec.encoding) { + return 0; + } + + /* Disable checks during Python finalization. For example, it allows to + call _PyObject_Dump() during finalization for debugging purpose. */ + if (interp->finalizing) { + return 0; + } + + if (encoding != NULL) { + PyObject *handler = _PyCodec_Lookup(encoding); + if (handler == NULL) { + return -1; + } + Py_DECREF(handler); + } + + if (errors != NULL) { + PyObject *handler = PyCodec_LookupError(errors); + if (handler == NULL) { + return -1; + } + Py_DECREF(handler); + } + return 0; +} + + /* The max unicode value is always 0x10FFFF while using the PEP-393 API. This function is kept for backward compatibility with the old API. */ Py_UNICODE @@ -515,21 +515,21 @@ PyUnicode_GetMax(void) int _PyUnicode_CheckConsistency(PyObject *op, int check_content) { -#define CHECK(expr) \ - do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) - +#define CHECK(expr) \ + do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0) + PyASCIIObject *ascii; unsigned int kind; - assert(op != NULL); - CHECK(PyUnicode_Check(op)); + assert(op != NULL); + CHECK(PyUnicode_Check(op)); ascii = (PyASCIIObject *)op; kind = ascii->state.kind; if (ascii->state.ascii == 1 && ascii->state.compact == 1) { - CHECK(kind == PyUnicode_1BYTE_KIND); - CHECK(ascii->state.ready == 1); + CHECK(kind == PyUnicode_1BYTE_KIND); + CHECK(ascii->state.ready == 1); } else { PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op; @@ -537,41 +537,41 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) if (ascii->state.compact == 1) { data = compact + 1; - CHECK(kind == PyUnicode_1BYTE_KIND - || kind == PyUnicode_2BYTE_KIND - || kind == PyUnicode_4BYTE_KIND); - CHECK(ascii->state.ascii == 0); - CHECK(ascii->state.ready == 1); - CHECK(compact->utf8 != data); + CHECK(kind == PyUnicode_1BYTE_KIND + || kind == PyUnicode_2BYTE_KIND + || kind == PyUnicode_4BYTE_KIND); + CHECK(ascii->state.ascii == 0); + CHECK(ascii->state.ready == 1); + CHECK(compact->utf8 != data); } else { PyUnicodeObject *unicode = (PyUnicodeObject *)op; data = unicode->data.any; if (kind == PyUnicode_WCHAR_KIND) { - CHECK(ascii->length == 0); - CHECK(ascii->hash == -1); - CHECK(ascii->state.compact == 0); - CHECK(ascii->state.ascii == 0); - CHECK(ascii->state.ready == 0); - CHECK(ascii->state.interned == SSTATE_NOT_INTERNED); - CHECK(ascii->wstr != NULL); - CHECK(data == NULL); - CHECK(compact->utf8 == NULL); + CHECK(ascii->length == 0); + CHECK(ascii->hash == -1); + CHECK(ascii->state.compact == 0); + CHECK(ascii->state.ascii == 0); + CHECK(ascii->state.ready == 0); + CHECK(ascii->state.interned == SSTATE_NOT_INTERNED); + CHECK(ascii->wstr != NULL); + CHECK(data == NULL); + CHECK(compact->utf8 == NULL); } else { - CHECK(kind == PyUnicode_1BYTE_KIND - || kind == PyUnicode_2BYTE_KIND - || kind == PyUnicode_4BYTE_KIND); - CHECK(ascii->state.compact == 0); - CHECK(ascii->state.ready == 1); - CHECK(data != NULL); + CHECK(kind == PyUnicode_1BYTE_KIND + || kind == PyUnicode_2BYTE_KIND + || kind == PyUnicode_4BYTE_KIND); + CHECK(ascii->state.compact == 0); + CHECK(ascii->state.ready == 1); + CHECK(data != NULL); if (ascii->state.ascii) { - CHECK(compact->utf8 == data); - CHECK(compact->utf8_length == ascii->length); + CHECK(compact->utf8 == data); + CHECK(compact->utf8_length == ascii->length); } else - CHECK(compact->utf8 != data); + CHECK(compact->utf8 != data); } } if (kind != PyUnicode_WCHAR_KIND) { @@ -583,23 +583,23 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) #endif ) { - CHECK(ascii->wstr == data); - CHECK(compact->wstr_length == ascii->length); + CHECK(ascii->wstr == data); + CHECK(compact->wstr_length == ascii->length); } else - CHECK(ascii->wstr != data); + CHECK(ascii->wstr != data); } if (compact->utf8 == NULL) - CHECK(compact->utf8_length == 0); + CHECK(compact->utf8_length == 0); if (ascii->wstr == NULL) - CHECK(compact->wstr_length == 0); + CHECK(compact->wstr_length == 0); } - - /* check that the best kind is used: O(n) operation */ - if (check_content && kind != PyUnicode_WCHAR_KIND) { + + /* check that the best kind is used: O(n) operation */ + if (check_content && kind != PyUnicode_WCHAR_KIND) { Py_ssize_t i; Py_UCS4 maxchar = 0; - const void *data; + const void *data; Py_UCS4 ch; data = PyUnicode_DATA(ascii); @@ -611,28 +611,28 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) } if (kind == PyUnicode_1BYTE_KIND) { if (ascii->state.ascii == 0) { - CHECK(maxchar >= 128); - CHECK(maxchar <= 255); + CHECK(maxchar >= 128); + CHECK(maxchar <= 255); } else - CHECK(maxchar < 128); + CHECK(maxchar < 128); } else if (kind == PyUnicode_2BYTE_KIND) { - CHECK(maxchar >= 0x100); - CHECK(maxchar <= 0xFFFF); + CHECK(maxchar >= 0x100); + CHECK(maxchar <= 0xFFFF); } else { - CHECK(maxchar >= 0x10000); - CHECK(maxchar <= MAX_UNICODE); + CHECK(maxchar >= 0x10000); + CHECK(maxchar <= MAX_UNICODE); } - CHECK(PyUnicode_READ(kind, data, ascii->length) == 0); + CHECK(PyUnicode_READ(kind, data, ascii->length) == 0); } return 1; - -#undef CHECK + +#undef CHECK } - + static PyObject* unicode_result_wchar(PyObject *unicode) { @@ -682,9 +682,9 @@ unicode_result_ready(PyObject *unicode) return unicode_empty; } -#ifdef LATIN1_SINGLETONS +#ifdef LATIN1_SINGLETONS if (length == 1) { - const void *data = PyUnicode_DATA(unicode); + const void *data = PyUnicode_DATA(unicode); int kind = PyUnicode_KIND(unicode); Py_UCS4 ch = PyUnicode_READ(kind, data, 0); if (ch < 256) { @@ -704,7 +704,7 @@ unicode_result_ready(PyObject *unicode) } } } -#endif +#endif assert(_PyUnicode_CheckConsistency(unicode, 1)); return unicode; @@ -743,7 +743,7 @@ backslashreplace(_PyBytesWriter *writer, char *str, Py_ssize_t size, i; Py_UCS4 ch; enum PyUnicode_Kind kind; - const void *data; + const void *data; assert(PyUnicode_IS_READY(unicode)); kind = PyUnicode_KIND(unicode); @@ -810,7 +810,7 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str, Py_ssize_t size, i; Py_UCS4 ch; enum PyUnicode_Kind kind; - const void *data; + const void *data; assert(PyUnicode_IS_READY(unicode)); kind = PyUnicode_KIND(unicode); @@ -852,11 +852,11 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str, /* generate replacement */ for (i = collstart; i < collend; ++i) { - size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i)); - if (size < 0) { - return NULL; - } - str += size; + size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i)); + if (size < 0) { + return NULL; + } + str += size; } return str; } @@ -890,7 +890,7 @@ static BLOOM_MASK bloom_linebreak = ~(BLOOM_MASK)0; (BLOOM(bloom_linebreak, (ch)) && Py_UNICODE_ISLINEBREAK(ch))) static inline BLOOM_MASK -make_bloom_mask(int kind, const void* ptr, Py_ssize_t len) +make_bloom_mask(int kind, const void* ptr, Py_ssize_t len) { #define BLOOM_UPDATE(TYPE, MASK, PTR, LEN) \ do { \ @@ -980,14 +980,14 @@ ensure_unicode(PyObject *obj) #include "stringlib/find_max_char.h" #include "stringlib/undef.h" -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS #include "stringlib/unicodedefs.h" #include "stringlib/fastsearch.h" #include "stringlib/count.h" #include "stringlib/find.h" #include "stringlib/undef.h" -_Py_COMP_DIAG_POP +_Py_COMP_DIAG_POP /* --- Unicode Object ----------------------------------------------------- */ @@ -1001,21 +1001,21 @@ findchar(const void *s, int kind, if ((Py_UCS1) ch != ch) return -1; if (direction > 0) - return ucs1lib_find_char((const Py_UCS1 *) s, size, (Py_UCS1) ch); + return ucs1lib_find_char((const Py_UCS1 *) s, size, (Py_UCS1) ch); else - return ucs1lib_rfind_char((const Py_UCS1 *) s, size, (Py_UCS1) ch); + return ucs1lib_rfind_char((const Py_UCS1 *) s, size, (Py_UCS1) ch); case PyUnicode_2BYTE_KIND: if ((Py_UCS2) ch != ch) return -1; if (direction > 0) - return ucs2lib_find_char((const Py_UCS2 *) s, size, (Py_UCS2) ch); + return ucs2lib_find_char((const Py_UCS2 *) s, size, (Py_UCS2) ch); else - return ucs2lib_rfind_char((const Py_UCS2 *) s, size, (Py_UCS2) ch); + return ucs2lib_rfind_char((const Py_UCS2 *) s, size, (Py_UCS2) ch); case PyUnicode_4BYTE_KIND: if (direction > 0) - return ucs4lib_find_char((const Py_UCS4 *) s, size, ch); + return ucs4lib_find_char((const Py_UCS4 *) s, size, ch); else - return ucs4lib_rfind_char((const Py_UCS4 *) s, size, ch); + return ucs4lib_rfind_char((const Py_UCS4 *) s, size, ch); default: Py_UNREACHABLE(); } @@ -1074,12 +1074,12 @@ resize_compact(PyObject *unicode, Py_ssize_t length) _PyUnicode_UTF8(unicode) = NULL; _PyUnicode_UTF8_LENGTH(unicode) = 0; } -#ifdef Py_REF_DEBUG - _Py_RefTotal--; -#endif -#ifdef Py_TRACE_REFS +#ifdef Py_REF_DEBUG + _Py_RefTotal--; +#endif +#ifdef Py_TRACE_REFS _Py_ForgetReference(unicode); -#endif +#endif new_unicode = (PyObject *)PyObject_REALLOC(unicode, new_size); if (new_unicode == NULL) { @@ -1332,18 +1332,18 @@ unicode_kind_name(PyObject *unicode) #ifdef Py_DEBUG /* Functions wrapping macros for use in debugger */ -const char *_PyUnicode_utf8(void *unicode_raw){ - PyObject *unicode = _PyObject_CAST(unicode_raw); +const char *_PyUnicode_utf8(void *unicode_raw){ + PyObject *unicode = _PyObject_CAST(unicode_raw); return PyUnicode_UTF8(unicode); } -const void *_PyUnicode_compact_data(void *unicode_raw) { - PyObject *unicode = _PyObject_CAST(unicode_raw); +const void *_PyUnicode_compact_data(void *unicode_raw) { + PyObject *unicode = _PyObject_CAST(unicode_raw); return _PyUnicode_COMPACT_DATA(unicode); } -const void *_PyUnicode_data(void *unicode_raw) { - PyObject *unicode = _PyObject_CAST(unicode_raw); - printf("obj %p\n", (void*)unicode); +const void *_PyUnicode_data(void *unicode_raw) { + PyObject *unicode = _PyObject_CAST(unicode_raw); + printf("obj %p\n", (void*)unicode); printf("compact %d\n", PyUnicode_IS_COMPACT(unicode)); printf("compact ascii %d\n", PyUnicode_IS_COMPACT_ASCII(unicode)); printf("ascii op %p\n", ((void*)((PyASCIIObject*)(unicode) + 1))); @@ -1358,7 +1358,7 @@ _PyUnicode_Dump(PyObject *op) PyASCIIObject *ascii = (PyASCIIObject *)op; PyCompactUnicodeObject *compact = (PyCompactUnicodeObject *)op; PyUnicodeObject *unicode = (PyUnicodeObject *)op; - const void *data; + const void *data; if (ascii->state.compact) { @@ -1374,14 +1374,14 @@ _PyUnicode_Dump(PyObject *op) if (ascii->wstr == data) printf("shared "); - printf("wstr=%p", (void *)ascii->wstr); + printf("wstr=%p", (void *)ascii->wstr); if (!(ascii->state.ascii == 1 && ascii->state.compact == 1)) { printf(" (%" PY_FORMAT_SIZE_T "u), ", compact->wstr_length); if (!ascii->state.compact && compact->utf8 == unicode->data.any) printf("shared "); printf("utf8=%p (%" PY_FORMAT_SIZE_T "u)", - (void *)compact->utf8, compact->utf8_length); + (void *)compact->utf8, compact->utf8_length); } printf(", data=%p\n", data); } @@ -1558,8 +1558,8 @@ _copy_characters(PyObject *to, Py_ssize_t to_start, Py_ssize_t how_many, int check_maxchar) { unsigned int from_kind, to_kind; - const void *from_data; - void *to_data; + const void *from_data; + void *to_data; assert(0 <= how_many); assert(0 <= from_start); @@ -1584,7 +1584,7 @@ _copy_characters(PyObject *to, Py_ssize_t to_start, if (!check_maxchar && PyUnicode_MAX_CHAR_VALUE(from) > PyUnicode_MAX_CHAR_VALUE(to)) { - Py_UCS4 to_maxchar = PyUnicode_MAX_CHAR_VALUE(to); + Py_UCS4 to_maxchar = PyUnicode_MAX_CHAR_VALUE(to); Py_UCS4 ch; Py_ssize_t i; for (i=0; i < how_many; i++) { @@ -1602,12 +1602,12 @@ _copy_characters(PyObject *to, Py_ssize_t to_start, check that all written characters are pure ASCII */ Py_UCS4 max_char; max_char = ucs1lib_find_max_char(from_data, - (const Py_UCS1*)from_data + how_many); + (const Py_UCS1*)from_data + how_many); if (max_char >= 128) return -1; } memcpy((char*)to_data + to_kind * to_start, - (const char*)from_data + from_kind * from_start, + (const char*)from_data + from_kind * from_start, to_kind * how_many); } else if (from_kind == PyUnicode_1BYTE_KIND @@ -1794,8 +1794,8 @@ find_maxchar_surrogates(const wchar_t *begin, const wchar_t *end, *maxchar = ch; if (*maxchar > MAX_UNICODE) { PyErr_Format(PyExc_ValueError, - "character U+%x is not in range [U+0000; U+%x]", - ch, MAX_UNICODE); + "character U+%x is not in range [U+0000; U+%x]", + ch, MAX_UNICODE); return -1; } } @@ -1891,7 +1891,7 @@ _PyUnicode_Ready(PyObject *unicode) _PyUnicode_WSTR_LENGTH(unicode) = 0; #endif } - /* maxchar exceeds 16 bit, wee need 4 bytes for unicode characters */ + /* maxchar exceeds 16 bit, wee need 4 bytes for unicode characters */ else { #if SIZEOF_WCHAR_T == 2 /* in case the native representation is 2-bytes, we need to allocate a @@ -1941,32 +1941,32 @@ unicode_dealloc(PyObject *unicode) case SSTATE_INTERNED_MORTAL: /* revive dead object temporarily for DelItem */ - Py_SET_REFCNT(unicode, 3); -#ifdef INTERNED_STRINGS - if (PyDict_DelItem(interned, unicode) != 0) { - _PyErr_WriteUnraisableMsg("deletion of interned string failed", - NULL); - } -#endif + Py_SET_REFCNT(unicode, 3); +#ifdef INTERNED_STRINGS + if (PyDict_DelItem(interned, unicode) != 0) { + _PyErr_WriteUnraisableMsg("deletion of interned string failed", + NULL); + } +#endif break; case SSTATE_INTERNED_IMMORTAL: - _PyObject_ASSERT_FAILED_MSG(unicode, "Immortal interned string died"); - break; + _PyObject_ASSERT_FAILED_MSG(unicode, "Immortal interned string died"); + break; default: - Py_UNREACHABLE(); + Py_UNREACHABLE(); } - if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) { + if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) { PyObject_DEL(_PyUnicode_WSTR(unicode)); - } - if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) { + } + if (_PyUnicode_HAS_UTF8_MEMORY(unicode)) { PyObject_DEL(_PyUnicode_UTF8(unicode)); - } - if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) { + } + if (!PyUnicode_IS_COMPACT(unicode) && _PyUnicode_DATA_ANY(unicode)) { PyObject_DEL(_PyUnicode_DATA_ANY(unicode)); - } + } Py_TYPE(unicode)->tp_free(unicode); } @@ -1975,10 +1975,10 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - if (unicode == unicode_empty) { - return 1; - } -#ifdef LATIN1_SINGLETONS + if (unicode == unicode_empty) { + return 1; + } +#ifdef LATIN1_SINGLETONS PyASCIIObject *ascii = (PyASCIIObject *)unicode; if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1) { @@ -1986,7 +1986,7 @@ unicode_is_singleton(PyObject *unicode) if (ch < 256 && unicode_latin1[ch] == unicode) return 1; } -#endif +#endif return 0; } #endif @@ -2083,10 +2083,10 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index, const char *str, Py_ssize_t len) { enum PyUnicode_Kind kind = PyUnicode_KIND(unicode); - const void *data = PyUnicode_DATA(unicode); + const void *data = PyUnicode_DATA(unicode); const char *end = str + len; - assert(index + len <= PyUnicode_GET_LENGTH(unicode)); + assert(index + len <= PyUnicode_GET_LENGTH(unicode)); switch (kind) { case PyUnicode_1BYTE_KIND: { #ifdef Py_DEBUG @@ -2110,7 +2110,7 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index, assert((ucs2 - start) <= PyUnicode_GET_LENGTH(unicode)); break; } - case PyUnicode_4BYTE_KIND: { + case PyUnicode_4BYTE_KIND: { Py_UCS4 *start = (Py_UCS4 *)data + index; Py_UCS4 *ucs4 = start; @@ -2118,38 +2118,38 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index, *ucs4 = (Py_UCS4)*str; assert((ucs4 - start) <= PyUnicode_GET_LENGTH(unicode)); - break; + break; } - default: - Py_UNREACHABLE(); + default: + Py_UNREACHABLE(); } } static PyObject* get_latin1_char(unsigned char ch) { - PyObject *unicode; - -#ifdef LATIN1_SINGLETONS - unicode = unicode_latin1[ch]; - if (unicode) { - Py_INCREF(unicode); - return unicode; - } -#endif - - unicode = PyUnicode_New(1, ch); + PyObject *unicode; + +#ifdef LATIN1_SINGLETONS + unicode = unicode_latin1[ch]; + if (unicode) { + Py_INCREF(unicode); + return unicode; + } +#endif + + unicode = PyUnicode_New(1, ch); if (!unicode) { - return NULL; + return NULL; } - - PyUnicode_1BYTE_DATA(unicode)[0] = ch; - assert(_PyUnicode_CheckConsistency(unicode, 1)); - -#ifdef LATIN1_SINGLETONS + + PyUnicode_1BYTE_DATA(unicode)[0] = ch; + assert(_PyUnicode_CheckConsistency(unicode, 1)); + +#ifdef LATIN1_SINGLETONS Py_INCREF(unicode); - unicode_latin1[ch] = unicode; -#endif + unicode_latin1[ch] = unicode; +#endif return unicode; } @@ -2215,20 +2215,20 @@ PyUnicode_FromWideChar(const wchar_t *u, Py_ssize_t size) if (size == 0) _Py_RETURN_UNICODE_EMPTY(); -#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION - /* Oracle Solaris uses non-Unicode internal wchar_t form for - non-Unicode locales and hence needs conversion to UCS-4 first. */ - if (_Py_LocaleUsesNonUnicodeWchar()) { - wchar_t* converted = _Py_DecodeNonUnicodeWchar(u, size); - if (!converted) { - return NULL; - } - PyObject *unicode = _PyUnicode_FromUCS4(converted, size); - PyMem_Free(converted); - return unicode; - } -#endif - +#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION + /* Oracle Solaris uses non-Unicode internal wchar_t form for + non-Unicode locales and hence needs conversion to UCS-4 first. */ + if (_Py_LocaleUsesNonUnicodeWchar()) { + wchar_t* converted = _Py_DecodeNonUnicodeWchar(u, size); + if (!converted) { + return NULL; + } + PyObject *unicode = _PyUnicode_FromUCS4(converted, size); + PyMem_Free(converted); + return unicode; + } +#endif + /* Single character Unicode objects in the Latin-1 range are shared when using this constructor */ if (size == 1 && (Py_UCS4)*u < 256) @@ -2316,8 +2316,8 @@ _PyUnicode_FromId(_Py_Identifier *id) return id->object; } -static void -unicode_clear_static_strings(void) +static void +unicode_clear_static_strings(void) { _Py_Identifier *tmp, *s = static_strings; while (s) { @@ -2464,7 +2464,7 @@ Py_UCS4 _PyUnicode_FindMaxChar(PyObject *unicode, Py_ssize_t start, Py_ssize_t end) { enum PyUnicode_Kind kind; - const void *startptr, *endptr; + const void *startptr, *endptr; assert(PyUnicode_IS_READY(unicode)); assert(0 <= start); @@ -2527,15 +2527,15 @@ unicode_adjust_maxchar(PyObject **p_unicode) if (max_char >= 256) return; } - else if (kind == PyUnicode_4BYTE_KIND) { + else if (kind == PyUnicode_4BYTE_KIND) { const Py_UCS4 *u = PyUnicode_4BYTE_DATA(unicode); max_char = ucs4lib_find_max_char(u, u + len); if (max_char >= 0x10000) return; } - else - Py_UNREACHABLE(); - + else + Py_UNREACHABLE(); + copy = PyUnicode_New(len, max_char); if (copy != NULL) _PyUnicode_FastCopyCharacters(copy, 0, unicode, 0, len); @@ -2572,12 +2572,12 @@ _PyUnicode_Copy(PyObject *unicode) /* Widen Unicode objects to larger buffers. Don't write terminating null character. Return NULL on error. */ -static void* -unicode_askind(unsigned int skind, void const *data, Py_ssize_t len, unsigned int kind) +static void* +unicode_askind(unsigned int skind, void const *data, Py_ssize_t len, unsigned int kind) { void *result; - assert(skind < kind); + assert(skind < kind); switch (kind) { case PyUnicode_2BYTE_KIND: result = PyMem_New(Py_UCS2, len); @@ -2586,8 +2586,8 @@ unicode_askind(unsigned int skind, void const *data, Py_ssize_t len, unsigned in assert(skind == PyUnicode_1BYTE_KIND); _PyUnicode_CONVERT_BYTES( Py_UCS1, Py_UCS2, - (const Py_UCS1 *)data, - ((const Py_UCS1 *)data) + len, + (const Py_UCS1 *)data, + ((const Py_UCS1 *)data) + len, result); return result; case PyUnicode_4BYTE_KIND: @@ -2597,22 +2597,22 @@ unicode_askind(unsigned int skind, void const *data, Py_ssize_t len, unsigned in if (skind == PyUnicode_2BYTE_KIND) { _PyUnicode_CONVERT_BYTES( Py_UCS2, Py_UCS4, - (const Py_UCS2 *)data, - ((const Py_UCS2 *)data) + len, + (const Py_UCS2 *)data, + ((const Py_UCS2 *)data) + len, result); } else { assert(skind == PyUnicode_1BYTE_KIND); _PyUnicode_CONVERT_BYTES( Py_UCS1, Py_UCS4, - (const Py_UCS1 *)data, - ((const Py_UCS1 *)data) + len, + (const Py_UCS1 *)data, + ((const Py_UCS1 *)data) + len, result); } return result; default: - Py_UNREACHABLE(); - return NULL; + Py_UNREACHABLE(); + return NULL; } } @@ -2621,7 +2621,7 @@ as_ucs4(PyObject *string, Py_UCS4 *target, Py_ssize_t targetsize, int copy_null) { int kind; - const void *data; + const void *data; Py_ssize_t len, targetlen; if (PyUnicode_READY(string) == -1) return NULL; @@ -2648,19 +2648,19 @@ as_ucs4(PyObject *string, Py_UCS4 *target, Py_ssize_t targetsize, } } if (kind == PyUnicode_1BYTE_KIND) { - const Py_UCS1 *start = (const Py_UCS1 *) data; + const Py_UCS1 *start = (const Py_UCS1 *) data; _PyUnicode_CONVERT_BYTES(Py_UCS1, Py_UCS4, start, start + len, target); } else if (kind == PyUnicode_2BYTE_KIND) { - const Py_UCS2 *start = (const Py_UCS2 *) data; + const Py_UCS2 *start = (const Py_UCS2 *) data; _PyUnicode_CONVERT_BYTES(Py_UCS2, Py_UCS4, start, start + len, target); } - else if (kind == PyUnicode_4BYTE_KIND) { + else if (kind == PyUnicode_4BYTE_KIND) { memcpy(target, data, len * sizeof(Py_UCS4)); } - else { - Py_UNREACHABLE(); - } + else { + Py_UNREACHABLE(); + } if (copy_null) target[len] = 0; return target; @@ -3126,83 +3126,83 @@ PyUnicode_FromFormat(const char *format, ...) return ret; } -static Py_ssize_t -unicode_get_widechar_size(PyObject *unicode) -{ - Py_ssize_t res; - - assert(unicode != NULL); - assert(_PyUnicode_CHECK(unicode)); - - if (_PyUnicode_WSTR(unicode) != NULL) { - return PyUnicode_WSTR_LENGTH(unicode); - } - assert(PyUnicode_IS_READY(unicode)); - - res = _PyUnicode_LENGTH(unicode); -#if SIZEOF_WCHAR_T == 2 - if (PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND) { - const Py_UCS4 *s = PyUnicode_4BYTE_DATA(unicode); - const Py_UCS4 *end = s + res; - for (; s < end; ++s) { - if (*s > 0xFFFF) { - ++res; - } - } - } -#endif - return res; -} - -static void -unicode_copy_as_widechar(PyObject *unicode, wchar_t *w, Py_ssize_t size) -{ - const wchar_t *wstr; - - assert(unicode != NULL); - assert(_PyUnicode_CHECK(unicode)); - - wstr = _PyUnicode_WSTR(unicode); - if (wstr != NULL) { - memcpy(w, wstr, size * sizeof(wchar_t)); - return; - } - assert(PyUnicode_IS_READY(unicode)); - - if (PyUnicode_KIND(unicode) == PyUnicode_1BYTE_KIND) { - const Py_UCS1 *s = PyUnicode_1BYTE_DATA(unicode); - for (; size--; ++s, ++w) { - *w = *s; - } - } - else { -#if SIZEOF_WCHAR_T == 4 - assert(PyUnicode_KIND(unicode) == PyUnicode_2BYTE_KIND); - const Py_UCS2 *s = PyUnicode_2BYTE_DATA(unicode); - for (; size--; ++s, ++w) { - *w = *s; - } -#else - assert(PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND); - const Py_UCS4 *s = PyUnicode_4BYTE_DATA(unicode); - for (; size--; ++s, ++w) { - Py_UCS4 ch = *s; - if (ch > 0xFFFF) { - assert(ch <= MAX_UNICODE); - /* encode surrogate pair in this case */ - *w++ = Py_UNICODE_HIGH_SURROGATE(ch); - if (!size--) - break; - *w = Py_UNICODE_LOW_SURROGATE(ch); - } - else { - *w = ch; - } - } -#endif - } -} - +static Py_ssize_t +unicode_get_widechar_size(PyObject *unicode) +{ + Py_ssize_t res; + + assert(unicode != NULL); + assert(_PyUnicode_CHECK(unicode)); + + if (_PyUnicode_WSTR(unicode) != NULL) { + return PyUnicode_WSTR_LENGTH(unicode); + } + assert(PyUnicode_IS_READY(unicode)); + + res = _PyUnicode_LENGTH(unicode); +#if SIZEOF_WCHAR_T == 2 + if (PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND) { + const Py_UCS4 *s = PyUnicode_4BYTE_DATA(unicode); + const Py_UCS4 *end = s + res; + for (; s < end; ++s) { + if (*s > 0xFFFF) { + ++res; + } + } + } +#endif + return res; +} + +static void +unicode_copy_as_widechar(PyObject *unicode, wchar_t *w, Py_ssize_t size) +{ + const wchar_t *wstr; + + assert(unicode != NULL); + assert(_PyUnicode_CHECK(unicode)); + + wstr = _PyUnicode_WSTR(unicode); + if (wstr != NULL) { + memcpy(w, wstr, size * sizeof(wchar_t)); + return; + } + assert(PyUnicode_IS_READY(unicode)); + + if (PyUnicode_KIND(unicode) == PyUnicode_1BYTE_KIND) { + const Py_UCS1 *s = PyUnicode_1BYTE_DATA(unicode); + for (; size--; ++s, ++w) { + *w = *s; + } + } + else { +#if SIZEOF_WCHAR_T == 4 + assert(PyUnicode_KIND(unicode) == PyUnicode_2BYTE_KIND); + const Py_UCS2 *s = PyUnicode_2BYTE_DATA(unicode); + for (; size--; ++s, ++w) { + *w = *s; + } +#else + assert(PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND); + const Py_UCS4 *s = PyUnicode_4BYTE_DATA(unicode); + for (; size--; ++s, ++w) { + Py_UCS4 ch = *s; + if (ch > 0xFFFF) { + assert(ch <= MAX_UNICODE); + /* encode surrogate pair in this case */ + *w++ = Py_UNICODE_HIGH_SURROGATE(ch); + if (!size--) + break; + *w = Py_UNICODE_LOW_SURROGATE(ch); + } + else { + *w = ch; + } + } +#endif + } +} + #ifdef HAVE_WCHAR_H /* Convert a Unicode object to a wide character string. @@ -3224,35 +3224,35 @@ PyUnicode_AsWideChar(PyObject *unicode, PyErr_BadInternalCall(); return -1; } - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); return -1; - } - - res = unicode_get_widechar_size(unicode); - if (w == NULL) { - return res + 1; - } - - if (size > res) { - size = res + 1; - } - else { - res = size; - } - unicode_copy_as_widechar(unicode, w, size); - -#if HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION - /* Oracle Solaris uses non-Unicode internal wchar_t form for - non-Unicode locales and hence needs conversion first. */ - if (_Py_LocaleUsesNonUnicodeWchar()) { - if (_Py_EncodeNonUnicodeWchar_InPlace(w, size) < 0) { - return -1; - } - } -#endif - - return res; + } + + res = unicode_get_widechar_size(unicode); + if (w == NULL) { + return res + 1; + } + + if (size > res) { + size = res + 1; + } + else { + res = size; + } + unicode_copy_as_widechar(unicode, w, size); + +#if HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION + /* Oracle Solaris uses non-Unicode internal wchar_t form for + non-Unicode locales and hence needs conversion first. */ + if (_Py_LocaleUsesNonUnicodeWchar()) { + if (_Py_EncodeNonUnicodeWchar_InPlace(w, size) < 0) { + return -1; + } + } +#endif + + return res; } wchar_t* @@ -3266,38 +3266,38 @@ PyUnicode_AsWideCharString(PyObject *unicode, PyErr_BadInternalCall(); return NULL; } - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); return NULL; } - buflen = unicode_get_widechar_size(unicode); - buffer = (wchar_t *) PyMem_NEW(wchar_t, (buflen + 1)); + buflen = unicode_get_widechar_size(unicode); + buffer = (wchar_t *) PyMem_NEW(wchar_t, (buflen + 1)); if (buffer == NULL) { PyErr_NoMemory(); return NULL; } - unicode_copy_as_widechar(unicode, buffer, buflen + 1); - -#if HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION - /* Oracle Solaris uses non-Unicode internal wchar_t form for - non-Unicode locales and hence needs conversion first. */ - if (_Py_LocaleUsesNonUnicodeWchar()) { - if (_Py_EncodeNonUnicodeWchar_InPlace(buffer, (buflen + 1)) < 0) { - return NULL; - } - } -#endif - - if (size != NULL) { + unicode_copy_as_widechar(unicode, buffer, buflen + 1); + +#if HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION + /* Oracle Solaris uses non-Unicode internal wchar_t form for + non-Unicode locales and hence needs conversion first. */ + if (_Py_LocaleUsesNonUnicodeWchar()) { + if (_Py_EncodeNonUnicodeWchar_InPlace(buffer, (buflen + 1)) < 0) { + return NULL; + } + } +#endif + + if (size != NULL) { *size = buflen; - } - else if (wcslen(buffer) != (size_t)buflen) { - PyMem_FREE(buffer); - PyErr_SetString(PyExc_ValueError, - "embedded null character"); - return NULL; - } + } + else if (wcslen(buffer) != (size_t)buflen) { + PyMem_FREE(buffer); + PyErr_SetString(PyExc_ValueError, + "embedded null character"); + return NULL; + } return buffer; } @@ -3352,13 +3352,13 @@ PyUnicode_FromEncodedObject(PyObject *obj, /* Decoding bytes objects is the most common case and should be fast */ if (PyBytes_Check(obj)) { - if (PyBytes_GET_SIZE(obj) == 0) { - if (unicode_check_encoding_errors(encoding, errors) < 0) { - return NULL; - } + if (PyBytes_GET_SIZE(obj) == 0) { + if (unicode_check_encoding_errors(encoding, errors) < 0) { + return NULL; + } _Py_RETURN_UNICODE_EMPTY(); - } - return PyUnicode_Decode( + } + return PyUnicode_Decode( PyBytes_AS_STRING(obj), PyBytes_GET_SIZE(obj), encoding, errors); } @@ -3379,9 +3379,9 @@ PyUnicode_FromEncodedObject(PyObject *obj, if (buffer.len == 0) { PyBuffer_Release(&buffer); - if (unicode_check_encoding_errors(encoding, errors) < 0) { - return NULL; - } + if (unicode_check_encoding_errors(encoding, errors) < 0) { + return NULL; + } _Py_RETURN_UNICODE_EMPTY(); } @@ -3449,14 +3449,14 @@ PyUnicode_Decode(const char *s, Py_buffer info; char buflower[11]; /* strlen("iso-8859-1\0") == 11, longest shortcut */ - if (unicode_check_encoding_errors(encoding, errors) < 0) { - return NULL; - } - - if (size == 0) { - _Py_RETURN_UNICODE_EMPTY(); - } - + if (unicode_check_encoding_errors(encoding, errors) < 0) { + return NULL; + } + + if (size == 0) { + _Py_RETURN_UNICODE_EMPTY(); + } + if (encoding == NULL) { return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL); } @@ -3639,7 +3639,7 @@ PyUnicode_AsEncodedObject(PyObject *unicode, static PyObject * -unicode_encode_locale(PyObject *unicode, _Py_error_handler error_handler, +unicode_encode_locale(PyObject *unicode, _Py_error_handler error_handler, int current_locale) { Py_ssize_t wlen; @@ -3658,7 +3658,7 @@ unicode_encode_locale(PyObject *unicode, _Py_error_handler error_handler, size_t error_pos; const char *reason; int res = _Py_EncodeLocaleEx(wstr, &str, &error_pos, &reason, - current_locale, error_handler); + current_locale, error_handler); PyMem_Free(wstr); if (res != 0) { @@ -3674,9 +3674,9 @@ unicode_encode_locale(PyObject *unicode, _Py_error_handler error_handler, Py_DECREF(exc); } } - else if (res == -3) { - PyErr_SetString(PyExc_ValueError, "unsupported error handler"); - } + else if (res == -3) { + PyErr_SetString(PyExc_ValueError, "unsupported error handler"); + } else { PyErr_NoMemory(); } @@ -3691,41 +3691,41 @@ unicode_encode_locale(PyObject *unicode, _Py_error_handler error_handler, PyObject * PyUnicode_EncodeLocale(PyObject *unicode, const char *errors) { - _Py_error_handler error_handler = _Py_GetErrorHandler(errors); - return unicode_encode_locale(unicode, error_handler, 1); + _Py_error_handler error_handler = _Py_GetErrorHandler(errors); + return unicode_encode_locale(unicode, error_handler, 1); } PyObject * PyUnicode_EncodeFSDefault(PyObject *unicode) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; - if (fs_codec->utf8) { - return unicode_encode_utf8(unicode, - fs_codec->error_handler, - fs_codec->errors); - } -#ifndef _Py_FORCE_UTF8_FS_ENCODING - else if (fs_codec->encoding) { - return PyUnicode_AsEncodedString(unicode, - fs_codec->encoding, - fs_codec->errors); - } -#endif - else { - /* Before _PyUnicode_InitEncodings() is called, the Python codec - machinery is not ready and so cannot be used: - use wcstombs() in this case. */ - const PyConfig *config = _PyInterpreterState_GetConfig(interp); - const wchar_t *filesystem_errors = config->filesystem_errors; - assert(filesystem_errors != NULL); - _Py_error_handler errors = get_error_handler_wide(filesystem_errors); - assert(errors != _Py_ERROR_UNKNOWN); -#ifdef _Py_FORCE_UTF8_FS_ENCODING - return unicode_encode_utf8(unicode, errors, NULL); + PyInterpreterState *interp = _PyInterpreterState_GET(); + struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; + if (fs_codec->utf8) { + return unicode_encode_utf8(unicode, + fs_codec->error_handler, + fs_codec->errors); + } +#ifndef _Py_FORCE_UTF8_FS_ENCODING + else if (fs_codec->encoding) { + return PyUnicode_AsEncodedString(unicode, + fs_codec->encoding, + fs_codec->errors); + } +#endif + else { + /* Before _PyUnicode_InitEncodings() is called, the Python codec + machinery is not ready and so cannot be used: + use wcstombs() in this case. */ + const PyConfig *config = _PyInterpreterState_GetConfig(interp); + const wchar_t *filesystem_errors = config->filesystem_errors; + assert(filesystem_errors != NULL); + _Py_error_handler errors = get_error_handler_wide(filesystem_errors); + assert(errors != _Py_ERROR_UNKNOWN); +#ifdef _Py_FORCE_UTF8_FS_ENCODING + return unicode_encode_utf8(unicode, errors, NULL); #else - return unicode_encode_locale(unicode, errors, 0); -#endif + return unicode_encode_locale(unicode, errors, 0); +#endif } } @@ -3742,10 +3742,10 @@ PyUnicode_AsEncodedString(PyObject *unicode, return NULL; } - if (unicode_check_encoding_errors(encoding, errors) < 0) { - return NULL; - } - + if (unicode_check_encoding_errors(encoding, errors) < 0) { + return NULL; + } + if (encoding == NULL) { return _PyUnicode_AsUTF8String(unicode, errors); } @@ -3869,8 +3869,8 @@ PyUnicode_AsEncodedUnicode(PyObject *unicode, } static PyObject* -unicode_decode_locale(const char *str, Py_ssize_t len, - _Py_error_handler errors, int current_locale) +unicode_decode_locale(const char *str, Py_ssize_t len, + _Py_error_handler errors, int current_locale) { if (str[len] != '\0' || (size_t)len != strlen(str)) { PyErr_SetString(PyExc_ValueError, "embedded null byte"); @@ -3881,7 +3881,7 @@ unicode_decode_locale(const char *str, Py_ssize_t len, size_t wlen; const char *reason; int res = _Py_DecodeLocaleEx(str, &wstr, &wlen, &reason, - current_locale, errors); + current_locale, errors); if (res != 0) { if (res == -2) { PyObject *exc; @@ -3895,9 +3895,9 @@ unicode_decode_locale(const char *str, Py_ssize_t len, Py_DECREF(exc); } } - else if (res == -3) { - PyErr_SetString(PyExc_ValueError, "unsupported error handler"); - } + else if (res == -3) { + PyErr_SetString(PyExc_ValueError, "unsupported error handler"); + } else { PyErr_NoMemory(); } @@ -3913,16 +3913,16 @@ PyObject* PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len, const char *errors) { - _Py_error_handler error_handler = _Py_GetErrorHandler(errors); - return unicode_decode_locale(str, len, error_handler, 1); + _Py_error_handler error_handler = _Py_GetErrorHandler(errors); + return unicode_decode_locale(str, len, error_handler, 1); } PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors) { Py_ssize_t size = (Py_ssize_t)strlen(str); - _Py_error_handler error_handler = _Py_GetErrorHandler(errors); - return unicode_decode_locale(str, size, error_handler, 1); + _Py_error_handler error_handler = _Py_GetErrorHandler(errors); + return unicode_decode_locale(str, size, error_handler, 1); } @@ -3935,35 +3935,35 @@ PyUnicode_DecodeFSDefault(const char *s) { PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; - if (fs_codec->utf8) { - return unicode_decode_utf8(s, size, - fs_codec->error_handler, - fs_codec->errors, - NULL); - } -#ifndef _Py_FORCE_UTF8_FS_ENCODING - else if (fs_codec->encoding) { - return PyUnicode_Decode(s, size, - fs_codec->encoding, - fs_codec->errors); - } -#endif - else { - /* Before _PyUnicode_InitEncodings() is called, the Python codec - machinery is not ready and so cannot be used: - use mbstowcs() in this case. */ - const PyConfig *config = _PyInterpreterState_GetConfig(interp); - const wchar_t *filesystem_errors = config->filesystem_errors; - assert(filesystem_errors != NULL); - _Py_error_handler errors = get_error_handler_wide(filesystem_errors); - assert(errors != _Py_ERROR_UNKNOWN); -#ifdef _Py_FORCE_UTF8_FS_ENCODING - return unicode_decode_utf8(s, size, errors, NULL, NULL); + PyInterpreterState *interp = _PyInterpreterState_GET(); + struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; + if (fs_codec->utf8) { + return unicode_decode_utf8(s, size, + fs_codec->error_handler, + fs_codec->errors, + NULL); + } +#ifndef _Py_FORCE_UTF8_FS_ENCODING + else if (fs_codec->encoding) { + return PyUnicode_Decode(s, size, + fs_codec->encoding, + fs_codec->errors); + } +#endif + else { + /* Before _PyUnicode_InitEncodings() is called, the Python codec + machinery is not ready and so cannot be used: + use mbstowcs() in this case. */ + const PyConfig *config = _PyInterpreterState_GetConfig(interp); + const wchar_t *filesystem_errors = config->filesystem_errors; + assert(filesystem_errors != NULL); + _Py_error_handler errors = get_error_handler_wide(filesystem_errors); + assert(errors != _Py_ERROR_UNKNOWN); +#ifdef _Py_FORCE_UTF8_FS_ENCODING + return unicode_decode_utf8(s, size, errors, NULL, NULL); #else - return unicode_decode_locale(s, size, errors, 0); -#endif + return unicode_decode_locale(s, size, errors, 0); +#endif } } @@ -3974,7 +3974,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr) PyObject *path = NULL; PyObject *output = NULL; Py_ssize_t size; - const char *data; + const char *data; if (arg == NULL) { Py_DECREF(*(PyObject**)addr); *(PyObject**)addr = NULL; @@ -4079,8 +4079,8 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr) } -static int unicode_fill_utf8(PyObject *unicode); - +static int unicode_fill_utf8(PyObject *unicode); + const char * PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) { @@ -4092,7 +4092,7 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) return NULL; if (PyUnicode_UTF8(unicode) == NULL) { - if (unicode_fill_utf8(unicode) == -1) { + if (unicode_fill_utf8(unicode) == -1) { return NULL; } } @@ -4115,38 +4115,38 @@ PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size) PyErr_BadArgument(); return NULL; } - Py_UNICODE *w = _PyUnicode_WSTR(unicode); - if (w == NULL) { + Py_UNICODE *w = _PyUnicode_WSTR(unicode); + if (w == NULL) { /* Non-ASCII compact unicode object */ - assert(_PyUnicode_KIND(unicode) != PyUnicode_WCHAR_KIND); + assert(_PyUnicode_KIND(unicode) != PyUnicode_WCHAR_KIND); assert(PyUnicode_IS_READY(unicode)); - Py_ssize_t wlen = unicode_get_widechar_size(unicode); - if ((size_t)wlen > PY_SSIZE_T_MAX / sizeof(wchar_t) - 1) { - PyErr_NoMemory(); + Py_ssize_t wlen = unicode_get_widechar_size(unicode); + if ((size_t)wlen > PY_SSIZE_T_MAX / sizeof(wchar_t) - 1) { + PyErr_NoMemory(); + return NULL; + } + w = (wchar_t *) PyObject_MALLOC(sizeof(wchar_t) * (wlen + 1)); + if (w == NULL) { + PyErr_NoMemory(); return NULL; } - w = (wchar_t *) PyObject_MALLOC(sizeof(wchar_t) * (wlen + 1)); - if (w == NULL) { - PyErr_NoMemory(); - return NULL; + unicode_copy_as_widechar(unicode, w, wlen + 1); + _PyUnicode_WSTR(unicode) = w; + if (!PyUnicode_IS_COMPACT_ASCII(unicode)) { + _PyUnicode_WSTR_LENGTH(unicode) = wlen; } - unicode_copy_as_widechar(unicode, w, wlen + 1); - _PyUnicode_WSTR(unicode) = w; - if (!PyUnicode_IS_COMPACT_ASCII(unicode)) { - _PyUnicode_WSTR_LENGTH(unicode) = wlen; - } } if (size != NULL) *size = PyUnicode_WSTR_LENGTH(unicode); - return w; + return w; } -/* Deprecated APIs */ - -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - +/* Deprecated APIs */ + +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + Py_UNICODE * PyUnicode_AsUnicode(PyObject *unicode) { @@ -4185,8 +4185,8 @@ PyUnicode_GetSize(PyObject *unicode) return -1; } -_Py_COMP_DIAG_POP - +_Py_COMP_DIAG_POP + Py_ssize_t PyUnicode_GetLength(PyObject *unicode) { @@ -4202,7 +4202,7 @@ PyUnicode_GetLength(PyObject *unicode) Py_UCS4 PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index) { - const void *data; + const void *data; int kind; if (!PyUnicode_Check(unicode)) { @@ -4277,21 +4277,21 @@ onError: } #ifdef MS_WINDOWS -static int -widechar_resize(wchar_t **buf, Py_ssize_t *size, Py_ssize_t newsize) -{ - if (newsize > *size) { - wchar_t *newbuf = *buf; - if (PyMem_Resize(newbuf, wchar_t, newsize) == NULL) { - PyErr_NoMemory(); - return -1; - } - *buf = newbuf; - } - *size = newsize; - return 0; -} - +static int +widechar_resize(wchar_t **buf, Py_ssize_t *size, Py_ssize_t newsize) +{ + if (newsize > *size) { + wchar_t *newbuf = *buf; + if (PyMem_Resize(newbuf, wchar_t, newsize) == NULL) { + PyErr_NoMemory(); + return -1; + } + *buf = newbuf; + } + *size = newsize; + return 0; +} + /* error handling callback helper: build arguments, call the callback and check the arguments, if no exception occurred, copy the replacement to the output @@ -4305,7 +4305,7 @@ unicode_decode_call_errorhandler_wchar( const char *encoding, const char *reason, const char **input, const char **inend, Py_ssize_t *startinpos, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr, - wchar_t **buf, Py_ssize_t *bufsize, Py_ssize_t *outpos) + wchar_t **buf, Py_ssize_t *bufsize, Py_ssize_t *outpos) { static const char *argparse = "Un;decoding error handler must return (str, int) tuple"; @@ -4333,7 +4333,7 @@ unicode_decode_call_errorhandler_wchar( if (*exceptionObject == NULL) goto onError; - restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); + restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); if (restuple == NULL) goto onError; if (!PyTuple_Check(restuple)) { @@ -4362,10 +4362,10 @@ unicode_decode_call_errorhandler_wchar( goto onError; } -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS repwstr = PyUnicode_AsUnicodeAndSize(repunicode, &repwlen); -_Py_COMP_DIAG_POP +_Py_COMP_DIAG_POP if (repwstr == NULL) goto onError; /* need more space? (at least enough for what we @@ -4379,15 +4379,15 @@ _Py_COMP_DIAG_POP if (requiredsize > PY_SSIZE_T_MAX - (insize - newpos)) goto overflow; requiredsize += insize - newpos; - outsize = *bufsize; + outsize = *bufsize; if (requiredsize > outsize) { if (outsize <= PY_SSIZE_T_MAX/2 && requiredsize < 2*outsize) requiredsize = 2*outsize; - if (widechar_resize(buf, bufsize, requiredsize) < 0) { + if (widechar_resize(buf, bufsize, requiredsize) < 0) { goto onError; - } + } } - wcsncpy(*buf + *outpos, repwstr, repwlen); + wcsncpy(*buf + *outpos, repwstr, repwlen); *outpos += repwlen; *endinpos = newpos; *inptr = *input + newpos; @@ -4440,7 +4440,7 @@ unicode_decode_call_errorhandler_writer( if (*exceptionObject == NULL) goto onError; - restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); + restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); if (restuple == NULL) goto onError; if (!PyTuple_Check(restuple)) { @@ -4714,11 +4714,11 @@ PyUnicode_DecodeUTF7Stateful(const char *s, if (_PyUnicodeWriter_WriteCharInline(&writer, '+') < 0) goto onError; } - else if (s < e && !IS_BASE64(*s)) { - s++; - errmsg = "ill-formed sequence"; - goto utf7Error; - } + else if (s < e && !IS_BASE64(*s)) { + s++; + errmsg = "ill-formed sequence"; + goto utf7Error; + } else { /* begin base64-encoded section */ inShift = 1; surrogate = 0; @@ -4807,7 +4807,7 @@ _PyUnicode_EncodeUTF7(PyObject *str, const char *errors) { int kind; - const void *data; + const void *data; Py_ssize_t len; PyObject *v; int inShift = 0; @@ -4815,7 +4815,7 @@ _PyUnicode_EncodeUTF7(PyObject *str, unsigned int base64bits = 0; unsigned long base64buffer = 0; char * out; - const char * start; + const char * start; if (PyUnicode_READY(str) == -1) return NULL; @@ -5007,7 +5007,7 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest) /* Help allocation */ const char *_p = p; while (_p < aligned_end) { - unsigned long value = *(const unsigned long *) _p; + unsigned long value = *(const unsigned long *) _p; if (value & ASCII_CHAR_MASK) break; _p += SIZEOF_LONG; @@ -5024,10 +5024,10 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest) return p - start; } -static PyObject * -unicode_decode_utf8(const char *s, Py_ssize_t size, - _Py_error_handler error_handler, const char *errors, - Py_ssize_t *consumed) +static PyObject * +unicode_decode_utf8(const char *s, Py_ssize_t size, + _Py_error_handler error_handler, const char *errors, + Py_ssize_t *consumed) { if (size == 0) { if (consumed) @@ -5042,29 +5042,29 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, return get_latin1_char((unsigned char)s[0]); } - const char *starts = s; - const char *end = s + size; - - // fast path: try ASCII string. - PyObject *u = PyUnicode_New(size, 127); - if (u == NULL) { - return NULL; - } - s += ascii_decode(s, end, PyUnicode_1BYTE_DATA(u)); - if (s == end) { - return u; - } - - // Use _PyUnicodeWriter after fast path is failed. - _PyUnicodeWriter writer; - _PyUnicodeWriter_InitWithBuffer(&writer, u); - writer.pos = s - starts; - - Py_ssize_t startinpos, endinpos; - const char *errmsg = ""; - PyObject *error_handler_obj = NULL; - PyObject *exc = NULL; - + const char *starts = s; + const char *end = s + size; + + // fast path: try ASCII string. + PyObject *u = PyUnicode_New(size, 127); + if (u == NULL) { + return NULL; + } + s += ascii_decode(s, end, PyUnicode_1BYTE_DATA(u)); + if (s == end) { + return u; + } + + // Use _PyUnicodeWriter after fast path is failed. + _PyUnicodeWriter writer; + _PyUnicodeWriter_InitWithBuffer(&writer, u); + writer.pos = s - starts; + + Py_ssize_t startinpos, endinpos; + const char *errmsg = ""; + PyObject *error_handler_obj = NULL; + PyObject *exc = NULL; + while (s < end) { Py_UCS4 ch; int kind = writer.kind; @@ -5095,13 +5095,13 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, endinpos = startinpos + 1; break; case 2: - if (consumed && (unsigned char)s[0] == 0xED && end - s == 2 - && (unsigned char)s[1] >= 0xA0 && (unsigned char)s[1] <= 0xBF) - { - /* Truncated surrogate code in range D800-DFFF */ - goto End; - } - /* fall through */ + if (consumed && (unsigned char)s[0] == 0xED && end - s == 2 + && (unsigned char)s[1] >= 0xA0 && (unsigned char)s[1] <= 0xBF) + { + /* Truncated surrogate code in range D800-DFFF */ + goto End; + } + /* fall through */ case 3: case 4: errmsg = "invalid continuation byte"; @@ -5115,7 +5115,7 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, } if (error_handler == _Py_ERROR_UNKNOWN) - error_handler = _Py_GetErrorHandler(errors); + error_handler = _Py_GetErrorHandler(errors); switch (error_handler) { case _Py_ERROR_IGNORE: @@ -5170,16 +5170,16 @@ onError: } -PyObject * -PyUnicode_DecodeUTF8Stateful(const char *s, - Py_ssize_t size, - const char *errors, - Py_ssize_t *consumed) -{ - return unicode_decode_utf8(s, size, _Py_ERROR_UNKNOWN, errors, consumed); -} - - +PyObject * +PyUnicode_DecodeUTF8Stateful(const char *s, + Py_ssize_t size, + const char *errors, + Py_ssize_t *consumed) +{ + return unicode_decode_utf8(s, size, _Py_ERROR_UNKNOWN, errors, consumed); +} + + /* UTF-8 decoder: use surrogateescape error handler if 'surrogateescape' is non-zero, use strict error handler otherwise. @@ -5194,29 +5194,29 @@ PyUnicode_DecodeUTF8Stateful(const char *s, is not NULL, write the decoding error message into *reason. */ int _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, - const char **reason, _Py_error_handler errors) + const char **reason, _Py_error_handler errors) { const char *orig_s = s; const char *e; wchar_t *unicode; Py_ssize_t outpos; - int surrogateescape = 0; - int surrogatepass = 0; - switch (errors) - { - case _Py_ERROR_STRICT: - break; - case _Py_ERROR_SURROGATEESCAPE: - surrogateescape = 1; - break; - case _Py_ERROR_SURROGATEPASS: - surrogatepass = 1; - break; - default: - return -3; - } - + int surrogateescape = 0; + int surrogatepass = 0; + switch (errors) + { + case _Py_ERROR_STRICT: + break; + case _Py_ERROR_SURROGATEESCAPE: + surrogateescape = 1; + break; + case _Py_ERROR_SURROGATEPASS: + surrogatepass = 1; + break; + default: + return -3; + } + /* Note: size will always be longer than the resulting Unicode character count */ if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) < (size + 1)) { @@ -5249,45 +5249,45 @@ _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, #endif } else { - if (!ch && s == e) { + if (!ch && s == e) { break; - } - - if (surrogateescape) { - unicode[outpos++] = 0xDC00 + (unsigned char)*s++; - } - else { - /* Is it a valid three-byte code? */ - if (surrogatepass - && (e - s) >= 3 - && (s[0] & 0xf0) == 0xe0 - && (s[1] & 0xc0) == 0x80 - && (s[2] & 0xc0) == 0x80) - { - ch = ((s[0] & 0x0f) << 12) + ((s[1] & 0x3f) << 6) + (s[2] & 0x3f); - s += 3; - unicode[outpos++] = ch; - } - else { - PyMem_RawFree(unicode ); - if (reason != NULL) { - switch (ch) { - case 0: - *reason = "unexpected end of data"; - break; - case 1: - *reason = "invalid start byte"; - break; - /* 2, 3, 4 */ - default: - *reason = "invalid continuation byte"; - break; - } + } + + if (surrogateescape) { + unicode[outpos++] = 0xDC00 + (unsigned char)*s++; + } + else { + /* Is it a valid three-byte code? */ + if (surrogatepass + && (e - s) >= 3 + && (s[0] & 0xf0) == 0xe0 + && (s[1] & 0xc0) == 0x80 + && (s[2] & 0xc0) == 0x80) + { + ch = ((s[0] & 0x0f) << 12) + ((s[1] & 0x3f) << 6) + (s[2] & 0x3f); + s += 3; + unicode[outpos++] = ch; + } + else { + PyMem_RawFree(unicode ); + if (reason != NULL) { + switch (ch) { + case 0: + *reason = "unexpected end of data"; + break; + case 1: + *reason = "invalid start byte"; + break; + /* 2, 3, 4 */ + default: + *reason = "invalid continuation byte"; + break; + } } - if (wlen != NULL) { - *wlen = s - orig_s; - } - return -2; + if (wlen != NULL) { + *wlen = s - orig_s; + } + return -2; } } } @@ -5300,21 +5300,21 @@ _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, return 0; } - + wchar_t* -_Py_DecodeUTF8_surrogateescape(const char *arg, Py_ssize_t arglen, - size_t *wlen) +_Py_DecodeUTF8_surrogateescape(const char *arg, Py_ssize_t arglen, + size_t *wlen) { wchar_t *wstr; - int res = _Py_DecodeUTF8Ex(arg, arglen, - &wstr, wlen, - NULL, _Py_ERROR_SURROGATEESCAPE); + int res = _Py_DecodeUTF8Ex(arg, arglen, + &wstr, wlen, + NULL, _Py_ERROR_SURROGATEESCAPE); if (res != 0) { - /* _Py_DecodeUTF8Ex() must support _Py_ERROR_SURROGATEESCAPE */ - assert(res != -3); - if (wlen) { - *wlen = (size_t)res; - } + /* _Py_DecodeUTF8Ex() must support _Py_ERROR_SURROGATEESCAPE */ + assert(res != -3); + if (wlen) { + *wlen = (size_t)res; + } return NULL; } return wstr; @@ -5333,29 +5333,29 @@ _Py_DecodeUTF8_surrogateescape(const char *arg, Py_ssize_t arglen, On memory allocation failure, return -1. */ int _Py_EncodeUTF8Ex(const wchar_t *text, char **str, size_t *error_pos, - const char **reason, int raw_malloc, _Py_error_handler errors) + const char **reason, int raw_malloc, _Py_error_handler errors) { const Py_ssize_t max_char_size = 4; Py_ssize_t len = wcslen(text); assert(len >= 0); - int surrogateescape = 0; - int surrogatepass = 0; - switch (errors) - { - case _Py_ERROR_STRICT: - break; - case _Py_ERROR_SURROGATEESCAPE: - surrogateescape = 1; - break; - case _Py_ERROR_SURROGATEPASS: - surrogatepass = 1; - break; - default: - return -3; - } - + int surrogateescape = 0; + int surrogatepass = 0; + switch (errors) + { + case _Py_ERROR_STRICT: + break; + case _Py_ERROR_SURROGATEESCAPE: + surrogateescape = 1; + break; + case _Py_ERROR_SURROGATEPASS: + surrogatepass = 1; + break; + default: + return -3; + } + if (len > PY_SSIZE_T_MAX / max_char_size - 1) { return -1; } @@ -5372,19 +5372,19 @@ _Py_EncodeUTF8Ex(const wchar_t *text, char **str, size_t *error_pos, char *p = bytes; Py_ssize_t i; - for (i = 0; i < len; ) { - Py_ssize_t ch_pos = i; + for (i = 0; i < len; ) { + Py_ssize_t ch_pos = i; Py_UCS4 ch = text[i]; - i++; -#if Py_UNICODE_SIZE == 2 - if (Py_UNICODE_IS_HIGH_SURROGATE(ch) - && i < len - && Py_UNICODE_IS_LOW_SURROGATE(text[i])) - { - ch = Py_UNICODE_JOIN_SURROGATES(ch, text[i]); - i++; - } -#endif + i++; +#if Py_UNICODE_SIZE == 2 + if (Py_UNICODE_IS_HIGH_SURROGATE(ch) + && i < len + && Py_UNICODE_IS_LOW_SURROGATE(text[i])) + { + ch = Py_UNICODE_JOIN_SURROGATES(ch, text[i]); + i++; + } +#endif if (ch < 0x80) { /* Encode ASCII */ @@ -5396,11 +5396,11 @@ _Py_EncodeUTF8Ex(const wchar_t *text, char **str, size_t *error_pos, *p++ = (char)(0xc0 | (ch >> 6)); *p++ = (char)(0x80 | (ch & 0x3f)); } - else if (Py_UNICODE_IS_SURROGATE(ch) && !surrogatepass) { + else if (Py_UNICODE_IS_SURROGATE(ch) && !surrogatepass) { /* surrogateescape error handler */ if (!surrogateescape || !(0xDC80 <= ch && ch <= 0xDCFF)) { if (error_pos != NULL) { - *error_pos = (size_t)ch_pos; + *error_pos = (size_t)ch_pos; } if (reason != NULL) { *reason = "encoding error"; @@ -5463,9 +5463,9 @@ _Py_EncodeUTF8Ex(const wchar_t *text, char **str, size_t *error_pos, maximum possible needed (4 result bytes per Unicode character), and return the excess memory at the end. */ -static PyObject * -unicode_encode_utf8(PyObject *unicode, _Py_error_handler error_handler, - const char *errors) +static PyObject * +unicode_encode_utf8(PyObject *unicode, _Py_error_handler error_handler, + const char *errors) { if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); @@ -5479,96 +5479,96 @@ unicode_encode_utf8(PyObject *unicode, _Py_error_handler error_handler, return PyBytes_FromStringAndSize(PyUnicode_UTF8(unicode), PyUnicode_UTF8_LENGTH(unicode)); - enum PyUnicode_Kind kind = PyUnicode_KIND(unicode); - const void *data = PyUnicode_DATA(unicode); - Py_ssize_t size = PyUnicode_GET_LENGTH(unicode); + enum PyUnicode_Kind kind = PyUnicode_KIND(unicode); + const void *data = PyUnicode_DATA(unicode); + Py_ssize_t size = PyUnicode_GET_LENGTH(unicode); + + _PyBytesWriter writer; + char *end; - _PyBytesWriter writer; - char *end; - switch (kind) { default: Py_UNREACHABLE(); case PyUnicode_1BYTE_KIND: /* the string cannot be ASCII, or PyUnicode_UTF8() would be set */ assert(!PyUnicode_IS_ASCII(unicode)); - end = ucs1lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); - break; + end = ucs1lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); + break; case PyUnicode_2BYTE_KIND: - end = ucs2lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); - break; + end = ucs2lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); + break; case PyUnicode_4BYTE_KIND: - end = ucs4lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); - break; - } - - if (end == NULL) { - _PyBytesWriter_Dealloc(&writer); - return NULL; - } - return _PyBytesWriter_Finish(&writer, end); -} - -static int -unicode_fill_utf8(PyObject *unicode) -{ - /* the string cannot be ASCII, or PyUnicode_UTF8() would be set */ - assert(!PyUnicode_IS_ASCII(unicode)); - - enum PyUnicode_Kind kind = PyUnicode_KIND(unicode); - const void *data = PyUnicode_DATA(unicode); - Py_ssize_t size = PyUnicode_GET_LENGTH(unicode); - - _PyBytesWriter writer; - char *end; - - switch (kind) { - default: - Py_UNREACHABLE(); - case PyUnicode_1BYTE_KIND: - end = ucs1lib_utf8_encoder(&writer, unicode, data, size, - _Py_ERROR_STRICT, NULL); - break; - case PyUnicode_2BYTE_KIND: - end = ucs2lib_utf8_encoder(&writer, unicode, data, size, - _Py_ERROR_STRICT, NULL); - break; - case PyUnicode_4BYTE_KIND: - end = ucs4lib_utf8_encoder(&writer, unicode, data, size, - _Py_ERROR_STRICT, NULL); - break; - } - if (end == NULL) { - _PyBytesWriter_Dealloc(&writer); - return -1; - } - - const char *start = writer.use_small_buffer ? writer.small_buffer : - PyBytes_AS_STRING(writer.buffer); - Py_ssize_t len = end - start; - - char *cache = PyObject_MALLOC(len + 1); - if (cache == NULL) { - _PyBytesWriter_Dealloc(&writer); - PyErr_NoMemory(); - return -1; - } - _PyUnicode_UTF8(unicode) = cache; - _PyUnicode_UTF8_LENGTH(unicode) = len; - memcpy(cache, start, len); - cache[len] = '\0'; - _PyBytesWriter_Dealloc(&writer); - return 0; -} - + end = ucs4lib_utf8_encoder(&writer, unicode, data, size, error_handler, errors); + break; + } + + if (end == NULL) { + _PyBytesWriter_Dealloc(&writer); + return NULL; + } + return _PyBytesWriter_Finish(&writer, end); +} + +static int +unicode_fill_utf8(PyObject *unicode) +{ + /* the string cannot be ASCII, or PyUnicode_UTF8() would be set */ + assert(!PyUnicode_IS_ASCII(unicode)); + + enum PyUnicode_Kind kind = PyUnicode_KIND(unicode); + const void *data = PyUnicode_DATA(unicode); + Py_ssize_t size = PyUnicode_GET_LENGTH(unicode); + + _PyBytesWriter writer; + char *end; + + switch (kind) { + default: + Py_UNREACHABLE(); + case PyUnicode_1BYTE_KIND: + end = ucs1lib_utf8_encoder(&writer, unicode, data, size, + _Py_ERROR_STRICT, NULL); + break; + case PyUnicode_2BYTE_KIND: + end = ucs2lib_utf8_encoder(&writer, unicode, data, size, + _Py_ERROR_STRICT, NULL); + break; + case PyUnicode_4BYTE_KIND: + end = ucs4lib_utf8_encoder(&writer, unicode, data, size, + _Py_ERROR_STRICT, NULL); + break; + } + if (end == NULL) { + _PyBytesWriter_Dealloc(&writer); + return -1; + } + + const char *start = writer.use_small_buffer ? writer.small_buffer : + PyBytes_AS_STRING(writer.buffer); + Py_ssize_t len = end - start; + + char *cache = PyObject_MALLOC(len + 1); + if (cache == NULL) { + _PyBytesWriter_Dealloc(&writer); + PyErr_NoMemory(); + return -1; + } + _PyUnicode_UTF8(unicode) = cache; + _PyUnicode_UTF8_LENGTH(unicode) = len; + memcpy(cache, start, len); + cache[len] = '\0'; + _PyBytesWriter_Dealloc(&writer); + return 0; +} + +PyObject * +_PyUnicode_AsUTF8String(PyObject *unicode, const char *errors) +{ + return unicode_encode_utf8(unicode, _Py_ERROR_UNKNOWN, errors); +} + + PyObject * -_PyUnicode_AsUTF8String(PyObject *unicode, const char *errors) -{ - return unicode_encode_utf8(unicode, _Py_ERROR_UNKNOWN, errors); -} - - -PyObject * PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors) @@ -5618,7 +5618,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s, PyObject *errorHandler = NULL; PyObject *exc = NULL; - q = (const unsigned char *)s; + q = (const unsigned char *)s; e = q + size; if (byteorder) @@ -5943,7 +5943,7 @@ PyUnicode_DecodeUTF16Stateful(const char *s, PyObject *exc = NULL; const char *encoding; - q = (const unsigned char *)s; + q = (const unsigned char *)s; e = q + size; if (byteorder) @@ -6271,10 +6271,10 @@ PyUnicode_AsUTF16String(PyObject *unicode) static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL; PyObject * -_PyUnicode_DecodeUnicodeEscapeInternal(const char *s, +_PyUnicode_DecodeUnicodeEscapeInternal(const char *s, Py_ssize_t size, const char *errors, - Py_ssize_t *consumed, + Py_ssize_t *consumed, const char **first_invalid_escape) { const char *starts = s; @@ -6287,9 +6287,9 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, *first_invalid_escape = NULL; if (size == 0) { - if (consumed) { - *consumed = 0; - } + if (consumed) { + *consumed = 0; + } _Py_RETURN_UNICODE_EMPTY(); } /* Escaped strings will always be longer than the resulting @@ -6334,11 +6334,11 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, continue; } - Py_ssize_t startinpos = s - starts - 1; + Py_ssize_t startinpos = s - starts - 1; /* \ - Escapes */ if (s >= end) { message = "\\ at end of string"; - goto incomplete; + goto incomplete; } c = (unsigned char) *s++; @@ -6392,10 +6392,10 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, count = 8; message = "truncated \\UXXXXXXXX escape"; hexescape: - for (ch = 0; count; ++s, --count) { - if (s >= end) { - goto incomplete; - } + for (ch = 0; count; ++s, --count) { + if (s >= end) { + goto incomplete; + } c = (unsigned char)*s; ch <<= 4; if (c >= '0' && c <= '9') { @@ -6408,7 +6408,7 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, ch += c - ('A' - 10); } else { - goto error; + goto error; } } @@ -6437,20 +6437,20 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, } message = "malformed \\N character escape"; - if (s >= end) { - goto incomplete; - } - if (*s == '{') { + if (s >= end) { + goto incomplete; + } + if (*s == '{') { const char *start = ++s; size_t namelen; /* look for the closing brace */ while (s < end && *s != '}') s++; - if (s >= end) { - goto incomplete; - } + if (s >= end) { + goto incomplete; + } namelen = s - start; - if (namelen) { + if (namelen) { /* found a name. look it up in the unicode database */ s++; ch = 0xffffffff; /* in case 'getcode' messes up */ @@ -6476,13 +6476,13 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, continue; } - incomplete: - if (consumed) { - *consumed = startinpos; - break; - } - error:; - Py_ssize_t endinpos = s-starts; + incomplete: + if (consumed) { + *consumed = startinpos; + break; + } + error:; + Py_ssize_t endinpos = s-starts; writer.min_length = end - s + writer.pos; if (unicode_decode_call_errorhandler_writer( errors, &errorHandler, @@ -6509,14 +6509,14 @@ _PyUnicode_DecodeUnicodeEscapeInternal(const char *s, } PyObject * -_PyUnicode_DecodeUnicodeEscapeStateful(const char *s, +_PyUnicode_DecodeUnicodeEscapeStateful(const char *s, Py_ssize_t size, - const char *errors, - Py_ssize_t *consumed) + const char *errors, + Py_ssize_t *consumed) { const char *first_invalid_escape; - PyObject *result = _PyUnicode_DecodeUnicodeEscapeInternal(s, size, errors, - consumed, + PyObject *result = _PyUnicode_DecodeUnicodeEscapeInternal(s, size, errors, + consumed, &first_invalid_escape); if (result == NULL) return NULL; @@ -6531,14 +6531,14 @@ _PyUnicode_DecodeUnicodeEscapeStateful(const char *s, return result; } -PyObject * -PyUnicode_DecodeUnicodeEscape(const char *s, - Py_ssize_t size, - const char *errors) -{ - return _PyUnicode_DecodeUnicodeEscapeStateful(s, size, errors, NULL); -} - +PyObject * +PyUnicode_DecodeUnicodeEscape(const char *s, + Py_ssize_t size, + const char *errors) +{ + return _PyUnicode_DecodeUnicodeEscapeStateful(s, size, errors, NULL); +} + /* Return a Unicode-Escape string version of the Unicode object. */ PyObject * @@ -6548,7 +6548,7 @@ PyUnicode_AsUnicodeEscapeString(PyObject *unicode) PyObject *repr; char *p; enum PyUnicode_Kind kind; - const void *data; + const void *data; Py_ssize_t expandsize; /* Initial allocation is based on the longest-possible character @@ -6677,10 +6677,10 @@ PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, /* --- Raw Unicode Escape Codec ------------------------------------------- */ PyObject * -_PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, - Py_ssize_t size, - const char *errors, - Py_ssize_t *consumed) +_PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, + Py_ssize_t size, + const char *errors, + Py_ssize_t *consumed) { const char *starts = s; _PyUnicodeWriter writer; @@ -6689,9 +6689,9 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, PyObject *exc = NULL; if (size == 0) { - if (consumed) { - *consumed = 0; - } + if (consumed) { + *consumed = 0; + } _Py_RETURN_UNICODE_EMPTY(); } @@ -6700,7 +6700,7 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, length after conversion to the true value. (But decoding error handler might have to resize the string) */ _PyUnicodeWriter_Init(&writer); - writer.min_length = size; + writer.min_length = size; if (_PyUnicodeWriter_Prepare(&writer, size, 127) < 0) { goto onError; } @@ -6724,21 +6724,21 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, } while(0) /* Non-escape characters are interpreted as Unicode ordinals */ - if (c != '\\' || (s >= end && !consumed)) { + if (c != '\\' || (s >= end && !consumed)) { WRITE_CHAR(c); continue; } - Py_ssize_t startinpos = s - starts - 1; - /* \ - Escapes */ - if (s >= end) { - assert(consumed); - // Set message to silent compiler warning. - // Actually it is never used. - message = "\\ at end of string"; - goto incomplete; - } - + Py_ssize_t startinpos = s - starts - 1; + /* \ - Escapes */ + if (s >= end) { + assert(consumed); + // Set message to silent compiler warning. + // Actually it is never used. + message = "\\ at end of string"; + goto incomplete; + } + c = (unsigned char) *s++; if (c == 'u') { count = 4; @@ -6756,10 +6756,10 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, } /* \uHHHH with 4 hex digits, \U00HHHHHH with 8 */ - for (ch = 0; count; ++s, --count) { - if (s >= end) { - goto incomplete; - } + for (ch = 0; count; ++s, --count) { + if (s >= end) { + goto incomplete; + } c = (unsigned char)*s; ch <<= 4; if (c >= '0' && c <= '9') { @@ -6772,23 +6772,23 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, ch += c - ('A' - 10); } else { - goto error; + goto error; } } - if (ch > MAX_UNICODE) { + if (ch > MAX_UNICODE) { message = "\\Uxxxxxxxx out of range"; - goto error; - } - WRITE_CHAR(ch); - continue; - - incomplete: - if (consumed) { - *consumed = startinpos; - break; - } - error:; - Py_ssize_t endinpos = s-starts; + goto error; + } + WRITE_CHAR(ch); + continue; + + incomplete: + if (consumed) { + *consumed = startinpos; + break; + } + error:; + Py_ssize_t endinpos = s-starts; writer.min_length = end - s + writer.pos; if (unicode_decode_call_errorhandler_writer( errors, &errorHandler, @@ -6810,14 +6810,14 @@ _PyUnicode_DecodeRawUnicodeEscapeStateful(const char *s, Py_XDECREF(errorHandler); Py_XDECREF(exc); return NULL; -} +} -PyObject * -PyUnicode_DecodeRawUnicodeEscape(const char *s, - Py_ssize_t size, - const char *errors) -{ - return _PyUnicode_DecodeRawUnicodeEscapeStateful(s, size, errors, NULL); +PyObject * +PyUnicode_DecodeRawUnicodeEscape(const char *s, + Py_ssize_t size, + const char *errors) +{ + return _PyUnicode_DecodeRawUnicodeEscapeStateful(s, size, errors, NULL); } @@ -6828,7 +6828,7 @@ PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode) char *p; Py_ssize_t expandsize, pos; int kind; - const void *data; + const void *data; Py_ssize_t len; if (!PyUnicode_Check(unicode)) { @@ -6868,7 +6868,7 @@ PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode) if (ch < 0x100) { *p++ = (char) ch; } - /* U+0100-U+ffff range: Map 16-bit characters to '\uHHHH' */ + /* U+0100-U+ffff range: Map 16-bit characters to '\uHHHH' */ else if (ch < 0x10000) { *p++ = '\\'; *p++ = 'u'; @@ -6921,7 +6921,7 @@ PyUnicode_DecodeLatin1(const char *s, const char *errors) { /* Latin-1 is equivalent to the first 256 ordinals in Unicode. */ - return _PyUnicode_FromUCS1((const unsigned char*)s, size); + return _PyUnicode_FromUCS1((const unsigned char*)s, size); } /* create or adjust a UnicodeEncodeError */ @@ -6996,7 +6996,7 @@ unicode_encode_call_errorhandler(const char *errors, if (*exceptionObject == NULL) return NULL; - restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); + restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); if (restuple == NULL) return NULL; if (!PyTuple_Check(restuple)) { @@ -7034,7 +7034,7 @@ unicode_encode_ucs1(PyObject *unicode, /* input state */ Py_ssize_t pos=0, size; int kind; - const void *data; + const void *data; /* pointer into the output */ char *str; const char *encoding = (limit == 256) ? "latin-1" : "ascii"; @@ -7085,7 +7085,7 @@ unicode_encode_ucs1(PyObject *unicode, /* cache callback name lookup (if not done yet, i.e. it's the first error) */ if (error_handler == _Py_ERROR_UNKNOWN) - error_handler = _Py_GetErrorHandler(errors); + error_handler = _Py_GetErrorHandler(errors); switch (error_handler) { case _Py_ERROR_STRICT: @@ -7245,7 +7245,7 @@ PyUnicode_DecodeASCII(const char *s, const char *errors) { const char *starts = s; - const char *e = s + size; + const char *e = s + size; PyObject *error_handler_obj = NULL; PyObject *exc = NULL; _Py_error_handler error_handler = _Py_ERROR_UNKNOWN; @@ -7257,25 +7257,25 @@ PyUnicode_DecodeASCII(const char *s, if (size == 1 && (unsigned char)s[0] < 128) return get_latin1_char((unsigned char)s[0]); - // Shortcut for simple case - PyObject *u = PyUnicode_New(size, 127); - if (u == NULL) { + // Shortcut for simple case + PyObject *u = PyUnicode_New(size, 127); + if (u == NULL) { return NULL; - } - Py_ssize_t outpos = ascii_decode(s, e, PyUnicode_1BYTE_DATA(u)); - if (outpos == size) { - return u; - } + } + Py_ssize_t outpos = ascii_decode(s, e, PyUnicode_1BYTE_DATA(u)); + if (outpos == size) { + return u; + } - _PyUnicodeWriter writer; - _PyUnicodeWriter_InitWithBuffer(&writer, u); + _PyUnicodeWriter writer; + _PyUnicodeWriter_InitWithBuffer(&writer, u); writer.pos = outpos; - s += outpos; - int kind = writer.kind; - void *data = writer.data; - Py_ssize_t startinpos, endinpos; - + s += outpos; + int kind = writer.kind; + void *data = writer.data; + Py_ssize_t startinpos, endinpos; + while (s < e) { unsigned char c = (unsigned char)*s; if (c < 128) { @@ -7288,7 +7288,7 @@ PyUnicode_DecodeASCII(const char *s, /* byte outsize range 0x00..0x7f: call the error handler */ if (error_handler == _Py_ERROR_UNKNOWN) - error_handler = _Py_GetErrorHandler(errors); + error_handler = _Py_GetErrorHandler(errors); switch (error_handler) { @@ -7383,12 +7383,12 @@ PyUnicode_AsASCIIString(PyObject *unicode) #define NEED_RETRY #endif -/* INT_MAX is the theoretical largest chunk (or INT_MAX / 2 when - transcoding from UTF-16), but INT_MAX / 4 performs better in - both cases also and avoids partial characters overrunning the - length limit in MultiByteToWideChar on Windows */ -#define DECODING_CHUNK_SIZE (INT_MAX/4) - +/* INT_MAX is the theoretical largest chunk (or INT_MAX / 2 when + transcoding from UTF-16), but INT_MAX / 4 performs better in + both cases also and avoids partial characters overrunning the + length limit in MultiByteToWideChar on Windows */ +#define DECODING_CHUNK_SIZE (INT_MAX/4) + #ifndef WC_ERR_INVALID_CHARS # define WC_ERR_INVALID_CHARS 0x0080 #endif @@ -7430,33 +7430,33 @@ decode_code_page_flags(UINT code_page) */ static int decode_code_page_strict(UINT code_page, - wchar_t **buf, - Py_ssize_t *bufsize, + wchar_t **buf, + Py_ssize_t *bufsize, const char *in, int insize) { - DWORD flags = MB_ERR_INVALID_CHARS; + DWORD flags = MB_ERR_INVALID_CHARS; wchar_t *out; DWORD outsize; /* First get the size of the result */ assert(insize > 0); - while ((outsize = MultiByteToWideChar(code_page, flags, - in, insize, NULL, 0)) <= 0) - { - if (!flags || GetLastError() != ERROR_INVALID_FLAGS) { - goto error; - } - /* For some code pages (e.g. UTF-7) flags must be set to 0. */ - flags = 0; - } - - /* Extend a wchar_t* buffer */ - Py_ssize_t n = *bufsize; /* Get the current length */ - if (widechar_resize(buf, bufsize, n + outsize) < 0) { - return -1; - } - out = *buf + n; + while ((outsize = MultiByteToWideChar(code_page, flags, + in, insize, NULL, 0)) <= 0) + { + if (!flags || GetLastError() != ERROR_INVALID_FLAGS) { + goto error; + } + /* For some code pages (e.g. UTF-7) flags must be set to 0. */ + flags = 0; + } + + /* Extend a wchar_t* buffer */ + Py_ssize_t n = *bufsize; /* Get the current length */ + if (widechar_resize(buf, bufsize, n + outsize) < 0) { + return -1; + } + out = *buf + n; /* Do the conversion */ outsize = MultiByteToWideChar(code_page, flags, in, insize, out, outsize); @@ -7480,14 +7480,14 @@ error: */ static int decode_code_page_errors(UINT code_page, - wchar_t **buf, - Py_ssize_t *bufsize, + wchar_t **buf, + Py_ssize_t *bufsize, const char *in, const int size, const char *errors, int final) { const char *startin = in; const char *endin = in + size; - DWORD flags = MB_ERR_INVALID_CHARS; + DWORD flags = MB_ERR_INVALID_CHARS; /* Ideally, we should get reason from FormatMessage. This is the Windows 2000 English version of the message. */ const char *reason = "No mapping for the Unicode character exists " @@ -7521,16 +7521,16 @@ decode_code_page_errors(UINT code_page, goto error; } - /* Extend a wchar_t* buffer */ - Py_ssize_t n = *bufsize; /* Get the current length */ - if (size > (PY_SSIZE_T_MAX - n) / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) { - PyErr_NoMemory(); - goto error; + /* Extend a wchar_t* buffer */ + Py_ssize_t n = *bufsize; /* Get the current length */ + if (size > (PY_SSIZE_T_MAX - n) / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) { + PyErr_NoMemory(); + goto error; } - if (widechar_resize(buf, bufsize, n + size * Py_ARRAY_LENGTH(buffer)) < 0) { - goto error; + if (widechar_resize(buf, bufsize, n + size * Py_ARRAY_LENGTH(buffer)) < 0) { + goto error; } - out = *buf + n; + out = *buf + n; /* Decode the byte string character per character */ while (in < endin) @@ -7545,11 +7545,11 @@ decode_code_page_errors(UINT code_page, if (outsize > 0) break; err = GetLastError(); - if (err == ERROR_INVALID_FLAGS && flags) { - /* For some code pages (e.g. UTF-7) flags must be set to 0. */ - flags = 0; - continue; - } + if (err == ERROR_INVALID_FLAGS && flags) { + /* For some code pages (e.g. UTF-7) flags must be set to 0. */ + flags = 0; + continue; + } if (err != ERROR_NO_UNICODE_TRANSLATION && err != ERROR_INSUFFICIENT_BUFFER) { @@ -7570,16 +7570,16 @@ decode_code_page_errors(UINT code_page, startinpos = in - startin; endinpos = startinpos + 1; - outpos = out - *buf; + outpos = out - *buf; if (unicode_decode_call_errorhandler_wchar( errors, &errorHandler, encoding, reason, &startin, &endin, &startinpos, &endinpos, &exc, &in, - buf, bufsize, &outpos)) + buf, bufsize, &outpos)) { goto error; } - out = *buf + outpos; + out = *buf + outpos; } else { in += insize; @@ -7588,9 +7588,9 @@ decode_code_page_errors(UINT code_page, } } - /* Shrink the buffer */ - assert(out - *buf <= *bufsize); - *bufsize = out - *buf; + /* Shrink the buffer */ + assert(out - *buf <= *bufsize); + *bufsize = out - *buf; /* (in - startin) <= size and size is an int */ ret = Py_SAFE_DOWNCAST(in - startin, Py_ssize_t, int); @@ -7606,8 +7606,8 @@ decode_code_page_stateful(int code_page, const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed) { - wchar_t *buf = NULL; - Py_ssize_t bufsize = 0; + wchar_t *buf = NULL; + Py_ssize_t bufsize = 0; int chunk_size, final, converted, done; if (code_page < 0) { @@ -7625,8 +7625,8 @@ decode_code_page_stateful(int code_page, do { #ifdef NEED_RETRY - if (size > DECODING_CHUNK_SIZE) { - chunk_size = DECODING_CHUNK_SIZE; + if (size > DECODING_CHUNK_SIZE) { + chunk_size = DECODING_CHUNK_SIZE; final = 0; done = 0; } @@ -7639,21 +7639,21 @@ decode_code_page_stateful(int code_page, } if (chunk_size == 0 && done) { - if (buf != NULL) + if (buf != NULL) break; _Py_RETURN_UNICODE_EMPTY(); } - converted = decode_code_page_strict(code_page, &buf, &bufsize, + converted = decode_code_page_strict(code_page, &buf, &bufsize, s, chunk_size); if (converted == -2) - converted = decode_code_page_errors(code_page, &buf, &bufsize, + converted = decode_code_page_errors(code_page, &buf, &bufsize, s, chunk_size, errors, final); assert(converted != 0 || done); if (converted < 0) { - PyMem_Free(buf); + PyMem_Free(buf); return NULL; } @@ -7664,9 +7664,9 @@ decode_code_page_stateful(int code_page, size -= converted; } while (!done); - PyObject *v = PyUnicode_FromWideChar(buf, bufsize); - PyMem_Free(buf); - return v; + PyObject *v = PyUnicode_FromWideChar(buf, bufsize); + PyMem_Free(buf); + return v; } PyObject * @@ -7747,10 +7747,10 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes, substring = PyUnicode_Substring(unicode, offset, offset+len); if (substring == NULL) return -1; -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS p = PyUnicode_AsUnicodeAndSize(substring, &size); -_Py_COMP_DIAG_POP +_Py_COMP_DIAG_POP if (p == NULL) { Py_DECREF(substring); return -1; @@ -7952,7 +7952,7 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes, else { Py_ssize_t i; enum PyUnicode_Kind kind; - const void *data; + const void *data; if (PyUnicode_READY(rep) == -1) { Py_DECREF(rep); @@ -8033,8 +8033,8 @@ encode_code_page(int code_page, do { #ifdef NEED_RETRY - if (len > DECODING_CHUNK_SIZE) { - chunk_len = DECODING_CHUNK_SIZE; + if (len > DECODING_CHUNK_SIZE) { + chunk_len = DECODING_CHUNK_SIZE; done = 0; } else @@ -8110,7 +8110,7 @@ charmap_decode_string(const char *s, PyObject *errorHandler = NULL, *exc = NULL; Py_ssize_t maplen; enum PyUnicode_Kind mapkind; - const void *mapdata; + const void *mapdata; Py_UCS4 x; unsigned char ch; @@ -8127,7 +8127,7 @@ charmap_decode_string(const char *s, /* fast-path for cp037, cp500 and iso8859_1 encodings. iso8859_1 * is disabled in encoding aliases, latin1 is preferred because * its implementation is faster. */ - const Py_UCS1 *mapdata_ucs1 = (const Py_UCS1 *)mapdata; + const Py_UCS1 *mapdata_ucs1 = (const Py_UCS1 *)mapdata; Py_UCS1 *outdata = (Py_UCS1 *)writer->data; Py_UCS4 maxchar = writer->maxchar; @@ -8151,7 +8151,7 @@ charmap_decode_string(const char *s, while (s < e) { if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) { enum PyUnicode_Kind outkind = writer->kind; - const Py_UCS2 *mapdata_ucs2 = (const Py_UCS2 *)mapdata; + const Py_UCS2 *mapdata_ucs2 = (const Py_UCS2 *)mapdata; if (outkind == PyUnicode_1BYTE_KIND) { Py_UCS1 *outdata = (Py_UCS1 *)writer->data; Py_UCS4 maxchar = writer->maxchar; @@ -8260,7 +8260,7 @@ charmap_decode_mapping(const char *s, goto Undefined; if (value < 0 || value > MAX_UNICODE) { PyErr_Format(PyExc_TypeError, - "character mapping must be in range(0x%x)", + "character mapping must be in range(0x%x)", (unsigned long)MAX_UNICODE + 1); goto onError; } @@ -8381,11 +8381,11 @@ static PyTypeObject EncodingMapType = { sizeof(struct encoding_map), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ - 0, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_dealloc*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ @@ -8431,7 +8431,7 @@ PyUnicode_BuildEncodingMap(PyObject* string) unsigned char *mlevel1, *mlevel2, *mlevel3; int count2 = 0, count3 = 0; int kind; - const void *data; + const void *data; Py_ssize_t length; Py_UCS4 ch; @@ -8599,7 +8599,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping) /* wrong return value */ PyErr_Format(PyExc_TypeError, "character mapping must return integer, bytes or None, not %.400s", - Py_TYPE(x)->tp_name); + Py_TYPE(x)->tp_name); Py_DECREF(x); return NULL; } @@ -8634,7 +8634,7 @@ charmapencode_output(Py_UCS4 c, PyObject *mapping, char *outstart; Py_ssize_t outsize = PyBytes_GET_SIZE(*outobj); - if (Py_IS_TYPE(mapping, &EncodingMapType)) { + if (Py_IS_TYPE(mapping, &EncodingMapType)) { int res = encoding_map_lookup(c, mapping); Py_ssize_t requiredsize = *outpos+1; if (res == -1) @@ -8695,7 +8695,7 @@ charmap_encoding_error( Py_ssize_t size, repsize; Py_ssize_t newpos; enum PyUnicode_Kind kind; - const void *data; + const void *data; Py_ssize_t index; /* startpos for collecting unencodable chars */ Py_ssize_t collstartpos = *inpos; @@ -8713,7 +8713,7 @@ charmap_encoding_error( /* find all unencodable characters */ while (collendpos < size) { PyObject *rep; - if (Py_IS_TYPE(mapping, &EncodingMapType)) { + if (Py_IS_TYPE(mapping, &EncodingMapType)) { ch = PyUnicode_READ_CHAR(unicode, collendpos); val = encoding_map_lookup(ch, mapping); if (val != -1) @@ -8736,7 +8736,7 @@ charmap_encoding_error( /* cache callback name lookup * (if not done yet, i.e. it's the first error) */ if (*error_handler == _Py_ERROR_UNKNOWN) - *error_handler = _Py_GetErrorHandler(errors); + *error_handler = _Py_GetErrorHandler(errors); switch (*error_handler) { case _Py_ERROR_STRICT: @@ -8845,7 +8845,7 @@ _PyUnicode_EncodeCharmap(PyObject *unicode, PyObject *error_handler_obj = NULL; PyObject *exc = NULL; _Py_error_handler error_handler = _Py_ERROR_UNKNOWN; - const void *data; + const void *data; int kind; if (PyUnicode_READY(unicode) == -1) @@ -8981,7 +8981,7 @@ unicode_translate_call_errorhandler(const char *errors, if (*exceptionObject == NULL) return NULL; - restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); + restuple = PyObject_CallOneArg(*errorHandler, *exceptionObject); if (restuple == NULL) return NULL; if (!PyTuple_Check(restuple)) { @@ -9177,8 +9177,8 @@ unicode_fast_translate(PyObject *input, PyObject *mapping, { Py_UCS1 ascii_table[128], ch, ch2; Py_ssize_t len; - const Py_UCS1 *in, *end; - Py_UCS1 *out; + const Py_UCS1 *in, *end; + Py_UCS1 *out; int res = 0; len = PyUnicode_GET_LENGTH(input); @@ -9227,7 +9227,7 @@ _PyUnicode_TranslateCharmap(PyObject *input, const char *errors) { /* input object */ - const void *data; + const void *data; Py_ssize_t size, i; int kind; /* output buffer */ @@ -9246,7 +9246,7 @@ _PyUnicode_TranslateCharmap(PyObject *input, if (PyUnicode_READY(input) == -1) return NULL; - data = PyUnicode_DATA(input); + data = PyUnicode_DATA(input); kind = PyUnicode_KIND(input); size = PyUnicode_GET_LENGTH(input); @@ -9424,7 +9424,7 @@ PyUnicode_TransformDecimalToASCII(Py_UNICODE *s, Py_ssize_t i; Py_UCS4 maxchar; enum PyUnicode_Kind kind; - const void *data; + const void *data; maxchar = 127; for (i = 0; i < length; i++) { @@ -9466,7 +9466,7 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s, PyObject *unicode; Py_ssize_t i; enum PyUnicode_Kind kind; - const void *data; + const void *data; if (output == NULL) { PyErr_BadArgument(); @@ -9544,7 +9544,7 @@ any_find_slice(PyObject* s1, PyObject* s2, int direction) { int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2, result; kind1 = PyUnicode_KIND(s1); @@ -9571,7 +9571,7 @@ any_find_slice(PyObject* s1, PyObject* s2, } if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return -2; } @@ -9613,9 +9613,9 @@ any_find_slice(PyObject* s1, PyObject* s2, } } - assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(s2))); + assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(s2))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return result; } @@ -9774,7 +9774,7 @@ PyUnicode_Count(PyObject *str, { Py_ssize_t result; int kind1, kind2; - const void *buf1 = NULL, *buf2 = NULL; + const void *buf1 = NULL, *buf2 = NULL; Py_ssize_t len1, len2; if (ensure_unicode(str) < 0 || ensure_unicode(substr) < 0) @@ -9794,7 +9794,7 @@ PyUnicode_Count(PyObject *str, buf1 = PyUnicode_DATA(str); buf2 = PyUnicode_DATA(substr); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) goto onError; } @@ -9803,24 +9803,24 @@ PyUnicode_Count(PyObject *str, case PyUnicode_1BYTE_KIND: if (PyUnicode_IS_ASCII(str) && PyUnicode_IS_ASCII(substr)) result = asciilib_count( - ((const Py_UCS1*)buf1) + start, end - start, + ((const Py_UCS1*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); else result = ucs1lib_count( - ((const Py_UCS1*)buf1) + start, end - start, + ((const Py_UCS1*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; case PyUnicode_2BYTE_KIND: result = ucs2lib_count( - ((const Py_UCS2*)buf1) + start, end - start, + ((const Py_UCS2*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; case PyUnicode_4BYTE_KIND: result = ucs4lib_count( - ((const Py_UCS4*)buf1) + start, end - start, + ((const Py_UCS4*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; @@ -9828,15 +9828,15 @@ PyUnicode_Count(PyObject *str, Py_UNREACHABLE(); } - assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substr))); + assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substr))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return result; onError: - assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substr))); - if (kind2 != kind1) - PyMem_Free((void *)buf2); + assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substr))); + if (kind2 != kind1) + PyMem_Free((void *)buf2); return -1; } @@ -9884,8 +9884,8 @@ tailmatch(PyObject *self, { int kind_self; int kind_sub; - const void *data_self; - const void *data_sub; + const void *data_self; + const void *data_sub; Py_ssize_t offset; Py_ssize_t i; Py_ssize_t end_sub; @@ -9959,8 +9959,8 @@ static PyObject * ascii_upper_or_lower(PyObject *self, int lower) { Py_ssize_t len = PyUnicode_GET_LENGTH(self); - const char *data = PyUnicode_DATA(self); - char *resdata; + const char *data = PyUnicode_DATA(self); + char *resdata; PyObject *res; res = PyUnicode_New(len, 127); @@ -9975,7 +9975,7 @@ ascii_upper_or_lower(PyObject *self, int lower) } static Py_UCS4 -handle_capital_sigma(int kind, const void *data, Py_ssize_t length, Py_ssize_t i) +handle_capital_sigma(int kind, const void *data, Py_ssize_t length, Py_ssize_t i) { Py_ssize_t j; int final_sigma; @@ -10004,7 +10004,7 @@ handle_capital_sigma(int kind, const void *data, Py_ssize_t length, Py_ssize_t i } static int -lower_ucs4(int kind, const void *data, Py_ssize_t length, Py_ssize_t i, +lower_ucs4(int kind, const void *data, Py_ssize_t length, Py_ssize_t i, Py_UCS4 c, Py_UCS4 *mapped) { /* Obscure special case. */ @@ -10016,14 +10016,14 @@ lower_ucs4(int kind, const void *data, Py_ssize_t length, Py_ssize_t i, } static Py_ssize_t -do_capitalize(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) +do_capitalize(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { Py_ssize_t i, k = 0; int n_res, j; Py_UCS4 c, mapped[3]; c = PyUnicode_READ(kind, data, 0); - n_res = _PyUnicode_ToTitleFull(c, mapped); + n_res = _PyUnicode_ToTitleFull(c, mapped); for (j = 0; j < n_res; j++) { *maxchar = Py_MAX(*maxchar, mapped[j]); res[k++] = mapped[j]; @@ -10040,7 +10040,7 @@ do_capitalize(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UC } static Py_ssize_t -do_swapcase(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { +do_swapcase(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { Py_ssize_t i, k = 0; for (i = 0; i < length; i++) { @@ -10065,7 +10065,7 @@ do_swapcase(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 } static Py_ssize_t -do_upper_or_lower(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, +do_upper_or_lower(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar, int lower) { Py_ssize_t i, k = 0; @@ -10086,19 +10086,19 @@ do_upper_or_lower(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, } static Py_ssize_t -do_upper(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) +do_upper(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { return do_upper_or_lower(kind, data, length, res, maxchar, 0); } static Py_ssize_t -do_lower(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) +do_lower(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { return do_upper_or_lower(kind, data, length, res, maxchar, 1); } static Py_ssize_t -do_casefold(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) +do_casefold(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { Py_ssize_t i, k = 0; @@ -10115,7 +10115,7 @@ do_casefold(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 } static Py_ssize_t -do_title(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) +do_title(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *maxchar) { Py_ssize_t i, k = 0; int previous_is_cased; @@ -10143,13 +10143,13 @@ do_title(int kind, const void *data, Py_ssize_t length, Py_UCS4 *res, Py_UCS4 *m static PyObject * case_operation(PyObject *self, - Py_ssize_t (*perform)(int, const void *, Py_ssize_t, Py_UCS4 *, Py_UCS4 *)) + Py_ssize_t (*perform)(int, const void *, Py_ssize_t, Py_UCS4 *, Py_UCS4 *)) { PyObject *res = NULL; Py_ssize_t length, newlength = 0; int kind, outkind; - const void *data; - void *outdata; + const void *data; + void *outdata; Py_UCS4 maxchar = 0, *tmp, *tmpend; assert(PyUnicode_IS_READY(self)); @@ -10396,7 +10396,7 @@ _PyUnicode_FastFill(PyObject *unicode, Py_ssize_t start, Py_ssize_t length, assert(fill_char <= PyUnicode_MAX_CHAR_VALUE(unicode)); assert(start >= 0); assert(start + length <= PyUnicode_GET_LENGTH(unicode)); - unicode_fill(kind, data, fill_char, start, length); + unicode_fill(kind, data, fill_char, start, length); } Py_ssize_t @@ -10467,9 +10467,9 @@ pad(PyObject *self, kind = PyUnicode_KIND(u); data = PyUnicode_DATA(u); if (left) - unicode_fill(kind, data, fill, 0, left); + unicode_fill(kind, data, fill, 0, left); if (right) - unicode_fill(kind, data, fill, left + _PyUnicode_LENGTH(self), right); + unicode_fill(kind, data, fill, left + _PyUnicode_LENGTH(self), right); _PyUnicode_FastCopyCharacters(u, left, self, 0, _PyUnicode_LENGTH(self)); assert(_PyUnicode_CheckConsistency(u, 1)); return u; @@ -10516,7 +10516,7 @@ split(PyObject *self, Py_ssize_t maxcount) { int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2; PyObject* out; @@ -10571,7 +10571,7 @@ split(PyObject *self, buf1 = PyUnicode_DATA(self); buf2 = PyUnicode_DATA(substring); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return NULL; } @@ -10596,9 +10596,9 @@ split(PyObject *self, default: out = NULL; } - assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substring))); + assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substring))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return out; } @@ -10608,7 +10608,7 @@ rsplit(PyObject *self, Py_ssize_t maxcount) { int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2; PyObject* out; @@ -10663,7 +10663,7 @@ rsplit(PyObject *self, buf1 = PyUnicode_DATA(self); buf2 = PyUnicode_DATA(substring); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return NULL; } @@ -10688,15 +10688,15 @@ rsplit(PyObject *self, default: out = NULL; } - assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substring))); + assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substring))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return out; } static Py_ssize_t -anylib_find(int kind, PyObject *str1, const void *buf1, Py_ssize_t len1, - PyObject *str2, const void *buf2, Py_ssize_t len2, Py_ssize_t offset) +anylib_find(int kind, PyObject *str1, const void *buf1, Py_ssize_t len1, + PyObject *str2, const void *buf2, Py_ssize_t len2, Py_ssize_t offset) { switch (kind) { case PyUnicode_1BYTE_KIND: @@ -10713,8 +10713,8 @@ anylib_find(int kind, PyObject *str1, const void *buf1, Py_ssize_t len1, } static Py_ssize_t -anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen, - PyObject *str1, const void *buf1, Py_ssize_t len1, Py_ssize_t maxcount) +anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen, + PyObject *str1, const void *buf1, Py_ssize_t len1, Py_ssize_t maxcount) { switch (kind) { case PyUnicode_1BYTE_KIND: @@ -10760,9 +10760,9 @@ replace(PyObject *self, PyObject *str1, PyObject *str2, Py_ssize_t maxcount) { PyObject *u; - const char *sbuf = PyUnicode_DATA(self); - const void *buf1 = PyUnicode_DATA(str1); - const void *buf2 = PyUnicode_DATA(str2); + const char *sbuf = PyUnicode_DATA(self); + const void *buf1 = PyUnicode_DATA(str1); + const void *buf2 = PyUnicode_DATA(str2); int srelease = 0, release1 = 0, release2 = 0; int skind = PyUnicode_KIND(self); int kind1 = PyUnicode_KIND(str1); @@ -10773,12 +10773,12 @@ replace(PyObject *self, PyObject *str1, int mayshrink; Py_UCS4 maxchar, maxchar_str1, maxchar_str2; - if (slen < len1) - goto nothing; - + if (slen < len1) + goto nothing; + if (maxcount < 0) maxcount = PY_SSIZE_T_MAX; - else if (maxcount == 0) + else if (maxcount == 0) goto nothing; if (str1 == str2) @@ -10823,7 +10823,7 @@ replace(PyObject *self, PyObject *str1, if (kind1 < rkind) { /* widen substring */ - buf1 = unicode_askind(kind1, buf1, len1, rkind); + buf1 = unicode_askind(kind1, buf1, len1, rkind); if (!buf1) goto error; release1 = 1; } @@ -10832,23 +10832,23 @@ replace(PyObject *self, PyObject *str1, goto nothing; if (rkind > kind2) { /* widen replacement */ - buf2 = unicode_askind(kind2, buf2, len2, rkind); + buf2 = unicode_askind(kind2, buf2, len2, rkind); if (!buf2) goto error; release2 = 1; } else if (rkind < kind2) { /* widen self and buf1 */ rkind = kind2; - if (release1) { - assert(buf1 != PyUnicode_DATA(str1)); - PyMem_Free((void *)buf1); - buf1 = PyUnicode_DATA(str1); - release1 = 0; - } - sbuf = unicode_askind(skind, sbuf, slen, rkind); + if (release1) { + assert(buf1 != PyUnicode_DATA(str1)); + PyMem_Free((void *)buf1); + buf1 = PyUnicode_DATA(str1); + release1 = 0; + } + sbuf = unicode_askind(skind, sbuf, slen, rkind); if (!sbuf) goto error; srelease = 1; - buf1 = unicode_askind(kind1, buf1, len1, rkind); + buf1 = unicode_askind(kind1, buf1, len1, rkind); if (!buf1) goto error; release1 = 1; } @@ -10886,7 +10886,7 @@ replace(PyObject *self, PyObject *str1, if (kind1 < rkind) { /* widen substring */ - buf1 = unicode_askind(kind1, buf1, len1, rkind); + buf1 = unicode_askind(kind1, buf1, len1, rkind); if (!buf1) goto error; release1 = 1; } @@ -10895,28 +10895,28 @@ replace(PyObject *self, PyObject *str1, goto nothing; if (kind2 < rkind) { /* widen replacement */ - buf2 = unicode_askind(kind2, buf2, len2, rkind); + buf2 = unicode_askind(kind2, buf2, len2, rkind); if (!buf2) goto error; release2 = 1; } else if (kind2 > rkind) { /* widen self and buf1 */ rkind = kind2; - sbuf = unicode_askind(skind, sbuf, slen, rkind); + sbuf = unicode_askind(skind, sbuf, slen, rkind); if (!sbuf) goto error; srelease = 1; - if (release1) { - assert(buf1 != PyUnicode_DATA(str1)); - PyMem_Free((void *)buf1); - buf1 = PyUnicode_DATA(str1); - release1 = 0; - } - buf1 = unicode_askind(kind1, buf1, len1, rkind); + if (release1) { + assert(buf1 != PyUnicode_DATA(str1)); + PyMem_Free((void *)buf1); + buf1 = PyUnicode_DATA(str1); + release1 = 0; + } + buf1 = unicode_askind(kind1, buf1, len1, rkind); if (!buf1) goto error; release1 = 1; } /* new_size = PyUnicode_GET_LENGTH(self) + n * (PyUnicode_GET_LENGTH(str2) - - PyUnicode_GET_LENGTH(str1)); */ + PyUnicode_GET_LENGTH(str1)); */ if (len1 < len2 && len2 - len1 > (PY_SSIZE_T_MAX - slen) / n) { PyErr_SetString(PyExc_OverflowError, "replace string is too long"); @@ -10999,41 +10999,41 @@ replace(PyObject *self, PyObject *str1, } done: - assert(srelease == (sbuf != PyUnicode_DATA(self))); - assert(release1 == (buf1 != PyUnicode_DATA(str1))); - assert(release2 == (buf2 != PyUnicode_DATA(str2))); + assert(srelease == (sbuf != PyUnicode_DATA(self))); + assert(release1 == (buf1 != PyUnicode_DATA(str1))); + assert(release2 == (buf2 != PyUnicode_DATA(str2))); if (srelease) - PyMem_FREE((void *)sbuf); + PyMem_FREE((void *)sbuf); if (release1) - PyMem_FREE((void *)buf1); + PyMem_FREE((void *)buf1); if (release2) - PyMem_FREE((void *)buf2); + PyMem_FREE((void *)buf2); assert(_PyUnicode_CheckConsistency(u, 1)); return u; nothing: /* nothing to replace; return original string (when possible) */ - assert(srelease == (sbuf != PyUnicode_DATA(self))); - assert(release1 == (buf1 != PyUnicode_DATA(str1))); - assert(release2 == (buf2 != PyUnicode_DATA(str2))); + assert(srelease == (sbuf != PyUnicode_DATA(self))); + assert(release1 == (buf1 != PyUnicode_DATA(str1))); + assert(release2 == (buf2 != PyUnicode_DATA(str2))); if (srelease) - PyMem_FREE((void *)sbuf); + PyMem_FREE((void *)sbuf); if (release1) - PyMem_FREE((void *)buf1); + PyMem_FREE((void *)buf1); if (release2) - PyMem_FREE((void *)buf2); + PyMem_FREE((void *)buf2); return unicode_result_unchanged(self); error: - assert(srelease == (sbuf != PyUnicode_DATA(self))); - assert(release1 == (buf1 != PyUnicode_DATA(str1))); - assert(release2 == (buf2 != PyUnicode_DATA(str2))); - if (srelease) - PyMem_FREE((void *)sbuf); - if (release1) - PyMem_FREE((void *)buf1); - if (release2) - PyMem_FREE((void *)buf2); + assert(srelease == (sbuf != PyUnicode_DATA(self))); + assert(release1 == (buf1 != PyUnicode_DATA(str1))); + assert(release2 == (buf2 != PyUnicode_DATA(str2))); + if (srelease) + PyMem_FREE((void *)sbuf); + if (release1) + PyMem_FREE((void *)buf1); + if (release2) + PyMem_FREE((void *)buf2); return NULL; } @@ -11170,7 +11170,7 @@ unicode_compare(PyObject *str1, PyObject *str2) while (0) int kind1, kind2; - const void *data1, *data2; + const void *data1, *data2; Py_ssize_t len1, len2, len; kind1 = PyUnicode_KIND(str1); @@ -11271,7 +11271,7 @@ static int unicode_compare_eq(PyObject *str1, PyObject *str2) { int kind; - const void *data1, *data2; + const void *data1, *data2; Py_ssize_t len; int cmp; @@ -11305,8 +11305,8 @@ PyUnicode_Compare(PyObject *left, PyObject *right) } PyErr_Format(PyExc_TypeError, "Can't compare %.100s and %.100s", - Py_TYPE(left)->tp_name, - Py_TYPE(right)->tp_name); + Py_TYPE(left)->tp_name, + Py_TYPE(right)->tp_name); return -1; } @@ -11356,7 +11356,7 @@ PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str) return 0; } else { - const void *data = PyUnicode_DATA(uni); + const void *data = PyUnicode_DATA(uni); /* Compare Unicode string and source character set string */ for (i = 0; (chr = PyUnicode_READ(kind, data, i)) && str[i]; i++) if (chr != (unsigned char)str[i]) @@ -11447,12 +11447,12 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right) if (PyUnicode_CHECK_INTERNED(left)) return 0; -#ifdef INTERNED_STRINGS +#ifdef INTERNED_STRINGS assert(_PyUnicode_HASH(right_uni) != -1); - Py_hash_t hash = _PyUnicode_HASH(left); + Py_hash_t hash = _PyUnicode_HASH(left); if (hash != -1 && hash != _PyUnicode_HASH(right_uni)) return 0; -#endif +#endif return unicode_compare_eq(left, right_uni); } @@ -11506,7 +11506,7 @@ int PyUnicode_Contains(PyObject *str, PyObject *substr) { int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2; int result; @@ -11537,7 +11537,7 @@ PyUnicode_Contains(PyObject *str, PyObject *substr) return result; } if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return -1; } @@ -11556,9 +11556,9 @@ PyUnicode_Contains(PyObject *str, PyObject *substr) Py_UNREACHABLE(); } - assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(substr))); + assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(substr))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return result; } @@ -11578,7 +11578,7 @@ PyUnicode_Concat(PyObject *left, PyObject *right) if (!PyUnicode_Check(right)) { PyErr_Format(PyExc_TypeError, "can only concatenate str (not \"%.200s\") to str", - Py_TYPE(right)->tp_name); + Py_TYPE(right)->tp_name); return NULL; } if (PyUnicode_READY(right) < 0) @@ -11735,7 +11735,7 @@ unicode_count(PyObject *self, PyObject *args) Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *result; int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2, iresult; if (!parse_args_finds_unicode("count", args, &substring, &start, &end)) @@ -11755,26 +11755,26 @@ unicode_count(PyObject *self, PyObject *args) buf1 = PyUnicode_DATA(self); buf2 = PyUnicode_DATA(substring); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return NULL; } switch (kind1) { case PyUnicode_1BYTE_KIND: iresult = ucs1lib_count( - ((const Py_UCS1*)buf1) + start, end - start, + ((const Py_UCS1*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; case PyUnicode_2BYTE_KIND: iresult = ucs2lib_count( - ((const Py_UCS2*)buf1) + start, end - start, + ((const Py_UCS2*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; case PyUnicode_4BYTE_KIND: iresult = ucs4lib_count( - ((const Py_UCS4*)buf1) + start, end - start, + ((const Py_UCS4*)buf1) + start, end - start, buf2, len2, PY_SSIZE_T_MAX ); break; @@ -11784,9 +11784,9 @@ unicode_count(PyObject *self, PyObject *args) result = PyLong_FromSsize_t(iresult); - assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(substring))); + assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(substring))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return result; } @@ -11830,8 +11830,8 @@ unicode_expandtabs_impl(PyObject *self, int tabsize) Py_ssize_t i, j, line_pos, src_len, incr; Py_UCS4 ch; PyObject *u; - const void *src_data; - void *dest_data; + const void *src_data; + void *dest_data; int kind; int found; @@ -11882,7 +11882,7 @@ unicode_expandtabs_impl(PyObject *self, int tabsize) if (tabsize > 0) { incr = tabsize - (line_pos % tabsize); line_pos += incr; - unicode_fill(kind, dest_data, ' ', j, incr); + unicode_fill(kind, dest_data, ' ', j, incr); j += incr; } } @@ -11937,7 +11937,7 @@ unicode_find(PyObject *self, PyObject *args) static PyObject * unicode_getitem(PyObject *self, Py_ssize_t index) { - const void *data; + const void *data; enum PyUnicode_Kind kind; Py_UCS4 ch; @@ -11972,7 +11972,7 @@ unicode_hash(PyObject *self) return _PyUnicode_HASH(self); if (PyUnicode_READY(self) == -1) return -1; - + x = _Py_HashBytes(PyUnicode_DATA(self), PyUnicode_GET_LENGTH(self) * PyUnicode_KIND(self)); _PyUnicode_HASH(self) = x; @@ -11982,7 +11982,7 @@ unicode_hash(PyObject *self) PyDoc_STRVAR(index__doc__, "S.index(sub[, start[, end]]) -> int\n\ \n\ -Return the lowest index in S where substring sub is found,\n\ +Return the lowest index in S where substring sub is found,\n\ such that sub is contained within S[start:end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ @@ -12050,7 +12050,7 @@ unicode_islower_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; int cased; if (PyUnicode_READY(self) == -1) @@ -12095,7 +12095,7 @@ unicode_isupper_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; int cased; if (PyUnicode_READY(self) == -1) @@ -12140,7 +12140,7 @@ unicode_istitle_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; int cased, previous_is_cased; if (PyUnicode_READY(self) == -1) @@ -12198,7 +12198,7 @@ unicode_isspace_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12238,7 +12238,7 @@ unicode_isalpha_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12276,7 +12276,7 @@ unicode_isalnum_impl(PyObject *self) /*[clinic end generated code: output=a5a23490ffc3660c input=5c6579bf2e04758c]*/ { int kind; - const void *data; + const void *data; Py_ssize_t len, i; if (PyUnicode_READY(self) == -1) @@ -12319,7 +12319,7 @@ unicode_isdecimal_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12358,7 +12358,7 @@ unicode_isdigit_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12398,7 +12398,7 @@ unicode_isnumeric_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12422,22 +12422,22 @@ unicode_isnumeric_impl(PyObject *self) Py_RETURN_TRUE; } -Py_ssize_t -_PyUnicode_ScanIdentifier(PyObject *self) +Py_ssize_t +_PyUnicode_ScanIdentifier(PyObject *self) { Py_ssize_t i; - if (PyUnicode_READY(self) == -1) - return -1; + if (PyUnicode_READY(self) == -1) + return -1; - Py_ssize_t len = PyUnicode_GET_LENGTH(self); - if (len == 0) { - /* an empty string is not a valid identifier */ + Py_ssize_t len = PyUnicode_GET_LENGTH(self); + if (len == 0) { + /* an empty string is not a valid identifier */ return 0; } - int kind = PyUnicode_KIND(self); - const void *data = PyUnicode_DATA(self); - Py_UCS4 ch = PyUnicode_READ(kind, data, 0); + int kind = PyUnicode_KIND(self); + const void *data = PyUnicode_DATA(self); + Py_UCS4 ch = PyUnicode_READ(kind, data, 0); /* PEP 3131 says that the first character must be in XID_Start and subsequent characters in XID_Continue, and for the ASCII range, the 2.x rules apply (i.e @@ -12446,70 +12446,70 @@ _PyUnicode_ScanIdentifier(PyObject *self) definition of XID_Start and XID_Continue, it is sufficient to check just for these, except that _ must be allowed as starting an identifier. */ - if (!_PyUnicode_IsXidStart(ch) && ch != 0x5F /* LOW LINE */) { + if (!_PyUnicode_IsXidStart(ch) && ch != 0x5F /* LOW LINE */) { return 0; - } - - for (i = 1; i < len; i++) { - ch = PyUnicode_READ(kind, data, i); - if (!_PyUnicode_IsXidContinue(ch)) { - return i; - } - } - return i; -} - -int -PyUnicode_IsIdentifier(PyObject *self) -{ - if (PyUnicode_IS_READY(self)) { - Py_ssize_t i = _PyUnicode_ScanIdentifier(self); - Py_ssize_t len = PyUnicode_GET_LENGTH(self); - /* an empty string is not a valid identifier */ - return len && i == len; - } - else { -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - Py_ssize_t i = 0, len = PyUnicode_GET_SIZE(self); - if (len == 0) { - /* an empty string is not a valid identifier */ + } + + for (i = 1; i < len; i++) { + ch = PyUnicode_READ(kind, data, i); + if (!_PyUnicode_IsXidContinue(ch)) { + return i; + } + } + return i; +} + +int +PyUnicode_IsIdentifier(PyObject *self) +{ + if (PyUnicode_IS_READY(self)) { + Py_ssize_t i = _PyUnicode_ScanIdentifier(self); + Py_ssize_t len = PyUnicode_GET_LENGTH(self); + /* an empty string is not a valid identifier */ + return len && i == len; + } + else { +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + Py_ssize_t i = 0, len = PyUnicode_GET_SIZE(self); + if (len == 0) { + /* an empty string is not a valid identifier */ return 0; - } - - const wchar_t *wstr = _PyUnicode_WSTR(self); - Py_UCS4 ch = wstr[i++]; -#if SIZEOF_WCHAR_T == 2 - if (Py_UNICODE_IS_HIGH_SURROGATE(ch) - && i < len - && Py_UNICODE_IS_LOW_SURROGATE(wstr[i])) - { - ch = Py_UNICODE_JOIN_SURROGATES(ch, wstr[i]); - i++; - } -#endif - if (!_PyUnicode_IsXidStart(ch) && ch != 0x5F /* LOW LINE */) { - return 0; - } - - while (i < len) { - ch = wstr[i++]; -#if SIZEOF_WCHAR_T == 2 - if (Py_UNICODE_IS_HIGH_SURROGATE(ch) - && i < len - && Py_UNICODE_IS_LOW_SURROGATE(wstr[i])) - { - ch = Py_UNICODE_JOIN_SURROGATES(ch, wstr[i]); - i++; - } -#endif - if (!_PyUnicode_IsXidContinue(ch)) { - return 0; - } - } - return 1; -_Py_COMP_DIAG_POP - } + } + + const wchar_t *wstr = _PyUnicode_WSTR(self); + Py_UCS4 ch = wstr[i++]; +#if SIZEOF_WCHAR_T == 2 + if (Py_UNICODE_IS_HIGH_SURROGATE(ch) + && i < len + && Py_UNICODE_IS_LOW_SURROGATE(wstr[i])) + { + ch = Py_UNICODE_JOIN_SURROGATES(ch, wstr[i]); + i++; + } +#endif + if (!_PyUnicode_IsXidStart(ch) && ch != 0x5F /* LOW LINE */) { + return 0; + } + + while (i < len) { + ch = wstr[i++]; +#if SIZEOF_WCHAR_T == 2 + if (Py_UNICODE_IS_HIGH_SURROGATE(ch) + && i < len + && Py_UNICODE_IS_LOW_SURROGATE(wstr[i])) + { + ch = Py_UNICODE_JOIN_SURROGATES(ch, wstr[i]); + i++; + } +#endif + if (!_PyUnicode_IsXidContinue(ch)) { + return 0; + } + } + return 1; +_Py_COMP_DIAG_POP + } } /*[clinic input] @@ -12517,13 +12517,13 @@ str.isidentifier as unicode_isidentifier Return True if the string is a valid Python identifier, False otherwise. -Call keyword.iskeyword(s) to test whether string s is a reserved identifier, -such as "def" or "class". +Call keyword.iskeyword(s) to test whether string s is a reserved identifier, +such as "def" or "class". [clinic start generated code]*/ static PyObject * unicode_isidentifier_impl(PyObject *self) -/*[clinic end generated code: output=fe585a9666572905 input=2d807a104f21c0c5]*/ +/*[clinic end generated code: output=fe585a9666572905 input=2d807a104f21c0c5]*/ { return PyBool_FromLong(PyUnicode_IsIdentifier(self)); } @@ -12543,7 +12543,7 @@ unicode_isprintable_impl(PyObject *self) { Py_ssize_t i, length; int kind; - const void *data; + const void *data; if (PyUnicode_READY(self) == -1) return NULL; @@ -12648,7 +12648,7 @@ static const char *stripfuncnames[] = {"lstrip", "rstrip", "strip"}; PyObject * _PyUnicode_XStrip(PyObject *self, int striptype, PyObject *sepobj) { - const void *data; + const void *data; int kind; Py_ssize_t i, j, len; BLOOM_MASK sepmask; @@ -12698,7 +12698,7 @@ _PyUnicode_XStrip(PyObject *self, int striptype, PyObject *sepobj) PyObject* PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end) { - const unsigned char *data; + const unsigned char *data; int kind; Py_ssize_t length; @@ -12721,7 +12721,7 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end) length = end - start; if (PyUnicode_IS_ASCII(self)) { data = PyUnicode_1BYTE_DATA(self); - return _PyUnicode_FromASCII((const char*)(data + start), length); + return _PyUnicode_FromASCII((const char*)(data + start), length); } else { kind = PyUnicode_KIND(self); @@ -12743,7 +12743,7 @@ do_strip(PyObject *self, int striptype) len = PyUnicode_GET_LENGTH(self); if (PyUnicode_IS_ASCII(self)) { - const Py_UCS1 *data = PyUnicode_1BYTE_DATA(self); + const Py_UCS1 *data = PyUnicode_1BYTE_DATA(self); i = 0; if (striptype != RIGHTSTRIP) { @@ -12769,7 +12769,7 @@ do_strip(PyObject *self, int striptype) } else { int kind = PyUnicode_KIND(self); - const void *data = PyUnicode_DATA(self); + const void *data = PyUnicode_DATA(self); i = 0; if (striptype != RIGHTSTRIP) { @@ -12801,7 +12801,7 @@ do_strip(PyObject *self, int striptype) static PyObject * do_argstrip(PyObject *self, int striptype, PyObject *sep) { - if (sep != Py_None) { + if (sep != Py_None) { if (PyUnicode_Check(sep)) return _PyUnicode_XStrip(self, striptype, sep); else { @@ -12822,14 +12822,14 @@ str.strip as unicode_strip chars: object = None / -Return a copy of the string with leading and trailing whitespace removed. +Return a copy of the string with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. [clinic start generated code]*/ static PyObject * unicode_strip_impl(PyObject *self, PyObject *chars) -/*[clinic end generated code: output=ca19018454345d57 input=385289c6f423b954]*/ +/*[clinic end generated code: output=ca19018454345d57 input=385289c6f423b954]*/ { return do_argstrip(self, BOTHSTRIP, chars); } @@ -12838,7 +12838,7 @@ unicode_strip_impl(PyObject *self, PyObject *chars) /*[clinic input] str.lstrip as unicode_lstrip - chars: object = None + chars: object = None / Return a copy of the string with leading whitespace removed. @@ -12848,7 +12848,7 @@ If chars is given and not None, remove characters in chars instead. static PyObject * unicode_lstrip_impl(PyObject *self, PyObject *chars) -/*[clinic end generated code: output=3b43683251f79ca7 input=529f9f3834448671]*/ +/*[clinic end generated code: output=3b43683251f79ca7 input=529f9f3834448671]*/ { return do_argstrip(self, LEFTSTRIP, chars); } @@ -12857,7 +12857,7 @@ unicode_lstrip_impl(PyObject *self, PyObject *chars) /*[clinic input] str.rstrip as unicode_rstrip - chars: object = None + chars: object = None / Return a copy of the string with trailing whitespace removed. @@ -12867,7 +12867,7 @@ If chars is given and not None, remove characters in chars instead. static PyObject * unicode_rstrip_impl(PyObject *self, PyObject *chars) -/*[clinic end generated code: output=4a59230017cc3b7a input=62566c627916557f]*/ +/*[clinic end generated code: output=4a59230017cc3b7a input=62566c627916557f]*/ { return do_argstrip(self, RIGHTSTRIP, chars); } @@ -12902,8 +12902,8 @@ unicode_repeat(PyObject *str, Py_ssize_t len) assert(PyUnicode_KIND(u) == PyUnicode_KIND(str)); if (PyUnicode_GET_LENGTH(str) == 1) { - int kind = PyUnicode_KIND(str); - Py_UCS4 fill_char = PyUnicode_READ(kind, PyUnicode_DATA(str), 0); + int kind = PyUnicode_KIND(str); + Py_UCS4 fill_char = PyUnicode_READ(kind, PyUnicode_DATA(str), 0); if (kind == PyUnicode_1BYTE_KIND) { void *to = PyUnicode_DATA(u); memset(to, (unsigned char)fill_char, len); @@ -12922,7 +12922,7 @@ unicode_repeat(PyObject *str, Py_ssize_t len) else { /* number of characters copied this far */ Py_ssize_t done = PyUnicode_GET_LENGTH(str); - Py_ssize_t char_size = PyUnicode_KIND(str); + Py_ssize_t char_size = PyUnicode_KIND(str); char *to = (char *) PyUnicode_DATA(u); memcpy(to, PyUnicode_DATA(str), PyUnicode_GET_LENGTH(str) * char_size); @@ -12975,62 +12975,62 @@ unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new, return replace(self, old, new, count); } -/*[clinic input] -str.removeprefix as unicode_removeprefix - - prefix: unicode - / - -Return a str with the given prefix string removed if present. - -If the string starts with the prefix string, return string[len(prefix):]. -Otherwise, return a copy of the original string. -[clinic start generated code]*/ - +/*[clinic input] +str.removeprefix as unicode_removeprefix + + prefix: unicode + / + +Return a str with the given prefix string removed if present. + +If the string starts with the prefix string, return string[len(prefix):]. +Otherwise, return a copy of the original string. +[clinic start generated code]*/ + +static PyObject * +unicode_removeprefix_impl(PyObject *self, PyObject *prefix) +/*[clinic end generated code: output=f1e5945e9763bcb9 input=27ec40b99a37eb88]*/ +{ + int match = tailmatch(self, prefix, 0, PY_SSIZE_T_MAX, -1); + if (match == -1) { + return NULL; + } + if (match) { + return PyUnicode_Substring(self, PyUnicode_GET_LENGTH(prefix), + PyUnicode_GET_LENGTH(self)); + } + return unicode_result_unchanged(self); +} + +/*[clinic input] +str.removesuffix as unicode_removesuffix + + suffix: unicode + / + +Return a str with the given suffix string removed if present. + +If the string ends with the suffix string and that suffix is not empty, +return string[:-len(suffix)]. Otherwise, return a copy of the original +string. +[clinic start generated code]*/ + +static PyObject * +unicode_removesuffix_impl(PyObject *self, PyObject *suffix) +/*[clinic end generated code: output=d36629e227636822 input=12cc32561e769be4]*/ +{ + int match = tailmatch(self, suffix, 0, PY_SSIZE_T_MAX, +1); + if (match == -1) { + return NULL; + } + if (match) { + return PyUnicode_Substring(self, 0, PyUnicode_GET_LENGTH(self) + - PyUnicode_GET_LENGTH(suffix)); + } + return unicode_result_unchanged(self); +} + static PyObject * -unicode_removeprefix_impl(PyObject *self, PyObject *prefix) -/*[clinic end generated code: output=f1e5945e9763bcb9 input=27ec40b99a37eb88]*/ -{ - int match = tailmatch(self, prefix, 0, PY_SSIZE_T_MAX, -1); - if (match == -1) { - return NULL; - } - if (match) { - return PyUnicode_Substring(self, PyUnicode_GET_LENGTH(prefix), - PyUnicode_GET_LENGTH(self)); - } - return unicode_result_unchanged(self); -} - -/*[clinic input] -str.removesuffix as unicode_removesuffix - - suffix: unicode - / - -Return a str with the given suffix string removed if present. - -If the string ends with the suffix string and that suffix is not empty, -return string[:-len(suffix)]. Otherwise, return a copy of the original -string. -[clinic start generated code]*/ - -static PyObject * -unicode_removesuffix_impl(PyObject *self, PyObject *suffix) -/*[clinic end generated code: output=d36629e227636822 input=12cc32561e769be4]*/ -{ - int match = tailmatch(self, suffix, 0, PY_SSIZE_T_MAX, +1); - if (match == -1) { - return NULL; - } - if (match) { - return PyUnicode_Substring(self, 0, PyUnicode_GET_LENGTH(self) - - PyUnicode_GET_LENGTH(suffix)); - } - return unicode_result_unchanged(self); -} - -static PyObject * unicode_repr(PyObject *unicode) { PyObject *repr; @@ -13038,8 +13038,8 @@ unicode_repr(PyObject *unicode) Py_ssize_t osize, squote, dquote, i, o; Py_UCS4 max, quote; int ikind, okind, unchanged; - const void *idata; - void *odata; + const void *idata; + void *odata; if (PyUnicode_READY(unicode) == -1) return NULL; @@ -13332,7 +13332,7 @@ PyUnicode_Partition(PyObject *str_obj, PyObject *sep_obj) { PyObject* out; int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2; if (ensure_unicode(str_obj) < 0 || ensure_unicode(sep_obj) < 0) @@ -13355,7 +13355,7 @@ PyUnicode_Partition(PyObject *str_obj, PyObject *sep_obj) buf1 = PyUnicode_DATA(str_obj); buf2 = PyUnicode_DATA(sep_obj); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return NULL; } @@ -13377,9 +13377,9 @@ PyUnicode_Partition(PyObject *str_obj, PyObject *sep_obj) Py_UNREACHABLE(); } - assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(sep_obj))); + assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(sep_obj))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return out; } @@ -13390,7 +13390,7 @@ PyUnicode_RPartition(PyObject *str_obj, PyObject *sep_obj) { PyObject* out; int kind1, kind2; - const void *buf1, *buf2; + const void *buf1, *buf2; Py_ssize_t len1, len2; if (ensure_unicode(str_obj) < 0 || ensure_unicode(sep_obj) < 0) @@ -13413,7 +13413,7 @@ PyUnicode_RPartition(PyObject *str_obj, PyObject *sep_obj) buf1 = PyUnicode_DATA(str_obj); buf2 = PyUnicode_DATA(sep_obj); if (kind2 != kind1) { - buf2 = unicode_askind(kind2, buf2, len2, kind1); + buf2 = unicode_askind(kind2, buf2, len2, kind1); if (!buf2) return NULL; } @@ -13435,9 +13435,9 @@ PyUnicode_RPartition(PyObject *str_obj, PyObject *sep_obj) Py_UNREACHABLE(); } - assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(sep_obj))); + assert((kind2 == kind1) == (buf2 == PyUnicode_DATA(sep_obj))); if (kind2 != kind1) - PyMem_Free((void *)buf2); + PyMem_Free((void *)buf2); return out; } @@ -13593,7 +13593,7 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z) return NULL; if (y != NULL) { int x_kind, y_kind, z_kind; - const void *x_data, *y_data, *z_data; + const void *x_data, *y_data, *z_data; /* x must be a string too, of equal length */ if (!PyUnicode_Check(x)) { @@ -13642,7 +13642,7 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z) } } else { int kind; - const void *data; + const void *data; /* x must be a dict */ if (!PyDict_CheckExact(x)) { @@ -13743,7 +13743,7 @@ unicode_zfill_impl(PyObject *self, Py_ssize_t width) Py_ssize_t fill; PyObject *u; int kind; - const void *data; + const void *data; Py_UCS4 chr; if (PyUnicode_READY(self) == -1) @@ -13924,16 +13924,16 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer) assert(writer->kind <= PyUnicode_1BYTE_KIND); } -// Initialize _PyUnicodeWriter with initial buffer -static inline void -_PyUnicodeWriter_InitWithBuffer(_PyUnicodeWriter *writer, PyObject *buffer) -{ - memset(writer, 0, sizeof(*writer)); - writer->buffer = buffer; - _PyUnicodeWriter_Update(writer); - writer->min_length = writer->size; -} - +// Initialize _PyUnicodeWriter with initial buffer +static inline void +_PyUnicodeWriter_InitWithBuffer(_PyUnicodeWriter *writer, PyObject *buffer) +{ + memset(writer, 0, sizeof(*writer)); + writer->buffer = buffer; + _PyUnicodeWriter_Update(writer); + writer->min_length = writer->size; +} + int _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, Py_ssize_t length, Py_UCS4 maxchar) @@ -14024,7 +14024,7 @@ _PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer, { case PyUnicode_1BYTE_KIND: maxchar = 0xff; break; case PyUnicode_2BYTE_KIND: maxchar = 0xffff; break; - case PyUnicode_4BYTE_KIND: maxchar = MAX_UNICODE; break; + case PyUnicode_4BYTE_KIND: maxchar = MAX_UNICODE; break; default: Py_UNREACHABLE(); } @@ -14122,7 +14122,7 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer, if (len == -1) len = strlen(ascii); - assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128); + assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128); if (writer->buffer == NULL && !writer->overallocate) { PyObject *str; @@ -14181,7 +14181,7 @@ _PyUnicodeWriter_WriteLatin1String(_PyUnicodeWriter *writer, { Py_UCS4 maxchar; - maxchar = ucs1lib_find_max_char((const Py_UCS1*)str, (const Py_UCS1*)str + len); + maxchar = ucs1lib_find_max_char((const Py_UCS1*)str, (const Py_UCS1*)str + len); if (_PyUnicodeWriter_Prepare(writer, len, maxchar) == -1) return -1; unicode_write_cstr(writer->buffer, writer->pos, str, len); @@ -14308,7 +14308,7 @@ unicode_sizeof_impl(PyObject *self) } static PyObject * -unicode_getnewargs(PyObject *v, PyObject *Py_UNUSED(ignored)) +unicode_getnewargs(PyObject *v, PyObject *Py_UNUSED(ignored)) { PyObject *copy = _PyUnicode_Copy(v); if (!copy) @@ -14346,8 +14346,8 @@ static PyMethodDef unicode_methods[] = { UNICODE_UPPER_METHODDEF {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__}, {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__}, - UNICODE_REMOVEPREFIX_METHODDEF - UNICODE_REMOVESUFFIX_METHODDEF + UNICODE_REMOVEPREFIX_METHODDEF + UNICODE_REMOVESUFFIX_METHODDEF UNICODE_ISASCII_METHODDEF UNICODE_ISLOWER_METHODDEF UNICODE_ISUPPER_METHODDEF @@ -14361,7 +14361,7 @@ static PyMethodDef unicode_methods[] = { UNICODE_ISIDENTIFIER_METHODDEF UNICODE_ISPRINTABLE_METHODDEF UNICODE_ZFILL_METHODDEF - {"format", (PyCFunction)(void(*)(void)) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__}, + {"format", (PyCFunction)(void(*)(void)) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__}, {"format_map", (PyCFunction) do_string_format_map, METH_O, format_map__doc__}, UNICODE___FORMAT___METHODDEF UNICODE_MAKETRANS_METHODDEF @@ -14371,7 +14371,7 @@ static PyMethodDef unicode_methods[] = { {"_decimal2ascii", (PyCFunction) unicode__decimal2ascii, METH_NOARGS}, #endif - {"__getnewargs__", unicode_getnewargs, METH_NOARGS}, + {"__getnewargs__", unicode_getnewargs, METH_NOARGS}, {NULL, NULL} }; @@ -14407,7 +14407,7 @@ unicode_subscript(PyObject* self, PyObject* item) if (PyUnicode_READY(self) == -1) return NULL; - if (_PyIndex_Check(item)) { + if (_PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) return NULL; @@ -14415,11 +14415,11 @@ unicode_subscript(PyObject* self, PyObject* item) i += PyUnicode_GET_LENGTH(self); return unicode_getitem(self, i); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength, i; - size_t cur; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; PyObject *result; - const void *src_data; - void *dest_data; + const void *src_data; + void *dest_data; int src_kind, dest_kind; Py_UCS4 ch, max_char, kind_limit; @@ -14490,7 +14490,7 @@ struct unicode_formatter_t { enum PyUnicode_Kind fmtkind; Py_ssize_t fmtcnt, fmtpos; - const void *fmtdata; + const void *fmtdata; PyObject *fmtstr; _PyUnicodeWriter writer; @@ -15164,7 +15164,7 @@ unicode_format_arg_output(struct unicode_formatter_t *ctx, { Py_ssize_t len; enum PyUnicode_Kind kind; - const void *pbuf; + const void *pbuf; Py_ssize_t pindex; Py_UCS4 signchar; Py_ssize_t buflen; @@ -15274,7 +15274,7 @@ unicode_format_arg_output(struct unicode_formatter_t *ctx, /* Pad left with the fill character if needed */ if (arg->width > len && !(arg->flags & F_LJUST)) { sublen = arg->width - len; - unicode_fill(writer->kind, writer->data, fill, writer->pos, sublen); + unicode_fill(writer->kind, writer->data, fill, writer->pos, sublen); writer->pos += sublen; arg->width = len; } @@ -15306,7 +15306,7 @@ unicode_format_arg_output(struct unicode_formatter_t *ctx, /* Pad right with the fill character if needed */ if (arg->width > len) { sublen = arg->width - len; - unicode_fill(writer->kind, writer->data, ' ', writer->pos, sublen); + unicode_fill(writer->kind, writer->data, ' ', writer->pos, sublen); writer->pos += sublen; } return 0; @@ -15581,52 +15581,52 @@ static PyObject *unicode_iter(PyObject *seq); PyTypeObject PyUnicode_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "str", /* tp_name */ - sizeof(PyUnicodeObject), /* tp_basicsize */ - 0, /* tp_itemsize */ + "str", /* tp_name */ + sizeof(PyUnicodeObject), /* tp_basicsize */ + 0, /* tp_itemsize */ /* Slots */ - (destructor)unicode_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - unicode_repr, /* tp_repr */ - &unicode_as_number, /* tp_as_number */ - &unicode_as_sequence, /* tp_as_sequence */ - &unicode_as_mapping, /* tp_as_mapping */ - (hashfunc) unicode_hash, /* tp_hash*/ - 0, /* tp_call*/ - (reprfunc) unicode_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ + (destructor)unicode_dealloc, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_as_async */ + unicode_repr, /* tp_repr */ + &unicode_as_number, /* tp_as_number */ + &unicode_as_sequence, /* tp_as_sequence */ + &unicode_as_mapping, /* tp_as_mapping */ + (hashfunc) unicode_hash, /* tp_hash*/ + 0, /* tp_call*/ + (reprfunc) unicode_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */ - unicode_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - PyUnicode_RichCompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - unicode_iter, /* tp_iter */ - 0, /* tp_iternext */ - unicode_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &PyBaseObject_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - unicode_new, /* tp_new */ - PyObject_Del, /* tp_free */ + Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */ + unicode_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + PyUnicode_RichCompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + unicode_iter, /* tp_iter */ + 0, /* tp_iternext */ + unicode_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PyBaseObject_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + unicode_new, /* tp_new */ + PyObject_Del, /* tp_free */ }; /* Initialize the Unicode implementation */ -PyStatus -_PyUnicode_Init(void) +PyStatus +_PyUnicode_Init(void) { /* XXX - move this array to unicodectype.c ? */ Py_UCS2 linebreak[] = { @@ -15642,30 +15642,30 @@ _PyUnicode_Init(void) /* Init the implementation */ _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) { - return _PyStatus_ERR("Can't create empty string"); - } + if (!unicode_empty) { + return _PyStatus_ERR("Can't create empty string"); + } Py_DECREF(unicode_empty); - if (PyType_Ready(&PyUnicode_Type) < 0) { - return _PyStatus_ERR("Can't initialize unicode type"); - } + if (PyType_Ready(&PyUnicode_Type) < 0) { + return _PyStatus_ERR("Can't initialize unicode type"); + } /* initialize the linebreak bloom filter */ bloom_linebreak = make_bloom_mask( PyUnicode_2BYTE_KIND, linebreak, Py_ARRAY_LENGTH(linebreak)); - if (PyType_Ready(&EncodingMapType) < 0) { - return _PyStatus_ERR("Can't initialize encoding map type"); - } - if (PyType_Ready(&PyFieldNameIter_Type) < 0) { - return _PyStatus_ERR("Can't initialize field name iterator type"); - } - if (PyType_Ready(&PyFormatterIter_Type) < 0) { - return _PyStatus_ERR("Can't initialize formatter iter type"); - } - return _PyStatus_OK(); + if (PyType_Ready(&EncodingMapType) < 0) { + return _PyStatus_ERR("Can't initialize encoding map type"); + } + if (PyType_Ready(&PyFieldNameIter_Type) < 0) { + return _PyStatus_ERR("Can't initialize field name iterator type"); + } + if (PyType_Ready(&PyFormatterIter_Type) < 0) { + return _PyStatus_ERR("Can't initialize formatter iter type"); + } + return _PyStatus_OK(); } @@ -15677,22 +15677,22 @@ PyUnicode_InternInPlace(PyObject **p) assert(s != NULL); assert(_PyUnicode_CHECK(s)); #else - if (s == NULL || !PyUnicode_Check(s)) { + if (s == NULL || !PyUnicode_Check(s)) { return; - } + } #endif - + /* If it's a subclass, we don't really know what putting it in the interned dict might do. */ - if (!PyUnicode_CheckExact(s)) { + if (!PyUnicode_CheckExact(s)) { return; - } - - if (PyUnicode_CHECK_INTERNED(s)) { + } + + if (PyUnicode_CHECK_INTERNED(s)) { return; - } - -#ifdef INTERNED_STRINGS + } + +#ifdef INTERNED_STRINGS if (interned == NULL) { interned = PyDict_New(); if (interned == NULL) { @@ -15700,26 +15700,26 @@ PyUnicode_InternInPlace(PyObject **p) return; } } - - PyObject *t; + + PyObject *t; t = PyDict_SetDefault(interned, s, s); - + if (t == NULL) { PyErr_Clear(); return; } - + if (t != s) { Py_INCREF(t); Py_SETREF(*p, t); return; } - + /* The two references in interned are not counted by refcnt. The deallocator will take care of this */ - Py_SET_REFCNT(s, Py_REFCNT(s) - 2); + Py_SET_REFCNT(s, Py_REFCNT(s) - 2); _PyUnicode_STATE(s).interned = SSTATE_INTERNED_MORTAL; -#endif +#endif } void @@ -15742,67 +15742,67 @@ PyUnicode_InternFromString(const char *cp) return s; } - -#if defined(WITH_VALGRIND) || defined(__INSURE__) -static void -unicode_release_interned(void) + +#if defined(WITH_VALGRIND) || defined(__INSURE__) +static void +unicode_release_interned(void) { - if (interned == NULL || !PyDict_Check(interned)) { + if (interned == NULL || !PyDict_Check(interned)) { return; - } - PyObject *keys = PyDict_Keys(interned); + } + PyObject *keys = PyDict_Keys(interned); if (keys == NULL || !PyList_Check(keys)) { PyErr_Clear(); return; } - /* Since unicode_release_interned() is intended to help a leak + /* Since unicode_release_interned() is intended to help a leak detector, interned unicode strings are not forcibly deallocated; rather, we give them their stolen references back, and then clear and DECREF the interned dict. */ - Py_ssize_t n = PyList_GET_SIZE(keys); -#ifdef INTERNED_STATS + Py_ssize_t n = PyList_GET_SIZE(keys); +#ifdef INTERNED_STATS fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n", n); - - Py_ssize_t immortal_size = 0, mortal_size = 0; -#endif - for (Py_ssize_t i = 0; i < n; i++) { - PyObject *s = PyList_GET_ITEM(keys, i); + + Py_ssize_t immortal_size = 0, mortal_size = 0; +#endif + for (Py_ssize_t i = 0; i < n; i++) { + PyObject *s = PyList_GET_ITEM(keys, i); if (PyUnicode_READY(s) == -1) { Py_UNREACHABLE(); } switch (PyUnicode_CHECK_INTERNED(s)) { case SSTATE_INTERNED_IMMORTAL: Py_REFCNT(s) += 1; -#ifdef INTERNED_STATS +#ifdef INTERNED_STATS immortal_size += PyUnicode_GET_LENGTH(s); -#endif +#endif break; case SSTATE_INTERNED_MORTAL: Py_REFCNT(s) += 2; -#ifdef INTERNED_STATS +#ifdef INTERNED_STATS mortal_size += PyUnicode_GET_LENGTH(s); -#endif +#endif break; - case SSTATE_NOT_INTERNED: - /* fall through */ + case SSTATE_NOT_INTERNED: + /* fall through */ default: - Py_UNREACHABLE(); + Py_UNREACHABLE(); } _PyUnicode_STATE(s).interned = SSTATE_NOT_INTERNED; } -#ifdef INTERNED_STATS +#ifdef INTERNED_STATS fprintf(stderr, "total size of all interned strings: " "%" PY_FORMAT_SIZE_T "d/%" PY_FORMAT_SIZE_T "d " "mortal/immortal\n", mortal_size, immortal_size); -#endif +#endif Py_DECREF(keys); PyDict_Clear(interned); Py_CLEAR(interned); } -#endif +#endif /********************* Unicode Iterator **************************/ @@ -15841,7 +15841,7 @@ unicodeiter_next(unicodeiterobject *it) if (it->it_index < PyUnicode_GET_LENGTH(seq)) { int kind = PyUnicode_KIND(seq); - const void *data = PyUnicode_DATA(seq); + const void *data = PyUnicode_DATA(seq); Py_UCS4 chr = PyUnicode_READ(kind, data, it->it_index); item = PyUnicode_FromOrdinal(chr); if (item != NULL) @@ -15855,7 +15855,7 @@ unicodeiter_next(unicodeiterobject *it) } static PyObject * -unicodeiter_len(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) +unicodeiter_len(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -15866,17 +15866,17 @@ unicodeiter_len(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) +unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + _Py_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), it->it_seq, it->it_index); } else { PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), u); + return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), u); } } @@ -15917,10 +15917,10 @@ PyTypeObject PyUnicodeIter_Type = { 0, /* tp_itemsize */ /* methods */ (destructor)unicodeiter_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -16062,10 +16062,10 @@ PyUnicode_AsUnicodeCopy(PyObject *unicode) PyErr_BadArgument(); return NULL; } -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS u = PyUnicode_AsUnicodeAndSize(unicode, &len); -_Py_COMP_DIAG_POP +_Py_COMP_DIAG_POP if (u == NULL) return NULL; /* Ensure we won't overflow the size. */ @@ -16084,242 +16084,242 @@ _Py_COMP_DIAG_POP return copy; } - -static int -encode_wstr_utf8(wchar_t *wstr, char **str, const char *name) -{ - int res; - res = _Py_EncodeUTF8Ex(wstr, str, NULL, NULL, 1, _Py_ERROR_STRICT); - if (res == -2) { - PyErr_Format(PyExc_RuntimeWarning, "cannot decode %s", name); - return -1; - } - if (res < 0) { - PyErr_NoMemory(); - return -1; - } - return 0; -} - - -static int -config_get_codec_name(wchar_t **config_encoding) -{ - char *encoding; - if (encode_wstr_utf8(*config_encoding, &encoding, "stdio_encoding") < 0) { - return -1; - } - - PyObject *name_obj = NULL; - PyObject *codec = _PyCodec_Lookup(encoding); - PyMem_RawFree(encoding); - - if (!codec) - goto error; - - name_obj = PyObject_GetAttrString(codec, "name"); - Py_CLEAR(codec); - if (!name_obj) { - goto error; - } - - wchar_t *wname = PyUnicode_AsWideCharString(name_obj, NULL); - Py_DECREF(name_obj); - if (wname == NULL) { - goto error; - } - - wchar_t *raw_wname = _PyMem_RawWcsdup(wname); - if (raw_wname == NULL) { - PyMem_Free(wname); - PyErr_NoMemory(); - goto error; - } - - PyMem_RawFree(*config_encoding); - *config_encoding = raw_wname; - - PyMem_Free(wname); - return 0; - -error: - Py_XDECREF(codec); - Py_XDECREF(name_obj); - return -1; -} - - -static PyStatus -init_stdio_encoding(PyThreadState *tstate) -{ - /* Update the stdio encoding to the normalized Python codec name. */ - PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(tstate->interp); - if (config_get_codec_name(&config->stdio_encoding) < 0) { - return _PyStatus_ERR("failed to get the Python codec name " - "of the stdio encoding"); - } - return _PyStatus_OK(); -} - - -static int -init_fs_codec(PyInterpreterState *interp) -{ - const PyConfig *config = _PyInterpreterState_GetConfig(interp); - - _Py_error_handler error_handler; - error_handler = get_error_handler_wide(config->filesystem_errors); - if (error_handler == _Py_ERROR_UNKNOWN) { - PyErr_SetString(PyExc_RuntimeError, "unknown filesystem error handler"); - return -1; - } - - char *encoding, *errors; - if (encode_wstr_utf8(config->filesystem_encoding, - &encoding, - "filesystem_encoding") < 0) { - return -1; - } - - if (encode_wstr_utf8(config->filesystem_errors, - &errors, - "filesystem_errors") < 0) { - PyMem_RawFree(encoding); - return -1; - } - - struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; - PyMem_RawFree(fs_codec->encoding); - fs_codec->encoding = encoding; - /* encoding has been normalized by init_fs_encoding() */ - fs_codec->utf8 = (strcmp(encoding, "utf-8") == 0); - PyMem_RawFree(fs_codec->errors); - fs_codec->errors = errors; - fs_codec->error_handler = error_handler; - -#ifdef _Py_FORCE_UTF8_FS_ENCODING - assert(fs_codec->utf8 == 1); -#endif - - /* At this point, PyUnicode_EncodeFSDefault() and - PyUnicode_DecodeFSDefault() can now use the Python codec rather than - the C implementation of the filesystem encoding. */ - - /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors - global configuration variables. */ - if (_Py_SetFileSystemEncoding(fs_codec->encoding, - fs_codec->errors) < 0) { - PyErr_NoMemory(); - return -1; - } - return 0; -} - - -static PyStatus -init_fs_encoding(PyThreadState *tstate) -{ - PyInterpreterState *interp = tstate->interp; - - /* Update the filesystem encoding to the normalized Python codec name. - For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii" - (Python codec name). */ - PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp); - if (config_get_codec_name(&config->filesystem_encoding) < 0) { - _Py_DumpPathConfig(tstate); - return _PyStatus_ERR("failed to get the Python codec " - "of the filesystem encoding"); - } - - if (init_fs_codec(interp) < 0) { - return _PyStatus_ERR("cannot initialize filesystem codec"); - } - return _PyStatus_OK(); -} - - -PyStatus -_PyUnicode_InitEncodings(PyThreadState *tstate) -{ - PyStatus status = init_fs_encoding(tstate); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - - return init_stdio_encoding(tstate); -} - - -static void -_PyUnicode_FiniEncodings(struct _Py_unicode_fs_codec *fs_codec) -{ - PyMem_RawFree(fs_codec->encoding); - fs_codec->encoding = NULL; - fs_codec->utf8 = 0; - PyMem_RawFree(fs_codec->errors); - fs_codec->errors = NULL; - fs_codec->error_handler = _Py_ERROR_UNKNOWN; -} - - -#ifdef MS_WINDOWS -int -_PyUnicode_EnableLegacyWindowsFSEncoding(void) -{ - PyInterpreterState *interp = _PyInterpreterState_GET(); - PyConfig *config = (PyConfig *)_PyInterpreterState_GetConfig(interp); - - /* Set the filesystem encoding to mbcs/replace (PEP 529) */ - wchar_t *encoding = _PyMem_RawWcsdup(L"mbcs"); - wchar_t *errors = _PyMem_RawWcsdup(L"replace"); - if (encoding == NULL || errors == NULL) { - PyMem_RawFree(encoding); - PyMem_RawFree(errors); - PyErr_NoMemory(); - return -1; - } - - PyMem_RawFree(config->filesystem_encoding); - config->filesystem_encoding = encoding; - PyMem_RawFree(config->filesystem_errors); - config->filesystem_errors = errors; - - return init_fs_codec(interp); -} -#endif - - -void -_PyUnicode_Fini(PyThreadState *tstate) -{ - if (_Py_IsMainInterpreter(tstate)) { -#if defined(WITH_VALGRIND) || defined(__INSURE__) - /* Insure++ is a memory analysis tool that aids in discovering - * memory leaks and other memory problems. On Python exit, the - * interned string dictionaries are flagged as being in use at exit - * (which it is). Under normal circumstances, this is fine because - * the memory will be automatically reclaimed by the system. Under - * memory debugging, it's a huge source of useless noise, so we - * trade off slower shutdown for less distraction in the memory - * reports. -baw - */ - unicode_release_interned(); -#endif /* __INSURE__ */ - - Py_CLEAR(unicode_empty); - -#ifdef LATIN1_SINGLETONS - for (Py_ssize_t i = 0; i < 256; i++) { - Py_CLEAR(unicode_latin1[i]); - } -#endif - unicode_clear_static_strings(); - } - - _PyUnicode_FiniEncodings(&tstate->interp->unicode.fs_codec); -} - - + +static int +encode_wstr_utf8(wchar_t *wstr, char **str, const char *name) +{ + int res; + res = _Py_EncodeUTF8Ex(wstr, str, NULL, NULL, 1, _Py_ERROR_STRICT); + if (res == -2) { + PyErr_Format(PyExc_RuntimeWarning, "cannot decode %s", name); + return -1; + } + if (res < 0) { + PyErr_NoMemory(); + return -1; + } + return 0; +} + + +static int +config_get_codec_name(wchar_t **config_encoding) +{ + char *encoding; + if (encode_wstr_utf8(*config_encoding, &encoding, "stdio_encoding") < 0) { + return -1; + } + + PyObject *name_obj = NULL; + PyObject *codec = _PyCodec_Lookup(encoding); + PyMem_RawFree(encoding); + + if (!codec) + goto error; + + name_obj = PyObject_GetAttrString(codec, "name"); + Py_CLEAR(codec); + if (!name_obj) { + goto error; + } + + wchar_t *wname = PyUnicode_AsWideCharString(name_obj, NULL); + Py_DECREF(name_obj); + if (wname == NULL) { + goto error; + } + + wchar_t *raw_wname = _PyMem_RawWcsdup(wname); + if (raw_wname == NULL) { + PyMem_Free(wname); + PyErr_NoMemory(); + goto error; + } + + PyMem_RawFree(*config_encoding); + *config_encoding = raw_wname; + + PyMem_Free(wname); + return 0; + +error: + Py_XDECREF(codec); + Py_XDECREF(name_obj); + return -1; +} + + +static PyStatus +init_stdio_encoding(PyThreadState *tstate) +{ + /* Update the stdio encoding to the normalized Python codec name. */ + PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(tstate->interp); + if (config_get_codec_name(&config->stdio_encoding) < 0) { + return _PyStatus_ERR("failed to get the Python codec name " + "of the stdio encoding"); + } + return _PyStatus_OK(); +} + + +static int +init_fs_codec(PyInterpreterState *interp) +{ + const PyConfig *config = _PyInterpreterState_GetConfig(interp); + + _Py_error_handler error_handler; + error_handler = get_error_handler_wide(config->filesystem_errors); + if (error_handler == _Py_ERROR_UNKNOWN) { + PyErr_SetString(PyExc_RuntimeError, "unknown filesystem error handler"); + return -1; + } + + char *encoding, *errors; + if (encode_wstr_utf8(config->filesystem_encoding, + &encoding, + "filesystem_encoding") < 0) { + return -1; + } + + if (encode_wstr_utf8(config->filesystem_errors, + &errors, + "filesystem_errors") < 0) { + PyMem_RawFree(encoding); + return -1; + } + + struct _Py_unicode_fs_codec *fs_codec = &interp->unicode.fs_codec; + PyMem_RawFree(fs_codec->encoding); + fs_codec->encoding = encoding; + /* encoding has been normalized by init_fs_encoding() */ + fs_codec->utf8 = (strcmp(encoding, "utf-8") == 0); + PyMem_RawFree(fs_codec->errors); + fs_codec->errors = errors; + fs_codec->error_handler = error_handler; + +#ifdef _Py_FORCE_UTF8_FS_ENCODING + assert(fs_codec->utf8 == 1); +#endif + + /* At this point, PyUnicode_EncodeFSDefault() and + PyUnicode_DecodeFSDefault() can now use the Python codec rather than + the C implementation of the filesystem encoding. */ + + /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors + global configuration variables. */ + if (_Py_SetFileSystemEncoding(fs_codec->encoding, + fs_codec->errors) < 0) { + PyErr_NoMemory(); + return -1; + } + return 0; +} + + +static PyStatus +init_fs_encoding(PyThreadState *tstate) +{ + PyInterpreterState *interp = tstate->interp; + + /* Update the filesystem encoding to the normalized Python codec name. + For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii" + (Python codec name). */ + PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp); + if (config_get_codec_name(&config->filesystem_encoding) < 0) { + _Py_DumpPathConfig(tstate); + return _PyStatus_ERR("failed to get the Python codec " + "of the filesystem encoding"); + } + + if (init_fs_codec(interp) < 0) { + return _PyStatus_ERR("cannot initialize filesystem codec"); + } + return _PyStatus_OK(); +} + + +PyStatus +_PyUnicode_InitEncodings(PyThreadState *tstate) +{ + PyStatus status = init_fs_encoding(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + + return init_stdio_encoding(tstate); +} + + +static void +_PyUnicode_FiniEncodings(struct _Py_unicode_fs_codec *fs_codec) +{ + PyMem_RawFree(fs_codec->encoding); + fs_codec->encoding = NULL; + fs_codec->utf8 = 0; + PyMem_RawFree(fs_codec->errors); + fs_codec->errors = NULL; + fs_codec->error_handler = _Py_ERROR_UNKNOWN; +} + + +#ifdef MS_WINDOWS +int +_PyUnicode_EnableLegacyWindowsFSEncoding(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + PyConfig *config = (PyConfig *)_PyInterpreterState_GetConfig(interp); + + /* Set the filesystem encoding to mbcs/replace (PEP 529) */ + wchar_t *encoding = _PyMem_RawWcsdup(L"mbcs"); + wchar_t *errors = _PyMem_RawWcsdup(L"replace"); + if (encoding == NULL || errors == NULL) { + PyMem_RawFree(encoding); + PyMem_RawFree(errors); + PyErr_NoMemory(); + return -1; + } + + PyMem_RawFree(config->filesystem_encoding); + config->filesystem_encoding = encoding; + PyMem_RawFree(config->filesystem_errors); + config->filesystem_errors = errors; + + return init_fs_codec(interp); +} +#endif + + +void +_PyUnicode_Fini(PyThreadState *tstate) +{ + if (_Py_IsMainInterpreter(tstate)) { +#if defined(WITH_VALGRIND) || defined(__INSURE__) + /* Insure++ is a memory analysis tool that aids in discovering + * memory leaks and other memory problems. On Python exit, the + * interned string dictionaries are flagged as being in use at exit + * (which it is). Under normal circumstances, this is fine because + * the memory will be automatically reclaimed by the system. Under + * memory debugging, it's a huge source of useless noise, so we + * trade off slower shutdown for less distraction in the memory + * reports. -baw + */ + unicode_release_interned(); +#endif /* __INSURE__ */ + + Py_CLEAR(unicode_empty); + +#ifdef LATIN1_SINGLETONS + for (Py_ssize_t i = 0; i < 256; i++) { + Py_CLEAR(unicode_latin1[i]); + } +#endif + unicode_clear_static_strings(); + } + + _PyUnicode_FiniEncodings(&tstate->interp->unicode.fs_codec); +} + + /* A _string module, to export formatter_parser and formatter_field_name_split to the string.Formatter class implemented in Python. */ diff --git a/contrib/tools/python3/src/Objects/unicodetype_db.h b/contrib/tools/python3/src/Objects/unicodetype_db.h index 72df50abf1..f668ed7ad5 100644 --- a/contrib/tools/python3/src/Objects/unicodetype_db.h +++ b/contrib/tools/python3/src/Objects/unicodetype_db.h @@ -1,4 +1,4 @@ -/* this file was generated by Tools/unicode/makeunicodedata.py 3.3 */ +/* this file was generated by Tools/unicode/makeunicodedata.py 3.3 */ /* a list of unique character type descriptors */ const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = { @@ -96,7 +96,7 @@ const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = { {-214, 0, -214, 0, 0, 9993}, {10727, 0, 10727, 0, 0, 9993}, {-218, 0, -218, 0, 0, 9993}, - {42307, 0, 42307, 0, 0, 9993}, + {42307, 0, 42307, 0, 0, 9993}, {42282, 0, 42282, 0, 0, 9993}, {-69, 0, -69, 0, 0, 9993}, {-217, 0, -217, 0, 0, 9993}, @@ -259,7 +259,7 @@ const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = { {0, -3008, 0, 0, 0, 10113}, {35332, 0, 35332, 0, 0, 9993}, {3814, 0, 3814, 0, 0, 9993}, - {35384, 0, 35384, 0, 0, 9993}, + {35384, 0, 35384, 0, 0, 9993}, {33554812, 18874745, 33554812, 0, 0, 26377}, {33554817, 18874750, 33554817, 0, 0, 26377}, {33554822, 18874755, 33554822, 0, 0, 26377}, @@ -393,7 +393,7 @@ const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = { {0, 0, 0, 0, 0, 3841}, {0, -35332, 0, 0, 0, 10113}, {0, -42280, 0, 0, 0, 10113}, - {48, 0, 48, 0, 0, 9993}, + {48, 0, 48, 0, 0, 9993}, {0, -42308, 0, 0, 0, 10113}, {0, -42319, 0, 0, 0, 10113}, {0, -42315, 0, 0, 0, 10113}, @@ -402,9 +402,9 @@ const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = { {0, -42282, 0, 0, 0, 10113}, {0, -42261, 0, 0, 0, 10113}, {0, 928, 0, 0, 0, 10113}, - {0, -48, 0, 0, 0, 10113}, - {0, -42307, 0, 0, 0, 10113}, - {0, -35384, 0, 0, 0, 10113}, + {0, -48, 0, 0, 0, 10113}, + {0, -42307, 0, 0, 0, 10113}, + {0, -35384, 0, 0, 0, 10113}, {-928, 0, -928, 0, 0, 9993}, {16778124, 17826698, 16778124, 0, 0, 26377}, {16778127, 17826701, 16778127, 0, 0, 26377}, @@ -1750,7 +1750,7 @@ const Py_UCS4 _PyUnicode_ExtendedCase[] = { /* type indexes */ #define SHIFT 7 -static const unsigned short index1[] = { +static const unsigned short index1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 34, 35, 36, 37, 38, 39, 34, 34, 34, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, @@ -1782,71 +1782,71 @@ static const unsigned short index1[] = { 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 128, 129, 130, 131, 132, 133, 34, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 144, 34, 34, 151, 144, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 144, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 144, 174, 175, 144, 176, 177, 178, 179, - 144, 180, 181, 182, 183, 184, 185, 144, 144, 186, 187, 188, 189, 144, - 190, 144, 191, 34, 34, 34, 34, 34, 34, 34, 192, 193, 34, 194, 144, 144, + 155, 156, 157, 158, 159, 160, 161, 162, 144, 163, 164, 165, 166, 167, + 168, 169, 170, 171, 172, 173, 144, 174, 175, 144, 176, 177, 178, 179, + 144, 180, 181, 182, 183, 184, 185, 144, 144, 186, 187, 188, 189, 144, + 190, 144, 191, 34, 34, 34, 34, 34, 34, 34, 192, 193, 34, 194, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 34, 34, 34, 34, 34, 34, 34, 34, 195, 144, 144, + 144, 144, 144, 144, 144, 34, 34, 34, 34, 34, 34, 34, 34, 195, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 34, 34, 34, 34, 196, 144, 144, 144, 144, 144, 144, 144, 144, 144, + 144, 34, 34, 34, 34, 196, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 34, 34, 34, 34, 197, 198, 199, 200, 144, 144, 144, 144, 201, - 202, 203, 204, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 144, 144, 34, 34, 34, 34, 197, 198, 199, 200, 144, 144, 144, 144, 201, + 202, 203, 204, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 205, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 206, 207, 144, 144, 144, 144, 144, 144, 144, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 205, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 206, 207, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 144, 34, 34, 208, 34, 34, 209, 144, 144, 144, + 144, 144, 144, 144, 144, 144, 34, 34, 208, 34, 34, 209, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 210, 211, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, + 144, 210, 211, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 64, 212, - 213, 214, 215, 216, 217, 144, 218, 219, 220, 221, 222, 223, 224, 225, 64, - 64, 64, 64, 226, 227, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 228, 144, 229, 144, 144, 230, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 34, 231, 232, 144, 144, 144, 144, 144, 233, 234, 235, 144, 236, - 237, 144, 144, 238, 239, 240, 241, 242, 144, 64, 243, 64, 64, 64, 64, 64, - 244, 245, 246, 247, 248, 249, 250, 251, 252, 64, 253, 144, 144, 144, 144, - 144, 144, 144, 144, 254, 255, 256, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 86, 257, 34, 258, 259, 34, 34, 34, 34, 34, 34, + 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 64, 212, + 213, 214, 215, 216, 217, 144, 218, 219, 220, 221, 222, 223, 224, 225, 64, + 64, 64, 64, 226, 227, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, + 228, 144, 229, 144, 144, 230, 144, 144, 144, 144, 144, 144, 144, 144, + 144, 144, 34, 231, 232, 144, 144, 144, 144, 144, 233, 234, 235, 144, 236, + 237, 144, 144, 238, 239, 240, 241, 242, 144, 64, 243, 64, 64, 64, 64, 64, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 64, 253, 144, 144, 144, 144, + 144, 144, 144, 144, 254, 255, 256, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 86, 257, 34, 258, 259, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 260, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 261, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 262, + 34, 34, 34, 34, 34, 34, 260, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 261, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 262, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 263, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 263, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 264, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 264, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 265, 34, 266, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 265, 34, 266, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 267, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 267, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 268, 144, 144, 144, 144, 144, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 268, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 34, 260, 34, 34, 269, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 144, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 270, 144, 144, 144, 144, 144, 144, + 144, 144, 144, 144, 144, 34, 260, 34, 34, 269, 144, 144, 144, 144, 144, + 144, 144, 144, 144, 144, 144, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 270, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, @@ -2246,7 +2246,7 @@ static const unsigned short index1[] = { 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 271, 144, 272, 273, 144, 144, 144, 144, 144, 144, 144, 144, 144, + 144, 271, 144, 272, 273, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, @@ -2282,7 +2282,7 @@ static const unsigned short index1[] = { 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, - 144, 144, 144, 144, 144, 144, 144, 144, 144, 126, 126, 126, 126, 126, + 144, 144, 144, 144, 144, 144, 144, 144, 144, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -2319,7 +2319,7 @@ static const unsigned short index1[] = { 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 274, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 274, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -2355,10 +2355,10 @@ static const unsigned short index1[] = { 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 274, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 274, }; -static const unsigned short index2[] = { +static const unsigned short index2[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 2, 4, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 6, 5, 5, 5, 5, 5, 5, 17, 17, 17, 17, @@ -2392,52 +2392,52 @@ static const unsigned short index2[] = { 30, 31, 66, 67, 68, 68, 30, 31, 69, 70, 71, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 72, 73, 74, 75, 76, 20, 77, 77, 20, 78, 20, 79, 80, 20, 20, 20, 77, 81, 20, 82, 20, 83, 84, 20, 85, 86, 84, 87, 88, 20, 20, 86, 20, - 89, 90, 20, 20, 91, 20, 20, 20, 20, 20, 20, 20, 92, 20, 20, 93, 20, 94, - 93, 20, 20, 20, 95, 93, 96, 97, 97, 98, 20, 20, 20, 20, 20, 99, 20, 55, - 20, 20, 20, 20, 20, 20, 20, 20, 100, 101, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 103, 103, 103, 103, 103, 103, 103, 102, 102, 6, 6, 6, 6, 103, - 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 102, 102, 102, 102, 102, 6, 6, 6, 6, 6, 6, 6, - 103, 6, 103, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 25, 25, + 89, 90, 20, 20, 91, 20, 20, 20, 20, 20, 20, 20, 92, 20, 20, 93, 20, 94, + 93, 20, 20, 20, 95, 93, 96, 97, 97, 98, 20, 20, 20, 20, 20, 99, 20, 55, + 20, 20, 20, 20, 20, 20, 20, 20, 100, 101, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 103, 103, 103, 103, 103, 103, 103, 102, 102, 6, 6, 6, 6, 103, + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 102, 102, 102, 102, 102, 6, 6, 6, 6, 6, 6, 6, + 103, 6, 103, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 104, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 104, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 30, 31, 30, 31, 103, 6, 30, 31, 0, 0, 105, 50, 50, 50, 5, 106, 0, - 0, 0, 0, 6, 6, 107, 25, 108, 108, 108, 0, 109, 0, 110, 110, 111, 17, 17, + 25, 25, 30, 31, 30, 31, 103, 6, 30, 31, 0, 0, 105, 50, 50, 50, 5, 106, 0, + 0, 0, 0, 6, 6, 107, 25, 108, 108, 108, 0, 109, 0, 110, 110, 111, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 112, 113, 113, 113, 114, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 115, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 116, 117, 117, 118, 119, 120, 121, 121, 121, 122, 123, - 124, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 125, 126, 127, 128, 129, 130, 5, 30, 31, 131, - 30, 31, 20, 64, 64, 64, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, - 132, 132, 132, 132, 132, 132, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 112, 113, 113, 113, 114, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 115, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 116, 117, 117, 118, 119, 120, 121, 121, 121, 122, 123, + 124, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 125, 126, 127, 128, 129, 130, 5, 30, 31, 131, + 30, 31, 20, 64, 64, 64, 132, 132, 132, 132, 132, 132, 132, 132, 132, 132, + 132, 132, 132, 132, 132, 132, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 133, - 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, - 133, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 133, + 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, + 133, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 5, 25, 25, 25, 25, 25, 6, 6, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 30, 31, 30, 31, 134, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 135, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, + 30, 31, 30, 31, 30, 31, 134, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 135, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 0, 136, 136, 136, 136, 136, 136, + 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 0, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 0, 0, 103, 5, 5, 5, 5, 5, 6, 20, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 138, 20, 5, 5, 0, 0, 5, 5, 5, 0, 25, 25, + 136, 136, 136, 136, 0, 0, 103, 5, 5, 5, 5, 5, 6, 20, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 138, 20, 5, 5, 0, 0, 5, 5, 5, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 25, 5, 25, 25, 5, 25, 25, 5, 25, 0, 0, 0, @@ -2446,7 +2446,7 @@ static const unsigned short index2[] = { 55, 55, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 21, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 21, 0, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 5, 5, 55, 55, 25, 55, 55, 55, 55, 55, 55, 55, 55, @@ -2456,7 +2456,7 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 55, 25, 25, 25, 25, 25, 25, 25, 21, 5, 25, 25, 25, 25, 25, 25, - 103, 103, 25, 25, 5, 25, 25, 25, 25, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, + 103, 103, 25, 25, 5, 25, 25, 25, 25, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 55, 5, 5, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 21, 55, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, @@ -2470,79 +2470,79 @@ static const unsigned short index2[] = { 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 103, 103, 5, 5, 5, 5, 103, 0, 0, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 103, 103, 5, 5, 5, 5, 103, 0, 0, 25, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 25, 25, 25, 25, 103, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 103, 25, 25, 25, 103, 25, 25, 25, 25, 25, 0, 0, 5, 5, 5, 5, 5, 5, 5, + 55, 55, 55, 55, 55, 25, 25, 25, 25, 103, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 103, 25, 25, 25, 103, 25, 25, 25, 25, 25, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 0, 0, 5, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 21, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 21, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 25, 18, 25, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, - 25, 25, 18, 18, 18, 18, 25, 18, 18, 55, 25, 25, 25, 25, 25, 25, 25, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 5, 5, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 5, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 25, 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 0, 0, 55, - 55, 55, 55, 0, 0, 25, 55, 18, 18, 18, 25, 25, 25, 25, 0, 0, 18, 18, 0, 0, - 18, 18, 25, 55, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 55, 55, 0, 55, - 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 5, 5, - 27, 27, 27, 27, 27, 27, 5, 5, 55, 5, 25, 0, 0, 25, 25, 18, 0, 55, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, - 55, 55, 55, 0, 55, 55, 0, 55, 55, 0, 55, 55, 0, 0, 25, 0, 18, 18, 18, 25, - 25, 0, 0, 0, 0, 25, 25, 0, 0, 25, 25, 25, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, - 0, 55, 55, 55, 55, 0, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 25, 25, 55, 55, 55, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, - 25, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, - 0, 0, 25, 55, 18, 18, 18, 25, 25, 25, 25, 25, 0, 25, 25, 18, 0, 18, 18, - 25, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 25, - 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 0, 0, 0, 0, 0, 0, 0, - 55, 25, 25, 25, 25, 25, 25, 0, 25, 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, - 55, 55, 0, 55, 55, 55, 55, 55, 0, 0, 25, 55, 18, 25, 18, 25, 25, 25, 25, - 0, 0, 18, 18, 0, 0, 18, 18, 25, 0, 0, 0, 0, 0, 0, 0, 25, 25, 18, 0, 0, 0, - 0, 55, 55, 0, 55, 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 5, 55, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 55, - 0, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 0, 55, 55, 55, 55, 0, 0, - 0, 55, 55, 0, 55, 0, 55, 55, 0, 0, 0, 55, 55, 0, 0, 0, 55, 55, 55, 0, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 18, 18, - 25, 18, 18, 0, 0, 0, 18, 18, 18, 0, 18, 18, 18, 25, 0, 0, 55, 0, 0, 0, 0, - 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 25, - 18, 18, 18, 25, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 0, 0, 55, 25, 25, 25, 18, 18, 18, 18, 0, 25, 25, 25, 0, 25, - 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 25, 25, 0, 55, 55, 55, 0, 0, 0, 0, 0, - 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, - 0, 0, 5, 27, 27, 27, 27, 27, 27, 27, 5, 55, 25, 18, 18, 5, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 0, 25, 55, 18, 25, - 18, 18, 18, 18, 18, 0, 25, 18, 18, 0, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, - 0, 18, 18, 0, 0, 0, 0, 0, 0, 0, 55, 0, 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, + 25, 25, 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 25, 18, 25, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, + 25, 25, 18, 18, 18, 18, 25, 18, 18, 55, 25, 25, 25, 25, 25, 25, 25, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 5, 5, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 5, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 25, 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 0, 0, 55, + 55, 55, 55, 0, 0, 25, 55, 18, 18, 18, 25, 25, 25, 25, 0, 0, 18, 18, 0, 0, + 18, 18, 25, 55, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 55, 55, 0, 55, + 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 5, 5, + 27, 27, 27, 27, 27, 27, 5, 5, 55, 5, 25, 0, 0, 25, 25, 18, 0, 55, 55, 55, + 55, 55, 55, 0, 0, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, + 55, 55, 55, 0, 55, 55, 0, 55, 55, 0, 55, 55, 0, 0, 25, 0, 18, 18, 18, 25, + 25, 0, 0, 0, 0, 25, 25, 0, 0, 25, 25, 25, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, + 0, 55, 55, 55, 55, 0, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 25, 25, 55, 55, 55, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, + 25, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, + 0, 0, 25, 55, 18, 18, 18, 25, 25, 25, 25, 25, 0, 25, 25, 18, 0, 18, 18, + 25, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 25, + 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 0, 0, 0, 0, 0, 0, 0, + 55, 25, 25, 25, 25, 25, 25, 0, 25, 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, + 55, 55, 0, 55, 55, 55, 55, 55, 0, 0, 25, 55, 18, 25, 18, 25, 25, 25, 25, + 0, 0, 18, 18, 0, 0, 18, 18, 25, 0, 0, 0, 0, 0, 0, 0, 25, 25, 18, 0, 0, 0, + 0, 55, 55, 0, 55, 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 5, 55, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 55, + 0, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 0, 55, 55, 55, 55, 0, 0, + 0, 55, 55, 0, 55, 0, 55, 55, 0, 0, 0, 55, 55, 0, 0, 0, 55, 55, 55, 0, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 18, 18, + 25, 18, 18, 0, 0, 0, 18, 18, 18, 0, 18, 18, 18, 25, 0, 0, 55, 0, 0, 0, 0, + 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 25, + 18, 18, 18, 25, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 0, 0, 55, 25, 25, 25, 18, 18, 18, 18, 0, 25, 25, 25, 0, 25, + 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 25, 25, 0, 55, 55, 55, 0, 0, 0, 0, 0, + 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, + 0, 0, 5, 27, 27, 27, 27, 27, 27, 27, 5, 55, 25, 18, 18, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 0, 25, 55, 18, 25, + 18, 18, 18, 18, 18, 0, 25, 18, 18, 0, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, + 0, 18, 18, 0, 0, 0, 0, 0, 0, 0, 55, 0, 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 25, 25, 18, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, + 25, 25, 18, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 55, 18, 18, 18, 25, 25, 25, 25, 0, 18, 18, 18, 0, 18, 18, 18, 25, 55, 5, 0, 0, 0, 0, 55, 55, 55, 18, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 25, 25, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 55, 55, 55, 55, 55, 55, 0, 25, 18, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 55, 55, 55, 55, 55, 55, 0, 25, 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, @@ -2552,44 +2552,44 @@ static const unsigned short index2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 25, 55, 139, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 0, 5, 55, 55, 55, - 55, 55, 55, 103, 25, 25, 25, 25, 25, 25, 25, 25, 5, 7, 8, 9, 10, 11, 12, + 55, 25, 55, 139, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 0, 5, 55, 55, 55, + 55, 55, 55, 103, 25, 25, 25, 25, 25, 25, 25, 25, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 0, - 55, 0, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 25, 55, 139, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 55, 0, 0, 55, 55, 55, 55, 55, 0, 103, 0, 25, 25, 25, 25, 25, 25, 0, - 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 25, 25, 5, 5, 5, 5, 5, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 25, 5, 25, 5, 25, 5, 5, 5, - 5, 18, 18, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 18, 25, 25, 25, 25, 25, 5, 25, - 25, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, + 55, 0, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 25, 55, 139, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 55, 0, 0, 55, 55, 55, 55, 55, 0, 103, 0, 25, 25, 25, 25, 25, 25, 0, + 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 25, 25, 5, 5, 5, 5, 5, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 25, 5, 25, 5, 25, 5, 5, 5, + 5, 18, 18, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 18, 25, 25, 25, 25, 25, 5, 25, + 25, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 0, 5, 5, 5, 5, 5, 5, 5, 5, 25, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 18, 18, 25, 25, 25, 25, 18, 25, 25, 25, 25, 25, 25, 18, 25, - 25, 18, 18, 25, 25, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 5, 5, - 5, 5, 55, 55, 55, 55, 55, 55, 18, 18, 25, 25, 55, 55, 55, 55, 25, 25, 25, - 55, 18, 18, 18, 55, 55, 18, 18, 18, 18, 18, 18, 18, 55, 55, 55, 25, 25, - 25, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 18, 18, - 25, 25, 18, 18, 18, 18, 18, 18, 25, 55, 18, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 18, 18, 18, 25, 5, 5, 140, 140, 140, 140, 140, 140, 140, 140, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 0, 5, 5, 5, 5, 5, 5, 5, 5, 25, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 18, 18, 25, 25, 25, 25, 18, 25, 25, 25, 25, 25, 25, 18, 25, + 25, 18, 18, 25, 25, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 5, 5, + 5, 5, 55, 55, 55, 55, 55, 55, 18, 18, 25, 25, 55, 55, 55, 55, 25, 25, 25, + 55, 18, 18, 18, 55, 55, 18, 18, 18, 18, 18, 18, 18, 55, 55, 55, 25, 25, + 25, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 18, 18, + 25, 25, 18, 18, 18, 18, 18, 18, 25, 55, 18, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 18, 18, 18, 25, 5, 5, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, - 140, 140, 0, 140, 0, 0, 0, 0, 0, 140, 0, 0, 141, 141, 141, 141, 141, 141, - 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, - 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, - 141, 141, 141, 141, 141, 141, 141, 141, 141, 5, 103, 141, 141, 141, 55, + 140, 140, 0, 140, 0, 0, 0, 0, 0, 140, 0, 0, 141, 141, 141, 141, 141, 141, + 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, + 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, + 141, 141, 141, 141, 141, 141, 141, 141, 141, 5, 103, 141, 141, 141, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -2601,32 +2601,32 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, - 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, + 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 0, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 0, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, - 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, + 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 142, 143, 144, 145, 146, - 147, 148, 149, 150, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 151, 152, 153, 154, 155, 156, 157, - 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 231, 232, 233, 234, 235, 236, 0, 0, 237, 238, 239, 240, - 241, 242, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 151, 152, 153, 154, 155, 156, 157, + 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, + 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, + 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 229, 230, 231, 232, 233, 234, 235, 236, 0, 0, 237, 238, 239, 240, + 241, 242, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -2639,163 +2639,163 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 2, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 0, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 2, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 0, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 5, 5, 5, 243, 243, 243, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 55, 55, 55, 55, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, - 25, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, - 0, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 5, 5, 5, 243, 243, 243, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 55, 55, 55, 55, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, + 25, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, + 0, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 25, 25, 25, 25, 25, - 25, 25, 18, 18, 18, 18, 18, 18, 18, 18, 25, 18, 18, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 5, 5, 5, 103, 5, 5, 5, 5, 55, 25, 0, 0, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, - 25, 21, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 25, 25, 25, 25, 25, + 25, 25, 18, 18, 18, 18, 18, 18, 18, 18, 25, 18, 18, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 5, 5, 5, 103, 5, 5, 5, 5, 55, 25, 0, 0, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, + 25, 21, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 55, 55, 55, 55, 55, 244, 244, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 55, 55, 55, 55, 55, 244, 244, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 25, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 25, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 25, 25, 25, - 18, 18, 18, 18, 25, 25, 18, 18, 18, 0, 0, 0, 0, 18, 18, 25, 18, 18, 18, - 18, 18, 18, 25, 25, 25, 0, 0, 0, 0, 5, 0, 0, 0, 5, 5, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 25, 25, 25, + 18, 18, 18, 18, 25, 25, 18, 18, 18, 0, 0, 0, 0, 18, 18, 25, 18, 18, 18, + 18, 18, 18, 25, 25, 25, 0, 0, 0, 0, 5, 0, 0, 0, 5, 5, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, - 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 142, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 18, 25, 0, 0, 5, 5, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 25, 18, 25, - 25, 25, 25, 25, 25, 25, 0, 25, 18, 25, 18, 18, 25, 25, 25, 25, 25, 25, - 25, 25, 18, 18, 18, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 0, 0, 25, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 103, - 5, 5, 5, 5, 5, 5, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 6, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 142, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 18, 25, 0, 0, 5, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 25, 18, 25, + 25, 25, 25, 25, 25, 25, 0, 25, 18, 25, 18, 18, 25, 25, 25, 25, 25, 25, + 25, 25, 18, 18, 18, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 0, 0, 25, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 103, + 5, 5, 5, 5, 5, 5, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 6, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, - 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 18, 25, 25, - 25, 25, 25, 18, 25, 18, 18, 18, 18, 18, 25, 18, 18, 55, 55, 55, 55, 55, - 55, 55, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 25, 25, 18, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 18, 25, 25, 25, 25, 18, 18, 25, 25, 18, 25, 25, - 25, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 25, 18, 25, 25, 18, 18, 18, 25, 18, 25, 25, 25, 18, 18, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, 18, 18, 18, 18, 25, 25, 25, - 25, 25, 25, 25, 25, 18, 18, 25, 25, 0, 0, 0, 5, 5, 5, 5, 5, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 0, 0, 0, 55, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 103, 103, - 103, 103, 103, 5, 5, 245, 246, 247, 248, 249, 250, 251, 252, 253, 0, 0, - 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 0, 0, 254, 254, 254, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, - 0, 0, 0, 0, 0, 25, 25, 25, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 18, 25, 25, 25, 25, 25, 25, 25, 55, 55, 55, 55, 25, 55, 55, 55, - 55, 55, 55, 25, 55, 55, 18, 25, 25, 55, 0, 0, 0, 0, 0, 20, 20, 20, 20, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, + 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 18, 25, 25, + 25, 25, 25, 18, 25, 18, 18, 18, 18, 18, 25, 18, 18, 55, 55, 55, 55, 55, + 55, 55, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 25, 25, 18, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 18, 25, 25, 25, 25, 18, 18, 25, 25, 18, 25, 25, + 25, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 25, 18, 25, 25, 18, 18, 18, 25, 18, 25, 25, 25, 18, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, 18, 18, 18, 18, 25, 25, 25, + 25, 25, 25, 25, 25, 18, 18, 25, 25, 0, 0, 0, 5, 5, 5, 5, 5, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 0, 0, 0, 55, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 103, 103, + 103, 103, 103, 5, 5, 245, 246, 247, 248, 249, 250, 251, 252, 253, 0, 0, + 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 0, 0, 254, 254, 254, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, + 0, 0, 0, 0, 0, 25, 25, 25, 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 18, 25, 25, 25, 25, 25, 25, 25, 55, 55, 55, 55, 25, 55, 55, 55, + 55, 55, 55, 25, 55, 55, 18, 25, 25, 55, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 102, 255, 20, 20, 20, 256, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 257, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 25, + 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 102, 255, 20, 20, 20, 256, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 257, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 0, 25, 25, 25, 25, 25, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 0, 25, 25, 25, 25, 25, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 258, 259, + 260, 261, 262, 263, 20, 20, 264, 20, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 258, 259, - 260, 261, 262, 263, 20, 20, 264, 20, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 265, 265, - 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, 266, 266, 266, 266, - 265, 265, 265, 265, 265, 265, 0, 0, 266, 266, 266, 266, 266, 266, 0, 0, - 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, 266, 266, - 266, 266, 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, - 266, 266, 266, 266, 265, 265, 265, 265, 265, 265, 0, 0, 266, 266, 266, - 266, 266, 266, 0, 0, 267, 265, 268, 265, 269, 265, 270, 265, 0, 266, 0, - 266, 0, 266, 0, 266, 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, - 266, 266, 266, 266, 266, 266, 271, 271, 272, 272, 272, 272, 273, 273, - 274, 274, 275, 275, 276, 276, 0, 0, 277, 278, 279, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 265, - 265, 325, 326, 327, 0, 328, 329, 266, 266, 330, 330, 331, 6, 332, 6, 6, - 6, 333, 334, 335, 0, 336, 337, 338, 338, 338, 338, 339, 6, 6, 6, 265, - 265, 340, 341, 0, 0, 342, 343, 266, 266, 344, 344, 0, 6, 6, 6, 265, 265, - 345, 346, 347, 127, 348, 349, 266, 266, 350, 350, 131, 6, 6, 6, 0, 0, - 351, 352, 353, 0, 354, 355, 356, 356, 357, 357, 358, 6, 6, 0, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 21, 21, 21, 21, 21, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 6, 3, 3, 21, 21, 21, 21, 21, 2, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 21, - 21, 21, 21, 21, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 359, 102, 0, - 0, 360, 361, 362, 363, 364, 365, 5, 5, 5, 5, 5, 102, 359, 26, 22, 23, - 360, 361, 362, 363, 364, 365, 5, 5, 5, 5, 5, 0, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 265, 265, + 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, 266, 266, 266, 266, + 265, 265, 265, 265, 265, 265, 0, 0, 266, 266, 266, 266, 266, 266, 0, 0, + 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, 266, 266, + 266, 266, 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, + 266, 266, 266, 266, 265, 265, 265, 265, 265, 265, 0, 0, 266, 266, 266, + 266, 266, 266, 0, 0, 267, 265, 268, 265, 269, 265, 270, 265, 0, 266, 0, + 266, 0, 266, 0, 266, 265, 265, 265, 265, 265, 265, 265, 265, 266, 266, + 266, 266, 266, 266, 266, 266, 271, 271, 272, 272, 272, 272, 273, 273, + 274, 274, 275, 275, 276, 276, 0, 0, 277, 278, 279, 280, 281, 282, 283, + 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, + 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 265, + 265, 325, 326, 327, 0, 328, 329, 266, 266, 330, 330, 331, 6, 332, 6, 6, + 6, 333, 334, 335, 0, 336, 337, 338, 338, 338, 338, 339, 6, 6, 6, 265, + 265, 340, 341, 0, 0, 342, 343, 266, 266, 344, 344, 0, 6, 6, 6, 265, 265, + 345, 346, 347, 127, 348, 349, 266, 266, 350, 350, 131, 6, 6, 6, 0, 0, + 351, 352, 353, 0, 354, 355, 356, 356, 357, 357, 358, 6, 6, 0, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 21, 21, 21, 21, 21, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 6, 3, 3, 21, 21, 21, 21, 21, 2, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 21, + 21, 21, 21, 21, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 359, 102, 0, + 0, 360, 361, 362, 363, 364, 365, 5, 5, 5, 5, 5, 102, 359, 26, 22, 23, + 360, 361, 362, 363, 364, 365, 5, 5, 5, 5, 5, 0, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 6, 6, 6, 6, 25, 6, 6, 6, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 5, 5, 121, 5, 5, 5, 5, 121, 5, 5, 20, 121, 121, 121, 20, 20, 121, 121, - 121, 20, 5, 121, 5, 5, 366, 121, 121, 121, 121, 121, 5, 5, 5, 5, 5, 5, - 121, 5, 367, 5, 121, 5, 368, 369, 121, 121, 366, 20, 121, 121, 370, 121, - 20, 55, 55, 55, 55, 20, 5, 5, 20, 20, 121, 121, 5, 5, 5, 5, 5, 121, 20, - 20, 20, 20, 5, 5, 5, 5, 371, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, - 372, 372, 372, 372, 372, 372, 373, 373, 373, 373, 373, 373, 373, 373, - 373, 373, 373, 373, 373, 373, 373, 373, 243, 243, 243, 30, 31, 243, 243, - 243, 243, 27, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 6, 6, 6, 6, 25, 6, 6, 6, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 121, 5, 5, 5, 5, 121, 5, 5, 20, 121, 121, 121, 20, 20, 121, 121, + 121, 20, 5, 121, 5, 5, 366, 121, 121, 121, 121, 121, 5, 5, 5, 5, 5, 5, + 121, 5, 367, 5, 121, 5, 368, 369, 121, 121, 366, 20, 121, 121, 370, 121, + 20, 55, 55, 55, 55, 20, 5, 5, 20, 20, 121, 121, 5, 5, 5, 5, 5, 121, 20, + 20, 20, 20, 5, 5, 5, 5, 371, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, + 372, 372, 372, 372, 372, 372, 373, 373, 373, 373, 373, 373, 373, 373, + 373, 373, 373, 373, 373, 373, 373, 373, 243, 243, 243, 30, 31, 243, 243, + 243, 243, 27, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, @@ -2805,38 +2805,38 @@ static const unsigned short index2[] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 22, 23, 360, 361, 362, 363, 364, 365, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, 360, 361, 362, - 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, - 360, 361, 362, 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, - 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 375, - 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, - 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 359, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, - 359, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 22, 23, 360, 361, 362, 363, 364, 365, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, 360, 361, 362, + 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, + 360, 361, 362, 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 26, - 22, 23, 360, 361, 362, 363, 364, 365, 27, 26, 22, 23, 360, 361, 362, 363, - 364, 365, 27, 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, 5, 5, 5, 5, + 5, 5, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, + 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 375, + 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, + 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 359, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, + 359, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 26, + 22, 23, 360, 361, 362, 363, 364, 365, 27, 26, 22, 23, 360, 361, 362, 363, + 364, 365, 27, 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, @@ -2844,95 +2844,96 @@ static const unsigned short index2[] = { 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 0, 137, 137, 137, 137, 137, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, - 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 0, 30, 31, 376, 377, - 378, 379, 380, 30, 31, 30, 31, 30, 31, 381, 382, 383, 384, 20, 30, 31, - 20, 30, 31, 20, 20, 20, 20, 20, 102, 102, 385, 385, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 20, 5, 5, 5, 5, 5, 5, 30, 31, 30, 31, 25, 25, 25, 30, - 31, 0, 0, 0, 0, 0, 5, 5, 5, 5, 27, 5, 5, 386, 386, 386, 386, 386, 386, - 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, - 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, - 386, 386, 386, 386, 0, 386, 0, 0, 0, 0, 0, 386, 0, 0, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 103, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, - 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, - 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 25, 25, + 136, 136, 136, 136, 136, 0, 137, 137, 137, 137, 137, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, + 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 0, 30, 31, 376, 377, + 378, 379, 380, 30, 31, 30, 31, 30, 31, 381, 382, 383, 384, 20, 30, 31, + 20, 30, 31, 20, 20, 20, 20, 20, 102, 102, 385, 385, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 20, 5, 5, 5, 5, 5, 5, 30, 31, 30, 31, 25, 25, 25, 30, + 31, 0, 0, 0, 0, 0, 5, 5, 5, 5, 27, 5, 5, 386, 386, 386, 386, 386, 386, + 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, + 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, + 386, 386, 386, 386, 0, 386, 0, 0, 0, 0, 0, 386, 0, 0, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 103, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, + 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, + 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 387, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 387, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 2, 5, 5, 5, 5, 103, 55, - 243, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 243, 243, 243, 243, 243, 243, 243, 243, 243, 25, 25, 25, 25, 18, - 18, 5, 103, 103, 103, 103, 103, 5, 5, 243, 243, 243, 103, 55, 5, 5, 5, 0, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 2, 5, 5, 5, 5, 103, 55, + 243, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 243, 243, 243, 243, 243, 243, 243, 243, 243, 25, 25, 25, 25, 18, + 18, 5, 103, 103, 103, 103, 103, 5, 5, 243, 243, 243, 103, 55, 5, 5, 5, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 6, - 6, 103, 103, 55, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 6, + 6, 103, 103, 55, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 5, 103, 103, 103, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 5, 103, 103, 103, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 5, 27, 27, 27, 27, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 27, 27, 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, + 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 5, 27, 27, 27, 27, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, + 27, 27, 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -2940,8 +2941,8 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -2949,57 +2950,56 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 55, 55, 55, 55, 55, 55, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 388, 55, 55, 388, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, + 388, 55, 55, 388, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, + 55, 55, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, - 55, 55, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 388, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 388, 55, 388, 388, 388, 55, 55, 55, 55, 55, 55, 388, 55, 55, + 55, 55, 55, 388, 55, 388, 388, 388, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 388, 388, 388, 388, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 388, 388, 388, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3007,7 +3007,7 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3016,14 +3016,14 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3031,8 +3031,8 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 388, 388, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 388, 388, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3045,11 +3045,11 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3057,10 +3057,10 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3068,7 +3068,7 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3076,194 +3076,194 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, - 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, + 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 103, 103, 103, 103, 103, 5, 5, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 5, 5, 5, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, - 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 55, 25, 6, 6, 6, 5, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 103, 30, 31, 30, 31, 30, 31, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 103, 103, 103, 103, 103, 5, 5, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 103, 5, 5, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, + 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 55, 25, 6, 6, 6, 5, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 103, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 30, 31, 102, 102, 25, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 30, 31, 30, 31, 102, 102, 25, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 25, 25, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 103, 103, 103, 103, 103, - 103, 103, 103, 103, 6, 6, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 20, 20, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, + 55, 55, 55, 55, 55, 55, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 25, 25, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 103, 103, 103, 103, 103, + 103, 103, 103, 103, 6, 6, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, + 30, 31, 20, 20, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 102, 20, 20, 20, 20, 20, - 20, 20, 20, 30, 31, 30, 31, 389, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, - 103, 6, 6, 30, 31, 390, 20, 55, 30, 31, 30, 31, 391, 20, 30, 31, 30, 31, - 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 392, 393, - 394, 395, 392, 20, 396, 397, 398, 399, 30, 31, 30, 31, 30, 31, 30, 31, - 30, 31, 30, 31, 0, 0, 30, 31, 400, 401, 402, 30, 31, 30, 31, 0, 0, 0, 0, + 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 102, 20, 20, 20, 20, 20, + 20, 20, 20, 30, 31, 30, 31, 389, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, + 103, 6, 6, 30, 31, 390, 20, 55, 30, 31, 30, 31, 391, 20, 30, 31, 30, 31, + 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 392, 393, + 394, 395, 392, 20, 396, 397, 398, 399, 30, 31, 30, 31, 30, 31, 30, 31, + 30, 31, 30, 31, 0, 0, 30, 31, 400, 401, 402, 30, 31, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 55, 102, 102, 20, 55, - 55, 55, 55, 55, 55, 55, 25, 55, 55, 55, 25, 55, 55, 55, 55, 25, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 18, 18, 25, 25, 18, 5, 5, 5, 5, 25, 0, 0, 0, 27, 27, 27, 27, - 27, 27, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 18, 18, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 55, 102, 102, 20, 55, + 55, 55, 55, 55, 55, 55, 25, 55, 55, 55, 25, 55, 55, 55, 55, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 18, 18, 25, 25, 18, 5, 5, 5, 5, 25, 0, 0, 0, 27, 27, 27, 27, + 27, 27, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, - 0, 0, 5, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 55, - 55, 55, 55, 55, 55, 5, 5, 5, 55, 5, 55, 55, 25, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, - 25, 25, 25, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 0, 0, 0, 25, 25, 25, 18, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 18, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 25, 18, 18, 25, 25, 25, 25, 18, 18, 25, 25, 18, 18, - 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 103, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 55, 55, 55, 55, 55, 25, 103, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 18, 18, 25, - 25, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 25, 55, 55, - 55, 55, 55, 55, 55, 55, 25, 18, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 0, 0, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 5, 5, 5, 55, 18, 25, 18, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 55, 25, 25, 25, 55, - 55, 25, 25, 55, 55, 55, 55, 55, 25, 25, 55, 25, 55, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 103, 5, 5, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 25, 25, 18, 18, 5, 5, 55, - 103, 103, 18, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, - 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, - 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, + 0, 0, 5, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 55, + 55, 55, 55, 55, 55, 5, 5, 5, 55, 5, 55, 55, 25, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, + 25, 25, 25, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 0, 0, 0, 25, 25, 25, 18, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 25, 18, 18, 25, 25, 25, 25, 18, 18, 25, 25, 18, 18, + 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 103, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 55, 55, 55, 55, 55, 25, 103, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 55, 55, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 18, 18, 25, + 25, 18, 18, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 25, 55, 55, + 55, 55, 55, 55, 55, 55, 25, 18, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 0, 0, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 5, 5, 5, 55, 18, 25, 18, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 55, 25, 25, 25, 55, + 55, 25, 25, 55, 55, 55, 55, 55, 25, 25, 55, 25, 55, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 103, 5, 5, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 25, 25, 18, 18, 5, 5, 55, + 103, 103, 18, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, + 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 403, 20, 20, 20, 20, 20, 20, 20, 6, 102, 102, 102, 102, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 103, 6, 6, 0, 0, 0, 0, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, - 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, - 480, 481, 482, 483, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 403, 20, 20, 20, 20, 20, 20, 20, 6, 102, 102, 102, 102, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 103, 6, 6, 0, 0, 0, 0, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, + 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, + 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, + 480, 481, 482, 483, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 18, 18, 25, 18, 18, 25, 18, 18, 5, 18, 25, 0, 0, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 18, 18, 25, 18, 18, 25, 18, 18, 5, 18, 25, 0, 0, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 55, 55, 55, 55, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 55, 55, 55, 55, 55, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, + 55, 55, 388, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, - 55, 55, 388, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 388, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 484, 485, 486, 487, 488, 489, - 490, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 491, 492, 493, 494, 495, 0, 0, - 0, 0, 0, 55, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 55, 0, - 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 484, 485, 486, 487, 488, 489, + 490, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 491, 492, 493, 494, 495, 0, 0, + 0, 0, 0, 55, 25, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 55, 0, + 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3271,369 +3271,369 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 496, 496, 496, 496, 496, 496, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 496, 496, 496, 496, 496, 496, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 5, 5, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 496, 496, 5, 5, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, - 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, - 5, 5, 18, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 18, 18, 18, 5, 5, 6, 0, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 0, 0, 0, 0, 496, 55, 496, 55, 496, 0, - 496, 55, 496, 55, 496, 55, 496, 55, 496, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 496, 496, 5, 5, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, + 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, + 5, 5, 18, 18, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 18, 18, 18, 5, 5, 6, 0, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 0, 0, 0, 0, 496, 55, 496, 55, 496, 0, + 496, 55, 496, 55, 496, 55, 496, 55, 496, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 21, 0, 5, 5, 5, 5, 5, 5, 6, - 5, 5, 5, 5, 5, 5, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 6, 5, 5, 5, - 5, 5, 5, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 5, 5, 5, 6, 18, 6, 19, 19, 19, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 21, 0, 5, 5, 5, 5, 5, 5, 6, + 5, 5, 5, 5, 5, 5, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 6, 5, 5, 5, + 5, 5, 5, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 5, 5, 5, 6, 18, 6, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 497, 497, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, - 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, - 55, 55, 55, 0, 0, 0, 5, 5, 5, 6, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 5, 5, 0, 0, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, - 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, + 19, 19, 19, 19, 19, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 103, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 497, 497, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 0, 0, + 55, 55, 55, 0, 0, 0, 5, 5, 5, 6, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 5, 5, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, + 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, + 55, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 27, 27, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 27, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 27, 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 27, 27, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 243, 55, 55, 55, - 55, 55, 55, 55, 55, 243, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 243, 55, 55, 55, + 55, 55, 55, 55, 55, 243, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 0, 0, - 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 0, 0, + 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 55, 55, 55, 55, 55, 55, 55, 55, 5, 243, 243, 243, 243, 243, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 5, 243, 243, 243, 243, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 498, 498, 498, 498, 498, 498, - 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, - 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, - 498, 498, 498, 498, 498, 498, 499, 499, 499, 499, 499, 499, 499, 499, - 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, - 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, - 499, 499, 499, 499, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 498, 498, 498, 498, 498, 498, + 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, + 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, + 498, 498, 498, 498, 498, 498, 499, 499, 499, 499, 499, 499, 499, 499, + 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, + 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, + 499, 499, 499, 499, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 498, 498, 498, 498, 498, 498, 498, 498, + 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, + 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 0, + 0, 0, 0, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, + 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, + 499, 499, 499, 499, 499, 499, 499, 499, 499, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 498, 498, 498, 498, 498, 498, 498, 498, - 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, - 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 498, 0, - 0, 0, 0, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, - 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, - 499, 499, 499, 499, 499, 499, 499, 499, 499, 0, 0, 0, 0, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 55, 55, 55, 0, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, + 0, 0, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 27, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, - 55, 55, 55, 55, 0, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 5, 5, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, - 0, 0, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 5, 27, 27, 27, 27, 27, 27, 27, 27, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 5, 5, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 55, 55, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 27, 27, 27, 27, 27, 27, 0, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 55, 55, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 27, 27, 27, 27, 27, 27, 0, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 27, 27, 55, 55, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 27, 27, 55, 55, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 55, - 25, 25, 25, 0, 25, 25, 0, 0, 0, 0, 0, 25, 25, 25, 25, 55, 55, 55, 55, 0, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, - 25, 0, 0, 0, 0, 25, 26, 22, 23, 360, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, - 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 27, 27, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, - 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 0, 0, 0, 0, 27, 27, - 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 5, - 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 5, - 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 55, + 25, 25, 25, 0, 25, 25, 0, 0, 0, 0, 0, 25, 25, 25, 25, 55, 55, 55, 55, 0, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, + 25, 0, 0, 0, 0, 25, 26, 22, 23, 360, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, + 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 27, 27, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, + 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 0, 0, 0, 0, 27, 27, + 27, 27, 27, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 5, + 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 5, + 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 109, 109, 109, 109, - 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, - 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, - 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, - 109, 109, 109, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, - 27, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, + 27, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 55, 55, 55, + 26, 22, 23, 360, 361, 362, 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 25, 25, 5, 0, 0, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 0, 25, 25, 5, 0, 0, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 55, - 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 27, 27, 27, 27, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 18, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 26, 22, 23, 360, 361, 362, - 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, - 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, - 25, 18, 18, 25, 25, 5, 5, 21, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 21, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, 25, 25, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, - 18, 25, 25, 25, 25, 25, 25, 25, 25, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 5, 5, 5, 5, 55, 18, 18, 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 5, 5, 55, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 18, 18, 55, 55, - 55, 55, 5, 5, 5, 5, 25, 25, 25, 25, 5, 18, 25, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 55, 5, 55, 5, 5, 5, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 18, 18, 25, - 18, 25, 25, 5, 5, 5, 5, 5, 5, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 0, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 5, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 27, 27, 27, 27, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 18, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 26, 22, 23, 360, 361, 362, + 363, 364, 365, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, + 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, + 25, 18, 18, 25, 25, 5, 5, 21, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 21, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, 25, 25, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, + 18, 25, 25, 25, 25, 25, 25, 25, 25, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 5, 5, 5, 5, 55, 18, 18, 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 5, 5, 55, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 25, 25, 18, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 25, 18, 18, 55, 55, + 55, 55, 5, 5, 5, 5, 25, 25, 25, 25, 5, 18, 25, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 55, 5, 55, 5, 5, 5, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 18, 18, 25, + 18, 25, 25, 5, 5, 5, 5, 5, 5, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 0, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 5, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 25, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, - 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, 25, - 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, - 0, 25, 25, 55, 18, 18, 25, 18, 18, 18, 18, 0, 0, 18, 18, 0, 0, 18, 18, - 18, 0, 0, 55, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, - 18, 18, 0, 0, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 25, 25, 25, 25, 25, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 25, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, + 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 25, 25, + 18, 18, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, + 0, 25, 25, 55, 18, 18, 25, 18, 18, 18, 18, 0, 0, 18, 18, 0, 0, 18, 18, + 18, 0, 0, 55, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, + 18, 18, 0, 0, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, 25, 25, 25, 25, 25, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 18, - 18, 25, 25, 25, 18, 25, 55, 55, 55, 55, 5, 5, 5, 5, 5, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 5, 5, 0, 5, 25, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 18, + 18, 25, 25, 25, 18, 25, 55, 55, 55, 55, 5, 5, 5, 5, 5, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 5, 5, 0, 5, 25, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, - 25, 18, 25, 18, 18, 18, 18, 25, 25, 18, 25, 25, 55, 55, 5, 55, 0, 0, 0, - 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, + 25, 18, 25, 18, 18, 18, 18, 25, 25, 18, 25, 25, 55, 55, 5, 55, 0, 0, 0, + 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, + 18, 25, 25, 25, 25, 0, 0, 18, 18, 18, 18, 25, 25, 18, 25, 25, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, + 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 18, 18, 25, 18, + 25, 25, 5, 5, 5, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 25, 18, 25, 18, 18, 25, 25, 25, 25, 25, 25, 18, 25, 55, + 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, - 18, 25, 25, 25, 25, 0, 0, 18, 18, 18, 18, 25, 25, 18, 25, 25, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 55, 55, 55, 55, - 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, 25, 25, 18, 18, 25, 18, - 25, 25, 5, 5, 5, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 25, 18, 25, 18, 18, 25, 25, 25, 25, 25, 25, 18, 25, 55, - 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 25, 18, 18, 25, 25, - 25, 25, 18, 25, 25, 25, 25, 25, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 27, 27, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 18, 25, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 25, 18, 18, 25, 25, + 25, 25, 18, 25, 25, 25, 25, 25, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 27, 27, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 18, 25, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 18, 18, 18, 18, 18, 18, 0, 18, 18, 0, 0, 25, 25, 18, 25, - 55, 18, 55, 18, 25, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, - 25, 25, 25, 25, 0, 0, 25, 25, 18, 18, 18, 18, 25, 55, 5, 55, 18, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, - 25, 25, 25, 18, 55, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 25, 0, 0, 0, - 0, 0, 0, 0, 0, 55, 25, 25, 25, 25, 25, 25, 18, 18, 25, 25, 25, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 18, 25, 25, 5, 5, 5, 55, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, - 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 25, 25, 25, 25, 18, 25, 55, 5, 5, - 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 0, 0, 0, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 0, 18, 25, 25, 25, 25, 25, 25, 25, 18, 25, 25, 18, - 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 19, 19, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 55, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 18, 18, 18, 18, 18, 18, 0, 18, 18, 0, 0, 25, 25, 18, 25, + 55, 18, 55, 18, 25, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, + 25, 25, 25, 25, 0, 0, 25, 25, 18, 18, 18, 18, 25, 55, 5, 55, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, + 25, 25, 25, 18, 55, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 25, 0, 0, 0, + 0, 0, 0, 0, 0, 55, 25, 25, 25, 25, 25, 25, 18, 18, 25, 25, 25, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 18, 25, 25, 5, 5, 5, 55, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, - 25, 25, 25, 0, 0, 0, 25, 0, 25, 25, 0, 25, 25, 25, 25, 25, 25, 25, 55, - 25, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, - 0, 0, 0, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, 18, 0, 25, 25, 0, 18, 18, - 25, 18, 25, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 18, + 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 25, 25, 25, 25, 18, 25, 55, 5, 5, + 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 0, 0, 0, 5, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 0, 18, 25, 25, 25, 25, 25, 25, 25, 18, 25, 25, 18, + 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, + 25, 25, 25, 0, 0, 0, 25, 0, 25, 25, 0, 25, 25, 25, 25, 25, 25, 25, 55, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, + 0, 0, 0, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 18, 18, 18, 18, 18, 0, 25, 25, 0, 18, 18, + 25, 18, 25, 55, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -3641,121 +3641,121 @@ static const unsigned short index2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 18, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, 18, 18, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, + 243, 243, 243, 243, 243, 243, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - 243, 243, 243, 243, 243, 243, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, - 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, + 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 25, 25, 25, 5, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 0, 0, 25, 25, 25, 25, 25, 5, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, - 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 103, 103, 103, 103, 5, 5, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 27, - 27, 27, 27, 27, 27, 27, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 25, 25, + 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 103, 103, 103, 103, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 27, + 27, 27, 27, 27, 27, 27, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 25, 55, 18, 18, 18, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 25, 55, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 0, 0, 0, - 0, 0, 0, 0, 25, 25, 25, 25, 103, 103, 103, 103, 103, 103, 103, 103, 103, - 103, 103, 103, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 0, 0, 0, + 0, 0, 0, 0, 25, 25, 25, 25, 103, 103, 103, 103, 103, 103, 103, 103, 103, + 103, 103, 103, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 103, - 103, 5, 103, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 18, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 103, + 103, 5, 103, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 18, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, - 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, + 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -3763,301 +3763,301 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, - 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 5, 25, - 25, 5, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, + 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 5, 25, + 25, 5, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 18, 25, 25, 25, 5, 5, - 5, 18, 18, 18, 18, 18, 18, 21, 21, 21, 21, 21, 21, 21, 21, 25, 25, 25, - 25, 25, 25, 25, 25, 5, 5, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 18, 25, 25, 25, 5, 5, + 5, 18, 18, 18, 18, 18, 18, 21, 21, 21, 21, 21, 21, 21, 21, 25, 25, 25, + 25, 25, 25, 25, 25, 5, 5, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 25, 25, 25, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 25, 25, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, - 0, 0, 0, 0, 0, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 0, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, + 0, 0, 0, 0, 0, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 0, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 121, 0, 121, 121, 0, 0, 121, 0, 0, 121, 121, 0, 0, 121, 121, 121, - 121, 0, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 0, 20, 0, - 20, 20, 20, 20, 20, 20, 20, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, + 20, 121, 0, 121, 121, 0, 0, 121, 0, 0, 121, 121, 0, 0, 121, 121, 121, + 121, 0, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 0, 20, 0, + 20, 20, 20, 20, 20, 20, 20, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 121, 121, 0, 121, 121, 121, 121, 0, 0, 121, 121, 121, - 121, 121, 121, 121, 121, 0, 121, 121, 121, 121, 121, 121, 121, 0, 20, 20, + 20, 20, 20, 20, 20, 121, 121, 0, 121, 121, 121, 121, 0, 0, 121, 121, 121, + 121, 121, 121, 121, 121, 0, 121, 121, 121, 121, 121, 121, 121, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 121, 121, 0, 121, 121, 121, 121, 0, 121, 121, - 121, 121, 121, 0, 121, 0, 0, 0, 121, 121, 121, 121, 121, 121, 121, 0, 20, + 20, 20, 20, 20, 20, 20, 121, 121, 0, 121, 121, 121, 121, 0, 121, 121, + 121, 121, 121, 0, 121, 0, 0, 0, 121, 121, 121, 121, 121, 121, 121, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 0, 0, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 5, + 20, 20, 20, 0, 0, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, + 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, - 20, 20, 121, 20, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 25, 25, 25, + 20, 20, 5, 20, 20, 20, 20, 20, 20, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 5, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, + 20, 20, 121, 20, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, - 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, + 5, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, - 5, 5, 5, 5, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 5, 5, 5, 5, - 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, - 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 5, 5, 5, 5, + 5, 5, 5, 5, 25, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 5, 5, 5, 5, + 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, + 0, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, 25, 25, 25, 25, 25, 25, 25, + 0, 25, 25, 0, 25, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 0, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 0, 0, 25, 25, 25, 25, 25, 25, 25, - 0, 25, 25, 0, 25, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, - 103, 103, 103, 103, 103, 103, 103, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 0, 0, 0, 0, 55, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 0, 0, 0, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 25, 25, 25, 25, 25, - 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 500, 500, - 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, - 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, - 500, 500, 500, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, - 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, - 501, 501, 501, 501, 501, 501, 501, 501, 501, 25, 25, 25, 25, 25, 25, 25, - 103, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, + 103, 103, 103, 103, 103, 103, 103, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 0, 0, 0, 0, 55, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 25, 25, 25, 25, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 0, 0, 0, 0, 0, 5, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 25, 25, 25, 25, 25, + 25, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 500, 500, 500, + 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, + 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, + 500, 500, 500, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, + 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, 501, + 501, 501, 501, 501, 501, 501, 501, 501, 501, 25, 25, 25, 25, 25, 25, 25, + 103, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 5, 27, 27, 27, 27, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 5, 27, 27, 27, 27, 0, 0, 0, 0, 0, + 27, 27, 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 5, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, + 55, 0, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, + 55, 0, 55, 0, 55, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 55, 0, 55, 0, 55, 0, + 55, 55, 55, 0, 55, 55, 0, 55, 0, 0, 55, 0, 55, 0, 55, 0, 55, 0, 55, 0, + 55, 55, 0, 55, 0, 0, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, + 55, 55, 55, 55, 0, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 0, - 55, 0, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 55, 55, 55, - 55, 0, 55, 0, 55, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 55, 0, 55, 0, 55, 0, - 55, 55, 55, 0, 55, 55, 0, 55, 0, 0, 55, 0, 55, 0, 55, 0, 55, 0, 55, 0, - 55, 55, 0, 55, 0, 0, 55, 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 0, - 55, 55, 55, 55, 0, 55, 55, 55, 55, 0, 55, 0, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 0, 55, 55, 55, 0, 55, 55, 55, 55, 55, 0, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, - 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 359, 359, 26, 22, 23, 360, 361, 362, 363, 364, - 365, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 502, 502, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 502, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, - 502, 502, 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, + 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 359, 359, 26, 22, 23, 360, 361, 362, 363, 364, + 365, 27, 27, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 502, 502, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 502, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, 502, + 502, 502, 502, 502, 502, 502, 502, 502, 502, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 5, 5, 5, - 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, - 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, + 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 388, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 0, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -4067,35 +4067,33 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, @@ -4104,61 +4102,63 @@ static const unsigned short index2[] = { 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 388, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 25, 25, 25, 25, 25, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, @@ -4172,13 +4172,13 @@ static const unsigned short index2[] = { 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, }; /* Returns the numeric value as double for Unicode characters @@ -4251,7 +4251,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C0: case 0x11730: case 0x118E0: - case 0x11950: + case 0x11950: case 0x11C50: case 0x11D50: case 0x11DA0: @@ -4264,14 +4264,14 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E2: case 0x1D7EC: case 0x1D7F6: - case 0x1E140: - case 0x1E2F0: + case 0x1E140: + case 0x1E2F0: case 0x1E950: case 0x1F100: case 0x1F101: case 0x1F10B: case 0x1F10C: - case 0x1FBF0: + case 0x1FBF0: return (double) 0.0; case 0x0031: case 0x00B9: @@ -4364,7 +4364,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10E60: case 0x10F1D: case 0x10F51: - case 0x10FC5: + case 0x10FC5: case 0x11052: case 0x11067: case 0x110F1: @@ -4378,7 +4378,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C1: case 0x11731: case 0x118E1: - case 0x11951: + case 0x11951: case 0x11C51: case 0x11C5A: case 0x11D51: @@ -4402,21 +4402,21 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E3: case 0x1D7ED: case 0x1D7F7: - case 0x1E141: - case 0x1E2F1: + case 0x1E141: + case 0x1E2F1: case 0x1E8C7: case 0x1E951: case 0x1EC71: case 0x1ECA3: case 0x1ECB1: - case 0x1ED01: + case 0x1ED01: case 0x1F102: - case 0x1FBF1: + case 0x1FBF1: case 0x2092A: return (double) 1.0; case 0x0D5C: case 0x2152: - case 0x11FCB: + case 0x11FCB: return (double) 1.0/10.0; case 0x109F6: return (double) 1.0/12.0; @@ -4424,11 +4424,11 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x0B75: case 0x0D76: case 0xA833: - case 0x11FC9: - case 0x11FCA: + case 0x11FC9: + case 0x11FCA: return (double) 1.0/16.0; case 0x0D58: - case 0x11FC1: + case 0x11FC1: return (double) 1.0/160.0; case 0x00BD: case 0x0B73: @@ -4443,14 +4443,14 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10A48: case 0x10E7B: case 0x10F26: - case 0x11FD1: - case 0x11FD2: + case 0x11FD1: + case 0x11FD2: case 0x12464: case 0x1ECAE: - case 0x1ED3C: + case 0x1ED3C: return (double) 1.0/2.0; case 0x0D5B: - case 0x11FC8: + case 0x11FC8: return (double) 1.0/20.0; case 0x2153: case 0x10E7D: @@ -4458,11 +4458,11 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1245D: case 0x12465: return (double) 1.0/3.0; - case 0x11FC5: - return (double) 1.0/32.0; - case 0x11FC0: - case 0x11FD4: - return (double) 1.0/320.0; + case 0x11FC5: + return (double) 1.0/32.0; + case 0x11FC0: + case 0x11FD4: + return (double) 1.0/320.0; case 0x00BC: case 0x09F7: case 0x0B72: @@ -4471,25 +4471,25 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10140: case 0x1018B: case 0x10E7C: - case 0x11FD0: + case 0x11FD0: case 0x12460: case 0x12462: case 0x12463: case 0x1ECAD: return (double) 1.0/4.0; case 0x0D59: - case 0x11FC4: + case 0x11FC4: return (double) 1.0/40.0; case 0x0D5E: case 0x2155: - case 0x11FCF: + case 0x11FCF: return (double) 1.0/5.0; case 0x2159: case 0x12461: - case 0x1ED3D: + case 0x1ED3D: return (double) 1.0/6.0; - case 0x11FC3: - return (double) 1.0/64.0; + case 0x11FC3: + return (double) 1.0/64.0; case 0x2150: return (double) 1.0/7.0; case 0x09F5: @@ -4497,11 +4497,11 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x0D77: case 0x215B: case 0xA834: - case 0x11FCC: + case 0x11FCC: case 0x1245F: return (double) 1.0/8.0; - case 0x11FC2: - return (double) 1.0/80.0; + case 0x11FC2: + return (double) 1.0/80.0; case 0x2151: return (double) 1.0/9.0; case 0x0BF0: @@ -4553,7 +4553,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10E69: case 0x10F22: case 0x10F52: - case 0x10FC9: + case 0x10FC9: case 0x1105B: case 0x111EA: case 0x1173A: @@ -4564,8 +4564,8 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D2EA: case 0x1D369: case 0x1EC7A: - case 0x1ED0A: - case 0x1ED37: + case 0x1ED0A: + case 0x1ED37: return (double) 10.0; case 0x109FF: return (double) 10.0/12.0; @@ -4597,13 +4597,13 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10E72: case 0x10F25: case 0x10F54: - case 0x10FCB: + case 0x10FCB: case 0x11064: case 0x111F3: case 0x11C6C: case 0x16B5C: case 0x1EC83: - case 0x1ED13: + case 0x1ED13: return (double) 100.0; case 0x0BF2: case 0x0D72: @@ -4626,7 +4626,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11065: case 0x111F4: case 0x1EC8C: - case 0x1ED1C: + case 0x1ED1C: return (double) 1000.0; case 0x137C: case 0x2182: @@ -4639,8 +4639,8 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x16B5D: case 0x1EC95: case 0x1ECB3: - case 0x1ED25: - case 0x1ED3B: + case 0x1ED25: + case 0x1ED3B: return (double) 10000.0; case 0x2188: case 0x109ED: @@ -4828,7 +4828,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10D32: case 0x10E61: case 0x10F1E: - case 0x10FC6: + case 0x10FC6: case 0x11053: case 0x11068: case 0x110F2: @@ -4842,7 +4842,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C2: case 0x11732: case 0x118E2: - case 0x11952: + case 0x11952: case 0x11C52: case 0x11C5B: case 0x11D52: @@ -4869,17 +4869,17 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E4: case 0x1D7EE: case 0x1D7F8: - case 0x1E142: - case 0x1E2F2: + case 0x1E142: + case 0x1E2F2: case 0x1E8C8: case 0x1E952: case 0x1EC72: case 0x1ECA4: case 0x1ECB2: - case 0x1ED02: - case 0x1ED2F: + case 0x1ED02: + case 0x1ED2F: case 0x1F103: - case 0x1FBF2: + case 0x1FBF2: case 0x22390: return (double) 2.0; case 0x109F7: @@ -4920,7 +4920,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10E6A: case 0x10F23: case 0x10F53: - case 0x10FCA: + case 0x10FCA: case 0x1105C: case 0x111EB: case 0x1173B: @@ -4928,25 +4928,25 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C64: case 0x1D36A: case 0x1EC7B: - case 0x1ED0B: + case 0x1ED0B: return (double) 20.0; case 0x1011A: case 0x102F4: case 0x109D3: case 0x10E73: case 0x1EC84: - case 0x1ED14: + case 0x1ED14: return (double) 200.0; case 0x10123: case 0x109DC: case 0x1EC8D: - case 0x1ED1D: - case 0x1ED3A: + case 0x1ED1D: + case 0x1ED3A: return (double) 2000.0; case 0x1012C: case 0x109E5: case 0x1EC96: - case 0x1ED26: + case 0x1ED26: return (double) 20000.0; case 0x109EE: case 0x1EC9F: @@ -5053,7 +5053,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10D33: case 0x10E62: case 0x10F1F: - case 0x10FC7: + case 0x10FC7: case 0x11054: case 0x11069: case 0x110F3: @@ -5067,7 +5067,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C3: case 0x11733: case 0x118E3: - case 0x11953: + case 0x11953: case 0x11C53: case 0x11C5C: case 0x11D53: @@ -5099,16 +5099,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E5: case 0x1D7EF: case 0x1D7F9: - case 0x1E143: - case 0x1E2F3: + case 0x1E143: + case 0x1E2F3: case 0x1E8C9: case 0x1E953: case 0x1EC73: case 0x1ECA5: - case 0x1ED03: - case 0x1ED30: + case 0x1ED03: + case 0x1ED30: case 0x1F104: - case 0x1FBF3: + case 0x1FBF3: case 0x20AFD: case 0x20B19: case 0x22998: @@ -5120,12 +5120,12 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x0B77: case 0x0D78: case 0xA835: - case 0x11FCE: + case 0x11FCE: return (double) 3.0/16.0; case 0x0F2B: return (double) 3.0/2.0; case 0x0D5D: - case 0x11FCD: + case 0x11FCD: return (double) 3.0/20.0; case 0x00BE: case 0x09F8: @@ -5133,17 +5133,17 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x0D75: case 0xA832: case 0x10178: - case 0x11FD3: + case 0x11FD3: case 0x1ECAF: return (double) 3.0/4.0; case 0x2157: return (double) 3.0/5.0; - case 0x11FC7: - return (double) 3.0/64.0; + case 0x11FC7: + return (double) 3.0/64.0; case 0x215C: return (double) 3.0/8.0; case 0x0D5A: - case 0x11FC6: + case 0x11FC6: return (double) 3.0/80.0; case 0x1374: case 0x303A: @@ -5162,7 +5162,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C65: case 0x1D36B: case 0x1EC7C: - case 0x1ED0C: + case 0x1ED0C: case 0x20983: return (double) 30.0; case 0x1011B: @@ -5171,17 +5171,17 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x109D4: case 0x10E74: case 0x1EC85: - case 0x1ED15: + case 0x1ED15: return (double) 300.0; case 0x10124: case 0x109DD: case 0x1EC8E: - case 0x1ED1E: + case 0x1ED1E: return (double) 3000.0; case 0x1012D: case 0x109E6: case 0x1EC97: - case 0x1ED27: + case 0x1ED27: return (double) 30000.0; case 0x109EF: return (double) 300000.0; @@ -5275,7 +5275,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10D34: case 0x10E63: case 0x10F20: - case 0x10FC8: + case 0x10FC8: case 0x11055: case 0x1106A: case 0x110F4: @@ -5289,7 +5289,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C4: case 0x11734: case 0x118E4: - case 0x11954: + case 0x11954: case 0x11C54: case 0x11C5D: case 0x11D54: @@ -5321,16 +5321,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E6: case 0x1D7F0: case 0x1D7FA: - case 0x1E144: - case 0x1E2F4: + case 0x1E144: + case 0x1E2F4: case 0x1E8CA: case 0x1E954: case 0x1EC74: case 0x1ECA6: - case 0x1ED04: - case 0x1ED31: + case 0x1ED04: + case 0x1ED31: case 0x1F105: - case 0x1FBF4: + case 0x1FBF4: case 0x20064: case 0x200E2: case 0x2626D: @@ -5354,7 +5354,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x12467: case 0x1D36C: case 0x1EC7D: - case 0x1ED0D: + case 0x1ED0D: case 0x2098C: case 0x2099C: return (double) 40.0; @@ -5363,18 +5363,18 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x109D5: case 0x10E75: case 0x1EC86: - case 0x1ED16: - case 0x1ED38: + case 0x1ED16: + case 0x1ED38: return (double) 400.0; case 0x10125: case 0x109DE: case 0x1EC8F: - case 0x1ED1F: + case 0x1ED1F: return (double) 4000.0; case 0x1012E: case 0x109E7: case 0x1EC98: - case 0x1ED28: + case 0x1ED28: return (double) 40000.0; case 0x109F0: return (double) 400000.0; @@ -5487,7 +5487,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C5: case 0x11735: case 0x118E5: - case 0x11955: + case 0x11955: case 0x11C55: case 0x11C5E: case 0x11D55: @@ -5516,16 +5516,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E7: case 0x1D7F1: case 0x1D7FB: - case 0x1E145: - case 0x1E2F5: + case 0x1E145: + case 0x1E2F5: case 0x1E8CB: case 0x1E955: case 0x1EC75: case 0x1ECA7: - case 0x1ED05: - case 0x1ED32: + case 0x1ED05: + case 0x1ED32: case 0x1F106: - case 0x1FBF5: + case 0x1FBF5: case 0x20121: return (double) 5.0; case 0x109FA: @@ -5565,7 +5565,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x12468: case 0x1D36D: case 0x1EC7E: - case 0x1ED0E: + case 0x1ED0E: return (double) 50.0; case 0x216E: case 0x217E: @@ -5582,7 +5582,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x109D6: case 0x10E76: case 0x1EC87: - case 0x1ED17: + case 0x1ED17: return (double) 500.0; case 0x2181: case 0x10126: @@ -5591,7 +5591,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10172: case 0x109DF: case 0x1EC90: - case 0x1ED20: + case 0x1ED20: return (double) 5000.0; case 0x2187: case 0x1012F: @@ -5599,7 +5599,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x10156: case 0x109E8: case 0x1EC99: - case 0x1ED29: + case 0x1ED29: return (double) 50000.0; case 0x109F1: return (double) 500000.0; @@ -5682,7 +5682,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C6: case 0x11736: case 0x118E6: - case 0x11956: + case 0x11956: case 0x11C56: case 0x11C5F: case 0x11D56: @@ -5705,16 +5705,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E8: case 0x1D7F2: case 0x1D7FC: - case 0x1E146: - case 0x1E2F6: + case 0x1E146: + case 0x1E2F6: case 0x1E8CC: case 0x1E956: case 0x1EC76: case 0x1ECA8: - case 0x1ED06: - case 0x1ED33: + case 0x1ED06: + case 0x1ED33: case 0x1F107: - case 0x1FBF6: + case 0x1FBF6: case 0x20AEA: return (double) 6.0; case 0x109FB: @@ -5731,25 +5731,25 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C68: case 0x1D36E: case 0x1EC7F: - case 0x1ED0F: + case 0x1ED0F: return (double) 60.0; case 0x1011E: case 0x102F8: case 0x109D7: case 0x10E77: case 0x1EC88: - case 0x1ED18: - case 0x1ED39: + case 0x1ED18: + case 0x1ED39: return (double) 600.0; case 0x10127: case 0x109E0: case 0x1EC91: - case 0x1ED21: + case 0x1ED21: return (double) 6000.0; case 0x10130: case 0x109E9: case 0x1EC9A: - case 0x1ED2A: + case 0x1ED2A: return (double) 60000.0; case 0x109F2: return (double) 600000.0; @@ -5830,7 +5830,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C7: case 0x11737: case 0x118E7: - case 0x11957: + case 0x11957: case 0x11C57: case 0x11C60: case 0x11D57: @@ -5854,16 +5854,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7E9: case 0x1D7F3: case 0x1D7FD: - case 0x1E147: - case 0x1E2F7: + case 0x1E147: + case 0x1E2F7: case 0x1E8CD: case 0x1E957: case 0x1EC77: case 0x1ECA9: - case 0x1ED07: - case 0x1ED34: + case 0x1ED07: + case 0x1ED34: case 0x1F108: - case 0x1FBF7: + case 0x1FBF7: case 0x20001: return (double) 7.0; case 0x109FC: @@ -5884,24 +5884,24 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C69: case 0x1D36F: case 0x1EC80: - case 0x1ED10: + case 0x1ED10: return (double) 70.0; case 0x1011F: case 0x102F9: case 0x109D8: case 0x10E78: case 0x1EC89: - case 0x1ED19: + case 0x1ED19: return (double) 700.0; case 0x10128: case 0x109E1: case 0x1EC92: - case 0x1ED22: + case 0x1ED22: return (double) 7000.0; case 0x10131: case 0x109EA: case 0x1EC9B: - case 0x1ED2B: + case 0x1ED2B: return (double) 70000.0; case 0x109F3: return (double) 700000.0; @@ -5980,7 +5980,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C8: case 0x11738: case 0x118E8: - case 0x11958: + case 0x11958: case 0x11C58: case 0x11C61: case 0x11D58: @@ -6003,16 +6003,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7EA: case 0x1D7F4: case 0x1D7FE: - case 0x1E148: - case 0x1E2F8: + case 0x1E148: + case 0x1E2F8: case 0x1E8CE: case 0x1E958: case 0x1EC78: case 0x1ECAA: - case 0x1ED08: - case 0x1ED35: + case 0x1ED08: + case 0x1ED35: case 0x1F109: - case 0x1FBF8: + case 0x1FBF8: return (double) 8.0; case 0x109FD: return (double) 8.0/12.0; @@ -6027,24 +6027,24 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C6A: case 0x1D370: case 0x1EC81: - case 0x1ED11: + case 0x1ED11: return (double) 80.0; case 0x10120: case 0x102FA: case 0x109D9: case 0x10E79: case 0x1EC8A: - case 0x1ED1A: + case 0x1ED1A: return (double) 800.0; case 0x10129: case 0x109E2: case 0x1EC93: - case 0x1ED23: + case 0x1ED23: return (double) 8000.0; case 0x10132: case 0x109EB: case 0x1EC9C: - case 0x1ED2C: + case 0x1ED2C: return (double) 80000.0; case 0x109F4: return (double) 800000.0; @@ -6124,7 +6124,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x116C9: case 0x11739: case 0x118E9: - case 0x11959: + case 0x11959: case 0x11C59: case 0x11C62: case 0x11D59: @@ -6149,16 +6149,16 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x1D7EB: case 0x1D7F5: case 0x1D7FF: - case 0x1E149: - case 0x1E2F9: + case 0x1E149: + case 0x1E2F9: case 0x1E8CF: case 0x1E959: case 0x1EC79: case 0x1ECAB: - case 0x1ED09: - case 0x1ED36: + case 0x1ED09: + case 0x1ED36: case 0x1F10A: - case 0x1FBF9: + case 0x1FBF9: case 0x2F890: return (double) 9.0; case 0x109FE: @@ -6176,7 +6176,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x11C6B: case 0x1D371: case 0x1EC82: - case 0x1ED12: + case 0x1ED12: return (double) 90.0; case 0x10121: case 0x102FB: @@ -6184,17 +6184,17 @@ double _PyUnicode_ToNumeric(Py_UCS4 ch) case 0x109DA: case 0x10E7A: case 0x1EC8B: - case 0x1ED1B: + case 0x1ED1B: return (double) 900.0; case 0x1012A: case 0x109E3: case 0x1EC94: - case 0x1ED24: + case 0x1ED24: return (double) 9000.0; case 0x10133: case 0x109EC: case 0x1EC9D: - case 0x1ED2D: + case 0x1ED2D: return (double) 90000.0; case 0x109F5: return (double) 900000.0; diff --git a/contrib/tools/python3/src/Objects/weakrefobject.c b/contrib/tools/python3/src/Objects/weakrefobject.c index 518af8b202..bb56c7dbdb 100644 --- a/contrib/tools/python3/src/Objects/weakrefobject.c +++ b/contrib/tools/python3/src/Objects/weakrefobject.c @@ -1,10 +1,10 @@ #include "Python.h" -#include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR() -#include "structmember.h" // PyMemberDef +#include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR() +#include "structmember.h" // PyMemberDef #define GET_WEAKREFS_LISTPTR(o) \ - ((PyWeakReference **) _PyObject_GET_WEAKREFS_LISTPTR(o)) + ((PyWeakReference **) _PyObject_GET_WEAKREFS_LISTPTR(o)) Py_ssize_t @@ -146,14 +146,14 @@ weakref_hash(PyWeakReference *self) { if (self->hash != -1) return self->hash; - PyObject* obj = PyWeakref_GET_OBJECT(self); - if (obj == Py_None) { + PyObject* obj = PyWeakref_GET_OBJECT(self); + if (obj == Py_None) { PyErr_SetString(PyExc_TypeError, "weak object has gone away"); return -1; } - Py_INCREF(obj); - self->hash = PyObject_Hash(obj); - Py_DECREF(obj); + Py_INCREF(obj); + self->hash = PyObject_Hash(obj); + Py_DECREF(obj); return self->hash; } @@ -163,33 +163,33 @@ weakref_repr(PyWeakReference *self) { PyObject *name, *repr; _Py_IDENTIFIER(__name__); - PyObject* obj = PyWeakref_GET_OBJECT(self); + PyObject* obj = PyWeakref_GET_OBJECT(self); - if (obj == Py_None) { + if (obj == Py_None) { return PyUnicode_FromFormat("<weakref at %p; dead>", self); - } + } - Py_INCREF(obj); - if (_PyObject_LookupAttrId(obj, &PyId___name__, &name) < 0) { - Py_DECREF(obj); - return NULL; - } + Py_INCREF(obj); + if (_PyObject_LookupAttrId(obj, &PyId___name__, &name) < 0) { + Py_DECREF(obj); + return NULL; + } if (name == NULL || !PyUnicode_Check(name)) { repr = PyUnicode_FromFormat( "<weakref at %p; to '%s' at %p>", self, Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name, - obj); + obj); } else { repr = PyUnicode_FromFormat( "<weakref at %p; to '%s' at %p (%U)>", self, Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name, - obj, + obj, name); } - Py_DECREF(obj); + Py_DECREF(obj); Py_XDECREF(name); return repr; } @@ -216,14 +216,14 @@ weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op) else Py_RETURN_FALSE; } - PyObject* obj = PyWeakref_GET_OBJECT(self); - PyObject* other_obj = PyWeakref_GET_OBJECT(other); - Py_INCREF(obj); - Py_INCREF(other_obj); - PyObject* res = PyObject_RichCompare(obj, other_obj, op); - Py_DECREF(obj); - Py_DECREF(other_obj); - return res; + PyObject* obj = PyWeakref_GET_OBJECT(self); + PyObject* other_obj = PyWeakref_GET_OBJECT(other); + Py_INCREF(obj); + Py_INCREF(other_obj); + PyObject* res = PyObject_RichCompare(obj, other_obj, op); + Py_DECREF(obj); + Py_DECREF(other_obj); + return res; } /* Given the head of an object's list of weak references, extract the @@ -362,12 +362,12 @@ static PyMemberDef weakref_members[] = { {NULL} /* Sentinel */ }; -static PyMethodDef weakref_methods[] = { - {"__class_getitem__", (PyCFunction)Py_GenericAlias, - METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, - {NULL} /* Sentinel */ -}; - +static PyMethodDef weakref_methods[] = { + {"__class_getitem__", (PyCFunction)Py_GenericAlias, + METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, + {NULL} /* Sentinel */ +}; + PyTypeObject _PyWeakref_RefType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) @@ -375,10 +375,10 @@ _PyWeakref_RefType = { sizeof(PyWeakReference), 0, weakref_dealloc, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ + 0, /*tp_vectorcall_offset*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_as_async*/ + 0, /*tp_as_async*/ (reprfunc)weakref_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ @@ -398,7 +398,7 @@ _PyWeakref_RefType = { 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - weakref_methods, /*tp_methods*/ + weakref_methods, /*tp_methods*/ weakref_members, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -440,10 +440,10 @@ proxy_checkref(PyWeakReference *proxy) static PyObject * \ method(PyObject *proxy) { \ UNWRAP(proxy); \ - Py_INCREF(proxy); \ - PyObject* res = generic(proxy); \ - Py_DECREF(proxy); \ - return res; \ + Py_INCREF(proxy); \ + PyObject* res = generic(proxy); \ + Py_DECREF(proxy); \ + return res; \ } #define WRAP_BINARY(method, generic) \ @@ -451,12 +451,12 @@ proxy_checkref(PyWeakReference *proxy) method(PyObject *x, PyObject *y) { \ UNWRAP(x); \ UNWRAP(y); \ - Py_INCREF(x); \ - Py_INCREF(y); \ - PyObject* res = generic(x, y); \ - Py_DECREF(x); \ - Py_DECREF(y); \ - return res; \ + Py_INCREF(x); \ + Py_INCREF(y); \ + PyObject* res = generic(x, y); \ + Py_DECREF(x); \ + Py_DECREF(y); \ + return res; \ } /* Note that the third arg needs to be checked for NULL since the tp_call @@ -469,25 +469,25 @@ proxy_checkref(PyWeakReference *proxy) UNWRAP(v); \ if (w != NULL) \ UNWRAP(w); \ - Py_INCREF(proxy); \ - Py_INCREF(v); \ - Py_XINCREF(w); \ - PyObject* res = generic(proxy, v, w); \ - Py_DECREF(proxy); \ - Py_DECREF(v); \ - Py_XDECREF(w); \ - return res; \ + Py_INCREF(proxy); \ + Py_INCREF(v); \ + Py_XINCREF(w); \ + PyObject* res = generic(proxy, v, w); \ + Py_DECREF(proxy); \ + Py_DECREF(v); \ + Py_XDECREF(w); \ + return res; \ } #define WRAP_METHOD(method, special) \ static PyObject * \ - method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ + method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ _Py_IDENTIFIER(special); \ UNWRAP(proxy); \ - Py_INCREF(proxy); \ - PyObject* res = _PyObject_CallMethodIdNoArgs(proxy, &PyId_##special); \ - Py_DECREF(proxy); \ - return res; \ + Py_INCREF(proxy); \ + PyObject* res = _PyObject_CallMethodIdNoArgs(proxy, &PyId_##special); \ + Py_DECREF(proxy); \ + return res; \ } @@ -513,11 +513,11 @@ proxy_setattr(PyWeakReference *proxy, PyObject *name, PyObject *value) { if (!proxy_checkref(proxy)) return -1; - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - Py_INCREF(obj); - int res = PyObject_SetAttr(obj, name, value); - Py_DECREF(obj); - return res; + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + Py_INCREF(obj); + int res = PyObject_SetAttr(obj, name, value); + Py_DECREF(obj); + return res; } static PyObject * @@ -561,20 +561,20 @@ WRAP_BINARY(proxy_iand, PyNumber_InPlaceAnd) WRAP_BINARY(proxy_ixor, PyNumber_InPlaceXor) WRAP_BINARY(proxy_ior, PyNumber_InPlaceOr) WRAP_UNARY(proxy_index, PyNumber_Index) -WRAP_BINARY(proxy_matmul, PyNumber_MatrixMultiply) -WRAP_BINARY(proxy_imatmul, PyNumber_InPlaceMatrixMultiply) +WRAP_BINARY(proxy_matmul, PyNumber_MatrixMultiply) +WRAP_BINARY(proxy_imatmul, PyNumber_InPlaceMatrixMultiply) static int proxy_bool(PyWeakReference *proxy) { PyObject *o = PyWeakref_GET_OBJECT(proxy); - if (!proxy_checkref(proxy)) { + if (!proxy_checkref(proxy)) { return -1; - } - Py_INCREF(o); - int res = PyObject_IsTrue(o); - Py_DECREF(o); - return res; + } + Py_INCREF(o); + int res = PyObject_IsTrue(o); + Py_DECREF(o); + return res; } static void @@ -593,12 +593,12 @@ proxy_contains(PyWeakReference *proxy, PyObject *value) { if (!proxy_checkref(proxy)) return -1; - - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - Py_INCREF(obj); - int res = PySequence_Contains(obj, value); - Py_DECREF(obj); - return res; + + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + Py_INCREF(obj); + int res = PySequence_Contains(obj, value); + Py_DECREF(obj); + return res; } /* mapping slots */ @@ -608,12 +608,12 @@ proxy_length(PyWeakReference *proxy) { if (!proxy_checkref(proxy)) return -1; - - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - Py_INCREF(obj); - Py_ssize_t res = PyObject_Length(obj); - Py_DECREF(obj); - return res; + + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + Py_INCREF(obj); + Py_ssize_t res = PyObject_Length(obj); + Py_DECREF(obj); + return res; } WRAP_BINARY(proxy_getitem, PyObject_GetItem) @@ -624,16 +624,16 @@ proxy_setitem(PyWeakReference *proxy, PyObject *key, PyObject *value) if (!proxy_checkref(proxy)) return -1; - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - Py_INCREF(obj); - int res; - if (value == NULL) { - res = PyObject_DelItem(obj, key); - } else { - res = PyObject_SetItem(obj, key, value); - } - Py_DECREF(obj); - return res; + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + Py_INCREF(obj); + int res; + if (value == NULL) { + res = PyObject_DelItem(obj, key); + } else { + res = PyObject_SetItem(obj, key, value); + } + Py_DECREF(obj); + return res; } /* iterator slots */ @@ -643,11 +643,11 @@ proxy_iter(PyWeakReference *proxy) { if (!proxy_checkref(proxy)) return NULL; - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - Py_INCREF(obj); - PyObject* res = PyObject_GetIter(obj); - Py_DECREF(obj); - return res; + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + Py_INCREF(obj); + PyObject* res = PyObject_GetIter(obj); + Py_DECREF(obj); + return res; } static PyObject * @@ -655,28 +655,28 @@ proxy_iternext(PyWeakReference *proxy) { if (!proxy_checkref(proxy)) return NULL; - - PyObject *obj = PyWeakref_GET_OBJECT(proxy); - if (!PyIter_Check(obj)) { - PyErr_Format(PyExc_TypeError, - "Weakref proxy referenced a non-iterator '%.200s' object", - Py_TYPE(obj)->tp_name); - return NULL; - } - Py_INCREF(obj); - PyObject* res = PyIter_Next(obj); - Py_DECREF(obj); - return res; + + PyObject *obj = PyWeakref_GET_OBJECT(proxy); + if (!PyIter_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "Weakref proxy referenced a non-iterator '%.200s' object", + Py_TYPE(obj)->tp_name); + return NULL; + } + Py_INCREF(obj); + PyObject* res = PyIter_Next(obj); + Py_DECREF(obj); + return res; } WRAP_METHOD(proxy_bytes, __bytes__) -WRAP_METHOD(proxy_reversed, __reversed__) +WRAP_METHOD(proxy_reversed, __reversed__) static PyMethodDef proxy_methods[] = { - {"__bytes__", proxy_bytes, METH_NOARGS}, - {"__reversed__", proxy_reversed, METH_NOARGS}, + {"__bytes__", proxy_bytes, METH_NOARGS}, + {"__reversed__", proxy_reversed, METH_NOARGS}, {NULL, NULL} }; @@ -716,8 +716,8 @@ static PyNumberMethods proxy_as_number = { proxy_ifloor_div, /*nb_inplace_floor_divide*/ proxy_itrue_div, /*nb_inplace_true_divide*/ proxy_index, /*nb_index*/ - proxy_matmul, /*nb_matrix_multiply*/ - proxy_imatmul, /*nb_inplace_matrix_multiply*/ + proxy_matmul, /*nb_matrix_multiply*/ + proxy_imatmul, /*nb_inplace_matrix_multiply*/ }; static PySequenceMethods proxy_as_sequence = { @@ -746,16 +746,16 @@ _PyWeakref_ProxyType = { 0, /* methods */ (destructor)proxy_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)proxy_repr, /* tp_repr */ &proxy_as_number, /* tp_as_number */ &proxy_as_sequence, /* tp_as_sequence */ &proxy_as_mapping, /* tp_as_mapping */ -// Notice that tp_hash is intentionally omitted as proxies are "mutable" (when the reference dies). - 0, /* tp_hash */ +// Notice that tp_hash is intentionally omitted as proxies are "mutable" (when the reference dies). + 0, /* tp_hash */ 0, /* tp_call */ proxy_str, /* tp_str */ proxy_getattr, /* tp_getattro */ @@ -781,10 +781,10 @@ _PyWeakref_CallableProxyType = { 0, /* methods */ (destructor)proxy_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (unaryfunc)proxy_repr, /* tp_repr */ &proxy_as_number, /* tp_as_number */ &proxy_as_sequence, /* tp_as_sequence */ @@ -898,12 +898,12 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback) if (result != NULL) { PyWeakReference *prev; - if (PyCallable_Check(ob)) { - Py_SET_TYPE(result, &_PyWeakref_CallableProxyType); - } - else { - Py_SET_TYPE(result, &_PyWeakref_ProxyType); - } + if (PyCallable_Check(ob)) { + Py_SET_TYPE(result, &_PyWeakref_CallableProxyType); + } + else { + Py_SET_TYPE(result, &_PyWeakref_ProxyType); + } get_basic_refs(*list, &ref, &proxy); if (callback == NULL) { if (proxy != NULL) { @@ -912,8 +912,8 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback) to avoid violating the invariants of the list of weakrefs for ob. */ Py_DECREF(result); - result = proxy; - Py_INCREF(result); + result = proxy; + Py_INCREF(result); goto skip_insert; } prev = ref; @@ -949,7 +949,7 @@ PyWeakref_GetObject(PyObject *ref) static void handle_callback(PyWeakReference *ref, PyObject *callback) { - PyObject *cbresult = PyObject_CallOneArg(callback, (PyObject *)ref); + PyObject *cbresult = PyObject_CallOneArg(callback, (PyObject *)ref); if (cbresult == NULL) PyErr_WriteUnraisable(callback); @@ -970,8 +970,8 @@ PyObject_ClearWeakRefs(PyObject *object) if (object == NULL || !PyType_SUPPORTS_WEAKREFS(Py_TYPE(object)) - || Py_REFCNT(object) != 0) - { + || Py_REFCNT(object) != 0) + { PyErr_BadInternalCall(); return; } @@ -994,9 +994,9 @@ PyObject_ClearWeakRefs(PyObject *object) current->wr_callback = NULL; clear_weakref(current); if (callback != NULL) { - if (Py_REFCNT((PyObject *)current) > 0) { + if (Py_REFCNT((PyObject *)current) > 0) { handle_callback(current, callback); - } + } Py_DECREF(callback); } } @@ -1013,7 +1013,7 @@ PyObject_ClearWeakRefs(PyObject *object) for (i = 0; i < count; ++i) { PyWeakReference *next = current->wr_next; - if (Py_REFCNT((PyObject *)current) > 0) { + if (Py_REFCNT((PyObject *)current) > 0) { Py_INCREF(current); PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current); PyTuple_SET_ITEM(tuple, i * 2 + 1, current->wr_callback); |