Commit 01a0b1a7 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add the rest of the sequence methods

parent 40f3a650
This diff is collapsed.
......@@ -209,20 +209,34 @@ call_funcs(PyObject* _module, PyObject* args) {
if (cls->tp_as_mapping) {
printf("tp_as_mapping exists\n");
if (cls->tp_as_mapping->mp_subscript) {
PyObject* rtn = cls->tp_as_mapping->mp_subscript(obj, PyInt_FromLong(1));
PyMappingMethods* map = cls->tp_as_mapping;
if (map->mp_subscript) {
PyObject* rtn = map->mp_subscript(obj, PyInt_FromLong(1));
printf("mp_subscript exists and returned\n");
Py_DECREF(rtn);
} else {
printf("mp_subscript does not exist\n");
}
if (map->mp_length) {
Py_ssize_t rtn = map->mp_length(obj);
printf("mp_length exists and returned %ld\n", rtn);
}
} else {
printf("tp_as_mapping doesnt exist\n");
}
if (cls->tp_as_sequence) {
printf("tp_as_sequence exists\n");
if (cls->tp_as_sequence->sq_item) {
PySequenceMethods* seq = cls->tp_as_sequence;
if (seq->sq_length) {
Py_ssize_t rtn = seq->sq_length(obj);
printf("sq_length exists and returned %ld\n", rtn);
}
if (seq->sq_item) {
PyObject* rtn = cls->tp_as_sequence->sq_item(obj, 1);
printf("sq_item exists and returned\n");
Py_DECREF(rtn);
......
# expected: fail
# - wip
import slots_test
for i in xrange(3):
......@@ -25,6 +22,10 @@ class C(object):
print "__getitem__", idx
return idx - 5
def __len__(self):
print "__len__"
return 3
slots_test.call_funcs(C())
# Test to make sure that updating an existing class also updates the tp_* slots:
......
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