Mercurial > octave
diff libinterp/corefcn/oct-stream.cc @ 29654:d13d090cb03a stable
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
Files affected: make_int.cc, file-editor-tab.cc, octave-qscintilla.cc,
Cell.cc, Cell.h, call-stack.cc, call-stack.h, cellfun.cc, data.cc,
debug.cc, dlmread.cc, error.cc, event-queue.h, fcn-info.cc,
fcn-info.h, file-io.cc, ft-text-renderer.cc, gl2ps-print.cc,
graphics.cc, graphics.in.h, help.cc, hex2num.cc, input.cc,
latex-text-renderer.cc, load-path.cc, load-save.cc, load-save.h,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat5.cc, ls-oct-text.cc, mex.cc,
mexproto.h, mxarray.h, oct-map.cc, oct-stream.cc, oct-stream.h,
pager.cc, pager.h, pr-output.cc, regexp.cc, settings.h,
stack-frame.cc, stack-frame.h, strfns.cc, syminfo.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, sysdep.cc, toplev.cc, utils.cc,
utils.h, variables.cc, __fltk_uigetfile__.cc, __init_fltk__.cc,
audioread.cc, gzip.cc, cdef-class.cc, cdef-manager.cc, cdef-method.cc,
cdef-object.cc, cdef-object.h, ov-base-diag.cc, ov-base-diag.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.h, ov-base.cc, ov-base.h, ov-cell.cc, ov-cell.h,
ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-fcn-handle.cc, ov-java.cc, ov-lazy-idx.h, ov-perm.cc, ov-perm.h,
ov-range.h, ov-str-mat.cc, ov-struct.cc, ov-struct.h, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, ovl.cc, octave.cc, bp-table.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.h, lex.h, lex.ll,
oct-lvalue.cc, oct-parse.yy, parse.h, profiler.h, pt-eval.cc,
pt-eval.h, pt-jit.cc, pt-jit.h, pt-pr-code.cc, pt-tm-const.cc,
pt-tm-const.h, Array.h, CMatrix.cc, DiagArray2.h, PermMatrix.h,
Sparse.h, dMatrix.cc, fCMatrix.cc, fMatrix.cc, bsxfun-defs.cc,
oct-fftw.cc, oct-fftw.h, randpoisson.cc, sparse-chol.cc,
mx-inlines.cc, file-ops.cc, lo-sysdep.cc, oct-env.cc, oct-time.cc,
action-container.cc, action-container.h, base-list.h, caseless-str.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, data-conv.h, f77-fcn.h,
file-info.cc, file-info.h, kpse.cc, kpse.h, lo-cutils.h, lo-hash.h,
lo-regexp.cc, oct-base64.cc, oct-base64.h, oct-binmap.h, oct-glob.cc,
oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sparse.h, oct-string.cc,
quit.cc, unwind-prot.h, url-transfer.cc, main.in.cc, mkoctfile.in.cc,
and shared-fcns.h.
(grafted from aef11bb4e6d1f303ad9de5688fcb7244ef48867e)
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Apr 2021 22:57:42 -0400 |
parents | 0a5b15007766 |
children | 32f4357ac8d9 |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc Wed Apr 28 22:23:39 2021 -0400 +++ b/libinterp/corefcn/oct-stream.cc Wed Apr 28 22:57:42 2021 -0400 @@ -203,9 +203,9 @@ { std::string retval; - size_t len = s.length (); - - size_t i = 0; + std::size_t len = s.length (); + + std::size_t i = 0; while (i < len) { @@ -301,7 +301,7 @@ // the list is 3 because of the characters that appear after the // last conversion. - size_t length (void) const { return fmt_elts.size (); } + std::size_t length (void) const { return fmt_elts.size (); } const scanf_format_elt * first (void) { @@ -349,7 +349,7 @@ octave_idx_type nconv; // Index to current element; - size_t curr_idx; + std::size_t curr_idx; // List of format elements. std::deque<scanf_format_elt*> fmt_elts; @@ -360,11 +360,11 @@ void add_elt_to_list (int width, bool discard, char type, char modifier, const std::string& char_class = ""); - void process_conversion (const std::string& s, size_t& i, size_t n, + void process_conversion (const std::string& s, std::size_t& i, std::size_t n, int& width, bool& discard, char& type, char& modifier); - int finish_conversion (const std::string& s, size_t& i, size_t n, + int finish_conversion (const std::string& s, std::size_t& i, std::size_t n, int width, bool discard, char& type, char modifier); }; @@ -372,9 +372,9 @@ scanf_format_list::scanf_format_list (const std::string& s) : nconv (0), curr_idx (0), fmt_elts (), buf () { - size_t n = s.length (); - - size_t i = 0; + std::size_t n = s.length (); + + std::size_t i = 0; int width = 0; bool discard = false; @@ -443,9 +443,9 @@ scanf_format_list::~scanf_format_list (void) { - size_t n = fmt_elts.size (); - - for (size_t i = 0; i < n; i++) + std::size_t n = fmt_elts.size (); + + for (std::size_t i = 0; i < n; i++) { scanf_format_elt *elt = fmt_elts[i]; delete elt; @@ -473,8 +473,8 @@ } void - scanf_format_list::process_conversion (const std::string& s, size_t& i, - size_t n, int& width, bool& discard, + scanf_format_list::process_conversion (const std::string& s, std::size_t& i, + std::size_t n, int& width, bool& discard, char& type, char& modifier) { width = 0; @@ -580,16 +580,16 @@ } int - scanf_format_list::finish_conversion (const std::string& s, size_t& i, - size_t n, int width, bool discard, + scanf_format_list::finish_conversion (const std::string& s, std::size_t& i, + std::size_t n, int width, bool discard, char& type, char modifier) { int retval = 0; std::string char_class; - size_t beg_idx = std::string::npos; - size_t end_idx = std::string::npos; + std::size_t beg_idx = std::string::npos; + std::size_t end_idx = std::string::npos; if (s[i] == '%') { @@ -658,9 +658,9 @@ void scanf_format_list::printme (void) const { - size_t n = fmt_elts.size (); - - for (size_t i = 0; i < n; i++) + std::size_t n = fmt_elts.size (); + + for (std::size_t i = 0; i < n; i++) { scanf_format_elt *elt = fmt_elts[i]; @@ -686,11 +686,11 @@ bool scanf_format_list::all_character_conversions (void) { - size_t n = fmt_elts.size (); + std::size_t n = fmt_elts.size (); if (n > 0) { - for (size_t i = 0; i < n; i++) + for (std::size_t i = 0; i < n; i++) { scanf_format_elt *elt = fmt_elts[i]; @@ -716,11 +716,11 @@ bool scanf_format_list::all_numeric_conversions (void) { - size_t n = fmt_elts.size (); + std::size_t n = fmt_elts.size (); if (n > 0) { - for (size_t i = 0; i < n; i++) + for (std::size_t i = 0; i < n; i++) { scanf_format_elt *elt = fmt_elts[i]; @@ -811,7 +811,7 @@ return length () > 0 ? fmt_elts[curr_idx] : nullptr; } - size_t length (void) const { return fmt_elts.size (); } + std::size_t length (void) const { return fmt_elts.size (); } const printf_format_elt * next (bool cycle = true) { @@ -843,7 +843,7 @@ octave_idx_type nconv; // Index to current element; - size_t curr_idx; + std::size_t curr_idx; // List of format elements. std::deque<printf_format_elt*> fmt_elts; @@ -854,11 +854,11 @@ void add_elt_to_list (int args, const std::string& flags, int fw, int prec, char type, char modifier); - void process_conversion (const std::string& s, size_t& i, size_t n, + void process_conversion (const std::string& s, std::size_t& i, std::size_t n, int& args, std::string& flags, int& fw, int& prec, char& modifier, char& type); - void finish_conversion (const std::string& s, size_t& i, int args, + void finish_conversion (const std::string& s, std::size_t& i, int args, const std::string& flags, int fw, int prec, char modifier, char& type); }; @@ -866,9 +866,9 @@ printf_format_list::printf_format_list (const std::string& s) : nconv (0), curr_idx (0), fmt_elts (), buf () { - size_t n = s.length (); - - size_t i = 0; + std::size_t n = s.length (); + + std::size_t i = 0; int args = 0; std::string flags; @@ -947,9 +947,9 @@ printf_format_list::~printf_format_list (void) { - size_t n = fmt_elts.size (); - - for (size_t i = 0; i < n; i++) + std::size_t n = fmt_elts.size (); + + for (std::size_t i = 0; i < n; i++) { printf_format_elt *elt = fmt_elts[i]; delete elt; @@ -977,8 +977,8 @@ } void - printf_format_list::process_conversion (const std::string& s, size_t& i, - size_t n, int& args, + printf_format_list::process_conversion (const std::string& s, std::size_t& i, + std::size_t n, int& args, std::string& flags, int& fw, int& prec, char& modifier, char& type) @@ -1092,7 +1092,7 @@ } void - printf_format_list::finish_conversion (const std::string& s, size_t& i, + printf_format_list::finish_conversion (const std::string& s, std::size_t& i, int args, const std::string& flags, int fw, int prec, char modifier, char& type) @@ -1149,9 +1149,9 @@ void printf_format_list::printme (void) const { - size_t n = fmt_elts.size (); - - for (size_t i = 0; i < n; i++) + std::size_t n = fmt_elts.size (); + + for (std::size_t i = 0; i < n; i++) { printf_format_elt *elt = fmt_elts[i]; @@ -1443,7 +1443,7 @@ if (eob < idx) idx = eob; - size_t old_remaining = eob - idx; + std::size_t old_remaining = eob - idx; octave_quit (); // allow ctrl-C @@ -1695,7 +1695,7 @@ // the list is 3 because of the characters that appear after the // last conversion. - size_t numel (void) const { return fmt_elts.size (); } + std::size_t numel (void) const { return fmt_elts.size (); } const textscan_format_elt * first (void) { @@ -1749,7 +1749,7 @@ octave_idx_type nconv; // Index to current element; - size_t curr_idx; + std::size_t curr_idx; // List of format elements. std::deque<textscan_format_elt*> fmt_elts; @@ -1765,11 +1765,11 @@ char type, const std::string& char_class = std::string ()); - void process_conversion (const std::string& s, size_t& i, size_t n); + void process_conversion (const std::string& s, std::size_t& i, std::size_t n); std::string parse_char_class (const std::string& pattern) const; - int finish_conversion (const std::string& s, size_t& i, size_t n, + int finish_conversion (const std::string& s, std::size_t& i, std::size_t n, unsigned int width, int prec, int bitwidth, octave_value& val_type, bool discard, char& type); @@ -1935,9 +1935,9 @@ : who (who_arg), set_from_first (false), has_string (false), nconv (0), curr_idx (0), fmt_elts (), buf () { - size_t n = s.length (); - - size_t i = 0; + std::size_t n = s.length (); + + std::size_t i = 0; unsigned int width = -1; // Unspecified width = max (except %c) int prec = -1; @@ -2032,9 +2032,9 @@ textscan_format_list::~textscan_format_list (void) { - size_t n = numel (); - - for (size_t i = 0; i < n; i++) + std::size_t n = numel (); + + for (std::size_t i = 0; i < n; i++) { textscan_format_elt *elt = fmt_elts[i]; delete elt; @@ -2066,8 +2066,8 @@ } void - textscan_format_list::process_conversion (const std::string& s, size_t& i, - size_t n) + textscan_format_list::process_conversion (const std::string& s, std::size_t& i, + std::size_t n) { unsigned width = 0; int prec = -1; @@ -2349,8 +2349,8 @@ } int - textscan_format_list::finish_conversion (const std::string& s, size_t& i, - size_t n, unsigned int width, + textscan_format_list::finish_conversion (const std::string& s, std::size_t& i, + std::size_t n, unsigned int width, int prec, int bitwidth, octave_value& val_type, bool discard, char& type) @@ -2359,8 +2359,8 @@ std::string char_class; - size_t beg_idx = std::string::npos; - size_t end_idx = std::string::npos; + std::size_t beg_idx = std::string::npos; + std::size_t end_idx = std::string::npos; if (type != '%') { @@ -2418,9 +2418,9 @@ void textscan_format_list::printme (void) const { - size_t n = numel (); - - for (size_t i = 0; i < n; i++) + std::size_t n = numel (); + + for (std::size_t i = 0; i < n; i++) { textscan_format_elt *elt = fmt_elts[i]; @@ -3101,7 +3101,7 @@ for (int i = 0; i < delimiters.numel (); i++) { std::string delim = delimiters(i).string_value (); - size_t start = (retval.length () > delim.length () + std::size_t start = (retval.length () > delim.length () ? retval.length () - delim.length () : 0); std::string may_match = retval.substr (start); @@ -3139,7 +3139,7 @@ // Grow string in an exponential fashion if necessary. if (i >= val.length ()) val.append (std::max (val.length (), - static_cast<size_t> (16)), '\0'); + static_cast<std::size_t> (16)), '\0'); int ch = is.get (); if (is_delim (ch) || ch == std::istream::traits_type::eof ()) @@ -3432,7 +3432,7 @@ octave_quit (); - for (size_t i = 0; i < fmt_list.numel (); i++) + for (std::size_t i = 0; i < fmt_list.numel (); i++) { bool this_conversion_failed = false; @@ -3825,7 +3825,7 @@ may_match = may_match + dummy + last; if (may_match.length () > end_c.length ()) { - size_t start = may_match.length () - end_c.length (); + std::size_t start = may_match.length () - end_c.length (); may_match = may_match.substr (start); } } @@ -3869,7 +3869,7 @@ // FIXME: pos may be corrupted by is.read int i; - int (*compare)(const char *, const char *, size_t); + int (*compare)(const char *, const char *, std::size_t); compare = (case_sensitive ? strncmp : strncasecmp); for (i = 0; i < targets.numel (); i++) @@ -5635,7 +5635,7 @@ return retval; } - static size_t + static std::size_t do_printf_string (std::ostream& os, const printf_format_elt *elt, int nsa, int sa_1, int sa_2, const std::string& arg, const std::string& encoding, const std::string& who) @@ -5647,19 +5647,19 @@ bool left = flags.find ('-') != std::string::npos; - size_t len = arg.length (); - - size_t prec = (nsa > 1 ? sa_2 : (elt->prec == -1 ? len : elt->prec)); + std::size_t len = arg.length (); + + std::size_t prec = (nsa > 1 ? sa_2 : (elt->prec == -1 ? len : elt->prec)); std::string print_str = prec < arg.length () ? arg.substr (0, prec) : arg; if (encoding.compare ("utf-8")) { - size_t src_len = print_str.length (); + std::size_t src_len = print_str.length (); print_str = string::u8_to_encoding (who, print_str, encoding); len -= src_len - print_str.length (); } - size_t fw = (nsa > 0 ? sa_1 : (elt->fw == -1 ? len : elt->fw)); + std::size_t fw = (nsa > 0 ? sa_1 : (elt->fw == -1 ? len : elt->fw)); os << std::setw (fw) << (left ? std::left : std::right) << print_str; @@ -6600,9 +6600,9 @@ // oct_data_conv class. // Expose this in a future version? - size_t char_count = 0; - - ptrdiff_t tmp_count = 0; + std::size_t char_count = 0; + + std::ptrdiff_t tmp_count = 0; try { @@ -6661,8 +6661,8 @@ octave_idx_type input_elt_size = oct_data_conv::data_type_size (input_type); - ptrdiff_t input_buf_size - = static_cast<ptrdiff_t> (input_buf_elts) * input_elt_size; + std::ptrdiff_t input_buf_size + = static_cast<std::ptrdiff_t> (input_buf_elts) * input_elt_size; assert (input_buf_size >= 0); @@ -6703,7 +6703,7 @@ is.read (input_buf, input_buf_size); - size_t gcount = is.gcount (); + std::size_t gcount = is.gcount (); char_count += gcount; cur_pos += gcount; @@ -6947,7 +6947,7 @@ } bool - stream::write_bytes (const void *data, size_t nbytes) + stream::write_bytes (const void *data, std::size_t nbytes) { bool status = false; @@ -6970,7 +6970,7 @@ } bool - stream::skip_bytes (size_t skip) + stream::skip_bytes (std::size_t skip) { bool status = false; @@ -6992,7 +6992,7 @@ // Is it possible for this to fail to return us to the original position? seek (orig_pos, SEEK_SET); - size_t remaining = eof_pos - orig_pos; + std::size_t remaining = eof_pos - orig_pos; if (remaining < skip) { @@ -7000,7 +7000,7 @@ // FIXME: probably should try to write larger blocks... unsigned char zero = 0; - for (size_t j = 0; j < skip - remaining; j++) + for (std::size_t j = 0; j < skip - remaining; j++) os.write (reinterpret_cast<const char *> (&zero), 1); } else @@ -7061,7 +7061,7 @@ if (do_data_conversion) { - size_t output_size + std::size_t output_size = chunk_size * oct_data_conv::data_type_size (output_type); OCTAVE_LOCAL_BUFFER (unsigned char, conv_data, output_size);