Octave file IO errors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Octave file IO errors

John W. Eaton
Administrator
On 26-Dec-2008, Jeremy Kepner wrote:

| Hi John,
|    I am getting a lot of intermittent file IO errors
| when I do certain file intensive operations.
| There errors are like:
|
|    error: fwrite: invalid stream number = -1
|
| They are hard to pin down.  For example,
| he program MatlabMPI/examples/speedtest.m
| will often produce the message:
|
|       warning: version: ignoring extra arguments
|
| after  the command
|
|    temp_fid = fopen(lock_file,'r');
|
| These don't seem to happen with 3.0.1.
|
| Anyway, I know these are vague errors (file IO errors
| always are).
|
| They could be related to the delete error
| I sent you.  I don't know.

When Octave opens a file, it calls fopen, then wraps the FILE pointer
in a C++ iostream object.  The number returned by Octave's fopen
function is obtained by calling fileno on the FILE pointer.  I don't
see how this could fail unless there is some race condition happening
in the OS or library code.  Could you apply the following patch to
Octave and see what messages are printed when the error occurs?  Maybe
that will give us a clue.

Thanks,

jwe



diff --git a/src/c-file-ptr-stream.h b/src/c-file-ptr-stream.h
--- a/src/c-file-ptr-stream.h
+++ b/src/c-file-ptr-stream.h
@@ -72,7 +72,18 @@
 
   int close (void);
 
-  int file_number () const { return f ? fileno (f) : -1; }
+  int file_number () const
+  {
+    if (f)
+      {
+ int tmp = fileno (f);
+ if (tmp < 0)
+  std::cerr << "fileno returned < 0" << std::endl;
+ return tmp;
+      }
+    else
+      return -1;
+  }
 
   int seek (long offset, int origin)
     { return f ? fseek (f, offset, origin) : -1; }
diff --git a/src/file-io.cc b/src/file-io.cc
--- a/src/file-io.cc
+++ b/src/file-io.cc
@@ -470,6 +470,9 @@
  {
   FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ());
 
+  if (! fptr)
+    std::cerr << "::fopen failed" << std::endl;
+
   retval = octave_stdiostream::create (fname, fptr, md, flt_fmt);
 
   if (! fptr)
@@ -668,10 +671,20 @@
       if (os && ! error_state)
  {
   retval(1) = "";
-  retval(0) = octave_stream_list::insert (os);
+  double tmp = octave_stream_list::insert (os);
+  if (tmp < 0)
+    std::cerr << "os is OK, but octave_stream_list::insert failed"
+      << std::endl;
+  retval(0) = tmp
  }
       else
  {
+  if (! os)
+    std::cerr << "os is not OK" << std::endl;
+
+  if (error_state)
+    std::cerr << "error_state is set" << std::endl;
+
   int error_number = 0;
 
   retval(1) = os.error (false, error_number);
diff --git a/src/oct-stream.cc b/src/oct-stream.cc
--- a/src/oct-stream.cc
+++ b/src/oct-stream.cc
@@ -3985,10 +3985,13 @@
 {
   // Insert item with key corresponding to file-descriptor.
 
-  int stream_number;
-
-  if ((stream_number = os.file_number ()) == -1)
-    return stream_number;
+  int stream_number = os.file_number ();
+
+  if (stream_number == -1)
+    {
+      std::cerr << "os.file_number () returned -1" << std::endl;
+      return stream_number;
+    }
 
   // Should we test for "(list.find (stream_number) != list.end ()) &&
   // list[stream_number].is_open ()" and respond with "error