Commit 5bacdd4b authored by Boxiang Sun's avatar Boxiang Sun

add PySequence_SetItem and GetItem

parent c66b6f17
...@@ -1606,20 +1606,54 @@ extern "C" PyObject* PySequence_GetSlice(PyObject* s, Py_ssize_t i1, Py_ssize_t ...@@ -1606,20 +1606,54 @@ extern "C" PyObject* PySequence_GetSlice(PyObject* s, Py_ssize_t i1, Py_ssize_t
return type_error("'%.200s' object is unsliceable", s); return type_error("'%.200s' object is unsliceable", s);
} }
extern "C" int PySequence_SetItem(PyObject* o, Py_ssize_t i, PyObject* v) noexcept { extern "C" int PySequence_SetItem(PyObject* s, Py_ssize_t i, PyObject* o) noexcept {
fatalOrError(PyExc_NotImplementedError, "unimplemented"); PySequenceMethods* m;
if (s == NULL) {
null_error();
return -1;
}
m = s->cls->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
i += l;
}
}
return m->sq_ass_item(s, i, o);
}
type_error("'%.200s' object does not support item assignment", s);
return -1; return -1;
} }
extern "C" int PySequence_DelItem(PyObject* o, Py_ssize_t i) noexcept { extern "C" int PySequence_DelItem(PyObject* s, Py_ssize_t i) noexcept {
try { PySequenceMethods* m;
// Not sure if this is really the same:
delitem(o, boxInt(i)); if (s == NULL) {
return 0; null_error();
} catch (ExcInfo e) {
setCAPIException(e);
return -1; return -1;
} }
m = s->cls->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
i += l;
}
}
return m->sq_ass_item(s, i, (PyObject*)NULL);
}
type_error("'%.200s' object doesn't support item deletion", s);
return -1;
} }
extern "C" int PySequence_SetSlice(PyObject* s, Py_ssize_t i1, Py_ssize_t i2, PyObject* o) noexcept { extern "C" int PySequence_SetSlice(PyObject* s, Py_ssize_t i1, Py_ssize_t i2, PyObject* o) noexcept {
......
...@@ -20,3 +20,6 @@ for op in sorted(dir(operator)): ...@@ -20,3 +20,6 @@ for op in sorted(dir(operator)):
if op.startswith("_"): if op.startswith("_"):
continue continue
print getattr(operator, op).__name__ print getattr(operator, op).__name__
a = range(4)
operator.setitem(a, 1, 3)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment