# HG changeset patch # User John W. Eaton # Date 1628008492 14400 # Node ID da7210e30f3e5fc730d6ad40038a85d37bfe7ecb # Parent 79c6a29dd3842bd585a2ff0a1183aff6e65802f8 move some utility functions inside octave namespace * lo-utils.h, lo-utils.cc (is_one_or_zero): Rename from xis_one_or_zero and move inside octave namespace. Change all uses. (is_zero): Rename from xis_zero and move inside octave namespace. Change all uses. (is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move inside octave namespace. Change all uses. (too_large_for_float): Rename from xtoo_large_for_float and move inside octave namespace. Change all uses. (too_large_for_float): Rename from xtoo_large_for_float and move inside octave namespace. Change all uses. (is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move inside octave namespace. Change all uses. (fgets): Rename from octave_fgets and move inside octave namespace. Change all uses. (fgetl): Rename from octave_fgetl and move inside octave namespace. Change all uses. (any_all_test, strsave): Move inside octave namespace. Tag uses with octave:: prefix as needed. * lo-utils.h: Provide deprecated templates and inline functions to preserve old names in global namespace. diff -r 79c6a29dd384 -r da7210e30f3e libinterp/corefcn/input.cc --- a/libinterp/corefcn/input.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/libinterp/corefcn/input.cc Tue Aug 03 12:34:52 2021 -0400 @@ -1045,7 +1045,7 @@ eof = false; - std::string src_str = octave_fgets (m_file, eof); + std::string src_str = fgets (m_file, eof); std::string mfile_encoding; diff -r 79c6a29dd384 -r da7210e30f3e libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/libinterp/corefcn/load-path.cc Tue Aug 03 12:34:52 2021 -0400 @@ -1166,7 +1166,7 @@ const std::string enc_prop = "encoding"; while (! eof) { - std::string conf_str = octave_fgets (cfile, eof); + std::string conf_str = fgets (cfile, eof); // delete any preceeding whitespace auto it = std::find_if_not (conf_str.begin (), conf_str.end (), diff -r 79c6a29dd384 -r da7210e30f3e libinterp/octave-value/ov-range.cc --- a/libinterp/octave-value/ov-range.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/libinterp/octave-value/ov-range.cc Tue Aug 03 12:34:52 2021 -0400 @@ -376,7 +376,7 @@ { Array matrix = raw_array_value (); - if (warn && ! matrix.test_all (xis_one_or_zero)) + if (warn && ! matrix.test_all (octave::is_one_or_zero)) warn_logical_conversion (); return boolNDArray (matrix); diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/Array.h --- a/liboctave/array/Array.h Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/Array.h Tue Aug 03 12:34:52 2021 -0400 @@ -805,7 +805,7 @@ template bool test (F fcn) const { - return any_all_test (fcn, data (), numel ()); + return octave::any_all_test (fcn, data (), numel ()); } //@{ diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/CNDArray.cc --- a/liboctave/array/CNDArray.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/CNDArray.cc Tue Aug 03 12:34:52 2021 -0400 @@ -339,7 +339,7 @@ bool ComplexNDArray::too_large_for_float (void) const { - return test_any (xtoo_large_for_float); + return test_any (octave::too_large_for_float); } boolNDArray diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/CSparse.cc --- a/liboctave/array/CSparse.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/CSparse.cc Tue Aug 03 12:34:52 2021 -0400 @@ -7352,7 +7352,7 @@ bool SparseComplexMatrix::too_large_for_float (void) const { - return test_any (xtoo_large_for_float); + return test_any (octave::too_large_for_float); } // FIXME: Do these really belong here? Maybe they should be in a base class? diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/Sparse.h --- a/liboctave/array/Sparse.h Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/Sparse.h Tue Aug 03 12:34:52 2021 -0400 @@ -590,7 +590,7 @@ template bool test (F fcn) const { - return any_all_test (fcn, data (), nnz ()); + return octave::any_all_test (fcn, data (), nnz ()); } // Simpler calls. diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/dNDArray.cc --- a/liboctave/array/dNDArray.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/dNDArray.cc Tue Aug 03 12:34:52 2021 -0400 @@ -329,19 +329,19 @@ bool NDArray::any_element_not_one_or_zero (void) const { - return ! test_all (xis_one_or_zero); + return ! test_all (octave::is_one_or_zero); } bool NDArray::all_elements_are_zero (void) const { - return test_all (xis_zero); + return test_all (octave::is_zero); } bool NDArray::all_elements_are_int_or_inf_or_nan (void) const { - return test_all (xis_int_or_inf_or_nan); + return test_all (octave::is_int_or_inf_or_nan); } // Return nonzero if any element of M is not an integer. Also extract @@ -386,7 +386,7 @@ bool NDArray::too_large_for_float (void) const { - return test_any (xtoo_large_for_float); + return test_any (octave::too_large_for_float); } // FIXME: this is not quite the right thing. diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/dSparse.cc --- a/liboctave/array/dSparse.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/dSparse.cc Tue Aug 03 12:34:52 2021 -0400 @@ -7323,7 +7323,7 @@ bool SparseMatrix::too_large_for_float (void) const { - return test_any (xtoo_large_for_float); + return test_any (octave::too_large_for_float); } SparseBoolMatrix diff -r 79c6a29dd384 -r da7210e30f3e liboctave/array/fNDArray.cc --- a/liboctave/array/fNDArray.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/array/fNDArray.cc Tue Aug 03 12:34:52 2021 -0400 @@ -286,19 +286,19 @@ bool FloatNDArray::any_element_not_one_or_zero (void) const { - return ! test_all (xis_one_or_zero); + return ! test_all (octave::is_one_or_zero); } bool FloatNDArray::all_elements_are_zero (void) const { - return test_all (xis_zero); + return test_all (octave::is_zero); } bool FloatNDArray::all_elements_are_int_or_inf_or_nan (void) const { - return test_all (xis_int_or_inf_or_nan); + return test_all (octave::is_int_or_inf_or_nan); } // Return nonzero if any element of M is not an integer. Also extract diff -r 79c6a29dd384 -r da7210e30f3e liboctave/util/cmd-edit.cc --- a/liboctave/util/cmd-edit.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/util/cmd-edit.cc Tue Aug 03 12:34:52 2021 -0400 @@ -976,7 +976,7 @@ std::fputs (prompt.c_str (), output_stream); std::fflush (output_stream); - return octave_fgetl (input_stream, eof); + return fgetl (input_stream, eof); } void diff -r 79c6a29dd384 -r da7210e30f3e liboctave/util/lo-utils.cc --- a/liboctave/util/lo-utils.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/util/lo-utils.cc Tue Aug 03 12:34:52 2021 -0400 @@ -45,140 +45,139 @@ #include "lo-utils.h" #include "oct-inttypes.h" -bool xis_int_or_inf_or_nan (double x) -{ return octave::math::isnan (x) || octave::math::x_nint (x) == x; } - -bool xtoo_large_for_float (double x) -{ - return (octave::math::isfinite (x) - && fabs (x) > std::numeric_limits::max ()); -} - -bool xtoo_large_for_float (const Complex& x) -{ - return (xtoo_large_for_float (x.real ()) - || xtoo_large_for_float (x.imag ())); -} - -bool xis_int_or_inf_or_nan (float x) -{ return octave::math::isnan (x) || octave::math::x_nint (x) == x; } - -// Save a string. - -char * -strsave (const char *s) -{ - if (! s) - return nullptr; - - int len = strlen (s); - char *tmp = new char [len+1]; - tmp = strcpy (tmp, s); - return tmp; -} - -std::string -octave_fgets (FILE *f) -{ - bool eof; - return octave_fgets (f, eof); -} - -std::string -octave_fgets (FILE *f, bool& eof) -{ - eof = false; - - std::string retval; - - int grow_size = 1024; - int max_size = grow_size; - - char *buf = static_cast (std::malloc (max_size)); - if (! buf) - (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); - - char *bufptr = buf; - int len = 0; - - do - { - if (std::fgets (bufptr, grow_size, f)) - { - len = strlen (bufptr); - - if (len == grow_size - 1) - { - int tmp = bufptr - buf + grow_size - 1; - grow_size *= 2; - max_size += grow_size; - auto tmpbuf = static_cast (std::realloc (buf, max_size)); - if (! tmpbuf) - { - free (buf); - (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); - } - buf = tmpbuf; - bufptr = buf + tmp; - - if (*(bufptr-1) == '\n') - { - *bufptr = '\0'; - retval = buf; - } - } - else if (bufptr[len-1] != '\n') - { - bufptr[len++] = '\n'; - bufptr[len] = '\0'; - retval = buf; - } - else - retval = buf; - } - else - { - if (len == 0) - { - eof = true; - - free (buf); - - buf = nullptr; - } - - break; - } - } - while (retval.empty ()); - - free (buf); - - octave_quit (); - - return retval; -} - -std::string -octave_fgetl (FILE *f) -{ - bool eof; - return octave_fgetl (f, eof); -} - -std::string -octave_fgetl (FILE *f, bool& eof) -{ - std::string retval = octave_fgets (f, eof); - - if (! retval.empty () && retval.back () == '\n') - retval.pop_back (); - - return retval; -} - namespace octave { + bool is_int_or_inf_or_nan (double x) + { + return math::isnan (x) || math::x_nint (x) == x; + } + + bool too_large_for_float (double x) + { + return (math::isfinite (x) + && fabs (x) > std::numeric_limits::max ()); + } + + bool too_large_for_float (const Complex& x) + { + return (too_large_for_float (x.real ()) + || too_large_for_float (x.imag ())); + } + + bool is_int_or_inf_or_nan (float x) + { + return math::isnan (x) || math::x_nint (x) == x; + } + + // Save a string. + + char * strsave (const char *s) + { + if (! s) + return nullptr; + + int len = strlen (s); + char *tmp = new char [len+1]; + tmp = strcpy (tmp, s); + return tmp; + } + + std::string fgets (FILE *f) + { + bool eof; + return fgets (f, eof); + } + + std::string fgets (FILE *f, bool& eof) + { + eof = false; + + std::string retval; + + int grow_size = 1024; + int max_size = grow_size; + + char *buf = static_cast (std::malloc (max_size)); + if (! buf) + (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); + + char *bufptr = buf; + int len = 0; + + do + { + if (std::fgets (bufptr, grow_size, f)) + { + len = strlen (bufptr); + + if (len == grow_size - 1) + { + int tmp = bufptr - buf + grow_size - 1; + grow_size *= 2; + max_size += grow_size; + auto tmpbuf = static_cast (std::realloc (buf, max_size)); + if (! tmpbuf) + { + free (buf); + (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); + } + buf = tmpbuf; + bufptr = buf + tmp; + + if (*(bufptr-1) == '\n') + { + *bufptr = '\0'; + retval = buf; + } + } + else if (bufptr[len-1] != '\n') + { + bufptr[len++] = '\n'; + bufptr[len] = '\0'; + retval = buf; + } + else + retval = buf; + } + else + { + if (len == 0) + { + eof = true; + + free (buf); + + buf = nullptr; + } + + break; + } + } + while (retval.empty ()); + + free (buf); + + octave_quit (); + + return retval; + } + + std::string fgetl (FILE *f) + { + bool eof; + return fgetl (f, eof); + } + + std::string fgetl (FILE *f, bool& eof) + { + std::string retval = fgets (f, eof); + + if (! retval.empty () && retval.back () == '\n') + retval.pop_back (); + + return retval; + } + template T read_value (std::istream& is) diff -r 79c6a29dd384 -r da7210e30f3e liboctave/util/lo-utils.h --- a/liboctave/util/lo-utils.h Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/util/lo-utils.h Tue Aug 03 12:34:52 2021 -0400 @@ -37,67 +37,65 @@ #include "oct-cmplx.h" #include "quit.h" -// Generic any/all test functionality with arbitrary predicate. - -template -bool -any_all_test (F fcn, const T *m, octave_idx_type len) -{ - octave_idx_type i; - - for (i = 0; i < len - 3; i += 4) - { - octave_quit (); - - if (fcn (m[i]) != zero - || fcn (m[i+1]) != zero - || fcn (m[i+2]) != zero - || fcn (m[i+3]) != zero) - return ! zero; - } - - octave_quit (); - - for (; i < len; i++) - if (fcn (m[i]) != zero) - return ! zero; - - return zero; -} - -extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); - -template -bool -xis_one_or_zero (const T& x) -{ - return x == T (0) || x == T (1); -} - -template -bool -xis_zero (const T& x) -{ - return x == T (0); -} - -extern OCTAVE_API bool xtoo_large_for_float (double x); - -extern OCTAVE_API bool xtoo_large_for_float (const Complex& x); - -extern OCTAVE_API bool xis_int_or_inf_or_nan (float x); -extern OCTAVE_API bool xtoo_large_for_float (float x); - -extern OCTAVE_API char * strsave (const char *); - -extern OCTAVE_API std::string octave_fgets (std::FILE *); -extern OCTAVE_API std::string octave_fgetl (std::FILE *); - -extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof); -extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof); - namespace octave { + // Generic any/all test functionality with arbitrary predicate. + + template + bool + any_all_test (F fcn, const T *m, octave_idx_type len) + { + octave_idx_type i; + + for (i = 0; i < len - 3; i += 4) + { + octave_quit (); + + if (fcn (m[i]) != zero + || fcn (m[i+1]) != zero + || fcn (m[i+2]) != zero + || fcn (m[i+3]) != zero) + return ! zero; + } + + octave_quit (); + + for (; i < len; i++) + if (fcn (m[i]) != zero) + return ! zero; + + return zero; + } + + extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); + + template + bool is_one_or_zero (const T& x) + { + return x == T (0) || x == T (1); + } + + template + bool is_zero (const T& x) + { + return x == T (0); + } + + extern OCTAVE_API bool too_large_for_float (double x); + + extern OCTAVE_API bool too_large_for_float (const Complex& x); + + extern OCTAVE_API bool is_int_or_inf_or_nan (float x); + extern OCTAVE_API bool too_large_for_float (float x); + + extern OCTAVE_API char * strsave (const char *); + + extern OCTAVE_API std::string fgets (std::FILE *); + extern OCTAVE_API std::string fgetl (std::FILE *); + + extern OCTAVE_API std::string fgets (std::FILE *, bool& eof); + extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof); + template OCTAVE_API T read_value (std::istream& is); template <> OCTAVE_API double read_value (std::istream& is); @@ -139,6 +137,90 @@ } } +template +OCTAVE_DEPRECATED (7, "use 'octave::any_all_test' instead") +bool +any_all_test (F fcn, const T *m, octave_idx_type len) +{ + return octave::any_all_test (fcn, m, len); +} + +OCTAVE_DEPRECATED (7, "use 'octave::is_int_or_inf_or_nan' instead") +inline bool xis_int_or_inf_or_nan (double x) +{ + return octave::is_int_or_inf_or_nan (x); +} + +template +OCTAVE_DEPRECATED (7, "use 'octave::is_one_or_zero' instead") +bool +xis_one_or_zero (const T& x) +{ + return octave::is_one_or_zero (x); +} + +template +OCTAVE_DEPRECATED (7, "use 'octave::is_zero' instead") +bool +xis_zero (const T& x) +{ + return octave::is_zero (x); +} + +OCTAVE_DEPRECATED (7, "use 'octave::' instead") +inline bool xtoo_large_for_float (double x) +{ + return octave::too_large_for_float (x); +} + +OCTAVE_DEPRECATED (7, "use 'octave::' instead") +inline bool xtoo_large_for_float (const Complex& x) +{ + return octave::too_large_for_float (x); +} + +OCTAVE_DEPRECATED (7, "use 'octave::' instead") +inline bool xis_int_or_inf_or_nan (float x) +{ + return octave::is_int_or_inf_or_nan (x); +} + +OCTAVE_DEPRECATED (7, "use 'octave::' instead") +inline bool xtoo_large_for_float (float x) +{ + return octave::too_large_for_float (x); +} + +OCTAVE_DEPRECATED (7, "use 'octave::strsave' instead") +inline char * strsave (const char *s) +{ + return octave::strsave (s); +} + +OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead") +inline std::string octave_fgets (std::FILE *f) +{ + return octave::fgets (f); +} + +OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead") +inline std::string octave_fgetl (std::FILE *f) +{ + return octave::fgetl (f); +} + +OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead") +inline std::string octave_fgets (std::FILE *f, bool& eof) +{ + return octave::fgets (f, eof); +} + +OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead") +inline std::string octave_fgetl (std::FILE *f, bool& eof) +{ + return octave::fgetl (f, eof); +} + OCTAVE_DEPRECATED (7, "use 'octave::read_value' instead") inline double octave_read_double (std::istream& is) diff -r 79c6a29dd384 -r da7210e30f3e liboctave/util/str-vec.cc --- a/liboctave/util/str-vec.cc Thu Mar 17 10:50:22 2016 +0530 +++ b/liboctave/util/str-vec.cc Tue Aug 03 12:34:52 2021 -0400 @@ -163,7 +163,7 @@ retval[len] = nullptr; for (octave_idx_type i = 0; i < len; i++) - retval[i] = strsave (elem (i).c_str ()); + retval[i] = octave::strsave (elem (i).c_str ()); return retval; }