changeset 20292:d54aa96abadf stable

Fix load/save of integers with -hdf5 (bug #45225) * oct-hdf5.h: Do not #define HDF5_SAVE_TYPE. * ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc: Restore correct definition of HDF5_SAVE_TYPE for each distinct integer type. * io.tst: Add %!test for load/save of integers with -hdf5.
author Mike Miller <mtmiller@octave.org>
date Wed, 10 Jun 2015 09:26:14 -0400
parents 7ab81a9fa065
children 36b32c07c045
files libinterp/corefcn/oct-hdf5.h libinterp/octave-value/ov-int16.cc libinterp/octave-value/ov-int32.cc libinterp/octave-value/ov-int64.cc libinterp/octave-value/ov-int8.cc libinterp/octave-value/ov-uint16.cc libinterp/octave-value/ov-uint32.cc libinterp/octave-value/ov-uint64.cc libinterp/octave-value/ov-uint8.cc test/io.tst
diffstat 10 files changed, 61 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-hdf5.h	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/corefcn/oct-hdf5.h	Wed Jun 10 09:26:14 2015 -0400
@@ -27,8 +27,6 @@
 
 #include <hdf5.h>
 
-#define HDF5_SAVE_TYPE H5T_NATIVE_UINT8
-
 #endif
 
 #endif
--- a/libinterp/octave-value/ov-int16.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-int16.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_INT16
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-int16.h"
--- a/libinterp/octave-value/ov-int32.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-int32.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_INT32
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-int32.h"
--- a/libinterp/octave-value/ov-int64.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-int64.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_INT64
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-int64.h"
--- a/libinterp/octave-value/ov-int8.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-int8.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_INT8
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-int8.h"
--- a/libinterp/octave-value/ov-uint16.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-uint16.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_UINT16
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-uint16.h"
--- a/libinterp/octave-value/ov-uint32.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-uint32.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_UINT32
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-uint32.h"
--- a/libinterp/octave-value/ov-uint64.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-uint64.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_UINT64
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-uint64.h"
--- a/libinterp/octave-value/ov-uint8.cc	Wed Jun 10 08:42:11 2015 -0400
+++ b/libinterp/octave-value/ov-uint8.cc	Wed Jun 10 09:26:14 2015 -0400
@@ -40,6 +40,10 @@
 #include "ops.h"
 #include "ov-base.h"
 
+#if defined (HAVE_HDF5)
+#define HDF5_SAVE_TYPE H5T_NATIVE_UINT8
+#endif
+
 #include "ov-base-int.h"
 #include "ov-base-int.cc"
 #include "ov-uint8.h"
--- a/test/io.tst	Wed Jun 10 08:42:11 2015 -0400
+++ b/test/io.tst	Wed Jun 10 09:26:14 2015 -0400
@@ -191,6 +191,35 @@
 %!
 %! assert (save_status && load_status);
 
+%!testif HAVE_HDF5
+%!
+%! s8  =   int8 (fix ((2^8  - 1) * (rand (2, 2) - 0.5)));
+%! u8  =  uint8 (fix ((2^8  - 1) * (rand (2, 2) - 0.5)));
+%! s16 =  int16 (fix ((2^16 - 1) * (rand (2, 2) - 0.5)));
+%! u16 = uint16 (fix ((2^16 - 1) * (rand (2, 2) - 0.5)));
+%! s32 =  int32 (fix ((2^32 - 1) * (rand (2, 2) - 0.5)));
+%! u32 = uint32 (fix ((2^32 - 1) * (rand (2, 2) - 0.5)));
+%! s64 =  int64 (fix ((2^64 - 1) * (rand (2, 2) - 0.5)));
+%! u64 = uint64 (fix ((2^64 - 1) * (rand (2, 2) - 0.5)));
+%! s8t = s8; u8t = u8; s16t = s16; u16t = u16; s32t = s32; u32t = u32;
+%! s64t = s64; u64t = u64;
+%! h5file = tempname ();
+%! unwind_protect
+%!   eval (sprintf ("save -hdf5 %s %s", h5file, "s8 u8 s16 u16 s32 u32 s64 u64"));
+%!   clear s8 u8 s16 u16 s32 u32 s64 u64;
+%!   load (h5file);
+%!   assert (s8, s8t);
+%!   assert (u8, u8t);
+%!   assert (s16, s16t);
+%!   assert (u16, u16t);
+%!   assert (s32, s32t);
+%!   assert (u32, u32t);
+%!   assert (s64, s64t);
+%!   assert (u64, u64t);
+%! unwind_protect_cleanup
+%!   unlink (h5file);
+%! end_unwind_protect
+
 %!test
 %!
 %! STR.scalar_fld = 1;