diff options
| author | shadchin <[email protected]> | 2025-02-16 15:28:01 +0300 |
|---|---|---|
| committer | shadchin <[email protected]> | 2025-02-16 16:03:50 +0300 |
| commit | a27b6a96fdc5ca444428ddef4823d0486dcdccb9 (patch) | |
| tree | adde5c24d9ea37e1634e7972e27e682a820ab941 /contrib/tools/python3/Objects | |
| parent | 7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (diff) | |
Update Python 3 to 3.12.9
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
Diffstat (limited to 'contrib/tools/python3/Objects')
| -rw-r--r-- | contrib/tools/python3/Objects/dictobject.c | 5 | ||||
| -rw-r--r-- | contrib/tools/python3/Objects/genobject.c | 33 | ||||
| -rw-r--r-- | contrib/tools/python3/Objects/iterobject.c | 2 | ||||
| -rw-r--r-- | contrib/tools/python3/Objects/namespaceobject.c | 4 | ||||
| -rw-r--r-- | contrib/tools/python3/Objects/typeobject.c | 15 | ||||
| -rw-r--r-- | contrib/tools/python3/Objects/unicodeobject.c | 7 |
6 files changed, 35 insertions, 31 deletions
diff --git a/contrib/tools/python3/Objects/dictobject.c b/contrib/tools/python3/Objects/dictobject.c index 4e965314945..7337e290e89 100644 --- a/contrib/tools/python3/Objects/dictobject.c +++ b/contrib/tools/python3/Objects/dictobject.c @@ -458,11 +458,14 @@ estimate_log2_keysize(Py_ssize_t n) /* This immutable, empty PyDictKeysObject is used for PyDict_Clear() * (which cannot fail and thus can do no allocation). + * + * See https://github.com/python/cpython/pull/127568#discussion_r1868070614 + * for the rationale of using dk_log2_index_bytes=3 instead of 0. */ static PyDictKeysObject empty_keys_struct = { _Py_IMMORTAL_REFCNT, /* dk_refcnt */ 0, /* dk_log2_size */ - 0, /* dk_log2_index_bytes */ + 3, /* dk_log2_index_bytes */ DICT_KEYS_UNICODE, /* dk_kind */ 1, /* dk_version */ 0, /* dk_usable (immutable) */ diff --git a/contrib/tools/python3/Objects/genobject.c b/contrib/tools/python3/Objects/genobject.c index 474abe1094b..640a7d906c8 100644 --- a/contrib/tools/python3/Objects/genobject.c +++ b/contrib/tools/python3/Objects/genobject.c @@ -618,30 +618,19 @@ gen_iternext(PyGenObject *gen) int _PyGen_SetStopIterationValue(PyObject *value) { - PyObject *e; - - if (value == NULL || - (!PyTuple_Check(value) && !PyExceptionInstance_Check(value))) - { - /* Delay exception instantiation if we can */ - PyErr_SetObject(PyExc_StopIteration, value); - return 0; - } - /* Construct an exception instance manually with - * 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 - * the first element of the tuple. - * - * (See PyErr_SetObject/_PyErr_CreateException code for details.) - */ - e = PyObject_CallOneArg(PyExc_StopIteration, value); - if (e == NULL) { + assert(!PyErr_Occurred()); + // Construct an exception instance manually with PyObject_CallOneArg() + // but use PyErr_SetRaisedException() instead of PyErr_SetObject() as + // PyErr_SetObject(exc_type, value) has a fast path when 'value' + // is a tuple, where the value of the StopIteration exception would be + // set to 'value[0]' instead of 'value'. + PyObject *exc = value == NULL + ? PyObject_CallNoArgs(PyExc_StopIteration) + : PyObject_CallOneArg(PyExc_StopIteration, value); + if (exc == NULL) { return -1; } - PyErr_SetObject(PyExc_StopIteration, e); - Py_DECREF(e); + PyErr_SetRaisedException(exc /* stolen */); return 0; } diff --git a/contrib/tools/python3/Objects/iterobject.c b/contrib/tools/python3/Objects/iterobject.c index 7cb17a6ca4a..66e4490766a 100644 --- a/contrib/tools/python3/Objects/iterobject.c +++ b/contrib/tools/python3/Objects/iterobject.c @@ -382,6 +382,7 @@ anextawaitable_iternext(anextawaitableobject *obj) return result; } if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)) { + PyErr_Clear(); _PyGen_SetStopIterationValue(obj->default_value); } return NULL; @@ -405,6 +406,7 @@ anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) { * exception we replace it with a `StopIteration(default)`, as if * it was the return value of `__anext__()` coroutine. */ + PyErr_Clear(); _PyGen_SetStopIterationValue(obj->default_value); } return NULL; diff --git a/contrib/tools/python3/Objects/namespaceobject.c b/contrib/tools/python3/Objects/namespaceobject.c index 2cc4ddd3c91..7082c6fd465 100644 --- a/contrib/tools/python3/Objects/namespaceobject.c +++ b/contrib/tools/python3/Objects/namespaceobject.c @@ -121,6 +121,10 @@ namespace_repr(PyObject *ns) goto error; } + if (PyErr_Occurred()) { + goto error; + } + separator = PyUnicode_FromString(", "); if (separator == NULL) goto error; diff --git a/contrib/tools/python3/Objects/typeobject.c b/contrib/tools/python3/Objects/typeobject.c index 46d7a4b973e..012920fcf83 100644 --- a/contrib/tools/python3/Objects/typeobject.c +++ b/contrib/tools/python3/Objects/typeobject.c @@ -2319,7 +2319,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name, */ static int -tail_contains(PyObject *tuple, int whence, PyObject *o) +tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o) { Py_ssize_t j, size; size = PyTuple_GET_SIZE(tuple); @@ -2382,7 +2382,7 @@ check_duplicates(PyObject *tuple) */ static void -set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain) +set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain) { Py_ssize_t i, n, off; char buf[1000]; @@ -2437,13 +2437,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size) { int res = 0; Py_ssize_t i, j, empty_cnt; - int *remain; + Py_ssize_t *remain; /* remain stores an index into each sublist of to_merge. remain[i] is the index of the next base in to_merge[i] that is not included in acc. */ - remain = PyMem_New(int, to_merge_size); + remain = PyMem_New(Py_ssize_t, to_merge_size); if (remain == NULL) { PyErr_NoMemory(); return -1; @@ -6473,8 +6473,11 @@ object___sizeof___impl(PyObject *self) res = 0; isize = Py_TYPE(self)->tp_itemsize; - if (isize > 0) - res = Py_SIZE(self) * isize; + if (isize > 0) { + /* This assumes that ob_size is valid if tp_itemsize is not 0, + which isn't true for PyLongObject. */ + res = _PyVarObject_CAST(self)->ob_size * isize; + } res += Py_TYPE(self)->tp_basicsize; return PyLong_FromSsize_t(res); diff --git a/contrib/tools/python3/Objects/unicodeobject.c b/contrib/tools/python3/Objects/unicodeobject.c index 8fe275d4c89..8c258666403 100644 --- a/contrib/tools/python3/Objects/unicodeobject.c +++ b/contrib/tools/python3/Objects/unicodeobject.c @@ -1472,10 +1472,13 @@ _copy_characters(PyObject *to, Py_ssize_t to_start, assert(PyUnicode_Check(from)); assert(from_start + how_many <= PyUnicode_GET_LENGTH(from)); - if (how_many == 0) + assert(to == NULL || PyUnicode_Check(to)); + + if (how_many == 0) { return 0; + } - assert(PyUnicode_Check(to)); + assert(to != NULL); assert(to_start + how_many <= PyUnicode_GET_LENGTH(to)); from_kind = PyUnicode_KIND(from); |
