changeset 29656:7f5bd197fea6 stable

maint: use std::size_t in more instances (bug #60471) * file-editor-tab.cc, debug.cc, hook-fcn.h, variables.cc, lex.ll, pt-eval.cc, pt-eval.h, file-ops.cc, lo-sysdep.cc, file-info.h, betaincinv.m, mkoctfile.in.cc: use std::size_t rather than just size_t.
author Rik <rik@octave.org>
date Wed, 12 May 2021 20:03:41 -0700
parents d13d090cb03a
children ce4436d2b206 2a1f57067fbf
files libgui/src/m-editor/file-editor-tab.cc libinterp/corefcn/debug.cc libinterp/corefcn/hook-fcn.h libinterp/corefcn/variables.cc libinterp/parse-tree/lex.ll libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h liboctave/system/file-ops.cc liboctave/system/lo-sysdep.cc liboctave/util/file-info.h scripts/specfun/betaincinv.m src/mkoctfile.in.cc
diffstat 12 files changed, 61 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Wed May 12 20:03:41 2021 -0700
@@ -1135,7 +1135,7 @@
     // Is the last component of DIR @foo?  If so, strip it and prepend it
     // to the name of the function.
 
-    size_t pos = dir.rfind (sys::file_ops::dir_sep_chars ());
+    std::size_t pos = dir.rfind (sys::file_ops::dir_sep_chars ());
 
     if (pos != std::string::npos && pos < dir.length () - 1)
       {
--- a/libinterp/corefcn/debug.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/corefcn/debug.cc	Wed May 12 20:03:41 2021 -0700
@@ -66,7 +66,7 @@
 
   NDArray retval (dim_vector (1, line.size ()));
 
-  for (size_t i = 0; i < line.size (); i++)
+  for (std::size_t i = 0; i < line.size (); i++)
     {
       octave::bp_table::const_intmap_iterator p = line.find (i);
 
--- a/libinterp/corefcn/hook-fcn.h	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/corefcn/hook-fcn.h	Wed May 12 20:03:41 2021 -0700
@@ -56,7 +56,7 @@
 
 protected:
 
-  size_t count;
+  std::size_t count;
 };
 
 class
--- a/libinterp/corefcn/variables.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/corefcn/variables.cc	Wed May 12 20:03:41 2021 -0700
@@ -1528,9 +1528,9 @@
 {
   int n = 1;
 
-  size_t pos = 0;
+  std::size_t pos = 0;
 
-  size_t len = text.length ();
+  std::size_t len = text.length ();
 
   while ((pos = text.find ('.', pos)) != std::string::npos)
     {
--- a/libinterp/parse-tree/lex.ll	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/parse-tree/lex.ll	Wed May 12 20:03:41 2021 -0700
@@ -2979,7 +2979,7 @@
       {
         uintmax_t long_int_value = 0;
 
-        for (size_t i = 0; i < strlen (tmptxt); i++)
+        for (std::size_t i = 0; i < strlen (tmptxt); i++)
           {
             if (tmptxt[i] == '0')
               long_int_value <<= 1;
--- a/libinterp/parse-tree/pt-eval.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Wed May 12 20:03:41 2021 -0700
@@ -730,7 +730,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -755,7 +755,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -2372,7 +2372,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -2424,7 +2424,7 @@
   void
   tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd)
   {
-    size_t line = cmd.line ();
+    std::size_t line = cmd.line ();
 
     if (m_echo_state)
       {
@@ -2558,7 +2558,7 @@
   void
   tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd)
   {
-    size_t line = cmd.line ();
+    std::size_t line = cmd.line ();
 
     if (m_echo_state)
       {
@@ -2716,7 +2716,7 @@
       return retval;
 #endif
 
-    if (m_call_stack.size () >= static_cast<size_t> (m_max_recursion_depth))
+    if (m_call_stack.size () >= static_cast<std::size_t> (m_max_recursion_depth))
       error ("max_recursion_depth exceeded");
 
     Matrix ignored_outputs = ignored_fcn_outputs ();
@@ -2857,7 +2857,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -2926,7 +2926,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -2970,7 +2970,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -3019,7 +3019,7 @@
               {
                 if (m_echo_state)
                   {
-                    size_t line = stmt.line ();
+                    std::size_t line = stmt.line ();
                     echo_code (line);
                     m_echo_file_pos = line + 1;
                   }
@@ -3169,7 +3169,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -3209,7 +3209,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -3361,7 +3361,7 @@
   {
     if (m_echo_state)
       {
-        size_t line = cmd.line ();
+        std::size_t line = cmd.line ();
         echo_code (line);
         m_echo_file_pos = line + 1;
       }
@@ -3412,7 +3412,7 @@
   void
   tree_evaluator::visit_while_command (tree_while_command& cmd)
   {
-    size_t line = cmd.line ();
+    std::size_t line = cmd.line ();
 
     if (m_echo_state)
       {
@@ -3458,7 +3458,7 @@
   void
   tree_evaluator::visit_do_until_command (tree_do_until_command& cmd)
   {
-    size_t line = cmd.line ();
+    std::size_t line = cmd.line ();
 
     if (m_echo_state)
       {
@@ -3877,7 +3877,7 @@
 
   void
   tree_evaluator::push_echo_state (int type, const std::string& file_name,
-                                   size_t pos)
+                                   std::size_t pos)
   {
     unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame ();
 
@@ -3891,7 +3891,7 @@
 
   void
   tree_evaluator::set_echo_state (int type, const std::string& file_name,
-                                  size_t pos)
+                                  std::size_t pos)
   {
     m_echo_state = echo_this_file (file_name, type);
     m_echo_file_name = file_name;
@@ -3900,7 +3900,7 @@
 
   void
   tree_evaluator::uwp_set_echo_state (bool state, const std::string& file_name,
-                                      size_t pos)
+                                      std::size_t pos)
   {
     m_echo_state = state;
     m_echo_file_name = file_name;
@@ -3920,7 +3920,7 @@
 
         std::string file_name = fcn->fcn_file_name ();
 
-        size_t pos = m_call_stack.current_line ();
+        std::size_t pos = m_call_stack.current_line ();
 
         set_echo_state (type, file_name, pos);
       }
@@ -4263,7 +4263,7 @@
     return false;
   }
 
-  void tree_evaluator::echo_code (size_t line)
+  void tree_evaluator::echo_code (std::size_t line)
   {
     std::string prefix = command_editor::decode_prompt_string (m_PS4);
 
@@ -4273,7 +4273,7 @@
       {
         octave_user_code *code = dynamic_cast<octave_user_code *> (curr_fcn);
 
-        size_t num_lines = line - m_echo_file_pos + 1;
+        std::size_t num_lines = line - m_echo_file_pos + 1;
 
         std::deque<std::string> lines
           = code->get_code_lines (m_echo_file_pos, num_lines);
--- a/libinterp/parse-tree/pt-eval.h	Wed Apr 28 22:57:42 2021 -0400
+++ b/libinterp/parse-tree/pt-eval.h	Wed May 12 20:03:41 2021 -0700
@@ -744,11 +744,11 @@
     std::list<octave_lvalue> make_lvalue_list (tree_argument_list *);
 
     void push_echo_state (int type, const std::string& file_name,
-                          size_t pos = 1);
+                          std::size_t pos = 1);
 
   private:
 
-    void set_echo_state (int type, const std::string& file_name, size_t pos);
+    void set_echo_state (int type, const std::string& file_name, std::size_t pos);
 
     void maybe_set_echo_state (void);
 
@@ -765,11 +765,11 @@
 
     // For unwind-protect.
     void uwp_set_echo_state (bool state, const std::string& file_name,
-                             size_t pos);
+                             std::size_t pos);
 
     bool echo_this_file (const std::string& file, int type) const;
 
-    void echo_code (size_t line);
+    void echo_code (std::size_t line);
 
     bool quit_loop_now (void);
 
@@ -848,7 +848,7 @@
     std::string m_echo_file_name;
 
     // Next line to echo, counting from 1.
-    size_t m_echo_file_pos;
+    std::size_t m_echo_file_pos;
 
     std::map<std::string, bool> m_echo_files;
 
--- a/liboctave/system/file-ops.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/liboctave/system/file-ops.cc	Wed May 12 20:03:41 2021 -0700
@@ -714,7 +714,7 @@
       const char *locale = octave_locale_charset_wrapper ();
       const uint8_t *name_u8 = reinterpret_cast<const uint8_t *>
                                  (name.c_str ());
-      size_t length = 0;
+      std::size_t length = 0;
       char *name_locale = octave_u8_conv_to_encoding (locale, name_u8,
                                                       name.length () + 1,
                                                       &length);
--- a/liboctave/system/lo-sysdep.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/liboctave/system/lo-sysdep.cc	Wed May 12 20:03:41 2021 -0700
@@ -467,11 +467,11 @@
     std::wstring
     u8_to_wstring (const std::string& utf8_string)
     {
-      size_t srclen = utf8_string.length ();
+      std::size_t srclen = utf8_string.length ();
       const uint8_t *src = reinterpret_cast<const uint8_t *>
                            (utf8_string.c_str ());
 
-      size_t length = 0;
+      std::size_t length = 0;
       wchar_t *wchar = reinterpret_cast<wchar_t *>
                        (octave_u8_conv_to_encoding ("wchar_t", src, srclen,
                                                     &length));
@@ -489,10 +489,10 @@
     std::string
     u8_from_wstring (const std::wstring& wchar_string)
     {
-      size_t srclen = wchar_string.length () * sizeof (wchar_t);
+      std::size_t srclen = wchar_string.length () * sizeof (wchar_t);
       const char *src = reinterpret_cast<const char *> (wchar_string.c_str ());
 
-      size_t length = 0;
+      std::size_t length = 0;
       char *mbchar = reinterpret_cast<char *>
                      (octave_u8_conv_from_encoding ("wchar_t", src, srclen,
                                                     &length));
--- a/liboctave/util/file-info.h	Wed Apr 28 22:57:42 2021 -0400
+++ b/liboctave/util/file-info.h	Wed May 12 20:03:41 2021 -0700
@@ -64,7 +64,7 @@
 
     std::string get_line (std::size_t line) const;
 
-    std::deque<std::string> get_lines (size_t line, size_t num_lines) const;
+    std::deque<std::string> get_lines (std::size_t line, std::size_t num_lines) const;
 
     std::size_t num_lines (void) const { return m_offsets.size (); }
 
--- a/scripts/specfun/betaincinv.m	Wed Apr 28 22:57:42 2021 -0400
+++ b/scripts/specfun/betaincinv.m	Wed May 12 20:03:41 2021 -0700
@@ -84,7 +84,7 @@
 
 function x = betaincinv (y, a, b, tail = "lower")
 
-  if (nargin < 3 || nargin > 4)
+  if (nargin < 3)
     print_usage ();
   endif
 
@@ -93,13 +93,11 @@
     error ("betaincinv: Y, A, and B must be of common size or scalars");
   endif
 
-  if (iscomplex (y) || iscomplex (a) || iscomplex (b))
-    error ("betaincinv: all inputs must be real");
+  if (! (isfloat (y) && isfloat (a) && isfloat (b)
+         && isreal (y) && isreal (a) && isreal (b)))
+    error ("betaincinv: Y, A, and B must be real, floating point values");
   endif
 
-  ## FIXME: Should there be isnumeric checking?  Right now it accepts char
-  ##        arrays, but then produces a weird error later on.
-
   ## Remember original shape of data, but convert to column vector for calcs.
   orig_sz = size (y);
   y = y(:);
@@ -119,28 +117,16 @@
   endif
 
   ## If any of the arguments is single then the output should be as well.
-  if (strcmp (class (y), "single") || strcmp (class (a), "single")
-      || strcmp (class (b), "single"))
+  if (isa (y, "single") || isa (a, "single") || isa (b, "single"))
     y = single (y);
     a = single (a);
     b = single (b);
   endif
 
-  ## Convert to floating point if necessary
-  if (isinteger (y))
-    y = double (y);
-  endif
-  if (isinteger (a))
-    a = double (a);
-  endif
-  if (isinteger (b))
-    b = double (b);
-  endif
-
   ## Initialize output array
   x = zeros (size (y), class (y));
 
-  ## Parameters for the Newton method
+  ## Parameters for the Newton's method search
   maxit = 20;
   tol = eps (class (y));
 
@@ -170,8 +156,8 @@
     n = nnz (idx);
     ## Function and derivative of the lower version.
     F = @(x, a, b, y) y - betainc (x, a, b);
-    JF = @(x, a, b) - real (exp ((a-1) .* log (x) + (b-1) .* log1p (-x) + ...
-                            gammaln (a+b) - gammaln (a) - gammaln (b)));
+    JF = @(x, a, b) -real (exp ((a-1) .* log (x) + (b-1) .* log1p (-x) + ...
+                           gammaln (a+b) - gammaln (a) - gammaln (b)));
 
     ## Compute the initial guess with a bisection method of 10 steps.
     x0 = bisection_method (F, zeros (n,1), ones (n,1), ...
@@ -225,9 +211,8 @@
 endfunction
 
 function x = newton_method (F, JF, x0, a, b, y, tol, maxit);
-  l = numel (y);
   res = -F (x0, a, b, y) ./ JF (x0, a, b);
-  todo = (abs(res) >= tol * abs (x0));
+  todo = (abs (res) >= tol * abs (x0));
   x = x0;
   it = 0;
   while (any (todo) && (it < maxit))
@@ -276,10 +261,7 @@
 %!assert (class (betaincinv (0.5, 1, 1)), "double")
 %!assert (class (betaincinv (single (0.5), 1, 1)), "single")
 %!assert (class (betaincinv (0.5, single (1), 1)), "single")
-%!assert (class (betaincinv (int8 (0), 1, 1)), "double")
-%!assert (class (betaincinv (0.5, int8 (1), 1)), "double")
-%!assert (class (betaincinv (int8 (0), single (1), 1)), "single")
-%!assert (class (betaincinv (single (0.5), int8 (1), 1)), "single")
+%!assert (class (betaincinv (0.5, 1, single (1))), "single")
 
 %!assert <*60528> (betaincinv (1e-6, 1, 3), 3.3333344444450657e-07, 5*eps)
 %!assert <*60528> (betaincinv (1-1e-6, 3, 1), 0.999999666666556, 5*eps)
@@ -288,12 +270,16 @@
 %!error betaincinv ()
 %!error betaincinv (1)
 %!error betaincinv (1,2)
-%!error betaincinv (1,2,3,4,5)
 %!error <must be of common size or scalars>
 %! betaincinv (ones (2,2), ones (1,2), 1);
-%!error <all inputs must be real> betaincinv (0.5i, 1, 2)
-%!error <all inputs must be real> betaincinv (0, 1i, 1)
-%!error <all inputs must be real> betaincinv (0, 1, 1i)
+
+%!error <must be .* floating point> betaincinv ('a', 1, 2)
+%!error <must be .* floating point> betaincinv (0, int8 (1), 1)
+%!error <must be .* floating point> betaincinv (0, 1, true)
+%!error <must be real> betaincinv (0.5i, 1, 2)
+%!error <must be real> betaincinv (0, 1i, 1)
+%!error <must be real> betaincinv (0, 1, 1i)
+
 %!error <Y must be in the range \[0, 1\]> betaincinv (-0.1,1,1)
 %!error <Y must be in the range \[0, 1\]> betaincinv (1.1,1,1)
 %!error <Y must be in the range \[0, 1\]>
--- a/src/mkoctfile.in.cc	Wed Apr 28 22:57:42 2021 -0400
+++ b/src/mkoctfile.in.cc	Wed May 12 20:03:41 2021 -0700
@@ -92,7 +92,7 @@
 
 static char *
 octave_u8_conv_to_encoding (const char *tocode, const uint8_t *src,
-                            size_t srclen, size_t *lengthp)
+                            std::size_t srclen, std::size_t *lengthp)
 {
   // FIXME: Do we need to provide the conversion here?
   return nullptr;
@@ -937,11 +937,11 @@
           // FIXME: liboctinterp isn't linked in to mkoctfile.
           // So we cannot use octave::sys::ofstream. Instead we fall back
           // on using the functions available from libwrappers.
-          size_t srclen = dfile.length ();
+          std::size_t srclen = dfile.length ();
           const uint8_t *src = reinterpret_cast<const uint8_t *>
                                (dfile.c_str ());
 
-          size_t length = 0;
+          std::size_t length = 0;
           wchar_t *wchar = reinterpret_cast<wchar_t *>
                            (octave_u8_conv_to_encoding ("wchar_t", src, srclen,
                                                         &length));
@@ -996,11 +996,11 @@
           // FIXME: liboctinterp isn't linked in to mkoctfile.
           // So we cannot use octave::sys::ofstream. Instead we fall back
           // on using the functions available from libwrappers.
-          size_t srclen = dfile.length ();
+          std::size_t srclen = dfile.length ();
           const uint8_t *src = reinterpret_cast<const uint8_t *>
                                (dfile.c_str ());
 
-          size_t length = 0;
+          std::size_t length = 0;
           wchar_t *wchar = reinterpret_cast<wchar_t *>
                            (octave_u8_conv_to_encoding ("wchar_t", src, srclen,
                                                         &length));