octave-maintainers
[Top][All Lists]
Advanced

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

Re: Saving/Loading anonymous function handles in HDF5


From: David Bateman
Subject: Re: Saving/Loading anonymous function handles in HDF5
Date: Tue, 05 Jun 2007 17:22:33 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Michael Goffioul wrote:
> Hi,
>
> With recent CVS (yesterday, I think), I get problems when running the
> tests
> in ov-fcn-handles.cc, when testing HDF5 format: the code generates a
> run-time
> error in HDF5 library with the following backtrace
>
> HDF5-DIAG: Error detected in HDF5 library version: 1.6.5 thread 0.
> Back trace follows.
>  #000: ..\..\src\H5F.c line 1968 in H5Fcreate(): unable to create file
>    major(04): File interface
>    minor(17): Unable to open file
>  #001: ..\..\src\H5F.c line 1746 in H5F_open(): unable to truncate a
> file which is already open
>    major(04): File interface
>    minor(17): Unable to open file
> error: save: unable to open output file
> `C:/DOCUME~1/goffioul/LOCALS~1/Temp\oct-9'
>
> When executing the test code line by line, this happens when saving to
> hdf5
> format for the second time. Tracing file handles with ProcessExplorer,
> it appears
> that octave still has a file handle referring the saved file after the
> "load(nm);"
> line. Subsequent "unlink" call fails (returns 0) and final "save" call
> produces
> a runtime error and exits octave.
>
> Any idea?
> (Note: hdf5 version is 1.6.5)
>
> Michael.
>
I have HDF5 1.6.4 installed under Mandriva 2006 and I can't see this
issue.. The code that opens the hdf5 file for loading is

      hdf5_ifstream hdf5_file (fname.c_str ());

      if (hdf5_file.file_id >= 0)
        {
          retval = do_load (hdf5_file, orig_fname, force, format,
                flt_fmt, list_only, swap, verbose,
                argv, i, argc, nargout);

          hdf5_file.close ();
        }
      else
        gripe_file_open ("load", orig_fname);

and for saving is

      hdf5_ofstream hdf5_file (fname.c_str ());

      if (hdf5_file.file_id >= 0)
        {
          save_vars (argv, i, argc, hdf5_file, format,
             save_as_floats, true);

          hdf5_file.close ();
      }
    else
      {
        gripe_file_open ("save", fname);
        return retval;
      }

so unless the interpretation of the file_id variable of the hdf5 C++
iostreams has changed, the oprn file should always be correctly closed..
This happens only with anonymous function handles saved to hdf5 files?
It doesn't happen for the other hdf5 load/save tests in
octave/tests/test_sparse.m ?  If so the issue might be in that the
windows hdf5 libraries don't like if the hdf5 IDs aren't correctly
closed and there is a missing call to something like "H5Gclose (hid)" in
ov-fcn-handle.cc. As I can't reproduce this error its going to be
difficult for me to debug it. Though try the attached patch that is much
more careful with calling the H5Xclose functions.

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** src/ov-fcn-handle.cc.~1.40.~        2007-05-23 08:49:53.000000000 +0200
--- src/ov-fcn-handle.cc        2007-06-05 17:18:40.782514521 +0200
***************
*** 737,742 ****
--- 737,743 ----
        H5Tset_size (type_hid, stmp.length () + 1);
        if (type_hid < 0)
        {
+         H5Sclose (space_hid);
          H5Gclose (group_hid);
          return false;
        }
***************
*** 837,843 ****
          H5Aclose (a_id);
        }
        else
!       retval = false;
  
        H5Sclose (space_hid);
        hdims[0] = 1;
--- 838,849 ----
          H5Aclose (a_id);
        }
        else
!       {
!         H5Sclose (space_hid);
!         H5Tclose (type_hid);
!         H5Gclose (group_hid);
!         return false;
!       }
  
        H5Sclose (space_hid);
        hdims[0] = 1;
***************
*** 934,941 ****
--- 940,949 ----
  
    if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0)
      {
+       H5Tclose (st_id);
        H5Sclose (space_hid);
        H5Tclose (type_hid);
+       H5Dclose (data_hid);
        H5Gclose (group_hid);
        return false;
      }
***************
*** 949,969 ****
--- 957,982 ----
  
        if (data_hid < 0)
        {
+         H5Sclose (space_hid);
+         H5Tclose (type_hid);
          H5Gclose (group_hid);
          return false;
        }
  
+       H5Tclose (type_hid);
        type_hid = H5Dget_type (data_hid);
        type_class_hid = H5Tget_class (type_hid);
  
        if (type_class_hid != H5T_STRING)
        {
+         H5Sclose (space_hid);
          H5Tclose (type_hid);
          H5Dclose (data_hid);
          H5Gclose (group_hid);
          return false;
        }
  
+       H5Sclose (space_hid);
        space_hid = H5Dget_space (data_hid);
        rank = H5Sget_simple_extent_ndims (space_hid);
  
***************
*** 994,1004 ****
--- 1007,1020 ----
  
        if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 
0)
        {
+         H5Tclose (st_id);
          H5Sclose (space_hid);
          H5Tclose (type_hid);
+         H5Dclose (data_hid);
          H5Gclose (group_hid);
          return false;
        }
+       H5Tclose (st_id);
        H5Dclose (data_hid);
  
        symbol_table *local_sym_tab = 0;
***************
*** 1081,1089 ****
            }
        }
  
-       H5Tclose (st_id);
-       H5Gclose (group_hid);
- 
        if (success)
        {
          unwind_protect::begin_frame ("anon_hdf5_load");
--- 1097,1102 ----
***************
*** 1133,1138 ****
--- 1146,1152 ----
        hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT");
        if (attr_id >= 0)
        {
+         H5Tclose (type_hid);
          type_hid = H5Aget_type (attr_id);
          type_class_hid = H5Tget_class (type_hid);
  
***************
*** 1149,1181 ****
                success = false;
              else
                octaveroot = root_tmp;
            }
  
          H5Aclose (attr_id);
        }
  
!       attr_id = H5Aopen_name (group_hid, "FILE");
!       if (attr_id >= 0)
        {
!         type_hid = H5Aget_type (attr_id);
!         type_class_hid = H5Tget_class (type_hid);
! 
!         if (type_class_hid != H5T_STRING)
!           success = false;
!         else
            {
!             slen = H5Tget_size (type_hid);
!             st_id = H5Tcopy (H5T_C_S1);
!             H5Tset_size (st_id, slen);
!             OCTAVE_LOCAL_BUFFER (char, path_tmp, slen);
  
!             if (H5Aread (attr_id, st_id, path_tmp) < 0)
                success = false;
              else
!               fpath = path_tmp;
!           }
  
!         H5Aclose (attr_id);
        }
  
        // restore error reporting:
--- 1163,1203 ----
                success = false;
              else
                octaveroot = root_tmp;
+ 
+             H5Tclose (st_id);
            }
  
          H5Aclose (attr_id);
        }
  
!       if (success)
        {
!         attr_id = H5Aopen_name (group_hid, "FILE");
!         if (attr_id >= 0)
            {
!             H5Tclose (type_hid);
!             type_hid = H5Aget_type (attr_id);
!             type_class_hid = H5Tget_class (type_hid);
  
!             if (type_class_hid != H5T_STRING)
                success = false;
              else
!               {
!                 slen = H5Tget_size (type_hid);
!                 st_id = H5Tcopy (H5T_C_S1);
!                 H5Tset_size (st_id, slen);
!                 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen);
  
!                 if (H5Aread (attr_id, st_id, path_tmp) < 0)
!                   success = false;
!                 else
!                   fpath = path_tmp;
! 
!                 H5Tclose (st_id);
!               }
! 
!             H5Aclose (attr_id);
!           }
        }
  
        // restore error reporting:
***************
*** 1184,1189 ****
--- 1206,1215 ----
        success = (success ? set_fcn (octaveroot, fpath) : success);
      }
  
+   H5Tclose (type_hid);
+   H5Sclose (space_hid);
+   H5Gclose (group_hid);
+ 
    return success;
  }
  

reply via email to

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