octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave/backend interface proposal


From: John W. Eaton
Subject: Re: Octave/backend interface proposal
Date: Tue, 22 Jan 2008 15:31:50 -0500

On 22-Jan-2008, Michael Goffioul wrote:

| On Jan 21, 2008 9:58 AM, Michael Goffioul <address@hidden> wrote:
| > I also think that putting this class into a separated header will get me
| > into trouble, because of the classes dependencies. I think I'll put it
| > into graphics.h.in and generate a new patch. Any objection?
| 
| Here's a completed (working) version of the patch. It defines the
| base_graphics_backend
| and graphics_backend classes, associate a backend with a figure, defines the
| default gnuplot backend and move drawnow to C++.
| 
| I tested it and it seems to work OK.

I applied the patch and checked it in.

I also made the following additional changes to avoid some calls to
eval and feval, and to (I think) properly protect the
drawnow_executing variable and the __drawnow_request__ state.

Thanks,

jwe


src/ChangeLog:

2008-01-22  John W. Eaton  <address@hidden>

        * graphics.cc (clear_drawnow_request): New function.
        (Fdrawnow): Add it to the unwind_protect stack.

        * input.cc (Vdrawnow_requested): No longer static.
        * input.h: Provide decl.
        * graphics.cc (Fdrawnow, Fset, make_graphics_object):
        Use Vdrawnow_requested directly.

        * toplev.cc (octave_add_atexit_function,
        octave_remove_atexit_function): New functions.
        (Fatexit): Use them.
        * graphics.cc (Fdrawnow): Call octave_add_atexit_function instead
        of using eval.
        * toplev.h (octave_add_atexit_function,
        octave_remove_atexit_function): Provide decls.


Index: src/graphics.cc
===================================================================
RCS file: /cvs/octave/src/graphics.cc,v
retrieving revision 1.77
diff -u -u -w -r1.77 graphics.cc
--- src/graphics.cc     22 Jan 2008 19:42:48 -0000      1.77
+++ src/graphics.cc     22 Jan 2008 20:27:11 -0000
@@ -34,17 +34,20 @@
 #include <set>
 #include <string>
 
+#include "file-ops.h"
+#include "file-stat.h"
+
 #include "defun.h"
 #include "error.h"
 #include "graphics.h"
+#include "input.h"
 #include "ov.h"
 #include "oct-obj.h"
 #include "oct-map.h"
 #include "ov-fcn-handle.h"
 #include "parse.h"
+#include "toplev.h"
 #include "unwind-prot.h"
-#include "file-ops.h"
-#include "file-stat.h"
 
 static void
 gripe_set_invalid (const std::string& pname)
@@ -1194,7 +1197,7 @@
       feval ("gnuplot_drawnow", args);
     }
 
-  Matrix get_canvas_size (const graphics_handle& fh) const
+  Matrix get_canvas_size (const graphics_handle&) const
     { return Matrix (1, 2, 0.0); }
 };
 
@@ -1955,7 +1958,7 @@
             }
 
          if (! error_state && request_drawnow)
-           feval ("__request_drawnow__");
+           Vdrawnow_requested = true;
         }
       else
         error ("set: expecting graphics handle as first argument");
@@ -2119,7 +2122,7 @@
              retval = h.value ();
 
              if (! error_state)
-               feval ("__request_drawnow__");
+               Vdrawnow_requested = true;
            }
          else
            error ("__go%s__: unable to create graphics handle",
@@ -2365,6 +2368,12 @@
   return octave_value (gh_manager::figure_handle_list ());
 }
 
+static void
+clear_drawnow_request (void *)
+{
+  Vdrawnow_requested = false;
+}
+
 DEFUN (drawnow, args, ,
    "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\
@@ -2377,19 +2386,20 @@
 
   octave_value retval;
 
-  if (drawnow_executing >= 1)
-    return retval;
+  unwind_protect::begin_frame ("Fdrawnow");
+  unwind_protect::add (clear_drawnow_request);
+
+  unwind_protect_int (drawnow_executing);
 
+  if (++drawnow_executing <= 1)
+    {
   if (! __go_close_all_registered__)
     {
-      // FIXME: is there a C++ way to do this?
-      int parse_status;
-      eval_string ("atexit (\"__go_close_all__\")", true, parse_status);
+         octave_add_atexit_function ("__go_close_all__");
+
       __go_close_all_registered__ = true;
     }
 
-  ++drawnow_executing;
-
   if (args.length () == 0)
     {
       Matrix hlist = gh_manager::figure_handle_list ();
@@ -2431,7 +2441,7 @@
 
          if (! error_state)
            {
-             int pos = file.find_last_of (file_ops::dir_sep_chars);
+                 size_t pos = file.find_last_of (file_ops::dir_sep_chars);
 
              if (pos != NPOS)
                {
@@ -2456,6 +2466,7 @@
                      if (h.ok ())
                        {
                          graphics_object go = gh_manager::get_object (h);
+
                          figure::properties& fprops = 
dynamic_cast<figure::properties&> (go.get_properties ());
 
                          fprops.get_backend ()
@@ -2478,13 +2489,9 @@
     }
   else
     print_usage ();
+    }
 
-  // FIXME: is there a C++ way to do this?
-  octave_value_list fargs;
-  fargs(0) = false;
-  feval ("__request_drawnow__", fargs);
-
-  --drawnow_executing;
+  unwind_protect::run_frame ("Fdrawnow");
 
   return retval;
 }
Index: src/input.cc
===================================================================
RCS file: /cvs/octave/src/input.cc,v
retrieving revision 1.191
diff -u -u -w -r1.191 input.cc
--- src/input.cc        28 Dec 2007 20:56:56 -0000      1.191
+++ src/input.cc        22 Jan 2008 20:27:11 -0000
@@ -141,7 +141,7 @@
 
 // TRUE if the plotting system has requested a call to drawnow at
 // the next user prompt.
-static bool Vdrawnow_requested = false;
+bool Vdrawnow_requested = false;
 
 // TRUE if we are running in the Emacs GUD mode.
 static bool Vgud_mode = false;
Index: src/input.h
===================================================================
RCS file: /cvs/octave/src/input.h,v
retrieving revision 1.45
diff -u -u -w -r1.45 input.h
--- src/input.h 12 Oct 2007 21:27:30 -0000      1.45
+++ src/input.h 22 Jan 2008 20:27:11 -0000
@@ -84,6 +84,10 @@
 // TRUE after a call to completion_matches.
 extern bool octave_completion_matches_called;
 
+// TRUE if the plotting system has requested a call to drawnow at
+// the next user prompt.
+extern bool Vdrawnow_requested;
+
 extern std::string gnu_readline (const std::string& s, bool force_readline = 
false);
 
 extern void initialize_command_input (void);
Index: src/toplev.cc
===================================================================
RCS file: /cvs/octave/src/toplev.cc,v
retrieving revision 1.211
diff -u -u -w -r1.211 toplev.cc
--- src/toplev.cc       12 Jan 2008 07:50:55 -0000      1.211
+++ src/toplev.cc       22 Jan 2008 20:27:11 -0000
@@ -663,6 +663,32 @@
     }
 }
 
+void
+octave_add_atexit_function (const std::string& fname)
+{
+  octave_atexit_functions.push_front (fname);
+}
+
+bool
+octave_remove_atexit_function (const std::string& fname)
+{
+  bool found = false;
+
+  for (std::list<std::string>::iterator p = octave_atexit_functions.begin ();
+       p != octave_atexit_functions.end (); p++)
+    {
+      if (*p == fname)
+       {
+         octave_atexit_functions.erase (p);
+         found = true;
+         break;
+       }
+    }
+
+  return found;
+}
+
+
 DEFUN (atexit, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\
@@ -723,22 +749,10 @@
           if (! error_state)
            {
              if (add_mode)
-               octave_atexit_functions.push_front (arg);
+               octave_add_atexit_function (arg);
              else
                {
-                 bool found = false;
-                 std::list<std::string>::iterator it;
-
-                 for (std::list<std::string>::iterator p = 
octave_atexit_functions.begin ();
-                      p != octave_atexit_functions.end (); p++)
-                   {
-                     if (*p == arg)
-                       {
-                         octave_atexit_functions.erase (p);
-                         found = true;
-                         break;
-                       }
-                   }
+                 bool found = octave_remove_atexit_function (arg);
 
                  if (nargout > 0)
                    retval(0) = found;
Index: src/toplev.h
===================================================================
RCS file: /cvs/octave/src/toplev.h,v
retrieving revision 1.62
diff -u -u -w -r1.62 toplev.h
--- src/toplev.h        4 Dec 2007 18:12:33 -0000       1.62
+++ src/toplev.h        22 Jan 2008 20:27:11 -0000
@@ -46,6 +46,12 @@
 extern OCTINTERP_API void
 do_octave_atexit (void);
 
+extern OCTINTERP_API void
+octave_add_atexit_function (const std::string& fname);
+
+extern OCTINTERP_API bool
+octave_remove_atexit_function (const std::string& fname);
+
 // Current command to execute.
 extern OCTINTERP_API tree_statement_list *global_command;
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]