octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behavior of feval when it fails?


From: John W. Eaton
Subject: Re: Behavior of feval when it fails?
Date: Wed, 2 Nov 2016 20:10:23 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

On 11/02/2016 05:40 PM, Rik wrote:
All,

I was looking into a bug report and found that the feval function fails
silently.  See test code below.

+verbatim+
octave:1> feval ('sin', 1)
ans =  0.84147
octave:2> feval ('sinABC', 1)
octave:3>
-verbatim-

It seems like feval should most likely throw an error if the function
doesn't exist.  But maybe we get in to weird loops where feval is called
repeatedly.  The code for feval is in oct-parse.cc.

+verbatim+
octave_value_list
feval (const std::string& name, const octave_value_list& args, int nargout)
{
  octave_value_list retval;

  octave_value fcn = symbol_table::find_function (name, args);

  if (fcn.is_defined ())
    retval = fcn.do_multi_index_op (nargout, args);
  else
    {
      try
        {
          maybe_missing_function_hook (name);
        }
      catch (octave::execution_exception& e)
        {
          error (e, "feval: function '%s' not found", name.c_str ());
        }
    }

  return retval;
}
-verbatim-

and the maybe_missing_function_hook function calls feval.

+verbatim+
void maybe_missing_function_hook (const std::string& name)
{
  // Don't do this if we're handling errors.
  if (buffer_error_messages == 0 && ! Vmissing_function_hook.empty ())
    {
      octave_value val = symbol_table::find_function (Vmissing_function_hook);

      if (val.is_defined ())
        {
          // Ensure auto-restoration.
          octave::unwind_protect frame;
          frame.protect_var (Vmissing_function_hook);

          // Clear the variable prior to calling the function.
          const std::string func_name = Vmissing_function_hook;
          Vmissing_function_hook.clear ();

          // Call.
          feval (func_name, octave_value (name));
        }
    }
}
-verbatim-

Maybe the Vmissing_function_hook function should return a value that
indicates whether the hook handled the exception or not.  If it didn't then
it could report that back to the caller?  Anyone have a good idea on this?

As John D noted on the tracker, it used to generate an error if feval was called for a nonexistent function. I assume this is an unintentional change in behavior that happened when error_state was eliminated.

I can look at it if you want me to. My first step might be to try using gdb (set up to catch exceptions when they are thrown) to see exactly what path is taken when feval is called for a missing function.

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]