Mercurial > octave
changeset 30001:428cccc75cc9
move most functions in variables.cc to octave namespace
* variables.h, variables.cc: Move most functions to octave namespace.
Provide deprecated inline wrapper functions to preserve old names.
Change all uses as needed.
(SET_INTERNAL_VARIABLE, SET_NONEMPTY_INTERNAL_STRING_VARIABLE,
SET_INTERNAL_VARIABLE_WITH_LIMITS, SET_INTERNAL_VARIABLE_CHOICES):
Note that these macros are obsolete.
* dirfns.cc, ls-oct-text.cc, pr-flt-fmt.cc, pr-output.cc, svd.cc,
ov-base.cc, ov-java.cc, ov-struct.cc, ov-usr-fcn.cc, ov.cc:
Eliminate use of SET_INTERNAL_VARIABLE macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 18 Aug 2021 11:40:25 -0400 |
parents | 362029cc0202 |
children | 1cf04058fea6 |
files | libinterp/corefcn/dirfns.cc libinterp/corefcn/ls-oct-text.cc libinterp/corefcn/pr-flt-fmt.cc libinterp/corefcn/pr-output.cc libinterp/corefcn/svd.cc libinterp/corefcn/variables.cc libinterp/corefcn/variables.h libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-struct.cc libinterp/octave-value/ov-usr-fcn.cc libinterp/octave-value/ov.cc |
diffstat | 12 files changed, 174 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/dirfns.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/dirfns.cc Wed Aug 18 11:40:25 2021 -0400 @@ -723,7 +723,8 @@ @seealso{rmdir} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); + return set_internal_variable (Vconfirm_recursive_rmdir, args, nargout, + "confirm_recursive_rmdir"); } OCTAVE_NAMESPACE_END
--- a/libinterp/corefcn/ls-oct-text.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/ls-oct-text.cc Wed Aug 18 11:40:25 2021 -0400 @@ -480,8 +480,9 @@ @seealso{save_default_options} @end deftypefn */) { - return SET_INTERNAL_VARIABLE_WITH_LIMITS (save_precision, -1, - std::numeric_limits<int>::max ()); + return set_internal_variable (Vsave_precision, args, nargout, + "save_precision", -1, + std::numeric_limits<int>::max ()); } OCTAVE_NAMESPACE_END
--- a/libinterp/corefcn/pr-flt-fmt.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/pr-flt-fmt.cc Wed Aug 18 11:40:25 2021 -0400 @@ -69,7 +69,8 @@ @seealso{format, fixed_point_format} @end deftypefn */) { - return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, 16); + return set_internal_variable (Voutput_precision, args, nargout, + "output_precision", 0, 16); } OCTAVE_NAMESPACE_END
--- a/libinterp/corefcn/pr-output.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/pr-output.cc Wed Aug 18 11:40:25 2021 -0400 @@ -4093,7 +4093,8 @@ @seealso{format, output_precision} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (fixed_point_format); + return set_internal_variable (Vfixed_point_format, args, nargout, + "fixed_point_format"); } DEFUN (print_empty_dimensions, args, nargout, @@ -4123,7 +4124,8 @@ @seealso{format} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (print_empty_dimensions); + return set_internal_variable (Vprint_empty_dimensions, args, nargout, + "print_empty_dimensions"); } DEFUN (split_long_rows, args, nargout, @@ -4162,7 +4164,8 @@ @seealso{format} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (split_long_rows); + return set_internal_variable (Vsplit_long_rows, args, nargout, + "split_long_rows"); } OCTAVE_NAMESPACE_END
--- a/libinterp/corefcn/svd.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/svd.cc Wed Aug 18 11:40:25 2021 -0400 @@ -438,7 +438,8 @@ { static const char *driver_names[] = { "gesvd", "gesdd", "gejsv", nullptr }; - return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names); + return set_internal_variable (Vsvd_driver, args, nargout, + "svd_driver", driver_names); } /*
--- a/libinterp/corefcn/variables.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/variables.cc Wed Aug 18 11:40:25 2021 -0400 @@ -120,46 +120,6 @@ return ans; } -octave_function * -extract_function (const octave_value& arg, const std::string& warn_for, - const std::string& fname, const std::string& header, - const std::string& trailer) -{ - octave_function *retval = is_valid_function (arg, warn_for, 0); - - if (! retval) - { - std::string s = arg.xstring_value ("%s: argument must be a string", - warn_for.c_str ()); - - std::string cmd = header; - cmd.append (s); - cmd.append (trailer); - - int parse_status; - - octave::interpreter& interp - = octave::__get_interpreter__ ("extract_function"); - - interp.eval_string (cmd, true, parse_status, 0); - - if (parse_status != 0) - error ("%s: '%s' is not valid as a function", - warn_for.c_str (), fname.c_str ()); - - retval = is_valid_function (fname, warn_for, 0); - - if (! retval) - error ("%s: '%s' is not valid as a function", - warn_for.c_str (), fname.c_str ()); - - warning ("%s: passing function body as a string is obsolete; please use anonymous functions", - warn_for.c_str ()); - } - - return retval; -} - OCTAVE_NAMESPACE_BEGIN DEFMETHOD (isglobal, interp, args, , @@ -356,8 +316,6 @@ return 0; } -OCTAVE_NAMESPACE_END - int symbol_exist (const std::string& name, const std::string& type) { @@ -394,8 +352,6 @@ return nm; } -OCTAVE_NAMESPACE_BEGIN - DEFMETHOD (exist, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {@var{c} =} exist (@var{name}) @@ -581,8 +537,6 @@ */ -OCTAVE_NAMESPACE_END - // Variable values. static bool @@ -892,8 +846,6 @@ return retval; } -OCTAVE_NAMESPACE_BEGIN - // NOTE: Calling Fmlock directly (without an associated stack frame) // will probably not do what you expect because it will lock the calling // function. You should use interpreter::mlock directly if you want to @@ -1434,12 +1386,8 @@ %!error clear -f -g */ -OCTAVE_NAMESPACE_END - static std::string Vmissing_function_hook = "__unimplemented__"; -OCTAVE_NAMESPACE_BEGIN - DEFUN (missing_function_hook, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {@var{val} =} missing_function_hook () @@ -1454,11 +1402,10 @@ @seealso{missing_component_hook} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (missing_function_hook); + return set_internal_variable (Vmissing_function_hook, args, nargout, + "missing_function_hook"); } -OCTAVE_NAMESPACE_END - std::string maybe_missing_function_hook (const std::string& name) { @@ -1493,8 +1440,6 @@ return ""; } -OCTAVE_NAMESPACE_BEGIN - DEFMETHOD (__varval__, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {@var{value} =} __varval__ (@var{name}) @@ -1572,7 +1517,50 @@ @seealso{missing_function_hook} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (missing_component_hook); + return set_internal_variable (Vmissing_component_hook, args, nargout, + "missing_component_hook"); } OCTAVE_NAMESPACE_END + +// DEPRECATED in Octave 6 + +octave_function * +extract_function (const octave_value& arg, const std::string& warn_for, + const std::string& fname, const std::string& header, + const std::string& trailer) +{ + octave_function *retval = is_valid_function (arg, warn_for, 0); + + if (! retval) + { + std::string s = arg.xstring_value ("%s: argument must be a string", + warn_for.c_str ()); + + std::string cmd = header; + cmd.append (s); + cmd.append (trailer); + + int parse_status; + + octave::interpreter& interp + = octave::__get_interpreter__ ("extract_function"); + + interp.eval_string (cmd, true, parse_status, 0); + + if (parse_status != 0) + error ("%s: '%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + + retval = is_valid_function (fname, warn_for, 0); + + if (! retval) + error ("%s: '%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + + warning ("%s: passing function body as a string is obsolete; please use anonymous functions", + warn_for.c_str ()); + } + + return retval; +}
--- a/libinterp/corefcn/variables.h Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/corefcn/variables.h Wed Aug 18 11:40:25 2021 -0400 @@ -48,6 +48,11 @@ #include "ov-builtin.h" +// The following two functions should be removed or the return type +// should be changed when we remove octave_function from the interpreter +// interface. See the discussion about this topic here: +// https://octave.discourse.group/t/refactoring-octave-value-function-objects-backward-incompatible-change/971 + extern OCTINTERP_API octave_function * is_valid_function (const octave_value&, const std::string& = "", bool warn = false); @@ -56,13 +61,7 @@ is_valid_function (const std::string&, const std::string& = "", bool warn = false); -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (6, "use 'octave::get_function_handle' instead") -extern OCTINTERP_API octave_function * -extract_function (const octave_value& arg, const std::string& warn_for, - const std::string& fname, const std::string& header, - const std::string& trailer); -#endif +OCTAVE_NAMESPACE_BEGIN extern OCTINTERP_API int symbol_exist (const std::string& name, const std::string& type = "any"); @@ -102,6 +101,93 @@ set_internal_variable (int& var, const octave_value_list& args, int nargout, const char *nm, const char **choices); +extern OCTINTERP_API std::string +maybe_missing_function_hook (const std::string& name); + +OCTAVE_NAMESPACE_END + +#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) + +OCTAVE_DEPRECATED (7, "use 'octave::symbol_exist' instead") +inline int +symbol_exist (const std::string& name, const std::string& type = "any") +{ + return octave::symbol_exist (name, type); +} + +OCTAVE_DEPRECATED (7, "use 'octave::unique_symbol_name' instead") +inline std::string +unique_symbol_name (const std::string& basename) +{ + return octave::unique_symbol_name (basename); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (bool& var, const octave_value_list& args, int nargout, const char *nm) +{ + return octave::set_internal_variable (var, args, nargout, nm); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (char& var, const octave_value_list& args, int nargout, const char *nm) +{ + return octave::set_internal_variable (var, args, nargout, nm); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (int& var, const octave_value_list& args, int nargout, const char *nm, int minval = std::numeric_limits<int>::min (), int maxval = std::numeric_limits<int>::max ()) +{ + return octave::set_internal_variable (var, args, nargout, nm, minval, maxval); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (double& var, const octave_value_list& args, int nargout, const char *nm, double minval = -octave::numeric_limits<double>::Inf (), double maxval = octave::numeric_limits<double>::Inf ()) +{ + return octave::set_internal_variable (var, args, nargout, nm, minval, maxval); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (std::string& var, const octave_value_list& args, int nargout, const char *nm, bool empty_ok = true) +{ + return octave::set_internal_variable (var, args, nargout, nm, empty_ok); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (std::string& var, const octave_value_list& args, int nargout, const char *nm, const char **choices) +{ + return octave::set_internal_variable (var, args, nargout, nm, choices); +} + +OCTAVE_DEPRECATED (7, "use 'octave::set_internal_variable' instead") +inline octave_value +set_internal_variable (int& var, const octave_value_list& args, int nargout, const char *nm, const char **choices) +{ + return octave::set_internal_variable (var, args, nargout, nm, choices); +} + +OCTAVE_DEPRECATED (7, "use 'octave::maybe_missing_function_hook' instead") +inline std::string +maybe_missing_function_hook (const std::string& name) +{ + return octave::maybe_missing_function_hook (name); +} + +OCTAVE_DEPRECATED (6, "use 'octave::get_function_handle' instead") +extern OCTINTERP_API octave_function * +extract_function (const octave_value& arg, const std::string& warn_for, + const std::string& fname, const std::string& header, + const std::string& trailer); + +#endif + +// The following macros should also be considered obsolete. + #define SET_INTERNAL_VARIABLE(NM) \ set_internal_variable (V ## NM, args, nargout, #NM) @@ -115,7 +201,4 @@ #define SET_INTERNAL_VARIABLE_CHOICES(NM, CHOICES) \ set_internal_variable (V ## NM, args, nargout, #NM, CHOICES) -extern OCTINTERP_API std::string -maybe_missing_function_hook (const std::string& name); - #endif
--- a/libinterp/octave-value/ov-base.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/octave-value/ov-base.cc Wed Aug 18 11:40:25 2021 -0400 @@ -1576,7 +1576,8 @@ The original variable value is restored when exiting the function. @end deftypefn */) { - return SET_INTERNAL_VARIABLE (sparse_auto_mutate); + return set_internal_variable (Vsparse_auto_mutate, args, nargout, + "sparse_auto_mutate"); } /*
--- a/libinterp/octave-value/ov-java.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/octave-value/ov-java.cc Wed Aug 18 11:40:25 2021 -0400 @@ -3385,7 +3385,8 @@ { #if defined (HAVE_JAVA) - return SET_INTERNAL_VARIABLE (java_matrix_autoconversion); + return set_internal_variable (Vjava_matrix_autoconversion, args, nargout, + "java_matrix_autoconversion"); #else @@ -3416,7 +3417,8 @@ { #if defined (HAVE_JAVA) - return SET_INTERNAL_VARIABLE (java_unsigned_autoconversion); + return set_internal_variable (Vjava_unsigned_autoconversion, args, nargout, + "java_unsigned_autoconversion"); #else @@ -3445,7 +3447,7 @@ { #if defined (HAVE_JAVA) - return SET_INTERNAL_VARIABLE (debug_java); + return set_internal_variable (Vdebug_java, args, nargout, "debug_java"); #else
--- a/libinterp/octave-value/ov-struct.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/octave-value/ov-struct.cc Wed Aug 18 11:40:25 2021 -0400 @@ -2222,8 +2222,9 @@ @seealso{print_struct_array_contents} @end deftypefn */) { - return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, -1, - std::numeric_limits<int>::max ()); + return set_internal_variable (Vstruct_levels_to_print, args, nargout, + "struct_levels_to_print", -1, + std::numeric_limits<int>::max ()); } DEFUN (print_struct_array_contents, args, nargout, @@ -2245,7 +2246,8 @@ @seealso{struct_levels_to_print} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (print_struct_array_contents); + return set_internal_variable (Vprint_struct_array_contents, args, nargout, + "print_struct_array_contents"); } OCTAVE_NAMESPACE_END
--- a/libinterp/octave-value/ov-usr-fcn.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Wed Aug 18 11:40:25 2021 -0400 @@ -883,7 +883,8 @@ @seealso{subsasgn} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); + return set_internal_variable (Voptimize_subsasgn_calls, args, nargout, + "optimize_subsasgn_calls"); } static bool val_in_table (const Matrix& table, double val)
--- a/libinterp/octave-value/ov.cc Wed Aug 18 09:23:45 2021 -0400 +++ b/libinterp/octave-value/ov.cc Wed Aug 18 11:40:25 2021 -0400 @@ -3656,7 +3656,8 @@ @seealso{optimize_range, optimize_diagonal_matrix} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (optimize_permutation_matrix); + return set_internal_variable (Voptimize_permutation_matrix, args, nargout, + "optimize_permutation_matrix"); } /* @@ -3686,7 +3687,8 @@ @seealso{optimize_range, optimize_permutation_matrix} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (optimize_diagonal_matrix); + return set_internal_variable (Voptimize_diagonal_matrix, args, nargout, + "optimize_diagonal_matrix"); } /* @@ -3730,7 +3732,8 @@ @seealso{optimize_diagonal_matrix, optimize_permutation_matrix} @end deftypefn */) { - return SET_INTERNAL_VARIABLE (optimize_range); + return set_internal_variable (Voptimize_range, args, nargout, + "optimize_range"); } /*