From 0ef95757d6fed29b99d1ea08b78732b2a7fe0e2c Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Mon, 28 Mar 2005 07:45:24 +0000 Subject: added a FREELISTPTR macro to free a PMList without freeing its data --- lib/libalpm/add.c | 11 ++--------- lib/libalpm/alpm.c | 2 +- lib/libalpm/cache.c | 6 +----- lib/libalpm/deps.c | 10 ++-------- lib/libalpm/list.h | 10 ++++++++++ lib/libalpm/remove.c | 13 +++---------- 6 files changed, 19 insertions(+), 33 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 0bbf0755..dd99313a 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -193,10 +193,7 @@ int add_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data) _alpm_log(PM_LOG_FLOW1, "sorting by dependencies"); lp = sortbydeps(trans->packages, PM_TRANS_TYPE_ADD); /* free the old alltargs */ - for(j = trans->packages; j; j = j->next) { - j->data = NULL; - } - FREELIST(trans->packages); + FREELISTPTR(trans->packages); trans->packages = lp; TRANS_CB(trans, PM_TRANS_EVT_DEPS_DONE, NULL, NULL); @@ -384,13 +381,9 @@ int add_commit(pmdb_t *db, pmtrans_t *trans) cache, thus eliminating the need for db_scan(DEPENDS) */ PMList *provides = _alpm_db_whatprovides(db, depend.name); if(provides) { - PMList *p; /* use the first one */ depinfo = db_scan(db, ((pmpkg_t *)provides->data)->name, INFRQ_DESC|INFRQ_DEPENDS); - for(p = provides; p; p = p->next) { - p->data = NULL; - } - FREELIST(provides); + FREELISTPTR(provides); if(depinfo == NULL) { /* wtf */ continue; diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 41b604ad..3a6989c7 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -245,7 +245,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts) db_free_pkgcache(db); /* remove the old dir */ - _alpm_log(PM_LOG_FLOW2, "removing %s (if it exists)\n", db->path); + _alpm_log(PM_LOG_FLOW2, "removing %s/%s (if it exists)\n", db->path); /* ORE We should db_remove each db entry, and not rmrf the top directory */ _alpm_rmrf(db->path); diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index c6b298eb..09d508a8 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -156,13 +156,9 @@ void db_free_grpcache(pmdb_t *db) } for(lg = db->grpcache; lg; lg = lg->next) { - PMList *lp; pmgrp_t *grp = lg->data; - for(lp = grp->packages; lp; lp = lp->next) { - lp->data = NULL; - } - FREELIST(grp->packages); + FREELISTPTR(grp->packages); FREEGRP(lg->data); } FREELIST(db->grpcache); diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 3e3bd267..9839014a 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -104,10 +104,7 @@ PMList *sortbydeps(PMList *targets, int mode) } if(clean && change) { /* free up targets -- it's local now */ - for(i = targets; i; i = i->next) { - i->data = NULL; - } - FREELIST(targets); + FREELISTPTR(targets); } targets = newtargs; clean = 1; @@ -116,10 +113,7 @@ PMList *sortbydeps(PMList *targets, int mode) /* we're removing packages, so reverse the order */ newtargs = _alpm_list_reverse(targets); /* free the old one */ - for(i = targets; i; i = i->next) { - i->data = NULL; - } - FREELIST(targets); + FREELISTPTR(targets); targets = newtargs; } diff --git a/lib/libalpm/list.h b/lib/libalpm/list.h index e7c9eb31..734a53d5 100644 --- a/lib/libalpm/list.h +++ b/lib/libalpm/list.h @@ -32,6 +32,16 @@ typedef struct __pmlist_t { typedef struct __pmlist_t PMList; #define FREELIST(p) do { if(p) { pm_list_free(p); p = NULL; } } while(0) +#define FREELISTPTR(p) do { \ + if(p) { \ + PMList *i; \ + for(i = p; i; i = i->next) { \ + i->data = NULL; \ + } \ + pm_list_free(p); \ + p = NULL; \ + } \ +} while(0) /* Sort comparison callback function declaration */ typedef int (*pm_fn_cmp) (const void *, const void *); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index b6e2452b..1c6e4806 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -65,7 +65,7 @@ int remove_loadtarget(pmdb_t *db, pmtrans_t *trans, char *name) int remove_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data) { pmpkg_t *info; - PMList *lp, *i; + PMList *lp; ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); @@ -104,10 +104,7 @@ int remove_prepare(pmdb_t *db, pmtrans_t *trans, PMList **data) _alpm_log(PM_LOG_FLOW1, "sorting by dependencies"); lp = sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE); /* free the old alltargs */ - for(i = trans->packages; i; i = i->next) { - i->data = NULL; - } - FREELIST(trans->packages); + FREELISTPTR(trans->packages); trans->packages = lp; TRANS_CB(trans, PM_TRANS_EVT_DEPS_DONE, NULL, NULL); @@ -228,16 +225,12 @@ int remove_commit(pmdb_t *db, pmtrans_t *trans) /* look for a provides package */ PMList *provides = _alpm_db_whatprovides(db, depend.name); if(provides) { - PMList *p; /* TODO: should check _all_ packages listed in provides, not just * the first one. */ /* use the first one */ depinfo = db_scan(db, ((pmpkg_t *)provides->data)->name, INFRQ_DESC|INFRQ_DEPENDS); - for(p = provides; p; p = p->next) { - p->data = NULL; - } - FREELIST(provides); + FREELISTPTR(provides); if(depinfo == NULL) { /* wtf */ continue; -- cgit v1.2.3-24-g4f1b