diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2009-12-08 14:06:04 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2009-12-08 14:06:04 +0000 |
commit | 361ae042505053cb924612be0c8c79380d29d941 (patch) | |
tree | c652761b90b8d96b675146b80aac4b7e80926cc3 /gdb/python | |
parent | 40b5c9fb4b794ff4337707edbd74af035bdbb0c2 (diff) | |
download | gdb-361ae042505053cb924612be0c8c79380d29d941.zip gdb-361ae042505053cb924612be0c8c79380d29d941.tar.gz gdb-361ae042505053cb924612be0c8c79380d29d941.tar.bz2 |
2009-12-08 Phil Muldoon <pmuldoon@redhat.com>
PR python/10804
* python/py-type.c (typy_range): New Function.
2009-12-08 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/py-type.exp (test_range): New test.
2009-12-08 Phil Muldoon <pmuldoon@redhat.com>
* gdb.texinfo (Types In Python): Describe range function.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-type.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index e73185e..c581307 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -273,6 +273,70 @@ typy_pointer (PyObject *self, PyObject *args) return type_to_type_object (type); } +/* Return the range of a type represented by SELF. The return type is + a tuple. The first element of the tuple contains the low bound, + while the second element of the tuple contains the high bound. */ +static PyObject * +typy_range (PyObject *self, PyObject *args) +{ + struct type *type = ((type_object *) self)->type; + PyObject *result; + PyObject *low_bound = NULL, *high_bound = NULL; + LONGEST low, high; + + if (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_STRING + && TYPE_CODE (type) != TYPE_CODE_RANGE) + { + PyErr_SetString (PyExc_RuntimeError, + "This type does not have a range."); + return NULL; + } + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_ARRAY: + case TYPE_CODE_STRING: + low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)); + high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type)); + break; + case TYPE_CODE_RANGE: + low = TYPE_LOW_BOUND (type); + high = TYPE_HIGH_BOUND (type); + break; + } + + low_bound = PyLong_FromLong (low); + if (!low_bound) + goto failarg; + + high_bound = PyLong_FromLong (high); + if (!high_bound) + goto failarg; + + result = PyTuple_New (2); + if (!result) + goto failarg; + + if (PyTuple_SetItem (result, 0, low_bound) != 0) + { + Py_DECREF (result); + goto failarg; + } + if (PyTuple_SetItem (result, 1, high_bound) != 0) + { + Py_DECREF (high_bound); + Py_DECREF (result); + return NULL; + } + return result; + + failarg: + Py_XDECREF (high_bound); + Py_XDECREF (low_bound); + return NULL; +} + /* Return a Type object which represents a reference to SELF. */ static PyObject * typy_reference (PyObject *self, PyObject *args) @@ -699,6 +763,9 @@ Each field is a dictionary." }, { "pointer", typy_pointer, METH_NOARGS, "pointer () -> Type\n\ Return a type of pointer to this type." }, + { "range", typy_range, METH_NOARGS, + "range () -> tuple\n\ +Return a tuple containing the lower and upper range for this type."}, { "reference", typy_reference, METH_NOARGS, "reference () -> Type\n\ Return a type of reference to this type." }, |