[pacman-dev] [PATCH] Use size_t for alpm_list sizes

Allan McRae allan at archlinux.org
Wed Dec 8 02:07:15 EST 2010


There is a lot of swtiching between size_t and int for alpm_list sizes
in the codebase.   Start converting these to all be size_t by adjusting
the return type of alpm_list_count and fixing all additional warnings
given by -Wconversion that are generated by this change.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 lib/libalpm/add.c       |    4 ++--
 lib/libalpm/alpm.h      |    2 +-
 lib/libalpm/alpm_list.c |    8 ++++----
 lib/libalpm/alpm_list.h |    6 +++---
 lib/libalpm/be_local.c  |    2 +-
 lib/libalpm/be_sync.c   |    2 +-
 lib/libalpm/conflict.c  |    4 ++--
 lib/libalpm/diskspace.c |    6 +++---
 lib/libalpm/remove.c    |    6 +++---
 lib/libalpm/sync.c      |    2 +-
 src/pacman/callback.c   |    5 +++--
 src/pacman/callback.h   |    2 +-
 12 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index b0b5a53..31a7928 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -477,7 +477,7 @@ static int extract_single_file(struct archive *archive,
 	return(errors);
 }
 
-static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
+static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current, size_t pkg_count,
 		pmtrans_t *trans, pmdb_t *db)
 {
 	int i, ret = 0, errors = 0;
@@ -715,7 +715,7 @@ cleanup:
 
 int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
 {
-	int pkg_count, pkg_current;
+	size_t pkg_count, pkg_current;
 	int skip_ldconfig = 0, ret = 0;
 	alpm_list_t *targ;
 
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 08d0269..86212a4 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -405,7 +405,7 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
                                    void *, int *);
 
 /* Transaction Progress callback */
-typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
+typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t);
 
 int alpm_trans_get_flags();
 alpm_list_t * alpm_trans_get_add();
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 80ba1ee..185295c 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -269,7 +269,7 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, a
  *
  * @return the resultant list
  */
-alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn)
+alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn_cmp fn)
 {
 	if (n > 1) {
 		alpm_list_t *left = list;
@@ -511,7 +511,7 @@ inline alpm_list_t SYMEXPORT *alpm_list_first(const alpm_list_t *list)
  *
  * @return an alpm_list_t node for index `n`
  */
-alpm_list_t SYMEXPORT *alpm_list_nth(const alpm_list_t *list, int n)
+alpm_list_t SYMEXPORT *alpm_list_nth(const alpm_list_t *list, size_t n)
 {
 	const alpm_list_t *i = list;
 	while(n--) {
@@ -574,9 +574,9 @@ void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
  *
  * @return the number of list items
  */
-int SYMEXPORT alpm_list_count(const alpm_list_t *list)
+size_t SYMEXPORT alpm_list_count(const alpm_list_t *list)
 {
-	unsigned int i = 0;
+	size_t i = 0;
 	const alpm_list_t *lp = list;
 	while(lp) {
 		++i;
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index bd639f7..19fe548 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -56,7 +56,7 @@ alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
 alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn);
 alpm_list_t *alpm_list_join(alpm_list_t *first, alpm_list_t *second);
 alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
-alpm_list_t *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn);
+alpm_list_t *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn_cmp fn);
 alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);
 alpm_list_t *alpm_list_remove_str(alpm_list_t *haystack, const char *needle, char **data);
 alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list);
@@ -67,13 +67,13 @@ alpm_list_t *alpm_list_reverse(alpm_list_t *list);
 
 /* item accessors */
 alpm_list_t *alpm_list_first(const alpm_list_t *list);
-alpm_list_t *alpm_list_nth(const alpm_list_t *list, int n);
+alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
 alpm_list_t *alpm_list_next(const alpm_list_t *list);
 alpm_list_t *alpm_list_last(const alpm_list_t *list);
 void *alpm_list_getdata(const alpm_list_t *entry);
 
 /* misc */
-int alpm_list_count(const alpm_list_t *list);
+size_t alpm_list_count(const alpm_list_t *list);
 void *alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn);
 void *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle);
 char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 9dce66d..fec8979 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -422,7 +422,7 @@ int _alpm_local_db_populate(pmdb_t *db)
 	}
 
 	closedir(dbdir);
-	db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
+	db->pkgcache = alpm_list_msort(db->pkgcache, (size_t)count, _alpm_pkg_cmp);
 	return(count);
 }
 
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index b6c9937..5951f2f 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -191,7 +191,7 @@ int _alpm_sync_db_populate(pmdb_t *db)
 		}
 	}
 
-	db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
+	db->pkgcache = alpm_list_msort(db->pkgcache, (size_t)count, _alpm_pkg_cmp);
 	archive_read_finish(archive);
 
 	return(count);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 2b0efa5..e64a00b 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -402,8 +402,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
 		alpm_list_t *upgrade, alpm_list_t *remove)
 {
 	alpm_list_t *i, *j, *conflicts = NULL;
-	int numtargs = alpm_list_count(upgrade);
-	int current;
+	size_t numtargs = alpm_list_count(upgrade);
+	size_t current;
 
 	ALPM_LOG_FUNC;
 
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index 5ed8e0b..728fd2c 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -243,11 +243,11 @@ cleanup:
 int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
 {
 	alpm_list_t *mount_points, *i;
-	int replaces = 0, abort = 0;
+	size_t replaces = 0, current = 0;
+	int abort = 0;
 	alpm_list_t *targ;
 	pmpkg_t *pkg;
-	int numtargs = alpm_list_count(trans->add);
-	int current = 0;
+	size_t numtargs = alpm_list_count(trans->add);
 
 	mount_points = mount_point_list();
 	if(mount_points == NULL) {
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 90848dc..fa870c1 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -368,7 +368,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 {
 	pmpkg_t *info;
 	alpm_list_t *targ, *lp;
-	int pkg_count;
+	size_t pkg_count;
 
 	ALPM_LOG_FUNC;
 
@@ -382,7 +382,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 		char scriptlet[PATH_MAX];
 		info = (pmpkg_t*)targ->data;
 		const char *pkgname = NULL;
-		int targcount = alpm_list_count(targ);
+		size_t targcount = alpm_list_count(targ);
 
 		if(handle->trans->state == STATE_INTERRUPTED) {
 			return(0);
@@ -413,7 +413,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 				}
 			}
 
-			int filenum = alpm_list_count(files);
+			size_t filenum = alpm_list_count(files);
 			alpm_list_t *newfiles;
 			_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
 
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 8af32e4..2d0a899 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -801,7 +801,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 {
 	alpm_list_t *i, *j, *files = NULL;
 	alpm_list_t *deltas = NULL;
-	int replaces = 0;
+	size_t replaces = 0;
 	int errors = 0;
 	const char *cachedir = NULL;
 	int ret = -1;
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index c8f604f..ec4a683 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -325,13 +325,14 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
 
 /* callback to handle display of transaction progress */
 void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
-                       int howmany, int remain)
+                       size_t howmany, size_t remain)
 {
 	float timediff;
 
 	/* size of line to allocate for text printing (e.g. not progressbar) */
 	int infolen;
-	int tmp, digits, textlen;
+	int digits, textlen;
+	size_t tmp;
 	char *opr = NULL;
 	/* used for wide character width determination and printing */
 	int len, wclen, wcwid, padwid;
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index c56eaa7..09fe8bd 100644
--- a/src/pacman/callback.h
+++ b/src/pacman/callback.h
@@ -33,7 +33,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
 
 /* callback to handle display of transaction progress */
 void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
-                   int howmany, int remain);
+                   size_t howmany, size_t remain);
 
 /* callback to handle receipt of total download value */
 void cb_dl_total(off_t total);
-- 
1.7.3.3



More information about the pacman-dev mailing list