Skip to content

Commit a76224b

Browse files
authored
Merge branch 'main' into pycfunctionobject_freelist
2 parents e86ccad + 2fcdc84 commit a76224b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible overflow when a class inherits from an absurd number of
2+
super-classes. Reported by Valery Fedorenko. Patch by Bénédikt Tran.

Modules/_threadmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,10 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
14141414
return NULL;
14151415
}
14161416

1417+
// gh-128691: Use deferred reference counting for thread-locals to avoid
1418+
// contention on the shared object.
1419+
_PyObject_SetDeferredRefcount((PyObject *)self);
1420+
14171421
self->args = Py_XNewRef(args);
14181422
self->kw = Py_XNewRef(kw);
14191423

Objects/typeobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,7 +2860,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name,
28602860
*/
28612861

28622862
static int
2863-
tail_contains(PyObject *tuple, int whence, PyObject *o)
2863+
tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o)
28642864
{
28652865
Py_ssize_t j, size;
28662866
size = PyTuple_GET_SIZE(tuple);
@@ -2923,7 +2923,7 @@ check_duplicates(PyObject *tuple)
29232923
*/
29242924

29252925
static void
2926-
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
2926+
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain)
29272927
{
29282928
Py_ssize_t i, n, off;
29292929
char buf[1000];
@@ -2978,13 +2978,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
29782978
{
29792979
int res = 0;
29802980
Py_ssize_t i, j, empty_cnt;
2981-
int *remain;
2981+
Py_ssize_t *remain;
29822982

29832983
/* remain stores an index into each sublist of to_merge.
29842984
remain[i] is the index of the next base in to_merge[i]
29852985
that is not included in acc.
29862986
*/
2987-
remain = PyMem_New(int, to_merge_size);
2987+
remain = PyMem_New(Py_ssize_t, to_merge_size);
29882988
if (remain == NULL) {
29892989
PyErr_NoMemory();
29902990
return -1;

0 commit comments

Comments
 (0)