changeset 9728:70925b11ba46

again allow the obsolete syntax for cellfun
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 15 Oct 2009 13:07:44 +0200
parents 04386b72d3df
children 3b7e644bb46d
files src/ChangeLog src/DLD-FUNCTIONS/cellfun.cc src/ov.cc src/ov.h
diffstat 4 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Oct 15 13:06:48 2009 +0200
+++ b/src/ChangeLog	Thu Oct 15 13:07:44 2009 +0200
@@ -1,3 +1,9 @@
+2009-10-15  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov.h (octave_value::octave_value (octave_base_value *, bool)) : New constructor.
+	(octave_value::octave_value (octave_base_value *, int)): Deprecate.
+	* DLD-FUNCTIONS/cellfun.cc (Fcellfun): Allow the obsolete func body syntax.
+
 2009-10-15  Jaroslav Hajek  <highegg@gmail.com>
 
 	* variables.cc (extract_function): Pass 0 to eval_string to avoid
--- a/src/DLD-FUNCTIONS/cellfun.cc	Thu Oct 15 13:06:48 2009 +0200
+++ b/src/DLD-FUNCTIONS/cellfun.cc	Thu Oct 15 13:07:44 2009 +0200
@@ -41,6 +41,7 @@
 #include "ov-colon.h"
 #include "unwind-prot.h"
 #include "gripes.h"
+#include "utils.h"
 
 // Rationale:
 // The octave_base_value::subsasgn method carries too much overhead for
@@ -296,9 +297,6 @@
       octave_idx_type k = f_args.numel ();
 
       std::string name = func.string_value ();
-      if (name.find_first_of ("(x)") != std::string::npos)
-        warning ("cellfun: passing function body as string is no longer supported."
-                 " Use @ or `inline'.");
 
       if (name == "isempty")
         {      
@@ -384,6 +382,19 @@
         }
       else
         {
+          if (! valid_identifier (name))
+            {
+
+              std::string fcn_name = unique_symbol_name ("__cellfun_fcn_");
+              std::string fname = "function y = ";
+              fname.append (fcn_name);
+              fname.append ("(x) y = ");
+              octave_function *ptr_func = extract_function (args(0), "cellfun", 
+                                                            fcn_name, fname, "; endfunction");
+              if (ptr_func && ! error_state)
+                func = octave_value (ptr_func, true);
+            }
+
           func = symbol_table::find_function (name);
           if (func.is_undefined ())
             error ("cellfun: invalid function name: %s", name.c_str ());
--- a/src/ov.cc	Thu Oct 15 13:06:48 2009 +0200
+++ b/src/ov.cc	Thu Oct 15 13:07:44 2009 +0200
@@ -1118,9 +1118,11 @@
 {
 }
 
-octave_value::octave_value (octave_base_value *new_rep)
+octave_value::octave_value (octave_base_value *new_rep, bool borrow)
   : rep (new_rep)
 {
+  if (borrow)
+    rep->count++;
 }
 
 octave_value::octave_value (octave_base_value *new_rep, int xcount)
--- a/src/ov.h	Thu Oct 15 13:06:48 2009 +0200
+++ b/src/ov.h	Thu Oct 15 13:07:44 2009 +0200
@@ -279,8 +279,8 @@
   octave_value (const octave_value_list& m, bool is_cs_list = false);
   octave_value (octave_value::magic_colon);
 
-  octave_value (octave_base_value *new_rep);
-  octave_value (octave_base_value *new_rep, int xcount);
+  octave_value (octave_base_value *new_rep, bool borrow = false);
+  octave_value (octave_base_value *new_rep, int xcount) GCC_ATTR_DEPRECATED;
 
   // Copy constructor.