changeset 22028:5c949eecb6dd

use int64_t for octave_hdf5_id (bug #47858) * oct-hdf5-types.h (octave_hdf5_id): Use int64_t. * ls-hdf5.cc (check_hdf5_id_value): New static function. * ls-hdf5.h, ls-hdf5.cc (hdf5_read_next_data_internal): Rename from hdf5_read_next_data. Use HDF5 types directly. (hdf5_read_next_data): Now a wrapper around hdf5_read_next_data_internal. Use octave HDF5 types in the interface. (hdf5_h5g_iterate): New function. (read_hdf5_data): Pass hdf5_read_next_data_internal instead of hdf5_read_next_data to H5Giterate. * ov-cell.cc (octave_cell::load_hdf5): Call hdf5_h5g_iterate wrapper function instead of calling H5giterate directly. * ov-class.cc (octave_class::load_hdf5): Likewise. * ov-fcn-handle.cc (octave_fcn_handle::load_hdf5): Likewise. * ov-struct.cc (octave_struct::load_hdf5): Likewise.
author Stefan Miereis <stefan.miereis@gmx.de>
date Sat, 02 Jul 2016 10:19:44 -0400
parents 0f2389d8fe0c
children 6e618b8277ad
files libinterp/corefcn/ls-hdf5.cc libinterp/corefcn/ls-hdf5.h libinterp/corefcn/oct-hdf5-types.h libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-struct.cc
diffstat 7 files changed, 62 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/ls-hdf5.cc	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/corefcn/ls-hdf5.cc	Sat Jul 02 10:19:44 2016 -0400
@@ -35,6 +35,7 @@
 #include <fstream>
 #include <iomanip>
 #include <iostream>
+#include <limits>
 #include <string>
 #include <vector>
 
@@ -72,6 +73,19 @@
 #include "ls-utils.h"
 #include "ls-hdf5.h"
 
+#if defined (HAVE_HDF5)
+
+static hid_t
+check_hdf5_id_value (octave_hdf5_id id, const char *who)
+{
+  if (id > std::numeric_limits<hid_t>::max ())
+    error ("%s: internal error: ID too large for hid_t", who);
+
+  return static_cast<hid_t> (id);
+}
+
+#endif
+
 hdf5_fstreambase::hdf5_fstreambase (const char *name, int mode, int /* prot */)
   : file_id (-1), current_item (-1)
 {
@@ -327,6 +341,8 @@
 #endif
 }
 
+#if defined (HAVE_HDF5)
+
 // This function is designed to be passed to H5Giterate, which calls it
 // on each data item in an HDF5 file.  For the item whose name is NAME in
 // the group GROUP_ID, this function sets dv->tc to an Octave representation
@@ -337,11 +353,9 @@
 // -1 on error, and 0 to tell H5Giterate to continue on to the next item
 // (e.g., if NAME was a data type we don't recognize).
 
-octave_hdf5_err
-hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv)
+static herr_t
+hdf5_read_next_data_internal (hid_t group_id, const char *name, void *dv)
 {
-#if defined (HAVE_HDF5)
-
   hdf5_callback_data *d = static_cast<hdf5_callback_data *> (dv);
   hid_t type_id = -1;
   hid_t type_class_id = -1;
@@ -670,12 +684,40 @@
     }
 
   return retval;
+}
+
+#endif
+
+octave_hdf5_err
+hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv)
+{
+#if defined (HAVE_HDF5)
+
+  hid_t new_id = check_hdf5_id_value (group_id, "hdf5_read_next_data");
+
+  return hdf5_read_next_data_internal (new_id, name, dv);
 
 #else
   err_disabled_feature ("hdf5_read_next_data", "HDF5");
 #endif
 }
 
+octave_hdf5_err
+hdf5_h5g_iterate (octave_hdf5_id loc_id, const char* name, int *idx,
+                  void *operator_data)
+{
+#if defined (HAVE_HDF5)
+
+  hid_t new_id = check_hdf5_id_value (loc_id, "hdf5_h5g_iterate");
+
+  return H5Giterate (new_id, name, idx, hdf5_read_next_data_internal,
+                     operator_data);
+
+#else
+  err_disabled_feature ("hdf5_h5g_iterate", "HDF5");
+#endif
+}
+
 // Read the next Octave variable from the stream IS, which must really be
 // an hdf5_ifstream.  Return the variable value in tc, its doc string
 // in doc, and whether it is global in global.  The return value is
@@ -739,7 +781,7 @@
 
   if (hs.current_item < static_cast<int> (num_obj))
     H5Giterate_retval = H5Giterate (hs.file_id, "/", &hs.current_item,
-                                    hdf5_read_next_data, &d);
+                                    hdf5_read_next_data_internal, &d);
 
   if (H5Giterate_retval > 0)
     {
--- a/libinterp/corefcn/ls-hdf5.h	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/corefcn/ls-hdf5.h	Sat Jul 02 10:19:44 2016 -0400
@@ -122,6 +122,10 @@
 extern OCTINTERP_API octave_hdf5_err
 hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv);
 
+extern OCTINTERP_API octave_hdf5_err
+hdf5_h5g_iterate (octave_hdf5_id loc_id, const char* name, int *idx,
+                  void *operator_data);
+
 extern OCTINTERP_API bool
 add_hdf5_data (octave_hdf5_id loc_id, const octave_value& tc,
                const std::string& name, const std::string& doc,
@@ -153,6 +157,7 @@
 extern OCTINTERP_API octave_hdf5_err
 hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name);
 
+
 extern OCTINTERP_API octave_hdf5_err
 hdf5_add_scalar_attr (octave_hdf5_id loc_id, octave_hdf5_id type_id,
                       const char *attr_name, void *buf);
--- a/libinterp/corefcn/oct-hdf5-types.h	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/corefcn/oct-hdf5-types.h	Sat Jul 02 10:19:44 2016 -0400
@@ -32,7 +32,7 @@
 
 // Available for C and C++.
 
-typedef int octave_hdf5_id;
+typedef int64_t octave_hdf5_id;
 typedef int octave_hdf5_err;
 
 #if defined (__cplusplus)
--- a/libinterp/octave-value/ov-cell.cc	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/octave-value/ov-cell.cc	Sat Jul 02 10:19:44 2016 -0400
@@ -1148,8 +1148,7 @@
       if (current_item >= static_cast<int> (num_obj))
         retval2 = -1;
       else
-        retval2 = H5Giterate (loc_id, name, &current_item,
-                              hdf5_read_next_data, &dsub);
+        retval2 = hdf5_h5g_iterate (loc_id, name, &current_item,&dsub);
 
       if (retval2 <= 0)
         break;
--- a/libinterp/octave-value/ov-class.cc	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/octave-value/ov-class.cc	Sat Jul 02 10:19:44 2016 -0400
@@ -1589,8 +1589,8 @@
   H5Gclose (subgroup_hid);
 
   while (current_item < static_cast<int> (num_obj)
-         && (retval2 = H5Giterate (group_hid, name, &current_item,
-                                   hdf5_read_next_data, &dsub)) > 0)
+         && (retval2 = hdf5_h5g_iterate (group_hid, name, &current_item,
+                                         &dsub)) > 0)
     {
       octave_value t2 = dsub.tc;
 
--- a/libinterp/octave-value/ov-fcn-handle.cc	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Sat Jul 02 10:19:44 2016 -0400
@@ -1147,8 +1147,8 @@
           int current_item = 0;
           for (octave_idx_type i = 0; i < len; i++)
             {
-              if (H5Giterate (group_hid, "symbol table", &current_item,
-                              hdf5_read_next_data, &dsub) <= 0)
+              if (hdf5_h5g_iterate (group_hid, "symbol table", &current_item,
+                                    &dsub) <= 0)
                 error ("load: failed to load anonymous function handle");
 
               symbol_table::assign (dsub.name, dsub.tc, local_scope);
--- a/libinterp/octave-value/ov-struct.cc	Fri Jul 01 14:49:35 2016 -0400
+++ b/libinterp/octave-value/ov-struct.cc	Sat Jul 02 10:19:44 2016 -0400
@@ -944,8 +944,8 @@
   // Why is that happening?
 
   while (current_item < static_cast<int> (num_obj)
-         && (retval2 = H5Giterate (loc_id, name, &current_item,
-                                   hdf5_read_next_data, &dsub)) > 0)
+         && (retval2 = hdf5_h5g_iterate (loc_id, name, &current_item,
+                                         &dsub)) > 0)
     {
       octave_value t2 = dsub.tc;
 
@@ -1549,8 +1549,8 @@
   // Why is that happening?
 
   while (current_item < static_cast<int> (num_obj)
-         && (retval2 = H5Giterate (loc_id, name, &current_item,
-                                   hdf5_read_next_data, &dsub)) > 0)
+         && (retval2 = hdf5_h5g_iterate (loc_id, name, &current_item,
+                                         &dsub)) > 0)
     {
       octave_value t2 = dsub.tc;