changeset 7878:b4ac6bb4114b

graphics.cc (execute_callback, xget_ancestor): pass args by const reference and make explicit copies
author John W. Eaton <jwe@octave.org>
date Tue, 10 Jun 2008 13:43:35 -0400
parents 59031cfe331b
children a017ca5a2f75
files src/ChangeLog src/graphics.cc
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Jun 09 14:47:25 2008 -0400
+++ b/src/ChangeLog	Tue Jun 10 13:43:35 2008 -0400
@@ -1,5 +1,9 @@
 2008-06-09  John W. Eaton  <jwe@octave.org>
 
+	* graphics.cc (execute_callback): Pass CB by const reference and
+	explicitly make a copy.
+	(xget_ancestor): Pass GO by const reference and explicitly make a copy.
+
 	* error.cc (verror): Omit "name: " and "\a" from Vlast_error_msg.
 	Save line and column information from user code.
 	* toplev.cc (octave_call_stack::do_caller_user_code_line,
--- a/src/graphics.cc	Mon Jun 09 14:47:25 2008 -0400
+++ b/src/graphics.cc	Tue Jun 10 13:43:35 2008 -0400
@@ -188,12 +188,8 @@
   xset_gcbo (graphics_handle ());
 }
 
-// NOTE: "cb" is passed by value, because "function_value" method
-//       is non-const; passing "cb" by const-reference is not
-//       possible
-
 static void
-execute_callback (octave_value cb, const graphics_handle& h,
+execute_callback (const octave_value& cb_arg, const graphics_handle& h,
                   const octave_value& data)
 {
   octave_value_list args;
@@ -212,6 +208,10 @@
 
   BEGIN_INTERRUPT_WITH_EXCEPTIONS;
 
+  // Copy CB because "function_value" method is non-const.
+
+  octave_value cb = cb_arg;
+
   if (cb.is_function_handle ())
     fcn = cb.function_value ();
   else if (cb.is_string ())
@@ -334,8 +334,10 @@
 }
 
 static graphics_object
-xget_ancestor (graphics_object go, const std::string& type)
+xget_ancestor (const graphics_object& go_arg, const std::string& type)
 {
+  graphics_object go = go_arg;
+
   do
     {
       if (go.valid_object ())