# HG changeset patch # User Stefan Miereis # Date 1467469184 14400 # Sat Jul 02 10:19:44 2016 -0400 # Node ID b7cf4a8e2682d2518fe1e453ebef0663a676efff # Parent 0f2389d8fe0cb9bbb9661967176cf4394c02476c 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. diff --git a/libinterp/corefcn/ls-hdf5.cc b/libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc +++ b/libinterp/corefcn/ls-hdf5.cc @@ -35,6 +35,7 @@ along with Octave; see the file COPYING. #include #include #include +#include #include #include @@ -72,6 +73,19 @@ along with Octave; see the file COPYING. #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::max ()) + error ("%s: internal error: ID too large for hid_t", who); + + return static_cast (id); +} + +#endif + hdf5_fstreambase::hdf5_fstreambase (const char *name, int mode, int /* prot */) : file_id (-1), current_item (-1) { @@ -327,6 +341,8 @@ hdf5_make_complex_type (octave_hdf5_id n #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 @@ hdf5_make_complex_type (octave_hdf5_id n // -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 (dv); hid_t type_id = -1; hid_t type_class_id = -1; @@ -670,12 +684,40 @@ done: } 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 @@ read_hdf5_data (std::istream& is, const if (hs.current_item < static_cast (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) { diff --git a/libinterp/corefcn/ls-hdf5.h b/libinterp/corefcn/ls-hdf5.h --- a/libinterp/corefcn/ls-hdf5.h +++ b/libinterp/corefcn/ls-hdf5.h @@ -157,4 +157,7 @@ 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); +extern OCTINTERP_API octave_hdf5_err +hdf5_h5g_iterate (octave_hdf5_id loc_id, const char* name, int *idx, + void *operator_data); #endif diff --git a/libinterp/corefcn/oct-hdf5-types.h b/libinterp/corefcn/oct-hdf5-types.h --- a/libinterp/corefcn/oct-hdf5-types.h +++ b/libinterp/corefcn/oct-hdf5-types.h @@ -32,7 +32,7 @@ extern bool check_hdf5_types (bool warn // Available for C and C++. -typedef int octave_hdf5_id; +typedef int64_t octave_hdf5_id; typedef int octave_hdf5_err; #if defined (__cplusplus) diff --git a/libinterp/octave-value/ov-cell.cc b/libinterp/octave-value/ov-cell.cc --- a/libinterp/octave-value/ov-cell.cc +++ b/libinterp/octave-value/ov-cell.cc @@ -1148,8 +1148,7 @@ octave_cell::load_hdf5 (octave_hdf5_id l if (current_item >= static_cast (num_obj)) retval2 = -1; else - retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub); + retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item,&dsub); if (retval2 <= 0) break; diff --git a/libinterp/octave-value/ov-class.cc b/libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -1589,8 +1589,8 @@ octave_class::load_hdf5 (octave_hdf5_id H5Gclose (subgroup_hid); while (current_item < static_cast (num_obj) - && (retval2 = H5Giterate (group_hid, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = hdf5_h5g_iterate (group_hid, name, ¤t_item, + &dsub)) > 0) { octave_value t2 = dsub.tc; diff --git a/libinterp/octave-value/ov-fcn-handle.cc b/libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc +++ b/libinterp/octave-value/ov-fcn-handle.cc @@ -1147,8 +1147,8 @@ octave_fcn_handle::load_hdf5 (octave_hdf int current_item = 0; for (octave_idx_type i = 0; i < len; i++) { - if (H5Giterate (group_hid, "symbol table", ¤t_item, - hdf5_read_next_data, &dsub) <= 0) + if (hdf5_h5g_iterate (group_hid, "symbol table", ¤t_item, + &dsub) <= 0) error ("load: failed to load anonymous function handle"); symbol_table::assign (dsub.name, dsub.tc, local_scope); diff --git a/libinterp/octave-value/ov-struct.cc b/libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc +++ b/libinterp/octave-value/ov-struct.cc @@ -944,8 +944,8 @@ octave_struct::load_hdf5 (octave_hdf5_id // Why is that happening? while (current_item < static_cast (num_obj) - && (retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item, + &dsub)) > 0) { octave_value t2 = dsub.tc; @@ -1549,8 +1549,8 @@ octave_scalar_struct::load_hdf5 (octave_ // Why is that happening? while (current_item < static_cast (num_obj) - && (retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item, + &dsub)) > 0) { octave_value t2 = dsub.tc;