# HG changeset patch # User John W. Eaton # Date 1444342556 14400 # Node ID 10ec79b47808cc8eaa5454f157f690440cc60a4c # Parent 647db46ad754c61bfd363b4ea453e226378784cd use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method. diff --git a/libinterp/dldfcn/__voronoi__.cc b/libinterp/dldfcn/__voronoi__.cc --- a/libinterp/dldfcn/__voronoi__.cc +++ b/libinterp/dldfcn/__voronoi__.cc @@ -87,7 +87,7 @@ { octave_value_list retval; - std::string caller = args(0).string_value (); + std::string caller = args(0).string_value ("__voronoi__: CALLER must be a string"); #if defined (HAVE_QHULL) diff --git a/libinterp/dldfcn/chol.cc b/libinterp/dldfcn/chol.cc --- a/libinterp/dldfcn/chol.cc +++ b/libinterp/dldfcn/chol.cc @@ -162,21 +162,16 @@ int n = 1; while (n < nargin) { - std::string tmp = args(n++).string_value (); + std::string tmp = args(n++).string_value ("chol: expecting trailing string arguments"); - if (! error_state) - { - if (tmp.compare ("vector") == 0) - vecout = true; - else if (tmp.compare ("lower") == 0) - LLt = true; - else if (tmp.compare ("upper") == 0) - LLt = false; - else - error ("chol: unexpected second or third input"); - } + if (tmp.compare ("vector") == 0) + vecout = true; + else if (tmp.compare ("lower") == 0) + LLt = true; + else if (tmp.compare ("upper") == 0) + LLt = false; else - error ("chol: expecting trailing string arguments"); + error ("chol: unexpected second or third input"); } octave_value arg = args(0); @@ -350,7 +345,8 @@ %!error chol () %!error chol ([1, 2; 3, 4]) %!error chol ([1, 2; 3, 4; 5, 6]) -%!error chol (1, 2) +%!error chol (1, 2) +%!error chol (1, "foobar") */ DEFUN_DLD (cholinv, args, , diff --git a/libinterp/dldfcn/colamd.cc b/libinterp/dldfcn/colamd.cc --- a/libinterp/dldfcn/colamd.cc +++ b/libinterp/dldfcn/colamd.cc @@ -705,17 +705,9 @@ if (nargin == 2) { - if (args(1).is_string ()) - { - std::string str = args(1).string_value (); - if (str.find ("C") == 0 || str.find ("c") == 0) - is_sym = false; - } - else - { - error ("etree: TYP must be a string"); - return retval; - } + std::string str = args(1).string_value ("etree: TYP must be a string"); + if (str.find ("C") == 0 || str.find ("c") == 0) + is_sym = false; } // column elimination tree post-ordering (reuse variables) diff --git a/libinterp/dldfcn/fftw.cc b/libinterp/dldfcn/fftw.cc --- a/libinterp/dldfcn/fftw.cc +++ b/libinterp/dldfcn/fftw.cc @@ -143,196 +143,183 @@ } #if defined (HAVE_FFTW) - if (args(0).is_string ()) + std::string arg0 = args(0).string_value ("fftw: first argument must be a string"); + + if (arg0 == "planner") { - std::string arg0 = args(0).string_value (); + if (nargin == 2) //planner setter + { + // Use STL function to convert to lower case + std::transform (arg0.begin (), arg0.end (), arg0.begin (), + tolower); + + std::string arg1 = args(1).string_value ("fftw: planner expects a string value as METHOD"); - if (arg0 == "planner") - { - if (nargin == 2) //planner setter + std::transform (arg1.begin (), arg1.end (), + arg1.begin (), tolower); + octave_fftw_planner::FftwMethod meth + = octave_fftw_planner::UNKNOWN; + octave_float_fftw_planner::FftwMethod methf + = octave_float_fftw_planner::UNKNOWN; + + if (arg1 == "estimate") + { + meth = octave_fftw_planner::ESTIMATE; + methf = octave_float_fftw_planner::ESTIMATE; + } + else if (arg1 == "measure") + { + meth = octave_fftw_planner::MEASURE; + methf = octave_float_fftw_planner::MEASURE; + } + else if (arg1 == "patient") { - if (args(1).is_string ()) - { - // Use STL function to convert to lower case - std::transform (arg0.begin (), arg0.end (), arg0.begin (), - tolower); - std::string arg1 = args(1).string_value (); + meth = octave_fftw_planner::PATIENT; + methf = octave_float_fftw_planner::PATIENT; + } + else if (arg1 == "exhaustive") + { + meth = octave_fftw_planner::EXHAUSTIVE; + methf = octave_float_fftw_planner::EXHAUSTIVE; + } + else if (arg1 == "hybrid") + { + meth = octave_fftw_planner::HYBRID; + methf = octave_float_fftw_planner::HYBRID; + } + else + error ("fftw: unrecognized planner METHOD"); - std::transform (arg1.begin (), arg1.end (), - arg1.begin (), tolower); - octave_fftw_planner::FftwMethod meth - = octave_fftw_planner::UNKNOWN; - octave_float_fftw_planner::FftwMethod methf - = octave_float_fftw_planner::UNKNOWN; + meth = octave_fftw_planner::method (meth); + octave_float_fftw_planner::method (methf); + + if (meth == octave_fftw_planner::MEASURE) + retval = octave_value ("measure"); + else if (meth == octave_fftw_planner::PATIENT) + retval = octave_value ("patient"); + else if (meth == octave_fftw_planner::EXHAUSTIVE) + retval = octave_value ("exhaustive"); + else if (meth == octave_fftw_planner::HYBRID) + retval = octave_value ("hybrid"); + else + retval = octave_value ("estimate"); + } + else //planner getter + { + octave_fftw_planner::FftwMethod meth = + octave_fftw_planner::method (); - if (arg1 == "estimate") - { - meth = octave_fftw_planner::ESTIMATE; - methf = octave_float_fftw_planner::ESTIMATE; - } - else if (arg1 == "measure") - { - meth = octave_fftw_planner::MEASURE; - methf = octave_float_fftw_planner::MEASURE; - } - else if (arg1 == "patient") - { - meth = octave_fftw_planner::PATIENT; - methf = octave_float_fftw_planner::PATIENT; - } - else if (arg1 == "exhaustive") - { - meth = octave_fftw_planner::EXHAUSTIVE; - methf = octave_float_fftw_planner::EXHAUSTIVE; - } - else if (arg1 == "hybrid") - { - meth = octave_fftw_planner::HYBRID; - methf = octave_float_fftw_planner::HYBRID; - } - else - error ("fftw: unrecognized planner METHOD"); + if (meth == octave_fftw_planner::MEASURE) + retval = octave_value ("measure"); + else if (meth == octave_fftw_planner::PATIENT) + retval = octave_value ("patient"); + else if (meth == octave_fftw_planner::EXHAUSTIVE) + retval = octave_value ("exhaustive"); + else if (meth == octave_fftw_planner::HYBRID) + retval = octave_value ("hybrid"); + else + retval = octave_value ("estimate"); + } + } + else if (arg0 == "dwisdom") + { + if (nargin == 2) //dwisdom setter + { + // Use STL function to convert to lower case + std::transform (arg0.begin (), arg0.end (), arg0.begin (), + tolower); + + std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string"); + + char *str = fftw_export_wisdom_to_string (); + + if (arg1.length () < 1) + fftw_forget_wisdom (); + else if (! fftw_import_wisdom_from_string (arg1.c_str ())) + error ("fftw: could not import supplied WISDOM"); + + retval = octave_value (std::string (str)); + + // FIXME: need to free string even if there is an + // exception. + free (str); + } + else //dwisdom getter + { + char *str = fftw_export_wisdom_to_string (); + retval = octave_value (std::string (str)); - meth = octave_fftw_planner::method (meth); - octave_float_fftw_planner::method (methf); + // FIXME: need to free string even if there is an + // exception. + free (str); + } + } + else if (arg0 == "swisdom") + { + //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real) + if (nargin == 2) //swisdom setter + { + // Use STL function to convert to lower case + std::transform (arg0.begin (), arg0.end (), arg0.begin (), + tolower); + + std::string arg1 = args(1).string_value ("fftw: WISDOM must be a string"); + + char *str = fftwf_export_wisdom_to_string (); + + if (arg1.length () < 1) + fftwf_forget_wisdom (); + else if (! fftwf_import_wisdom_from_string (arg1.c_str ())) + error ("fftw: could not import supplied WISDOM"); + + retval = octave_value (std::string (str)); - if (meth == octave_fftw_planner::MEASURE) - retval = octave_value ("measure"); - else if (meth == octave_fftw_planner::PATIENT) - retval = octave_value ("patient"); - else if (meth == octave_fftw_planner::EXHAUSTIVE) - retval = octave_value ("exhaustive"); - else if (meth == octave_fftw_planner::HYBRID) - retval = octave_value ("hybrid"); - else - retval = octave_value ("estimate"); + // FIXME: need to free string even if there is an + // exception. + free (str); + } + else //swisdom getter + { + char *str = fftwf_export_wisdom_to_string (); + retval = octave_value (std::string (str)); + + // FIXME: need to free string even if there is an + // exception. + free (str); + } + } + else if (arg0 == "threads") + { + if (nargin == 2) //threads setter + { + if (args(1).is_real_scalar ()) + { + int nthreads = args(1).int_value(); + if (nthreads >= 1) + { +#if defined (HAVE_FFTW3_THREADS) + octave_fftw_planner::threads (nthreads); +#else + gripe_disabled_feature ("fftw", "multithreaded FFTW"); +#endif +#if defined (HAVE_FFTW3F_THREADS) + octave_float_fftw_planner::threads (nthreads); +#else + gripe_disabled_feature ("fftw", "multithreaded FFTW"); +#endif } else - error ("fftw: planner expects a string value as METHOD"); - } - else //planner getter - { - octave_fftw_planner::FftwMethod meth = - octave_fftw_planner::method (); - - if (meth == octave_fftw_planner::MEASURE) - retval = octave_value ("measure"); - else if (meth == octave_fftw_planner::PATIENT) - retval = octave_value ("patient"); - else if (meth == octave_fftw_planner::EXHAUSTIVE) - retval = octave_value ("exhaustive"); - else if (meth == octave_fftw_planner::HYBRID) - retval = octave_value ("hybrid"); - else - retval = octave_value ("estimate"); + error ("fftw: number of threads must be >=1"); } - } - else if (arg0 == "dwisdom") - { - if (nargin == 2) //dwisdom setter - { - if (args(1).is_string ()) - { - // Use STL function to convert to lower case - std::transform (arg0.begin (), arg0.end (), arg0.begin (), - tolower); - std::string arg1 = args(1).string_value (); - - char *str = fftw_export_wisdom_to_string (); - - if (arg1.length () < 1) - fftw_forget_wisdom (); - else if (! fftw_import_wisdom_from_string (arg1.c_str ())) - error ("fftw: could not import supplied WISDOM"); - - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an - // exception. - free (str); - } - } - else //dwisdom getter - { - char *str = fftw_export_wisdom_to_string (); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an - // exception. - free (str); - } + else + error ("fftw: setting threads needs one integer argument"); } - else if (arg0 == "swisdom") - { - //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real) - if (nargin == 2) //swisdom setter - { - if (args(1).is_string ()) - { - // Use STL function to convert to lower case - std::transform (arg0.begin (), arg0.end (), arg0.begin (), - tolower); - std::string arg1 = args(1).string_value (); - - char *str = fftwf_export_wisdom_to_string (); - - if (arg1.length () < 1) - fftwf_forget_wisdom (); - else if (! fftwf_import_wisdom_from_string (arg1.c_str ())) - error ("fftw: could not import supplied WISDOM"); - - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an - // exception. - free (str); - } - } - else //swisdom getter - { - char *str = fftwf_export_wisdom_to_string (); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an - // exception. - free (str); - } - } - else if (arg0 == "threads") - { - if (nargin == 2) //threads setter - { - if (args(1).is_real_scalar ()) - { - int nthreads = args(1).int_value(); - if (nthreads >= 1) - { + else //threads getter #if defined (HAVE_FFTW3_THREADS) - octave_fftw_planner::threads (nthreads); + retval = octave_value (octave_fftw_planner::threads()); #else - gripe_disabled_feature ("fftw", "multithreaded FFTW"); -#endif -#if defined (HAVE_FFTW3F_THREADS) - octave_float_fftw_planner::threads (nthreads); -#else - gripe_disabled_feature ("fftw", "multithreaded FFTW"); + retval = 1; #endif - } - else - error ("fftw: number of threads must be >=1"); - } - else - error ("fftw: setting threads needs one integer argument"); - } - else //threads getter -#if defined (HAVE_FFTW3_THREADS) - retval = octave_value (octave_fftw_planner::threads()); -#else - retval = 1; -#endif - } - else - error ("fftw: unrecognized argument"); } else error ("fftw: unrecognized argument");