Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Silence compiler warnings #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/F2matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ matrix constructMat(u_int32_t cols, u_int32_t rows)
exit(1);
}

for (int32_t i = 0; i < rows; i++) //make second matrix identity, i.e. 1's along diagonal
for (u_int32_t i = 0; i < rows; i++) //make second matrix identity, i.e. 1's along diagonal
{
insertEntry(m,i,i+32*dwords);
}
Expand Down
64 changes: 31 additions & 33 deletions src/QS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ unsigned long knuthSchroeppel(mpz_t n)
float factors[NUMMULTS];
float logpdivp;
mpz_t prime, r, mult;
long kron, multindex;
long kron;
size_t multindex;

mpz_init(prime);
mpz_init(r);
Expand Down Expand Up @@ -503,14 +504,12 @@ void tonelliShanks(unsigned long numPrimes,mpz_t n)
===========================================================================*/
void evaluateSieve(unsigned long ** relations, unsigned long ctimesreps, unsigned long M, unsigned char * sieve, mpz_t A, mpz_t B, mpz_t C, unsigned long * soln1, unsigned long * soln2, long polyadd, unsigned long * polycorr, mpz_t * XArr, unsigned long * aind, long min, long s,unsigned long multiplier, long * exponents, la_col_t* colarray, unsigned long * factors, char * rel_str, FILE* LPNEW,FILE* RELS)
{
long i,j;
register unsigned long k;
unsigned long i, j, k;
unsigned long exponent, vv;
unsigned char extra;
register unsigned long modp;
unsigned long modp;
unsigned long * sieve2;
unsigned char bits;
long numfactors;
unsigned long factnum;
char * last_ptr;
char Q_str[200];
Expand Down Expand Up @@ -547,8 +546,6 @@ void evaluateSieve(unsigned long ** relations, unsigned long ctimesreps, unsigne
bits=mpz_sizeinbase(res,2);
bits-=errorbits;

numfactors=0;

extra = 0;
if (factorBase[0]!=1)
{
Expand Down Expand Up @@ -732,7 +729,7 @@ void evaluateSieve(unsigned long ** relations, unsigned long ctimesreps, unsigne
#ifdef RELPRINT
printf("....R\n");
#endif
for (long i = 0; i<firstprime; i++)
for (unsigned long i = 0; i<firstprime; i++)
{
if (exponents[i]) add_factor(&last_ptr, (unsigned long) exponents[i], (unsigned long) i);
}
Expand Down Expand Up @@ -777,11 +774,11 @@ void evaluateSieve(unsigned long ** relations, unsigned long ctimesreps, unsigne
=============================================================================*/
void sieveInterval(unsigned long M, unsigned long numPrimes, unsigned char * sieve, long last, long first, long polyadd, unsigned long * soln1, unsigned long * soln2, unsigned long * polycorr, unsigned char * * offsets, unsigned char * * offsets2)
{
register unsigned char currentprimesize;
register unsigned long currentprime;
unsigned char currentprimesize;
unsigned long currentprime;
unsigned char * position2;
register unsigned char * position;
register long diff;
unsigned char * position;
long diff;
unsigned char * end;
unsigned long ptimes4;
long correction;
Expand Down Expand Up @@ -826,7 +823,7 @@ void sieveInterval(unsigned long M, unsigned long numPrimes, unsigned char * sie
diff=position2-position;

ptimes4 = currentprime*4;
register unsigned char * bound=end-ptimes4;
unsigned char * bound=end-ptimes4;
while (bound - position > 0)
{
(* position)+=currentprimesize,(* (position+diff))+=currentprimesize, position+=currentprime;
Expand Down Expand Up @@ -879,7 +876,7 @@ void sieveInterval(unsigned long M, unsigned long numPrimes, unsigned char * sie
diff=position2-position;

ptimes4 = 2*currentprime;
register unsigned char * bound=end-ptimes4;
unsigned char * bound=end-ptimes4;
while (bound - position > 0)
{
(* position)+=currentprimesize,(* (position+diff))+=currentprimesize, position+=currentprime;
Expand Down Expand Up @@ -918,10 +915,10 @@ void sieveInterval(unsigned long M, unsigned long numPrimes, unsigned char * sie
=========================================================================== */
void sieve2(unsigned long M, unsigned long numPrimes, unsigned char * sieve, long last, long first, long polyadd, unsigned long * soln1, unsigned long * soln2, unsigned long * polycorr, unsigned char * * offsets, unsigned char * * offsets2)
{
register unsigned char currentprimesize;
register unsigned long currentprime;
register unsigned char * position2;
register unsigned char * position;
unsigned char currentprimesize;
unsigned long currentprime;
unsigned char * position2;
unsigned char * position;
unsigned char * end;
long correction;

Expand Down Expand Up @@ -1116,7 +1113,7 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
offsets2 = (unsigned char * *)calloc(numPrimes,sizeof(unsigned char *));

relations = (unsigned long * *) calloc(relSought,sizeof(unsigned long *));
for (long i = 0; i < relSought; i++)
for (unsigned long i = 0; i < relSought; i++)
{
relations[i] = (unsigned long *) calloc(200, sizeof(unsigned long));
}
Expand Down Expand Up @@ -1154,9 +1151,9 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
while (j!=i)
{
ran++;
for (j=0;((j<i)&&(aind[j]!=ran));j++);
for (j=0;((j<i)&&(aind[j]!=(unsigned long)ran));j++);
}
aind[i] = ran;
aind[i] = (unsigned long)ran;
mpz_mul_ui(A,A,factorBase[ran+min]);
i++;
if (i < s-1)
Expand All @@ -1166,9 +1163,9 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
while (j!=i)
{
ran++;
for (j=0;((j<i)&&(aind[j]!=ran));j++);
for (j=0;((j<i)&&(aind[j]!=(unsigned long)ran));j++);
}
aind[i] = ran;
aind[i] = (unsigned long)ran;
mpz_mul_ui(A,A,factorBase[ran+min]);
i++;
}
Expand All @@ -1179,11 +1176,11 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
fact-=min;
do
{
for (j=0;((j<i)&&(aind[j]!=fact));j++);
for (j=0;((j<i)&&(aind[j]!=(unsigned long)fact));j++);
fact++;
} while (j!=i);
fact--;
aind[i] = fact;
aind[i] = (unsigned long)fact;
mpz_mul_ui(A,A,factorBase[fact+min]);

for (long i=0; i<s; i++)
Expand All @@ -1210,7 +1207,7 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
mpz_add(B,B,Bterms[i]);
}

for (long i=0; i<numPrimes; i++)
for (unsigned long i=0; i<numPrimes; i++)
{
p = factorBase[i];
Ainv[i] = modinverse(mpz_fdiv_r_ui(temp,A,p),p);
Expand Down Expand Up @@ -1473,7 +1470,8 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
nullrows = block_lanczos(nrows, 0, ncols, colarray);
} while (nullrows == NULL);

long i,j, mask;
unsigned long i;
long j, mask;

for (i = 0, mask = 0; i < ncols; i++)
mask |= nullrows[i];
Expand Down Expand Up @@ -1521,25 +1519,25 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)

// Now do the "square root" and GCD steps hopefully obtaining factors of n
printf("FACTORS:\n");
for (long l = 0;l<64;l++)
for (unsigned long l = 0;l<64;l++)
{
while (!(mask & ((u_int64_t)(1) << l))) l++;
mpz_set_ui(temp,1);
mpz_set_ui(temp2,1);
memset(primecount,0,numPrimes*sizeof(unsigned long));
for (long i = 0; i<ncols; i++)
for (unsigned long i = 0; i<ncols; i++)
{
if (getNullEntry(nullrows,i,l))
{
mpz_mul(temp2,temp2,XArr[colarray[i].orig]);
for (long j=1; j<=relations[colarray[i].orig][0]; j++)
for (unsigned long j=1; j<=relations[colarray[i].orig][0]; j++)
{
primecount[relations[colarray[i].orig][j]]++;
}
}
if (i%30==0) mpz_mod(temp2,temp2,n);
}
for (long j = 0; j<numPrimes; j++)
for (unsigned long j = 0; j<numPrimes; j++)
{
mpz_set_ui(temp3,factorBase[j]);
mpz_pow_ui(temp3,temp3,primecount[j]/2);
Expand Down Expand Up @@ -1638,9 +1636,9 @@ int main(int argc, char *argv[])

getchar();
#if defined(WINCE) || defined(macintosh)
char * tmp_dir = NULL;
const char * tmp_dir = NULL;
#else
char * tmp_dir = getenv("TMPDIR");
const char * tmp_dir = getenv("TMPDIR");
#endif
if (tmp_dir == NULL) tmp_dir = "./";
char * delfile;
Expand Down
2 changes: 1 addition & 1 deletion src/lanczos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const u_int64_t bitmask[64] = {
};

/*--------------------------------------------------------------------*/
u_int64_t getNullEntry(u_int64_t * nullrows, long i, long l) {
u_int64_t getNullEntry(u_int64_t * nullrows, unsigned long i, unsigned long l) {

/* Returns true if the entry with indices i,l is 1 in the
supplied 64xN matrix. This is used to read the nullspace
Expand Down
6 changes: 3 additions & 3 deletions src/lanczos.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct {
unsigned long orig; /* Original relation number */
} la_col_t;

u_int64_t getNullEntry(u_int64_t *, long, long);
u_int64_t getNullEntry(u_int64_t *, unsigned long, unsigned long);
void reduce_matrix(unsigned long *, unsigned long *, la_col_t *);
u_int64_t * block_lanczos(unsigned long, unsigned long, unsigned long, la_col_t*);

Expand All @@ -55,7 +55,7 @@ static inline void insertColEntry(la_col_t* colarray, unsigned long colNum, unsi
{
temp = colarray[colNum].data;
colarray[colNum].data = (unsigned long*)malloc((colarray[colNum].weight+16)*sizeof(unsigned long));
for (long i = 0; i<colarray[colNum].weight; i++)
for (unsigned long i = 0; i<colarray[colNum].weight; i++)
{
colarray[colNum].data[i] = temp[i];
}
Expand All @@ -77,7 +77,7 @@ static inline void insertColEntry(la_col_t* colarray, unsigned long colNum, unsi
===========================================================================*/
static inline void xorColEntry(la_col_t* colarray, unsigned long colNum, unsigned long entry)
{
for (long i = 0; i < colarray[colNum].weight; i++)
for (unsigned long i = 0; i < colarray[colNum].weight; i++)
if (colarray[colNum].data[i] == entry)
{
for (unsigned long j = i; j < colarray[colNum].weight - 1; j++)
Expand Down
24 changes: 12 additions & 12 deletions src/lprels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
Concatenates a filename and directory name to give a full path
*/

char * get_filename(char *dir, char *s)
char * get_filename(const char *dir, const char *s)
{
char *buf = (char *) malloc(strlen(dir) + strlen(s) + 2);
#if defined(__EMX__) || defined(WINCE)
Expand All @@ -56,7 +56,7 @@ char * get_filename(char *dir, char *s)
return buf;
}

char * unique_filename(char *s)
char * unique_filename(const char *s)
{
char *buf, suf[64];
size_t lsuf;
Expand All @@ -72,12 +72,12 @@ char * unique_filename(char *s)
}


FILE * flint_fopen(char * name, char * mode)
FILE * flint_fopen(const char * name, const char * mode)
{
#if defined(WINCE) || defined(macintosh)
char * tmp_dir = NULL;
const char * tmp_dir = NULL;
#else
char * tmp_dir = getenv("TMPDIR");
const char * tmp_dir = getenv("TMPDIR");
#endif
if (tmp_dir == NULL) tmp_dir = "./";
FILE * temp_file = fopen(get_filename(tmp_dir,unique_filename(name)),mode);
Expand Down Expand Up @@ -111,7 +111,7 @@ int relations_cmp(const void *a, const void *b)
Writes the given string to the given file and aborts upon error
*/

void flint_fputs(char *s, FILE *file)
void flint_fputs(const char *s, FILE *file)
{
if (fputs(s, file) < 0)
{
Expand All @@ -127,7 +127,7 @@ void flint_fputs(char *s, FILE *file)
file. Returns the number of relations after sorting and discarding.
*/

long sort_lp_file(char *filename)
long sort_lp_file(const char *filename)
{
FILE *TMP;
char *old_s, *buf, *cur_line;
Expand Down Expand Up @@ -182,7 +182,7 @@ long sort_lp_file(char *filename)
bufspace = MPQS_STRING_LENGTH;
if (fgets(cur_line, bufspace, TMP) == NULL) { free(buf); break; }

if (buflist - buflist_head >= buflist_size) abort();
if ((unsigned long)(buflist - buflist_head) >= buflist_size) abort();

/* remember buffer for later deallocation */
*buflist++ = buf;
Expand All @@ -200,7 +200,7 @@ long sort_lp_file(char *filename)
{
size_t lg1;
buf = (char*) malloc(MPQS_STRING_LENGTH * sizeof(char));
if (buflist - buflist_head >= buflist_size) abort();
if ((unsigned long)(buflist - buflist_head) >= buflist_size) abort();
/* remember buffer for later deallocation */
*buflist++ = buf;

Expand Down Expand Up @@ -487,14 +487,14 @@ long mergesort_lp_file_internal(FILE *LPREL, FILE *LPNEW, FILE *COMB, FILE *TMP)
Perform mergesort of large prime files
*/

long mergesort_lp_file(char *REL_str, char *NEW_str, char *TMP_str, FILE *COMB)
long mergesort_lp_file(const char *REL_str, const char *NEW_str, const char *TMP_str, FILE *COMB)
{
FILE *NEW = flint_fopen(NEW_str, "r");

#if defined(WINCE) || defined(macintosh)
char * tmp_dir = NULL;
const char * tmp_dir = NULL;
#else
char * tmp_dir = getenv("TMPDIR");
const char * tmp_dir = getenv("TMPDIR");
#endif
if (tmp_dir == NULL) tmp_dir = "./";
char * TMP_name = get_filename(tmp_dir,unique_filename(TMP_str));
Expand Down
12 changes: 6 additions & 6 deletions src/lprels.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ typedef struct {
char E[MPQS_STRING_LENGTH];
} mpqs_lp_entry;

char * get_filename(char *dir, char *s);
char * get_filename(const char *dir, const char *s);
int mpqs_relations_cmp(const void *a, const void *b);
void flint_fputs(char *s, FILE *file);
long sort_lp_file(char *filename);
void flint_fputs(const char *s, FILE *file);
long sort_lp_file(const char *filename);
long append_file(FILE *fp, FILE *fp1);
long mpqs_mergesort_lp_file_internal(FILE *LPREL, FILE *LPNEW, FILE *COMB, FILE *TMP);
long mergesort_lp_file(char *REL_str, char *NEW_str, char *TMP_str, FILE *COMB);
long mergesort_lp_file(const char *REL_str, const char *NEW_str, const char *TMP_str, FILE *COMB);
void add_factor(char **last, unsigned long ei, unsigned long pi);
void add_0(char **last);
void set_exponents(unsigned long *ei, char *r);
void set_lp_entry(mpqs_lp_entry *e, char *buf);
long combine_large_primes(unsigned long numPrimes, FILE *COMB, FILE *FNEW, mpz_t N, mpz_t factor);
void read_matrix(unsigned long ** relations, FILE *FREL, la_col_t* colarray, unsigned long * relsFound, unsigned long relSought, mpz_t * XArr, mpz_t n, unsigned long * factorBase);
FILE * flint_fopen(char * name, char * mode);
char * unique_filename(char *s);
FILE * flint_fopen(const char * name, const char * mode);
char * unique_filename(const char *s);

#endif