Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-02-22 20:49:33 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-02-22 20:49:33 +0000
commit16ff7cfa8ef2d50c97d79357c2b2c1fdc2bc241b (patch)
treed259cc5a0de95d478c3a21df549dbd90880147cd
parent78ffd98701b64bff74fc530db91ffc7e8768989a (diff)
improved _alpm_list_free handling
-rw-r--r--lib/libalpm/db.c5
-rw-r--r--lib/libalpm/db.h2
-rw-r--r--lib/libalpm/group.c4
-rw-r--r--lib/libalpm/group.h10
-rw-r--r--lib/libalpm/list.c6
-rw-r--r--lib/libalpm/list.h14
-rw-r--r--lib/libalpm/package.c4
-rw-r--r--lib/libalpm/package.h13
-rw-r--r--lib/libalpm/sync.c4
-rw-r--r--lib/libalpm/sync.h2
-rw-r--r--lib/libalpm/trans.c4
-rw-r--r--lib/libalpm/trans.h2
-rw-r--r--src/util/convertdb.c2
13 files changed, 33 insertions, 39 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a81d5406..437715e8 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -64,6 +64,7 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
if(db->dir == NULL) {
if(mode & DB_O_CREATE) {
_alpm_log(PM_LOG_WARNING, "could not open database '%s' -- try creating it", treename);
+ _alpm_log(PM_LOG_DEBUG, "creating database '%s'", treename);
if(mkdir(db->path, 0755) == 0) {
db->dir = opendir(db->path);
}
@@ -83,8 +84,10 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
return(db);
}
-void _alpm_db_close(pmdb_t *db)
+void _alpm_db_close(void *data)
{
+ pmdb_t *db = data;
+
if(db == NULL) {
return;
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index a86940f7..dbade3b0 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -48,7 +48,7 @@ typedef struct __pmdb_t {
} pmdb_t;
pmdb_t *_alpm_db_open(char *path, char *treename, int mode);
-void _alpm_db_close(pmdb_t *db);
+void _alpm_db_close(void *data);
void _alpm_db_rewind(pmdb_t *db);
pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq);
int _alpm_db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info);
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index 5d5ecbba..a77a8eef 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -42,8 +42,10 @@ pmgrp_t *_alpm_grp_new()
return(grp);
}
-void _alpm_grp_free(pmgrp_t *grp)
+void _alpm_grp_free(void *data)
{
+ pmgrp_t *grp = data;
+
if(grp == NULL) {
return;
}
diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h
index 6fa3a24c..e36d3603 100644
--- a/lib/libalpm/group.h
+++ b/lib/libalpm/group.h
@@ -33,16 +33,10 @@ typedef struct __pmgrp_t {
#define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0)
-#define FREELISTGRPS(p) do { \
- PMList *i; \
- for(i = p; i; i = i->next) { \
- FREEGRP(i->data); \
- } \
- FREELIST(p); \
-} while(0)
+#define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free)
pmgrp_t *_alpm_grp_new(void);
-void _alpm_grp_free(pmgrp_t *grp);
+void _alpm_grp_free(void *data);
int _alpm_grp_cmp(const void *g1, const void *g2);
#endif /* _ALPM_GROUP_H */
diff --git a/lib/libalpm/list.c b/lib/libalpm/list.c
index 632ee2a3..0e1c9426 100644
--- a/lib/libalpm/list.c
+++ b/lib/libalpm/list.c
@@ -42,13 +42,15 @@ PMList *_alpm_list_new()
return(list);
}
-void _alpm_list_free(PMList *list)
+void _alpm_list_free(PMList *list, _alpm_fn_free fn)
{
PMList *ptr, *it = list;
while(it) {
ptr = it->next;
- free(it->data);
+ if(fn) {
+ fn(it->data);
+ }
free(it);
it = ptr;
}
diff --git a/lib/libalpm/list.h b/lib/libalpm/list.h
index 0052efc4..7cfc886f 100644
--- a/lib/libalpm/list.h
+++ b/lib/libalpm/list.h
@@ -31,20 +31,16 @@ typedef struct __pmlist_t {
typedef struct __pmlist_t PMList;
-#define FREELIST(p) do { if(p) { _alpm_list_free(p); p = NULL; } } while(0)
-#define FREELISTPTR(p) do { \
- PMList *i; \
- for(i = p; i; i = i->next) { \
- i->data = NULL; \
- } \
- FREELIST(p); \
-} while(0)
+#define _FREELIST(p, f) do { if(p) { _alpm_list_free(p, f); p = NULL; } } while(0)
+#define FREELIST(p) _FREELIST(p, free)
+#define FREELISTPTR(p) _FREELIST(p, NULL)
+typedef void (*_alpm_fn_free) (void *);
/* Sort comparison callback function declaration */
typedef int (*_alpm_fn_cmp) (const void *, const void *);
PMList *_alpm_list_new(void);
-void _alpm_list_free(PMList *list);
+void _alpm_list_free(PMList *list, _alpm_fn_free fn);
PMList *_alpm_list_add(PMList *list, void *data);
PMList *_alpm_list_add_sorted(PMList *list, void *data, _alpm_fn_cmp fn);
PMList *_alpm_list_remove(PMList *haystack, void *needle, _alpm_fn_cmp fn, void **data);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index fe568fe0..4f2bcaaa 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -121,8 +121,10 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
return(newpkg);
}
-void _alpm_pkg_free(pmpkg_t *pkg)
+void _alpm_pkg_free(void *data)
{
+ pmpkg_t *pkg = data;
+
if(pkg == NULL) {
return;
}
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index c22cfe59..2fe60dd7 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -75,20 +75,11 @@ do { \
} \
} while(0)
-#define FREELISTPKGS(p) \
-do { \
- if(p) { \
- PMList *i; \
- for(i = p; i; i = i->next) { \
- FREEPKG(i->data); \
- }\
- FREELIST(p);\
- } \
-} while(0)
+#define FREELISTPKGS(p) _FREELIST(p, _alpm_pkg_free)
pmpkg_t* _alpm_pkg_new(const char *name, const char *version);
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
-void _alpm_pkg_free(pmpkg_t *pkg);
+void _alpm_pkg_free(void *data);
pmpkg_t *_alpm_pkg_load(char *pkgfile);
pmpkg_t *_alpm_pkg_isin(char *needle, PMList *haystack);
int _alpm_pkg_splitname(char *target, char *name, char *version);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 22f49f84..20d50dc2 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -63,8 +63,10 @@ pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data)
return(sync);
}
-void _alpm_sync_free(pmsyncpkg_t *sync)
+void _alpm_sync_free(void *data)
{
+ pmsyncpkg_t *sync = data;
+
if(sync == NULL) {
return;
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 196910ad..29d601b9 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -34,7 +34,7 @@ typedef struct __pmsyncpkg_t {
#define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0)
pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data);
-void _alpm_sync_free(pmsyncpkg_t *sync);
+void _alpm_sync_free(void *data);
PMList *_alpm_sync_load_dbarchive(char *archive);
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index c89abe69..b71d2fae 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -56,8 +56,10 @@ pmtrans_t *_alpm_trans_new()
return(trans);
}
-void _alpm_trans_free(pmtrans_t *trans)
+void _alpm_trans_free(void *data)
{
+ pmtrans_t *trans = data;
+
if(trans == NULL) {
return;
}
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 6b01035d..bddfbf9c 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -62,7 +62,7 @@ do { \
} while(0)
pmtrans_t *_alpm_trans_new(void);
-void _alpm_trans_free(pmtrans_t *trans);
+void _alpm_trans_free(void *data);
int _alpm_trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb_event event, alpm_trans_cb_conv conv);
int _alpm_trans_sysupgrade(pmtrans_t *trans);
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
diff --git a/src/util/convertdb.c b/src/util/convertdb.c
index 4d3f901d..b858466d 100644
--- a/src/util/convertdb.c
+++ b/src/util/convertdb.c
@@ -134,7 +134,7 @@ int main(int argc, char* argv[])
snprintf(line, PATH_MAX, "/bin/cp %s %s/install", path, topdir);
system(line);
}
- _alpm_list_free(backup);
+ _alpm_list_free(backup, free);
}
umask(oldumask);
return(0);