summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-28 09:45:24 +0200
committerAurelien Foret <aurelien@archlinux.org>2005-03-28 09:45:24 +0200
commit0ef95757d6fed29b99d1ea08b78732b2a7fe0e2c (patch)
tree533229e29f3d37f6cad859b97cc2d2d9b2dce6fd
parent350a3972d1d372a009c67aba5af4ff0d3e25e813 (diff)
downloadpacman-0ef95757d6fed29b99d1ea08b78732b2a7fe0e2c.tar.gz
pacman-0ef95757d6fed29b99d1ea08b78732b2a7fe0e2c.tar.xz
added a FREELISTPTR macro to free a PMList without freeing its data
-rw-r--r--lib/libalpm/add.c11
-rw-r--r--lib/libalpm/alpm.c2
-rw-r--r--lib/libalpm/cache.c6
-rw-r--r--lib/libalpm/deps.c10
-rw-r--r--lib/libalpm/list.h10
-rw-r--r--lib/libalpm/remove.c13
6 files changed, 19 insertions, 33 deletions
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;