Mercurial > pidgin.yaz
comparison src/stringref.c @ 7795:069ee4ecb56a
[gaim-migrate @ 8441]
Everybody likes a good macro!
committer: Tailor Script <tailor@pidgin.im>
| author | Ethan Blanton <elb@pidgin.im> |
|---|---|
| date | Sun, 07 Dec 2003 20:44:07 +0000 |
| parents | c2e391c480b6 |
| children | e04c0044c56f |
comparison
equal
deleted
inserted
replaced
| 7794:d2710acd0020 | 7795:069ee4ecb56a |
|---|---|
| 27 #include <string.h> | 27 #include <string.h> |
| 28 #include <stdarg.h> | 28 #include <stdarg.h> |
| 29 | 29 |
| 30 #include "debug.h" | 30 #include "debug.h" |
| 31 #include "stringref.h" | 31 #include "stringref.h" |
| 32 | |
| 33 #define REFCOUNT(x) ((x) & 0x7fffffff) | |
| 32 | 34 |
| 33 static GList *gclist = NULL; | 35 static GList *gclist = NULL; |
| 34 | 36 |
| 35 static void stringref_free(GaimStringref *stringref); | 37 static void stringref_free(GaimStringref *stringref); |
| 36 static gboolean gs_idle_cb(gpointer data); | 38 static gboolean gs_idle_cb(gpointer data); |
| 94 | 96 |
| 95 void gaim_stringref_unref(GaimStringref *stringref) | 97 void gaim_stringref_unref(GaimStringref *stringref) |
| 96 { | 98 { |
| 97 if (stringref == NULL) | 99 if (stringref == NULL) |
| 98 return; | 100 return; |
| 99 if ((--(stringref->ref) & 0x7fffffff) == 0) { | 101 if (REFCOUNT(--(stringref->ref)) == 0) { |
| 100 if (stringref->ref & 0x80000000) | 102 if (stringref->ref & 0x80000000) |
| 101 gclist = g_list_remove(gclist, stringref); | 103 gclist = g_list_remove(gclist, stringref); |
| 102 stringref_free(stringref); | 104 stringref_free(stringref); |
| 103 } | 105 } |
| 104 } | 106 } |
| 119 } | 121 } |
| 120 | 122 |
| 121 static void stringref_free(GaimStringref *stringref) | 123 static void stringref_free(GaimStringref *stringref) |
| 122 { | 124 { |
| 123 #ifdef DEBUG | 125 #ifdef DEBUG |
| 124 if (stringref->ref != 0) { | 126 if (REFCOUNT(stringref->ref) != 0) { |
| 125 gaim_debug(GAIM_DEBUG_ERROR, "stringref", "Free of nonzero (%d) ref stringref!\n", stringref->ref); | 127 gaim_debug(GAIM_DEBUG_ERROR, "stringref", "Free of nonzero (%d) ref stringref!\n", stringref->ref); |
| 126 return; | 128 return; |
| 127 } | 129 } |
| 128 #endif /* DEBUG */ | 130 #endif /* DEBUG */ |
| 129 g_free(stringref); | 131 g_free(stringref); |
| 134 GaimStringref *ref; | 136 GaimStringref *ref; |
| 135 GList *del; | 137 GList *del; |
| 136 | 138 |
| 137 while (gclist != NULL) { | 139 while (gclist != NULL) { |
| 138 ref = gclist->data; | 140 ref = gclist->data; |
| 139 ref->ref &= 0x7fffffff; | 141 if (REFCOUNT(ref->ref) == 0) { |
| 140 if (ref->ref == 0) { | |
| 141 stringref_free(ref); | 142 stringref_free(ref); |
| 142 } | 143 } |
| 143 del = gclist; | 144 del = gclist; |
| 144 gclist = gclist->next; | 145 gclist = gclist->next; |
| 145 g_list_free_1(del); | 146 g_list_free_1(del); |
