mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-114258: Use Argument Clinic for __setitem__ (GH-160048)
This commit is contained in:
1 parent
8f3243dc33
commit
796b26b360
16 files changed
+289
-132
No files matched your search
@@ -1499,8 +1499,19 @@ deque_remove_impl(dequeobject *deque, PyObject *value)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_collections.deque.__setitem__ as deque_ass_item
|
||||
|
||||
deque: dequeobject
|
||||
i: Py_ssize_t
|
||||
v: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
deque_ass_item_lock_held(dequeobject *deque, Py_ssize_t i, PyObject *v)
|
||||
deque_ass_item_impl(dequeobject *deque, Py_ssize_t i, PyObject *v)
|
||||
/*[clinic end generated code: output=28739a830dc69ab1 input=b767e1a4972fa537]*/
|
||||
{
|
||||
block *b;
|
||||
Py_ssize_t n, len=Py_SIZE(deque), halflen=(len+1)>>1, index=i;
|
||||
@@ -1531,17 +1542,6 @@ deque_ass_item_lock_held(dequeobject *deque, Py_ssize_t i, PyObject *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
deque_ass_item(PyObject *self, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
dequeobject *deque = dequeobject_CAST(self);
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(deque);
|
||||
result = deque_ass_item_lock_held(deque, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
deque_dealloc(PyObject *self)
|
||||
{
|
||||
|
||||
+47
-38
@@ -4983,8 +4983,11 @@ static PyType_Spec pycunion_spec = {
|
||||
/*
|
||||
PyCArray_Type
|
||||
*/
|
||||
static int Array_ass_item_lock_held(PyObject *, Py_ssize_t, PyObject *);
|
||||
static int Array_ass_subscript(PyObject *, PyObject *, PyObject *);
|
||||
|
||||
/*[clinic input]
|
||||
class _ctypes.Array "PyObject *" "clinic_state()->PyCArray_Type"
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b2d780e2e2dc6e8a]*/
|
||||
|
||||
static int
|
||||
Array_init(PyObject *self, PyObject *args, PyObject *kw)
|
||||
@@ -5008,7 +5011,7 @@ Array_init(PyObject *self, PyObject *args, PyObject *kw)
|
||||
for (i = 0; result >= 0 && i < n; ++i) {
|
||||
PyObject *v = PyTuple_GET_ITEM(args, i);
|
||||
assert(v != NULL);
|
||||
result = Array_ass_item_lock_held(self, i, v);
|
||||
result = Array_ass_item_impl(self, i, v);
|
||||
}
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
@@ -5192,8 +5195,19 @@ Array_subscript(PyObject *myself, PyObject *item)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_ctypes.Array.__setitem__ as Array_ass_item
|
||||
|
||||
myself: self
|
||||
index: Py_ssize_t
|
||||
value: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
Array_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
Array_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
/*[clinic end generated code: output=8fb1fd51b5b45da8 input=8b6ddb53d6377b96]*/
|
||||
{
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(myself);
|
||||
|
||||
@@ -5227,19 +5241,19 @@ Array_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
index, size, ptr);
|
||||
}
|
||||
|
||||
static int
|
||||
Array_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(myself);
|
||||
result = Array_ass_item_lock_held(myself, index, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_ctypes.Array.__setitem__ as Array_ass_subscript
|
||||
|
||||
myself: self
|
||||
item: object
|
||||
value: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
Array_ass_subscript_lock_held(PyObject *myself, PyObject *item, PyObject *value)
|
||||
Array_ass_subscript_impl(PyObject *myself, PyObject *item, PyObject *value)
|
||||
/*[clinic end generated code: output=cb9a138e4e40c5ac input=4b7aedebbb357853]*/
|
||||
{
|
||||
CDataObject *self = _CDataObject_CAST(myself);
|
||||
|
||||
@@ -5256,7 +5270,7 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject *item, PyObject *value)
|
||||
return -1;
|
||||
if (i < 0)
|
||||
i += self->b_length;
|
||||
return Array_ass_item_lock_held(myself, i, value);
|
||||
return Array_ass_item_impl(myself, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelen, otherlen, i;
|
||||
@@ -5281,7 +5295,7 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject *item, PyObject *value)
|
||||
int result;
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
result = Array_ass_item_lock_held(myself, cur, item);
|
||||
result = Array_ass_item_impl(myself, cur, item);
|
||||
Py_DECREF(item);
|
||||
if (result == -1)
|
||||
return -1;
|
||||
@@ -5295,17 +5309,6 @@ Array_ass_subscript_lock_held(PyObject *myself, PyObject *item, PyObject *value)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(myself);
|
||||
result = Array_ass_subscript_lock_held(myself, item, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static Py_ssize_t
|
||||
Array_length(PyObject *myself)
|
||||
{
|
||||
@@ -5624,8 +5627,24 @@ Pointer_item(PyObject *self, Py_ssize_t index)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
class _ctypes._Pointer "PyObject *" "clinic_state()->PyCPointer_Type"
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=452695db70aa7c3e]*/
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_ctypes._Pointer.__setitem__ as Pointer_ass_item
|
||||
|
||||
myself: self
|
||||
index: Py_ssize_t
|
||||
value: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
Pointer_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
Pointer_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
/*[clinic end generated code: output=4503430bd55b6c69 input=344ad19b3094558c]*/
|
||||
{
|
||||
CDataObject *self = _CDataObject_CAST(myself);
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
|
||||
@@ -5670,16 +5689,6 @@ Pointer_ass_item_lock_held(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
index, size, ((char *)deref + offset));
|
||||
}
|
||||
|
||||
static int
|
||||
Pointer_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
|
||||
{
|
||||
int res;
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
res = Pointer_ass_item_lock_held(self, index, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
Pointer_get_contents_lock_held(PyObject *self, void *closure)
|
||||
{
|
||||
|
||||
Generated
+46
-1
@@ -746,6 +746,36 @@ _ctypes_CFuncPtr_argtypes_get(PyObject *self, void *Py_UNUSED(context))
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
Array_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value);
|
||||
|
||||
static int
|
||||
Array_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(myself);
|
||||
return_value = Array_ass_item_impl(myself, index, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
Array_ass_subscript_impl(PyObject *myself, PyObject *item, PyObject *value);
|
||||
|
||||
static int
|
||||
Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(myself);
|
||||
return_value = Array_ass_subscript_impl(myself, item, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
_ctypes_Simple_value_set_impl(CDataObject *self, PyObject *value);
|
||||
|
||||
@@ -804,6 +834,21 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py
|
||||
}
|
||||
return Simple_from_outparm_impl(self, cls);
|
||||
}
|
||||
|
||||
static int
|
||||
Pointer_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value);
|
||||
|
||||
static int
|
||||
Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(myself);
|
||||
return_value = Pointer_ass_item_impl(myself, index, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
#define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, NULL},
|
||||
|
||||
#define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, (setter)_ctypes_PyCArrayType_Type_raw_set, NULL},
|
||||
@@ -818,4 +863,4 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py
|
||||
|
||||
#define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL},
|
||||
|
||||
/*[clinic end generated code: output=fdf9a3519e34b6f4 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=f01123efc29f8ae0 input=a9049054013a1b77]*/
|
||||
+12
-12
@@ -224,12 +224,22 @@ dbm_subscript(PyObject *self, PyObject *key)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_dbm.dbm.__setitem__ as dbm_ass_sub
|
||||
|
||||
v: object
|
||||
w: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
dbm_ass_sub_lock_held(PyObject *self, PyObject *v, PyObject *w)
|
||||
dbm_ass_sub_impl(dbmobject *self, PyObject *v, PyObject *w)
|
||||
/*[clinic end generated code: output=33e861810d1fd44a input=4f10cc93a02142ee]*/
|
||||
{
|
||||
datum krec, drec;
|
||||
Py_ssize_t tmp_size;
|
||||
dbmobject *dp = dbmobject_CAST(self);
|
||||
dbmobject *dp = self;
|
||||
|
||||
if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
@@ -279,16 +289,6 @@ dbm_ass_sub_lock_held(PyObject *self, PyObject *v, PyObject *w)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
result = dbm_ass_sub_lock_held(self, v, w);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_dbm.dbm.close
|
||||
|
||||
+12
-12
@@ -310,12 +310,22 @@ _gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, PyObject *default_value)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
_gdbm.gdbm.__setitem__ as gdbm_ass_sub
|
||||
|
||||
v: object
|
||||
w: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
gdbm_ass_sub_lock_held(PyObject *op, PyObject *v, PyObject *w)
|
||||
gdbm_ass_sub_impl(gdbmobject *self, PyObject *v, PyObject *w)
|
||||
/*[clinic end generated code: output=b46cce6ffa309dab input=fbd980f3b49e2f91]*/
|
||||
{
|
||||
datum krec, drec;
|
||||
const char *failmsg = "gdbm mappings have bytes or string indices only";
|
||||
gdbmobject *dp = _gdbmobject_CAST(op);
|
||||
gdbmobject *dp = self;
|
||||
_gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp));
|
||||
|
||||
if (!parse_datum(v, &krec, failmsg)) {
|
||||
@@ -356,16 +366,6 @@ gdbm_ass_sub_lock_held(PyObject *op, PyObject *v, PyObject *w)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
gdbm_ass_sub(PyObject *op, PyObject *v, PyObject *w)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(op);
|
||||
result = gdbm_ass_sub_lock_held(op, v, w);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@permit_long_summary
|
||||
@critical_section
|
||||
|
||||
Generated
+16
-1
@@ -434,6 +434,21 @@ deque_remove(PyObject *deque, PyObject *value)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
deque_ass_item_impl(dequeobject *deque, Py_ssize_t i, PyObject *v);
|
||||
|
||||
static int
|
||||
deque_ass_item(PyObject *deque, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(deque);
|
||||
return_value = deque_ass_item_impl((dequeobject *)deque, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(deque___reduce____doc__,
|
||||
"__reduce__($self, /)\n"
|
||||
"--\n"
|
||||
@@ -632,4 +647,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=f5a388add99d3d15 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=1bdec9485a9d40fb input=a9049054013a1b77]*/
|
||||
Generated
+16
-1
@@ -21,6 +21,21 @@ dbm_length(PyObject *self)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
dbm_ass_sub_impl(dbmobject *self, PyObject *v, PyObject *w);
|
||||
|
||||
static int
|
||||
dbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = dbm_ass_sub_impl((dbmobject *)self, v, w);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_dbm_dbm_close__doc__,
|
||||
"close($self, /)\n"
|
||||
"--\n"
|
||||
@@ -264,4 +279,4 @@ skip_optional:
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=7ae22ba4a7aeffa2 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=da6b5d201f8d3853 input=a9049054013a1b77]*/
|
||||
Generated
+16
-1
@@ -55,6 +55,21 @@ exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
gdbm_ass_sub_impl(gdbmobject *self, PyObject *v, PyObject *w);
|
||||
|
||||
static int
|
||||
gdbm_ass_sub(PyObject *self, PyObject *v, PyObject *w)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = gdbm_ass_sub_impl((gdbmobject *)self, v, w);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_gdbm_gdbm_setdefault__doc__,
|
||||
"setdefault($self, key, default=None, /)\n"
|
||||
"--\n"
|
||||
@@ -416,4 +431,4 @@ skip_optional:
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=36e1ed1cc3523aeb input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=6f91f162b0f822d3 input=a9049054013a1b77]*/
|
||||
Generated
+31
-1
@@ -877,6 +877,36 @@ mmap_length(PyObject *self)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_ass_item_impl(mmap_object *self, Py_ssize_t i, PyObject *v);
|
||||
|
||||
static int
|
||||
mmap_ass_item(PyObject *self, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = mmap_ass_item_impl((mmap_object *)self, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_ass_subscript_impl(mmap_object *self, PyObject *item, PyObject *value);
|
||||
|
||||
static int
|
||||
mmap_ass_subscript(PyObject *self, PyObject *item, PyObject *value)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = mmap_ass_subscript_impl((mmap_object *)self, item, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
#ifndef MMAP_MMAP_RESIZE_METHODDEF
|
||||
#define MMAP_MMAP_RESIZE_METHODDEF
|
||||
#endif /* !defined(MMAP_MMAP_RESIZE_METHODDEF) */
|
||||
@@ -892,4 +922,4 @@ mmap_length(PyObject *self)
|
||||
#ifndef MMAP_MMAP_MADVISE_METHODDEF
|
||||
#define MMAP_MMAP_MADVISE_METHODDEF
|
||||
#endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */
|
||||
/*[clinic end generated code: output=e52bf0f914c90a96 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=eb09e5d722968cef input=a9049054013a1b77]*/
|
||||
+21
-24
@@ -1599,11 +1599,20 @@ mmap_subscript(PyObject *op, PyObject *item)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
mmap.mmap.__setitem__ as mmap_ass_item
|
||||
|
||||
i: Py_ssize_t
|
||||
v: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
mmap_ass_item_lock_held(PyObject *op, Py_ssize_t i, PyObject *v)
|
||||
mmap_ass_item_impl(mmap_object *self, Py_ssize_t i, PyObject *v)
|
||||
/*[clinic end generated code: output=398d9d502e560f58 input=5fe8a60de3a6c39e]*/
|
||||
{
|
||||
const char *buf;
|
||||
mmap_object *self = mmap_object_CAST(op);
|
||||
|
||||
CHECK_VALID(-1);
|
||||
if (i < 0 || i >= self->size) {
|
||||
@@ -1630,21 +1639,19 @@ mmap_ass_item_lock_held(PyObject *op, Py_ssize_t i, PyObject *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_ass_item(PyObject *op, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(op);
|
||||
result = mmap_ass_item_lock_held(op, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
mmap.mmap.__setitem__ as mmap_ass_subscript
|
||||
|
||||
item: object
|
||||
value: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
mmap_ass_subscript_lock_held(PyObject *op, PyObject *item, PyObject *value)
|
||||
mmap_ass_subscript_impl(mmap_object *self, PyObject *item, PyObject *value)
|
||||
/*[clinic end generated code: output=e346a1c7f35800d4 input=4827c15e710601f0]*/
|
||||
{
|
||||
mmap_object *self = mmap_object_CAST(op);
|
||||
|
||||
if (!is_writable(self))
|
||||
return -1;
|
||||
|
||||
@@ -1743,16 +1750,6 @@ mmap_ass_subscript_lock_held(PyObject *op, PyObject *item, PyObject *value)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_ass_subscript(PyObject *op, PyObject *item, PyObject *value)
|
||||
{
|
||||
int result;
|
||||
Py_BEGIN_CRITICAL_SECTION(op);
|
||||
result = mmap_ass_subscript_lock_held(op, item, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict);
|
||||
|
||||
|
||||
+13
-13
@@ -743,11 +743,21 @@ bytearray_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi,
|
||||
return res;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
bytearray.__setitem__ as bytearray_setitem
|
||||
|
||||
i: Py_ssize_t
|
||||
value: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
bytearray_setitem_lock_held(PyObject *op, Py_ssize_t i, PyObject *value)
|
||||
bytearray_setitem_impl(PyByteArrayObject *self, Py_ssize_t i,
|
||||
PyObject *value)
|
||||
/*[clinic end generated code: output=c8e973819dd58098 input=460a77c3d8b7268f]*/
|
||||
{
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
|
||||
PyByteArrayObject *self = _PyByteArray_CAST(op);
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
|
||||
|
||||
// GH-91153: We need to do this *before* the size check, in case value has a
|
||||
// nasty __index__ method that changes the size of the bytearray:
|
||||
@@ -774,16 +784,6 @@ bytearray_setitem_lock_held(PyObject *op, Py_ssize_t i, PyObject *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bytearray_setitem(PyObject *op, Py_ssize_t i, PyObject *value)
|
||||
{
|
||||
int ret;
|
||||
Py_BEGIN_CRITICAL_SECTION(op);
|
||||
ret = bytearray_setitem_lock_held(op, i, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *values)
|
||||
{
|
||||
|
||||
Generated
+17
-1
@@ -11,6 +11,22 @@ preserve
|
||||
#include "pycore_runtime.h" // _Py_SINGLETON()
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL()
|
||||
|
||||
static int
|
||||
bytearray_setitem_impl(PyByteArrayObject *self, Py_ssize_t i,
|
||||
PyObject *value);
|
||||
|
||||
static int
|
||||
bytearray_setitem(PyObject *self, Py_ssize_t i, PyObject *value)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = bytearray_setitem_impl((PyByteArrayObject *)self, i, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static int
|
||||
bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
|
||||
const char *encoding, const char *errors);
|
||||
@@ -1946,4 +1962,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return bytearray_sizeof_impl((PyByteArrayObject *)self);
|
||||
}
|
||||
/*[clinic end generated code: output=b67d1f1e84c7ed0f input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=a16aaa01f1fcf5a6 input=a9049054013a1b77]*/
|
||||
Generated
+16
-1
@@ -10,6 +10,21 @@ preserve
|
||||
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
|
||||
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
|
||||
|
||||
static int
|
||||
list_ass_item_impl(PyListObject *a, Py_ssize_t i, PyObject *v);
|
||||
|
||||
static int
|
||||
list_ass_item(PyObject *a, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
int return_value = -1;
|
||||
|
||||
Py_BEGIN_CRITICAL_SECTION(a);
|
||||
return_value = list_ass_item_impl((PyListObject *)a, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(list_insert__doc__,
|
||||
"insert($self, index, object, /)\n"
|
||||
"--\n"
|
||||
@@ -468,4 +483,4 @@ list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return list___reversed___impl((PyListObject *)self);
|
||||
}
|
||||
/*[clinic end generated code: output=06c21b0bffbe8d84 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=ef8a058598f58f7e input=a9049054013a1b77]*/
|
||||
+13
-13
@@ -1189,8 +1189,19 @@ list_inplace_repeat(PyObject *_self, Py_ssize_t n)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
list.__setitem__ as list_ass_item
|
||||
|
||||
a: self(type="PyListObject *")
|
||||
i: Py_ssize_t
|
||||
v: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
list_ass_item_lock_held(PyListObject *a, Py_ssize_t i, PyObject *v)
|
||||
list_ass_item_impl(PyListObject *a, Py_ssize_t i, PyObject *v)
|
||||
/*[clinic end generated code: output=51d8b4f1790b67db input=0ba2adeaf8b3d5a0]*/
|
||||
{
|
||||
if (!valid_index(i, Py_SIZE(a))) {
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
@@ -1212,17 +1223,6 @@ list_ass_item_lock_held(PyListObject *a, Py_ssize_t i, PyObject *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
list_ass_item(PyObject *aa, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
int ret;
|
||||
PyListObject *a = (PyListObject *)aa;
|
||||
Py_BEGIN_CRITICAL_SECTION(a);
|
||||
ret = list_ass_item_lock_held(a, i, v);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
list.insert
|
||||
@@ -3796,7 +3796,7 @@ list_ass_subscript_lock_held(PyObject *_self, PyObject *item, PyObject *value)
|
||||
return -1;
|
||||
if (i < 0)
|
||||
i += PyList_GET_SIZE(self);
|
||||
return list_ass_item_lock_held(self, i, value);
|
||||
return list_ass_item_impl(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step;
|
||||
|
||||
@@ -98,7 +98,6 @@ __rsub__
|
||||
__rtruediv__
|
||||
__rxor__
|
||||
__setattr__
|
||||
__setitem__
|
||||
__str__
|
||||
__sub__
|
||||
__truediv__
|
||||
|
||||
@@ -40,4 +40,5 @@ class SlotSpec:
|
||||
SLOTS: Final[dict[str, SlotSpec]] = {
|
||||
'__next__': SlotSpec(return_converter='object'),
|
||||
'__len__': SlotSpec(return_converter='Py_ssize_t'),
|
||||
'__setitem__': SlotSpec(return_converter='int'),
|
||||
}
|
||||
Reference in new issue
Block a user