From: Adam Dickmeiss Date: Wed, 7 Jun 2006 10:14:39 +0000 (+0000) Subject: Use CAST_ZINT_TO_INT in some places, so we can easily spot casts X-Git-Tag: before.bug.529~78 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=0af00389d43835ef54928dc22f7d34ae30f3c723;p=idzebra-moved-to-github.git Use CAST_ZINT_TO_INT in some places, so we can easily spot casts --- diff --git a/bfile/mfile.c b/bfile/mfile.c index b5b125e..2f6500f 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,5 +1,5 @@ -/* $Id: mfile.c,v 1.65 2006-05-10 08:13:17 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: mfile.c,v 1.66 2006-06-07 10:14:39 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -628,9 +628,15 @@ int mf_area_directory_stat(MFile_area ma, int no, const char **directory, if (directory) *directory = d->name; if (max_bytes) - *max_bytes = d->max_bytes; + { + /* possible loss of data. But it's just statistics and lies */ + *max_bytes = (double) d->max_bytes; + } if (used_bytes) - *used_bytes = d->max_bytes - d->avail_bytes; + { + /* possible loss of data. But it's just statistics and lies */ + *used_bytes = (double) (d->max_bytes - d->avail_bytes); + } return 1; } /* diff --git a/include/idzebra/api.h b/include/idzebra/api.h index 19f2c16..fb6efea 100644 --- a/include/idzebra/api.h +++ b/include/idzebra/api.h @@ -1,4 +1,4 @@ -/* $Id: api.h,v 1.35 2006-05-30 13:21:13 adam Exp $ +/* $Id: api.h,v 1.36 2006-06-07 10:14:40 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -53,10 +53,10 @@ YAZ_BEGIN_CDECL #endif typedef struct { - int processed; - int inserted; - int updated; - int deleted; + zint processed; + zint inserted; + zint updated; + zint deleted; long utime; long stime; } ZebraTransactionStatus; diff --git a/include/idzebra/recctrl.h b/include/idzebra/recctrl.h index 4ad6157..3f20cb0 100644 --- a/include/idzebra/recctrl.h +++ b/include/idzebra/recctrl.h @@ -1,4 +1,4 @@ -/* $Id: recctrl.h,v 1.20 2006-05-19 13:49:34 adam Exp $ +/* $Id: recctrl.h,v 1.21 2006-06-07 10:14:40 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -79,7 +79,7 @@ struct recExtractCtrl { int flagShowRecords; int seqno[256]; char match_criteria[256]; - int staticrank; + zint staticrank; void (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid); data1_handle dh; void *handle; diff --git a/index/extract.c b/index/extract.c index a980bcf..8d4cd9c 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.218 2006-05-30 13:44:44 adam Exp $ +/* $Id: extract.c,v 1.219 2006-06-07 10:14:40 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -145,7 +145,7 @@ static void searchRecordKey(ZebraHandle zh, if (zebra_rec_keys_rewind(reckeys)) { - int startSeq = -1; + zint startSeq = -1; const char *str; size_t slen; struct it_key key; @@ -158,7 +158,7 @@ static void searchRecordKey(ZebraHandle zh, if (key.mem[0] == ch) { - int woff; + zint woff; if (startSeq == -1) startSeq = seqno; @@ -1300,7 +1300,7 @@ void extract_rec_keys_adjust(ZebraHandle zh, int is_insert, struct it_key key_in; while(zebra_rec_keys_read(reckeys, &str, &slen, &key_in)) { - int ord = key_in.mem[0]; + int ord = CAST_ZINT_TO_INT(key_in.mem[0]); for (p = ord_list; p ; p = p->next) if (p->ord == ord) @@ -1384,7 +1384,7 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, (char*)zh->reg->key_buf + zh->reg->key_buf_used; /* encode the ordinal value (field/use/attribute) .. */ - ch = (int) key_in.mem[0]; + ch = CAST_ZINT_TO_INT(key_in.mem[0]); zh->reg->key_buf_used += key_SU_encode(ch, (char*)zh->reg->key_buf + zh->reg->key_buf_used); @@ -1573,11 +1573,13 @@ ZEBRA_RES zebra_snippets_rec_keys(ZebraHandle zh, { char dst_buf[IT_MAX_WORD]; char *dst_term = dst_buf; - int ord, seqno; + int ord; + zint seqno; int index_type; + assert(key.len <= 4 && key.len > 2); - seqno = (int) key.mem[key.len-1]; - ord = key.mem[0]; + seqno = key.mem[key.len-1]; + ord = CAST_ZINT_TO_INT(key.mem[0]); zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, 0/* db */, 0 /* string_index */); @@ -1603,20 +1605,20 @@ void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys) while (zebra_rec_keys_read(reckeys, &str, &slen, &key)) { char dst_buf[IT_MAX_WORD]; - int seqno; + zint seqno; int index_type; + int ord = CAST_ZINT_TO_INT(key.mem[0]); const char *db = 0; assert(key.len <= 4 && key.len > 2); - zebraExplain_lookup_ord(zh->reg->zei, - key.mem[0], &index_type, &db, 0); + zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db, 0); - seqno = (int) key.mem[key.len-1]; + seqno = key.mem[key.len-1]; zebra_term_untrans(zh, index_type, dst_buf, str); - yaz_log(YLOG_LOG, "ord=" ZINT_FORMAT " seqno=%d term=%s", - key.mem[0], seqno, dst_buf); + yaz_log(YLOG_LOG, "ord=%d seqno=" ZINT_FORMAT + " term=%s", ord, seqno, dst_buf); } } } @@ -1887,7 +1889,7 @@ void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno, while (zebra_rec_keys_read(reckeys, &str, &slen, &key_in)) { - int ord = (int) key_in.mem[0]; + int ord = CAST_ZINT_TO_INT(key_in.mem[0]); sortIdx_type(sortIdx, ord); if (cmd == 1) diff --git a/index/invstat.c b/index/invstat.c index 8a1cf1a..df2af05 100644 --- a/index/invstat.c +++ b/index/invstat.c @@ -1,4 +1,4 @@ -/* $Id: invstat.c,v 1.51 2006-05-19 23:20:24 adam Exp $ +/* $Id: invstat.c,v 1.52 2006-06-07 10:14:41 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -120,7 +120,7 @@ static int inv_stat_handle (char *name, const char *info, int pos, { ISAMB_PP pp; struct it_key key; - int cat = (int) (isam_p & 3); + int cat = CAST_ZINT_TO_INT(isam_p & 3); int level; zint size; zint blocks; @@ -242,13 +242,13 @@ int zebra_register_statistics (ZebraHandle zh, int dumpdict) stat_info.no_isam_entries[i]); if (stat_info.no_isam_entries[i]) - fprintf (stdout, " %8d %f", - (int) ((1023.0 + (double) - isamc_block_used(zh->reg->isamc, i) * - isamc_block_size(zh->reg->isamc,i))/1024), - ((double) isamc_block_used(zh->reg->isamc, i) * + fprintf(stdout, " %8d %f", + (int) ((1023.0 + (double) + isamc_block_used(zh->reg->isamc, i) * + isamc_block_size(zh->reg->isamc,i))/1024), + ((double) isamc_block_used(zh->reg->isamc, i) * isamc_block_size(zh->reg->isamc,i))/ - stat_info.no_isam_entries[i]); + stat_info.no_isam_entries[i]); fprintf (stdout, "\n"); } } diff --git a/index/recindex.c b/index/recindex.c index a888c85..c3f560e 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,4 +1,4 @@ -/* $Id: recindex.c,v 1.49 2006-05-10 12:30:02 adam Exp $ +/* $Id: recindex.c,v 1.50 2006-06-07 10:14:41 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -106,7 +106,7 @@ static int read_indx(Records p, SYSNO sysno, void *buf, int itemsize, { int r; zint pos = (sysno-1)*itemsize; - int off = (int) (pos%RIDX_CHUNK); + int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK); int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ if (sz1 > itemsize) @@ -127,7 +127,7 @@ static int read_indx(Records p, SYSNO sysno, void *buf, int itemsize, static void write_indx(Records p, SYSNO sysno, void *buf, int itemsize) { zint pos = (sysno-1)*itemsize; - int off = (int) (pos%RIDX_CHUNK); + int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK); int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ if (sz1 > itemsize) @@ -152,7 +152,7 @@ static ZEBRA_RES rec_release_blocks(Records p, SYSNO sysno) freeblock = entry.next; assert(freeblock > 0); - dst_type = (int) (freeblock & 7); + dst_type = CAST_ZINT_TO_INT(freeblock & 7); assert(dst_type < REC_BLOCK_TYPES); freeblock = freeblock / 8; while (freeblock) @@ -259,7 +259,8 @@ static ZEBRA_RES rec_write_tmp_buf(Records p, int size, SYSNO *sysnos) cptr = p->tmp_buf + no_written; } block_prev = block_free; - no_written += (int)(p->head.block_size[dst_type]) - sizeof(zint); + no_written += CAST_ZINT_TO_INT(p->head.block_size[dst_type]) + - sizeof(zint); p->head.block_used[dst_type]++; } assert(block_prev != -1); @@ -345,9 +346,9 @@ Records rec_open(BFiles bfs, int rw, int compression_method) } for (i = 0; idata_BFile[i] = bf_open(bfs, p->data_fname[i], - (int) (p->head.block_size[i]), - rw))) + if (!(p->data_BFile[i] = + bf_open(bfs, p->data_fname[i], + CAST_ZINT_TO_INT(p->head.block_size[i]), rw))) { yaz_log(YLOG_FATAL|YLOG_ERRNO, "bf_open %s", p->data_fname[i]); ret = ZEBRA_FAIL; @@ -432,7 +433,7 @@ static void rec_cache_flush_block1(Records p, Record rec, Record last_rec, for (i = 0; isize[i] + 20 > *out_size) + if (*out_offset + CAST_ZINT_TO_INT(rec->size[i]) + 20 > *out_size) { int new_size = *out_offset + rec->size[i] + 65536; char *np = (char *) xmalloc(new_size); diff --git a/index/reckeys.c b/index/reckeys.c index bf83a65..649ec1c 100644 --- a/index/reckeys.c +++ b/index/reckeys.c @@ -1,4 +1,4 @@ -/* $Id: reckeys.c,v 1.5 2006-05-22 13:28:00 adam Exp $ +/* $Id: reckeys.c,v 1.6 2006-06-07 10:14:41 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -58,10 +58,11 @@ struct zebra_rec_key_entry **zebra_rec_keys_mk_hash(zebra_rec_keys_t p, { unsigned h = 0; size_t i; + int j; for (i = 0; ilen; i++) - h = h * 65509 + key->mem[i]; + for (j = 0; jlen; j++) + h = h * 65509 + CAST_ZINT_TO_INT(key->mem[j]); return &p->entries[h % (unsigned) p->hash_size]; } diff --git a/index/retrieve.c b/index/retrieve.c index 6492745..f0183c7 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,5 +1,5 @@ -/* $Id: retrieve.c,v 1.41 2006-05-19 23:20:24 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: retrieve.c,v 1.42 2006-06-07 10:14:41 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -145,7 +145,7 @@ int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, while(zebra_rec_keys_read(keys, &str, &slen, &key_in)) { int i; - int ord = key_in.mem[0]; + int ord = CAST_ZINT_TO_INT(key_in.mem[0]); int index_type; const char *db = 0; int set = 0; diff --git a/index/zebraapi.c b/index/zebraapi.c index 33980ce..4ef13f8 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.219 2006-05-30 13:21:16 adam Exp $ +/* $Id: zebraapi.c,v 1.220 2006-06-07 10:14:41 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -1901,10 +1901,10 @@ ZEBRA_RES zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status) zh->records_processed, zh->records_inserted, zh->records_updated, zh->records_deleted); - status->processed = (int) zh->records_processed; - status->inserted = (int) zh->records_inserted; - status->updated = (int) zh->records_updated; - status->deleted = (int) zh->records_deleted; + status->processed = zh->records_processed; + status->inserted = zh->records_inserted; + status->updated = zh->records_updated; + status->deleted = zh->records_deleted; zebra_get_state (zh, &val, &seqno); if (val != 'd') diff --git a/index/zserver.c b/index/zserver.c index 8989087..129fbe2 100644 --- a/index/zserver.c +++ b/index/zserver.c @@ -1,5 +1,5 @@ -/* $Id: zserver.c,v 1.146 2006-05-10 08:13:23 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: zserver.c,v 1.147 2006-06-07 10:14:41 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -251,15 +251,15 @@ static void search_terms(ZebraHandle zh, bend_search_rr *r) se->subqueryExpression->u.term->termComment = 0; se->subqueryInterpretation = 0; se->subqueryRecommendation = 0; - if (count > 2000000000) - count = 2000000000; - se->subqueryCount = odr_intdup(r->stream, (int) count); + if (count > 2147483646) + count = 2147483647; + se->subqueryCount = odr_intdup(r->stream, CAST_ZINT_TO_INT(count)); se->subqueryWeight = 0; se->resultsByDB = 0; } } -int bend_search (void *handle, bend_search_rr *r) +int bend_search(void *handle, bend_search_rr *r) { ZebraHandle zh = (ZebraHandle) handle; zint zhits = 0; @@ -282,10 +282,9 @@ int bend_search (void *handle, bend_search_rr *r) zebra_result(zh, &r->errcode, &r->errstring); else { - if (zhits > 2147483646) - r->hits = 2147483647; - else - r->hits = (int) zhits; + if (zhits > 2147483646) + zhits = 2147483647; + r->hits = CAST_ZINT_TO_INT(zhits); search_terms (zh, r); } break; diff --git a/index/zsets.c b/index/zsets.c index 5d0be02..a8d8ce9 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.106 2006-06-06 21:01:30 adam Exp $ +/* $Id: zsets.c,v 1.107 2006-06-07 10:14:42 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -954,7 +954,7 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet, { RSFD rfd = rset_open(rset, RSETF_READ); struct rank_control *rc = rank_class->control; - double score; + int score; zint count = 0; void *handle = diff --git a/util/snippet.c b/util/snippet.c index 3bc028e..b900c1b 100644 --- a/util/snippet.c +++ b/util/snippet.c @@ -1,5 +1,5 @@ -/* $Id: snippet.c,v 1.6 2006-05-10 08:13:46 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: snippet.c,v 1.7 2006-06-07 10:14:42 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server.