SF.net SVN: geany:[5559] trunk/tagmanager
colombanw at users.sourceforge.net
colombanw at xxxxx
Sat Mar 5 22:48:25 UTC 2011
Revision: 5559
http://geany.svn.sourceforge.net/geany/?rev=5559&view=rev
Author: colombanw
Date: 2011-03-05 22:48:25 +0000 (Sat, 05 Mar 2011)
Log Message:
-----------
Make TMTag reference-counted
Modified Paths:
--------------
trunk/tagmanager/include/tm_tag.h
trunk/tagmanager/tm_project.c
trunk/tagmanager/tm_source_file.c
trunk/tagmanager/tm_tag.c
trunk/tagmanager/tm_workspace.c
Modified: trunk/tagmanager/include/tm_tag.h
===================================================================
--- trunk/tagmanager/include/tm_tag.h 2011-03-05 22:47:13 UTC (rev 5558)
+++ trunk/tagmanager/include/tm_tag.h 2011-03-05 22:48:25 UTC (rev 5559)
@@ -147,6 +147,7 @@
gboolean inactive; /*!< Whether this file is to be parsed */
} file;
} atts;
+ gint refcount; /*!< the reference count of the tag */
} TMTag;
/*!
@@ -306,15 +307,29 @@
\sa tm_tag_free()
*/
void tm_tag_destroy(TMTag *tag);
-#endif
/*!
Destroys all data in the tag and frees the tag structure as well.
\param tag Pointer to a TMTag structure
*/
void tm_tag_free(gpointer tag);
+#endif
/*!
+ Drops a reference from a TMTag. If the reference count reaches 0, this function
+ destroys all data in the tag and frees the tag structure as well.
+ \param tag Pointer to a TMTag structure
+*/
+void tm_tag_unref(TMTag *tag);
+
+/*!
+ Adds a reference to a TMTag.
+ \param tag Pointer to a TMTag structure
+ \return the passed-in TMTag
+*/
+TMTag *tm_tag_ref(TMTag *tag);
+
+/*!
Returns the type of tag as a string
\param tag The tag whose type is required
*/
Modified: trunk/tagmanager/tm_project.c
===================================================================
--- trunk/tagmanager/tm_project.c 2011-03-05 22:47:13 UTC (rev 5558)
+++ trunk/tagmanager/tm_project.c 2011-03-05 22:48:25 UTC (rev 5559)
@@ -396,7 +396,7 @@
#endif
if (!force)
{
- tm_tag_free(tag);
+ tm_tag_unref(tag);
fclose(fp);
return FALSE;
}
@@ -412,7 +412,7 @@
project->file_list = g_ptr_array_new();
g_ptr_array_add(project->file_list, source_file);
}
- tm_tag_free(tag);
+ tm_tag_unref(tag);
}
else
{
@@ -421,7 +421,7 @@
#ifdef TM_DEBUG
g_warning("Dangling tag %s", tag->name);
#endif
- tm_tag_free(tag);
+ tm_tag_unref(tag);
if (!force)
{
fclose(fp);
Modified: trunk/tagmanager/tm_source_file.c
===================================================================
--- trunk/tagmanager/tm_source_file.c 2011-03-05 22:47:13 UTC (rev 5558)
+++ trunk/tagmanager/tm_source_file.c 2011-03-05 22:48:25 UTC (rev 5559)
@@ -324,7 +324,7 @@
if (NULL != (tag = tm_tag_new(TM_SOURCE_FILE(source_file), NULL)))
{
tm_tag_write(tag, fp, tm_tag_attr_max_t);
- tm_tag_free(tag);
+ tm_tag_unref(tag);
if (NULL != source_file->tags_array)
{
for (i=0; i < source_file->tags_array->len; ++i)
Modified: trunk/tagmanager/tm_tag.c
===================================================================
--- trunk/tagmanager/tm_tag.c 2011-03-05 22:47:13 UTC (rev 5558)
+++ trunk/tagmanager/tm_tag.c 2011-03-05 22:48:25 UTC (rev 5559)
@@ -129,6 +129,7 @@
gboolean tm_tag_init(TMTag *tag, TMSourceFile *file, const tagEntryInfo *tag_entry)
{
+ tag->refcount = 1;
if (NULL == tag_entry)
{
/* This is a file tag */
@@ -224,6 +225,7 @@
gboolean status;
guchar changed_char = TA_NAME;
+ tag->refcount = 1;
if ((NULL == fgets((gchar*)buf, BUFSIZ, fp)) || ('\0' == *buf))
return FALSE;
for (start = end = buf, status = TRUE; (TRUE == status); start = end, ++ end)
@@ -327,6 +329,7 @@
gboolean status;
/*guchar changed_char = TA_NAME;*/
+ tag->refcount = 1;
if ((NULL == fgets((gchar*)buf, BUFSIZ, fp)) || ('\0' == *buf))
return FALSE;
{
@@ -436,15 +439,30 @@
}
}
+#if 0
void tm_tag_free(gpointer tag)
{
- if (NULL != tag)
+ tm_tag_unref(tag);
+}
+#endif
+
+void tm_tag_unref(TMTag *tag)
+{
+ /* be NULL-proof because tm_tag_free() was NULL-proof and we indent to be a
+ * drop-in replacment of it */
+ if (NULL != tag && g_atomic_int_dec_and_test(&tag->refcount))
{
- tm_tag_destroy((TMTag *) tag);
+ tm_tag_destroy(tag);
TAG_FREE(tag);
}
}
+TMTag *tm_tag_ref(TMTag *tag)
+{
+ g_atomic_int_inc(&tag->refcount);
+ return tag;
+}
+
int tm_tag_compare(const void *ptr1, const void *ptr2)
{
unsigned int *sort_attr;
@@ -603,7 +621,7 @@
{
guint i;
for (i = 0; i < tags_array->len; ++i)
- tm_tag_free(tags_array->pdata[i]);
+ tm_tag_unref(tags_array->pdata[i]);
if (free_all)
g_ptr_array_free(tags_array, TRUE);
else
Modified: trunk/tagmanager/tm_workspace.c
===================================================================
--- trunk/tagmanager/tm_workspace.c 2011-03-05 22:47:13 UTC (rev 5558)
+++ trunk/tagmanager/tm_workspace.c 2011-03-05 22:48:25 UTC (rev 5559)
@@ -82,7 +82,7 @@
if (theWorkspace->global_tags)
{
for (i=0; i < theWorkspace->global_tags->len; ++i)
- tm_tag_free(theWorkspace->global_tags->pdata[i]);
+ tm_tag_unref(theWorkspace->global_tags->pdata[i]);
g_ptr_array_free(theWorkspace->global_tags, TRUE);
}
tm_work_object_destroy(TM_WORK_OBJECT(theWorkspace));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list