# HG changeset patch # User jwe # Date 1094073894 0 # Node ID ed0f3cb6d3d40742052301b84146bb76a7131055 # Parent 7a3a480e86450dff670f0ea7a3a6f94925bb8816 [project @ 2004-09-01 21:24:53 by jwe] diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/ChangeLog --- a/src/ChangeLog Wed Sep 01 21:10:28 2004 +0000 +++ b/src/ChangeLog Wed Sep 01 21:24:54 2004 +0000 @@ -1,3 +1,22 @@ +2004-09-01 David Bateman + + * DLD-FUNCTION/quad.cc: Allow function handle and inline functions. + Use a unique function name and delete it on exit. + + * ov.h (is_inline_function): New virtual function. + * ov-fcn-inline.h (is_inline_function): New function. + * ov-base.h (is_inline_function): New function. + + * ov-fcn-inline.cc (octave_fcn_handle::octave_fcn_handle): + Use unique_symbol_name and clear_function instead of manipulating + symbol table directly. + + * variables.cc (unique_symbol_name): New function. + (clear_function): New function. + * variables.h: Provide decls. + + * dynamic-ld.cc (do_clear_function): Rename from clear_function. + 2004-09-01 John W. Eaton * OPERATORS/op-i8-i8.cc, OPERATORS/op-i16-i16.cc, diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/DLD-FUNCTIONS/quad.cc --- a/src/DLD-FUNCTIONS/quad.cc Wed Sep 01 21:10:28 2004 +0000 +++ b/src/DLD-FUNCTIONS/quad.cc Wed Sep 01 21:24:54 2004 +0000 @@ -105,6 +105,8 @@ #define QUAD_ABORT() \ do \ { \ + if (fcn_name.length()) \ + clear_function (fcn_name); \ unwind_protect::run_frame ("Fquad"); \ return retval; \ } \ @@ -130,8 +132,9 @@ "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{v}, @var{ier}, @var{nfun}, @var{err}] =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\ Integrate a nonlinear function of one variable using Quadpack.\n\ -The first argument is the name of the function to call to compute the\n\ -value of the integrand. It must have the form\n\ +The first argument is the name of the function, the function handle or\n\ +the inline function to call to compute the value of the integrand. It\n\ +must have the form\n\ \n\ @example\n\ y = f (x)\n\ @@ -165,6 +168,8 @@ { octave_value_list retval; + std::string fcn_name; + warned_imaginary = false; unwind_protect::begin_frame ("Fquad"); @@ -179,9 +184,18 @@ if (nargin > 2 && nargin < 6 && nargout < 5) { - quad_fcn = extract_function (args(0), "quad", "__quad_fcn__", - "function y = __quad_fcn__ (x) y = ", - "; endfunction"); + if (args(0).is_function_handle () || args(0).is_inline_function ()) + quad_fcn = args(0).function_value (); + else + { + fcn_name = unique_symbol_name ("__quad__fcn__"); + std::string fname = "function y = "; + fname.append (fcn_name); + fname.append ("(x) y = "); + quad_fcn = extract_function (args(0), "quad", fcn_name, fname, + "; endfunction"); + } + if (! quad_fcn) QUAD_ABORT (); @@ -289,6 +303,9 @@ retval(2) = static_cast (nfun); retval(1) = static_cast (ier); retval(0) = val; + + if (fcn_name.length()) + clear_function (fcn_name); } else print_usage ("quad"); diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/dynamic-ld.cc --- a/src/dynamic-ld.cc Wed Sep 01 21:10:28 2004 +0000 +++ b/src/dynamic-ld.cc Wed Sep 01 21:24:54 2004 +0000 @@ -195,7 +195,7 @@ } static -void clear_function (const std::string& fcn_name) +void do_clear_function (const std::string& fcn_name) { if (Vwarn_reload_forces_clear) warning (" %s", fcn_name.c_str ()); @@ -235,7 +235,7 @@ warning ("reloading %s clears the following functions:", oct_file.file_name().c_str ()); - oct_file.close (clear_function); + oct_file.close (do_clear_function); function = 0; } diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/ov-base.h --- a/src/ov-base.h Wed Sep 01 21:10:28 2004 +0000 +++ b/src/ov-base.h Wed Sep 01 21:24:54 2004 +0000 @@ -171,6 +171,8 @@ bool is_function_handle (void) const { return false; } + bool is_inline_function (void) const { return false; } + bool is_function (void) const { return false; } bool is_builtin_function (void) const { return false; } diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/ov-fcn-inline.cc --- a/src/ov-fcn-inline.cc Wed Sep 01 21:10:28 2004 +0000 +++ b/src/ov-fcn-inline.cc Wed Sep 01 21:24:54 2004 +0000 @@ -55,11 +55,7 @@ : octave_fcn_handle (0, n), iftext (f), ifargs (a) { // Find a function name that isn't already in the symbol table. - - std::string fname = "__inline__"; - - while (symbol_exist (fname)) - fname.append ("X"); + std::string fname = unique_symbol_name ("__inline__"); // Form a string representing the function. @@ -91,10 +87,7 @@ { fcn = tmp; - // XXX FIXME XXX -- probably shouldn't be directly altering the - // symbol table here. - - fbi_sym_tab->clear_function (fname); + clear_function (fname); } else error ("inline: unable to define function"); diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/ov-fcn-inline.h --- a/src/ov-fcn-inline.h Wed Sep 01 21:10:28 2004 +0000 +++ b/src/ov-fcn-inline.h Wed Sep 01 21:24:54 2004 +0000 @@ -57,6 +57,8 @@ ~octave_fcn_inline (void) { } + bool is_inline_function (void) const { return true; } + octave_fcn_inline *fcn_inline_value (bool = false) { return this; } std::string fcn_text (void) const { return iftext; } diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/ov.h --- a/src/ov.h Wed Sep 01 21:10:28 2004 +0000 +++ b/src/ov.h Wed Sep 01 21:24:54 2004 +0000 @@ -484,6 +484,9 @@ virtual bool is_function_handle (void) const { return rep->is_function_handle (); } + virtual bool is_inline_function (void) const + { return rep->is_inline_function (); } + virtual bool is_function (void) const { return rep->is_function (); } diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/variables.cc --- a/src/variables.cc Wed Sep 01 21:10:28 2004 +0000 +++ b/src/variables.cc Wed Sep 01 21:24:54 2004 +0000 @@ -662,6 +662,16 @@ return retval; } +std::string +unique_symbol_name (const std::string& basename) +{ + // XXX FIXME XXX Can we be smarter than just adding characters? + std::string name = basename; + while (symbol_exist (name, "any")) + name.append ("X"); + return name; +} + DEFUN (exist, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ @@ -1897,6 +1907,13 @@ } \ while (0) + +bool +clear_function (const std::string& nm) +{ + return do_clear_function (nm); +} + DEFCMD (clear, args, , "-*- texinfo -*-\n\ @deffn {Command} clear [-x] pattern @dots{}\n\ diff -r 7a3a480e8645 -r ed0f3cb6d3d4 src/variables.h --- a/src/variables.h Wed Sep 01 21:10:28 2004 +0000 +++ b/src/variables.h Wed Sep 01 21:24:54 2004 +0000 @@ -77,6 +77,9 @@ extern int symbol_exist (const std::string& name, const std::string& type = "any"); +extern std::string +unique_symbol_name (const std::string& basename); + extern bool lookup (symbol_record *s, bool exec_script = true); extern symbol_record * @@ -116,6 +119,8 @@ extern void munlock (const std::string&); extern bool mislocked (const std::string&); +extern bool clear_function (const std::string& nm); + // Symbol table for symbols at the top level. extern symbol_table *top_level_sym_tab;