songvec, dirvec: use GLib instead of utils.h

This commit is contained in:
Max Kellermann 2009-01-03 14:53:02 +01:00
parent 457301d97b
commit 2064e8ac4c
2 changed files with 14 additions and 14 deletions

View File

@ -1,12 +1,11 @@
#include "dirvec.h" #include "dirvec.h"
#include "directory.h" #include "directory.h"
#include "utils.h"
#include "path.h"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
static GMutex *nr_lock = NULL; static GMutex *nr_lock = NULL;
@ -74,13 +73,13 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
/* we _don't_ call directory_free() here */ /* we _don't_ call directory_free() here */
if (!--dv->nr) { if (!--dv->nr) {
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
free(dv->base); g_free(dv->base);
dv->base = NULL; dv->base = NULL;
return i; return i;
} else { } else {
memmove(&dv->base[i], &dv->base[i + 1], memmove(&dv->base[i], &dv->base[i + 1],
(dv->nr - i) * sizeof(struct directory *)); (dv->nr - i) * sizeof(struct directory *));
dv->base = xrealloc(dv->base, dv_size(dv)); dv->base = g_realloc(dv->base, dv_size(dv));
} }
break; break;
} }
@ -93,7 +92,7 @@ void dirvec_add(struct dirvec *dv, struct directory *add)
{ {
g_mutex_lock(nr_lock); g_mutex_lock(nr_lock);
++dv->nr; ++dv->nr;
dv->base = xrealloc(dv->base, dv_size(dv)); dv->base = g_realloc(dv->base, dv_size(dv));
dv->base[dv->nr - 1] = add; dv->base[dv->nr - 1] = add;
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
} }
@ -104,7 +103,7 @@ void dirvec_destroy(struct dirvec *dv)
dv->nr = 0; dv->nr = 0;
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
if (dv->base) { if (dv->base) {
free(dv->base); g_free(dv->base);
dv->base = NULL; dv->base = NULL;
} }
} }

View File

@ -1,9 +1,11 @@
#include "songvec.h" #include "songvec.h"
#include "song.h" #include "song.h"
#include "utils.h"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
static GMutex *nr_lock = NULL; static GMutex *nr_lock = NULL;
@ -68,12 +70,12 @@ songvec_delete(struct songvec *sv, const struct song *del)
continue; continue;
/* we _don't_ call song_free() here */ /* we _don't_ call song_free() here */
if (!--sv->nr) { if (!--sv->nr) {
free(sv->base); g_free(sv->base);
sv->base = NULL; sv->base = NULL;
} else { } else {
memmove(&sv->base[i], &sv->base[i + 1], memmove(&sv->base[i], &sv->base[i + 1],
(sv->nr - i) * sizeof(struct song *)); (sv->nr - i) * sizeof(struct song *));
sv->base = xrealloc(sv->base, sv_size(sv)); sv->base = g_realloc(sv->base, sv_size(sv));
} }
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
return i; return i;
@ -88,7 +90,7 @@ songvec_add(struct songvec *sv, struct song *add)
{ {
g_mutex_lock(nr_lock); g_mutex_lock(nr_lock);
++sv->nr; ++sv->nr;
sv->base = xrealloc(sv->base, sv_size(sv)); sv->base = g_realloc(sv->base, sv_size(sv));
sv->base[sv->nr - 1] = add; sv->base[sv->nr - 1] = add;
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
} }
@ -98,10 +100,9 @@ void songvec_destroy(struct songvec *sv)
g_mutex_lock(nr_lock); g_mutex_lock(nr_lock);
sv->nr = 0; sv->nr = 0;
g_mutex_unlock(nr_lock); g_mutex_unlock(nr_lock);
if (sv->base) {
free(sv->base); g_free(sv->base);
sv->base = NULL; sv->base = NULL;
}
} }
int int