improved _alpm_list_free handling
This commit is contained in:
parent
78ffd98701
commit
16ff7cfa8e
13 changed files with 33 additions and 39 deletions
|
@ -64,6 +64,7 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
|
||||||
if(db->dir == NULL) {
|
if(db->dir == NULL) {
|
||||||
if(mode & DB_O_CREATE) {
|
if(mode & DB_O_CREATE) {
|
||||||
_alpm_log(PM_LOG_WARNING, "could not open database '%s' -- try creating it", treename);
|
_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) {
|
if(mkdir(db->path, 0755) == 0) {
|
||||||
db->dir = opendir(db->path);
|
db->dir = opendir(db->path);
|
||||||
}
|
}
|
||||||
|
@ -83,8 +84,10 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
|
||||||
return(db);
|
return(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_db_close(pmdb_t *db)
|
void _alpm_db_close(void *data)
|
||||||
{
|
{
|
||||||
|
pmdb_t *db = data;
|
||||||
|
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ typedef struct __pmdb_t {
|
||||||
} pmdb_t;
|
} pmdb_t;
|
||||||
|
|
||||||
pmdb_t *_alpm_db_open(char *path, char *treename, int mode);
|
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);
|
void _alpm_db_rewind(pmdb_t *db);
|
||||||
pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq);
|
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);
|
int _alpm_db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info);
|
||||||
|
|
|
@ -42,8 +42,10 @@ pmgrp_t *_alpm_grp_new()
|
||||||
return(grp);
|
return(grp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_grp_free(pmgrp_t *grp)
|
void _alpm_grp_free(void *data)
|
||||||
{
|
{
|
||||||
|
pmgrp_t *grp = data;
|
||||||
|
|
||||||
if(grp == NULL) {
|
if(grp == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,10 @@ typedef struct __pmgrp_t {
|
||||||
|
|
||||||
#define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0)
|
#define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0)
|
||||||
|
|
||||||
#define FREELISTGRPS(p) do { \
|
#define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free)
|
||||||
PMList *i; \
|
|
||||||
for(i = p; i; i = i->next) { \
|
|
||||||
FREEGRP(i->data); \
|
|
||||||
} \
|
|
||||||
FREELIST(p); \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
pmgrp_t *_alpm_grp_new(void);
|
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);
|
int _alpm_grp_cmp(const void *g1, const void *g2);
|
||||||
|
|
||||||
#endif /* _ALPM_GROUP_H */
|
#endif /* _ALPM_GROUP_H */
|
||||||
|
|
|
@ -42,13 +42,15 @@ PMList *_alpm_list_new()
|
||||||
return(list);
|
return(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_list_free(PMList *list)
|
void _alpm_list_free(PMList *list, _alpm_fn_free fn)
|
||||||
{
|
{
|
||||||
PMList *ptr, *it = list;
|
PMList *ptr, *it = list;
|
||||||
|
|
||||||
while(it) {
|
while(it) {
|
||||||
ptr = it->next;
|
ptr = it->next;
|
||||||
free(it->data);
|
if(fn) {
|
||||||
|
fn(it->data);
|
||||||
|
}
|
||||||
free(it);
|
free(it);
|
||||||
it = ptr;
|
it = ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,20 +31,16 @@ typedef struct __pmlist_t {
|
||||||
|
|
||||||
typedef struct __pmlist_t PMList;
|
typedef struct __pmlist_t PMList;
|
||||||
|
|
||||||
#define FREELIST(p) do { if(p) { _alpm_list_free(p); p = NULL; } } while(0)
|
#define _FREELIST(p, f) do { if(p) { _alpm_list_free(p, f); p = NULL; } } while(0)
|
||||||
#define FREELISTPTR(p) do { \
|
#define FREELIST(p) _FREELIST(p, free)
|
||||||
PMList *i; \
|
#define FREELISTPTR(p) _FREELIST(p, NULL)
|
||||||
for(i = p; i; i = i->next) { \
|
|
||||||
i->data = NULL; \
|
|
||||||
} \
|
|
||||||
FREELIST(p); \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
|
typedef void (*_alpm_fn_free) (void *);
|
||||||
/* Sort comparison callback function declaration */
|
/* Sort comparison callback function declaration */
|
||||||
typedef int (*_alpm_fn_cmp) (const void *, const void *);
|
typedef int (*_alpm_fn_cmp) (const void *, const void *);
|
||||||
|
|
||||||
PMList *_alpm_list_new(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(PMList *list, void *data);
|
||||||
PMList *_alpm_list_add_sorted(PMList *list, void *data, _alpm_fn_cmp fn);
|
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);
|
PMList *_alpm_list_remove(PMList *haystack, void *needle, _alpm_fn_cmp fn, void **data);
|
||||||
|
|
|
@ -121,8 +121,10 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
|
||||||
return(newpkg);
|
return(newpkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_pkg_free(pmpkg_t *pkg)
|
void _alpm_pkg_free(void *data)
|
||||||
{
|
{
|
||||||
|
pmpkg_t *pkg = data;
|
||||||
|
|
||||||
if(pkg == NULL) {
|
if(pkg == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,20 +75,11 @@ do { \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define FREELISTPKGS(p) \
|
#define FREELISTPKGS(p) _FREELIST(p, _alpm_pkg_free)
|
||||||
do { \
|
|
||||||
if(p) { \
|
|
||||||
PMList *i; \
|
|
||||||
for(i = p; i; i = i->next) { \
|
|
||||||
FREEPKG(i->data); \
|
|
||||||
}\
|
|
||||||
FREELIST(p);\
|
|
||||||
} \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
pmpkg_t* _alpm_pkg_new(const char *name, const char *version);
|
pmpkg_t* _alpm_pkg_new(const char *name, const char *version);
|
||||||
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
|
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_load(char *pkgfile);
|
||||||
pmpkg_t *_alpm_pkg_isin(char *needle, PMList *haystack);
|
pmpkg_t *_alpm_pkg_isin(char *needle, PMList *haystack);
|
||||||
int _alpm_pkg_splitname(char *target, char *name, char *version);
|
int _alpm_pkg_splitname(char *target, char *name, char *version);
|
||||||
|
|
|
@ -63,8 +63,10 @@ pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data)
|
||||||
return(sync);
|
return(sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_sync_free(pmsyncpkg_t *sync)
|
void _alpm_sync_free(void *data)
|
||||||
{
|
{
|
||||||
|
pmsyncpkg_t *sync = data;
|
||||||
|
|
||||||
if(sync == NULL) {
|
if(sync == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ typedef struct __pmsyncpkg_t {
|
||||||
#define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0)
|
#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);
|
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);
|
PMList *_alpm_sync_load_dbarchive(char *archive);
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,10 @@ pmtrans_t *_alpm_trans_new()
|
||||||
return(trans);
|
return(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _alpm_trans_free(pmtrans_t *trans)
|
void _alpm_trans_free(void *data)
|
||||||
{
|
{
|
||||||
|
pmtrans_t *trans = data;
|
||||||
|
|
||||||
if(trans == NULL) {
|
if(trans == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ do { \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
pmtrans_t *_alpm_trans_new(void);
|
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_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_sysupgrade(pmtrans_t *trans);
|
||||||
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
|
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
|
||||||
|
|
|
@ -134,7 +134,7 @@ int main(int argc, char* argv[])
|
||||||
snprintf(line, PATH_MAX, "/bin/cp %s %s/install", path, topdir);
|
snprintf(line, PATH_MAX, "/bin/cp %s %s/install", path, topdir);
|
||||||
system(line);
|
system(line);
|
||||||
}
|
}
|
||||||
_alpm_list_free(backup);
|
_alpm_list_free(backup, free);
|
||||||
}
|
}
|
||||||
umask(oldumask);
|
umask(oldumask);
|
||||||
return(0);
|
return(0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue