WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/python/py-heap.c
/* Implementation of gdb.heap_walk()
 * Take one argument of long or gdb.Heap_block, or no argument
   Returns the next heap block after the given address, or None.  */
Implementation of gdb.heap_walk()
Take one argument of long or gdb.Heap_block, or no argument
Returns the next heap block after the given address, or None.
Implementation of gdb . heap_walk () Take one argument of long or gdb . Heap_block or no argument Returns the next heap block after the given address or None .
PyObject *gdbpy_heap_walk (PyObject *self, PyObject *args)
{
	PyObject *result = NULL;
	struct heap_block blk;
	address_t addr = 0;
	int input_prev_block = 0;
	if (PyTuple_Size (args) == 0)
		addr = 0;
	else if (PyTuple_Size (args) == 1)
	{
		PyObject *obj = PyTuple_GetItem (args, 0);
		if (PyInt_Check (obj))
			addr = (address_t) PyInt_AsLong (obj);
		else if (PyLong_Check (obj))
			addr = (address_t) PyLong_AsLong (obj);
		else if (PyObject_TypeCheck(obj, &heap_block_object_type))
		{
			PyObject *addr_obj = ((heap_block_object*)obj)->address;
			input_prev_block = 1;
			if (PyLong_Check (addr_obj))
				addr = (address_t) PyLong_AsLong (addr_obj);
			else if (PyInt_Check (addr_obj))
				addr = (address_t) PyInt_AsLong (addr_obj);
			else
			{
				PyErr_SetString (PyExc_TypeError, _("Expect long of gdb.Heap_block's address field."));
				return NULL;
			}
		}
	}
	else
	{
		PyErr_SetString (PyExc_TypeError, _("Heap_walk takes one argument or none."));
		return NULL;
	}
	if (!input_prev_block && !update_memory_segments_and_heaps())
	{
		PyErr_SetString (PyExc_MemoryError, _("Failed to read and initialize process's heap segments."));
		return NULL;
	}
	if (get_next_heap_block (addr, &blk))
	{
		heap_block_object* blk_object;
		blk_object = PyObject_New (heap_block_object, &heap_block_object_type);
		if (blk_object)
		{
			blk_object->address = Py_BuildValue("l", blk.addr);
			blk_object->size = Py_BuildValue("l", blk.size);
			blk_object->inuse = Py_BuildValue("b", blk.inuse);
		}
		else
		{
			PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory to create heap_block object."));
			return NULL;
		}
		result = (PyObject*) blk_object;
	}
	else
	{
		result = Py_None;
		Py_INCREF (Py_None);
	}
	  return result;
}
PyObject * gdbpy_heap_walk ( PyObject * self , PyObject * args ) { PyObject * result = NULL ; struct heap_block blk ; address_t addr = 0 ; int input_prev_block = 0 ; if ( PyTuple_Size ( args ) == 0 ) addr = 0 ; else if ( PyTuple_Size ( args ) == 1 ) { PyObject * obj = PyTuple_GetItem ( args , 0 ) ; if ( PyInt_Check ( obj ) ) addr = ( address_t ) PyInt_AsLong ( obj ) ; else if ( PyLong_Check ( obj ) ) addr = ( address_t ) PyLong_AsLong ( obj ) ; else if ( PyObject_TypeCheck ( obj , & heap_block_object_type ) ) { PyObject * addr_obj = ( ( heap_block_object * ) obj ) -> address ; input_prev_block = 1 ; if ( PyLong_Check ( addr_obj ) ) addr = ( address_t ) PyLong_AsLong ( addr_obj ) ; else if ( PyInt_Check ( addr_obj ) ) addr = ( address_t ) PyInt_AsLong ( addr_obj ) ; else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } } } else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } if ( ! input_prev_block && ! update_memory_segments_and_heaps ( ) ) { PyErr_SetString ( PyExc_MemoryError , _ ( " " ) ) ; return NULL ; } if ( get_next_heap_block ( addr , & blk ) ) { heap_block_object * blk_object ; blk_object = PyObject_New ( heap_block_object , & heap_block_object_type ) ; if ( blk_object ) { blk_object -> address = Py_BuildValue ( " " , blk . addr ) ; blk_object -> size = Py_BuildValue ( " " , blk . size ) ; blk_object -> inuse = Py_BuildValue ( " " , blk . inuse ) ; } else { PyErr_SetString ( PyExc_MemoryError , _ ( " " ) ) ; return NULL ; } result = ( PyObject * ) blk_object ; } else { result = Py_None ; Py_INCREF ( Py_None ) ; } return result ; }
Implementation of gdb.heap_walk()
 Take one argument of long or gdb.Heap_block, or no argument
Returns the next heap block after the given address, or None.
Implementation of gdb . heap_walk () Take one argument of long or gdb . Heap_block or no argument Returns the next heap block after the given address or None .