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);
}
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;

View File

@ -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(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
*/
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;

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_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);

View File

@ -443,7 +443,7 @@ static int 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);
}

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);
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 *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;

View File

@ -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) {

View File

@ -369,7 +369,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;
@ -383,7 +383,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);
@ -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_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
_alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* init progress bar */
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 *deltas = NULL;
int replaces = 0;
size_t replaces = 0;
int errors = 0;
const char *cachedir = NULL;
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 */
void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
int howmany, int remain)
size_t howmany, size_t current)
{
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;
@ -402,7 +403,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
* done here to figure out the actual number of screen columns used
* by the output, and then pad it accordingly so we fill the terminal.
*/
/* len = opr len + pkgname len (if available) + space + null */
/* len = opr len + pkgname len (if available) + space + null */
len = strlen(opr) + ((pkgname) ? strlen(pkgname) : 0) + 2;
wcstr = calloc(len, sizeof(wchar_t));
/* print our strings to the alloc'ed memory */
@ -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,
wcstr, padwid, "");
printf("(%*ld/%*ld) %ls%-*s", digits, (unsigned long)current,
digits, (unsigned long)howmany, wcstr, padwid, "");
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 */
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);