/*-*-linux-c-*-*/

/***********************************************
*
* Memory debugging and encapsulation functions.
* submitted by Kervin
***********************************************/
#include "../config.h"
#include <gtk/gtk.h>

//#define NEWTELLA_MEMORY_DEBUG

/* wrapper for malloc */
/* This function uses malloc0 to initialize memory to   */
/* zero.  It also includes option memory debuging stuff */
/* TODO: Add memory in-use list, or write an external 	*/
/*		script or program to do the accounting	*/
gpointer _newtella_malloc(gulong size, gchar *file, gint line)
{
	gpointer ret = g_malloc0(size);

	/*This section will help in tracking memory issues*/
	/*More stuff like a memory list can be added later*/
#ifdef NEWTELLA_MEMORY_DEBUG
	g_message("%s:%d: newtella_malloc: %ld request. %p returned.", file, line, size, ret);
#endif

	if(ret == NULL)
		g_warning("newtella_malloc returned NULL for size == %ld.", size);
	return ret;
}

/* TODO: Add a freed list, or write a script that does it */
void _newtella_free(gpointer mem, gchar *file, gint line)
{
#ifdef NEWTELLA_MEMORY_DEBUG
	g_message("%s:%d: newtella_free: %p freed.", file, line, mem);
#endif
 	if (mem != NULL)
		g_free(mem);
	else
		g_message("%s:%d: Failed to free memory\n", file, line);
} 
 




