Skip to content

Commit

Permalink
Audit and convert varlist.m
Browse files Browse the repository at this point in the history
Issue #608
  • Loading branch information
ronaldoussoren committed Jul 16, 2024
1 parent 124270b commit 6f5aa4e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pyobjc-core/Modules/objc/varlist.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
static int
varlist__setslice__(PyObject* _self, Py_ssize_t start, Py_ssize_t stop, PyObject* newval)
{
int result;
PyObjCVarList* self = (PyObjCVarList*)_self;
Py_ssize_t idx;
PyObject* seq;
Expand All @@ -187,29 +188,33 @@
stop = start;
}

seq = PySequence_Fast(newval, "New value must be a sequence");
seq = PySequence_Tuple(newval);
if (seq == NULL) {
return -1;
}

if (PySequence_Fast_GET_SIZE(seq) != stop - start) {
if (PyTuple_GET_SIZE(seq) != stop - start) {
PyErr_SetString(PyExc_ValueError,
"objc.varlist slice assignment doesn't support resizing");
Py_DECREF(seq);
return -1;
}

Py_BEGIN_CRITICAL_SECTION(self);
result = 0;
for (idx = start; idx < stop; idx++) {
PyObject* v = PySequence_Fast_GET_ITEM(seq, idx - start);
PyObject* v = PyTuple_GET_ITEM(seq, idx - start);
int r = depythonify_c_value(
self->typestr, v, ((unsigned char*)self->array) + (idx * self->itemsize));
if (r == -1) {
Py_DECREF(seq);
return -1;
result = -1;
break;
}
}
Py_END_CRITICAL_SECTION();
Py_DECREF(seq);
return 0;
return result;
}

static int
Expand All @@ -221,8 +226,12 @@
return -1;
}

return depythonify_c_value(self->typestr, value,
int result;
Py_BEGIN_CRITICAL_SECTION(self);
result = depythonify_c_value(self->typestr, value,
((unsigned char*)self->array) + (idx * self->itemsize));
Py_END_CRITICAL_SECTION();
return result;
}

static Py_ssize_t
Expand Down

0 comments on commit 6f5aa4e

Please sign in to comment.