Browse Source

Fix compilation with GCC 4.4.

Use std::iostream functions instead of EOF and cl_EOF macros.
This enables us to get rid of the freadchar and funreadchar functions.
While at it, removed the extra signatures introduced for CLN-1.2.0
compatibilty. After all, the soname has been bumped.

Also updated largest known Mersenne prime in examples/perfnum.cc.
master
Richard B. Kreckel 16 years ago
parent
commit
a446756831
  1. 6
      TODO
  2. 25
      doc/cln.texi
  3. 5
      examples/perfnum.cc
  4. 21
      include/cln/io.h
  5. 6
      src/base/string/input/cl_st_get1.cc
  6. 6
      src/base/string/input/cl_st_get2.cc
  7. 6
      src/base/string/input/cl_st_getline1.cc
  8. 6
      src/base/string/input/cl_st_getline2.cc
  9. 6
      src/base/string/input/cl_st_gettoken.cc
  10. 22
      src/complex/input/cl_N_read_stream.cc
  11. 6
      src/float/dfloat/conv/cl_DF_from_double.cc
  12. 6
      src/float/ffloat/conv/cl_FF_from_float.cc
  13. 18
      src/float/input/cl_F_read_stream.cc
  14. 8
      src/float/input/cl_F_readparsed.cc
  15. 18
      src/integer/input/cl_I_read_stream.cc
  16. 8
      src/integer/input/cl_I_readparsed.cc
  17. 18
      src/rational/input/cl_RA_read_stream.cc
  18. 8
      src/rational/input/cl_RA_readparsed.cc
  19. 18
      src/real/input/cl_R_read_stream.cc

6
TODO

@ -1,9 +1,3 @@
ABI Issues:
Remove extra signatures in cl_FF_from_float.cc, cl_DF_from_double.cc,
cl_F_readparsed.cc, cl_I_readparsed.cc, and cl_RA_readparsed.cc.
Algorithms: Algorithms:
Niels Moeller's subquadratic GCD Niels Moeller's subquadratic GCD

25
doc/cln.texi

@ -2661,30 +2661,7 @@ In Common Lisp notation: @code{#C(@var{realpart} @var{imagpart})}.
@node Input functions @node Input functions
@section Input functions @section Input functions
Including @code{<cln/io.h>} defines a number of simple input functions
that read from @code{std::istream&}:
@table @code
@item int freadchar (std::istream& stream)
Reads a character from @code{stream}. Returns @code{cl_EOF} (not a @samp{char}!)
if the end of stream was encountered or an error occurred.
@item int funreadchar (std::istream& stream, int c)
Puts back @code{c} onto @code{stream}. @code{c} must be the result of the
last @code{freadchar} operation on @code{stream}.
@end table
Each of the classes @code{cl_N}, @code{cl_R}, @code{cl_RA}, @code{cl_I},
@code{cl_F}, @code{cl_SF}, @code{cl_FF}, @code{cl_DF}, @code{cl_LF}
defines, in @code{<cln/@var{type}_io.h>}, the following input function:
@table @code
@item std::istream& operator>> (std::istream& stream, @var{type}& result)
Reads a number from @code{stream} and stores it in the @code{result}.
@end table
The most flexible input functions, defined in @code{<cln/@var{type}_io.h>},
are the following:
Including @code{<cln/io.h>} defines flexible input functions:
@table @code @table @code
@item cl_N read_complex (std::istream& stream, const cl_read_flags& flags) @item cl_N read_complex (std::istream& stream, const cl_read_flags& flags)

5
examples/perfnum.cc

@ -8,8 +8,9 @@ using namespace cln;
int main () int main ()
{ {
// previous ones were 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457
int p = 32582657;
// previous ones were 1257787, 1398269, 2976221, 3021377, 6972593,
// 13466917, 20996011, 24036583, 25964951, 30402457, 32582657, 37156667
int p = 43112609;
cl_I x = (((cl_I)1 << p) - 1) << (p-1); cl_I x = (((cl_I)1 << p) - 1) << (p-1);
cout << x << endl; cout << x << endl;
} }

21
include/cln/io.h

@ -24,27 +24,6 @@ typedef std::ostream& cl_ostream;
extern std::ostream* cl_debugout_stream; extern std::ostream* cl_debugout_stream;
#define cl_debugout (*cl_debugout_stream) #define cl_debugout (*cl_debugout_stream)
// Elementary operations on std::istream&
#define cl_EOF (-1)
inline int freadchar (std::istream& stream)
{
char c;
if (stream.get(c))
return c;
else
// EOF or error
return cl_EOF;
}
inline int funreadchar (std::istream& stream, int c)
{
if (c != cl_EOF)
stream.putback((char)c);
return c;
}
// Elementary operations on std::ostream& // Elementary operations on std::ostream&
inline void fprintchar (std::ostream& stream, char c) inline void fprintchar (std::ostream& stream, char c)

6
src/base/string/input/cl_st_get1.cc

@ -17,11 +17,11 @@ namespace cln {
const cl_string cl_fget (std::istream& stream, char delim) const cl_string cl_fget (std::istream& stream, char delim)
{ {
var cl_spushstring buffer; var cl_spushstring buffer;
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) { while (stream.good()) {
var int c = stream.get(); var int c = stream.get();
if (c==EOF)
break; // std::ios::eofbit already set
if (stream.eof())
break;
if (c==delim) { if (c==delim) {
stream.unget(); stream.unget();
break; break;

6
src/base/string/input/cl_st_get2.cc

@ -17,11 +17,11 @@ namespace cln {
const cl_string cl_fget (std::istream& stream, int n, char delim) const cl_string cl_fget (std::istream& stream, int n, char delim)
{ {
var cl_spushstring buffer; var cl_spushstring buffer;
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) { while (stream.good()) {
var int c = stream.get(); var int c = stream.get();
if (c==EOF)
break; // ios::eofbit already set
if (stream.eof())
break;
if (c==delim) { if (c==delim) {
stream.unget(); stream.unget();
break; break;

6
src/base/string/input/cl_st_getline1.cc

@ -17,11 +17,11 @@ namespace cln {
const cl_string cl_fgetline (std::istream& stream, char delim) const cl_string cl_fgetline (std::istream& stream, char delim)
{ {
var cl_spushstring buffer; var cl_spushstring buffer;
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) { while (stream.good()) {
var int c = stream.get(); var int c = stream.get();
if (c==EOF)
break; // std::ios::eofbit already set
if (stream.eof())
break;
if (c==delim) if (c==delim)
break; break;
buffer.push(c); buffer.push(c);

6
src/base/string/input/cl_st_getline2.cc

@ -17,11 +17,11 @@ namespace cln {
const cl_string cl_fgetline (std::istream& stream, int n, char delim) const cl_string cl_fgetline (std::istream& stream, int n, char delim)
{ {
var cl_spushstring buffer; var cl_spushstring buffer;
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
while (stream.good()) { while (stream.good()) {
var int c = stream.get(); var int c = stream.get();
if (c==EOF)
break; // std::ios::eofbit already set
if (stream.eof())
break;
if (c==delim) if (c==delim)
break; break;
if (--n <= 0) { if (--n <= 0) {

6
src/base/string/input/cl_st_gettoken.cc

@ -19,12 +19,12 @@ std::istream& operator>> (std::istream& stream, cl_string& str)
{ {
var cl_spushstring buffer; var cl_spushstring buffer;
var int n = stream.width(); var int n = stream.width();
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
// Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.eof()).
int c; int c;
// Skip whitespace. // Skip whitespace.
while (stream.good()) { while (stream.good()) {
c = stream.get(); c = stream.get();
if (c==EOF)
if (stream.eof())
break; break;
if (!isspace(c)) { if (!isspace(c)) {
if (--n == 0) { if (--n == 0) {
@ -40,7 +40,7 @@ std::istream& operator>> (std::istream& stream, cl_string& str)
// Read non-whitespace. // Read non-whitespace.
while (stream.good()) { while (stream.good()) {
c = stream.get(); c = stream.get();
if (c==EOF)
if (stream.eof())
break; break;
if (isspace(c)) { if (isspace(c)) {
stream.unget(); stream.unget();

22
src/complex/input/cl_N_read_stream.cc

@ -46,8 +46,8 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
var int c; var int c;
// Skip whitespace at the beginning. // Skip whitespace at the beginning.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n')) if ((c == ' ') || (c == '\t') || (c == '\n'))
continue; continue;
else else
@ -62,8 +62,8 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
buffer.push(c); buffer.push(c);
// Read some digits, then a letter, then a list or token. // Read some digits, then a letter, then a list or token.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
buffer.push(c); buffer.push(c);
if ((c >= '0') && (c <= '9')) if ((c >= '0') && (c <= '9'))
continue; continue;
@ -72,8 +72,8 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
} }
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))) if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1; goto syntax1;
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if (c == '(') { if (c == '(') {
var uintL paren_level = 0; var uintL paren_level = 0;
loop { loop {
@ -81,8 +81,8 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
if (c == '(') paren_level++; if (c == '(') paren_level++;
else if (c == ')') paren_level--; else if (c == ')') paren_level--;
if (paren_level == 0) goto done; if (paren_level == 0) goto done;
c = freadchar(stream);
if ((c == cl_EOF) || (c == '\n')) goto syntax;
c = stream.get();
if (stream.eof() || stream.fail() || c == '\n') goto syntax;
} }
} }
} }
@ -91,11 +91,11 @@ const cl_N read_complex (std::istream& stream, const cl_read_flags& flags)
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = freadchar(stream);
if (c == cl_EOF)
c = stream.get();
if (stream.eof() || stream.fail())
break; break;
if (!number_char_p(c)) { if (!number_char_p(c)) {
funreadchar(stream,c);
stream.putback(c);
break; break;
} }
} }

6
src/float/dfloat/conv/cl_DF_from_double.cc

@ -11,12 +11,6 @@
namespace cln { namespace cln {
cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_)
{
// XXX: This signature is for binary compatibility with CLN-1.2.0 only.
return cl_double_to_DF_pointer(*(double *)(&val_));
}
cl_heap_dfloat* cl_double_to_DF_pointer (const double x) cl_heap_dfloat* cl_double_to_DF_pointer (const double x)
{ {
var union { dfloat eksplicit; double machine_double; } u; var union { dfloat eksplicit; double machine_double; } u;

6
src/float/ffloat/conv/cl_FF_from_float.cc

@ -10,12 +10,6 @@ namespace cln {
// Implementation. // Implementation.
cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val_)
{
// XXX: This signature is for binary compatibility with CLN-1.2.0 only.
return cl_float_to_FF_pointer(*(float *)(&val_));
}
cl_private_thing cl_float_to_FF_pointer (const float x) cl_private_thing cl_float_to_FF_pointer (const float x)
{ {
var union { ffloat eksplicit; float machine_float; } u; var union { ffloat eksplicit; float machine_float; } u;

18
src/float/input/cl_F_read_stream.cc

@ -48,8 +48,8 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags)
var int c; var int c;
// Skip whitespace at the beginning. // Skip whitespace at the beginning.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n')) if ((c == ' ') || (c == '\t') || (c == '\n'))
continue; continue;
else else
@ -64,8 +64,8 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags)
buffer.push(c); buffer.push(c);
// Read some digits, then a letter, then a token. // Read some digits, then a letter, then a token.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
buffer.push(c); buffer.push(c);
if ((c >= '0') && (c <= '9')) if ((c >= '0') && (c <= '9'))
continue; continue;
@ -74,19 +74,19 @@ const cl_F read_float (std::istream& stream, const cl_read_flags& flags)
} }
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))) if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1; goto syntax1;
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
} }
// Read a number token. // Read a number token.
if (!number_char_p(c)) if (!number_char_p(c))
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = freadchar(stream);
if (c == cl_EOF)
c = stream.get();
if (stream.eof() || stream.fail())
break; break;
if (!number_char_p(c)) { if (!number_char_p(c)) {
funreadchar(stream,c);
stream.putback(c);
break; break;
} }
} }

8
src/float/input/cl_F_readparsed.cc

@ -26,14 +26,6 @@
namespace cln { namespace cln {
#if intCsize > intLsize
const cl_F read_float (unsigned int base, float_format_t prec, cl_signean sign, const char * string, uintL index1, uintL index4, uintL index2, uintL index3)
{
// XXX: This signature is for binary compatibility with CLN-1.2.0 only.
return read_float(base, prec, sign, string, uintC(index1), uintC(index4), uintC(index2), uintC(index3));
}
#endif
const cl_F read_float (unsigned int base, float_format_t prec, cl_signean sign, const char * string, uintC index1, uintC index4, uintC index2, uintC index3) const cl_F read_float (unsigned int base, float_format_t prec, cl_signean sign, const char * string, uintC index1, uintC index4, uintC index2, uintC index3)
{ {
var cl_I exponent; var cl_I exponent;

18
src/integer/input/cl_I_read_stream.cc

@ -48,8 +48,8 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags)
var int c; var int c;
// Skip whitespace at the beginning. // Skip whitespace at the beginning.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n')) if ((c == ' ') || (c == '\t') || (c == '\n'))
continue; continue;
else else
@ -64,8 +64,8 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags)
buffer.push(c); buffer.push(c);
// Read some digits, then a letter, then a token. // Read some digits, then a letter, then a token.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
buffer.push(c); buffer.push(c);
if ((c >= '0') && (c <= '9')) if ((c >= '0') && (c <= '9'))
continue; continue;
@ -74,19 +74,19 @@ const cl_I read_integer (std::istream& stream, const cl_read_flags& flags)
} }
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))) if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1; goto syntax1;
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
} }
// Read a number token. // Read a number token.
if (!number_char_p(c)) if (!number_char_p(c))
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = freadchar(stream);
if (c == cl_EOF)
c = stream.get();
if (stream.eof() || stream.fail())
break; break;
if (!number_char_p(c)) { if (!number_char_p(c)) {
funreadchar(stream,c);
stream.putback(c);
break; break;
} }
} }

8
src/integer/input/cl_I_readparsed.cc

@ -13,14 +13,6 @@
namespace cln { namespace cln {
#if intCsize > intLsize
const cl_I read_integer (unsigned int base, cl_signean sign, const char* string, uintL index1, uintL index2)
{
// XXX: This signature is for binary compatibility with CLN-1.2.0 only.
return read_integer(base, sign, string, uintC(index1), uintC(index2));
}
#endif
const cl_I read_integer (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index2) const cl_I read_integer (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index2)
{ {
var cl_I x = digits_to_I(&string[index1],index2-index1,(uintD)base); var cl_I x = digits_to_I(&string[index1],index2-index1,(uintD)base);

18
src/rational/input/cl_RA_read_stream.cc

@ -49,8 +49,8 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags)
var int c; var int c;
// Skip whitespace at the beginning. // Skip whitespace at the beginning.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n')) if ((c == ' ') || (c == '\t') || (c == '\n'))
continue; continue;
else else
@ -65,8 +65,8 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags)
buffer.push(c); buffer.push(c);
// Read some digits, then a letter, then a token. // Read some digits, then a letter, then a token.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
buffer.push(c); buffer.push(c);
if ((c >= '0') && (c <= '9')) if ((c >= '0') && (c <= '9'))
continue; continue;
@ -75,19 +75,19 @@ const cl_RA read_rational (std::istream& stream, const cl_read_flags& flags)
} }
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))) if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1; goto syntax1;
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
} }
// Read a number token. // Read a number token.
if (!number_char_p(c)) if (!number_char_p(c))
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = freadchar(stream);
if (c == cl_EOF)
c = stream.get();
if (stream.eof() || stream.fail())
break; break;
if (!number_char_p(c)) { if (!number_char_p(c)) {
funreadchar(stream,c);
stream.putback(c);
break; break;
} }
} }

8
src/rational/input/cl_RA_readparsed.cc

@ -15,14 +15,6 @@
namespace cln { namespace cln {
#if intCsize > intLsize
const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintL index1, uintL index3, uintL index2)
{
// XXX: This signature is for binary compatibility with CLN-1.2.0 only.
return read_rational(base, sign, string, uintC(index1), uintC(index3), uintC(index2));
}
#endif
const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index3, uintC index2) const cl_RA read_rational (unsigned int base, cl_signean sign, const char * string, uintC index1, uintC index3, uintC index2)
{ {
var uintC index3_1 = index3+1; // Index der ersten Nennerziffer var uintC index3_1 = index3+1; // Index der ersten Nennerziffer

18
src/real/input/cl_R_read_stream.cc

@ -48,8 +48,8 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
var int c; var int c;
// Skip whitespace at the beginning. // Skip whitespace at the beginning.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
if ((c == ' ') || (c == '\t') || (c == '\n')) if ((c == ' ') || (c == '\t') || (c == '\n'))
continue; continue;
else else
@ -64,8 +64,8 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
buffer.push(c); buffer.push(c);
// Read some digits, then a letter, then a token. // Read some digits, then a letter, then a token.
loop { loop {
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
buffer.push(c); buffer.push(c);
if ((c >= '0') && (c <= '9')) if ((c >= '0') && (c <= '9'))
continue; continue;
@ -74,19 +74,19 @@ const cl_R read_real (std::istream& stream, const cl_read_flags& flags)
} }
if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))) if (!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))))
goto syntax1; goto syntax1;
c = freadchar(stream);
if (c == cl_EOF) goto eof;
c = stream.get();
if (stream.eof() || stream.fail()) goto eof;
} }
// Read a number token. // Read a number token.
if (!number_char_p(c)) if (!number_char_p(c))
goto syntax1; goto syntax1;
loop { loop {
buffer.push(c); buffer.push(c);
c = freadchar(stream);
if (c == cl_EOF)
c = stream.get();
if (stream.eof() || stream.fail())
break; break;
if (!number_char_p(c)) { if (!number_char_p(c)) {
funreadchar(stream,c);
stream.putback(c);
break; break;
} }
} }

Loading…
Cancel
Save