Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/c/_cffi_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,11 @@ cdata_ass_slice(CDataObject *cd, PySliceObject *slice, PyObject *v)
cdata = cd->c_data + itemsize * bounds[0];
length = bounds[1];

if (v == NULL) {
PyErr_SetString(PyExc_TypeError,
"'del x[n]' not supported for cdata objects");
return -1;
}
if (CData_Check(v)) {
CTypeDescrObject *ctv = ((CDataObject *)v)->c_type;
if ((ctv->ct_flags & CT_ARRAY) && (ctv->ct_itemdescr == ct) &&
Expand Down
5 changes: 5 additions & 0 deletions src/c/minibuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ static PyObject *mb_subscript(MiniBufferObj *self, PyObject *item)
static int
mb_ass_subscript(MiniBufferObj* self, PyObject* item, PyObject* value)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"'del x[n]' not supported for buffer objects");
return -1;
}
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
Expand Down
8 changes: 8 additions & 0 deletions testing/cffi0/test_ffi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ def test_unpack(self):
p = ffi.new("int[]", [-123456789])
assert ffi.unpack(p, 1) == [-123456789]

def test_delitem_raises(self):
ffi = FFI()
arr = ffi.new("int[5]")
buf = ffi.buffer(arr)
for obj in (arr, buf):
pytest.raises(TypeError, obj.__delitem__, 0) # del obj[0]
pytest.raises(TypeError, obj.__delitem__, slice(1, 3)) # del obj[1:3]

def test_negative_array_size(self):
ffi = FFI()
pytest.raises(ValueError, ffi.cast, "int[-5]", 0)
Expand Down