changeset 6757:c3cd7d14fc5e

[project @ 2007-06-25 19:06:42 by jwe]
author jwe
date Mon, 25 Jun 2007 19:13:06 +0000
parents 47dc81fefe8a
children 1894012e6b84
files doc/interpreter/contributors.in scripts/image/imshow.m src/ChangeLog src/oct-stream.cc src/oct-stream.h test/test_diffeq.m test/test_nonlin.m test/test_quad.m
diffstat 8 files changed, 126 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/contributors.in	Mon Jun 25 18:40:21 2007 +0000
+++ b/doc/interpreter/contributors.in	Mon Jun 25 19:13:06 2007 +0000
@@ -175,6 +175,7 @@
 Ariel Tankus
 Georg Thimm
 Duncan Temple Lang
+Olaf Till
 Thomas Treichl
 Utkarsh Upadhyay
 Stefan van der Walt
--- a/scripts/image/imshow.m	Mon Jun 25 18:40:21 2007 +0000
+++ b/scripts/image/imshow.m	Mon Jun 25 19:13:06 2007 +0000
@@ -102,7 +102,7 @@
     if (ismatrix (arg) && size (arg, 2) == 3)
       color_map = arg;
       isindexed = true;
-    elseif (ismatrix (arg) && ndims (arg) == 2)
+    elseif (ismatrix (arg) && numel (arg) == 2)
       display_range = arg;
     elseif (isempty (arg))
       display_range = [min(im(:)), max(im(:))];
--- a/src/ChangeLog	Mon Jun 25 18:40:21 2007 +0000
+++ b/src/ChangeLog	Mon Jun 25 19:13:06 2007 +0000
@@ -1,3 +1,20 @@
+2007-06-25  Olaf Till  <i7tiol@t-online.de>
+
+	* oct-stream.h (octave_stream_list::list): Use std::map.
+	(octave_stream_list::curr_len): Delete data member.
+	(octave_stream_list::octave_stream_list): Fix initializations.
+ 
+	* oct-stream.cc (octave_steam_list::do_insert,
+	octave_steam_list::do_lookup, octave_steam_list::do_remove,
+	octave_steam_list::do_clear, octave_steam_list::do_list_open_files, 
+	octave_steam_list::do_open_file_numbers,
+	octave_steam_list::do_get_file_number):
+ 	Use new octave_stream_list::list type.
+	(octave_stream_list::do_insert): Insert octave_stream with key
+	corresponding to file-descriptor.
+	(octave_stream_list::do_insert, octave_steam_list::insert):
+	Remove const qualifier of argument.
+
 2007-06-18  Søren Hauberg  <hauberg@gmail.com>
 
         * DLD-FUNCTIONS/__lin_interpn__.cc: Replace octave_NaN with octave_NA.
--- a/src/oct-stream.cc	Mon Jun 25 18:40:21 2007 +0000
+++ b/src/oct-stream.cc	Mon Jun 25 19:13:06 2007 +0000
@@ -897,10 +897,11 @@
   // std::filebuf (nor in the GNU libstdc++-v3 implementation). We cache
   // the descriptor in c_file_ptr_buf, and then extract it here.
 
-  c_file_ptr_buf *ibuf = is ?
-    dynamic_cast<c_file_ptr_buf *> (is->rdbuf ()) : 0;
-  c_file_ptr_buf *obuf = os ?
-    dynamic_cast<c_file_ptr_buf *> (os->rdbuf ()) : 0;
+  c_file_ptr_buf *ibuf
+    = is ? dynamic_cast<c_file_ptr_buf *> (is->rdbuf ()) : 0;
+
+  c_file_ptr_buf *obuf
+    = os ? dynamic_cast<c_file_ptr_buf *> (os->rdbuf ()) : 0;
 
   int i_fid = ibuf ? ibuf->file_number () : -1;
   int o_fid = obuf ? obuf->file_number () : -1;
@@ -3888,7 +3889,7 @@
 }
 
 int
-octave_stream_list::insert (const octave_stream& os)
+octave_stream_list::insert (octave_stream& os)
 {
   return (instance_ok ()) ? instance->do_insert (os) : -1;
 }
@@ -3956,40 +3957,35 @@
 }
 
 int
-octave_stream_list::do_insert (const octave_stream& os)
+octave_stream_list::do_insert (octave_stream& os)
 {
-  octave_value retval;
-
-  int stream_number = -1;
-
-  // Insert item in first open slot, increasing size of list if
-  // necessary.
-
-  for (int i = 0; i < curr_len; i++)
+  // Insert item with key corresponding to file-descriptor.
+
+  int stream_number;
+
+  if ((stream_number = os.file_number ()) == -1)
+    return stream_number;
+
+  // Should we test for "(list.find (stream_number) != list.end ()) &&
+  // list[stream_number].is_open ()" and respond with "error
+  // ("internal error: ...")"? It should not happen except for some
+  // bug or if the user has opened a stream with an interpreted
+  // command, but closed it directly with a system call in an
+  // oct-file; then the kernel knows the fd is free, but Octave does
+  // not know. If it happens, it should not do harm here to simply
+  // overwrite this entry, although the wrong entry might have done
+  // harm before.
+
+  if (list.size () < list.max_size ())
+    list[stream_number] = os;
+  else
     {
-      octave_stream tmp = list(i);
-
-      if (! tmp.is_open ())
-	{
-	  list(i) = os;
-	  stream_number = i;
-	  break;
-	}
-    }
-
-  if (stream_number < 0)
-    {
-      int total_len = list.length ();
-
-      if (curr_len == total_len)
-	list.resize (total_len * 2);
-
-      list(curr_len) = os;
-      stream_number = curr_len;
-      curr_len++;
+      stream_number = -1;
+      error ("could not create file id");
     }
 
   return stream_number;
+
 }
 
 static void
@@ -4006,8 +4002,15 @@
 {
   octave_stream retval;
 
-  if (fid >= 0 && fid < curr_len)
-    retval = list(fid);
+  if (fid >= 0)
+    {
+      ostrl_map::const_iterator iter = list.find (fid);
+
+      if (iter != list.end ())
+	retval = iter->second;
+      else
+	gripe_invalid_file_id (fid, who);
+    }
   else
     gripe_invalid_file_id (fid, who);
 
@@ -4036,15 +4039,22 @@
   // Can't remove stdin (std::cin), stdout (std::cout), or stderr
   // (std::cerr).
 
-  if (fid > 2 && fid < curr_len)
+  if (fid > 2)
     {
-      octave_stream os = list(fid);
-
-      if (os.is_valid ())
+      ostrl_map::iterator iter = list.find (fid);
+
+      if (iter != list.end ())
 	{
-	  os.close ();
-	  list(fid) = octave_stream ();
-	  retval = 0;
+	  octave_stream os = iter->second;
+
+	  if (os.is_valid ())
+	    {
+	      os.close ();
+	      iter->second = octave_stream ();
+	      retval = 0;
+	    }
+	  else
+	    gripe_invalid_file_id (fid, who);
 	}
       else
 	gripe_invalid_file_id (fid, who);
@@ -4062,14 +4072,17 @@
 
   if (fid.is_string () && fid.string_value () == "all")
     {
-      // Skip stdin, stdout, and stderr.
-
-      for (int i = 3; i < curr_len; i++)
+      for (ostrl_map::iterator p = list.begin (); p != list.end (); p++)
 	{
-	  octave_stream os = list(i);
-
-	  if (os.is_valid ())
-	    do_remove (i, who);
+	  // Skip stdin, stdout, and stderr.
+
+	  if (p->first > 2)
+	    {
+	      octave_stream os = p->second;
+
+	      if (os.is_valid ())
+		do_remove (p->first, who);
+	    }
 	}
 
       retval = 0;
@@ -4090,13 +4103,18 @@
 {
   // Do flush stdout and stderr.
 
-  list(0) . flush ();
-  list(1) . flush ();
+  list[0].flush ();
+  list[1].flush ();
 
   // But don't delete them or stdin.
 
-  for (int i = 3; i < curr_len; i++)
-    list(i) = octave_stream ();
+  for (ostrl_map::iterator p = list.begin (); p != list.end (); p++)
+    {
+      // Skip stdin, stdout, and stderr.
+
+      if (p->first > 2)
+	p->second = octave_stream ();
+    }
 }
 
 string_vector
@@ -4148,13 +4166,13 @@
       << "  number  mode  arch       name\n"
       << "  ------  ----  ----       ----\n";
 
-  for (int i = 0; i < curr_len; i++)
+  for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
     {
-      octave_stream os = list(i);
+      octave_stream os = p->second;
 
       buf << "  "
 	  << std::setiosflags (std::ios::right)
-	  << std::setw (4) << i << "     "
+	  << std::setw (4) << p->first << "     "
 	  << std::setiosflags (std::ios::left)
 	  << std::setw (3)
 	  << octave_stream::mode_as_string (os.mode ())
@@ -4175,16 +4193,16 @@
 octave_value
 octave_stream_list::do_open_file_numbers (void) const
 {
-  Matrix retval (1, curr_len, 0.0);
+  Matrix retval (1, list.size (), 0.0);
 
   int num_open = 0;
 
-  // Skip stdin, stdout, and stderr.
-
-  for (int i = 3; i < curr_len; i++)
+  for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
     {
-      if (list(i))
-	retval (0, num_open++) = i;
+      // Skip stdin, stdout, and stderr.
+
+      if (p->first > 2 && p->second)
+	retval(0,num_open++) = p->first;
     }
 
   retval.resize ((num_open > 0), num_open);
@@ -4201,17 +4219,20 @@
     {
       std::string nm = fid.string_value ();
 
-      // stdin (std::cin), stdout (std::cout), and stderr (std::cerr)
-      // are unnamed.
-
-      for (int i = 3; i < curr_len; i++)
+      for (ostrl_map::const_iterator p = list.begin (); p != list.end (); p++)
 	{
-	  octave_stream os = list(i);
-
-	  if (os && os.name () == nm)
+	  // stdin (std::cin), stdout (std::cout), and stderr (std::cerr)
+	  // are unnamed.
+
+	  if (p->first > 2)
 	    {
-	      retval = i;
-	      break;
+	      octave_stream os = p->second;
+
+	      if (os && os.name () == nm)
+		{
+		  retval = p->first;
+		  break;
+		}
 	    }
 	}
     }
--- a/src/oct-stream.h	Mon Jun 25 18:40:21 2007 +0000
+++ b/src/oct-stream.h	Mon Jun 25 19:13:06 2007 +0000
@@ -32,6 +32,7 @@
 #include <iostream>
 #include <sstream>
 #include <string>
+#include <map>
 
 #include "Array.h"
 #include "data-conv.h"
@@ -583,9 +584,15 @@
 
   static std::string mode_as_string (int mode);
 
-  std::istream *input_stream (void) { return rep ? rep->input_stream () : 0; }
+  std::istream *input_stream (void)
+  {
+    return rep ? rep->input_stream () : 0;
+  }
 
-  std::ostream *output_stream (void) { return rep ? rep->output_stream () : 0; }
+  std::ostream *output_stream (void)
+  {
+    return rep ? rep->output_stream () : 0;
+  }
 
   void clearerr (void) { if (rep) rep->clearerr (); }
 
@@ -622,7 +629,7 @@
 {
 protected:
 
-  octave_stream_list (void) : list (32), curr_len (0) { }
+  octave_stream_list (void) : list () { }
 
 public:
 
@@ -630,7 +637,7 @@
 
   static bool instance_ok (void);
 
-  static int insert (const octave_stream& os);
+  static int insert (octave_stream& os);
 
   static octave_stream
   lookup (int fid, const std::string& who = std::string ());
@@ -655,13 +662,13 @@
 
 private:
 
-  Array<octave_stream> list;
+  typedef std::map<int, octave_stream> ostrl_map;
 
-  int curr_len;
+  ostrl_map list;
 
   static octave_stream_list *instance;
 
-  int do_insert (const octave_stream& os);
+  int do_insert (octave_stream& os);
 
   octave_stream do_lookup (int fid, const std::string& who = std::string ()) const;
   octave_stream do_lookup (const octave_value& fid,
--- a/test/test_diffeq.m	Mon Jun 25 18:40:21 2007 +0000
+++ b/test/test_diffeq.m	Mon Jun 25 19:13:06 2007 +0000
@@ -70,9 +70,6 @@
 %! lsode_options ("absolute tolerance", eps);
 %! assert(lsode_options ("absolute tolerance") == eps);
 
-%% test/octave.test/diffeq/lsode_options-2.m
-%!error <Invalid call to lsode_options.*> lsode_options ();
-
 %% test/octave.test/diffeq/lsode_options-3.m
 %!error <Invalid call to lsode_options.*> lsode_options ("foo", 1, 2);
 
@@ -154,9 +151,6 @@
 %! dassl_options ("absolute tolerance", eps);
 %! assert(dassl_options ("absolute tolerance") == eps);
 
-%% test/octave.test/diffeq/dassl_options-2.m
-%!error <Invalid call to dassl_options.*> dassl_options ();
-
 %% test/octave.test/diffeq/dassl_options-3.m
 %!error <Invalid call to dassl_options.*> dassl_options ("foo", 1, 2);
 
--- a/test/test_nonlin.m	Mon Jun 25 18:40:21 2007 +0000
+++ b/test/test_nonlin.m	Mon Jun 25 19:13:06 2007 +0000
@@ -80,9 +80,6 @@
 %! fsolve_options ("tolerance", eps);
 %! assert(fsolve_options ("tolerance") == eps);
 
-%% test/octave.test/nonlin/fsolve_options-2.m
-%!error <Invalid call to fsolve_options.*> fsolve_options ();
-
 %% test/octave.test/nonlin/fsolve_options-3.m
 %!error <Invalid call to fsolve_options.*> fsolve_options ("foo", 1, 2);
 
--- a/test/test_quad.m	Mon Jun 25 18:40:21 2007 +0000
+++ b/test/test_quad.m	Mon Jun 25 19:13:06 2007 +0000
@@ -26,9 +26,6 @@
 %! quad_options ("absolute tolerance", eps);
 %! assert(quad_options ("absolute tolerance") == eps);
 
-%% test/octave.test/quad/quad_options-2.m
-%!error <Invalid call to quad_options.*> quad_options ();
-
 %% test/octave.test/quad/quad_options-3.m
 %!error <Invalid call to quad_options.*> quad_options (1, 2, 3);