Use size_t for alpm_list sizes

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.

Dan: a few more small changes to ensure things compile, adjusting some
printf format string characters to accommodate the larger size on x86_64.

Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2010-12-08 15:13:36 +10:00 committed by Dan McGee
parent 4bc6ed56aa
commit f966f3a834
12 changed files with 29 additions and 28 deletions

View file

@ -477,7 +477,7 @@ static int extract_single_file(struct archive *archive,
return(errors); 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) pmtrans_t *trans, pmdb_t *db)
{ {
int i, ret = 0, errors = 0; int i, ret = 0, errors = 0;
@ -715,7 +715,7 @@ cleanup:
int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db) 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; int skip_ldconfig = 0, ret = 0;
alpm_list_t *targ; alpm_list_t *targ;

View file

@ -405,7 +405,7 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
void *, int *); void *, int *);
/* Transaction Progress callback */ /* 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(void); int alpm_trans_get_flags(void);
alpm_list_t * alpm_trans_get_add(void); alpm_list_t * alpm_trans_get_add(void);

View file

@ -269,7 +269,7 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, a
* *
* @return the resultant list * @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) { if (n > 1) {
alpm_list_t *left = list; 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` * @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; const alpm_list_t *i = list;
while(n--) { while(n--) {
@ -574,9 +574,9 @@ void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
* *
* @return the number of list items * @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; const alpm_list_t *lp = list;
while(lp) { while(lp) {
++i; ++i;

View file

@ -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_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_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_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(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_str(alpm_list_t *haystack, const char *needle, char **data);
alpm_list_t *alpm_list_remove_dupes(const alpm_list_t *list); 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 */ /* item accessors */
alpm_list_t *alpm_list_first(const alpm_list_t *list); 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_next(const alpm_list_t *list);
alpm_list_t *alpm_list_last(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); void *alpm_list_getdata(const alpm_list_t *entry);
/* misc */ /* 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(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); 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); char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);

View file

@ -443,7 +443,7 @@ static int local_db_populate(pmdb_t *db)
} }
closedir(dbdir); 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); return(count);
} }

View file

@ -212,7 +212,7 @@ static int 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); archive_read_finish(archive);
return(count); return(count);

View file

@ -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 *upgrade, alpm_list_t *remove)
{ {
alpm_list_t *i, *j, *conflicts = NULL; alpm_list_t *i, *j, *conflicts = NULL;
int numtargs = alpm_list_count(upgrade); size_t numtargs = alpm_list_count(upgrade);
int current; size_t current;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;

View file

@ -243,11 +243,11 @@ cleanup:
int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local) int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
{ {
alpm_list_t *mount_points, *i; alpm_list_t *mount_points, *i;
int replaces = 0, abort = 0; size_t replaces = 0, current = 0;
int abort = 0;
alpm_list_t *targ; alpm_list_t *targ;
pmpkg_t *pkg; pmpkg_t *pkg;
int numtargs = alpm_list_count(trans->add); size_t numtargs = alpm_list_count(trans->add);
int current = 0;
mount_points = mount_point_list(); mount_points = mount_point_list();
if(mount_points == NULL) { if(mount_points == NULL) {

View file

@ -369,7 +369,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
{ {
pmpkg_t *info; pmpkg_t *info;
alpm_list_t *targ, *lp; alpm_list_t *targ, *lp;
int pkg_count; size_t pkg_count;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
@ -383,7 +383,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
char scriptlet[PATH_MAX]; char scriptlet[PATH_MAX];
info = (pmpkg_t*)targ->data; info = (pmpkg_t*)targ->data;
const char *pkgname = NULL; const char *pkgname = NULL;
int targcount = alpm_list_count(targ); size_t targcount = alpm_list_count(targ);
if(handle->trans->state == STATE_INTERRUPTED) { if(handle->trans->state == STATE_INTERRUPTED) {
return(0); return(0);
@ -414,9 +414,9 @@ 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_list_t *newfiles;
_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum); _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* init progress bar */ /* init progress bar */
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0, PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0,

View file

@ -822,7 +822,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 *i, *j, *files = NULL;
alpm_list_t *deltas = NULL; alpm_list_t *deltas = NULL;
int replaces = 0; size_t replaces = 0;
int errors = 0; int errors = 0;
const char *cachedir = NULL; const char *cachedir = NULL;
int ret = -1; int ret = -1;

View file

@ -325,13 +325,14 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
/* callback to handle display of transaction progress */ /* callback to handle display of transaction progress */
void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
int howmany, int remain) size_t howmany, size_t current)
{ {
float timediff; float timediff;
/* size of line to allocate for text printing (e.g. not progressbar) */ /* size of line to allocate for text printing (e.g. not progressbar) */
int infolen; int infolen;
int tmp, digits, textlen; int digits, textlen;
size_t tmp;
char *opr = NULL; char *opr = NULL;
/* used for wide character width determination and printing */ /* used for wide character width determination and printing */
int len, wclen, wcwid, padwid; int len, wclen, wcwid, padwid;
@ -434,8 +435,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
} }
printf("(%*d/%*d) %ls%-*s", digits, remain, digits, howmany, printf("(%*ld/%*ld) %ls%-*s", digits, (unsigned long)current,
wcstr, padwid, ""); digits, (unsigned long)howmany, wcstr, padwid, "");
free(wcstr); free(wcstr);

View file

@ -33,7 +33,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
/* callback to handle display of transaction progress */ /* callback to handle display of transaction progress */
void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, 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 */ /* callback to handle receipt of total download value */
void cb_dl_total(off_t total); void cb_dl_total(off_t total);