gh-111178: Fix function signatures in setobject.c (#124888)

This commit is contained in:
Victor Stinner 2024-10-02 16:03:23 +02:00 committed by GitHub
parent 1d4e3e0585
commit 9132148edf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 90 additions and 68 deletions

View File

@ -404,8 +404,9 @@ set_empty_to_minsize(PySetObject *so)
}
static int
set_clear_internal(PySetObject *so)
set_clear_internal(PyObject *self)
{
PySetObject *so = _PySet_CAST(self);
setentry *entry;
setentry *table = so->table;
Py_ssize_t fill = so->fill;
@ -490,8 +491,9 @@ set_next(PySetObject *so, Py_ssize_t *pos_ptr, setentry **entry_ptr)
}
static void
set_dealloc(PySetObject *so)
set_dealloc(PyObject *self)
{
PySetObject *so = _PySet_CAST(self);
setentry *entry;
Py_ssize_t used = so->used;
@ -559,8 +561,9 @@ done:
}
static PyObject *
set_repr(PySetObject *so)
set_repr(PyObject *self)
{
PySetObject *so = _PySet_CAST(self);
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(so);
result = set_repr_lock_held(so);
@ -569,8 +572,9 @@ set_repr(PySetObject *so)
}
static Py_ssize_t
set_len(PySetObject *so)
set_len(PyObject *self)
{
PySetObject *so = _PySet_CAST(self);
return FT_ATOMIC_LOAD_SSIZE_RELAXED(so->used);
}
@ -584,11 +588,10 @@ set_merge_lock_held(PySetObject *so, PyObject *otherset)
setentry *other_entry;
assert (PyAnySet_Check(so));
assert (PyAnySet_Check(otherset));
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(so);
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(otherset);
other = (PySetObject*)otherset;
other = _PySet_CAST(otherset);
if (other == so || other->used == 0)
/* a.update(a) or a.update(set()); nothing to do */
return 0;
@ -684,8 +687,9 @@ set_pop_impl(PySetObject *so)
}
static int
set_traverse(PySetObject *so, visitproc visit, void *arg)
set_traverse(PyObject *self, visitproc visit, void *arg)
{
PySetObject *so = _PySet_CAST(self);
Py_ssize_t pos = 0;
setentry *entry;
@ -718,8 +722,7 @@ _shuffle_bits(Py_uhash_t h)
static Py_hash_t
frozenset_hash_impl(PyObject *self)
{
assert(PyAnySet_Check(self));
PySetObject *so = (PySetObject *)self;
PySetObject *so = _PySet_CAST(self);
Py_uhash_t hash = 0;
setentry *entry;
@ -761,7 +764,7 @@ frozenset_hash_impl(PyObject *self)
static Py_hash_t
frozenset_hash(PyObject *self)
{
PySetObject *so = (PySetObject *)self;
PySetObject *so = _PySet_CAST(self);
Py_uhash_t hash;
if (so->hash != -1) {
@ -784,8 +787,9 @@ typedef struct {
} setiterobject;
static void
setiter_dealloc(setiterobject *si)
setiter_dealloc(PyObject *self)
{
setiterobject *si = (setiterobject*)self;
/* bpo-31095: UnTrack is needed before calling any callbacks */
_PyObject_GC_UNTRACK(si);
Py_XDECREF(si->si_set);
@ -793,8 +797,9 @@ setiter_dealloc(setiterobject *si)
}
static int
setiter_traverse(setiterobject *si, visitproc visit, void *arg)
setiter_traverse(PyObject *self, visitproc visit, void *arg)
{
setiterobject *si = (setiterobject*)self;
Py_VISIT(si->si_set);
return 0;
}
@ -810,8 +815,6 @@ setiter_len(setiterobject *si, PyObject *Py_UNUSED(ignored))
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
static PyObject *setiter_iternext(setiterobject *si);
static PyObject *
setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored))
{
@ -836,8 +839,9 @@ static PyMethodDef setiter_methods[] = {
{NULL, NULL} /* sentinel */
};
static PyObject *setiter_iternext(setiterobject *si)
static PyObject *setiter_iternext(PyObject *self)
{
setiterobject *si = (setiterobject*)self;
PyObject *key = NULL;
Py_ssize_t i, mask;
setentry *entry;
@ -884,7 +888,7 @@ PyTypeObject PySetIter_Type = {
sizeof(setiterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)setiter_dealloc, /* tp_dealloc */
setiter_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
@ -901,18 +905,18 @@ PyTypeObject PySetIter_Type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
(traverseproc)setiter_traverse, /* tp_traverse */
setiter_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)setiter_iternext, /* tp_iternext */
setiter_iternext, /* tp_iternext */
setiter_methods, /* tp_methods */
0,
};
static PyObject *
set_iter(PySetObject *so)
set_iter(PyObject *so)
{
Py_ssize_t size = set_len(so);
setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type);
@ -1270,7 +1274,7 @@ static PyObject *
set_clear_impl(PySetObject *so)
/*[clinic end generated code: output=4e71d5a83904161a input=c6f831b366111950]*/
{
set_clear_internal(so);
set_clear_internal((PyObject*)so);
Py_RETURN_NONE;
}
@ -1307,12 +1311,13 @@ set_union_impl(PySetObject *so, PyObject *args)
}
static PyObject *
set_or(PySetObject *so, PyObject *other)
set_or(PyObject *self, PyObject *other)
{
PySetObject *result;
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
result = (PySetObject *)set_copy(so, NULL);
if (result == NULL) {
@ -1329,10 +1334,11 @@ set_or(PySetObject *so, PyObject *other)
}
static PyObject *
set_ior(PySetObject *so, PyObject *other)
set_ior(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
if (set_update_internal(so, other)) {
return NULL;
@ -1495,10 +1501,11 @@ set_intersection_update_multi_impl(PySetObject *so, PyObject *args)
}
static PyObject *
set_and(PySetObject *so, PyObject *other)
set_and(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
PyObject *rv;
Py_BEGIN_CRITICAL_SECTION2(so, other);
@ -1509,12 +1516,13 @@ set_and(PySetObject *so, PyObject *other)
}
static PyObject *
set_iand(PySetObject *so, PyObject *other)
set_iand(PyObject *self, PyObject *other)
{
PyObject *result;
if (!PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
Py_BEGIN_CRITICAL_SECTION2(so, other);
result = set_intersection_update(so, other);
@ -1603,7 +1611,7 @@ set_difference_update_internal(PySetObject *so, PyObject *other)
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(other);
if ((PyObject *)so == other)
return set_clear_internal(so);
return set_clear_internal((PyObject*)so);
if (PyAnySet_Check(other)) {
setentry *entry;
@ -1815,10 +1823,11 @@ set_difference_multi_impl(PySetObject *so, PyObject *args)
}
static PyObject *
set_sub(PySetObject *so, PyObject *other)
set_sub(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
PyObject *rv;
Py_BEGIN_CRITICAL_SECTION2(so, other);
@ -1828,10 +1837,11 @@ set_sub(PySetObject *so, PyObject *other)
}
static PyObject *
set_isub(PySetObject *so, PyObject *other)
set_isub(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
int rv;
Py_BEGIN_CRITICAL_SECTION2(so, other);
@ -1973,20 +1983,23 @@ set_symmetric_difference_impl(PySetObject *so, PyObject *other)
}
static PyObject *
set_xor(PySetObject *so, PyObject *other)
set_xor(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
return set_symmetric_difference(so, other);
}
static PyObject *
set_ixor(PySetObject *so, PyObject *other)
set_ixor(PyObject *self, PyObject *other)
{
PyObject *result;
if (!PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
PySetObject *so = _PySet_CAST(self);
result = set_symmetric_difference_update(so, other);
if (result == NULL)
return NULL;
@ -2081,8 +2094,9 @@ set_issuperset_impl(PySetObject *so, PyObject *other)
}
static PyObject *
set_richcompare(PySetObject *v, PyObject *w, int op)
set_richcompare(PyObject *self, PyObject *w, int op)
{
PySetObject *v = _PySet_CAST(self);
PyObject *r1;
int r2;
@ -2099,7 +2113,7 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
Py_RETURN_FALSE;
return set_issubset(v, w);
case Py_NE:
r1 = set_richcompare(v, w, Py_EQ);
r1 = set_richcompare((PyObject*)v, w, Py_EQ);
if (r1 == NULL)
return NULL;
r2 = PyObject_IsTrue(r1);
@ -2173,6 +2187,13 @@ _PySet_Contains(PySetObject *so, PyObject *key)
return rv;
}
static int
set_contains(PyObject *self, PyObject *key)
{
PySetObject *so = _PySet_CAST(self);
return _PySet_Contains(so, key);
}
/*[clinic input]
@critical_section
@coexist
@ -2321,8 +2342,9 @@ set___sizeof___impl(PySetObject *so)
}
static int
set_init(PySetObject *self, PyObject *args, PyObject *kwds)
set_init(PyObject *so, PyObject *args, PyObject *kwds)
{
PySetObject *self = _PySet_CAST(so);
PyObject *iterable = NULL;
if (!_PyArg_NoKeywords("set", kwds))
@ -2339,7 +2361,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
}
Py_BEGIN_CRITICAL_SECTION(self);
if (self->fill)
set_clear_internal(self);
set_clear_internal((PyObject*)self);
self->hash = -1;
Py_END_CRITICAL_SECTION();
@ -2371,14 +2393,14 @@ set_vectorcall(PyObject *type, PyObject * const*args,
}
static PySequenceMethods set_as_sequence = {
(lenfunc)set_len, /* sq_length */
set_len, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
0, /* sq_item */
0, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
(objobjproc)_PySet_Contains, /* sq_contains */
set_contains, /* sq_contains */
};
/* set object ********************************************************/
@ -2410,7 +2432,7 @@ static PyMethodDef set_methods[] = {
static PyNumberMethods set_as_number = {
0, /*nb_add*/
(binaryfunc)set_sub, /*nb_subtract*/
set_sub, /*nb_subtract*/
0, /*nb_multiply*/
0, /*nb_remainder*/
0, /*nb_divmod*/
@ -2422,22 +2444,22 @@ static PyNumberMethods set_as_number = {
0, /*nb_invert*/
0, /*nb_lshift*/
0, /*nb_rshift*/
(binaryfunc)set_and, /*nb_and*/
(binaryfunc)set_xor, /*nb_xor*/
(binaryfunc)set_or, /*nb_or*/
set_and, /*nb_and*/
set_xor, /*nb_xor*/
set_or, /*nb_or*/
0, /*nb_int*/
0, /*nb_reserved*/
0, /*nb_float*/
0, /*nb_inplace_add*/
(binaryfunc)set_isub, /*nb_inplace_subtract*/
set_isub, /*nb_inplace_subtract*/
0, /*nb_inplace_multiply*/
0, /*nb_inplace_remainder*/
0, /*nb_inplace_power*/
0, /*nb_inplace_lshift*/
0, /*nb_inplace_rshift*/
(binaryfunc)set_iand, /*nb_inplace_and*/
(binaryfunc)set_ixor, /*nb_inplace_xor*/
(binaryfunc)set_ior, /*nb_inplace_or*/
set_iand, /*nb_inplace_and*/
set_ixor, /*nb_inplace_xor*/
set_ior, /*nb_inplace_or*/
};
PyDoc_STRVAR(set_doc,
@ -2452,12 +2474,12 @@ PyTypeObject PySet_Type = {
sizeof(PySetObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)set_dealloc, /* tp_dealloc */
set_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
(reprfunc)set_repr, /* tp_repr */
set_repr, /* tp_repr */
&set_as_number, /* tp_as_number */
&set_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
@ -2469,13 +2491,13 @@ PyTypeObject PySet_Type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE |
_Py_TPFLAGS_MATCH_SELF, /* tp_flags */
_Py_TPFLAGS_MATCH_SELF, /* tp_flags */
set_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
(inquiry)set_clear_internal, /* tp_clear */
(richcmpfunc)set_richcompare, /* tp_richcompare */
set_traverse, /* tp_traverse */
set_clear_internal, /* tp_clear */
set_richcompare, /* tp_richcompare */
offsetof(PySetObject, weakreflist), /* tp_weaklistoffset */
(getiterfunc)set_iter, /* tp_iter */
set_iter, /* tp_iter */
0, /* tp_iternext */
set_methods, /* tp_methods */
0, /* tp_members */
@ -2485,7 +2507,7 @@ PyTypeObject PySet_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)set_init, /* tp_init */
set_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
set_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
@ -2513,7 +2535,7 @@ static PyMethodDef frozenset_methods[] = {
static PyNumberMethods frozenset_as_number = {
0, /*nb_add*/
(binaryfunc)set_sub, /*nb_subtract*/
set_sub, /*nb_subtract*/
0, /*nb_multiply*/
0, /*nb_remainder*/
0, /*nb_divmod*/
@ -2525,9 +2547,9 @@ static PyNumberMethods frozenset_as_number = {
0, /*nb_invert*/
0, /*nb_lshift*/
0, /*nb_rshift*/
(binaryfunc)set_and, /*nb_and*/
(binaryfunc)set_xor, /*nb_xor*/
(binaryfunc)set_or, /*nb_or*/
set_and, /*nb_and*/
set_xor, /*nb_xor*/
set_or, /*nb_or*/
};
PyDoc_STRVAR(frozenset_doc,
@ -2542,12 +2564,12 @@ PyTypeObject PyFrozenSet_Type = {
sizeof(PySetObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)set_dealloc, /* tp_dealloc */
set_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
(reprfunc)set_repr, /* tp_repr */
set_repr, /* tp_repr */
&frozenset_as_number, /* tp_as_number */
&set_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
@ -2559,13 +2581,13 @@ PyTypeObject PyFrozenSet_Type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE |
_Py_TPFLAGS_MATCH_SELF, /* tp_flags */
_Py_TPFLAGS_MATCH_SELF, /* tp_flags */
frozenset_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
(inquiry)set_clear_internal, /* tp_clear */
(richcmpfunc)set_richcompare, /* tp_richcompare */
set_traverse, /* tp_traverse */
set_clear_internal, /* tp_clear */
set_richcompare, /* tp_richcompare */
offsetof(PySetObject, weakreflist), /* tp_weaklistoffset */
(getiterfunc)set_iter, /* tp_iter */
set_iter, /* tp_iter */
0, /* tp_iternext */
frozenset_methods, /* tp_methods */
0, /* tp_members */
@ -2604,7 +2626,7 @@ PySet_Size(PyObject *anyset)
PyErr_BadInternalCall();
return -1;
}
return set_len((PySetObject *)anyset);
return set_len(anyset);
}
int
@ -2621,7 +2643,7 @@ PySet_Clear(PyObject *set)
void
_PySet_ClearInternal(PySetObject *so)
{
(void)set_clear_internal(so);
(void)set_clear_internal((PyObject*)so);
}
int