summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-21 17:41:54 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-21 17:41:54 (GMT)
commit6cdc6f41465e88344b5ed62e45b036cf502f3770 (patch)
treef601508b8e5d36d8672f1344a90924db482fd702
parentc9fb47ef084709783baf77a5ccfd3c6b4ecf9434 (diff)
downloadcpython-6cdc6f41465e88344b5ed62e45b036cf502f3770.zip
cpython-6cdc6f41465e88344b5ed62e45b036cf502f3770.tar.gz
cpython-6cdc6f41465e88344b5ed62e45b036cf502f3770.tar.bz2
Added PyObject_DelItem and PySequence_Del{Item,Slice}.
-rw-r--r--Include/abstract.h23
-rw-r--r--Objects/abstract.c61
2 files changed, 84 insertions, 0 deletions
diff --git a/Include/abstract.h b/Include/abstract.h
index 53b4193..956ca89 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -410,6 +410,13 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
statement: o[key]=v.
*/
+ int PyObject_DelItem Py_PROTO((PyObject *o, PyObject *key));
+
+ /*
+ Delete the mapping for key from *o. Returns -1 on failure.
+ This is the equivalent of the Python statement: del o[key].
+ */
+
/* Number Protocol:*/
@@ -672,6 +679,14 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
+ int PySequence_DelItem Py_PROTO((PyObject *o, int i));
+
+ /*
+ Delete the ith element of object v. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: del o[i].
+ */
+
int PySequence_SetSlice Py_PROTO((PyObject *o, int i1, int i2, PyObject *v));
/*
@@ -680,6 +695,14 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
equivalent of the Python statement: o[i1:i2]=v.
*/
+ int PySequence_DelSlice Py_PROTO((PyObject *o, int i1, int i2));
+
+ /*
+ Delete the slice in sequence object, o, from i1 to i2.
+ Returns -1 on failure. This is the equivalent of the Python
+ statement: del o[i1:i2].
+ */
+
PyObject *PySequence_Tuple Py_PROTO((PyObject *o));
/*
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 1efec1a..e0483a1 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -155,6 +155,24 @@ PyObject_SetItem(o, key, value)
return -1;
}
+int
+PyObject_DelItem(o, key)
+ PyObject *o;
+ PyObject *key;
+{
+ PyMappingMethods *m;
+
+ if(! o || ! key) return Py_ReturnNullError(),-1;
+ if((m=o->ob_type->tp_as_mapping) && m->mp_ass_subscript)
+ return m->mp_ass_subscript(o,key,(PyObject*)NULL);
+
+ if(PyInt_Check(key))
+ return PySequence_SetItem(o,PyInt_AsLong(key),(PyObject*)NULL);
+
+ PyErr_SetString(PyExc_TypeError,"expeced integer index");
+ return -1;
+}
+
int
PyNumber_Check(o)
PyObject *o;
@@ -695,6 +713,27 @@ PySequence_SetItem(s, i, o)
return m->sq_ass_item(s,i,o);
}
+int
+PySequence_DelItem(s, i)
+ PyObject *s;
+ int i;
+{
+ PySequenceMethods *m;
+ int l;
+ if(! s) return Py_ReturnNullError(),-1;
+
+ if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_item))
+ return Py_ReturnMethodError("__delitem__"),-1;
+
+ if(i < 0)
+ {
+ if(0 > (l=m->sq_length(s))) return -1;
+ i += l;
+ }
+
+ return m->sq_ass_item(s,i,(PyObject*)NULL);
+}
+
int
PySequence_SetSlice(s, i1, i2, o)
PyObject *s;
@@ -718,6 +757,28 @@ PySequence_SetSlice(s, i1, i2, o)
return m->sq_ass_slice(s,i1,i2,o);
}
+int
+PySequence_DelSlice(s, i1, i2)
+ PyObject *s;
+ int i1;
+ int i2;
+{
+ PySequenceMethods *m;
+ int l;
+
+ if(! s) return Py_ReturnNullError(),-1;
+
+ if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_ass_slice))
+ return Py_ReturnMethodError("__delslice__"),-1;
+
+ if(0 > (l=m->sq_length(s))) return -1;
+
+ if(i1 < 0) i1 += l;
+ if(i2 < 0) i2 += l;
+
+ return m->sq_ass_slice(s,i1,i2,(PyObject*)NULL);
+}
+
PyObject *
PySequence_Tuple(s)
PyObject *s;