Mercurial > jwe > octave
changeset 20700:68e3a747ca02
rename octave_value value extractors that accept error message args
* ov.h, ov.cc (octave_value::xcell_value, octave_value::xstring_value,
octave_value::xcellstr_value): Rename functions that accept error
message args. Handle error directly. Only forward to functions that
don't attempt type conversion. Change all uses.
* ov-base.h, ov-base.cc (octave_base_value::xstring_value): Don't do
type conversion.
(octave_base_value::cell_value, octave_base_value::cellstr_value):
Delete versions that accept error message args.
* ov-str-mat.h, ov-str-mat.cc (octave_char_matrix_str::string_value,
octave_char_matrix_str::cell_value): Delete.
line wrap: on
line diff
--- a/libinterp/corefcn/__dispatch__.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/__dispatch__.cc Fri Nov 13 14:10:26 2015 -0500 @@ -50,13 +50,13 @@ { std::string f, r, t; - f = args(0).string_value ("__dispatch__: first argument must be a function name"); + f = args(0).xstring_value ("__dispatch__: first argument must be a function name"); if (nargin > 1) - r = args(1).string_value ("__dispatch__: second argument must be a function name"); + r = args(1).xstring_value ("__dispatch__: second argument must be a function name"); if (nargin > 2) - t = args(2).string_value ("__dispatch__: third argument must be a type name"); + t = args(2).xstring_value ("__dispatch__: third argument must be a type name"); if (nargin == 1) {
--- a/libinterp/corefcn/balance.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/balance.cc Fri Nov 13 14:10:26 2015 -0500 @@ -244,7 +244,7 @@ if (nargin == 2) bal_job = "B"; else - bal_job = args(2).string_value ("balance: OPT argument must be a string"); + bal_job = args(2).xstring_value ("balance: OPT argument must be a string"); if ((nn != args(1).columns ()) || (nn != args(1).rows ())) {
--- a/libinterp/corefcn/cellfun.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/cellfun.cc Fri Nov 13 14:10:26 2015 -0500 @@ -2463,7 +2463,7 @@ if (args.length () >= 1) { - const Cell x = args(0).cell_value ("cellindexmat: X must be a cell"); + const Cell x = args(0).xcell_value ("cellindexmat: X must be a cell"); NoAlias<Cell> y(x.dims ()); octave_idx_type nel = x.numel (); octave_value_list idx = args.slice (1, args.length () - 1);
--- a/libinterp/corefcn/colloc.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/colloc.cc Fri Nov 13 14:10:26 2015 -0500 @@ -80,7 +80,7 @@ for (int i = 1; i < nargin; i++) { - std::string s = args(i).string_value ("colloc: expecting string argument \"left\" or \"right\""); + std::string s = args(i).xstring_value ("colloc: expecting string argument \"left\" or \"right\""); if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) || s == "right")
--- a/libinterp/corefcn/conv2.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/conv2.cc Fri Nov 13 14:10:26 2015 -0500 @@ -329,7 +329,7 @@ return retval; } else if (nargin == 3) - shape = args(2).string_value ("convn: SHAPE must be a string"); + shape = args(2).xstring_value ("convn: SHAPE must be a string"); if (shape == "full") ct = convn_full;
--- a/libinterp/corefcn/data.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/data.cc Fri Nov 13 14:10:26 2015 -0500 @@ -6661,7 +6661,7 @@ return retval; } - std::string mode = args(2).string_value ("sort: MODE must be a string"); + std::string mode = args(2).xstring_value ("sort: MODE must be a string"); if (mode == "ascend") smode = ASCENDING; @@ -6940,7 +6940,7 @@ // FIXME: shouldn't these modes be scoped inside a class? sortmode smode = UNSORTED; - std::string mode = arg.string_value ("issorted: expecting %s argument to be a string", argn); + std::string mode = arg.xstring_value ("issorted: expecting %s argument to be a string", argn); if (mode == "ascending") smode = ASCENDING; @@ -6995,7 +6995,7 @@ if (nargin == 3) smode = get_sort_mode_option (args(2), "third"); - std::string tmp = args(1).string_value ("issorted: second argument must be a string"); + std::string tmp = args(1).xstring_value ("issorted: second argument must be a string"); if (tmp == "rows") by_rows = true; else
--- a/libinterp/corefcn/debug.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/debug.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1389,7 +1389,7 @@ print_usage (); else if (nargin == 1) { - std::string arg = args(0).string_value ("dbstep: input argument must be a string"); + std::string arg = args(0).xstring_value ("dbstep: input argument must be a string"); if (arg == "in") {
--- a/libinterp/corefcn/dirfns.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/dirfns.cc Fri Nov 13 14:10:26 2015 -0500 @@ -184,7 +184,7 @@ if (args.length () == 1) { - std::string dirname = args(0).string_value ("readdir: DIR must be a string"); + std::string dirname = args(0).xstring_value ("readdir: DIR must be a string"); dir_entry dir (dirname); @@ -240,13 +240,13 @@ if (nargin == 2) { - std::string parent = args(0).string_value ("mkdir: PARENT must be a string"); - std::string dir = args(1).string_value ("mkdir: DIR must be a string"); + std::string parent = args(0).xstring_value ("mkdir: PARENT must be a string"); + std::string dir = args(1).xstring_value ("mkdir: DIR must be a string"); dirname = file_ops::concat (parent, dir); } else if (nargin == 1) - dirname = args(0).string_value ("mkdir: DIR must be a string"); + dirname = args(0).xstring_value ("mkdir: DIR must be a string"); if (nargin == 1 || nargin == 2) { @@ -312,7 +312,7 @@ if (nargin == 1 || nargin == 2) { - std::string dirname = args(0).string_value ("rmdir: DIR must be a string"); + std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); std::string fulldir = file_ops::tilde_expand (dirname); int status = -1; @@ -375,8 +375,8 @@ if (args.length () == 2) { - std::string from = args(0).string_value ("link: OLD must be a string"); - std::string to = args(1).string_value ("link: NEW must be a string"); + std::string from = args(0).xstring_value ("link: OLD must be a string"); + std::string to = args(1).xstring_value ("link: NEW must be a string"); std::string msg; @@ -412,8 +412,8 @@ if (args.length () == 2) { - std::string from = args(0).string_value ("symlink: OLD must be a string"); - std::string to = args(1).string_value ("symlink: NEW must be a string"); + std::string from = args(0).xstring_value ("symlink: OLD must be a string"); + std::string to = args(1).xstring_value ("symlink: NEW must be a string"); std::string msg; @@ -451,7 +451,7 @@ if (args.length () == 1) { - std::string symlink = args(0).string_value ("readlink: SYMLINK must be a string"); + std::string symlink = args(0).xstring_value ("readlink: SYMLINK must be a string"); std::string result; std::string msg; @@ -489,8 +489,8 @@ if (args.length () == 2) { - std::string from = args(0).string_value ("rename: OLD must be a string"); - std::string to = args(1).string_value ("rename: NEW must be a string"); + std::string from = args(0).xstring_value ("rename: OLD must be a string"); + std::string to = args(1).xstring_value ("rename: NEW must be a string"); std::string msg; @@ -659,7 +659,7 @@ retval = file_ops::dir_sep_str (); else if (args.length () == 1) { - std::string s = args(0).string_value ("filesep: argument must be a string"); + std::string s = args(0).xstring_value ("filesep: argument must be a string"); if (s == "all") retval = file_ops::dir_sep_chars (); else @@ -688,7 +688,7 @@ if (nargin == 1) { - std::string sval = args(0).string_value ("pathsep: argument must be a single character"); + std::string sval = args(0).xstring_value ("pathsep: argument must be a single character"); switch (sval.length ()) {
--- a/libinterp/corefcn/file-io.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/file-io.cc Fri Nov 13 14:10:26 2015 -0500 @@ -538,9 +538,9 @@ fid = -1; - std::string name = tc_name.string_value ("%s: file name must be a string", fcn); - std::string mode = tc_mode.string_value ("%s: file mode must be a string", fcn); - std::string arch = tc_arch.string_value ("%s: architecture type must be a string", fcn); + std::string name = tc_name.xstring_value ("%s: file name must be a string", fcn); + std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn); + std::string arch = tc_arch.xstring_value ("%s: architecture type must be a string", fcn); retval = do_stream_open (name, mode, arch, fid); @@ -1325,7 +1325,7 @@ if (! error_state) { - std::string prec = prec_arg.string_value ("fread: PRECISION must be a string"); + std::string prec = prec_arg.xstring_value ("fread: PRECISION must be a string"); int block_size = 1; oct_data_conv::data_type input_type; @@ -1340,7 +1340,7 @@ if (! error_state) { - std::string arch = arch_arg.string_value ("fread: ARCH architecture type must be a string"); + std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); oct_mach_info::float_format flt_fmt = oct_mach_info::string_to_float_format (arch); @@ -1586,7 +1586,7 @@ { int retval = -1; - std::string prec = prec_arg.string_value ("fwrite: PRECISION must be a string"); + std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string"); int block_size = 1; oct_data_conv::data_type output_type; @@ -1599,7 +1599,7 @@ if (! error_state) { - std::string arch = arch_arg.string_value ("fwrite: ARCH architecture type must be a string"); + std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); oct_mach_info::float_format flt_fmt = oct_mach_info::string_to_float_format (arch); @@ -1801,8 +1801,8 @@ if (nargin == 2) { - std::string name = args(0).string_value ("popen: COMMAND must be a string"); - std::string mode = args(1).string_value ("popen: MODE must be a string"); + std::string name = args(0).xstring_value ("popen: COMMAND must be a string"); + std::string mode = args(1).xstring_value ("popen: MODE must be a string"); if (mode == "r") { @@ -1875,12 +1875,12 @@ std::string dir; if (len > 0) - dir = args(0).string_value ("tempname: DIR must be a string"); + dir = args(0).xstring_value ("tempname: DIR must be a string"); std::string pfx ("oct-"); if (len > 1) - pfx = args(1).string_value ("tempname: PREFIX must be a string"); + pfx = args(1).xstring_value ("tempname: PREFIX must be a string"); retval = octave_tempnam (dir, pfx); } @@ -2023,7 +2023,7 @@ if (nargin == 1 || nargin == 2) { - std::string tmpl8 = args(0).string_value ("mkstemp: TEMPLATE argument must be a string"); + std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string"); OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); strcpy (tmp, tmpl8.c_str ());
--- a/libinterp/corefcn/gammainc.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/gammainc.cc Fri Nov 13 14:10:26 2015 -0500 @@ -85,7 +85,7 @@ if (nargin == 3) { - std::string s = args(2).string_value ("gammainc: third argument must be \"lower\" or \"upper\""); + std::string s = args(2).xstring_value ("gammainc: third argument must be \"lower\" or \"upper\""); std::transform (s.begin (), s.end (), s.begin (), tolower);
--- a/libinterp/corefcn/graphics.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/graphics.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1673,7 +1673,7 @@ error ("addproperty: missing possible values for radio property"); else { - std::string sv = args(0).string_value ("addproperty: invalid argument for radio property, expected a string value"); + std::string sv = args(0).xstring_value ("addproperty: invalid argument for radio property, expected a string value"); retval = property (new radio_property (name, h, sv)); @@ -2151,7 +2151,7 @@ { for (int i = 0; i < nargin; i += 2) { - caseless_str pname = args(i).string_value ("set: expecting argument %d to be a property name", i); + caseless_str pname = args(i).xstring_value ("set: expecting argument %d to be a property name", i); octave_value val = args(i+1); @@ -10024,7 +10024,7 @@ if (nargin > 1 && args(1).is_cellstr ()) { - Array<std::string> plist = args(1).cellstr_value ("get: expecting property name or cell array of property names as second argument"); + Array<std::string> plist = args(1).xcellstr_value ("get: expecting property name or cell array of property names as second argument"); octave_idx_type plen = plist.numel (); @@ -10057,7 +10057,7 @@ caseless_str property; if (nargin > 1) - property = args(1).string_value ("get: expecting property name or cell array of property names as second argument"); + property = args(1).xstring_value ("get: expecting property name or cell array of property names as second argument"); vals.resize (dim_vector (len, 1)); @@ -10681,7 +10681,7 @@ if (h.ok ()) { - std::string name = args(1).string_value ("__go_execute_callback__: invalid callback name"); + std::string name = args(1).xstring_value ("__go_execute_callback__: invalid callback name"); if (nargin == 2) gh_manager::execute_callback (h, name); @@ -10855,7 +10855,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("register_graphics_toolkit: TOOLKIT must be a string"); + std::string name = args(0).xstring_value ("register_graphics_toolkit: TOOLKIT must be a string"); gtk_manager::register_toolkit (name); } @@ -10969,9 +10969,9 @@ std::string term, file, debug_file; bool mono; - term = args(0).string_value ("drawnow: invalid terminal TERM, expected a string value"); - - file = args(1).string_value ("drawnow: invalid FILE, expected a string value"); + term = args(0).xstring_value ("drawnow: invalid terminal TERM, expected a string value"); + + file = args(1).xstring_value ("drawnow: invalid FILE, expected a string value"); size_t pos_p = file.find_first_of ("|"); size_t pos_c = file.find_first_not_of ("| "); @@ -11024,7 +11024,7 @@ if (! error_state) { - debug_file = (args.length () > 3 ? args(3).string_value ("drawnow: invalid DEBUG_FILE, expected a string value") : ""); + debug_file = (args.length () > 3 ? args(3).xstring_value ("drawnow: invalid DEBUG_FILE, expected a string value") : ""); graphics_handle h = gcf (); @@ -11099,7 +11099,7 @@ if (! error_state) { - std::string pname = args(1).string_value ("addlistener: invalid property name, expected a string value"); + std::string pname = args(1).xstring_value ("addlistener: invalid property name, expected a string value"); graphics_handle gh = gh_manager::lookup (h); @@ -11166,7 +11166,7 @@ if (! error_state) { - std::string pname = args(1).string_value ("dellistener: invalid property name, expected a string value"); + std::string pname = args(1).xstring_value ("dellistener: invalid property name, expected a string value"); graphics_handle gh = gh_manager::lookup (h); @@ -11280,7 +11280,7 @@ if (args.length () >= 3) { - std::string name = args(0).string_value ("addproperty: invalid property NAME, expected a string value"); + std::string name = args(0).xstring_value ("addproperty: invalid property NAME, expected a string value"); double h = args(1).double_value (); @@ -11292,7 +11292,7 @@ { graphics_object go = gh_manager::get_object (gh); - std::string type = args(2).string_value ("addproperty: invalid property TYPE, expected a string value"); + std::string type = args(2).xstring_value ("addproperty: invalid property TYPE, expected a string value"); if (! go.get_properties ().has_property (name)) {
--- a/libinterp/corefcn/gripes.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/gripes.cc Fri Nov 13 14:10:26 2015 -0500 @@ -163,6 +163,29 @@ } void +gripe_wrong_type_arg (const char *s, bool is_error) +{ + if (is_error) + error ("wrong type argument '%s'", s); + else + warning ("wrong type argument '%s'", s); +} + +void +gripe_wrong_type_arg (const std::string& s, bool is_error) +{ + gripe_wrong_type_arg (s.c_str (), is_error); +} + +void +gripe_wrong_type_arg (const octave_value& tc, bool is_error) +{ + std::string type = tc.type_name (); + + gripe_wrong_type_arg (type, is_error); +} + +void gripe_wrong_type_arg_for_unary_op (const octave_value& op) { std::string type = op.type_name ();
--- a/libinterp/corefcn/gripes.h Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/gripes.h Fri Nov 13 14:10:26 2015 -0500 @@ -95,6 +95,15 @@ bool is_error = true); extern OCTINTERP_API void +gripe_wrong_type_arg (const char *s, bool is_error = true); + +extern OCTINTERP_API void +gripe_wrong_type_arg (const std::string& s, bool is_error = true); + +extern OCTINTERP_API void +gripe_wrong_type_arg (const octave_value& tc, bool is_error = true); + +extern OCTINTERP_API void gripe_wrong_type_arg_for_unary_op (const octave_value& op); extern OCTINTERP_API void
--- a/libinterp/corefcn/help.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/help.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1093,7 +1093,7 @@ if (args.length () == 1) { - const std::string name = args(0).string_value ("get_help_text: NAME must be a string"); + const std::string name = args(0).xstring_value ("get_help_text: NAME must be a string"); std::string text; std::string format; @@ -1158,7 +1158,7 @@ if (args.length () == 1) { - const std::string fname = args(0).string_value ("get_help_text_from_file: NAME must be a string"); + const std::string fname = args(0).xstring_value ("get_help_text_from_file: NAME must be a string"); std::string text; std::string format; @@ -1370,7 +1370,7 @@ retval = Cell (ffl.append (afl)); else { - std::string dir = args(0).string_value ("__list_functions__: DIRECTORY argument must be a string"); + std::string dir = args(0).xstring_value ("__list_functions__: DIRECTORY argument must be a string"); string_vector fl = load_path::files (dir, true);
--- a/libinterp/corefcn/input.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/input.cc Fri Nov 13 14:10:26 2015 -0500 @@ -693,7 +693,7 @@ if (nargin == 2) read_as_string++; - std::string prompt = args(0).string_value ("input: unrecognized argument"); + std::string prompt = args(0).xstring_value ("input: unrecognized argument"); flush_octave_stdout (); @@ -836,7 +836,7 @@ std::string prompt; if (nargin == 1) - prompt = args(0).string_value ("yes_or_no: PROMPT must be a string"); + prompt = args(0).xstring_value ("yes_or_no: PROMPT must be a string"); retval = octave_yes_or_no (prompt); }
--- a/libinterp/corefcn/load-path.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/load-path.cc Fri Nov 13 14:10:26 2015 -0500 @@ -2239,18 +2239,18 @@ if (nargin == 1) { - std::string dirname = args(0).string_value ("genpath: DIR must be a string"); + std::string dirname = args(0).xstring_value ("genpath: DIR must be a string"); retval = genpath (dirname); } else if (nargin > 1) { - std::string dirname = args(0).string_value ("genpath: all arguments must be strings"); + std::string dirname = args(0).xstring_value ("genpath: all arguments must be strings"); string_vector skip (nargin - 1); for (octave_idx_type i = 1; i < nargin; i++) - skip[i-1] = args(i).string_value ("genpath: all arguments must be strings"); + skip[i-1] = args(i).xstring_value ("genpath: all arguments must be strings"); retval = genpath (dirname, skip); } @@ -2455,7 +2455,7 @@ for (int i = 0; i < nargin; i++) { - std::string arg = args(i).string_value ("addpath: all arguments must be strings"); + std::string arg = args(i).xstring_value ("addpath: all arguments must be strings"); std::list<std::string> dir_elts = split_path (arg); @@ -2519,7 +2519,7 @@ for (int i = 0; i < nargin; i++) { - std::string arg = args(i).string_value ("rmpath: all arguments must be strings"); + std::string arg = args(i).xstring_value ("rmpath: all arguments must be strings"); std::list<std::string> dir_elts = split_path (arg); for (std::list<std::string>::const_iterator p = dir_elts.begin ();
--- a/libinterp/corefcn/matrix_type.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/matrix_type.cc Fri Nov 13 14:10:26 2015 -0500 @@ -215,7 +215,7 @@ { // Ok, we're changing the matrix type - std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); + std::string str_typ = args(1).xstring_value ("matrix_type: TYPE must be a string"); // FIXME: why do I have to explicitly call the constructor? MatrixType mattyp = MatrixType (); @@ -393,7 +393,7 @@ { // Ok, we're changing the matrix type - std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); + std::string str_typ = args(1).xstring_value ("matrix_type: TYPE must be a string"); // FIXME: why do I have to explicitly call the constructor? MatrixType mattyp = MatrixType (MatrixType::Unknown, true);
--- a/libinterp/corefcn/oct-hist.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/oct-hist.cc Fri Nov 13 14:10:26 2015 -0500 @@ -172,7 +172,7 @@ if (i < nargin - 1) { std::string fname - = args(++i).string_value ("history: expecting file name for %s option", + = args(++i).xstring_value ("history: expecting file name for %s option", option.c_str ()); command_history::set_file (fname);
--- a/libinterp/corefcn/octave-link.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/octave-link.cc Fri Nov 13 14:10:26 2015 -0500 @@ -122,7 +122,7 @@ if (args.length () == 1) { - std::string file = args(0).string_value ("expecting file name as argument"); + std::string file = args(0).xstring_value ("expecting file name as argument"); flush_octave_stdout (); @@ -130,7 +130,7 @@ } else if (args.length () == 2) { - std::string file = args(0).string_value ("expecting file name as first argument"); + std::string file = args(0).xstring_value ("expecting file name as first argument"); flush_octave_stdout (); @@ -150,9 +150,9 @@ if (args.length () == 3) { - std::string dlg = args(0).string_value ("invalid arguments"); - std::string msg = args(1).string_value ("invalid arguments"); - std::string title = args(2).string_value ("invalid arguments"); + std::string dlg = args(0).xstring_value ("invalid arguments"); + std::string msg = args(1).xstring_value ("invalid arguments"); + std::string title = args(2).xstring_value ("invalid arguments"); flush_octave_stdout (); @@ -172,12 +172,12 @@ if (args.length () == 6) { - std::string msg = args(0).string_value ("invalid arguments"); - std::string title = args(1).string_value ("invalid arguments"); - std::string btn1 = args(2).string_value ("invalid arguments"); - std::string btn2 = args(3).string_value ("invalid arguments"); - std::string btn3 = args(4).string_value ("invalid arguments"); - std::string btndef = args(5).string_value ("invalid arguments"); + std::string msg = args(0).xstring_value ("invalid arguments"); + std::string title = args(1).xstring_value ("invalid arguments"); + std::string btn1 = args(2).xstring_value ("invalid arguments"); + std::string btn2 = args(3).xstring_value ("invalid arguments"); + std::string btn3 = args(4).xstring_value ("invalid arguments"); + std::string btndef = args(5).xstring_value ("invalid arguments"); flush_octave_stdout ();
--- a/libinterp/corefcn/qz.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/qz.cc Fri Nov 13 14:10:26 2015 -0500 @@ -405,7 +405,7 @@ ord_job = 'N'; else { - std::string tmp = args(2).string_value ("qz: OPT must be a string"); + std::string tmp = args(2).xstring_value ("qz: OPT must be a string"); if (! tmp.empty ()) ord_job = tmp[0];
--- a/libinterp/corefcn/regexp.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/regexp.cc Fri Nov 13 14:10:26 2015 -0500 @@ -288,7 +288,7 @@ { std::string str; - str = args(i).string_value ("%s: optional arguments must be strings", who.c_str ()); + str = args(i).xstring_value ("%s: optional arguments must be strings", who.c_str ()); std::transform (str.begin (), str.end (), str.begin (), tolower);
--- a/libinterp/corefcn/schur.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/schur.cc Fri Nov 13 14:10:26 2015 -0500 @@ -143,7 +143,7 @@ std::string ord; if (nargin == 2) - ord = args(1).string_value ("schur: second argument must be a string"); + ord = args(1).xstring_value ("schur: second argument must be a string"); bool force_complex = false;
--- a/libinterp/corefcn/spparms.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/spparms.cc Fri Nov 13 14:10:26 2015 -0500 @@ -167,7 +167,7 @@ } else if (nargin == 2) { - std::string str = args(0).string_value ("spparms: first argument must be a string"); + std::string str = args(0).xstring_value ("spparms: first argument must be a string"); double val = args(1).double_value ();
--- a/libinterp/corefcn/strfns.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/strfns.cc Fri Nov 13 14:10:26 2015 -0500 @@ -923,7 +923,7 @@ std::string prefix; if (nargin > 2) - prefix = args(2).string_value ("list_in_columns: PREFIX must be a string"); + prefix = args(2).xstring_value ("list_in_columns: PREFIX must be a string"); std::ostringstream buf;
--- a/libinterp/corefcn/symtab.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/symtab.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1688,7 +1688,7 @@ if (nargin == 1) { - std::string sval = args(0).string_value ("ignore_function_time_stamp: expecting argument to be a string"); + std::string sval = args(0).xstring_value ("ignore_function_time_stamp: expecting argument to be a string"); if (sval == "all") Vignore_function_time_stamp = 2; @@ -1819,7 +1819,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("__get_cmd_line_function_text__: expecting function name"); + std::string name = args(0).xstring_value ("__get_cmd_line_function_text__: expecting function name"); octave_value ov = symbol_table::find_cmdline_function (name); @@ -1852,7 +1852,7 @@ if (args.length () == 2) { - std::string name = args(0).string_value ("set_variable: expecting variable name as first argument"); + std::string name = args(0).xstring_value ("set_variable: expecting variable name as first argument"); symbol_table::assign (name, args(1)); } @@ -1868,7 +1868,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("variable_value: expecting variable name as first argument"); + std::string name = args(0).xstring_value ("variable_value: expecting variable name as first argument"); retval = symbol_table::varval (name);
--- a/libinterp/corefcn/syscalls.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/syscalls.cc Fri Nov 13 14:10:26 2015 -0500 @@ -189,7 +189,7 @@ if (nargin == 1 || nargin == 2) { - std::string exec_file = args(0).string_value ("exec: FILE must be a string"); + std::string exec_file = args(0).xstring_value ("exec: FILE must be a string"); string_vector exec_args; @@ -293,7 +293,7 @@ if (nargin >= 1 && nargin <= 3) { - std::string exec_file = args(0).string_value ("popen2: COMMAND argument must be a string"); + std::string exec_file = args(0).xstring_value ("popen2: COMMAND argument must be a string"); string_vector arg_list; @@ -776,7 +776,7 @@ if (args.length () == 1) { - std::string fname = args(0).string_value ("lstat: NAME must be a string"); + std::string fname = args(0).xstring_value ("lstat: NAME must be a string"); file_stat fs (fname, false); @@ -843,7 +843,7 @@ if (nargin == 2) { - std::string name = args(0).string_value ("mkfifo: FILE must be a string"); + std::string name = args(0).xstring_value ("mkfifo: FILE must be a string"); int octal_mode = args(1).int_value (); @@ -1052,7 +1052,7 @@ } else { - std::string fname = args(0).string_value ("stat: NAME must be a string"); + std::string fname = args(0).xstring_value ("stat: NAME must be a string"); file_stat fs (fname); @@ -1332,7 +1332,7 @@ if (nargin == 1) { - std::string name = args(0).string_value ("unlink: FILE must be a string"); + std::string name = args(0).xstring_value ("unlink: FILE must be a string"); std::string msg; @@ -1648,7 +1648,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("canonicalize_file_name: NAME must be a string"); + std::string name = args(0).xstring_value ("canonicalize_file_name: NAME must be a string"); std::string msg; std::string result = octave_canonicalize_file_name (name, msg);
--- a/libinterp/corefcn/sysdep.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/sysdep.cc Fri Nov 13 14:10:26 2015 -0500 @@ -195,7 +195,7 @@ if (args.length () == 1) { - std::string file = args(0).string_value ("__open_with_system_app__: argument must be a file name"); + std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a file name"); #if defined (__WIN32__) && ! defined (_POSIX_VERSION) HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, @@ -645,10 +645,10 @@ if (nargin == 2 || nargin == 1) { - std::string var = args(0).string_value ("setenv: VAR must be a string"); + std::string var = args(0).xstring_value ("setenv: VAR must be a string"); std::string val = (nargin == 2 - ? args(1).string_value ("setenv: VALUE must be a string") + ? args(1).xstring_value ("setenv: VALUE must be a string") : std::string ()); octave_env::putenv (var, val);
--- a/libinterp/corefcn/time.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/time.cc Fri Nov 13 14:10:26 2015 -0500 @@ -473,7 +473,7 @@ if (args.length () == 2) { - std::string fmt = args(0).string_value ("strftime: FMT must be a string"); + std::string fmt = args(0).xstring_value ("strftime: FMT must be a string"); octave_scalar_map map = args(1).scalar_map_value (); @@ -524,9 +524,9 @@ if (args.length () == 2) { - std::string str = args(0).string_value ("strptime: argument STR must be a string"); + std::string str = args(0).xstring_value ("strptime: argument STR must be a string"); - std::string fmt = args(1).string_value ("strptime: FMT must be a string"); + std::string fmt = args(1).xstring_value ("strptime: FMT must be a string"); octave_strptime t (str, fmt);
--- a/libinterp/corefcn/toplev.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/toplev.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1038,7 +1038,7 @@ if (nargin == 3) { - std::string type_str = args(2).string_value ("system: TYPE must be a string"); + std::string type_str = args(2).xstring_value ("system: TYPE must be a string"); if (type_str == "sync") type = et_sync; @@ -1068,7 +1068,7 @@ return retval; } - std::string cmd_str = args(0).string_value ("system: expecting string as first argument"); + std::string cmd_str = args(0).xstring_value ("system: expecting string as first argument"); #if defined (__WIN32__) && ! defined (__CYGWIN__) // Work around weird double-quote handling on Windows systems. @@ -1223,7 +1223,7 @@ if (nargin == 1 || nargin == 2) { - std::string arg = args(0).string_value ("atexit: FCN argument must be a string"); + std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string"); bool add_mode = true;
--- a/libinterp/corefcn/urlwrite.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/urlwrite.cc Fri Nov 13 14:10:26 2015 -0500 @@ -345,17 +345,17 @@ return retval; } - std::string url = args(0).string_value ("urlwrite: URL must be a string"); + std::string url = args(0).xstring_value ("urlwrite: URL must be a string"); // name to store the file if download is succesful - std::string filename = args(1).string_value ("urlwrite: LOCALFILE must be a string"); + std::string filename = args(1).xstring_value ("urlwrite: LOCALFILE must be a string"); std::string method; Array<std::string> param; if (nargin == 4) { - method = args(2).string_value ("urlwrite: METHOD must be a string"); + method = args(2).xstring_value ("urlwrite: METHOD must be a string"); if (method != "get" && method != "post") { @@ -363,7 +363,7 @@ return retval; } - param = args(3).cellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); + param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); if (param.numel () % 2 == 1) { @@ -482,14 +482,14 @@ return retval; } - std::string url = args(0).string_value ("urlread: URL must be a string"); + std::string url = args(0).xstring_value ("urlread: URL must be a string"); std::string method; Array<std::string> param; if (nargin == 3) { - method = args(1).string_value ("urlread: METHOD must be a string"); + method = args(1).xstring_value ("urlread: METHOD must be a string"); if (method != "get" && method != "post") { @@ -497,7 +497,7 @@ return retval; } - param = args(2).cellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); + param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); if (param.numel () % 2 == 1) { @@ -552,13 +552,13 @@ } else { - host = args(0).string_value ("__ftp__: HOST must be a string"); + host = args(0).xstring_value ("__ftp__: HOST must be a string"); if (nargin > 1) - user = args(1).string_value ("__ftp__: USER must be a string"); + user = args(1).xstring_value ("__ftp__: USER must be a string"); if (nargin > 2) - passwd = args(2).string_value ("__ftp__: PASSWD must be a string"); + passwd = args(2).xstring_value ("__ftp__: PASSWD must be a string"); curl_handle ch = ch_manager::make_curl_handle (host, user, passwd, octave_stdout); @@ -615,7 +615,7 @@ std::string path = ""; if (nargin > 1) - path = args(1).string_value ("__ftp_cwd__: PATH must be a string"); + path = args(1).xstring_value ("__ftp_cwd__: PATH must be a string"); curl.cwd (path); } @@ -822,7 +822,7 @@ if (curl.is_valid ()) { - std::string file = args(1).string_value ("__ftp_delete__: FILE must be a string"); + std::string file = args(1).xstring_value ("__ftp_delete__: FILE must be a string"); curl.del (file); } @@ -851,7 +851,7 @@ if (curl.is_valid ()) { - std::string dir = args(1).string_value ("__ftp_rmdir__: DIR must be a string"); + std::string dir = args(1).xstring_value ("__ftp_rmdir__: DIR must be a string"); curl.rmdir (dir); } @@ -880,7 +880,7 @@ if (curl.is_valid ()) { - std::string dir = args(1).string_value ("__ftp_mkdir__: DIR must be a string"); + std::string dir = args(1).xstring_value ("__ftp_mkdir__: DIR must be a string"); curl.mkdir (dir); } @@ -909,8 +909,8 @@ if (curl.is_valid ()) { - std::string oldname = args(1).string_value ("__ftp_rename__: OLDNAME must be a string"); - std::string newname = args(2).string_value ("__ftp_rename__: NEWNAME must be a string"); + std::string oldname = args(1).xstring_value ("__ftp_rename__: OLDNAME must be a string"); + std::string newname = args(2).xstring_value ("__ftp_rename__: NEWNAME must be a string"); curl.rename (oldname, newname); } @@ -939,7 +939,7 @@ if (curl.is_valid ()) { - std::string pat = args(1).string_value ("__ftp_mput__: PATTERN must be a string"); + std::string pat = args(1).xstring_value ("__ftp_mput__: PATTERN must be a string"); string_vector file_list; @@ -1023,11 +1023,11 @@ if (curl.is_valid ()) { - std::string file = args(1).string_value ("__ftp_mget__: PATTERN must be a string"); + std::string file = args(1).xstring_value ("__ftp_mget__: PATTERN must be a string"); std::string target; if (nargin == 3) - target = args(2).string_value ("__ftp_mget__: TARGET must be a string") + file_ops::dir_sep_str (); + target = args(2).xstring_value ("__ftp_mget__: TARGET must be a string") + file_ops::dir_sep_str (); string_vector sv = curl.list (); octave_idx_type n = 0;
--- a/libinterp/corefcn/utils.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/utils.cc Fri Nov 13 14:10:26 2015 -0500 @@ -393,7 +393,7 @@ if (nargin == 2 || nargin == 3) { - std::string path = args(0).string_value ("file_in_path: PATH must be a string"); + std::string path = args(0).xstring_value ("file_in_path: PATH must be a string"); string_vector names = args(1).all_strings (); @@ -756,7 +756,7 @@ if (nargin == 1) { - std::string str = args(0).string_value ("do_string_escapes: STRING argument must be of type string"); + std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string"); retval = do_string_escapes (str); } @@ -899,7 +899,7 @@ if (nargin == 1) { - std::string str = args(0).string_value ("undo_string_escapes: S argument must be a string"); + std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string"); retval = undo_string_escapes (str); } @@ -995,7 +995,7 @@ if (args.length () == 1) { - std::string nm = args(0).string_value ("make_absolute_filename: FILE argument must be a file name"); + std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a file name"); retval = octave_env::make_absolute (nm); } @@ -1037,7 +1037,7 @@ if (nargin == 1 || nargin == 2) { - dir = args(0).string_value ("dir_in_loadpath: DIR must be a directory name"); + dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name"); if (nargin == 1) retval = load_path::find_dir (dir);
--- a/libinterp/corefcn/variables.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/corefcn/variables.cc Fri Nov 13 14:10:26 2015 -0500 @@ -147,7 +147,7 @@ if (! retval) { - std::string s = arg.string_value ("%s: expecting first argument to be a string", + std::string s = arg.xstring_value ("%s: expecting first argument to be a string", warn_for.c_str ()); std::string cmd = header; @@ -590,11 +590,11 @@ if (nargin == 1 || nargin == 2) { - std::string name = args(0).string_value ("exist: NAME must be a string"); + std::string name = args(0).xstring_value ("exist: NAME must be a string"); if (nargin == 2) { - std::string type = args(1).string_value ("exist: TYPE must be a string"); + std::string type = args(1).xstring_value ("exist: TYPE must be a string"); if (type == "class") warning ("exist: \"class\" type argument is not implemented"); @@ -811,7 +811,7 @@ if (nargin == 1) { - std::string sval = args(0).string_value ("%s: argument must be a single character", nm); + std::string sval = args(0).xstring_value ("%s: argument must be a single character", nm); switch (sval.length ()) { @@ -934,7 +934,7 @@ if (nargin == 1) { - std::string sval = args(0).string_value ("%s: first argument must be a string", nm); + std::string sval = args(0).xstring_value ("%s: first argument must be a string", nm); if (empty_ok || ! sval.empty ()) var = sval; @@ -970,7 +970,7 @@ if (nargin == 1) { - std::string sval = args(0).string_value ("%s: first argument must be a string", nm); + std::string sval = args(0).xstring_value ("%s: first argument must be a string", nm); int i = 0; for (; i < nchoices; i++) @@ -2063,7 +2063,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("munlock: FCN must be a string"); + std::string name = args(0).xstring_value ("munlock: FCN must be a string"); munlock (name); } @@ -2097,7 +2097,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("mislocked: FCN must be a string"); + std::string name = args(0).xstring_value ("mislocked: FCN must be a string"); retval = mislocked (name); } @@ -2674,7 +2674,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("__varval__: expecting argument to be variable name"); + std::string name = args(0).xstring_value ("__varval__: expecting argument to be variable name"); retval = symbol_table::varval (args(0).string_value ()); }
--- a/libinterp/dldfcn/__voronoi__.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/dldfcn/__voronoi__.cc Fri Nov 13 14:10:26 2015 -0500 @@ -87,7 +87,7 @@ { octave_value_list retval; - std::string caller = args(0).string_value ("__voronoi__: CALLER must be a string"); + std::string caller = args(0).xstring_value ("__voronoi__: CALLER must be a string"); #if defined (HAVE_QHULL)
--- a/libinterp/dldfcn/chol.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/dldfcn/chol.cc Fri Nov 13 14:10:26 2015 -0500 @@ -162,7 +162,7 @@ int n = 1; while (n < nargin) { - std::string tmp = args(n++).string_value ("chol: expecting trailing string arguments"); + std::string tmp = args(n++).xstring_value ("chol: expecting trailing string arguments"); if (tmp.compare ("vector") == 0) vecout = true;
--- a/libinterp/dldfcn/colamd.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/dldfcn/colamd.cc Fri Nov 13 14:10:26 2015 -0500 @@ -705,7 +705,7 @@ if (nargin == 2) { - std::string str = args(1).string_value ("etree: TYP must be a string"); + std::string str = args(1).xstring_value ("etree: TYP must be a string"); if (str.find ("C") == 0 || str.find ("c") == 0) is_sym = false; }
--- a/libinterp/dldfcn/fftw.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/dldfcn/fftw.cc Fri Nov 13 14:10:26 2015 -0500 @@ -143,7 +143,7 @@ } #if defined (HAVE_FFTW) - std::string arg0 = args(0).string_value ("fftw: first argument must be a string"); + std::string arg0 = args(0).xstring_value ("fftw: first argument must be a string"); if (arg0 == "planner") { @@ -153,7 +153,7 @@ std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); - std::string arg1 = args(1).string_value ("fftw: planner expects a string value as METHOD"); + std::string arg1 = args(1).xstring_value ("fftw: planner expects a string value as METHOD"); std::transform (arg1.begin (), arg1.end (), arg1.begin (), tolower); @@ -229,7 +229,7 @@ std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); - std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string"); + std::string arg1 = args(1).xstring_value ("fftw: WISDOM must be a string"); char *str = fftw_export_wisdom_to_string (); @@ -263,7 +263,7 @@ std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); - std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string"); + std::string arg1 = args(1).xstring_value ("fftw: WISDOM must be a string"); char *str = fftwf_export_wisdom_to_string ();
--- a/libinterp/octave-value/ov-base.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-base.cc Fri Nov 13 14:10:26 2015 -0500 @@ -56,30 +56,6 @@ #include "toplev.h" #include "variables.h" -static void -gripe_wrong_type_arg_with_msg (const char *name, const std::string& type, - const char *fmt, va_list args) -{ - // Note that this method does not need to be particularly efficient - // since it is already an error to end up here. - - // FIXME: do we want both the wrong-type-argument error and any custom - // error message, or just the custom error message, or should that - // behavior be optional in some way? - - try - { - gripe_wrong_type_arg (name, type); - } - catch (const octave_execution_exception&) - { - if (fmt) - verror (fmt, args); - - throw; - } -} - builtin_type_t btyp_mixed_numeric (builtin_type_t x, builtin_type_t y) { builtin_type_t retval = btyp_unknown; @@ -561,14 +537,6 @@ return retval; } -Cell -octave_base_value::cell_value (const char *fmt, va_list args) const -{ - gripe_wrong_type_arg_with_msg ("cell value", type_name (), fmt, args); - - return Cell (); -} - Matrix octave_base_value::matrix_value (bool) const { @@ -943,11 +911,11 @@ } std::string -octave_base_value::string_value (const char *fmt, va_list args) const +octave_base_value::xstring_value (void) const { - gripe_wrong_type_arg_with_msg ("string value", type_name (), fmt, args); - - return std::string (); + std::string retval; + wrong_type_arg_error (); + return retval; } Array<std::string> @@ -959,14 +927,6 @@ return retval; } -Array<std::string> -octave_base_value::cellstr_value (const char *fmt, va_list args) const -{ - gripe_wrong_type_arg_with_msg ("cellstr value", type_name (), fmt, args); - - return Array<std::string> (); -} - Range octave_base_value::range_value (void) const { @@ -1316,6 +1276,12 @@ t_name.c_str (), type); } +void +octave_base_value::wrong_type_arg_error (void) const +{ + gripe_wrong_type_arg (type_name ()); +} + octave_value octave_base_value::map (unary_mapper_t umap) const {
--- a/libinterp/octave-value/ov-base.h Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-base.h Fri Nov 13 14:10:26 2015 -0500 @@ -481,8 +481,6 @@ virtual Cell cell_value (void) const; - virtual Cell cell_value (const char *fmt, va_list args) const; - virtual Matrix matrix_value (bool = false) const; virtual FloatMatrix float_matrix_value (bool = false) const; @@ -566,13 +564,8 @@ virtual std::string string_value (bool force = false) const; - virtual std::string string_value (const char *fmt, va_list args) const; - virtual Array<std::string> cellstr_value (void) const; - virtual Array<std::string> - cellstr_value (const char *fmt, va_list args) const; - virtual Range range_value (void) const; virtual octave_map map_value (void) const; @@ -617,6 +610,11 @@ virtual void convert_to_row_or_column_vector (void); + // The following extractor functions don't perform any implicit type + // conversions. + + virtual std::string xstring_value () const; + virtual bool print_as_scalar (void) const { return false; } virtual void print (std::ostream& os, bool pr_as_read_syntax = false); @@ -832,6 +830,8 @@ private: + void wrong_type_arg_error (void) const; + static int curr_print_indent_level; static bool beginning_of_line;
--- a/libinterp/octave-value/ov-cell.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-cell.cc Fri Nov 13 14:10:26 2015 -0500 @@ -480,7 +480,10 @@ { octave_value retval; - Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); + if (! is_cellstr ()) + error ("sort: only cell arrays of character strings may be sorted"); + + Array<std::string> tmp = cellstr_value (); tmp = tmp.sort (dim, mode); @@ -496,7 +499,10 @@ { octave_value retval; - Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); + if (! is_cellstr ()) + error ("sort: only cell arrays of character strings may be sorted"); + + Array<std::string> tmp = cellstr_value (); tmp = tmp.sort (sidx, dim, mode); @@ -511,7 +517,10 @@ { sortmode retval = UNSORTED; - Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); + if (! is_cellstr ()) + error ("issorted: A is not a cell array of strings"); + + Array<std::string> tmp = cellstr_value (); retval = tmp.is_sorted (mode); @@ -524,7 +533,10 @@ { Array<octave_idx_type> retval; - Array<std::string> tmp = cellstr_value ("sortrows: only cell arrays of character strings may be sorted"); + if (! is_cellstr ()) + error ("sortrows: only cell arrays of character strings may be sorted"); + + Array<std::string> tmp = cellstr_value (); retval = tmp.sort_rows_idx (mode); @@ -536,7 +548,10 @@ { sortmode retval = UNSORTED; - Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); + if (! is_cellstr ()) + error ("issorted: A is not a cell array of strings"); + + Array<std::string> tmp = cellstr_value (); retval = tmp.is_sorted_rows (mode); @@ -636,49 +651,6 @@ return retval; } -Array<std::string> -octave_cell::cellstr_value (const char *fmt, ...) const -{ - Array<std::string> retval; - va_list args; - retval = cellstr_value (fmt, args); - va_end (args); - return retval; -} - -Array<std::string> -octave_cell::cellstr_value (const char *fmt, va_list args) const -{ - Array<std::string> retval; - - if (! fmt) - return cellstr_value (); - - bool conversion_error = false; - - if (is_cellstr ()) - { - try - { - if (cellstr_cache->is_empty ()) - *cellstr_cache = matrix.cellstr_value (); - - retval = *cellstr_cache; - } - catch (const octave_execution_exception&) - { - conversion_error = true; - } - } - else - conversion_error = true; - - if (conversion_error) - verror (fmt, args); - - return retval; -} - bool octave_cell::print_as_scalar (void) const {
--- a/libinterp/octave-value/ov-cell.h Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-cell.h Fri Nov 13 14:10:26 2015 -0500 @@ -135,8 +135,6 @@ Cell cell_value (void) const { return matrix; } - Cell cell_value (const char *, va_list) const { return matrix; } - octave_value_list list_value (void) const; octave_value convert_to_str_internal (bool pad, bool, char type) const @@ -148,8 +146,6 @@ Array<std::string> cellstr_value (const char *fmt, ...) const; - Array<std::string> cellstr_value (const char *fmt, va_list args) const; - bool print_as_scalar (void) const; void print (std::ostream& os, bool pr_as_read_syntax = false);
--- a/libinterp/octave-value/ov-class.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-class.cc Fri Nov 13 14:10:26 2015 -0500 @@ -289,7 +289,7 @@ octave_map my_map = (obvp != this) ? obvp->map_value () : map; - std::string nm = idx(0).string_value ("invalid index for class"); + std::string nm = idx(0).xstring_value ("invalid index for class"); octave_map::const_iterator p = my_map.seek (nm); @@ -650,7 +650,7 @@ assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value ("invalid index for class assignment"); + std::string key = key_idx(0).xstring_value ("invalid index for class assignment"); octave_value u; @@ -747,7 +747,7 @@ assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value ("assignment to class element failed"); + std::string key = key_idx(0).xstring_value ("assignment to class element failed"); map.assign (idx.front (), key, t_rhs); @@ -1286,7 +1286,7 @@ if (! is) break; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); m.assign (nm, tcell); } @@ -1423,7 +1423,7 @@ if (! is) break; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); m.assign (nm, tcell); } @@ -1657,7 +1657,7 @@ { octave_value t2 = dsub.tc; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); m.assign (dsub.name, tcell); @@ -1823,7 +1823,7 @@ // Called as class constructor octave_function *fcn = octave_call_stack::caller (); - std::string id = args(1).string_value ("class: ID (class name) must be a string"); + std::string id = args(1).xstring_value ("class: ID (class name) must be a string"); if (fcn) { @@ -1917,7 +1917,7 @@ octave_value obj = args(0); // not const because of find_parent_class () std::string obj_cls = obj.class_name (); - Array<std::string> clsnames = args(1).cellstr_value ("isa: CLASSNAME must be a string or cell array of strings"); + Array<std::string> clsnames = args(1).xcellstr_value ("isa: CLASSNAME must be a string or cell array of strings"); boolNDArray matches (clsnames.dims (), false); for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++) @@ -2144,7 +2144,7 @@ for (int i = 0; i < args.length (); i++) { - std::string inf_class = args(i).string_value ("superiorto: expecting argument to be class name"); + std::string inf_class = args(i).xstring_value ("superiorto: expecting argument to be class name"); // User defined classes always have higher precedence // than built-in classes @@ -2185,7 +2185,7 @@ for (int i = 0; i < args.length (); i++) { - std::string sup_class = args(i).string_value ("inferiorto: expecting argument to be class name"); + std::string sup_class = args(i).xstring_value ("inferiorto: expecting argument to be class name"); if (is_built_in_class (sup_class)) {
--- a/libinterp/octave-value/ov-classdef.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-classdef.cc Fri Nov 13 14:10:26 2015 -0500 @@ -522,7 +522,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("fromName: invalid class name, expected a string value"); + std::string name = args(0).xstring_value ("fromName: invalid class name, expected a string value"); retval(0) = to_ov (lookup_class (name)); } @@ -543,7 +543,7 @@ if (! error_state) { - std::string meth_name = args(1).string_value ("fevalStatic: invalid method name, expected a string value"); + std::string meth_name = args(1).xstring_value ("fevalStatic: invalid method name, expected a string value"); cdef_method meth = cls.find_method (meth_name); @@ -580,7 +580,7 @@ if (! error_state) { - std::string prop_name = args(1).string_value ("getConstant: invalid property name, expected a string value"); + std::string prop_name = args(1).xstring_value ("getConstant: invalid property name, expected a string value"); cdef_property prop = cls.find_property (prop_name); @@ -2394,7 +2394,7 @@ if (idx.front ().length () == 1) { - std::string nm = idx.front ()(0).string_value ("invalid meta.class indexing, expected a method or property name"); + std::string nm = idx.front ()(0).xstring_value ("invalid meta.class indexing, expected a method or property name"); cdef_method meth = find_method (nm); @@ -3281,7 +3281,7 @@ if (args.length () == 1) { - std::string name = args(0).string_value ("fromName: invalid package name, expected a string value"); + std::string name = args(0).xstring_value ("fromName: invalid package name, expected a string value"); retval(0) = to_ov (lookup_package (name)); } @@ -3438,7 +3438,7 @@ case '.': if (idx.front ().length () == 1) { - std::string nm = idx.front ()(0).string_value ("invalid meta.package indexing, expected a symbol name"); + std::string nm = idx.front ()(0).xstring_value ("invalid meta.package indexing, expected a symbol name"); #if DEBUG_TRACE std::cerr << "meta.package query: " << nm << std::endl; @@ -3823,7 +3823,7 @@ if (args.length () == 1) { - std::string cname = args(0).string_value ("invalid package name, expected a string value"); + std::string cname = args(0).xstring_value ("invalid package name, expected a string value"); retval = to_ov (lookup_package (cname)); } @@ -3858,7 +3858,7 @@ if (args.length () == 1) { - std::string cls = args(0).string_value ("invalid class name, expected a string value"); + std::string cls = args(0).xstring_value ("invalid class name, expected a string value"); retval = to_ov (lookup_class (cls)); }
--- a/libinterp/octave-value/ov-fcn-handle.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-fcn-handle.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1859,7 +1859,7 @@ if (nargin == 1 || nargin == 2) { - std::string nm = args(0).string_value ("str2func: FCN_NAME must be a string"); + std::string nm = args(0).xstring_value ("str2func: FCN_NAME must be a string"); if (nm[0] == '@') {
--- a/libinterp/octave-value/ov-fcn-inline.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-fcn-inline.cc Fri Nov 13 14:10:26 2015 -0500 @@ -681,7 +681,7 @@ if (nargin > 0) { - std::string fun = args(0).string_value ("inline: STR argument must be a string"); + std::string fun = args(0).xstring_value ("inline: STR argument must be a string"); string_vector fargs; @@ -819,7 +819,7 @@ for (int i = 1; i < nargin; i++) { - std::string s = args(i).string_value ("inline: expecting string arguments"); + std::string s = args(i).xstring_value ("inline: expecting string arguments"); fargs(i-1) = s; } }
--- a/libinterp/octave-value/ov-str-mat.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-str-mat.cc Fri Nov 13 14:10:26 2015 -0500 @@ -252,38 +252,6 @@ return retval; } -std::string -octave_char_matrix_str::string_value (const char *fmt, va_list args) const -{ - std::string retval; - - if (! fmt) - return string_value (); - - bool conversion_error = false; - - if (matrix.ndims () == 2) - { - charMatrix chm (matrix); - - try - { - retval = chm.row_as_string (0); // FIXME? - } - catch (const octave_execution_exception&) - { - conversion_error = true; - } - } - else - conversion_error = true; - - if (conversion_error) - verror (fmt, args); - - return retval; -} - Array<std::string> octave_char_matrix_str::cellstr_value (void) const { @@ -303,41 +271,6 @@ return retval; } -Array<std::string> -octave_char_matrix_str::cellstr_value (const char *fmt, va_list args) const -{ - Array<std::string> retval; - - if (! fmt) - return cellstr_value (); - - bool conversion_error = false; - - if (matrix.ndims () == 2) - { - const charMatrix chm (matrix); - octave_idx_type nr = chm.rows (); - retval.clear (nr, 1); - - try - { - for (octave_idx_type i = 0; i < nr; i++) - retval.xelem (i) = chm.row_as_string (i); - } - catch (const octave_execution_exception&) - { - conversion_error = true; - } - } - else - conversion_error = true; - - if (conversion_error) - verror (fmt, args); - - return retval; -} - void octave_char_matrix_str::print_raw (std::ostream& os, bool pr_as_read_syntax) const
--- a/libinterp/octave-value/ov-str-mat.h Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-str-mat.h Fri Nov 13 14:10:26 2015 -0500 @@ -129,12 +129,10 @@ std::string string_value (bool force = false) const; - std::string string_value (const char *fmt, va_list args) const; + std::string xstring_value (void) const { return string_value (); } Array<std::string> cellstr_value (void) const; - Array<std::string> cellstr_value (const char *fmt, va_list args) const; - octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const { return octave_value (matrix.sort (dim, mode)); }
--- a/libinterp/octave-value/ov-struct.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-struct.cc Fri Nov 13 14:10:26 2015 -0500 @@ -803,7 +803,7 @@ if (!is) break; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2); m.setfield (nm, tcell); } @@ -925,7 +925,7 @@ if (!is) break; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2); m.setfield (nm, tcell); } @@ -1022,7 +1022,7 @@ { octave_value t2 = dsub.tc; - Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2); + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2); m.setfield (dsub.name, tcell); @@ -1814,7 +1814,7 @@ if (nargin == 2) { - Array<std::string> cstr = args(1).cellstr_value ("struct: expecting cell array of field names as second argument"); + Array<std::string> cstr = args(1).xcellstr_value ("struct: expecting cell array of field names as second argument"); retval = octave_map (args(0).dims (), cstr); }
--- a/libinterp/octave-value/ov-usr-fcn.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov-usr-fcn.cc Fri Nov 13 14:10:26 2015 -0500 @@ -635,7 +635,7 @@ octave_value varargout_varval = symbol_table::varval ("varargout"); if (varargout_varval.is_defined ()) - varargout = varargout_varval.cell_value ("expecting varargout to be a cell array object"); + varargout = varargout_varval.xcell_value ("expecting varargout to be a cell array object"); } retval = ret_list->convert_to_const_vector (nargout, varargout);
--- a/libinterp/octave-value/ov.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov.cc Fri Nov 13 14:10:26 2015 -0500 @@ -1550,17 +1550,6 @@ return rep->cell_value (); } -Cell -octave_value::cell_value (const char *fmt, ...) const -{ - Cell retval; - va_list args; - va_start (args,fmt); - retval = rep->cell_value (fmt, args); - va_end (args); - return retval; -} - // Define the idx_type_value function here instead of in ov.h to avoid // needing definitions for the SIZEOF_X macros in ov.h. @@ -1895,6 +1884,42 @@ type_name (), "complex vector")); } +// NAME can't always be "x ## FCN" because some of the original +// value extraction functions perform implicit type conversions that we +// wish to avoid for these functions. + +#define XVALUE_EXTRACTOR(TYPE, NAME, FCN) \ + TYPE \ + octave_value::NAME (const char *fmt, ...) const \ + { \ + TYPE retval; \ + \ + try \ + { \ + retval = FCN (); \ + } \ + catch (const octave_execution_exception&) \ + { \ + if (fmt) \ + { \ + va_list args; \ + va_start (args, fmt); \ + verror (fmt, args); \ + va_end (args); \ + } \ + \ + throw; \ + } \ + \ + return retval; \ + } + +XVALUE_EXTRACTOR (Cell, xcell_value, cell_value) +XVALUE_EXTRACTOR (std::string, xstring_value, rep->xstring_value) +XVALUE_EXTRACTOR (Array<std::string>, xcellstr_value, cellstr_value) + +#undef XVALUE_EXTRACTOR + octave_value octave_value::storable_value (void) const { @@ -2845,7 +2870,7 @@ for (int k = 0; k < nel; k++) { - std::string item = type(k).string_value ("%s: type(%d) must be a string", name, k+1); + std::string item = type(k).xstring_value ("%s: type(%d) must be a string", name, k+1); if (item == "{}") type_string[k] = '{';
--- a/libinterp/octave-value/ov.h Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/octave-value/ov.h Fri Nov 13 14:10:26 2015 -0500 @@ -770,8 +770,6 @@ Cell cell_value (void) const; - Cell cell_value (const char *fmt, ...) const; - Matrix matrix_value (bool frc_str_conv = false) const { return rep->matrix_value (frc_str_conv); } @@ -899,29 +897,9 @@ std::string string_value (bool force = false) const { return rep->string_value (force); } - std::string string_value (const char *fmt, ...) const - { - std::string retval; - va_list args; - va_start (args,fmt); - retval = rep->string_value (fmt, args); - va_end (args); - return retval; - } - Array<std::string> cellstr_value (void) const { return rep->cellstr_value (); } - Array<std::string> cellstr_value (const char *fmt, ...) const - { - Array<std::string> retval; - va_list args; - va_start (args,fmt); - retval = rep->cellstr_value (fmt, args); - va_end (args); - return retval; - } - Range range_value (void) const { return rep->range_value (); } @@ -1016,6 +994,21 @@ float_complex_vector_value (bool frc_str_conv = false, bool frc_vec_conv = false) const; + // Extract values of specific types without any implicit type + // conversions. Throw an error if an object is the wrong type for + // the requested value extraction. + // + // These functions are intended to provide a simple way to extract + // values of specific types and display error messages that are more + // meaningful than the generic "error: wrong type argument 'cell'" + // message. + + Cell xcell_value (const char *fmt, ...) const; + + std::string xstring_value (const char *fmt, ...) const; + + Array<std::string> xcellstr_value (const char *fmt, ...) const; + // Possibly economize a lazy-indexed value. void maybe_economize (void)
--- a/libinterp/parse-tree/oct-parse.in.yy Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/parse-tree/oct-parse.in.yy Fri Nov 13 14:10:26 2015 -0500 @@ -4548,7 +4548,7 @@ std::string arg; if (nargin == 1) - arg = args(0).string_value ("mfilename: expecting argument to be a character string"); + arg = args(0).xstring_value ("mfilename: expecting argument to be a character string"); std::string fname; @@ -4599,12 +4599,12 @@ if (nargin == 1 || nargin == 2) { - std::string file_name = args(0).string_value ("source: expecting file name as argument"); + std::string file_name = args(0).xstring_value ("source: expecting file name as argument"); std::string context; if (nargin == 2) - context = args(1).string_value ("source: expecting context to be character string"); + context = args(1).xstring_value ("source: expecting context to be character string"); source_file (file_name, context); } @@ -4785,7 +4785,7 @@ if (nargin > 0) { - const std::string name (args(0).string_value ("builtin: function name (F) must be a string")); + const std::string name (args(0).xstring_value ("builtin: function name (F) must be a string")); octave_value fcn = symbol_table::builtin_find (name); @@ -4885,7 +4885,7 @@ eval_string (const octave_value& arg, bool silent, int& parse_status, int nargout) { - std::string s = arg.string_value ("eval: expecting std::string argument"); + std::string s = arg.xstring_value ("eval: expecting std::string argument"); return eval_string (s, silent, parse_status, nargout); } @@ -5051,7 +5051,7 @@ if (nargin == 3) { - std::string context = args(0).string_value ("assignin: CONTEXT must be a string"); + std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string"); unwind_protect frame; @@ -5064,7 +5064,7 @@ frame.add_fcn (octave_call_stack::pop); - std::string nm = args(1).string_value ("assignin: VARNAME must be a string"); + std::string nm = args(1).xstring_value ("assignin: VARNAME must be a string"); if (valid_identifier (nm)) symbol_table::assign (nm, args(2)); @@ -5092,7 +5092,7 @@ if (nargin > 1) { - std::string context = args(0).string_value ("evalin: CONTEXT must be a string"); + std::string context = args(0).xstring_value ("evalin: CONTEXT must be a string"); unwind_protect frame; @@ -5192,7 +5192,7 @@ if (nargin == 1 || nargin == 2) { - std::string file = args(0).string_value ("__parse_file__: expecting file name as argument"); + std::string file = args(0).xstring_value ("__parse_file__: expecting file name as argument"); std::string full_file = octave_env::make_absolute (file);
--- a/libinterp/parse-tree/pt-idx.cc Thu Nov 12 19:27:25 2015 -0800 +++ b/libinterp/parse-tree/pt-idx.cc Fri Nov 13 14:10:26 2015 -0500 @@ -209,7 +209,7 @@ { octave_value t = df->rvalue1 (); - fn = t.string_value ("dynamic structure field names must be strings"); + fn = t.xstring_value ("dynamic structure field names must be strings"); } else panic_impossible ();