comparison libinterp/octave-value/ov-fcn-handle.cc @ 20640:f9c991dc5c1a

avoid scope error in anonymous functions (bug #45835) * ov-fcn-handle.cc (octave_fcn_binder::maybe_binder): Don't optimize functions that wrap eval or feval.
author John W. Eaton <jwe@octave.org>
date Sun, 11 Oct 2015 18:53:05 -0400
parents 729a85dafba8
children
comparison
equal deleted inserted replaced
20639:a260a6acb70f 20640:f9c991dc5c1a
2064 root_val = head_id->rvalue1 (); 2064 root_val = head_id->rvalue1 ();
2065 else 2065 else
2066 { 2066 {
2067 // It's a name. 2067 // It's a name.
2068 std::string head_name = head_id->name (); 2068 std::string head_name = head_id->name ();
2069 // Function handles can't handle legacy dispatch, so 2069
2070 // we make sure it's not defined. 2070 if (head_name == "eval" || head_name == "feval")
2071 if (symbol_table::get_dispatch (head_name).size () > 0)
2072 bad = true; 2071 bad = true;
2073 else 2072 else
2074 { 2073 {
2075 // Simulate try/catch. 2074 // Function handles can't handle legacy
2076 unwind_protect frame; 2075 // dispatch, so we make sure it's not
2077 interpreter_try (frame); 2076 // defined.
2078 2077
2079 bool execution_error = false; 2078 if (symbol_table::get_dispatch (head_name).size () > 0)
2080 2079 bad = true;
2081 try 2080 else
2082 { 2081 {
2083 root_val = make_fcn_handle (head_name); 2082 // Simulate try/catch.
2083 unwind_protect frame;
2084 interpreter_try (frame);
2085
2086 try
2087 {
2088 root_val = make_fcn_handle (head_name);
2089 }
2090 catch (const octave_execution_exception&)
2091 {
2092 bad = true;
2093 }
2084 } 2094 }
2085 catch (const octave_execution_exception&)
2086 {
2087 execution_error = true;
2088 }
2089
2090 if (execution_error)
2091 bad = true;
2092 } 2095 }
2093 } 2096 }
2094 } 2097 }
2095 2098
2096 if (! bad) 2099 if (! bad)
2110 if (! retval) 2113 if (! retval)
2111 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous); 2114 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous);
2112 2115
2113 return retval; 2116 return retval;
2114 } 2117 }
2118
2119 /*
2120 %!test
2121 %! f = @(t) eval ('2*t');
2122 %! assert (f (21), 42);
2123 */
2115 2124
2116 octave_value_list 2125 octave_value_list
2117 octave_fcn_binder::do_multi_index_op (int nargout, 2126 octave_fcn_binder::do_multi_index_op (int nargout,
2118 const octave_value_list& args) 2127 const octave_value_list& args)
2119 { 2128 {