From bug-octave-request at bevo dot che dot wisc dot edu Mon Nov 25 00:23:25 2002 Subject: Function cache too tenacious From: "John W. Eaton" To: Julius Smith Cc: bug-octave at bevo dot che dot wisc dot edu Date: Mon, 25 Nov 2002 00:22:54 -0600 On 22-Nov-2002, Julius Smith wrote: | I'm running Octave version 2.1.36 on a Linux PC, and I encountered a what | appears to be a bug in function caching behavior. Briefly described, I | often debug functions by commenting out their declaration line at the top | and invoking them by name only (after setting up arguments using | assignments). This helps because all the function local variables become | available in the top-level scope where they can be inspected. The problem | I found is that Octave seems to be trying to use the function definition | after I have "overridden it" with a script version of the same name. | Even more surprising, "clear functions" does not fix the problem. I don't think 2.1.36 had "clear functions" as a special case, so all it would try to do is clear a symbol called "functions". | However, an | explicit "clear function-name" does work, so that's a workaround. All of | this is illustrated in the diary output below: The following patch (relative to the current CVS) seems to fix the problem. jwe src/ChangeLog: 2002-11-25 John W. Eaton * pt-stmt.cc (tree_statement::eval): Allow the lookup to execute script files. If script file has been executed, don't bother to call expr->rvalue (). Index: src/pt-stmt.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/pt-stmt.cc,v retrieving revision 1.17 diff -u -r1.17 pt-stmt.cc --- src/pt-stmt.cc 20 Nov 2002 16:56:49 -0000 1.17 +++ src/pt-stmt.cc 25 Nov 2002 06:18:54 -0000 at @ -111,25 +111,32 @@ // or not the expression will take care of binding ans and // printing the result. + // XXX FIXME XXX -- it seems that we should just have to + // call expr->rvalue () and that should take care of + // everything, binding ans as necessary? + bool do_bind_ans = false; + bool script_file_executed = false; + if (expr->is_identifier ()) { - bool script_file_executed = false; - tree_identifier *id = static_cast (expr); - id->do_lookup (script_file_executed, false); + id->do_lookup (script_file_executed, true); do_bind_ans = id->is_function (); } else do_bind_ans = (! expr->is_assignment_expression ()); - retval = expr->rvalue (nargout); + if (! script_file_executed) + { + retval = expr->rvalue (nargout); - if (do_bind_ans && ! (error_state || retval.empty ())) - bind_ans (retval(0), pf); + if (do_bind_ans && ! (error_state || retval.empty ())) + bind_ans (retval(0), pf); + } } unwind_protect::run (); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------