2011-03-17 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / python / py-block.c
index 9d0d6ccbcdb069edeb4cafca86a796ecdc827858..08d4455508bc83bca7b12c3c56d4086155a97c93 100644 (file)
@@ -263,6 +263,36 @@ blpy_block_syms_dealloc (PyObject *obj)
   Py_XDECREF (iter_obj->source);
 }
 
+/* Implementation of gdb.Block.is_valid (self) -> Boolean.
+   Returns True if this block object still exists in GDB.  */
+
+static PyObject *
+blpy_is_valid (PyObject *self, PyObject *args)
+{
+  struct block *block;
+
+  block = block_object_to_block (self);
+  if (block == NULL)
+    Py_RETURN_FALSE;
+
+  Py_RETURN_TRUE;
+}
+
+/* Implementation of gdb.BlockIterator.is_valid (self) -> Boolean.
+   Returns True if this block iterator object still exists in GDB  */
+
+static PyObject *
+blpy_iter_is_valid (PyObject *self, PyObject *args)
+{
+  block_syms_iterator_object *iter_obj =
+    (block_syms_iterator_object *) self;
+
+  if (iter_obj->source->block == NULL)
+    Py_RETURN_FALSE;
+
+  Py_RETURN_TRUE;
+}
+
 /* Return the innermost lexical block containing the specified pc value,
    or 0 if there is none.  */
 PyObject *
@@ -342,6 +372,13 @@ gdbpy_initialize_blocks (void)
 
 \f
 
+static PyMethodDef block_object_methods[] = {
+  { "is_valid", blpy_is_valid, METH_NOARGS,
+    "is_valid () -> Boolean.\n\
+Return true if this block is valid, false if not." },
+  {NULL}  /* Sentinel */
+};
+
 static PyGetSetDef block_object_getset[] = {
   { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
   { "end", blpy_get_end, NULL, "End address of the block.", NULL },
@@ -381,11 +418,18 @@ PyTypeObject block_object_type = {
   0,                             /* tp_weaklistoffset */
   blpy_iter,                     /* tp_iter */
   0,                             /* tp_iternext */
-  0,                             /* tp_methods */
+  block_object_methods,                  /* tp_methods */
   0,                             /* tp_members */
   block_object_getset            /* tp_getset */
 };
 
+static PyMethodDef block_iterator_object_methods[] = {
+  { "is_valid", blpy_iter_is_valid, METH_NOARGS,
+    "is_valid () -> Boolean.\n\
+Return true if this block iterator is valid, false if not." },
+  {NULL}  /* Sentinel */
+};
+
 static PyTypeObject block_syms_iterator_object_type = {
   PyObject_HEAD_INIT (NULL)
   0,                             /*ob_size*/
@@ -415,5 +459,5 @@ static PyTypeObject block_syms_iterator_object_type = {
   0,                             /*tp_weaklistoffset */
   blpy_block_syms_iter,           /*tp_iter */
   blpy_block_syms_iternext,      /*tp_iternext */
-  0                              /*tp_methods */
+  block_iterator_object_methods   /*tp_methods */
 };
This page took 0.028495 seconds and 4 git commands to generate.