# HG changeset patch # User Matti Hamalainen # Date 1189344710 -10800 # Node ID b2a82a73a788e8515adadcb1484b4cbb5bafc40c # Parent 08085ecc7e917786277ca37ddbe65c5015496c8c Few bits of pre-integration shit. diff -r 08085ecc7e91 -r b2a82a73a788 src/audacious/playlist.c --- a/src/audacious/playlist.c Sun Sep 09 07:14:00 2007 +0300 +++ b/src/audacious/playlist.c Sun Sep 09 16:31:50 2007 +0300 @@ -180,12 +180,8 @@ entry->tuple = NULL; } - if (entry->filename != NULL) - g_free(entry->filename); - - if (entry->title != NULL) - g_free(entry->title); - + g_free(entry->filename); + g_free(entry->title); mowgli_heap_free(playlist_entry_heap, entry); } diff -r 08085ecc7e91 -r b2a82a73a788 src/audacious/tuple.c --- a/src/audacious/tuple.c Sun Sep 09 07:14:00 2007 +0300 +++ b/src/audacious/tuple.c Sun Sep 09 16:31:50 2007 +0300 @@ -161,6 +161,17 @@ return tuple; } + +static gint tuple_get_nfield(const gchar *field) +{ + gint i; + for (i = 0; i < FIELD_LAST; i++) + if (!strcmp(field, tuple_fields[i].name)) + return i; + return -1; +} + + static TupleValue * tuple_associate_data(Tuple *tuple, const gint cnfield, const gchar *field, TupleValueType ftype) { @@ -173,11 +184,7 @@ /* Check for known fields */ if (nfield < 0) { - gint i; - for (i = 0; i < FIELD_LAST && nfield < 0; i++) - if (!strcmp(field, tuple_fields[i].name)) - nfield = i; - + nfield = tuple_get_nfield(field); if (nfield >= 0) { fprintf(stderr, "WARNING! FIELD_* not used for '%s'!\n", field); } @@ -209,9 +216,10 @@ /* Allocate a new value */ value = mowgli_heap_alloc(tuple_value_heap); value->type = ftype; - mowgli_dictionary_add(tuple->dict, tfield, value); if (nfield >= 0) tuple->values[nfield] = value; + else + mowgli_dictionary_add(tuple->dict, tfield, value); } return value; @@ -223,7 +231,6 @@ TupleValue *value; TUPLE_LOCK_WRITE(); - if ((value = tuple_associate_data(tuple, nfield, field, TUPLE_STRING)) == NULL) return FALSE; @@ -252,24 +259,27 @@ } void -tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field) +tuple_disassociate(Tuple *tuple, const gint cnfield, const gchar *field) { TupleValue *value; - const gchar *tfield; + gint nfield = cnfield; g_return_if_fail(tuple != NULL); g_return_if_fail(nfield < FIELD_LAST); + if (nfield < 0) + nfield = tuple_get_nfield(field); + TUPLE_LOCK_WRITE(); if (nfield < 0) - tfield = field; + /* why _delete()? because _delete() returns the dictnode's data on success */ + value = mowgli_dictionary_delete(tuple->dict, field); else { - tfield = tuple_fields[nfield].name; + value = tuple->values[nfield]; tuple->values[nfield] = NULL; } - /* why _delete()? because _delete() returns the dictnode's data on success */ - if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL) { + if (value == NULL) { TUPLE_UNLOCK_WRITE(); return; } @@ -285,13 +295,17 @@ } TupleValueType -tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field) +tuple_get_value_type(Tuple *tuple, const gint cnfield, const gchar *field) { TupleValueType type = TUPLE_UNKNOWN; + gint nfield = cnfield; g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN); + if (nfield < 0) + nfield = tuple_get_nfield(field); + TUPLE_LOCK_READ(); if (nfield < 0) { TupleValue *value; @@ -307,13 +321,17 @@ } const gchar * -tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field) +tuple_get_string(Tuple *tuple, const gint cnfield, const gchar *field) { TupleValue *value; + gint nfield = cnfield; g_return_val_if_fail(tuple != NULL, NULL); g_return_val_if_fail(nfield < FIELD_LAST, NULL); + if (nfield < 0) + nfield = tuple_get_nfield(field); + TUPLE_LOCK_READ(); if (nfield < 0) value = mowgli_dictionary_retrieve(tuple->dict, field); @@ -333,13 +351,17 @@ } gint -tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field) +tuple_get_int(Tuple *tuple, const gint cnfield, const gchar *field) { TupleValue *value; + gint nfield = cnfield; g_return_val_if_fail(tuple != NULL, 0); g_return_val_if_fail(nfield < FIELD_LAST, 0); + if (nfield < 0) + nfield = tuple_get_nfield(field); + TUPLE_LOCK_READ(); if (nfield < 0) value = mowgli_dictionary_retrieve(tuple->dict, field);