changeset 874:fa39a4d786ad

Increase debugging info in file_data_ref() and file_data_unref(). When compiled with DEBUG defined, file and line of the caller is displayed in debug log.
author zas_
date Thu, 03 Jul 2008 08:33:10 +0000
parents bd3bdceb1230
children f103af877504
files src/filedata.c src/filedata.h
diffstat 2 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.c	Wed Jul 02 08:38:47 2008 +0000
+++ b/src/filedata.c	Thu Jul 03 08:33:10 2008 +0000
@@ -457,15 +457,25 @@
 	return target;
 }
 
-
+#ifdef DEBUG_FILEDATA
+FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd)
+#else
 FileData *file_data_ref(FileData *fd)
+#endif
 {
 	if (fd == NULL) return NULL;
-	DEBUG_2("file_data_ref (%d): '%s'", fd->ref, fd->path);
-
-//	return g_memdup(fd, sizeof(FileData));
+#ifdef DEBUG_FILEDATA
+	if (fd->magick != 0x12345678)
+		DEBUG_0("fd magick mismatch at %s:%d", file, line);
+#endif
 	g_assert(fd->magick == 0x12345678);
 	fd->ref++;
+
+#ifdef DEBUG_FILEDATA
+	DEBUG_2("file_data_ref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+#else
+	DEBUG_2("file_data_ref (%d): '%s'", fd->ref, fd->path);
+#endif
 	return fd;
 }
 
@@ -488,14 +498,26 @@
 	g_free(fd);
 }
 
+#ifdef DEBUG_FILEDATA
+void file_data_unref_debug(const gchar *file, gint line, FileData *fd)
+#else
 void file_data_unref(FileData *fd)
+#endif
 {
 	if (fd == NULL) return;
+#ifdef DEBUG_FILEDATA
+	if (fd->magick != 0x12345678)
+		DEBUG_0("fd magick mismatch @ %s:%d", file, line);
+#endif
 	g_assert(fd->magick == 0x12345678);
-
+	
 	fd->ref--;
+#ifdef DEBUG_FILEDATA
+	DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+
+#else
 	DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path);
-
+#endif
 	if (fd->ref == 0)
 		{
 		GList *work;
@@ -515,7 +537,7 @@
 
 		/* none of parent/children is referenced, we can free everything */
 
-		DEBUG_2("file_data_unref: deleting '%s', parent '%s'", fd->path, parent->path);
+		DEBUG_2("file_data_unref: deleting '%s', parent '%s'", fd->path, fd->parent ? parent->path : "-");
 
 		work = parent->sidecar_files;
 		while (work)
--- a/src/filedata.h	Wed Jul 02 08:38:47 2008 +0000
+++ b/src/filedata.h	Thu Jul 03 08:33:10 2008 +0000
@@ -14,6 +14,10 @@
 #ifndef FILEDATA_H
 #define FILEDATA_H
 
+#ifdef DEBUG
+#define DEBUG_FILEDATA
+#endif
+
 gchar *text_from_size(gint64 size);
 gchar *text_from_size_abrev(gint64 size);
 const gchar *text_from_time(time_t t);
@@ -21,8 +25,15 @@
 /* this expects a utf-8 path */
 FileData *file_data_new_simple(const gchar *path_utf8);
 
+#ifdef DEBUG_FILEDATA
+FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd);
+void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
+#define file_data_ref(fd) file_data_ref_debug(__FILE__, __LINE__, fd)
+#define file_data_unref(fd) file_data_unref_debug(__FILE__, __LINE__, fd)
+#else
 FileData *file_data_ref(FileData *fd);
 void file_data_unref(FileData *fd);
+#endif
 
 void file_data_increment_version(FileData *fd);