From 822caec9071019d02da869fe0c9b06f24d88c2d5 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 25 Jan 2019 11:36:36 -0600 Subject: Fix CMake on Windows --- config/cmake_ext_mod/HDFMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmake_ext_mod/HDFMacros.cmake b/config/cmake_ext_mod/HDFMacros.cmake index 27d730b..b3d97ce 100644 --- a/config/cmake_ext_mod/HDFMacros.cmake +++ b/config/cmake_ext_mod/HDFMacros.cmake @@ -14,7 +14,7 @@ macro (SET_HDF_BUILD_TYPE) get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(_isMultiConfig) - set(HDF_CFG_NAME ${CTEST_CONFIGURATION_TYPE}) + set(HDF_CFG_NAME \${CTEST_CONFIGURATION_TYPE}) set(HDF_BUILD_TYPE ${CMAKE_CFG_INTDIR}) set(HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME}) else() -- cgit v0.12 From ad906dc708fc803e8c5f17963fafa63591d3cc8d Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 25 Jan 2019 15:21:11 -0600 Subject: Invalid position of declaration fixed. --- tools/src/h5repack/h5repack_filters.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/src/h5repack/h5repack_filters.c b/tools/src/h5repack/h5repack_filters.c index 123263c..3d9472a 100644 --- a/tools/src/h5repack/h5repack_filters.c +++ b/tools/src/h5repack/h5repack_filters.c @@ -338,9 +338,10 @@ int apply_filters(const char* name, /* object name from traverse list */ sm_nbytes = msize; for (i = rank; i > 0; --i) { + hsize_t size = 0; if(sm_nbytes == 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "number of bytes per stripmine must be > 0"); - hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; + size = H5TOOLS_BUFSIZE / sm_nbytes; if (size == 0) /* datum size > H5TOOLS_BUFSIZE */ size = 1; sm_size[i - 1] = MIN(dims[i - 1], size); -- cgit v0.12 From f522479035c893c9123dbe6b89ae4c71c3d2615e Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sat, 26 Jan 2019 11:58:52 -0600 Subject: Added test file for CMake --- test/CMakeTests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeTests.cmake b/test/CMakeTests.cmake index c0d4813..087461f 100644 --- a/test/CMakeTests.cmake +++ b/test/CMakeTests.cmake @@ -171,6 +171,7 @@ set (HDF5_REFERENCE_TEST_FILES le_data.h5 le_extlink1.h5 le_extlink2.h5 + memleak_H5O_dtype_decode_helper_H5Odtype.h5 mergemsg.h5 multi_file_v16-r.h5 multi_file_v16-s.h5 -- cgit v0.12 From b91cb20c697ae58ca791ae3e1e191d59dc531039 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Sat, 26 Jan 2019 16:44:09 -0600 Subject: Add batch files with batch parameters specific to cori and ray. Release.txt entry for skipping long double dt_arith tests on ppc64. --- bin/batch/cori_ctestP.sl.in.cmake | 17 +++++++++++++++++ bin/batch/cori_ctestS.sl.in.cmake | 16 ++++++++++++++++ bin/batch/ctestP.sl.in.cmake | 4 ++-- bin/batch/ctestS.sl.in.cmake | 3 ++- bin/batch/knl_ctestP.sl.in.cmake | 2 +- bin/batch/knl_ctestS.sl.in.cmake | 2 +- bin/batch/ray_ctestP.lsf.in.cmake | 20 ++++++++++++++++++++ bin/batch/ray_ctestS.lsf.in.cmake | 18 ++++++++++++++++++ release_docs/RELEASE.txt | 9 +++++++++ 9 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 bin/batch/cori_ctestP.sl.in.cmake create mode 100644 bin/batch/cori_ctestS.sl.in.cmake create mode 100644 bin/batch/ray_ctestP.lsf.in.cmake create mode 100644 bin/batch/ray_ctestS.lsf.in.cmake diff --git a/bin/batch/cori_ctestP.sl.in.cmake b/bin/batch/cori_ctestP.sl.in.cmake new file mode 100644 index 0000000..90dd52a --- /dev/null +++ b/bin/batch/cori_ctestP.sl.in.cmake @@ -0,0 +1,17 @@ +#!/bin/bash + +#SBATCH -C knl,quad,cache +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestP + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" + +echo "Run $CMD. Test output will be in build/ctestP.out" +$CMD >& ctestP.out +echo "Done running $CMD" + diff --git a/bin/batch/cori_ctestS.sl.in.cmake b/bin/batch/cori_ctestS.sl.in.cmake new file mode 100644 index 0000000..0ec7bf7 --- /dev/null +++ b/bin/batch/cori_ctestS.sl.in.cmake @@ -0,0 +1,16 @@ +#!/bin/bash + +#SBATCH -C knl,quad, cache +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestS + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" + +echo "Run $CMD. Test output will be in build/ctestS.out" +$CMD >& ctestS.out +echo "Done running $CMD" diff --git a/bin/batch/ctestP.sl.in.cmake b/bin/batch/ctestP.sl.in.cmake index 230a642..9fed14d 100644 --- a/bin/batch/ctestP.sl.in.cmake +++ b/bin/batch/ctestP.sl.in.cmake @@ -5,10 +5,10 @@ #SBATCH --mail-type=BEGIN,END,FAIL ##SBATCH --mail-user=@sandia.gov #SBATCH --export=ALL -#SBATCH --job-name=h5_ctestS +#SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM -E t_cache_image -C Release -T test" +CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/ctestS.sl.in.cmake b/bin/batch/ctestS.sl.in.cmake index 9802e13..a5d7d76 100644 --- a/bin/batch/ctestS.sl.in.cmake +++ b/bin/batch/ctestS.sl.in.cmake @@ -1,5 +1,6 @@ #!/bin/bash +#SBATCH -p knl -C quad,cache #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL @@ -8,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM -C Release -j 32 -T test" +CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/knl_ctestP.sl.in.cmake b/bin/batch/knl_ctestP.sl.in.cmake index 687804b..8d786da 100644 --- a/bin/batch/knl_ctestP.sl.in.cmake +++ b/bin/batch/knl_ctestP.sl.in.cmake @@ -10,7 +10,7 @@ cd @HDF5_BINARY_DIR@ #run parallel tests except t_cache_image test -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM -E t_cache_image -C Release -T test" +CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/knl_ctestS.sl.in.cmake b/bin/batch/knl_ctestS.sl.in.cmake index de1335c..b983228 100644 --- a/bin/batch/knl_ctestS.sl.in.cmake +++ b/bin/batch/knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM -C Release -j 32 -T test" +CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ray_ctestP.lsf.in.cmake b/bin/batch/ray_ctestP.lsf.in.cmake new file mode 100644 index 0000000..6b5316a --- /dev/null +++ b/bin/batch/ray_ctestP.lsf.in.cmake @@ -0,0 +1,20 @@ +#!/bin/tcsh +### LSF syntax +#BSUB -n 6 #number of nodes +#BSUB -R "span[ptile=6]" +#BSUB -W 30 #walltime in minutes +#BSUB -G guests #account +#BSUB -e ctestPerrors.txt #stderr +#BSUB -o ctestPoutput.txt #stdout +#BSUB -J hdf5_ctestP #job +##BSUB -q pbatch #queue to use +#BSUB -q pdebug + +##date; hostname +##echo -n 'JobID is '; echo $LSB_JOBID + +cd @HDF5_BINARY_DIR@ +echo "Run parallel test command. Test output will be in build/ctestP.out" +ctest . -R 'TEST_PAR|PH5DIFF|PERFORM|ph5example' -E t_cache_image -C Release -T test >& ctestP.out + +echo "Done running ctest parallel command." diff --git a/bin/batch/ray_ctestS.lsf.in.cmake b/bin/batch/ray_ctestS.lsf.in.cmake new file mode 100644 index 0000000..cbc7130 --- /dev/null +++ b/bin/batch/ray_ctestS.lsf.in.cmake @@ -0,0 +1,18 @@ +#!/bin/tcsh +### LSF syntax +#BSUB -n 1 #number of nodes +#BSUB -W 29 #walltime in minutes +#BSUB -G guests #account +#BSUB -e ctestSerrors.txt #stderr +#BSUB -o ctestSoutput.txt #stdout +#BSUB -J hdf5_ctestS #job +##BSUB -q pbatch #queue to use +#BSUB -q pdebug + +cd @HDF5_BINARY_DIR@ +echo "Run command. Test output will be in build/ctestS.out" +ctest . -E 'TEST_PAR|H5DIFF|PERFORM|ph5example' -C Release -j 32 -T test >& ctestS.out + +##$CMD >& ctestS.out +echo "Done running command." + diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 2dfcfc1..2af832b 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -637,6 +637,15 @@ Bug Fixes since HDF5-1.10.2 release Testing ------- + - The dt_arith test failed on IBM Power8 and Power9 machines when testing + conversions from or to long double types, especially when special values + such as infinity or NAN were involved. In some cases the results differed + by extremely small amounts from those on other machines, while some other + tests resulted in segmentation faults. These conversion tests with long + double types have been disabled for ppc64 machines until the problems are + better understood and can be properly addressed. + + (SRL - 2019/01/07, TRILAB-98) Supported Platforms =================== -- cgit v0.12 From f26ee27b1fd85d192b37d9e45fb6d20f1b7e23db Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Sun, 27 Jan 2019 16:55:39 -0600 Subject: Revert build name setting --- config/cmake_ext_mod/HDFMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmake_ext_mod/HDFMacros.cmake b/config/cmake_ext_mod/HDFMacros.cmake index b3d97ce..2f4ce52 100644 --- a/config/cmake_ext_mod/HDFMacros.cmake +++ b/config/cmake_ext_mod/HDFMacros.cmake @@ -14,7 +14,7 @@ macro (SET_HDF_BUILD_TYPE) get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(_isMultiConfig) - set(HDF_CFG_NAME \${CTEST_CONFIGURATION_TYPE}) + set(HDF_CFG_NAME ${CMAKE_BUILD_TYPE}) set(HDF_BUILD_TYPE ${CMAKE_CFG_INTDIR}) set(HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME}) else() -- cgit v0.12 From cee36ca40d91ced2a417156feac3fd7407f0b82d Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Sun, 27 Jan 2019 17:55:44 -0600 Subject: Remove knl configuration from ctestS.sl.in.cmake. Add sandia batch files with account info. --- bin/batch/ctestS.sl.in.cmake | 1 - bin/batch/sandia_ctestP.sl.in.cmake | 17 +++++++++++++++++ bin/batch/sandia_ctestS.sl.in.cmake | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 bin/batch/sandia_ctestP.sl.in.cmake create mode 100644 bin/batch/sandia_ctestS.sl.in.cmake diff --git a/bin/batch/ctestS.sl.in.cmake b/bin/batch/ctestS.sl.in.cmake index a5d7d76..f772be9 100644 --- a/bin/batch/ctestS.sl.in.cmake +++ b/bin/batch/ctestS.sl.in.cmake @@ -1,6 +1,5 @@ #!/bin/bash -#SBATCH -p knl -C quad,cache #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL diff --git a/bin/batch/sandia_ctestP.sl.in.cmake b/bin/batch/sandia_ctestP.sl.in.cmake new file mode 100644 index 0000000..55d47eb --- /dev/null +++ b/bin/batch/sandia_ctestP.sl.in.cmake @@ -0,0 +1,17 @@ +#!/bin/bash + +##SBATCH --account=fy140085 # WC ID +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestP + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" + +echo "Run $CMD. Test output will be in build/ctestP.out" +$CMD >& ctestP.out +echo "Done running $CMD" + diff --git a/bin/batch/sandia_ctestS.sl.in.cmake b/bin/batch/sandia_ctestS.sl.in.cmake new file mode 100644 index 0000000..3d491b7 --- /dev/null +++ b/bin/batch/sandia_ctestS.sl.in.cmake @@ -0,0 +1,16 @@ +#!/bin/bash + +##SBATCH --account=fy140085 # WC ID +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestS + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" + +echo "Run $CMD. Test output will be in build/ctestS.out" +$CMD >& ctestS.out +echo "Done running $CMD" -- cgit v0.12 From 64114e331a90cec440f1d1f0943a0792c8802ca9 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Mon, 28 Jan 2019 12:43:35 -0600 Subject: Add HDF5options.cmake files for serial and parallel tests on HPC machines (where tests are to be run as batch jobs. Add README_HPC file with instructions for setting up configuration to use batch scripts for running tests on HPC machines and some pointers for cross compiling. --- config/cmake/scripts/HPC/par-HDF5options.cmake | 117 +++++++++++++++++++++++++ config/cmake/scripts/HPC/ser-HDF5options.cmake | 117 +++++++++++++++++++++++++ release_docs/README_HPC | 79 +++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 config/cmake/scripts/HPC/par-HDF5options.cmake create mode 100644 config/cmake/scripts/HPC/ser-HDF5options.cmake create mode 100644 release_docs/README_HPC diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake new file mode 100644 index 0000000..0527995 --- /dev/null +++ b/config/cmake/scripts/HPC/par-HDF5options.cmake @@ -0,0 +1,117 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +############################################################################################# +#### Change default configuration of options in config/cmake/cacheinit.cmake file ### +#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### +############################################################################################# + +### uncomment/comment and change the following lines for other configuration options + +############################################################################################# +#### maximum parallel processor count for build and test #### +set (MAX_PROC_COUNT 8) + +############################################################################################# +#### alternate toolsets #### +#set (CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler 17.0") + +############################################################################################# +#### Only build static libraries #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF") +#### Add PICC option on linux/mac #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_ANSI_CFLAGS:STRING=-fPIC") + +############################################################################################# +#### fortran enabled #### +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") + ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=ON") +#### fortran disabled #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") + ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=OFF") + +############################################################################################# +#### java enabled #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON") +#### java disabled #### +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") + +############################################################################################# +### change install prefix (default use INSTALLDIR value) +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALLDIR}") + +############################################################################################# +#### ext libraries #### + +### ext libs from tgz +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=${CTEST_SCRIPT_DIRECTORY}") +### ext libs from git +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=GIT") +### ext libs on system +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=NO") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DZLIB_LIBRARY:FILEPATH=some_location/lib/zlib.lib -DZLIB_INCLUDE_DIR:PATH=some_location/include") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSZIP_LIBRARY:FILEPATH=some_location/lib/szlib.lib -DSZIP_INCLUDE_DIR:PATH=some_location/include") + +### disable using ext zlib +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF") +### disable using ext szip +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") + +#### package examples #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.10.9-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") + +############################################################################################# +### enable parallel builds + +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") + +############################################################################################# +### enable thread-safety builds + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=ON") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_HL_LIB:BOOL=OFF") + +############################################################################################# +### disable test program builds + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_TESTING:BOOL=OFF") + +############################################################################################# +### disable packaging + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_NO_PACKAGES:BOOL=ON") +### Create install package with external libraries (szip, zlib) +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") + +############################################################################################# +### use a toolchain file + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/craype.cmake") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") + +#options to run test scripts in batch commands +set (LOCAL_BATCH_TEST ON) +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_SCRIPT_NAME "knl_ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "knl_ctestP.sl") +set(MPIEXEC_EXECUTABLE "srun") + +############################################################################################# diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake new file mode 100644 index 0000000..71266ec --- /dev/null +++ b/config/cmake/scripts/HPC/ser-HDF5options.cmake @@ -0,0 +1,117 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +############################################################################################# +#### Change default configuration of options in config/cmake/cacheinit.cmake file ### +#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### +############################################################################################# + +### uncomment/comment and change the following lines for other configuration options + +############################################################################################# +#### maximum parallel processor count for build and test #### +#set (MAX_PROC_COUNT 8) + +############################################################################################# +#### alternate toolsets #### +#set (CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler 17.0") + +############################################################################################# +#### Only build static libraries #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF") +#### Add PICC option on linux/mac #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_ANSI_CFLAGS:STRING=-fPIC") + +############################################################################################# +#### fortran enabled #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") + ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=ON") +#### fortran disabled #### +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") + ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=OFF") + +############################################################################################# +#### java enabled #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON") +#### java disabled #### +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") + +############################################################################################# +### change install prefix (default use INSTALLDIR value) +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALLDIR}") + +############################################################################################# +#### ext libraries #### + +### ext libs from tgz +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=${CTEST_SCRIPT_DIRECTORY}") +### ext libs from git +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=GIT") +### ext libs on system +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=NO") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DZLIB_LIBRARY:FILEPATH=some_location/lib/zlib.lib -DZLIB_INCLUDE_DIR:PATH=some_location/include") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSZIP_LIBRARY:FILEPATH=some_location/lib/szlib.lib -DSZIP_INCLUDE_DIR:PATH=some_location/include") + +### disable using ext zlib +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF") +### disable using ext szip +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") + +#### package examples #### +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.10.9-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") + +############################################################################################# +### enable parallel builds + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") + +############################################################################################# +### enable thread-safety builds + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=ON") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_HL_LIB:BOOL=OFF") + +############################################################################################# +### disable test program builds + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_TESTING:BOOL=OFF") + +############################################################################################# +### disable packaging + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_NO_PACKAGES:BOOL=ON") +### Create install package with external libraries (szip, zlib) +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") + +############################################################################################# +### use a toolchain file + +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/crayle.cmake") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") + +#options to run test scripts in batch commands +set (LOCAL_BATCH_TEST ON) +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_SCRIPT_NAME "knl_ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "knl_ctestP.sl") +set(MPIEXEC_EXECUTABLE "srun") + +############################################################################################# diff --git a/release_docs/README_HPC b/release_docs/README_HPC new file mode 100644 index 0000000..bdeab67 --- /dev/null +++ b/release_docs/README_HPC @@ -0,0 +1,79 @@ +HDF5 version 1.11.4 currently under development + +HDF5 source tar files with the HPC prefix are intended for use on clusters where +configuration and build steps will be done on a login node and executable and +lib files that are built will be run on compute nodes. + +Note these differences from the regular CMake tar and zip files: + - Test programs produced by this tar file will be run using batch scripts. + - Serial and parallel HDF5options.cmake files, using parallel options by default. + +Note also that options are now available in HDF5 source to facilitate use of +toolchain files for using cross compilers available on login nodes to compile +HDF5 for compute nodes. + +Instructions to configure build and test HDF5 using CMake: + +1. The cmake version must be 3.10 or later (cmake --version). +2. Load or switch modules and set CC, FC, CXX for compilers desired. +3. run build-unix.sh to configure, build, test and package HDF5 with CMake. + +Contents: + +build-unix.sh Simple script for running CMake to configure, build, + test, and package HDF5. +CTestScript.cmake CMake script to configure, build, test and package + HDF5. +hdf5- HDF5 source for . +HDF5config.cmake CMake script to configure, build, test and package + HDF5. +HDF5Examples Source for HDF5 Examples. +HDF5options.cmake symlink to parallel or serial HDF5options.cmake files. + Default is parallel file, which builds and tests both + serial and parallel C and Fortran wrappers. + To build serial only, C Fortran and C++ wrappers, delete + The HDF5options.cmake link and run + 'ln -s ser-HDF5options.cmake HDF5options.cmake' to switch. +par-HDF5options.cmake Options file for HDF5 serial and parallel build and test. +ser-HDF5options.cmake Options file for HDF5 serial only build and test. +SZip.tar.gz Source for building SZip. +ZLib.tar.gz Source for buildng Zlib. + + +To cross compile with this HPC-CMake tar.gz HDF5 source file: +On Cray XC40 haswell login node for knl compute nodes using CMake and Cray modules: + 1. Uncomment line in HDF5options.txt to use a toolchain file - line 106 for + config/toolchain/crayle.cmake. + 2. Uncomment lines 110, 111, and 115 - 122 of HDF5options.cmake. + Line 110 allows configuring to complete on the haswell node. + Line 111 switches the compiler to build files for knl nodes. + Lines 115 - 122 set up test files to use sbatch to run build tests + in batch jobs on a knl compute node with 6 processes. + 3. Compiler module may be the default PrgEnv-intel/6.0.4 to use + intel/18.0.2 or other intel, PrgEnv-cray/6.0.4 to use cce/8.7.4, + or PrgEnv-gnu/6.0.4 for GCC compilers. PrgEnv-pgi/6.0.4 is also + available but has not been tested with this tar file. + 4. These CMake options are set in config/toolchain/crayle.cmake: + set(CMAKE_SYSTEM_NAME Linux) + set(CMAKE_COMPILER_VENDOR "CrayLinuxEnvironment") + set(CMAKE_C_COMPILER cc) + set(CMAKE_CXX_COMPILER c++) + set(CMAKE_Fortran_COMPILER ftn) + set(CMAKE_CROSSCOMPILING_EMULATOR "") + + 5. Settings for two other cross-compiling options are also in the + config/toolchain files which do not seem to be necessary with the + Cray PrgEnv-* modules + a. HDF5_USE_PREGEN. This option, along with the HDF5_USE_PREGEN_DIR + CMake variable would allow the use of an appropriate H5Tinit.c + file with type information generated on a compute node to be used + when cross compiling for those compute nodes. The use of the + variables in lines 110 and 111 of HDF5options.cmake file seem to + preclude needing this option with the available Cray modules and + CMake options. + b. HDF5_BATCH_H5DETECT and associated CMake variables. This option + when properly configured will run H5detect in a batch job on a + compute node at the beginning of the CMake build process. It + was also found to be unnecessary with the available Cray modules + and CMake options. +- -- cgit v0.12 From 252beb50b69d68ef087f00aded1994a3d9b235f0 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Mon, 28 Jan 2019 12:52:14 -0600 Subject: Account info can be submitted as an argument to run the batch scripts. Special versions for sandia are not needed. --- bin/batch/sandia_ctestP.sl.in.cmake | 17 ----------------- bin/batch/sandia_ctestS.sl.in.cmake | 16 ---------------- 2 files changed, 33 deletions(-) delete mode 100644 bin/batch/sandia_ctestP.sl.in.cmake delete mode 100644 bin/batch/sandia_ctestS.sl.in.cmake diff --git a/bin/batch/sandia_ctestP.sl.in.cmake b/bin/batch/sandia_ctestP.sl.in.cmake deleted file mode 100644 index 55d47eb..0000000 --- a/bin/batch/sandia_ctestP.sl.in.cmake +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -##SBATCH --account=fy140085 # WC ID -#SBATCH --nodes=1 -#SBATCH -t 00:30:00 -#SBATCH --mail-type=BEGIN,END,FAIL -##SBATCH --mail-user=@sandia.gov -#SBATCH --export=ALL -#SBATCH --job-name=h5_ctestP - -cd @HDF5_BINARY_DIR@ -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" - -echo "Run $CMD. Test output will be in build/ctestP.out" -$CMD >& ctestP.out -echo "Done running $CMD" - diff --git a/bin/batch/sandia_ctestS.sl.in.cmake b/bin/batch/sandia_ctestS.sl.in.cmake deleted file mode 100644 index 3d491b7..0000000 --- a/bin/batch/sandia_ctestS.sl.in.cmake +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -##SBATCH --account=fy140085 # WC ID -#SBATCH --nodes=1 -#SBATCH -t 00:30:00 -#SBATCH --mail-type=BEGIN,END,FAIL -##SBATCH --mail-user=@sandia.gov -#SBATCH --export=ALL -#SBATCH --job-name=h5_ctestS - -cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" - -echo "Run $CMD. Test output will be in build/ctestS.out" -$CMD >& ctestS.out -echo "Done running $CMD" -- cgit v0.12 From 773c35a664d7483c55ea543b5203fdd6826f2de0 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 29 Jan 2019 10:22:18 -0600 Subject: Add RELEASE.txt note for unknown message fix (pull request 1448) --- release_docs/RELEASE.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 2dfcfc1..172b55d 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -264,6 +264,12 @@ Bug Fixes since HDF5-1.10.3 release Library ------- + - Fixed a potential invalid memory access and failure that could occur when + decoding an unknown object header message (from a future version of the + library). + + (NAF - 2019/01/07) + - Deleting attributes in dense storage The library aborts with "infinite loop closing library" after -- cgit v0.12 From f833001e3948c1088e09697c1b1820313e0d65e4 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 30 Jan 2019 17:32:40 -0800 Subject: Updated sec2, log, and core VFDs to use pread/pwrite when available (can be controlled via a configure/CMake option) --- CMakeLists.txt | 9 ++++++ config/cmake/H5pubconf.h.in | 3 ++ config/cmake_ext_mod/ConfigureChecks.cmake | 8 ++++-- configure.ac | 46 ++++++++++++++++++++++++++++-- src/H5FDcore.c | 28 ++++++++++++++---- src/H5FDlog.c | 30 +++++++++++++++---- src/H5FDsec2.c | 32 ++++++++++++++++----- src/H5private.h | 6 ++++ 8 files changed, 139 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a16cb08..cb9839b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -482,6 +482,15 @@ if (HDF5_MEMORY_ALLOC_SANITY_CHECK) endif () #----------------------------------------------------------------------------- +# Option to enable/disable using pread/pwrite for VFDs +#----------------------------------------------------------------------------- +option (HDF5_ENABLE_PREADWRITE "Use pread/pwrite in sec2/log/core VFDs in place of read/write (when available)" ON) +mark_as_advanced (HDF5_ENABLE_PREADWRITE) +if (HDF5_ENABLE_PREADWRITE AND ${HDF_PREFIX}_HAVE_PREAD AND ${HDF_PREFIX}_HAVE_PWRITE) + set (H5_HAVE_PREADWRITE 1) +endif () + +#----------------------------------------------------------------------------- # Option to use deprecated public API symbols #----------------------------------------------------------------------------- option (HDF5_ENABLE_DEPRECATED_SYMBOLS "Enable deprecated public API symbols" ON) diff --git a/config/cmake/H5pubconf.h.in b/config/cmake/H5pubconf.h.in index a740df2..273adb5 100644 --- a/config/cmake/H5pubconf.h.in +++ b/config/cmake/H5pubconf.h.in @@ -267,6 +267,9 @@ /* Define if we have parallel support */ #cmakedefine H5_HAVE_PARALLEL @H5_HAVE_PARALLEL@ +/* Define if both pread and pwrite exist. */ +#cmakedefine H5_HAVE_PREADWRITE @H5_HAVE_PREADWRITE@ + /* Define to 1 if you have the header file. */ #cmakedefine H5_HAVE_PTHREAD_H @H5_HAVE_PTHREAD_H@ diff --git a/config/cmake_ext_mod/ConfigureChecks.cmake b/config/cmake_ext_mod/ConfigureChecks.cmake index c24c1f8..986280f 100644 --- a/config/cmake_ext_mod/ConfigureChecks.cmake +++ b/config/cmake_ext_mod/ConfigureChecks.cmake @@ -274,10 +274,12 @@ if (NOT WINDOWS) # functionality so clock_gettime and CLOCK_MONOTONIC are defined # correctly. This was later updated to 200112L so that # posix_memalign() is visible for the direct VFD code on Linux - # systems. + # systems. Even later, this was changed to 200809L to support + # pread/pwrite in VFDs. + # # POSIX feature information can be found in the gcc manual at: # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html - set (HDF_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=200112L) + set (HDF_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=200809L) # Need to add this so that O_DIRECT is visible for the direct # VFD on Linux systems. @@ -506,6 +508,8 @@ CHECK_FUNCTION_EXISTS (lround ${HDF_PREFIX}_HAVE_LROUND) CHECK_FUNCTION_EXISTS (lroundf ${HDF_PREFIX}_HAVE_LROUNDF) CHECK_FUNCTION_EXISTS (lstat ${HDF_PREFIX}_HAVE_LSTAT) +CHECK_FUNCTION_EXISTS (pread ${HDF_PREFIX}_HAVE_PREAD) +CHECK_FUNCTION_EXISTS (pwrite ${HDF_PREFIX}_HAVE_PWRITE) CHECK_FUNCTION_EXISTS (rand_r ${HDF_PREFIX}_HAVE_RAND_R) CHECK_FUNCTION_EXISTS (random ${HDF_PREFIX}_HAVE_RANDOM) CHECK_FUNCTION_EXISTS (round ${HDF_PREFIX}_HAVE_ROUND) diff --git a/configure.ac b/configure.ac index 25c4b78..30fe725 100644 --- a/configure.ac +++ b/configure.ac @@ -1130,11 +1130,12 @@ case "$host_cpu-$host_vendor-$host_os" in ## functionality so clock_gettime and CLOCK_MONOTONIC are defined ## correctly. This was later updated to 200112L so that ## posix_memalign() is visible for the direct VFD code on Linux - ## systems. + ## systems. Even later, this was changed to 200809L to support + ## pread/pwrite in VFDs. ## ## POSIX feature information can be found in the gcc manual at: ## http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html - H5_CPPFLAGS="-D_POSIX_C_SOURCE=200112L $H5_CPPFLAGS" + H5_CPPFLAGS="-D_POSIX_C_SOURCE=200809L $H5_CPPFLAGS" ## Need to add this so that O_DIRECT is visible for the direct ## VFD on Linux systems. @@ -3266,6 +3267,47 @@ esac ## ---------------------------------------------------------------------- +## Enable use of pread/pwrite instead of read/write in certain VFDs. +## +AC_SUBST([PREADWRITE]) + +## Check these first to avoid interspersed output in the AC_ARG_ENABLE line +## below. (Probably overkill to check for both, but we'll be extra careful) +PREADWRITE_HAVE_BOTH=yes +AC_CHECK_FUNC([pread], [], [PREADWRITE_HAVE_BOTH=no]) +AC_CHECK_FUNC([pwrite], [], [PREADWRITE_HAVE_BOTH=no]) + +AC_MSG_CHECKING([whether to use pread/pwrite instead of read/write in certain VFDs]) +AC_ARG_ENABLE([preadwrite], + [AS_HELP_STRING([--enable-preadwrite], + [Enable using pread/pwrite instead of read/write in sec2/log/core VFDs. + [default=yes if pread/pwrite are present]])], + [PREADWRITE=$enableval]) + +## Set the default level. +if test "X-$PREADWRITE" = X- ; then + PREADWRITE=yes +fi + +case "X-$PREADWRITE" in + X-yes) + if test "X-$PREADWRITE_HAVE_BOTH" = "X-yes"; then + AC_DEFINE([HAVE_PREADWRITE], [1], [Define if both pread and pwrite exist.]) + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + X-no) + AC_MSG_RESULT([no]) + ;; + *) + AC_MSG_ERROR([Unrecognized value: $PREADWRITE]) + ;; +esac + + +## ---------------------------------------------------------------------- ## Enable embedded library information ## AC_MSG_CHECKING([whether to have library information embedded in the executables]) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index ed05e95..d1a17cd 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -348,14 +348,17 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size) HDassert(file); - /* Write to backing store */ - if((off_t)addr != HDlseek(file->fd, (off_t)addr, SEEK_SET)) +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pwrite) */ + if((HDoff_t)addr != HDlseek(file->fd, (off_t)addr, SEEK_SET)) HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "error seeking in backing store") +#endif /* H5_HAVE_PREADWRITE */ while (size > 0) { h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -366,15 +369,21 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size) bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_wrote = HDpwrite(file->fd, ptr, bytes_in, offset); + offset += bytes_wrote; +#else bytes_wrote = HDwrite(file->fd, ptr, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_wrote && EINTR == errno); if(-1 == bytes_wrote) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)offset); } /* end if */ HDassert(bytes_wrote > 0); @@ -852,6 +861,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr while(size > 0) { h5_posix_io_t bytes_in = 0; /* # of bytes to read */ h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ + HDoff_t offset = (HDoff_t)0; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -862,15 +872,21 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, mem, bytes_in, offset); + offset += bytes_read; +#else bytes_read = HDread(file->fd, mem, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_read && EINTR == errno); if(-1 == bytes_read) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)offset); } /* end if */ HDassert(bytes_read >= 0); diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 97d1b41..655d7d3 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -1191,7 +1191,8 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd } /* end if */ } /* end if */ - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pread) */ if(addr != file->pos || OP_READ != file->op) { #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags & H5FD_LOG_TIME_SEEK) @@ -1234,6 +1235,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* * Read data, being careful of interrupted system calls, partial results, @@ -1247,6 +1249,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd h5_posix_io_t bytes_in = 0; /* # of bytes to read */ h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ + HDoff_t offset = (HDoff_t)addr; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -1257,18 +1260,24 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, buf, bytes_in, offset); + offset += bytes_read; +#else bytes_read = HDread(file->fd, buf, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_read && EINTR == errno); if(-1 == bytes_read) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); if(file->fa.flags & H5FD_LOG_LOC_READ) HDfprintf(file->logfp, "Error! Reading: %10a-%10a (%10Zu bytes)\n", orig_addr, (orig_addr + orig_size) - 1, orig_size); - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)myoffset); + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)offset); } /* end if */ if(0 == bytes_read) { @@ -1398,7 +1407,8 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had file->nwrite[tmp_addr++]++; } /* end if */ - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pwrite) */ if(addr != file->pos || OP_WRITE != file->op) { #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags & H5FD_LOG_TIME_SEEK) @@ -1441,6 +1451,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* * Write the data, being careful of interrupted system calls and partial @@ -1454,6 +1465,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -1464,18 +1476,24 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_wrote = HDpwrite(file->fd, buf, bytes_in, offset); + offset += bytes_wrote; +#else bytes_wrote = HDwrite(file->fd, buf, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_wrote && EINTR == errno); if(-1 == bytes_wrote) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); if(file->fa.flags & H5FD_LOG_LOC_WRITE) HDfprintf(file->logfp, "Error! Writing: %10a-%10a (%10Zu bytes)\n", orig_addr, (orig_addr + orig_size) - 1, orig_size); - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)myoffset); + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)offset); } /* end if */ HDassert(bytes_wrote > 0); diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index c507387..0054a86 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -682,11 +682,13 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS if(REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pread) */ if(addr != file->pos || OP_READ != file->op) { if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* Read data, being careful of interrupted system calls, partial results, * and the end of the file. @@ -694,7 +696,8 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS while(size > 0) { h5_posix_io_t bytes_in = 0; /* # of bytes to read */ - h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ + h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ + HDoff_t offset = (HDoff_t)addr; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -705,15 +708,21 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, buf, bytes_in, offset); + offset += bytes_read; +#else bytes_read = HDread(file->fd, buf, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_read && EINTR == errno); if(-1 == bytes_read) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)offset); } /* end if */ if(0 == bytes_read) { @@ -777,11 +786,13 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU if(REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size) - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pwrite) */ if(addr != file->pos || OP_WRITE != file->op) { if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* Write the data, being careful of interrupted system calls and partial * results @@ -790,6 +801,7 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -800,15 +812,21 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_wrote = HDpwrite(file->fd, buf, bytes_in, offset); + offset += bytes_wrote; +#else bytes_wrote = HDwrite(file->fd, buf, bytes_in); +#endif /* H5_HAVE_PREADWRITE */ } while(-1 == bytes_wrote && EINTR == errno); if(-1 == bytes_wrote) { /* error */ int myerrno = errno; time_t mytime = HDtime(NULL); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)offset); } /* end if */ HDassert(bytes_wrote > 0); diff --git a/src/H5private.h b/src/H5private.h index f58faec..8b6253d 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1156,6 +1156,9 @@ typedef off_t h5_stat_size_t; #ifndef HDpowf #define HDpowf(X,Y) powf(X,Y) #endif /* HDpowf */ +#ifndef HDpread + #define HDpread(F,B,C,O) pread(F,B,C,O) +#endif /* HDpread */ #ifndef HDprintf #define HDprintf(...) HDfprintf(stdout, __VA_ARGS__) #endif /* HDprintf */ @@ -1168,6 +1171,9 @@ typedef off_t h5_stat_size_t; #ifndef HDputs #define HDputs(S) puts(S) #endif /* HDputs */ +#ifndef HDpwrite + #define HDpwrite(F,B,C,O) pwrite(F,B,C,O) +#endif /* HDpwrite */ #ifndef HDqsort #define HDqsort(M,N,Z,F) qsort(M,N,Z,F) #endif /* HDqsort*/ -- cgit v0.12 From 90bf59edc59bfabb38d677dc6bddb12eb57e8b11 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 30 Jan 2019 23:45:32 -0800 Subject: Fixed a bug revealed by the dtransform test. A datatype transform buffer needed to be calloc'd. --- src/H5Dio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5Dio.c b/src/H5Dio.c index 607bfcf..4fdbebd 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -1040,7 +1040,7 @@ H5D__typeinfo_init(const H5D_t *dset, hid_t mem_type_id, hbool_t do_write, */ if(NULL == (type_info->tconv_buf = (uint8_t *)tconv_buf)) { /* Allocate temporary buffer */ - if(NULL == (type_info->tconv_buf = H5FL_BLK_MALLOC(type_conv, target_size))) + if(NULL == (type_info->tconv_buf = H5FL_BLK_CALLOC(type_conv, target_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") type_info->tconv_buf_allocated = TRUE; } /* end if */ -- cgit v0.12 From 99d70c494d72bed9c2961348a659696090752ac5 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 31 Jan 2019 00:14:11 -0800 Subject: Fixed a valgrind issue with the unprotect log message. The logging call was placed after the point where the cache entry was freed. The fix was to just use the entry's address directly in the log call instead of the entry itself. --- src/H5AC.c | 2 +- src/H5Clog.c | 5 ++--- src/H5Clog.h | 4 ++-- src/H5Clog_json.c | 9 ++++----- src/H5Clog_trace.c | 7 +++---- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/H5AC.c b/src/H5AC.c index 0a5411a..e1838fb 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -1612,7 +1612,7 @@ H5AC_unprotect(H5F_t *f, const H5AC_class_t *type, haddr_t addr, void *thing, done: /* If currently logging, generate a message */ if(f->shared->cache->log_info->logging) - if(H5C_log_write_unprotect_entry_msg(f->shared->cache, (H5AC_info_t *)thing, type->id, flags, ret_value) < 0) + if(H5C_log_write_unprotect_entry_msg(f->shared->cache, addr, type->id, flags, ret_value) < 0) HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message") FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Clog.c b/src/H5Clog.c index 0ae7f13..cf9b7e8 100644 --- a/src/H5Clog.c +++ b/src/H5Clog.c @@ -887,7 +887,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5C_log_write_unprotect_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, +H5C_log_write_unprotect_entry_msg(H5C_t *cache, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value) { herr_t ret_value = SUCCEED; @@ -898,9 +898,8 @@ H5C_log_write_unprotect_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, HDassert(cache); /* Write a log message */ - HDassert(entry); if(cache->log_info->cls->write_unprotect_entry_log_msg) - if(cache->log_info->cls->write_unprotect_entry_log_msg(cache->log_info->udata, entry, type_id, flags, fxn_ret_value) < 0) + if(cache->log_info->cls->write_unprotect_entry_log_msg(cache->log_info->udata, address, type_id, flags, fxn_ret_value) < 0) HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "log-specific unprotect entry call failed") done: diff --git a/src/H5Clog.h b/src/H5Clog.h index 9ba6786..0235c4a 100644 --- a/src/H5Clog.h +++ b/src/H5Clog.h @@ -59,7 +59,7 @@ typedef struct H5C_log_class_t { herr_t (*write_resize_entry_log_msg)(void *udata, const H5C_cache_entry_t *entry, size_t new_size, herr_t fxn_ret_value); herr_t (*write_unpin_entry_log_msg)(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); herr_t (*write_destroy_fd_log_msg)(void *udata, const H5C_cache_entry_t *parent, const H5C_cache_entry_t *child, herr_t fxn_ret_value); - herr_t (*write_unprotect_entry_log_msg)(void *udata, const H5C_cache_entry_t *entry, int type_id, unsigned flags, herr_t fxn_ret_value); + herr_t (*write_unprotect_entry_log_msg)(void *udata, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value); herr_t (*write_set_cache_config_log_msg)(void *udata, const H5AC_cache_config_t *config, herr_t fxn_ret_value); herr_t (*write_remove_entry_log_msg)(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); @@ -102,7 +102,7 @@ H5_DLL herr_t H5C_log_write_protect_entry_msg(H5C_t *cache, const H5C_cache_entr H5_DLL herr_t H5C_log_write_resize_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, size_t new_size, herr_t fxn_ret_value); H5_DLL herr_t H5C_log_write_unpin_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); H5_DLL herr_t H5C_log_write_destroy_fd_msg(H5C_t *cache, const H5C_cache_entry_t *parent, const H5C_cache_entry_t *child, herr_t fxn_ret_value); -H5_DLL herr_t H5C_log_write_unprotect_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, int type_id, unsigned flags, herr_t fxn_ret_value); +H5_DLL herr_t H5C_log_write_unprotect_entry_msg(H5C_t *cache, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value); H5_DLL herr_t H5C_log_write_set_cache_config_msg(H5C_t *cache, const H5AC_cache_config_t *config, herr_t fxn_ret_value); H5_DLL herr_t H5C_log_write_remove_entry_msg(H5C_t *cache, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); diff --git a/src/H5Clog_json.c b/src/H5Clog_json.c index ccfa222..dd9e9b2 100644 --- a/src/H5Clog_json.c +++ b/src/H5Clog_json.c @@ -41,7 +41,7 @@ /****************/ /* Max log message size */ -#define H5C_MAX_JSON_LOG_MSG_SIZE 128 +#define H5C_MAX_JSON_LOG_MSG_SIZE 1024 /******************/ @@ -87,7 +87,7 @@ static herr_t H5C__json_write_protect_entry_log_msg(void *udata, const H5C_cache static herr_t H5C__json_write_resize_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, size_t new_size, herr_t fxn_ret_value); static herr_t H5C__json_write_unpin_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); static herr_t H5C__json_write_destroy_fd_log_msg(void *udata, const H5C_cache_entry_t *parent, const H5C_cache_entry_t *child, herr_t fxn_ret_value); -static herr_t H5C__json_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, int type_id, unsigned flags, herr_t fxn_ret_value); +static herr_t H5C__json_write_unprotect_entry_log_msg(void *udata, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value); static herr_t H5C__json_write_set_cache_config_log_msg(void *udata, const H5AC_cache_config_t *config, herr_t fxn_ret_value); static herr_t H5C__json_write_remove_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); @@ -1232,7 +1232,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5C__json_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, +H5C__json_write_unprotect_entry_log_msg(void *udata, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value) { H5C_log_json_udata_t *json_udata = (H5C_log_json_udata_t *)(udata); @@ -1243,7 +1243,6 @@ H5C__json_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *en /* Sanity checks */ HDassert(json_udata); HDassert(json_udata->message); - HDassert(entry); /* Create the log message string */ HDsnprintf(json_udata->message, H5C_MAX_JSON_LOG_MSG_SIZE, @@ -1257,7 +1256,7 @@ H5C__json_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *en \"returned\":%d\ },\n\ " - , (long long)HDtime(NULL), (unsigned long)entry->addr, + , (long long)HDtime(NULL), (unsigned long)address, type_id, flags, (int)fxn_ret_value); /* Write the log message to the file */ diff --git a/src/H5Clog_trace.c b/src/H5Clog_trace.c index f7d6889..7c1305c 100644 --- a/src/H5Clog_trace.c +++ b/src/H5Clog_trace.c @@ -82,7 +82,7 @@ static herr_t H5C__trace_write_protect_entry_log_msg(void *udata, const H5C_cach static herr_t H5C__trace_write_resize_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, size_t new_size, herr_t fxn_ret_value); static herr_t H5C__trace_write_unpin_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); static herr_t H5C__trace_write_destroy_fd_log_msg(void *udata, const H5C_cache_entry_t *parent, const H5C_cache_entry_t *child, herr_t fxn_ret_value); -static herr_t H5C__trace_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, int type_id, unsigned flags, herr_t fxn_ret_value); +static herr_t H5C__trace_write_unprotect_entry_log_msg(void *udata, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value); static herr_t H5C__trace_write_set_cache_config_log_msg(void *udata, const H5AC_cache_config_t *config, herr_t fxn_ret_value); static herr_t H5C__trace_write_remove_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, herr_t fxn_ret_value); @@ -872,7 +872,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5C__trace_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *entry, +H5C__trace_write_unprotect_entry_log_msg(void *udata, haddr_t address, int type_id, unsigned flags, herr_t fxn_ret_value) { H5C_log_trace_udata_t *trace_udata = (H5C_log_trace_udata_t *)(udata); @@ -883,11 +883,10 @@ H5C__trace_write_unprotect_entry_log_msg(void *udata, const H5C_cache_entry_t *e /* Sanity checks */ HDassert(trace_udata); HDassert(trace_udata->message); - HDassert(entry); /* Create the log message string */ HDsnprintf(trace_udata->message, H5C_MAX_TRACE_LOG_MSG_SIZE, "H5AC_unprotect 0x%lx %d 0x%x %d\n", - (unsigned long)(entry->addr), type_id, flags, (int)fxn_ret_value); + (unsigned long)(address), type_id, flags, (int)fxn_ret_value); /* Write the log message to the file */ if(H5C__trace_write_log_message(trace_udata) < 0) -- cgit v0.12 From bae744199b69eb7c3f5eda2441cca30cb8c6175f Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Thu, 31 Jan 2019 14:22:52 -0600 Subject: Add more specific batch scripts. Add script raybsub to handle submitting .lsf files on ray with bsub < script.lsf syntax that we couldn't handle with CMake. Add hpc-cmake-tgz option for bin/release. --- bin/batch/cori_ctestP.sl.in.cmake | 2 +- bin/batch/cori_ctestS.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestP.sl.in.cmake | 17 ++++++ bin/batch/cori_knl_ctestS.sl.in.cmake | 16 ++++++ bin/batch/raybsub | 7 +++ bin/release | 102 ++++++++++++++++++++++++++++++++- config/cmake/scripts/CTestScript.cmake | 12 +++- src/CMakeLists.txt | 6 ++ 8 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 bin/batch/cori_knl_ctestP.sl.in.cmake create mode 100644 bin/batch/cori_knl_ctestS.sl.in.cmake create mode 100644 bin/batch/raybsub diff --git a/bin/batch/cori_ctestP.sl.in.cmake b/bin/batch/cori_ctestP.sl.in.cmake index 90dd52a..6aa4916 100644 --- a/bin/batch/cori_ctestP.sl.in.cmake +++ b/bin/batch/cori_ctestP.sl.in.cmake @@ -1,6 +1,6 @@ #!/bin/bash -#SBATCH -C knl,quad,cache +#SBATCH -C haswell #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL diff --git a/bin/batch/cori_ctestS.sl.in.cmake b/bin/batch/cori_ctestS.sl.in.cmake index 0ec7bf7..502db3f 100644 --- a/bin/batch/cori_ctestS.sl.in.cmake +++ b/bin/batch/cori_ctestS.sl.in.cmake @@ -1,6 +1,6 @@ #!/bin/bash -#SBATCH -C knl,quad, cache +#SBATCH -C haswell #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL diff --git a/bin/batch/cori_knl_ctestP.sl.in.cmake b/bin/batch/cori_knl_ctestP.sl.in.cmake new file mode 100644 index 0000000..90dd52a --- /dev/null +++ b/bin/batch/cori_knl_ctestP.sl.in.cmake @@ -0,0 +1,17 @@ +#!/bin/bash + +#SBATCH -C knl,quad,cache +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestP + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" + +echo "Run $CMD. Test output will be in build/ctestP.out" +$CMD >& ctestP.out +echo "Done running $CMD" + diff --git a/bin/batch/cori_knl_ctestS.sl.in.cmake b/bin/batch/cori_knl_ctestS.sl.in.cmake new file mode 100644 index 0000000..0ec7bf7 --- /dev/null +++ b/bin/batch/cori_knl_ctestS.sl.in.cmake @@ -0,0 +1,16 @@ +#!/bin/bash + +#SBATCH -C knl,quad, cache +#SBATCH --nodes=1 +#SBATCH -t 00:30:00 +#SBATCH --mail-type=BEGIN,END,FAIL +##SBATCH --mail-user=@sandia.gov +#SBATCH --export=ALL +#SBATCH --job-name=h5_ctestS + +cd @HDF5_BINARY_DIR@ +CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" + +echo "Run $CMD. Test output will be in build/ctestS.out" +$CMD >& ctestS.out +echo "Done running $CMD" diff --git a/bin/batch/raybsub b/bin/batch/raybsub new file mode 100644 index 0000000..19dceef --- /dev/null +++ b/bin/batch/raybsub @@ -0,0 +1,7 @@ +#!/bin/tcsh + +# ray.llnl.gov requires a '<' with bsub for submitting .lsf batch jobs. +# CMake is reluctant to pass the '<', so we put it in this script and use +# the script to submit the bsub command on ray. + +bsub < $1 diff --git a/bin/release b/bin/release index e43be17..1cf1b13 100755 --- a/bin/release +++ b/bin/release @@ -55,13 +55,21 @@ for compressing the resulting tar archive (if none are given then tar -- use tar and don't do any compressing. gzip -- use gzip with "-9" and append ".gz" to the output name. + bzip2 -- use bzip2 with "-9" and append ".bz2" to the output name. + zip -- convert all text files to DOS style and form a zip file for Windows use. cmake-tgz -- create a tar file using the gzip default level with a build-unix.sh command file and all other CMake files needed to build HDF5 source using CMake on unix machines. - bzip2 -- use bzip2 with "-9" and append ".bz2" to the output name. - zip -- convert all text files to DOS style and form a zip file for Windows use. cmake-zip -- convert all text files to DOS style and create a zip file inluding cmake scripts and .bat files to build HDF5 source using CMake on Windows. + hpc-cmake-tgz + -- create a tar file using the gzip default level with a build-unix.sh + command file and all other CMake files needed to build HDF5 source + using CMake on unix machines, with HDF5options.cmake files for serial + and parallel builds on machines requiring batch jobs to run tests. + The default is for parallel build, with serial only build by changing + the HDF5options.cmake symlink to ser-HDF5options.cmake. More + information is available in the README_HPC file. doc -- produce the latest doc tree in addition to the archive. An md5 checksum is produced for each archive created and stored in the md5 file. @@ -256,7 +264,7 @@ tar2cmakezip() } # Function name: tar2cmaketgz -# Convert the release tarball to a Windows zipball with files to run CMake build. +# Convert the release tarball to a gzipped tar file with files to run CMake build. # # Programmer: Larry Knox # Creation date: 2017-02-20 @@ -330,6 +338,94 @@ tar2cmaketgz() rm -rf $cmgztmpdir } +# Function name: tar2hpccmaketgz +# Convert the release tarball to a gzipped tarfile with files to run CMake build +# and HDF5options.cmake files for parallel or serial only builds where build +# tests are run on compute nodes using batch scripts. +# +# Programmer: Larry Knox +# Creation date: 2019-01-28 +# +# Modifications +# +# Steps: +# 1. untar the tarball in a temporary directory; +# Note: do this in a temporary directory to avoid changing +# the original source directory which may be around. +# 2. add build-unix.sh script. +# 3. add SZIP.tar.gz, ZLib.tar.gz and cmake files to top level directory. +# 4. create gzipped tar file with these contents: +# build-unix.sh script +# hdf5- source code directory extracted from tar file +# CTestScript.cmake cmake file copied from /config/cmake/scripts +# HDF5config.cmake cmake file copied from /config/cmake/scripts +# HDF5options.cmake cmake file copied from /config/cmake/scripts +# SZip.tar.gz copied from /mnt/scr1/pre-release/hdf5/CMake +# ZLib.tar.gz copied from /mnt/scr1/pre-release/hdf5/CMake +# +# 5. For HPC-CMake tgz file the following are also needed in the top-level directory: +# README_HPC copied from release_docs +# ser-HDF5options.cmake copied from /config/cmake/scripts/HPC +# par-HDF5options.cmake copied from /config/cmake/scripts/HPC +# HDF5options.cmake symlink to par-HDF5options.cmake +# + +# Parameters: +# $1 version +# $2 release tarball +# $3 output zipball file name +# +# Returns 0 if successful; 1 otherwise +# + # need function to create another temporary directory, extract the + # $tmpdir/$HDF5_VERS.tar into it, create build-unix.sh, + # add CTestScript.cmake, HDF5config.cmake, SZIP.tar.gz + # ZLib.tar.gz, HDF5 examples, and then tar.gz it. +tar2hpccmaketgz() +{ + if [ $# -ne 3 ]; then + echo "usage: tar2cmaketgz " + return 1 + fi + cmgztmpdir=/tmp/cmgztmpdir$$ + cmgztmpsubdir=$cmgztmpdir/CMake-$HDF5_VERS + mkdir -p $cmgztmpsubdir + version=$1 + tarfile=$2 + tgzfile=$3 + + # step 1: untar tarball in cmgztmpdir + (cd $cmgztmpsubdir; tar xf -) < $tarfile + # sanity check + if [ ! -d $cmgztmpsubdir/$version ]; then + echo "untar did not create $cmgztmpsubdir/$version source dir" + # cleanup + rm -rf $cmgztmpdir + return 1 + fi + + + # step 2: add build-unix.sh script + (cd $cmgztmpsubdir; echo "ctest -S HDF5config.cmake,BUILD_GENERATOR=Unix -C Release -V -O hdf5.log" > build-unix.sh; chmod 755 build-unix.sh) + + # step 3: add SZIP.tar.gz, ZLib.tar.gz and cmake files + cp /mnt/scr1/pre-release/hdf5/CMake/SZip.tar.gz $cmgztmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/ZLib.tar.gz $cmgztmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.10.10-Source.tar.gz $cmgztmpsubdir + cp $cmgztmpsubdir/$version/config/cmake/scripts/CTestScript.cmake $cmgztmpsubdir + cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5config.cmake $cmgztmpsubdir + cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5options.cmake $cmgztmpsubdir + + cp $cmgztmpsubdir/$version/release_docs/README_HPC $cmgztmpsubdir + cp $cmgztmpsubdir/$version/config/cmake/scripts/HPC/ser-HDF5options.cmake $cmgztmpsubdir + cp $cmgztmpsubdir/$version/config/cmake/scripts/HPC/par-HDF5options.cmake $cmgztmpsubdir + (cd $cmgztmpsubdir; ln -s par-HDF5options.cmake HDF5options.cmake) + tar czf $DEST/CMake-$HDF5_VERS.tar.gz -C $cmgztmpdir . || exit 1 + + # cleanup + rm -rf $cmgztmpdir +} + # This command must be run at the top level of the hdf5 source directory. # Verify this requirement. if [ ! \( -f configure.ac -a -f bin/release \) ]; then diff --git a/config/cmake/scripts/CTestScript.cmake b/config/cmake/scripts/CTestScript.cmake index eb466d2..c380a9d 100644 --- a/config/cmake/scripts/CTestScript.cmake +++ b/config/cmake/scripts/CTestScript.cmake @@ -277,7 +277,11 @@ message (STATUS "Dashboard script configuration:\n${vars}\n") ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res) else () file(STRINGS ${CTEST_BINARY_DIRECTORY}/Testing/TAG TAG_CONTENTS REGEX "^2([0-9]+)[-]([0-9]+)$") - execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) + if ("${LOCAL_BATCH_SCRIPT_COMMAND}" STREQUAL "raybsub") + execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) + else () + execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) + endif () message(STATUS "Check for existence of ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml") execute_process(COMMAND ls ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET) while(result) @@ -292,7 +296,11 @@ message (STATUS "Dashboard script configuration:\n${vars}\n") file (RENAME ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/SerialTest.xml) file (RENAME ${CTEST_BINARY_DIRECTORY}/Testing/Temporary/LastTest_${TAG_CONTENTS}.log ${CTEST_BINARY_DIRECTORY}/Testing/Temporary/LastTest_${TAG_CONTENTS}_Serial.log) unset(result CACHE) - execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) + if ("${LOCAL_BATCH_SCRIPT_COMMAND}" STREQUAL "raybsub") + execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) + else () + execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) + endif () message(STATUS "Check for existence of ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml") execute_process(COMMAND ls ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET) while(result) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff7402b..6b105a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -944,6 +944,12 @@ if (BUILD_SHARED_LIBS) endif () if (LOCAL_BATCH_TEST) + if ("${LOCAL_BATCH_SCRIPT_COMMAND}" STREQUAL "raybsub") + configure_file ( + ${HDF5_SOURCE_DIR}/bin/batch/${LOCAL_BATCH_SCRIPT_COMMAND} + ${HDF5_BINARY_DIR}/${LOCAL_BATCH_SCRIPT_COMMAND} ESCAPE_QUOTES @ONLY + ) + endif () if (LOCAL_BATCH_SCRIPT_NAME) configure_file ( ${HDF5_SOURCE_DIR}/bin/batch/${LOCAL_BATCH_SCRIPT_NAME}.in.cmake -- cgit v0.12 From 5352bf49717cd4fa52a444b18ff866848084f2aa Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Fri, 1 Feb 2019 08:57:52 -0600 Subject: Add new files to MANIFEST. Update permissions for raybsub to 755. --- MANIFEST | 10 ++++++++++ bin/batch/raybsub | 0 2 files changed, 10 insertions(+) mode change 100644 => 100755 bin/batch/raybsub diff --git a/MANIFEST b/MANIFEST index bd44d27..52770fd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -92,6 +92,10 @@ ./bin/timekeeper _DO_NOT_DISTRIBUTE_ ./bin/trace ./bin/yodconfigure +./bin/batch/cori_ctestP.sl.in.cmake +./bin/batch/cori_ctestS.sl.in.cmake +./bin/batch/cori_knl_ctestP.sl.in.cmake +./bin/batch/cori_knl_ctestS.sl.in.cmake ./bin/batch/ctestP.lsf.in.cmake ./bin/batch/ctestP.sl.in.cmake ./bin/batch/ctestS.lsf.in.cmake @@ -99,6 +103,9 @@ ./bin/batch/knl_ctestP.sl.in.cmake ./bin/batch/knl_ctestS.sl.in.cmake ./bin/batch/knl_H5detect.sl.in.cmake +./bin/batch/ray_ctestP.lsf.in.cmake +./bin/batch/ray_ctestS.lsf.in.cmake +./bin/batch/raybsub ./bin/pkgscrpts/h5rmflags _DO_NOT_DISTRIBUTE_ ./bin/pkgscrpts/makeHDF5BinaryTarfiles.pl _DO_NOT_DISTRIBUTE_ ./bin/pkgscrpts/makeInternalREADME.pl _DO_NOT_DISTRIBUTE_ @@ -455,6 +462,7 @@ ./release_docs/INSTALL_Warnings.txt ./release_docs/INSTALL_Windows.txt ./release_docs/RELEASE.txt +./release_docs/README_HPC ./release_docs/USING_HDF5_CMake.txt ./release_docs/USING_HDF5_VS.txt @@ -3362,6 +3370,8 @@ ./config/cmake/scripts/CTestScript.cmake ./config/cmake/scripts/HDF5config.cmake ./config/cmake/scripts/HDF5options.cmake +./config/cmake/scripts/HPC/par-HDF5options.cmake +./config/cmake/scripts/HPC/ser-HDF5options.cmake # Files generated by autogen ./aclocal.m4 diff --git a/bin/batch/raybsub b/bin/batch/raybsub old mode 100644 new mode 100755 -- cgit v0.12 From eb84f922c84dbcf51658d338910d99568bc43769 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Fri, 1 Feb 2019 10:21:53 -0600 Subject: Update bin/release for filename changes and HPC-CMake tar file corrections. --- bin/release | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/release b/bin/release index 1cf1b13..b1aa2c4 100755 --- a/bin/release +++ b/bin/release @@ -233,7 +233,7 @@ tar2cmakezip() # step 3: add SZIP.tar.gz, ZLib.tar.gz and cmake files cp /mnt/scr1/pre-release/hdf5/CMake/SZip.tar.gz $cmziptmpsubdir cp /mnt/scr1/pre-release/hdf5/CMake/ZLib.tar.gz $cmziptmpsubdir - cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.10.10-Source.tar.gz $cmziptmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.12.4-Source.tar.gz $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/CTestScript.cmake $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/HDF5config.cmake $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/HDF5options.cmake $cmziptmpsubdir @@ -328,7 +328,7 @@ tar2cmaketgz() # step 3: add SZIP.tar.gz, ZLib.tar.gz and cmake files cp /mnt/scr1/pre-release/hdf5/CMake/SZip.tar.gz $cmgztmpsubdir cp /mnt/scr1/pre-release/hdf5/CMake/ZLib.tar.gz $cmgztmpsubdir - cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.10.10-Source.tar.gz $cmgztmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.12.4-Source.tar.gz $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/CTestScript.cmake $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5config.cmake $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5options.cmake $cmgztmpsubdir @@ -384,11 +384,11 @@ tar2cmaketgz() tar2hpccmaketgz() { if [ $# -ne 3 ]; then - echo "usage: tar2cmaketgz " + echo "usage: tar2hpccmaketgz " return 1 fi cmgztmpdir=/tmp/cmgztmpdir$$ - cmgztmpsubdir=$cmgztmpdir/CMake-$HDF5_VERS + cmgztmpsubdir=$cmgztmpdir/HPC-CMake-$HDF5_VERS mkdir -p $cmgztmpsubdir version=$1 tarfile=$2 @@ -411,16 +411,15 @@ tar2hpccmaketgz() # step 3: add SZIP.tar.gz, ZLib.tar.gz and cmake files cp /mnt/scr1/pre-release/hdf5/CMake/SZip.tar.gz $cmgztmpsubdir cp /mnt/scr1/pre-release/hdf5/CMake/ZLib.tar.gz $cmgztmpsubdir - cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.10.10-Source.tar.gz $cmgztmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.12.4-Source.tar.gz $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/CTestScript.cmake $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5config.cmake $cmgztmpsubdir - cp $cmgztmpsubdir/$version/config/cmake/scripts/HDF5options.cmake $cmgztmpsubdir cp $cmgztmpsubdir/$version/release_docs/README_HPC $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/HPC/ser-HDF5options.cmake $cmgztmpsubdir cp $cmgztmpsubdir/$version/config/cmake/scripts/HPC/par-HDF5options.cmake $cmgztmpsubdir (cd $cmgztmpsubdir; ln -s par-HDF5options.cmake HDF5options.cmake) - tar czf $DEST/CMake-$HDF5_VERS.tar.gz -C $cmgztmpdir . || exit 1 + tar czf $DEST/HPC-CMake-$HDF5_VERS.tar.gz -C $cmgztmpdir . || exit 1 # cleanup rm -rf $cmgztmpdir @@ -610,6 +609,11 @@ for comp in $methods; do tar2cmaketgz $HDF5_VERS $tmpdir/$HDF5_VERS.tar $DEST/CMake-$HDF5_VERS.tar.gz 1>&2 (cd $DEST; md5sum CMake-$HDF5_VERS.tar.gz >> $MD5file) ;; + hpc-cmake-tgz) + test "$verbose" && echo " Creating HPC-CMake tar.gz file..." 1>&2 + tar2hpccmaketgz $HDF5_VERS $tmpdir/$HDF5_VERS.tar $DEST/HPC-CMake-$HDF5_VERS.tar.gz 1>&2 + (cd $DEST; md5sum HPC-CMake-$HDF5_VERS.tar.gz >> $MD5file) + ;; bzip2) test "$verbose" && echo " Running bzip2..." 1>&2 bzip2 -9 <$tmpdir/$HDF5_VERS.tar >$DEST/$HDF5_VERS.tar.bz2 -- cgit v0.12 From cc7ce0eb8b1aa14960b00af0f0711bdb43add2a5 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Fri, 1 Feb 2019 12:19:28 -0600 Subject: Change examples file to zip for CMake zip file. --- bin/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/release b/bin/release index b1aa2c4..96c2e78 100755 --- a/bin/release +++ b/bin/release @@ -233,7 +233,7 @@ tar2cmakezip() # step 3: add SZIP.tar.gz, ZLib.tar.gz and cmake files cp /mnt/scr1/pre-release/hdf5/CMake/SZip.tar.gz $cmziptmpsubdir cp /mnt/scr1/pre-release/hdf5/CMake/ZLib.tar.gz $cmziptmpsubdir - cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.12.4-Source.tar.gz $cmziptmpsubdir + cp /mnt/scr1/pre-release/hdf5/CMake/HDF5Examples-1.12.4-Source.zip $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/CTestScript.cmake $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/HDF5config.cmake $cmziptmpsubdir cp $cmziptmpsubdir/$version/config/cmake/scripts/HDF5options.cmake $cmziptmpsubdir -- cgit v0.12 From 5f1f231310bcb3278f11a51e1ea47782f6ee3235 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 1 Feb 2019 13:12:39 -0800 Subject: Updated H5Dio.c comment. --- src/H5Dio.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/H5Dio.c b/src/H5Dio.c index 4fdbebd..2f87e38 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -1031,12 +1031,9 @@ H5D__typeinfo_init(const H5D_t *dset, hid_t mem_type_id, hbool_t do_write, if(type_info->request_nelmts == 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "temporary buffer max size is too small") - /* - * Get a temporary buffer for type conversion unless the app has already + /* Get a temporary buffer for type conversion unless the app has already * supplied one through the xfer properties. Instead of allocating a - * buffer which is the exact size, we allocate the target size. The - * malloc() is usually less resource-intensive if we allocate/free the - * same size over and over. + * buffer which is the exact size, we allocate the target size. */ if(NULL == (type_info->tconv_buf = (uint8_t *)tconv_buf)) { /* Allocate temporary buffer */ -- cgit v0.12 From 055208b71c573be3d4b1047b840d4d8b255bc25e Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 1 Feb 2019 13:23:54 -0800 Subject: Minor tweak to CMake preadwrite entry. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb9839b..85f701e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -486,7 +486,7 @@ endif () #----------------------------------------------------------------------------- option (HDF5_ENABLE_PREADWRITE "Use pread/pwrite in sec2/log/core VFDs in place of read/write (when available)" ON) mark_as_advanced (HDF5_ENABLE_PREADWRITE) -if (HDF5_ENABLE_PREADWRITE AND ${HDF_PREFIX}_HAVE_PREAD AND ${HDF_PREFIX}_HAVE_PWRITE) +if (HDF5_ENABLE_PREADWRITE AND H5_HAVE_PREAD AND H5_HAVE_PWRITE) set (H5_HAVE_PREADWRITE 1) endif () -- cgit v0.12 From c348d453b583ec9092152e6aef1f7fa9854cf5d9 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Sat, 2 Feb 2019 08:02:48 -0600 Subject: Correct H5DIFF to PH5DIFF in *ctestS.sl.in.cmake list of parallel tests reserved for *ctestP.sl.cmake. Revise options to run batch tests and alternative options for cross compile in HPC/*-HDF5options.cmake. --- bin/batch/cori_ctestS.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestS.sl.in.cmake | 2 +- bin/batch/ctestS.lsf.in.cmake | 2 +- bin/batch/ctestS.sl.in.cmake | 2 +- bin/batch/ray_ctestS.lsf.in.cmake | 2 +- config/cmake/scripts/HPC/par-HDF5options.cmake | 24 +++++++++++++++++------- config/cmake/scripts/HPC/ser-HDF5options.cmake | 16 ++++++++++------ 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/bin/batch/cori_ctestS.sl.in.cmake b/bin/batch/cori_ctestS.sl.in.cmake index 502db3f..cf68826 100644 --- a/bin/batch/cori_ctestS.sl.in.cmake +++ b/bin/batch/cori_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/cori_knl_ctestS.sl.in.cmake b/bin/batch/cori_knl_ctestS.sl.in.cmake index 0ec7bf7..7db4483 100644 --- a/bin/batch/cori_knl_ctestS.sl.in.cmake +++ b/bin/batch/cori_knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ctestS.lsf.in.cmake b/bin/batch/ctestS.lsf.in.cmake index 5692574..7ef5af5 100644 --- a/bin/batch/ctestS.lsf.in.cmake +++ b/bin/batch/ctestS.lsf.in.cmake @@ -11,7 +11,7 @@ cd @HDF5_BINARY_DIR@ echo "Run command. Test output will be in build/ctestS.out" -ctest . -E 'TEST_PAR|H5DIFF|PERFORM' -C Release -j 32 -T test >& ctestS.out +ctest . -E 'TEST_PAR|PH5DIFF|PERFORM' -C Release -j 32 -T test >& ctestS.out ##$CMD >& ctestS.out echo "Done running command." diff --git a/bin/batch/ctestS.sl.in.cmake b/bin/batch/ctestS.sl.in.cmake index f772be9..98c1bcd 100644 --- a/bin/batch/ctestS.sl.in.cmake +++ b/bin/batch/ctestS.sl.in.cmake @@ -8,7 +8,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|H5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ray_ctestS.lsf.in.cmake b/bin/batch/ray_ctestS.lsf.in.cmake index cbc7130..d23a513 100644 --- a/bin/batch/ray_ctestS.lsf.in.cmake +++ b/bin/batch/ray_ctestS.lsf.in.cmake @@ -11,7 +11,7 @@ cd @HDF5_BINARY_DIR@ echo "Run command. Test output will be in build/ctestS.out" -ctest . -E 'TEST_PAR|H5DIFF|PERFORM|ph5example' -C Release -j 32 -T test >& ctestS.out +ctest . -E 'TEST_PAR|PH5DIFF|PERFORM|ph5example' -C Release -j 32 -T test >& ctestS.out ##$CMD >& ctestS.out echo "Done running command." diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake index 0527995..68d35dc 100644 --- a/config/cmake/scripts/HPC/par-HDF5options.cmake +++ b/config/cmake/scripts/HPC/par-HDF5options.cmake @@ -100,6 +100,17 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") ### Create install package with external libraries (szip, zlib) set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") + +#options to run test scripts in batch commands +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") + + ############################################################################################# ### use a toolchain file @@ -107,11 +118,10 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") -#options to run test scripts in batch commands -set (LOCAL_BATCH_TEST ON) -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") -set (LOCAL_BATCH_SCRIPT_NAME "knl_ctestS.sl") -set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "knl_ctestP.sl") -set(MPIEXEC_EXECUTABLE "srun") - +#some additions and alternatives to cross compile on haswell for knl +#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") +#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") +#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=knl_ctestP.sl") ############################################################################################# diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake index 71266ec..80c8b9e 100644 --- a/config/cmake/scripts/HPC/ser-HDF5options.cmake +++ b/config/cmake/scripts/HPC/ser-HDF5options.cmake @@ -100,6 +100,11 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRIN ### Create install package with external libraries (szip, zlib) set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") +#options to run test scripts in batch commands +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") + ############################################################################################# ### use a toolchain file @@ -107,11 +112,10 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/crayle.cmake") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") -#options to run test scripts in batch commands -set (LOCAL_BATCH_TEST ON) -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") -set (LOCAL_BATCH_SCRIPT_NAME "knl_ctestS.sl") -set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "knl_ctestP.sl") -set(MPIEXEC_EXECUTABLE "srun") +#some additions and alternatives to cross compile on haswell for knl +#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") +#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") +#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") ############################################################################################# -- cgit v0.12 From dddc940bdf4a0ae236b7096245a436aead30b55d Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Sun, 3 Feb 2019 21:33:16 -0600 Subject: Add batchscript options that work when running ctest directly. --- config/cmake/scripts/HPC/par-HDF5options.cmake | 5 ++++- config/cmake/scripts/HPC/ser-HDF5options.cmake | 2 ++ config/toolchain/crayle.cmake | 7 +++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake index 68d35dc..5386373 100644 --- a/config/cmake/scripts/HPC/par-HDF5options.cmake +++ b/config/cmake/scripts/HPC/par-HDF5options.cmake @@ -103,6 +103,9 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") #options to run test scripts in batch commands set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_TEST "TRUE") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") @@ -114,7 +117,7 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") ############################################################################################# ### use a toolchain file -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/craype.cmake") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/crayle.cmake") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake index 80c8b9e..f935efc 100644 --- a/config/cmake/scripts/HPC/ser-HDF5options.cmake +++ b/config/cmake/scripts/HPC/ser-HDF5options.cmake @@ -102,6 +102,8 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") #options to run test scripts in batch commands set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_TEST "TRUE") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") diff --git a/config/toolchain/crayle.cmake b/config/toolchain/crayle.cmake index 47d8afc..159f43a 100644 --- a/config/toolchain/crayle.cmake +++ b/config/toolchain/crayle.cmake @@ -15,7 +15,6 @@ set(HDF5_USE_PREGEN OFF) #set(HDF5_USE_PREGEN_DIR "/lscratch1/lknox/HDF5_1_10_4/CMake-hdf5-1.10.4") # option to generate H5Tinit.c by running H5detect on knl compute node during build -set(HDF5_BATCH_H5DETECT ON) -set(HDF5_BATCH_CMD "sbatch") -set(HDF5_BATCH_H5DETECT_SCRIPT "knl_H5detect.sl") -set(MPIEXEC_EXECUTABLE "srun") +#set(HDF5_BATCH_H5DETECT ON) +#set(HDF5_BATCH_CMD "sbatch") +#set(HDF5_BATCH_H5DETECT_SCRIPT "knl_H5detect.sl") -- cgit v0.12 From 6c2a4b728f3c8eadb18d4e10d41bdbd7d1c8f3e8 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Mon, 4 Feb 2019 08:46:57 -0600 Subject: Add LOCAL_BATCH_SCRIPT_ARG variable for submitting account information and other batch command variations with ctest command. --- bin/batch/knl_ctestP.sl.in.cmake | 2 +- bin/batch/knl_ctestS.sl.in.cmake | 2 +- config/cmake/scripts/CTestScript.cmake | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/batch/knl_ctestP.sl.in.cmake b/bin/batch/knl_ctestP.sl.in.cmake index 8d786da..5c7c83f 100644 --- a/bin/batch/knl_ctestP.sl.in.cmake +++ b/bin/batch/knl_ctestP.sl.in.cmake @@ -1,6 +1,6 @@ #!/bin/bash -#SBATCH -C knl,quad,cache +#SBATCH -p knl -C quad,cache #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL diff --git a/bin/batch/knl_ctestS.sl.in.cmake b/bin/batch/knl_ctestS.sl.in.cmake index b983228..0dae31f 100644 --- a/bin/batch/knl_ctestS.sl.in.cmake +++ b/bin/batch/knl_ctestS.sl.in.cmake @@ -1,6 +1,6 @@ #!/bin/bash -#SBATCH -C knl,quad,cache +#SBATCH -p knl -C quad,cache #SBATCH --nodes=1 #SBATCH -t 00:30:00 #SBATCH --mail-type=BEGIN,END,FAIL diff --git a/config/cmake/scripts/CTestScript.cmake b/config/cmake/scripts/CTestScript.cmake index c380a9d..0e2afc7 100644 --- a/config/cmake/scripts/CTestScript.cmake +++ b/config/cmake/scripts/CTestScript.cmake @@ -278,9 +278,9 @@ message (STATUS "Dashboard script configuration:\n${vars}\n") else () file(STRINGS ${CTEST_BINARY_DIRECTORY}/Testing/TAG TAG_CONTENTS REGEX "^2([0-9]+)[-]([0-9]+)$") if ("${LOCAL_BATCH_SCRIPT_COMMAND}" STREQUAL "raybsub") - execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) + execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${LOCAL_BATCH_SCRIPT_ARGS} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) else () - execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) + execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${LOCAL_BATCH_SCRIPT_ARGS} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_NAME}) endif () message(STATUS "Check for existence of ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml") execute_process(COMMAND ls ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET) @@ -297,9 +297,9 @@ message (STATUS "Dashboard script configuration:\n${vars}\n") file (RENAME ${CTEST_BINARY_DIRECTORY}/Testing/Temporary/LastTest_${TAG_CONTENTS}.log ${CTEST_BINARY_DIRECTORY}/Testing/Temporary/LastTest_${TAG_CONTENTS}_Serial.log) unset(result CACHE) if ("${LOCAL_BATCH_SCRIPT_COMMAND}" STREQUAL "raybsub") - execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) + execute_process (COMMAND ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_COMMAND} ${LOCAL_BATCH_SCRIPT_ARGS} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) else () - execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) + execute_process (COMMAND ${LOCAL_BATCH_SCRIPT_COMMAND} ${LOCAL_BATCH_SCRIPT_ARGS} ${CTEST_BINARY_DIRECTORY}/${LOCAL_BATCH_SCRIPT_PARALLEL_NAME}) endif () message(STATUS "Check for existence of ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml") execute_process(COMMAND ls ${CTEST_BINARY_DIRECTORY}/Testing/${TAG_CONTENTS}/Test.xml RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET) -- cgit v0.12 From 91c7ff81dcac1af7a7b609698aa69f0c213a6184 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 4 Feb 2019 10:11:59 -0800 Subject: Added a line for the CMake pread/write option to INSTALL_CMake.txt. --- release_docs/INSTALL_CMake.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/release_docs/INSTALL_CMake.txt b/release_docs/INSTALL_CMake.txt index 26cf3ce..233c2cc 100644 --- a/release_docs/INSTALL_CMake.txt +++ b/release_docs/INSTALL_CMake.txt @@ -635,6 +635,7 @@ HDF5_ENABLE_DIRECT_VFD "Build the Direct I/O Virtual File Driver" HDF5_ENABLE_EMBEDDED_LIBINFO "embed library info into executables" ON HDF5_ENABLE_HSIZET "Enable datasets larger than memory" ON HDF5_ENABLE_PARALLEL "Enable parallel build (requires MPI)" OFF +HDF5_ENABLE_PREADWRITE "Use pread/pwrite in sec2/log/core VFDs in place of read/write (when available)" ON HDF5_ENABLE_TRACE "Enable API tracing capability" OFF HDF5_ENABLE_USING_MEMCHECKER "Indicate that a memory checker is used" OFF HDF5_GENERATE_HEADERS "Rebuild Generated Files" ON -- cgit v0.12 From 7f718e9ea232a84ec2be1b52f25f152de775fdac Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Mon, 4 Feb 2019 22:30:48 -0600 Subject: There is performance issue when closing an object. The slow down is due to the search of the "tag_list" to find out the "corked" status of an object. The fix: (1) Add a counter "num_objs_corked" in the cache structure to track the number of "corked" objects. (2) Skip the search of "tag_list" if the counter is zero i.e. no "corked" objects. --- src/H5AC.c | 9 +++++++-- src/H5C.c | 4 ++++ src/H5Cpkg.h | 8 ++++++++ src/H5Cprivate.h | 1 + src/H5Ctag.c | 26 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/H5AC.c b/src/H5AC.c index e1838fb..4801194 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -2403,8 +2403,13 @@ H5AC_cork(H5F_t *f, haddr_t obj_addr, unsigned action, hbool_t *corked) HDassert(H5F_addr_defined(obj_addr)); HDassert(action == H5AC__SET_CORK || action == H5AC__UNCORK || action == H5AC__GET_CORKED); - if(action == H5AC__GET_CORKED) - HDassert(corked); + if(action == H5AC__GET_CORKED) { + HDassert(corked); + if(H5C_get_num_objs_corked(f->shared->cache) == 0) { + *corked = FALSE; + HGOTO_DONE(SUCCEED) + } + } if(H5C_cork(f->shared->cache, obj_addr, action, corked) < 0) HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Cannot perform the cork action") diff --git a/src/H5C.c b/src/H5C.c index b5dc6a5..d53e0ca 100644 --- a/src/H5C.c +++ b/src/H5C.c @@ -327,6 +327,7 @@ H5C_create(size_t max_cache_size, /* Tagging Field Initializations */ cache_ptr->ignore_tags = FALSE; + cache_ptr->num_objs_corked = FALSE; cache_ptr->slist_changed = FALSE; cache_ptr->slist_len = 0; @@ -7729,6 +7730,8 @@ H5C_cork(H5C_t *cache_ptr, haddr_t obj_addr, unsigned action, hbool_t *corked) /* Set the corked status for the entire object */ tag_info->corked = TRUE; + cache_ptr->num_objs_corked++; + } /* end if */ else { /* Sanity check */ @@ -7740,6 +7743,7 @@ H5C_cork(H5C_t *cache_ptr, haddr_t obj_addr, unsigned action, hbool_t *corked) /* Set the corked status for the entire object */ tag_info->corked = FALSE; + cache_ptr->num_objs_corked--; /* Remove the tag info from the tag list, if there's no more entries with this tag */ if(0 == tag_info->entry_cnt) { diff --git a/src/H5Cpkg.h b/src/H5Cpkg.h index 9201afb..9156c0d 100644 --- a/src/H5Cpkg.h +++ b/src/H5Cpkg.h @@ -3823,6 +3823,13 @@ typedef struct H5C_tag_info_t { * * ignore_tags: Boolean flag to disable tag validation during entry insertion. * + * num_objs_corked: Unsigned integer field containing the number of objects + * that are "corked". The "corked" status of an object is + * found by searching the "tag_list". This field is added + * for optimization so that the skip list search on "tag_list" + * can be skipped if this field is zero, i.e. no "corked" + * objects. + * * When a cache entry is protected, it must be removed from the LRU * list(s) as it cannot be either flushed or evicted until it is unprotected. * The following fields are used to implement the protected list (pl). @@ -4693,6 +4700,7 @@ struct H5C_t { /* Fields for maintaining list of tagged entries */ H5SL_t * tag_list; hbool_t ignore_tags; + uint32_t num_objs_corked; /* Fields for tracking protected entries */ uint32_t pl_len; diff --git a/src/H5Cprivate.h b/src/H5Cprivate.h index c39c1df..ee2d033 100644 --- a/src/H5Cprivate.h +++ b/src/H5Cprivate.h @@ -2301,6 +2301,7 @@ H5_DLL herr_t H5C_validate_resize_config(H5C_auto_size_ctl_t *config_ptr, unsigned int tests); H5_DLL herr_t H5C_ignore_tags(H5C_t *cache_ptr); H5_DLL hbool_t H5C_get_ignore_tags(const H5C_t *cache_ptr); +H5_DLL hbool_t H5C_get_num_objs_corked(const H5C_t *cache_ptr); H5_DLL herr_t H5C_retag_entries(H5C_t * cache_ptr, haddr_t src_tag, haddr_t dest_tag); H5_DLL herr_t H5C_cork(H5C_t *cache_ptr, haddr_t obj_addr, unsigned action, hbool_t *corked); H5_DLL herr_t H5C_get_entry_ring(const H5F_t *f, haddr_t addr, H5C_ring_t *ring); diff --git a/src/H5Ctag.c b/src/H5Ctag.c index 0f08ede..611ff37 100644 --- a/src/H5Ctag.c +++ b/src/H5Ctag.c @@ -175,6 +175,32 @@ H5C_get_ignore_tags(const H5C_t *cache_ptr) /*------------------------------------------------------------------------- * + * Function: H5C_get_num_objs_corked + * + * Purpose: Retrieve the 'num_objs_corked' field for the cache + * + * Return: 'num_objs_corked' value (can't fail) + * + * Programmer: Vailin Choi; Feb 2019 + * + *------------------------------------------------------------------------- + */ +hbool_t +H5C_get_num_objs_corked(const H5C_t *cache_ptr) +{ + FUNC_ENTER_NOAPI_NOERR + + /* Sanity checks */ + HDassert(cache_ptr); + HDassert(cache_ptr->magic == H5C__H5C_T_MAGIC); + + /* Return value for num_objs_corked */ + FUNC_LEAVE_NOAPI(cache_ptr->num_objs_corked) +} /* H5C_get_num_objs_corked */ + + +/*------------------------------------------------------------------------- + * * Function: H5C__tag_entry * * Purpose: Tags an entry with the provided tag (contained in the API context). -- cgit v0.12 From 18e875f75fadc93a1c8132420f612e188933de85 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Tue, 5 Feb 2019 15:25:30 -0600 Subject: Fail configure if SZIP/ZLIB is requested but not found --- CMakeFilters.cmake | 8 ++++++++ config/cmake/scripts/HDF5config.cmake | 6 +++++- tools/test/h5dump/h5dumpgentest.c | 6 ++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeFilters.cmake b/CMakeFilters.cmake index 71dabb1..0e05cf0 100644 --- a/CMakeFilters.cmake +++ b/CMakeFilters.cmake @@ -27,7 +27,15 @@ if (HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF5_ALLOW_EXTERNAL_SUPPORT MAT set (TGZPATH ${HDF5_SOURCE_DIR}) endif () set (ZLIB_URL ${TGZPATH}/${ZLIB_TGZ_NAME}) + if (NOT EXISTS "${ZLIB_URL}") + set (ZLIB_USE_EXTERNAL 0) + message (STATUS "Filter ZLIB file ${ZLIB_URL} not found") + endif () set (SZIP_URL ${TGZPATH}/${SZIP_TGZ_NAME}) + if (NOT EXISTS "${SZIP_URL}") + set (SZIP_USE_EXTERNAL 0) + message (STATUS "Filter SZIP file ${SZIP_URL} not found") + endif () else () set (ZLIB_USE_EXTERNAL 0) set (SZIP_USE_EXTERNAL 0) diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index dd3b17c..1d8d501 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -43,6 +43,7 @@ set (CTEST_SOURCE_VERSEXT "") #INSTALLDIR - HDF5-1.10.0 root folder #CTEST_CONFIGURATION_TYPE - Release, Debug, RelWithDebInfo #CTEST_SOURCE_NAME - name of source folder; HDF5-1.10.0 +#MODEL - CDash group name if (DEFINED CTEST_SCRIPT_ARG) # transform ctest script arguments of the form # script.ctest,var1=value1,var2=value2 @@ -169,7 +170,10 @@ endif () ################################################################### ######### Following is for submission to CDash ############ ################################################################### -set (MODEL "Experimental") +if (NOT DEFINED MODEL) + set (MODEL "Experimental") +endif () + ################################################################### ################################################################### diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index cbbbcfa..946ca04 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -9529,15 +9529,13 @@ gent_intattrscalars(void) } /*------------------------------------------------------------------------- - * Function: gent_packedbits + * Function: gent_intsattrs * - * Purpose: Generate a file to be used in the h5dump packed bits tests. + * Purpose: Generate a file to be used in the h5dump tests. * Four datasets of 1, 2, 4 and 8 bytes of unsigned int types are created. * Four more datasets of 1, 2, 4 and 8 bytes of signed int types are created. * Fill them with raw data such that no bit will be all zero in a dataset. * A dummy dataset of double type is created for failure test. - * Created: Albert Cheng, 2010/5/10. - * Modified: Allen Byrne, 2011/1/5 Use file to test Signed/Unsigned datatypes *------------------------------------------------------------------------- */ static void -- cgit v0.12 From abd74c8310792ad52085a10ca46ec4ef4eafd976 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Tue, 5 Feb 2019 15:44:38 -0600 Subject: Switch OFF if compression source is not available --- CMakeFilters.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeFilters.cmake b/CMakeFilters.cmake index 0e05cf0..5a89564 100644 --- a/CMakeFilters.cmake +++ b/CMakeFilters.cmake @@ -28,12 +28,12 @@ if (HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF5_ALLOW_EXTERNAL_SUPPORT MAT endif () set (ZLIB_URL ${TGZPATH}/${ZLIB_TGZ_NAME}) if (NOT EXISTS "${ZLIB_URL}") - set (ZLIB_USE_EXTERNAL 0) + set (HDF5_ENABLE_Z_LIB_SUPPORT OFF CACHE BOOL "" FORCE) message (STATUS "Filter ZLIB file ${ZLIB_URL} not found") endif () set (SZIP_URL ${TGZPATH}/${SZIP_TGZ_NAME}) if (NOT EXISTS "${SZIP_URL}") - set (SZIP_USE_EXTERNAL 0) + set (HDF5_ENABLE_SZIP_SUPPORT OFF CACHE BOOL "" FORCE) message (STATUS "Filter SZIP file ${SZIP_URL} not found") endif () else () -- cgit v0.12 From e272e64e7492a934c456f652ce023a8952e727b3 Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Tue, 5 Feb 2019 17:04:04 -0600 Subject: Modification based on feedback from pull request. --- src/H5C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5C.c b/src/H5C.c index d53e0ca..c1d9d17 100644 --- a/src/H5C.c +++ b/src/H5C.c @@ -327,7 +327,7 @@ H5C_create(size_t max_cache_size, /* Tagging Field Initializations */ cache_ptr->ignore_tags = FALSE; - cache_ptr->num_objs_corked = FALSE; + cache_ptr->num_objs_corked = 0; cache_ptr->slist_changed = FALSE; cache_ptr->slist_len = 0; -- cgit v0.12 From 7d124cb7961ad0089aa6a18e1c2e08e351d8ba86 Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Tue, 5 Feb 2019 18:13:11 -0600 Subject: Modification based on feedback from pull request. --- src/H5AC.c | 5 +++++ src/H5Cprivate.h | 2 +- src/H5Ctag.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/H5AC.c b/src/H5AC.c index 4801194..440dfd8 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -2403,6 +2403,11 @@ H5AC_cork(H5F_t *f, haddr_t obj_addr, unsigned action, hbool_t *corked) HDassert(H5F_addr_defined(obj_addr)); HDassert(action == H5AC__SET_CORK || action == H5AC__UNCORK || action == H5AC__GET_CORKED); + /* Skip the search on "tag_list" when there are no "corked" objects. + * This is done to mitigate the slow down when closing objects. + * Re-visit this optimization when we optimize tag info management + * in the future. + */ if(action == H5AC__GET_CORKED) { HDassert(corked); if(H5C_get_num_objs_corked(f->shared->cache) == 0) { diff --git a/src/H5Cprivate.h b/src/H5Cprivate.h index ee2d033..d4ed6fc 100644 --- a/src/H5Cprivate.h +++ b/src/H5Cprivate.h @@ -2301,7 +2301,7 @@ H5_DLL herr_t H5C_validate_resize_config(H5C_auto_size_ctl_t *config_ptr, unsigned int tests); H5_DLL herr_t H5C_ignore_tags(H5C_t *cache_ptr); H5_DLL hbool_t H5C_get_ignore_tags(const H5C_t *cache_ptr); -H5_DLL hbool_t H5C_get_num_objs_corked(const H5C_t *cache_ptr); +H5_DLL uint32_t H5C_get_num_objs_corked(const H5C_t *cache_ptr); H5_DLL herr_t H5C_retag_entries(H5C_t * cache_ptr, haddr_t src_tag, haddr_t dest_tag); H5_DLL herr_t H5C_cork(H5C_t *cache_ptr, haddr_t obj_addr, unsigned action, hbool_t *corked); H5_DLL herr_t H5C_get_entry_ring(const H5F_t *f, haddr_t addr, H5C_ring_t *ring); diff --git a/src/H5Ctag.c b/src/H5Ctag.c index 611ff37..807e68d 100644 --- a/src/H5Ctag.c +++ b/src/H5Ctag.c @@ -185,7 +185,7 @@ H5C_get_ignore_tags(const H5C_t *cache_ptr) * *------------------------------------------------------------------------- */ -hbool_t +uint32_t H5C_get_num_objs_corked(const H5C_t *cache_ptr) { FUNC_ENTER_NOAPI_NOERR -- cgit v0.12 From ee9771425f63c04da117827751755bb19132e974 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 08:37:11 -0600 Subject: Update to example reference version --- config/cmake/scripts/HDF5options.cmake | 2 +- config/cmake/scripts/HPC/par-HDF5options.cmake | 2 +- config/cmake/scripts/HPC/ser-HDF5options.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/cmake/scripts/HDF5options.cmake b/config/cmake/scripts/HDF5options.cmake index d4cc996..bce188a 100644 --- a/config/cmake/scripts/HDF5options.cmake +++ b/config/cmake/scripts/HDF5options.cmake @@ -69,7 +69,7 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRIN #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") #### package examples #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.10.9-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.12.4-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") ############################################################################################# ### enable parallel builds diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake index 5386373..3158d01 100644 --- a/config/cmake/scripts/HPC/par-HDF5options.cmake +++ b/config/cmake/scripts/HPC/par-HDF5options.cmake @@ -69,7 +69,7 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") #### package examples #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.10.9-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.12.4-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") ############################################################################################# ### enable parallel builds diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake index f935efc..d30bab0 100644 --- a/config/cmake/scripts/HPC/ser-HDF5options.cmake +++ b/config/cmake/scripts/HPC/ser-HDF5options.cmake @@ -69,7 +69,7 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRIN #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") #### package examples #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.10.9-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.12.4-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") ############################################################################################# ### enable parallel builds -- cgit v0.12 From a476f5348edda24816d24891433330c89e470947 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 08:38:55 -0600 Subject: Update examples version --- config/cmake/HDF518_Examples.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmake/HDF518_Examples.cmake.in b/config/cmake/HDF518_Examples.cmake.in index ba79ef2..231ab1b 100644 --- a/config/cmake/HDF518_Examples.cmake.in +++ b/config/cmake/HDF518_Examples.cmake.in @@ -70,7 +70,7 @@ set(BUILD_OPTIONS "${BUILD_OPTIONS} -DSITE:STRING=${CTEST_SITE} -DBUILDNAME:STRI #TAR_SOURCE - name of tarfile #if(NOT DEFINED TAR_SOURCE) -# set(CTEST_USE_TAR_SOURCE "HDF5Examples-1.2.1-Source") +# set(CTEST_USE_TAR_SOURCE "HDF5Examples-1.10.13-Source") #endif() ############################################################################################################### -- cgit v0.12 From 3ebfd7edd4546febcff2b521a3ca56a965cd9fa0 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 08:45:59 -0600 Subject: Remove obsolete file --- CMakeInstallation.cmake | 2 +- MANIFEST | 1 - config/cmake/HDF518_Examples.cmake.in | 106 ---------------------------------- 3 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 config/cmake/HDF518_Examples.cmake.in diff --git a/CMakeInstallation.cmake b/CMakeInstallation.cmake index 464477b..7a0746a 100644 --- a/CMakeInstallation.cmake +++ b/CMakeInstallation.cmake @@ -134,7 +134,7 @@ install ( ) #----------------------------------------------------------------------------- -# Configure the HDF518_Examples.cmake file and the examples +# Configure the HDF5_Examples.cmake file and the examples #----------------------------------------------------------------------------- option (HDF5_PACK_EXAMPLES "Package the HDF5 Library Examples Compressed File" OFF) if (HDF5_PACK_EXAMPLES) diff --git a/MANIFEST b/MANIFEST index 52770fd..5af06ac 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3259,7 +3259,6 @@ # CMake-specific Examples Files ./config/cmake/HDF5_Examples.cmake.in -./config/cmake/HDF518_Examples.cmake.in ./release_docs/USING_CMake_Examples.txt ./CMakeLists.txt diff --git a/config/cmake/HDF518_Examples.cmake.in b/config/cmake/HDF518_Examples.cmake.in deleted file mode 100644 index 231ab1b..0000000 --- a/config/cmake/HDF518_Examples.cmake.in +++ /dev/null @@ -1,106 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the COPYING file, which can be found at the root of the source code -# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# -cmake_minimum_required (VERSION 3.10) -############################################################################################################### -# This script will build and run the examples from a folder -# Execute from a command line: -# ctest -S HDF518_Examples.cmake,OPTION=VALUE -C Release -VV -O test.log -############################################################################################################### - -set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@") -if("@CMAKE_GENERATOR_TOOLSET@") - set(CMAKE_GENERATOR_TOOLSET "@CMAKE_GENERATOR_TOOLSET@") -endif() -set(CTEST_DASHBOARD_ROOT ${CTEST_SCRIPT_DIRECTORY}) - -# handle input parameters to script. -#INSTALLDIR - HDF5-1.8 root folder -#CTEST_CONFIGURATION_TYPE - Release, Debug, RelWithDebInfo -#CTEST_SOURCE_NAME - name of source folder; HDF5Examples -if(DEFINED CTEST_SCRIPT_ARG) - # transform ctest script arguments of the form - # script.ctest,var1=value1,var2=value2 - # to variables with the respective names set to the respective values - string(REPLACE "," ";" script_args "${CTEST_SCRIPT_ARG}") - foreach(current_var ${script_args}) - if("${current_var}" MATCHES "^([^=]+)=(.+)$") - set("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") - endif() - endforeach() -endif() - -################################################################### -### Following Line is one of [Release, RelWithDebInfo, Debug] ##### -set(CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}") -if(NOT DEFINED CTEST_CONFIGURATION_TYPE) - set(CTEST_CONFIGURATION_TYPE "Release") -endif() -set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCTEST_CONFIGURATION_TYPE:STRING=${CTEST_CONFIGURATION_TYPE}") -################################################################## - -if(NOT DEFINED INSTALLDIR) - set(INSTALLDIR "C:/Program Files/HDF_Group/@HDF5_PACKAGE_NAME@/@HDF5_PACKAGE_VERSION@") -endif() - -if(NOT DEFINED CTEST_SOURCE_NAME) - set(CTEST_SOURCE_NAME "HDF5Examples") -endif() - -if(NOT DEFINED HDF_LOCAL) - set(CDASH_LOCAL "NO") -else() - set(CDASH_LOCAL "YES") -endif() -if(NOT DEFINED CTEST_SITE) - set(CTEST_SITE "local") -endif() -if(NOT DEFINED CTEST_BUILD_NAME) - set(CTEST_BUILD_NAME "examples") -endif() -set(BUILD_OPTIONS "${BUILD_OPTIONS} -DSITE:STRING=${CTEST_SITE} -DBUILDNAME:STRING=${CTEST_BUILD_NAME}") - -#TAR_SOURCE - name of tarfile -#if(NOT DEFINED TAR_SOURCE) -# set(CTEST_USE_TAR_SOURCE "HDF5Examples-1.10.13-Source") -#endif() - -############################################################################################################### -if(WIN32) - set(SITE_OS_NAME "Windows") - set(ENV{HDF5_DIR} "${INSTALLDIR}/cmake") - set(CTEST_BINARY_NAME ${CTEST_SOURCE_NAME}\\build) - set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}\\${CTEST_SOURCE_NAME}") - set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}\\${CTEST_BINARY_NAME}") -else() - set(ENV{HDF5_DIR} "${INSTALLDIR}/share/cmake") - set(ENV{LD_LIBRARY_PATH} "${INSTALLDIR}/lib") - set(CTEST_BINARY_NAME ${CTEST_SOURCE_NAME}/build) - set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${CTEST_SOURCE_NAME}") - set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${CTEST_BINARY_NAME}") -endif() -if(${CDASH_LOCAL}) - set(BUILD_OPTIONS "${BUILD_OPTIONS} -DCDASH_LOCAL:BOOL=ON") -endif() -set(BUILD_OPTIONS "${BUILD_OPTIONS} -DHDF5_PACKAGE_NAME:STRING=@HDF5_PACKAGE@@HDF_PACKAGE_EXT@") - -############################################################################################################### -# For any comments please contact cdashhelp@hdfgroup.org -# -############################################################################################################### - -if(WIN32) - include(${CTEST_SCRIPT_DIRECTORY}\\HDF5_Examples_options.cmake) - include(${CTEST_SCRIPT_DIRECTORY}\\CTestScript.cmake) -else() - include(${CTEST_SCRIPT_DIRECTORY}/HDF5_Examples_options.cmake) - include(${CTEST_SCRIPT_DIRECTORY}/CTestScript.cmake) -endif() -- cgit v0.12 From e73197077babe31076713c73bcb6c0255693d73a Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 10:10:46 -0600 Subject: Remove F2003 Option and references --- CMakeLists.txt | 9 +--- config/cmake/scripts/HDF5options.cmake | 4 -- config/cmake/scripts/HPC/par-HDF5options.cmake | 4 -- config/cmake/scripts/HPC/ser-HDF5options.cmake | 4 -- fortran/examples/CMakeTests.cmake | 60 +++++++++++----------- fortran/examples/run-fortran-ex.sh.in | 18 ++----- fortran/src/CMakeLists.txt | 6 +-- fortran/test/CMakeTests.cmake | 70 ++++++++++++-------------- 8 files changed, 68 insertions(+), 107 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85f701e..da44ae1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -835,9 +835,6 @@ set (H5_FC_FUNC_ "H5_FC_FUNC_(name,NAME) name ## _") if (EXISTS "${HDF5_SOURCE_DIR}/fortran" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/fortran") option (HDF5_BUILD_FORTRAN "Build FORTRAN support" OFF) if (HDF5_BUILD_FORTRAN) - - option (HDF5_ENABLE_F2003 "Enable FORTRAN 2003 Standard" ON) - include (${HDF_RESOURCES_EXT_DIR}/HDFUseFortran.cmake) message (STATUS "Fortran compiler ID is ${CMAKE_Fortran_COMPILER_ID}") @@ -850,10 +847,8 @@ if (EXISTS "${HDF5_SOURCE_DIR}/fortran" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/for include (${HDF_RESOURCES_DIR}/HDF5UseFortran.cmake) set (LINK_Fortran_LIBS ${LINK_LIBS}) - if (HDF5_ENABLE_F2003) - if (NOT FORTRAN_HAVE_ISO_C_BINDING) - set (HDF5_ENABLE_F2003 OFF) - endif () + if (NOT FORTRAN_HAVE_ISO_C_BINDING) + message (FATAL_ERROR " **** Fortran compiler lacks required Fortran 2003 features; unsupported Fortran 2003 compiler, disable HDF5_BUILD_FORTRAN **** ") endif () # Parallel IO usage requires MPI to be Linked and Included diff --git a/config/cmake/scripts/HDF5options.cmake b/config/cmake/scripts/HDF5options.cmake index bce188a..45877d7 100644 --- a/config/cmake/scripts/HDF5options.cmake +++ b/config/cmake/scripts/HDF5options.cmake @@ -33,12 +33,8 @@ ############################################################################################# #### fortran enabled #### #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=ON") #### fortran disabled #### set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=OFF") ############################################################################################# #### java enabled #### diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake index 3158d01..c7b22b9 100644 --- a/config/cmake/scripts/HPC/par-HDF5options.cmake +++ b/config/cmake/scripts/HPC/par-HDF5options.cmake @@ -33,12 +33,8 @@ set (MAX_PROC_COUNT 8) ############################################################################################# #### fortran enabled #### set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=ON") #### fortran disabled #### #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=OFF") ############################################################################################# #### java enabled #### diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake index d30bab0..7f2e96f 100644 --- a/config/cmake/scripts/HPC/ser-HDF5options.cmake +++ b/config/cmake/scripts/HPC/ser-HDF5options.cmake @@ -33,12 +33,8 @@ ############################################################################################# #### fortran enabled #### #set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=ON") #### fortran disabled #### set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") - ### enable Fortran 2003 depends on HDF5_BUILD_FORTRAN -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_F2003:BOOL=OFF") ############################################################################################# #### java enabled #### diff --git a/fortran/examples/CMakeTests.cmake b/fortran/examples/CMakeTests.cmake index c3d94b4..323cf91 100644 --- a/fortran/examples/CMakeTests.cmake +++ b/fortran/examples/CMakeTests.cmake @@ -109,48 +109,46 @@ foreach (example ${examples}) endif () endforeach () -if (HDF5_ENABLE_F2003) - foreach (example ${F2003_examples}) +foreach (example ${F2003_examples}) + if (HDF5_ENABLE_USING_MEMCHECKER) + add_test (NAME f03_ex_${example} COMMAND $) + else () + add_test (NAME f03_ex_${example} COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=f03_ex_${example}.txt" + #-D "TEST_REFERENCE=f03_ex_${example}.out" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + endif () + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (f03_ex_${example} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "f03_ex_${example}") + if (BUILD_SHARED_LIBS) if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME f03_ex_${example} COMMAND $) + add_test (NAME f03_ex-shared_${example} COMMAND $) else () - add_test (NAME f03_ex_${example} COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$" + add_test (NAME f03_ex-shared_${example} COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$" -D "TEST_ARGS:STRING=" -D "TEST_EXPECT=0" -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_OUTPUT=f03_ex_${example}.txt" - #-D "TEST_REFERENCE=f03_ex_${example}.out" + -D "TEST_OUTPUT=f03_ex_${example}-shared.txt" + #-D "TEST_REFERENCE=f03_ex_${example}-shared.out" -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" ) endif () if (NOT "${last_test}" STREQUAL "") - set_tests_properties (f03_ex_${example} PROPERTIES DEPENDS ${last_test}) + set_tests_properties (f03_ex-shared_${example} PROPERTIES DEPENDS ${last_test}) endif () - set (last_test "f03_ex_${example}") - if (BUILD_SHARED_LIBS) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME f03_ex-shared_${example} COMMAND $) - else () - add_test (NAME f03_ex-shared_${example} COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$" - -D "TEST_ARGS:STRING=" - -D "TEST_EXPECT=0" - -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_OUTPUT=f03_ex_${example}-shared.txt" - #-D "TEST_REFERENCE=f03_ex_${example}-shared.out" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (f03_ex-shared_${example} PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "f03_ex-shared_${example}") - endif () - endforeach () -endif () + set (last_test "f03_ex-shared_${example}") + endif () +endforeach () if (H5_HAVE_PARALLEL AND MPI_Fortran_FOUND) add_test (NAME f90_ex_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) diff --git a/fortran/examples/run-fortran-ex.sh.in b/fortran/examples/run-fortran-ex.sh.in index da0c357..aa17f89 100644 --- a/fortran/examples/run-fortran-ex.sh.in +++ b/fortran/examples/run-fortran-ex.sh.in @@ -61,8 +61,6 @@ RunTest() ./$TEST_EXEC } -F2003_ENABLED=@HAVE_FORTRAN_2003@ - ################## MAIN ################## # Run tests @@ -97,17 +95,8 @@ then RunTest mountexample &&\ rm mountexample &&\ RunTest compound &&\ - rm compound); then - EXIT_VALUE=${EXIT_SUCCESS} - else - EXIT_VALUE=${EXIT_FAILURE} - fi -fi - -if [ $EXIT_VALUE -eq ${EXIT_SUCCESS} -a "$F2003_ENABLED" = "yes" ] -then -# Add attention tests for Fortran 2003 features - if (RunTest rwdset_fortran2003 &&\ + rm compound &&\ + RunTest rwdset_fortran2003 &&\ rm rwdset_fortran2003 &&\ RunTest nested_derived_type &&\ rm nested_derived_type &&\ @@ -120,12 +109,11 @@ then EXIT_VALUE=${EXIT_FAILURE} fi fi - # Cleanup rm *.o rm *.h5 echo -exit $EXIT_VALUE +exit $EXIT_VALUE diff --git a/fortran/src/CMakeLists.txt b/fortran/src/CMakeLists.txt index 025fab5..f71e820 100644 --- a/fortran/src/CMakeLists.txt +++ b/fortran/src/CMakeLists.txt @@ -9,11 +9,7 @@ if (WIN32) if (NOT H5_HAVE_PARALLEL) set (H5_NOPAREXP ";") endif () - if (NOT HDF5_ENABLE_F2003) - set (H5_NOF03EXP ";") - else () - set (H5_F03EXP ";") - endif () + set (H5_F03EXP ";") configure_file (${HDF5_F90_SRC_SOURCE_DIR}/hdf5_fortrandll.def.in ${HDF5_F90_SRC_BINARY_DIR}/hdf5_fortrandll.def @ONLY) endif () endif () diff --git a/fortran/test/CMakeTests.cmake b/fortran/test/CMakeTests.cmake index 4d06359..2824ef7 100644 --- a/fortran/test/CMakeTests.cmake +++ b/fortran/test/CMakeTests.cmake @@ -103,26 +103,24 @@ endif () set_tests_properties (FORTRAN_testhdf5_fortran_1_8 PROPERTIES DEPENDS FORTRAN_testhdf5_fortran) #-- Adding test for fortranlib_test_F03 -if (HDF5_ENABLE_F2003) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME FORTRAN_fortranlib_test_F03 COMMAND $) - else () - add_test (NAME FORTRAN_fortranlib_test_F03 COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$" - -D "TEST_ARGS:STRING=" - -D "TEST_EXPECT=0" - -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_REGEX= 0 error.s." - -D "TEST_MATCH= 0 error(s)" - -D "TEST_OUTPUT=fortranlib_test_F03.txt" - #-D "TEST_REFERENCE=fortranlib_test_F03.out" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () +if (HDF5_ENABLE_USING_MEMCHECKER) + add_test (NAME FORTRAN_fortranlib_test_F03 COMMAND $) +else () + add_test (NAME FORTRAN_fortranlib_test_F03 COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_REGEX= 0 error.s." + -D "TEST_MATCH= 0 error(s)" + -D "TEST_OUTPUT=fortranlib_test_F03.txt" + #-D "TEST_REFERENCE=fortranlib_test_F03.out" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) +endif () # set_tests_properties (FORTRAN_fortranlib_test_F03 PROPERTIES PASS_REGULAR_EXPRESSION "[ ]*0 error.s") set_tests_properties (FORTRAN_fortranlib_test_F03 PROPERTIES DEPENDS FORTRAN_testhdf5_fortran_1_8) -endif () #-- Adding test for fflush1 add_test (NAME FORTRAN_fflush1 COMMAND $) @@ -215,26 +213,24 @@ if (BUILD_SHARED_LIBS) set_tests_properties (FORTRAN_testhdf5_fortran_1_8-shared PROPERTIES DEPENDS FORTRAN_testhdf5_fortran_1_8) #-- Adding test for fortranlib_test_F03 - if (HDF5_ENABLE_F2003) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME FORTRAN_fortranlib_test_F03-shared COMMAND $) - else () - add_test (NAME FORTRAN_fortranlib_test_F03-shared COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$" - -D "TEST_ARGS:STRING=" - -D "TEST_EXPECT=0" - -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_REGEX= 0 error.s." - -D "TEST_MATCH= 0 error(s)" - -D "TEST_OUTPUT=fortranlib_test_F03.txt" - #-D "TEST_REFERENCE=fortranlib_test_F03.out" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/fshared" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () -# set_tests_properties (FORTRAN_fortranlib_test_F03-shared PROPERTIES PASS_REGULAR_EXPRESSION "[ ]*0 error.s") - set_tests_properties (FORTRAN_fortranlib_test_F03-shared PROPERTIES DEPENDS FORTRAN_fortranlib_test_F03) + if (HDF5_ENABLE_USING_MEMCHECKER) + add_test (NAME FORTRAN_fortranlib_test_F03-shared COMMAND $) + else () + add_test (NAME FORTRAN_fortranlib_test_F03-shared COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_REGEX= 0 error.s." + -D "TEST_MATCH= 0 error(s)" + -D "TEST_OUTPUT=fortranlib_test_F03.txt" + #-D "TEST_REFERENCE=fortranlib_test_F03.out" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/fshared" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) endif () +# set_tests_properties (FORTRAN_fortranlib_test_F03-shared PROPERTIES PASS_REGULAR_EXPRESSION "[ ]*0 error.s") + set_tests_properties (FORTRAN_fortranlib_test_F03-shared PROPERTIES DEPENDS FORTRAN_fortranlib_test_F03) #-- Adding test for fflush1 add_test (NAME FORTRAN_fflush1-shared COMMAND $) -- cgit v0.12 From 7f5741825db0737db5ac46c43009681508a73002 Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Wed, 6 Feb 2019 10:48:30 -0600 Subject: Add release notes information. --- release_docs/RELEASE.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 20abad9..21a64c6 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -264,6 +264,16 @@ Bug Fixes since HDF5-1.10.3 release Library ------- + - Performance issue when closing an object + + The slow down is due to the search of the "tag_list" to find + out the "corked" status of an object and "uncork" it if so. + + Improve porformance by skipping the search of the "tag_list" + if there are no "corked" objects when closing an object. + + (VC - 2019/2/6) + - Fixed a potential invalid memory access and failure that could occur when decoding an unknown object header message (from a future version of the library). -- cgit v0.12 From 5ba4266a046b58e8c56ef2f0e26a648e541763b9 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 11:02:16 -0600 Subject: Correct name of variable --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da44ae1..d6adc9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -847,7 +847,7 @@ if (EXISTS "${HDF5_SOURCE_DIR}/fortran" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/for include (${HDF_RESOURCES_DIR}/HDF5UseFortran.cmake) set (LINK_Fortran_LIBS ${LINK_LIBS}) - if (NOT FORTRAN_HAVE_ISO_C_BINDING) + if (NOT H5_FORTRAN_HAVE_ISO_C_BINDING) message (FATAL_ERROR " **** Fortran compiler lacks required Fortran 2003 features; unsupported Fortran 2003 compiler, disable HDF5_BUILD_FORTRAN **** ") endif () -- cgit v0.12 From 36e3d1600a3f9d771cfb9b4475f23c57d4b10280 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 6 Feb 2019 16:41:58 -0600 Subject: Refactor out timeout values --- CMakeLists.txt | 5 +++++ c++/test/CMakeVFDTests.cmake | 2 +- test/CMakeTests.cmake | 20 ++++++++++---------- test/CMakeVFDTests.cmake | 12 ++++++------ test/CMakeVOLTests.cmake | 12 ++++++------ tools/test/perform/CMakeTests.cmake | 2 +- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6adc9a..b9cdf4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -758,6 +758,11 @@ if (BUILD_TESTING) "Timeout in seconds for each test (default 1200=20minutes)" ) + # Generate a list of timeouts based on DART_TESTING_TIMEOUT + math (EXPR CTEST_SHORT_TIMEOUT "${DART_TESTING_TIMEOUT} / 2") + math (EXPR CTEST_LONG_TIMEOUT "${DART_TESTING_TIMEOUT} * 2") + math (EXPR CTEST_VERY_LONG_TIMEOUT "${DART_TESTING_TIMEOUT} * 3") + option (HDF5_TEST_VFD "Execute tests with different VFDs" OFF) mark_as_advanced (HDF5_TEST_VFD) if (HDF5_TEST_VFD) diff --git a/c++/test/CMakeVFDTests.cmake b/c++/test/CMakeVFDTests.cmake index 996a20f..6a8ce2c 100644 --- a/c++/test/CMakeVFDTests.cmake +++ b/c++/test/CMakeVFDTests.cmake @@ -55,7 +55,7 @@ -P "${HDF_RESOURCES_DIR}/vfdTest.cmake" ) set_tests_properties (CPP_VFD-${vfdname}-cpp_testhdf5 PROPERTIES DEPENDS CPP_VFD-${vfdname}-cpp_testhdf5-clear-objects) - set_tests_properties (CPP_VFD-${vfdname}-cpp_testhdf5 PROPERTIES TIMEOUT 30) + set_tests_properties (CPP_VFD-${vfdname}-cpp_testhdf5 PROPERTIES TIMEOUT ${CTEST_SHORT_TIMEOUT}) endif () endmacro () diff --git a/test/CMakeTests.cmake b/test/CMakeTests.cmake index 087461f..ba72e3a 100644 --- a/test/CMakeTests.cmake +++ b/test/CMakeTests.cmake @@ -587,10 +587,10 @@ foreach (test ${H5_TESTS}) endif () endforeach () -set_tests_properties (H5TEST-fheap PROPERTIES TIMEOUT 1800) -set_tests_properties (H5TEST-big PROPERTIES TIMEOUT 1800) -set_tests_properties (H5TEST-btree2 PROPERTIES TIMEOUT 1800) -set_tests_properties (H5TEST-objcopy PROPERTIES TIMEOUT 1800) +set_tests_properties (H5TEST-fheap PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) +set_tests_properties (H5TEST-big PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) +set_tests_properties (H5TEST-btree2 PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) +set_tests_properties (H5TEST-objcopy PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) if (BUILD_SHARED_LIBS) # Remove any output file left over from previous test run @@ -629,10 +629,10 @@ if (BUILD_SHARED_LIBS) endif () endforeach () - set_tests_properties (H5TEST-shared-fheap PROPERTIES TIMEOUT 1800) - set_tests_properties (H5TEST-shared-big PROPERTIES TIMEOUT 1800) - set_tests_properties (H5TEST-shared-btree2 PROPERTIES TIMEOUT 1800) - set_tests_properties (H5TEST-shared-objcopy PROPERTIES TIMEOUT 1800) + set_tests_properties (H5TEST-shared-fheap PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) + set_tests_properties (H5TEST-shared-big PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) + set_tests_properties (H5TEST-shared-btree2 PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) + set_tests_properties (H5TEST-shared-objcopy PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () #-- Adding test for cache @@ -664,7 +664,7 @@ if (NOT CYGWIN) ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/H5TEST;HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/H5TEST ) - set_tests_properties (H5TEST-cache PROPERTIES TIMEOUT 1800) + set_tests_properties (H5TEST-cache PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () #-- Adding test for cache_image @@ -714,7 +714,7 @@ if (BUILD_SHARED_LIBS) ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/H5TEST-shared;HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/H5TEST-shared ) - set_tests_properties (H5TEST-shared-cache PROPERTIES TIMEOUT 1800) + set_tests_properties (H5TEST-shared-cache PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () endif () diff --git a/test/CMakeVFDTests.cmake b/test/CMakeVFDTests.cmake index be02110..9f03c40 100644 --- a/test/CMakeVFDTests.cmake +++ b/test/CMakeVFDTests.cmake @@ -263,17 +263,17 @@ endif () set_tests_properties (VFD-${vfdname}-flush2 PROPERTIES DEPENDS VFD-${vfdname}-flush1) set_tests_properties (VFD-${vfdname}-flush1 PROPERTIES TIMEOUT 10) set_tests_properties (VFD-${vfdname}-flush2 PROPERTIES TIMEOUT 10) - set_tests_properties (VFD-${vfdname}-istore PROPERTIES TIMEOUT 1800) + set_tests_properties (VFD-${vfdname}-istore PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) if (NOT CYGWIN) - set_tests_properties (VFD-${vfdname}-cache PROPERTIES TIMEOUT 1800) + set_tests_properties (VFD-${vfdname}-cache PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () if (BUILD_SHARED_LIBS) set_tests_properties (VFD-${vfdname}-flush2-shared PROPERTIES DEPENDS VFD-${vfdname}-flush1-shared) set_tests_properties (VFD-${vfdname}-flush1-shared PROPERTIES TIMEOUT 10) set_tests_properties (VFD-${vfdname}-flush2-shared PROPERTIES TIMEOUT 10) - set_tests_properties (VFD-${vfdname}-istore-shared PROPERTIES TIMEOUT 1800) + set_tests_properties (VFD-${vfdname}-istore-shared PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) if (NOT CYGWIN AND NOT WIN32) - set_tests_properties (VFD-${vfdname}-cache-shared PROPERTIES TIMEOUT 1800) + set_tests_properties (VFD-${vfdname}-cache-shared PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () endif () if (HDF5_TEST_FHEAP_VFD) @@ -288,7 +288,7 @@ endif () -P "${HDF_RESOURCES_DIR}/vfdTest.cmake" ) set_tests_properties (VFD-${vfdname}-fheap PROPERTIES - TIMEOUT 1800 + TIMEOUT ${CTEST_VERY_LONG_TIMEOUT} ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/${vfdname};HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/${vfdname} ) @@ -304,7 +304,7 @@ endif () -P "${HDF_RESOURCES_DIR}/vfdTest.cmake" ) set_tests_properties (VFD-${vfdname}-fheap-shared PROPERTIES - TIMEOUT 1800 + TIMEOUT ${CTEST_VERY_LONG_TIMEOUT} ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/${vfdname}-shared;HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/${vfdname}-shared ) diff --git a/test/CMakeVOLTests.cmake b/test/CMakeVOLTests.cmake index 39fa2a6..fdd7ba0 100644 --- a/test/CMakeVOLTests.cmake +++ b/test/CMakeVOLTests.cmake @@ -262,17 +262,17 @@ endif () set_tests_properties (VOL-${volname}-flush2 PROPERTIES DEPENDS VOL-${volname}-flush1) set_tests_properties (VOL-${volname}-flush1 PROPERTIES TIMEOUT 10) set_tests_properties (VOL-${volname}-flush2 PROPERTIES TIMEOUT 10) - set_tests_properties (VOL-${volname}-istore PROPERTIES TIMEOUT 1800) + set_tests_properties (VOL-${volname}-istore PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) if (NOT CYGWIN) - set_tests_properties (VOL-${volname}-cache PROPERTIES TIMEOUT 1800) + set_tests_properties (VOL-${volname}-cache PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () if (BUILD_SHARED_LIBS) set_tests_properties (VOL-${volname}-flush2-shared PROPERTIES DEPENDS VOL-${volname}-flush1-shared) set_tests_properties (VOL-${volname}-flush1-shared PROPERTIES TIMEOUT 10) set_tests_properties (VOL-${volname}-flush2-shared PROPERTIES TIMEOUT 10) - set_tests_properties (VOL-${volname}-istore-shared PROPERTIES TIMEOUT 1800) + set_tests_properties (VOL-${volname}-istore-shared PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) if (NOT CYGWIN AND NOT WIN32) - set_tests_properties (VOL-${volname}-cache-shared PROPERTIES TIMEOUT 1800) + set_tests_properties (VOL-${volname}-cache-shared PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) endif () endif () if (HDF5_TEST_FHEAP_VOL) @@ -287,7 +287,7 @@ endif () -P "${HDF_RESOURCES_DIR}/volTest.cmake" ) set_tests_properties (VOL-${volname}-fheap PROPERTIES - TIMEOUT 1800 + TIMEOUT ${CTEST_VERY_LONG_TIMEOUT} ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/${volname};HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/${volname} ) @@ -303,7 +303,7 @@ endif () -P "${HDF_RESOURCES_DIR}/volTest.cmake" ) set_tests_properties (VOL-${volname}-fheap-shared PROPERTIES - TIMEOUT 1800 + TIMEOUT ${CTEST_VERY_LONG_TIMEOUT} ENVIRONMENT "srcdir=${HDF5_TEST_BINARY_DIR}/${volname}-shared;HDF5TestExpress=${HDF_TEST_EXPRESS}" WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/${volname}-shared ) diff --git a/tools/test/perform/CMakeTests.cmake b/tools/test/perform/CMakeTests.cmake index 450667a..5abd038 100644 --- a/tools/test/perform/CMakeTests.cmake +++ b/tools/test/perform/CMakeTests.cmake @@ -66,7 +66,7 @@ else () -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" ) endif () -set_tests_properties (PERFORM_h5perf_serial PROPERTIES TIMEOUT 1800) +set_tests_properties (PERFORM_h5perf_serial PROPERTIES TIMEOUT ${CTEST_VERY_LONG_TIMEOUT}) set_tests_properties (PERFORM_h5perf_serial PROPERTIES DEPENDS "PERFORM_h5perform-clearall-objects") if (HDF5_BUILD_PERFORM_STANDALONE) -- cgit v0.12 From 163dcebec5d853b720dcb64b5e9828670b963773 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 7 Feb 2019 14:31:26 -0600 Subject: Add ID type (of eventual hid_t) to the VOL "wrap" callback. --- src/H5VLcallback.c | 11 ++++++----- src/H5VLint.c | 10 +++++----- src/H5VLpassthru.c | 7 ++++--- src/H5VLprivate.h | 2 +- src/H5VLpublic.h | 6 ++++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 811162d..2d6ac33 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -829,7 +829,8 @@ done: *------------------------------------------------------------------------- */ void * -H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj) +H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, + H5I_type_t obj_type) { void *ret_value = SUCCEED; /* Return value */ @@ -842,7 +843,7 @@ H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj) /* Only wrap object if there's a wrap context */ if(wrap_ctx) { /* Ask the connector to wrap the object */ - if(NULL == (ret_value = (connector->wrap_object)(obj, wrap_ctx))) + if(NULL == (ret_value = (connector->wrap_object)(obj, obj_type, wrap_ctx))) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") } /* end if */ else @@ -864,13 +865,13 @@ done: *--------------------------------------------------------------------------- */ void * -H5VLwrap_object(void *obj, hid_t connector_id, void *wrap_ctx) +H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx) { H5VL_class_t *cls; /* VOL connector's class struct */ void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE3("*x", "*xi*x", obj, connector_id, wrap_ctx); + H5TRACE4("*x", "*xIti*x", obj, obj_type, connector_id, wrap_ctx); /* Check args and get class pointer */ if(NULL == obj) @@ -879,7 +880,7 @@ H5VLwrap_object(void *obj, hid_t connector_id, void *wrap_ctx) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") /* Wrap the object */ - if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj))) + if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj, obj_type))) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to wrap object") done: diff --git a/src/H5VLint.c b/src/H5VLint.c index bdb2908..f22fdb6 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -65,7 +65,7 @@ typedef struct H5VL_wrap_ctx_t { /* Local Prototypes */ /********************/ static herr_t H5VL__free_cls(H5VL_class_t *cls); -static void *H5VL__wrap_obj(void *obj); +static void *H5VL__wrap_obj(void *obj, H5I_type_t obj_type); static H5VL_object_t *H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t wrap_obj); static void *H5VL__object(hid_t id, H5I_type_t obj_type); @@ -248,7 +248,7 @@ done: *------------------------------------------------------------------------- */ static void * -H5VL__wrap_obj(void *obj) +H5VL__wrap_obj(void *obj, H5I_type_t obj_type) { H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */ void *ret_value = NULL; /* Return value */ @@ -265,7 +265,7 @@ H5VL__wrap_obj(void *obj) /* If there is a VOL object wrapping context, wrap the object */ if(vol_wrap_ctx) { /* Wrap object, using the VOL callback */ - if(NULL == (ret_value = H5VL_wrap_object(vol_wrap_ctx->connector->cls, vol_wrap_ctx->obj_wrap_ctx, obj))) + if(NULL == (ret_value = H5VL_wrap_object(vol_wrap_ctx->connector->cls, vol_wrap_ctx->obj_wrap_ctx, obj, obj_type))) HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") } /* end if */ else @@ -310,7 +310,7 @@ H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, NULL, "can't allocate memory for VOL object") new_vol_obj->connector = vol_connector; if(wrap_obj) { - if(NULL == (new_vol_obj->data = H5VL__wrap_obj(object))) + if(NULL == (new_vol_obj->data = H5VL__wrap_obj(object, type))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "can't wrap library object") } /* end if */ else @@ -1099,7 +1099,7 @@ H5VL_wrap_register(H5I_type_t type, void *obj, hbool_t app_ref) HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, H5I_INVALID_HID, "can't wrap an uncommitted datatype") /* Wrap the object with VOL connector info */ - if(NULL == (new_obj = H5VL__wrap_obj(obj))) + if(NULL == (new_obj = H5VL__wrap_obj(obj, type))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, H5I_INVALID_HID, "can't wrap library object") /* Retrieve the VOL object wrapping context */ diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 13d8d8e..f7f9058 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -90,7 +90,8 @@ static herr_t H5VL_pass_through_str_to_info(const char *str, void **info); static void *H5VL_pass_through_get_object(const void *obj); static herr_t H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx); static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); -static void *H5VL_pass_through_wrap_object(void *obj, void *wrap_ctx); +static void *H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, + void *wrap_ctx); /* Attribute callbacks */ static void *H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); @@ -660,7 +661,7 @@ H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx) *--------------------------------------------------------------------------- */ static void * -H5VL_pass_through_wrap_object(void *obj, void *_wrap_ctx) +H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, void *_wrap_ctx) { H5VL_pass_through_wrap_ctx_t *wrap_ctx = (H5VL_pass_through_wrap_ctx_t *)_wrap_ctx; H5VL_pass_through_t *new_obj; @@ -671,7 +672,7 @@ H5VL_pass_through_wrap_object(void *obj, void *_wrap_ctx) #endif /* Wrap the object with the underlying VOL */ - under = H5VLwrap_object(obj, wrap_ctx->under_vol_id, wrap_ctx->under_wrap_ctx); + under = H5VLwrap_object(obj, obj_type, wrap_ctx->under_vol_id, wrap_ctx->under_wrap_ctx); if(under) new_obj = H5VL_pass_through_new_obj(under, wrap_ctx->under_vol_id); else diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index ef5a81e..283c77a 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -95,7 +95,7 @@ H5_DLL herr_t H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx); H5_DLL herr_t H5VL_set_vol_wrapper(void *obj, const H5VL_t *vol_connector); H5_DLL herr_t H5VL_reset_vol_wrapper(void); H5_DLL void * H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, - void *obj); + void *obj, H5I_type_t obj_type); /* ID registration functions */ H5_DLL hid_t H5VL_register(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t app_ref); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index dd1ed54..6ea9fc1 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -22,6 +22,7 @@ #include "H5Apublic.h" /* Attributes */ #include "H5ESpublic.h" /* Event Stack */ #include "H5Fpublic.h" /* Files */ +#include "H5Ipublic.h" /* IDs */ #include "H5Lpublic.h" /* Links */ #include "H5Opublic.h" /* Objects */ #include "H5Rpublic.h" /* References */ @@ -383,7 +384,7 @@ typedef struct H5VL_class_t { herr_t (*str_to_info)(const char *str, void **info); /* Callback to deserialize a string into connector's info */ void * (*get_object)(const void *obj); /* Callback to retrieve underlying object */ herr_t (*get_wrap_ctx)(const void *obj, void **wrap_ctx); /* Callback to retrieve the object wrapping context for the connector */ - void* (*wrap_object)(void *obj, void *wrap_ctx); /* Callback to wrap a library object */ + void* (*wrap_object)(void *obj, H5I_type_t obj_type, void *wrap_ctx); /* Callback to wrap a library object */ herr_t (*free_wrap_ctx)(void *wrap_ctx); /* Callback to release the object wrapping context for the connector */ /* Data Model */ @@ -450,7 +451,8 @@ H5_DLL herr_t H5VLconnector_info_to_str(const void *info, hid_t connector_id, ch H5_DLL herr_t H5VLconnector_str_to_info(const char *str, hid_t connector_id, void **info); H5_DLL void *H5VLget_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLget_wrap_ctx(void *obj, hid_t connector_id, void **wrap_ctx); -H5_DLL void *H5VLwrap_object(void *obj, hid_t connector_id, void *wrap_ctx); +H5_DLL void *H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, + void *wrap_ctx); H5_DLL herr_t H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id); /* Public wrappers for attribute callbacks */ -- cgit v0.12 From 28b9af4f28df6c0e4f7fbf1ce4a0f50e1797b4d3 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Thu, 7 Feb 2019 14:31:32 -0600 Subject: Fix test issue in testpar/t_dset.c with MPI-2 implementations --- release_docs/RELEASE.txt | 5 +++++ testpar/t_dset.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 21a64c6..ef3bda0 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -411,6 +411,11 @@ Bug Fixes since HDF5-1.10.3 release Testing ------- + - Fixed a test failure in testpar/t_dset.c caused by + the test trying to use the parallel filters feature + on MPI-2 implementations. + + (JTH, 2019/2/7) Bug Fixes since HDF5-1.10.2 release ================================== diff --git a/testpar/t_dset.c b/testpar/t_dset.c index 35501d8..d4e556d 100644 --- a/testpar/t_dset.c +++ b/testpar/t_dset.c @@ -2659,8 +2659,10 @@ compress_readAll(void) nerrors++; } +#if MPI_VERSION >= 3 ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer_plist, data_read); VRFY((ret >= 0), "H5Dwrite succeeded"); +#endif ret = H5Pclose(xfer_plist); VRFY((ret >= 0), "H5Pclose succeeded"); -- cgit v0.12 From d0be2f5840fcadb6f2852bbf2c35082760165388 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 8 Feb 2019 10:48:49 -0600 Subject: CMake script changes to simplify execution --- MANIFEST | 7 +- config/cmake/scripts/HDF5config.cmake | 147 +++++++++++---------- config/cmake/scripts/HPC/bsub-HDF5options.cmake | 49 +++++++ config/cmake/scripts/HPC/par-HDF5options.cmake | 126 ------------------ config/cmake/scripts/HPC/raybsub-HDF5options.cmake | 49 +++++++ config/cmake/scripts/HPC/sbatch-HDF5options.cmake | 49 +++++++ config/cmake/scripts/HPC/ser-HDF5options.cmake | 119 ----------------- 7 files changed, 231 insertions(+), 315 deletions(-) create mode 100644 config/cmake/scripts/HPC/bsub-HDF5options.cmake delete mode 100644 config/cmake/scripts/HPC/par-HDF5options.cmake create mode 100644 config/cmake/scripts/HPC/raybsub-HDF5options.cmake create mode 100644 config/cmake/scripts/HPC/sbatch-HDF5options.cmake delete mode 100644 config/cmake/scripts/HPC/ser-HDF5options.cmake diff --git a/MANIFEST b/MANIFEST index 5af06ac..2b48295 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3369,8 +3369,11 @@ ./config/cmake/scripts/CTestScript.cmake ./config/cmake/scripts/HDF5config.cmake ./config/cmake/scripts/HDF5options.cmake -./config/cmake/scripts/HPC/par-HDF5options.cmake -./config/cmake/scripts/HPC/ser-HDF5options.cmake + +# CMake-specific HPC Scripts +./config/cmake/scripts/HPC/sbatch-HDF5options.cmake +./config/cmake/scripts/HPC/bsub-HDF5options.cmake +./config/cmake/scripts/HPC/raybsub-HDF5options.cmake # Files generated by autogen ./aclocal.m4 diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index 1d8d501..fda9fcc 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -44,6 +44,8 @@ set (CTEST_SOURCE_VERSEXT "") #CTEST_CONFIGURATION_TYPE - Release, Debug, RelWithDebInfo #CTEST_SOURCE_NAME - name of source folder; HDF5-1.10.0 #MODEL - CDash group name +#HPC - run alternate configurations for HPC machines; sbatch, bsub, raybsub +#MPI - enable MPI; if (DEFINED CTEST_SCRIPT_ARG) # transform ctest script arguments of the form # script.ctest,var1=value1,var2=value2 @@ -56,6 +58,11 @@ if (DEFINED CTEST_SCRIPT_ARG) endforeach () endif () +#HPC - run alternate configurations for HPC machines +if (DEFINED HPC) + set (BUILD_GENERATOR "Unix") +endif () + # build generator must be defined if (NOT DEFINED BUILD_GENERATOR) message (FATAL_ERROR "BUILD_GENERATOR must be defined - Unix, VS2017, or VS201764, VS2015, VS201564, VS2013, VS201364") @@ -93,77 +100,81 @@ endif () ################################################################### ######### Following describes compiler ############ -if (WIN32) - set (SITE_OS_NAME "Windows") - set (SITE_OS_VERSION "WIN7") - if (${BUILD_GENERATOR} STREQUAL "VS201764") - set (CTEST_CMAKE_GENERATOR "Visual Studio 15 2017 Win64") - set (SITE_OS_BITS "64") - set (SITE_COMPILER_NAME "vs2017") - set (SITE_COMPILER_VERSION "15") - elseif (${BUILD_GENERATOR} STREQUAL "VS2017") - set (CTEST_CMAKE_GENERATOR "Visual Studio 15 2017") - set (SITE_OS_BITS "32") - set (SITE_COMPILER_NAME "vs2017") - set (SITE_COMPILER_VERSION "15") - elseif (${BUILD_GENERATOR} STREQUAL "VS201564") - set (CTEST_CMAKE_GENERATOR "Visual Studio 14 2015 Win64") - set (SITE_OS_BITS "64") - set (SITE_COMPILER_NAME "vs2015") - set (SITE_COMPILER_VERSION "14") - elseif (${BUILD_GENERATOR} STREQUAL "VS2015") - set (CTEST_CMAKE_GENERATOR "Visual Studio 14 2015") - set (SITE_OS_BITS "32") - set (SITE_COMPILER_NAME "vs2015") - set (SITE_COMPILER_VERSION "14") - elseif (${BUILD_GENERATOR} STREQUAL "VS201364") - set (CTEST_CMAKE_GENERATOR "Visual Studio 12 2013 Win64") - set (SITE_OS_BITS "64") - set (SITE_COMPILER_NAME "vs2013") - set (SITE_COMPILER_VERSION "12") - elseif (${BUILD_GENERATOR} STREQUAL "VS2013") - set (CTEST_CMAKE_GENERATOR "Visual Studio 12 2013") - set (SITE_OS_BITS "32") - set (SITE_COMPILER_NAME "vs2013") - set (SITE_COMPILER_VERSION "12") - elseif (${BUILD_GENERATOR} STREQUAL "VS201264") - set (CTEST_CMAKE_GENERATOR "Visual Studio 11 2012 Win64") - set (SITE_OS_BITS "64") - set (SITE_COMPILER_NAME "vs2012") - set (SITE_COMPILER_VERSION "11") - elseif (${BUILD_GENERATOR} STREQUAL "VS2012") - set (CTEST_CMAKE_GENERATOR "Visual Studio 11 2012") - set (SITE_OS_BITS "32") - set (SITE_COMPILER_NAME "vs2012") - set (SITE_COMPILER_VERSION "11") +if (NOT DEFINED HPC) + if (WIN32) + set (SITE_OS_NAME "Windows") + set (SITE_OS_VERSION "WIN7") + if (${BUILD_GENERATOR} STREQUAL "VS201764") + set (CTEST_CMAKE_GENERATOR "Visual Studio 15 2017 Win64") + set (SITE_OS_BITS "64") + set (SITE_COMPILER_NAME "vs2017") + set (SITE_COMPILER_VERSION "15") + elseif (${BUILD_GENERATOR} STREQUAL "VS2017") + set (CTEST_CMAKE_GENERATOR "Visual Studio 15 2017") + set (SITE_OS_BITS "32") + set (SITE_COMPILER_NAME "vs2017") + set (SITE_COMPILER_VERSION "15") + elseif (${BUILD_GENERATOR} STREQUAL "VS201564") + set (CTEST_CMAKE_GENERATOR "Visual Studio 14 2015 Win64") + set (SITE_OS_BITS "64") + set (SITE_COMPILER_NAME "vs2015") + set (SITE_COMPILER_VERSION "14") + elseif (${BUILD_GENERATOR} STREQUAL "VS2015") + set (CTEST_CMAKE_GENERATOR "Visual Studio 14 2015") + set (SITE_OS_BITS "32") + set (SITE_COMPILER_NAME "vs2015") + set (SITE_COMPILER_VERSION "14") + elseif (${BUILD_GENERATOR} STREQUAL "VS201364") + set (CTEST_CMAKE_GENERATOR "Visual Studio 12 2013 Win64") + set (SITE_OS_BITS "64") + set (SITE_COMPILER_NAME "vs2013") + set (SITE_COMPILER_VERSION "12") + elseif (${BUILD_GENERATOR} STREQUAL "VS2013") + set (CTEST_CMAKE_GENERATOR "Visual Studio 12 2013") + set (SITE_OS_BITS "32") + set (SITE_COMPILER_NAME "vs2013") + set (SITE_COMPILER_VERSION "12") + elseif (${BUILD_GENERATOR} STREQUAL "VS201264") + set (CTEST_CMAKE_GENERATOR "Visual Studio 11 2012 Win64") + set (SITE_OS_BITS "64") + set (SITE_COMPILER_NAME "vs2012") + set (SITE_COMPILER_VERSION "11") + elseif (${BUILD_GENERATOR} STREQUAL "VS2012") + set (CTEST_CMAKE_GENERATOR "Visual Studio 11 2012") + set (SITE_OS_BITS "32") + set (SITE_COMPILER_NAME "vs2012") + set (SITE_COMPILER_VERSION "11") + else () + message (FATAL_ERROR "Invalid BUILD_GENERATOR must be - Unix, VS2017, or VS201764, VS2015, VS201564, VS2013, VS201364") + endif () + ## Set the following to unique id your computer ## + set (CTEST_SITE "WIN7${BUILD_GENERATOR}.XXXX") else () - message (FATAL_ERROR "Invalid BUILD_GENERATOR must be - Unix, VS2017, or VS201764, VS2015, VS201564, VS2013, VS201364") + set (CTEST_CMAKE_GENERATOR "Unix Makefiles") + ## Set the following to unique id your computer ## + if (APPLE) + set (CTEST_SITE "MAC.XXXX") + else () + set (CTEST_SITE "LINUX.XXXX") + endif () + if (APPLE) + execute_process (COMMAND xcrun --find cc OUTPUT_VARIABLE XCODE_CC OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND xcrun --find c++ OUTPUT_VARIABLE XCODE_CXX OUTPUT_STRIP_TRAILING_WHITESPACE) + set (ENV{CC} "${XCODE_CC}") + set (ENV{CXX} "${XCODE_CXX}") + set (CTEST_USE_LAUNCHERS 1) + set (RR_WARNINGS_COMMON "-Wno-format-nonliteral -Wno-cast-align -Wno-unused -Wno-unused-variable -Wno-unused-function -Wno-self-assign -Wno-unused-parameter -Wno-sign-compare") + set (RR_WARNINGS_C "${RR_WARNINGS_COMMON} -Wno-deprecated-declarations -Wno-uninitialized") + set (RR_WARNINGS_CXX "${RR_WARNINGS_COMMON} -Woverloaded-virtual -Wshadow -Wwrite-strings -Wc++11-compat") + set (RR_FLAGS_COMMON "-g -O0 -fstack-protector-all -D_FORTIFY_SOURCE=2") + set (RR_FLAGS_C "${RR_FLAGS_COMMON}") + set (RR_FLAGS_CXX "${RR_FLAGS_COMMON}") + set (ENV{CFLAGS} "${RR_WARNINGS_C} ${RR_FLAGS_C}") + set (ENV{CXXFLAGS} "${RR_WARNINGS_CXX} ${RR_FLAGS_CXX}") + endif () endif () -## Set the following to unique id your computer ## - set (CTEST_SITE "WIN7${BUILD_GENERATOR}.XXXX") else () - set (CTEST_CMAKE_GENERATOR "Unix Makefiles") -## Set the following to unique id your computer ## - if (APPLE) - set (CTEST_SITE "MAC.XXXX") - else () - set (CTEST_SITE "LINUX.XXXX") - endif () - if (APPLE) - execute_process (COMMAND xcrun --find cc OUTPUT_VARIABLE XCODE_CC OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process (COMMAND xcrun --find c++ OUTPUT_VARIABLE XCODE_CXX OUTPUT_STRIP_TRAILING_WHITESPACE) - set (ENV{CC} "${XCODE_CC}") - set (ENV{CXX} "${XCODE_CXX}") - set (CTEST_USE_LAUNCHERS 1) - set (RR_WARNINGS_COMMON "-Wno-format-nonliteral -Wno-cast-align -Wno-unused -Wno-unused-variable -Wno-unused-function -Wno-self-assign -Wno-unused-parameter -Wno-sign-compare") - set (RR_WARNINGS_C "${RR_WARNINGS_COMMON} -Wno-deprecated-declarations -Wno-uninitialized") - set (RR_WARNINGS_CXX "${RR_WARNINGS_COMMON} -Woverloaded-virtual -Wshadow -Wwrite-strings -Wc++11-compat") - set (RR_FLAGS_COMMON "-g -O0 -fstack-protector-all -D_FORTIFY_SOURCE=2") - set (RR_FLAGS_C "${RR_FLAGS_COMMON}") - set (RR_FLAGS_CXX "${RR_FLAGS_COMMON}") - set (ENV{CFLAGS} "${RR_WARNINGS_C} ${RR_FLAGS_C}") - set (ENV{CXXFLAGS} "${RR_WARNINGS_CXX} ${RR_FLAGS_CXX}") - endif () + include (${CTEST_SOURCE_DIRECTORY}/config/cmake/scripts/HPC/${HPC}-HDF5options.cmake) endif () ################################################################### diff --git a/config/cmake/scripts/HPC/bsub-HDF5options.cmake b/config/cmake/scripts/HPC/bsub-HDF5options.cmake new file mode 100644 index 0000000..5316f41 --- /dev/null +++ b/config/cmake/scripts/HPC/bsub-HDF5options.cmake @@ -0,0 +1,49 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +############################################################################################# +#### Change default configuration of options in config/cmake/cacheinit.cmake file ### +#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### +############################################################################################# + +### uncomment/comment and change the following lines for other configuration options + +############################################################################################# +### enable parallel builds +if (DEFINED MPI) + # maximum parallel processor count for build and test #### + set (MAX_PROC_COUNT 8) + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") +endif () +############################################################################################# +### options to run test scripts in batch commands +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_TEST "TRUE") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") + +############################################################################################# +### some additions and alternatives to cross compile on haswell for knl +#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") +#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") +#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=knl_ctestP.sl") +############################################################################################# diff --git a/config/cmake/scripts/HPC/par-HDF5options.cmake b/config/cmake/scripts/HPC/par-HDF5options.cmake deleted file mode 100644 index c7b22b9..0000000 --- a/config/cmake/scripts/HPC/par-HDF5options.cmake +++ /dev/null @@ -1,126 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the COPYING file, which can be found at the root of the source code -# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# -############################################################################################# -#### Change default configuration of options in config/cmake/cacheinit.cmake file ### -#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### -############################################################################################# - -### uncomment/comment and change the following lines for other configuration options - -############################################################################################# -#### maximum parallel processor count for build and test #### -set (MAX_PROC_COUNT 8) - -############################################################################################# -#### alternate toolsets #### -#set (CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler 17.0") - -############################################################################################# -#### Only build static libraries #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF") -#### Add PICC option on linux/mac #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_ANSI_CFLAGS:STRING=-fPIC") - -############################################################################################# -#### fortran enabled #### -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") -#### fortran disabled #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") - -############################################################################################# -#### java enabled #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON") -#### java disabled #### -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") - -############################################################################################# -### change install prefix (default use INSTALLDIR value) -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALLDIR}") - -############################################################################################# -#### ext libraries #### - -### ext libs from tgz -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=${CTEST_SCRIPT_DIRECTORY}") -### ext libs from git -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=GIT") -### ext libs on system -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=NO") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DZLIB_LIBRARY:FILEPATH=some_location/lib/zlib.lib -DZLIB_INCLUDE_DIR:PATH=some_location/include") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSZIP_LIBRARY:FILEPATH=some_location/lib/szlib.lib -DSZIP_INCLUDE_DIR:PATH=some_location/include") - -### disable using ext zlib -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF") -### disable using ext szip -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") - -#### package examples #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.12.4-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") - -############################################################################################# -### enable parallel builds - -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") - -############################################################################################# -### enable thread-safety builds - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=ON") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_HL_LIB:BOOL=OFF") - -############################################################################################# -### disable test program builds - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_TESTING:BOOL=OFF") - -############################################################################################# -### disable packaging - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_NO_PACKAGES:BOOL=ON") -### Create install package with external libraries (szip, zlib) -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") - - -#options to run test scripts in batch commands -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") -set (LOCAL_BATCH_TEST "TRUE") -set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") -set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") - - -############################################################################################# -### use a toolchain file - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/crayle.cmake") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") - -#some additions and alternatives to cross compile on haswell for knl -#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") -#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") -#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=knl_ctestP.sl") -############################################################################################# diff --git a/config/cmake/scripts/HPC/raybsub-HDF5options.cmake b/config/cmake/scripts/HPC/raybsub-HDF5options.cmake new file mode 100644 index 0000000..5316f41 --- /dev/null +++ b/config/cmake/scripts/HPC/raybsub-HDF5options.cmake @@ -0,0 +1,49 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +############################################################################################# +#### Change default configuration of options in config/cmake/cacheinit.cmake file ### +#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### +############################################################################################# + +### uncomment/comment and change the following lines for other configuration options + +############################################################################################# +### enable parallel builds +if (DEFINED MPI) + # maximum parallel processor count for build and test #### + set (MAX_PROC_COUNT 8) + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") +endif () +############################################################################################# +### options to run test scripts in batch commands +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_TEST "TRUE") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") + +############################################################################################# +### some additions and alternatives to cross compile on haswell for knl +#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") +#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") +#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=knl_ctestP.sl") +############################################################################################# diff --git a/config/cmake/scripts/HPC/sbatch-HDF5options.cmake b/config/cmake/scripts/HPC/sbatch-HDF5options.cmake new file mode 100644 index 0000000..5316f41 --- /dev/null +++ b/config/cmake/scripts/HPC/sbatch-HDF5options.cmake @@ -0,0 +1,49 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +############################################################################################# +#### Change default configuration of options in config/cmake/cacheinit.cmake file ### +#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### +############################################################################################# + +### uncomment/comment and change the following lines for other configuration options + +############################################################################################# +### enable parallel builds +if (DEFINED MPI) + # maximum parallel processor count for build and test #### + set (MAX_PROC_COUNT 8) + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") + set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") +endif () +############################################################################################# +### options to run test scripts in batch commands +set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_TEST "TRUE") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") + +############################################################################################# +### some additions and alternatives to cross compile on haswell for knl +#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") +#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") +#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") +#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=knl_ctestP.sl") +############################################################################################# diff --git a/config/cmake/scripts/HPC/ser-HDF5options.cmake b/config/cmake/scripts/HPC/ser-HDF5options.cmake deleted file mode 100644 index 7f2e96f..0000000 --- a/config/cmake/scripts/HPC/ser-HDF5options.cmake +++ /dev/null @@ -1,119 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the COPYING file, which can be found at the root of the source code -# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# -############################################################################################# -#### Change default configuration of options in config/cmake/cacheinit.cmake file ### -#### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") ### -############################################################################################# - -### uncomment/comment and change the following lines for other configuration options - -############################################################################################# -#### maximum parallel processor count for build and test #### -#set (MAX_PROC_COUNT 8) - -############################################################################################# -#### alternate toolsets #### -#set (CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler 17.0") - -############################################################################################# -#### Only build static libraries #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF") -#### Add PICC option on linux/mac #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_ANSI_CFLAGS:STRING=-fPIC") - -############################################################################################# -#### fortran enabled #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") -#### fortran disabled #### -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") - -############################################################################################# -#### java enabled #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON") -#### java disabled #### -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") - -############################################################################################# -### change install prefix (default use INSTALLDIR value) -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALLDIR}") - -############################################################################################# -#### ext libraries #### - -### ext libs from tgz -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=${CTEST_SCRIPT_DIRECTORY}") -### ext libs from git -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=GIT") -### ext libs on system -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=NO") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DZLIB_LIBRARY:FILEPATH=some_location/lib/zlib.lib -DZLIB_INCLUDE_DIR:PATH=some_location/include") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSZIP_LIBRARY:FILEPATH=some_location/lib/szlib.lib -DSZIP_INCLUDE_DIR:PATH=some_location/include") - -### disable using ext zlib -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF") -### disable using ext szip -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF") - -#### package examples #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACK_EXAMPLES:BOOL=ON -DHDF5_EXAMPLES_COMPRESSED:STRING=HDF5Examples-1.12.4-Source.tar.gz -DHDF5_EXAMPLES_COMPRESSED_DIR:PATH=${CTEST_SCRIPT_DIRECTORY}") - -############################################################################################# -### enable parallel builds - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=OFF") - -############################################################################################# -### enable thread-safety builds - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=ON") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_HL_LIB:BOOL=OFF") - -############################################################################################# -### disable test program builds - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_TESTING:BOOL=OFF") - -############################################################################################# -### disable packaging - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_NO_PACKAGES:BOOL=ON") -### Create install package with external libraries (szip, zlib) -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_PACKAGE_EXTLIBS:BOOL=ON") - -#options to run test scripts in batch commands -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") -set (LOCAL_BATCH_TEST "TRUE") -set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") - -############################################################################################# -### use a toolchain file - -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/intel.cmake") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/crayle.cmake") -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/GCC.cmake") - -#some additions and alternatives to cross compile on haswell for knl -#set (COMPILENODE_HWCOMPILE_MODULE "craype-haswell") -#set (COMPUTENODE_HWCOMPILE_MODULE "craype-mic-knl") -#set (SITE_BUILDNAME_SUFFIX "knl-intel17-SHARED" -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=knl_ctestS.sl") - -############################################################################################# -- cgit v0.12 From 648a21473f078697630b4cbde43da68bb97be277 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 8 Feb 2019 21:38:39 -0600 Subject: Use correct values for other file versions --- config/cmake/scripts/HPC/bsub-HDF5options.cmake | 10 +++++----- config/cmake/scripts/HPC/raybsub-HDF5options.cmake | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config/cmake/scripts/HPC/bsub-HDF5options.cmake b/config/cmake/scripts/HPC/bsub-HDF5options.cmake index 5316f41..a862a6b 100644 --- a/config/cmake/scripts/HPC/bsub-HDF5options.cmake +++ b/config/cmake/scripts/HPC/bsub-HDF5options.cmake @@ -28,13 +28,13 @@ if (DEFINED MPI) endif () ############################################################################################# ### options to run test scripts in batch commands -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_SCRIPT_COMMAND "bsub") set (LOCAL_BATCH_TEST "TRUE") -set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") -set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") +set (LOCAL_BATCH_SCRIPT_NAME "ctestS.lsf") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.lsf") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.lsf") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.lsf") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") diff --git a/config/cmake/scripts/HPC/raybsub-HDF5options.cmake b/config/cmake/scripts/HPC/raybsub-HDF5options.cmake index 5316f41..d3c8721 100644 --- a/config/cmake/scripts/HPC/raybsub-HDF5options.cmake +++ b/config/cmake/scripts/HPC/raybsub-HDF5options.cmake @@ -28,15 +28,15 @@ if (DEFINED MPI) endif () ############################################################################################# ### options to run test scripts in batch commands -set (LOCAL_BATCH_SCRIPT_COMMAND "sbatch") +set (LOCAL_BATCH_SCRIPT_COMMAND "raybsub") set (LOCAL_BATCH_TEST "TRUE") -set (LOCAL_BATCH_SCRIPT_NAME "ctestS.sl") -set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ctestP.sl") +set (LOCAL_BATCH_SCRIPT_NAME "ray_ctestS.lsf") +set (LOCAL_BATCH_SCRIPT_PARALLEL_NAME "ray_ctestP.lsf") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_TEST:BOOL=ON") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ctestS.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ctestP.sl") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=srun") -set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-n") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_NAME:STRING=ray_ctestS.lsf") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLOCAL_BATCH_SCRIPT_PARALLEL_NAME:STRING=ray_ctestP.lsf") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_EXECUTABLE:STRING=mpirun") +set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_NUMPROC_FLAG:STRING=-np") set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=6") ############################################################################################# -- cgit v0.12 From 742894ce88b127d38dbaf91a3c8ad1c0f01f9b01 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 08:56:14 -0600 Subject: Add new cmake copy file tests to ignore --- config/cmake/CTestCustom.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/cmake/CTestCustom.cmake b/config/cmake/CTestCustom.cmake index 27eaa56..2333f67 100644 --- a/config/cmake/CTestCustom.cmake +++ b/config/cmake/CTestCustom.cmake @@ -64,11 +64,19 @@ set (CTEST_CUSTOM_MEMCHECK_IGNORE CPP_testhdf5-clear-objects ######### tools/h5clear ######### H5CLEAR-clearall-objects + H5CLEAR-copy_h5clear_fsm_persist_equal.h5 + H5CLEAR-copy_h5clear_fsm_persist_greater.h5 + H5CLEAR-copy_h5clear_fsm_persist_less.h5 + H5CLEAR-copy_h5clear_fsm_persist_noclose.h5 + H5CLEAR-copy_h5clear_fsm_persist_user_equal.h5 + H5CLEAR-copy_h5clear_fsm_persist_user_greater.h5 + H5CLEAR-copy_h5clear_fsm_persist_user_less.h5 H5CLEAR-copy_h5clear_log_v3.h5 H5CLEAR-copy_h5clear_mdc_image.h5 H5CLEAR-copy_h5clear_sec2_v0.h5 H5CLEAR-copy_h5clear_sec2_v2.h5 H5CLEAR-copy_h5clear_sec2_v3.h5 + H5CLEAR-copy_h5clear_status_noclear.h5 H5CLEAR-copy_latest_h5clear_log_v3.h5 H5CLEAR-copy_latest_h5clear_sec2_v3.h5 H5CLEAR-copy_mod_h5clear_mdc_image.h5 -- cgit v0.12 From 691b92ff9c8429cd704e482628ceb5438df1aca1 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 10:09:32 -0600 Subject: Set the full generator name --- config/cmake/scripts/HDF5config.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index fda9fcc..bcd33df 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -45,7 +45,7 @@ set (CTEST_SOURCE_VERSEXT "") #CTEST_SOURCE_NAME - name of source folder; HDF5-1.10.0 #MODEL - CDash group name #HPC - run alternate configurations for HPC machines; sbatch, bsub, raybsub -#MPI - enable MPI; +#MPI - enable MPI; if (DEFINED CTEST_SCRIPT_ARG) # transform ctest script arguments of the form # script.ctest,var1=value1,var2=value2 @@ -174,6 +174,7 @@ if (NOT DEFINED HPC) endif () endif () else () + set (CTEST_CMAKE_GENERATOR "Unix Makefiles") include (${CTEST_SOURCE_DIRECTORY}/config/cmake/scripts/HPC/${HPC}-HDF5options.cmake) endif () ################################################################### -- cgit v0.12 From f7bab665bbb97f0ef01ef986d0dfa7932100de78 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 10:53:13 -0600 Subject: Distinguish parallel performance tests --- tools/test/perform/CMakeTests.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test/perform/CMakeTests.cmake b/tools/test/perform/CMakeTests.cmake index 5abd038..02dc15d 100644 --- a/tools/test/perform/CMakeTests.cmake +++ b/tools/test/perform/CMakeTests.cmake @@ -170,9 +170,9 @@ endif () set_tests_properties (PERFORM_zip_perf PROPERTIES DEPENDS "PERFORM_zip_perf_help;PERFORM_h5perform-clearall-objects") if (H5_HAVE_PARALLEL) - add_test (NAME PERFORM_h5perf COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_PERFORM_h5perf COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) if (HDF5_BUILD_PERFORM_STANDALONE) - add_test (NAME PERFORM_h5perf_alone COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_PERFORM_h5perf_alone COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endif () endif () -- cgit v0.12 From cc6a61215e508d047ed6aa2daf67475cfe34ee4d Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Mon, 11 Feb 2019 10:58:58 -0600 Subject: Re-write of Java JNI error handling --- java/src/jni/CMakeLists.txt | 26 + java/src/jni/Makefile.am | 5 +- java/src/jni/exceptionImp.c | 206 +- java/src/jni/h5Constants.c | 2 +- java/src/jni/h5Imp.c | 110 +- java/src/jni/h5aImp.c | 2710 ++++++++------- java/src/jni/h5dImp.c | 2566 +++++++------- java/src/jni/h5eImp.c | 583 ++-- java/src/jni/h5fImp.c | 585 ++-- java/src/jni/h5fImp.h | 2 +- java/src/jni/h5gImp.c | 224 +- java/src/jni/h5iImp.c | 233 +- java/src/jni/h5jni.h | 382 ++- java/src/jni/h5lImp.c | 869 ++--- java/src/jni/h5oImp.c | 936 ++--- java/src/jni/h5pACPLImp.c | 36 + java/src/jni/h5pACPLImp.h | 27 + java/src/jni/h5pDAPLImp.c | 322 ++ java/src/jni/h5pDAPLImp.h | 112 + java/src/jni/h5pDCPLImp.c | 1404 ++++++++ java/src/jni/h5pDCPLImp.h | 396 +++ java/src/jni/h5pDXPLImp.c | 502 +++ java/src/jni/h5pDXPLImp.h | 209 ++ java/src/jni/h5pFAPLImp.c | 1624 +++++++++ java/src/jni/h5pFAPLImp.h | 501 +++ java/src/jni/h5pFCPLImp.c | 572 ++++ java/src/jni/h5pFCPLImp.h | 207 ++ java/src/jni/h5pGAPLImp.c | 36 + java/src/jni/h5pGAPLImp.h | 27 + java/src/jni/h5pGCPLImp.c | 227 ++ java/src/jni/h5pGCPLImp.h | 99 + java/src/jni/h5pImp.c | 6234 ++++------------------------------ java/src/jni/h5pImp.h | 1554 +-------- java/src/jni/h5pLAPLImp.c | 237 ++ java/src/jni/h5pLAPLImp.h | 107 + java/src/jni/h5pLCPLImp.c | 36 + java/src/jni/h5pLCPLImp.h | 27 + java/src/jni/h5pOCPLImp.c | 211 ++ java/src/jni/h5pOCPLImp.h | 99 + java/src/jni/h5pOCpyPLImp.c | 92 + java/src/jni/h5pOCpyPLImp.h | 61 + java/src/jni/h5pStrCPLImp.c | 74 + java/src/jni/h5pStrCPLImp.h | 45 + java/src/jni/h5plImp.c | 177 +- java/src/jni/h5rImp.c | 399 ++- java/src/jni/h5sImp.c | 1661 +++++---- java/src/jni/h5tImp.c | 1444 ++++---- java/src/jni/h5util.c | 4732 ++++++++++++++------------ java/src/jni/h5util.h | 33 +- java/src/jni/h5vlImp.c | 148 +- java/src/jni/h5vlImp.h | 2 +- java/src/jni/h5zImp.c | 29 +- java/src/jni/nativeData.c | 1342 ++++---- java/test/TestH5.java | 17 + java/test/testfiles/JUnit-TestH5.txt | 3 +- src/H5Torder.c | 4 +- 56 files changed, 18289 insertions(+), 16219 deletions(-) create mode 100644 java/src/jni/h5pACPLImp.c create mode 100644 java/src/jni/h5pACPLImp.h create mode 100644 java/src/jni/h5pDAPLImp.c create mode 100644 java/src/jni/h5pDAPLImp.h create mode 100644 java/src/jni/h5pDCPLImp.c create mode 100644 java/src/jni/h5pDCPLImp.h create mode 100644 java/src/jni/h5pDXPLImp.c create mode 100644 java/src/jni/h5pDXPLImp.h create mode 100644 java/src/jni/h5pFAPLImp.c create mode 100644 java/src/jni/h5pFAPLImp.h create mode 100644 java/src/jni/h5pFCPLImp.c create mode 100644 java/src/jni/h5pFCPLImp.h create mode 100644 java/src/jni/h5pGAPLImp.c create mode 100644 java/src/jni/h5pGAPLImp.h create mode 100644 java/src/jni/h5pGCPLImp.c create mode 100644 java/src/jni/h5pGCPLImp.h create mode 100644 java/src/jni/h5pLAPLImp.c create mode 100644 java/src/jni/h5pLAPLImp.h create mode 100644 java/src/jni/h5pLCPLImp.c create mode 100644 java/src/jni/h5pLCPLImp.h create mode 100644 java/src/jni/h5pOCPLImp.c create mode 100644 java/src/jni/h5pOCPLImp.h create mode 100644 java/src/jni/h5pOCpyPLImp.c create mode 100644 java/src/jni/h5pOCpyPLImp.h create mode 100644 java/src/jni/h5pStrCPLImp.c create mode 100644 java/src/jni/h5pStrCPLImp.h diff --git a/java/src/jni/CMakeLists.txt b/java/src/jni/CMakeLists.txt index 00c2b34..42b4a48 100644 --- a/java/src/jni/CMakeLists.txt +++ b/java/src/jni/CMakeLists.txt @@ -14,6 +14,19 @@ set (HDF5_JAVA_JNI_CSRCS ${HDF5_JAVA_JNI_SOURCE_DIR}/h5lImp.c ${HDF5_JAVA_JNI_SOURCE_DIR}/h5oImp.c ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pACPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDAPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDCPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDXPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pFAPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pFCPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pGAPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pGCPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pLAPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pLCPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pOCPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pOCpyPLImp.c + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pStrCPLImp.c ${HDF5_JAVA_JNI_SOURCE_DIR}/h5plImp.c ${HDF5_JAVA_JNI_SOURCE_DIR}/h5rImp.c ${HDF5_JAVA_JNI_SOURCE_DIR}/h5sImp.c @@ -36,6 +49,19 @@ set (HDF5_JAVA_JNI_CHDRS ${HDF5_JAVA_JNI_SOURCE_DIR}/h5lImp.h ${HDF5_JAVA_JNI_SOURCE_DIR}/h5oImp.h ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pACPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDAPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDCPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pDXPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pFAPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pFCPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pGAPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pGCPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pLAPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pLCPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pOCPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pOCpyPLImp.h + ${HDF5_JAVA_JNI_SOURCE_DIR}/h5pStrCPLImp.h ${HDF5_JAVA_JNI_SOURCE_DIR}/h5plImp.h ${HDF5_JAVA_JNI_SOURCE_DIR}/h5rImp.h ${HDF5_JAVA_JNI_SOURCE_DIR}/h5sImp.h diff --git a/java/src/jni/Makefile.am b/java/src/jni/Makefile.am index 370b08b..1ec9b94 100644 --- a/java/src/jni/Makefile.am +++ b/java/src/jni/Makefile.am @@ -34,7 +34,10 @@ libhdf5_java_la_LDFLAGS = -avoid-version -shared -export-dynamic -version-info $ # Source files for the library libhdf5_java_la_SOURCES=exceptionImp.c h5Constants.c nativeData.c h5util.c h5Imp.c \ h5aImp.c h5dImp.c h5eImp.c h5fImp.c h5gImp.c h5iImp.c h5lImp.c h5oImp.c \ - h5pImp.c h5plImp.c h5rImp.c h5sImp.c h5tImp.c h5vlImp.c h5zImp.c + h5pImp.c h5pACPLImp.c h5pDAPLImp.c h5pDCPLImp.c h5pDXPLImp.c \ + h5pFAPLImp.c h5pFCPLImp.c h5pGAPLImp.c h5pGCPLImp.c h5pLAPLImp.c h5pLCPLImp.c \ + h5pOCPLImp.c h5pOCpyPLImp.c h5pStrCPLImp.c h5plImp.c h5rImp.c h5sImp.c h5tImp.c \ + h5vlImp.c h5zImp.c # HDF5 Java (JNI) library depends on HDF5 Library. libhdf5_java_la_LIBADD=$(LIBHDF5) diff --git a/java/src/jni/exceptionImp.c b/java/src/jni/exceptionImp.c index ccda0d2..0faa0cc 100644 --- a/java/src/jni/exceptionImp.c +++ b/java/src/jni/exceptionImp.c @@ -33,21 +33,14 @@ extern "C" { #include "h5jni.h" #include "exceptionImp.h" -extern H5E_auto2_t efunc; -extern void *edata; +extern H5E_auto2_t efunc; +extern void *edata; /*******************/ /* Local Variables */ /*******************/ -/* These types are copied from H5Eprivate.h - * They should be moved to a public include file, and deleted from - * here. - */ - -#define H5E_NSLOTS 32 /*number of slots in an error stack */ - /* * The list of error messages in the system is kept as an array of * error_code/message pairs, one for major error numbers and another for @@ -73,29 +66,29 @@ typedef struct H5E_num_t { /* Local Macros */ /********************/ -#define THROWEXCEPTION(className,args) { \ - jclass jc; \ - jmethodID jm; \ - jobject ex; \ - jc = ENVPTR->FindClass(ENVPAR (className)); \ - if (jc == NULL) { \ - return JNI_FALSE; \ - } \ - jm = ENVPTR->GetMethodID(ENVPAR jc, "", "(Ljava/lang/String;)V"); \ - if (jm == NULL) { \ - printf("THROWEXCEPTION FATAL ERROR: GetMethodID failed\n"); \ - return JNI_FALSE; \ - } \ - ex = ENVPTR->NewObjectA (ENVPAR jc, jm, (jvalue*)(args)); \ - if (ex == NULL) { \ - printf("THROWEXCEPTION FATAL ERROR: %s: Creation failed\n", (className)); \ - return JNI_FALSE; \ - } \ - if (ENVPTR->Throw(ENVPAR (jthrowable)ex) < 0) { \ - printf("THROWEXCEPTION FATAL ERROR: %s: Throw failed\n", (className)); \ - return JNI_FALSE; \ - } \ - return JNI_TRUE; \ +#define THROWEXCEPTION(className, args) \ +{ \ + jmethodID jm; \ + jclass jc; \ + jobject ex; \ + \ + if (NULL == (jc = ENVPTR->FindClass(ENVONLY, (className)))) \ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \ + \ + if (NULL == (jm = ENVPTR->GetMethodID(ENVONLY, jc, "", "(Ljava/lang/String;)V"))) { \ + HDprintf("THROWEXCEPTION FATAL ERROR: GetMethodID failed\n"); \ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \ + } \ + \ + if (NULL == (ex = ENVPTR->NewObjectA(ENVONLY, jc, jm, (jvalue *)(args)))) { \ + HDprintf("THROWEXCEPTION FATAL ERROR: Class %s: Creation failed\n", (className)); \ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \ + } \ + \ + if (ENVPTR->Throw(ENVONLY, (jthrowable)ex) < 0) { \ + HDprintf("THROWEXCEPTION FATAL ERROR: Class %s: Throw failed\n", (className)); \ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \ + } \ } /********************/ @@ -112,7 +105,9 @@ walk_error_callback { H5E_num_t *err_nums = (H5E_num_t *)_err_nums; - if(err_desc) { + UNUSED(n); + + if (err_desc) { err_nums->maj_num = err_desc->maj_num; err_nums->min_num = err_desc->min_num; } /* end if */ @@ -130,8 +125,15 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5error_1off (JNIEnv *env, jclass clss) { - H5Eget_auto2(H5E_DEFAULT, &efunc, &edata); - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + UNUSED(env); + UNUSED(clss); + + if (H5Eget_auto2(H5E_DEFAULT, &efunc, &edata) < 0) + return -1; + + if (H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0) + return -1; + return 0; } /* end Java_hdf_hdf5lib_H5_H5error_1off() */ @@ -145,10 +147,12 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5error_1on (JNIEnv *env, jclass clss) { + UNUSED(env); + UNUSED(clss); + H5Eset_auto2(H5E_DEFAULT, efunc, edata); } /* end Java_hdf_hdf5lib_H5_H5error_1on() */ - /* * Class: hdf_hdf5lib_exceptions_HDFLibraryException * Method: printStackTrace0 @@ -163,18 +167,25 @@ Java_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0 FILE *stream = NULL; const char *file = NULL; - if(file_name == NULL) { + UNUSED(obj); + + if (NULL == file_name) { H5Eprint2(H5E_DEFAULT, stderr); - } /* end if */ + } else { - file = ENVPTR->GetStringUTFChars(ENVPAR file_name, 0); - stream = HDfopen(file, "a+"); - if(stream) { + PIN_JAVA_STRING(ENVONLY, file_name, file, NULL, "printStackTrace0: file name not pinned"); + + if ((stream = HDfopen(file, "a+"))) { H5Eprint2(H5E_DEFAULT, stream); HDfclose(stream); - } /* end if */ - ENVPTR->ReleaseStringUTFChars(ENVPAR file_name, file); - } /* end else */ + } + } + +done: + if (file) + UNPIN_JAVA_STRING(ENVONLY, file_name, file); + + return; } /* end Java_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0() */ /* @@ -189,10 +200,15 @@ Java_hdf_hdf5lib_exceptions_HDF5LibraryException__1getMajorErrorNumber (JNIEnv *env, jobject obj) { H5E_num_t err_nums; + + UNUSED(env); + UNUSED(obj); + err_nums.maj_num = 0; err_nums.min_num = 0; - H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &err_nums); + if (H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &err_nums) < 0) + return -1; return err_nums.maj_num; } /* end Java_hdf_hdf5lib_exceptions_HDF5LibraryException__1getMajorErrorNumber() */ @@ -209,27 +225,42 @@ Java_hdf_hdf5lib_exceptions_HDF5LibraryException__1getMinorErrorNumber (JNIEnv *env, jobject obj) { H5E_num_t err_nums; + + UNUSED(env); + UNUSED(obj); + err_nums.maj_num = 0; err_nums.min_num = 0; - H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &err_nums); + if (H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &err_nums) < 0) + return -1; return err_nums.min_num; } /* end Java_hdf_hdf5lib_exceptions_HDF5LibraryException__1getMinorErrorNumber() */ /* - * Routine to raise particular Java exceptions from C + * Routine to raise particular Java exceptions from C. */ static jboolean H5JNIErrorClass (JNIEnv *env, const char *message, const char *className) { - char *args[2]; - jstring str = ENVPTR->NewStringUTF(ENVPAR message); - args[0] = (char *)str; + jstring str; + char *args[2]; + jboolean retVal = JNI_FALSE; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, message))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + args[0] = (char *) str; args[1] = 0; THROWEXCEPTION(className, args); + + retVal = JNI_TRUE; + +done: + return retVal; } /* end H5JNIErrorClass() */ /* @@ -316,7 +347,7 @@ h5unimplemented */ jboolean h5raiseException - (JNIEnv *env, const char *exception, const char *message) + (JNIEnv *env, const char *message, const char *exception) { return H5JNIErrorClass(env, message, exception); } /* end h5raiseException() */ @@ -336,51 +367,76 @@ jboolean h5libraryError (JNIEnv *env) { - char *args[2]; const char *exception = NULL; - char *msg_str = NULL; - int num_errs = 0; - hid_t min_num; - hid_t maj_num; - ssize_t msg_size = 0; H5E_type_t error_msg_type; - jstring str = NULL; - hid_t stk_id = -1; H5E_num_t exceptionNumbers; + jstring str = NULL; + ssize_t msg_size = 0; + hid_t min_num; + hid_t maj_num; + hid_t stk_id = H5I_INVALID_HID; + char *args[2]; + char *msg_str = NULL; + jboolean retVal = JNI_FALSE; exceptionNumbers.maj_num = 0; exceptionNumbers.min_num = 0; /* Save current stack contents for future use */ - stk_id = H5Eget_current_stack(); /* This will clear current stack */ - if(stk_id >= 0) - H5Ewalk2(stk_id, H5E_WALK_DOWNWARD, walk_error_callback, &exceptionNumbers); + if ((stk_id = H5Eget_current_stack()) >= 0) + /* This will clear current stack */ + if (H5Ewalk2(stk_id, H5E_WALK_DOWNWARD, walk_error_callback, &exceptionNumbers) < 0) + goto done; + maj_num = exceptionNumbers.maj_num; min_num = exceptionNumbers.min_num; + /* + * TODO: handle < 0 case. + */ + + /* + * No error detected in HDF5 error stack. + */ + if (!maj_num && !min_num) + goto done; + exception = defineHDF5LibraryException(maj_num); /* get the length of the name */ - msg_size = H5Eget_msg(min_num, NULL, NULL, 0); - if(msg_size > 0) { - msg_size++; /* add extra space for the null terminator */ - msg_str = (char*)HDcalloc((size_t)msg_size, sizeof(char)); - if(msg_str) { - msg_size = H5Eget_msg(min_num, &error_msg_type, (char *)msg_str, (size_t)msg_size); - str = ENVPTR->NewStringUTF(ENVPAR msg_str); - HDfree(msg_str); - } /* end if */ - } /* end if */ + if ((msg_size = H5Eget_msg(min_num, NULL, NULL, 0)) < 0) + goto done; + + if (msg_size > 0) { + if (NULL == (msg_str = (char *) HDcalloc((size_t)msg_size + 1, sizeof(char)))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5libraryerror: failed to allocate buffer for error message"); + + if ((msg_size = H5Eget_msg(min_num, &error_msg_type, msg_str, (size_t)msg_size + 1)) < 0) + goto done; + msg_str[msg_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, msg_str))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } else str = NULL; - if(stk_id >= 0) + + if (stk_id >= 0) H5Eset_current_stack(stk_id); - args[0] = (char *)str; + args[0] = (char *) str; args[1] = 0; + THROWEXCEPTION(exception, args); -} /* end h5libraryError() */ + retVal = JNI_TRUE; + +done: + if (msg_str) + HDfree(msg_str); + + return retVal; +} /* end h5libraryError() */ /* * defineHDF5LibraryException() returns the name of the sub-class diff --git a/java/src/jni/h5Constants.c b/java/src/jni/h5Constants.c index e88fa55..2ac0892 100644 --- a/java/src/jni/h5Constants.c +++ b/java/src/jni/h5Constants.c @@ -1260,7 +1260,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5VL_1CAP_1FLAG_1THREADSAFE(JNIEnv *env, jclass c JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE(JNIEnv *env, jclass cls) { return H5VL_NATIVE; } JNIEXPORT jobject JNICALL -Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE_1NAME(JNIEnv *env, jclass cls) { return (jstring)ENVPTR->NewStringUTF(ENVPAR H5VL_NATIVE_NAME); } +Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE_1NAME(JNIEnv *env, jclass cls) { return (jstring)ENVPTR->NewStringUTF(ENVONLY, H5VL_NATIVE_NAME); } JNIEXPORT jint JNICALL Java_hdf_hdf5lib_HDF5Constants_H5VL_1NATIVE_1VALUE(JNIEnv *env, jclass cls) { return H5VL_NATIVE_VALUE; } JNIEXPORT jint JNICALL diff --git a/java/src/jni/h5Imp.c b/java/src/jni/h5Imp.c index 1ad6b17..99c91fd 100644 --- a/java/src/jni/h5Imp.c +++ b/java/src/jni/h5Imp.c @@ -35,7 +35,10 @@ extern "C" { #include "h5jni.h" #include "h5Imp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -46,10 +49,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5open (JNIEnv *env, jclass clss) { - herr_t retVal = H5open(); - if (retVal < 0) - h5libraryError(env); + herr_t retVal = FAIL; + + UNUSED(clss); + if ((retVal = H5open()) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5open */ @@ -62,10 +69,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5close (JNIEnv *env, jclass clss) { - herr_t retVal = H5close(); - if (retVal < 0) - h5libraryError(env); + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5close()) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5close */ @@ -78,10 +89,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5dont_1atexit (JNIEnv *env, jclass clss) { - herr_t retVal = H5dont_atexit(); - if (retVal < 0) - h5libraryError(env); + herr_t retVal = FAIL; + UNUSED(clss); + + if ((retVal = H5dont_atexit()) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5dont_1atexit */ @@ -94,29 +109,25 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5get_1libversion (JNIEnv *env, jclass clss, jintArray libversion) { - unsigned *theArray = NULL; - herr_t status = -1; - jboolean isCopy; - - if (libversion == NULL) { - h5nullArgument(env, "H5get_version: libversion is NULL"); - } /* end if */ - else { - theArray = (unsigned*)ENVPTR->GetIntArrayElements(ENVPAR libversion, &isCopy); - if (theArray == NULL) { - h5JNIFatalError( env, "H5get_libversion: input not pinned"); - } /* end if */ - else { - status = H5get_libversion(&(theArray[0]), &(theArray[1]), &(theArray[2])); - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR libversion, (jint*)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - ENVPTR->ReleaseIntArrayElements(ENVPAR libversion, (jint*)theArray,0); - } /* end else */ - } /* end else */ - return (jint)status; + jboolean libversionArrayIsCopy; + int *libversionArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (libversion == NULL) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5get_libversion: libversion is NULL"); + + PIN_INT_ARRAY(ENVONLY, libversion, libversionArray, &libversionArrayIsCopy, "H5get_libversion: libversion input not pinned"); + + if ((status = H5get_libversion((unsigned *) &(libversionArray[0]), (unsigned *) &(libversionArray[1]), (unsigned *) &(libversionArray[2]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (libversionArray) + UNPIN_INT_ARRAY(ENVONLY, libversion, libversionArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5get_1libversion */ /* @@ -128,6 +139,9 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5check_1version (JNIEnv *env, jclass clss, jint majnum, jint minnum, jint relnum) { + UNUSED(env); + UNUSED(clss); + return (jint)H5check_version((unsigned)majnum, (unsigned)minnum, (unsigned)relnum); } /* end Java_hdf_hdf5lib_H5_H5check_1version */ @@ -141,10 +155,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5garbage_1collect (JNIEnv *env, jclass clss) { - herr_t retVal = H5garbage_collect(); - if (retVal < 0) - h5libraryError(env); + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5garbage_collect()) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5garbage_1collect */ @@ -158,11 +176,15 @@ Java_hdf_hdf5lib_H5_H5set_1free_1list_1limits (JNIEnv *env, jclass clss, jint reg_global_lim, jint reg_list_lim, jint arr_global_lim, jint arr_list_lim, jint blk_global_lim, jint blk_list_lim ) { - herr_t retVal = H5set_free_list_limits((int)reg_global_lim, (int)reg_list_lim, - (int)arr_global_lim, (int)arr_list_lim, (int)blk_global_lim, (int)blk_list_lim); - if (retVal < 0) - h5libraryError(env); + herr_t retVal = FAIL; + UNUSED(clss); + + if ((retVal = H5set_free_list_limits((int)reg_global_lim, (int)reg_list_lim, + (int)arr_global_lim, (int)arr_list_lim, (int)blk_global_lim, (int)blk_list_lim)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5set_1free_1list_1limits */ @@ -176,7 +198,13 @@ Java_hdf_hdf5lib_H5_H5is_1library_1threadsafe (JNIEnv *env, jclass clss) { hbool_t is_ts = false; - H5is_library_threadsafe(&is_ts); + + UNUSED(clss); + + if (H5is_library_threadsafe(&is_ts) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jboolean)is_ts; } /* end Java_hdf_hdf5lib_H5_H5is_1library_1threadsafe */ diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index e0ec4ca..666626f 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -21,13 +21,17 @@ extern "C" { #endif /* __cplusplus */ -#include "hdf5.h" -#include "h5util.h" #include #include #include +#include "hdf5.h" +#include "h5util.h" +#include "h5jni.h" #include "h5aImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; typedef struct _cb_wrapper { @@ -35,28 +39,14 @@ typedef struct _cb_wrapper { jobject op_data; } cb_wrapper; -#ifdef __cplusplus -#define CBENVPTR (cbenv) -#define CBENVPAR -#define JVMPTR (jvm) -#define JVMPAR -#define JVMPAR2 -#else -#define CBENVPTR (*cbenv) -#define CBENVPAR cbenv, -#define JVMPTR (*jvm) -#define JVMPAR jvm -#define JVMPAR2 jvm, -#endif - /********************/ /* Local Prototypes */ /********************/ -static herr_t H5AwriteVL_asstr (JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); -static herr_t H5AwriteVL_str (JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); -static herr_t H5AreadVL_asstr (JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); -static herr_t H5AreadVL_str (JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); +static herr_t H5AwriteVL_asstr(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); +static herr_t H5AwriteVL_str(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); +static herr_t H5AreadVL_asstr(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); +static herr_t H5AreadVL_str(JNIEnv *env, hid_t attr_id, hid_t mem_id, jobjectArray buf); static herr_t H5A_iterate_cb(hid_t g_id, const char *name, const H5A_info_t *info, void *cb_data); @@ -64,90 +54,6 @@ static herr_t H5A_iterate_cb(hid_t g_id, const char *name, const H5A_info_t *inf /* Local Macros */ /********************/ -#define PIN_BYTE_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jbyte*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_BYTE_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_SHORT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jshort*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetShortArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_SHORT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseShortArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_INT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jint*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetIntArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_INT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseIntArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_LONG_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jlong*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetLongArrayElements(ENVPAR buf,&isCopy); \ -} - -#define UNPIN_LONG_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_FLOAT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jfloat*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetFloatArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_FLOAT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseFloatArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_DOUBLE_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jdouble*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetDoubleArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_DOUBLE_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseDoubleArrayElements(ENVPAR buf, buffP, mode); \ -} - /* * Class: hdf_hdf5lib_H5 @@ -159,18 +65,22 @@ Java_hdf_hdf5lib_H5__1H5Acreate (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id, jlong space_id, jlong create_plist) { - hid_t attr_id = -1; - const char *aName; + const char *attrName = NULL; + hid_t attr_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - attr_id = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, (hid_t)space_id, (hid_t)create_plist, (hid_t)H5P_DEFAULT); + UNUSED(clss); - UNPIN_JAVA_STRING(name, aName); + if (NULL == name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Acreate: attribute name is NULL"); - if (attr_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Acreate: attribute name not pinned"); + + if ((attr_id = H5Acreate2((hid_t)loc_id, attrName, (hid_t)type_id, (hid_t)space_id, (hid_t)create_plist, (hid_t)H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, name, attrName); return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Acreate */ @@ -184,18 +94,22 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name) { - hid_t attr_id = -1; - const char *aName; + const char *attrName = NULL; + hid_t attr_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - attr_id = H5Aopen_name((hid_t)loc_id, aName); + UNUSED(clss); - UNPIN_JAVA_STRING(name,aName); + if (NULL == name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aopen_name: attribute name is null"); - if (attr_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Aopen_name: attribute name not pinned"); + + if((attr_id = H5Aopen_name((hid_t)loc_id, attrName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, name, attrName); return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1name */ @@ -209,39 +123,17 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1idx (JNIEnv *env, jclass clss, jlong loc_id, jint idx) { - hid_t attr_id = H5Aopen_idx((hid_t)loc_id, (unsigned int) idx); + hid_t attr_id = H5I_INVALID_HID; - if (attr_id < 0) - h5libraryError(env); + UNUSED(clss); + if ((attr_id = H5Aopen_idx((hid_t) loc_id, (unsigned int) idx)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1idx */ -static htri_t -H5Tdetect_variable_str - (hid_t tid) { - htri_t ret_val = 0; - - if (H5Tget_class(tid) == H5T_COMPOUND) { - unsigned i; - unsigned nm = (unsigned)H5Tget_nmembers(tid); - for(i = 0; i < nm; i++) { - htri_t status = 0; - hid_t mtid = 0; - if((mtid = H5Tget_member_type(tid, i)) < 0) - return -1; /* exit immediately on error */ - if((status = H5Tdetect_variable_str(mtid)) < 0) - return status; /* exit immediately on error */ - ret_val |= status; - H5Tclose (mtid); - } /* end for */ - } /* end if */ - else - ret_val = H5Tis_variable_str(tid); - - return ret_val; -} /* end H5Tdetect_variable_str */ - /* * Class: hdf_hdf5lib_H5 * Method: H5Aread @@ -251,46 +143,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jbyte *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument( env,"H5Aread: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Aread: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + jbyte *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported"); + + if (isCriticalPinning) { + PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread: buf does not support variable length type"); - } /* end else if */ + PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_BYTE_ARRAY(); - - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - if (status < 0) { - UNPIN_BYTE_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_BYTE_ARRAY(0); /* update java buffer for return */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread */ @@ -304,43 +198,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jbyte *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument( env,"H5Awrite: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Awrite: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jbyte *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported"); + + if (isCriticalPinning) { + PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite: buf does not support variable length type"); - } /* end else if */ - else { - PIN_BYTE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); + PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite: write buffer not pinned"); + } - UNPIN_BYTE_ARRAY(JNI_ABORT); /* no need to update buffer */ + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + else { + UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite */ @@ -354,46 +253,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1short (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jshortArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jshort *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Aread_short: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Aread: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_short: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + jshort *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported"); + + if (isCriticalPinning) { + PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_short: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread_short: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_short: buf does not support variable length type"); - } /* end else if */ + PIN_SHORT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_short: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_SHORT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread_short: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - if (status < 0) { - UNPIN_SHORT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_SHORT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_SHORT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1short */ @@ -407,43 +308,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1short (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jshortArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jshort *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL ) { - h5nullArgument(env, "H5Awrite_short: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Awrite_short: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_short: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jshort *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported"); + + if (isCriticalPinning) { + PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_short: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite_short: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_short: buf does not support variable length type"); - } /* end else if */ - else { - PIN_SHORT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite_short: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); + PIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_short: write buffer not pinned"); + } - UNPIN_SHORT_ARRAY(JNI_ABORT); + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + else { + UNPIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1short */ @@ -457,46 +363,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1int (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jintArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jint *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Aread_int: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Aread_int: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_int: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + htri_t data_class; + jint *readBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (buf == NULL) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported"); + + if (isCriticalPinning) { + PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_int: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread_int: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_int: buf does not support variable length type"); - } /* end else if */ + PIN_INT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_int: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_INT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread_int: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - if (status < 0) { - UNPIN_INT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_INT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_INT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1int */ @@ -510,43 +418,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1int (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jintArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jint *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Awrite_int: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Awrite_int: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_int: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jint *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (buf == NULL) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported"); + + if (isCriticalPinning) { + PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_int: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite_int: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_int: buf does not support variable length type"); - } /* end else if */ - else { - PIN_INT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite_int: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); + PIN_INT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_int: write buffer not pinned"); + } - UNPIN_INT_ARRAY(JNI_ABORT); + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + else { + UNPIN_INT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1int */ @@ -560,46 +473,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1long (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jlongArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jlong *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Aread_long: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Aread_long: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_long: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + jlong *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported"); + + if (isCriticalPinning) { + PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_long: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread_long: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_long: buf does not support variable length type"); - } /* end else if */ + PIN_LONG_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_long: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_LONG_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread_long: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - if (status < 0) { - UNPIN_LONG_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_LONG_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_LONG_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1long */ @@ -613,42 +528,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1long (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jlongArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jlong *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Awrite_long: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_long: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_long: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jlong *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported"); + + if (isCriticalPinning) { + PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_long: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite_long: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_long: buf does not support variable length type"); - } /* end else if */ + PIN_LONG_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_long: write buffer not pinned"); + } + + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_LONG_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite_long: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - UNPIN_LONG_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_LONG_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1long */ @@ -662,46 +583,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1float (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jfloatArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jfloat *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Aread_float: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread_float: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_float: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + jfloat *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported"); + + if (isCriticalPinning) { + PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_float: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread_float: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_float: buf does not support variable length type"); - } /* end else if */ + PIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_float: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_FLOAT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread_float: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - if (status < 0) { - UNPIN_FLOAT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_FLOAT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1float */ @@ -715,42 +638,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1float (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jfloatArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jfloat *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Awrite_float: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Awrite_float: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_float: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jfloat *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported"); + + if (isCriticalPinning) { + PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_float: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite_float: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_float: buf does not support variable length type"); - } /* end else if */ + PIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_float: write buffer not pinned"); + } + + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_FLOAT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite_float: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - UNPIN_FLOAT_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1float */ @@ -764,46 +693,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1double (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jdoubleArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jdouble *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Aread_double: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Aread_double: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_double: buf does not support variable length type"); - } /* end else if */ + jboolean readBufIsCopy; + jdouble *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported"); + + if (isCriticalPinning) { + PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_double: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Aread_double: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Aread_double: buf does not support variable length type"); - } /* end else if */ + PIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread_double: read buffer not pinned"); + } + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_DOUBLE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Aread_double: buf not pinned"); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - if (status < 0) { - UNPIN_DOUBLE_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_DOUBLE_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1double */ @@ -817,42 +748,48 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1double (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jdoubleArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jdouble *buffP; - jboolean isCopy; - htri_t data_class; - - if (buf == NULL) { - h5nullArgument(env, "H5Awrite_double: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Awrite_double: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_double: buf does not support variable length type"); - } /* end else if */ + jboolean writeBufIsCopy; + jdouble *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported"); + + if (isCriticalPinning) { + PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_double: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Awrite_double: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Awrite_double: buf does not support variable length type"); - } /* end else if */ + PIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Awrite_double: write buffer not pinned"); + } + + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_DOUBLE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Awrite_double: buf not pinned"); - } /* end if */ - else { - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, buffP); - - UNPIN_DOUBLE_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1double */ @@ -866,67 +803,58 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1string (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray j_buf) { - herr_t status = -1; - char *c_buf; - char *cstr; - size_t str_len; - jsize i; - jsize n; - size_t pos; - jstring jstr; - - c_buf = cstr = NULL; - if (j_buf == NULL) { - h5nullArgument(env, "H5Aread_string: buf is NULL"); - } /* end if */ - else if ((n = ENVPTR->GetArrayLength(ENVPAR j_buf)) <= 0) { - h5nullArgument(env, "H5Aread_string: buf length <= 0"); - } /* end else if */ - else if ((str_len = H5Tget_size((hid_t)mem_type_id)) <=0) { - h5libraryError(env); - } /* end else if */ - else { - if ((cstr = (char*)HDmalloc(str_len + 1)) == NULL) { - h5JNIFatalError(env, "H5Aread_string: memory allocation failed."); - } /* end if */ - else { - if ((c_buf = (char*)HDmalloc((size_t)n * str_len)) == NULL) { - if (cstr) - HDfree(cstr); - cstr = NULL; - h5JNIFatalError(env, "H5Aread_string: memory allocation failed."); - } /* end if */ - else { - status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, c_buf); - - if (status < 0) { - if (cstr) - HDfree(cstr); - cstr = NULL; - if (c_buf) - HDfree(c_buf); - c_buf = NULL; - h5libraryError(env); - } /* end if */ - else { - pos = 0; - for (i = 0; i < n; i++) { - HDmemcpy(cstr, c_buf+pos, str_len); - cstr[str_len] = '\0'; - jstr = ENVPTR->NewStringUTF(ENVPAR cstr); - ENVPTR->SetObjectArrayElement(ENVPAR j_buf, i, jstr); - pos += str_len; - } /* end for */ - } /* end else */ - - if (c_buf) - HDfree(c_buf); - } /* end else cbuf allocation*/ - - if (cstr) - HDfree(cstr); - } /* end else cstr allocation*/ - } /* end else */ + jstring jstr; + size_t str_len; + size_t pos; + jsize i, n; + char *c_buf = NULL; + char *cstr = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == j_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_string: read buffer is NULL"); + + if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_string: read buffer length <= 0"); + } + + if (!(str_len = H5Tget_size((hid_t)mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (cstr = (char *) HDmalloc(str_len + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: memory allocation failed"); + + if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: memory allocation failed"); + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, c_buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0, pos = 0; i < n; i++) { + HDmemcpy(cstr, c_buf+pos, str_len); + cstr[str_len] = '\0'; + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, cstr))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_string: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, j_buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + pos += str_len; + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (c_buf) + HDfree(c_buf); + if (cstr) + HDfree(cstr); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1string */ @@ -940,52 +868,63 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1string (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray j_buf) { - herr_t status = -1; - char *c_buf; - jsize str_len; - jsize i; - jsize n; - - if (j_buf == NULL) { - h5nullArgument(env, "H5Awrite_string: buf is NULL"); - } /* end if */ - else if ((n = ENVPTR->GetArrayLength(ENVPAR j_buf)) <= 0) { - h5nullArgument(env, "H5Awrite_string: buf length <= 0"); - } /* end else if */ - else if ((str_len = (jsize)H5Tget_size((hid_t)mem_type_id)) <=0) { - h5libraryError(env); - } /* end else if */ - else { - if ((c_buf = (char*)HDmalloc((size_t)n * (size_t)str_len)) == NULL) { - h5JNIFatalError(env, "H5Awrite_string: memory allocation failed."); - } /* end if */ - else { - for (i = 0; i < n; i++) { - jstring obj = (jstring)ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray)j_buf, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); + const char *utf8 = NULL; + jstring obj; + size_t i, str_len; + jsize n; + char *c_buf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == j_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_string: write buffer is NULL"); - if (utf8) { - HDstrncpy(&c_buf[i * str_len], utf8, str_len); - } /* end if */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_string: write buffer length <= 0"); + } + + if (!(str_len = H5Tget_size((hid_t)mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for */ + if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Awrite_string: memory allocation failed"); - status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, c_buf); + for (i = 0; i < (size_t) n; i++) { + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)j_buf, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + HDmemset(&c_buf[i * str_len], 0, str_len); + continue; + } + + /* + * length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + */ + + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5Awrite_string: string not pinned"); + + HDstrncpy(&c_buf[i * str_len], utf8, str_len); + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } /* end for */ - if (c_buf) - HDfree(c_buf); - c_buf = NULL; + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, c_buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) { - h5libraryError(env); - } /* end if */ - } /* end else */ - } /* end else */ +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + if (c_buf) + HDfree(c_buf); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1string */ @@ -999,167 +938,201 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadVL (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - herr_t status = -1; - htri_t isStr = 0; - htri_t isVlenStr = 0; - htri_t isComplex = 0; - - if (buf == NULL) { - h5nullArgument(env, "H5AreadVL: buf is NULL"); - } /* end if */ - else { - isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); - if (H5Tget_class((hid_t)mem_type_id) == H5T_COMPOUND) { - unsigned i; - int nm = H5Tget_nmembers(mem_type_id); - for(i = 0; i 0 || isVlenStr) { - status = H5AreadVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf); - } - else if (isStr > 0) { - status = H5AreadVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf); + H5T_class_t type_class; + htri_t isStr = 0; + htri_t isVlenStr = 0; + htri_t isComplex = 0; + htri_t isComplex2 = 0; + hid_t nested_tid = H5I_INVALID_HID; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL"); + + if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (type_class == H5T_COMPOUND) { + unsigned i; + int num_members; + + if ((num_members = H5Tget_nmembers(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (unsigned) num_members; i++) { + if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + isComplex = isComplex || isComplex2; + + if (H5Tclose(nested_tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nested_tid = H5I_INVALID_HID; } - } /* end else */ + } + else if (type_class == H5T_VLEN) { + isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */ + } + + if (!isStr || isComplex || isVlenStr) { + if ((status = H5AreadVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else if (isStr) { + if ((status = H5AreadVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (nested_tid >= 0) + H5Tclose(nested_tid); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1VL */ -herr_t -H5AreadVL_asstr +/* + * Helper method to read in a buffer of variable-length strings from an HDF5 + * attribute. Each C-string is converted to a Java string and set in the output + * buffer in turn. + */ +static herr_t +H5AreadVL_str (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf) { - jint i; - jint n; - hid_t sid; - jstring jstr; - h5str_t h5str; - hvl_t *rdata; - hsize_t dims[H5S_MAX_RANK]; - size_t size; - size_t max_len = 0; - herr_t status = -1; + jstring jstr; + jsize i, n; + char **strs = NULL; + herr_t status = FAIL; - /* Get size of string array */ - n = ENVPTR->GetArrayLength(ENVPAR buf); - /* we will need to read n number of hvl_t structures */ - rdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); - if (rdata == NULL) { - h5JNIFatalError(env, "H5AreadVL_asstr: failed to allocate buff for read"); - } /* end if */ - else { - status = H5Aread(aid, tid, rdata); - - if (status < 0) { - dims[0] = (hsize_t)n; - sid = H5Screate_simple(1, dims, NULL); - H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, rdata); - H5Sclose(sid); - HDfree(rdata); - h5JNIFatalError(env, "H5AreadVL_asstr: failed to read data"); - } /* end if */ - else { - /* calculate the largest size of all the hvl_t structures read */ - max_len = 1; - for (i=0; i < n; i++) { - if ((rdata + i)->len > max_len) - max_len = (rdata + i)->len; - } - - /* create one malloc to hold largest element */ - size = H5Tget_size(tid) * max_len; - HDmemset(&h5str, 0, sizeof(h5str_t)); - h5str_new(&h5str, 4 * size); - - if (h5str.s == NULL) { - dims[0] = (hsize_t)n; - sid = H5Screate_simple(1, dims, NULL); - H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, rdata); - H5Sclose(sid); - HDfree(rdata); - h5JNIFatalError(env, "H5AreadVL_asstr: failed to allocate buf"); - } /* end if */ - else { - H5T_class_t tclass = H5Tget_class(tid); - /* convert each element to char string */ - for (i=0; i < n; i++) { - h5str.s[0] = '\0'; - h5str_vlsprintf(&h5str, aid, tid, rdata+i, 0); - jstr = ENVPTR->NewStringUTF(ENVPAR h5str.s); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - } /* end for */ - h5str_free(&h5str); - - dims[0] = (hsize_t)n; - sid = H5Screate_simple(1, dims, NULL); - H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, rdata); - H5Sclose(sid); - HDfree(rdata); - } /* end else */ - } /* end else */ - } /* end else */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL_str: buf length < 0"); + } + + if (NULL == (strs = (char **) HDcalloc((size_t)n, sizeof(char *)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_str: failed to allocate variable length string read buffer"); + + if ((status = H5Aread(aid, tid, strs)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* + * When repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings), + * H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect + * free space in time. Instead, we use "H5free_memory(strs[i])" to free individual strings + * once done. + */ + for (i = 0; i < n; i++) { + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, strs[i]))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + H5free_memory(strs[i]); + strs[i] = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (strs) { + for (i = 0; i < n; i++) { + if (strs[i]) + H5free_memory(strs[i]); + } + + HDfree(strs); + } return status; -} +} /* end H5AreadVL_str */ -herr_t -H5AreadVL_str +/* + * Helper method to read in a buffer of variable-length (hvl_t) + * structures from an HDF5 attribute and convert each variable-length + * element's buffer into a Java string. Each string is then set + * in the output buffer in turn. + */ +static herr_t +H5AreadVL_asstr (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf) { - char **strs; - jstring jstr; - jint i; - jint n; - hid_t sid; - hsize_t dims[H5S_MAX_RANK]; - herr_t status = -1; - - n = ENVPTR->GetArrayLength(ENVPAR buf); - strs =(char**)HDcalloc((size_t)n, sizeof(char*)); - - if (strs == NULL) { - h5JNIFatalError(env, "H5AreadVL_str: failed to allocate buff for read variable length strings"); - } /* end if */ - else { - status = H5Aread(aid, tid, strs); - - if (status < 0) { - dims[0] = (hsize_t)n; - sid = H5Screate_simple(1, dims, NULL); - H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, strs); - H5Sclose(sid); - HDfree(strs); - h5JNIFatalError(env, "H5AreadVL_str: failed to read variable length strings"); - } /* end if */ - else { - for (i=0; i < n; i++) { - jstr = ENVPTR->NewStringUTF(ENVPAR strs[i]); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - H5free_memory (strs[i]); - } /* end for */ + hsize_t dims[H5S_MAX_RANK]; + jstring jstr; + h5str_t h5str; + size_t typeSize; + size_t i; + hid_t sid = H5I_INVALID_HID; + jsize n; + void *readBuf = NULL; + herr_t status = FAIL; - /* - for repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings, - H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect - free space in time. Instead, use "H5free_memory(strs[i])" above to free individual strings - after it is done. - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, strs); - */ + HDmemset(&h5str, 0, sizeof(h5str_t)); + + /* Get size of string array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL_asstr: buf length < 0"); + } + + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (readBuf = HDcalloc((size_t)n, typeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_asstr: failed to allocate read buffer"); - HDfree(strs); - } /* end else */ - } /* end else */ + if ((status = H5Aread(aid, tid, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Allocate a decent-sized initial string */ + h5str_new(&h5str, 4 * typeSize); + + if (!h5str.s) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadVL_asstr: failed to allocate buffer"); + + /* Convert each element to a char string */ + for (i = 0; i < (size_t) n; i++) { + h5str.s[0] = '\0'; + + if (!h5str_sprintf(ENVONLY, &h5str, aid, tid, &(((char *) readBuf)[i * typeSize]), typeSize, 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, (jsize) i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (h5str.s) + h5str_free(&h5str); + if (readBuf) { + H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, readBuf); + HDfree(readBuf); + } + if (sid >= 0) + H5Sclose(sid); return status; -} /* end H5AreadVL_str */ +} /* * Class: hdf_hdf5lib_H5 @@ -1170,139 +1143,224 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AwriteVL (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - herr_t status = -1; - htri_t isStr = 0; - htri_t isVlenStr = 0; - htri_t isComplex = 0; - - if (buf == NULL) { - h5nullArgument(env, "H5AwriteVL: buf is NULL"); - } /* end if */ - else { - isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); - if (H5Tget_class((hid_t)mem_type_id) == H5T_COMPOUND) { - unsigned i; - int nm = H5Tget_nmembers(mem_type_id); - for(i = 0; i 0 || isVlenStr) { - status = H5AwriteVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf); - } - else if (isStr > 0) { - status = H5AwriteVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf); + H5T_class_t type_class; + htri_t isStr = 0; + htri_t isVlenStr = 0; + htri_t isComplex = 0; + htri_t isComplex2 = 0; + hid_t nested_tid = H5I_INVALID_HID; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL"); + + if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (type_class == H5T_COMPOUND) { + unsigned i; + int num_members; + + if ((num_members = H5Tget_nmembers(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for(i = 0; i < (unsigned) num_members; i++) { + if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + isComplex = isComplex || isComplex2; + + if (H5Tclose(nested_tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nested_tid = H5I_INVALID_HID; } - } /* end else */ + } + else if (type_class == H5T_VLEN) { + isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */ + } + + if (!isStr || isComplex || isVlenStr) { + if ((status = H5AwriteVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else if (isStr) { + if ((status = H5AwriteVL_str(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (nested_tid >= 0) + H5Tclose(nested_tid); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Awrite_1VL */ -herr_t +/* + * Helper method to convert an array of Java strings into a buffer of C-strings. + * The buffer of C-strings is then written to the HDF5 attribute specified. + */ +static herr_t H5AwriteVL_str (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf) { - herr_t status = -1; - char **wdata; - jsize size; - jint i; + const char *utf8 = NULL; + jstring obj; + jsize size; + jint i; + char **writeBuf = NULL; + herr_t status = FAIL; + + if ((size = ENVPTR->GetArrayLength(ENVONLY, (jarray) buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL_str: buf length < 0"); + } - size = ENVPTR->GetArrayLength(ENVPAR (jarray) buf); + if (NULL == (writeBuf = (char **) HDcalloc((size_t)size + 1, sizeof(char *)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate variable length string write buffer") - wdata = (char**)HDcalloc((size_t)size + 1, sizeof(char*)); - if (!wdata) { - h5JNIFatalError(env, "H5AwriteVL_str: cannot allocate buffer"); - } /* end if */ - else { - HDmemset(wdata, 0, (size_t)size * sizeof(char*)); - for (i = 0; i < size; ++i) { - jstring obj = (jstring) ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray) buf, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); - - if (utf8) { - wdata[i] = (char*)HDmalloc((size_t)length + 1); - if (wdata[i]) { - HDmemset(wdata[i], 0, ((size_t)length + 1)); - HDstrncpy(wdata[i], utf8, (size_t)length); - } /* end if */ - } /* end if */ - - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for (i = 0; i < size; ++i) */ - - status = H5Awrite((hid_t)aid, (hid_t)tid, wdata); + for (i = 0; i < size; ++i) { + jsize length; + + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray) buf, i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + writeBuf[i] = NULL; + continue; + } + + length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5AwriteVL_str: string not pinned"); + + if (NULL == (writeBuf[i] = (char *) HDmalloc((size_t)length + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate string buffer"); + + HDstrncpy(writeBuf[i], utf8, (size_t)length); + writeBuf[i][length] = '\0'; + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } /* end for (i = 0; i < size; ++i) */ + + if ((status = H5Awrite((hid_t)aid, (hid_t)tid, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + if (writeBuf) { for (i = 0; i < size; i++) { - if(wdata[i]) { - HDfree(wdata[i]); - } /* end if */ - } /* end for */ - HDfree(wdata); + if (writeBuf[i]) + HDfree(writeBuf[i]); + } - if (status < 0) - h5libraryError(env); - } /* end else */ + HDfree(writeBuf); + } return (jint)status; } -herr_t +/* + * Helper method to convert an array of Java strings into a buffer of + * variable-length (hvl_t) elements. The buffer of variable-length + * elements is then written to the HDF5 attribute. + */ +static herr_t H5AwriteVL_asstr (JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf) { - char **strs; - jstring jstr; - jint i; - jint n; - hid_t sid; - hsize_t dims[H5S_MAX_RANK]; - herr_t status = -1; - - n = ENVPTR->GetArrayLength(ENVPAR buf); - strs =(hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); - - if (strs == NULL) { - h5JNIFatalError(env, "H5AwriteVL_asstr: failed to allocate buff for read variable length strings"); - } /* end if */ - else { - status = H5Awrite(aid, tid, strs); - - if (status < 0) { - dims[0] = (hsize_t)n; - sid = H5Screate_simple(1, dims, NULL); - H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, strs); - H5Sclose(sid); - HDfree(strs); - h5JNIFatalError(env, "H5AwriteVL_str: failed to read variable length strings"); - } /* end if */ - else { - for (i=0; i < n; i++) { - jstr = ENVPTR->NewStringUTF(ENVPAR strs[i]); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - H5free_memory (strs[i]); - } /* end for */ + const char *utf8 = NULL; + hsize_t dims[H5S_MAX_RANK]; + jstring jstr; + size_t typeSize; + size_t i; + hid_t sid = H5I_INVALID_HID; + jsize n; + void *writeBuf = NULL; + herr_t status = FAIL; + + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL_asstr: buf length < 0"); + } + + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (writeBuf = HDcalloc((size_t)n, typeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_asstr: failed to allocate write buffer"); + + /* + * When repeatedly writing a dataset with a large number of strs (e.g., 1,000,000 strings), + * H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect + * free space in time. Instead, we use "H5free_memory(strs[i])" to free individual strings + * once done. + */ + for (i = 0; i < (size_t) n; i++) { + if (NULL == (jstr = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray) buf, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); /* - for repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings, - H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect - free space in time. Instead, use "H5free_memory(strs[i])" above to free individual strings - after it is done. - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, strs); - */ + * If the string object was NULL, skip it. + */ + HDmemset(&(((char *) writeBuf)[i * typeSize]), 0, typeSize); + continue; + } + + /* + * length = ENVPTR->GetStringUTFLength(ENVONLY, jstr); + * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + */ + + PIN_JAVA_STRING(ENVONLY, jstr, utf8, NULL, "H5AwriteVL_asstr: failed to pin string buffer"); + + /* + * TODO: If the string isn't a copy, we should probably make + * one before destroying it with h5str_convert. + */ + + if (!h5str_convert(ENVONLY, (char **) &utf8, aid, tid, &(((char *) writeBuf)[i * typeSize]), 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - HDfree(strs); - } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(ENVONLY, jstr, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for (i = 0; i < n; i++) */ + + if ((status = H5Awrite(aid, tid, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, jstr, utf8); + if (writeBuf) { + H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, writeBuf); + HDfree(writeBuf); + } + if (sid >= 0) + H5Sclose(sid); return status; } /* end H5AwriteVL_str */ @@ -1316,47 +1374,52 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - herr_t status = -1; - h5str_t h5str; - size_t size; - hdset_reg_ref_t *ref_data; - jint i; - jint n; - jstring jstr; + hdset_reg_ref_t *ref_data = NULL; + h5str_t h5str; + jstring jstr; + jsize i, n; + herr_t status = FAIL; - hid_t region = -1; - hid_t aid = (hid_t) attr_id; - hid_t tid = (hid_t) mem_type_id; + UNUSED(clss); - n = ENVPTR->GetArrayLength(ENVPAR buf); - size = sizeof(hdset_reg_ref_t); /*H5Tget_size(tid);*/ - ref_data = (hdset_reg_ref_t*)HDmalloc(size * (size_t)n); + HDmemset(&h5str, 0, sizeof(h5str_t)); - if (ref_data == NULL) { - h5JNIFatalError(env, "H5Aread_reg_ref: failed to allocate buff for read"); - return -1; - } /* end if */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_reg_ref: buf length < 0"); + } - status = H5Aread(aid, tid, ref_data); + if (NULL == (ref_data = (hdset_reg_ref_t *) HDmalloc((size_t)n * sizeof(hdset_reg_ref_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_reg_ref: failed to allocate read buffer"); - if (status < 0) { - HDfree(ref_data); - h5JNIFatalError(env, "H5Aread_reg_ref: failed to read data"); - return -1; - } /* end if */ + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, ref_data)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - HDmemset(&h5str, 0, sizeof(h5str_t)); h5str_new(&h5str, 1024); - for (i=0; iNewStringUTF(ENVPAR h5str.s); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); + if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)attr_id, (hid_t)mem_type_id, ref_data[i], 0, 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); } /* end for */ - h5str_free(&h5str); - HDfree(ref_data); +done: + if (h5str.s) + h5str_free(&h5str); + if (ref_data) + HDfree(ref_data); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref */ @@ -1370,12 +1433,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1space (JNIEnv *env, jclass clss, jlong attr_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Aget_space((hid_t)attr_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Aget_space((hid_t)attr_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aget_1space */ @@ -1388,12 +1453,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1type (JNIEnv *env, jclass clss, jlong attr_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Aget_type((hid_t)attr_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Aget_type((hid_t)attr_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aget_1type */ @@ -1406,34 +1473,29 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Aget_1name (JNIEnv *env, jclass clss, jlong attr_id) { - char *aName; jstring str = NULL; ssize_t buf_size; + char *attrName = NULL; + + UNUSED(clss); + + if ((buf_size = H5Aget_name((hid_t)attr_id, 0, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (attrName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aget_name: failed to allocate attribute name buffer"); + + if (H5Aget_name((hid_t)attr_id, (size_t)buf_size + 1, attrName) < 0) + H5_LIBRARY_ERROR(ENVONLY); + attrName[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, attrName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (attrName) + HDfree(attrName); - /* get the length of the name */ - buf_size = H5Aget_name((hid_t)attr_id, 0, NULL); - if (buf_size <= 0) { - h5badArgument(env, "H5Aget_name: buf_size <= 0"); - } /* end if */ - else { - buf_size++; /* add extra space for the null terminator */ - aName = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (aName == NULL) { - h5outOfMemory(env, "H5Aget_name: malloc failed"); - } /* end if */ - else { - buf_size = H5Aget_name((hid_t)attr_id, (size_t)buf_size, aName); - if (buf_size < 0) { - HDfree(aName); - h5libraryError(env); - } /* end if */ - else { - /* save the string; */ - str = ENVPTR->NewStringUTF(ENVPAR aName); - HDfree(aName); - } /* end else */ - } /* end else */ - } /* end else */ return str; } /* end Java_hdf_hdf5lib_H5_H5Aget_1name */ @@ -1446,12 +1508,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aget_1num_1attrs (JNIEnv *env, jclass clss, jlong loc_id) { - int retVal = -1; + int retVal = FAIL; + + UNUSED(clss); - retVal = H5Aget_num_attrs((hid_t)loc_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Aget_num_attrs((hid_t)loc_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Aget_1num_1attrs */ @@ -1464,18 +1528,19 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Adelete (JNIEnv *env, jclass clss, jlong loc_id, jstring name) { - herr_t status = -1; - const char *aName; + const char *attrName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - status = H5Adelete((hid_t)loc_id, aName); + UNUSED(clss); - UNPIN_JAVA_STRING(name, aName); + PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Adelete: attribute name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Adelete((hid_t)loc_id, attrName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, name, attrName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Adelete */ @@ -1489,14 +1554,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Aclose (JNIEnv *env, jclass clss, jlong attr_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; - if (attr_id > 0) - retVal = H5Aclose((hid_t)attr_id); + UNUSED(clss); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Aclose((hid_t)attr_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aclose */ @@ -1510,24 +1575,24 @@ Java_hdf_hdf5lib_H5__1H5Acreate2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id, jlong space_id, jlong create_plist, jlong access_plist) { - hid_t status = -1; - const char *aName; + const char *attrName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - status = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, - (hid_t)space_id, (hid_t)create_plist, (hid_t)access_plist ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, aName); + PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Acreate2: attribute name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Acreate2((hid_t)loc_id, attrName, (hid_t)type_id, + (hid_t)space_id, (hid_t)create_plist, (hid_t)access_plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, name, attrName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Acreate2 */ - /* * Class: hdf_hdf5lib_H5 * Method: _H5Aopen @@ -1538,18 +1603,19 @@ Java_hdf_hdf5lib_H5__1H5Aopen (JNIEnv *env, jclass clss, jlong obj_id, jstring name, jlong access_plist) { - hid_t retVal = -1; - const char *aName; + const char *attrName = NULL; + hid_t retVal = H5I_INVALID_HID; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - retVal = H5Aopen((hid_t)obj_id, aName, (hid_t)access_plist); + UNUSED(clss); - UNPIN_JAVA_STRING(name, aName); + PIN_JAVA_STRING(ENVONLY, name, attrName, NULL, "H5Aopen: attribute name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Aopen((hid_t)obj_id, attrName, (hid_t)access_plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, name, attrName); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aopen */ @@ -1563,19 +1629,20 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint idx_type, jint order, jlong n, jlong aapl_id, jlong lapl_id) { - hid_t retVal = -1; - const char *aName; + const char *objName = NULL; + hid_t retVal = H5I_INVALID_HID; - PIN_JAVA_STRING(name, aName); - if (aName != NULL) { - retVal = H5Aopen_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t)order, (hsize_t)n, (hid_t)aapl_id, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, aName); + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Aopen_by_idx: object name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Aopen_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, + (H5_iter_order_t)order, (hsize_t)n, (hid_t)aapl_id, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx */ @@ -1589,20 +1656,24 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong type_id, jlong space_id, jlong acpl_id, jlong aapl_id, jlong lapl_id) { - hid_t retVal = -1; - const char *aName; - const char *attrName; + const char *objName = NULL; + const char *attrName = NULL; + hid_t retVal = H5I_INVALID_HID; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (aName != NULL && attrName != NULL) { - retVal = H5Acreate_by_name((hid_t)loc_id, aName, attrName, (hid_t)type_id, - (hid_t)space_id, (hid_t)acpl_id, (hid_t)aapl_id, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Acreate_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Acreate_by_name: attribute name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Acreate_by_name((hid_t)loc_id, objName, attrName, (hid_t)type_id, + (hid_t)space_id, (hid_t)acpl_id, (hid_t)aapl_id, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name */ @@ -1616,21 +1687,25 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Aexists_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id) { + const char *objName = NULL; + const char *attrName = NULL; htri_t bval = JNI_FALSE; - const char *aName; - const char *attrName; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (aName != NULL && attrName != NULL) { - bval = H5Aexists_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aexists_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aexists_by_name: attribute name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5Aexists_by_name((hid_t)loc_id, objName, attrName, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Aexists_1by_1name */ @@ -1644,24 +1719,27 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Arename (JNIEnv *env, jclass clss, jlong loc_id, jstring old_attr_name, jstring new_attr_name) { - herr_t retVal = -1; - const char *oName; - const char *nName; + const char *oldAttrName = NULL; + const char *newAttrName = NULL; + herr_t retVal = FAIL; - PIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName); - if (oName != NULL && nName != NULL) { - retVal = H5Arename((hid_t)loc_id, oName, nName); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName); + PIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName, NULL, "H5Arename: old attribute name not pinned"); + PIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName, NULL, "H5Arename: new attribute name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Arename((hid_t)loc_id, oldAttrName, newAttrName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (newAttrName) + UNPIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName); + if (oldAttrName) + UNPIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Arename */ - /* * Class: hdf_hdf5lib_H5 * Method: H5Arename_by_name @@ -1671,20 +1749,27 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Arename_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring old_attr_name, jstring new_attr_name, jlong lapl_id) { - herr_t retVal = -1; - const char *aName; - const char *oName; - const char *nName; + const char *objName = NULL; + const char *oldAttrName = NULL; + const char *newAttrName = NULL; + herr_t retVal = FAIL; - PIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName); - if (aName != NULL && oName != NULL && nName != NULL) { - retVal = H5Arename_by_name((hid_t)loc_id, aName, oName, nName, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Arename_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName, NULL, "H5Arename_by_name: old attribute name not pinned"); + PIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName, NULL, "H5Arename_by_name: new attribute name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Arename_by_name((hid_t)loc_id, objName, oldAttrName, newAttrName, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (newAttrName) + UNPIN_JAVA_STRING(ENVONLY, new_attr_name, newAttrName); + if (oldAttrName) + UNPIN_JAVA_STRING(ENVONLY, old_attr_name, oldAttrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Arename_1by_1name */ @@ -1698,51 +1783,37 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id) { - size_t buf_size; - char *aValue; - jlong status_size; - jstring str = NULL; - const char *aName; - - PIN_JAVA_STRING(obj_name, aName); - if (aName != NULL) { - /* get the length of the attribute name */ - status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t) order, (hsize_t) n, (char*)NULL, (size_t)0, (hid_t)lapl_id); - - if(status_size < 0) { - UNPIN_JAVA_STRING(obj_name, aName); - h5libraryError(env); - } /* end if */ - else { - buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - - aValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (aValue == NULL) { - UNPIN_JAVA_STRING(obj_name, aName); - h5outOfMemory(env, "H5Aget_name_by_idx: malloc failed "); - } /* end if */ - else { - status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t) order, (hsize_t) n, (char*)aValue, (size_t)buf_size, (hid_t)lapl_id); - - UNPIN_JAVA_STRING(obj_name, aName); - - if (status_size < 0) { - HDfree(aValue); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aValue); - HDfree(aValue); - if (str == NULL) { - /* exception -- fatal JNI error */ - h5JNIFatalError(env, "H5Aget_name_by_idx: return string not created"); - } /* end if */ - } /* end else */ - } /* end else */ - } /* end else */ - } + const char *objName = NULL; + jstring str = NULL; + ssize_t status_size = -1; + char *attrName = NULL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_name_by_idx: object name not pinned"); + + /* Get the length of the attribute name */ + if ((status_size = H5Aget_name_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, + (H5_iter_order_t) order, (hsize_t) n, (char *)NULL, (size_t)0, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (attrName = (char *) HDmalloc(sizeof(char) * (size_t) status_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Aget_name_by_idx: failed to allocate buffer for attribute name"); + + if ((H5Aget_name_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, + (H5_iter_order_t) order, (hsize_t) n, (char *)attrName, (size_t)status_size + 1, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + attrName[status_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, attrName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (attrName) + HDfree(attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); + return str; } /* end Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx */ @@ -1755,14 +1826,17 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Aget_1storage_1size (JNIEnv *env, jclass clss, jlong attr_id) { - hsize_t retVal = (hsize_t)-1; + hsize_t retVal = 0; - retVal = H5Aget_storage_size((hid_t)attr_id); -/* probably returns '0' if fails--don't do an exception */ + UNUSED(clss); + + if (!(retVal = H5Aget_storage_size((hid_t)attr_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Aget_1storage_1size */ - /* * Class: hdf_hdf5lib_H5 * Method: H5Aget_info @@ -1772,23 +1846,23 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Aget_1info (JNIEnv *env, jclass clss, jlong attr_id) { - herr_t status = -1; H5A_info_t ainfo; - jvalue args[4]; jobject ret_obj = NULL; + jvalue args[4]; - status = H5Aget_info((hid_t)attr_id, &ainfo); + UNUSED(clss); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].z = ainfo.corder_valid; - args[1].j = ainfo.corder; - args[2].i = ainfo.cset; - args[3].j = (jlong)ainfo.data_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); - } /* end else */ + if (H5Aget_info((hid_t)attr_id, &ainfo) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].z = ainfo.corder_valid; + args[1].j = ainfo.corder; + args[2].i = ainfo.cset; + args[3].j = (jlong)ainfo.data_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj); + +done: return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info */ @@ -1801,30 +1875,31 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id) { - herr_t status; + const char *objName = NULL; H5A_info_t ainfo; + herr_t status; jvalue args[4]; jobject ret_obj = NULL; - const char *aName; - PIN_JAVA_STRING(obj_name, aName); - if (aName != NULL) { - status = H5Aget_info_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t)order, (hsize_t)n, &ainfo, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING(obj_name, aName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_info_by_idx: object name not pinned"); + + if ((status = H5Aget_info_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, + (H5_iter_order_t)order, (hsize_t)n, &ainfo, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].z = ainfo.corder_valid; + args[1].j = ainfo.corder; + args[2].i = ainfo.cset; + args[3].j = (jlong)ainfo.data_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].z = ainfo.corder_valid; - args[1].j = ainfo.corder; - args[2].i = ainfo.cset; - args[3].j = (jlong)ainfo.data_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); - } /* end else */ - } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx */ @@ -1837,30 +1912,34 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id) { - const char *aName; - const char *attrName; - herr_t status; + const char *objName = NULL; + const char *attrName = NULL; H5A_info_t ainfo; + herr_t status; jvalue args[4]; jobject ret_obj = NULL; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (aName != NULL && attrName != NULL) { - status = H5Aget_info_by_name((hid_t)loc_id, aName, attrName, &ainfo, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aget_info_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aget_info_by_name: attribute name not pinned"); + + if ((status = H5Aget_info_by_name((hid_t)loc_id, objName, attrName, &ainfo, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].z = ainfo.corder_valid; + args[1].j = ainfo.corder; + args[2].i = ainfo.cset; + args[3].j = (jlong)ainfo.data_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args, ret_obj); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].z = ainfo.corder_valid; - args[1].j = ainfo.corder; - args[2].i = ainfo.cset; - args[3].j = (jlong)ainfo.data_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); - } /* end else */ - } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name */ @@ -1873,19 +1952,23 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Adelete_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id) { - herr_t retVal = -1; - const char *aName; - const char *attrName; + const char *objName = NULL; + const char *attrName = NULL; + herr_t retVal = FAIL; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (aName != NULL && attrName != NULL) { - retVal = H5Adelete_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Adelete_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Adelete_by_name: attribute name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Adelete_by_name((hid_t)loc_id, objName, attrName, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1name */ @@ -1899,20 +1982,21 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Aexists (JNIEnv *env, jclass clss, jlong obj_id, jstring attr_name) { + const char *attrName = NULL; htri_t bval = JNI_FALSE; - const char *aName; - PIN_JAVA_STRING(attr_name, aName); - if (aName != NULL) { - bval = H5Aexists((hid_t)obj_id, aName); + UNUSED(clss); - UNPIN_JAVA_STRING(attr_name, aName); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aexists: attribute name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5Aexists((hid_t)obj_id, attrName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Aexists */ @@ -1926,18 +2010,19 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jint idx_type, jint order, jlong n, jlong lapl_id) { - herr_t status = -1; - const char *aName; + const char *objName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(obj_name, aName); - if (aName != NULL) { - status = H5Adelete_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t)n, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING(obj_name, aName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Adelete_by_idx: object name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Adelete_by_idx((hid_t)loc_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t)n, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx */ /* @@ -1950,19 +2035,23 @@ Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong aapl_id, jlong lapl_id) { - hid_t status = -1; - const char *aName; - const char *oName; + const char *attrName = NULL; + const char *objName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName); - if (oName != NULL && aName != NULL) { - status = H5Aopen_by_name((hid_t)loc_id, oName, aName, (hid_t)aapl_id, (hid_t)lapl_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName); + PIN_JAVA_STRING(ENVONLY, obj_name, objName, NULL, "H5Aopen_by_name: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, attr_name, attrName, NULL, "H5Aopen_by_name: attribute name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Aopen_by_name((hid_t)loc_id, objName, attrName, (hid_t)aapl_id, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (attrName) + UNPIN_JAVA_STRING(ENVONLY, attr_name, attrName); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, obj_name, objName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name */ @@ -1976,60 +2065,69 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist (JNIEnv *env, jclass clss, jlong attr_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Aget_create_plist((hid_t)attr_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Aget_create_plist((hid_t)attr_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist */ static herr_t H5A_iterate_cb (hid_t g_id, const char *name, const H5A_info_t *info, void *cb_data) { - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - jmethodID constructor; - jvalue args[4]; - jobject cb_info_t = NULL; cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5A_info_t;Lhdf/hdf5lib/callbacks/H5A_iterate_t;)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - - args[0].z = info->corder_valid; - args[1].j = info->corder; - args[2].i = info->cset; - args[3].j = (jlong)info->data_size; - /* get a reference to your class if you don't have it already */ - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5A_info_t"); - if (cls != 0) { - /* get a reference to the constructor; the name is */ - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(ZJIJ)V"); - if (constructor != 0) { - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (cb_info_t == NULL) { - printf("FATAL ERROR: hdf/hdf5lib/structs/H5A_info_t: Creation failed\n"); - } - else { - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); - } - } /* end if (constructor != 0) */ - } /* end if (cls != 0) */ - } /* end if (mid != 0) */ - } /* end if (cls != 0) */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); + jmethodID constructor, mid; + jobject cb_info_t = NULL; + jobject visit_callback = wrapper->visit_callback; + jstring str; + JNIEnv *cbenv = NULL; + jclass cls; + jvalue args[4]; + void *op_data = (void *)wrapper->op_data; + jint status = -1; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5A_iterate_cb: failed to attach current thread to JVM"); + } + + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5A_info_t;Lhdf/hdf5lib/callbacks/H5A_iterate_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[0].z = info->corder_valid; + args[1].j = info->corder; + args[2].i = info->cset; + args[3].j = (jlong)info->data_size; + + /* Get a reference to your class if you don't have it already */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5A_info_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* Get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(ZJIJ)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("FATAL ERROR: hdf/hdf5lib/structs/H5A_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); return (herr_t)status; } /* end H5A_iterate_cb */ @@ -2044,22 +2142,24 @@ Java_hdf_hdf5lib_H5_H5Aiterate (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order, jlong idx, jobject callback_op, jobject op_data) { - hsize_t start_idx = (hsize_t)idx; - herr_t status = -1; + cb_wrapper wrapper = { callback_op, op_data }; + hsize_t start_idx = (hsize_t)idx; + herr_t status = FAIL; - cb_wrapper wrapper = {callback_op, op_data}; - ENVPTR->GetJavaVM(ENVPAR &jvm); + UNUSED(clss); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Literate_by_name: op_data or callback_op is NULL"); - } /* end if */ - else { - status = H5Aiterate2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (status < 0) - h5libraryError(env); - } /* end else */ + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate: callback_op is NULL"); + if ((status = H5Aiterate2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aiterate */ @@ -2073,27 +2173,29 @@ Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order, jlong idx, jobject callback_op, jobject op_data, jlong access_id) { - const char *lName; - hsize_t start_idx = (hsize_t)idx; - herr_t status = -1; - cb_wrapper wrapper = {callback_op, op_data}; + const char *objName = NULL; + cb_wrapper wrapper = { callback_op, op_data }; + hsize_t start_idx = (hsize_t)idx; + herr_t status = FAIL; - ENVPTR->GetJavaVM(ENVPAR &jvm); + UNUSED(clss); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Literate_by_name: op_data or callback_op is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Aiterate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper, (hid_t)access_id); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - UNPIN_JAVA_STRING(name, lName); + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate_by_name: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aiterate_by_name: callback_op is NULL"); - if (status < 0) - h5libraryError(env); - } - } /* end else */ + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Aiterate_by_name: object name not pinned"); + + if ((status = H5Aiterate_by_name((hid_t)grp_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)&wrapper, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name */ diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index 79a5d0a..0ed3b6e 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -27,8 +27,12 @@ extern "C" { #include #include "hdf5.h" #include "h5util.h" +#include "h5jni.h" #include "h5dImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; typedef struct _cb_wrapper { @@ -36,121 +40,19 @@ typedef struct _cb_wrapper { jobject op_data; } cb_wrapper; -#ifdef __cplusplus - #ifdef _WINDOWS - #include - #endif - #define CBENVPTR (cbenv) - #define CBENVPAR - #define JVMPTR (jvm) - #define JVMPAR - #define JVMPAR2 -#else - #define CBENVPTR (*cbenv) - #define CBENVPAR cbenv, - #define JVMPTR (*jvm) - #define JVMPAR jvm - #define JVMPAR2 jvm, -#endif - /********************/ /* Local Prototypes */ /********************/ -static herr_t H5DreadVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); -static herr_t H5DreadVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); -static herr_t H5DreadVL_array (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); -static herr_t H5DwriteVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); -static herr_t H5DwriteVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); -static herr_t H5DwriteVL_array (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); +static herr_t H5DreadVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); +static herr_t H5DreadVL_str(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); +static herr_t H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); +static herr_t H5DwriteVL_str(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); /********************/ /* Local Macros */ /********************/ -#define PIN_BYTE_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jbyte*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_BYTE_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_SHORT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jshort*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetShortArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_SHORT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseShortArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_INT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jint*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetIntArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_INT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseIntArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_LONG_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jlong*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetLongArrayElements(ENVPAR buf,&isCopy); \ -} - -#define UNPIN_LONG_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_FLOAT_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jfloat*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetFloatArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_FLOAT_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseFloatArrayElements(ENVPAR buf, buffP, mode); \ -} - -#define PIN_DOUBLE_ARRAY() { \ - if (isCriticalPinning) \ - buffP = (jdouble*)ENVPTR->GetPrimitiveArrayCritical(ENVPAR buf, &isCopy); \ - else \ - buffP = ENVPTR->GetDoubleArrayElements(ENVPAR buf, &isCopy); \ -} - -#define UNPIN_DOUBLE_ARRAY(mode) { \ - if (isCriticalPinning) \ - ENVPTR->ReleasePrimitiveArrayCritical(ENVPAR buf, buffP, mode); \ - else \ - ENVPTR->ReleaseDoubleArrayElements(ENVPAR buf, buffP, mode); \ -} /* * Class: hdf_hdf5lib_H5 @@ -162,18 +64,19 @@ Java_hdf_hdf5lib_H5__1H5Dcreate (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id, jlong space_id, jlong create_plist_id) { - hid_t dset_id = -1; - const char *fileName; + const char *dsetName = NULL; + hid_t dset_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, H5P_DEFAULT, (hid_t)create_plist_id, H5P_DEFAULT); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, dsetName, NULL, "H5Dcreate: dataset name not pinned"); - if (dset_id < 0) - h5libraryError(env); - } + if ((dset_id = H5Dcreate2((hid_t)loc_id, dsetName, (hid_t)type_id, (hid_t)space_id, H5P_DEFAULT, (hid_t)create_plist_id, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dsetName) + UNPIN_JAVA_STRING(ENVONLY, name, dsetName); return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dcreate */ @@ -187,17 +90,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dopen (JNIEnv *env, jclass clss, jlong loc_id, jstring name) { - hid_t dset_id = -1; - const char *fileName; + const char *dsetName = NULL; + hid_t dset_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - dset_id = H5Dopen2((hid_t)loc_id, fileName, H5P_DEFAULT); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, dsetName, NULL, "H5Dopen: dataset name not pinned"); + + if ((dset_id = H5Dopen2((hid_t)loc_id, dsetName, H5P_DEFAULT))) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dsetName) + UNPIN_JAVA_STRING(ENVONLY, name, dsetName); return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dopen */ @@ -211,12 +116,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dget_1space (JNIEnv *env, jclass clss, jlong dataset_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Dget_space((hid_t)dataset_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Dget_space((hid_t)dataset_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Dget_1space */ @@ -229,12 +136,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dget_1type (JNIEnv *env, jclass clss, jlong dataset_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Dget_type((hid_t)dataset_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Dget_type((hid_t)dataset_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Dget_1type */ @@ -247,40 +156,17 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dget_1create_1plist (JNIEnv *env, jclass clss, jlong dataset_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Dget_create_plist((hid_t)dataset_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Dget_create_plist((hid_t)dataset_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Dget_1create_1plist */ -static htri_t -H5Tdetect_variable_str - (hid_t tid) { - htri_t ret_val = 0; - - if (H5Tget_class(tid) == H5T_COMPOUND) { - unsigned i; - unsigned nm = (unsigned)H5Tget_nmembers(tid); - for(i = 0; i < nm; i++) { - htri_t status = 0; - hid_t mtid = 0; - if((mtid = H5Tget_member_type(tid, i)) < 0) - return -1; /* exit immediately on error */ - if((status = H5Tdetect_variable_str(mtid)) < 0) - return status; /* exit immediately on error */ - ret_val |= status; - H5Tclose (mtid); - } /* end for */ - } /* end if */ - else - ret_val = H5Tis_variable_str(tid); - - return ret_val; -} /* end H5Tdetect_variable_str */ - /* * Class: hdf_hdf5lib_H5 * Method: H5Dread @@ -291,48 +177,49 @@ Java_hdf_hdf5lib_H5_H5Dread (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jbyte *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + htri_t data_class; + jbyte *readBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: variable length type not supported"); + + if (isCriticalPinning) { + PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread: buf does not support variable length type"); - } /* end else if */ + PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_BYTE_ARRAY(); - - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_BYTE_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_BYTE_ARRAY(0); /* update java buffer for return */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread */ @@ -347,44 +234,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jbyte *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + htri_t data_class; + jbyte *writeBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: variable length type not supported"); + + if (isCriticalPinning) { + PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite: buf does not support variable length type"); - } /* end else if */ + PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_BYTE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_BYTE_ARRAY(JNI_ABORT); /* no need to update buffer */ - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite */ @@ -398,13 +290,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Dclose (JNIEnv *env, jclass clss, jlong dataset_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Dclose((hid_t)dataset_id); + UNUSED(clss); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Dclose((hid_t)dataset_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Dclose */ @@ -417,15 +310,17 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Dget_1storage_1size (JNIEnv *env, jclass clss, jlong dataset_id) { - hsize_t retVal = (hsize_t)-1; + hsize_t retVal = 0; - if (dataset_id < 0) { - h5badArgument(env, "H5Dget_storage_size: not a dataset"); - } /* end if */ - else { - retVal = H5Dget_storage_size((hid_t)dataset_id); - } /* end else */ + UNUSED(clss); + + if (dataset_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dget_storage_size: not a dataset"); + if (!(retVal = H5Dget_storage_size((hid_t)dataset_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Dget_1storage_1size */ @@ -439,27 +334,23 @@ Java_hdf_hdf5lib_H5_H5Dvlen_1reclaim (JNIEnv *env, jclass clss, jlong type_id, jlong space_id, jlong xfer_plist_id, jbyteArray buf) { - herr_t status = -1; - jbyte *byteP; - jboolean isCopy; + jboolean vlenBufIsCopy; + jbyte *vlenBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dvlen_reclaim: buf is NULL"); - } /* end if */ - else { - byteP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Dvlen_reclaim: buf not pinned"); - } /* end if */ - else { - status = H5Dvlen_reclaim((hid_t)type_id, (hid_t)space_id, (hid_t)xfer_plist_id, byteP); + UNUSED(clss); - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, byteP, JNI_ABORT); + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dvlen_reclaim: buffer is NULL"); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + PIN_BYTE_ARRAY(ENVONLY, buf, vlenBuf, &vlenBufIsCopy, "H5Dvlen_reclaim: buffer not pinned"); + + if ((status = H5Dvlen_reclaim((hid_t)type_id, (hid_t)space_id, (hid_t)xfer_plist_id, vlenBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (vlenBuf) + UNPIN_BYTE_ARRAY(ENVONLY, buf, vlenBuf, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dvlen_1reclaim */ @@ -474,47 +365,49 @@ Java_hdf_hdf5lib_H5_H5Dread_1short (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jshortArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jshort *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + jshort *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_short: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_short: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: variable length type not supported"); + + if (isCriticalPinning) { + PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_short: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread_short: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_short: buf does not support variable length type"); - } /* end else if */ + PIN_SHORT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_short: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_SHORT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread_short: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_SHORT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_SHORT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_SHORT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1short */ @@ -529,44 +422,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1short (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jshortArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jshort *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + jshort *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; - if (buf == NULL ) { - h5nullArgument(env, "H5Dwrite_short: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_short: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_short: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: variable length type not supported"); + + if (isCriticalPinning) { + PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_short: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite_short: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_short: buf does not support variable length type"); - } /* end else if */ + PIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_short: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_SHORT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite_short: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_SHORT_ARRAY(JNI_ABORT); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_SHORT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1short */ @@ -581,47 +479,49 @@ Java_hdf_hdf5lib_H5_H5Dread_1int (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jintArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jint *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + htri_t data_class; + jint *readBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_int: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread_int: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_int: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: variable length type not supported"); + + if (isCriticalPinning) { + PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_int: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread_int: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_int: buf does not support variable length type"); - } /* end else if */ + PIN_INT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_int: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_INT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread_int: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_INT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_INT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_INT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1int */ @@ -636,44 +536,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1int (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jintArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jint *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + htri_t data_class; + jint *writeBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite_int: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_int: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_int: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: variable length type not supported"); + + if (isCriticalPinning) { + PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_int: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite_int: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_int: buf does not support variable length type"); - } /* end else if */ + PIN_INT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_int: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_INT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite_int: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_INT_ARRAY(JNI_ABORT); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_INT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1int */ @@ -688,47 +593,49 @@ Java_hdf_hdf5lib_H5_H5Dread_1long (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jlongArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jlong *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + htri_t data_class; + jlong *readBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_long: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread_long: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_long: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: variable length type not supported"); + + if (isCriticalPinning) { + PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_long: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread_long: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_long: buf does not support variable length type"); - } /* end else if */ + PIN_LONG_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_long: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_LONG_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread_long: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_LONG_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_LONG_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_LONG_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1long */ @@ -743,43 +650,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1long (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jlongArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jlong *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + htri_t data_class; + jlong *writeBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite_long: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_long: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_long: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: variable length type not supported"); + + if (isCriticalPinning) { + PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_long: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite_long: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_long: buf does not support variable length type"); - } /* end else if */ + PIN_LONG_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_long: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_LONG_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite_long: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_LONG_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_LONG_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1long */ @@ -794,47 +707,49 @@ Java_hdf_hdf5lib_H5_H5Dread_1float (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jfloatArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jfloat *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + htri_t data_class; + jfloat *readBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_float: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread_float: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_float: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: variable length type not supported"); + + if (isCriticalPinning) { + PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_float: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread_float: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_float: buf does not support variable length type"); - } /* end else if */ + PIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_float: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_FLOAT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread_float: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_FLOAT_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_FLOAT_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_FLOAT_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1float */ @@ -849,43 +764,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1float (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jfloatArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jfloat *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + htri_t data_class; + jfloat *writeBuf = NULL; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite_float: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_float: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_float: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: variable length type not supported"); + + if (isCriticalPinning) { + PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_float: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite_float: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_float: buf does not support variable length type"); - } /* end else if */ + PIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_float: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_FLOAT_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite_float: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_FLOAT_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_FLOAT_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1float */ @@ -900,47 +821,49 @@ Java_hdf_hdf5lib_H5_H5Dread_1double (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jdoubleArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jdouble *buffP; - jboolean isCopy; - htri_t data_class; + jboolean readBufIsCopy; + jdouble *readBuf = NULL; + htri_t data_class; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_double: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dread_double: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_double: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: read buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: variable length type not supported"); + + if (isCriticalPinning) { + PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_double: read buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dread_double: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dread_double: buf does not support variable length type"); - } /* end else if */ + PIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_double: read buffer not pinned"); + } + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (readBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_DOUBLE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dread_double: buf not pinned"); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - if (status < 0) { - UNPIN_DOUBLE_ARRAY(JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - UNPIN_DOUBLE_ARRAY(0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_DOUBLE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1double */ @@ -955,43 +878,49 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jdoubleArray buf, jboolean isCriticalPinning) { - herr_t status = -1; - jdouble *buffP; - jboolean isCopy; - htri_t data_class; + jboolean writeBufIsCopy; + jdouble *writeBuf = NULL; + htri_t data_class; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite_double: buf is NULL"); - } /* end if */ - else if((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) { - h5JNIFatalError(env, "H5Dwrite_double: H5Tdetect_class() failed"); - } /* end else if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_double: buf does not support variable length type"); - } /* end else if */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: write buffer is NULL"); + + if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: variable length type not supported"); + + /* Recursively detect any vlen string in type (compound, array ...) */ + if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (data_class) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: variable length type not supported"); + + if (isCriticalPinning) { + PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_double: write buffer not critically pinned"); + } else { - /* recursive detect any vlen string in type (compound, array ...) */ - if((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) { - h5JNIFatalError(env, "H5Dwrite_double: H5Tdetect_variable_str() failed"); - } /* end if */ - else if(data_class == 1) { - h5badArgument(env, "H5Dwrite_double: buf does not support variable length type"); - } /* end else if */ + PIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_double: write buffer not pinned"); + } + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (writeBuf) { + if (isCriticalPinning) { + UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } else { - PIN_DOUBLE_ARRAY(); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dwrite_double: buf not pinned"); - } /* end if */ - else { - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buffP); - - UNPIN_DOUBLE_ARRAY(JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + UNPIN_DOUBLE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1double */ @@ -1006,68 +935,59 @@ Java_hdf_hdf5lib_H5_H5Dread_1string (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray j_buf) { - herr_t status = -1; - char *c_buf; - char *cstr; - size_t str_len; - jsize i; - jsize n; - size_t pos; - jstring jstr; - - c_buf = cstr = NULL; - if (j_buf == NULL) { - h5nullArgument(env, "H5Dread_string: buf is NULL"); - } /* end if */ - else if ((n = ENVPTR->GetArrayLength(ENVPAR j_buf)) <= 0) { - h5nullArgument(env, "H5Dread_string: buf length <= 0"); - } /* end else if */ - else if ((str_len = H5Tget_size((hid_t)mem_type_id)) <=0) { - h5libraryError(env); - } /* end else if */ - else { - if ((cstr = (char*)HDmalloc(str_len + 1)) == NULL) { - h5JNIFatalError(env, "H5Dread_string: memory allocation failed."); - } /* end if */ - else { - if ((c_buf = (char*)HDmalloc((size_t)n * str_len)) == NULL) { - if (cstr) - HDfree(cstr); - cstr = NULL; - h5JNIFatalError(env, "H5Dread_string: memory allocation failed."); - } /* end if */ - else { - status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, c_buf); - - if (status < 0) { - if (cstr) - HDfree(cstr); - cstr = NULL; - if (c_buf) - HDfree(c_buf); - c_buf = NULL; - h5libraryError(env); - } /* end if */ - else { - pos = 0; - for (i = 0; i < n; i++) { - HDmemcpy(cstr, c_buf+pos, str_len); - cstr[str_len] = '\0'; - jstr = ENVPTR->NewStringUTF(ENVPAR cstr); - ENVPTR->SetObjectArrayElement(ENVPAR j_buf, i, jstr); - pos += str_len; - } /* end for */ - } /* end else */ - - if (c_buf) - HDfree(c_buf); - } /* end else cbuf allocation*/ - - if (cstr) - HDfree(cstr); - } /* end else cstr allocation*/ - } /* end else */ + jstring jstr; + size_t str_len; + size_t pos; + jsize i, n; + char *c_buf = NULL; + char *cstr = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == j_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_string: read buffer is NULL"); + + if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_string: read buffer length <= 0"); + } + + if (!(str_len = H5Tget_size((hid_t)mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (cstr = (char *) HDmalloc(str_len + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dread_string: memory allocation failed"); + + if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dread_string: memory allocation failed"); + + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, c_buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0, pos = 0; i < n; i++) { + HDmemcpy(cstr, c_buf+pos, str_len); + cstr[str_len] = '\0'; + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, cstr))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dread_string: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, j_buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + pos += str_len; + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (c_buf) + HDfree(c_buf); + if (cstr) + HDfree(cstr); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1string */ @@ -1082,53 +1002,64 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1string (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray j_buf) { - herr_t status = -1; - char *c_buf; - jsize str_len; - jsize i; - jsize n; - - if (j_buf == NULL) { - h5nullArgument(env, "H5Dwrite_string: buf is NULL"); - } /* end if */ - else if ((n = ENVPTR->GetArrayLength(ENVPAR j_buf)) <= 0) { - h5nullArgument(env, "H5Dwrite_string: buf length <= 0"); - } /* end else if */ - else if ((str_len = (jsize)H5Tget_size((hid_t)mem_type_id)) <=0) { - h5libraryError(env); - } /* end else if */ - else { - if ((c_buf = (char*)HDmalloc((size_t)n * (size_t)str_len)) == NULL) { - h5JNIFatalError(env, "H5Dwrite_string: memory allocation failed."); - } /* end if */ - else { - for (i = 0; i < n; i++) { - jstring obj = (jstring)ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray)j_buf, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); - - if (utf8) { - HDstrncpy(&c_buf[i * str_len], utf8, str_len); - } /* end if */ - - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for */ - - status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, c_buf); - - if (c_buf) - HDfree(c_buf); - c_buf = NULL; - - if (status < 0) { - h5libraryError(env); - } /* end if */ - } /* end else */ - } /* end else */ + const char *utf8 = NULL; + jstring obj; + size_t i, str_len; + jsize n; + char *c_buf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == j_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_string: write buffer is NULL"); + + if ((n = ENVPTR->GetArrayLength(ENVONLY, j_buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_string: write buffer length <= 0"); + } + + if (!(str_len = H5Tget_size((hid_t)mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (c_buf = (char *) HDmalloc((size_t)n * str_len))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dwrite_string: memory allocation failed"); + + for (i = 0; i < (size_t) n; i++) { + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)j_buf, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + HDmemset(&c_buf[i * str_len], 0, str_len); + continue; + } + + /* + * length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + */ + + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5Dwrite_string: string not pinned"); + + HDstrncpy(&c_buf[i * str_len], utf8, str_len); + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } /* end for */ + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, c_buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + if (c_buf) + HDfree(c_buf); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dwrite_1string */ @@ -1143,106 +1074,216 @@ Java_hdf_hdf5lib_H5_H5DreadVL (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - htri_t isStr = 0; - htri_t isVlenStr = 0; - htri_t isComplex = 0; + H5T_class_t type_class; + htri_t isStr = 0; + htri_t isVlenStr = 0; + htri_t isComplex = 0; + htri_t isComplex2 = 0; + hid_t nested_tid = H5I_INVALID_HID; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5DreadVL: buf is NULL"); - } /* end if */ - else { - isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); - if (H5Tget_class((hid_t)mem_type_id) == H5T_COMPOUND) { - unsigned i; - int nm = H5Tget_nmembers(mem_type_id); - for(i = 0; i 0 || isVlenStr) { - status = H5DreadVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); - } - else if (isStr > 0) { - status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: read buffer is NULL"); + + if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (type_class == H5T_COMPOUND) { + unsigned i; + int num_members; + + if ((num_members = H5Tget_nmembers(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (unsigned) num_members; i++) { + if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + isComplex = isComplex || isComplex2; + + if (H5Tclose(nested_tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nested_tid = H5I_INVALID_HID; } - } /* end else */ + } + else if (type_class == H5T_VLEN) { + isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */ + } + + if (!isStr || isComplex || isVlenStr) { + if ((status = H5DreadVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else if (isStr) { + if ((status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (nested_tid >= 0) + H5Tclose(nested_tid); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1VL */ -herr_t +/* + * Helper method to read in a buffer of variable-length strings from an HDF5 + * dataset. Each C-string is converted to a Java string and set in the output + * buffer in turn. + */ +static herr_t +H5DreadVL_str + (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf) +{ + jstring jstr; + jsize i, n; + char **strs = NULL; + herr_t status = FAIL; + + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL_str: buf length < 0"); + } + + if (NULL == (strs = (char **) HDcalloc((size_t)n, sizeof(char *)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL_str: failed to allocate variable length string read buffer"); + + if ((status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, strs)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* + * When repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings), + * H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect + * free space in time. Instead, we use "H5free_memory(strs[i])" to free individual strings + * once done. + */ + for (i = 0; i < n; i++) { + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, strs[i]))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + H5free_memory(strs[i]); + strs[i] = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (strs) { + for (i = 0; i < n; i++) { + if (strs[i]) + H5free_memory(strs[i]); + } + + HDfree(strs); + } + + return status; +} /* end H5DreadVL_str */ + +/* + * Helper method to read in a buffer of variable-length (hvl_t) + * structures from an HDF5 dataset and convert each variable-length + * element's buffer into a Java string. Each string is then set + * in the output buffer in turn. + */ +static herr_t H5DreadVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf) { - jint i; - jint n; - jstring jstr; - h5str_t h5str; - hvl_t *rdata; - size_t size; - size_t max_len = 0; - herr_t status = -1; + H5T_class_t tclass; + jstring jstr; + h5str_t h5str; + hbool_t close_mem_space = FALSE; + size_t typeSize; + size_t i; + hid_t mem_space = mem_sid; + jsize n; + void *readBuf = NULL; + herr_t status = FAIL; + + HDmemset(&h5str, 0, sizeof(h5str_t)); + + if (mem_space == H5S_ALL) { + mem_space = file_sid; + + if (mem_space == H5S_ALL) { + /* + * Retrieve a valid dataspace for H5Dvlen_reclaim(). + */ + if ((mem_space = H5Dget_space(did)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + close_mem_space = TRUE; + + if (H5Sselect_all(mem_space) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + } /* Get size of string array */ - n = ENVPTR->GetArrayLength(ENVPAR buf); - /* we will need to read n number of hvl_t structures */ - rdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); - if (rdata == NULL) { - h5JNIFatalError(env, "H5DreadVL_asstr: failed to allocate buff for read"); - } /* end if */ - else { - status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, rdata); + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL_asstr: buf length < 0"); + } - if (status < 0) { - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata); - HDfree(rdata); - h5JNIFatalError(env, "H5DreadVL_asstr: failed to read data"); - } /* end if */ - else { - /* calculate the largest size of all the hvl_t structures read */ - max_len = 1; - for (i=0; i < n; i++) { - if ((rdata + i)->len > max_len) - max_len = (rdata + i)->len; - } - - /* create one malloc to hold largest element */ - size = H5Tget_size(tid) * max_len; - HDmemset(&h5str, 0, sizeof(h5str_t)); - h5str_new(&h5str, 4 * size); - - if (h5str.s == NULL) { - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata); - HDfree(rdata); - h5JNIFatalError(env, "H5DreadVL_asstr: failed to allocate buf"); - } /* end if */ - else { - H5T_class_t tclass = H5Tget_class(tid); - /* convert each element to char string */ - for (i=0; i < n; i++) { - h5str.s[0] = '\0'; - h5str_vlsprintf(&h5str, did, tid, rdata+i, 0); - jstr = ENVPTR->NewStringUTF(ENVPAR h5str.s); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - } /* end for */ - h5str_free(&h5str); - - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata); - HDfree(rdata); - } /* end else */ - } /* end else */ - } /* end else */ + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (readBuf = HDcalloc((size_t)n, typeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL_asstr: failed to allocate read buffer"); + + if ((status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Allocate a decent-sized initial string */ + h5str_new(&h5str, 4 * typeSize); + + if (!h5str.s) + H5_JNI_FATAL_ERROR(ENVONLY, "H5DreadVL_asstr: failed to allocate buffer"); + + if ((tclass = H5Tget_class(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Convert each element to a char string */ + for (i = 0; i < (size_t) n; i++) { + h5str.s[0] = '\0'; + + if (!h5str_sprintf(ENVONLY, &h5str, did, tid, &(((char *) readBuf)[i * typeSize]), typeSize, 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, (jsize) i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (h5str.s) + h5str_free(&h5str); + if (readBuf) { + H5Dvlen_reclaim(tid, mem_space, xfer_plist_id, readBuf); + HDfree(readBuf); + } + if (close_mem_space) + H5Sclose(mem_space); return status; } @@ -1264,168 +1305,265 @@ Java_hdf_hdf5lib_H5_H5Dread_1VLStrings (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - htri_t isVlenStr=0; + htri_t isVlenStr = 0; + herr_t status = FAIL; - if (buf == NULL) { - h5nullArgument(env, "H5Dread_VLStrings: buf is NULL"); - } /* end if */ - else { - isVlenStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); + UNUSED(clss); - if (isVlenStr) { - status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); - } /* end if */ - else - h5badArgument(env, "H5Dread_VLStrings: type is not variable length String"); - } /* end else */ + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_VLStrings: read buffer is NULL"); + if ((isVlenStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (isVlenStr) { + if ((status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + else + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_VLStrings: datatype is not variable length String"); + +done: return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1VLStrings */ -herr_t -H5DreadVL_str - (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf) +/* + * Class: hdf_hdf5lib_H5 + * Method: H5DwriteVL + * Signature: (JJJJJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5DwriteVL + (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, + jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - char **strs; - jstring jstr; - jint i; - jint n; - herr_t status = -1; + H5T_class_t type_class; + htri_t isStr = 0; + htri_t isVlenStr = 0; + htri_t isComplex = 0; + htri_t isComplex2 = 0; + hid_t nested_tid = H5I_INVALID_HID; + herr_t status = FAIL; - n = ENVPTR->GetArrayLength(ENVPAR buf); - strs =(char**)HDcalloc((size_t)n, sizeof(char*)); + UNUSED(clss); - if (strs == NULL) { - h5JNIFatalError(env, "H5DreadVL_str: failed to allocate buff for read variable length strings"); - } /* end if */ - else { - status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, strs); + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL"); - if (status < 0) { - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, strs); - HDfree(strs); - h5JNIFatalError(env, "H5DreadVL_str: failed to read variable length strings"); - } /* end if */ - else { - for (i=0; i < n; i++) { - jstr = ENVPTR->NewStringUTF(ENVPAR strs[i]); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - H5free_memory (strs[i]); - } /* end for */ + if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - /* - for repeatedly reading a dataset with a large number of strs (e.g., 1,000,000 strings, - H5Dvlen_reclaim() may crash on Windows because the Java GC will not be able to collect - free space in time. Instead, use "H5free_memory(strs[i])" above to free individual strings - after it is done. - H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, strs); - */ + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - HDfree(strs); - } /* end else */ - } /* end else */ + if (type_class == H5T_COMPOUND) { + unsigned i; + int num_members; - return status; -} /* end H5DreadVL_str */ + if ((num_members = H5Tget_nmembers(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (unsigned) num_members; i++) { + if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + isComplex = isComplex || isComplex2; + + if (H5Tclose(nested_tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nested_tid = H5I_INVALID_HID; + } + } + else if (type_class == H5T_VLEN) { + isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */ + } + + if (!isStr || isComplex || isVlenStr) { + if ((status = H5DwriteVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else if (isStr) { + if ((status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (nested_tid >= 0) + H5Tclose(nested_tid); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VL */ /* - * Class: hdf_hdf5lib_H5 - * Method: H5DwriteVL - * Signature: (JJJJJ[Ljava/lang/String;)I + * Helper method to convert an array of Java strings into a buffer of C-strings. + * The buffer of C-strings is then written to the HDF5 dataset specified. */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5DwriteVL - (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, - jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) +static herr_t +H5DwriteVL_str + (JNIEnv *env, hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - htri_t isStr = 0; - htri_t isVlenStr = 0; - htri_t isComplex = 0; + const char *utf8 = NULL; + jstring obj; + jsize size; + jsize i; + char **writeBuf = NULL; + herr_t status = FAIL; + + if ((size = ENVPTR->GetArrayLength(ENVONLY, (jarray) buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL_str: buf length < 0"); + } - if (buf == NULL) { - h5nullArgument(env, "H5DwriteVL: buf is NULL"); - } /* end if */ - else { - isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); - if (H5Tget_class((hid_t)mem_type_id) == H5T_COMPOUND) { - unsigned i; - int nm = H5Tget_nmembers(mem_type_id); - for(i = 0; i 0 || isVlenStr) { - status = H5DwriteVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); + if (NULL == (writeBuf = (char **) HDcalloc((size_t)size + 1, sizeof(char *)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5DwriteVL_str: failed to allocate variable length string write buffer"); + + for (i = 0; i < size; ++i) { + jsize length; + + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + writeBuf[i] = NULL; + continue; } - else if (isStr > 0) { - status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); + + length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5DwriteVL_str: string not pinned"); + + if (NULL == (writeBuf[i] = (char *) HDmalloc((size_t)length + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5DwriteVL_str: failed to allocate string buffer"); + + HDstrncpy(writeBuf[i], utf8, (size_t)length + 1); + writeBuf[i][length] = '\0'; + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } /* end for (i = 0; i < size; ++i) */ + + if ((status = H5Dwrite(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + if (writeBuf) { + for (i = 0; i < size; i++) { + if (writeBuf[i]) + HDfree(writeBuf[i]); } - } /* end else */ - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VL */ + HDfree(writeBuf); + } + + return status; +} /* end H5DwriteVL_str */ -herr_t +/* + * Helper method to convert an array of Java strings into a buffer of + * variable-length (hvl_t) elements. The buffer of variable-length + * elements is then written to the HDF5 dataset. + */ +static herr_t H5DwriteVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - hvl_t *wdata; - jsize size; - jint i; - jint n; + const char *utf8 = NULL; + jstring obj; + hbool_t close_mem_space = FALSE; + size_t typeSize; + size_t i; + hid_t mem_space = mem_sid; + jsize n; + void *writeBuf = NULL; + herr_t status = FAIL; + + if (mem_space == H5S_ALL) { + mem_space = file_sid; + + if (mem_space == H5S_ALL) { + /* + * Retrieve a valid dataspace for H5Dvlen_reclaim(). + */ + if ((mem_space = H5Dget_space(did)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + close_mem_space = TRUE; + + if (H5Sselect_all(mem_space) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + } - /* Get size of string array */ - n = ENVPTR->GetArrayLength(ENVPAR buf); - wdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL_asstr: buf length < 0"); + } - if (wdata == NULL) { - h5JNIFatalError(env, "H5DwriteVL_asstr: failed to allocate buff for write"); - } /* end if */ - else { - for (i = 0; i < n; ++i) { - jstring obj = (jstring) ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray)buf, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); - if (utf8) { - h5str_vlconvert(utf8, did, tid, wdata+i, 0); - } /* end if */ + if (NULL == (writeBuf = HDcalloc((size_t)n, typeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AwriteVL_asstr: failed to allocate write buffer"); - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for (i = 0; i < size; ++i) */ + for (i = 0; i < (size_t) n; ++i) { + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - status = H5Dwrite(did, tid, mem_sid, file_sid, xfer_plist_id, wdata); + /* + * If the string object was NULL, skip it. + */ + HDmemset(&(((char *) writeBuf)[i * typeSize]), 0, typeSize); + continue; + } - /* now free memory*/ - for (i = 0; i < n; i++) { - if(wdata+i) { - HDfree(wdata+i); - } /* end if */ - } /* end for */ - HDfree(wdata); + /* + * length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + */ - if (status < 0) - h5libraryError(env); - } /* end else */ + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5DwriteVL_asstr: failed to pin string buffer"); + + /* + * TODO: If the string isn't a copy, we should probably make + * one before destroying it with h5str_convert. + */ + + if (!h5str_convert(ENVONLY, (char **) &utf8, did, tid, &(((char *) writeBuf)[i * typeSize]), 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } /* end for (i = 0; i < size; ++i) */ + + if ((status = H5Dwrite(did, tid, mem_sid, file_sid, xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (utf8) + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + if (writeBuf) { + H5Dvlen_reclaim(tid, mem_space, xfer_plist_id, writeBuf); + HDfree(writeBuf); + } + if (close_mem_space) + H5Sclose(mem_space); return status; } /* end H5DwriteVL_asstr */ @@ -1440,79 +1578,28 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - htri_t isVlenStr=0; - - if (buf == NULL) { - h5nullArgument(env, "H5Dwrite_VLStrings: buf is NULL"); - } /* end if */ - else { - isVlenStr = H5Tis_variable_str((hid_t)mem_type_id); + htri_t isVlenStr = 0; + herr_t status = FAIL; - if (isVlenStr) { - status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, - (hid_t)mem_space_id, (hid_t)file_space_id, - (hid_t)xfer_plist_id, buf); - } /* end if */ - else - h5badArgument(env, "H5Dwrite_VLStrings: type is not variable length String"); - } /* end else */ + UNUSED(clss); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings */ - -herr_t -H5DwriteVL_str - (JNIEnv *env, hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, jobjectArray buf) -{ - herr_t status = -1; - char **wdata; - jsize size; - jsize i; + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_VLStrings: write buffer is NULL"); - size = ENVPTR->GetArrayLength(ENVPAR (jarray) buf); - wdata = (char**)HDmalloc((size_t)size * sizeof (char*)); + if ((isVlenStr = H5Tis_variable_str((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (!wdata) { - h5JNIFatalError(env, "H5DwriteVL_str: cannot allocate buffer"); + if (isVlenStr) { + if ((status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); } /* end if */ - else { - HDmemset(wdata, 0, (size_t)size * sizeof(char*)); - for (i = 0; i < size; ++i) { - jstring obj = (jstring) ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray)buf, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); - - if (utf8) { - wdata[i] = (char*)HDmalloc((size_t)length + 1); - if (wdata[i]) { - HDmemset(wdata[i], 0, (size_t)length + 1); - HDstrncpy(wdata[i], utf8, (size_t)length + 1); - } /* end if */ - } /* end if */ - - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for (i = 0; i < size; ++i) */ - - status = H5Dwrite(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, wdata); - - /* now free memory*/ - for (i = 0; i < size; i++) { - if(wdata[i]) { - HDfree(wdata[i]); - } /* end if */ - } /* end for */ - HDfree(wdata); - - if (status < 0) - h5libraryError(env); - } /* end else */ + else + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_VLStrings: datatype is not variable length String"); - return status; -} /* end H5DwriteVL_str */ +done: + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings */ /* * Class: hdf_hdf5lib_H5 @@ -1525,49 +1612,52 @@ Java_hdf_hdf5lib_H5_H5Dread_1reg_1ref jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - herr_t status = -1; - h5str_t h5str; - size_t size; - hdset_reg_ref_t *ref_data; - jint i; - jint n; - jstring jstr; + hdset_reg_ref_t *ref_data = NULL; + h5str_t h5str; + jstring jstr; + jsize i, n; + herr_t status = FAIL; - hid_t region = -1; - hid_t did = (hid_t) dataset_id; - hid_t tid = (hid_t) mem_type_id; - hid_t mem_sid = (hid_t) mem_space_id; - hid_t file_sid = (hid_t) file_space_id; + UNUSED(clss); - n = ENVPTR->GetArrayLength(ENVPAR buf); - size = sizeof(hdset_reg_ref_t); /*H5Tget_size(tid);*/ - ref_data = (hdset_reg_ref_t*)HDmalloc(size * (size_t)n); + HDmemset(&h5str, 0, sizeof(h5str_t)); - if (ref_data == NULL) { - h5JNIFatalError(env, "H5Dread_reg_ref: failed to allocate buff for read"); - return -1; - } /* end if */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_reg_ref: buf length < 0"); + } - status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, ref_data); + if (NULL == (ref_data = (hdset_reg_ref_t *) HDmalloc((size_t)n * sizeof(hdset_reg_ref_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dread_reg_ref: failed to allocate read buffer"); - if (status < 0) { - HDfree(ref_data); - h5JNIFatalError(env, "H5Dread_reg_ref: failed to read data"); - return -1; - } /* end if */ + if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, (hid_t)file_space_id, xfer_plist_id, ref_data)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - HDmemset(&h5str, 0, sizeof(h5str_t)); h5str_new(&h5str, 1024); - for (i=0; iNewStringUTF(ENVPAR h5str.s); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); + if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)dataset_id, (hid_t)mem_type_id, &ref_data[i], 0, 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); } /* end for */ - h5str_free(&h5str); - HDfree(ref_data); +done: + if (h5str.s) + h5str_free(&h5str); + if (ref_data) + HDfree(ref_data); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Dread_1reg_1ref */ @@ -1582,17 +1672,19 @@ Java_hdf_hdf5lib_H5__1H5Dcreate2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type_id, jlong space_id, jlong link_plist_id, jlong create_plist_id, jlong access_plist_id) { - hid_t dset_id = -1; - const char *fileName; + const char *dsetName = NULL; + hid_t dset_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, dsetName, NULL, "H5Dcreate2: dataset name not pinned"); + + if ((dset_id = H5Dcreate2((hid_t)loc_id, dsetName, (hid_t)type_id, (hid_t)space_id, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dsetName) + UNPIN_JAVA_STRING(ENVONLY, name, dsetName); return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dcreate2 */ @@ -1606,17 +1698,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dopen2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist) { - hid_t dset_id = -1; - const char *fileName; + const char *dsetName = NULL; + hid_t dset_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - dset_id = H5Dopen2((hid_t)loc_id, fileName, (hid_t)access_plist); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, dsetName, NULL, "H5Dopen2: dataset name not pinned"); + + if ((dset_id = H5Dopen2((hid_t)loc_id, dsetName, (hid_t)access_plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dsetName) + UNPIN_JAVA_STRING(ENVONLY, name, dsetName); return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dopen2 */ @@ -1630,12 +1724,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dcreate_1anon (JNIEnv *env, jclass clss, jlong loc_id, jlong type_id, jlong space_id, jlong dcpl_id, jlong dapl_id) { - hid_t dset_id = -1; + hid_t dset_id = H5I_INVALID_HID; + + UNUSED(clss); - dset_id = H5Dcreate_anon((hid_t)loc_id, (hid_t)type_id, (hid_t)space_id, (hid_t)dcpl_id, (hid_t)dapl_id); - if (dset_id < 0) - h5libraryError(env); + if ((dset_id = H5Dcreate_anon((hid_t)loc_id, (hid_t)type_id, (hid_t)space_id, (hid_t)dcpl_id, (hid_t)dapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dcreate_1anon */ @@ -1650,9 +1746,12 @@ Java_hdf_hdf5lib_H5_H5Dget_1space_1status { H5D_space_status_t space_status = H5D_SPACE_STATUS_ERROR; + UNUSED(clss); + if (H5Dget_space_status((hid_t)loc_id, &space_status) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)space_status; } /* end Java_hdf_hdf5lib_H5_H5Dget_1space_1status */ @@ -1665,12 +1764,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Dget_1access_1plist (JNIEnv *env, jclass clss, jlong loc_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Dget_access_plist((hid_t)loc_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Dget_access_plist((hid_t)loc_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Dget_1access_1plist */ @@ -1685,10 +1786,12 @@ Java_hdf_hdf5lib_H5_H5Dget_1offset { haddr_t offset = HADDR_UNDEF; - offset = H5Dget_offset((hid_t)loc_id); - if (offset == HADDR_UNDEF) - h5libraryError(env); + UNUSED(clss); + if (HADDR_UNDEF == (offset = H5Dget_offset((hid_t)loc_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)offset; } /* end Java_hdf_hdf5lib_H5_H5Dget_1offset */ @@ -1701,12 +1804,15 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Dvlen_1get_1buf_1size (JNIEnv *env, jclass clss, jlong dataset_id, jlong type_id, jlong space_id) { - hsize_t sz = 0; + hsize_t sz = 0; + + UNUSED(clss); - if (H5Dvlen_get_buf_size((hid_t)dataset_id, (hid_t)type_id, (hid_t)space_id, &sz) < 0) - h5libraryError(env); + if (H5Dvlen_get_buf_size((hid_t)dataset_id, (hid_t)type_id, (hid_t)space_id, &sz) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jlong)sz; +done: + return (jlong)sz; } /* end Java_hdf_hdf5lib_H5_H5Dvlen_1get_1buf_1size_1long */ /* @@ -1718,49 +1824,36 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Dfill (JNIEnv *env, jclass clss, jbyteArray fill, jlong fill_type_id, jbyteArray buf, jlong buf_type_id, jlong space_id) { - herr_t status; - jbyte *fillP; - jbyte *buffP; jboolean isCopy1; jboolean isCopy2; + herr_t status; + jbyte *fillP = NULL; + jbyte *buffP = NULL; + UNUSED(clss); - if (buf == NULL) { - h5nullArgument(env, "H5Dfill: buf is NULL"); - } /* end if */ - else { - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy2); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dfill: buf not pinned"); - } /* end if */ - else { - if(fill) { - fillP = ENVPTR->GetByteArrayElements(ENVPAR fill, &isCopy1); - if (fillP == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5JNIFatalError( env, "H5Dfill: fill not pinned"); - return; - } /* end if */ - } /* end if */ - else - fillP = NULL; - - status = H5Dfill((const void*)fillP, (hid_t)fill_type_id, (void*)buffP, (hid_t)buf_type_id, (hid_t)space_id); - if(fillP) { - /* free the buffer without copying back */ - ENVPTR->ReleaseByteArrayElements(ENVPAR fill, fillP, JNI_ABORT); - } /* end if */ - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - if (isCopy2 == JNI_TRUE) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); - } /* end if */ - } /* end else */ - } + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dfill: buffer is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, buf, buffP, &isCopy2, "H5Dfill: buffer not pinned"); + + if (fill) { + PIN_BYTE_ARRAY(ENVONLY, fill, fillP, &isCopy1, "H5Dfill: fill buffer not pinned"); + } + + if ((status = H5Dfill((const void *)fillP, (hid_t)fill_type_id, (void *)buffP, (hid_t)buf_type_id, (hid_t)space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (fillP) { + UNPIN_BYTE_ARRAY(ENVONLY, fill, fillP, JNI_ABORT); + fillP = NULL; } + +done: + if (fillP) + UNPIN_BYTE_ARRAY(ENVONLY, fill, fillP, JNI_ABORT); + if (buffP) + UNPIN_BYTE_ARRAY(ENVONLY, buf, buffP, (status < 0) ? JNI_ABORT : 0); } /* end Java_hdf_hdf5lib_H5_H5Dfill */ /* @@ -1772,106 +1865,97 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Dset_1extent (JNIEnv *env, jclass clss, jlong loc_id, jlongArray buf) { + jboolean isCopy; + hsize_t *dims = NULL; herr_t status; - hsize_t *dims; - jlong *buffP; jsize rank; - jboolean isCopy; + jlong *dimsBuf = NULL; int i = 0; - if (buf == NULL) { - h5nullArgument(env, "H5Dset_extent: buf is NULL"); - } /* end if */ - else { - rank = ENVPTR->GetArrayLength(ENVPAR buf); - if (rank <= 0) { - h5JNIFatalError(env, "H5Dset_extent: rank <=0"); - } /* end if */ - else { - buffP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy); - if (buffP == NULL) { - h5JNIFatalError( env, "H5Dset_extent: buf not pinned"); - } /* end if */ - else { - dims = (hsize_t*)HDmalloc((size_t)rank * sizeof(hsize_t)); - for (i = 0; i< rank; i++) - dims[i] = (hsize_t)buffP[i]; - - status = H5Dset_extent((hid_t)loc_id, (hsize_t*)dims); - - HDfree (dims); - - /* free the buffer without copying back */ - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, buffP, JNI_ABORT); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - } /* end else */ - } /* end else */ + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dset_extent: buffer is NULL"); + + if ((rank = ENVPTR->GetArrayLength(ENVONLY, buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dset_extent: buf length <= 0"); } + + PIN_LONG_ARRAY(ENVONLY, buf, dimsBuf, &isCopy, "H5Dset_extent: buffer not pinned"); + + if (NULL == (dims = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dset_extent: failed to allocate dataset dimension buffer"); + + for (i = 0; i < rank; i++) + dims[i] = (hsize_t)dimsBuf[i]; + + if ((status = H5Dset_extent((hid_t)loc_id, (hsize_t *)dims)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dims) + HDfree(dims); + if (dimsBuf) + UNPIN_LONG_ARRAY(ENVONLY, buf, dimsBuf, JNI_ABORT); } /* end Java_hdf_hdf5lib_H5_H5Dset_1extent */ static herr_t H5D_iterate_cb - (void* elem, hid_t elem_id, unsigned ndim, const hsize_t *point, void *cb_data) { - JNIEnv *cbenv; - jint status; - jclass cls; - jmethodID mid; - jbyteArray elemArray; - jlongArray pointArray; - jsize size; + (void *elem, hid_t elem_id, unsigned ndim, const hsize_t *point, void *cb_data) { cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; + jbyteArray elemArray; + jlongArray pointArray; + jmethodID mid; + jobject visit_callback = wrapper->visit_callback; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = FAIL; + jsize size; + void *op_data = (void *)wrapper->op_data; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5D_iterate_cb: failed to attach current thread to JVM"); + } - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) != 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "([BJI[JLhdf/hdf5lib/callbacks/H5D_iterate_t;)I"); - if (mid == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - if (elem == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - if (point == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "([BJI[JLhdf/hdf5lib/callbacks/H5D_iterate_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - size = (jsize)H5Tget_size(elem_id); - elemArray = CBENVPTR->NewByteArray(CBENVPAR size); - if (elemArray == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - CBENVPTR->SetByteArrayRegion(CBENVPAR elemArray, 0, size, (jbyte *)elem); + if (NULL == elem) + H5_NULL_ARGUMENT_ERROR(CBENVONLY, "H5D_iterate_cb: element buffer is NULL"); + if (NULL == point) + H5_NULL_ARGUMENT_ERROR(CBENVONLY, "H5D_iterate_cb: point is NULL"); - pointArray = CBENVPTR->NewLongArray(CBENVPAR 2); - if (pointArray == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - CBENVPTR->SetLongArrayRegion(CBENVPAR pointArray, 0, 2, (const jlong *)point); + if (!(size = (jsize)H5Tget_size(elem_id))) + H5_LIBRARY_ERROR(CBENVONLY); - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, (void*)elemArray, elem_id, ndim, pointArray, op_data); + if (NULL == (elemArray = CBENVPTR->NewByteArray(CBENVONLY, size))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - CBENVPTR->GetByteArrayRegion(CBENVPAR elemArray, 0, size, (jbyte *)elem); + CBENVPTR->SetByteArrayRegion(CBENVONLY, elemArray, 0, size, (jbyte *)elem); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - JVMPTR->DetachCurrentThread(JVMPAR); + if (NULL == (pointArray = CBENVPTR->NewLongArray(CBENVONLY, 2))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return status; + CBENVPTR->SetLongArrayRegion(CBENVONLY, pointArray, 0, 2, (const jlong *)point); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, (void *)elemArray, elem_id, ndim, pointArray, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + CBENVPTR->GetByteArrayRegion(CBENVONLY, elemArray, 0, size, (jbyte *)elem); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); + + return (herr_t)status; } /* end H5D_iterate_cb */ /* @@ -1884,41 +1968,31 @@ Java_hdf_hdf5lib_H5_H5Diterate (JNIEnv *env, jclass clss, jbyteArray buf, jlong buf_type, jlong space, jobject callback_op, jobject op_data) { - herr_t status = -1; - jboolean isCopy; - jbyte *buffP; - cb_wrapper wrapper = {callback_op, op_data}; + cb_wrapper wrapper = { callback_op, op_data }; + jboolean isCopy; + jbyte *iterBuf = NULL; + herr_t status = FAIL; - ENVPTR->GetJavaVM(ENVPAR &jvm); + UNUSED(clss); - if (op_data == NULL) { - h5nullArgument(env, "H5Diterate: op_data is NULL"); - } /* end if */ - else if (callback_op == NULL) { - h5nullArgument(env, "H5Diterate: callback_op is NULL"); - } /* end if */ - else if (buf == NULL) { - h5nullArgument(env, "H5Diterate: buf is NULL"); - } /* end if */ - else { - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Diterate: buf not pinned"); - } /* end if */ - else { - status = H5Diterate((void*)buffP, (hid_t)buf_type, (hid_t)space, (H5D_operator_t)H5D_iterate_cb, (void*)&wrapper); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - if (isCopy == JNI_TRUE) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); - } /* end if */ - } /* end else */ - } /* end else */ - } + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Diterate: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Diterate: callback_op is NULL"); + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Diterate: buffer is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, buf, iterBuf, &isCopy, "H5Diterate: buffer not pinned"); + + if ((status = H5Diterate((void *)iterBuf, (hid_t)buf_type, (hid_t)space, (H5D_operator_t)H5D_iterate_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (iterBuf) + UNPIN_BYTE_ARRAY(ENVONLY, buf, iterBuf, (status < 0) ? (JNI_ABORT) : ((isCopy == JNI_TRUE) ? 0 : JNI_ABORT)); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Diterate */ @@ -1932,8 +2006,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Dflush (JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Dflush((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* @@ -1945,11 +2024,14 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Drefresh (JNIEnv *env, jclass clss, jlong loc_id) { - if (H5Drefresh((hid_t)loc_id) < 0) - h5libraryError(env); -} + UNUSED(clss); + if (H5Drefresh((hid_t)loc_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: + return; +} #ifdef __cplusplus } /* end extern "C" */ diff --git a/java/src/jni/h5eImp.c b/java/src/jni/h5eImp.c index 9c80461..1c5a5a9 100644 --- a/java/src/jni/h5eImp.c +++ b/java/src/jni/h5eImp.c @@ -39,6 +39,9 @@ extern "C" { #include "h5jni.h" #include "h5eImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; typedef struct _cb_wrapper { @@ -46,20 +49,6 @@ typedef struct _cb_wrapper { jobject op_data; } cb_wrapper; -#ifdef __cplusplus - #define CBENVPTR (cbenv) - #define CBENVPAR - #define JVMPTR (jvm) - #define JVMPAR - #define JVMPAR2 -#else /* __cplusplus */ - #define CBENVPTR (*cbenv) - #define CBENVPAR cbenv, - #define JVMPTR (*jvm) - #define JVMPAR jvm - #define JVMPAR2 jvm, -#endif /* __cplusplus */ - /********************/ /* Local Prototypes */ /********************/ @@ -77,12 +66,15 @@ Java_hdf_hdf5lib_H5_H5Eauto_1is_1v2 { unsigned int is_stack = 0; - if (stk_id < 0) { - h5badArgument(env, "H5Eauto_is_v2: invalid argument"); - } /* end if */ - else if (H5Eauto_is_v2((hid_t)stk_id, &is_stack) < 0) - h5libraryError(env); + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eauto_is_v2: invalid stack ID"); + if (H5Eauto_is_v2((hid_t)stk_id, &is_stack) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jboolean)is_stack; } /* end Java_hdf_hdf5lib_H5_H5Eauto_1is_1v2 */ @@ -95,20 +87,27 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Eregister_1class (JNIEnv *env, jclass cls, jstring cls_name, jstring lib_name, jstring version) { - hid_t ret_val = -1; - const char* the_cls_name; - const char* the_lib_name; - const char* the_version; + const char* the_cls_name = NULL; + const char* the_lib_name = NULL; + const char* the_version = NULL; + hid_t ret_val = H5I_INVALID_HID; - PIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version); - if (the_cls_name != NULL && the_lib_name != NULL && the_version != NULL) { - ret_val = H5Eregister_class(the_cls_name, the_lib_name, the_version); + UNUSED(cls); - UNPIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version); + PIN_JAVA_STRING(ENVONLY, cls_name, the_cls_name, NULL, "H5Eregister_class: class name not pinned"); + PIN_JAVA_STRING(ENVONLY, lib_name, the_lib_name, NULL, "H5Eregister_class: lib name not pinned"); + PIN_JAVA_STRING(ENVONLY, version, the_version, NULL, "H5Eregister_class: version string not pinned"); - if (ret_val < 0) - h5libraryError(env); - } + if ((ret_val = H5Eregister_class(the_cls_name, the_lib_name, the_version)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (the_version) + UNPIN_JAVA_STRING(ENVONLY, version, the_version); + if (the_lib_name) + UNPIN_JAVA_STRING(ENVONLY, lib_name, the_lib_name); + if (the_cls_name) + UNPIN_JAVA_STRING(ENVONLY, cls_name, the_cls_name); return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Eregister_1class */ @@ -122,11 +121,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eunregister_1class (JNIEnv *env, jclass cls, jlong cls_id) { - if (cls_id < 0) { - h5badArgument(env, "H5Eunregister_class: invalid argument"); - } /* end if */ - else if (H5Eunregister_class((hid_t)cls_id) < 0) - h5libraryError(env); + UNUSED(cls); + + if (cls_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eunregister_class: invalid error class ID"); + + if (H5Eunregister_class((hid_t)cls_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eunregister_1class */ /* @@ -138,11 +142,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eclose_1msg (JNIEnv *env, jclass cls, jlong err_id) { - if (err_id < 0) { - h5badArgument(env, "H5Eclose_msg: invalid argument"); - } /* end if */ - else if (H5Eclose_msg((hid_t)err_id) < 0) - h5libraryError(env); + UNUSED(cls); + + if (err_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eclose_msg: invalid error message ID"); + + if (H5Eclose_msg((hid_t)err_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eclose_1msg */ /* @@ -154,24 +163,23 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Ecreate_1msg (JNIEnv *env, jclass cls, jlong err_id, jint msg_type, jstring err_msg) { - hid_t ret_val = -1; - const char *the_err_msg; H5E_type_t error_msg_type = (H5E_type_t)msg_type; + const char *the_err_msg = NULL; + hid_t ret_val = H5I_INVALID_HID; - if (err_id < 0) { - h5badArgument(env, "H5Ecreate_msg: invalid argument"); - } /* end if */ - else { - PIN_JAVA_STRING(err_msg, the_err_msg); - if (the_err_msg != NULL) { - ret_val = H5Ecreate_msg((hid_t)err_id, error_msg_type, the_err_msg); + UNUSED(cls); - UNPIN_JAVA_STRING(err_msg, the_err_msg); + if (err_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Ecreate_msg: invalid error class ID"); - if (ret_val < 0) - h5libraryError(env); - } - } /* end else */ + PIN_JAVA_STRING(ENVONLY, err_msg, the_err_msg, NULL, "H5Ecreate_msg: error message string not pinned"); + + if ((ret_val = H5Ecreate_msg((hid_t)err_id, error_msg_type, the_err_msg)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (the_err_msg) + UNPIN_JAVA_STRING(ENVONLY, err_msg, the_err_msg); return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Ecreate_1msg */ @@ -185,12 +193,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Ecreate_1stack (JNIEnv *env, jclass cls) { - hid_t ret_val = -1; + hid_t ret_val = H5I_INVALID_HID; + + UNUSED(cls); - ret_val = H5Ecreate_stack(); - if (ret_val < 0) - h5libraryError(env); + if ((ret_val = H5Ecreate_stack()) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Ecreate_1stack */ @@ -203,12 +213,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Eget_1current_1stack (JNIEnv *env, jclass cls) { - hid_t ret_val = -1; + hid_t ret_val = H5I_INVALID_HID; - ret_val = H5Eget_current_stack(); - if (ret_val < 0) - h5libraryError(env); + UNUSED(cls); + if ((ret_val = H5Eget_current_stack()) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Eget_1current_1stack */ @@ -221,11 +233,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eclose_1stack (JNIEnv *env, jclass cls, jlong stk_id) { - if (stk_id < 0) { - h5badArgument(env, "H5Eclose_stack: invalid argument"); - } /* end if */ - else if (H5Eclose_stack((hid_t)stk_id) < 0) - h5libraryError(env); + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eclose_stack: invalid error stack ID"); + + if (H5Eclose_stack((hid_t)stk_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eclose_1stack */ /* @@ -237,20 +254,24 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eprint2 (JNIEnv *env, jclass cls, jlong stk_id, jobject stream_obj) { - herr_t ret_val = -1; + herr_t ret_val = FAIL; + + UNUSED(cls); - if (stk_id < 0) { - h5badArgument(env, "H5Eprint2: invalid argument"); - } /* end if */ + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eprint2: invalid error stack ID"); + + if (!stream_obj) { + if ((ret_val = H5Eprint2((hid_t)stk_id, stdout)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } else { - if(!stream_obj) - ret_val = H5Eprint2((hid_t)stk_id, stdout); - else - ret_val = H5Eprint2((hid_t)stk_id, (FILE*)stream_obj); - - if (ret_val < 0) - h5libraryError(env); - } /* end else */ + if ((ret_val = H5Eprint2((hid_t)stk_id, (FILE *)stream_obj)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eprint2 */ /* @@ -262,43 +283,36 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Eget_1class_1name (JNIEnv *env, jclass cls, jlong cls_id) { - char *namePtr; - jstring str = NULL; - ssize_t buf_size; + jstring str = NULL; + ssize_t buf_size; + char *namePtr = NULL; + + UNUSED(cls); + + if (cls_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eget_class_name: invalid error class ID"); + + /* Get the length of the name */ + if ((buf_size = H5Eget_class_name((hid_t)cls_id, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!buf_size) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eget_class_name: no class name"); + + if (NULL == (namePtr = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Eget_class_name: malloc failed"); + + if ((H5Eget_class_name((hid_t)cls_id, (char *)namePtr, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + namePtr[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, namePtr))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (namePtr) + HDfree(namePtr); - if (cls_id < 0) { - h5badArgument(env, "H5Eget_class_name: invalid argument"); - } /* end if */ - else { - /* get the length of the name */ - buf_size = H5Eget_class_name((hid_t)cls_id, NULL, 0); - - if (buf_size < 0) { - h5badArgument( env, "H5Eget_class_name: buf_size < 0"); - } /* end if */ - else if (buf_size == 0) { - h5badArgument( env, "H5Eget_class_name: No class name"); - } /* end else if */ - else { - buf_size++; /* add extra space for the null terminator */ - namePtr = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (namePtr == NULL) { - h5outOfMemory( env, "H5Eget_class_name: malloc failed"); - } /* end if */ - else { - buf_size = H5Eget_class_name((hid_t)cls_id, (char *)namePtr, (size_t)buf_size); - - if (buf_size < 0) { - HDfree(namePtr); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR namePtr); - HDfree(namePtr); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ return str; } /* end Java_hdf_hdf5lib_H5_H5Eget_1class_1name */ @@ -311,11 +325,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eset_1current_1stack (JNIEnv *env, jclass cls, jlong stk_id) { - if (stk_id < 0) { - h5badArgument(env, "H5Eset_current_stack: invalid argument"); - } /* end if */ - else if (H5Eset_current_stack((hid_t)stk_id) < 0) - h5libraryError(env); + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eset_current_stack: invalid error stack ID"); + + if (H5Eset_current_stack((hid_t)stk_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eset_1current_1stack */ /* @@ -327,11 +346,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Epop (JNIEnv *env, jclass cls, jlong stk_id, jlong count) { - if (stk_id < 0) { - h5badArgument(env, "H5Epop: invalid argument"); - } /* end if */ - else if (H5Epop((hid_t)stk_id, (size_t)count) < 0) - h5libraryError(env); + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Epop: invalid error stack ID"); + + if (H5Epop((hid_t)stk_id, (size_t)count) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Epop */ /* @@ -344,35 +368,37 @@ Java_hdf_hdf5lib_H5_H5Epush2 (JNIEnv *env, jclass cls, jlong stk_id, jstring filename, jstring funcname, jint linenumber, jlong class_id, jlong major_id, jlong minor_id, jstring err_desc) { - herr_t ret_val = -1; - const char* fName; - const char* fncName; - const char* errMsg; - - if (stk_id < 0) { - h5badArgument(env, "H5Epush: invalid argument"); - } /* end if */ - else if (class_id < 0) { - h5badArgument(env, "H5Epush: invalid class_id argument"); - } /* end else if */ - else if (major_id < 0) { - h5badArgument(env, "H5Epush: invalid major_id argument"); - } /* end else if */ - else if (minor_id < 0) { - h5badArgument(env, "H5Epush: invalid minor_id argument"); - } /* end else if */ - else { - PIN_JAVA_STRING_THREE(filename, fName, funcname, fncName, err_desc, errMsg); - if (fName != NULL && fncName != NULL && errMsg != NULL) { - ret_val = H5Epush2((hid_t)stk_id, fName, fncName, (unsigned)linenumber, (hid_t)class_id, - (hid_t)major_id, (hid_t)minor_id, errMsg); - - UNPIN_JAVA_STRING_THREE(filename, fName, funcname, fncName, err_desc, errMsg); - - if (ret_val < 0) - h5libraryError(env); - } - } /* end else */ + const char *fName = NULL; + const char *fncName = NULL; + const char *errMsg = NULL; + herr_t ret_val = FAIL; + + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Epush: invalid error stack ID"); + if (class_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Epush: invalid error class ID"); + if (major_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Epush: invalid major error class ID"); + if (minor_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Epush: invalid minor error class ID"); + + PIN_JAVA_STRING(ENVONLY, filename, fName, NULL, "H5Epush2: filename not pinned"); + PIN_JAVA_STRING(ENVONLY, funcname, fncName, NULL, "H5Epush2: function name not pinned"); + PIN_JAVA_STRING(ENVONLY, err_desc, errMsg, NULL, "H5Epush2: error message not pinned"); + + if ((ret_val = H5Epush2((hid_t)stk_id, fName, fncName, (unsigned)linenumber, (hid_t)class_id, + (hid_t)major_id, (hid_t)minor_id, errMsg)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (errMsg) + UNPIN_JAVA_STRING(ENVONLY, err_desc, errMsg); + if (fncName) + UNPIN_JAVA_STRING(ENVONLY, funcname, fncName); + if (fName) + UNPIN_JAVA_STRING(ENVONLY, filename, fName); } /* end Java_hdf_hdf5lib_H5_H5Epush2 */ /* @@ -384,11 +410,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eclear2 (JNIEnv *env, jclass cls, jlong stk_id) { - if (stk_id < 0) { - h5badArgument(env, "H5Eclear2: invalid argument"); - } /* end if */ - else if (H5Eclear2((hid_t)stk_id) < 0) - h5libraryError(env); + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eclear2: invalid error stack ID"); + + if (H5Eclear2((hid_t)stk_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Eclear2 */ /* @@ -400,57 +431,45 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Eget_1msg (JNIEnv *env, jclass cls, jlong msg_id, jintArray error_msg_type_list) { - char *namePtr; - jstring str = NULL; - jboolean isCopy; - ssize_t buf_size; - jint *theArray; - H5E_type_t error_msg_type; - - if (msg_id < 0) { - h5badArgument(env, "H5Eget_msg: invalid argument"); - } /* end if */ - else if (error_msg_type_list == NULL) { - h5nullArgument(env, "H5Eget_msg: error_msg_type_list is NULL"); - } /* end if */ - else { - /* get the length of the name */ - buf_size = H5Eget_msg((hid_t)msg_id, NULL, NULL, 0); - - if ((buf_size < 0) || (buf_size == 0)) { - h5JNIFatalError(env, "H5Eget_msg: Invalid message"); - } /* end if */ - else { - buf_size++; /* add extra space for the null terminator */ - namePtr = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (namePtr == NULL) { - h5outOfMemory(env, "H5Eget_msg: malloc failed"); - } /* end if */ - else { - theArray = (jint*)ENVPTR->GetIntArrayElements(ENVPAR error_msg_type_list, &isCopy); - if (theArray == NULL) { - HDfree(namePtr); - h5JNIFatalError(env, "H5Eget_msg: error_msg_type_list not pinned"); - } /* end if */ - else { - buf_size = H5Eget_msg((hid_t)msg_id, &error_msg_type, (char *)namePtr, (size_t)buf_size); - - if (buf_size < 0) { - HDfree(namePtr); - ENVPTR->ReleaseIntArrayElements(ENVPAR error_msg_type_list, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = error_msg_type; - ENVPTR->ReleaseIntArrayElements(ENVPAR error_msg_type_list, theArray, 0); - - str = ENVPTR->NewStringUTF(ENVPAR namePtr); - HDfree(namePtr); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + H5E_type_t error_msg_type; + jstring str = NULL; + ssize_t buf_size; + jint *theArray = NULL; + char *namePtr = NULL; + + UNUSED(cls); + + if (msg_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eget_msg: invalid error message ID"); + if (NULL == error_msg_type_list) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Eget_msg: error_msg_type_list is NULL"); + + /* Get the length of the name */ + if ((buf_size = H5Eget_msg((hid_t)msg_id, NULL, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!buf_size) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Eget_msg: invalid message"); + + if (NULL == (namePtr = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Eget_msg: malloc failed"); + + PIN_INT_ARRAY(ENVONLY, error_msg_type_list, theArray, NULL, "H5Eget_msg: error_msg_type_list not pinned"); + + if ((H5Eget_msg((hid_t)msg_id, &error_msg_type, (char *)namePtr, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + namePtr[buf_size] = '\0'; + + theArray[0] = error_msg_type; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, namePtr))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, error_msg_type_list, theArray, 0); + if (namePtr) + HDfree(namePtr); return str; } /* end Java_hdf_hdf5lib_H5_H5Eget_1msg */ @@ -466,14 +485,15 @@ Java_hdf_hdf5lib_H5_H5Eget_1num { ssize_t ret_val = -1; - if (stk_id < 0) { - h5badArgument(env, "H5Eget_num: invalid argument"); - } /* end if */ - else { - ret_val = H5Eget_num((hid_t)stk_id); - if (ret_val < 0) - h5libraryError(env); - } /* end else */ + UNUSED(cls); + + if (stk_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Eget_num: invalid error stack ID"); + + if ((ret_val = H5Eget_num((hid_t)stk_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Eget_1num */ @@ -481,52 +501,67 @@ static herr_t H5E_walk_cb (int nindx, const H5E_error2_t *info, void *cb_data) { - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str1, str2, str3; - jmethodID constructor; - jvalue args[7]; - jobject cb_info_t = NULL; cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(ILhdf/hdf5lib/structs/H5E_error2_t;Lhdf/hdf5lib/callbacks/H5E_walk_t;)I"); - if (mid != 0) { - args[0].j = info->cls_id; - args[1].j = info->maj_num; - args[2].j = info->min_num; - args[3].i = (jint)info->line; - str1 = CBENVPTR->NewStringUTF(CBENVPAR info->func_name); - args[4].l = str1; - str2 = CBENVPTR->NewStringUTF(CBENVPAR info->file_name); - args[5].l = str2; - str3 = CBENVPTR->NewStringUTF(CBENVPAR info->desc); - args[6].l = str3; - // get a reference to your class if you don't have it already - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5E_error2_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); - if (constructor != 0) { - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (cb_info_t == NULL) { - printf("FATAL ERROR: hdf/hdf5lib/structs/H5E_error2_t: Creation failed\n"); - } - else { - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, nindx, cb_info_t, op_data); - } - } /* end if (constructor != 0) */ - } /* end if(cls != 0) */ - } /* end if (mid != 0) */ - } /* end if (cls != 0) */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); + jmethodID constructor; + jmethodID mid; + jobject visit_callback = wrapper->visit_callback; + jstring str1, str2, str3; + jobject cb_info_t = NULL; + jvalue args[7]; + JNIEnv *cbenv = NULL; + jclass cls; + void *op_data = (void *)wrapper->op_data; + jint status = FAIL; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5E_walk_cb: failed to attach current thread to JVM"); + } + + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(ILhdf/hdf5lib/structs/H5E_error2_t;Lhdf/hdf5lib/callbacks/H5E_walk_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[0].j = info->cls_id; + args[1].j = info->maj_num; + args[2].j = info->min_num; + args[3].i = (jint)info->line; + + if (NULL == (str1 = CBENVPTR->NewStringUTF(CBENVONLY, info->func_name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[4].l = str1; + + if (NULL == (str2 = CBENVPTR->NewStringUTF(CBENVONLY, info->file_name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[5].l = str2; + + if (NULL == (str3 = CBENVPTR->NewStringUTF(CBENVONLY, info->desc))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[6].l = str3; + + /* Get a reference to your class if you don't have it already */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5E_error2_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(JJJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, nindx, cb_info_t, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + +done: + if (CBENVONLY) + JVMPTR->DetachCurrentThread(JVMPAR); + return (herr_t)status; } /* end H5E_walk_cb */ @@ -539,15 +574,23 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Ewalk2 (JNIEnv *env, jclass cls, jlong stk_id, jlong direction, jobject callback_op, jobject op_data) { - cb_wrapper wrapper = {callback_op, op_data}; + cb_wrapper wrapper = { callback_op, op_data }; + + UNUSED(cls); + + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ewalk2: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ewalk2: callback_op is NULL"); - ENVPTR->GetJavaVM(ENVPAR &jvm); + if (H5Ewalk2(stk_id, (H5E_direction_t)direction, (H5E_walk2_t)H5E_walk_cb, (void *)&wrapper) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Ewalk2: op_data or callback_op is NULL"); - } /* end if */ - else if (H5Ewalk2(stk_id, (H5E_direction_t)direction, (H5E_walk2_t)H5E_walk_cb, (void*)&wrapper) < 0) - h5libraryError(env); +done: + return; } /* end iJava_hdf_hdf5lib_H5_H5Ewalk2f */ #ifdef __cplusplus diff --git a/java/src/jni/h5fImp.c b/java/src/jni/h5fImp.c index 80adffb..624c788 100644 --- a/java/src/jni/h5fImp.c +++ b/java/src/jni/h5fImp.c @@ -28,7 +28,10 @@ extern "C" { #include "h5fImp.h" #include "h5util.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -39,18 +42,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Fopen (JNIEnv *env, jclass clss, jstring name, jint flags, jlong access_id) { - hid_t status = -1; - const char *fileName; + const char *fileName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - status = H5Fopen(fileName, (unsigned)flags, (hid_t)access_id ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Fopen: file name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Fopen(fileName, (unsigned)flags, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Fopen */ @@ -64,18 +68,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Fcreate (JNIEnv *env, jclass clss, jstring name, jint flags, jlong create_id, jlong access_id) { - hid_t status = -1; - const char *fileName; + const char *fileName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - status = H5Fcreate(fileName, (unsigned)flags, create_id, access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Fcreate: file name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Fcreate(fileName, (unsigned)flags, create_id, access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Fcreate */ @@ -89,12 +94,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Fflush (JNIEnv *env, jclass clss, jlong object_id, jint scope) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Fflush((hid_t)object_id, (H5F_scope_t)scope ); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Fflush((hid_t)object_id, (H5F_scope_t)scope)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Fflush */ @@ -107,34 +114,29 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Fget_1name (JNIEnv *env, jclass cls, jlong file_id) { - char *namePtr; - jstring str = NULL; - ssize_t buf_size; - - /* get the length of the name */ - buf_size = H5Fget_name((hid_t)file_id, NULL, 0); - - if (buf_size <= 0) { - h5badArgument(env, "H5Fget_name: buf_size <= 0"); - } /* end if */ - else { - buf_size++; /* add extra space for the null terminator */ - namePtr = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (namePtr == NULL) { - h5outOfMemory(env, "H5Fget_name: malloc failed"); - } /* end if */ - else { - buf_size = H5Fget_name((hid_t)file_id, namePtr, (size_t)buf_size); - if (buf_size < 0) { - HDfree(namePtr); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR namePtr); - HDfree(namePtr); - }/* end else */ - }/* end else */ - }/* end else */ + jstring str = NULL; + ssize_t buf_size; + char *namePtr = NULL; + + UNUSED(cls); + + /* Get the length of the name */ + if ((buf_size = H5Fget_name((hid_t)file_id, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (namePtr = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Fget_name: malloc failed"); + + if ((H5Fget_name((hid_t)file_id, namePtr, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + namePtr[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, namePtr))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (namePtr) + HDfree(namePtr); return str; } /* end Java_hdf_hdf5lib_H5_H5Fget_1name */ @@ -148,24 +150,26 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Fis_1hdf5 (JNIEnv *env, jclass clss, jstring name) { + const char *fileName = NULL; htri_t bval = JNI_FALSE; + + UNUSED(clss); + #ifdef H5_NO_DEPRECATED_SYMBOLS - h5unimplemented(env, "H5Fis_hdf5: not implemented"); -#else - const char *fileName; + H5_UNIMPLEMENTED(ENVONLY, "H5Fis_hdf5: not implemented"); +#endif - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - bval = H5Fis_hdf5(fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Fis_hdf5: file name not pinned"); - UNPIN_JAVA_STRING(name, fileName); + if ((bval = H5Fis_hdf5(fileName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } -#endif return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Fis_1hdf5 */ @@ -178,20 +182,21 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Fis_1accessible (JNIEnv *env, jclass clss, jstring name, jlong file_id) { + const char *fileName = NULL; htri_t bval = JNI_FALSE; - const char *fileName; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - bval = H5Fis_accessible(fileName, (hid_t)file_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Fis_accessible: file name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5Fis_accessible(fileName, (hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Fis_1accessible */ @@ -205,12 +210,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Fget_1create_1plist (JNIEnv *env, jclass clss, jlong file_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Fget_create_plist((hid_t)file_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Fget_create_plist((hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Fget_1create_1plist */ @@ -223,12 +230,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Fget_1access_1plist (JNIEnv *env, jclass clss, jlong file_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Fget_access_plist((hid_t)file_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Fget_access_plist((hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Fget_1access_1plist */ @@ -243,9 +252,12 @@ Java_hdf_hdf5lib_H5_H5Fget_1intent { unsigned intent = 0; + UNUSED(cls); + if (H5Fget_intent((hid_t)file_id, &intent) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)intent; } /* end Java_hdf_hdf5lib_H5_H5Fget_1intent */ @@ -258,14 +270,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Fclose (JNIEnv *env, jclass clss, jlong file_id) { - herr_t status = -1; + herr_t status = FAIL; - if (file_id > 0) - status = H5Fclose((hid_t)file_id ); + UNUSED(clss); - if (status < 0) - h5libraryError(env); + if ((status = H5Fclose((hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)status; } /* end Java_hdf_hdf5lib_H5__1H5Fclose */ @@ -278,18 +290,19 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Fmount (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong child_id, jlong plist_id) { - herr_t status = -1; - const char *fileName; + const char *fileName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - status = H5Fmount((hid_t)loc_id, fileName, (hid_t)child_id, (hid_t)plist_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Fmount: file name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Fmount((hid_t)loc_id, fileName, (hid_t)child_id, (hid_t)plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Fmount */ @@ -303,18 +316,19 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Funmount (JNIEnv *env, jclass clss, jlong loc_id, jstring name) { - herr_t status = -1; - const char *fileName; + const char *fileName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - status = H5Funmount((hid_t)loc_id, fileName); + UNUSED(clss); - UNPIN_JAVA_STRING(name, fileName); + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Funmount: file name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Funmount((hid_t)loc_id, fileName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Funmount */ @@ -328,11 +342,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Fget_1freespace (JNIEnv *env, jclass cls, jlong file_id) { - hssize_t ret_val = H5Fget_freespace((hid_t)file_id); + hssize_t ret_val = -1; + + UNUSED(cls); - if (ret_val < 0) - h5libraryError(env); + if ((ret_val = H5Fget_freespace((hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Fget_1freespace */ @@ -345,12 +362,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Freopen (JNIEnv *env, jclass clss, jlong file_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Freopen((hid_t)file_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Freopen((hid_t)file_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Freopen */ @@ -364,47 +383,40 @@ Java_hdf_hdf5lib_H5_H5Fget_1obj_1ids (JNIEnv *env, jclass cls, jlong file_id, jint types, jlong maxObjs, jlongArray obj_id_list) { - ssize_t ret_val = -1; - jlong *obj_id_listP; - jboolean isCopy; - hid_t *id_list; - size_t rank; - size_t i; - - if (obj_id_list == NULL) { - h5nullArgument(env, "H5Fget_obj_ids: obj_id_list is NULL"); - } /* end if */ - else { - obj_id_listP = ENVPTR->GetLongArrayElements(ENVPAR obj_id_list, &isCopy); - if (obj_id_listP == NULL) { - h5JNIFatalError(env, "H5Fget_obj_ids: obj_id_list not pinned"); - } /* end if */ - else { - rank = (size_t)ENVPTR->GetArrayLength(ENVPAR obj_id_list); - - id_list = (hid_t *)HDmalloc(rank * sizeof(hid_t)); - if (id_list == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR obj_id_list, obj_id_listP, JNI_ABORT); - h5JNIFatalError(env, "H5Fget_obj_ids: obj_id_list not converted to hid_t"); - } /* end if */ - else { - ret_val = H5Fget_obj_ids((hid_t)file_id, (unsigned int)types, (size_t)maxObjs, id_list); - - if (ret_val < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR obj_id_list, obj_id_listP, JNI_ABORT); - HDfree(id_list); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < rank; i++) { - obj_id_listP[i] = (jlong)id_list[i]; - } /* end for */ - HDfree(id_list); - ENVPTR->ReleaseLongArrayElements(ENVPAR obj_id_list, obj_id_listP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + ssize_t ret_val = -1; + size_t i; + jsize rank; + jlong *obj_id_listP = NULL; + hid_t *id_list = NULL; + + UNUSED(cls); + + if (NULL == obj_id_list) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Fget_obj_ids: obj_id_list is NULL"); + + PIN_LONG_ARRAY(ENVONLY, obj_id_list, obj_id_listP, &isCopy, "H5Fget_obj_ids: obj_id_list not pinned"); + + if ((rank = ENVPTR->GetArrayLength(ENVONLY, obj_id_list)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Fget_obj_ids: obj_id_list length < 0"); + } + + if (NULL == (id_list = (hid_t *) HDmalloc((size_t)rank * sizeof(hid_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Fget_obj_ids: malloc failed"); + + if ((ret_val = H5Fget_obj_ids((hid_t)file_id, (unsigned int)types, (size_t)maxObjs, id_list)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (size_t)rank; i++) { + obj_id_listP[i] = (jlong)id_list[i]; + } /* end for */ + +done: + if (id_list) + HDfree(id_list); + if (obj_id_listP) + UNPIN_LONG_ARRAY(ENVONLY, obj_id_list, obj_id_listP, (ret_val < 0) ? JNI_ABORT : 0); return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Fget_1obj_1ids */ @@ -418,11 +430,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Fget_1obj_1count (JNIEnv *env, jclass cls, jlong file_id, jint types) { - ssize_t ret_val = H5Fget_obj_count((hid_t)file_id, (unsigned int)types); + ssize_t ret_val = -1; + + UNUSED(cls); - if (ret_val < 0) - h5libraryError(env); + if ((ret_val = H5Fget_obj_count((hid_t)file_id, (unsigned int)types)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Fget_1obj_1count_1long */ @@ -437,9 +452,12 @@ Java_hdf_hdf5lib_H5_H5Fget_1filesize { hsize_t size = 0; - if (H5Fget_filesize ((hid_t)file_id, &size) < 0) - h5libraryError(env); + UNUSED(clss); + + if (H5Fget_filesize((hid_t)file_id, &size) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong) size; } /* end Java_hdf_hdf5lib_H5_H5Fget_1filesize */ @@ -454,9 +472,12 @@ Java_hdf_hdf5lib_H5_H5Fget_1mdc_1hit_1rate { double rate = 0.0; + UNUSED(cls); + if (H5Fget_mdc_hit_rate((hid_t)file_id, &rate) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); +done: return (jdouble)rate; } /* end Java_hdf_hdf5lib_H5_H5Fget_1mdc_1hit_1rate */ @@ -469,33 +490,37 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Fget_1mdc_1size (JNIEnv *env, jclass cls, jlong file_id, jlongArray metadata_cache) { - jint size = 0; - jlong *metadata_cache_ptr; - size_t max_size = 0, min_clean_size = 0, cur_size = 0; - int cur_num_entries = -1; - jboolean isCopy; - - if (metadata_cache == NULL) { - h5nullArgument(env, "H5Fget_mdc_size: metadata_cache is NULL"); - } /* end if */ - else { - size = (int)ENVPTR->GetArrayLength(ENVPAR metadata_cache); - if (size < 3) { - h5badArgument(env, "H5Fget_mdc_size: length of metadata_cache < 3."); - } /* end if */ - else { - if (H5Fget_mdc_size((hid_t)file_id, &max_size, &min_clean_size, &cur_size, &cur_num_entries) < 0) { - h5libraryError(env); - } /* end if */ - else { - metadata_cache_ptr = ENVPTR->GetLongArrayElements(ENVPAR metadata_cache, &isCopy); - metadata_cache_ptr[0] = (jlong)max_size; - metadata_cache_ptr[1] = (jlong)min_clean_size; - metadata_cache_ptr[2] = (jlong)cur_size; - ENVPTR->ReleaseLongArrayElements(ENVPAR metadata_cache, metadata_cache_ptr, 0); - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + size_t max_size = 0, min_clean_size = 0, cur_size = 0; + jlong *metadata_cache_ptr = NULL; + jsize size = 0; + int cur_num_entries = -1; + + UNUSED(cls); + + if (NULL == metadata_cache) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_size: metadata cache array is NULL"); + + if ((size = ENVPTR->GetArrayLength(ENVONLY, metadata_cache)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_size: metadata_cache length < 0"); + } + + if (size < 3) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_size: length of metadata_cache array < 3"); + + if (H5Fget_mdc_size((hid_t)file_id, &max_size, &min_clean_size, &cur_size, &cur_num_entries) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + PIN_LONG_ARRAY(ENVONLY, metadata_cache, metadata_cache_ptr, &isCopy, "H5Fget_mdc_size: metadata_cache array not pinned"); + + metadata_cache_ptr[0] = (jlong)max_size; + metadata_cache_ptr[1] = (jlong)min_clean_size; + metadata_cache_ptr[2] = (jlong)cur_size; + +done: + if (metadata_cache_ptr) + UNPIN_LONG_ARRAY(ENVONLY, metadata_cache, metadata_cache_ptr, 0); return (jint)cur_num_entries; } /* end Java_hdf_hdf5lib_H5_H5Fget_1mdc_1size */ @@ -509,31 +534,36 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Fget_1info (JNIEnv *env, jclass clss, jlong obj_id) { - H5F_info2_t finfo; - jvalue args[9]; + H5F_info2_t finfo; jobject ihinfobuf; + jvalue args[9]; jobject ret_obj = NULL; - if (H5Fget_info2((hid_t)obj_id, &finfo) < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].j = (jlong)finfo.sohm.msgs_info.index_size; - args[1].j = (jlong)finfo.sohm.msgs_info.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf = ret_obj; - - args[0].i = (jint)finfo.super.version; - args[1].j = (jlong)finfo.super.super_size; - args[2].j = (jlong)finfo.super.super_ext_size; - args[3].i = (jint)finfo.free.version; - args[4].j = (jlong)finfo.free.meta_size; - args[5].j = (jlong)finfo.free.tot_space; - args[6].j = (jint)finfo.sohm.version; - args[7].j = (jlong)finfo.sohm.hdr_size; - args[8].l = ihinfobuf; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5F_info2_t", "(IJJIJJIJLhdf/hdf5lib/structs/H5_ih_info_t;)V", args); - } /* end else */ + UNUSED(clss); + + if (H5Fget_info2((hid_t)obj_id, &finfo) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].j = (jlong)finfo.sohm.msgs_info.index_size; + args[1].j = (jlong)finfo.sohm.msgs_info.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + + ihinfobuf = ret_obj; + + args[0].i = (jint)finfo.super.version; + args[1].j = (jlong)finfo.super.super_size; + args[2].j = (jlong)finfo.super.super_ext_size; + args[3].i = (jint)finfo.free.version; + args[4].j = (jlong)finfo.free.meta_size; + args[5].j = (jlong)finfo.free.tot_space; + args[6].j = (jint)finfo.sohm.version; + args[7].j = (jlong)finfo.sohm.hdr_size; + args[8].l = ihinfobuf; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5F_info2_t", "(IJJIJJIJLhdf/hdf5lib/structs/H5_ih_info_t;)V", args, ret_obj); + +done: return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Fget_1info */ @@ -546,8 +576,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Freset_1mdc_1hit_1rate_1stats (JNIEnv *env, jclass cls, jlong file_id) { + UNUSED(cls); + if (H5Freset_mdc_hit_rate_stats((hid_t)file_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Freset_1mdc_1hit_1rate_1stats */ /* @@ -559,8 +594,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fclear_1elink_1file_1cache (JNIEnv *env, jclass cls, jlong file_id) { + UNUSED(cls); + if (H5Fclear_elink_file_cache((hid_t)file_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Fclear_1elink_1file_1cache */ /* @@ -572,8 +612,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fstart_1swmr_1write (JNIEnv *env, jclass cls, jlong file_id) { + UNUSED(cls); + if (H5Fstart_swmr_write((hid_t)file_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Fstart_1swmr_1write */ /* @@ -585,8 +630,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fstart_1mdc_1logging (JNIEnv *env, jclass cls, jlong file_id) { + UNUSED(cls); + if (H5Fstart_mdc_logging((hid_t)file_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Fstart_1mdc_1logging */ /* @@ -598,8 +648,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fstop_1mdc_1logging (JNIEnv *env, jclass cls, jlong file_id) { + UNUSED(cls); + if (H5Fstop_mdc_logging((hid_t)file_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Fstop_1mdc_1logging */ /* @@ -611,32 +666,38 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fget_1mdc_1logging_1status (JNIEnv *env, jclass cls, jlong file_id, jbooleanArray mdc_logging_status) { + jboolean *mdc_logging_status_ptr = NULL; + jboolean isCopy; hbool_t is_enabled; hbool_t is_currently_logging; - jboolean *mdc_logging_status_ptr; - jint size; - jboolean isCopy; + jsize size; + + UNUSED(cls); + + if (NULL == mdc_logging_status) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_logging_status: mdc_logging_status is NULL"); + + if ((size = ENVPTR->GetArrayLength(ENVONLY, mdc_logging_status)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_logging_status: mdc_logging_status length < 0"); + } + + if (size < 2) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Fget_mdc_logging_status: length of mdc_logging_status < 2"); - if (mdc_logging_status == NULL) { - h5nullArgument(env, "H5Fget_mdc_logging_status: mdc_logging_status is NULL"); - } /* end if */ - else { - size = (int)ENVPTR->GetArrayLength(ENVPAR mdc_logging_status); - if (size < 2) { - h5badArgument(env, "H5Fget_mdc_logging_status: length of mdc_logging_status < 2."); - } /* end if */ - else { - if (H5Fget_mdc_logging_status((hid_t)file_id, &is_enabled, &is_currently_logging) < 0) { - h5libraryError(env); - } /* end if */ - else { - mdc_logging_status_ptr = ENVPTR->GetBooleanArrayElements(ENVPAR mdc_logging_status, &isCopy); - mdc_logging_status_ptr[0] = (jboolean)is_enabled; - mdc_logging_status_ptr[1] = (jboolean)is_currently_logging; - ENVPTR->ReleaseBooleanArrayElements(ENVPAR mdc_logging_status, mdc_logging_status_ptr, 0); - } /* end else */ - } /* end else */ - } /* end else */ + if (H5Fget_mdc_logging_status((hid_t)file_id, &is_enabled, &is_currently_logging) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + PIN_BOOL_ARRAY(ENVONLY, mdc_logging_status, mdc_logging_status_ptr, &isCopy, "H5Fget_mdc_logging_status: mdc_logging_status array not pinned"); + + mdc_logging_status_ptr[0] = (jboolean)is_enabled; + mdc_logging_status_ptr[1] = (jboolean)is_currently_logging; + +done: + if (mdc_logging_status_ptr) + UNPIN_BOOL_ARRAY(ENVONLY, mdc_logging_status, mdc_logging_status_ptr, 0); + + return; } /* end Java_hdf_hdf5lib_H5_H5Fget_1mdc_1logging_1status */ /* @@ -648,17 +709,18 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fset_1dset_1no_1attrs_1hint (JNIEnv *env, jclass clss, jlong file_id, jboolean minimize) { - herr_t retVal = -1; - hbool_t minimize_val; + hbool_t minimize_val; + herr_t retVal = FAIL; + + UNUSED(clss); + + minimize_val = (minimize == JNI_TRUE) ? TRUE : FALSE; - if (minimize == JNI_TRUE) - minimize_val = TRUE; - else - minimize_val = FALSE; + if ((retVal = H5Fset_dset_no_attrs_hint((hid_t)file_id, (hbool_t)minimize_val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Fset_dset_no_attrs_hint((hid_t)file_id, (hbool_t)minimize_val); - if (retVal < 0) - h5libraryError(env); +done: + return; } /* @@ -670,17 +732,18 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Fget_1dset_1no_1attrs_1hint (JNIEnv *env, jclass clss, jlong file_id) { - hbool_t minimize = FALSE; - jboolean bval = JNI_FALSE; + jboolean bval = JNI_FALSE; + hbool_t minimize = FALSE; - if (H5Fget_dset_no_attrs_hint((hid_t)file_id, (hbool_t *)&minimize) < 0) { - h5libraryError(env); - } - else { - if (minimize == TRUE) - bval = JNI_TRUE; - } /* end else */ + UNUSED(clss); + + if (H5Fget_dset_no_attrs_hint((hid_t)file_id, (hbool_t *)&minimize) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (minimize == TRUE) + bval = JNI_TRUE; +done: return bval; } @@ -693,11 +756,15 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Fset_1libver_1bounds (JNIEnv *env, jclass clss, jlong file_id, jint low, jint high) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Fset_libver_bounds((hid_t)file_id, (H5F_libver_t)low, (H5F_libver_t)high)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Fset_libver_bounds((hid_t)file_id, (H5F_libver_t)low, (H5F_libver_t)high); - if(retVal < 0) - h5libraryError(env); +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Fset_1libver_1bounds */ diff --git a/java/src/jni/h5fImp.h b/java/src/jni/h5fImp.h index fe253f9..410a249 100644 --- a/java/src/jni/h5fImp.h +++ b/java/src/jni/h5fImp.h @@ -72,7 +72,7 @@ Java_hdf_hdf5lib_H5_H5Fis_1hdf5 * Signature: (Ljava/lang/String;J)Z */ JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Fis_1ccessible +Java_hdf_hdf5lib_H5_H5Fis_1accessible (JNIEnv*, jclass, jstring, jlong); /* diff --git a/java/src/jni/h5gImp.c b/java/src/jni/h5gImp.c index 42c042a..8adabca 100644 --- a/java/src/jni/h5gImp.c +++ b/java/src/jni/h5gImp.c @@ -29,7 +29,10 @@ extern "C" { #include "h5util.h" #include "h5gImp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -40,12 +43,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Gclose (JNIEnv *env, jclass clss, jlong group_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Gclose((hid_t)group_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Gclose((hid_t)group_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Gclose */ @@ -63,33 +68,46 @@ jobject create_H5G_info_t (JNIEnv *env, H5G_info_t group_info) { - jclass cls; + jfieldID fid_storage_type, fid_nlinks, fid_max_corder, fid_mounted; jboolean jmounted; + jclass cls; jint storage_type; jobject obj = NULL; - jfieldID fid_storage_type, fid_nlinks, fid_max_corder, fid_mounted; - cls = ENVPTR->FindClass(ENVPAR "hdf/hdf5lib/structs/H5G_info_t"); - if (cls != NULL) { - obj = ENVPTR->AllocObject(ENVPAR cls); - if (obj != NULL) { - if ((fid_storage_type = ENVPTR->GetFieldID(ENVPAR cls, "storage_type", "I")) != NULL) { - if ((fid_nlinks = ENVPTR->GetFieldID(ENVPAR cls, "nlinks", "J")) != NULL) { - if ((fid_max_corder = ENVPTR->GetFieldID(ENVPAR cls, "max_corder", "J")) != NULL) { - if ((fid_mounted = ENVPTR->GetFieldID(ENVPAR cls, "mounted", "Z")) != NULL) { - jmounted = (group_info.mounted==0) ? JNI_FALSE : JNI_TRUE; - storage_type = (jint)group_info.storage_type; - - ENVPTR->SetIntField(ENVPAR obj, fid_storage_type, (jint)storage_type); - ENVPTR->SetLongField(ENVPAR obj, fid_nlinks, (jlong)group_info.nlinks); - ENVPTR->SetLongField(ENVPAR obj, fid_max_corder, (jlong)group_info.max_corder); - ENVPTR->SetBooleanField(ENVPAR obj, fid_mounted, jmounted); - } - } - } - } - } - } + if (NULL == (cls = ENVPTR->FindClass(ENVONLY, "hdf/hdf5lib/structs/H5G_info_t"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (obj = ENVPTR->AllocObject(ENVONLY, cls))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid_storage_type = ENVPTR->GetFieldID(ENVONLY, cls, "storage_type", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid_nlinks = ENVPTR->GetFieldID(ENVONLY, cls, "nlinks", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid_max_corder = ENVPTR->GetFieldID(ENVONLY, cls, "max_corder", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid_mounted = ENVPTR->GetFieldID(ENVONLY, cls, "mounted", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + jmounted = (group_info.mounted == 0) ? JNI_FALSE : JNI_TRUE; + storage_type = (jint)group_info.storage_type; + + ENVPTR->SetIntField(ENVONLY, obj, fid_storage_type, (jint)storage_type); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetLongField(ENVONLY, obj, fid_nlinks, (jlong)group_info.nlinks); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetLongField(ENVONLY, obj, fid_max_corder, (jlong)group_info.max_corder); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetBooleanField(ENVONLY, obj, fid_mounted, jmounted); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: return obj; } /* end create_H5G_info_t */ @@ -103,17 +121,19 @@ Java_hdf_hdf5lib_H5__1H5Gcreate2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong link_plist_id, jlong create_plist_id, jlong access_plist_id) { - hid_t group_id = -1; - const char *gName; + const char *grpName = NULL; + hid_t group_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, gName); - if (gName != NULL) { - group_id = H5Gcreate2((hid_t)loc_id, gName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, gName); - if (group_id < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gcreate2: group name not pinned"); + + if ((group_id = H5Gcreate2((hid_t)loc_id, grpName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); return (jlong)group_id; } /* end Java_hdf_hdf5lib_H5__1H5Gcreate2 */ @@ -127,12 +147,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Gcreate_1anon (JNIEnv *env, jclass cls, jlong loc_id, jlong gcpl_id, jlong gapl_id) { - hid_t group_id = -1; + hid_t group_id = H5I_INVALID_HID; - group_id = H5Gcreate_anon((hid_t)loc_id, (hid_t)gcpl_id, (hid_t)gapl_id); - if (group_id < 0) - h5libraryError(env); + UNUSED(cls); + if ((group_id = H5Gcreate_anon((hid_t)loc_id, (hid_t)gcpl_id, (hid_t)gapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)group_id; } /* end Java_hdf_hdf5lib_H5__1H5Gcreate_1anon */ @@ -145,18 +167,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Gopen2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id) { - hid_t group_id = -1; - const char *gName; + const char *grpName = NULL; + hid_t group_id = H5I_INVALID_HID; - PIN_JAVA_STRING(name, gName); - if (gName != NULL) { - group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, gName); + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gopen2: group name not pinned"); - if (group_id < 0) - h5libraryError(env); - } + if ((group_id = H5Gopen2((hid_t)loc_id, grpName, (hid_t)access_plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); return (jlong)group_id; } /* end Java_hdf_hdf5lib_H5__1H5Gopen2 */ @@ -171,11 +194,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Gget_1create_1plist (JNIEnv *env, jclass cls, jlong loc_id) { - hid_t plist_id = H5Gget_create_plist((hid_t)loc_id); + hid_t plist_id = H5I_INVALID_HID; - if (plist_id < 0) - h5libraryError(env); + UNUSED(cls); + if ((plist_id = H5Gget_create_plist((hid_t)loc_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)plist_id; } /* end Java_hdf_hdf5lib_H5_H5Gget_1create_1plist */ @@ -188,14 +214,18 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Gget_1info (JNIEnv *env, jclass cls, jlong loc_id) { - jobject obj = NULL; H5G_info_t group_info; + jobject obj = NULL; + + UNUSED(cls); if (H5Gget_info((hid_t)loc_id, &group_info) < 0) - h5libraryError(env); - else - obj = create_H5G_info_t(env, group_info); + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (obj = create_H5G_info_t(env, group_info))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info: unable to create H5G_info_t object"); +done: return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info */ @@ -208,23 +238,27 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jlong lapl_id) { - jobject obj = NULL; - herr_t ret_val = -1; - const char *gName; H5G_info_t group_info; + const char *grpName = NULL; + jobject obj = NULL; + herr_t ret_val = FAIL; + + UNUSED(cls); - PIN_JAVA_STRING(name, gName); - if (gName != NULL) { - ret_val = H5Gget_info_by_name((hid_t)loc_id, gName, &group_info, (hid_t)lapl_id); + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gget_info_by_name: group name not pinned"); - UNPIN_JAVA_STRING(name, gName); + if ((ret_val = H5Gget_info_by_name((hid_t)loc_id, grpName, &group_info, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (ret_val < 0) - h5libraryError(env); - else - obj = create_H5G_info_t(env, group_info); + if (NULL == (obj = create_H5G_info_t(env, group_info))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info_by_name: unable to create H5G_info_t object"); } +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); + return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name */ @@ -238,26 +272,30 @@ Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jint index_type, jint order, jlong n, jlong lapl_id) { - jobject obj = NULL; - herr_t ret_val = -1; - const char *gName; - H5G_info_t group_info; - H5_index_t cindex_type = (H5_index_t)index_type; - H5_iter_order_t corder = (H5_iter_order_t)order; - - PIN_JAVA_STRING(name, gName); - if (gName != NULL) { - ret_val = H5Gget_info_by_idx((hid_t)loc_id, gName, cindex_type, - corder, (hsize_t)n, &group_info, (hid_t)lapl_id); - - UNPIN_JAVA_STRING(name, gName); - - if (ret_val < 0) - h5libraryError(env); - else - obj = create_H5G_info_t(env, group_info); + H5_iter_order_t corder = (H5_iter_order_t)order; + H5_index_t cindex_type = (H5_index_t)index_type; + H5G_info_t group_info; + const char *grpName = NULL; + jobject obj = NULL; + herr_t ret_val = FAIL; + + UNUSED(cls); + + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gget_info_by_idx: group name not pinned"); + + if ((ret_val = H5Gget_info_by_idx((hid_t)loc_id, grpName, cindex_type, + corder, (hsize_t)n, &group_info, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (obj = create_H5G_info_t(env, group_info))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info_by_idx: unable to create H5G_info_t object"); } +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); + return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx */ @@ -270,8 +308,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Gflush (JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Gflush((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Gflush */ /* @@ -283,8 +326,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Grefresh (JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Grefresh((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Grefresh */ diff --git a/java/src/jni/h5iImp.c b/java/src/jni/h5iImp.c index b8bd1cd..a367802 100644 --- a/java/src/jni/h5iImp.c +++ b/java/src/jni/h5iImp.c @@ -27,7 +27,10 @@ extern "C" { #include "h5jni.h" #include "h5iImp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -40,10 +43,12 @@ Java_hdf_hdf5lib_H5_H5Iget_1type { H5I_type_t retVal = H5I_BADID; - retVal = H5Iget_type((hid_t)obj_id); - if (retVal == H5I_BADID) - h5libraryError(env); + UNUSED(clss); + + if (H5I_BADID == (retVal = H5Iget_type((hid_t)obj_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Iget_1type */ @@ -56,32 +61,32 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Iget_1name_1long (JNIEnv *env, jclass clss, jlong obj_id, jobjectArray name, jlong buf_size) { - char *aName; - jstring str; - hssize_t size = -1; - long bs; - - bs = (long)buf_size; - if (bs <= 0) { - h5badArgument(env, "H5Iget_name: buf_size <= 0"); - } /* end if */ - else { - aName = (char*)HDmalloc(sizeof(char) * (size_t)bs); - if (aName == NULL) { - h5outOfMemory(env, "H5Iget_name: malloc failed"); - } /* end if */ - else { - size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size); - if (size < 0) { - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, str); - } - HDfree(aName); - } - } + ssize_t size = -1; + jstring str; + char *aName = NULL; + + UNUSED(clss); + + if (buf_size < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Iget_name_long: buf_size < 0"); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Iget_name_long: malloc failed"); + + if ((size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + aName[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (aName) + HDfree(aName); + return (jlong)size; } /* end Java_hdf_hdf5lib_H5_H5Iget_1name */ @@ -95,33 +100,30 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Iget_1name (JNIEnv *env, jclass clss, jlong obj_id) { - char *aName; jstring str = NULL; - ssize_t buf_size; - - /* get the length of the name */ - buf_size = H5Iget_name((hid_t)obj_id, NULL, 0); - - if (buf_size <= 0) { - h5badArgument(env, "H5Iget_name: buf_size <= 0"); - } /* end if */ - else { - buf_size++; /* add extra space for the null terminator */ - aName = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (aName == NULL) { - h5outOfMemory(env, "H5Iget_name: malloc failed"); - } /* end if */ - else { - buf_size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size); - if (buf_size < 0) { - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - } - HDfree(aName); - } - } + ssize_t buf_size = -1; + char *aName = NULL; + + UNUSED(clss); + + /* Get the length of the name */ + if ((buf_size = H5Iget_name((hid_t)obj_id, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Iget_name: malloc failed"); + + if (H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + aName[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (aName) + HDfree(aName); + return str; } /* end Java_hdf_hdf5lib_H5_H5Iget_1name */ @@ -134,12 +136,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Iget_1ref (JNIEnv *env, jclass clss, jlong obj_id) { - int retVal = -1; + int retVal = FAIL; + + UNUSED(clss); - retVal = H5Iget_ref((hid_t)obj_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Iget_ref((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Iget_1ref */ @@ -152,12 +156,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Iinc_1ref (JNIEnv *env, jclass clss, jlong obj_id) { - int retVal = -1; + int retVal = FAIL; + + UNUSED(clss); - retVal = H5Iinc_ref((hid_t)obj_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Iinc_ref((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Iinc_1ref */ @@ -170,12 +176,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Idec_1ref (JNIEnv *env, jclass clss, jlong obj_id) { - int retVal = -1; + int retVal = FAIL; - retVal = H5Idec_ref((hid_t)obj_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Idec_ref((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Idec_1ref */ @@ -189,12 +197,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Iget_1file_1id (JNIEnv *env, jclass clss, jlong obj_id) { - hid_t file_id = -1; + hid_t file_id = H5I_INVALID_HID; + + UNUSED(clss); - file_id = H5Iget_file_id((hid_t)obj_id); - if (file_id < 0) - h5libraryError(env); + if ((file_id = H5Iget_file_id((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong) file_id; } /* end Java_hdf_hdf5lib_H5_H5Iget_1file_1id */ @@ -207,12 +217,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Iget_1type_1ref (JNIEnv *env, jclass clss, jint type) { - int retVal = -1; + int retVal = FAIL; - retVal = H5Iget_type_ref((H5I_type_t)type); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Iget_type_ref((H5I_type_t)type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Iget_1type_1ref */ @@ -225,12 +237,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Idec_1type_1ref (JNIEnv *env, jclass clss, jint type) { - int retVal = -1; + int retVal = FAIL; + + UNUSED(clss); - retVal = H5Idec_type_ref((H5I_type_t)type); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Idec_type_ref((H5I_type_t)type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Idec_1type_1ref */ @@ -243,12 +257,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Iinc_1type_1ref (JNIEnv *env, jclass clss, jint type) { - int retVal = -1; + int retVal = FAIL; - retVal = H5Iinc_type_ref((H5I_type_t)type); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Iinc_type_ref((H5I_type_t)type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Iinc_1type_1ref */ @@ -261,11 +277,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Inmembers (JNIEnv *env, jclass clss, jint type) { - hsize_t num_members; + hsize_t num_members = 0; + + UNUSED(clss); if (H5Inmembers((H5I_type_t)type, &num_members) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)num_members; } /* end Java_hdf_hdf5lib_H5_H5Inmembers */ @@ -280,12 +299,14 @@ Java_hdf_hdf5lib_H5_H5Iis_1valid { htri_t bval = JNI_FALSE; - bval = H5Iis_valid((hid_t)obj_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + if ((bval = H5Iis_valid((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Iis_1valid */ /* @@ -299,12 +320,14 @@ Java_hdf_hdf5lib_H5_H5Itype_1exists { htri_t bval = JNI_FALSE; - bval = H5Itype_exists((H5I_type_t)type); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Itype_exists((H5I_type_t)type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; +done: return (jboolean)bval; } /* end else Java_hdf_hdf5lib_H5_H5Itype_1exists */ @@ -317,8 +340,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Iclear_1type (JNIEnv *env, jclass clss, jint type, jboolean force) { - if (H5Iclear_type((H5I_type_t)type, (hbool_t)force) < 0) - h5libraryError(env); + UNUSED(clss); + + if (H5Iclear_type((H5I_type_t)type, (hbool_t)force) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Iclear_1type */ /* @@ -330,8 +358,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Idestroy_1type (JNIEnv *env, jclass clss, jint type) { - if (H5Idestroy_type((H5I_type_t)type) < 0) - h5libraryError(env); + UNUSED(clss); + + if (H5Idestroy_type((H5I_type_t)type) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Idestroy_1type */ #ifdef __cplusplus diff --git a/java/src/jni/h5jni.h b/java/src/jni/h5jni.h index 2970e14..4a94180 100644 --- a/java/src/jni/h5jni.h +++ b/java/src/jni/h5jni.h @@ -27,147 +27,299 @@ #ifdef __cplusplus #define ENVPTR (env) - #define ENVPAR #define ENVONLY #define CBENVPTR (cbenv) - #define CBENVPAR + #define CBENVONLY #define JVMPTR (jvm) #define JVMPAR - #define JVMPAR2 #else /* __cplusplus */ #define ENVPTR (*env) - #define ENVPAR env, #define ENVONLY env #define CBENVPTR (*cbenv) - #define CBENVPAR cbenv, + #define CBENVONLY cbenv #define JVMPTR (*jvm) #define JVMPAR jvm - #define JVMPAR2 jvm, #endif /* __cplusplus */ +/* + * Used to silence compiler when a particular + * function parameter is not used. + */ +#define UNUSED(o) (void) o + /* Macros for class access */ /* Calling code must define ret_obj as jobject */ -#define CALL_CONSTRUCTOR(classname,classsig,args) { \ - jclass cls; \ - jmethodID constructor; \ - cls = ENVPTR->FindClass(ENVPAR (classname)); \ - if (cls == 0) { \ - h5JNIFatalError(env, "JNI error: GetObjectClass\n"); \ - ret_obj = NULL; \ - } \ - constructor = ENVPTR->GetMethodID(ENVPAR cls, "", (classsig)); \ - if (constructor == 0) { \ - h5JNIFatalError(env, "JNI error: GetMethodID failed\n"); \ - ret_obj = NULL; \ - } \ - ret_obj = ENVPTR->NewObjectA(ENVPAR cls, constructor, (args)); \ +#define CALL_CONSTRUCTOR(env, classname, classsig, args, ret_obj) \ +{ \ + jmethodID constructor; \ + jclass cls; \ + \ + if (NULL == (cls = ENVPTR->FindClass(env, (classname)))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, "JNI error: GetObjectClass"); \ + } \ + if (NULL == (constructor = ENVPTR->GetMethodID(ENVONLY, cls, "", (classsig)))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, "JNI error: GetMethodID failed"); \ + } \ + if (NULL == (ret_obj = ENVPTR->NewObjectA(ENVONLY, cls, constructor, (args)))) { \ + CHECK_JNI_EXCEPTION(env, JNI_FALSE); \ + } \ +} + +/* + * Macros for pinning/unpinning objects. + */ +#define PIN_BYTE_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetByteArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_BYTE_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jbyte *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_BYTE_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseByteArrayElements(env, pinnedArray, (jbyte *) bufToRelease, freeMode); \ +} + +#define PIN_SHORT_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetShortArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_SHORT_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jshort *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_SHORT_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseShortArrayElements(env, pinnedArray, (jshort *) bufToRelease, freeMode); \ +} + +#define PIN_INT_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetIntArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_INT_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jint *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_INT_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseIntArrayElements(env, pinnedArray, (jint *) bufToRelease, freeMode); \ +} + +#define PIN_LONG_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetLongArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_LONG_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jlong *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_LONG_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseLongArrayElements(env, pinnedArray, (jlong *) bufToRelease, freeMode); \ +} + +#define PIN_FLOAT_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetFloatArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_FLOAT_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jfloat *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_FLOAT_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseFloatArrayElements(env, pinnedArray, (jfloat *) bufToRelease, freeMode); \ +} + +#define PIN_DOUBLE_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetDoubleArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_DOUBLE_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jdouble *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_DOUBLE_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseDoubleArrayElements(env, pinnedArray, (jdouble *) bufToRelease, freeMode); \ +} + +#define PIN_BOOL_ARRAY(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = ENVPTR->GetBooleanArrayElements(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define PIN_BOOL_ARRAY_CRITICAL(env, arrayToPin, outBuf, isCopy, failErrMsg) \ +{ \ + if (NULL == (outBuf = (jboolean *) ENVPTR->GetPrimitiveArrayCritical(env, arrayToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ } +#define UNPIN_BOOL_ARRAY(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleaseBooleanArrayElements(env, pinnedArray, (jboolean *) bufToRelease, freeMode); \ +} + +#define UNPIN_ARRAY_CRITICAL(env, pinnedArray, bufToRelease, freeMode) \ +{ \ + ENVPTR->ReleasePrimitiveArrayCritical(env, pinnedArray, bufToRelease, freeMode); \ +} /* Macros for string access */ -#define PIN_JAVA_STRING(javastr,localstr) { \ - jboolean isCopy; \ - (localstr) = NULL; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - } \ - else { \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - } \ - } \ -} - -#define UNPIN_JAVA_STRING(javastr,localstr) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ -} - -#define PIN_JAVA_STRING_TWO(javastr,localstr,java2str,local2str) { \ - jboolean isCopy; \ - (localstr) = NULL; \ - (local2str) = NULL; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - } \ - else if ((java2str) == NULL) { \ - h5nullArgument(env, "second java string is NULL"); \ - } \ - else { \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - } \ - else { \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - } \ - } \ - } \ -} - -#define UNPIN_JAVA_STRING_TWO(javastr,localstr,java2str,local2str) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ -} - -#define PIN_JAVA_STRING_THREE(javastr,localstr,java2str,local2str,java3str,local3str) { \ - jboolean isCopy; \ - (localstr) = NULL; \ - (local2str) = NULL; \ - (local3str) = NULL; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - } \ - else if ((java2str) == NULL) { \ - h5nullArgument(env, "second java string is NULL"); \ - } \ - else if ((java3str) == NULL) { \ - h5nullArgument(env, "third java string is NULL"); \ - } \ - else { \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - } \ - else { \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - } \ - else { \ - (local3str) = ENVPTR->GetStringUTFChars(ENVPAR (java3str), &isCopy); \ - if ((local3str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ - h5JNIFatalError(env, "third local c string is not pinned"); \ - } \ - } \ - } \ - } \ -} - -#define UNPIN_JAVA_STRING_THREE(javastr,localstr,java2str,local2str,java3str,local3str) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java3str), (local3str)); \ +#define PIN_JAVA_STRING(env, stringToPin, outString, isCopy, failErrMsg) \ +{ \ + if (NULL == (outString = ENVPTR->GetStringUTFChars(env, stringToPin, isCopy))) { \ + CHECK_JNI_EXCEPTION(env, JNI_TRUE); \ + H5_JNI_FATAL_ERROR(env, failErrMsg); \ + } \ +} + +#define UNPIN_JAVA_STRING(env, pinnedString, stringToRelease) \ +{ \ + ENVPTR->ReleaseStringUTFChars(env, pinnedString, stringToRelease); \ +} + +/* + * Macro to check for a JNI exception after a JNI method is called. + * If an exception occurred, the value of 'clearException' will determine + * whether or not the exception will be cleared in order for the native + * method to do its own error handling. + * + * If the exception does not get cleared, this macro will skip to the + * cleanup+return section of the native method, since at that point + * cleaning up and returning is the only safe thing that can be done. + */ +#define CHECK_JNI_EXCEPTION(env, clearException) \ +{ \ + if (JNI_TRUE == (*env)->ExceptionCheck(env)) { \ + if (JNI_TRUE == clearException) \ + (*env)->ExceptionClear(env); \ + else \ + goto done; \ + } \ } #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -extern jboolean h5JNIFatalError(JNIEnv *, const char *); -extern jboolean h5nullArgument(JNIEnv *, const char *); -extern jboolean h5badArgument (JNIEnv *, const char *); -extern jboolean h5outOfMemory (JNIEnv *, const char *); -extern jboolean h5libraryError(JNIEnv *env ); -extern jboolean h5raiseException(JNIEnv *, const char *, const char *); +extern jboolean h5JNIFatalError(JNIEnv *env, const char *); +extern jboolean h5nullArgument(JNIEnv *env, const char *); +extern jboolean h5badArgument(JNIEnv *env, const char *); +extern jboolean h5outOfMemory(JNIEnv *env, const char *); +extern jboolean h5libraryError(JNIEnv *env); +extern jboolean h5raiseException(JNIEnv *env, const char *, const char *); extern jboolean h5unimplemented( JNIEnv *env, const char *functName); +/* + * The following macros are to facilitate immediate cleanup+return + * from a native JNI method when an exception is to be thrown. + * Since, in general, the "cleanup" methods are the only safe JNI + * methods to call once an exception has occurred, we want to immediately + * cleanup and return instead of letting the native method continue. + * + * Note that a native method can clear the exception when one occurs and + * then do its own error handling, but we instead opt to immediately return. + */ +#define H5_JNI_FATAL_ERROR(env, message) \ +{ \ + h5JNIFatalError(env, message); \ + goto done; \ +} + +#define H5_NULL_ARGUMENT_ERROR(env, message) \ +{ \ + h5nullArgument(env, message); \ + goto done; \ +} + +#define H5_BAD_ARGUMENT_ERROR(env, message) \ +{ \ + h5badArgument(env, message); \ + goto done; \ +} + +#define H5_OUT_OF_MEMORY_ERROR(env, message) \ +{ \ + h5outOfMemory(env, message); \ + goto done; \ +} + +#define H5_LIBRARY_ERROR(env) \ +{ \ + h5libraryError(env); \ + goto done; \ +} + +#define H5_RAISE_EXCEPTION(env, message, exception) \ +{ \ + h5raiseException(env, message, exception); \ + goto done; \ +} + +#define H5_UNIMPLEMENTED(env, message) \ +{ \ + h5unimplemented(env, message); \ + goto done; \ +} + /* implemented at H5.c */ extern jint get_enum_value(JNIEnv *env, jobject enum_obj); extern jobject get_enum_object(JNIEnv *env, const char* enum_class_name, diff --git a/java/src/jni/h5lImp.c b/java/src/jni/h5lImp.c index e1ec3bd..5999270 100644 --- a/java/src/jni/h5lImp.c +++ b/java/src/jni/h5lImp.c @@ -27,6 +27,9 @@ extern "C" { #include "h5jni.h" #include "h5lImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; typedef struct _cb_wrapper { @@ -50,19 +53,23 @@ Java_hdf_hdf5lib_H5_H5Lcopy (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lCurName; - const char *lDstName; + const char *lCurName = NULL; + const char *lDstName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (lCurName != NULL && lDstName != NULL) { - status = H5Lcopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Lcopy: src name not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Lcopy: dest name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Lcopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (lDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName); + if (lCurName) + UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName); } /* end Java_hdf_hdf5lib_H5_H5Lcopy */ /* @@ -75,20 +82,27 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1external (JNIEnv *env, jclass clss, jstring file_name, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lFileName; - const char *lCurName; - const char *lDstName; - - PIN_JAVA_STRING_THREE(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); - if (lFileName != NULL && lCurName != NULL && lDstName != NULL) { - status = H5Lcreate_external(lFileName, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - - UNPIN_JAVA_STRING_THREE(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); - - if (status < 0) - h5libraryError(env); - } + const char *lFileName = NULL; + const char *lCurName = NULL; + const char *lDstName = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, file_name, lFileName, NULL, "H5Lcreate_external: file name not pinned"); + PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Lcreate_external: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Lcreate_external: link name not pinned"); + + if ((status = H5Lcreate_external(lFileName, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (lDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName); + if (lCurName) + UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName); + if (lFileName) + UNPIN_JAVA_STRING(ENVONLY, file_name, lFileName); } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1external */ /* @@ -101,19 +115,23 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1hard (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lCurName; - const char *lDstName; + const char *lCurName = NULL; + const char *lDstName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (lCurName != NULL && lDstName != NULL) { - status = H5Lcreate_hard((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Lcreate_hard: object name not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Lcreate_hard: link name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Lcreate_hard((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (lDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName); + if (lCurName) + UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName); } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1hard */ /* @@ -126,19 +144,23 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1soft (JNIEnv *env, jclass clss, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lCurName; - const char *lDstName; + const char *linkTarget = NULL; + const char *linkName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (lCurName != NULL && lDstName != NULL) { - status = H5Lcreate_soft(lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, cur_name, linkTarget, NULL, "H5Lcreate_soft: link target not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, linkName, NULL, "H5Lcreate_soft: link name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Lcreate_soft(linkTarget, (hid_t)dst_loc_id, linkName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (linkName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, linkName); + if (linkTarget) + UNPIN_JAVA_STRING(ENVONLY, cur_name, linkTarget); } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1soft */ /* @@ -150,18 +172,19 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Ldelete (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id) { - herr_t status = -1; - const char *lName; + const char *linkName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Ldelete((hid_t)loc_id, lName, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, lName); + PIN_JAVA_STRING(ENVONLY, name, linkName, NULL, "H5Ldelete: link name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Ldelete((hid_t)loc_id, linkName, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (linkName) + UNPIN_JAVA_STRING(ENVONLY, name, linkName); } /* end Java_hdf_hdf5lib_H5_H5Ldelete */ /* @@ -174,19 +197,20 @@ Java_hdf_hdf5lib_H5_H5Ldelete_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jlong access_id) { + const char *groupName = NULL; hsize_t n = (hsize_t)link_n; - herr_t status; - const char *lName; + herr_t status = FAIL; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Ldelete_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, n, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, lName); + PIN_JAVA_STRING(ENVONLY, name, groupName, NULL, "H5Ldelete_by_idx: group name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Ldelete_by_idx((hid_t)loc_id, groupName, (H5_index_t)index_field, (H5_iter_order_t)order, n, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (groupName) + UNPIN_JAVA_STRING(ENVONLY, name, groupName); } /* end Java_hdf_hdf5lib_H5_H5Ldelete_1by_1idx */ /* @@ -198,20 +222,21 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Lexists (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id) { - htri_t bval = JNI_FALSE; - const char *lName; + const char *linkName = NULL; + htri_t bval = JNI_FALSE; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - bval = H5Lexists((hid_t)loc_id, lName, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, lName); + PIN_JAVA_STRING(ENVONLY, name, linkName, NULL, "H5Lexists: link name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5Lexists((hid_t)loc_id, linkName, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (linkName) + UNPIN_JAVA_STRING(ENVONLY, name, linkName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Lexists */ @@ -225,33 +250,31 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Lget_1info (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id) { - jobject ret_obj = NULL; - jvalue args[5]; - herr_t status; H5L_info_t infobuf; - const char *lName; - - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Lget_info((hid_t)loc_id, lName, &infobuf, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = infobuf.type; - args[1].z = infobuf.corder_valid; - args[2].j = infobuf.corder; - args[3].i = infobuf.cset; - if(infobuf.type==0) - args[4].j = (jlong)infobuf.u.address; - else - args[4].j = (jlong)infobuf.u.val_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); - } /* end else */ - } /* end if */ + const char *linkName = NULL; + jvalue args[5]; + herr_t status = FAIL; + jobject ret_obj = NULL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, linkName, NULL, "H5Lget_info: link name not pinned"); + + if ((status = H5Lget_info((hid_t)loc_id, linkName, &infobuf, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = infobuf.type; + args[1].z = infobuf.corder_valid; + args[2].j = infobuf.corder; + args[3].i = infobuf.cset; + args[4].j = (infobuf.type == H5L_TYPE_HARD) ? (jlong) infobuf.u.address : (jlong) infobuf.u.val_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args, ret_obj); + +done: + if (linkName) + UNPIN_JAVA_STRING(ENVONLY, name, linkName); + return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Lget_1info */ @@ -265,33 +288,31 @@ Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jlong access_id) { - jobject ret_obj = NULL; - jvalue args[5]; - herr_t status; H5L_info_t infobuf; - const char *lName; - - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = infobuf.type; - args[1].z = infobuf.corder_valid; - args[2].j = infobuf.corder; - args[3].i = infobuf.cset; - if(infobuf.type==0) - args[4].j = (jlong)infobuf.u.address; - else - args[4].j = (jlong)infobuf.u.val_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); - } /* end els */ - } + const char *groupName = NULL; + jvalue args[5]; + herr_t status = FAIL; + jobject ret_obj = NULL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, groupName, NULL, "H5Lget_info_by_idx: group name not pinned"); + + if ((status = H5Lget_info_by_idx((hid_t)loc_id, groupName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = infobuf.type; + args[1].z = infobuf.corder_valid; + args[2].j = infobuf.corder; + args[3].i = infobuf.cset; + args[4].j = (infobuf.type == H5L_TYPE_HARD) ? (jlong) infobuf.u.address : (jlong) infobuf.u.val_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args, ret_obj); + +done: + if (groupName) + UNPIN_JAVA_STRING(ENVONLY, name, groupName); + return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx */ @@ -305,43 +326,35 @@ Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jlong access_id) { - jlong status_size; + const char *groupName = NULL; jstring str = NULL; - size_t buf_size; - const char *lName; - char *lValue; - - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - /* get the length of the link name */ - status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)NULL, (size_t)0, H5P_DEFAULT); - if(status_size < 0) { - h5libraryError(env); - } /* end if */ - else { - buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - - lValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (lValue == NULL) { - h5outOfMemory(env, "H5Lget_name_by_idx: malloc failed "); - } /* end if */ - else { - status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)lValue, (size_t)buf_size, (hid_t)access_id); - - if (status_size < 0) { - HDfree(lValue); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR lValue); - HDfree(lValue); - if (str == NULL) - h5JNIFatalError(env, "H5Lget_name_by_idx: return string not created"); - } /* end else */ - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, lName); - } + ssize_t status_size = -1; + char *linkName = NULL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, groupName, NULL, "H5Lget_name_by_idx: group name not pinned"); + + /* Get the length of the link name */ + if ((status_size = H5Lget_name_by_idx((hid_t)loc_id, groupName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char *)NULL, (size_t)0, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* add extra space for the null terminator */ + if (NULL == (linkName = (char *) HDmalloc(sizeof(char) * (size_t)status_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_name_by_idx: failed to allocate buffer for link name"); + + if ((H5Lget_name_by_idx((hid_t)loc_id, groupName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char *)linkName, (size_t)status_size + 1, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + linkName[status_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, linkName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (linkName) + HDfree(linkName); + if (groupName) + UNPIN_JAVA_STRING(ENVONLY, name, groupName); return str; } /* end Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx */ @@ -355,80 +368,80 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Lget_1value (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jobjectArray link_value, jlong access_id) { - size_t buf_size; - herr_t status; H5L_info_t infobuf; - const char *lName; - char *lValue; - const char *file_name; - const char *obj_name; + const char *file_name = NULL; + const char *obj_name = NULL; + const char *linkName = NULL; jstring str; + herr_t status; + char *linkValue = NULL; + + UNUSED(clss); + + infobuf.type = H5L_TYPE_ERROR; + + PIN_JAVA_STRING(ENVONLY, name, linkName, NULL, "H5Lget_value: link name not pinned"); + + /* Get the length of the link value */ + if ((status = H5Lget_info((hid_t)loc_id, linkName, &infobuf, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5L_TYPE_HARD == infobuf.type) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val: hard links are unsupported"); + + if (NULL == (linkValue = (char *) HDmalloc(sizeof(char) * infobuf.u.val_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val: failed to allocate buffer for link value"); + + if ((status = H5Lget_val((hid_t)loc_id, linkName, (void *)linkValue, infobuf.u.val_size + 1, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + linkValue[infobuf.u.val_size] = '\0'; + + switch (infobuf.type) { + case H5L_TYPE_SOFT: + { + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, linkValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - infobuf.type = -1; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - /* get the length of the link val */ - status = H5Lget_info((hid_t)loc_id, lName, &infobuf, H5P_DEFAULT); - if(status < 0) { - h5libraryError(env); - } /* end if */ - else { - buf_size = infobuf.u.val_size + 1;/* add extra space for the null terminator */ - - if(infobuf.type == H5L_TYPE_HARD) { - h5JNIFatalError(env, "H5Lget_val: link is hard type"); - } /* end if */ - else { - lValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (lValue == NULL) { - h5outOfMemory(env, "H5Lget_val: malloc failed"); - } /* end if */ - else { - status = H5Lget_val((hid_t)loc_id, lName, (void*)lValue, buf_size, (hid_t)access_id); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else if(infobuf.type == H5L_TYPE_EXTERNAL) { - status = H5Lunpack_elink_val(lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, &file_name, &obj_name); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR obj_name); - if (str == NULL) { - h5JNIFatalError(env, "H5Lget_val: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - - str = ENVPTR->NewStringUTF(ENVPAR file_name); - if (str == NULL) { - h5JNIFatalError(env, "H5Lget_val: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR lValue); - if (str == NULL) { - /* exception -- fatal JNI error */ - h5JNIFatalError(env, "H5Lget_val: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - } /* end else */ - } /* end else */ - HDfree(lValue); - } /* end else */ - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, lName); + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + case H5L_TYPE_EXTERNAL: + { + if ((status = H5Lunpack_elink_val(linkValue, (size_t)infobuf.u.val_size, (unsigned *)NULL, &file_name, &obj_name)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, obj_name))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, file_name))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 1, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + case H5L_TYPE_ERROR: + case H5L_TYPE_MAX: + case H5L_TYPE_HARD: + default: + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val: invalid link type"); + break; } +done: + if (linkValue) + HDfree(linkValue); + if (linkName) + UNPIN_JAVA_STRING(ENVONLY, name, linkName); + return infobuf.type; } /* end Java_hdf_hdf5lib_H5_H5Lget_1val */ @@ -442,78 +455,83 @@ Java_hdf_hdf5lib_H5_H5Lget_1value_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jobjectArray link_value, jlong access_id) { - herr_t status; - size_t buf_size; H5L_info_t infobuf; - const char *lName; - void *lValue; - const char *file_name; - const char *obj_name; + const char *file_name = NULL; + const char *obj_name = NULL; + const char *grpName = NULL; jstring str; + herr_t status; + void *linkValue = NULL; + + UNUSED(clss); + + infobuf.type = H5L_TYPE_ERROR; + + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Lget_val_by_idx: group name not pinned"); + + /* Get the length of the link value */ + if ((status = H5Lget_info_by_idx((hid_t)loc_id, grpName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5L_TYPE_HARD == infobuf.type) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val_by_idx: hard links are unsupported") + + if (!infobuf.u.val_size) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (linkValue = (void *) HDmalloc(infobuf.u.val_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val_by_idx: failed to allocate buffer for link value"); + + if ((status = H5Lget_val_by_idx((hid_t)loc_id, grpName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (void *)linkValue, infobuf.u.val_size + 1, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + ((char *) linkValue)[infobuf.u.val_size] = '\0'; + + switch (infobuf.type) { + case H5L_TYPE_SOFT: + { + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, (char *)linkValue))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + case H5L_TYPE_EXTERNAL: + { + if ((status = H5Lunpack_elink_val((char *)linkValue, (size_t)infobuf.u.val_size, (unsigned *)NULL, (const char **)&file_name, (const char**)&obj_name)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, obj_name))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, file_name))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, link_value, 1, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } - infobuf.type = -1; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - /* get the length of the link valuee */ - status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - if(status < 0) { - h5libraryError(env); - } /* end if */ - else { - buf_size = infobuf.u.val_size; - if(buf_size == 0) { - h5libraryError(env); - } /* end if */ - else { - lValue = (void*)HDmalloc(buf_size); - if (lValue == NULL) { - h5outOfMemory(env, "H5Lget_val_by_idx: malloc failed "); - } /* end if */ - else { - status = H5Lget_val_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (void*)lValue, (size_t)buf_size, (hid_t)access_id); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else if(infobuf.type == H5L_TYPE_EXTERNAL) { - status = H5Lunpack_elink_val((char*)lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, (const char**)&file_name, (const char**)&obj_name); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR obj_name); - if (str == NULL) { - h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - - str = ENVPTR->NewStringUTF(ENVPAR file_name); - if (str == NULL) { - h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR (char *)lValue); - if (str == NULL) { - h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); - } /* end if */ - else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - } /* end else */ - } /* end else */ - HDfree(lValue); - } /* end else */ - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, lName); + case H5L_TYPE_ERROR: + case H5L_TYPE_MAX: + case H5L_TYPE_HARD: + default: + H5_JNI_FATAL_ERROR(ENVONLY, "H5Lget_val_by_idx: invalid link type"); + break; } +done: + if (linkValue) + HDfree(linkValue); + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); + return infobuf.type; } /* end Java_hdf_hdf5lib_H5_H5Lget_1val_1by_1idx */ @@ -527,73 +545,81 @@ Java_hdf_hdf5lib_H5_H5Lmove (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lCurName; - const char *lDstName; + const char *lCurName = NULL; + const char *lDstName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (lCurName != NULL && lDstName != NULL) { - status = H5Lmove((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Lmove: src name not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Lmove: dest name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Lmove((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: + if (lDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName); + if (lCurName) + UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName); } /* end Java_hdf_hdf5lib_H5_H5Lmove */ static herr_t H5L_iterate_cb (hid_t g_id, const char *name, const H5L_info_t *info, void *cb_data) { - JNIEnv *cbenv; - jint status; - jclass cls; - jmethodID mid; - jstring str; - jmethodID constructor; - jvalue args[5]; - jobject cb_info_t = NULL; cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5L_info_t;Lhdf/hdf5lib/callbacks/H5L_iterate_t;)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - - args[0].i = info->type; - args[1].z = info->corder_valid; - args[2].j = info->corder; - args[3].i = info->cset; - if(info->type==0) - args[4].j = (jlong)info->u.address; - else - args[4].j = (jlong)info->u.val_size; - // get a reference to your class if you don't have it already - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5L_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(IZJIJ)V"); - if (constructor != 0) { - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (cb_info_t == NULL) { - printf("FATAL ERROR: hdf/hdf5lib/structs/H5L_info_t: Creation failed\n"); - } - else { - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); - } - } /* end if */ - } /* end if */ - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return status; + jmethodID constructor, mid; + jobject cb_info_t = NULL; + jobject visit_callback = wrapper->visit_callback; + jstring str; + JNIEnv *cbenv = NULL; + jclass cls; + jvalue args[5]; + void *op_data = (void *)wrapper->op_data; + jint status; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5L_iterate_cb: failed to attach current thread to JVM"); + } + + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5L_info_t;Lhdf/hdf5lib/callbacks/H5L_iterate_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[0].i = info->type; + args[1].z = info->corder_valid; + args[2].j = info->corder; + args[3].i = info->cset; + args[4].j = (info->type == H5L_TYPE_HARD) ? (jlong)info->u.address : (jlong)info->u.val_size; + + /* Get a reference to your class if you don't have it already */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5L_info_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* Get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(IZJIJ)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("FATAL ERROR: hdf/hdf5lib/structs/H5L_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); + + return (herr_t)status; } /* end H5L_iterate_cb */ /* @@ -606,20 +632,23 @@ Java_hdf_hdf5lib_H5_H5Lvisit (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order, jobject callback_op, jobject op_data) { - herr_t status = -1; - cb_wrapper wrapper = {callback_op, op_data}; + cb_wrapper wrapper = { callback_op, op_data }; + herr_t status = FAIL; + + UNUSED(clss); - ENVPTR->GetJavaVM(ENVPAR &jvm); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Lvisit: op_data or callback_op is NULL"); - } /* end if */ - else { - status = H5Lvisit((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void*)&wrapper); - if (status < 0) - h5libraryError(env); - } /* end else */ + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Lvisit: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Lvisit: callback_op is NULL"); + if ((status = H5Lvisit((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return status; } /* end Java_hdf_hdf5lib_H5_H5Lvisit */ @@ -633,26 +662,28 @@ Java_hdf_hdf5lib_H5_H5Lvisit_1by_1name (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order, jobject callback_op, jobject op_data, jlong access_id) { - herr_t status = -1; - const char *lName; - cb_wrapper wrapper = {callback_op, op_data}; + cb_wrapper wrapper = { callback_op, op_data }; + const char *grpName = NULL; + herr_t status = FAIL; - ENVPTR->GetJavaVM(ENVPAR &jvm); + UNUSED(clss); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Lvisit_by_name: op_data or callback_op is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Lvisit_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void*)&wrapper, (hid_t)access_id); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - UNPIN_JAVA_STRING(name, lName); + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Lvisit_by_name: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Lvisit_by_name: callback_op is NULL"); - if (status < 0) - h5libraryError(env); - } - } /* end else */ + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Lvisit_by_name: group name not pinned"); + + if ((status = H5Lvisit_by_name((hid_t)grp_id, grpName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void *)&wrapper, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); return status; } /* end Java_hdf_hdf5lib_H5_H5Lvisit_1by_1name */ @@ -667,22 +698,24 @@ Java_hdf_hdf5lib_H5_H5Literate (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order, jlong idx, jobject callback_op, jobject op_data) { - hsize_t start_idx = (hsize_t)idx; - herr_t status = -1; - cb_wrapper wrapper = {callback_op, op_data}; + cb_wrapper wrapper = { callback_op, op_data }; + hsize_t start_idx = (hsize_t)idx; + herr_t status = FAIL; - ENVPTR->GetJavaVM(ENVPAR &jvm); + UNUSED(clss); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Literate: op_data or callback_op is NULL"); - } /* end if */ - else { - status = H5Literate((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void*)&wrapper); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (status < 0) - h5libraryError(env); - } /* end else */ + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Literate: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Literate: callback_op is NULL"); + if ((status = H5Literate((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t *)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return status; } /* end Java_hdf_hdf5lib_H5_H5Literate */ @@ -696,27 +729,29 @@ Java_hdf_hdf5lib_H5_H5Literate_1by_1name (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order, jlong idx, jobject callback_op, jobject op_data, jlong access_id) { - hsize_t start_idx = (hsize_t)idx; - herr_t status = -1; - const char *lName; + cb_wrapper wrapper = { callback_op, op_data }; + const char *groupName = NULL; + hsize_t start_idx = (hsize_t)idx; + herr_t status = FAIL; - ENVPTR->GetJavaVM(ENVPAR &jvm); - cb_wrapper wrapper = {callback_op, op_data}; + UNUSED(clss); - if ((op_data == NULL) || (callback_op == NULL)) { - h5nullArgument(env, "H5Literate_by_name: op_data or callback_op is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Literate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void*)&wrapper, (hid_t)access_id); + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - UNPIN_JAVA_STRING(name, lName); + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Literate_by_name: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Literate_by_name: callback_op is NULL"); - if (status < 0) - h5libraryError(env); - } - } /* end else */ + PIN_JAVA_STRING(ENVONLY, name, groupName, NULL, "H5Literate_by_name: group name not pinned"); + + if ((status = H5Literate_by_name((hid_t)grp_id, groupName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void*)&wrapper, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (groupName) + UNPIN_JAVA_STRING(ENVONLY, name, groupName); return status; } /* end Java_hdf_hdf5lib_H5_H5Literate_1by_1name */ @@ -730,11 +765,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Lis_1registered (JNIEnv *env, jclass clss, jint link_cls_id) { - htri_t ret_val = H5Lis_registered((H5L_type_t)link_cls_id); + htri_t ret_val = FAIL; - if (ret_val < 0) - h5libraryError(env); + UNUSED(clss); + if ((ret_val = H5Lis_registered((H5L_type_t)link_cls_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (int)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Lis_1registered */ @@ -747,8 +785,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Lunregister (JNIEnv *env, jclass clss, jint link_cls_id) { + UNUSED(clss); + if (H5Lunregister((H5L_type_t)link_cls_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Lunregister */ diff --git a/java/src/jni/h5oImp.c b/java/src/jni/h5oImp.c index 1de505a..0b1a984 100644 --- a/java/src/jni/h5oImp.c +++ b/java/src/jni/h5oImp.c @@ -26,6 +26,9 @@ extern "C" { #include "h5jni.h" #include "h5oImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; typedef struct _cb_wrapper { @@ -48,18 +51,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Oopen (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id) { - hid_t status = -1; - const char *oName; + const char *objName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(name, oName); - if (oName != NULL) { - status = H5Oopen((hid_t)loc_id, oName, (hid_t)access_plist_id ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, oName); + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oopen: object name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Oopen((hid_t)loc_id, objName, (hid_t)access_plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Oopen */ @@ -73,11 +77,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Oclose (JNIEnv *env, jclass clss, jlong object_id) { - herr_t retVal = H5Oclose((hid_t)object_id); + herr_t retVal = FAIL; - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Oclose((hid_t)object_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Oclose */ @@ -91,19 +98,23 @@ Java_hdf_hdf5lib_H5_H5Ocopy (JNIEnv *env, jclass clss, jlong cur_loc_id, jstring cur_name, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lCurName; - const char *lDstName; + const char *lCurName = NULL; + const char *lDstName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (lCurName != NULL && lDstName != NULL) { - status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, cur_name, lCurName, NULL, "H5Ocopy: src name not pinned"); + PIN_JAVA_STRING(ENVONLY, dst_name, lDstName, NULL, "H5Ocopy: dest name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (lDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, lDstName); + if (lCurName) + UNPIN_JAVA_STRING(ENVONLY, cur_name, lCurName); } /* end Java_hdf_hdf5lib_H5_H5Ocopy */ /* @@ -115,57 +126,61 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Oget_1info (JNIEnv *env, jclass clss, jlong loc_id, jint fields) { - herr_t status = -1; - H5O_info_t infobuf; - jvalue args[12]; - jobject hdrinfobuf; - jobject ihinfobuf1; - jobject ihinfobuf2; - jobject ret_obj = NULL; - - status = H5Oget_info2((hid_t)loc_id, &infobuf, (unsigned)fields); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); - } - + H5O_info_t infobuf; + jobject hdrinfobuf; + jobject ihinfobuf1; + jobject ihinfobuf2; + jvalue args[12]; + herr_t status = FAIL; + jobject ret_obj = NULL; + + UNUSED(clss); + + if ((status = H5Oget_info2((hid_t)loc_id, &infobuf, (unsigned)fields)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args, ret_obj); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf1 = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args, ret_obj); + +done: return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info */ @@ -178,62 +193,66 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint fields, jlong access_id) { - const char *lName; - herr_t status = -1; H5O_info_t infobuf; - jvalue args[12]; + const char *objName = NULL; jobject hdrinfobuf; jobject ihinfobuf1; jobject ihinfobuf2; + jvalue args[12]; + herr_t status = FAIL; jobject ret_obj = NULL; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Oget_info_by_name2((hid_t)loc_id, lName, &infobuf, (unsigned)fields, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); - } - } + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oget_info_by_name: object name not pinned"); + + if ((status = H5Oget_info_by_name2((hid_t)loc_id, objName, &infobuf, (unsigned)fields, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args, ret_obj); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf1 = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args, ret_obj); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name */ @@ -248,62 +267,66 @@ Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jint fields, jlong access_id) { - const char *lName; - herr_t status; H5O_info_t infobuf; - jvalue args[12]; + const char *grpName = NULL; jobject hdrinfobuf; jobject ihinfobuf1; jobject ihinfobuf2; + jvalue args[12]; + herr_t status = FAIL; jobject ret_obj = NULL; - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Oget_info_by_idx2((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (unsigned)fields, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); - } - } + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Oget_info_by_idx: group name not pinned"); + + if ((status = H5Oget_info_by_idx2((hid_t)loc_id, grpName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (unsigned)fields, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args, ret_obj); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf1 = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args, ret_obj); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args, ret_obj); + +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1idx */ @@ -318,130 +341,135 @@ Java_hdf_hdf5lib_H5_H5Olink (JNIEnv *env, jclass clss, jlong cur_loc_id, jlong dst_loc_id, jstring dst_name, jlong create_id, jlong access_id) { - herr_t status = -1; - const char *lDstName; + const char *linkDstName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(dst_name, lDstName); - if (lDstName != NULL) { - status = H5Olink((hid_t)cur_loc_id, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(dst_name, lDstName); + PIN_JAVA_STRING(ENVONLY, dst_name, linkDstName, NULL, "H5Olink: link destination name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Olink((hid_t)cur_loc_id, (hid_t)dst_loc_id, linkDstName, (hid_t)create_id, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (linkDstName) + UNPIN_JAVA_STRING(ENVONLY, dst_name, linkDstName); } /* end Java_hdf_hdf5lib_H5_H5Olink */ static herr_t H5O_iterate_cb (hid_t g_id, const char *name, const H5O_info_t *info, void *cb_data) { - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - jmethodID constructor; - jvalue args[12]; - jobject hdrinfobuf; - jobject ihinfobuf1; - jobject ihinfobuf2; - jobject cb_info_t = NULL; cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; + jmethodID constructor, mid; + jobject cb_info_t = NULL; + jobject visit_callback = wrapper->visit_callback; + jobject hdrinfobuf; + jobject ihinfobuf1; + jobject ihinfobuf2; + jstring str; + JNIEnv *cbenv = NULL; + jclass cls; + jvalue args[12]; + void *op_data = (void *)wrapper->op_data; + jint status = FAIL; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5O_iterate_cb: failed to attach current thread to JVM"); + } + + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + args[0].i = (jint)info->hdr.version; + args[1].i = (jint)info->hdr.nmesgs; + args[2].i = (jint)info->hdr.nchunks; + args[3].i = (jint)info->hdr.flags; + args[4].j = (jlong)info->hdr.space.total; + args[5].j = (jlong)info->hdr.space.meta; + args[6].j = (jlong)info->hdr.space.mesg; + args[7].j = (jlong)info->hdr.space.free; + args[8].j = (jlong)info->hdr.mesg.present; + args[9].j = (jlong)info->hdr.mesg.shared; + + /* Get a reference to the H5_hdr_info_t class */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* Get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(IIIIJJJJJJ)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (hdrinfobuf = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_hdr_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + args[0].j = (jlong)info->meta_size.obj.index_size; + args[1].j = (jlong)info->meta_size.obj.heap_size; - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) != 0) { - /* printf("JNI H5O_iterate_cb error: AttachCurrentThread failed\n"); */ + /* Get a reference to the H5_ih_info_t class */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* Get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(JJ)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (ihinfobuf1 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + args[0].j = (jlong)info->meta_size.attr.index_size; + args[1].j = (jlong)info->meta_size.attr.heap_size; + + if (NULL == (ihinfobuf2 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + args[0].j = (jlong)info->fileno; + args[1].j = (jlong)info->addr; + args[2].i = info->type; + args[3].i = (jint)info->rc; + args[4].j = (jlong)info->num_attrs; + args[5].j = info->atime; + args[6].j = info->mtime; + args[7].j = info->ctime; + args[8].j = info->btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + + /* Get a reference to the H5O_info_t class */ + if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_info_t"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + /* Get a reference to the constructor; the name is */ + if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { + HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_info_t: Creation failed\n"); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + +done: + if (cbenv) JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - - args[0].i = (jint)info->hdr.version; - args[1].i = (jint)info->hdr.nmesgs; - args[2].i = (jint)info->hdr.nchunks; - args[3].i = (jint)info->hdr.flags; - args[4].j = (jlong)info->hdr.space.total; - args[5].j = (jlong)info->hdr.space.meta; - args[6].j = (jlong)info->hdr.space.mesg; - args[7].j = (jlong)info->hdr.space.free; - args[8].j = (jlong)info->hdr.mesg.present; - args[9].j = (jlong)info->hdr.mesg.shared; - // get a reference to the H5_hdr_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_hdr_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(IIIIJJJJJJ)V"); - if (constructor != 0) { - hdrinfobuf = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (hdrinfobuf == NULL) { - printf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_hdr_info_t: Creation failed\n"); - } - else { - args[0].j = (jlong)info->meta_size.obj.index_size; - args[1].j = (jlong)info->meta_size.obj.heap_size; - // get a reference to the H5_ih_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5_ih_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJ)V"); - if (constructor != 0) { - ihinfobuf1 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (ihinfobuf1 == NULL) { - printf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); - } - else { - args[0].j = (jlong)info->meta_size.attr.index_size; - args[1].j = (jlong)info->meta_size.attr.heap_size; - ihinfobuf2 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (ihinfobuf2 == NULL) { - printf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); - } - else { - args[0].j = (jlong)info->fileno; - args[1].j = (jlong)info->addr; - args[2].i = info->type; - args[3].i = (jint)info->rc; - args[4].j = (jlong)info->num_attrs; - args[5].j = info->atime; - args[6].j = info->mtime; - args[7].j = info->ctime; - args[8].j = info->btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - // get a reference to the H5O_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"); - if (constructor != 0) { - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - if (cb_info_t == NULL) { - printf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_info_t: Creation failed\n"); - } - else { - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); - } - } - } - } - } - } - } - } - } - } - } - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5O_iterate_cb */ /* @@ -454,24 +482,23 @@ Java_hdf_hdf5lib_H5_H5Ovisit (JNIEnv *env, jclass clss, jlong grp_id, jint idx_type, jint order, jobject callback_op, jobject op_data, jint fields) { - herr_t status = -1; - cb_wrapper wrapper = {callback_op, op_data}; - - ENVPTR->GetJavaVM(ENVPAR &jvm); - - if (op_data == NULL) { - h5nullArgument(env, "H5Ovisit: op_data is NULL"); - } /* end if */ - else if (callback_op == NULL) { - h5nullArgument(env, "H5Ovisit: callback_op is NULL"); - } /* end if */ - else { - status = H5Ovisit2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)&wrapper, (unsigned)fields); - - if (status < 0) - h5libraryError(env); - } + cb_wrapper wrapper = { callback_op, op_data }; + herr_t status = FAIL; + + UNUSED(clss); + + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit: callback_op is NULL"); + + if ((status = H5Ovisit2((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void *)&wrapper, (unsigned)fields)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return status; } /* end Java_hdf_hdf5lib_H5_H5Ovisit */ @@ -485,31 +512,28 @@ Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name (JNIEnv *env, jclass clss, jlong grp_id, jstring name, jint idx_type, jint order, jobject callback_op, jobject op_data, jint fields, jlong access_id) { - herr_t status = -1; - const char *lName; - cb_wrapper wrapper = {callback_op, op_data}; - - ENVPTR->GetJavaVM(ENVPAR &jvm); - - if (op_data == NULL) { - h5nullArgument(env, "H5Ovisit_by_name: op_data is NULL"); - return -1; - } /* end if */ - else if (callback_op == NULL) { - h5nullArgument(env, "H5Ovisit_by_name: callback_op is NULL"); - return -1; - } /* end if */ - else { - PIN_JAVA_STRING(name, lName); - if (lName != NULL) { - status = H5Ovisit_by_name2((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)&wrapper, (unsigned)fields, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) - h5libraryError(env); - } - } + cb_wrapper wrapper = { callback_op, op_data }; + const char *objName = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit_by_name: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Ovisit_by_name: callback_op is NULL"); + + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Ovisit_by_name: object name not pinned"); + + if ((status = H5Ovisit_by_name2((hid_t)grp_id, objName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void *)&wrapper, (unsigned)fields, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return status; } /* end Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name */ @@ -523,24 +547,20 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oset_1comment (JNIEnv *env, jclass clss, jlong loc_id, jstring comment) { - herr_t status = -1; const char *oComment = NULL; - jboolean isCopy; + herr_t status = FAIL; - if (comment == NULL) { - status = H5Oset_comment((hid_t)loc_id, oComment); - } /* end if */ - else { - oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); - if (oComment != NULL) { - status = H5Oset_comment((hid_t)loc_id, oComment); + UNUSED(clss); - ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); - } - } /* end else */ + if (NULL != comment) + PIN_JAVA_STRING(ENVONLY, comment, oComment, NULL, "H5Oset_comment: object comment not pinned"); - if (status < 0) - h5libraryError(env); + if ((status = H5Oset_comment((hid_t)loc_id, oComment)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (oComment) + UNPIN_JAVA_STRING(ENVONLY, comment, oComment); } /* end Java_hdf_hdf5lib_H5_H5Oset_1comment */ /* @@ -553,29 +573,26 @@ Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jstring comment, jlong access_id) { - herr_t status = -1; - const char *oName; - const char *oComment; - - PIN_JAVA_STRING(name, oName); - if (oName != NULL) { - if (comment == NULL) { - status = H5Oset_comment_by_name((hid_t)loc_id, oName, NULL, (hid_t)access_id); - } /* end if */ - else { - jboolean isCopy; - oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); - if (oComment != NULL) { - status = H5Oset_comment_by_name((hid_t)loc_id, oName, oComment, (hid_t)access_id); - ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); - } /* end if */ - } /* end else */ - - UNPIN_JAVA_STRING(name, oName); - - if (status < 0) - h5libraryError(env); - } + const char *objName = NULL; + const char *objComment = NULL; + jboolean isCopy; + herr_t status = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oset_comment_by_name: object name not pinned"); + + if (NULL != comment) + PIN_JAVA_STRING(ENVONLY, comment, objComment, &isCopy, "H5Oset_comment_by_name: object comment not pinned"); + + if ((status = H5Oset_comment_by_name((hid_t)loc_id, objName, objComment, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (objComment) + UNPIN_JAVA_STRING(ENVONLY, comment, objComment); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); } /* end Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name */ /* @@ -587,39 +604,32 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Oget_1comment (JNIEnv *env, jclass clss, jlong loc_id) { - char *oComment; - ssize_t buf_size; - ssize_t status; jstring str = NULL; + ssize_t buf_size; + ssize_t status = -1; + char *oComment = NULL; + + UNUSED(clss); + + /* Get the length of the comment */ + if ((buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (buf_size) { + if (NULL == (oComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment: failed to allocate object comment buffer"); + + if ((status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + oComment[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oComment))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } - /* get the length of the comment */ - buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0); - if (buf_size < 0) { - h5badArgument( env, "H5Oget_comment: buf_size < 0"); - } /* end if */ - else if (buf_size > 0) { - buf_size++; /* add extra space for the null terminator */ - oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (oComment == NULL) { - /* exception -- out of memory */ - h5outOfMemory( env, "H5Oget_comment: malloc failed"); - } /* end if */ - else { - status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - /* may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR oComment); - if (str == NULL) { - h5JNIFatalError( env, "H5Oget_comment: return string not allocated"); - } /* end if */ - } /* end else */ - HDfree(oComment); - } - } /* end else if */ +done: + if (oComment) + HDfree(oComment); return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */ @@ -633,44 +643,38 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id) { - char *oComment; - const char *oName; + const char *objName = NULL; + jstring str = NULL; ssize_t buf_size; ssize_t status; - jstring str = NULL; + char *objComment = NULL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oget_comment_by_name: object name not pinned"); + + /* Get the length of the comment */ + if ((buf_size = H5Oget_comment_by_name((hid_t)loc_id, objName, NULL, 0, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (buf_size) { + if (NULL == (objComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment_by_name: failed to allocate buffer for object comment"); + + if ((status = H5Oget_comment_by_name((hid_t)loc_id, objName, objComment, (size_t)buf_size + 1, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + objComment[buf_size] = '\0'; - PIN_JAVA_STRING(name, oName); - if (oName != NULL) { - /* get the length of the comment */ - buf_size = H5Oget_comment_by_name((hid_t)loc_id, oName, NULL, 0, (hid_t)access_id); - if (buf_size < 0) { - h5badArgument( env, "H5Oget_comment_by_name: buf_size < 0"); - } /* end if */ - else if (buf_size > 0) { - buf_size++; /* add extra space for the null terminator */ - oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (oComment == NULL) { - h5outOfMemory( env, "H5Oget_comment_by_name: malloc failed"); - } /* end if */ - else { - status = H5Oget_comment_by_name((hid_t)loc_id, oName, oComment, (size_t)buf_size, (hid_t)access_id); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - /* may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR oComment); - if (str == NULL) { - h5JNIFatalError( env, "H5Oget_comment_by_name: return string not allocated"); - } /* end if */ - } /* end else */ - HDfree(oComment); - } - } /* end if */ - UNPIN_JAVA_STRING(name, oName); + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, objComment))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } +done: + if (objComment) + HDfree(objComment); + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); + return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name */ @@ -683,20 +687,21 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Oexists_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id) { + const char *objName = NULL; htri_t bval = JNI_FALSE; - const char *oName; - PIN_JAVA_STRING(name, oName); - if (oName != NULL) { - bval = H5Oexists_by_name((hid_t)loc_id, oName, (hid_t)access_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, oName); + PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oexists_by_name: object name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5Oexists_by_name((hid_t)loc_id, objName, (hid_t)access_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (objName) + UNPIN_JAVA_STRING(ENVONLY, name, objName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Oexists_1by_1name */ @@ -710,8 +715,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Odecr_1refcount (JNIEnv *env, jclass clss, jlong object_id) { + UNUSED(clss); + if (H5Odecr_refcount((hid_t)object_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Odecr_1refcount */ /* @@ -723,8 +733,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oincr_1refcount (JNIEnv *env, jclass clss, jlong object_id) { + UNUSED(clss); + if (H5Oincr_refcount((hid_t)object_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Oincr_1refcount */ /* @@ -736,12 +751,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Oopen_1by_1addr (JNIEnv *env, jclass clss, jlong loc_id, jlong addr) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Oopen_by_addr((hid_t)loc_id, (haddr_t)addr ); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Oopen_by_addr((hid_t)loc_id, (haddr_t)addr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Oopen_1by_1addr */ @@ -755,18 +772,19 @@ Java_hdf_hdf5lib_H5__1H5Oopen_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jlong lapl_id) { - hid_t retVal = -1; - const char *oName; + const char *grpName = NULL; + hid_t retVal = H5I_INVALID_HID; - PIN_JAVA_STRING(name, oName); - if (oName != NULL) { - retVal = H5Oopen_by_idx((hid_t)loc_id, oName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (hid_t)lapl_id ); + UNUSED(clss); - UNPIN_JAVA_STRING(name, oName); + PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Oopen_by_idx: object name not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5Oopen_by_idx((hid_t)loc_id, grpName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (grpName) + UNPIN_JAVA_STRING(ENVONLY, name, grpName); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Oopen_1by_1idx */ @@ -780,8 +798,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oflush (JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Oflush((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Oflush */ /* @@ -793,8 +816,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Orefresh (JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Orefresh((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Orefresh */ diff --git a/java/src/jni/h5pACPLImp.c b/java/src/jni/h5pACPLImp.c new file mode 100644 index 0000000..f6c14e1 --- /dev/null +++ b/java/src/jni/h5pACPLImp.c @@ -0,0 +1,36 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pACPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pACPLImp.h b/java/src/jni/h5pACPLImp.h new file mode 100644 index 0000000..194afc0 --- /dev/null +++ b/java/src/jni/h5pACPLImp.h @@ -0,0 +1,27 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PACPL +#define _Included_hdf_hdf5lib_H5_H5PACPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PACPL */ diff --git a/java/src/jni/h5pDAPLImp.c b/java/src/jni/h5pDAPLImp.c new file mode 100644 index 0000000..0afbbd6 --- /dev/null +++ b/java/src/jni/h5pDAPLImp.c @@ -0,0 +1,322 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pDAPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +extern JavaVM *jvm; + +typedef struct _cb_wrapper { + jobject visit_callback; + jobject op_data; +} cb_wrapper; + +static herr_t H5D_append_cb(hid_t dataset_id, hsize_t *cur_dims, void *cb_data); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk_cache + * Signature: (JJJD)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache + (JNIEnv *env, jclass clss, jlong dapl, jlong rdcc_nslots, + jlong rdcc_nbytes, jdouble rdcc_w0) +{ + UNUSED(clss); + + if (H5Pset_chunk_cache((hid_t)dapl, (size_t)rdcc_nslots, (size_t)rdcc_nbytes, (double) rdcc_w0) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk_cache + * Signature: (J[J[J[D)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache + (JNIEnv *env, jclass clss, jlong dapl, jlongArray rdcc_nslots, + jlongArray rdcc_nbytes, jdoubleArray rdcc_w0) +{ + jboolean isCopy; + jdouble *w0Array = NULL; + jlong *rdcc_nslotsArray = NULL; + jlong *nbytesArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL != rdcc_w0) + PIN_DOUBLE_ARRAY(ENVONLY, rdcc_w0, w0Array, &isCopy, "H5Pget_chunk_cache: rdcc_w0 array not pinned"); + if (NULL != rdcc_nslots) + PIN_LONG_ARRAY(ENVONLY, rdcc_nslots, rdcc_nslotsArray, &isCopy, "H5Pget_chunk_cache: rdcc_nslots array not pinned"); + if (NULL != rdcc_nbytes) + PIN_LONG_ARRAY(ENVONLY, rdcc_nbytes, nbytesArray, &isCopy, "H5Pget_chunk_cache: nbytesArray array not pinned"); + + { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long rdcc_nslots_temp = *rdcc_nslotsArray; + long long nbytes_temp = *nbytesArray; + size_t rdcc_nslots_t = (size_t) rdcc_nslots_temp; + size_t nbytes_t = (size_t) nbytes_temp; + + if ((status = H5Pget_chunk_cache((hid_t)dapl, &rdcc_nslots_t, &nbytes_t, (double *)w0Array)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + *rdcc_nslotsArray = (jlong)rdcc_nslots_t; + *nbytesArray = (jlong)nbytes_t; + } /* end direct cast special handling */ + +done: + if (nbytesArray) + UNPIN_LONG_ARRAY(ENVONLY, rdcc_nbytes, nbytesArray, (status < 0) ? JNI_ABORT : 0); + if (rdcc_nslotsArray) + UNPIN_LONG_ARRAY(ENVONLY, rdcc_nslots, rdcc_nslotsArray, (status < 0) ? JNI_ABORT : 0); + if (w0Array) + UNPIN_DOUBLE_ARRAY(ENVONLY, rdcc_w0, w0Array, (status < 0) ? JNI_ABORT : 0); +} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_efile_prefix + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix + (JNIEnv *env, jclass clss, jlong dapl_id, jstring prefix) +{ + const char *extFilePrefix = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, prefix, extFilePrefix, NULL, "H5Pset_efile_prefix: external file prefix not pinned"); + + if ((retVal = H5Pset_efile_prefix((hid_t)dapl_id, extFilePrefix)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (extFilePrefix) + UNPIN_JAVA_STRING(ENVONLY, prefix, extFilePrefix); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_efile_prefix + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix + (JNIEnv *env, jclass clss, jlong dapl_id) +{ + ssize_t prefix_size = -1; + char *pre = NULL; + jstring str = NULL; + + UNUSED(clss); + + if ((prefix_size = H5Pget_efile_prefix((hid_t)dapl_id, (char *)NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t)prefix_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_efile_prefix: memory allocation failed"); + + if (H5Pget_efile_prefix((hid_t)dapl_id, (char *)pre, (size_t)prefix_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + pre[(size_t)prefix_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_efile_prefix: out of memory - unable to construct string from UTF characters"); + } + +done: + if (pre) + HDfree(pre); + + return (jstring)str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_append_flush + * Signature: (JI[JLjava/lang/Object;Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1append_1flush + (JNIEnv *env, jclass clss, jlong plist_id, jint ndims, jlongArray boundary, jobject callback_op, jobject op_data) +{ + cb_wrapper wrapper = { callback_op, op_data }; + herr_t status = FAIL; + + UNUSED(clss); + + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pset_append_flush: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pset_append_flush: callback_op is NULL"); + + if ((status = H5Pset_append_flush((hid_t)plist_id, (unsigned)ndims, (const hsize_t *)boundary, (H5D_append_cb_t)H5D_append_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1append_1flush */ + +/* + * TODO: H5Pget_append_flush + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_view + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view + (JNIEnv *env, jclass clss, jlong dapl_id, jint view) +{ + UNUSED(clss); + + if (H5Pset_virtual_view((hid_t)dapl_id, (H5D_vds_view_t)view) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_view + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view + (JNIEnv *env, jclass clss, jlong dapl_id) +{ + H5D_vds_view_t virtual_view = H5D_VDS_ERROR; + + UNUSED(clss); + + if (H5Pget_virtual_view((hid_t)dapl_id, &virtual_view) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)virtual_view; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_printf_gap + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap + (JNIEnv *env, jclass clss, jlong dapl_id, jlong gap_size) +{ + UNUSED(clss); + + if (H5Pset_virtual_printf_gap((hid_t)dapl_id, (hsize_t)gap_size) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_printf_gap + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap + (JNIEnv *env, jclass clss, jlong dapl_id) +{ + hsize_t gap_size = 0; + + UNUSED(clss); + + if (H5Pget_virtual_printf_gap((hid_t)dapl_id, &gap_size) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)gap_size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap */ + +static herr_t +H5D_append_cb + (hid_t dataset_id, hsize_t *cur_dims, void *cb_data) +{ + cb_wrapper *wrapper = (cb_wrapper *)cb_data; + jlongArray cur_dimsArray; + jmethodID mid; + jobject visit_callback = wrapper->visit_callback; + jclass cls; + JNIEnv *cbenv = NULL; + void *op_data = (void *)wrapper->op_data; + jint status = -1; + + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5D_append_cb: failed to attach current thread to JVM"); + } + + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(J[JLhdf/hdf5lib/callbacks/H5D_append_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + if (NULL != cur_dims) { + if (NULL == (cur_dimsArray = CBENVPTR->NewLongArray(CBENVONLY, 2))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + CBENVPTR->SetLongArrayRegion(CBENVONLY, cur_dimsArray, 0, 2, (const jlong *)cur_dims); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, dataset_id, cur_dims, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + } + +done: + if (CBENVONLY) + JVMPTR->DetachCurrentThread(JVMPAR); + + return (herr_t)status; +} /* end H5D_append_cb */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pDAPLImp.h b/java/src/jni/h5pDAPLImp.h new file mode 100644 index 0000000..a9fbadd --- /dev/null +++ b/java/src/jni/h5pDAPLImp.h @@ -0,0 +1,112 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PDAPL +#define _Included_hdf_hdf5lib_H5_H5PDAPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk_cache + * Signature: (JJJD)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache +(JNIEnv *, jclass, jlong, jlong, jlong, jdouble); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk_cache + * Signature: (J[J[J[D)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache +(JNIEnv *, jclass, jlong, jlongArray, jlongArray, jdoubleArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_efile_prefix + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix +(JNIEnv *, jclass, jlong, jstring); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_efile_prefix + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_append_flush + * Signature: (JI[JLjava/lang/Object;Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1append_1flush + (JNIEnv*, jclass, jlong, jint, jlongArray, jobject, jobject); + +/* + * TODO: H5Pget_append_flush + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_view + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_view + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_printf_gap + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_printf_gap + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap +(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PDAPL */ diff --git a/java/src/jni/h5pDCPLImp.c b/java/src/jni/h5pDCPLImp.c new file mode 100644 index 0000000..0671843 --- /dev/null +++ b/java/src/jni/h5pDCPLImp.c @@ -0,0 +1,1404 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pDCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_layout + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1layout + (JNIEnv *env, jclass clss, jlong plist, jint layout) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_layout((hid_t)plist, (H5D_layout_t)layout)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1layout */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_layout + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1layout + (JNIEnv *env, jclass clss, jlong plist) +{ + H5D_layout_t retVal = H5D_LAYOUT_ERROR; + + UNUSED(clss); + + if (H5D_LAYOUT_ERROR == (retVal = H5Pget_layout((hid_t)plist))) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1layout */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk + * Signature: (JI[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk + (JNIEnv *env, jclass clss, jlong plist, jint ndims, jbyteArray dim) +{ + jboolean isCopy; + hsize_t *da = NULL; + hsize_t *lp = NULL; + size_t i; + size_t rank; + jsize arrLen; + jbyte *theArray = NULL; + jlong *jlp = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (ndims < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_chunk: ndims < 0"); + if (NULL == dim) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pset_chunk: dim array is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, dim)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_chunk: dim array length < 0"); + } + + rank = (size_t) arrLen / sizeof(jlong); + if (rank < (size_t) ndims) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_chunk: dims array rank < ndims"); + + PIN_BYTE_ARRAY(ENVONLY, dim, theArray, &isCopy, "H5Pset_chunk: dim array not pinned"); + + if (NULL == (da = lp = (hsize_t *) HDmalloc(rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pset_chunk: memory allocation failed"); + + jlp = (jlong *)theArray; + for (i = 0; i < rank; i++) { + *lp = (hsize_t)*jlp; + lp++; + jlp++; + } /* end if */ + + if ((status = H5Pset_chunk((hid_t)plist, (int)ndims, da)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (da) + HDfree(da); + if (theArray) + UNPIN_BYTE_ARRAY(ENVONLY, dim, theArray, JNI_ABORT); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk + * Signature: (JI[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk + (JNIEnv *env, jclass clss, jlong plist, jint max_ndims, jlongArray dims) +{ + jboolean isCopy; + hsize_t *da = NULL; + jlong *theArray = NULL; + jsize arrLen; + int i; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_chunk: dims is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_chunk: dims array length < 0"); + } + if (arrLen < max_ndims) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_chunk: dims array < max_ndims"); + + PIN_LONG_ARRAY(ENVONLY, dims, theArray, &isCopy, "H5Pget_chunk: input dims not pinned"); + + if (NULL == (da = (hsize_t *) HDmalloc((size_t)max_ndims * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_chunk: memory allocation failed"); + + if ((status = H5Pget_chunk((hid_t)plist, (int)max_ndims, da)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < max_ndims; i++) + theArray[i] = (jlong)da[i]; + +done: + if (da) + HDfree(da); + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, dims, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk_opts + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts + (JNIEnv *env, jclass clss, jlong dcpl_id, jint opts) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_chunk_opts((hid_t)dcpl_id, (unsigned)opts)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk_opts + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts + (JNIEnv *env, jclass clss, jlong dcpl_id) +{ + unsigned opts = 0; + + UNUSED(clss); + + if (H5Pget_chunk_opts((hid_t)dcpl_id, &opts) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)opts; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_dset_no_attrs_hint + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1dset_1no_1attrs_1hint +(JNIEnv *env, jclass clss, jlong dcpl_id, jboolean minimize) +{ + hbool_t minimize_val; + herr_t retVal = FAIL; + + UNUSED(clss); + + minimize_val = (JNI_TRUE == minimize) ? TRUE : FALSE; + + if ((retVal = H5Pset_dset_no_attrs_hint((hid_t)dcpl_id, (hbool_t)minimize_val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1dset_1no_1attrs_1hint */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_dset_no_attrs_hint + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1dset_1no_1attrs_1hint +(JNIEnv *env, jclass clss, jlong dcpl_id) +{ + hbool_t minimize = FALSE; + jboolean bval = JNI_FALSE; + + UNUSED(clss); + + if (H5Pget_dset_no_attrs_hint((hid_t)dcpl_id, (hbool_t *)&minimize) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (minimize == TRUE) + bval = JNI_TRUE; + +done: + return bval; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1dset_1no_1attrs_1hint */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_deflate + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1deflate + (JNIEnv *env, jclass clss, jlong plist, jint level) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_deflate((hid_t)plist, (unsigned)level)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1deflate */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fill_value + * Signature: (JJ[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fill_1value + (JNIEnv *env, jclass clss, jlong plist_id, jlong type_id, jbyteArray value) +{ + jboolean isCopy; + jbyte *byteP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) { + if ((status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + else { + PIN_BYTE_ARRAY(ENVONLY, value, byteP, &isCopy, "H5Pget_fill_value: value array not pinned"); + + if ((status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (byteP) + UNPIN_BYTE_ARRAY(ENVONLY, value, byteP, JNI_ABORT); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fill_1value */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fill_value + * Signature: (JJ[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fill_1value + (JNIEnv *env, jclass clss, jlong plist_id, jlong type_id, jbyteArray value) +{ + jboolean isCopy; + herr_t status = FAIL; + jbyte *byteP = NULL; + + UNUSED(clss); + + if (NULL == value) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_fill_value: value is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, value, byteP, &isCopy, "H5Pget_fill_value: value array not pinned"); + + if ((status = H5Pget_fill_value((hid_t)plist_id, (hid_t)type_id, byteP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (byteP) + UNPIN_BYTE_ARRAY(ENVONLY, value, byteP, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fill_1value */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pfill_value_defined + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined + (JNIEnv *env, jclass clss, jlong plist, jintArray status) +{ + H5D_fill_value_t value = H5D_FILL_VALUE_ERROR; + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == status) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pfill_value_defined: status is NULL"); + + PIN_INT_ARRAY(ENVONLY, status, theArray, &isCopy, "H5Pfill_value_defined: status not pinned"); + + if ((retVal = H5Pfill_value_defined((hid_t)plist, &value)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jint)value; + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, status, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fill_time + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fill_1time + (JNIEnv *env, jclass clss, jlong plist, jint fill_time) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fill_time((hid_t)plist, (H5D_fill_time_t)fill_time)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fill_1time */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fill_time + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fill_1time + (JNIEnv *env, jclass clss, jlong plist, jintArray fill_time) +{ + H5D_fill_time_t time = H5D_FILL_TIME_ERROR; + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == fill_time) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_fill_time: fill_time is NULL"); + + PIN_INT_ARRAY(ENVONLY, fill_time, theArray, &isCopy, "H5Pget_fill_time: fill_time not pinned"); + + if ((retVal = H5Pget_fill_time((hid_t)plist, &time)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jint)time; + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, fill_time, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fill_1time */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_alloc_time + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time + (JNIEnv *env, jclass clss, jlong plist, jint alloc_time) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_alloc_time((hid_t)plist, (H5D_alloc_time_t)alloc_time)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_alloc_time + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time + (JNIEnv *env, jclass clss, jlong plist, jintArray alloc_time) +{ + H5D_alloc_time_t time = H5D_ALLOC_TIME_ERROR; + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == alloc_time) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_alloc_time: alloc_time is NULL"); + + PIN_INT_ARRAY(ENVONLY, alloc_time, theArray, &isCopy, "H5Pget_alloc_time: alloc_time not pinned"); + + if ((retVal = H5Pget_alloc_time((hid_t)plist, &time)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = time; + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, alloc_time, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_filter + * Signature: (JIIJ[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1filter + (JNIEnv *env, jclass clss, jlong plist, jint filter, jint flags, + jlong cd_nelmts, jintArray cd_values) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == cd_values) { + if ((status = H5Pset_filter((hid_t)plist, (H5Z_filter_t)filter, + (unsigned int)flags, (size_t)cd_nelmts, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + else { + PIN_INT_ARRAY(ENVONLY, cd_values, theArray, &isCopy, "H5Pset_filter: input array not pinned"); + + if ((status = H5Pset_filter((hid_t)plist, (H5Z_filter_t)filter, + (unsigned int)flags, (size_t)cd_nelmts, (const unsigned int *)theArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, cd_values, theArray, JNI_ABORT); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1filter */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pall_filters_avail + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail + (JNIEnv *env, jclass clss, jlong dcpl_id) +{ + htri_t bval = JNI_FALSE; + + UNUSED(clss); + + if ((bval = H5Pall_filters_avail((hid_t)dcpl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + return (jboolean)bval; +} /* end Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_nfilters + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1nfilters + (JNIEnv *env, jclass clss, jlong plist) +{ + int retVal = -1; + + UNUSED(clss); + + if ((retVal = H5Pget_nfilters((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1nfilters */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter + * Signature: (JI[I[J[IJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter + (JNIEnv *env, jclass clss, jlong plist, jint filter_number, jintArray flags, + jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name) +{ + jboolean isCopy; + jstring str; + jint *flagsArray = NULL; + jlong *cd_nelmtsArray = NULL; + jint *cd_valuesArray = NULL; + char *filter = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (namelen <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter: namelen <= 0"); + if (NULL == flags) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter: flags is NULL"); + if (NULL == cd_nelmts) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter: cd_nelmts is NULL"); + if (NULL == cd_values) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter: cd_values is NULL"); + + if (NULL == (filter = (char *) HDmalloc(sizeof(char) * (size_t)namelen))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter: memory allocation failed"); + + PIN_INT_ARRAY(ENVONLY, flags, flagsArray, &isCopy, "H5Pget_filter: flags array not pinned"); + PIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, &isCopy, "H5Pget_filter: nelmts array not pinned"); + PIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, &isCopy, "H5Pget_filter: elmts array not pinned"); + + + /* direct cast (size_t *)variable fails on 32-bit environment */ + { + unsigned int filter_config; + long long cd_nelmts_temp = *cd_nelmtsArray; + size_t cd_nelmts_t = (size_t) cd_nelmts_temp; + + if ((status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, + (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, + (size_t)namelen, filter, &filter_config)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + filter[namelen - 1] = '\0'; + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + } + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, filter))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (cd_valuesArray) + UNPIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, (status < 0) ? JNI_ABORT : 0); + if (cd_nelmtsArray) + UNPIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, (status < 0) ? JNI_ABORT : 0); + if (flagsArray) + UNPIN_INT_ARRAY(ENVONLY, flags, flagsArray, (status < 0) ? JNI_ABORT : 0) + if (filter) + HDfree(filter); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter2 + * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter2 + (JNIEnv *env, jclass clss, jlong plist, jint filter_number, + jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, + jobjectArray name, jintArray filter_config) +{ + jboolean isCopy; + jstring str; + jint *flagsArray = NULL; + jlong *cd_nelmtsArray = NULL; + jint *cd_valuesArray = NULL; + jint *filter_configArray = NULL; + char *filter = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (namelen <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter2: namelen <= 0"); + if (NULL == flags) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter2: flags is NULL"); + if (NULL == cd_nelmts) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter2: cd_nelmts is NULL"); + if (NULL == filter_config) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter2: filter_config is NULL"); + + if (NULL == (filter = (char *) HDmalloc(sizeof(char) * (size_t)namelen))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter2: memory allocation failed"); + + PIN_INT_ARRAY(ENVONLY, flags, flagsArray, &isCopy, "H5Pget_filter2: flags array not pinned"); + PIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, &isCopy, "H5Pget_filter2: nelmts array not pinned"); + PIN_INT_ARRAY(ENVONLY, filter_config, filter_configArray, &isCopy, "H5Pget_filter2: filter_config array not pinned"); + + if (NULL == cd_values && *cd_nelmtsArray == 0) { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long cd_nelmts_temp = 0; + size_t cd_nelmts_t = (size_t) cd_nelmts_temp; + + if ((status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, + (unsigned int *)flagsArray, &cd_nelmts_t, NULL, + (size_t)namelen, filter, (unsigned int *)filter_configArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + filter[namelen - 1] = '\0'; + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + } + else { + if (NULL == cd_values) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter2: cd_values is NULL"); + + PIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, &isCopy, "H5Pget_filter2: elmts array not pinned"); + + { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long cd_nelmts_temp = *cd_nelmtsArray; + size_t cd_nelmts_t = (size_t) cd_nelmts_temp; + + if ((status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, + (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, + (size_t)namelen, filter, (unsigned int *)filter_configArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + filter[namelen - 1] = '\0'; + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + } /* end direct cast special */ + } + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, filter))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter2: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (cd_valuesArray) + UNPIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, (status < 0) ? JNI_ABORT : 0); + if (filter_configArray) + UNPIN_INT_ARRAY(ENVONLY, filter_config, filter_configArray, (status < 0) ? JNI_ABORT : 0); + if (cd_nelmtsArray) + UNPIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, (status < 0) ? JNI_ABORT : 0); + if (flagsArray) + UNPIN_INT_ARRAY(ENVONLY, flags, flagsArray, (status < 0) ? JNI_ABORT : 0); + if (filter) + HDfree(filter); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter2 */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter_by_id + * Signature: (JI[I[J[IJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id + (JNIEnv *env, jclass clss, jlong plist, jint filter, + jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name) +{ + jboolean isCopy; + jstring str; + jlong *cd_nelmtsArray = NULL; + jint *cd_valuesArray = NULL; + jint *flagsArray = NULL; + char *aName = NULL; + long bs; + int rank; + herr_t status = FAIL; + + UNUSED(clss); + + bs = (long)namelen; + + if (bs <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: namelen <= 0"); + if (NULL == flags) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: flags is NULL"); + if (NULL == cd_nelmts) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: cd_nelmts is NULL"); + if (NULL == cd_values) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: cd_values is NULL"); + if (NULL == name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: name is NULL"); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)bs))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter_by_id: memory allocation failed"); + + PIN_INT_ARRAY(ENVONLY, flags, flagsArray, &isCopy, "H5Pget_filter_by_id: flags not pinned"); + PIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, &isCopy, "H5Pget_filter_by_id: cd_nelms not pinned"); + PIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, &isCopy, "H5Pget_filter_by_id: cd_values array not pinned"); + + if ((rank = ENVPTR->GetArrayLength(ENVONLY, cd_values)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id: cd_values array length < 0"); + } + + { + /* direct cast (size_t *)variable fails on 32-bit environment */ + unsigned int filter_config; + long long cd_nelmts_temp = *cd_nelmtsArray; + size_t cd_nelmts_t = (size_t) cd_nelmts_temp; + + if ((status = H5Pget_filter_by_id2((hid_t)plist, (H5Z_filter_t)filter, + (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, + (size_t)namelen, (char *)aName, &filter_config)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + aName[bs - 1] = '\0'; + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + } /* end direct cast special */ + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter_by_id: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (cd_valuesArray) + UNPIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, (status < 0) ? JNI_ABORT : 0); + if (cd_nelmtsArray) + UNPIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, (status < 0) ? JNI_ABORT : 0); + if (flagsArray) + UNPIN_INT_ARRAY(ENVONLY, flags, flagsArray, (status < 0) ? JNI_ABORT : 0); + if (aName) + HDfree(aName); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter_by_id2 + * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 + (JNIEnv *env, jclass clss, jlong plist, jint filter, + jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name, jintArray filter_config) +{ + jboolean isCopy; + jstring str; + jlong *cd_nelmtsArray = NULL; + jint *cd_valuesArray = NULL; + jint *flagsArray = NULL; + jint *filter_configArray = NULL; + long bs; + char *aName = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + bs = (long)namelen; + + if (bs <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: namelen <= 0"); + if (NULL == flags) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: flags is NULL"); + if (NULL == cd_nelmts) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: cd_nelmts is NULL"); + if (NULL == cd_values) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: cd_values is NULL"); + if (NULL == name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: name is NULL"); + if (NULL == filter_config) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_filter_by_id2: filter_config is NULL"); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)bs))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter_by_id2: memory allocation failed"); + + PIN_INT_ARRAY(ENVONLY, flags, flagsArray, &isCopy, "H5Pget_filter_by_id2: flags not pinned"); + PIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, &isCopy, "H5Pget_filter_by_id2: cd_nelms not pinned"); + PIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, &isCopy, "H5Pget_filter_by_id2: cd_values array not pinned"); + PIN_INT_ARRAY(ENVONLY, filter_config, filter_configArray, &isCopy, "H5Pget_filter_by_id2: filter_config not pinned"); + + { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long cd_nelmts_temp = *cd_nelmtsArray; + size_t cd_nelmts_t = (size_t) cd_nelmts_temp; + + if ((status = H5Pget_filter_by_id2((hid_t)plist, (H5Z_filter_t)filter, + (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, + (size_t)namelen, (char *)aName, (unsigned int *)filter_configArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + aName[bs - 1] = '\0'; + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + } /* end direct cast special handling */ + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_filter_by_id2: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (filter_configArray) + UNPIN_INT_ARRAY(ENVONLY, filter_config, filter_configArray, (status < 0) ? JNI_ABORT : 0); + if (cd_valuesArray) + UNPIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesArray, (status < 0) ? JNI_ABORT : 0); + if (cd_nelmtsArray) + UNPIN_LONG_ARRAY(ENVONLY, cd_nelmts, cd_nelmtsArray, (status < 0) ? JNI_ABORT : 0); + if (flagsArray) + UNPIN_INT_ARRAY(ENVONLY, flags, flagsArray, (status < 0) ? JNI_ABORT : 0); + if (aName) + HDfree(aName); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pmodify_filter + * Signature: (JIIJ[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pmodify_1filter + (JNIEnv *env, jclass clss, jlong plist, jint filter, + jint flags, jlong cd_nelmts, jintArray cd_values) +{ + jboolean isCopy; + jint *cd_valuesP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == cd_values) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pmodify_filter: cd_values is NULL"); + + PIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesP, &isCopy, "H5Pmodify_filter: cd_values not pinned"); + + if ((status = H5Pmodify_filter((hid_t)plist, (H5Z_filter_t)filter, (const unsigned int)flags, + (size_t)cd_nelmts, (unsigned int *)cd_valuesP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (cd_valuesP) + UNPIN_INT_ARRAY(ENVONLY, cd_values, cd_valuesP, JNI_ABORT); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pmodify_1filter */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Premove_filter + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5P1remove_1filter + (JNIEnv *env, jclass clss, jlong obj_id, jint filter) +{ + herr_t status = FAIL; + + UNUSED(clss); + + if ((status = H5Premove_filter((hid_t)obj_id, (H5Z_filter_t)filter)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5P1remove_1filter */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fletcher32 + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 + (JNIEnv *env, jclass clss, jlong plist) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fletcher32((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_nbit + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1nbit + (JNIEnv *env, jclass clss, jlong plist_id) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_nbit((hid_t)plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1nbit */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_scaleoffset + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset + (JNIEnv *env, jclass clss, jlong plist_id, jint scale_type, jint scale_factor) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if (scale_factor <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_scaleoffset: scale factor must be > 0"); + if (scale_type != H5Z_SO_FLOAT_DSCALE && scale_type != H5Z_SO_FLOAT_ESCALE && scale_type != H5Z_SO_INT) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_scaleoffset: invalid scale type"); + + if ((retVal = H5Pset_scaleoffset((hid_t)plist_id, (H5Z_SO_scale_type_t)scale_type, scale_factor)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shuffle + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shuffle + (JNIEnv *env, jclass clss, jlong plist) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_shuffle((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1shuffle */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_szip + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1szip + (JNIEnv *env, jclass clss, jlong plist, jint options_mask, jint pixels_per_block) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_szip((hid_t)plist, (unsigned int)options_mask, (unsigned int)pixels_per_block)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1szip */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_external + * Signature: (JLjava/lang/String;JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1external + (JNIEnv *env, jclass clss, jlong plist, jstring name, jlong offset, jlong size) +{ + const char *fileName = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, fileName, NULL, "H5Pset_external: file name not pinned"); + + if ((status = H5Pset_external((hid_t)plist, fileName, (off_t)offset, (hsize_t)size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, name, fileName); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1external */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_external + * Signature: (JIJ[Ljava/lang/String;[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1external + (JNIEnv *env, jclass clss, jlong plist, jint idx, jlong name_size, + jobjectArray name, jlongArray size) +{ + jboolean isCopy; + jstring str; + hsize_t s; + off_t o; + jsize arrLen; + jlong *theArray = NULL; + char *file = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (name_size < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_external: name_size < 0"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, size)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_external: size array length < 0"); + } + if ((size != NULL) && (arrLen < 2)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_external: size input array < 2"); + + if (name_size > 0) + if (NULL == (file = (char *) HDmalloc(sizeof(char) * (size_t)name_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_external: memory allocation failed"); + + if ((status = H5Pget_external((hid_t) plist, (unsigned)idx, (size_t)name_size, + file, (off_t *)&o, (hsize_t *)&s)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL != size) { + PIN_LONG_ARRAY(ENVONLY, size, theArray, &isCopy, "H5Pget_external: size array not pinned"); + + theArray[0] = o; + theArray[1] = (jlong)s; + } + + if (NULL != file) { + file[name_size - 1] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, file))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_external: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); + if (file) + HDfree(file); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1external */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_external_count + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1external_1count + (JNIEnv *env, jclass clss, jlong plist) +{ + int retVal = -1; + + UNUSED(clss); + + if ((retVal = H5Pget_external_count((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1external_1count */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual + * Signature: (JJLjava/lang/String;Ljava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual + (JNIEnv *env, jclass clss, jlong dcpl_id, jlong vspace_id, + jstring src_file_name, jstring src_dset_name, jlong src_space_id) +{ + const char *fstr = NULL; + const char *dstr = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, src_file_name, fstr, NULL, "H5Pset_virtual: src_file_name not pinned"); + PIN_JAVA_STRING(ENVONLY, src_dset_name, dstr, NULL, "H5Pset_virtual: src_dset_name not pinned"); + + if ((retVal = H5Pset_virtual((hid_t)dcpl_id, (hid_t)vspace_id, fstr, dstr, (hid_t)src_space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (dstr) + UNPIN_JAVA_STRING(ENVONLY, src_dset_name, dstr); + if (fstr) + UNPIN_JAVA_STRING(ENVONLY, src_file_name, fstr); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_count + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count + (JNIEnv *env, jclass clss, jlong dcpl_id) +{ + size_t s = 0; + + UNUSED(clss); + + if (H5Pget_virtual_count((hid_t)dcpl_id, &s) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)s; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_dsetname + * Signature: (JJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname + (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) +{ + ssize_t buf_size; + char *dname = NULL; + jstring str = NULL; + + UNUSED(clss); + + /* get the length of the filename */ + if ((buf_size = H5Pget_virtual_dsetname((hid_t)dcpl_id, (size_t)index, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (dname = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_dsetname: memory allocation failed"); + + if (H5Pget_virtual_dsetname((hid_t)dcpl_id, (size_t)index, dname, (size_t)buf_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + dname[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, dname))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_dsetname: out of memory - unable to construct string from UTF characters"); + } + +done: + if (dname) + HDfree(dname); + + return (jstring)str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_filename + * Signature: (JJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename + (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) +{ + ssize_t buf_size; + char *fname = NULL; + jstring str = NULL; + + UNUSED(clss); + + /* get the length of the filename */ + if ((buf_size = H5Pget_virtual_filename((hid_t)dcpl_id, (size_t)index, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (fname = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_filename: memory allocation failed"); + + if (H5Pget_virtual_filename((hid_t)dcpl_id, (size_t)index, fname, (size_t)buf_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + fname[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, fname))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_filename: out of memory - unable to construct string from UTF characters"); + } + +done: + if (fname) + HDfree(fname); + + return (jstring)str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_srcspace + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace + (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) +{ + hid_t space_id = H5I_INVALID_HID; + + UNUSED(clss); + + if ((space_id = H5Pget_virtual_srcspace((hid_t)dcpl_id, (size_t)index)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)space_id; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_vspace + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace + (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) +{ + hid_t space_id = H5I_INVALID_HID; + + UNUSED(clss); + + if ((space_id = H5Pget_virtual_vspace((hid_t)dcpl_id, (size_t)index)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)space_id; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_prefix + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix + (JNIEnv *env, jclass clss, jlong dapl_id, jstring prefix) +{ + const char *virtPrefix = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, prefix, virtPrefix, NULL, "H5Pset_virtual_prefix: virtual prefix not pinned"); + + if ((retVal = H5Pset_virtual_prefix((hid_t)dapl_id, virtPrefix)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (virtPrefix) + UNPIN_JAVA_STRING(ENVONLY, prefix, virtPrefix); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_prefix + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix + (JNIEnv *env, jclass clss, jlong dapl_id) +{ + ssize_t prefix_size = -1; + char *pre = NULL; + jstring str = NULL; + + UNUSED(clss); + + if ((prefix_size = H5Pget_virtual_prefix((hid_t)dapl_id, (char *)NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t) prefix_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_prefix: memory allocation failed"); + + if (H5Pget_virtual_prefix((hid_t)dapl_id, (char *)pre, (size_t) prefix_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + pre[prefix_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_virtual_prefix: out of memory - unable to construct string from UTF characters"); + } + +done: + if (pre) + HDfree(pre); + + return (jstring)str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pDCPLImp.h b/java/src/jni/h5pDCPLImp.h new file mode 100644 index 0000000..6e5c225 --- /dev/null +++ b/java/src/jni/h5pDCPLImp.h @@ -0,0 +1,396 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PDCPL +#define _Included_hdf_hdf5lib_H5_H5PDCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_layout + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1layout +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_layout + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1layout +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk + * Signature: (JI[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk +(JNIEnv *, jclass, jlong, jint, jbyteArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk + * Signature: (JI[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk +(JNIEnv *, jclass, jlong, jint, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_chunk_opts + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_chunk_opts + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_dset_no_attrs_hint + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1dset_1no_1attrs_1hint + (JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_dset_no_attrs_hint + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1dset_1no_1attrs_1hint + (JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_deflate + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1deflate +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fill_value + * Signature: (JJ[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fill_1value +(JNIEnv *, jclass, jlong, jlong, jbyteArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fill_value + * Signature: (JJ[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fill_1value +(JNIEnv *, jclass, jlong, jlong, jbyteArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pfill_value_defined + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fill_time + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fill_1time +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fill_time + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fill_1time +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_alloc_time + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_alloc_time + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_filter + * Signature: (JIIJ[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1filter +(JNIEnv *, jclass, jlong, jint, jint, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pall_filters_avail + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_nfilters + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1nfilters +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter + * Signature: (JI[I[J[IJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter +(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter2 + * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter2 +(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter_by_id + * Signature: (JI[I[J[IJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id +(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_filter_by_id2 + * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 +(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pmodify_filter + * Signature: (JIIJ[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pmodify_1filter +(JNIEnv *, jclass, jlong, jint, jint, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Premove_filter + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5P1remove_1filter +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fletcher32 + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_nbit + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1nbit +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_scaleoffset + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shuffle + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shuffle +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_szip + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1szip +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_external + * Signature: (JLjava/lang/String;JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1external +(JNIEnv *, jclass, jlong, jstring, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_external + * Signature: (JIJ[Ljava/lang/String;[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1external +(JNIEnv *, jclass, jlong, jint, jlong, jobjectArray, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_external_count + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1external_1count +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual + * Signature: (JJLjava/lang/String;Ljava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual +(JNIEnv *, jclass, jlong, jlong, jstring, jstring, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_count + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_dsetname + * Signature: (JJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_filename + * Signature: (JJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_srcspace + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_vspace + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_virtual_prefix + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix +(JNIEnv *, jclass, jlong, jstring); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_virtual_prefix + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix +(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PDCPL */ diff --git a/java/src/jni/h5pDXPLImp.c b/java/src/jni/h5pDXPLImp.c new file mode 100644 index 0000000..2bdc36b --- /dev/null +++ b/java/src/jni/h5pDXPLImp.c @@ -0,0 +1,502 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pDXPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_buffer + * Signature: (JJ[B[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1buffer + (JNIEnv *env, jclass clss, jlong plist, jlong size, jbyteArray tconv, jbyteArray bkg) +{ +#ifdef notdef + jboolean isCopy; + jbyte *tconvP = NULL; + jbyte *bkgP = NULL; +#endif + herr_t status = FAIL; + + UNUSED(clss); +#ifndef notdef + UNUSED(plist); + UNUSED(size); + UNUSED(tconv); + UNUSED(bkg); +#endif + + H5_UNIMPLEMENTED(ENVONLY, "H5Pset_buffer: not implemented"); + + /* NOTE: DON'T IMPLEMENT THIS!!! */ +#ifdef notdef + if (NULL != tconv) + PIN_BYTE_ARRAY(ENVONLY, tconv, tconvP, &isCopy, "H5Pset_buffer: tconv not pinned"); + if (NULL != bkg) + PIN_BYTE_ARRAY(ENVONLY, bkg, bkgP, &isCopy, "H5Pset_buffer: bkg not pinned"); + + if ((status = H5Pset_buffer((hid_t)plist, (size_t)size, tconvP, bkgP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +#endif + +done: +#ifdef notdef + if (bkgP) + UNPIN_BYTE_ARRAY(ENVONLY, bkg, bkgP, (status < 0) ? JNI_ABORT : 0); + if (tconvP) + UNPIN_BYTE_ARRAY(ENVONLY, tconv, tconvP, (status < 0) ? JNI_ABORT : 0); +#endif + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1buffer */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_buffer + * Signature: (J[B[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1buffer + (JNIEnv *env, jclass clss, jlong plist, jbyteArray tconv, jbyteArray bkg) +{ +#ifdef notdef + jboolean isCopy; + jbyte *tconvP = NULL; + jbyte *bkgP = NULL; +#endif + herr_t status = FAIL; + + UNUSED(clss); +#ifndef notdef + UNUSED(plist); + UNUSED(tconv); + UNUSED(bkg); +#endif + + H5_UNIMPLEMENTED(ENVONLY, "H5Pget_buffer: not implemented"); + + /* NOTE: DON'T IMPLEMENT THIS!!! */ +#ifdef notdef + if (NULL == tconv) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_buffer: tconv input array is NULL"); + if (NULL == bkg) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_buffer: bkg array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, tconv, tconvP, &isCopy, "H5Pget_buffer: tconv not pinned"); + PIN_BYTE_ARRAY(ENVONLY, bkg, bkgP, &isCopy, "H5Pget_buffer: bkg not pinned"); + + if ((status = H5Pget_buffer((hid_t)plist, tconvP, bkgP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +#endif + +done: +#ifdef notdef + if (bkgP) + UNPIN_BYTE_ARRAY(ENVONLY, bkg, bkgP, (status < 0) ? JNI_ABORT : 0); + if (tconvP) + UNPIN_BYTE_ARRAY(ENVONLY, tconv, tconvP, (status < 0) ? JNI_ABORT : 0); +#endif + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1buffer */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_buffer_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size + (JNIEnv *env, jclass clss, jlong plist, jlong size) +{ + UNUSED(clss); + + if (H5Pset_buffer((hid_t)plist, (size_t)size, NULL, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_buffer_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size + (JNIEnv *env, jclass clss, jlong plist) +{ + size_t size = 0; + + UNUSED(clss); + + if (!(size = H5Pget_buffer((hid_t)plist, NULL, NULL))) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_preserve + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1preserve + (JNIEnv *env, jclass clss, jlong plist, jboolean status) +{ + hbool_t st = JNI_FALSE; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (JNI_TRUE == status) + st = TRUE; + else if (JNI_FALSE == status) + st = false; + else + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_preserve: status not TRUE or FALSE"); + + if ((retVal = H5Pset_preserve((hid_t)plist, st)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1preserve */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_preserve + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1preserve + (JNIEnv *env, jclass clss, jlong plist) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pget_preserve((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1preserve */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_edc_check + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1edc_1check + (JNIEnv *env, jclass clss, jlong plist, jint check) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_edc_check((hid_t)plist, (H5Z_EDC_t)check)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1edc_1check */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_edc_check + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1edc_1check + (JNIEnv *env, jclass clss, jlong plist) +{ + H5Z_EDC_t retVal = -1; + + UNUSED(clss); + + if ((retVal = H5Pget_edc_check((hid_t)plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1edc_1check */ + +/* + * TODO: H5Pset_filter_callback + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_data_transform + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1data_1transform + (JNIEnv *env, jclass clss, jlong plist_id, jstring expression) +{ + const char *express = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, expression, express, NULL, "H5Pset_data_transform: data transform expression not pinned"); + + if ((retVal = H5Pset_data_transform((hid_t)plist_id, express)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (express) + UNPIN_JAVA_STRING(ENVONLY, expression, express); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1data_1transform */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_data_transform + * Signature: (J[Ljava/lang/String;J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1data_1transform + (JNIEnv *env, jclass clss, jlong plist_id, jobjectArray expression, jlong size) +{ + jstring str = NULL; + char *express = NULL; + ssize_t express_size = -1; + + UNUSED(clss); + + if (size <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_data_transform: size <= 0"); + + if ((express_size = H5Pget_data_transform((hid_t)plist_id, (char *)NULL, (size_t)size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (express = (char *) HDmalloc(sizeof(char) * (size_t)express_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_data_transform: memory allocation failed"); + + if (H5Pget_data_transform((hid_t)plist_id, express, (size_t)express_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + express[express_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, express))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_data_transform: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, expression, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (express) + HDfree(express); + + return (jlong)express_size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1data_1transform */ + +/* + * TODO: H5Pset_type_conv_cb + */ + +/* + * TODO: H5Pget_type_conv_cb + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_hyper_vector_size + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size + (JNIEnv *env, jclass clss, jlong plist, jlong vector_size) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_hyper_vector_size((hid_t)plist, (size_t)vector_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_hyper_vector_size + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size + (JNIEnv *env, jclass clss, jlong plist, jlongArray vector_size) +{ + jboolean isCopy; + size_t size; + jlong *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == vector_size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_hyper_vector_size: vector_size is NULL"); + + PIN_LONG_ARRAY(ENVONLY, vector_size, theArray, &isCopy, "H5Pget_hyper_vector_size: vector_size not pinned"); + + if ((retVal = H5Pget_hyper_vector_size((hid_t)plist, &size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jlong)size; + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, vector_size, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_btree_ratios + * Signature: (JDDD)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios + (JNIEnv *env, jclass clss, jlong plist_id, jdouble left, jdouble middle, jdouble right) +{ + herr_t status = FAIL; + + UNUSED(clss); + + if ((status = H5Pset_btree_ratios((hid_t)plist_id, (double)left,(double)middle, (double)right)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_btree_ratios + * Signature: (J[D[D[D)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios + (JNIEnv *env, jclass clss, jlong plist_id, jdoubleArray left, + jdoubleArray middle, jdoubleArray right) +{ + jboolean isCopy; + jdouble *leftP = NULL; + jdouble *middleP = NULL; + jdouble *rightP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == left) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_btree_ratios: left input array is NULL"); + if (NULL == middle) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_btree_ratios: middle input array is NULL"); + if (NULL == right) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_btree_ratios: right input array is NULL"); + + PIN_DOUBLE_ARRAY(ENVONLY, left, leftP, &isCopy, "H5Pget_btree_ratios: left array not pinned"); + PIN_DOUBLE_ARRAY(ENVONLY, middle, middleP, &isCopy, "H5Pget_btree_ratios: middle array not pinned"); + PIN_DOUBLE_ARRAY(ENVONLY, right, rightP, &isCopy, "H5Pget_btree_ratios: right array not pinned"); + + if ((status = H5Pget_btree_ratios((hid_t)plist_id, (double *)leftP, + (double *)middleP, (double *)rightP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (rightP) + UNPIN_DOUBLE_ARRAY(ENVONLY, right, rightP, (status < 0) ? JNI_ABORT : 0); + if (middleP) + UNPIN_DOUBLE_ARRAY(ENVONLY, middle, middleP, (status < 0) ? JNI_ABORT : 0); + if (leftP) + UNPIN_DOUBLE_ARRAY(ENVONLY, left, leftP, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios */ + +/* + * TODO: H5Pset_vlen_mem_manager + */ + +/* + * TODO: H5Pget_vlen_mem_manager + */ + +/* + * TODO: H5Pset_dxpl_mpio + */ + +/* + * TODO: H5Pget_dxpl_mpio + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt_num + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt_ratio + */ + +/* + * TODO: H5Pset_dxpl_mpio_collective_opt + */ + +/* + * TODO: H5Pget_mpio_actual_chunk_opt_mode + */ + +/* + * TODO: H5Pget_mpio_actual_io_mode + */ + +/* + * TODO: H5Pget_mpio_no_collective_cause + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pDXPLImp.h b/java/src/jni/h5pDXPLImp.h new file mode 100644 index 0000000..d62f9c5 --- /dev/null +++ b/java/src/jni/h5pDXPLImp.h @@ -0,0 +1,209 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PDXPL +#define _Included_hdf_hdf5lib_H5_H5PDXPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_buffer + * Signature: (JJ[B[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1buffer +(JNIEnv *, jclass, jlong, jlong, jbyteArray, jbyteArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_buffer + * Signature: (J[B[B)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1buffer +(JNIEnv *, jclass, jlong, jbyteArray, jbyteArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_buffer_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_buffer_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_preserve + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1preserve +(JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_preserve + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1preserve +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_edc_check + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1edc_1check +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_edc_check + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1edc_1check +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pset_filter_callback + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_data_transform + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1data_1transform +(JNIEnv *, jclass, jlong, jstring); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_data_transform + * Signature: (J[Ljava/lang/String;J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1data_1transform +(JNIEnv *, jclass, jlong, jobjectArray, jlong); + +/* + * TODO: H5Pset_type_conv_cb + */ + +/* + * TODO: H5Pget_type_conv_cb + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_hyper_vector_size + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_hyper_vector_size + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size +(JNIEnv *, jclass, jlong, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_btree_ratios + * Signature: (JDDD)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios +(JNIEnv *, jclass, jlong, jdouble, jdouble, jdouble); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_btree_ratios + * Signature: (J[D[D[D)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios +(JNIEnv *, jclass, jlong, jdoubleArray, jdoubleArray, jdoubleArray); + +/* + * TODO: H5Pset_vlen_mem_manager + */ + +/* + * TODO: H5Pget_vlen_mem_manager + */ + +/* + * TODO: H5Pset_dxpl_mpio + */ + +/* + * TODO: H5Pget_dxpl_mpio + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt_num + */ + +/* + * TODO: H5Pset_dxpl_mpio_chunk_opt_ratio + */ + +/* + * TODO: H5Pset_dxpl_mpio_collective_opt + */ + +/* + * TODO: H5Pget_mpio_actual_chunk_opt_mode + */ + +/* + * TODO: H5Pget_mpio_actual_io_mode + */ + +/* + * TODO: H5Pget_mpio_no_collective_cause + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PDXPL */ diff --git a/java/src/jni/h5pFAPLImp.c b/java/src/jni/h5pFAPLImp.c new file mode 100644 index 0000000..aec6581 --- /dev/null +++ b/java/src/jni/h5pFAPLImp.c @@ -0,0 +1,1624 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5util.h" +#include "h5pFAPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * TODO: H5Pset_driver + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_driver + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1driver + (JNIEnv *env, jclass clss, jlong plist) +{ + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if ((retVal = H5Pget_driver((hid_t) plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1driver */ + +/* + * TODO: H5Pget_driver_info + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fclose_degree + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree + (JNIEnv *env, jclass clss, jlong plist, jint fc_degree) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fclose_degree((hid_t)plist, (H5F_close_degree_t)fc_degree)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fclose_degree + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree + (JNIEnv *env, jclass clss, jlong plist) +{ + H5F_close_degree_t degree = H5F_CLOSE_DEFAULT; + + UNUSED(clss); + + if (H5Pget_fclose_degree((hid_t)plist, °ree) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)degree; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_core + * Signature: (JJZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core + (JNIEnv *env, jclass clss, jlong fapl_id, jlong increment, jboolean backing_store) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fapl_core((hid_t)fapl_id, (size_t)increment, (hbool_t)backing_store)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_core + * Signature: (J[J[Z)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core + (JNIEnv *env, jclass clss, jlong fapl_id, jlongArray increment, jbooleanArray backing_store) +{ + jboolean isCopy; + jboolean *backArray = NULL; + jlong *incArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == increment) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_fapl_core: increment is NULL"); + if (NULL == backing_store) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_fapl_core: backing_store is NULL"); + + PIN_LONG_ARRAY(ENVONLY, increment, incArray, &isCopy, "H5Pget_fapl_core: incArray not pinned"); + PIN_BOOL_ARRAY(ENVONLY, backing_store, backArray, &isCopy, "H5Pget_fapl_core: backArray not pinned"); + + { + /* Direct cast (size_t *)variable fails on 32-bit environment */ + long long inc_temp = *incArray; + size_t inc_t = (size_t) inc_temp; + + if ((status = H5Pget_fapl_core((hid_t)fapl_id, &inc_t, (hbool_t *)backArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + *incArray = (jlong)inc_t; + } + +done: + if (backArray) + UNPIN_BOOL_ARRAY(ENVONLY, backing_store, backArray, (status < 0) ? JNI_ABORT : 0); + if (incArray) + UNPIN_LONG_ARRAY(ENVONLY, increment, incArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core */ + +/* + * TODO: H5Pset_core_write_tracking + */ + +/* + * TODO: H5Pget_core_write_tracking + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_direct + * Signature: (JJJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct + (JNIEnv *env, jclass clss, jlong fapl_id, jlong alignment, + jlong block_size, jlong cbuf_size) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + +#ifdef H5_HAVE_DIRECT + if ((retVal = H5Pset_fapl_direct((hid_t)fapl_id, (size_t)alignment, (size_t)block_size, (size_t)cbuf_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: +#else + UNUSED(env); + UNUSED(fapl_id); + UNUSED(alignment); + UNUSED(block_size); + UNUSED(cbuf_size); +#endif + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_direct + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct + (JNIEnv *env, jclass clss, jlong fapl_id, jlongArray info) +{ +#ifdef H5_HAVE_DIRECT + jboolean isCopy; + jlong *theArray = NULL; + size_t alignment = 0; + size_t block_size = 0; + size_t cbuf_size = 0; + jsize arrLen; +#endif + herr_t retVal = FAIL; + + UNUSED(clss); + +#ifdef H5_HAVE_DIRECT + if (NULL == info) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_fapl_direct: info input array is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, info)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_fapl_direct: info array length < 0"); + } + if (arrLen < 3) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_fapl_direct: info input array < 3"); + + PIN_LONG_ARRAY(ENVONLY, info, theArray, &isCopy, "H5Pget_fapl_direct: info not pinned"); + + if ((retVal = H5Pget_fapl_direct((hid_t)fapl_id, &alignment, &block_size, &cbuf_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jlong)alignment; + theArray[1] = (jlong)block_size; + theArray[2] = (jlong)cbuf_size; + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, info, theArray, (retVal < 0) ? JNI_ABORT : 0); +#else + UNUSED(env); + UNUSED(fapl_id); + UNUSED(info); +#endif + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_family + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family + (JNIEnv *env, jclass clss, jlong plist, jlong memb_size, jlong memb_plist) +{ + long ms = (long)memb_size; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fapl_family((hid_t)plist, (hsize_t)ms, (hid_t)memb_plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_family + * Signature: (J[J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family + (JNIEnv *env, jclass clss, jlong tid, jlongArray memb_size, jlongArray memb_plist) +{ + jboolean isCopy; + hsize_t *sa = NULL; + size_t i; + jlong *sizeArray = NULL; + jlong *plistArray = NULL; + jsize rank; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == memb_size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_family: memb_size is NULL"); + if (NULL == memb_plist) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_family: memb_plist is NULL"); + + PIN_LONG_ARRAY(ENVONLY, memb_size, sizeArray, &isCopy, "H5Pget_family: sizeArray not pinned"); + + if ((rank = ENVPTR->GetArrayLength(ENVONLY, memb_size)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_family: memb_size array length < 0"); + } + + if (NULL == (sa = (hsize_t *) HDmalloc((size_t) rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_family: memory allocation failed"); + + PIN_LONG_ARRAY(ENVONLY, memb_plist, plistArray, &isCopy, "H5Pget_family: plistArray not pinned"); + + if ((status = H5Pget_fapl_family((hid_t)tid, sa, (hid_t *)plistArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (size_t) rank; i++) + sizeArray[i] = (jlong)sa[i]; + +done: + if (plistArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_plist, plistArray, (status < 0) ? JNI_ABORT : 0); + if (sa) + HDfree(sa); + if (sizeArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_size, sizeArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_family_offset + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1family_1offset + (JNIEnv *env, jclass clss, jlong fapl_id, jlong offset) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_family_offset((hid_t)fapl_id, (hsize_t)offset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1family_1offset */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_family_offset + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1family_1offset + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + hsize_t offset = 0; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pget_family_offset((hid_t)fapl_id, &offset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)offset; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1family_1offset */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_log + * Signature: (JLjava/lang/String;JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log + (JNIEnv *env, jclass clss, jlong fapl_id, jstring logfile, jlong flags, jlong buf_size) +{ + const char *pLogfile = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, logfile, pLogfile, NULL, "H5Pset_fapl_log: log file name not pinned"); + + if ((retVal = H5Pset_fapl_log((hid_t)fapl_id, pLogfile, (unsigned long long)flags, (size_t)buf_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (pLogfile) + UNPIN_JAVA_STRING(ENVONLY, logfile, pLogfile); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log */ + +/* + * TODO: H5Pset_fapl_mpio + */ + +/* + * TODO: H5Pget_fapl_mpio + */ + +/* + * TODO: H5Pset_fapl_mpiposix + */ + +/* + * TODO: H5Pget_fapl_mpiposix + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_multi + * Signature: (J[I[J[Ljava/lang/String;[JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1multi + (JNIEnv *env, jclass clss, jlong tid, jintArray memb_map, + jlongArray memb_fapl, jobjectArray memb_name, jlongArray memb_addr, jboolean relax) +{ + const char * const *mName = NULL; + jboolean isCopy; + jboolean bb; + jobject o; + jstring rstring; + jclass Sjc; + size_t i; + jlong *thefaplArray = NULL; + jlong *theaddrArray = NULL; + jint *themapArray = NULL; + char *member_name[H5FD_MEM_NTYPES]; + herr_t status = FAIL; + + UNUSED(clss); + + HDmemset(member_name, 0, H5FD_MEM_NTYPES * sizeof(char *)); + + if (memb_map) + PIN_INT_ARRAY(ENVONLY, memb_map, themapArray, &isCopy, "H5Pset_fapl_multi: memb_map not pinned"); + if (memb_fapl) + PIN_LONG_ARRAY(ENVONLY, memb_fapl, thefaplArray, &isCopy, "H5Pset_fapl_multi: memb_fapl not pinned"); + if (memb_addr) + PIN_LONG_ARRAY(ENVONLY, memb_addr, theaddrArray, &isCopy, "H5Pset_fapl_multi: memb_addr not pinned"); + + if (memb_name) { + jstring obj; + + for (i = 0; i < H5FD_MEM_NTYPES; i++) { + const char *utf8 = NULL; + size_t str_len; + + if (NULL == (obj = (jstring) ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray) memb_name, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + member_name[i] = NULL; + continue; + } + + /* + * length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + */ + + PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5Pset_fapl_multi: string not pinned"); + + str_len = HDstrlen(utf8); + + if (NULL == (member_name[i] = (char *) HDmalloc(str_len + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pset_fapl_multi: memory allocation failed"); + + HDstrncpy(member_name[i], utf8, str_len + 1); + + UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + utf8 = NULL; + + ENVPTR->DeleteLocalRef(ENVONLY, obj); + } + + mName = (const char * const *)member_name; + } + + if ((status = H5Pset_fapl_multi((hid_t)tid, (const H5FD_mem_t *)themapArray, (const hid_t *)thefaplArray, + mName, (const haddr_t *)theaddrArray, (hbool_t)relax)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (memb_name && mName) { + if (NULL == (Sjc = ENVPTR->FindClass(ENVONLY, "java/lang/String"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + for (i = 0; i < H5FD_MEM_NTYPES; i++) { + if (NULL == (rstring = ENVPTR->NewStringUTF(ENVONLY, member_name[i]))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pset_fapl_multi: out of memory - unable to construct string from UTF characters"); + } + + if (NULL == (o = ENVPTR->GetObjectArrayElement(ENVONLY, memb_name, (jsize) i))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* + * If the string object was NULL, skip it. + */ + ENVPTR->DeleteLocalRef(ENVONLY, rstring); + continue; + } + + if (JNI_TRUE == (bb = ENVPTR->IsInstanceOf(ENVONLY, o, Sjc))) { + ENVPTR->SetObjectArrayElement(ENVONLY, memb_name, (jsize) i, (jobject)rstring); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + + ENVPTR->DeleteLocalRef(ENVONLY, o); + ENVPTR->DeleteLocalRef(ENVONLY, rstring); + + HDfree(member_name[i]); + member_name[i] = NULL; + } + } + +done: + h5str_array_free(member_name, H5FD_MEM_NTYPES); + if (theaddrArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_addr, theaddrArray, (status < 0) ? JNI_ABORT : 0); + if (thefaplArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_fapl, thefaplArray, (status < 0) ? JNI_ABORT : 0); + if (themapArray) + UNPIN_INT_ARRAY(ENVONLY, memb_map, themapArray, (status < 0) ? JNI_ABORT : 0); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1multi */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_multi + * Signature: (J[I[J[Ljava/lang/String;[J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1multi + (JNIEnv *env, jclass clss, jlong tid, jintArray memb_map, + jlongArray memb_fapl, jobjectArray memb_name, jlongArray memb_addr) +{ + jboolean isCopy; + jstring str; + herr_t status = FAIL; + size_t i; + jlong *thefaplArray = NULL; + jlong *theaddrArray = NULL; + jint *themapArray = NULL; + char **mName = NULL; + int relax = 0; + int retVal = 0; + + UNUSED(clss); + + if (memb_map) + PIN_INT_ARRAY(ENVONLY, memb_map, themapArray, &isCopy, "H5Pget_fapl_multi: memb_map not pinned"); + if (memb_fapl) + PIN_LONG_ARRAY(ENVONLY, memb_fapl, thefaplArray, &isCopy, "H5Pget_fapl_multi: memb_fapl not pinned"); + if (memb_addr) + PIN_LONG_ARRAY(ENVONLY, memb_addr, theaddrArray, &isCopy, "H5Pget_fapl_multi: memb_addr not pinned"); + if (memb_name) + if (NULL == (mName = (char **) HDcalloc(H5FD_MEM_NTYPES, sizeof(*mName)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_fapl_multi: memory allocation failed"); + + if ((status = H5Pget_fapl_multi((hid_t)tid, (H5FD_mem_t *)themapArray, (hid_t *)thefaplArray, + mName, (haddr_t *)theaddrArray, (hbool_t *)&relax)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (memb_name && mName) { + for (i = 0; i < H5FD_MEM_NTYPES; i++) { + if (mName[i]) { + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, mName[i]))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_fapl_multi: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, memb_name, (jsize) i, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, str); + } + } + } + + retVal = (relax != 0); + +done: + h5str_array_free(mName, H5FD_MEM_NTYPES); + if (theaddrArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_addr, theaddrArray, (status < 0) ? JNI_ABORT : 0); + if (thefaplArray) + UNPIN_LONG_ARRAY(ENVONLY, memb_fapl, thefaplArray, (status < 0) ? JNI_ABORT : 0); + if (themapArray) + UNPIN_INT_ARRAY(ENVONLY, memb_map, themapArray, (status < 0) ? JNI_ABORT : 0); + + return (jboolean)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1multi */ + +/* + * TODO: H5Pset_multi_type + */ + +/* + * TODO: H5Pget_multi_type + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_split + * Signature: (JLjava/lang/String;JLjava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split + (JNIEnv *env, jclass clss, jlong fapl_id, jstring metaext, jlong meta_pl_id, jstring rawext, jlong raw_pl_id) +{ + const char *mstr = NULL; + const char *rstr = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, metaext, mstr, NULL, "H5Pset_fapl_split: metaext not pinned"); + PIN_JAVA_STRING(ENVONLY, rawext, rstr, NULL, "H5Pset_fapl_split: rawext not pinned"); + + if ((retVal = H5Pset_fapl_split((hid_t)fapl_id, mstr, (hid_t)meta_pl_id, rstr, (hid_t)raw_pl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (rstr) + UNPIN_JAVA_STRING(ENVONLY, rawext, rstr); + if (mstr) + UNPIN_JAVA_STRING(ENVONLY, metaext, mstr); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_sec2 + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fapl_sec2((hid_t) fapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_stdio + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_fapl_stdio((hid_t) fapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_windows + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + +#ifdef H5_HAVE_WINDOWS + if ((retVal = H5Pset_fapl_windows((hid_t) fapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: +#else + UNUSED(env); + UNUSED(fapl_id); +#endif + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows */ + +/* + * TODO: H5Pset_file_image + */ + +/* + * TODO: H5Pget_file_image + */ + +/* + * TODO: H5Pset_file_image_callbacks + */ + +/* + * TODO: H5Pget_file_image_callbacks + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_meta_block_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size + (JNIEnv *env, jclass clss, jlong plist, jlong size) +{ + long sz = (long)size; + + UNUSED(clss); + + if (H5Pset_meta_block_size((hid_t)plist, (hsize_t)sz) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_meta_block_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size + (JNIEnv *env, jclass clss, jlong plist) +{ + hsize_t s = 0; + + UNUSED(clss); + + if (H5Pget_meta_block_size((hid_t)plist, &s) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)s; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size */ + +/* + * TODO: H5Pset_page_buffer_size + */ + +/* + * TODO: H5Pget_page_buffer_size + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sieve_buf_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size + (JNIEnv *env, jclass clss, jlong plist, jlong size) +{ + size_t sz = (size_t)size; + + UNUSED(clss); + + if (H5Pset_sieve_buf_size((hid_t)plist, (size_t)sz) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sieve_buf_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size + (JNIEnv *env, jclass clss, jlong plist) +{ + size_t s = 0; + + UNUSED(clss); + + if (H5Pget_sieve_buf_size((hid_t)plist, &s) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)s; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_alignment + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1alignment + (JNIEnv *env, jclass clss, jlong plist, jlong threshold, jlong alignment) +{ + long thr = (long)threshold; + long align = (long)alignment; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_alignment((hid_t)plist, (hsize_t)thr, (hsize_t)align)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1alignment */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_alignment + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1alignment + (JNIEnv *env, jclass clss, jlong plist, jlongArray alignment) +{ + jboolean isCopy; + hsize_t t = 0; + hsize_t a = 0; + jsize arrLen; + jlong *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == alignment) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_alignment: input alignment is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, alignment)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_alignment: alignment array length < 0"); + } + if (arrLen < 2) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_alignment: alignment input array < 2"); + + PIN_LONG_ARRAY(ENVONLY, alignment, theArray, &isCopy, "H5Pget_alignment: input array not pinned"); + + if ((status = H5Pget_alignment((hid_t)plist, &t, &a)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jlong)t; + theArray[1] = (jlong)a; + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, alignment, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1alignment */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_cache + * Signature: (JIJJD)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1cache + (JNIEnv *env, jclass clss, jlong plist, jint mdc_nelmts, jlong rdcc_nelmts, + jlong rdcc_nbytes, jdouble rdcc_w0) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_cache((hid_t)plist, (int)mdc_nelmts, (size_t)rdcc_nelmts, + (size_t)rdcc_nbytes, (double) rdcc_w0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1cache */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_cache + * Signature: (J[I[J[J[D)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1cache + (JNIEnv *env, jclass clss, jlong plist, jintArray mdc_nelmts, + jlongArray rdcc_nelmts, jlongArray rdcc_nbytes, jdoubleArray rdcc_w0) +{ + jboolean isCopy; + jdouble *w0Array = NULL; + jlong *rdcc_nelmtsArray = NULL; + jlong *nbytesArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + UNUSED(mdc_nelmts); + + if (NULL != rdcc_w0) + PIN_DOUBLE_ARRAY(ENVONLY, rdcc_w0, w0Array, &isCopy, "H5Pget_cache: rdcc_w0 array not pinned"); + if (NULL != rdcc_nelmts) + PIN_LONG_ARRAY(ENVONLY, rdcc_nelmts, rdcc_nelmtsArray, &isCopy, "H5Pget_cache: rdcc_nelmts array not pinned"); + if (NULL != rdcc_nbytes) + PIN_LONG_ARRAY(ENVONLY, rdcc_nbytes, nbytesArray, &isCopy, "H5Pget_cache: nbytesArray array not pinned"); + + { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long rdcc_nelmts_temp = *rdcc_nelmtsArray; + long long nbytes_temp = *nbytesArray; + size_t rdcc_nelmts_t = (size_t) rdcc_nelmts_temp; + size_t nbytes_t = (size_t) nbytes_temp; + + if ((status = H5Pget_cache((hid_t)plist, (int *)NULL, &rdcc_nelmts_t, + &nbytes_t, (double *)w0Array)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + *rdcc_nelmtsArray = (jlong)rdcc_nelmts_t; + *nbytesArray = (jlong)nbytes_t; + } /* end direct cast special */ + +done: + if (nbytesArray) + UNPIN_LONG_ARRAY(ENVONLY, rdcc_nbytes, nbytesArray, (status < 0) ? JNI_ABORT : 0); + if (rdcc_nelmtsArray) + UNPIN_LONG_ARRAY(ENVONLY, rdcc_nelmts, rdcc_nelmtsArray, (status < 0) ? JNI_ABORT : 0); + if (w0Array) + UNPIN_DOUBLE_ARRAY(ENVONLY, rdcc_w0, w0Array, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1cache */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_file_cache_size + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size + (JNIEnv *env, jclass clss, jlong plist, jint size) +{ + unsigned sz = (unsigned)size; + + UNUSED(clss); + + if (H5Pset_elink_file_cache_size((hid_t)plist, (unsigned)sz) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_file_cache_size + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size + (JNIEnv *env, jclass clss, jlong plist) +{ + unsigned s = 0; + + UNUSED(clss); + + if (H5Pget_elink_file_cache_size((hid_t)plist, &s) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)s; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_evict_on_close + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close + (JNIEnv *env, jclass clss, jlong fapl_id, jboolean evict_on_close) +{ + hbool_t evict_on_close_val = FALSE; + herr_t retVal = FAIL; + + UNUSED(clss); + + evict_on_close_val = (evict_on_close == JNI_TRUE) ? TRUE : FALSE; + + if ((retVal = H5Pset_evict_on_close((hid_t)fapl_id, (hbool_t)evict_on_close_val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_evict_on_close + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + hbool_t evict_on_close_val = FALSE; + jboolean bval = JNI_FALSE; + + UNUSED(clss); + + if (H5Pget_evict_on_close((hid_t)fapl_id, (hbool_t *)&evict_on_close_val) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (evict_on_close_val == TRUE) ? JNI_TRUE : JNI_FALSE; + +done: + return bval; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_metadata_read_attempts + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts + (JNIEnv *env, jclass clss, jlong plist_id, jlong attempts) +{ + UNUSED(clss); + + if (attempts <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_metadata_read_attempts: attempts <= 0"); + + if (H5Pset_metadata_read_attempts((hid_t)plist_id, (unsigned)attempts) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_metadata_read_attempts + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts + (JNIEnv *env, jclass clss, jlong plist_id) +{ + unsigned attempts = 0; + + UNUSED(clss); + + if (H5Pget_metadata_read_attempts((hid_t)plist_id, &attempts) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong) attempts; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_mdc_config + * Signature: (JLhdf/hdf5lib/structs/H5AC_cache_config_t;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config + (JNIEnv *env, jclass clss, jlong plist, jobject cache_config) +{ + H5AC_cache_config_t cacheinfo; + const char *str = NULL; + jfieldID fid; + jstring j_str; + jclass cls; + jint flash_incr_mode; + jint incr_mode; + jint decr_mode; + herr_t status = FAIL; + + UNUSED(clss); + + HDmemset(&cacheinfo, 0, sizeof(H5AC_cache_config_t)); + + if (NULL == (cls = ENVPTR->GetObjectClass(ENVONLY, cache_config))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "version", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.version = ENVPTR->GetIntField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "rpt_fcn_enabled", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.rpt_fcn_enabled = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "open_trace_file", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.open_trace_file = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "close_trace_file", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.close_trace_file = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "trace_file_name", "Ljava/lang/String;"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (j_str = (jstring)ENVPTR->GetObjectField(ENVONLY, cache_config, fid))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_JAVA_STRING(ENVONLY, j_str, str, NULL, "H5Pset_mdc_config: cache_config not pinned"); + + HDstrncpy(cacheinfo.trace_file_name, str, H5AC__MAX_TRACE_FILE_NAME_LEN + 1); + + UNPIN_JAVA_STRING(ENVONLY, j_str, str); + str = NULL; + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "evictions_enabled", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.evictions_enabled = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "set_initial_size", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.set_initial_size = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "initial_size", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.initial_size = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "min_clean_fraction", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.min_clean_fraction = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "max_size", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.max_size = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "min_size", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.min_size = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "epoch_length", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.epoch_length = (long int)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "incr_mode", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + incr_mode = ENVPTR->GetIntField(ENVONLY, cache_config, fid); /*(enum H5C_cache_incr_mode) */ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + cacheinfo.incr_mode = (enum H5C_cache_incr_mode) incr_mode; + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "lower_hr_threshold", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.lower_hr_threshold = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "increment", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.increment = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "apply_max_increment", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.apply_max_increment = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "max_increment", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.max_increment = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "flash_incr_mode", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + flash_incr_mode = ENVPTR->GetIntField(ENVONLY, cache_config, fid); /*(enum H5C_cache_flash_incr_mode) */ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + cacheinfo.flash_incr_mode = (enum H5C_cache_flash_incr_mode) flash_incr_mode; + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "flash_multiple", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.flash_multiple = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "flash_threshold", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.flash_threshold = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "decr_mode", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + decr_mode = ENVPTR->GetIntField(ENVONLY, cache_config, fid); /*(enum H5C_cache_decr_mode) */ + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + cacheinfo.decr_mode = (enum H5C_cache_decr_mode) decr_mode; + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "upper_hr_threshold", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.upper_hr_threshold = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "decrement", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.decrement = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "apply_max_decrement", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.apply_max_decrement = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "max_decrement", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.max_decrement = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "epochs_before_eviction", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.epochs_before_eviction = ENVPTR->GetIntField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "apply_empty_reserve", "Z"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.apply_empty_reserve = ENVPTR->GetBooleanField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "empty_reserve", "D"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.empty_reserve = ENVPTR->GetDoubleField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "dirty_bytes_threshold", "J"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.dirty_bytes_threshold = (size_t)ENVPTR->GetLongField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (fid = ENVPTR->GetFieldID(ENVONLY, cls, "metadata_write_strategy", "I"))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cacheinfo.metadata_write_strategy = ENVPTR->GetIntField(ENVONLY, cache_config, fid); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if ((status = H5Pset_mdc_config((hid_t)plist, &cacheinfo)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (str) + UNPIN_JAVA_STRING(ENVONLY, j_str, str); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_mdc_config + * Signature: (J)Lhdf/hdf5lib/structs/H5AC_cache_config_t; + */ +JNIEXPORT jobject JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config + (JNIEnv *env, jclass clss, jlong plist) +{ + H5AC_cache_config_t cacheinfo; + jstring j_str = NULL; + jvalue args[30]; + herr_t status = FAIL; + jobject ret_obj = NULL; + + UNUSED(clss); + + HDmemset(&cacheinfo, 0, sizeof(H5AC_cache_config_t)); + cacheinfo.version = H5AC__CURR_CACHE_CONFIG_VERSION; + + if ((status = H5Pget_mdc_config((hid_t)plist, &cacheinfo)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + args[0].i = cacheinfo.version; + args[1].z = cacheinfo.rpt_fcn_enabled; + args[2].z = cacheinfo.open_trace_file; + args[3].z = cacheinfo.close_trace_file; + + if (NULL != cacheinfo.trace_file_name) { + if (NULL == (j_str = ENVPTR->NewStringUTF(ENVONLY, cacheinfo.trace_file_name))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_mdc_config: out of memory - unable to construct string from UTF characters"); + } + } + + args[4].l = j_str; + args[5].z = cacheinfo.evictions_enabled; + args[6].z = cacheinfo.set_initial_size; + args[7].j = (jlong)cacheinfo.initial_size; + args[8].d = cacheinfo.min_clean_fraction; + args[9].j = (jlong)cacheinfo.max_size; + args[10].j = (jlong)cacheinfo.min_size; + args[11].j = cacheinfo.epoch_length; + args[12].i = cacheinfo.incr_mode; + args[13].d = cacheinfo.lower_hr_threshold; + args[14].d = cacheinfo.increment; + args[15].z = cacheinfo.apply_max_increment; + args[16].j = (jlong)cacheinfo.max_increment; + args[17].i = cacheinfo.flash_incr_mode; + args[18].d = cacheinfo.flash_multiple; + args[19].d = cacheinfo.flash_threshold; + args[20].i = cacheinfo.decr_mode; + args[21].d = cacheinfo.upper_hr_threshold; + args[22].d = cacheinfo.decrement; + args[23].z = cacheinfo.apply_max_decrement; + args[24].j = (jlong)cacheinfo.max_decrement; + args[25].i = cacheinfo.epochs_before_eviction; + args[26].z = cacheinfo.apply_empty_reserve; + args[27].d = cacheinfo.empty_reserve; + args[28].j = (jlong)cacheinfo.dirty_bytes_threshold; + args[29].i = cacheinfo.metadata_write_strategy; + + CALL_CONSTRUCTOR(ENVONLY, "hdf/hdf5lib/structs/H5AC_cache_config_t", "(IZZZLjava/lang/String;ZZJDJJJIDDZJIDDIDDZJIZDJI)V", args, ret_obj); + +done: + return ret_obj; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config */ + +/* + * TODO: H5Pset_mdc_image_config + */ + +/* + * TODO: H5Pget_mdc_image_config + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_mdc_log_options + * Signature: (JZLjava/lang/String;Z)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options + (JNIEnv *env, jclass clss, jlong fapl_id, jboolean is_enabled, jstring location, jboolean start_on_access) +{ + const char *locStr = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, location, locStr, NULL, "H5Pset_mdc_log_options: location string not pinned"); + + if ((retVal = H5Pset_mdc_log_options((hid_t)fapl_id, (hbool_t)is_enabled, locStr, (hbool_t)start_on_access)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (locStr) + UNPIN_JAVA_STRING(ENVONLY, location, locStr); +} /* end Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_mdc_log_options + * Signature: (J[Z)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1mdc_1log_1options + (JNIEnv *env, jclass clss, jlong fapl_id, jbooleanArray mdc_log_options) +{ + jboolean isCopy; + jboolean *mdc_log_options_ptr = NULL; + hbool_t is_enabled; + hbool_t start_on_access; + ssize_t status = -1; + size_t location_size; + jsize arrLen; + char *lname = NULL; + jstring str = NULL; + + UNUSED(clss); + + if (NULL == mdc_log_options) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_mdc_log_options: mdc_log_options is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, mdc_log_options)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_mdc_log_options: mdc_log_options array length < 0"); + } + if (arrLen < 2) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_mdc_log_options: length of mdc_log_options < 2"); + + PIN_BOOL_ARRAY(ENVONLY, mdc_log_options, mdc_log_options_ptr, &isCopy, "H5Pget_mdc_log_options: mdc_log_options array not pinned"); + + /* get the length of the filename */ + if (H5Pget_mdc_log_options((hid_t)fapl_id, &is_enabled, NULL, &location_size, &start_on_access) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!location_size) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_mdc_log_options: location_size is 0"); + + location_size++; /* add extra space for the null terminator */ + if (NULL == (lname = (char *) HDmalloc(sizeof(char) * location_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_mdc_log_options: memory allocation failed"); + + if ((status = H5Pget_mdc_log_options((hid_t)fapl_id, &is_enabled, lname, &location_size, &start_on_access)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + lname[location_size - 1] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, lname))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_mdc_log_options: out of memory - unable to construct string from UTF characters"); + } + + mdc_log_options_ptr[0] = (jboolean)is_enabled; + mdc_log_options_ptr[1] = (jboolean)start_on_access; + +done: + if (lname) + HDfree(lname); + if (mdc_log_options_ptr) + UNPIN_BOOL_ARRAY(ENVONLY, mdc_log_options, mdc_log_options_ptr, (status < 0) ? JNI_ABORT : 0); + + return (jstring)str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1mdc_1log_1options */ + +/* + * TODO: H5Pset_all_coll_metadata_ops + */ + +/* + * TODO: H5Pget_all_coll_metadata_ops + */ + +/* + * TODO: H5Pset_coll_metadata_write + */ + +/* + * TODO: H5Pget_coll_metadata_write + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_gc_references + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1gc_1references + (JNIEnv *env, jclass clss, jlong fapl_id, jboolean gc_ref) +{ + unsigned gc_ref_val = 0; + herr_t retVal = FAIL; + + UNUSED(clss); + + gc_ref_val = (gc_ref == JNI_TRUE) ? 1 : 0; + + if ((retVal = H5Pset_gc_references((hid_t)fapl_id, gc_ref_val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1gc_1references */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_gc_references + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1gc_1references + (JNIEnv *env, jclass clss, jlong fapl_id) +{ + unsigned gc_ref_val = 0; + jboolean bval = JNI_FALSE; + + UNUSED(clss); + + if (H5Pget_gc_references((hid_t)fapl_id, (unsigned *)&gc_ref_val) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (gc_ref_val == 1) ? JNI_TRUE : JNI_FALSE; + +done: + return bval; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1gc_1references */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_small_data_block_size + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size + (JNIEnv *env, jclass clss, jlong plist, jlong size) +{ + long sz = (long)size; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_small_data_block_size((hid_t)plist, (hsize_t)sz)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_small_data_block_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size + (JNIEnv *env, jclass clss, jlong plist) +{ + hsize_t s = 0; + + UNUSED(clss); + + if (H5Pget_small_data_block_size((hid_t)plist, &s) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)s; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_libver_bounds + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds + (JNIEnv *env, jclass clss, jlong fapl_id, jint low, jint high) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_libver_bounds((hid_t)fapl_id, (H5F_libver_t)low, (H5F_libver_t)high)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_libver_bounds + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds + (JNIEnv *env, jclass clss, jlong fapl_id, jintArray libver) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == libver) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_libver_bounds: libversion bounds is NULL"); + + PIN_INT_ARRAY(ENVONLY, libver, theArray, &isCopy, "H5Pget_libver_bounds: input not pinned"); + + if ((retVal = H5Pget_libver_bounds((hid_t)fapl_id, (H5F_libver_t *)&(theArray[0]), (H5F_libver_t *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, libver, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds */ + +/* + * TODO: H5Pset_object_flush_cb + */ + +/* + * TODO: H5Pget_object_flush_cb + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pFAPLImp.h b/java/src/jni/h5pFAPLImp.h new file mode 100644 index 0000000..28b1d95 --- /dev/null +++ b/java/src/jni/h5pFAPLImp.h @@ -0,0 +1,501 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PFAPL +#define _Included_hdf_hdf5lib_H5_H5PFAPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * TODO: H5Pset_driver + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_driver + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1driver +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pget_driver_info + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fclose_degree + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fclose_degree + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_core + * Signature: (JJZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core +(JNIEnv *, jclass, jlong, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_core + * Signature: (J[J[Z)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core +(JNIEnv *, jclass, jlong, jlongArray, jbooleanArray); + +/* + * TODO: H5Pset_core_write_tracking + */ + +/* + * TODO: H5Pget_core_write_tracking + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_direct + * Signature: (JJJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct +(JNIEnv *, jclass, jlong, jlong, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_direct + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct +(JNIEnv *, jclass, jlong, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_family + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family +(JNIEnv *, jclass, jlong, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_family + * Signature: (J[J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family +(JNIEnv *, jclass, jlong, jlongArray, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_family_offset + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1family_1offset +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_family_offset + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1family_1offset +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_log + * Signature: (JLjava/lang/String;JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log +(JNIEnv *, jclass, jlong, jstring, jlong, jlong); + +/* + * TODO: H5Pset_fapl_mpio + */ + +/* + * TODO: H5Pget_fapl_mpio + */ + +/* + * TODO: H5Pset_fapl_mpiposix + */ + +/* + * TODO: H5Pget_fapl_mpiposix + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_multi + * Signature: (J[I[J[Ljava/lang/String;[JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1multi +(JNIEnv *, jclass, jlong, jintArray, jlongArray, jobjectArray, jlongArray, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_fapl_multi + * Signature: (J[I[J[Ljava/lang/String;[J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1fapl_1multi +(JNIEnv *, jclass, jlong, jintArray, jlongArray, jobjectArray, jlongArray); + +/* + * TODO: H5Pset_multi_type + */ + +/* + * TODO: H5Pget_multi_type + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_split + * Signature: (JLjava/lang/String;JLjava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split +(JNIEnv *, jclass, jlong, jstring, jlong, jstring, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_sec2 + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_stdio + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_fapl_windows + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pset_file_image + */ + +/* + * TODO: H5Pget_file_image + */ + +/* + * TODO: H5Pset_file_image_callbacks + */ + +/* + * TODO: H5Pget_file_image_callbacks + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_meta_block_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_meta_block_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pset_page_buffer_size + */ + +/* + * TODO: H5Pget_page_buffer_size + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sieve_buf_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sieve_buf_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_alignment + * Signature: (JJJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1alignment +(JNIEnv *, jclass, jlong, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_alignment + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1alignment +(JNIEnv *, jclass, jlong, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_cache + * Signature: (JIJJD)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1cache +(JNIEnv *, jclass, jlong, jint, jlong, jlong, jdouble); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_cache + * Signature: (J[I[J[J[D)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1cache +(JNIEnv *, jclass, jlong, jintArray, jlongArray, jlongArray, jdoubleArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_file_cache_size + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_file_cache_size + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_evict_on_close + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close +(JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_evict_on_close + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_metadata_read_attempts + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_metadata_read_attempts + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_mdc_config + * Signature: (JLhdf/hdf5lib/structs/H5AC_cache_config_t;)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config +(JNIEnv *, jclass, jlong, jobject); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_mdc_config + * Signature: (J)Lhdf/hdf5lib/structs/H5AC_cache_config_t; + */ +JNIEXPORT jobject JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pset_mdc_image_config + */ + +/* + * TODO: H5Pget_mdc_image_config + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_mdc_log_options + * Signature: (JZLjava/lang/String;Z)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options +(JNIEnv *, jclass, jlong, jboolean, jstring, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_mdc_log_options + * Signature: (J[Z)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1mdc_1log_1options +(JNIEnv *, jclass, jlong, jbooleanArray); + +/* + * TODO: H5Pset_all_coll_metadata_ops + */ + +/* + * TODO: H5Pget_all_coll_metadata_ops + */ + +/* + * TODO: H5Pset_coll_metadata_write + */ + +/* + * TODO: H5Pget_coll_metadata_write + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_gc_references + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1gc_1references +(JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_gc_references + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1gc_1references +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_small_data_block_size + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_small_data_block_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_libver_bounds + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_libver_bounds + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds +(JNIEnv *, jclass, jlong, jintArray); + +/* + * TODO: H5Pset_object_flush_cb + */ + +/* + * TODO: H5Pget_object_flush_cb + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PFAPL */ diff --git a/java/src/jni/h5pFCPLImp.c b/java/src/jni/h5pFCPLImp.c new file mode 100644 index 0000000..9c82ba6 --- /dev/null +++ b/java/src/jni/h5pFCPLImp.c @@ -0,0 +1,572 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pFCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_userblock + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1userblock + (JNIEnv *env, jclass clss, jlong plist, jlong size) +{ + long sz = (long) size; + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_userblock((hid_t)plist, (hsize_t)sz)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1userblock */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_userblock + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1userblock + (JNIEnv *env, jclass clss, jlong plist, jlongArray size) +{ + jboolean isCopy; + hsize_t s; + jlong *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_userblock: size is NULL"); + + PIN_LONG_ARRAY(ENVONLY, size, theArray, &isCopy, "H5Pget_userblock: size not pinned"); + + if ((status = H5Pget_userblock((hid_t)plist, &s)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jlong)s; + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1userblock */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sizes + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sizes + (JNIEnv *env, jclass clss, jlong plist, jint sizeof_addr, jint sizeof_size) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_sizes((hid_t)plist, (size_t)sizeof_addr, (size_t)sizeof_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1sizes */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sizes + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sizes + (JNIEnv *env, jclass clss, jlong plist, jlongArray size) +{ + jboolean isCopy; + jlong *theArray = NULL; + jsize arrLen; + size_t ss; + size_t sa; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_sizes: size is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, size)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_sizes: size array length < 0"); + } + if (arrLen < 2) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_sizes: size input array < 2 elements"); + + PIN_LONG_ARRAY(ENVONLY, size, theArray, &isCopy, "H5Pget_sizes: size not pinned"); + + if ((status = H5Pget_sizes((hid_t)plist, &sa, &ss)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + theArray[0] = (jlong)sa; + theArray[1] = (jlong)ss; + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1sizes */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sym_k + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sym_1k + (JNIEnv *env, jclass clss, jlong plist, jint ik, jint lk) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_sym_k((hid_t)plist, (unsigned)ik, (unsigned)lk)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1sym_1k */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sym_k + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sym_1k + (JNIEnv *env, jclass clss, jlong plist, jintArray size) +{ + jboolean isCopy; + jsize arrLen; + jint *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_sym_k: size is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, size)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_sym_k: size array length < 0"); + } + if (arrLen < 2) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_sym_k: size < 2 elements"); + + PIN_INT_ARRAY(ENVONLY, size, theArray, &isCopy, "H5Pget_sym_k: size not pinned"); + + if ((status = H5Pget_sym_k((hid_t)plist, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_LONG_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1sym_1k */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_istore_k + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1istore_1k + (JNIEnv *env, jclass clss, jlong plist, jint ik) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_istore_k((hid_t)plist, (unsigned)ik)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1istore_1k */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_istore_k + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1istore_1k + (JNIEnv *env, jclass clss, jlong plist, jintArray ik) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == ik) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_store_k: ik is NULL"); + + PIN_INT_ARRAY(ENVONLY, ik, theArray, &isCopy, "H5Pget_store_k: size not pinned"); + + if ((status = H5Pget_istore_k((hid_t)plist, (unsigned *)&(theArray[0]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, ik, theArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1istore_1k */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_file_space_page_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1page_1size + (JNIEnv *env, jclass clss, jlong fcpl_id, jlong fsp_size) +{ + UNUSED(clss); + + if (H5Pset_file_space_page_size((hid_t)fcpl_id, (hsize_t)fsp_size) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1page_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_page_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1page_1size + (JNIEnv *env, jclass clss, jlong fcpl_id) +{ + hsize_t fsp_size = 0; + + UNUSED(clss); + + if (H5Pget_file_space_page_size((hid_t)fcpl_id, &fsp_size) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)fsp_size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1page_1size */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_file_space_strategy + * Signature: (JIZJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1strategy + (JNIEnv *env, jclass clss, jlong fcpl_id, jint strategy, jboolean persist, jlong threshold) +{ + UNUSED(clss); + + if (H5Pset_file_space_strategy((hid_t)fcpl_id, (H5F_fspace_strategy_t)strategy, (hbool_t)persist, (hsize_t)threshold) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_file_space_strategy */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy + * Signature: (J[Z[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy + (JNIEnv *env, jclass clss, jlong fcpl_id, jbooleanArray persist, jlongArray threshold) +{ + H5F_fspace_strategy_t thestrategy = H5F_FSPACE_STRATEGY_FSM_AGGR; /* Library default */ + jboolean isCopy; + jboolean *persistArray = NULL; + jlong *thresholdArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (persist) + PIN_BOOL_ARRAY(ENVONLY, persist, persistArray, &isCopy, "H5Pget_file_space: persist not pinned"); + if (threshold) + PIN_LONG_ARRAY(ENVONLY, threshold, thresholdArray, &isCopy, "H5Pget_file_space: threshold not pinned"); + + if ((status = H5Pget_file_space_strategy((hid_t)fcpl_id, &thestrategy, (hbool_t *)persistArray, (hsize_t *)thresholdArray)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (thresholdArray) + UNPIN_LONG_ARRAY(ENVONLY, threshold, thresholdArray, (status < 0) ? JNI_ABORT : 0); + if (persistArray) + UNPIN_BOOL_ARRAY(ENVONLY, persist, persistArray, (status < 0) ? JNI_ABORT : 0); + + return (jint)thestrategy; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy_persist + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist + (JNIEnv *env, jclass clss, jlong fcpl_id) +{ + hbool_t persist = FALSE; + herr_t status = FAIL; + + UNUSED(clss); + + if ((status = H5Pget_file_space_strategy((hid_t)fcpl_id, NULL, &persist, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jboolean)persist; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy_threshold + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1threshold + (JNIEnv *env, jclass clss, jlong fcpl_id) +{ + hsize_t threshold = 0; + herr_t status = FAIL; + + UNUSED(clss); + + if ((status = H5Pget_file_space_strategy((hid_t)fcpl_id, NULL, NULL, &threshold)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)threshold; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1threshold */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_nindexes + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes + (JNIEnv *env, jclass clss, jlong plist_id, jint nindexes) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if (nindexes > H5O_SHMESG_MAX_NINDEXES) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_nindexes: number of indexes is greater than H5O_SHMESG_MAX_NINDEXES"); + + if ((retVal = H5Pset_shared_mesg_nindexes((hid_t)plist_id, (unsigned)nindexes)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_nindexes + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes + (JNIEnv *env, jclass clss, jlong fcpl_id) +{ + unsigned nindexes; + + UNUSED(clss); + + if (H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)nindexes; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_index + * Signature: (JIII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index + (JNIEnv *env, jclass clss, jlong fcpl_id, jint index_num, + jint mesg_type_flags, jint min_mesg_size) +{ + unsigned nindexes; /* Number of SOHM indexes */ + herr_t retVal = FAIL; + + UNUSED(clss); + + /* Check arguments */ + if ((unsigned) mesg_type_flags > H5O_SHMESG_ALL_FLAG) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_index: unrecognized flags in mesg_type_flags"); + + /* Read the current number of indexes */ + if (H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Range check */ + if ((unsigned) index_num >= nindexes) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_index: index_num is too large; no such index"); + + if ((retVal = H5Pset_shared_mesg_index((hid_t)fcpl_id, (unsigned)index_num, (unsigned) mesg_type_flags, (unsigned) min_mesg_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_index + * Signature: (JI[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index + (JNIEnv *env, jclass clss, jlong fcpl_id, jint index_num, jintArray mesg_info) +{ + jboolean isCopy; + unsigned nindexes; /* Number of SOHM indexes */ + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == mesg_info) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_shared_mesg_index: mesg_info is NULL"); + + /* Read the current number of indexes */ + if (H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Range check */ + if ((unsigned) index_num >= nindexes) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pget_shared_mesg_index: index_num is too large; no such index"); + + PIN_INT_ARRAY(ENVONLY, mesg_info, theArray, &isCopy, "H5Pget_shared_mesg_index: input not pinned"); + + if ((retVal = H5Pget_shared_mesg_index((hid_t)fcpl_id, (unsigned)index_num, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, mesg_info, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_phase_change + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change + (JNIEnv *env, jclass clss, jlong fcpl_id, jint max_list, jint min_btree) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + /* Check that values are sensible. The min_btree value must be no greater + * than the max list plus one. + * + * Range check to make certain they will fit into encoded form. + */ + + if (max_list + 1 < min_btree) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_phase_change: minimum B-tree value is greater than maximum list value"); + if (max_list > H5O_SHMESG_MAX_LIST_SIZE) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_phase_change: max list value is larger than H5O_SHMESG_MAX_LIST_SIZE"); + if (min_btree > H5O_SHMESG_MAX_LIST_SIZE) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_shared_mesg_phase_change: min btree value is larger than H5O_SHMESG_MAX_LIST_SIZE"); + + if ((retVal = H5Pset_shared_mesg_phase_change((hid_t)fcpl_id, (unsigned)max_list, (unsigned)min_btree)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change + (JNIEnv *env, jclass clss, jlong fcpl_id, jintArray size) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == size) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_shared_mesg_phase_change: size is NULL"); + + PIN_INT_ARRAY(ENVONLY, size, theArray, &isCopy, "H5Pget_shared_mesg_phase_change: input not pinned"); + + if ((retVal = H5Pget_shared_mesg_phase_change((hid_t)fcpl_id, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, size, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pFCPLImp.h b/java/src/jni/h5pFCPLImp.h new file mode 100644 index 0000000..57fcae8 --- /dev/null +++ b/java/src/jni/h5pFCPLImp.h @@ -0,0 +1,207 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PFCPL +#define _Included_hdf_hdf5lib_H5_H5PFCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_userblock + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1userblock +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_userblock + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1userblock +(JNIEnv *, jclass, jlong, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sizes + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sizes +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sizes + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sizes +(JNIEnv *, jclass, jlong, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_sym_k + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1sym_1k +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_sym_k + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1sym_1k +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_istore_k + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1istore_1k +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_istore_k + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1istore_1k +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_file_space_page_size + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1page_1size +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_page_size + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1page_1size +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_file_space_strategy + * Signature: (JIZJ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1strategy +(JNIEnv *, jclass, jlong, jint, jboolean, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy + * Signature: (J[Z[J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy +(JNIEnv *, jclass, jlong, jbooleanArray, jlongArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy_persist + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_file_space_strategy_threshold + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1threshold +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_nindexes + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_nindexes + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_index + * Signature: (JIII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index +(JNIEnv *, jclass, jlong, jint, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_index + * Signature: (JI[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index +(JNIEnv *, jclass, jlong, jint, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_shared_mesg_phase_change + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_shared_mesg_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change +(JNIEnv *, jclass, jlong, jintArray); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PFCPL */ diff --git a/java/src/jni/h5pGAPLImp.c b/java/src/jni/h5pGAPLImp.c new file mode 100644 index 0000000..9540387 --- /dev/null +++ b/java/src/jni/h5pGAPLImp.c @@ -0,0 +1,36 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pGAPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pGAPLImp.h b/java/src/jni/h5pGAPLImp.h new file mode 100644 index 0000000..73ad4a8 --- /dev/null +++ b/java/src/jni/h5pGAPLImp.h @@ -0,0 +1,27 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PGAPL +#define _Included_hdf_hdf5lib_H5_H5PGAPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PGAPL */ diff --git a/java/src/jni/h5pGCPLImp.c b/java/src/jni/h5pGCPLImp.c new file mode 100644 index 0000000..2ba1c7d --- /dev/null +++ b/java/src/jni/h5pGCPLImp.c @@ -0,0 +1,227 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pGCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_local_heap_size_hint + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint + (JNIEnv *env, jclass clss, jlong gcpl_id, jlong size_hint) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_local_heap_size_hint((hid_t)gcpl_id, (size_t)size_hint)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_local_heap_size_hint + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint + (JNIEnv *env, jclass clss, jlong gcpl_id) +{ + size_t size_hint = 0; + + UNUSED(clss); + + if (H5Pget_local_heap_size_hint((hid_t)gcpl_id, &size_hint) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)size_hint; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_link_creation_order + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order + (JNIEnv *env, jclass clss, jlong gcpl_id, jint crt_order_flags) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_link_creation_order((hid_t)gcpl_id, (unsigned)crt_order_flags)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_link_creation_order + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order + (JNIEnv *env, jclass clss, jlong gcpl_id) +{ + unsigned crt_order_flags; + + UNUSED(clss); + + if (H5Pget_link_creation_order((hid_t)gcpl_id, &crt_order_flags) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)crt_order_flags; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_est_link_info + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info + (JNIEnv *env, jclass clss, jlong gcpl_id, jint est_num_entries, jint est_name_len) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + /* Range check values */ + if ((est_num_entries > 65535) || (est_name_len > 65535)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_est_link_info: est. name length or number of entries must be < 65536"); + + if ((retVal = H5Pset_est_link_info((hid_t)gcpl_id, (unsigned)est_num_entries, (unsigned)est_name_len)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_est_link_info + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info + (JNIEnv *env, jclass clss, jlong gcpl_id, jintArray link_info) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == link_info) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_est_link_info: link_info is NULL"); + + PIN_INT_ARRAY(ENVONLY, link_info, theArray, &isCopy, "H5Pget_est_link_info: input not pinned"); + + if ((retVal = H5Pget_est_link_info((hid_t)gcpl_id, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, link_info, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_link_phase_change + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change + (JNIEnv *env, jclass clss, jlong gcpl_id, jint max_compact, jint min_dense) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if (max_compact < min_dense) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_link_phase_change: max compact value must be >= min dense value"); + if (max_compact > 65535) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_link_phase_change: max compact value must be < 65536"); + if (min_dense > 65535) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_link_phase_change: min dense value must be < 65536"); + + if ((retVal = H5Pset_link_phase_change((hid_t)gcpl_id, (unsigned)max_compact, (unsigned)min_dense)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_link_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change + (JNIEnv *env, jclass clss, jlong gcpl_id, jintArray links) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == links) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_link_phase_change: links is NULL"); + + PIN_INT_ARRAY(ENVONLY, links, theArray, &isCopy, "H5Pget_link_phase_change: input not pinned"); + + if ((retVal = H5Pget_link_phase_change((hid_t)gcpl_id, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, links, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pGCPLImp.h b/java/src/jni/h5pGCPLImp.h new file mode 100644 index 0000000..9c32063 --- /dev/null +++ b/java/src/jni/h5pGCPLImp.h @@ -0,0 +1,99 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PGCPL +#define _Included_hdf_hdf5lib_H5_H5PGCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_local_heap_size_hint + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_local_heap_size_hint + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_link_creation_order + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_link_creation_order + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_est_link_info + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_est_link_info + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_link_phase_change + * Signature: (JII)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_link_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change +(JNIEnv *, jclass, jlong, jintArray); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PGCPL */ diff --git a/java/src/jni/h5pImp.c b/java/src/jni/h5pImp.c index ac21d1d..bed23c9 100644 --- a/java/src/jni/h5pImp.c +++ b/java/src/jni/h5pImp.c @@ -26,7 +26,11 @@ extern "C" { #include "h5util.h" #include "h5pImp.h" +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ extern JavaVM *jvm; + extern jobject copy_callback; extern jobject close_callback; extern jobject create_callback; @@ -44,17 +48,16 @@ typedef struct _cb_wrapper { /* Local Prototypes */ /********************/ -static herr_t H5P_cls_create_func_cb(hid_t prop_id, void *create_data); -static herr_t H5P_cls_copy_func_cb(hid_t new_prop_id, hid_t old_prop_id, void *copy_data); -static herr_t H5P_cls_close_func_cb(hid_t prop_id, void *close_data); - -static herr_t H5P_prp_create_func_cb(const char *name, size_t size, void *value); -static herr_t H5P_prp_copy_func_cb(const char *name, size_t size, void *value); -static herr_t H5P_prp_close_func_cb(const char *name, size_t size, void *value); -static int H5P_prp_compare_func_cb(void *value1, void *value2, size_t size); -static herr_t H5P_prp_get_func_cb(hid_t prop_id, const char *name, size_t size, void *value); -static herr_t H5P_prp_set_func_cb(hid_t prop_id, const char *name, size_t size, void *value); -static herr_t H5P_prp_delete_func_cb(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P_cls_create_cb(hid_t prop_id, void *create_data); +static herr_t H5P_cls_copy_cb(hid_t new_prop_id, hid_t old_prop_id, void *copy_data); +static herr_t H5P_cls_close_cb(hid_t prop_id, void *close_data); +static herr_t H5P_prp_create_cb(const char *name, size_t size, void *value); +static herr_t H5P_prp_copy_cb(const char *name, size_t size, void *value); +static herr_t H5P_prp_close_cb(const char *name, size_t size, void *value); +static int H5P_prp_compare_cb(void *value1, void *value2, size_t size); +static herr_t H5P_prp_get_cb(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P_prp_set_cb(hid_t prop_id, const char *name, size_t size, void *value); +static herr_t H5P_prp_delete_cb(hid_t prop_id, const char *name, size_t size, void *value); static herr_t H5P_iterate_cb(hid_t prop_id, const char *name, void *cb_data); @@ -67,37 +70,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Pcreate (JNIEnv *env, jclass clss, jlong type) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Pcreate((hid_t)type); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Pcreate((hid_t) type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Pcreate */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pclose - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5__1H5Pclose - (JNIEnv *env, jclass clss, jlong plist) -{ - herr_t retVal = 0; - - if (plist > 0) - retVal = H5Pclose((hid_t)plist); - - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5__1H5Pclose */ - -/* - * Class: hdf_hdf5lib_H5 * Method: H5Pget_class * Signature: (J)J */ @@ -105,12 +90,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Pget_1class (JNIEnv *env, jclass clss, jlong plist) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Pget_class((hid_t) plist); - if (retVal == H5P_ROOT) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Pget_class((hid_t) plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* + * if (retVal == H5P_ROOT) + * H5_LIBRARY_ERROR(ENVONLY); + */ + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Pget_1class */ @@ -123,5834 +115,964 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Pcopy (JNIEnv *env, jclass clss, jlong plist) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Pcopy((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Pcopy((hid_t) plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Pcopy */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_userblock - * Signature: (JJ)I + * Method: H5Pclose + * Signature: (J)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1userblock - (JNIEnv *env, jclass clss, jlong plist, jlong size) +Java_hdf_hdf5lib_H5__1H5Pclose + (JNIEnv *env, jclass clss, jlong plist) { - herr_t retVal = -1; - long sz = (long)size; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Pset_userblock((hid_t)plist, (hsize_t)sz); - if (retVal < 0) - h5libraryError(env); + if (plist >= 0) + if ((retVal = H5Pclose((hid_t) plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1userblock */ +} /* end Java_hdf_hdf5lib_H5__1H5Pclose */ /* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_userblock - * Signature: (J[J)I + * TODO: H5Pencode */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1userblock - (JNIEnv *env, jclass clss, jlong plist, jlongArray size) -{ - herr_t status = -1; - jlong *theArray; - jboolean isCopy; - hsize_t s; - - if (size == NULL) { - h5nullArgument(env, "H5Pget_userblock: size is NULL"); - } /* end if */ - else { - theArray = (jlong*)ENVPTR->GetLongArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_userblock: size not pinned"); - } /* end if */ - else { - status = H5Pget_userblock((hid_t)plist, &s); - - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jlong)s; - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1userblock */ +/* + * TODO: H5Pdecode + */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sizes - * Signature: (JII)I + * Method: _H5Pcreate_class + * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sizes - (JNIEnv *env, jclass clss, jlong plist, jint sizeof_addr, jint sizeof_size) +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pcreate_1class + (JNIEnv *env, jclass clss, jlong parent_class, jstring name, jobject create_op, + jobject create_data, jobject copy_op, jobject copy_data, jobject close_op, jobject close_data) { - herr_t retVal = -1; + const char *cstr = NULL; + hid_t class_id = H5I_INVALID_HID; - retVal = H5Pset_sizes((hid_t)plist, (size_t)sizeof_addr, (size_t)sizeof_size); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1sizes */ + create_callback = create_op; + close_callback = close_op; + copy_callback = copy_op; -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sizes - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sizes - (JNIEnv *env, jclass clss, jlong plist, jlongArray size) -{ - herr_t status = -1; - jlong *theArray; - jboolean isCopy; - size_t ss; - size_t sa; - - if (size == NULL) { - h5nullArgument(env, "H5Pget_sizes: size is NULL"); - } /* end if */ - else if (ENVPTR->GetArrayLength(ENVPAR size) < 2) { - h5badArgument(env, "H5Pget_sizes: size input array < 2 elements"); - } - else { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_sizes: size not pinned"); - } /* end if */ - else { - status = H5Pget_sizes((hid_t)plist, &sa, &ss); - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jlong)sa; - theArray[1] = (jlong)ss; - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "_H5Pcreate_class: class name not pinned"); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1sizes */ + if ((class_id = H5Pcreate_class((hid_t)parent_class, cstr, (H5P_cls_create_func_t)H5P_cls_create_cb, (void *) create_data, + (H5P_cls_copy_func_t)H5P_cls_copy_cb, (void *) copy_data, (H5P_cls_close_func_t)H5P_cls_close_cb, (void *) close_data)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); + + return (jlong)class_id; +} /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sym_k - * Signature: (JII)I + * Method: _H5Pcreate_class_nocb + * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sym_1k - (JNIEnv *env, jclass clss, jlong plist, jint ik, jint lk) +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb + (JNIEnv *env, jclass clss, jlong parent_class, jstring name) { - herr_t retVal = -1; + const char *cstr = NULL; + hid_t class_id = H5I_INVALID_HID; - retVal = H5Pset_sym_k((hid_t)plist, (unsigned)ik, (unsigned)lk); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1sym_1k */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "_H5Pcreate_class_nocb: class name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sym_k - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sym_1k - (JNIEnv *env, jclass clss, jlong plist, jintArray size) -{ - herr_t status = -1; - jint *theArray; - jboolean isCopy; - - if (size == NULL) { - h5nullArgument(env, "H5Pget_sym_k: size is NULL"); - } /* end if */ - else if (ENVPTR->GetArrayLength(ENVPAR size) < 2) { - h5badArgument(env, "H5Pget_sym_k: size < 2 elements"); - } /* end else if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_sym_k: size not pinned"); - } /* end if */ - else { - status = H5Pget_sym_k((hid_t)plist, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1])); - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR size, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR size, theArray, 0); - } /* end else */ - } /* end else */ + if ((class_id = H5Pcreate_class((hid_t)parent_class, cstr, NULL, NULL, NULL, NULL, NULL, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1sym_1k */ +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); + + return (jlong)class_id; +} /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_istore_k - * Signature: (JI)I + * Method: H5Pregister2 + * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1istore_1k - (JNIEnv *env, jclass clss, jlong plist, jint ik) +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pregister2 + (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, + jbyteArray def_value, jobject prp_create, jobject prp_set, jobject prp_get, jobject prp_delete, + jobject prp_copy, jobject prp_cmp, jobject prp_close) { - herr_t retVal = -1; + const char *cstr = NULL; + jboolean isCopy; + herr_t status = FAIL; + jbyte *propValBuf = NULL; - retVal = H5Pset_istore_k((hid_t)plist, (unsigned)ik); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1istore_1k */ + copy_callback = prp_copy; + close_callback = prp_close; + create_callback = prp_create; + compare_callback = prp_cmp; + set_callback = prp_set; + get_callback = prp_get; + delete_callback = prp_delete; -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_istore_k - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1istore_1k - (JNIEnv *env, jclass clss, jlong plist, jintArray ik) -{ - herr_t status = -1; - jint *theArray; - jboolean isCopy; + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pregister2: property name not pinned"); - if (ik == NULL) { - h5nullArgument(env, "H5Pget_store_k: ik is NULL"); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR ik, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_store_k: size not pinned"); - } /* end if */ - else { - status = H5Pget_istore_k((hid_t)plist, (unsigned *)&(theArray[0])); - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR ik, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR ik, theArray, 0); - } /* end else */ - } /* end else */ + PIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, &isCopy, "H5Pregister2: default property value buffer not pinned"); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1istore_1k */ + if ((status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void *)propValBuf, (H5P_prp_create_func_t)H5P_prp_create_cb, + (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, + (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (propValBuf) + UNPIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, (status < 0) ? JNI_ABORT : 0); + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); +} /* end Java_hdf_hdf5lib_H5_H5Pregister2 */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_layout - * Signature: (JI)I + * Method: H5Pregister2_nocb + * Signature: (JLjava/lang/String;J[B)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1layout - (JNIEnv *env, jclass clss, jlong plist, jint layout) +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pregister2_1nocb + (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, jbyteArray def_value) { - herr_t retVal = -1; + const char *cstr = NULL; + jboolean isCopy; + herr_t status = FAIL; + jbyte *propValBuf = NULL; - retVal = H5Pset_layout((hid_t)plist, (H5D_layout_t)layout); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1layout */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pregister2_nocb: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_layout - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1layout - (JNIEnv *env, jclass clss, jlong plist) -{ - H5D_layout_t retVal = H5D_LAYOUT_ERROR; + PIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, &isCopy, "H5Pregister2_nocb: default property value buffer not pinned"); - retVal = H5Pget_layout((hid_t)plist); - if (retVal == H5D_LAYOUT_ERROR) - h5libraryError(env); + if ((status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void *)propValBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1layout */ +done: + if (propValBuf) + UNPIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, (status < 0) ? JNI_ABORT : 0); + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); +} /* end Java_hdf_hdf5lib_H5_H5Pregister2_1nocb */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk - * Signature: (JI[B)I + * Method: H5Pinsert2 + * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk - (JNIEnv *env, jclass clss, jlong plist, jint ndims, jbyteArray dim) +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pinsert2 + (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, + jbyteArray def_value, jobject prp_set, jobject prp_get, jobject prp_delete, + jobject prp_copy, jobject prp_cmp, jobject prp_close) { - herr_t status = -1; - jbyte *theArray; - jboolean isCopy; - hsize_t *da; - hsize_t *lp; - jlong *jlp; - size_t i; - size_t rank; - - if (dim == NULL) { - h5nullArgument(env, "H5Pset_chunk: dim array is NULL"); - } /* end if */ - else { - i = (size_t)ENVPTR->GetArrayLength(ENVPAR dim); - rank = i / sizeof(jlong); - if (rank < ndims) { - h5badArgument(env, "H5Pset_chunk: dims array < ndims"); - } /* end if */ - else { - theArray = (jbyte *)ENVPTR->GetByteArrayElements(ENVPAR dim, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pset_chunk: dim array not pinned"); - } /* end if */ - else { - da = lp = (hsize_t *)HDmalloc(rank * sizeof(hsize_t)); - if (da == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR dim, theArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pset_chunk: dims not converted to hsize_t"); - } /* end if */ - else { - jlp = (jlong *)theArray; - for (i = 0; i < rank; i++) { - *lp = (hsize_t)*jlp; - lp++; - jlp++; - } /* end if */ - - status = H5Pset_chunk((hid_t)plist, (int)ndims, da); - - ENVPTR->ReleaseByteArrayElements(ENVPAR dim, theArray, JNI_ABORT); - HDfree(da); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + const char *cstr = NULL; + jboolean isCopy; + herr_t status = FAIL; + jbyte *propValBuf = NULL; - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk */ + UNUSED(clss); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk - * Signature: (JI[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk - (JNIEnv *env, jclass clss, jlong plist, jint max_ndims, jlongArray dims) -{ - herr_t status = -1; - jlong *theArray; - jboolean isCopy; - hsize_t *da; - int i; - - if (dims == NULL) { - h5nullArgument(env, "H5Pget_chunk: dims is NULL"); - } /* end if */ - else if (ENVPTR->GetArrayLength(ENVPAR dims) < max_ndims) { - h5badArgument(env, "H5Pget_chunk: dims array < max_ndims"); - } /* end else if */ - else { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_chunk: input dims not pinned"); - } /* end if */ - else { - da = (hsize_t *)HDmalloc((size_t)max_ndims * sizeof(hsize_t)); - if (da == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, theArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_chunk: dims not converted to hsize_t"); - } /* end if */ - else { - status = H5Pget_chunk((hid_t)plist, (int)max_ndims, da); - - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, theArray, JNI_ABORT); - HDfree (da); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < max_ndims; i++) { - theArray[i] = (jlong)da[i]; - } - HDfree (da); - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + copy_callback = prp_copy; + close_callback = prp_close; + compare_callback = prp_cmp; + set_callback = prp_set; + get_callback = prp_get; + delete_callback = prp_delete; - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pinsert2: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_alignment - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1alignment - (JNIEnv *env, jclass clss, jlong plist, jlong threshold, jlong alignment) -{ - herr_t retVal = -1; - long thr = (long)threshold; - long align = (long)alignment; + PIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, &isCopy, "H5Pinsert2: property value buffer not pinned"); - retVal = H5Pset_alignment((hid_t)plist, (hsize_t)thr, (hsize_t)align); - if (retVal < 0) - h5libraryError(env); + if ((status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void *)propValBuf, + (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, + (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1alignment */ +done: + if (propValBuf) + UNPIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, (status < 0) ? JNI_ABORT : 0); + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); +} /* end Java_hdf_hdf5lib_H5_H5Pinsert2 */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_alignment - * Signature: (J[J)I + * Method: H5Pinsert2_nocb + * Signature: (JLjava/lang/String;J[B)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1alignment - (JNIEnv *env, jclass clss, jlong plist, jlongArray alignment) +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb + (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, jbyteArray def_value) { - herr_t status = -1; - jlong *theArray; - jboolean isCopy; - hsize_t t; - hsize_t a; - - if (alignment == NULL) { - h5nullArgument(env, "H5Pget_alignment: input alignment is NULL"); - } /* end if */ - else { - if (ENVPTR->GetArrayLength(ENVPAR alignment) < 2) { - h5badArgument(env, "H5Pget_alignment: alignment input array < 2"); - } /* end if */ - else { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR alignment, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_alignment: input array not pinned"); - } /* end if */ - else { - status = H5Pget_alignment((hid_t)plist, &t, &a); - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR alignment, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jlong)t; - theArray[1] = (jlong)a; - ENVPTR->ReleaseLongArrayElements(ENVPAR alignment, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + const char *cstr = NULL; + jboolean isCopy; + herr_t status = FAIL; + jbyte *propValBuf = NULL; - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1alignment */ + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pinsert2_nocb: property name not pinned"); + + PIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, &isCopy, "H5Pinsert2_nocb: property value buffer not pinned"); + + if ((status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void *)propValBuf, NULL, NULL, NULL, NULL, NULL, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (propValBuf) + UNPIN_BYTE_ARRAY(ENVONLY, def_value, propValBuf, (status < 0) ? JNI_ABORT : 0); + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); +} /* end Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_external - * Signature: (JLjava/lang/String;JJ)I + * Method: H5Pset + * Signature: (JLjava/lang/String;I)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1external - (JNIEnv *env, jclass clss, jlong plist, jstring name, jlong offset, jlong size) +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pset + (JNIEnv *env, jclass clss, jlong plid, jstring name, jint val) { - herr_t status = -1; - const char *fileName; - off_t off; - hsize_t sz; - hid_t plid; + const char *cstr = NULL; + hid_t retVal = H5I_INVALID_HID; - plid = (hid_t)plist; - off = (off_t)offset; - sz = (hsize_t)size; + UNUSED(clss); - PIN_JAVA_STRING(name, fileName); - if (fileName != NULL) { - status = H5Pset_external(plid, fileName, off, sz); + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pset: property name not pinned"); - UNPIN_JAVA_STRING(name, fileName); + if ((retVal = H5Pset((hid_t)plid, cstr, &val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); - } +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1external */ + return (jlong)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_external_count - * Signature: (J)I + * Method: H5Pexist + * Signature: (JLjava/lang/String;)Z */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1external_1count - (JNIEnv *env, jclass clss, jlong plist) +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pexist + (JNIEnv *env, jclass clss, jlong plid, jstring name) { - int retVal = -1; + const char *cstr = NULL; + htri_t bval = JNI_FALSE; - retVal = H5Pget_external_count((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1external_1count */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pexist: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_external - * Signature: (JIJ[Ljava/lang/String;[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1external - (JNIEnv *env, jclass clss, jlong plist, jint idx, jlong name_size, - jobjectArray name, jlongArray size) -{ - herr_t status = -1; - jlong *theArray; - jboolean isCopy; - char *file = NULL; - jstring str; - off_t o; - hsize_t s; - - if (name_size < 0) { - h5badArgument(env, "H5Pget_external: name_size < 0"); - } /* end if */ - else if ((size != NULL) && (ENVPTR->GetArrayLength(ENVPAR size) < 2)) { - h5badArgument(env, "H5Pget_external: size input array < 2"); - } /* end else if */ - else { - if (name_size > 0) { - file = (char *)HDmalloc(sizeof(char)*(size_t)name_size); - } /* end else */ - - status = H5Pget_external((hid_t) plist, (unsigned)idx, (size_t)name_size, - file, (off_t *)&o, (hsize_t *)&s); - if (status < 0) { - HDfree(file); - h5libraryError(env); - } /* end if */ - else { - if (size != NULL) { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError( env, "H5Pget_external: size array not pinned"); - } /* end if */ - else { - theArray[0] = o; - theArray[1] = (jlong)s; - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, 0); - } - } /* end if */ - - if (file != NULL) { - /* NewStringUTF may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR file); - if (str == NULL) { - HDfree(file); - h5JNIFatalError(env, "H5Pget_external: return array not created"); - } /* end if */ - else { - /* SetObjectArrayElement may raise exceptions */ - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - HDfree(file); - } /* end else */ - } /* end if */ - } /* end else */ - } + if ((bval = H5Pexist((hid_t)plid, cstr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1external */ + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); + + return (jboolean)bval; +} /* end Java_hdf_hdf5lib_H5_H5Pexist */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fill_value - * Signature: (JJ[B)I + * Method: H5Pget_size + * Signature: (JLjava/lang/String;)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fill_1value - (JNIEnv *env, jclass clss, jlong plist_id, jlong type_id, jbyteArray value) +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1size + (JNIEnv *env, jclass clss, jlong plid, jstring name) { - jint status = -1; - jbyte *byteP = NULL; - jboolean isCopy; - - if (value != NULL) { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Pget_fill_value: value array not pinned"); - } /* end if */ - else { - status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - } - } /* end if */ - else { - status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); - } + const char *cstr = NULL; + size_t size = 0; + herr_t status = FAIL; - if (status < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fill_1value */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pget_size: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fill_value - * Signature: (JJ[B)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fill_1value - (JNIEnv *env, jclass clss, jlong plist_id, jlong type_id, jbyteArray value) -{ - jint status = -1; - jbyte *byteP; - jboolean isCopy; + if ((status = H5Pget_size((hid_t)plid, cstr, &size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (value == NULL) { - h5badArgument(env, "H5Pget_fill_value: value is NULL"); - } /* end if */ - else { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Pget_fill_value: value array not pinned"); - } /* end if */ - else { - status = H5Pget_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, 0); - } /* end else */ - } /* end else */ +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fill_1value */ + return (jlong) size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1size */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_filter - * Signature: (JIIJ[I)I + * Method: H5Pget_nprops + * Signature: (J)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1filter - (JNIEnv *env, jclass clss, jlong plist, jint filter, jint flags, - jlong cd_nelmts, jintArray cd_values) +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1nprops + (JNIEnv *env, jclass clss, jlong plid) { - herr_t status = -1; - jint *theArray; - jboolean isCopy; - - if (cd_values == NULL) { - status = H5Pset_filter((hid_t)plist, (H5Z_filter_t)filter, - (unsigned int)flags, (size_t)cd_nelmts, NULL); - if (status < 0) - h5libraryError(env); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pset_filter: input array not pinned"); - }/* end if */ - else { - status = H5Pset_filter((hid_t)plist, (H5Z_filter_t)filter, - (unsigned int)flags, (size_t)cd_nelmts, (const unsigned int *)theArray); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, theArray, JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + size_t nprops = 0; - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1filter */ + UNUSED(clss); + + if (H5Pget_nprops((hid_t)plid, &nprops) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)nprops; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1nprops */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nfilters - * Signature: (J)I + * Method: H5Pget_class_name + * Signature: (J)Ljava/lang/String; */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nfilters - (JNIEnv *env, jclass clss, jlong plist) +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1class_1name + (JNIEnv *env, jclass clss, jlong plid) { - int retVal = -1; + char *c_str = NULL; + jstring j_str = NULL; - retVal = H5Pget_nfilters((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1nfilters */ + if (NULL == (c_str = H5Pget_class_name((hid_t)plid))) + H5_LIBRARY_ERROR(ENVONLY); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter - * Signature: (JI[I[J[IJ[Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter - (JNIEnv *env, jclass clss, jlong plist, jint filter_number, jintArray flags, - jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name) -{ - herr_t status = -1; - jint *flagsArray; - jlong *cd_nelmtsArray; - jint *cd_valuesArray; - jint mode = JNI_ABORT; - jboolean isCopy; - jstring str; - char *filter; - - if (namelen <= 0) { - h5badArgument(env, "H5Pget_filter: namelen <= 0"); - } /* end if */ - else if (flags == NULL) { - h5badArgument(env, "H5Pget_filter: flags is NULL"); - } /* end else if */ - else if (cd_nelmts == NULL) { - h5badArgument(env, "H5Pget_filter: cd_nelmts is NULL"); - } /* end else if */ - else if (cd_values == NULL) { - h5badArgument(env, "H5Pget_filter: cd_values is NULL"); - } /* end else if */ - else { - filter = (char *)HDmalloc(sizeof(char)*(size_t)namelen); - if (filter == NULL) { - h5outOfMemory(env, "H5Pget_filter: namelen malloc failed"); - } /* end if */ - else { - flagsArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR flags, &isCopy); - if (flagsArray == NULL) { - h5JNIFatalError(env, "H5Pget_filter: flags array not pinned"); - } /* end if */ - else { - cd_nelmtsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); - if (cd_nelmtsArray == NULL) { - h5JNIFatalError(env, "H5Pget_filter: nelmts array not pinned"); - } /* end if */ - else { - cd_valuesArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - if (cd_valuesArray == NULL) { - h5JNIFatalError(env, "H5Pget_filter: elmts array not pinned"); - } /* end if */ - else { - /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = *(cd_nelmtsArray); - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - unsigned int filter_config; - status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, - (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, - (size_t)namelen, filter, &filter_config); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - /* end direct cast special */ - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - mode = 0; - - /* NewStringUTF may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR filter); - if (str == NULL) { - h5JNIFatalError(env, "H5Pget_filter: return string not pinned"); - } /* end if */ - else { - /* SetObjectArrayElement may throw exceptiosn */ - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - } /* end else */ - } /* end else */ - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, mode); - } - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, mode); - } - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, mode); - } - HDfree(filter); - } - } /* end else */ + if (NULL == (j_str = ENVPTR->NewStringUTF(ENVONLY, c_str))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_class_name: out of memory - unable to construct string from UTF characters"); + } - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter */ +done: + if (c_str) + H5free_memory(c_str); + + return j_str; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1class_1name */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_driver + * Method: H5Pget_class_parent * Signature: (J)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1driver - (JNIEnv *env, jclass clss, jlong plist) +Java_hdf_hdf5lib_H5_H5Pget_1class_1parent + (JNIEnv *env, jclass clss, jlong plid) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Pget_driver((hid_t) plist); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Pget_class_parent((hid_t)plid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1driver */ +} /* end Java_hdf_hdf5lib_H5_H5Pget_1class_1parent */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_cache - * Signature: (JIJJD)I + * Method: H5Pisa_class + * Signature: (JJ)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1cache - (JNIEnv *env, jclass clss, jlong plist, jint mdc_nelmts, jlong rdcc_nelmts, - jlong rdcc_nbytes, jdouble rdcc_w0) +Java_hdf_hdf5lib_H5_H5Pisa_1class + (JNIEnv *env, jclass clss, jlong plid, jlong pcls) { - herr_t retVal = -1; + htri_t retVal = FAIL; - retVal = H5Pset_cache((hid_t)plist, (int)mdc_nelmts, (size_t)rdcc_nelmts, - (size_t)rdcc_nbytes, (double) rdcc_w0); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1cache */ + if ((retVal = H5Pisa_class((hid_t)plid, (hid_t)pcls)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pisa_1class */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_cache - * Signature: (J[I[J[J[D)I + * Method: H5Pget + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1cache - (JNIEnv *env, jclass clss, jlong plist, jintArray mdc_nelmts, - jlongArray rdcc_nelmts, jlongArray rdcc_nbytes, jdoubleArray rdcc_w0) +Java_hdf_hdf5lib_H5_H5Pget + (JNIEnv *env, jclass clss, jlong plid, jstring name) { - herr_t status = -1; - jint mode; - jdouble *w0Array = (jdouble *)NULL; - jlong *rdcc_nelmtsArray = (jlong *)NULL; - jlong *nbytesArray = (jlong *)NULL; - jboolean isCopy; - - if (rdcc_w0 != NULL) { - w0Array = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR rdcc_w0, &isCopy); - if (w0Array == NULL) { - h5JNIFatalError(env, "H5Pget_cache: w0_array array not pinned"); - return -1; - } /* end if */ - } /* end else */ - - if (rdcc_nelmts != NULL) { - rdcc_nelmtsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nelmts, &isCopy); - if (rdcc_nelmtsArray == NULL) { - /* exception -- out of memory */ - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, JNI_ABORT); - } - h5JNIFatalError(env, "H5Pget_cache: rdcc_nelmts array not pinned"); - return -1; - } /* end if */ - } /* end else */ - - if (rdcc_nbytes != NULL) { - nbytesArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nbytes, &isCopy); - if (nbytesArray == NULL) { - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, JNI_ABORT); - } /* end if */ - if (rdcc_nelmtsArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nelmts, rdcc_nelmtsArray, JNI_ABORT); - } /* end if */ - h5JNIFatalError(env, "H5Pget_cache: nbytesArray array not pinned"); - return -1; - } /* end if */ - } /* end else */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long rdcc_nelmts_temp = *(rdcc_nelmtsArray); - size_t rdcc_nelmts_t = (size_t)rdcc_nelmts_temp; - long long nbytes_temp = *(nbytesArray); - size_t nbytes_t = (size_t)nbytes_temp; - - status = H5Pget_cache((hid_t)plist, (int *)NULL, &rdcc_nelmts_t, - &nbytes_t, (double *)w0Array); - - *rdcc_nelmtsArray = (jlong)rdcc_nelmts_t; - *nbytesArray = (jlong)nbytes_t; - } /* end direct cast special */ - - - if (status < 0) { - mode = JNI_ABORT; - } /* end if */ - else { - mode = 0; /* commit and free */ - } /* end else */ + const char *cstr = NULL; + jint val; + herr_t status = FAIL; - if (rdcc_nelmtsArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nelmts, rdcc_nelmtsArray, mode); - } /* end if */ + UNUSED(clss); - if (nbytesArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nbytes, nbytesArray, mode); - } /* end if */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pget: property name not pinned"); - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, mode); - } /* end if */ + if ((status = H5Pget((hid_t)plid, cstr, &val)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) { - h5libraryError(env); - } /* end if */ +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1cache */ + return (jint)val; +} /* end Java_hdf_hdf5lib_H5_H5Pget */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_buffer - * Signature: (JJ[B[B)I + * Method: H5Pequal + * Signature: (JJ)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1buffer - (JNIEnv *env, jclass clss, jlong plist, jlong size, jbyteArray tconv, jbyteArray bkg) +Java_hdf_hdf5lib_H5_H5Pequal + (JNIEnv *env, jclass clss, jlong plid1, jlong plid2) { - h5unimplemented(env, "H5Pset_buffer: not implemented"); - return -1; -#ifdef notdef - -/* DON'T IMPLEMENT THIS!!! */ - jint status = -1; - jbyte *tconvP; - jbyte *bkgP; - jboolean isCopy; - - if (tconv == NULL) - tconvP = (jbyte *)NULL; - else { - tconvP = ENVPTR->GetByteArrayElements(ENVPAR tconv, &isCopy); - if (tconvP == NULL) { - h5JNIFatalError(env, "H5Pset_buffer: tconv not pinned"); - return -1; - } - } - if (bkg == NULL) - bkgP = (jbyte *)NULL; - else { - bkgP = ENVPTR->GetByteArrayElements(ENVPAR bkg, &isCopy); - if (bkgP == NULL) { - h5JNIFatalError(env, "H5Pset_buffer: bkg not pinned"); - return -1; - } - } + htri_t retVal = FAIL; - status = H5Pset_buffer((hid_t)plist, (size_t)size, tconvP, bkgP); - if (status < 0) { - if (tconv != NULL) - ENVPTR->ReleaseByteArrayElements(ENVPAR tconv, tconvP, JNI_ABORT); - if (bkg != NULL) - ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, JNI_ABORT); - h5libraryError(env); - return -1; - } + UNUSED(clss); - if (tconv != NULL) - ENVPTR->ReleaseByteArrayElements(ENVPAR tconv, tconvP, 0); - if (bkg != NULL) - ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, 0); + if ((retVal = H5Pequal((hid_t)plid1, (hid_t)plid2)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)status; -#endif -} /* end Java_hdf_hdf5lib_H5_H5Pset_1buffer */ +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pequal */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_buffer - * Signature: (J[B[B)I + * Method: H5Piterate + * Signature: (J[ILjava/lang/Object;Ljava/lang/Object;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1buffer - (JNIEnv *env, jclass clss, jlong plist, jbyteArray tconv, jbyteArray bkg) +Java_hdf_hdf5lib_H5_H5Piterate + (JNIEnv *env, jclass clss, jlong prop_id, jintArray idx, jobject callback_op, jobject op_data) { - h5unimplemented(env, "H5Pget_buffer: not implemented"); - return -1; -#ifdef notdef - -/* DON'T IMPLEMENT THIS!!! */ - jlong status = -1; - jbyte *tconvP; - jbyte *bkgP; - jboolean isCopy; - - if (tconv == NULL) { - h5nullArgument(env, "H5Pget_buffer: tconv input array is NULL"); - return -1; - } - tconvP = ENVPTR->GetByteArrayElements(ENVPAR tconv, &isCopy); - if (tconvP == NULL) { - h5JNIFatalError(env, "H5Pget_buffer: tconv not pinned"); - return -1; - } - if (bkg == NULL) { - h5nullArgument(env, "H5Pget_buffer: bkg array is NULL"); - return -1; - } - bkgP = ENVPTR->GetByteArrayElements(ENVPAR bkg, &isCopy); - if (bkgP == NULL) { - h5JNIFatalError(env, "H5Pget_buffer: bkg not pinned"); - return -1; + cb_wrapper wrapper = { callback_op, op_data }; + jboolean isCopy; + jint *theArray = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + ENVPTR->GetJavaVM(ENVONLY, &jvm); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == op_data) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Piterate: op_data is NULL"); + if (NULL == callback_op) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Piterate: callback_op is NULL"); + + if (NULL == idx) { + if ((status = H5Piterate((hid_t)prop_id, NULL, (H5P_iterate_t)H5P_iterate_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); } + else { + PIN_INT_ARRAY(ENVONLY, idx, theArray, &isCopy, "H5Piterate: idx not pinned"); - status = H5Pget_buffer((hid_t)plist, tconvP, bkgP); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR tconv, tconvP, JNI_ABORT); - ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, JNI_ABORT); - h5libraryError(env); - return -1; + if ((status = H5Piterate((hid_t)prop_id, (int *)&theArray[0], (H5P_iterate_t)H5P_iterate_cb, (void *)&wrapper)) < 0) + H5_LIBRARY_ERROR(ENVONLY); } - ENVPTR->ReleaseByteArrayElements(ENVPAR tconv, tconvP, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, 0); - return (jint)status; -#endif -} /* end Java_hdf_hdf5lib_H5_H5Pget_1buffer */ +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, idx, theArray, (status < 0) ? JNI_ABORT : 0); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_buffer_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size - (JNIEnv *env, jclass clss, jlong plist, jlong size) -{ - if (H5Pset_buffer((hid_t)plist, (size_t)size, NULL, NULL) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size */ + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5Piterate */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_buffer_size - * Signature: (J)J + * Method: H5Pcopy_prop + * Signature: (JJLjava/lang/String;)I */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size - (JNIEnv *env, jclass clss, jlong plist) +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pcopy_1prop + (JNIEnv *env, jclass clss, jlong dst_plid, jlong src_plid, jstring name) { - size_t size = 0; + const char *cstr = NULL; + herr_t retVal = FAIL; - size = H5Pget_buffer((hid_t)plist, NULL, NULL); - if (size == 0) - h5libraryError(env); + UNUSED(clss); - return (jlong)size; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Pcopy_prop: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_preserve - * Signature: (JZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1preserve - (JNIEnv *env, jclass clss, jlong plist, jboolean status) -{ - hbool_t st; - herr_t retVal = -1; - - if (status == JNI_TRUE) { - st = TRUE; - } /* end if */ - else if (status == JNI_FALSE) { - st = false; - } /* end else if */ - else { - h5badArgument(env, "H5Pset_preserve: status not TRUE or FALSE"); - return -1; - } /* end else */ + if ((retVal = H5Pcopy_prop((hid_t)dst_plid, (hid_t)src_plid, cstr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Pset_preserve((hid_t)plist, st); - if (retVal < 0) - h5libraryError(env); +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1preserve */ +} /* end Java_hdf_hdf5lib_H5_H5Pcopy_1prop */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_preserve - * Signature: (J)I + * Method: H5Premove + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1preserve - (JNIEnv *env, jclass clss, jlong plist) +Java_hdf_hdf5lib_H5_H5Premove + (JNIEnv *env, jclass clss, jlong plid, jstring name) { - herr_t retVal = -1; + const char *cstr = NULL; + herr_t retVal = FAIL; - retVal = H5Pget_preserve((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1preserve */ + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Premove: property name not pinned"); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_deflate - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1deflate - (JNIEnv *env, jclass clss, jlong plist, jint level) -{ - herr_t retVal = -1; + if ((retVal = H5Premove((hid_t)plid, cstr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Pset_deflate((hid_t)plist, (unsigned)level); - if (retVal < 0) - h5libraryError(env); +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1deflate */ +} /* end Java_hdf_hdf5lib_H5_H5Premove */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_gc_references - * Signature: (JZ)I + * Method: H5Punregister + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1gc_1references - (JNIEnv *env, jclass clss, jlong fapl_id, jboolean gc_ref) +Java_hdf_hdf5lib_H5_H5Punregister + (JNIEnv *env, jclass clss, jlong plid, jstring name) { - herr_t retVal = -1; - unsigned gc_ref_val; + const char *cstr = NULL; + herr_t retVal = FAIL; - if (gc_ref == JNI_TRUE) - gc_ref_val = 1; - else - gc_ref_val = 0; + UNUSED(clss); - retVal = H5Pset_gc_references((hid_t)fapl_id, gc_ref_val); - if (retVal < 0) - h5libraryError(env); + PIN_JAVA_STRING(ENVONLY, name, cstr, NULL, "H5Punregister: property name not pinned"); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1gc_1references */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_gc_references - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1gc_1references - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - unsigned gc_ref_val = 0; - jboolean bval = JNI_FALSE; + if ((retVal = H5Punregister((hid_t)plid, cstr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (H5Pget_gc_references((hid_t)fapl_id, (unsigned *)&gc_ref_val) < 0) { - h5libraryError(env); - } /* end if */ - else { - if (gc_ref_val == 1) - bval = JNI_TRUE; - } /* end else */ +done: + if (cstr) + UNPIN_JAVA_STRING(ENVONLY, name, cstr); - return bval; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1gc_1references */ + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Punregister */ /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_btree_ratios - * Signature: (JDDD)I + * Method: _H5Pclose_class + * Signature: (J)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios - (JNIEnv *env, jclass clss, jlong plist_id, jdouble left, jdouble middle, jdouble right) +Java_hdf_hdf5lib_H5__1H5Pclose_1class + (JNIEnv *env, jclass clss, jlong plid) { - herr_t status = -1; + herr_t retVal = FAIL; - status = H5Pset_btree_ratios((hid_t)plist_id, (double)left,(double)middle, (double)right); - if (status < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios */ + if ((retVal = H5Pclose_class((hid_t)plid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_btree_ratios - * Signature: (J[D[D[D)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios - (JNIEnv *env, jclass clss, jlong plist_id, jdoubleArray left, - jdoubleArray middle, jdoubleArray right) +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5__1H5Pclose_1class */ + +static herr_t +H5P_cls_create_cb + (hid_t prop_id, void *create_data) { - herr_t status = -1; - jdouble *leftP; - jdouble *middleP; - jdouble *rightP; - jboolean isCopy; - - if (left == NULL) { - h5nullArgument(env, "H5Pget_btree_ratios: left input array is NULL"); - } /* end if */ - else if (middle == NULL) { - h5nullArgument(env, "H5Pget_btree_ratios: middle input array is NULL"); - } /* end else if */ - else if (right == NULL) { - h5nullArgument(env, "H5Pget_btree_ratios: right input array is NULL"); - } /* end else if */ - else { - leftP = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR left, &isCopy); - if (leftP == NULL) { - h5JNIFatalError(env, "H5Pget_btree_ratios: left not pinned"); - } /* end if */ - else { - middleP = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR middle, &isCopy); - if (middleP == NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR left, leftP, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_btree_ratios: middle not pinned"); - } /* end if */ - else { - rightP = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR right, &isCopy); - if (rightP == NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR left, leftP, JNI_ABORT); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR middle, middleP, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_btree_ratios: middle not pinned"); - } /* end if */ - else { - status = H5Pget_btree_ratios((hid_t)plist_id, (double *)leftP, - (double *)middleP, (double *)rightP); - if (status < 0) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR left, leftP, JNI_ABORT); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR middle, middleP, JNI_ABORT); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR right, rightP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR left, leftP, 0); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR middle, middleP, 0); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR right, rightP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jmethodID mid; + JNIEnv *cbenv = NULL; + jclass cls; + jint status = -1; - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_cls_create_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_small_data_block_size - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size - (JNIEnv *env, jclass clss, jlong plist, jlong size) -{ - long sz = (long)size; - herr_t retVal = -1; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, create_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_small_data_block_size((hid_t)plist, (hsize_t)sz); - if (retVal < 0) - h5libraryError(env); + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLhdf/hdf5lib/callbacks/H5P_cls_create_func_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size */ + status = CBENVPTR->CallIntMethod(CBENVONLY, create_callback, mid, prop_id, create_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_small_data_block_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size - (JNIEnv *env, jclass clss, jlong plist) +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); + + return (herr_t)status; +} /* end H5P_cls_create_cb */ + +static herr_t +H5P_cls_copy_cb + (hid_t new_prop_id, hid_t old_prop_id, void *copy_data) { - hsize_t s; + jmethodID mid; + JNIEnv *cbenv = NULL; + jclass cls; + jint status = -1; - if (H5Pget_small_data_block_size((hid_t)plist, &s) < 0) - h5libraryError(env); + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_cls_copy_cb: failed to attach current thread to JVM"); + } - return (jlong)s; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size */ + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, copy_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_alloc_time - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time - (JNIEnv *env, jclass clss, jlong plist, jint alloc_time) -{ - herr_t retVal = -1; + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JJLhdf/hdf5lib/callbacks/H5P_cls_copy_func_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_alloc_time((hid_t)plist, (H5D_alloc_time_t)alloc_time); - if (retVal < 0) - h5libraryError(env); + status = CBENVPTR->CallIntMethod(CBENVONLY, copy_callback, mid, new_prop_id, old_prop_id, copy_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time */ +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_alloc_time - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time - (JNIEnv *env, jclass clss, jlong plist, jintArray alloc_time) + return (herr_t)status; +} /* end H5P_cls_copy_cb */ + +static herr_t +H5P_cls_close_cb + (hid_t prop_id, void *close_data) { - herr_t retVal = -1; - jint *theArray; - jboolean isCopy; - H5D_alloc_time_t time; - - if (alloc_time == NULL) { - /* exception ? */ - h5nullArgument(env, "H5Pget_alloc_time: alloc_time is NULL"); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR alloc_time, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_alloc_time: alloc_time not pinned"); - } /* end if */ - else { - retVal = H5Pget_alloc_time((hid_t)plist, &time); - if (retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR alloc_time, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = time; - ENVPTR->ReleaseIntArrayElements(ENVPAR alloc_time, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ + jmethodID mid; + JNIEnv *cbenv = NULL; + jclass cls; + jint status = -1; - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_cls_close_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fill_time - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fill_1time - (JNIEnv *env, jclass clss, jlong plist, jint fill_time) -{ - herr_t retVal = -1; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, close_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_fill_time((hid_t)plist, (H5D_fill_time_t)fill_time); - if (retVal < 0) - h5libraryError(env); + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLhdf/hdf5lib/callbacks/H5P_cls_close_func_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fill_1time */ + status = CBENVPTR->CallIntMethod(CBENVONLY, close_callback, mid, prop_id, close_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fill_time - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fill_1time - (JNIEnv *env, jclass clss, jlong plist, jintArray fill_time) -{ - herr_t retVal = -1; - jint *theArray; - jboolean isCopy; - H5D_fill_time_t time; - - if (fill_time == NULL) { - /* exception ? */ - h5nullArgument(env, "H5Pget_fill_time: fill_time is NULL"); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR fill_time, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_fill_time: fill_time not pinned"); - } /* end if */ - else { - retVal = H5Pget_fill_time((hid_t)plist, &time); - if (retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR fill_time, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jint)time; - ENVPTR->ReleaseIntArrayElements(ENVPAR fill_time, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fill_1time */ + return (herr_t)status; +} /* end H5P_cls_close_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pfill_value_defined - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined - (JNIEnv *env, jclass clss, jlong plist, jintArray status) +static herr_t +H5P_prp_create_cb + (const char *name, size_t size, void *value) { - herr_t retVal = -1; - jint *theArray; - jboolean isCopy; - H5D_fill_value_t value; - - if (status == NULL) { - /* exception ? */ - h5nullArgument(env, "H5Pfill_value_defined: status is NULL"); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR status, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pfill_value_defined: status not pinned"); - } /* end if */ - else { - retVal = H5Pfill_value_defined((hid_t)plist, &value); - if (retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR status, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = value; - ENVPTR->ReleaseIntArrayElements(ENVPAR status, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ + jmethodID mid; + jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_create_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fletcher32 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 - (JNIEnv *env, jclass clss, jlong plist) -{ - herr_t retVal = -1; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, create_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_fletcher32((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(Ljava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 */ + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_edc_check - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1edc_1check - (JNIEnv *env, jclass clss, jlong plist, jint check) -{ - herr_t retVal = -1; + status = CBENVPTR->CallIntMethod(CBENVONLY, create_callback, mid, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_edc_check((hid_t)plist, (H5Z_EDC_t)check); - if (retVal < 0) - h5libraryError(env); +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1edc_1check */ + return (herr_t)status; +} /* end H5P_prp_create_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_edc_check - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1edc_1check - (JNIEnv *env, jclass clss, jlong plist) +static herr_t +H5P_prp_set_cb + (hid_t prop_id, const char *name, size_t size, void *value) { - H5Z_EDC_t retVal = -1; - - retVal = H5Pget_edc_check((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + jmethodID mid; + jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1edc_1check */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_set_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shuffle - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shuffle - (JNIEnv *env, jclass clss, jlong plist) -{ - herr_t retVal = -1; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, set_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_shuffle((hid_t)plist); - if (retVal < 0) - h5libraryError(env); + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1shuffle */ + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_szip - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1szip - (JNIEnv *env, jclass clss, jlong plist, jint options_mask, jint pixels_per_block) -{ - herr_t retVal = -1; + status = CBENVPTR->CallIntMethod(CBENVONLY, set_callback, mid, prop_id, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_szip((hid_t)plist, (unsigned int)options_mask, (unsigned int)pixels_per_block); - if (retVal < 0) - h5libraryError(env); +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1szip */ + return (herr_t)status; +} /* end H5P_prp_set_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_hyper_vector_size - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size - (JNIEnv *env, jclass clss, jlong plist, jlong vector_size) +static herr_t +H5P_prp_get_cb + (hid_t prop_id, const char *name, size_t size, void *value) { - herr_t retVal = -1; + jmethodID mid; + jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - retVal = H5Pset_hyper_vector_size((hid_t)plist, (size_t)vector_size); - if (retVal < 0) - h5libraryError(env); + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_get_cb: failed to attach current thread to JVM"); + } - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size */ + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, get_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_hyper_vector_size - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size - (JNIEnv *env, jclass clss, jlong plist, jlongArray vector_size) -{ - herr_t retVal = -1; - jlong *theArray; - size_t size; - jboolean isCopy; - - if (vector_size == NULL) { - /* exception ? */ - h5nullArgument(env, "H5Pget_hyper_vector_size: vector_size is NULL"); - } /* end if */ - else { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR vector_size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_hyper_vector_size: vector_size not pinned"); - } /* end if */ - else { - retVal = H5Pget_hyper_vector_size((hid_t)plist, &size); - if (retVal < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR vector_size, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jlong)size; - ENVPTR->ReleaseLongArrayElements(ENVPAR vector_size, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size */ + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pall_filters_avail - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail - (JNIEnv *env, jclass clss, jlong dcpl_id) -{ - htri_t bval = JNI_FALSE; - - bval = H5Pall_filters_avail((hid_t)dcpl_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - - return (jboolean)bval; -} /* end Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pmodify_filter - * Signature: (JIIJ[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pmodify_1filter - (JNIEnv *env, jclass clss, jlong plist, jint filter, - jint flags, jlong cd_nelmts, jintArray cd_values) -{ - herr_t status = -1; - jint *cd_valuesP; - jboolean isCopy; - - if (cd_values == NULL) { - h5nullArgument(env, "H5Pmodify_filter: cd_values is NULL"); - } /* end if */ - else { - cd_valuesP = ENVPTR->GetIntArrayElements(ENVPAR cd_values,&isCopy); - if (cd_valuesP == NULL) { - h5JNIFatalError(env, "H5Pmodify_filter: cd_values not pinned"); - } /* end if */ - else { - status = H5Pmodify_filter((hid_t)plist, (H5Z_filter_t)filter,(const unsigned int)flags, - (size_t)cd_nelmts, (unsigned int *)cd_valuesP); - - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesP, JNI_ABORT); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pmodify_1filter */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter_by_id - * Signature: (JI[I[J[IJ[Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id - (JNIEnv *env, jclass clss, jlong plist, jint filter, - jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name) -{ - jboolean isCopy; - herr_t status = -1; - jint *cd_valuesArray; - jint *flagsArray; - jlong *cd_nelmtsArray; - jstring str; - char *aName; - int i = 0; - int rank; - long bs; - - bs = (long)namelen; - if (bs <= 0) { - h5badArgument(env, "H5Pget_filter_by_id: namelen <= 0"); - } /* end if */ - else if (flags == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: flags is NULL"); - } /* end else if */ - else if (cd_nelmts == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: cd_nelms is NULL"); - } /* end else if */ - else if (cd_values == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: cd_values is NULL"); - } /* end else if */ - else if (name == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: name is NULL"); - } /* end else if */ - else { - aName = (char*)HDmalloc(sizeof(char) * (size_t)bs); - if (aName == NULL) { - h5outOfMemory(env, "H5Pget_filter_by_id: malloc failed"); - return -1; - } /* end if */ - - flagsArray = ENVPTR->GetIntArrayElements(ENVPAR flags, &isCopy); - if (flagsArray == NULL) { - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: flags not pinned"); - return -1; - } /* end if */ - - cd_nelmtsArray = ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); - if (cd_nelmtsArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: cd_nelms not pinned"); - return -1; - } /* end if */ - - cd_valuesArray = ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - rank = ENVPTR->GetArrayLength(ENVPAR cd_values); - if (cd_valuesArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: cd_values array not converted to unsigned int."); - return -1; - } /* end if */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = *(cd_nelmtsArray); - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - unsigned int filter_config; - - status = H5Pget_filter_by_id2( (hid_t)plist, (H5Z_filter_t)filter, - (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, - (size_t)namelen, (char *)aName, &filter_config); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - } /* end direct cast special */ - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - HDfree(aName); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, 0); - - HDfree(aName); - } /* end else */ - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fclose_degree - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree - (JNIEnv *env, jclass clss, jlong plist, jint fc_degree) -{ - herr_t retVal = -1; - - retVal = H5Pset_fclose_degree((hid_t)plist, (H5F_close_degree_t)fc_degree); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fclose_degree - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree - (JNIEnv *env, jclass clss, jlong plist) -{ - H5F_close_degree_t degree; - - if (H5Pget_fclose_degree((hid_t)plist, °ree) < 0) - h5libraryError(env); - - return (jint)degree; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree */ - - -/********************************************************************** - * * - * File access properties * - * * - **********************************************************************/ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_family - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family - (JNIEnv *env, jclass clss, jlong plist, jlong memb_size, jlong memb_plist) -{ - long ms = (long)memb_size; - herr_t retVal = -1; - - retVal = H5Pset_fapl_family((hid_t)plist, (hsize_t)ms, (hid_t)memb_plist); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_family - * Signature: (J[J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family - (JNIEnv *env, jclass clss, jlong tid, jlongArray memb_size, jlongArray memb_plist) -{ - herr_t status = -1; - jlong *sizeArray; - jlong *plistArray; - jint mode = JNI_ABORT; - jboolean isCopy; - hsize_t *sa; - size_t i; - size_t rank; - - if (memb_size == NULL) { - h5nullArgument(env, "H5Pget_family: memb_size is NULL"); - } /* end if */ - else if (memb_plist == NULL) { - h5nullArgument(env, "H5Pget_family: memb_plist is NULL"); - } /* end else if */ - else { - sizeArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_size, &isCopy); - if (sizeArray == NULL) { - h5JNIFatalError(env, "H5Pget_family: sizeArray not pinned"); - } /* end if */ - else { - rank = (size_t)ENVPTR->GetArrayLength(ENVPAR memb_size); - sa = (hsize_t *)HDmalloc(rank * sizeof(hsize_t)); - if (sa == NULL) { - h5JNIFatalError(env, "H5Screate-simple: dims not converted to hsize_t"); - } /* end if */ - else { - plistArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_plist, &isCopy); - if (plistArray == NULL) { - h5JNIFatalError(env, "H5Pget_family: plistArray not pinned"); - } /* end if */ - else { - status = H5Pget_fapl_family ((hid_t)tid, sa, (hid_t *)plistArray); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < rank; i++) { - sizeArray[i] = (jlong)sa[i]; - } /* end for */ - mode = 0; - } /* end else */ - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_plist, plistArray, mode); - } - HDfree(sa); - } - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, mode); - } - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_core - * Signature: (JJZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core - (JNIEnv *env, jclass clss, jlong fapl_id, jlong increment, jboolean backing_store) -{ - herr_t retVal = -1; - - retVal = H5Pset_fapl_core((hid_t)fapl_id, (size_t)increment, (hbool_t)backing_store); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_core - * Signature: (J[J[Z)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core - (JNIEnv *env, jclass clss, jlong fapl_id, jlongArray increment, jbooleanArray backing_store) -{ - herr_t status = -1; - jint mode = JNI_ABORT; - jlong *incArray; - jboolean *backArray; - jboolean isCopy; - - if (increment == NULL) { - h5nullArgument(env, "H5Pget_fapl_core: increment is NULL"); - } /* end if */ - else if (backing_store == NULL) { - h5nullArgument(env, "H5Pget_fapl_core: backing_store is NULL"); - } /* end else if */ - else { - incArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR increment, &isCopy); - if (incArray == NULL) { - h5JNIFatalError(env, "H5Pget_fapl_core: incArray not pinned"); - } /* end if */ - else { - backArray = (jboolean *)ENVPTR->GetBooleanArrayElements(ENVPAR backing_store, &isCopy); - if (backArray == NULL) { - h5JNIFatalError(env, "H5Pget_fapl_core: backArray not pinned"); - } /* end if */ - else { - /* direct cast (size_t *)variable fails on 32-bit environment */ - long long inc_temp = *(incArray); - size_t inc_t = (size_t)inc_temp; - - status = H5Pget_fapl_core((hid_t)fapl_id, &inc_t, (hbool_t *)backArray); - - *incArray = (jlong)inc_t; - /* end direct cast special */ - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - mode = 0; - } /* end else */ - ENVPTR->ReleaseBooleanArrayElements(ENVPAR backing_store, backArray, mode); - } - ENVPTR->ReleaseLongArrayElements(ENVPAR increment, incArray, mode); - } - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_family_offset - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1family_1offset - (JNIEnv *env, jclass clss, jlong fapl_id, jlong offset) -{ - herr_t retVal = -1; - - retVal = H5Pset_family_offset ((hid_t)fapl_id, (hsize_t)offset); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1family_1offset */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_family_offset - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1family_1offset - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - hsize_t offset = 0; - herr_t retVal = -1; - - retVal = H5Pget_family_offset ((hid_t)fapl_id, &offset); - if (retVal < 0) - h5libraryError(env); - - return (jlong)offset; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1family_1offset */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_log - * Signature: (JLjava/lang/String;JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log - (JNIEnv *env, jclass clss, jlong fapl_id, jstring logfile, jlong flags, jlong buf_size) -{ - herr_t retVal = -1; - const char *pLogfile; - - PIN_JAVA_STRING(logfile, pLogfile); - if (pLogfile != NULL) { - retVal = H5Pset_fapl_log( (hid_t)fapl_id, pLogfile, (unsigned long long)flags, (size_t)buf_size ); - - UNPIN_JAVA_STRING(logfile, pLogfile); - - if (retVal < 0) - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Premove_filter - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5P1remove_1filter - (JNIEnv *env, jclass clss, jlong obj_id, jint filter) -{ - herr_t status = -1; - - status = H5Premove_filter ((hid_t)obj_id, (H5Z_filter_t)filter); - if (status < 0) - h5libraryError(env); - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5P1remove_1filter */ - - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset - * Signature: (JLjava/lang/String;I)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pset - (JNIEnv *env, jclass clss, jlong plid, jstring name, jint val) -{ - hid_t retVal = -1; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Pset((hid_t)plid, cstr, &val); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jlong)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pexist - * Signature: (JLjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pexist - (JNIEnv *env, jclass clss, jlong plid, jstring name) -{ - htri_t bval = JNI_FALSE; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - bval = H5Pexist((hid_t)plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); - - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } - - return (jboolean)bval; -} /* end Java_hdf_hdf5lib_H5_H5Pexist */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_size - * Signature: (JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1size - (JNIEnv *env, jclass clss, jlong plid, jstring name) -{ - hid_t retVal = -1; - const char *cstr; - size_t size = 0; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Pget_size((hid_t)plid, cstr, &size); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jlong) size; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nprops - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nprops - (JNIEnv *env, jclass clss, jlong plid) -{ - size_t nprops; - - if (H5Pget_nprops((hid_t)plid, &nprops) < 0) - h5libraryError(env); - - return (jlong)nprops; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1nprops */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_class_name - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1class_1name - (JNIEnv *env, jclass clss, jlong plid) -{ - char *c_str; - jstring j_str = NULL; - - c_str = H5Pget_class_name((hid_t)plid); - if (c_str == NULL) { - h5libraryError(env); - } /* end if */ - else { - j_str = ENVPTR->NewStringUTF(ENVPAR c_str); - H5free_memory(c_str); - - if (j_str == NULL) - h5JNIFatalError(env,"H5Pget_class_name: return string failed"); - } /* end else */ - return j_str; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1class_1name */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_class_parent - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1class_1parent - (JNIEnv *env, jclass clss, jlong plid) -{ - hid_t retVal = -1; - - retVal = H5Pget_class_parent((hid_t)plid); - if (retVal < 0) - h5libraryError(env); - - return (jlong)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1class_1parent */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pisa_class - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pisa_1class - (JNIEnv *env, jclass clss, jlong plid, jlong pcls) -{ - htri_t retVal = -1; - - retVal = H5Pisa_class((hid_t)plid, (hid_t)pcls); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pisa_1class */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget - (JNIEnv *env, jclass clss, jlong plid, jstring name) -{ - herr_t retVal = -1; - const char *cstr; - jint val; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Pget((hid_t)plid, cstr, &val); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jint)val; -} /* end Java_hdf_hdf5lib_H5_H5Pget */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pequal - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pequal - (JNIEnv *env, jclass clss, jlong plid1, jlong plid2) -{ - htri_t retVal = -1; - - retVal = H5Pequal((hid_t)plid1, (hid_t)plid2); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pequal */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pcopy_prop - * Signature: (JJLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pcopy_1prop - (JNIEnv *env, jclass clss, jlong dst_plid, jlong src_plid, jstring name) -{ - herr_t retVal = -1; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Pcopy_prop((hid_t)dst_plid, (hid_t)src_plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pcopy_1prop */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Premove - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Premove - (JNIEnv *env, jclass clss, jlong plid, jstring name) -{ - herr_t retVal = -1; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Premove((hid_t)plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Premove */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Punregister - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Punregister - (JNIEnv *env, jclass clss, jlong plid, jstring name) -{ - herr_t retVal = -1; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - retVal = H5Punregister((hid_t)plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); - - if (retVal < 0) - h5libraryError(env); - } - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Punregister */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pclose_class - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5__1H5Pclose_1class - (JNIEnv *env, jclass clss, jlong plid) -{ - herr_t retVal = -1; - - retVal = H5Pclose_class((hid_t)plid); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5__1H5Pclose_1class */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter2 - * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter2 - (JNIEnv *env, jclass clss, jlong plist, jint filter_number, - jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, - jobjectArray name, jintArray filter_config) -{ - herr_t status = -1; - jint *flagsArray; - jlong *cd_nelmtsArray; - jint *cd_valuesArray; - jint *filter_configArray; - jboolean isCopy; - char *filter; - jstring str; - - if (namelen <= 0) { - h5badArgument(env, "H5Pget_filter: namelen <= 0"); - } /* end if */ - else if (flags == NULL) { - h5badArgument(env, "H5Pget_filter: flags is NULL"); - } /* end else if */ - else if (cd_nelmts == NULL) { - h5badArgument(env, "H5Pget_filter: cd_nelmts is NULL"); - } /* end else if */ - else if (filter_config == NULL) { - h5badArgument(env, "H5Pget_filter: filter_config is NULL"); - } /* end else if */ - else { - filter = (char*)HDmalloc(sizeof(char)*(size_t)namelen); - if (filter == NULL) { - h5outOfMemory(env, "H5Pget_filter: namelent malloc failed"); - return -1; - } /* end if */ - flagsArray = (jint*)ENVPTR->GetIntArrayElements(ENVPAR flags, &isCopy); - if (flagsArray == NULL) { - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: flags array not pinned"); - return -1; - } /* end if */ - - cd_nelmtsArray = (jlong*)ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); - if (cd_nelmtsArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: nelmts array not pinned"); - return -1; - } /* end if */ - filter_configArray = (jint*)ENVPTR->GetIntArrayElements(ENVPAR filter_config, &isCopy); - if (filter_configArray == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: filter_config array not pinned"); - return -1; - } /* end if */ - - if (*cd_nelmtsArray == 0 && cd_values == NULL) { - /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = 0; - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - - status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, - (unsigned int *)flagsArray, &cd_nelmts_t, NULL, - (size_t)namelen, filter, (unsigned int *)filter_configArray); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - } /* end if */ - else { - if (cd_values == NULL) { - h5badArgument(env, "H5Pget_filter: cd_values is NULL"); - return -1; - } /* end if */ - cd_valuesArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - if (cd_valuesArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR filter_config, filter_configArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: elmts array not pinned"); - return -1; - } /* end if */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = *(cd_nelmtsArray); - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - - status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, - (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, - (size_t)namelen, filter, (unsigned int *)filter_configArray); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - } /* end direct cast special */ - } /* end else */ - - if (status < 0) { - if (cd_values) - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR filter_config, filter_configArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5libraryError(env); - } /* end if */ - else { - if (cd_values) - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR filter_config, filter_configArray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, 0); - /* NewStringUTF may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR filter); - HDfree(filter); - if (str == NULL) - h5JNIFatalError(env, "H5Pget_filter: return string not pinned"); - else - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - } /* end else */ - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter2 */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter_by_id2 - * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 - (JNIEnv *env, jclass clss, jlong plist, jint filter, - jintArray flags, jlongArray cd_nelmts, jintArray cd_values, jlong namelen, jobjectArray name, jintArray filter_config) -{ - herr_t status = -1; - int i = 0; - jint *cd_valuesArray; - jint *flagsArray; - jint *filter_configArray; - jlong *cd_nelmtsArray; - jboolean isCopy; - long bs; - char *aName; - jstring str; - - bs = (long)namelen; - if (bs <= 0) { - h5badArgument(env, "H5Pget_filter_by_id: namelen <= 0"); - } /* end if */ - else if (flags == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: flags is NULL"); - } /* end else if */ - else if (cd_nelmts == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: cd_nelms is NULL"); - } /* end else if */ - else if (cd_values == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: cd_values is NULL"); - } /* end else if */ - else if (name == NULL) { - h5nullArgument(env, "H5Pget_filter_by_id: name is NULL"); - } /* end else if */ - else if (filter_config == NULL) { - h5badArgument(env, "H5Pget_filter_by_id: filter_config is NULL"); - } /* end else if */ - else { - aName = (char*)HDmalloc(sizeof(char) * (size_t)bs); - if (aName == NULL) { - h5outOfMemory(env, "H5Pget_filter_by_id: malloc failed"); - return -1; - } /* end if */ - flagsArray = ENVPTR->GetIntArrayElements(ENVPAR flags,&isCopy); - if (flagsArray == NULL) { - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: flags not pinned"); - return -1; - } /* end if */ - cd_nelmtsArray = ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); - if (cd_nelmtsArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: cd_nelms not pinned"); - return -1; - } /* end if */ - cd_valuesArray = ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - if (cd_valuesArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: cd_values array not converted to unsigned int."); - return -1; - } /* end if */ - filter_configArray = ENVPTR->GetIntArrayElements(ENVPAR filter_config, &isCopy); - if (filter_configArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - HDfree(aName); - h5JNIFatalError(env, "H5Pget_filter_by_id: flags not pinned"); - return -1; - } /* end if */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = *(cd_nelmtsArray); - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - - status = H5Pget_filter_by_id2((hid_t)plist, (H5Z_filter_t)filter, - (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, - (size_t)namelen, (char *)aName, (unsigned int *)filter_configArray); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - } /* end direct cast special handling */ - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR filter_config, filter_configArray, JNI_ABORT); - HDfree(aName); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - HDfree(aName); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR filter_config, filter_configArray, 0); - } /* end else */ - } /* end else */ - - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nlinks - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nlinks - (JNIEnv *env, jclass clss, jlong lapl_id) -{ - size_t nlinks; - if (H5Pget_nlinks((hid_t)lapl_id, &nlinks) < 0) - h5libraryError(env); - - return (jlong) nlinks; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1nlinks */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_nlinks - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1nlinks - (JNIEnv *env, jclass clss, jlong lapl_id, jlong nlinks) -{ - herr_t retVal = -1; - - if (nlinks <= 0) { - h5badArgument(env, "H5Pset_1nlinks: nlinks_l <= 0"); - } /* end if */ - else { - retVal = H5Pset_nlinks((hid_t)lapl_id, (size_t)nlinks); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1nlinks */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_libver_bounds - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds - (JNIEnv *env, jclass clss, jlong fapl_id, jintArray libver) -{ - herr_t retVal = -1; - H5F_libver_t *theArray = NULL; - jboolean isCopy; - - if (libver == NULL) { - h5nullArgument(env, "H5Pget_libver_bounds: libversion bounds is NULL"); - } /* end if */ - else { - theArray = (H5F_libver_t*)ENVPTR->GetIntArrayElements(ENVPAR libver, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_libver_bounds: input not pinned"); - } /* end if */ - else { - retVal = H5Pget_libver_bounds((hid_t)fapl_id, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR libver, (jint*)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR libver, (jint*)theArray, 0); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_libver_bounds - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds - (JNIEnv *env, jclass clss, jlong fapl_id, jint low, jint high) -{ - herr_t retVal = -1; - - retVal = H5Pset_libver_bounds((hid_t)fapl_id, (H5F_libver_t)low, (H5F_libver_t)high); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_link_creation_order - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order - (JNIEnv *env, jclass clss, jlong gcpl_id) -{ - unsigned crt_order_flags; - - if(H5Pget_link_creation_order((hid_t)gcpl_id, &crt_order_flags) < 0) - h5libraryError(env); - - return (jint)crt_order_flags; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_link_creation_order - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order - (JNIEnv *env, jclass clss, jlong gcpl_id, jint crt_order_flags) -{ - herr_t retVal = -1; - - retVal = H5Pset_link_creation_order((hid_t)gcpl_id, (unsigned)crt_order_flags); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_attr_creation_order - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order - (JNIEnv *env, jclass clss, jlong ocpl_id) -{ - unsigned crt_order_flags; - - if(H5Pget_attr_creation_order((hid_t)ocpl_id, &crt_order_flags) < 0) - h5libraryError(env); - - return (jint)crt_order_flags; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_attr_creation_order - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order - (JNIEnv *env, jclass clss, jlong ocpl_id, jint crt_order_flags) -{ - herr_t retVal = -1; - - retVal = H5Pset_attr_creation_order((hid_t)ocpl_id, (unsigned)crt_order_flags); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_copy_object - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1copy_1object - (JNIEnv *env, jclass clss, jlong ocp_plist_id, jint copy_options) -{ - herr_t retVal = -1; - - retVal = H5Pset_copy_object((hid_t)ocp_plist_id, (unsigned)copy_options); - if(retVal < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1copy_1object */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_copy_object - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1copy_1object - (JNIEnv *env, jclass clss, jlong ocp_plist_id) -{ - unsigned copy_options; - - if(H5Pget_copy_object((hid_t)ocp_plist_id, ©_options) < 0) - h5libraryError(env); - - return (jint)copy_options; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1copy_1object */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_create_intermediate_group - * Signature: (JZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group - (JNIEnv *env, jclass clss, jlong lcpl_id, jboolean crt_intermed_group) -{ - herr_t retVal = -1; - - retVal = H5Pset_create_intermediate_group((hid_t)lcpl_id, (unsigned)crt_intermed_group); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_create_intermediate_group - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group - (JNIEnv *env, jclass clss, jlong lcpl_id) -{ - unsigned crt_intermed_group; - - if(H5Pget_create_intermediate_group((hid_t)lcpl_id, &crt_intermed_group) < 0) - h5libraryError(env); - - return (jboolean)crt_intermed_group; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_data_transform - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1data_1transform - (JNIEnv *env, jclass clss, jlong plist_id, jstring expression) -{ - herr_t retVal = -1; - const char *express; - - PIN_JAVA_STRING(expression, express); - if (express != NULL) { - retVal = H5Pset_data_transform((hid_t)plist_id, express); - - UNPIN_JAVA_STRING(expression, express); - - if (retVal < 0) - h5libraryError(env); - } - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1data_1transform */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_data_transform - * Signature: (J[Ljava/lang/String;J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1data_1transform - (JNIEnv *env, jclass clss, jlong plist_id, jobjectArray expression, jlong size) -{ - size_t buf_size; - char *express; - jlong express_size = -1; - jstring str = NULL; - - if (size <= 0) { - h5badArgument(env, "H5Pget_data_transform: size <= 0"); - } /* end if */ - else { - express_size = (jlong)H5Pget_data_transform((hid_t)plist_id, (char*)NULL, (size_t)size); - if(express_size < 0) { - h5libraryError(env); - } /* end if */ - else { - buf_size = (size_t)express_size + 1;/* add extra space for the null terminator */ - express = (char*)HDmalloc(sizeof(char) * buf_size); - if (express == NULL) { - h5outOfMemory(env, "H5Pget_data_transform: malloc failed "); - } /* end if */ - else { - express_size = (jlong)H5Pget_data_transform((hid_t)plist_id, express, (size_t)size); - if (express_size < 0) { - HDfree(express); - h5libraryError(env); - } - else { - str = ENVPTR->NewStringUTF(ENVPAR express); - HDfree(express); - if (str == NULL) - h5JNIFatalError(env, "H5Pget_data_transform: return string not created"); - else - ENVPTR->SetObjectArrayElement(ENVPAR expression, 0, str); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - return express_size; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1data_1transform */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_acc_flags - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags - (JNIEnv *env, jclass clss, jlong lapl_id) -{ - unsigned flags; - - if(H5Pget_elink_acc_flags((hid_t)lapl_id, &flags) < 0) - h5libraryError(env); - - return (jint)flags; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_acc_flags - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags - (JNIEnv *env, jclass clss, jlong lapl_id, jint flags) -{ - herr_t retVal = -1; - - retVal = H5Pset_elink_acc_flags((hid_t)lapl_id, (unsigned)flags); - if (retVal < 0) - h5libraryError(env); - - return (jint) retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_link_phase_change - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change - (JNIEnv *env, jclass clss, jlong gcpl_id, jint max_compact, jint min_dense) -{ - herr_t retVal = -1; - - if(max_compact < min_dense) { - h5badArgument(env, "H5Pset_link_phase_change: max compact value must be >= min dense value"); - } /* end if */ - else if(max_compact > 65535) { - h5badArgument(env, "H5Pset_link_phase_change: max compact value must be < 65536"); - } /* end else if */ - else if(min_dense > 65535) { - h5badArgument(env, "H5Pset_link_phase_change: min dense value must be < 65536"); - } /* end else if */ - else { - retVal = H5Pset_link_phase_change((hid_t)gcpl_id, (unsigned)max_compact, (unsigned)min_dense); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_link_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change - (JNIEnv *env, jclass clss, jlong gcpl_id, jintArray links) -{ - herr_t retVal = -1; - unsigned *theArray = NULL; - jboolean isCopy; - - if (links == NULL) { - h5nullArgument( env, "H5Pget_link_phase_change: links is NULL"); - } /* end if */ - else { - theArray = (unsigned *)ENVPTR->GetIntArrayElements(ENVPAR links, &isCopy); - if (theArray == NULL) { - h5JNIFatalError( env, "H5Pget_link_phase_change: input not pinned"); - } /* end if */ - else { - retVal = H5Pget_link_phase_change((hid_t)gcpl_id, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR links, (jint *)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR links, (jint *)theArray, 0); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_attr_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change - (JNIEnv *env, jclass clss, jlong ocpl_id, jintArray attributes) -{ - herr_t retVal = -1; - unsigned *theArray = NULL; - jboolean isCopy; - - if (attributes == NULL) { - h5nullArgument(env, "H5Pget_attr_phase_change: attributes is NULL"); - } /* end if */ - else { - theArray = (unsigned *)ENVPTR->GetIntArrayElements(ENVPAR attributes, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_attr_phase_change: input not pinned"); - } /* end if */ - else { - retVal = H5Pget_attr_phase_change((hid_t)ocpl_id, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR attributes, (jint *)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR attributes, (jint *)theArray, 0); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_attr_phase_change - * Signature: (JII)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change - (JNIEnv *env, jclass clss, jlong ocpl_id, jint max_compact, jint min_dense) -{ - herr_t retVal = -1; - - retVal = H5Pset_attr_phase_change((hid_t)ocpl_id, (unsigned)max_compact, (unsigned)min_dense); - if(retVal < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change - (JNIEnv *env, jclass clss, jlong fcpl_id, jintArray size) -{ - herr_t retVal = -1; - unsigned *theArray = NULL; - jboolean isCopy; - - if (size == NULL) { - h5nullArgument(env, "H5Pget_shared_mesg_phase_change: size is NULL"); - } /* end if */ - else { - theArray = (unsigned *)ENVPTR->GetIntArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_shared_mesg_phase_change: input not pinned"); - } /* end if */ - else { - retVal = H5Pget_shared_mesg_phase_change((hid_t)fcpl_id, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR size, (jint *)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR size, (jint *)theArray, 0); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_phase_change - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change - (JNIEnv *env, jclass clss, jlong fcpl_id, jint max_list, jint min_btree) -{ - herr_t retVal = -1; - - /* Check that values are sensible. The min_btree value must be no greater - * than the max list plus one. - * - * Range check to make certain they will fit into encoded form. - */ - - if(max_list + 1 < min_btree) { - h5badArgument(env, "H5Pset_shared_mesg_phase_change: minimum B-tree value is greater than maximum list value"); - } /* end if */ - else if(max_list > H5O_SHMESG_MAX_LIST_SIZE) { - h5badArgument(env, "H5Pset_shared_mesg_phase_change: max list value is larger than H5O_SHMESG_MAX_LIST_SIZE"); - } /* end else if */ - else if(min_btree > H5O_SHMESG_MAX_LIST_SIZE) { - h5badArgument(env, "H5Pset_shared_mesg_phase_change: min btree value is larger than H5O_SHMESG_MAX_LIST_SIZE"); - } /* end else if */ - else { - retVal = H5Pset_shared_mesg_phase_change((hid_t)fcpl_id, (unsigned)max_list, (unsigned)min_btree); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_nindexes - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes - (JNIEnv *env, jclass clss, jlong fcpl_id) -{ - unsigned nindexes; - - if(H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes) < 0) - h5libraryError(env); - - return (jint)nindexes; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_nindexes - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes - (JNIEnv *env, jclass clss, jlong plist_id, jint nindexes) -{ - herr_t retVal = -1; - - if (nindexes > H5O_SHMESG_MAX_NINDEXES) { - h5badArgument(env, "H5Pset_shared_mesg_nindexes: number of indexes is greater than H5O_SHMESG_MAX_NINDEXES"); - } /* end if */ - else { - retVal = H5Pset_shared_mesg_nindexes((hid_t)plist_id, (unsigned)nindexes); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_index - * Signature: (JIII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index - (JNIEnv *env, jclass clss, jlong fcpl_id, jint index_num, - jint mesg_type_flags, jint min_mesg_size) -{ - herr_t retVal = -1; - unsigned nindexes;/* Number of SOHM indexes */ - - /* Check arguments */ - if(mesg_type_flags > H5O_SHMESG_ALL_FLAG) { - h5badArgument(env, "H5Pset_shared_mesg_index: unrecognized flags in mesg_type_flags"); - } /* end if */ - else if(H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes) < 0) { /* Read the current number of indexes */ - h5libraryError(env); - } /* end else if */ - else { - /* Range check */ - if((unsigned)index_num >= nindexes) { - h5badArgument(env, "H5Pset_shared_mesg_index: index_num is too large; no such index"); - } /* end if */ - else { - retVal = H5Pset_shared_mesg_index((hid_t)fcpl_id, (unsigned)index_num, (unsigned) mesg_type_flags, (unsigned) min_mesg_size); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_index - * Signature: (JI[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index - (JNIEnv *env, jclass clss, jlong fcpl_id, jint index_num, jintArray mesg_info) -{ - herr_t retVal = -1; - unsigned nindexes;/* Number of SOHM indexes */ - unsigned *theArray = NULL; - jboolean isCopy; - - /* Read the current number of indexes */ - if(H5Pget_shared_mesg_nindexes((hid_t)fcpl_id, &nindexes)<0) { - h5libraryError(env); - } /* end if */ - else { - /* Range check */ - if((unsigned)index_num >= nindexes) { - h5badArgument(env, "H5Pget_shared_mesg_index: index_num is too large; no such index"); - } /* end if */ - else if (mesg_info == NULL) { - h5nullArgument(env, "H5Pget_shared_mesg_index: mesg_info is NULL"); - } /* end else if */ - else { - theArray = (unsigned *)ENVPTR->GetIntArrayElements(ENVPAR mesg_info, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_shared_mesg_index: input not pinned"); - } /* end if */ - else { - retVal = H5Pget_shared_mesg_index((hid_t)fcpl_id, (unsigned)index_num, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR mesg_info, (jint*)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR mesg_info, (jint*)theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_local_heap_size_hint - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint - (JNIEnv *env, jclass clss, jlong gcpl_id, jlong size_hint) -{ - herr_t retVal = -1; - - retVal = H5Pset_local_heap_size_hint((hid_t)gcpl_id, (size_t)size_hint); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_local_heap_size_hint - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint - (JNIEnv *env, jclass clss, jlong gcpl_id) -{ - size_t size_hint; - - if(H5Pget_local_heap_size_hint((hid_t)gcpl_id, &size_hint) < 0) - h5libraryError(env); - - return (jlong)size_hint; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_nbit - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1nbit - (JNIEnv *env, jclass clss, jlong plist_id) -{ - herr_t retVal = -1; - - retVal = H5Pset_nbit((hid_t)plist_id); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1nbit */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_scaleoffset - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset - (JNIEnv *env, jclass clss, jlong plist_id, jint scale_type, jint scale_factor) -{ - herr_t retVal = -1; - - /* Check arguments */ - if(scale_factor < 0) { - h5badArgument(env, "H5Pset_scaleoffset: scale factor must be > 0"); - } /* end if */ - else { - if(scale_type != H5Z_SO_FLOAT_DSCALE && scale_type != H5Z_SO_FLOAT_ESCALE && scale_type != H5Z_SO_INT){ - h5badArgument(env, "H5Pset_scaleoffset: invalid scale type"); - } /* end if */ - else { - retVal = H5Pset_scaleoffset((hid_t)plist_id, (H5Z_SO_scale_type_t)scale_type, scale_factor); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_est_link_info - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info - (JNIEnv *env, jclass clss, jlong gcpl_id, jint est_num_entries, jint est_name_len) -{ - herr_t retVal = -1; - - /* Range check values */ - if((est_num_entries > 65535) || (est_name_len > 65535)) { - h5badArgument(env, "H5Pset_est_link_info: est. name length or number of entries must be < 65536"); - } /* end if */ - else { - retVal = H5Pset_est_link_info((hid_t)gcpl_id, (unsigned)est_num_entries, (unsigned)est_name_len); - if(retVal < 0) - h5libraryError(env); - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_est_link_info - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info - (JNIEnv *env, jclass clss, jlong gcpl_id, jintArray link_info) -{ - herr_t retVal = -1; - unsigned *theArray = NULL; - jboolean isCopy; - - if (link_info == NULL) { - h5nullArgument(env, "H5Pget_est_link_info: link_info is NULL"); - } /* end if */ - else { - theArray = (unsigned *)ENVPTR->GetIntArrayElements(ENVPAR link_info,&isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_est_link_info: input not pinned"); - } /* end if */ - else { - retVal= H5Pget_est_link_info((hid_t)gcpl_id, &(theArray[0]), &(theArray[1])); - if(retVal < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR link_info, (jint *)theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR link_info, (jint *)theArray, 0); - } /* end else */ - } /* end else */ - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_fapl - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl - (JNIEnv *env, jclass clss, jlong lapl_id, jlong fapl_id) -{ - herr_t retVal = -1; - - retVal = H5Pset_elink_fapl((hid_t)lapl_id, (hid_t)fapl_id); - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pget_elink_fapl - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl - (JNIEnv *env, jclass clss, jlong lapl_id) -{ - hid_t retVal = -1; - - retVal = H5Pget_elink_fapl((hid_t)lapl_id); - if (retVal < 0) - h5libraryError(env); - - return (jlong)retVal; -} /* end Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_prefix - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix - (JNIEnv *env, jclass clss, jlong lapl_id, jstring prefix) -{ - herr_t retVal = -1; - const char *aName; - - PIN_JAVA_STRING(prefix, aName); - if (aName != NULL) { - retVal = H5Pset_elink_prefix((hid_t)lapl_id, aName); - - UNPIN_JAVA_STRING(prefix, aName); - - if(retVal < 0) - h5libraryError(env); - } - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_prefix - * Signature: (J[Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix - (JNIEnv *env, jclass clss, jlong lapl_id, jobjectArray prefix) -{ - size_t size = 0; - char *pre; - jlong prefix_size = -1; - jstring str = NULL; - - if (prefix == NULL) { - h5nullArgument(env, "H5Pget_elink_prefix: prefix is NULL"); - } /* end if */ - else { - prefix_size = (jlong)H5Pget_elink_prefix((hid_t)lapl_id, (char*)NULL, size); - if(prefix_size < 0) { - h5libraryError(env); - } /* end if */ - else { - size = (size_t)prefix_size + 1;/* add extra space for the null terminator */ - pre = (char*)HDmalloc(sizeof(char)*size); - if (pre == NULL) { - h5outOfMemory(env, "H5Pget_elink_prefix: malloc failed "); - } /* end if */ - else { - prefix_size = (jlong)H5Pget_elink_prefix((hid_t)lapl_id, (char*)pre, size); - - if (prefix_size < 0) { - HDfree(pre); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR pre); - HDfree(pre); - if (str == NULL) { - h5JNIFatalError(env, "H5Pget_elink_prefix: return string not created"); - } /* end if */ - else - ENVPTR->SetObjectArrayElement(ENVPAR prefix, 0, str); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - - return prefix_size; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_direct - * Signature: (JJJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct - (JNIEnv *env, jclass clss, jlong fapl_id, jlong alignment, - jlong block_size, jlong cbuf_size) -{ - herr_t retVal = -1; - -#ifdef H5_HAVE_DIRECT - retVal = H5Pset_fapl_direct((hid_t)fapl_id, (size_t)alignment, (size_t)block_size, (size_t)cbuf_size); -#endif - if(retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_direct - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct - (JNIEnv *env, jclass clss, jlong fapl_id, jlongArray info) -{ - herr_t retVal = -1; - -#ifdef H5_HAVE_DIRECT - size_t alignment = 0; - size_t block_size = 0; - size_t cbuf_size = 0; - jlong *theArray; - jboolean isCopy; - if (info == NULL) { - h5nullArgument(env, "H5Pget_fapl_direct: info input array is NULL"); - } /* end if */ - else { - if (ENVPTR->GetArrayLength(ENVPAR info) < 3) { - h5badArgument( env, "H5Pget_fapl_direct: info input array < 4"); - } /* end if */ - else { - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR info, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Pget_fapl_direct: info not pinned"); - } /* end if */ - else { - retVal = H5Pget_fapl_direct((hid_t)fapl_id, &alignment, &block_size, &cbuf_size); - if(retVal < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR info, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - theArray[0] = (jlong)alignment; - theArray[1] = (jlong)block_size; - theArray[2] = (jlong)cbuf_size; - ENVPTR->ReleaseLongArrayElements(ENVPAR info, theArray, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ -#else - if (retVal < 0) - h5libraryError(env); -#endif - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_sec2 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - herr_t retVal = -1; - - retVal = H5Pset_fapl_sec2((hid_t) fapl_id); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_stdio - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - herr_t retVal = -1; - - retVal = H5Pset_fapl_stdio((hid_t) fapl_id); - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_windows - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - herr_t retVal = -1; - -#ifdef H5_HAVE_WINDOWS - retVal = H5Pset_fapl_windows((hid_t) fapl_id); -#endif - if (retVal < 0) - h5libraryError(env); - - return (jint)retVal; -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_muti - * Signature: (J[I[J[Ljava/lang/String;[J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1multi - (JNIEnv *env, jclass clss, jlong tid, jintArray memb_map, - jlongArray memb_fapl, jobjectArray memb_name, jlongArray memb_addr) -{ - herr_t status = -1; - int i; - jint *themapArray = NULL; - jlong *thefaplArray = NULL; - jlong *theaddrArray = NULL; - char **mName = NULL; - jstring str; - jboolean isCopy; - int relax = 0; - - if (memb_map) { - themapArray = (jint*)ENVPTR->GetIntArrayElements(ENVPAR memb_map, &isCopy); - if (themapArray == NULL) { - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_map not pinned"); - return 0; - } /* end if */ - } /* end if */ - - if (memb_fapl) { - thefaplArray = (jlong*)ENVPTR->GetLongArrayElements(ENVPAR memb_fapl, &isCopy); - if (thefaplArray == NULL) { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_fapl not pinned"); - return 0; - } /* end if */ - } /* end if */ - - if (memb_addr) { - theaddrArray = (jlong*)ENVPTR->GetLongArrayElements(ENVPAR memb_addr, &isCopy); - if (theaddrArray == NULL) { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - if (memb_fapl) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_addr not pinned"); - return 0; - } /* end if */ - } /* end if */ - - if (memb_name) - mName = (char**)HDcalloc(H5FD_MEM_NTYPES, sizeof (*mName)); - - status = H5Pget_fapl_multi((hid_t)tid, (H5FD_mem_t*)themapArray, (hid_t*)thefaplArray, mName, (haddr_t*)theaddrArray, (hbool_t*)&relax); - - if (status < 0) { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - if (memb_fapl) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, JNI_ABORT); - if (memb_addr) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_addr, theaddrArray, JNI_ABORT); - if (memb_name) h5str_array_free(mName, H5FD_MEM_NTYPES); - h5libraryError(env); - } /* end if */ - else { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, 0); - if (memb_fapl) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, 0); - if (memb_addr) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_addr, theaddrArray, 0); - - if (memb_name) { - if (mName) { - for (i = 0; i < H5FD_MEM_NTYPES; i++) { - if (*(mName + i)) { - str = ENVPTR->NewStringUTF(ENVPAR *(mName+i)); - ENVPTR->SetObjectArrayElement(ENVPAR memb_name, i, (jobject)str); - } /* end if */ - } /* for (i=0; iGetIntArrayElements(ENVPAR memb_map, &isCopy); - if (themapArray == NULL) { - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_map not pinned"); - return; - } /* end if */ - } /* end if */ - - if (memb_fapl) { - thefaplArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_fapl, &isCopy); - if (thefaplArray == NULL) { - if (memb_map) - ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_fapl not pinned"); - return; - } /* end if */ - } /* end if */ - - if (memb_addr) { - theaddrArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_addr, &isCopy); - if (theaddrArray == NULL) { - if (memb_map) - ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - if (memb_fapl) - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_fapl_muti: memb_addr not pinned"); - return; - } /* end if */ - } /* end if */ - - HDmemset(member_name, 0, H5FD_MEM_NTYPES * sizeof(char*)); - if (memb_name) { - int i; - for (i = 0; i < H5FD_MEM_NTYPES; i++) { - jstring obj = (jstring) ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray) memb_name, i); - if (obj != 0) { - jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); - const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); - - if (utf8) { - member_name[i] = (char*)HDmalloc(HDstrlen(utf8) + 1); - if (member_name[i]) { - strcpy(member_name[i], utf8); - } /* end if */ - } /* end if */ - - ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); - ENVPTR->DeleteLocalRef(ENVPAR obj); - } /* end if */ - } /* end for */ - mName = (const char **)member_name; - } /* end if */ - - status = H5Pset_fapl_multi((hid_t)tid, (const H5FD_mem_t *)themapArray, (const hid_t *)thefaplArray, mName, (const haddr_t *)theaddrArray, (hbool_t)relax); - - if (status < 0) { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, JNI_ABORT); - if (memb_fapl) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, JNI_ABORT); - if (memb_addr) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_addr, theaddrArray, JNI_ABORT); - if (memb_name) { - int i; - for (i = 0; i < H5FD_MEM_NTYPES; i++) - HDfree(member_name[i]); - } /* end if */ - h5libraryError(env); - } /* end if */ - else { - if (memb_map) ENVPTR->ReleaseIntArrayElements(ENVPAR memb_map, themapArray, 0); - if (memb_fapl) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_fapl, thefaplArray, 0); - if (memb_addr) ENVPTR->ReleaseLongArrayElements(ENVPAR memb_addr, theaddrArray, 0); - if (memb_name) { - if (mName != NULL) { - int i; - Sjc = ENVPTR->FindClass(ENVPAR "java/lang/String"); - if (Sjc != NULL) { - for (i = 0; i < H5FD_MEM_NTYPES; i++) { - rstring = ENVPTR->NewStringUTF(ENVPAR member_name[i]); - o = ENVPTR->GetObjectArrayElement(ENVPAR memb_name, i); - if (o != NULL) { - bb = ENVPTR->IsInstanceOf(ENVPAR o, Sjc); - if (bb == JNI_TRUE) { - ENVPTR->SetObjectArrayElement(ENVPAR memb_name, i, (jobject)rstring); - } /* end if */ - ENVPTR->DeleteLocalRef(ENVPAR o); - } /* end if */ - HDfree(member_name[i]); - } /* end for */ - } /* end if */ - } /* end if */ - } /* end if */ - } /* end else */ -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1multi */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_split - * Signature: (JLjava/lang/String;JLjava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split - (JNIEnv *env, jclass clss, jlong fapl_id, jstring metaext, jlong meta_pl_id, jstring rawext, jlong raw_pl_id) -{ - herr_t retVal = -1; - const char *mstr; - const char *rstr; - - PIN_JAVA_STRING_TWO(metaext, mstr, rawext, rstr); - if (mstr != NULL && rstr != NULL) { - retVal = H5Pset_fapl_split((hid_t)fapl_id, mstr, (hid_t)meta_pl_id, rstr, (hid_t)raw_pl_id); - - UNPIN_JAVA_STRING_TWO(metaext, mstr, rawext, rstr); - - if (retVal < 0) - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_meta_block_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size - (JNIEnv *env, jclass clss, jlong plist, jlong size) -{ - long sz = (long)size; - - if (H5Pset_meta_block_size((hid_t)plist, (hsize_t)sz) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_meta_block_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size - (JNIEnv *env, jclass clss, jlong plist) -{ - hsize_t s; - - if (H5Pget_meta_block_size((hid_t)plist, &s) < 0) - h5libraryError(env); - - return (jlong)s; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sieve_buf_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size - (JNIEnv *env, jclass clss, jlong plist, jlong size) -{ - size_t sz = (size_t)size; - - if (H5Pset_sieve_buf_size((hid_t)plist, (size_t)sz) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sieve_buf_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size - (JNIEnv *env, jclass clss, jlong plist) -{ - size_t s; - - if (H5Pget_sieve_buf_size((hid_t)plist, &s) < 0) - h5libraryError(env); - - return (jlong)s; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_file_cache_size - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size - (JNIEnv *env, jclass clss, jlong plist, jint size) -{ - unsigned sz = (unsigned)size; - - if (H5Pset_elink_file_cache_size((hid_t)plist, (unsigned)sz) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_file_cache_size - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size - (JNIEnv *env, jclass clss, jlong plist) -{ - unsigned s; - - if (H5Pget_elink_file_cache_size((hid_t)plist, &s) < 0) - h5libraryError(env); - - return (jint)s; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size */ - - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_mdc_config - * Signature: (J)Lhdf/hdf5lib/structs/H5AC_cache_config_t; - */ -JNIEXPORT jobject JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config - (JNIEnv *env, jclass clss, jlong plist) -{ - H5AC_cache_config_t cacheinfo; - herr_t status = -1; - jvalue args[30]; - jstring j_str = NULL; - jobject ret_obj = NULL; - - HDmemset(&cacheinfo, 0, sizeof(H5AC_cache_config_t)); - cacheinfo.version = H5AC__CURR_CACHE_CONFIG_VERSION; - - status = H5Pget_mdc_config((hid_t)plist, &cacheinfo); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = cacheinfo.version; - args[1].z = cacheinfo.rpt_fcn_enabled; - args[2].z = cacheinfo.open_trace_file; - args[3].z = cacheinfo.close_trace_file; - if (cacheinfo.trace_file_name != NULL) { - j_str = ENVPTR->NewStringUTF(ENVPAR cacheinfo.trace_file_name); - } /* end if */ - args[4].l = j_str; - args[5].z = cacheinfo.evictions_enabled; - args[6].z = cacheinfo.set_initial_size; - args[7].j = (jlong)cacheinfo.initial_size; - args[8].d = cacheinfo.min_clean_fraction; - args[9].j = (jlong)cacheinfo.max_size; - args[10].j = (jlong)cacheinfo.min_size; - args[11].j = cacheinfo.epoch_length; - args[12].i = cacheinfo.incr_mode; - args[13].d = cacheinfo.lower_hr_threshold; - args[14].d = cacheinfo.increment; - args[15].z = cacheinfo.apply_max_increment; - args[16].j = (jlong)cacheinfo.max_increment; - args[17].i = cacheinfo.flash_incr_mode; - args[18].d = cacheinfo.flash_multiple; - args[19].d = cacheinfo.flash_threshold; - args[20].i = cacheinfo.decr_mode; - args[21].d = cacheinfo.upper_hr_threshold; - args[22].d = cacheinfo.decrement; - args[23].z = cacheinfo.apply_max_decrement; - args[24].j = (jlong)cacheinfo.max_decrement; - args[25].i = cacheinfo.epochs_before_eviction; - args[26].z = cacheinfo.apply_empty_reserve; - args[27].d = cacheinfo.empty_reserve; - args[28].j = (jlong)cacheinfo.dirty_bytes_threshold; - args[29].i = cacheinfo.metadata_write_strategy; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5AC_cache_config_t", "(IZZZLjava/lang/String;ZZJDJJJIDDZJIDDIDDZJIZDJI)V", args); - } /* end else */ - return ret_obj; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_mdc_config - * Signature: (JLhdf/hdf5lib/structs/H5AC_cache_config_t;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config - (JNIEnv *env, jclass clss, jlong plist, jobject cache_config) -{ - herr_t status = -1; - jclass cls; - jfieldID fid; - jstring j_str; - const char *str; - H5AC_cache_config_t cacheinfo; - - cls = ENVPTR->GetObjectClass(ENVPAR cache_config); - fid = ENVPTR->GetFieldID(ENVPAR cls, "version", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: version"); - return; - } /* end if */ - cacheinfo.version = ENVPTR->GetIntField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading version failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "rpt_fcn_enabled", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: rpt_fcn_enabled"); - return; - } /* end if */ - cacheinfo.rpt_fcn_enabled = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading rpt_fcn_enabled failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "open_trace_file", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: open_trace_file"); - return; - } /* end if */ - cacheinfo.open_trace_file = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading open_trace_file failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "close_trace_file", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: close_trace_file"); - return; - } /* end if */ - cacheinfo.close_trace_file = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading close_trace_file failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "trace_file_name", "Ljava/lang/String;"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: trace_file_name"); - return; - } /* end if */ - j_str = (jstring)ENVPTR->GetObjectField(ENVPAR cache_config, fid); - str = ENVPTR->GetStringUTFChars(ENVPAR j_str, NULL); - if (str == NULL) { - h5JNIFatalError(env, "H5Pset_mdc_config: out of memory trace_file_name"); - return; - } /* end if */ - HDstrncpy(cacheinfo.trace_file_name, str, 1025); - ENVPTR->ReleaseStringUTFChars(ENVPAR j_str, str); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading trace_file_name failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "evictions_enabled", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: evictions_enabled"); - return; - } /* end if */ - cacheinfo.evictions_enabled = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading evictions_enabled failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "set_initial_size", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: set_initial_size"); - return; - } /* end if */ - cacheinfo.set_initial_size = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading set_initial_size failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "initial_size", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: initial_size"); - return; - } /* end if */ - cacheinfo.initial_size = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading initial_size failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "min_clean_fraction", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: min_clean_fraction"); - return; - } /* end if */ - cacheinfo.min_clean_fraction = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading min_clean_fraction failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "max_size", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: max_size"); - return; - } /* end if */ - cacheinfo.max_size = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading max_size failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "min_size", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: min_size"); - return; - } /* end if */ - cacheinfo.min_size = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading min_size failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "epoch_length", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: epoch_length"); - return; - } - cacheinfo.epoch_length = (long int)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading epoch_length failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "incr_mode", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: incr_mode"); - return; - } /* end if */ - cacheinfo.incr_mode = ENVPTR->GetIntField(ENVPAR cache_config, fid); /*(enum H5C_cache_incr_mode) */ - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading incr_mode failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "lower_hr_threshold", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: lower_hr_threshold"); - return; - } /* end if */ - cacheinfo.lower_hr_threshold = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading lower_hr_threshold failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "increment", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: increment"); - return; - } /* end if */ - cacheinfo.increment = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading increment failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "apply_max_increment", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: apply_max_increment"); - return; - } /* end if */ - cacheinfo.apply_max_increment = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading apply_max_increment failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "max_increment", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: max_increment"); - return; - } /* end if */ - cacheinfo.max_increment = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading max_increment failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "flash_incr_mode", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: flash_incr_mode"); - return; - } /* end if */ - cacheinfo.flash_incr_mode = ENVPTR->GetIntField(ENVPAR cache_config, fid); /*(enum H5C_cache_flash_incr_mode) */ - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading flash_incr_mode failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "flash_multiple", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: flash_multiple"); - return; - } /* end if */ - cacheinfo.flash_multiple = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading flash_multiple failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "flash_threshold", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: flash_threshold"); - return; - } /* end if */ - cacheinfo.flash_threshold = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading flash_threshold failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "decr_mode", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: decr_mode"); - return; - } /* end if */ - cacheinfo.decr_mode = ENVPTR->GetIntField(ENVPAR cache_config, fid); /*(enum H5C_cache_decr_mode) */ - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading decr_mode failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "upper_hr_threshold", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: upper_hr_threshold"); - return; - } /* end if */ - cacheinfo.upper_hr_threshold = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading upper_hr_threshold failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "decrement", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: decrement"); - return; - } /* end if */ - cacheinfo.decrement = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading decrement failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "apply_max_decrement", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: apply_max_decrement"); - return; - } /* end if */ - cacheinfo.apply_max_decrement = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading apply_max_decrement failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "max_decrement", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: max_decrement"); - return; - } /* end if */ - cacheinfo.max_decrement = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading max_decrement failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "epochs_before_eviction", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: epochs_before_eviction"); - return; - } /* end if */ - cacheinfo.epochs_before_eviction = ENVPTR->GetIntField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading epochs_before_eviction failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "apply_empty_reserve", "Z"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: apply_empty_reserve"); - return; - } /* end if */ - cacheinfo.apply_empty_reserve = ENVPTR->GetBooleanField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading apply_empty_reserve failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "empty_reserve", "D"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: empty_reserve"); - return; - } /* end if */ - cacheinfo.empty_reserve = ENVPTR->GetDoubleField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading empty_reserve failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "dirty_bytes_threshold", "J"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: dirty_bytes_threshold"); - return; - } /* end if */ - cacheinfo.dirty_bytes_threshold = (size_t)ENVPTR->GetLongField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading dirty_bytes_threshold failed"); - return; - } /* end if */ - - fid = ENVPTR->GetFieldID(ENVPAR cls, "metadata_write_strategy", "I"); - if(fid == 0) { - h5badArgument(env, "H5Pset_mdc_config: metadata_write_strategy"); - return; - } /* end if */ - cacheinfo.metadata_write_strategy = ENVPTR->GetIntField(ENVPAR cache_config, fid); - if(ENVPTR->ExceptionOccurred(ENVONLY)) { - h5JNIFatalError(env, "H5Pset_mdc_config: loading metadata_write_strategy failed"); - } /* end if */ - else { - status = H5Pset_mdc_config((hid_t)plist, &cacheinfo); - - if (status < 0) - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk_cache - * Signature: (JJJD)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache - (JNIEnv *env, jclass clss, jlong dapl, jlong rdcc_nslots, - jlong rdcc_nbytes, jdouble rdcc_w0) -{ - if (H5Pset_chunk_cache((hid_t)dapl, (size_t)rdcc_nslots, (size_t)rdcc_nbytes, (double) rdcc_w0) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk_cache - * Signature: (J[J[J[D)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache - (JNIEnv *env, jclass clss, jlong dapl, jlongArray rdcc_nslots, - jlongArray rdcc_nbytes, jdoubleArray rdcc_w0) -{ - herr_t status = -1; - jint mode; - jdouble *w0Array = (jdouble *)NULL; - jlong *rdcc_nslotsArray = (jlong *)NULL; - jlong *nbytesArray = (jlong *)NULL; - jboolean isCopy; - - if (rdcc_w0 != NULL) { - w0Array = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR rdcc_w0, &isCopy); - if (w0Array == NULL) { - h5JNIFatalError(env, "H5Pget_chunk_cache: w0_array array not pinned"); - return; - } /* end if */ - } /* end else */ - - if (rdcc_nslots != NULL) { - rdcc_nslotsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nslots, &isCopy); - if (rdcc_nslotsArray == NULL) { - /* exception -- out of memory */ - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, JNI_ABORT); - } /* end if */ - h5JNIFatalError(env, "H5Pget_chunk_cache: rdcc_nslots array not pinned"); - return; - } /* end if */ - } /* end else */ - - if (rdcc_nbytes != NULL) { - nbytesArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nbytes, &isCopy); - if (nbytesArray == NULL) { - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, JNI_ABORT); - } /* end if */ - if (rdcc_nslotsArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nslots, rdcc_nslotsArray, JNI_ABORT); - } /* end if */ - h5JNIFatalError(env, "H5Pget_chunk_cache: nbytesArray array not pinned"); - return; - } /* end if */ - } /* end else */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long rdcc_nslots_temp = *(rdcc_nslotsArray); - size_t rdcc_nslots_t = (size_t)rdcc_nslots_temp; - long long nbytes_temp = *(nbytesArray); - size_t nbytes_t = (size_t)nbytes_temp; - - status = H5Pget_chunk_cache((hid_t)dapl, &rdcc_nslots_t, &nbytes_t, (double *)w0Array); - - *rdcc_nslotsArray = (jlong)rdcc_nslots_t; - *nbytesArray = (jlong)nbytes_t; - } /* end direct cast special handling */ - - if (status < 0) { - mode = JNI_ABORT; - } /* end if */ - else { - mode = 0; /* commit and free */ - } /* end else */ - - if (rdcc_nslotsArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nslots, rdcc_nslotsArray, mode); - } - /* end if */ - if (nbytesArray != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR rdcc_nbytes, nbytesArray, mode); - } /* end if */ - - if (w0Array != NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rdcc_w0, w0Array, mode); - } /* end if */ - - if (status < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_obj_track_times - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times - (JNIEnv *env, jclass clss, jlong objplid) -{ - hbool_t track_times; - - if (H5Pget_obj_track_times((hid_t)objplid, &track_times) < 0) { - h5libraryError(env); - return JNI_FALSE; - } /* end if */ - if (track_times == 1) { - return JNI_TRUE; - } /* end if */ - return JNI_FALSE; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_obj_track_times - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times - (JNIEnv *env, jclass clss, jlong objplid, jboolean track_times) -{ - hbool_t track; - - if (track_times == JNI_TRUE) { - track = 1; - } /* end if */ - else { - track = 0; - } /* end else */ - - if (H5Pset_obj_track_times((hid_t)objplid, track) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_char_encoding - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding - (JNIEnv *env, jclass clss, jlong acpl) -{ - H5T_cset_t encoding; - - if (H5Pget_char_encoding((hid_t)acpl, &encoding) < 0) - h5libraryError(env); - - return encoding; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_char_encoding - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding - (JNIEnv *env, jclass clss, jlong acpl, jint encoding) -{ - if (H5Pset_char_encoding((hid_t)acpl, (H5T_cset_t)encoding) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual - * Signature: (JJLjava/lang/String;Ljava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual - (JNIEnv *env, jclass clss, jlong dcpl_id, jlong vspace_id, - jstring src_file_name, jstring src_dset_name, jlong src_space_id) -{ - herr_t retVal = -1; - const char *fstr; - const char *dstr; - - PIN_JAVA_STRING_TWO(src_file_name, fstr, src_dset_name, dstr); - if (fstr != NULL && dstr != NULL) { - retVal = H5Pset_virtual((hid_t)dcpl_id, (hid_t)vspace_id, fstr, dstr, (hid_t)src_space_id); - - UNPIN_JAVA_STRING_TWO(src_file_name, fstr, src_dset_name, dstr); - - if (retVal < 0) - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_count - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count - (JNIEnv *env, jclass clss, jlong dcpl_id) -{ - size_t s; - - if (H5Pget_virtual_count((hid_t)dcpl_id, &s) < 0) - h5libraryError(env); - - return (jlong)s; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_vspace - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace - (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) -{ - hid_t space_id = -1; - - space_id = H5Pget_virtual_vspace((hid_t)dcpl_id, (size_t)index); - if (space_id < 0) - h5libraryError(env); - - return (jlong)space_id; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_srcspace - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace - (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) -{ - hid_t space_id = -1; - - space_id = H5Pget_virtual_srcspace((hid_t)dcpl_id, (size_t)index); - if (space_id < 0) - h5libraryError(env); - - return (jlong)space_id; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_filename - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename - (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) -{ - char *fname; - ssize_t buf_size; - ssize_t status; - jstring str = NULL; - - /* get the length of the filename */ - buf_size = H5Pget_virtual_filename((hid_t)dcpl_id, (size_t)index, NULL, 0); - if (buf_size < 0) { - h5badArgument( env, "H5Pget_virtual_filename: buf_size < 0"); - } /* end if */ - else if (buf_size >= 0) { - buf_size++; /* add extra space for the null terminator */ - fname = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (fname == NULL) { - h5outOfMemory( env, "H5Pget_virtual_filename: malloc failed"); - } /* end if */ - else { - status = H5Pget_virtual_filename((hid_t)dcpl_id, (size_t)index, fname, (size_t)buf_size); - - if (status >= 0) { - str = ENVPTR->NewStringUTF(ENVPAR fname); - HDfree(fname); - if (str == NULL) - h5JNIFatalError( env, "H5Pget_virtual_filename: return string not allocated"); - } /* end if */ - else { - HDfree(fname); - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else if */ - - return (jstring)str; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_dsetname - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname - (JNIEnv *env, jclass clss, jlong dcpl_id, jlong index) -{ - char *dname; - ssize_t buf_size; - ssize_t status; - jstring str = NULL; - - /* get the length of the filename */ - buf_size = H5Pget_virtual_dsetname((hid_t)dcpl_id, (size_t)index, NULL, 0); - if (buf_size < 0) { - h5badArgument( env, "H5Pget_virtual_dsetname: buf_size < 0"); - } /* end if */ - else if (buf_size > 0) { - buf_size++; /* add extra space for the null terminator */ - dname = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (dname == NULL) { - h5outOfMemory( env, "H5Pget_virtual_dsetname: malloc failed"); - } /* end if */ - else { - status = H5Pget_virtual_dsetname((hid_t)dcpl_id, (size_t)index, dname, (size_t)buf_size); - - if (status >= 0) { - str = ENVPTR->NewStringUTF(ENVPAR dname); - HDfree(dname); - if (str == NULL) - h5JNIFatalError( env, "H5Pget_virtual_dsetname: return string not allocated"); - } /* end if */ - else { - HDfree(dname); - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else if */ - return (jstring)str; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_view - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view - (JNIEnv *env, jclass clss, jlong dapl_id) -{ - H5D_vds_view_t virtual_view; - - if (H5Pget_virtual_view((hid_t)dapl_id, &virtual_view) < 0) - h5libraryError(env); - - return (jint)virtual_view; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_view - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view - (JNIEnv *env, jclass clss, jlong dapl_id, jint view) -{ - if (H5Pset_virtual_view((hid_t)dapl_id, (H5D_vds_view_t)view) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_printf_gap - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap - (JNIEnv *env, jclass clss, jlong dapl_id) -{ - hsize_t gap_size; - - if (H5Pget_virtual_printf_gap((hid_t)dapl_id, &gap_size) < 0) - h5libraryError(env); - - return (jlong)gap_size; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_printf_gap - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap - (JNIEnv *env, jclass clss, jlong dapl_id, jlong gap_size) -{ - if (H5Pset_virtual_printf_gap((hid_t)dapl_id, (hsize_t)gap_size) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy - * Signature: (J[Z[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy - (JNIEnv *env, jclass clss, jlong fcpl_id, jbooleanArray persist, jlongArray threshold) -{ - herr_t status = -1; - H5F_fspace_strategy_t thestrategy = H5F_FSPACE_STRATEGY_FSM_AGGR; /* Library default */ - jlong *thethresholdArray = NULL; - jboolean *thepersistArray = NULL; - jboolean isCopy; - - if (persist) { - thepersistArray = (jboolean*)ENVPTR->GetBooleanArrayElements(ENVPAR persist, &isCopy); - if (thepersistArray == NULL) { - h5JNIFatalError(env, "H5Pget_file_space: persist not pinned"); - return -1; - } - } - - if (threshold) { - thethresholdArray = (jlong*)ENVPTR->GetLongArrayElements(ENVPAR threshold, &isCopy); - if (thethresholdArray == NULL) { - if (persist) ENVPTR->ReleaseBooleanArrayElements(ENVPAR persist, thepersistArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_file_space: threshold not pinned"); - return -1; - } /* end if */ - } /* end if */ - - status = H5Pget_file_space_strategy((hid_t)fcpl_id, &thestrategy, (hbool_t*)thepersistArray, (hsize_t*)thethresholdArray); - - if (status < 0) { - if (persist) ENVPTR->ReleaseBooleanArrayElements(ENVPAR persist, thepersistArray, JNI_ABORT); - if (threshold) ENVPTR->ReleaseLongArrayElements(ENVPAR threshold, thethresholdArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - if (persist) ENVPTR->ReleaseBooleanArrayElements(ENVPAR persist, thepersistArray, 0); - if (threshold) ENVPTR->ReleaseLongArrayElements(ENVPAR threshold, thethresholdArray, 0); - } /* end else */ - return (jint)thestrategy; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy_persist - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist - (JNIEnv *env, jclass clss, jlong fcpl_id) -{ - herr_t status = -1; - hbool_t thepersist = FALSE; - - status = H5Pget_file_space_strategy((hid_t)fcpl_id, NULL, &thepersist, NULL); - - if (status < 0) - h5libraryError(env); - - return (jboolean)thepersist; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy_threshold - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1threshold - (JNIEnv *env, jclass clss, jlong fcpl_id) -{ - herr_t status = -1; - hsize_t thethreshold; - - status = H5Pget_file_space_strategy((hid_t)fcpl_id, NULL, NULL, &thethreshold); - - if (status < 0) - h5libraryError(env); - - return (jlong)thethreshold; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1threshold */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_file_space_strategy - * Signature: (JIZJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1strategy - (JNIEnv *env, jclass clss, jlong fcpl_id, jint strategy, jboolean persist, jlong threshold) -{ - if (H5Pset_file_space_strategy((hid_t)fcpl_id, (H5F_fspace_strategy_t)strategy, (hbool_t)persist, (hsize_t)threshold) < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_file_space_strategy */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_file_space_page_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1page_1size - (JNIEnv *env, jclass clss, jlong fcpl_id, jlong fsp_size) -{ - if (H5Pset_file_space_page_size((hid_t)fcpl_id, (hsize_t)fsp_size) < 0) - h5libraryError(env); -} - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_page_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1page_1size - (JNIEnv *env, jclass clss, jlong fcpl_id) -{ - hsize_t fsp_size = 0; - if (H5Pget_file_space_page_size((hid_t)fcpl_id, &fsp_size) < 0) - h5libraryError(env); - return (jlong)fsp_size; -} - -static herr_t -H5P_cls_create_cb - (hid_t prop_id, void *create_data) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR create_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLhdf/hdf5lib/callbacks/H5P_cls_create_func_t;)I"); - if (mid != 0) { - /* fprintf(stderr, "JNI H5P_cls_create_func_cb execute\n"); fflush(stderr); */ - status = CBENVPTR->CallIntMethod(CBENVPAR create_callback, mid, prop_id, create_data); - /* fprintf(stderr, "\nJNI H5P_cls_create_func_cb status: %d\n", status); fflush(stderr); */ - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_cls_create_cb */ - -static herr_t -H5P_cls_copy_cb - (hid_t new_prop_id, hid_t old_prop_id, void *copy_data) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR copy_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JJLhdf/hdf5lib/callbacks/H5P_cls_copy_func_t;)I"); - if (mid != 0) { - status = CBENVPTR->CallIntMethod(CBENVPAR copy_callback, mid, new_prop_id, old_prop_id, copy_data); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_cls_copy_cb */ - -static herr_t -H5P_cls_close_cb - (hid_t prop_id, void *close_data) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR close_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLhdf/hdf5lib/callbacks/H5P_cls_close_func_t;)I"); - if (mid != 0) { - status = CBENVPTR->CallIntMethod(CBENVPAR close_callback, mid, prop_id, close_data); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_cls_close_cb */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_mdc_log_options - * Signature: (JZLjava/lang/String;Z)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options - (JNIEnv *env, jclass clss, jlong fapl_id, jboolean is_enabled, jstring location, jboolean start_on_access) -{ - herr_t retVal = -1; - const char *lstr; - - PIN_JAVA_STRING(location, lstr); - - retVal = H5Pset_mdc_log_options((hid_t)fapl_id, (hbool_t)is_enabled, lstr, (hbool_t)start_on_access); - - UNPIN_JAVA_STRING(location, lstr); - - if (retVal < 0) { - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_mdc_log_options - * Signature: (J[Z)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1mdc_1log_1options - (JNIEnv *env, jclass clss, jlong fapl_id, jbooleanArray mdc_log_options) -{ - hbool_t is_enabled; - hbool_t start_on_access; - jboolean *mdc_log_options_ptr; - char *lname; - size_t location_size; - ssize_t status; - jstring str = NULL; - jint size; - jboolean isCopy; - - if (mdc_log_options == NULL) { - h5nullArgument(env, "H5Fget_mdc_log_options: mdc_log_options is NULL"); - } /* end if */ - else { - size = (int)ENVPTR->GetArrayLength(ENVPAR mdc_log_options); - if (size < 2) { - h5badArgument(env, "H5Fget_mdc_log_options: length of mdc_log_options < 2."); - } /* end if */ - else { - /* get the length of the filename */ - H5Pget_mdc_log_options((hid_t)fapl_id, &is_enabled, NULL, &location_size, &start_on_access); - if (location_size == 0) { - h5badArgument(env, "H5Pget_mdc_log_options: location_size is 0"); - }/* end if */ - else if (location_size > 0) { - location_size++; /* add extra space for the null terminator */ - lname = (char *)HDmalloc(sizeof(char) * location_size); - if (lname == NULL) { - h5outOfMemory(env, "H5Pget_mdc_log_options: malloc failed"); - } /* end if */ - else { - status = H5Pget_mdc_log_options((hid_t)fapl_id, &is_enabled, lname, &location_size, &start_on_access); - - if (status < 0) { - HDfree(lname); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR lname); - HDfree(lname); - if (str == NULL) { - h5JNIFatalError(env, "H5Pget_mdc_log_options: return string not allocated"); - } /* end if */ - else { - mdc_log_options_ptr = ENVPTR->GetBooleanArrayElements(ENVPAR mdc_log_options, &isCopy); - mdc_log_options_ptr[0] = (jboolean)is_enabled; - mdc_log_options_ptr[1] = (jboolean)start_on_access; - ENVPTR->ReleaseBooleanArrayElements(ENVPAR mdc_log_options, mdc_log_options_ptr, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else if*/ - } /* end else */ - } /* end else */ - - return (jstring)str; -} /* end if */ - -static herr_t -H5D_append_cb - (hid_t dataset_id, hsize_t *cur_dims, void *cb_data) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jlongArray cur_dimsArray; - cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) != 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(J[JLhdf/hdf5lib/callbacks/H5D_append_t;)I"); - if (mid != 0) { - if (cur_dims != NULL) { - cur_dimsArray = CBENVPTR->NewLongArray(CBENVPAR 2); - if (cur_dimsArray != NULL) { - CBENVPTR->SetLongArrayRegion(CBENVPAR cur_dimsArray, 0, 2, (const jlong *)cur_dims); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, dataset_id, cur_dims, op_data); - } - } - } - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - - return (herr_t)status; -} /* end H5D_append_cb */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_append_flush - * Signature: (JI[JLjava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1append_1flush - (JNIEnv *env, jclass clss, jlong plist_id, jint ndims, jlongArray boundary, jobject callback_op, jobject op_data) -{ - herr_t status = -1; - cb_wrapper wrapper = {callback_op, op_data}; - - ENVPTR->GetJavaVM(ENVPAR &jvm); - - if (op_data == NULL) { - h5nullArgument(env, "H5Pset_append_flush: op_data is NULL"); - } /* end if */ - else if (callback_op == NULL) { - h5nullArgument(env, "H5Pset_append_flush: callback_op is NULL"); - } /* end if */ - else { - status = H5Pset_append_flush((hid_t)plist_id, (unsigned)ndims, (const hsize_t*)boundary, (H5D_append_cb_t)H5D_append_cb, (void*)&wrapper); - - if (status < 0) - h5libraryError(env); - } /* end else */ -} /* end Java_hdf_hdf5lib_H5_H5Pset_1append_1flush */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pcreate_class_nocb - * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb - (JNIEnv *env, jclass clss, jlong parent_class, jstring name) -{ - hid_t class_id = -1; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - class_id = H5Pcreate_class((hid_t)parent_class, cstr, NULL, NULL, NULL, NULL, NULL, NULL); - - UNPIN_JAVA_STRING(name, cstr); - - if (class_id < 0) - h5libraryError(env); - } - - return (jlong)class_id; -} /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pcreate_class - * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pcreate_1class - (JNIEnv *env, jclass clss, jlong parent_class, jstring name, jobject create_op, - jobject create_data, jobject copy_op, jobject copy_data, jobject close_op, jobject close_data) -{ - hid_t class_id = -1; - const char *cstr; - copy_callback = copy_op; - close_callback = close_op; - create_callback = create_op; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - class_id = H5Pcreate_class((hid_t)parent_class, cstr, (H5P_cls_create_func_t)H5P_cls_create_cb, (void*) create_data, - (H5P_cls_copy_func_t)H5P_cls_copy_cb, (void*) copy_data, (H5P_cls_close_func_t)H5P_cls_close_cb, (void*) close_data); - - UNPIN_JAVA_STRING(name, cstr); - - if (class_id < 0) - h5libraryError(env); - } - - return (jlong)class_id; -} /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class */ - -static herr_t -H5P_prp_create_cb - (const char *name, size_t size, void *value) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR create_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(Ljava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR create_callback, mid, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_create_cb */ - -static herr_t -H5P_prp_copy_cb - (const char *name, size_t size, void *value) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR copy_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(Ljava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR copy_callback, mid, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_copy_cb */ - -static herr_t -H5P_prp_close_cb - (const char *name, size_t size, void *value) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR close_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(Ljava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR close_callback, mid, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_close_cb */ - -static int -H5P_prp_compare_cb - (void *value1, void *value2, size_t size) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR compare_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "([B[BJ)I"); - if (mid != 0) { - status = CBENVPTR->CallIntMethod(CBENVPAR compare_callback, mid, value1, value2, size); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_compare_cb */ + status = CBENVPTR->CallIntMethod(CBENVONLY, get_callback, mid, prop_id, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -static herr_t -H5P_prp_get_cb - (hid_t prop_id, const char *name, size_t size, void *value) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR get_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR get_callback, mid, prop_id, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); return (herr_t)status; } /* end H5P_prp_get_cb */ static herr_t -H5P_prp_set_cb - (hid_t prop_id, const char *name, size_t size, void *value) -{ - JNIEnv *cbenv; - jint status = -1; - jclass cls; - jmethodID mid; - jstring str; - - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR set_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR set_callback, mid, prop_id, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_set_cb */ - -static herr_t H5P_prp_delete_cb (hid_t prop_id, const char *name, size_t size, void *value) { - JNIEnv *cbenv; - jint status = -1; - jclass cls; jmethodID mid; jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) == 0) { - cls = CBENVPTR->GetObjectClass(CBENVPAR delete_callback); - if (cls != 0) { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;J[B)I"); - if (mid != 0) { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - status = CBENVPTR->CallIntMethod(CBENVPAR delete_callback, mid, prop_id, str, size, value); - } /* end if */ - } /* end if */ - } /* end if */ - JVMPTR->DetachCurrentThread(JVMPAR); - return (herr_t)status; -} /* end H5P_prp_delete_cb */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pregister2_nocb - * Signature: (JLjava/lang/String;J[B)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pregister2_1nocb - (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, jbyteArray def_value) -{ - herr_t status = -1; - jbyte *buffP; - jboolean isCopy2; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Pregister2: buf not pinned"); - } /* end if */ - else { - status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, cstr); + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_delete_cb: failed to attach current thread to JVM"); } -} /* end Java_hdf_hdf5lib_H5_H5Pregister2_1nocb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pregister2 - * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pregister2 - (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, - jbyteArray def_value, jobject prp_create, jobject prp_set, jobject prp_get, jobject prp_delete, - jobject prp_copy, jobject prp_cmp, jobject prp_close) -{ - herr_t status = -1; - jbyte *buffP; - jboolean isCopy2; - const char *cstr; - copy_callback = prp_copy; - close_callback = prp_close; - create_callback = prp_create; - compare_callback = prp_cmp; - set_callback = prp_set; - get_callback = prp_get; - delete_callback = prp_delete; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, delete_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Pregister2: buf not pinned"); - } /* end if */ - else { - status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, (H5P_prp_create_func_t)H5P_prp_create_cb, - (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, - (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, cstr); - } -} /* end Java_hdf_hdf5lib_H5_H5Pregister2 */ + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pinsert2_nocb - * Signature: (JLjava/lang/String;J[B)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb - (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, jbyteArray def_value) -{ - herr_t status = -1; - jbyte *buffP; - jboolean isCopy2; - const char *cstr; - - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); - } /* end if */ - else { - status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, cstr); - } -} /* end Java_hdf_hdf5lib_H5_H5Pinsert2 */ + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); + status = CBENVPTR->CallIntMethod(CBENVONLY, delete_callback, mid, prop_id, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pinsert2 - * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pinsert2 - (JNIEnv *env, jclass clss, jlong cls_id, jstring name, jlong prp_size, - jbyteArray def_value, jobject prp_set, jobject prp_get, jobject prp_delete, - jobject prp_copy, jobject prp_cmp, jobject prp_close) -{ - herr_t status = -1; - jbyte *buffP; - jboolean isCopy2; - const char *cstr; - copy_callback = prp_copy; - close_callback = prp_close; - compare_callback = prp_cmp; - set_callback = prp_set; - get_callback = prp_get; - delete_callback = prp_delete; +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - PIN_JAVA_STRING(name, cstr); - if (cstr != NULL) { - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - UNPIN_JAVA_STRING(name, cstr); - h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); - } /* end if */ - else { - status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, - (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, - (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, cstr); - } -} /* end Java_hdf_hdf5lib_H5_H5Pinsert2 */ + return (herr_t)status; +} /* end H5P_prp_delete_cb */ static herr_t -H5P_iterate_cb - (hid_t prop_id, const char *name, void *cb_data) +H5P_prp_copy_cb + (const char *name, size_t size, void *value) { - JNIEnv *cbenv; - jint status = -1; - jclass cls; jmethodID mid; jstring str; - cb_wrapper *wrapper = (cb_wrapper *)cb_data; - void *op_data = (void *)wrapper->op_data; - jobject visit_callback = wrapper->visit_callback; - - /* fprintf(stderr, "\nJNI H5P_iterate_cb entered\n"); fflush(stderr); */ - if(JVMPTR->AttachCurrentThread(JVMPAR2 (void**)&cbenv, NULL) != 0) { - /* fprintf(stderr, "\nJNI H5P_iterate_cb error: AttachCurrentThread failed\n"); fflush(stderr); */ - JVMPTR->DetachCurrentThread(JVMPAR); - } /* end if */ - else { - cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls == 0) { - /* fprintf(stderr, "\nJNI H5P_iterate_cb error: GetObjectClass failed\n"); fflush(stderr); */ - JVMPTR->DetachCurrentThread(JVMPAR); - } /* end if */ - else { - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/callbacks/H5P_iterate_t;)I"); - if (mid == 0) { - /* fprintf(stderr, "\nJNI H5P_iterate_cb error: GetMethodID failed\n"); fflush(stderr); */ - JVMPTR->DetachCurrentThread(JVMPAR); - } /* end if */ - else { - str = CBENVPTR->NewStringUTF(CBENVPAR name); - - /* fprintf(stderr, "JNI H5P_iterate_cb execute\n"); fflush(stderr); */ - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, prop_id, str, op_data); - /* fprintf(stderr, "\nJNI H5P_iterate_cb status: %d\n", status); fflush(stderr); */ - } /* end else */ - } /* end else */ - } /* end else */ - - JVMPTR->DetachCurrentThread(JVMPAR); - /* fprintf(stderr, "\nJNI H5P_iterate_cb leave\n"); fflush(stderr); */ + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - return status; -} /* end H5P_iterate_cb */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_copy_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Piterate - * Signature: (J[ILjava/lang/Object;Ljava/lang/Object;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Piterate - (JNIEnv *env, jclass clss, jlong prop_id, jintArray idx, jobject callback_op, jobject op_data) -{ - herr_t status = -1; - jint *theArray = NULL; - jboolean isCopy; - cb_wrapper wrapper = {callback_op, op_data}; - - ENVPTR->GetJavaVM(ENVPAR &jvm); - - if (op_data == NULL) { - h5nullArgument(env, "H5Piterate: op_data is NULL"); - } /* end if */ - else if (callback_op == NULL) { - h5nullArgument(env, "H5Piterate: callback_op is NULL"); - } /* end else if */ - else { - if (idx == NULL) { - status = H5Piterate((hid_t)prop_id, NULL, (H5P_iterate_t)H5P_iterate_cb, (void*)&wrapper); - } /* end if */ - else { - theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR idx, &isCopy); - if (theArray == NULL) { - h5JNIFatalError(env, "H5Piterate: idx not pinned"); - } /* end if */ - else - status = H5Piterate((hid_t)prop_id, (int*)&theArray[0], (H5P_iterate_t)H5P_iterate_cb, (void*)&wrapper); - } /* end else */ - - if (status < 0) { - if(idx) - ENVPTR->ReleaseIntArrayElements(ENVPAR idx, theArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else if (idx) - ENVPTR->ReleaseIntArrayElements(ENVPAR idx, theArray, 0); - } /* end else */ + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, copy_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Piterate */ + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(Ljava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_metadata_read_attempts - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts - (JNIEnv *env, jclass clss, jlong plist_id) -{ - unsigned attempts; - if (H5Pget_metadata_read_attempts((hid_t)plist_id, &attempts) < 0) - h5libraryError(env); + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return (jlong) attempts; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts */ + status = CBENVPTR->CallIntMethod(CBENVONLY, copy_callback, mid, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_metadata_read_attempts - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts - (JNIEnv *env, jclass clss, jlong plist_id, jlong attempts) -{ - if (attempts <= 0) { - h5badArgument(env, "H5Pset_metadata_read_attempts: attempts <= 0"); - } /* end if */ - else { - if(H5Pset_metadata_read_attempts((hid_t)plist_id, (unsigned)attempts) < 0) - h5libraryError(env); - } /* end else */ -} /* end Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts */ +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); + return (herr_t)status; +} /* end H5P_prp_copy_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_prefix - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix - (JNIEnv *env, jclass clss, jlong dapl_id, jstring prefix) +static int +H5P_prp_compare_cb + (void *value1, void *value2, size_t size) { - herr_t retVal = -1; - const char *aName; - - PIN_JAVA_STRING(prefix, aName); - if (aName != NULL) { - retVal = H5Pset_virtual_prefix((hid_t)dapl_id, aName); - - UNPIN_JAVA_STRING(prefix, aName); + jmethodID mid; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - if(retVal < 0) - h5libraryError(env); + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_compare_cb: failed to attach current thread to JVM"); } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_prefix - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix - (JNIEnv *env, jclass clss, jlong dapl_id) -{ - size_t size = 0; - char *pre; - jlong prefix_size = -1; - jstring str = NULL; - - prefix_size = (jlong)H5Pget_virtual_prefix((hid_t)dapl_id, (char*)NULL, size); - if(prefix_size < 0) { - h5libraryError(env); - } /* end if */ - else { - size = (size_t)prefix_size + 1;/* add extra space for the null terminator */ - pre = (char*)HDmalloc(sizeof(char)*size); - if (pre == NULL) { - h5outOfMemory(env, "H5Pget_virtual_prefix: malloc failed "); - } /* end if */ - else { - prefix_size = (jlong)H5Pget_virtual_prefix((hid_t)dapl_id, (char*)pre, size); - - if (prefix_size >= 0) { - str = ENVPTR->NewStringUTF(ENVPAR pre); - HDfree(pre); - if (str == NULL) - h5JNIFatalError( env, "H5Pget_virtual_prefix: return string not allocated"); - } /* end if */ - else { - HDfree(pre); - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ - - return (jstring)str; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_efile_prefix - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix - (JNIEnv *env, jclass clss, jlong dapl_id, jstring prefix) -{ - herr_t retVal = -1; - const char *aName; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, compare_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - PIN_JAVA_STRING(prefix, aName); - if (aName != NULL) { - retVal = H5Pset_efile_prefix((hid_t)dapl_id, aName); + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "([B[BJ)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - UNPIN_JAVA_STRING(prefix, aName); + status = CBENVPTR->CallIntMethod(CBENVONLY, compare_callback, mid, value1, value2, size); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - if(retVal < 0) - h5libraryError(env); - } -} /* end Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix */ +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_efile_prefix - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix - (JNIEnv *env, jclass clss, jlong dapl_id) -{ - size_t size = 0; - char *pre; - jlong prefix_size = -1; - jstring str = NULL; - - prefix_size = (jlong)H5Pget_efile_prefix((hid_t)dapl_id, (char*)NULL, size); - if(prefix_size < 0) { - h5libraryError(env); - } /* end if */ - else { - size = (size_t)prefix_size + 1;/* add extra space for the null terminator */ - pre = (char*)HDmalloc(sizeof(char)*size); - if (pre == NULL) { - h5outOfMemory(env, "H5Pget_efile_prefix: malloc failed "); - } /* end if */ - else { - prefix_size = (jlong)H5Pget_efile_prefix((hid_t)dapl_id, (char*)pre, size); - - if (prefix_size >= 0) { - str = ENVPTR->NewStringUTF(ENVPAR pre); - HDfree(pre); - if (str == NULL) - h5JNIFatalError( env, "H5Pget_efile_prefix: return string not allocated"); - } /* end if */ - else { - HDfree(pre); - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ - - return (jstring)str; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix */ + return (herr_t)status; +} /* end H5P_prp_compare_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_evict_on_close - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close - (JNIEnv *env, jclass clss, jlong fapl_id, jboolean evict_on_close) +static herr_t +H5P_prp_close_cb + (const char *name, size_t size, void *value) { - herr_t retVal = -1; - hbool_t evict_on_close_val; + jmethodID mid; + jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + jint status = -1; - if (evict_on_close == JNI_TRUE) - evict_on_close_val = TRUE; - else - evict_on_close_val = FALSE; + if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_prp_close_cb: failed to attach current thread to JVM"); + } - retVal = H5Pset_evict_on_close((hid_t)fapl_id, (hbool_t)evict_on_close_val); - if (retVal < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close */ + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, close_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_evict_on_close - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close - (JNIEnv *env, jclass clss, jlong fapl_id) -{ - hbool_t evict_on_close_val = FALSE; - jboolean bval = JNI_FALSE; + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(Ljava/lang/String;J[B)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - if (H5Pget_evict_on_close((hid_t)fapl_id, (hbool_t *)&evict_on_close_val) < 0) { - h5libraryError(env); - } /* end if */ - else { - if (evict_on_close_val == TRUE) - bval = JNI_TRUE; - } /* end else */ + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - return bval; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close */ + status = CBENVPTR->CallIntMethod(CBENVONLY, close_callback, mid, str, size, value); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk_opts - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts - (JNIEnv *env, jclass clss, jlong dcpl_id, jint opts) -{ - herr_t retVal = -1; +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - retVal = H5Pset_chunk_opts((hid_t)dcpl_id, (unsigned)opts); - if (retVal < 0) - h5libraryError(env); -} /* end Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts */ + return (herr_t)status; +} /* end H5P_prp_close_cb */ -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk_opts - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts - (JNIEnv *env, jclass clss, jlong dcpl_id) +static herr_t +H5P_iterate_cb + (hid_t prop_id, const char *name, void *cb_data) { - unsigned opts = 0; - - if (H5Pget_chunk_opts((hid_t)dcpl_id, opts) < 0) - h5libraryError(env); + cb_wrapper *wrapper = (cb_wrapper *) cb_data; + jmethodID mid; + jobject visit_callback = wrapper->visit_callback; + jstring str; + jclass cls; + JNIEnv *cbenv = NULL; + void *op_data = (void *) wrapper->op_data; + jint status = -1; - return (jint)opts; -} /* end Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts */ + if (JVMPTR->AttachCurrentThread(JVMPAR, (void**)&cbenv, NULL) < 0) { + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(CBENVONLY, "H5P_iterate_cb: failed to attach current thread to JVM"); + } -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_dset_no_attrs_hint - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1dset_1no_1attrs_1hint -(JNIEnv *env, jclass clss, jlong dcpl_id, jboolean minimize) -{ - herr_t retVal = -1; - hbool_t minimize_val; + if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - if (minimize == JNI_TRUE) - minimize_val = TRUE; - else - minimize_val = FALSE; + if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/callbacks/H5P_iterate_t;)I"))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - retVal = H5Pset_dset_no_attrs_hint((hid_t)dcpl_id, (hbool_t)minimize_val); - if (retVal < 0) - h5libraryError(env); -} + if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_dset_no_attrs_hint - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1dset_1no_1attrs_1hint -(JNIEnv *env, jclass clss, jlong dcpl_id) -{ - hbool_t minimize = FALSE; - jboolean bval = JNI_FALSE; + status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, prop_id, str, op_data); + CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); - if (H5Pget_dset_no_attrs_hint((hid_t)dcpl_id, (hbool_t *)&minimize) < 0) { - h5libraryError(env); - } - else { - if (minimize == TRUE) - bval = JNI_TRUE; - } /* end else */ +done: + if (cbenv) + JVMPTR->DetachCurrentThread(JVMPAR); - return bval; -} + return status; +} /* end H5P_iterate_cb */ #ifdef __cplusplus } /* end extern "C" */ diff --git a/java/src/jni/h5pImp.h b/java/src/jni/h5pImp.h index 056c569..8318be4 100644 --- a/java/src/jni/h5pImp.h +++ b/java/src/jni/h5pImp.h @@ -11,12 +11,13 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include /* Header for class hdf_hdf5lib_H5_H5_H5P */ #ifndef _Included_hdf_hdf5lib_H5_H5P #define _Included_hdf_hdf5lib_H5_H5P +#include + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -32,15 +33,6 @@ Java_hdf_hdf5lib_H5__1H5Pcreate /* * Class: hdf_hdf5lib_H5 - * Method: H5Pclose - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5__1H5Pclose -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 * Method: H5Pget_class * Signature: (J)J */ @@ -59,1571 +51,201 @@ Java_hdf_hdf5lib_H5__1H5Pcopy /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_userblock - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1userblock -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_userblock - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1userblock -(JNIEnv *, jclass, jlong, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sizes - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sizes -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sizes - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sizes -(JNIEnv *, jclass, jlong, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sym_k - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sym_1k -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sym_k - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sym_1k -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_istore_k - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1istore_1k -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_istore_k - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1istore_1k -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_layout - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1layout -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_layout + * Method: H5Pclose * Signature: (J)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1layout +Java_hdf_hdf5lib_H5__1H5Pclose (JNIEnv *, jclass, jlong); /* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk - * Signature: (JI[B)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk -(JNIEnv *, jclass, jlong, jint, jbyteArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk - * Signature: (JI[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk -(JNIEnv *, jclass, jlong, jint, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_alignment - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1alignment -(JNIEnv *, jclass, jlong, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_alignment - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1alignment -(JNIEnv *, jclass, jlong, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_external - * Signature: (JLjava/lang/String;JJ)I + * TODO: H5Pencode */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1external -(JNIEnv *, jclass, jlong, jstring, jlong, jlong); /* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_external_count - * Signature: (J)I + * TODO: H5Pdecode */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1external_1count -(JNIEnv *, jclass, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_external - * Signature: (JIJ[Ljava/lang/String;[J)I + * Method: _H5Pcreate_class + * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1external -(JNIEnv *, jclass, jlong, jint, jlong, jobjectArray, jlongArray); +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pcreate_1class + (JNIEnv*, jclass, jlong, jstring, jobject, jobject, jobject, jobject, jobject, jobject); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fill_value - * Signature: (JJ[B)I + * Method: _H5Pcreate_class_nocb + * Signature: (JLjava/lang/String;)J */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fill_1value -(JNIEnv *, jclass, jlong, jlong, jbyteArray); +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb + (JNIEnv*, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fill_value - * Signature: (JJ[B)I + * Method: H5Pregister2 + * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fill_1value -(JNIEnv *, jclass, jlong, jlong, jbyteArray); +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pregister2 + (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray, jobject, jobject, jobject, jobject, jobject, jobject, jobject); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_filter - * Signature: (JIIJ[I)I + * Method: H5Pregister2_nocb + * Signature: (JLjava/lang/String;J[B)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1filter -(JNIEnv *, jclass, jlong, jint, jint, jlong, jintArray); +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pregister2_1nocb + (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nfilters - * Signature: (J)I + * Method: H5Pinsert2 + * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nfilters -(JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pinsert2 + (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray, jobject, jobject, jobject, jobject, jobject, jobject); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter - * Signature: (JI[I[J[IJ[Ljava/lang/String;)I + * Method: H5Pinsert2_nocb + * Signature: (JLjava/lang/String;J[B)V */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter -(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray); +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb + (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_driver - * Signature: (J)J + * Method: H5Pset + * Signature: (JLjava/lang/String;I)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1driver -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_cache - * Signature: (JIJJD)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1cache -(JNIEnv *, jclass, jlong, jint, jlong, jlong, jdouble); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_cache - * Signature: (J[I[J[J[D)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1cache -(JNIEnv *, jclass, jlong, jintArray, jlongArray, jlongArray, jdoubleArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_buffer - * Signature: (JJ[B[B)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1buffer -(JNIEnv *, jclass, jlong, jlong, jbyteArray, jbyteArray); +Java_hdf_hdf5lib_H5_H5Pset +(JNIEnv *, jclass, jlong, jstring, jint); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_buffer - * Signature: (J[B[B)I + * Method: H5Pexist + * Signature: (JLjava/lang/String;)Z */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1buffer -(JNIEnv *, jclass, jlong, jbyteArray, jbyteArray); +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pexist +(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_buffer_size - * Signature: (JJ)V + * Method: H5Pget_size + * Signature: (JLjava/lang/String;)J */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1buffer_1size -(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1size +(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_buffer_size + * Method: H5Pget_nprops * Signature: (J)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1buffer_1size -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_preserve - * Signature: (JZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1preserve -(JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_preserve - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1preserve +Java_hdf_hdf5lib_H5_H5Pget_1nprops (JNIEnv *, jclass, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_deflate - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1deflate -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_gc_references - * Signature: (JZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1gc_1references -(JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_gc_references - * Signature: (J)Z + * Method: H5Pget_class_name + * Signature: (J)Ljava/lang/String; */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1gc_1references +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1class_1name (JNIEnv *, jclass, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_btree_ratios - * Signature: (JDDD)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1btree_1ratios -(JNIEnv *, jclass, jlong, jdouble, jdouble, jdouble); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_btree_ratios - * Signature: (J[D[D[D)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1btree_1ratios -(JNIEnv *, jclass, jlong, jdoubleArray, jdoubleArray, jdoubleArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_small_data_block_size - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1small_1data_1block_1size -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_small_data_block_size + * Method: H5Pget_class_parent * Signature: (J)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1small_1data_1block_1size +Java_hdf_hdf5lib_H5_H5Pget_1class_1parent (JNIEnv *, jclass, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_alloc_time - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1alloc_1time -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_alloc_time - * Signature: (J[I)I + * Method: H5Pisa_class + * Signature: (JJ)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1alloc_1time -(JNIEnv *, jclass, jlong, jintArray); +Java_hdf_hdf5lib_H5_H5Pisa_1class +(JNIEnv *, jclass, jlong, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fill_time - * Signature: (JI)I + * Method: H5Pget + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fill_1time -(JNIEnv *, jclass, jlong, jint); +Java_hdf_hdf5lib_H5_H5Pget +(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fill_time - * Signature: (J[I)I + * Method: H5Pequal + * Signature: (JJ)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fill_1time -(JNIEnv *, jclass, jlong, jintArray); +Java_hdf_hdf5lib_H5_H5Pequal +(JNIEnv *, jclass, jlong, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pfill_value_defined - * Signature: (J[I)I + * Method: H5Piterate + * Signature: (J[ILjava/lang/Object;Ljava/lang/Object;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pfill_1value_1defined -(JNIEnv *, jclass, jlong, jintArray); +Java_hdf_hdf5lib_H5_H5Piterate + (JNIEnv*, jclass, jlong, jintArray, jobject, jobject); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fletcher32 - * Signature: (J)I + * Method: H5Pcopy_prop + * Signature: (JJLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fletcher32 -(JNIEnv *, jclass, jlong); +Java_hdf_hdf5lib_H5_H5Pcopy_1prop +(JNIEnv *, jclass, jlong, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_edc_check - * Signature: (JI)I + * Method: H5Premove + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1edc_1check -(JNIEnv *, jclass, jlong, jint); +Java_hdf_hdf5lib_H5_H5Premove +(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pget_edc_check - * Signature: (J)I + * Method: H5Punregister + * Signature: (JLjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1edc_1check -(JNIEnv *, jclass, jlong); +Java_hdf_hdf5lib_H5_H5Punregister +(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shuffle + * Method: _H5Pclose_class * Signature: (J)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shuffle +Java_hdf_hdf5lib_H5__1H5Pclose_1class (JNIEnv *, jclass, jlong); -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_szip - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1szip -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_hyper_vector_size - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1hyper_1vector_1size -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_hyper_vector_size - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1hyper_1vector_1size -(JNIEnv *, jclass, jlong, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pall_filters_avail - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pall_1filters_1avail -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pmodify_filter - * Signature: (JIIJ[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pmodify_1filter -(JNIEnv *, jclass, jlong, jint, jint, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter_by_id - * Signature: (JI[I[J[IJ[Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id -(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fclose_degree - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fclose_1degree -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fclose_degree - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fclose_1degree -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_family - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1family -(JNIEnv *, jclass, jlong, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_family - * Signature: (J[J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family -(JNIEnv *, jclass, jlong, jlongArray, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_core - * Signature: (JJZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1core -(JNIEnv *, jclass, jlong, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_core - * Signature: (J[J[Z)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core -(JNIEnv *, jclass, jlong, jlongArray, jbooleanArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_family_offset - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1family_1offset -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_family_offset - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1family_1offset -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_log - * Signature: (JLjava/lang/String;JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log -(JNIEnv *, jclass, jlong, jstring, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Premove_filter - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5P1remove_1filter -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset - * Signature: (JLjava/lang/String;I)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pset -(JNIEnv *, jclass, jlong, jstring, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pexist - * Signature: (JLjava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pexist -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_size - * Signature: (JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1size -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nprops - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nprops -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_class_name - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1class_1name -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_class_parent - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1class_1parent -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pisa_class - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pisa_1class -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pequal - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pequal -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pcopy_prop - * Signature: (JJLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pcopy_1prop -(JNIEnv *, jclass, jlong, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Premove - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Premove -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Punregister - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Punregister -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pclose_class - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5__1H5Pclose_1class -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter2 - * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter2 -(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_filter_by_id2 - * Signature: (JI[I[J[IJ[Ljava/lang/String;[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1filter_1by_1id2 -(JNIEnv *, jclass, jlong, jint, jintArray, jlongArray, jintArray, jlong, jobjectArray, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_nlinks - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1nlinks -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_nlinks - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1nlinks -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_libver_bounds - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1libver_1bounds -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_libver_bounds - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1libver_1bounds -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_link_creation_order - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1link_1creation_1order -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_link_creation_order - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1link_1creation_1order -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_attr_creation_order - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_attr_creation_order - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_copy_object - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1copy_1object -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_copy_object - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1copy_1object -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_create_intermediate_group - * Signature: (JZ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group -(JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_create_intermediate_group - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_data_transform - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1data_1transform -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_data_transform - * Signature: (J[Ljava/lang/String;J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1data_1transform -(JNIEnv *, jclass, jlong, jobjectArray, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_acc_flags - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_acc_flags - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_link_phase_change - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1link_1phase_1change -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_link_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1link_1phase_1change -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_attr_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_attr_phase_change - * Signature: (JII)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_phase_change - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1phase_1change -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_phase_change - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1phase_1change -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_nindexes - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1nindexes -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_nindexes - * Signature: (JI)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1nindexes -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_shared_mesg_index - * Signature: (JIII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1shared_1mesg_1index -(JNIEnv *, jclass, jlong, jint, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_shared_mesg_index - * Signature: (JI[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1shared_1mesg_1index -(JNIEnv *, jclass, jlong, jint, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_local_heap_size_hint - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1local_1heap_1size_1hint -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_local_heap_size_hint - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1local_1heap_1size_1hint -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_nbit - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1nbit -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_scaleoffset - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1scaleoffset -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_est_link_info - * Signature: (JII)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1est_1link_1info -(JNIEnv *, jclass, jlong, jint, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_est_link_info - * Signature: (J[I)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1est_1link_1info -(JNIEnv *, jclass, jlong, jintArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_fapl - * Signature: (JJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pget_elink_fapl - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_prefix - * Signature: (JLjava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_prefix - * Signature: (J[Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix -(JNIEnv *, jclass, jlong, jobjectArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_direct - * Signature: (JJJJ)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1direct -(JNIEnv *, jclass, jlong, jlong, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_direct - * Signature: (J[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1direct -(JNIEnv *, jclass, jlong, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_sec2 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1sec2 -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_stdio - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1stdio -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_windows - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1windows -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_fapl_muti - * Signature: (J[I[J[Ljava/lang/String;[J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1fapl_1multi -(JNIEnv *, jclass, jlong, jintArray, jlongArray, jobjectArray, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_muti - * Signature: (J[I[J[Ljava/lang/String;[JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1multi -(JNIEnv *, jclass, jlong, jintArray, jlongArray, jobjectArray, jlongArray, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_fapl_split - * Signature: (JLjava/lang/String;JLjava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split -(JNIEnv *, jclass, jlong, jstring, jlong, jstring, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_meta_block_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1meta_1block_1size -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_meta_block_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1meta_1block_1size -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_sieve_buf_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1sieve_1buf_1size -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_sieve_buf_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_elink_file_cache_size - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1elink_1file_1cache_1size -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_elink_file_cache_size - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1elink_1file_1cache_1size -(JNIEnv *, jclass, jlong); - - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_mdc_config - * Signature: (J)Lhdf/hdf5lib/structs/H5AC_cache_config_t; - */ -JNIEXPORT jobject JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1mdc_1config -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_mdc_config - * Signature: (JLhdf/hdf5lib/structs/H5AC_cache_config_t;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config -(JNIEnv *, jclass, jlong, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk_cache - * Signature: (JJJD)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk_1cache -(JNIEnv *, jclass, jlong, jlong, jlong, jdouble); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk_cache - * Signature: (J[J[J[D)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache -(JNIEnv *, jclass, jlong, jlongArray, jlongArray, jdoubleArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_obj_track_times - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_obj_track_times - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times -(JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_char_encoding - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_char_encoding - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual - * Signature: (JJLjava/lang/String;Ljava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual -(JNIEnv *, jclass, jlong, jlong, jstring, jstring, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_count - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1count -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_vspace - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1vspace -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_srcspace - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1srcspace -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_filename - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1filename -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_dsetname - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1dsetname -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_view - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1view -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_view - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1view -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_printf_gap - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1printf_1gap -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_printf_gap - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1printf_1gap -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy - * Signature: (J[Z[J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy -(JNIEnv *, jclass, jlong, jbooleanArray, jlongArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy_persist - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1persist -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_strategy_threshold - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1strategy_1threshold -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_file_space_strategy - * Signature: (JIZJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1strategy -(JNIEnv *, jclass, jlong, jint, jboolean, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_file_space_page_size - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1file_1space_1page_1size -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_file_space_page_size - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1file_1space_1page_1size -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_mdc_log_options - * Signature: (JZLjava/lang/String;Z)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1mdc_1log_1options -(JNIEnv *, jclass, jlong, jboolean, jstring, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_mdc_log_options - * Signature: (J[Z)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1mdc_1log_1options -(JNIEnv *, jclass, jlong, jbooleanArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_append_flush - * Signature: (JI[JLjava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1append_1flush - (JNIEnv*, jclass, jlong, jint, jlongArray, jobject, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pcreate_class_nocb - * Signature: (JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb - (JNIEnv*, jclass, jlong, jstring); -/* - * Class: hdf_hdf5lib_H5 - * Method: _H5Pcreate_class - * Signature: (JLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5__1H5Pcreate_1class - (JNIEnv*, jclass, jlong, jstring, jobject, jobject, jobject, jobject, jobject, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pregister2_nocb - * Signature: (JLjava/lang/String;J[B)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pregister2_1nocb - (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pregister2 - * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pregister2 - (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray, jobject, jobject, jobject, jobject, jobject, jobject, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pinsert2_nocb - * Signature: (JLjava/lang/String;J[B)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb - (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pinsert2 - * Signature: (JLjava/lang/String;J[BLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pinsert2 - (JNIEnv*, jclass, jlong, jstring, jlong, jbyteArray, jobject, jobject, jobject, jobject, jobject, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Piterate - * Signature: (J[ILjava/lang/Object;Ljava/lang/Object;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Piterate - (JNIEnv*, jclass, jlong, jintArray, jobject, jobject); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_metadata_read_attempts - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1metadata_1read_1attempts -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_metadata_read_attempts - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1metadata_1read_1attempts -(JNIEnv *, jclass, jlong, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_virtual_prefix - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1virtual_1prefix -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_virtual_prefix - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1virtual_1prefix -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_efile_prefix - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1efile_1prefix -(JNIEnv *, jclass, jlong, jstring); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_efile_prefix - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1efile_1prefix -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_evict_on_close - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1evict_1on_1close -(JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_evict_on_close - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1evict_1on_1close -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_chunk_opts - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1chunk_1opts -(JNIEnv *, jclass, jlong, jint); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_chunk_opts - * Signature: (J)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1chunk_1opts -(JNIEnv *, jclass, jlong); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pset_dset_no_attrs_hint - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL -Java_hdf_hdf5lib_H5_H5Pset_1dset_1no_1attrs_1hint - (JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Pget_dset_no_attrs_hint - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5Pget_1dset_1no_1attrs_1hint - (JNIEnv *, jclass, jlong); - - #ifdef __cplusplus } /* end extern "C" */ #endif /* __cplusplus */ diff --git a/java/src/jni/h5pLAPLImp.c b/java/src/jni/h5pLAPLImp.c new file mode 100644 index 0000000..c4502d5 --- /dev/null +++ b/java/src/jni/h5pLAPLImp.c @@ -0,0 +1,237 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pLAPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_nlinks + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1nlinks + (JNIEnv *env, jclass clss, jlong lapl_id, jlong nlinks) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if (nlinks <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_nlinks: nlinks <= 0"); + + if ((retVal = H5Pset_nlinks((hid_t)lapl_id, (size_t)nlinks)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1nlinks */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_nlinks + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1nlinks + (JNIEnv *env, jclass clss, jlong lapl_id) +{ + size_t nlinks = 0; + + UNUSED(clss); + + if (H5Pget_nlinks((hid_t)lapl_id, &nlinks) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong) nlinks; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1nlinks */ + +/* + * TODO: H5Pset_elink_cb + */ + +/* + * TODO: H5Pget_elink_cb + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_prefix + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix + (JNIEnv *env, jclass clss, jlong lapl_id, jstring prefix) +{ + const char *linkPrefix = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + PIN_JAVA_STRING(ENVONLY, prefix, linkPrefix, NULL, "H5Pset_elink_prefix: link prefix not pinned"); + + if ((retVal = H5Pset_elink_prefix((hid_t)lapl_id, linkPrefix)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (linkPrefix) + UNPIN_JAVA_STRING(ENVONLY, prefix, linkPrefix); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_prefix + * Signature: (J[Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix + (JNIEnv *env, jclass clss, jlong lapl_id, jobjectArray prefix) +{ + ssize_t prefix_size = -1; + size_t size = 0; + char *pre = NULL; + jstring str = NULL; + + UNUSED(clss); + + if (NULL == prefix) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_elink_prefix: prefix is NULL"); + + if ((prefix_size = H5Pget_elink_prefix((hid_t)lapl_id, (char *)NULL, size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t) prefix_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: memory allocation failed"); + + if (H5Pget_elink_prefix((hid_t)lapl_id, (char *)pre, (size_t) prefix_size + 1) < 0) + H5_LIBRARY_ERROR(ENVONLY); + pre[prefix_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: out of memory - unable to construct string from UTF characters"); + } + + ENVPTR->SetObjectArrayElement(ENVONLY, prefix, 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (pre) + HDfree(pre); + + return (jlong)prefix_size; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_fapl + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl + (JNIEnv *env, jclass clss, jlong lapl_id, jlong fapl_id) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_elink_fapl((hid_t)lapl_id, (hid_t)fapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: _H5Pget_elink_fapl + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl + (JNIEnv *env, jclass clss, jlong lapl_id) +{ + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if ((retVal = H5Pget_elink_fapl((hid_t)lapl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)retVal; +} /* end Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_acc_flags + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags + (JNIEnv *env, jclass clss, jlong lapl_id, jint flags) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_elink_acc_flags((hid_t)lapl_id, (unsigned)flags)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint) retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_acc_flags + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags + (JNIEnv *env, jclass clss, jlong lapl_id) +{ + unsigned flags; + + UNUSED(clss); + + if (H5Pget_elink_acc_flags((hid_t)lapl_id, &flags) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)flags; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pLAPLImp.h b/java/src/jni/h5pLAPLImp.h new file mode 100644 index 0000000..8efcfb5 --- /dev/null +++ b/java/src/jni/h5pLAPLImp.h @@ -0,0 +1,107 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PLAPL +#define _Included_hdf_hdf5lib_H5_H5PLAPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_nlinks + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1nlinks +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_nlinks + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1nlinks +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Pset_elink_cb + */ + +/* + * TODO: H5Pget_elink_cb + */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_prefix + * Signature: (JLjava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix +(JNIEnv *, jclass, jlong, jstring); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_prefix + * Signature: (J[Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix +(JNIEnv *, jclass, jlong, jobjectArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_fapl + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl +(JNIEnv *, jclass, jlong, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: _H5Pget_elink_fapl + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_elink_acc_flags + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_elink_acc_flags + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags +(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PLAPL */ diff --git a/java/src/jni/h5pLCPLImp.c b/java/src/jni/h5pLCPLImp.c new file mode 100644 index 0000000..7c79796 --- /dev/null +++ b/java/src/jni/h5pLCPLImp.c @@ -0,0 +1,36 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pLCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pLCPLImp.h b/java/src/jni/h5pLCPLImp.h new file mode 100644 index 0000000..009d1b4 --- /dev/null +++ b/java/src/jni/h5pLCPLImp.h @@ -0,0 +1,27 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PLCPL +#define _Included_hdf_hdf5lib_H5_H5PLCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PLCPL */ diff --git a/java/src/jni/h5pOCPLImp.c b/java/src/jni/h5pOCPLImp.c new file mode 100644 index 0000000..241842e --- /dev/null +++ b/java/src/jni/h5pOCPLImp.c @@ -0,0 +1,211 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pOCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_create_intermediate_group + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group + (JNIEnv *env, jclass clss, jlong lcpl_id, jboolean crt_intermed_group) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_create_intermediate_group((hid_t)lcpl_id, (unsigned)crt_intermed_group)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_create_intermediate_group + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group + (JNIEnv *env, jclass clss, jlong lcpl_id) +{ + unsigned crt_intermed_group = 0; + + UNUSED(clss); + + if (H5Pget_create_intermediate_group((hid_t)lcpl_id, &crt_intermed_group) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jboolean)crt_intermed_group; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_obj_track_times + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times + (JNIEnv *env, jclass clss, jlong objplid, jboolean track_times) +{ + hbool_t track = FALSE; + + UNUSED(clss); + + track = (JNI_TRUE == track_times) ? 1 : 0; + + if (H5Pset_obj_track_times((hid_t)objplid, track) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_obj_track_times + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times + (JNIEnv *env, jclass clss, jlong objplid) +{ + hbool_t track_times = FALSE; + jboolean retVal = JNI_FALSE; + + UNUSED(clss); + + if (H5Pget_obj_track_times((hid_t)objplid, &track_times) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + retVal = (track_times == TRUE) ? JNI_TRUE : JNI_FALSE; + +done: + return retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_attr_phase_change + * Signature: (JII)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change + (JNIEnv *env, jclass clss, jlong ocpl_id, jint max_compact, jint min_dense) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_attr_phase_change((hid_t)ocpl_id, (unsigned)max_compact, (unsigned)min_dense)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_attr_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change + (JNIEnv *env, jclass clss, jlong ocpl_id, jintArray attributes) +{ + jboolean isCopy; + jint *theArray = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (NULL == attributes) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_attr_phase_change: attributes is NULL"); + + PIN_INT_ARRAY(ENVONLY, attributes, theArray, &isCopy, "H5Pget_attr_phase_change: input not pinned"); + + if ((retVal = H5Pget_attr_phase_change((hid_t)ocpl_id, (unsigned *)&(theArray[0]), (unsigned *)&(theArray[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (theArray) + UNPIN_INT_ARRAY(ENVONLY, attributes, theArray, (retVal < 0) ? JNI_ABORT : 0); + + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_attr_creation_order + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order + (JNIEnv *env, jclass clss, jlong ocpl_id, jint crt_order_flags) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_attr_creation_order((hid_t)ocpl_id, (unsigned)crt_order_flags)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_attr_creation_order + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order + (JNIEnv *env, jclass clss, jlong ocpl_id) +{ + unsigned crt_order_flags = 0; + + UNUSED(clss); + + if (H5Pget_attr_creation_order((hid_t)ocpl_id, &crt_order_flags) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)crt_order_flags; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pOCPLImp.h b/java/src/jni/h5pOCPLImp.h new file mode 100644 index 0000000..fe01f06 --- /dev/null +++ b/java/src/jni/h5pOCPLImp.h @@ -0,0 +1,99 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5POCPL +#define _Included_hdf_hdf5lib_H5_H5POCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_create_intermediate_group + * Signature: (JZ)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1create_1intermediate_1group +(JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_create_intermediate_group + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1create_1intermediate_1group +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_obj_track_times + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1obj_1track_1times +(JNIEnv *, jclass, jlong, jboolean); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_obj_track_times + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1obj_1track_1times +(JNIEnv *, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_attr_phase_change + * Signature: (JII)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1attr_1phase_1change +(JNIEnv *, jclass, jlong, jint, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_attr_phase_change + * Signature: (J[I)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1attr_1phase_1change +(JNIEnv *, jclass, jlong, jintArray); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_attr_creation_order + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1attr_1creation_1order +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_attr_creation_order + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1attr_1creation_1order +(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5POCPL */ diff --git a/java/src/jni/h5pOCpyPLImp.c b/java/src/jni/h5pOCpyPLImp.c new file mode 100644 index 0000000..9481f91 --- /dev/null +++ b/java/src/jni/h5pOCpyPLImp.c @@ -0,0 +1,92 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pOCpyPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_copy_object + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1copy_1object + (JNIEnv *env, jclass clss, jlong ocp_plist_id, jint copy_options) +{ + herr_t retVal = FAIL; + + UNUSED(clss); + + if ((retVal = H5Pset_copy_object((hid_t)ocp_plist_id, (unsigned)copy_options)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1copy_1object */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_copy_object + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1copy_1object + (JNIEnv *env, jclass clss, jlong ocp_plist_id) +{ + unsigned copy_options = 0; + + UNUSED(clss); + + if (H5Pget_copy_object((hid_t)ocp_plist_id, ©_options) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)copy_options; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1copy_1object */ + +/* + * TODO: H5Padd_merge_committed_dtype_path + */ + +/* + * TODO: H5Pfree_merge_committed_dtype_paths + */ + +/* + * TODO: H5Pset_mcdt_search_cb + */ + +/* + * TODO: H5Pget_mcdt_search_cb + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pOCpyPLImp.h b/java/src/jni/h5pOCpyPLImp.h new file mode 100644 index 0000000..f1dca58 --- /dev/null +++ b/java/src/jni/h5pOCpyPLImp.h @@ -0,0 +1,61 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5POCpyPL +#define _Included_hdf_hdf5lib_H5_H5POCpyPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_copy_object + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1copy_1object +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_copy_object + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1copy_1object +(JNIEnv *, jclass, jlong); + +/* + * TODO: H5Padd_merge_committed_dtype_path + */ + +/* + * TODO: H5Pfree_merge_committed_dtype_paths + */ + +/* + * TODO: H5Pset_mcdt_search_cb + */ + +/* + * TODO: H5Pget_mcdt_search_cb + */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5POCpyPL */ diff --git a/java/src/jni/h5pStrCPLImp.c b/java/src/jni/h5pStrCPLImp.c new file mode 100644 index 0000000..e69847d --- /dev/null +++ b/java/src/jni/h5pStrCPLImp.c @@ -0,0 +1,74 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * For details of the HDF libraries, see the HDF Documentation at: + * http://hdfgroup.org/HDF5/doc/ + * + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include "hdf5.h" +#include "h5jni.h" +#include "h5pStrCPLImp.h" + +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_char_encoding + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding + (JNIEnv *env, jclass clss, jlong acpl, jint encoding) +{ + UNUSED(clss); + + if (H5Pset_char_encoding((hid_t)acpl, (H5T_cset_t)encoding) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; +} /* end Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_char_encoding + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding + (JNIEnv *env, jclass clss, jlong acpl) +{ + H5T_cset_t encoding = H5T_CSET_ERROR; + + UNUSED(clss); + + if (H5Pget_char_encoding((hid_t)acpl, &encoding) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return encoding; +} /* end Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ diff --git a/java/src/jni/h5pStrCPLImp.h b/java/src/jni/h5pStrCPLImp.h new file mode 100644 index 0000000..6e140d3 --- /dev/null +++ b/java/src/jni/h5pStrCPLImp.h @@ -0,0 +1,45 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef _Included_hdf_hdf5lib_H5_H5PStrCPL +#define _Included_hdf_hdf5lib_H5_H5PStrCPL + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pset_char_encoding + * Signature: (JI)V + */ +JNIEXPORT void JNICALL +Java_hdf_hdf5lib_H5_H5Pset_1char_1encoding +(JNIEnv *, jclass, jlong, jint); + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Pget_char_encoding + * Signature: (J)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Pget_1char_1encoding +(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif /* __cplusplus */ + +#endif /* _Included_hdf_hdf5lib_H5_H5PStrCPL */ diff --git a/java/src/jni/h5plImp.c b/java/src/jni/h5plImp.c index d551120..4e096f1 100644 --- a/java/src/jni/h5plImp.c +++ b/java/src/jni/h5plImp.c @@ -26,7 +26,10 @@ extern "C" { #include "h5jni.h" #include "h5plImp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -37,9 +40,13 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLset_1loading_1state (JNIEnv *env, jclass clss, jint plugin_flags) { - if (H5PLset_loading_state((unsigned int)plugin_flags) < 0) { - h5libraryError(env); - } + UNUSED(clss); + + if (H5PLset_loading_state((unsigned int)plugin_flags) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5PLset_1loading_1state */ /* @@ -52,9 +59,13 @@ Java_hdf_hdf5lib_H5_H5PLget_1loading_1state (JNIEnv *env, jclass clss) { unsigned int plugin_type = 0; - if (H5PLget_loading_state(&plugin_type) < 0) { - h5libraryError(env); - } + + UNUSED(clss); + + if (H5PLget_loading_state(&plugin_type) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)plugin_type; } /* end Java_hdf_hdf5lib_H5_H5PLget_1loading_1state */ @@ -67,18 +78,19 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLappend (JNIEnv *env, jclass clss, jobjectArray plugin_path) { - const char *aName; - herr_t retVal = -1; + const char *newPath = NULL; + herr_t retVal = FAIL; - PIN_JAVA_STRING(plugin_path, aName); - if (aName != NULL) { - retVal = H5PLappend(aName); + UNUSED(clss); - UNPIN_JAVA_STRING(plugin_path, aName); + PIN_JAVA_STRING(ENVONLY, plugin_path, newPath, NULL, "H5PLappend: new path not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5PLappend(newPath)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (newPath) + UNPIN_JAVA_STRING(ENVONLY, plugin_path, newPath); } /* end Java_hdf_hdf5lib_H5_H5PLappend */ /* * Class: hdf_hdf5lib_H5 @@ -89,18 +101,19 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLprepend (JNIEnv *env, jclass clss, jobjectArray plugin_path) { - const char *aName; - herr_t retVal = -1; + const char *newPath = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); - PIN_JAVA_STRING(plugin_path, aName); - if (aName != NULL) { - retVal = H5PLprepend(aName); + PIN_JAVA_STRING(ENVONLY, plugin_path, newPath, NULL, "H5PLprepend: new path not pinned"); - UNPIN_JAVA_STRING(plugin_path, aName); + if ((retVal = H5PLprepend(newPath)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retVal < 0) - h5libraryError(env); - } +done: + if (newPath) + UNPIN_JAVA_STRING(ENVONLY, plugin_path, newPath); } /* end Java_hdf_hdf5lib_H5_H5PLprepend */ /* @@ -112,18 +125,22 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLreplace (JNIEnv *env, jclass clss, jobjectArray plugin_path, jint index) { - const char *aName; - herr_t retVal = -1; + const char *newPath = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); - PIN_JAVA_STRING(plugin_path, aName); - if (aName != NULL) { - retVal = H5PLreplace(aName, index); + if (index < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5PLreplace: index < 0"); - UNPIN_JAVA_STRING(plugin_path, aName); + PIN_JAVA_STRING(ENVONLY, plugin_path, newPath, NULL, "H5PLreplace: new path not pinned"); - if (retVal < 0) - h5libraryError(env); - } + if ((retVal = H5PLreplace(newPath, (unsigned) index)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (newPath) + UNPIN_JAVA_STRING(ENVONLY, plugin_path, newPath); } /* end Java_hdf_hdf5lib_H5_H5PLreplace */ /* @@ -135,18 +152,22 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLinsert (JNIEnv *env, jclass clss, jobjectArray plugin_path, jint index) { - const char *aName; - herr_t retVal = -1; + const char *newPath = NULL; + herr_t retVal = FAIL; + + UNUSED(clss); + + if (index < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5PLinsert: index < 0"); - PIN_JAVA_STRING(plugin_path, aName); - if (aName != NULL) { - retVal = H5PLinsert(aName, index); + PIN_JAVA_STRING(ENVONLY, plugin_path, newPath, NULL, "H5PLinsert: new path not pinned"); - UNPIN_JAVA_STRING(plugin_path, aName); + if ((retVal = H5PLinsert(newPath, (unsigned) index)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retVal < 0) - h5libraryError(env); - } +done: + if (newPath) + UNPIN_JAVA_STRING(ENVONLY, plugin_path, newPath); } /* end Java_hdf_hdf5lib_H5_H5PLinsert */ /* @@ -158,8 +179,16 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5PLremove (JNIEnv *env, jclass clss, jint index) { - if (H5PLremove(index) < 0) - h5libraryError(env); + UNUSED(clss); + + if (index < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5PLremove: index < 0"); + + if (H5PLremove((unsigned) index) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5PLremove */ /* @@ -171,33 +200,33 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5PLget (JNIEnv *env, jclass clss, jint index) { - char *aName; jstring str = NULL; ssize_t buf_size; + char *aName = NULL; + + UNUSED(clss); + + if (index < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5PLget: index < 0"); + + /* Get the length of the name */ + if ((buf_size = H5PLget((unsigned) index, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5PLget: failed to allocate plugin name buffer"); + + if ((H5PLget((unsigned) index, aName, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + aName[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (aName) + HDfree(aName); - /* get the length of the name */ - buf_size = H5PLget(index, NULL, 0); - - if (buf_size <= 0) { - h5badArgument(env, "H5PLget: buf_size <= 0"); - } /* end if */ - else { - buf_size++; /* add extra space for the null terminator */ - aName = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); - if (aName == NULL) { - h5outOfMemory(env, "H5PLget: malloc failed"); - } /* end if */ - else { - buf_size = H5PLget(index, aName, (size_t)buf_size); - if (buf_size < 0) { - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - } - HDfree(aName); - } - } return str; } /* end Java_hdf_hdf5lib_H5_H5PLget */ @@ -211,9 +240,13 @@ Java_hdf_hdf5lib_H5_H5PLsize (JNIEnv *env, jclass clss) { unsigned int listsize = 0; - if (H5PLsize(&listsize) < 0) { - h5libraryError(env); - } + + UNUSED(clss); + + if (H5PLsize(&listsize) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)listsize; } /* end Java_hdf_hdf5lib_H5_H5PLsize */ diff --git a/java/src/jni/h5rImp.c b/java/src/jni/h5rImp.c index 5f2b86d..9278113 100644 --- a/java/src/jni/h5rImp.c +++ b/java/src/jni/h5rImp.c @@ -26,8 +26,10 @@ extern "C" { #include "h5jni.h" #include "h5rImp.h" -extern JavaVM *jvm; - +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -38,47 +40,42 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rcreate (JNIEnv *env, jclass clss, jbyteArray ref, jlong loc_id, jstring name, jint ref_type, jlong space_id) { - const char *rName; - herr_t status = -1; - jbyte *refP; - jboolean isCopy2; - - PIN_JAVA_STRING(name, rName); - if (rName != NULL) { - if (ref == NULL) { - h5nullArgument( env, "H5Rcreate: ref is NULL"); - } /* end if */ - else { - if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument( env, "H5Rcreate: ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end if */ - else if ((ref_type == H5R_DATASET_REGION) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rcreate: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else if ((ref_type != H5R_OBJECT) && (ref_type != H5R_DATASET_REGION)) { - h5badArgument( env, "H5Rcreate: ref_type unknown type "); - } /* end else if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy2); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rcreate: ref not pinned"); - } /* end if */ - else { - status = H5Rcreate(refP, (hid_t)loc_id, rName, (H5R_type_t)ref_type, (hid_t)space_id); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, rName); + const char *refName = NULL; + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: reference is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: ref array length < 0"); } + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: unknown reference type"); + + PIN_JAVA_STRING(ENVONLY, name, refName, NULL, "H5Rcreate: reference name not pinned"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rcreate: reference buffer not pinned"); + + if ((status = H5Rcreate(refBuf, (hid_t)loc_id, refName, (H5R_type_t)ref_type, (hid_t)space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (status < 0) ? JNI_ABORT : 0); + if (refName) + UNPIN_JAVA_STRING(ENVONLY, name, refName); + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Rcreate */ @@ -91,33 +88,36 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Rdereference (JNIEnv *env, jclass clss, jlong dataset, jlong access_list, jint ref_type, jbyteArray ref) { - jboolean isCopy; - jbyte *refP; - hid_t retVal = -1; - - if (ref == NULL) { - h5nullArgument( env, "H5Rdereference: ref is NULL"); - } /* end if */ - else if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument( env, "H5Rdereference: obj ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end else if */ - else if ((ref_type == H5R_DATASET_REGION) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rdereference: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rderefernce: ref not pinned"); - } /* end if */ - else { - retVal = H5Rdereference2((hid_t)dataset, (hid_t)access_list, (H5R_type_t)ref_type, refP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: ref array length < 0"); + } + + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: unknown reference type"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rderefernce: reference buffer not pinned"); + + if ((retVal = H5Rdereference2((hid_t)dataset, (hid_t)access_list, (H5R_type_t)ref_type, refBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Rdereference */ @@ -131,33 +131,34 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Rget_1region (JNIEnv *env, jclass clss, jlong dataset, jint ref_type, jbyteArray ref) { - hid_t retVal = -1; - jboolean isCopy; - jbyte *refP; - - if (ref_type != H5R_DATASET_REGION) { - h5badArgument( env, "H5Rget_region: bad ref_type "); - } /* end if */ - else if (ref == NULL) { - h5nullArgument( env, "H5Rget_region: ref is NULL"); - } /* end if */ - else if ( ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rget_region: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_region: ref not pinned"); - } /* end if */ - else { - retVal = H5Rget_region((hid_t)dataset, (H5R_type_t)ref_type, refP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (H5R_DATASET_REGION != ref_type) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: bad reference type"); + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: ref array length < 0"); + } + + if (refBufLen != H5R_DSET_REG_REF_BUF_SIZE) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_region: reference buffer not pinned"); + + if ((retVal = H5Rget_region((hid_t)dataset, (H5R_type_t)ref_type, refBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Rget_1region */ @@ -171,31 +172,27 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rget_1obj_1type (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref) { - int retVal =-1; - jboolean isCopy; - jbyte *refP; - H5O_type_t object_info; - - - if (ref == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref is NULL"); - } /* end if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_object_type: ref not pinned"); - } /* end if */ - else { - retVal = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refP, &object_info); - if(retVal >= 0) - retVal = object_info; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + H5O_type_t object_info; + jboolean isCopy; + jbyte *refBuf = NULL; + int retVal = -1; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference buffer is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_obj_type: reference buffer not pinned"); + + if ((retVal = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, &object_info)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (retVal >= 0) + retVal = object_info; + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Rget_1obj_1type */ @@ -209,46 +206,33 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rget_1obj_1type2 (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref, jintArray ref_obj) { + jboolean isCopy, isCopy2; + jbyte *refBuf = NULL; + jint *ref_objP = NULL; + jint status; + int retVal = -1; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference buffer is NULL"); + if (NULL == ref_obj) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference object is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_obj_type: reference buffer not pinned"); - jint status; - jboolean isCopy; - jbyte *refP; - jint *ref_objP; - int retVal = -1; - - - if (ref == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref is NULL"); - } /* end if */ - else if (ref_obj == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref_obj is NULL"); - } /* end else if */ - else { - refP = (jbyte *)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_object_type: ref not pinned"); - } /* end if */ - else { - ref_objP = (jint *)ENVPTR->GetIntArrayElements(ENVPAR ref_obj, &isCopy); - if (ref_objP == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref,refP,0); - h5JNIFatalError(env, "H5Rget_object_type: ref_obj not pinned"); - } /* end if */ - else { - status = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refP, (H5O_type_t*)ref_objP); - retVal = ref_objP[0]; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR ref_obj,ref_objP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseIntArrayElements(ENVPAR ref_obj, ref_objP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + PIN_INT_ARRAY(ENVONLY, ref_obj, ref_objP, &isCopy2, "H5Rget_obj_type: reference object array not pinned"); + + if ((status = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, (H5O_type_t *)ref_objP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + retVal = ref_objP[0]; + +done: + if (ref_objP) + UNPIN_INT_ARRAY(ENVONLY, ref_obj, ref_objP, (status < 0) ? JNI_ABORT : 0); + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, JNI_ABORT); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Rget_1obj_1type2 */ @@ -262,57 +246,52 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Rget_1name (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref, jobjectArray name, jlong size) { - jlong ret_val = -1; - jbyte *refP; - jboolean isCopy; - char *aName = NULL; - jstring str; - size_t bs; - - bs = (size_t)size; - if (bs <= 0) { - h5badArgument(env, "H5Rget_name: size <= 0"); - } /* end if */ - else if (ref == NULL) { - h5nullArgument(env, "H5Rget_name: ref is NULL"); - } /* end else if */ - else { - if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument(env, "H5Rget_name: obj ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end if */ - else if ((ref_type == H5R_DATASET_REGION) - && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument(env, "H5Rget_name: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else { - refP = (jbyte *)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_name: ref not pinned"); - } /* end if */ - else { - aName = (char*)HDmalloc(sizeof(char)*bs); - if (aName == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - h5outOfMemory(env, "H5Rget_name: malloc failed"); - } /* end if */ - else { - ret_val = (jlong)H5Rget_name((hid_t)loc_id, (H5R_type_t)ref_type, refP, aName, bs) ; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - if (ret_val < 0) { - HDfree(aName); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, str); - - HDfree(aName); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + jstring str; + jsize refBufLen; + jbyte *refBuf = NULL; + char *aName = NULL; + jlong ret_val = -1; + + UNUSED(clss); + + if (size <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: size <= 0"); + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: ref array length < 0"); + } + + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: unknown reference type"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_name: reference buffer not pinned"); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Rget_name: failed to allocate referenced object name buffer"); + + if ((ret_val = (jlong)H5Rget_name((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, aName, (size_t)size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + aName[(size_t)size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, name, (jsize) 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (aName) + HDfree(aName); + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, JNI_ABORT); return ret_val; } /* end Java_hdf_hdf5lib_H5_H5Rget_1name */ diff --git a/java/src/jni/h5sImp.c b/java/src/jni/h5sImp.c index 65cdd7b..67ea59d 100644 --- a/java/src/jni/h5sImp.c +++ b/java/src/jni/h5sImp.c @@ -26,7 +26,10 @@ extern "C" { #include "h5jni.h" #include "h5sImp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -37,12 +40,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Screate (JNIEnv *env, jclass clss, jint type) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Screate((H5S_class_t) type); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Screate((H5S_class_t) type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Screate */ @@ -55,98 +60,83 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Screate_1simple (JNIEnv *env, jclass clss, jint rank, jlongArray dims, jlongArray maxdims) { - hid_t retVal = -1; - jlong *dimsP, *maxdimsP; - jboolean isCopy; - hsize_t *sa = NULL; - hsize_t *msa = NULL; - int i; - int drank, mrank; - hsize_t *lp; - jlong *jlp; - - if (rank < 0) { - h5badArgument(env, "H5Screate_simple: rank is invalid"); - } /* end if */ - else if (dims == NULL) { - h5nullArgument(env, "H5Screate_simple: dims is NULL"); - } /* end else if */ + jboolean isCopy; + hsize_t *sa = NULL; + hsize_t *msa = NULL; + hsize_t *lp = NULL; + jlong *dimsP = NULL, *maxdimsP = NULL; + jlong *jlp = NULL; + jsize drank, mrank; + int i; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (rank < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: rank is invalid"); + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: dims is NULL"); + + if ((drank = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: dims array length < 0"); + } + + if (drank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: dims rank is invalid"); + + if (NULL != maxdims) { + if ((mrank = ENVPTR->GetArrayLength(ENVONLY, maxdims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: maxdims array length < 0"); + } + + if (mrank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Screate_simple: maxdims rank is invalid"); + } + + PIN_LONG_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Screate_simple: dims not pinned"); + + if (NULL == (sa = lp = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Screate_simple: failed to allocate dims buffer") + + jlp = (jlong *) dimsP; + for (i = 0; i < rank; i++) { + *lp = (hsize_t) *jlp; + lp++; + jlp++; + } /* end for */ + + if (NULL == maxdims) { + maxdimsP = NULL; + msa = (hsize_t *)maxdimsP; + } else { - drank = (int)ENVPTR->GetArrayLength(ENVPAR dims); - if (drank != rank) { - h5badArgument(env, "H5Screate_simple: dims rank is invalid"); - return -1; - } /* end if */ - if (maxdims != NULL) { - mrank = (int)ENVPTR->GetArrayLength(ENVPAR maxdims); - if (mrank != rank) { - h5badArgument(env, "H5Screate_simple: maxdims rank is invalid"); - return -1; - } /* end if */ - } /* end if */ - dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy); - if (dimsP == NULL) { - h5JNIFatalError(env, "H5Screate_simple: dims not pinned"); - return -1; - } /* end if */ + PIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, &isCopy, "H5Screate_simple: maxdims not pinned"); - sa = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (sa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Screate_simple: dims not converted to hsize_t"); - return -1; - } /* end if */ + if (NULL == (msa = lp = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Screate_simple: failed to allocate maxdims buffer") - jlp = (jlong *) dimsP; - for (i = 0; i < rank; i++) { + jlp = (jlong *) maxdimsP; + for (i = 0; i < mrank; i++) { *lp = (hsize_t) *jlp; lp++; jlp++; } /* end for */ + } - if (maxdims == NULL) { - maxdimsP = NULL; - msa = (hsize_t *)maxdimsP; - } /* end if */ - else { - maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims, &isCopy); - if (maxdimsP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - h5JNIFatalError(env, "H5Screate_simple: maxdims not pinned"); - return -1; - } /* end if */ - msa = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (msa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - HDfree(sa); - h5JNIFatalError(env, "H5Screate_simple: dims not converted to hsize_t"); - return -1; - } /* end if */ - jlp = (jlong *)maxdimsP; - for (i = 0; i < mrank; i++) { - *lp = (hsize_t)*jlp; - lp++; - jlp++; - } /* end for */ - } /* end else */ - - retVal = H5Screate_simple(rank, (const hsize_t *)sa, (const hsize_t *)msa); - - if (maxdimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - if (msa) - HDfree(msa); - } /* end if */ + if ((retVal = H5Screate_simple(rank, (const hsize_t *)sa, (const hsize_t *)msa)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - if (sa) - HDfree(sa); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ +done: + if (msa) + HDfree(msa); + if (maxdimsP) + UNPIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, JNI_ABORT); + if (sa) + HDfree(sa); + if (dimsP) + UNPIN_LONG_ARRAY(ENVONLY, dims, dimsP, JNI_ABORT); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Screate_1simple */ @@ -160,12 +150,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Scopy (JNIEnv *env, jclass clss, jlong space_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Scopy(space_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Scopy(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Scopy */ @@ -185,41 +177,37 @@ Java_hdf_hdf5lib_H5__1H5Scopy */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sselect_1elements - (JNIEnv *env, jclass clss, jlong space_id, jint op, jint num_elemn, jlongArray coord) + (JNIEnv *env, jclass clss, jlong space_id, jint op, jint num_elemn, jlongArray coords) { - herr_t status = -1; - jint i; - jlong *P; - jboolean isCopy; - hssize_t *sa; - int rank; - - if (coord == NULL) { - h5nullArgument( env, "H5Sselect_elements: coord is NULL"); - return -1; - } /* end if */ + jboolean isCopy; + hssize_t *sa = NULL; + jlong *P = NULL; + jint i; + int rank; + herr_t status = FAIL; - P = ENVPTR->GetLongArrayElements(ENVPAR env,coord,&isCopy); - if (P == NULL) { - h5JNIFatalError(env, "H5Sselect_elements: coord not pinned"); - return -1; - } /* end if */ - sa = (hssize_t *)HDmalloc( (size_t)num_elems * 2 * sizeof(hssize_t)); - if (sa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR env,coord,P,JNI_ABORT); - h5JNIFatalError(env, "H5Sselect_elements: coord array not converted to hssize_t"); - return -1; - } /* end if */ - for (i= 0; i < (num_elsms * 2); i++) { + UNUSED(clss); + + if (NULL == coords) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sselect_elements: coords is NULL"); + + PIN_LONG_ARRAY(ENVONLY, coords, P, &isCopy, "H5Sselect_elements: coords not pinned"); + + if (NULL == (sa = (hssize_t *) HDmalloc( (size_t)num_elemn * 2 * sizeof(hssize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_elements: failed to allocate coordinate buffer"); + + for (i = 0; i < (num_elemn * 2); i++) { sa[i] = P[i]; } /* end for */ - status = H5Sselect_elements (space_id, (H5S_seloper_t)op, num_elemn, (const hssize_t **)&sa); - ENVPTR->ReleaseLongArrayElements(ENVPAR env, coord, P, JNI_ABORT); - HDfree(sa); + if ((status = H5Sselect_elements(space_id, (H5S_seloper_t)op, num_elemn, (const hssize_t **)&sa)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); +done: + if (sa) + HDfree(sa); + if (P) + UNPIN_LONG_ARRAY(ENVONLY, coords, P, JNI_ABORT); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1elements */ @@ -232,49 +220,51 @@ Java_hdf_hdf5lib_H5_H5Sselect_1elements */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sselect_1elements - (JNIEnv *env, jclass clss, jlong space_id, jint op, jint num_elemn, jbyteArray coord) + (JNIEnv *env, jclass clss, jlong space_id, jint op, jint num_elemn, jbyteArray coords) { - int ii; - hsize_t *lp = NULL; - hsize_t *llp; - jlong *jlp; - herr_t status = -1; - jbyte *P; - jboolean isCopy; - jsize size; - int nlongs; - - if (coord == NULL) { - h5nullArgument(env, "H5Sselect_elements: coord is NULL"); - } /* end if */ - else { - P = ENVPTR->GetByteArrayElements(ENVPAR coord, &isCopy); - if (P == NULL) { - h5JNIFatalError(env, "H5Sselect_elements: coord not pinned"); - } /* end if */ - else { - size = (int)ENVPTR->GetArrayLength(ENVPAR coord); - nlongs = (int)((size_t)size / sizeof(jlong)); - lp = (hsize_t *)HDmalloc((size_t)nlongs * sizeof(hsize_t)); - jlp = (jlong *) P; - llp = lp; - for (ii = 0; ii < nlongs; ii++) { - *lp = (hsize_t) *jlp; - lp++; - jlp++; - } /* end for */ - - status = H5Sselect_elements(space_id, (H5S_seloper_t)op, (size_t)num_elemn, (const hsize_t *)llp); - - ENVPTR->ReleaseByteArrayElements(ENVPAR coord, P, JNI_ABORT); - - if (llp) - HDfree(llp); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *lp = NULL; + hsize_t *llp = NULL; + jlong *jlp = NULL; + jbyte *P = NULL; + jsize size; + int ii; + int nlongs; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == coords) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sselect_elements: coords is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, coords, P, &isCopy, "H5Sselect_elements: coords not pinned"); + + if ((size = ENVPTR->GetArrayLength(ENVONLY, coords)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_elements: coords array length < 0"); + } + + nlongs = (int)((size_t)size / sizeof(jlong)); + + if (NULL == (lp = (hsize_t *) HDmalloc((size_t)nlongs * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_elements: failed to allocate coordinate buffer"); + + jlp = (jlong *) P; + llp = lp; + for (ii = 0; ii < nlongs; ii++) { + *lp = (hsize_t) *jlp; + lp++; + jlp++; + } /* end for */ + + if ((status = H5Sselect_elements(space_id, (H5S_seloper_t)op, (size_t)num_elemn, (const hsize_t *)llp)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (llp) + HDfree(llp); + if (P) + UNPIN_BYTE_ARRAY(ENVONLY, coords, P, JNI_ABORT); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1elements */ @@ -288,12 +278,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sselect_1all (JNIEnv *env, jclass clss, jlong space_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Sselect_all(space_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Sselect_all(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1all */ @@ -306,12 +298,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sselect_1none (JNIEnv *env, jclass clss, jlong space_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Sselect_none(space_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Sselect_none(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1none */ @@ -326,12 +320,14 @@ Java_hdf_hdf5lib_H5_H5Sselect_1valid { htri_t bval = JNI_FALSE; - bval = H5Sselect_valid(space_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + if ((bval = H5Sselect_valid(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1valid */ @@ -344,11 +340,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1npoints (JNIEnv *env, jclass clss, jlong space_id) { - hssize_t retVal = H5Sget_simple_extent_npoints(space_id); + hssize_t retVal = -1; + + UNUSED(clss); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Sget_simple_extent_npoints(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1npoints */ @@ -361,11 +360,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Sget_1select_1npoints (JNIEnv *env, jclass clss, jlong space_id) { - hssize_t retVal = H5Sget_select_npoints(space_id); + hssize_t retVal = -1; + + UNUSED(clss); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Sget_select_npoints(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1npoints */ @@ -380,10 +382,12 @@ Java_hdf_hdf5lib_H5_H5Sget_1select_1type { int retVal = -1; - retVal = H5Sget_select_type(space_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if (H5S_SEL_ERROR == (retVal = H5Sget_select_type(space_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1type */ @@ -398,10 +402,12 @@ Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1ndims { int retVal = -1; - retVal = H5Sget_simple_extent_ndims(space_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + + if ((retVal = H5Sget_simple_extent_ndims(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint) retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1ndims */ @@ -414,100 +420,78 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1dims (JNIEnv *env, jclass clss, jlong space_id, jlongArray dims, jlongArray maxdims) { - int status = -1; - jlong *dimsP, *maxdimsP; - jboolean isCopy; - hsize_t *sa; - hsize_t *msa; - int i; - int rank = -1; - int mrank; - - if (dims == NULL) { + jboolean isCopy; + hsize_t *sa = NULL; + hsize_t *msa = NULL; + jlong *dimsP = NULL, *maxdimsP = NULL; + int i; + int rank = -1; + int mrank; + int status = -1; + + UNUSED(clss); + + if (NULL == dims) { dimsP = NULL; sa = (hsize_t *) dimsP; - } /* end if */ + } else { - dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy); - if (dimsP == NULL) { - h5JNIFatalError(env, "H5Pget_simple_extent_dims: dims not pinned"); - return -1; - } /* end if */ - rank = (int)ENVPTR->GetArrayLength(ENVPAR dims); - sa = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (sa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_simple_extent_dims: dims not converted to hsize_t"); - return -1; - } /* end if */ - } /* end else */ - if (maxdims == NULL) { + PIN_LONG_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Sget_simple_extent_dims: dims not pinned"); + + if ((rank = (int)ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_simple_extent_dims: dims array length < 0"); + } + + if (NULL == (sa = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_simple_extent_dims: failed to allocate dimension buffer"); + } + + if (NULL == maxdims) { maxdimsP = NULL; msa = (hsize_t *) maxdimsP; - } /* end if */ + } else { - maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims, &isCopy); - if (maxdimsP == NULL) { - if (dimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - } /* end if */ - h5JNIFatalError(env, "H5Pget_simple_extent_dims: maxdims not pinned"); - return -1; - } /* end if */ - mrank = (int) ENVPTR->GetArrayLength(ENVPAR maxdims); + PIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, &isCopy, "H5Sget_simple_extent_dims: maxdims not pinned"); + + if ((mrank = (int) ENVPTR->GetArrayLength(ENVONLY, maxdims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_simple_extent_dims: maxdims array length < 0"); + } + if (rank < 0) rank = mrank; - else if (mrank != rank) { - if (dimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - } /* end if */ - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_simple_extent_dims: maxdims rank not same as dims"); - return -1; - } /* end else if */ - msa = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (msa == NULL) { - if (dimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - } /* end if */ - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_simple_extent_dims: maxdims not converted to hsize_t"); - return -1; - } /* end if */ - } /* end else */ + else if (mrank != rank) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_simple_extent_dims: maxdims rank not same as dims"); - status = H5Sget_simple_extent_dims(space_id, (hsize_t *)sa, (hsize_t *)msa); + if (NULL == (msa = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_simple_extent_dims: failed to allocate maximum dimension buffer"); + } - if (status < 0) { - if (dimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - } /* end if */ - if (maxdimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - HDfree(msa); - } /* end if */ - h5libraryError(env); - return -1; - } /* end if */ + if ((status = H5Sget_simple_extent_dims(space_id, (hsize_t *)sa, (hsize_t *)msa)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (dimsP != NULL) { + if (NULL != dimsP) { for (i = 0; i < rank; i++) { dimsP[i] = (jlong)sa[i]; } /* end for */ - HDfree(sa); - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, 0); - } /* end if */ - if (maxdimsP != NULL) { + } + + if (NULL != maxdimsP) { for (i = 0; i < rank; i++) { maxdimsP[i] = (jlong)msa[i]; } /* end for */ + } + +done: + if (msa) HDfree(msa); - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, 0); - } /* end if */ + if (maxdimsP) + UNPIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, (status < 0) ? JNI_ABORT : 0); + if (sa) + HDfree(sa); + if (dimsP) + UNPIN_LONG_ARRAY(ENVONLY, dims, dimsP, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1dims */ @@ -523,11 +507,15 @@ Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1type { H5S_class_t retVal = H5S_NO_CLASS; + UNUSED(clss); + if (space_id < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Sget_simple_extent_type(space_id); + if (H5S_NO_CLASS == (retVal = H5Sget_simple_extent_type(space_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1simple_1extent_1type */ @@ -540,87 +528,81 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sset_1extent_1simple (JNIEnv *env, jclass clss, jlong space_id, jint rank, jlongArray dims, jlongArray maxdims) { - herr_t status = -1; - jlong *dimsP, *maxdimsP; - jboolean isCopy; - hsize_t *sa; - hsize_t *msa; - int i; - int drank, mrank; - hsize_t *lp; - jlong *jlp; - - if (dims == NULL) { - h5nullArgument(env, "H5Sset_simple_extent: dims is NULL"); - return -1; - } /* end if */ - drank = (int) ENVPTR->GetArrayLength(ENVPAR dims); - if (drank != rank) { - h5badArgument(env, "H5Screate_simple: dims rank is invalid"); - return -1; - } /* end if */ - if (maxdims != NULL) { - mrank = (int) ENVPTR->GetArrayLength(ENVPAR maxdims); - if (mrank != rank) { - h5badArgument(env, "H5Screate_simple: maxdims rank is invalid"); - return -1; - } /* end if */ - } /* end if */ - dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy); - if (dimsP == NULL) { - h5JNIFatalError(env, "H5Pset_simple_extent: dims not pinned"); - return -1; - } /* end if */ - sa = lp = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)); - if (sa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Sset_simple_extent: dims not converted to hsize_t"); - return -1; - } /* end if */ + jboolean isCopy; + hsize_t *sa = NULL; + hsize_t *msa = NULL; + hsize_t *lp = NULL; + jlong *dimsP = NULL, *maxdimsP = NULL; + jlong *jlp = NULL; + jsize drank, mrank; + int i; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sset_extent_simple: dims is NULL"); + + if ((drank = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sset_extent_simple: dims array length < 0"); + } + + if (drank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sset_extent_simple: dims rank is invalid"); + + if (NULL != maxdims) { + if ((mrank = ENVPTR->GetArrayLength(ENVONLY, maxdims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sset_extent_simple: maxdims array length < 0"); + } + + if (mrank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sset_extent_simple: maxdims rank is invalid"); + } + + PIN_LONG_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Sset_extent_simple: dims not pinned"); + + if (NULL == (sa = lp = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sset_extent_simple: failed to allocate dimension buffer"); + jlp = (jlong *) dimsP; for (i = 0; i < rank; i++) { *lp = (hsize_t) *jlp; lp++; jlp++; } /* end for */ - if (maxdims == NULL) { + + if (NULL == maxdims) { maxdimsP = NULL; msa = (hsize_t *) maxdimsP; - } /* end if */ + } else { - maxdimsP = ENVPTR->GetLongArrayElements(ENVPAR maxdims, &isCopy); - if (maxdimsP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5JNIFatalError(env, "H5Pset_simple_extent: maxdims not pinned"); - return -1; - } /* end if */ - msa = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (msa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); - HDfree(sa); - h5JNIFatalError(env, "H5Sset_simple_extent: maxdims not converted to hsize_t"); - return -1; - } /* end if */ + PIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, &isCopy, "H5Sset_extent_simple: maxdims not pinned"); + + if (NULL == (msa = lp = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sset_extent_simple: failed to allocate maximum dimension buffer"); + jlp = (jlong *) maxdimsP; for (i = 0; i < rank; i++) { *lp = (hsize_t) *jlp; lp++; jlp++; } /* end for */ - } /* end else */ + } - status = H5Sset_extent_simple(space_id, rank, (hsize_t *) sa, (hsize_t *) msa); + if ((status = H5Sset_extent_simple(space_id, rank, (hsize_t *) sa, (hsize_t *) msa)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - HDfree(sa); - if (maxdimsP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR maxdims, maxdimsP, JNI_ABORT); +done: + if (msa) HDfree(msa); - } /* end if */ - - if (status < 0) - h5libraryError(env); + if (maxdimsP) + UNPIN_LONG_ARRAY(ENVONLY, maxdims, maxdimsP, JNI_ABORT); + if (sa) + HDfree(sa); + if (dimsP) + UNPIN_LONG_ARRAY(ENVONLY, dims, dimsP, JNI_ABORT); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sset_1extent_1simple */ @@ -636,12 +618,14 @@ Java_hdf_hdf5lib_H5_H5Sis_1simple { htri_t bval = JNI_FALSE; - bval = H5Sis_simple(space_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Sis_simple(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Sis_1simple */ @@ -654,49 +638,50 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Soffset_1simple (JNIEnv *env, jclass clss, jlong space_id, jbyteArray offset) { - herr_t status; - jbyte *P = NULL; jboolean isCopy; - hssize_t *sa; + hssize_t *sa = NULL; + hssize_t *lp = NULL; size_t rank; - size_t i; - hssize_t *lp; - jlong *jlp; - - if (offset != NULL) { - P = ENVPTR->GetByteArrayElements(ENVPAR offset, &isCopy); - if (P == NULL) { - h5JNIFatalError(env, "H5Soffset_simple: offset not pinned"); - return -1; - } /* end if */ - i = (size_t)ENVPTR->GetArrayLength(ENVPAR offset); - rank = i / sizeof(jlong); - sa = lp = (hssize_t *)HDmalloc((size_t)rank * sizeof(hssize_t)); - if (sa == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR offset, P, JNI_ABORT); - h5JNIFatalError(env, "H5Soffset_simple: offset not converted to hssize_t"); - return -1; - } /* end if */ + jsize i; + jbyte *P = NULL; + jlong *jlp = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL != offset) { + PIN_BYTE_ARRAY(ENVONLY, offset, P, &isCopy, "H5Soffset_simple: offset not pinned"); + + if ((i = ENVPTR->GetArrayLength(ENVONLY, offset)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Soffset_simple: offset array length < 0"); + } + + rank = (size_t) i / sizeof(jlong); + + if (NULL == (sa = lp = (hssize_t *) HDmalloc((size_t)rank * sizeof(hssize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Soffset_simple: failed to allocate offset buffer"); + jlp = (jlong *) P; - for (i = 0; i < rank; i++) { + for (i = 0; (size_t) i < rank; i++) { *lp = (hssize_t) *jlp; lp++; jlp++; } /* end for */ - } /* end if */ + } else { P = NULL; sa = (hssize_t *) P; - } /* end else */ + } - status = H5Soffset_simple(space_id, sa); - if (P != NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR offset, P, JNI_ABORT); - HDfree(sa); - } /* end if */ + if ((status = H5Soffset_simple(space_id, sa)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (status < 0) - h5libraryError(env); +done: + if (sa) + HDfree(sa); + if (P) + UNPIN_BYTE_ARRAY(ENVONLY, offset, P, JNI_ABORT); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Soffset_1simple */ @@ -710,12 +695,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sextent_1copy (JNIEnv *env, jclass clss, jlong space_id, jlong src_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Sextent_copy(space_id, src_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Sextent_copy(space_id, src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Sextent_1copy */ @@ -730,12 +717,14 @@ Java_hdf_hdf5lib_H5_H5Sextent_1equal { htri_t bval = JNI_FALSE; - bval = H5Sextent_equal(space_id, src_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Sextent_equal(space_id, src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Sextent_1equal */ @@ -748,12 +737,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sset_1extent_1none (JNIEnv *env, jclass clss, jlong space_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Sset_extent_none(space_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Sset_extent_none(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Sset_1extent_1none */ @@ -766,162 +757,131 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sselect_1hyperslab (JNIEnv *env, jclass clss, jlong space_id, jint op, jlongArray start, jlongArray stride, jlongArray count, jlongArray block) { - herr_t status = -1; - jlong *startP, *strideP, *countP, *blockP; - jboolean isCopy; - hsize_t *strt; - hsize_t *strd; - hsize_t *cnt; - hsize_t *blk; - int rank; - int i; - hsize_t *lp; - jlong *jlp; - - if (start == NULL) { - h5nullArgument(env, "H5Sselect_hyperslab: start is NULL"); + jboolean isCopy; + hsize_t *strt = NULL, *strd = NULL, *cnt = NULL, *blk = NULL; + hsize_t *lp = NULL; + jlong *startP = NULL, *strideP = NULL, *countP = NULL, *blockP = NULL; + jlong *jlp = NULL; + jsize start_rank, stride_rank, count_rank, block_rank; + int i; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == start) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: start is NULL"); + if (NULL == count) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: count is NULL"); + + if ((start_rank = ENVPTR->GetArrayLength(ENVONLY, start)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: start array length < 0"); + } + if ((count_rank = ENVPTR->GetArrayLength(ENVONLY, count)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: count array length < 0"); + } + + if (start_rank != count_rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: count and start have different rank!"); + + PIN_LONG_ARRAY(ENVONLY, start, startP, &isCopy, "H5Sselect_hyperslab: start not pinned"); + + if (NULL == (strt = lp = (hsize_t *) HDmalloc((size_t)start_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_hyperslab: failed to allocate start buffer"); + + jlp = (jlong *) startP; + for (i = 0; i < start_rank; i++) { + *lp = (hsize_t) *jlp; + lp++; + jlp++; } /* end if */ - else if (count == NULL) { - h5nullArgument(env, "H5Sselect_hyperslab: count is NULL"); + + PIN_LONG_ARRAY(ENVONLY, count, countP, &isCopy, "H5Sselect_hyperslab: count not pinned"); + + if (NULL == (cnt = lp = (hsize_t *) HDmalloc((size_t)count_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_hyperslab: failed to allocate count buffer"); + + jlp = (jlong *) countP; + for (i = 0; i < count_rank; i++) { + *lp = (hsize_t) *jlp; + lp++; + jlp++; } /* end if */ + + if (NULL == stride) { + strideP = NULL; + strd = (hsize_t *) strideP; + } else { - rank = (int) ENVPTR->GetArrayLength(ENVPAR start); - if (rank != ENVPTR->GetArrayLength(ENVPAR count)) { - h5badArgument(env, "H5Sselect_hyperslab: count and start have different rank!"); - return -1; - } /* end if */ + if ((stride_rank = ENVPTR->GetArrayLength(ENVONLY, stride)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: stride array length < 0"); + } - startP = ENVPTR->GetLongArrayElements(ENVPAR start, &isCopy); - if (startP == NULL) { - h5JNIFatalError(env, "H5Sselect_hyperslab: start not pinned"); - return -1; - } /* end if */ - strt = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (strt == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - h5JNIFatalError(env, "H5Sselect_hyperslab: start not converted to hsize_t"); - return -1; - } /* end if */ + if (stride_rank != start_rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: stride and start have different rank!"); - jlp = (jlong *) startP; - for (i = 0; i < rank; i++) { + PIN_LONG_ARRAY(ENVONLY, stride, strideP, &isCopy, "H5Sselect_hyperslab: stride not pinned"); + + if (NULL == (strd = lp = (hsize_t *) HDmalloc((size_t)stride_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_hyperslab: failed to allocate stride buffer"); + + jlp = (jlong *) strideP; + for (i = 0; i < stride_rank; i++) { *lp = (hsize_t) *jlp; lp++; jlp++; } /* end if */ + } - countP = ENVPTR->GetLongArrayElements(ENVPAR count, &isCopy); - if (countP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(strt); - h5JNIFatalError(env, "H5Sselect_hyperslab: count not pinned"); - return -1; - } /* end if */ - cnt = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (cnt == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - HDfree(strt); - h5JNIFatalError(env, "H5Sselect_hyperslab: count not converted to hsize_t"); - return -1; - } /* end if */ + if (NULL == block) { + blockP = NULL; + blk = (hsize_t *) blockP; + } + else { + if ((block_rank = ENVPTR->GetArrayLength(ENVONLY, block)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: block array length < 0"); + } - jlp = (jlong *) countP; - for (i = 0; i < rank; i++) { + if (block_rank != start_rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sselect_hyperslab: block and start have different rank!"); + + PIN_LONG_ARRAY(ENVONLY, block, blockP, &isCopy, "H5Sselect_hyperslab: block not pinned"); + + if (NULL == (blk = lp = (hsize_t *) HDmalloc((size_t)block_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sselect_hyperslab: failed to allocate block buffer"); + + jlp = (jlong *) blockP; + for (i = 0; i < block_rank; i++) { *lp = (hsize_t) *jlp; lp++; jlp++; - } /* end if */ - if (stride == NULL) { - strideP = NULL; - strd = (hsize_t *) strideP; - } /* end if */ - else { - strideP = ENVPTR->GetLongArrayElements(ENVPAR stride, &isCopy); - if (strideP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - h5badArgument(env, "H5Sselect_hyperslab: stride not pinned"); - return -1; - } /* end if */ - strd = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (strd == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - h5JNIFatalError(env, "H5Sselect_hyperslab: stride not converted to hsize_t"); - return -1; - } /* end if */ - jlp = (jlong *) strideP; - for (i = 0; i < rank; i++) { - *lp = (hsize_t) *jlp; - lp++; - jlp++; - } /* end if */ - } /* end if */ - if (block == NULL) { - blockP = NULL; - blk = (hsize_t *) blockP; - } /* end if */ - else { - blockP = ENVPTR->GetLongArrayElements(ENVPAR block, &isCopy); - if (blockP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - if (strd != NULL) - free(strd); - - h5JNIFatalError(env, "H5Sselect_hyperslab: block not pinned"); - return -1; - } /* end if */ - blk = lp = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (blk == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - if (strd != NULL) - free(strd); - - h5JNIFatalError(env, "H5Sget_simple_extent: block not converted to hsize_t"); - return -1; - } /* end if */ - jlp = (jlong *) blockP; - for (i = 0; i < rank; i++) { - *lp = (hsize_t) *jlp; - lp++; - jlp++; - } /* end for */ - } /* end else */ - - status = H5Sselect_hyperslab(space_id, (H5S_seloper_t) op, (const hsize_t *) strt, (const hsize_t *) strd, - (const hsize_t *) cnt, (const hsize_t *) blk); - - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - HDfree(strt); + } /* end for */ + } + + if ((status = H5Sselect_hyperslab(space_id, (H5S_seloper_t) op, (const hsize_t *) strt, (const hsize_t *) strd, + (const hsize_t *) cnt, (const hsize_t *) blk)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (blk) + HDfree(blk); + if (blockP) + UNPIN_LONG_ARRAY(ENVONLY, block, blockP, JNI_ABORT); + if (strd) + HDfree(strd); + if (strideP) + UNPIN_LONG_ARRAY(ENVONLY, stride, strideP, JNI_ABORT); + if (cnt) HDfree(cnt); - if (strideP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - HDfree(strd); - } /* end if */ - if (blockP != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP, JNI_ABORT); - HDfree(blk); - } /* end if */ - - if (status < 0) - h5libraryError(env); - } /* end else */ + if (countP) + UNPIN_LONG_ARRAY(ENVONLY, count, countP, JNI_ABORT); + if (strt) + HDfree(strt); + if (startP) + UNPIN_LONG_ARRAY(ENVONLY, start, startP, JNI_ABORT); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sselect_1hyperslab */ @@ -935,12 +895,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Sclose (JNIEnv *env, jclass clss, jlong space_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Sclose(space_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Sclose(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Sclose */ @@ -955,10 +917,12 @@ Java_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1nblocks { hssize_t retVal = -1; - retVal = H5Sget_select_hyper_nblocks((hid_t) spaceid); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + + if ((retVal = H5Sget_select_hyper_nblocks((hid_t) spaceid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1nblocks */ @@ -973,10 +937,12 @@ Java_hdf_hdf5lib_H5_H5Sget_1select_1elem_1npoints { hssize_t retVal = -1; - retVal = H5Sget_select_elem_npoints((hid_t) spaceid); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Sget_select_elem_npoints((hid_t) spaceid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1elem_1npoints */ @@ -989,58 +955,53 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1blocklist (JNIEnv *env, jclass clss, jlong spaceid, jlong startblock, jlong numblocks, jlongArray buf) { - herr_t status = -1; - jlong *bufP; - jboolean isCopy; - hsize_t *ba; - int i; - int rank; - hsize_t st; - hsize_t nb; - - st = (hsize_t) startblock; - nb = (hsize_t) numblocks; - - if (buf == NULL) { - h5nullArgument(env, "H5Sget_select_hyper_blocklist: buf is NULL"); - } /* end if */ - else { - rank = H5Sget_simple_extent_ndims(spaceid); - if (rank <= 0) - rank = 1; - if (ENVPTR->GetArrayLength(ENVPAR buf) < (numblocks * rank)) { - h5badArgument(env, "H5Sget_select_hyper_blocklist: buf input array too small"); - } /* end if */ - else { - bufP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy); - if (bufP == NULL) { - h5JNIFatalError(env, "H5Sget_select_hyper_blocklist: buf not pinned"); - } /* end if */ - else { - ba = (hsize_t *) HDmalloc((size_t)nb * 2 * (size_t)rank * sizeof(hsize_t)); - if (ba == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, JNI_ABORT); - h5JNIFatalError(env, "H5Screate-simple: buffer not converted to hsize_t"); - } /* end if */ - else { - status = H5Sget_select_hyper_blocklist((hid_t)spaceid, st, nb, (hsize_t *)ba); - - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, JNI_ABORT); - free(ba); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < (numblocks * 2 * rank); i++) { - bufP[i] = (jlong)ba[i]; - } /* end for */ - free(ba); - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *ba = NULL; + size_t i, buf_size; + jlong *bufP = NULL; + jsize buflen; + int rank; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_hyper_blocklist: buf is NULL"); + if (numblocks < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_hyper_blocklist: numblocks < 0"); + + if ((rank = H5Sget_simple_extent_ndims(spaceid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (rank == 0) + rank = 1; + + if ((buflen = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_hyper_blocklist: buf array length < 0"); + } + + if (buflen < (numblocks * rank)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_hyper_blocklist: buffer input array too small"); + + PIN_LONG_ARRAY(ENVONLY, buf, bufP, &isCopy, "H5Sget_select_hyper_blocklist: buffer not pinned"); + + buf_size = (size_t) numblocks * (size_t) 2 * (size_t) rank * sizeof(hsize_t); + if (NULL == (ba = (hsize_t *) HDmalloc(buf_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_select_hyper_blocklist: failed to allocate block list buffer"); + + if ((status = H5Sget_select_hyper_blocklist((hid_t)spaceid, (hsize_t) startblock, (hsize_t) numblocks, (hsize_t *)ba)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (buf_size / sizeof(hsize_t)); i++) { + bufP[i] = (jlong) ba[i]; + } /* end for */ + +done: + if (ba) + HDfree(ba); + if (bufP) + UNPIN_LONG_ARRAY(ENVONLY, buf, bufP, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1hyper_1blocklist */ @@ -1054,53 +1015,49 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sget_1select_1elem_1pointlist (JNIEnv *env, jclass clss, jlong spaceid, jlong startpoint, jlong numpoints, jlongArray buf) { - herr_t status = -1; - jlong *bufP; - jboolean isCopy; - hsize_t *ba; - int i; - int rank; - - if (buf == NULL) { - h5nullArgument(env, "H5Sget_select_elem_pointlist: buf is NULL"); - } /* end if */ - else { - rank = H5Sget_simple_extent_ndims(spaceid); - if (rank <= 0) - rank = 1; - if (ENVPTR->GetArrayLength(ENVPAR buf) < (numpoints * rank)) { - h5badArgument(env, "H5Sget_select_elem_pointlist: buf input array too small"); - } /* end if */ - else { - bufP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy); - if (bufP == NULL) { - h5JNIFatalError(env, "H5Sget_select_elem_pointlist: buf not pinned"); - } /* end if */ - else { - ba = (hsize_t *)HDmalloc(((size_t)numpoints * (size_t)rank) * sizeof(hsize_t)); - if (ba == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_select_elem_pointlist: buf not converted to hsize_t"); - } /* end if */ - else { - status = H5Sget_select_elem_pointlist((hid_t) spaceid, (hsize_t)startpoint, (hsize_t)numpoints, (hsize_t *)ba); - - if (status < 0) { - HDfree(ba); - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < (numpoints * rank); i++) { - bufP[i] = (jlong)ba[i]; - } /* end for */ - HDfree(ba); - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, bufP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *ba = NULL; + jlong *bufP = NULL; + jsize buflen; + int i, rank; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_elem_pointlist: buffer is NULL"); + + if ((rank = H5Sget_simple_extent_ndims(spaceid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (rank == 0) + rank = 1; + + if ((buflen = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_elem_pointlist: buf array length < 0"); + } + + if (buflen < (numpoints * rank)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_elem_pointlist: buffer input array too small"); + + PIN_LONG_ARRAY(ENVONLY, buf, bufP, &isCopy, "H5Sget_select_elem_pointlist: buffer not pinned"); + + if (NULL == (ba = (hsize_t *) HDmalloc(((size_t)numpoints * (size_t)rank) * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_select_elem_pointlist: failed to allocate point list buffer"); + + if ((status = H5Sget_select_elem_pointlist((hid_t)spaceid, (hsize_t)startpoint, (hsize_t)numpoints, (hsize_t *)ba)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (numpoints * rank); i++) { + bufP[i] = (jlong) ba[i]; + } /* end for */ + +done: + if (ba) + HDfree(ba); + if (bufP) + UNPIN_LONG_ARRAY(ENVONLY, buf, bufP, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end if */ @@ -1114,70 +1071,53 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Sget_1select_1bounds (JNIEnv *env, jclass clss, jlong spaceid, jlongArray start, jlongArray end) { - herr_t status = -1; - jlong *startP, *endP; - jboolean isCopy; - hsize_t *strt; - hsize_t *en; - int rank; - int i; - - if (start == NULL) { - h5nullArgument(env, "H5Sget_select_bounds: start is NULL"); - } /* end if */ - else if (end == NULL) { - h5nullArgument(env, "H5Sget_select_bounds: end is NULL"); - } /* end else if */ - else { - startP = ENVPTR->GetLongArrayElements(ENVPAR start, &isCopy); - if (startP == NULL) { - h5JNIFatalError(env, "H5Sget_select_bounds: start not pinned"); - return -1; - } /* end if */ - rank = (int) ENVPTR->GetArrayLength(ENVPAR start); - strt = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (strt == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_select_bounds: start not converted to hsize_t"); - return -1; - } /* end if */ + jboolean isCopy; + hsize_t *strt = NULL; + hsize_t *en = NULL; + size_t i; + jlong *startP = NULL, *endP = NULL; + jsize rank; + herr_t status = FAIL; - endP = ENVPTR->GetLongArrayElements(ENVPAR end, &isCopy); - if (endP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - free(strt); - h5JNIFatalError(env, "H5Sget_select_bounds: end not pinned"); - return -1; - } /* end if */ - en = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (en == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR end, endP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(strt); - h5JNIFatalError(env, "H5Sget_simple_extent: dims not converted to hsize_t"); - return -1; - } /* end if */ + UNUSED(clss); - status = H5Sget_select_bounds((hid_t) spaceid, (hsize_t *) strt, (hsize_t *) en); + if (NULL == start) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_bounds: start is NULL"); + if (NULL == end) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_bounds: end is NULL"); - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR end, endP, JNI_ABORT); - HDfree(strt); - HDfree(en); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < rank; i++) { - startP[i] = (jlong)strt[i]; - endP[i] = (jlong)en[i]; - } /* end for */ - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR end, endP, 0); - HDfree(strt); - HDfree(en); - } /* end else */ - } /* end else */ + PIN_LONG_ARRAY(ENVONLY, start, startP, &isCopy, "H5Sget_select_bounds: start not pinned"); + + if ((rank = ENVPTR->GetArrayLength(ENVONLY, start)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_select_bounds: start array length < 0"); + } + + if (NULL == (strt = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_select_bounds: failed to allocate start buffer"); + + PIN_LONG_ARRAY(ENVONLY, end, endP, &isCopy, "H5Sget_select_bounds: end not pinned"); + + if (NULL == (en = (hsize_t *) HDmalloc((size_t)rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_select_bounds: failed to allocate end buffer"); + + if ((status = H5Sget_select_bounds((hid_t) spaceid, (hsize_t *) strt, (hsize_t *) en)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (size_t) rank; i++) { + startP[i] = (jlong) strt[i]; + endP[i] = (jlong) en[i]; + } /* end for */ + +done: + if (en) + HDfree(en); + if (endP) + UNPIN_LONG_ARRAY(ENVONLY, end, endP, (status < 0) ? JNI_ABORT : 0); + if (strt) + HDfree(strt); + if (startP) + UNPIN_LONG_ARRAY(ENVONLY, start, startP, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Sget_1select_1bounds */ @@ -1191,43 +1131,37 @@ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_H5_H5Sencode (JNIEnv *env, jclass cls, jlong obj_id) { - herr_t status = -1; - unsigned char *bufPtr; - size_t buf_size = 0; - jbyteArray returnedArray = NULL; - - if (obj_id < 0) { - h5badArgument(env, "H5Sencode: invalid argument"); - } /* end if */ - else { - status = H5Sencode(obj_id, NULL, &buf_size); + unsigned char *bufPtr = NULL; + size_t buf_size = 0; + herr_t status = FAIL; + jbyteArray returnedArray = NULL; - if (status < 0) { - h5libraryError(env); - } /* end else if */ - else if (buf_size == 0) { - h5badArgument(env, "H5Sencode: buf_size = 0"); - } /* end if */ - else { - bufPtr = (unsigned char*)HDcalloc((size_t) 1, buf_size); - if (bufPtr == NULL) { - h5outOfMemory(env, "H5Sencode: calloc failed"); - } /* end if */ - else { - status = H5Sencode((hid_t) obj_id, bufPtr, &buf_size); - - if (status < 0) { - HDfree(bufPtr); - h5libraryError(env); - } /* end if */ - else { - returnedArray = ENVPTR->NewByteArray(ENVPAR (jsize)buf_size); - ENVPTR->SetByteArrayRegion(ENVPAR returnedArray, 0, (jsize)buf_size, (jbyte*) bufPtr); - HDfree(bufPtr); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + UNUSED(cls); + + if (obj_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sencode: invalid object ID"); + + if ((status = H5Sencode(obj_id, NULL, &buf_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (buf_size == 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sencode: buf_size = 0"); + + if (NULL == (bufPtr = (unsigned char *) HDcalloc((size_t) 1, buf_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sencode: failed to allocate encoding buffer"); + + if ((status = H5Sencode((hid_t) obj_id, bufPtr, &buf_size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (returnedArray = ENVPTR->NewByteArray(ENVONLY, (jsize) buf_size))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetByteArrayRegion(ENVONLY, returnedArray, 0, (jsize) buf_size, (jbyte *) bufPtr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (bufPtr) + HDfree(bufPtr); return returnedArray; } /* end Java_hdf_hdf5lib_H5_H5Sencode */ @@ -1241,27 +1175,23 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Sdecode (JNIEnv *env, jclass cls, jbyteArray buf) { - hid_t sid = -1; - jbyte *bufP; - jboolean isCopy; + jboolean isCopy; + jbyte *bufP = NULL; + hid_t sid = H5I_INVALID_HID; - if (buf == NULL) { - h5nullArgument(env, "H5Sdecode: buf is NULL"); - } /* end if */ - else { - bufP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); - if (bufP == NULL) { - h5JNIFatalError( env, "H5Sdecode: buf not pinned"); - } /* end if */ - else { - sid = H5Sdecode(bufP); + UNUSED(cls); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Sdecode: buffer is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, buf, bufP, &isCopy, "H5Sdecode: buffer not pinned"); - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, bufP, JNI_ABORT); + if ((sid = H5Sdecode(bufP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (sid < 0) - h5libraryError(env); - } /* end else if */ - } /* end else if */ +done: + if (bufP) + UNPIN_BYTE_ARRAY(ENVONLY, buf, bufP, JNI_ABORT); return (jlong)sid; } /* end Java_hdf_hdf5lib_H5_H5Sdecode */ @@ -1277,12 +1207,14 @@ Java_hdf_hdf5lib_H5_H5Sis_1regular_1hyperslab { htri_t bval = JNI_FALSE; - bval = H5Sis_regular_hyperslab((hid_t)obj_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(cls); + if ((bval = H5Sis_regular_hyperslab((hid_t)obj_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Sis_1regular_1hyperslab */ @@ -1295,131 +1227,126 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Sget_1regular_1hyperslab (JNIEnv *env, jclass clss, jlong space_id, jlongArray start, jlongArray stride, jlongArray count, jlongArray block) { - herr_t status; - jlong *startP, *strideP, *countP, *blockP; - jboolean isCopy; - hsize_t *strt; - hsize_t *strd; - hsize_t *cnt; - hsize_t *blk; - int rank; - int i; - - if (start == NULL) { - h5nullArgument(env, "H5Sget_regular_hyperslab: start is NULL"); - } /* end if */ - else if (count == NULL) { - h5nullArgument(env, "H5Sget_regular_hyperslab: count is NULL"); - } /* end else if */ + jboolean isCopy; + hsize_t *strt = NULL, *strd = NULL, *cnt = NULL, *blk = NULL; + jlong *startP = NULL, *strideP = NULL, *countP = NULL, *blockP = NULL; + jsize start_rank = -1, stride_rank = -1, count_rank = -1, block_rank = -1; + int i, rank = -1; + herr_t status = FAIL; + + UNUSED(clss); + + if (space_id < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: invalid dataspace ID"); + + if ((rank = H5Sget_simple_extent_ndims(space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == start) { + startP = NULL; + strt = (hsize_t *) startP; + } else { - rank = (int) ENVPTR->GetArrayLength(ENVPAR start); - if (rank != ENVPTR->GetArrayLength(ENVPAR count)) { - h5badArgument(env, "H5Sget_regular_hyperslab: count and start have different rank!"); - return; - } /* end if */ + if ((start_rank = ENVPTR->GetArrayLength(ENVONLY, start)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: start array length < 0"); + } - startP = ENVPTR->GetLongArrayElements(ENVPAR start, &isCopy); - if (startP == NULL) { - h5JNIFatalError(env, "H5Sget_regular_hyperslab: start not pinned"); - return; - } /* end if */ - strt = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (strt == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: start not converted to hsize_t"); - return; - } /* end if */ + if (start_rank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: start rank doesn't match dataspace rank!"); - countP = ENVPTR->GetLongArrayElements(ENVPAR count, &isCopy); - if (countP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(strt); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: count not pinned"); - return; - } /* end if */ - cnt = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (cnt == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - HDfree(strt); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: count not converted to hsize_t"); - return; - } /* end if */ + PIN_LONG_ARRAY(ENVONLY, start, startP, &isCopy, "H5Sget_regular_hyperslab: start not pinned"); - strideP = ENVPTR->GetLongArrayElements(ENVPAR stride, &isCopy); - if (strideP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - h5badArgument(env, "H5Sget_regular_hyperslab: stride not pinned"); - return; - } /* end if */ - strd = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (strd == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: stride not converted to hsize_t"); - return; - } /* end if */ + if (NULL == (strt = (hsize_t *) HDmalloc((size_t)start_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_regular_hyperslab: failed to allocate start buffer"); + } - blockP = ENVPTR->GetLongArrayElements(ENVPAR block, &isCopy); - if (blockP == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - HDfree(strd); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: block not pinned"); - return; - } /* end if */ - blk = (hsize_t *)HDmalloc((size_t)rank * sizeof(hsize_t)); - if (blk == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP, JNI_ABORT); - HDfree(cnt); - HDfree(strt); - HDfree(strd); - h5JNIFatalError(env, "H5Sget_regular_hyperslab: block not converted to hsize_t"); - return; - } /* end if */ + if (NULL == stride) { + strideP = NULL; + strd = (hsize_t *) strideP; + } + else { + if ((stride_rank = ENVPTR->GetArrayLength(ENVONLY, stride)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: stride array length < 0"); + } - status = H5Sget_regular_hyperslab(space_id, (hsize_t *) strt, (hsize_t *) strd, (hsize_t *) cnt, (hsize_t *) blk); - - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP, JNI_ABORT); - HDfree(strt); - HDfree(cnt); - HDfree(strd); - HDfree(blk); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < (rank); i++) { - startP[i] = (jlong)strt[i]; - countP[i] = (jlong)cnt[i]; - strideP[i] = (jlong)strd[i]; - blockP[i] = (jlong)blk[i]; - } /* end for */ - HDfree(strt); - HDfree(cnt); - HDfree(strd); - HDfree(blk); - ENVPTR->ReleaseLongArrayElements(ENVPAR start, startP, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR count, countP, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR stride, strideP, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR block, blockP, 0); - } /* end else */ - } /* end else */ + if (stride_rank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: stride rank doesn't match dataspace rank!"); + + PIN_LONG_ARRAY(ENVONLY, stride, strideP, &isCopy, "H5Sget_regular_hyperslab: stride not pinned"); + + if (NULL == (strd = (hsize_t *) HDmalloc((size_t)stride_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_regular_hyperslab: failed to allocate stride buffer"); + } + + if (NULL == count) { + countP = NULL; + cnt = (hsize_t *) countP; + } + else { + if ((count_rank = ENVPTR->GetArrayLength(ENVONLY, count)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: count array length < 0"); + } + + if (count_rank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: count rank doesn't match dataspace rank!"); + + PIN_LONG_ARRAY(ENVONLY, count, countP, &isCopy, "H5Sget_regular_hyperslab: count not pinned"); + + if (NULL == (cnt = (hsize_t *) HDmalloc((size_t)count_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_regular_hyperslab: failed to allocate count buffer"); + } + + if (NULL == block) { + blockP = NULL; + blk = (hsize_t *) blockP; + } + else { + if ((block_rank = ENVPTR->GetArrayLength(ENVONLY, block)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: block array length < 0"); + } + + if (block_rank != rank) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Sget_regular_hyperslab: block rank doesn't match dataspace rank!"); + + PIN_LONG_ARRAY(ENVONLY, block, blockP, &isCopy, "H5Sget_regular_hyperslab: block not pinned"); + + if (NULL == (blk = (hsize_t *) HDmalloc((size_t)block_rank * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Sget_regular_hyperslab: failed to allocate block buffer"); + } + + if ((status = H5Sget_regular_hyperslab(space_id, (hsize_t *) strt, (hsize_t *) strd, (hsize_t *) cnt, (hsize_t *) blk)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < start_rank; i++) { + startP[i] = (jlong) strt[i]; + countP[i] = (jlong) cnt[i]; + strideP[i] = (jlong) strd[i]; + blockP[i] = (jlong) blk[i]; + } /* end for */ + +done: + if (blk) + HDfree(blk); + if (blockP) + UNPIN_LONG_ARRAY(ENVONLY, block, blockP, (status < 0) ? JNI_ABORT : 0); + if (cnt) + HDfree(cnt); + if (countP) + UNPIN_LONG_ARRAY(ENVONLY, count, countP, (status < 0) ? JNI_ABORT : 0); + if (strd) + HDfree(strd); + if (strideP) + UNPIN_LONG_ARRAY(ENVONLY, stride, strideP, (status < 0) ? JNI_ABORT : 0); + if (strt) + HDfree(strt); + if (startP) + UNPIN_LONG_ARRAY(ENVONLY, start, startP, (status < 0) ? JNI_ABORT : 0); + + return; } /* end Java_hdf_hdf5lib_H5_H5Sget_1regular_1hyperslab */ #ifdef __cplusplus diff --git a/java/src/jni/h5tImp.c b/java/src/jni/h5tImp.c index 307f1a5..08ddf85 100644 --- a/java/src/jni/h5tImp.c +++ b/java/src/jni/h5tImp.c @@ -29,7 +29,10 @@ extern "C" { #include "h5jni.h" #include "h5tImp.h" -extern JavaVM *jvm; +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -40,18 +43,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Topen2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist) { - hid_t status = -1; - const char *tName; + const char *datatypeName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(name, tName); - if (tName != NULL) { - status = H5Topen2((hid_t)loc_id, tName, (hid_t)access_plist); + UNUSED(clss); - UNPIN_JAVA_STRING(name, tName); + PIN_JAVA_STRING(ENVONLY, name, datatypeName, NULL, "H5Topen2: datatype name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Topen2((hid_t)loc_id, datatypeName, (hid_t)access_plist)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (datatypeName) + UNPIN_JAVA_STRING(ENVONLY, name, datatypeName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Topen2 */ @@ -67,12 +71,14 @@ Java_hdf_hdf5lib_H5_H5Tcommitted { htri_t bval = JNI_FALSE; - bval = H5Tcommitted(type_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Tcommitted(type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Tcommitted */ @@ -85,12 +91,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tcreate (JNIEnv *env, jclass clss, jint dclass, jlong size) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Tcreate((H5T_class_t )dclass, (size_t)size); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tcreate((H5T_class_t )dclass, (size_t)size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tcreate */ @@ -103,12 +111,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tcopy (JNIEnv *env, jclass clss, jlong type_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Tcopy((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tcopy((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tcopy */ @@ -123,12 +133,14 @@ Java_hdf_hdf5lib_H5_H5Tequal { htri_t bval = JNI_FALSE; - bval = H5Tequal((hid_t)type_id1, (hid_t)type_id2); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Tequal((hid_t)type_id1, (hid_t)type_id2)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Tequal */ @@ -141,12 +153,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tlock (JNIEnv *env, jclass clss, jlong type_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tlock((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tlock((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tlock */ @@ -161,10 +175,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1class { H5T_class_t retVal = H5T_NO_CLASS; - retVal = H5Tget_class((hid_t)type_id); - if (retVal == H5T_NO_CLASS) - h5libraryError(env); + UNUSED(clss); + if (H5T_NO_CLASS == (retVal = H5Tget_class((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1class */ @@ -179,10 +195,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1size { size_t retVal = 0; - retVal = H5Tget_size((hid_t)type_id); - if (retVal == 0) - h5libraryError(env); + UNUSED(clss); + + if (!(retVal = H5Tget_size((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1size*/ @@ -196,12 +214,14 @@ Java_hdf_hdf5lib_H5_H5Tset_1size (JNIEnv *env, jclass clss, jlong type_id, jlong size) { size_t tsize = (size_t)size; - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_size((hid_t)type_id, tsize); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_size((hid_t)type_id, tsize)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end ifJava_hdf_hdf5lib_H5_H5Tset_1size */ @@ -216,10 +236,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1order { H5T_order_t retVal = H5T_ORDER_ERROR; - retVal = H5Tget_order((hid_t)type_id); - if (retVal == H5T_ORDER_ERROR) - h5libraryError(env); + UNUSED(clss); + if (H5T_ORDER_ERROR == (retVal = H5Tget_order((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1order */ @@ -232,12 +254,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1order (JNIEnv *env, jclass clss, jlong type_id, jint order) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_order((hid_t)type_id, (H5T_order_t)order); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_order((hid_t)type_id, (H5T_order_t)order)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1order */ @@ -252,10 +276,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1precision { size_t retVal = 0; - retVal = H5Tget_precision((hid_t)type_id); - if (retVal == 0) - h5libraryError(env); + UNUSED(clss); + + if (!(retVal = H5Tget_precision((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1precision */ @@ -270,10 +296,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1precision_1long { size_t retVal = 0; - retVal = H5Tget_precision((hid_t)type_id); - if (retVal == 0) - h5libraryError(env); + UNUSED(clss); + if (!(retVal = H5Tget_precision((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1precision_1long */ @@ -286,12 +314,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1precision (JNIEnv *env, jclass clss, jlong type_id, jlong precision) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_precision((hid_t)type_id, (size_t)precision); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_precision((hid_t)type_id, (size_t)precision)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1precision */ @@ -306,10 +336,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1offset { int retVal = -1; - retVal = H5Tget_offset((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + + if ((retVal = H5Tget_offset((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1offset */ @@ -322,12 +354,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1offset (JNIEnv *env, jclass clss, jlong type_id, jlong offset) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Tset_offset((hid_t)type_id, (size_t)offset); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tset_offset((hid_t)type_id, (size_t)offset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1offset */ @@ -340,29 +374,23 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1pad (JNIEnv *env, jclass clss, jlong type_id, jintArray pad) { - herr_t status = -1; - jboolean isCopy; - jint *P; - - if (pad == NULL) { - h5nullArgument(env, "H5Tget_pad: pad is NULL"); - } /* end if */ - else { - P = ENVPTR->GetIntArrayElements(ENVPAR pad, &isCopy); - if (P == NULL) { - h5JNIFatalError(env, "H5Tget_pad: pad not pinned"); - } /* end if */ - else { - status = H5Tget_pad((hid_t)type_id, (H5T_pad_t *)&(P[0]), (H5T_pad_t *)&(P[1])); - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR pad, P, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR pad, P, 0); - } /* end else */ - } /* end else */ + jboolean isCopy; + jint *P = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == pad) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_pad: pad is NULL"); + + PIN_INT_ARRAY(ENVONLY, pad, P, &isCopy, "H5Tget_pad: pad not pinned"); + + if ((status = H5Tget_pad((hid_t)type_id, (H5T_pad_t *)&(P[0]), (H5T_pad_t *)&(P[1]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (P) + UNPIN_INT_ARRAY(ENVONLY, pad, P, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tget_1pad */ @@ -376,12 +404,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1pad (JNIEnv *env, jclass clss, jlong type_id, jint lsb, jint msb) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_pad((hid_t)type_id, (H5T_pad_t)lsb, (H5T_pad_t)msb); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_pad((hid_t)type_id, (H5T_pad_t)lsb, (H5T_pad_t)msb)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1pad */ @@ -396,10 +426,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1sign { H5T_sign_t retVal = H5T_SGN_ERROR; - retVal = H5Tget_sign((hid_t)type_id); - if (retVal == H5T_SGN_ERROR) - h5libraryError(env); + UNUSED(clss); + + if (H5T_SGN_ERROR == (retVal = H5Tget_sign((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1sign */ @@ -412,12 +444,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1sign (JNIEnv *env, jclass clss, jlong type_id, jint sign) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Tset_sign((hid_t)type_id, (H5T_sign_t)sign); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tset_sign((hid_t)type_id, (H5T_sign_t)sign)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1sign */ @@ -430,32 +464,31 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1fields_1int (JNIEnv *env, jclass clss, jlong type_id, jintArray fields) { - herr_t status; - jboolean isCopy; - jint *P; - - if (fields == NULL) { - h5nullArgument(env, "H5Tget_fields: fields is NULL"); - } /* end if */ - else if (ENVPTR->GetArrayLength(ENVPAR fields) < 5) { - h5badArgument(env, "H5Tget_fields: fields input array < order 5"); - } /* end else if */ - else { - P = ENVPTR->GetIntArrayElements(ENVPAR fields, &isCopy); - if (P == NULL) { - h5JNIFatalError(env, "H5Tget_fields: fields not pinned"); - } /* end if */ - else { - status = H5Tget_fields((hid_t)type_id, (size_t *)&(P[0]), (size_t *)&(P[1]), (size_t *)&(P[2]), (size_t *)&(P[3]), (size_t *)&(P[4])); - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR fields, P, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR fields, P, 0); - } /* end else */ - } /* end else */ + jboolean isCopy; + jsize arrLen; + jint *P = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == fields) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields_int: fields is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, fields)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields_int: fields array length < 0"); + } + if (arrLen < 5) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields_int: fields input array < order 5"); + + PIN_INT_ARRAY(ENVONLY, fields, P, &isCopy, "H5Tget_fields_int: fields not pinned"); + + if ((status = H5Tget_fields((hid_t)type_id, (size_t *)&(P[0]), (size_t *)&(P[1]), (size_t *)&(P[2]), (size_t *)&(P[3]), (size_t *)&(P[4]))) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (P) + UNPIN_INT_ARRAY(ENVONLY, fields, P, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tget_1fields_1int */ @@ -469,56 +502,57 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Tget_1fields (JNIEnv *env, jclass clss, jlong type_id, jlongArray fields) { - herr_t status; - jboolean isCopy; - jlong *fieldsArray; - - if (fields == NULL) { - h5nullArgument(env, "H5Tget_fields: fields is NULL"); - } /* end if */ - else if (ENVPTR->GetArrayLength(ENVPAR fields) < 5) { - h5badArgument(env, "H5Tget_fields: fields input array < order 5"); - } /* end else if */ - else { - fieldsArray = ENVPTR->GetLongArrayElements(ENVPAR fields, &isCopy); - if (fieldsArray == NULL) { - h5JNIFatalError(env, "H5Tget_fields: fields not pinned"); - } /* end if */ - else { - { /* direct cast (size_t *)variable fails on 32-bit environment */ - size_t spos_t = 0; - size_t epos_t = 0; - size_t esize_t = 0; - size_t mpos_t = 0; - size_t msize_t = 0; - long long fields_temp = *(&fieldsArray[0]); - spos_t = (size_t)fields_temp; - fields_temp = *(&fieldsArray[1]); - epos_t = (size_t)fields_temp; - fields_temp = *(&fieldsArray[2]); - esize_t = (size_t)fields_temp; - fields_temp = *(&fieldsArray[3]); - mpos_t = (size_t)fields_temp; - fields_temp = *(&fieldsArray[4]); - msize_t = (size_t)fields_temp; - - status = H5Tget_fields((hid_t)type_id, &spos_t, &epos_t, &esize_t, &mpos_t, &msize_t); - - *(&fieldsArray[0]) = (jlong)spos_t; - *(&fieldsArray[1]) = (jlong)epos_t; - *(&fieldsArray[2]) = (jlong)esize_t; - *(&fieldsArray[3]) = (jlong)mpos_t; - *(&fieldsArray[4]) = (jlong)msize_t; - } /* end direct cast special handling */ - - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR fields, fieldsArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseLongArrayElements(ENVPAR fields, fieldsArray, 0); - } /* end else */ - } /* end else */ + jboolean isCopy; + jlong *fieldsArray = NULL; + jsize arrLen; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == fields) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields: fields is NULL"); + + if ((arrLen = ENVPTR->GetArrayLength(ENVONLY, fields)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields: fields array length < 0"); + } + if (arrLen < 5) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tget_fields: fields input array < order 5"); + + PIN_LONG_ARRAY(ENVONLY, fields, fieldsArray, &isCopy, "H5Tget_fields: fields not pinned"); + + { /* Direct cast (size_t *)variable fails on 32-bit environment */ + size_t spos_t = 0; + size_t epos_t = 0; + size_t esize_t = 0; + size_t mpos_t = 0; + size_t msize_t = 0; + long long fields_temp = *(&fieldsArray[0]); + spos_t = (size_t)fields_temp; + fields_temp = *(&fieldsArray[1]); + epos_t = (size_t)fields_temp; + fields_temp = *(&fieldsArray[2]); + esize_t = (size_t)fields_temp; + fields_temp = *(&fieldsArray[3]); + mpos_t = (size_t)fields_temp; + fields_temp = *(&fieldsArray[4]); + msize_t = (size_t)fields_temp; + + if ((status = H5Tget_fields((hid_t)type_id, &spos_t, &epos_t, &esize_t, &mpos_t, &msize_t)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + *(&fieldsArray[0]) = (jlong)spos_t; + *(&fieldsArray[1]) = (jlong)epos_t; + *(&fieldsArray[2]) = (jlong)esize_t; + *(&fieldsArray[3]) = (jlong)mpos_t; + *(&fieldsArray[4]) = (jlong)msize_t; + } /* end direct cast special handling */ + +done: + if (fieldsArray) + UNPIN_LONG_ARRAY(ENVONLY, fields, fieldsArray, (status < 0) ? JNI_ABORT : 0); + + return; } /* end Java_hdf_hdf5lib_H5_H5Tget_1fields */ /* @@ -531,8 +565,13 @@ Java_hdf_hdf5lib_H5_H5Tset_1fields (JNIEnv *env, jclass clss, jlong type_id, jlong spos, jlong epos, jlong esize, jlong mpos, jlong msize) { + UNUSED(clss); + if (H5Tset_fields((hid_t)type_id, (size_t)spos, (size_t)epos, (size_t)esize, (size_t)mpos, (size_t)msize) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* end Java_hdf_hdf5lib_H5_H5Tset_1fields */ /* @@ -546,10 +585,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1ebias { size_t retVal = 0; - retVal = H5Tget_ebias((hid_t)type_id); - if (retVal == 0) - h5libraryError(env); + UNUSED(clss); + + if (!(retVal = H5Tget_ebias((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1ebias */ @@ -564,10 +605,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1ebias_1long { size_t retVal = 0; - retVal = H5Tget_ebias((hid_t)type_id); - if (retVal == 0) - h5libraryError(env); + UNUSED(clss); + if (!(retVal = H5Tget_ebias((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1ebias_1long */ @@ -580,12 +623,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1ebias (JNIEnv *env, jclass clss, jlong type_id, jlong ebias) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_ebias((hid_t)type_id, (size_t)ebias); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_ebias((hid_t)type_id, (size_t)ebias)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1ebias */ @@ -600,10 +645,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1norm { H5T_norm_t retVal = H5T_NORM_ERROR; - retVal = H5Tget_norm((hid_t)type_id); - if (retVal == H5T_NORM_ERROR) - h5libraryError(env); + UNUSED(clss); + + if (H5T_NORM_ERROR == (retVal = H5Tget_norm((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1norm */ @@ -616,12 +663,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1norm (JNIEnv *env, jclass clss, jlong type_id, jint norm) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Tset_norm((hid_t)type_id, (H5T_norm_t )norm); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tset_norm((hid_t)type_id, (H5T_norm_t )norm)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1norm */ @@ -636,10 +685,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1inpad { H5T_pad_t retVal = H5T_PAD_ERROR; - retVal = H5Tget_inpad((hid_t)type_id ); - if (retVal == H5T_PAD_ERROR) - h5libraryError(env); + UNUSED(clss); + + if (H5T_PAD_ERROR == (retVal = H5Tget_inpad((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1inpad */ @@ -652,12 +703,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1inpad (JNIEnv *env, jclass clss, jlong type_id, jint inpad) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_inpad((hid_t)type_id, (H5T_pad_t) inpad); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_inpad((hid_t)type_id, (H5T_pad_t) inpad)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1inpad */ @@ -672,10 +725,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1cset { H5T_cset_t retVal = H5T_CSET_ERROR; - retVal = H5Tget_cset((hid_t)type_id); - if (retVal == H5T_CSET_ERROR) - h5libraryError(env); + UNUSED(clss); + if (H5T_CSET_ERROR == (retVal = H5Tget_cset((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1cset */ @@ -688,12 +743,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1cset (JNIEnv *env, jclass clss, jlong type_id, jint cset) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tset_cset((hid_t)type_id, (H5T_cset_t)cset); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tset_cset((hid_t)type_id, (H5T_cset_t)cset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1cset */ @@ -708,10 +765,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1strpad { H5T_str_t retVal = H5T_STR_ERROR; - retVal = H5Tget_strpad((hid_t)type_id); - if (retVal == H5T_STR_ERROR) - h5libraryError(env); + UNUSED(clss); + + if (H5T_STR_ERROR == (retVal = H5Tget_strpad((hid_t)type_id))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1strpad */ @@ -724,12 +783,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1strpad (JNIEnv *env, jclass clss, jlong type_id, jint strpad) { - herr_t retVal = -1; + herr_t retVal = FAIL; - retVal = H5Tset_strpad((hid_t)type_id, (H5T_str_t)strpad); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tset_strpad((hid_t)type_id, (H5T_str_t)strpad)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tset_1strpad */ @@ -744,10 +805,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1nmembers { int retVal = -1; - retVal = H5Tget_nmembers((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + + if ((retVal = H5Tget_nmembers((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1nmembers */ @@ -760,17 +823,20 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1name (JNIEnv *env, jclass clss, jlong type_id, jint field_idx) { - char *name; - jstring str = NULL; + char *member_name = NULL; + jstring str = NULL; - name = H5Tget_member_name((hid_t)type_id, (unsigned)field_idx); - if (name != NULL) { - str = ENVPTR->NewStringUTF(ENVPAR name); - H5free_memory(name); + UNUSED(clss); - if (str == NULL) - h5JNIFatalError(env, "H5Tget_member_name: returned string not created"); - } /* end if */ + if (NULL == (member_name = H5Tget_member_name((hid_t)type_id, (unsigned)field_idx))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, member_name))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (member_name) + H5free_memory(member_name); return str; } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1name */ @@ -784,18 +850,19 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1index (JNIEnv *env, jclass clss, jlong type_id, jstring field_name) { - const char *tName; + const char *datatypeName = NULL; int index = -1; - PIN_JAVA_STRING(field_name, tName); - if (tName != NULL) { - index = H5Tget_member_index((hid_t)type_id, tName); + UNUSED(clss); - UNPIN_JAVA_STRING(field_name, tName); + PIN_JAVA_STRING(ENVONLY, field_name, datatypeName, NULL, "H5Tget_member_index: datatype name not pinned"); - if (index < 0) - h5libraryError(env); - } + if ((index = H5Tget_member_index((hid_t)type_id, datatypeName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (datatypeName) + UNPIN_JAVA_STRING(ENVONLY, field_name, datatypeName); return (jint)index; } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1index */ @@ -809,12 +876,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tget_1member_1type (JNIEnv *env, jclass clss, jlong type_id, jint field_idx) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Tget_member_type((hid_t)type_id, (unsigned)field_idx); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tget_member_type((hid_t)type_id, (unsigned)field_idx)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tget_1member_1type */ @@ -827,6 +896,9 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1offset (JNIEnv *env, jclass clss, jlong type_id, jint memno) { + UNUSED(env); + UNUSED(clss); + return (jlong)H5Tget_member_offset((hid_t)type_id, (unsigned)memno); } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1offset */ @@ -839,12 +911,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1class (JNIEnv *env, jclass clss, jlong type_id, jint memno) { - int retVal = -1; + H5T_class_t retVal = H5T_NO_CLASS; + + UNUSED(clss); - retVal = H5Tget_member_class((hid_t)type_id, (unsigned)memno); - if (retVal < 0) - h5libraryError(env); + if (H5T_NO_CLASS == (retVal = H5Tget_member_class((hid_t)type_id, (unsigned)memno))) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1class */ @@ -857,18 +931,20 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tinsert (JNIEnv *env, jclass clss, jlong type_id, jstring name, jlong offset, jlong field_id) { - herr_t status = -1; - const char *tName; + const char *datatypeName = NULL; long off = (long)offset; + herr_t status = FAIL; - PIN_JAVA_STRING(name, tName); - if (tName != NULL) { - status = H5Tinsert((hid_t)type_id, tName, (size_t)off, field_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name,tName); - if (status < 0) - h5libraryError(env); - } + PIN_JAVA_STRING(ENVONLY, name, datatypeName, NULL, "H5Tinsert: datatype name not pinned"); + + if ((status = H5Tinsert((hid_t)type_id, datatypeName, (size_t)off, field_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (datatypeName) + UNPIN_JAVA_STRING(ENVONLY, name, datatypeName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tinsert */ @@ -882,12 +958,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tpack (JNIEnv *env, jclass clss, jlong type_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tpack((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tpack((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Tpack */ @@ -900,12 +978,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Tclose (JNIEnv *env, jclass clss, jlong type_id) { - herr_t retVal = -1; + herr_t retVal = FAIL; + + UNUSED(clss); - retVal = H5Tclose((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tclose((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tclose */ @@ -918,12 +998,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tvlen_1create (JNIEnv *env, jclass clss, jlong base_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Tvlen_create((hid_t)base_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tvlen_create((hid_t)base_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tvlen_1create */ @@ -936,18 +1018,19 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tset_1tag (JNIEnv *env, jclass clss, jlong type, jstring tag) { - herr_t status = -1; - const char *tagP; + const char *tagBuf = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(tag, tagP); - if (tagP != NULL) { - status = H5Tset_tag((hid_t)type, tagP); + UNUSED(clss); - UNPIN_JAVA_STRING(tag,tagP); + PIN_JAVA_STRING(ENVONLY, tag, tagBuf, NULL, "H5Tset_tag: tag buffer not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Tset_tag((hid_t)type, tagBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (tagBuf) + UNPIN_JAVA_STRING(ENVONLY, tag, tagBuf); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tset_1tag */ @@ -961,17 +1044,20 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Tget_1tag (JNIEnv *env, jclass clss, jlong type) { - jstring str = NULL; - char *tag; + jstring str = NULL; + char *tag = NULL; - tag = H5Tget_tag((hid_t)type); - if (tag != NULL) { - str = ENVPTR->NewStringUTF(ENVPAR tag); - H5free_memory(tag); + UNUSED(clss); + + if (NULL == (tag = H5Tget_tag((hid_t)type))) + H5_LIBRARY_ERROR(ENVONLY); - if (str == NULL) - h5JNIFatalError(env, "H5Tget_tag: returned string not created"); - } /* end if */ + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, tag))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (tag) + H5free_memory(tag); return str; } /* end Java_hdf_hdf5lib_H5_H5Tget_1tag */ @@ -985,12 +1071,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tget_1super (JNIEnv *env, jclass clss, jlong type_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); - retVal = H5Tget_super((hid_t)type_id); - if (retVal < 0) - h5libraryError(env); + if ((retVal = H5Tget_super((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tget_1super */ @@ -1003,12 +1091,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tenum_1create (JNIEnv *env, jclass clss, jlong base_id) { - hid_t retVal = -1; + hid_t retVal = H5I_INVALID_HID; - retVal = H5Tenum_create((hid_t)base_id); - if (retVal < 0) - h5libraryError(env); + UNUSED(clss); + if ((retVal = H5Tenum_create((hid_t)base_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tenum_1create */ @@ -1021,32 +1111,28 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tenum_1insert_1int (JNIEnv *env, jclass clss, jlong type_id, jstring name, jintArray value) { - herr_t status = -1; - jint *intP; - const char *nameP; - jboolean isCopy2; - - if (value == NULL ) { - h5nullArgument(env, "H5Tenum_insert: value is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, nameP); - if (nameP != NULL) { - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); - if (intP == NULL) { - h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); - } /* end if */ - else { - status = H5Tenum_insert((hid_t)type_id, nameP, intP); - - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - - if (status < 0) - h5libraryError(env); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); - } - } /* end else */ + const char *memberName = NULL; + jboolean isCopy; + jint *intBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_insert: value is NULL"); + + PIN_JAVA_STRING(ENVONLY, name, memberName, NULL, "H5Tenum_insert: member name not pinned"); + + PIN_INT_ARRAY(ENVONLY, value, intBuf, &isCopy, "H5Tenum_insert: int buffer not pinned"); + + if ((status = H5Tenum_insert((hid_t)type_id, memberName, intBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (intBuf) + UNPIN_INT_ARRAY(ENVONLY, value, intBuf, (status < 0) ? JNI_ABORT : 0); + if (memberName) + UNPIN_JAVA_STRING(ENVONLY, name, memberName); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tenum_1insert_1int */ @@ -1060,32 +1146,28 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Tenum_1insert (JNIEnv *env, jclass clss, jlong type_id, jstring name, jbyteArray value) { - herr_t status = -1; - jbyte *byteP; - const char *nameP; - jboolean isCopy2; - - if (value == NULL) { - h5nullArgument(env, "H5Tenum_insert: value is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, nameP); - if (nameP != NULL) { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); - } /* end if */ - else { - status = H5Tenum_insert((hid_t)type_id, nameP, byteP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - - if (status < 0) - h5libraryError(env); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); - } - } /* end else */ + const char *memberName = NULL; + jboolean isCopy; + jbyte *memberBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_insert: value is NULL"); + + PIN_JAVA_STRING(ENVONLY, name, memberName, NULL, "H5Tenum_insert: member name not pinned"); + + PIN_BYTE_ARRAY(ENVONLY, value, memberBuf, &isCopy, "H5Tenum_insert: member buffer not pinned"); + + if ((status = H5Tenum_insert((hid_t)type_id, memberName, memberBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (memberBuf) + UNPIN_BYTE_ARRAY(ENVONLY, value, memberBuf, (status < 0) ? JNI_ABORT : 0); + if (memberName) + UNPIN_JAVA_STRING(ENVONLY, name, memberName); } /* end Java_hdf_hdf5lib_H5_H5Tenum_1insert */ /* @@ -1098,51 +1180,39 @@ Java_hdf_hdf5lib_H5_H5Tenum_1nameof_1int (JNIEnv *env, jclass clss, jlong type_id, jintArray value, jobjectArray name, jint size) { - herr_t status = -1; - jint *intP; - char *nameP; - jboolean isCopy; - jstring str; - - if (size <= 0) { - h5badArgument(env, "H5Tenum_nameof: name size < 0"); - } /* end if */ - else if (value == NULL) { - h5nullArgument(env, "H5Tenum_nameof: value is NULL"); - } /* end if */ - else { - nameP = (char*)HDmalloc(sizeof(char) * (size_t)size); - if (nameP == NULL) { - /* exception -- out of memory */ - h5outOfMemory(env, "H5Tenum_nameof: malloc name size"); - } /* end if */ - else { - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy); - if (intP == NULL) { - HDfree(nameP); - h5JNIFatalError(env, "H5Tenum_nameof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_nameof((hid_t)type_id, intP, nameP, (size_t)size); - - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - - if (status < 0) { - HDfree(nameP); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR nameP); - HDfree(nameP); - if (str == NULL) { - h5JNIFatalError(env, "H5Tenum_nameof: return array not created"); - } /* end if */ - else - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + jstring str; + jint *intP = NULL; + char *nameP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_nameof_int: value is NULL"); + if (size <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tenum_nameof_int: name size < 0"); + + if (NULL == (nameP = (char *) HDmalloc(sizeof(char) * (size_t)size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tenum_nameof_int: failed to allocate name buffer"); + + PIN_INT_ARRAY(ENVONLY, value, intP, &isCopy, "H5Tenum_nameof_int: value not pinned"); + + if ((status = H5Tenum_nameof((hid_t)type_id, intP, nameP, (size_t)size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nameP[(size_t)size - 1] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, nameP))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, name, 0, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (intP) + UNPIN_INT_ARRAY(ENVONLY, value, intP, JNI_ABORT); + if (nameP) + HDfree(nameP); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tenum_1nameof_1int */ @@ -1156,49 +1226,36 @@ JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Tenum_1nameof (JNIEnv *env, jclass clss, jlong type_id, jbyteArray value, jlong size) { - herr_t status = -1; - jbyte *byteP; - char *nameP; - jboolean isCopy; - jstring str = NULL; - - if (size <= 0) { - h5badArgument(env, "H5Tenum_nameof: name size < 0"); - } /* end if */ - else if (value == NULL ) { - h5nullArgument(env, "H5Tenum_nameof: value is NULL"); - } /* end if */ - else { - nameP = (char*)HDmalloc(sizeof(char) * (size_t)size); - if (nameP == NULL) { - h5outOfMemory(env, "H5Tenum_nameof: malloc name size"); - } /* end if */ - else { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy); - if (byteP == NULL) { - HDfree(nameP); - h5JNIFatalError(env, "H5Tenum_nameof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_nameof((hid_t)type_id, byteP, nameP, (size_t)size); - - /* free the buffer without copying back */ - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - - if (status < 0) { - HDfree(nameP); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR nameP); - HDfree(nameP); - if (str == NULL) { - h5JNIFatalError(env, "H5Tenum_nameof: return array not created"); - } /* end if */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + jstring str = NULL; + jbyte *byteP = NULL; + char *nameP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_nameof: value is NULL"); + if (size <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tenum_nameof: name size < 0"); + + if (NULL == (nameP = (char *) HDmalloc(sizeof(char) * (size_t)size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tenum_nameof: failed to allocate name buffer"); + + PIN_BYTE_ARRAY(ENVONLY, value, byteP, &isCopy, "H5Tenum_nameof: value not pinned"); + + if ((status = H5Tenum_nameof((hid_t)type_id, byteP, nameP, (size_t)size)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + nameP[(size_t)size - 1] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, nameP))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (byteP) + UNPIN_BYTE_ARRAY(ENVONLY, value, byteP, JNI_ABORT); + if (nameP) + HDfree(nameP); return str; } /* end Java_hdf_hdf5lib_H5_H5Tenum_1nameof */ @@ -1212,34 +1269,28 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tenum_1valueof_1int (JNIEnv *env, jclass clss, jlong type_id, jstring name, jintArray value) { - herr_t status = -1; - jint *intP; - const char *nameP; - jboolean isCopy2; - - if (value == NULL) { - h5nullArgument(env, "H5Tenum_valueof: value is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, nameP); - if (nameP != NULL) { - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); - if (intP == NULL) { - h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_valueof((hid_t)type_id, nameP, intP); - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, 0); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); - } - } /* end else */ + const char *enumValue = NULL; + jboolean isCopy; + jint *enumValueBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_valueof_int: value is NULL"); + + PIN_JAVA_STRING(ENVONLY, name, enumValue, NULL, "H5Tenum_valueof_int: enum value not pinned"); + + PIN_INT_ARRAY(ENVONLY, value, enumValueBuf, &isCopy, "H5Tenum_valueof_int: enum value buffer not pinned"); + + if ((status = H5Tenum_valueof((hid_t)type_id, enumValue, enumValueBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (enumValueBuf) + UNPIN_INT_ARRAY(ENVONLY, value, enumValueBuf, (status < 0) ? JNI_ABORT : 0); + if (enumValue) + UNPIN_JAVA_STRING(ENVONLY, name, enumValue); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tenum_1valueof_1int */ @@ -1253,34 +1304,28 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Tenum_1valueof (JNIEnv *env, jclass clss, jlong type_id, jstring name, jbyteArray value) { - herr_t status = -1; - jbyte *byteP; - const char *nameP; - jboolean isCopy2; - - if (value == NULL) { - h5nullArgument(env, "H5Tenum_valueof: value is NULL"); - } /* end if */ - else { - PIN_JAVA_STRING(name, nameP); - if (nameP != NULL) { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_valueof((hid_t)type_id, nameP, byteP); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, 0); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); - } - } /* end else */ + const char *enumValue = NULL; + jboolean isCopy; + jbyte *enumValueBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tenum_valueof: value is NULL"); + + PIN_JAVA_STRING(ENVONLY, name, enumValue, NULL, "H5Tenum_valueof: enum value not pinned"); + + PIN_BYTE_ARRAY(ENVONLY, value, enumValueBuf, &isCopy, "H5Tenum_valueof: enum value buffer not pinned"); + + if ((status = H5Tenum_valueof((hid_t)type_id, enumValue, enumValueBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (enumValueBuf) + UNPIN_BYTE_ARRAY(ENVONLY, value, enumValueBuf, (status < 0) ? JNI_ABORT : 0); + if (enumValue) + UNPIN_JAVA_STRING(ENVONLY, name, enumValue); } /* end Java_hdf_hdf5lib_H5_H5Tenum_1valueof */ /* @@ -1292,30 +1337,23 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1value_1int (JNIEnv *env, jclass clss, jlong type_id, jint membno, jintArray value) { - herr_t status = -1; - jint *intP; - jboolean isCopy; - - if (value == NULL) { - h5nullArgument(env, "H5Tget_member_value: value is NULL"); - } /* end if */ - else { - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy); - if (intP == NULL) { - h5JNIFatalError(env, "H5Tget_member_value: value not pinned"); - } /* end if */ - else { - status = H5Tget_member_value((hid_t)type_id, (unsigned)membno, intP); - - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, 0); - } /* end else */ - } /* end else */ + jboolean isCopy; + jint *intP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_member_value: value is NULL"); + + PIN_INT_ARRAY(ENVONLY, value, intP, &isCopy, "H5Tget_member_value: value not pinned"); + + if ((status = H5Tget_member_value((hid_t)type_id, (unsigned)membno, intP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (intP) + UNPIN_INT_ARRAY(ENVONLY, value, intP, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1value_1int */ @@ -1329,29 +1367,23 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Tget_1member_1value (JNIEnv *env, jclass clss, jlong type_id, jint membno, jbyteArray value) { - herr_t status = -1; - jbyte *byteP; - jboolean isCopy; - - if (value == NULL) { - h5nullArgument( env, "H5Tget_member_value: value is NULL"); - } /* end if */ - else { - byteP = ENVPTR->GetByteArrayElements(ENVPAR value,&isCopy); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Tget_member_value: value not pinned"); - } /* end if */ - else { - status = H5Tget_member_value((hid_t)type_id, (unsigned)membno, byteP); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, 0); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *byteP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == value) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_member_value: value is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, value, byteP, &isCopy, "H5Tget_member_value: value not pinned"); + + if ((status = H5Tget_member_value((hid_t)type_id, (unsigned)membno, byteP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (byteP) + UNPIN_BYTE_ARRAY(ENVONLY, value, byteP, (status < 0) ? JNI_ABORT : 0); } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1value */ /* @@ -1365,10 +1397,12 @@ Java_hdf_hdf5lib_H5_H5Tget_1array_1ndims { int ndims = -1; - ndims = H5Tget_array_ndims((hid_t)type_id); - if (ndims < 0) - h5libraryError(env); + UNUSED(clss); + + if ((ndims = H5Tget_array_ndims((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)ndims; } /* end Java_hdf_hdf5lib_H5_H5Tget_1array_1ndims */ @@ -1381,41 +1415,41 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1array_1dims (JNIEnv *env, jclass clss, jlong type_id, jintArray dims, jintArray perms) { - int ndims = -1; - int dlen; - int i; - jint *dimsP; - hsize_t *cdims = NULL; - jboolean isCopy; - - if (dims == NULL) { - h5nullArgument( env, "H5Tget_array_dims: value is NULL"); - } /* end if */ - else { - dimsP = ENVPTR->GetIntArrayElements(ENVPAR dims, &isCopy); - if (dimsP == NULL) { - h5JNIFatalError(env, "H5Tget_array_dims: dimsP not pinned"); - } /* end if */ - else { - dlen = ENVPTR->GetArrayLength(ENVPAR dims); - cdims = (hsize_t*)HDmalloc((size_t)dlen * sizeof(hsize_t)); - - ndims = H5Tget_array_dims2((hid_t)type_id, cdims); - - if (ndims < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < dlen; i++) { - dimsP[i] = (jint) cdims[i]; - } /* end for */ - ENVPTR->ReleaseIntArrayElements(ENVPAR dims, dimsP, 0); - - if (cdims) HDfree(cdims); - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *cdims = NULL; + size_t i; + jsize dlen; + jint *dimsP = NULL; + int ndims = -1; + + UNUSED(clss); + UNUSED(perms); + + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tget_array_dims: dims array is NULL"); + + PIN_INT_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Tget_array_dims: dimsP not pinned"); + + if ((dlen = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tget_array_dims: dims array length < 0"); + } + + if (NULL == (cdims = (hsize_t *) HDmalloc((size_t)dlen * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tget_array_dims: failed to allocate dimension buffer"); + + if ((ndims = H5Tget_array_dims2((hid_t)type_id, cdims)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (size_t) dlen; i++) { + dimsP[i] = (jint) cdims[i]; + } /* end for */ + +done: + if (cdims) + HDfree(cdims); + if (dimsP) + UNPIN_INT_ARRAY(ENVONLY, dims, dimsP, (ndims < 0) ? JNI_ABORT : 0); return (jint)ndims; } /* end Java_hdf_hdf5lib_H5_H5Tget_1array_1dims */ @@ -1431,12 +1465,14 @@ Java_hdf_hdf5lib_H5_H5Tis_1variable_1str { htri_t bval = JNI_FALSE; - bval = H5Tis_variable_str((hid_t)type_id); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Tis_variable_str((hid_t)type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Tis_1variable_1str */ @@ -1449,13 +1485,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tget_1native_1type (JNIEnv *env, jclass clss, jlong type_id, jint direction) { - hid_t native_tid = -1; + hid_t native_tid = H5I_INVALID_HID; - native_tid = H5Tget_native_type((hid_t)type_id, (H5T_direction_t)direction); + UNUSED(clss); - if (native_tid < 0) - h5libraryError(env); + if ((native_tid = H5Tget_native_type((hid_t)type_id, (H5T_direction_t)direction)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)native_tid; } /* end Java_hdf_hdf5lib_H5__1H5Tget_1native_1type */ @@ -1470,12 +1507,14 @@ Java_hdf_hdf5lib_H5_H5Tdetect_1class { htri_t bval = JNI_FALSE; - bval = H5Tdetect_class((hid_t)type_id, (H5T_class_t)dtype_class); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + UNUSED(clss); + + if ((bval = H5Tdetect_class((hid_t)type_id, (H5T_class_t)dtype_class)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; +done: return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Tdetect_1class */ @@ -1489,18 +1528,19 @@ Java_hdf_hdf5lib_H5_H5Tcommit (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong type, jlong link_plist_id, jlong create_plist_id, jlong access_plist_id) { - herr_t status = -1; - const char *tName; + const char *datatypeName = NULL; + herr_t status = FAIL; - PIN_JAVA_STRING(name, tName); - if (tName != NULL) { - status = H5Tcommit2((hid_t)loc_id, tName, (hid_t)type, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); + UNUSED(clss); - UNPIN_JAVA_STRING(name, tName); + PIN_JAVA_STRING(ENVONLY, name, datatypeName, NULL, "H5Tcommit: datatype name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5Tcommit2((hid_t)loc_id, datatypeName, (hid_t)type, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (datatypeName) + UNPIN_JAVA_STRING(ENVONLY, name, datatypeName); } /* end Java_hdf_hdf5lib_H5_H5Tcommit */ /* @@ -1512,45 +1552,45 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tarray_1create2 (JNIEnv *env, jclass clss, jlong base_id, jint rank, jlongArray dims) { - hid_t retVal = -1; - jlong *dimsP; - int dlen; - hsize_t *cdims = NULL; - jboolean isCopy; - int i; - - if (rank <= 0) { - h5badArgument(env, "H5Tarray_create: rank is < 1"); - } /* end if */ - else if (dims == NULL) { - h5nullArgument(env, "H5Tarray_create: dims is NULL"); - } /* end else if */ - else { - dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims, &isCopy); - if (dimsP == NULL) { - h5JNIFatalError( env, "H5Tarray_create: dimsP not pinned"); - } /* end if */ - else { - dlen = ENVPTR->GetArrayLength(ENVPAR dims); - if (dlen != rank) { - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - } /* end if */ - else { - cdims = (hsize_t*)HDmalloc((size_t)dlen * sizeof(hsize_t)); - for (i = 0; i < dlen; i++) { - cdims[i] = (hsize_t)dimsP[i]; - } /* end for */ - - retVal = H5Tarray_create2((hid_t)base_id, (unsigned)rank, (const hsize_t*)cdims); - - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, 0); - - HDfree(cdims); - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *cdims = NULL; + size_t i; + jlong *dimsP = NULL; + jsize dlen; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tarray_create: dims is NULL"); + if (rank <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tarray_create: rank is < 1"); + + PIN_LONG_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Tarray_create: dimsP not pinned"); + + if ((dlen = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tarray_create: dims array length < 0"); + } + + if (dlen != rank) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tarray_create: dimension array length != array rank"); + + if (NULL == (cdims = (hsize_t *) HDmalloc((size_t)dlen * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tarray_create: failed to allocate dimension buffer"); + + for (i = 0; i < (size_t) dlen; i++) { + cdims[i] = (hsize_t)dimsP[i]; + } /* end for */ + + if ((retVal = H5Tarray_create2((hid_t)base_id, (unsigned)rank, (const hsize_t *)cdims)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (cdims) + HDfree(cdims); + if (dimsP) + UNPIN_LONG_ARRAY(ENVONLY, dims, dimsP, (retVal < 0) ? JNI_ABORT : 0); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Tarray_1create2 */ @@ -1564,44 +1604,40 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1array_1dims2 (JNIEnv *env, jclass clss, jlong type_id, jlongArray dims) { - int ndims = -1; - int dlen; - int i; - jlong *dimsP; - hsize_t *cdims=NULL; - jboolean isCopy; - - if (dims == NULL) { - h5nullArgument(env, "H5Tget_array_dims: value is NULL"); - } /* end if */ - else { - dimsP = ENVPTR->GetLongArrayElements(ENVPAR dims,&isCopy); - if (dimsP == NULL) { - h5JNIFatalError(env, "H5Tget_array_dims: dimsP not pinned"); - } /* end if */ - else { - dlen = ENVPTR->GetArrayLength(ENVPAR dims); - cdims = (hsize_t*)HDmalloc((size_t)dlen * sizeof(hsize_t)); - - ndims = H5Tget_array_dims2((hid_t)type_id, (hsize_t*)cdims); - - if (ndims < 0) { - if (cdims) - free(cdims); - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - for (i = 0; i < dlen; i++) { - dimsP[i] = (jlong) cdims[i]; - } /* end for */ - ENVPTR->ReleaseLongArrayElements(ENVPAR dims, dimsP, 0); - - if (cdims) - HDfree(cdims); - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + hsize_t *cdims = NULL; + size_t i; + jlong *dimsP = NULL; + jsize dlen; + int ndims = -1; + + UNUSED(clss); + + if (NULL == dims) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Tarray_get_dims2: value is NULL"); + + PIN_LONG_ARRAY(ENVONLY, dims, dimsP, &isCopy, "H5Tarray_get_dims2: dimsP not pinned"); + + if ((dlen = ENVPTR->GetArrayLength(ENVONLY, dims)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tarray_get_dims2: dims array length < 0"); + } + + if (NULL == (cdims = (hsize_t *) HDmalloc((size_t)dlen * sizeof(hsize_t)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Tarray_get_dims2: failed to allocate dimension buffer"); + + if ((ndims = H5Tget_array_dims2((hid_t)type_id, (hsize_t*)cdims)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0; i < (size_t) dlen; i++) { + dimsP[i] = (jlong) cdims[i]; + } /* end for */ + +done: + if (cdims) + HDfree(cdims); + if (dimsP) + UNPIN_LONG_ARRAY(ENVONLY, dims, dimsP, (ndims < 0) ? JNI_ABORT : 0); return (jint)ndims; } /* end Java_hdf_hdf5lib_H5_H5Tget_1array_1dims2 */ @@ -1616,34 +1652,29 @@ Java_hdf_hdf5lib_H5_H5Tconvert (JNIEnv *env, jclass clss, jlong src_id, jlong dst_id, jlong nelmts, jbyteArray buf, jbyteArray background, jlong plist_id) { - herr_t status; - jbyte *bufP; - jbyte *bgP = NULL; - jboolean isCopy; - - if (nelmts <= 0) { - h5badArgument(env, "H5Tconvert: name nelmts < 0"); - } /* end if */ - else { - bufP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); - if (bufP == NULL) { - h5JNIFatalError(env, "H5Tconvert: value not pinned"); - } /* end if */ - else { - if (background) - bgP = ENVPTR->GetByteArrayElements(ENVPAR background, &isCopy); - - status = H5Tconvert((hid_t)src_id, (hid_t)dst_id, (size_t)nelmts, (void *)bufP, (void *)bgP, (hid_t)plist_id) ; - - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, bufP, 0); - - if (bgP) - ENVPTR->ReleaseByteArrayElements(ENVPAR background, bgP, 0); - - if (status < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *bufP = NULL; + jbyte *bgP = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + if (nelmts <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Tconvert: nelmts < 0"); + + PIN_BYTE_ARRAY(ENVONLY, buf, bufP, &isCopy, "H5Tconvert: buffer not pinned"); + + if (background) + PIN_BYTE_ARRAY(ENVONLY, background, bgP, &isCopy, "H5Tconvert: background buffer not pinned"); + + if ((status = H5Tconvert((hid_t)src_id, (hid_t)dst_id, (size_t)nelmts, (void *)bufP, (void *)bgP, (hid_t)plist_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (bgP) + UNPIN_BYTE_ARRAY(ENVONLY, background, bgP, (status < 0) ? JNI_ABORT : 0); + if (bufP) + UNPIN_BYTE_ARRAY(ENVONLY, buf, bufP, (status < 0) ? JNI_ABORT : 0); } /* end Java_hdf_hdf5lib_H5_H5Tconvert */ /* @@ -1654,8 +1685,13 @@ Java_hdf_hdf5lib_H5_H5Tconvert JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Tflush(JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Tflush((hid_t)loc_id) < 0) - h5libraryError(env); + H5_LIBRARY_ERROR(ENVONLY); + +done: + return; } /* @@ -1666,10 +1702,14 @@ Java_hdf_hdf5lib_H5_H5Tflush(JNIEnv *env, jclass clss, jlong loc_id) JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Trefresh(JNIEnv *env, jclass clss, jlong loc_id) { + UNUSED(clss); + if (H5Trefresh((hid_t)loc_id) < 0) - h5libraryError(env); -} + H5_LIBRARY_ERROR(ENVONLY); +done: + return; +} #ifdef __cplusplus diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index fd34ba1..4208ce1 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -32,7 +32,11 @@ extern "C" { hsize_t H5TOOLS_BUFSIZE = (32 * 1024 * 1024); /* 32 MB */ int H5TOOLS_TEXT_BLOCK = 16; /* Number of elements on a line in a text export file */ +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ JavaVM *jvm; + jobject copy_callback; jobject close_callback; jobject create_callback; @@ -41,22 +45,22 @@ jobject get_callback; jobject set_callback; jobject delete_callback; -H5E_auto2_t efunc; -void *edata; +H5E_auto2_t efunc; +void *edata; /********************/ /* Local Prototypes */ /********************/ -static int h5str_dump_region_blocks(h5str_t *str, hid_t region, hid_t region_obj); -static int h5str_dump_region_points(h5str_t *str, hid_t region, hid_t region_obj); +static int h5str_dump_region_blocks(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); +static int h5str_dump_region_points(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); static int h5str_is_zero(const void *_mem, size_t size); static hid_t h5str_get_native_type(hid_t type); static hid_t h5str_get_little_endian_type(hid_t type); static hid_t h5str_get_big_endian_type(hid_t type); static htri_t h5str_detect_vlen(hid_t tid); static htri_t h5str_detect_vlen_str(hid_t tid); -static int h5tools_dump_simple_data(FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts); +static int h5tools_dump_simple_data(JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts); static int h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t block_nelmts); static int render_bin_output_region_data_blocks(FILE *stream, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); @@ -78,9 +82,10 @@ h5str_array_free return; for (i = 0; i < len; i++) { - if (*(strs + i)) - HDfree(*(strs + i)); + if (strs[i]) + HDfree(strs[i]); } /* for (i=0; imax == new_len) return; - new_str = (char *)HDmalloc(new_len); + if (NULL == (new_str = (char *) HDmalloc(new_len))) + return; + if (new_len > str->max) /* increase memory */ HDstrcpy(new_str, str->s); else @@ -152,860 +162,1044 @@ h5str_append return HDstrcat(str->s, cstr); } /* end h5str_append */ -/** print value of a vlen data point into string. - Return Value: - On success, the total number of characters printed is returned. - On error, a negative number is returned. +/* + * Converts the given data point string into a real data point. + * + * Returns: + * SUCCESS: Length of string token processed + * FAILURE: 0 */ size_t -h5str_vlconvert - (char *str, hid_t container, hid_t tid, hvl_t *ptr, int expand_data) +h5str_convert + (JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_buf, size_t out_buf_offset) { - unsigned char tmp_uchar = 0; - char tmp_char = 0; - unsigned short tmp_ushort = 0; - short tmp_short = 0; - unsigned int tmp_uint = 0; - int tmp_int = 0; - unsigned long tmp_ulong = 0; - long tmp_long = 0; - unsigned long long tmp_ullong = 0; - long long tmp_llong = 0; - float tmp_float = 0.0; - double tmp_double = 0.0; - long double tmp_ldouble = 0.0; - static char fmt_llong[8], fmt_ullong[8]; - - hid_t mtid = -1; - size_t offset; - size_t nll; - char *this_str; - size_t this_strlen; - int n; - H5T_class_t tclass = H5Tget_class(tid); - size_t size = H5Tget_size(tid); - H5T_sign_t nsign = H5Tget_sign(tid); - int bdata_print = 0; - - if (!str || !ptr) - return 0; - - this_str = NULL; - this_strlen = 0; + unsigned char *ucptr = NULL; + static char fmt_llong[8], fmt_ullong[8]; + H5T_class_t tclass = H5T_NO_CLASS; + const char delimiter[] = " ," H5_COMPOUND_BEGIN_INDICATOR H5_COMPOUND_END_INDICATOR \ + H5_ARRAY_BEGIN_INDICATOR H5_ARRAY_END_INDICATOR \ + H5_VLEN_BEGIN_INDICATOR H5_VLEN_END_INDICATOR; + size_t typeSize = 0; + hid_t mtid = H5I_INVALID_HID; + char *this_str = NULL; + char *token; + char *cptr = NULL; + int n; + size_t retVal = 0; + + if (!in_str) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_convert: in_str is NULL"); + if (!out_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_convert: out_buf is NULL"); + + this_str = *in_str; + cptr = &(((char *) out_buf)[out_buf_offset]); + ucptr = &(((unsigned char *) out_buf)[out_buf_offset]); + + if (H5T_NO_CLASS == (tclass = H5Tget_class(tid))) + H5_LIBRARY_ERROR(ENVONLY); + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + + /* Build default formats for long long types */ + if (!fmt_llong[0]) { + if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); + if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); + } /* end if */ switch (tclass) { - case H5T_COMPOUND: + case H5T_FLOAT: { - unsigned i; - n = H5Tget_nmembers(tid); + token = HDstrtok(this_str, delimiter); - /* remove compound indicators */ - if (str[0] == ' ') - str++; - if (str[0] == '{') - str++; + switch (typeSize) { + case sizeof(float): + { + float tmp_float = 0.0; - ptr->p = HDcalloc((size_t)1, size); - ptr->len = size; - for (i = 0; i < n; i++) { - offset = H5Tget_member_offset(tid, i); - mtid = H5Tget_member_type(tid, i); - str += offset; - h5str_convert(&str, container, mtid, ptr, 0, expand_data); - /* remove compound indicators */ - if (str[0] == ',') - str++; - if (str[0] == ' ') - str++; - H5Tclose(mtid); + sscanf(token, "%f", &tmp_float); + HDmemcpy(cptr, &tmp_float, sizeof(float)); + break; + } + + case sizeof(double): + { + double tmp_double = 0.0; + + sscanf(token, "%lf", &tmp_double); + HDmemcpy(cptr, &tmp_double, sizeof(double)); + break; + } +#if H5_SIZEOF_LONG_DOUBLE != 0 + case sizeof(long double): + { + long double tmp_ldouble = 0.0; + + sscanf(token, "%Lf", &tmp_ldouble); + HDmemcpy(cptr, &tmp_ldouble, sizeof(long double)); + break; + } +#endif + + default: + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: floating-point datatype size didn't match any of expected sizes"); + break; } - /* remove compound indicators */ - if (str[0] == '}') - str++; - if (str[0] == ' ') - str++; + + retVal = typeSize; + + break; } - break; - case H5T_ARRAY: + + case H5T_STRING: { - int rank = 0; - hsize_t i, dims[H5S_MAX_RANK], total_elmts; + size_t len = HDstrlen(this_str); - /* remove array indicators */ - if (str[0] == '[') - str++; - if (str[0] == ' ') - str++; + if (len > 0) { + HDstrncpy(cptr, this_str, typeSize); + retVal = typeSize; + } + else { + cptr = NULL; + } - mtid = H5Tget_super(tid); - size = H5Tget_size(mtid); - rank = H5Tget_array_ndims(tid); + break; + } - H5Tget_array_dims2(tid, dims); + case H5T_INTEGER: + { + H5T_sign_t nsign = H5T_SGN_ERROR; - total_elmts = 1; - for (i = 0; i < rank; i++) - total_elmts *= dims[i]; + if (H5T_SGN_ERROR == (nsign = H5Tget_sign(tid))) + H5_LIBRARY_ERROR(ENVONLY); - ptr->p = HDcalloc((size_t)total_elmts, size); - ptr->len = total_elmts; - h5str_convert(&str, container, mtid, ptr, 0, expand_data); - H5Tclose(mtid); - /* remove array indicators */ - if (str[0] == ' ') - str++; - if (str[0] == ']') - str++; - if (str[0] == ' ') - str++; - } - break; - default: - ptr->len = size; - ptr->p = HDcalloc(1, size); - this_strlen = h5str_convert(&str, container, tid, ptr, 0, expand_data); - break; - } /* end switch */ + token = HDstrtok(this_str, delimiter); - return this_strlen; -} /* end h5str_vlconvert */ + switch (typeSize) { + case sizeof(char): + { + unsigned char tmp_uchar = 0; + signed char tmp_char = 0; -/** print value of a data point into string. - Return Value: - On success, the total number of characters printed is returned. - On error, a negative number is returned. - */ -size_t -h5str_convert - (char **str, hid_t container, hid_t tid, hvl_t *ptr, int ptroffset, int expand_data) -{ - unsigned char tmp_uchar = 0; - char tmp_char = 0; - unsigned short tmp_ushort = 0; - short tmp_short = 0; - unsigned int tmp_uint = 0; - int tmp_int = 0; - unsigned long tmp_ulong = 0; - long tmp_long = 0; - unsigned long long tmp_ullong = 0; - long long tmp_llong = 0; - float tmp_float = 0.0; - double tmp_double = 0.0; - long double tmp_ldouble = 0.0; - static char fmt_llong[8], fmt_ullong[8]; - const char delimiter[] = " ,}]"; - - char *token; - hid_t mtid = -1; - size_t offset; - size_t nll; - char *this_str = *str; - size_t this_strlen; - int n; - char *cptr = ((char*) ((hvl_t *) ptr)->p) + ptroffset; - unsigned char *ucptr = ((unsigned char*) ((hvl_t *) ptr)->p) + ptroffset; - H5T_class_t tclass = H5Tget_class(tid); - size_t size = H5Tget_size(tid); - H5T_sign_t nsign = H5Tget_sign(tid); - int bdata_print = 0; - - if (!str || !ptr) - return 0; + if (H5T_SGN_NONE == nsign) { + sscanf(token, "%hhu", &tmp_uchar); + HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char)); + } + else { + sscanf(token, "%hhd", &tmp_char); + HDmemcpy(cptr, &tmp_char, sizeof(char)); + } - /* Build default formats for long long types */ - if (!fmt_llong[0]) { - sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); - } /* end if */ + break; + } - this_strlen = HDstrlen(this_str); + case sizeof(short): + { + unsigned short tmp_ushort = 0; + short tmp_short = 0; - switch (tclass) { - case H5T_FLOAT: - token = HDstrtok (this_str, delimiter); - if (sizeof(float) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_FLOAT)) */ - tmp_float = 0; - sscanf(token, "%f", &tmp_float); - HDmemcpy(cptr, &tmp_float, sizeof(float)); - } - else if (sizeof(double) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_DOUBLE)) */ - tmp_double = 0; - sscanf(token, "%%lf", &tmp_double); - HDmemcpy(cptr, &tmp_double, sizeof(double)); - } -#if H5_SIZEOF_LONG_DOUBLE !=0 - else if (sizeof(long double) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_LDOUBLE)) */ - tmp_ldouble = 0; - sscanf(token, "%Lf", &tmp_ldouble); - HDmemcpy(cptr, &tmp_ldouble, sizeof(long double)); - } + if (H5T_SGN_NONE == nsign) { + sscanf(token, "%hu", &tmp_ushort); + HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); + } + else { + sscanf(token, "%hd", &tmp_short); + HDmemcpy(&tmp_short, cptr, sizeof(short)); + } + + break; + } + + case sizeof(int): + { + unsigned int tmp_uint = 0; + int tmp_int = 0; + + if (H5T_SGN_NONE == nsign) { + sscanf(token, "%u", &tmp_uint); + HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int)); + } + else { + sscanf(token, "%d", &tmp_int); + HDmemcpy(cptr, &tmp_int, sizeof(int)); + } + + break; + } + + case sizeof(long): + { + unsigned long tmp_ulong = 0; + long tmp_long = 0; + + if (H5T_SGN_NONE == nsign) { + sscanf(token, "%lu", &tmp_ulong); + HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long)); + } + else { + sscanf(token, "%ld", &tmp_long); + HDmemcpy(cptr, &tmp_long, sizeof(long)); + } + + break; + } + +#if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG + case sizeof(long long): + { + unsigned long long tmp_ullong = 0; + long long tmp_llong = 0; + + if (H5T_SGN_NONE == nsign) { + sscanf(token, fmt_ullong, &tmp_ullong); + HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long)); + } + else { + sscanf(token, fmt_llong, &tmp_llong); + HDmemcpy(cptr, &tmp_llong, sizeof(long long)); + } + + break; + } #endif - break; - case H5T_STRING: - { - if (this_strlen > 0) { - HDstrncpy(cptr, this_str, size); - } - else { - cptr = NULL; - } - } - break; - case H5T_INTEGER: - token = HDstrtok (this_str, delimiter); - if (sizeof(char) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_UCHAR)) */ - tmp_uchar = 0; - sscanf(token, "%hu", &tmp_uchar); - HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char)); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_SCHAR)) */ - tmp_char = 0; - sscanf(token, "%hd", &tmp_char); - HDmemcpy(cptr, &tmp_char, sizeof(char)); - } - } - else if (sizeof(int) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_UINT)) */ - tmp_uint = 0; - sscanf(token, "%u", &tmp_uint); - HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int)); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_INT)) */ - tmp_int = 0; - sscanf(token, "%d", &tmp_int); - HDmemcpy(cptr, &tmp_int, sizeof(int)); - } - } - else if (sizeof(short) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_USHORT)) */ - tmp_ushort = 0; - sscanf(token, "%u", &tmp_ushort); - HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_SHORT)) */ - tmp_short = 0; - sscanf(token, "%d", &tmp_short); - HDmemcpy(&tmp_short, cptr, sizeof(short)); - } - } - else if (sizeof(long) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_ULONG)) */ - tmp_ulong = 0; - sscanf(token, "%lu", &tmp_ulong); - HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long)); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_LONG)) */ - tmp_long = 0; - sscanf(token, "%ld", &tmp_long); - HDmemcpy(cptr, &tmp_long, sizeof(long)); + + default: + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: integer datatype size didn't match any of expected sizes"); + break; } + + retVal = typeSize; + + break; } - else if (sizeof(long long) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_ULLONG)) */ - tmp_ullong = 0; - sscanf(token, fmt_ullong, &tmp_ullong); - HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long)); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_LLONG)) */ - tmp_llong = 0; - sscanf(token, fmt_llong, &tmp_llong); - HDmemcpy(cptr, &tmp_llong, sizeof(long long)); + + case H5T_COMPOUND: + { + unsigned i; + size_t member_offset; + + if ((n = H5Tget_nmembers(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Skip whitespace and compound indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == '{') this_str++; + while (*this_str == ' ') this_str++; + + for (i = 0; i < (unsigned) n; i++) { + member_offset = H5Tget_member_offset(tid, i); + + if ((mtid = H5Tget_member_type(tid, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, member_offset)) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + goto done; + } + + /* Skip whitespace and commas */ + while (*this_str == ' ') this_str++; + if (*this_str == ',') this_str++; + while (*this_str == ' ') this_str++; + + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; } + + /* Skip whitespace and compound indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == '}') this_str++; + while (*this_str == ' ') this_str++; + + retVal = typeSize * (size_t) n; + + break; } - break; - case H5T_COMPOUND: - { - unsigned i; - n = H5Tget_nmembers(tid); - /* remove compound indicators */ - if ((*str)[0] == ' ') - (*str)++; - if ((*str)[0] == '{') - (*str)++; - - for (i = 0; i < n; i++) { - offset = H5Tget_member_offset(tid, i); - mtid = H5Tget_member_type(tid, i); - h5str_convert(str, container, mtid, ptr, offset, expand_data); - /* remove compound indicators */ - if ((*str)[0] == ',') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - H5Tclose(mtid); - } - /* remove compound indicators */ - if ((*str)[0] == '}') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - } - break; - case H5T_ENUM: - { - char enum_name[1024]; - void *value; - if (sizeof(char) == size) { - tmp_uchar = 0; - value = &tmp_uchar; - } - else if (sizeof(short) == size) { - tmp_ushort = 0; - value = &tmp_ushort; - } - else if (sizeof(long) == size) { - tmp_ulong = 0; - value = &tmp_ulong; - } - else if (sizeof(long long) == size) { - tmp_ullong = 0; - value = &tmp_ullong; - } - else { - tmp_uint = 0; - value = &tmp_uint; - } - token = HDstrtok (this_str, delimiter); - H5Tenum_valueof(tid, token, value); - HDmemcpy(ucptr, value, size); - } - break; - case H5T_REFERENCE: + /* TODO handle reference writing */ - cptr = NULL; - break; - case H5T_ARRAY: - { - int rank = 0; - hsize_t i, dims[H5S_MAX_RANK], total_elmts; - /* remove array indicators */ - if ((*str)[0] == '[') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - - mtid = H5Tget_super(tid); - offset = H5Tget_size(mtid); - rank = H5Tget_array_ndims(tid); - - H5Tget_array_dims2(tid, dims); - - total_elmts = 1; - for (i = 0; i < rank; i++) - total_elmts *= dims[i]; - - cptr = HDcalloc((size_t)total_elmts, offset); - for (i = 0; i < total_elmts; i++) { - h5str_convert(str, container, mtid, cptr + (i*offset), offset, expand_data); - /* remove array indicators */ - if ((*str)[0] == ',') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - } - H5Tclose(mtid); - /* remove array indicators */ - if ((*str)[0] == ' ') - (*str)++; - if ((*str)[0] == ']') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - } - break; - case H5T_VLEN: + case H5T_REFERENCE: + cptr = NULL; + break; + + case H5T_ENUM: { - unsigned int i; - mtid = H5Tget_super(tid); - offset = H5Tget_size(mtid); - - /* remove vlen indicators */ - if ((*str)[0] == '{') - (*str)++; - cptr = HDcalloc(offset, sizeof(hvl_t)); - for (i = 0; (i*offset) < (int)size; i++) { - h5str_convert(str, container, mtid, cptr + (i*offset), offset, expand_data); - /* remove vlen indicators */ - if ((*str)[0] == ',') - (*str)++; - if ((*str)[0] == ' ') - (*str)++; - if ((*str)[0] == '}') + void *value; + + token = HDstrtok(this_str, delimiter); + + switch (typeSize) { + case sizeof(char): + { + unsigned char tmp_uchar = 0; + value = &tmp_uchar; + break; + } + + case sizeof(short): + { + unsigned short tmp_ushort = 0; + value = &tmp_ushort; + break; + } + + case sizeof(long): + { + unsigned long tmp_ulong = 0; + value = &tmp_ulong; + break; + } + +#if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG + case sizeof(long long): + { + unsigned long long tmp_ullong = 0; + value = &tmp_ullong; + break; + } +#endif + + default: + { + unsigned int tmp_uint = 0; + value = &tmp_uint; break; + } } - H5Tclose(mtid); - /* remove vlen indicators */ - if ((*str)[0] == '}') - (*str)++; + + if (H5Tenum_valueof(tid, token, value) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + HDmemcpy(ucptr, value, typeSize); + + retVal = typeSize; + + break; } - break; - default: - { - /* All other types get copied raw */ - HDmemcpy(ucptr, this_str, size); - } - break; - } /* end switch */ + case H5T_ARRAY: + { + hsize_t i, dims[H5S_MAX_RANK], total_elmts; + size_t baseTypeSize; + int rank = 0; - return this_strlen; -} /* end h5str_convert */ + /* Skip whitespace and array indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == '[') this_str++; + while (*this_str == ' ') this_str++; -/** print value of a vlen data point into string. - Return Value: - On success, the total number of characters printed is returned. - On error, a negative number is returned. - */ -size_t -h5str_vlsprintf - (h5str_t *str, hid_t container, hid_t tid, hvl_t *ptr, int expand_data) -{ - unsigned char tmp_uchar = 0; - char tmp_char = 0; - unsigned short tmp_ushort = 0; - short tmp_short = 0; - unsigned int tmp_uint = 0; - int tmp_int = 0; - unsigned long tmp_ulong = 0; - long tmp_long = 0; - unsigned long long tmp_ullong = 0; - long long tmp_llong = 0; - float tmp_float = 0.0; - double tmp_double = 0.0; - long double tmp_ldouble = 0.0; - static char fmt_llong[8], fmt_ullong[8]; - - hid_t mtid = -1; - size_t offset; - size_t nll; - char *this_str; - size_t this_strlen; - int n; - H5T_class_t tclass = H5Tget_class(tid); - size_t size = H5Tget_size(tid); - H5T_sign_t nsign = H5Tget_sign(tid); - int bdata_print = 0; - - if (!str || !ptr) - return 0; + if ((mtid = H5Tget_super(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - /* Build default formats for long long types */ - if (!fmt_llong[0]) { - sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); - } /* end if */ + if (!(baseTypeSize = H5Tget_size(mtid))) + H5_LIBRARY_ERROR(ENVONLY); - this_str = NULL; - this_strlen = 0; + if ((rank = H5Tget_array_ndims(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - switch (tclass) { - case H5T_COMPOUND: - { - unsigned i; - n = H5Tget_nmembers(tid); - h5str_append(str, " {"); + if (H5Tget_array_dims2(tid, dims) < 0) + H5_LIBRARY_ERROR(ENVONLY); - for (i = 0; i < n; i++) { - offset = H5Tget_member_offset(tid, i); - mtid = H5Tget_member_type(tid, i); - h5str_sprintf(str, container, mtid, ((char *) (ptr->p)) + offset, ptr->len, expand_data); - if ((i + 1) < n) - h5str_append(str, ", "); - H5Tclose(mtid); + for (i = 0, total_elmts = 1; i < (hsize_t) rank; i++) + total_elmts *= dims[i]; + + if (NULL == (cptr = (char *) HDcalloc((size_t)total_elmts, baseTypeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to allocate array buffer"); + + for (i = 0; i < total_elmts; i++) { + if (!(h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, i * baseTypeSize))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + goto done; + } + + /* Skip whitespace and commas */ + while (*this_str == ' ') this_str++; + if (*this_str == ',') this_str++; + while (*this_str == ' ') this_str++; } - h5str_append(str, "} "); + + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; + + /* Skip whitespace and array indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == ']') this_str++; + while (*this_str == ' ') this_str++; + + retVal = typeSize * total_elmts; + + break; } - break; - case H5T_ARRAY: + + case H5T_VLEN: { - int rank = 0; - hsize_t i, dims[H5S_MAX_RANK], total_elmts; - h5str_append(str, "[ "); + size_t i, baseTypeSize; + hvl_t *vl_buf = (hvl_t *) out_buf; + char cur_char; + + if ((mtid = H5Tget_super(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(baseTypeSize = H5Tget_size(mtid))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (vl_buf->p = HDmalloc(baseTypeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to allocate vlen buffer"); + vl_buf->len = 1; + + /* Skip whitespace and vlen indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == '(') this_str++; + while (*this_str == ' ') this_str++; + + cur_char = *this_str; + for (i = 0; cur_char != ')' && cur_char != '\0'; i++) { + if (i >= vl_buf->len) { + char *tmp_realloc; + + if (NULL == (tmp_realloc = (char *) HDrealloc(vl_buf->p, vl_buf->len * 2 * baseTypeSize))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to reallocate vlen buffer"); + vl_buf->len *= 2; + vl_buf->p = tmp_realloc; + } - mtid = H5Tget_super(tid); - size = H5Tget_size(mtid); - rank = H5Tget_array_ndims(tid); + if (!(h5str_convert(ENVONLY, &this_str, container, mtid, vl_buf->p, i * baseTypeSize))) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + vl_buf->len = i; + goto done; + } - H5Tget_array_dims2(tid, dims); + /* Skip whitespace and commas */ + while (*this_str == ' ') this_str++; + if (*this_str == ',') this_str++; + while (*this_str == ' ') this_str++; + } - total_elmts = 1; - for (i = 0; i < rank; i++) - total_elmts *= dims[i]; + vl_buf->len = i; - h5str_sprintf(str, container, mtid, ((char *) (ptr->p)), ptr->len, expand_data); - H5Tclose(mtid); - h5str_append(str, " ] "); + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; + + /* Skip whitespace and vlen indicators */ + while (*this_str == ' ') this_str++; + if (*this_str == ')') this_str++; + while (*this_str == ' ') this_str++; + + retVal = typeSize; + + break; + } + + case H5T_NCLASSES: + case H5T_NO_CLASS: + { + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: invalid datatype class"); + break; + } + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + default: + { + /* All other types get copied raw */ + HDmemcpy(ucptr, this_str, typeSize); + + retVal = typeSize; + + break; } - break; - default: - this_strlen = h5str_sprintf(str, container, tid, ((char *) (ptr->p)), ptr->len, expand_data); - break; } /* end switch */ - return this_strlen; -} /* end h5str_vlsprintf */ +done: + if (mtid >= 0) + H5Tclose(mtid); + + return retVal; +} /* end h5str_convert */ -/** print value of a data point into string. - Return Value: - On success, the total number of characters printed is returned. - On error, a negative number is returned. +/* + * Prints the value of a data point into a string. + * + * Returns: + * SUCCESS: Total number of characters printed + * FAILURE: 0 */ size_t h5str_sprintf - (h5str_t *str, hid_t container, hid_t tid, void *ptr, int ptr_len, int expand_data) + (JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *in_buf, size_t in_buf_len, int expand_data) { - unsigned char tmp_uchar = 0; - char tmp_char = 0; - unsigned short tmp_ushort = 0; - short tmp_short = 0; - unsigned int tmp_uint = 0; - int tmp_int = 0; - unsigned long tmp_ulong = 0; - long tmp_long = 0; - unsigned long long tmp_ullong = 0; - long long tmp_llong = 0; - float tmp_float = 0.0; - double tmp_double = 0.0; - long double tmp_ldouble = 0.0; - static char fmt_llong[8], fmt_ullong[8]; - - hid_t mtid = -1; - size_t offset; - size_t nll; - char *this_str; - size_t this_strlen; - int n; - char *cptr = (char*) (ptr); - unsigned char *ucptr = (unsigned char*) (ptr); - H5T_class_t tclass = H5Tget_class(tid); - size_t size = H5Tget_size(tid); - H5T_sign_t nsign = H5Tget_sign(tid); - int bdata_print = 0; - - if (!str || !ptr) - return 0; + unsigned char *ucptr = (unsigned char *) in_buf; + static char fmt_llong[8], fmt_ullong[8]; + H5T_class_t tclass = H5T_NO_CLASS; + size_t typeSize = 0; + hid_t mtid = H5I_INVALID_HID; + char *cptr = (char *) in_buf; + char *this_str = NULL; + int n; + size_t retVal = 0; + + if (!out_str) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: out_str is NULL"); + if (!in_buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: in_buf is NULL"); + + if (H5T_NO_CLASS == (tclass = H5Tget_class(tid))) + H5_LIBRARY_ERROR(ENVONLY); + if (!(typeSize = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); /* Build default formats for long long types */ if (!fmt_llong[0]) { - sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); + if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); + if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); } /* end if */ - this_str = NULL; - this_strlen = 0; - switch (tclass) { - case H5T_FLOAT: - if (sizeof(float) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_FLOAT)) */ - HDmemcpy(&tmp_float, cptr, sizeof(float)); - this_str = (char*)HDmalloc(25); - sprintf(this_str, "%g", tmp_float); - } - else if (sizeof(double) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_DOUBLE)) */ - HDmemcpy(&tmp_double, cptr, sizeof(double)); - this_str = (char*)HDmalloc(25); - sprintf(this_str, "%g", tmp_double); - } -#if H5_SIZEOF_LONG_DOUBLE !=0 - else if (sizeof(long double) == size) { - /* if (H5Tequal(tid, H5T_NATIVE_LDOUBLE)) */ - HDmemcpy(&tmp_ldouble, cptr, sizeof(long double)); - this_str = (char*)HDmalloc(27); - sprintf(this_str, "%Lf", tmp_ldouble); - } -#endif - break; - case H5T_STRING: - { - char *tmp_str; - size = 0; + case H5T_FLOAT: + { + switch (typeSize) { + case sizeof(float): + { + float tmp_float = 0.0; - if (H5Tis_variable_str(tid)) { - tmp_str = *(char**) ptr; - if (tmp_str != NULL) - size = HDstrlen(tmp_str); - } - else { - tmp_str = cptr; - } + HDmemcpy(&tmp_float, cptr, sizeof(float)); - /* Check for NULL pointer for string */ - if (tmp_str == NULL) { - this_str = (char *)HDmalloc(5); - HDstrncpy(this_str, "NULL", 4); - } - else { - if (size > 0) { - this_str = (char *)HDmalloc(size+1); - HDstrncpy(this_str, tmp_str, size); - } - } - } - break; - case H5T_INTEGER: - if (sizeof(char) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_UCHAR)) */ - HDmemcpy(&tmp_uchar, cptr, sizeof(unsigned char)); - this_str = (char*)HDmalloc(7); - sprintf(this_str, "%u", tmp_uchar); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_SCHAR)) */ - HDmemcpy(&tmp_char, cptr, sizeof(char)); - this_str = (char*)HDmalloc(7); - sprintf(this_str, "%hhd", tmp_char); - } - } - else if (sizeof(int) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_UINT)) */ - HDmemcpy(&tmp_uint, cptr, sizeof(unsigned int)); - this_str = (char*)HDmalloc(14); - sprintf(this_str, "%u", tmp_uint); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_INT)) */ - HDmemcpy(&tmp_int, cptr, sizeof(int)); - this_str = (char*)HDmalloc(14); - sprintf(this_str, "%d", tmp_int); + if (NULL == (this_str = (char *) HDmalloc(25))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%g", tmp_float) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + + break; + } + + case sizeof(double): + { + double tmp_double = 0.0; + + HDmemcpy(&tmp_double, cptr, sizeof(double)); + + if (NULL == (this_str = (char *) HDmalloc(25))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%g", tmp_double) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + + break; + } +#if H5_SIZEOF_LONG_DOUBLE != 0 + case sizeof(long double): + { + long double tmp_ldouble = 0.0; + + HDmemcpy(&tmp_ldouble, cptr, sizeof(long double)); + + if (NULL == (this_str = (char *) HDmalloc(27))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%Lf", tmp_ldouble) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + + break; + } +#endif + + default: + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: floating-point datatype size didn't match any of expected sizes"); + break; } + + break; } - else if (sizeof(short) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_USHORT)) */ - HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); - this_str = (char*)HDmalloc(9); - sprintf(this_str, "%u", tmp_ushort); + + case H5T_STRING: + { + htri_t is_variable; + char *tmp_str; + + typeSize = 0; + + if ((is_variable = H5Tis_variable_str(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (is_variable) { + if (NULL != (tmp_str = *(char **) in_buf)) + typeSize = HDstrlen(tmp_str); } else { - /* if (H5Tequal(tid, H5T_NATIVE_SHORT)) */ - HDmemcpy(&tmp_short, cptr, sizeof(short)); - this_str = (char*)HDmalloc(9); - sprintf(this_str, "%d", tmp_short); + tmp_str = cptr; } - } - else if (sizeof(long) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_ULONG)) */ - HDmemcpy(&tmp_ulong, cptr, sizeof(unsigned long)); - this_str = (char*)HDmalloc(23); - sprintf(this_str, "%lu", tmp_ulong); + + /* Check for NULL pointer for string */ + if (!tmp_str) { + if (NULL == (this_str = (char *) HDmalloc(5))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + HDstrncpy(this_str, "NULL", 5); } else { - /* if (H5Tequal(tid, H5T_NATIVE_LONG)) */ - HDmemcpy(&tmp_long, cptr, sizeof(long)); - this_str = (char*)HDmalloc(23); - sprintf(this_str, "%ld", tmp_long); + if (typeSize > 0) { + if (NULL == (this_str = (char *) HDmalloc(typeSize + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + HDstrncpy(this_str, tmp_str, typeSize); + } } + + break; } - else if (sizeof(long long) == size) { - if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(tid, H5T_NATIVE_ULLONG)) */ - HDmemcpy(&tmp_ullong, cptr, sizeof(unsigned long long)); - this_str = (char*)HDmalloc(25); - sprintf(this_str, fmt_ullong, tmp_ullong); - } - else { - /* if (H5Tequal(tid, H5T_NATIVE_LLONG)) */ - HDmemcpy(&tmp_llong, cptr, sizeof(long long)); - this_str = (char*)HDmalloc(25); - sprintf(this_str, fmt_llong, tmp_llong); + + case H5T_INTEGER: + { + H5T_sign_t nsign = H5T_SGN_ERROR; + + if (H5T_SGN_ERROR == (nsign = H5Tget_sign(tid))) + H5_LIBRARY_ERROR(ENVONLY); + + switch (typeSize) { + case sizeof(char): + { + unsigned char tmp_uchar = 0; + char tmp_char = 0; + + if (H5T_SGN_NONE == nsign) { + HDmemcpy(&tmp_uchar, cptr, sizeof(unsigned char)); + + if (NULL == (this_str = (char *) HDmalloc(7))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%u", tmp_uchar) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + HDmemcpy(&tmp_char, cptr, sizeof(char)); + + if (NULL == (this_str = (char *) HDmalloc(7))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%hhd", tmp_char) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; + } + + case sizeof(short): + { + unsigned short tmp_ushort = 0; + short tmp_short = 0; + + if (H5T_SGN_NONE == nsign) { + HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); + + if (NULL == (this_str = (char *) HDmalloc(9))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%u", tmp_ushort) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + HDmemcpy(&tmp_short, cptr, sizeof(short)); + + if (NULL == (this_str = (char *) HDmalloc(9))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%d", tmp_short) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; + } + + case sizeof(int): + { + unsigned int tmp_uint = 0; + int tmp_int = 0; + + if (H5T_SGN_NONE == nsign) { + HDmemcpy(&tmp_uint, cptr, sizeof(unsigned int)); + + if (NULL == (this_str = (char *) HDmalloc(14))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%u", tmp_uint) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + HDmemcpy(&tmp_int, cptr, sizeof(int)); + + if (NULL == (this_str = (char *) HDmalloc(14))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%d", tmp_int) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; + } + + case sizeof(long): + { + unsigned long tmp_ulong = 0; + long tmp_long = 0; + + if (H5T_SGN_NONE == nsign) { + HDmemcpy(&tmp_ulong, cptr, sizeof(unsigned long)); + + if (NULL == (this_str = (char *) HDmalloc(23))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%lu", tmp_ulong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + HDmemcpy(&tmp_long, cptr, sizeof(long)); + + if (NULL == (this_str = (char *) HDmalloc(23))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, "%ld", tmp_long) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; + } + +#if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG + case sizeof(long long): + { + unsigned long long tmp_ullong = 0; + long long tmp_llong = 0; + + if (H5T_SGN_NONE == nsign) { + HDmemcpy(&tmp_ullong, cptr, sizeof(unsigned long long)); + + if (NULL == (this_str = (char *) HDmalloc(25))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, fmt_ullong, tmp_ullong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + HDmemcpy(&tmp_llong, cptr, sizeof(long long)); + + if (NULL == (this_str = (char *) HDmalloc(25))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (HDsprintf(this_str, fmt_llong, tmp_llong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; + } +#endif + + default: + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: integer datatype size didn't match any of expected sizes"); + break; } + + break; } - break; - case H5T_COMPOUND: - { - unsigned i; - n = H5Tget_nmembers(tid); - h5str_append(str, " {"); - - for (i = 0; i < n; i++) { - offset = H5Tget_member_offset(tid, i); - mtid = H5Tget_member_type(tid, i); - h5str_sprintf(str, container, mtid, cptr + offset, ptr_len, expand_data); - if ((i + 1) < n) - h5str_append(str, ", "); - H5Tclose(mtid); - } - h5str_append(str, "} "); - } - break; - case H5T_ENUM: - { - char enum_name[1024]; - if (H5Tenum_nameof(tid, cptr, enum_name, sizeof enum_name) >= 0) { - h5str_append(str, enum_name); + + case H5T_COMPOUND: + { + unsigned i; + size_t offset; + + if ((n = H5Tget_nmembers(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_append(out_str, H5_COMPOUND_BEGIN_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + for (i = 0; i < (unsigned) n; i++) { + offset = H5Tget_member_offset(tid, i); + + if ((mtid = H5Tget_member_type(tid, i)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &cptr[offset], in_buf_len, expand_data)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if ((i + 1) < (unsigned) n) + if (!h5str_append(out_str, ", ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; + } + + if (!h5str_append(out_str, H5_COMPOUND_END_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; } - else { - size_t i; - nll = H5Tget_size(tid); - this_str = (char*)HDmalloc(4 * (nll + 1)); - if (1 == nll) { - sprintf(this_str, "%#02x", ucptr[0]); + case H5T_ENUM: + { + char enum_name[1024]; + + if (H5Tenum_nameof(tid, cptr, enum_name, sizeof enum_name) >= 0) { + if (!h5str_append(out_str, enum_name)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } else { - for (i = 0; i < (int)nll; i++) - sprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]); + size_t i; + + if (NULL == (this_str = (char *) HDmalloc(4 * (typeSize + 1)))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (1 == typeSize) { + if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + for (i = 0; i < typeSize; i++) + if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } } + + break; } - } - break; - case H5T_REFERENCE: - if (h5str_is_zero(cptr, size)) { - h5str_append(str, "NULL"); - } - else { - if (H5R_DSET_REG_REF_BUF_SIZE == size) { - /* if (H5Tequal(tid, H5T_STD_REF_DSETREG)) */ + + case H5T_REFERENCE: + { + if (h5str_is_zero(cptr, 99)) { + if (!h5str_append(out_str, "NULL")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + + if (H5R_DSET_REG_REF_BUF_SIZE == typeSize) { + H5S_sel_type region_type = H5S_SEL_ERROR; + hid_t region_obj = H5I_INVALID_HID; + hid_t region = H5I_INVALID_HID; + char ref_name[1024]; + /* * Dataset region reference -- * show the type and the referenced object */ - char ref_name[1024]; - hid_t region_obj; - hid_t region; - H5S_sel_type region_type; - /* get name of the dataset the region reference points to using H5Rget_name */ - region_obj = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, cptr); - if (region_obj >= 0) { - region = H5Rget_region(container, H5R_DATASET_REGION, cptr); - if (region >= 0) { - if(expand_data) { - region_type = H5Sget_select_type(region); - if(region_type==H5S_SEL_POINTS) { - h5str_dump_region_points_data(str, region, region_obj); - } - else { - h5str_dump_region_blocks_data(str, region, region_obj); - } - } - else { - if(H5Rget_name(region_obj, H5R_DATASET_REGION, cptr, (char*)ref_name, 1024) >= 0) { - h5str_append(str, ref_name); - } - - region_type = H5Sget_select_type(region); - - if(region_type==H5S_SEL_POINTS) { - h5str_append(str, " REGION_TYPE POINT"); - h5str_dump_region_points(str, region, region_obj); - } - else { - h5str_append(str, " REGION_TYPE BLOCK"); - h5str_dump_region_blocks(str, region, region_obj); - } - } + /* Get name of the dataset the region reference points to using H5Rget_name */ + if ((region_obj = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, cptr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((region = H5Rget_region(container, H5R_DATASET_REGION, cptr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (expand_data) { + if (H5S_SEL_ERROR == (region_type = H5Sget_select_type(region))) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5S_SEL_POINTS == region_type) { + if (h5str_dump_region_points_data(ENVONLY, out_str, region, region_obj) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else { + if (h5str_dump_region_blocks_data(ENVONLY, out_str, region, region_obj) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + } + else { + if (H5Rget_name(region_obj, H5R_DATASET_REGION, cptr, (char *)ref_name, 1024) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_append(out_str, ref_name)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (H5S_SEL_ERROR == (region_type = H5Sget_select_type(region))) + H5_LIBRARY_ERROR(ENVONLY); - H5Sclose(region); + if (H5S_SEL_POINTS == region_type) { + if (!h5str_append(out_str, " REGION_TYPE POINT")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (h5str_dump_region_points(ENVONLY, out_str, region, region_obj) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else { + if (!h5str_append(out_str, " REGION_TYPE BLOCK")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (h5str_dump_region_blocks(ENVONLY, out_str, region, region_obj) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } - H5Dclose(region_obj); } + + if (H5Sclose(region) < 0) + H5_LIBRARY_ERROR(ENVONLY); + region = H5I_INVALID_HID; + + if (H5Dclose(region_obj) < 0) + H5_LIBRARY_ERROR(ENVONLY); + region_obj = H5I_INVALID_HID; } - else if (H5R_OBJ_REF_BUF_SIZE == size) { - /* if (H5Tequal(tid, H5T_STD_REF_OBJ)) */ + else if (H5R_OBJ_REF_BUF_SIZE == typeSize) { + H5O_info_t oi; + hid_t obj = H5I_INVALID_HID; + /* * Object references -- show the type and OID of the referenced * object. */ - H5O_info_t oi; - hid_t obj; - this_str = (char*)HDmalloc(64); - obj = H5Rdereference2(container, H5P_DEFAULT, H5R_OBJECT, cptr); - H5Oget_info2(obj, &oi, H5O_INFO_ALL); + if (NULL == (this_str = (char *) HDmalloc(64))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if ((obj = H5Rdereference2(container, H5P_DEFAULT, H5R_OBJECT, cptr)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Oget_info2(obj, &oi, H5O_INFO_ALL) < 0) + H5_LIBRARY_ERROR(ENVONLY); /* Print object data and close object */ - sprintf(this_str, "%u-%lu", (unsigned) oi.type, oi.addr); - H5Oclose(obj); + if (HDsprintf(this_str, "%u-%lu", (unsigned) oi.type, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + + if (H5Oclose(obj) < 0) + H5_LIBRARY_ERROR(ENVONLY); + obj = H5I_INVALID_HID; } + + break; } - break; - case H5T_ARRAY: - { - int rank = 0; - hsize_t i, dims[H5S_MAX_RANK], total_elmts; - h5str_append(str, "[ "); - mtid = H5Tget_super(tid); - size = H5Tget_size(mtid); - rank = H5Tget_array_ndims(tid); + case H5T_ARRAY: + { + hsize_t dims[H5S_MAX_RANK], i, total_elmts; + size_t baseSize; + int rank = 0; + + if (!h5str_append(out_str, H5_ARRAY_BEGIN_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if ((mtid = H5Tget_super(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(baseSize = H5Tget_size(mtid))) + H5_LIBRARY_ERROR(ENVONLY); + + if ((rank = H5Tget_array_ndims(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Tget_array_dims2(tid, dims) < 0) + H5_LIBRARY_ERROR(ENVONLY); - H5Tget_array_dims2(tid, dims); + for (i = 0, total_elmts = 1; i < (hsize_t) rank; i++) + total_elmts *= dims[i]; + + for (i = 0; i < total_elmts; i++) { + if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &(cptr[i * baseSize]), in_buf_len, expand_data)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if ((i + 1) < total_elmts) + if (!h5str_append(out_str, ", ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + + if (!h5str_append(out_str, H5_ARRAY_END_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - total_elmts = 1; - for (i = 0; i < rank; i++) - total_elmts *= dims[i]; + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; - for (i = 0; i < total_elmts; i++) { - h5str_sprintf(str, container, mtid, cptr + i * size, ptr_len, expand_data); - if ((i + 1) < total_elmts) - h5str_append(str, ", "); + break; } - H5Tclose(mtid); - h5str_append(str, " ] "); - } - break; - case H5T_VLEN: + + case H5T_VLEN: { - unsigned int i; - mtid = H5Tget_super(tid); - size = H5Tget_size(mtid); - - h5str_append(str, "{"); - for (i = 0; i < (int)ptr_len; i++) { - h5str_sprintf(str, container, mtid, cptr + i * size, ptr_len, expand_data); - if ((i + 1) < (int)ptr_len) - h5str_append(str, ", "); + unsigned int i; + size_t baseSize; + hvl_t *vl_buf = (hvl_t *) in_buf; + + if ((mtid = H5Tget_super(tid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(baseSize = H5Tget_size(mtid))) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_append(out_str, H5_VLEN_BEGIN_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + for (i = 0; i < (unsigned) vl_buf->len; i++) { + if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &(((char *) vl_buf->p)[i * baseSize]), vl_buf->len, expand_data)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if ((i + 1) < (unsigned) vl_buf->len) + if (!h5str_append(out_str, ", ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } - H5Tclose(mtid); - h5str_append(str, "}"); - } - break; - default: - { - /* All other types get printed as hexadecimal */ - size_t i; - nll = H5Tget_size(tid); - this_str = (char*)HDmalloc(4 * (nll + 1)); + if (!h5str_append(out_str, H5_VLEN_END_INDICATOR)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (1 == nll) { - sprintf(this_str, "%#02x", ucptr[0]); + if (H5Tclose(mtid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + mtid = H5I_INVALID_HID; + + break; } - else { - for (i = 0; i < (int)nll; i++) - sprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]); + + case H5T_NO_CLASS: + case H5T_NCLASSES: + { + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: invalid datatype class"); + break; + } + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + default: + { + size_t i; + + /* All other types get printed as hexadecimal */ + + if (NULL == (this_str = (char *) HDmalloc(4 * (typeSize + 1)))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + + if (1 == typeSize) { + if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + else { + for (i = 0; i < typeSize; i++) + if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + + break; } } - break; - } /* end switch */ if (this_str) { - h5str_append(str, this_str); - this_strlen = HDstrlen(str->s); + if (!h5str_append(out_str, this_str)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + HDfree(this_str); + this_str = NULL; } /* end if */ - return this_strlen; + retVal = HDstrlen(out_str->s); + +done: + if (mtid >= 0) + H5Tclose(mtid); + + return retVal; } /* end h5str_sprintf */ /*------------------------------------------------------------------------- @@ -1020,113 +1214,115 @@ h5str_sprintf */ static int h5str_print_region_data_blocks - (hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) + (JNIEnv *env, hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { - hsize_t *dims1 = NULL; - hsize_t *start = NULL; - hsize_t *count = NULL; - hsize_t blkndx; - hsize_t total_size[H5S_MAX_RANK]; - hsize_t numelem; - hsize_t numindex; - size_t jndx; - unsigned indx; - size_t type_size; - int ret_value = SUCCEED; - hid_t mem_space = -1; - hid_t sid1 = -1; - void *region_buf = NULL; + unsigned indx; + hsize_t *dims1 = NULL; + hsize_t *start = NULL; + hsize_t *count = NULL; + hsize_t blkndx; + hsize_t total_size[H5S_MAX_RANK]; + hsize_t numelem; + hsize_t numindex; + size_t jndx; + size_t type_size; + hid_t mem_space = H5I_INVALID_HID; + hid_t sid1 = H5I_INVALID_HID; + void *region_buf = NULL; + int ret_value = FAIL; + + if (ndims < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_blocks: ndims < 0"); + if (nblocks < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_blocks: nblocks < 0"); /* Get the dataspace of the dataset */ - if((sid1 = H5Dget_space(region_id)) >= 0) { + if ((sid1 = H5Dget_space(region_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - - /* find the dimensions of each data space from the block coordinates */ - numelem = 1; - for (jndx = 0; jndx < ndims; jndx++) { - dims1[jndx] = ptdata[jndx + (size_t)ndims] - ptdata[jndx] + 1; - numelem = dims1[jndx] * numelem; - } /* end for */ - - /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(ndims, dims1, NULL)) >= 0) { - if((type_size = H5Tget_size(type_id)) > 0) { - if((region_buf = HDmalloc(type_size * (size_t)numelem)) != NULL) { - /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ - /* 1 2 n 1 2 n */ - if((start = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - if((count = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - for (blkndx = 0; blkndx < nblocks; blkndx++) { - for (indx = 0; indx < ndims; indx++) { - start[indx] = ptdata[indx + blkndx * (hsize_t)ndims * 2]; - count[indx] = dims1[indx]; - } /* end for */ - - if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) >= 0) { - if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) >= 0) { - if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) { - for (numindex = 0; numindex < numelem; numindex++) { - h5str_sprintf(str, region_id, type_id, ((char*)region_buf + numindex * type_size), 0, 1); - - if (numindex + 1 < numelem) - h5str_append(str, ", "); - } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ - } /* end if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) */ - } /* end if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) >= 0) */ - } /* end if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) >= 0) */ - } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ - - HDfree(count); - } /* end if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - - HDfree(start); - } /* end if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; + /* Allocate space for the dimension array */ + if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate dimension array buffer"); - HDfree(region_buf); - } /* end if((region_buf = HDmalloc(type_size * (size_t)numelem)) != NULL) */ - else - ret_value = -1; - } /* end if((type_size = H5Tget_size(type_id)) > 0) */ - else - ret_value = -1; - - if(H5Sclose(mem_space) < 0) - ret_value = -1; - } /* end if((mem_space = H5Screate_simple(ndims, dims1, NULL)) >= 0) */ - else - ret_value = -1; - - HDfree(dims1); - } /* end if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - - if(H5Sclose(sid1) < 0) - ret_value = -1; - } /* end if((sid1 = H5Dget_space(region_id)) >= 0) */ - else - ret_value = -1; + /* Find the dimensions of each data space from the block coordinates */ + for (jndx = 0, numelem = 1; jndx < (size_t) ndims; jndx++) { + dims1[jndx] = ptdata[jndx + (size_t)ndims] - ptdata[jndx] + 1; + numelem = dims1[jndx] * numelem; + } /* end for */ + + /* Create dataspace for reading buffer */ + if ((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!(type_size = H5Tget_size(type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + if (NULL == (region_buf = HDmalloc(type_size * (size_t)numelem))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate region buffer"); + + /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ + /* 1 2 n 1 2 n */ + if (NULL == (start = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate hyperslab start buffer"); + + if (NULL == (count = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate hyperslab count buffer"); + + for (blkndx = 0; blkndx < (hsize_t) nblocks; blkndx++) { + for (indx = 0; indx < (unsigned) ndims; indx++) { + start[indx] = ptdata[indx + blkndx * (hsize_t)ndims * 2]; + count[indx] = dims1[indx]; + } /* end for */ + + if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + for (numindex = 0; numindex < numelem; numindex++) { + if (!h5str_sprintf(ENVONLY, str, region_id, type_id, ((char *)region_buf + numindex * type_size), 0, 1)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (numindex + 1 < numelem) + if (!h5str_append(str, ", ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ + } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ + + ret_value = SUCCEED; + +done: + if (count) + HDfree(count); + if (start) + HDfree(start); + if (region_buf) + HDfree(region_buf); + if (mem_space >= 0) + H5Sclose(mem_space); + if (dims1) + HDfree(dims1); + if (sid1 >= 0) + H5Sclose(sid1); return ret_value; } /* end h5str_print_region_data_blocks */ int h5str_dump_region_blocks_data - (h5str_t *str, hid_t region, hid_t region_id) + (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { - int ret_value = 0; - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata; - hid_t dtype = -1; - hid_t type_id = -1; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t nblocks; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + hid_t dtype = H5I_INVALID_HID; + hid_t type_id = H5I_INVALID_HID; + int ndims = -1; + int ret_value = FAIL; /* * This function fails if the region does not have blocks. @@ -1135,50 +1331,56 @@ h5str_dump_region_blocks_data nblocks = H5Sget_select_hyper_nblocks(region); } H5E_END_TRY; + if (nblocks < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* Print block information */ - if (nblocks > 0) { - alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); - if (alloc_size == (hsize_t)((size_t) alloc_size)) { - ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5Sget_select_hyper_blocklist(region, (hsize_t) 0, - (hsize_t) nblocks, ptdata); + alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); + if (alloc_size == (hsize_t)((size_t) alloc_size)) { + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks_data: failed to allocate region block buffer"); + if (H5Sget_select_hyper_blocklist(region, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if((dtype = H5Dget_type(region_id)) >= 0) { - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) { + if ((dtype = H5Dget_type(region_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - h5str_print_region_data_blocks(region_id, str, ndims, type_id, nblocks, ptdata); + if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if(H5Tclose(type_id) < 0) - ret_value = -1; - } /* end if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) */ - else - ret_value = -1; + if (h5str_print_region_data_blocks(ENVONLY, region_id, str, ndims, type_id, nblocks, ptdata) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ - if(H5Tclose(dtype) < 0) - ret_value = -1; - } /* end if((dtype = H5Dget_type(region_id)) >= 0) */ - else - ret_value = -1; - HDfree(ptdata); - } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ - } /* if (nblocks > 0) */ + ret_value = SUCCEED; + +done: + if (type_id >= 0) + H5Tclose(type_id); + if (dtype >= 0) + H5Tclose(dtype); + if (ptdata) + HDfree(ptdata); return ret_value; } /* end h5str_dump_region_blocks_data */ static int h5str_dump_region_blocks - (h5str_t *str, hid_t region, hid_t region_id) + (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { - int ret_value = 0; - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata; - hid_t dtype = -1; - hid_t type_id = -1; - char tmp_str[256]; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t nblocks; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + char tmp_str[256]; + int ndims = -1; + int ret_value = FAIL; + + UNUSED(region_id); /* * This function fails if the region does not have blocks. @@ -1187,44 +1389,70 @@ h5str_dump_region_blocks nblocks = H5Sget_select_hyper_nblocks(region); } H5E_END_TRY; + if (nblocks < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* Print block information */ - if (nblocks > 0) { + alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); + if (alloc_size == (hsize_t)((size_t) alloc_size)) { int i; - alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); - if (alloc_size == (hsize_t)((size_t) alloc_size)) { - ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5Sget_select_hyper_blocklist(region, (hsize_t) 0, - (hsize_t) nblocks, ptdata); + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: failed to allocate region block buffer"); - h5str_append(str, " {"); - for (i = 0; i < nblocks; i++) { - int j; + if (H5Sget_select_hyper_blocklist(region, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) + H5_LIBRARY_ERROR(ENVONLY); - h5str_append(str, " "); + if (!h5str_append(str, " {")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - /* Start coordinates and opposite corner */ - for (j = 0; j < ndims; j++) { - tmp_str[0] = '\0'; - sprintf(tmp_str, "%s%lu", j ? "," : "(", - (unsigned long) ptdata[i * 2 * ndims + j]); - h5str_append(str, tmp_str); - } + for (i = 0; i < nblocks; i++) { + int j; - for (j = 0; j < ndims; j++) { - tmp_str[0] = '\0'; - sprintf(tmp_str, "%s%lu", j ? "," : ")-(", - (unsigned long) ptdata[i * 2 * ndims + j + ndims]); - h5str_append(str, tmp_str); - } - h5str_append(str, ") "); + if (!h5str_append(str, " ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + /* Start coordinates and opposite corner */ + for (j = 0; j < ndims; j++) { + tmp_str[0] = '\0'; + + if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", + (unsigned long) ptdata[i * 2 * ndims + j]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); + + if (!h5str_append(str, tmp_str)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + + for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; + + if (HDsprintf(tmp_str, "%s%lu", j ? "," : ")-(", + (unsigned long) ptdata[i * 2 * ndims + j + ndims]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); + + if (!h5str_append(str, tmp_str)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } - h5str_append(str, " }"); - HDfree(ptdata); - } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ - } /* if (nblocks > 0) */ + if (!h5str_append(str, ") ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + tmp_str[0] = '\0'; + } + + if (!h5str_append(str, " }")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ + + ret_value = SUCCEED; + +done: + if (ptdata) + HDfree(ptdata); return ret_value; } /* end h5str_dump_region_blocks */ @@ -1241,76 +1469,76 @@ h5str_dump_region_blocks */ static int h5str_print_region_data_points - (hid_t region_space, hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) + (JNIEnv *env, hid_t region_space, hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) { - hsize_t *dims1 = NULL; - hsize_t total_size[H5S_MAX_RANK]; - size_t jndx; - size_t type_size; - int ret_value = SUCCEED; - hid_t mem_space = -1; - void *region_buf = NULL; + hsize_t *dims1 = NULL; + hsize_t total_size[H5S_MAX_RANK]; + size_t jndx; + size_t type_size; + hid_t mem_space = H5I_INVALID_HID; + void *region_buf = NULL; + int ret_value = FAIL; + + UNUSED(ptdata); + + if (npoints < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_points: npoints < 0"); /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { + if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_points: failed to allocate dimension array buffer"); - dims1[0] = (hsize_t)npoints; + dims1[0] = (hsize_t)npoints; - /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(1, dims1, NULL)) >= 0) { + /* Create dataspace for reading buffer */ + if ((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if((type_size = H5Tget_size(type_id)) > 0) { + if (!(type_size = H5Tget_size(type_id))) + H5_LIBRARY_ERROR(ENVONLY); - if((region_buf = HDmalloc(type_size * (size_t)npoints)) != NULL) { + if (NULL == (region_buf = HDmalloc(type_size * (size_t)npoints))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_points: failed to allocate region buffer"); - if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) >= 0) { + if (H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) + H5_LIBRARY_ERROR(ENVONLY); - for (jndx = 0; jndx < npoints; jndx++) { - if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) { + for (jndx = 0; jndx < (size_t) npoints; jndx++) { + if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); - h5str_sprintf(str, region_id, type_id, ((char*)region_buf + jndx * type_size), 0, 1); + if (!h5str_sprintf(ENVONLY, str, region_id, type_id, ((char *)region_buf + jndx * type_size), 0, 1)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (jndx + 1 < npoints) - h5str_append(str, ", "); + if (jndx + 1 < (size_t) npoints) + if (!h5str_append(str, ", ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ - } /* end if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) */ - } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ - } /* end if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) >= 0) */ - else - ret_value = -1; + ret_value = SUCCEED; - HDfree(region_buf); - } /* end if((region_buf = HDmalloc(type_size * (size_t)npoints)) != NULL) */ - else - ret_value = -1; - } /* end if((type_size = H5Tget_size(type_id)) > 0) */ - else - ret_value = -1; - - if(H5Sclose(mem_space) < 0) - ret_value = -1; - } /* end if((mem_space = H5Screate_simple(1, dims1, NULL)) >= 0) */ - else - ret_value = -1; +done: + if (region_buf) + HDfree(region_buf); + if (mem_space >= 0) + H5Sclose(mem_space); + if (dims1) HDfree(dims1); - } /* end if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; return ret_value; } /* end h5str_print_region_data_points */ int h5str_dump_region_points_data - (h5str_t *str, hid_t region, hid_t region_id) + (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { - int ret_value = 0; - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - hid_t dtype = -1; - hid_t type_id = -1; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + hid_t dtype = H5I_INVALID_HID; + hid_t type_id = H5I_INVALID_HID; + int ndims = -1; + int ret_value = FAIL; /* * This function fails if the region does not have points. @@ -1319,50 +1547,59 @@ h5str_dump_region_points_data npoints = H5Sget_select_elem_npoints(region); } H5E_END_TRY; + if (npoints < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* Print point information */ if (npoints > 0) { alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { - ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5Sget_select_elem_pointlist(region, (hsize_t) 0, - (hsize_t) npoints, ptdata); + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points_data: failed to allocate region point data buffer"); - if((dtype = H5Dget_type(region_id)) >= 0) { - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) { + if (H5Sget_select_elem_pointlist(region, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) + H5_LIBRARY_ERROR(ENVONLY); - h5str_print_region_data_points(region, region_id, - str, ndims, type_id, npoints, ptdata); + if ((dtype = H5Dget_type(region_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if(H5Tclose(type_id) < 0) - ret_value = -1; - } /* end if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) */ - else - ret_value = -1; - - if(H5Tclose(dtype) < 0) - ret_value = -1; - } /* end if((dtype = H5Dget_type(region_id)) >= 0) */ - else - ret_value = -1; - HDfree(ptdata); + if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (h5str_print_region_data_points(ENVONLY, region, region_id, + str, ndims, type_id, npoints, ptdata) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } } + ret_value = SUCCEED; + +done: + if (type_id >= 0) + H5Tclose(type_id); + if (dtype >= 0) + H5Tclose(dtype); + if (ptdata) + HDfree(ptdata); + return ret_value; } /* end h5str_dump_region_points_data */ static int h5str_dump_region_points - (h5str_t *str, hid_t region, hid_t region_id) + (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { - int ret_value = 0; - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - char tmp_str[256]; - hid_t dtype = -1; - hid_t type_id = -1; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + char tmp_str[256]; + int ndims = -1; + int ret_value = FAIL; + + UNUSED(region_id); /* * This function fails if the region does not have points. @@ -1371,37 +1608,59 @@ h5str_dump_region_points npoints = H5Sget_select_elem_npoints(region); } H5E_END_TRY; + if (npoints < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* Print point information */ if (npoints > 0) { int i; alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { - ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5Sget_select_elem_pointlist(region, (hsize_t) 0, - (hsize_t) npoints, ptdata); + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: failed to allocate region point buffer"); + + if (H5Sget_select_elem_pointlist(region, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (!h5str_append(str, " {")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - h5str_append(str, " {"); for (i = 0; i < npoints; i++) { int j; - h5str_append(str, " "); + if (!h5str_append(str, " ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; - sprintf(tmp_str, "%s%lu", j ? "," : "(", - (unsigned long) (ptdata[i * ndims + j])); - h5str_append(str, tmp_str); + + if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", + (unsigned long) (ptdata[i * ndims + j])) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: HDsprintf failure"); + + if (!h5str_append(str, tmp_str)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (j = 0; j < ndims; j++) */ - h5str_append(str, ") "); + if (!h5str_append(str, ") ")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (i = 0; i < npoints; i++) */ - h5str_append(str, " }"); - HDfree(ptdata); + if (!h5str_append(str, " }")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end if (alloc_size == (hsize_t)((size_t) alloc_size)) */ } /* end if (npoints > 0) */ + ret_value = SUCCEED; + +done: + if (ptdata) + HDfree(ptdata); + return ret_value; } /* end h5str_dump_region_points */ @@ -1419,6 +1678,37 @@ h5str_is_zero } /* end h5str_is_zero */ /*------------------------------------------------------------------------- + * Function: h5str_detect_vlen + * + * Purpose: Recursive check for any variable length data in given type. + * + * Return: + * 1 : type contains any variable length data + * 0 : type doesn't contain any variable length data + * Negative value: error occurred + *------------------------------------------------------------------------- + */ +static htri_t +h5str_detect_vlen + (hid_t tid) +{ + htri_t ret = FAIL; + + /* Recursively detect any vlen data values in type (compound, array ...) */ + ret = H5Tdetect_class(tid, H5T_VLEN); + if ((ret == 1) || (ret < 0)) + goto done; + + /* Recursively detect any vlen string in type (compound, array ...) */ + ret = h5str_detect_vlen_str(tid); + if ((ret == 1) || (ret < 0)) + goto done; + +done: + return ret; +} /* end h5str_detect_vlen */ + +/*------------------------------------------------------------------------- * Function: h5str_detect_vlen_str * * Purpose: Recursive check for variable length string of a datatype. @@ -1459,12 +1749,10 @@ h5str_detect_vlen_str unsigned i = 0; int n = H5Tget_nmembers(tid); - if(n < 0) { - n = ret; + if (n < 0) goto done; - } /* end if */ - for(i = 0; i < n; i++) { + for(i = 0; i < (unsigned) n; i++) { hid_t mtid = H5Tget_member_type(tid, i); ret = h5str_detect_vlen_str(mtid); @@ -1494,15 +1782,18 @@ static hid_t h5str_get_native_type (hid_t type) { - hid_t p_type; H5T_class_t type_class; + hid_t p_type = H5I_INVALID_HID; + + if ((type_class = H5Tget_class(type)) < 0) + goto done; - type_class = H5Tget_class(type); - if(type_class==H5T_BITFIELD) - p_type=H5Tcopy(type); + if (type_class == H5T_BITFIELD) + p_type = H5Tcopy(type); else - p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT); + p_type = H5Tget_native_type(type, H5T_DIR_DEFAULT); +done: return(p_type); } /* end h5str_get_native_type */ @@ -1520,73 +1811,89 @@ static hid_t h5str_get_little_endian_type (hid_t tid) { - hid_t p_type=-1; H5T_class_t type_class; - size_t size; H5T_sign_t sign; + size_t size; + hid_t p_type = H5I_INVALID_HID; - type_class = H5Tget_class(tid); - size = H5Tget_size(tid); - sign = H5Tget_sign(tid); + if ((type_class = H5Tget_class(tid)) < 0) + goto done; - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8LE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16LE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32LE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64LE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8LE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16LE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32LE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64LE); - } - break; + if (!(size = H5Tget_size(tid))) + goto done; - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32LE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64LE); - break; + if ((sign = H5Tget_sign(tid)) < 0) + goto done; - case H5T_BITFIELD: - { - if ( size == 1) - p_type=H5Tcopy(H5T_STD_B8LE); - else if ( size == 2) - p_type=H5Tcopy(H5T_STD_B16LE); - else if ( size == 4) - p_type=H5Tcopy(H5T_STD_B32LE); - else if ( size == 8) - p_type=H5Tcopy(H5T_STD_B64LE); - } - break; + switch ( type_class ) { + case H5T_INTEGER: + { + if ( size == 1 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I8LE); + else if ( size == 2 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I16LE); + else if ( size == 4 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I32LE); + else if ( size == 8 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I64LE); + else if ( size == 1 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U8LE); + else if ( size == 2 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U16LE); + else if ( size == 4 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U32LE); + else if ( size == 8 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U64LE); + + break; + } + + case H5T_FLOAT: + { + if ( size == 4 ) + p_type = H5Tcopy(H5T_IEEE_F32LE); + else if ( size == 8 ) + p_type = H5Tcopy(H5T_IEEE_F64LE); - case H5T_TIME: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; + break; + } + + case H5T_BITFIELD: + { + if ( size == 1 ) + p_type = H5Tcopy(H5T_STD_B8LE); + else if ( size == 2 ) + p_type = H5Tcopy(H5T_STD_B16LE); + else if ( size == 4 ) + p_type = H5Tcopy(H5T_STD_B32LE); + else if ( size == 8 ) + p_type = H5Tcopy(H5T_STD_B64LE); + + break; + } - default: - break; + case H5T_NO_CLASS: + case H5T_NCLASSES: + { + goto done; + break; + } + case H5T_TIME: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + default: + break; } +done: return(p_type); } /* end h5str_get_little_endian_type */ @@ -1594,115 +1901,100 @@ h5str_get_little_endian_type * Function: h5str_get_big_endian_type * * Purpose: Get a big endian type from a file type - * - * Return: Success: datatype ID - * Failure: FAIL - *------------------------------------------------------------------------- - */ -static hid_t -h5str_get_big_endian_type - (hid_t tid) -{ - hid_t p_type=-1; - H5T_class_t type_class; - size_t size; - H5T_sign_t sign; - - type_class = H5Tget_class(tid); - size = H5Tget_size(tid); - sign = H5Tget_sign(tid); - - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8BE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16BE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32BE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64BE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8BE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16BE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32BE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64BE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32BE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64BE); - break; - - case H5T_BITFIELD: - { - if ( size == 1) - p_type=H5Tcopy(H5T_STD_B8BE); - else if ( size == 2) - p_type=H5Tcopy(H5T_STD_B16BE); - else if ( size == 4) - p_type=H5Tcopy(H5T_STD_B32BE); - else if ( size == 8) - p_type=H5Tcopy(H5T_STD_B64BE); - } - break; - - case H5T_TIME: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - return(p_type); -} /* end h5str_get_big_endian_type */ - -/*------------------------------------------------------------------------- - * Function: h5str_detect_vlen - * - * Purpose: Recursive check for any variable length data in given type. - * - * Return: - * 1 : type conatains any variable length data - * 0 : type doesn't contain any variable length data - * Negative value: error occur + * + * Return: Success: datatype ID + * Failure: FAIL *------------------------------------------------------------------------- */ -static htri_t -h5str_detect_vlen +static hid_t +h5str_get_big_endian_type (hid_t tid) { - htri_t ret; + H5T_class_t type_class; + H5T_sign_t sign; + size_t size; + hid_t p_type = H5I_INVALID_HID; - /* recursive detect any vlen data values in type (compound, array ...) */ - ret = H5Tdetect_class(tid, H5T_VLEN); - if((ret == 1) || (ret < 0)) + if ((type_class = H5Tget_class(tid)) < 0) goto done; - /* recursive detect any vlen string in type (compound, array ...) */ - ret = h5str_detect_vlen_str(tid); - if((ret == 1) || (ret < 0)) + if (!(size = H5Tget_size(tid))) + goto done; + + if ((sign = H5Tget_sign(tid)) < 0) goto done; + switch ( type_class ) { + case H5T_INTEGER: + { + if ( size == 1 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I8BE); + else if ( size == 2 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I16BE); + else if ( size == 4 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I32BE); + else if ( size == 8 && sign == H5T_SGN_2 ) + p_type = H5Tcopy(H5T_STD_I64BE); + else if ( size == 1 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U8BE); + else if ( size == 2 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U16BE); + else if ( size == 4 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U32BE); + else if ( size == 8 && sign == H5T_SGN_NONE ) + p_type = H5Tcopy(H5T_STD_U64BE); + + break; + } + + case H5T_FLOAT: + { + if ( size == 4 ) + p_type = H5Tcopy(H5T_IEEE_F32BE); + else if ( size == 8 ) + p_type = H5Tcopy(H5T_IEEE_F64BE); + + break; + } + + case H5T_BITFIELD: + { + if ( size == 1 ) + p_type = H5Tcopy(H5T_STD_B8BE); + else if ( size == 2 ) + p_type = H5Tcopy(H5T_STD_B16BE); + else if ( size == 4 ) + p_type = H5Tcopy(H5T_STD_B32BE); + else if ( size == 8 ) + p_type = H5Tcopy(H5T_STD_B64BE); + + break; + } + + case H5T_NO_CLASS: + case H5T_NCLASSES: + { + goto done; + break; + } + + case H5T_TIME: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + default: + break; + } + done: - return ret; -} /* end h5str_detect_vlen */ + return(p_type); +} /* end h5str_get_big_endian_type */ /*------------------------------------------------------------------------- * Function: render_bin_output @@ -1717,201 +2009,261 @@ static int h5str_render_bin_output (FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t block_nelmts) { - int ret_value = 0; - unsigned char *mem = (unsigned char*)_mem; - size_t size; /* datum size */ - hsize_t block_index; - H5T_class_t type_class; - - if((size = H5Tget_size(tid)) > 0) { - - if((type_class = H5Tget_class(tid)) >= 0) { - - switch (type_class) { - case H5T_INTEGER: - case H5T_FLOAT: - case H5T_ENUM: - block_index = block_nelmts * size; - while(block_index > 0) { - size_t bytes_in = 0; /* # of bytes to write */ - size_t bytes_wrote = 0; /* # of bytes written */ - size_t item_size = size; /* size of items in bytes */ - - if(block_index > sizeof(size_t)) - bytes_in = sizeof(size_t); - else - bytes_in = (size_t)block_index; + unsigned char *mem = (unsigned char*)_mem; + H5T_class_t type_class; + hsize_t block_index; + size_t size; /* datum size */ + int ret_value = 0; + + if (!(size = H5Tget_size(tid))) { + ret_value = FAIL; + goto done; + } + + if ((type_class = H5Tget_class(tid)) < 0) { + ret_value = FAIL; + goto done; + } - bytes_wrote = fwrite(mem, 1, bytes_in, stream); + switch (type_class) { + case H5T_INTEGER: + case H5T_FLOAT: + case H5T_ENUM: + { + block_index = block_nelmts * size; + while (block_index > 0) { + size_t bytes_in = 0; /* # of bytes to write */ + size_t bytes_wrote = 0; /* # of bytes written */ - if(bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(stream))) { - ret_value = -1; - break; - } + if (block_index > sizeof(size_t)) + bytes_in = sizeof(size_t); + else + bytes_in = (size_t)block_index; - block_index -= (hsize_t)bytes_wrote; - mem = mem + bytes_wrote; - } + bytes_wrote = fwrite(mem, 1, bytes_in, stream); + + if (bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(stream))) { + ret_value = FAIL; break; - case H5T_STRING: - { - unsigned int i; - H5T_str_t pad; - char *s; - unsigned char tempuchar; + } - pad = H5Tget_strpad(tid); + block_index -= (hsize_t)bytes_wrote; + mem = mem + bytes_wrote; + } - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; + break; + } - if (H5Tis_variable_str(tid)) { - s = *(char**) mem; - if (s != NULL) - size = HDstrlen(s); - } - else { - s = (char *) mem; - } - for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); - if (1 != fwrite(&tempuchar, sizeof(unsigned char), 1, stream)) { - ret_value = -1; - break; - } - } /* i */ - if(ret_value < 0) - break; - } /* for (block_index = 0; block_index < block_nelmts; block_index++) */ + case H5T_STRING: + { + unsigned char tempuchar; + unsigned int i; + H5T_str_t pad; + char *s; + + if ((pad = H5Tget_strpad(tid)) < 0) { + ret_value = FAIL; + goto done; + } + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char *)_mem) + block_index * size; + + if (H5Tis_variable_str(tid)) { + s = *(char**) mem; + if (s != NULL) + size = HDstrlen(s); } - break; - case H5T_COMPOUND: - { - unsigned j; - hid_t memb; - unsigned nmembs; - size_t offset; - - nmembs = (unsigned)H5Tget_nmembers(tid); - - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; - for (j = 0; j < nmembs; j++) { - offset = H5Tget_member_offset(tid, j); - memb = H5Tget_member_type(tid, j); - - if (h5str_render_bin_output(stream, container, memb, mem + offset, 1) < 0) { - H5Tclose(memb); - ret_value = -1; - break; - } - - H5Tclose(memb); - } - if(ret_value < 0) - break; - } + else { + s = (char *) mem; } - break; - case H5T_ARRAY: - { - int k, ndims; - hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts; - hid_t memb; - - /* get the array's base datatype for each element */ - memb = H5Tget_super(tid); - ndims = H5Tget_array_ndims(tid); - H5Tget_array_dims2(tid, dims); - - /* calculate the number of array elements */ - for (k = 0, nelmts = 1; k < ndims; k++) { - temp_nelmts = nelmts; - temp_nelmts *= dims[k]; - nelmts = (size_t) temp_nelmts; + for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { + HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); + if (1 != fwrite(&tempuchar, sizeof(unsigned char), 1, stream)) { + ret_value = FAIL; + break; } + } /* i */ + if (ret_value < 0) + break; + } /* for (block_index = 0; block_index < block_nelmts; block_index++) */ - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; - /* dump the array element */ - if (h5str_render_bin_output(stream, container, memb, mem, nelmts) < 0) { - ret_value = -1; - break; - } + break; + } + + case H5T_COMPOUND: + { + unsigned j; + size_t offset; + hid_t memb = H5I_INVALID_HID; + int nmembs; + + if ((nmembs = H5Tget_nmembers(tid)) < 0) { + ret_value = FAIL; + goto done; + } + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + for (j = 0; j < (unsigned) nmembs; j++) { + offset = H5Tget_member_offset(tid, j); + memb = H5Tget_member_type(tid, j); + + if (h5str_render_bin_output(stream, container, memb, mem + offset, 1) < 0) { + H5Tclose(memb); + ret_value = FAIL; + break; } + H5Tclose(memb); } - break; - case H5T_VLEN: - { - hsize_t nelmts; - hid_t memb; - /* get the VL sequences's base datatype for each element */ - memb = H5Tget_super(tid); + if (ret_value < 0) + break; + } + + break; + } - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; - /* Get the number of sequence elements */ - nelmts = ((hvl_t *) mem)->len; + case H5T_ARRAY: + { + hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts; + hid_t memb; + int k, ndims; - /* dump the array element */ - if (h5str_render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) { - ret_value = -1; - break; - } - } - H5Tclose(memb); + /* Get the array's base datatype for each element */ + if ((memb = H5Tget_super(tid)) < 0) { + ret_value = FAIL; + goto done; + } + + if ((ndims = H5Tget_array_ndims(tid)) < 0) { + ret_value = FAIL; + goto done; + } + + if (H5Tget_array_dims2(tid, dims) < 0) { + ret_value = FAIL; + goto done; + } + + /* Calculate the number of array elements */ + for (k = 0, nelmts = 1; k < ndims; k++) { + temp_nelmts = nelmts; + temp_nelmts *= dims[k]; + nelmts = (size_t) temp_nelmts; + } + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + + /* dump the array element */ + if (h5str_render_bin_output(stream, container, memb, mem, nelmts) < 0) { + ret_value = FAIL; + break; } - break; - case H5T_REFERENCE: - { - if (H5Tequal(tid, H5T_STD_REF_DSETREG)) { - /* region data */ - hid_t region_id, region_space; - H5S_sel_type region_type; - - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; - region_id = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, mem); - if (region_id >= 0) { - region_space = H5Rget_region(container, H5R_DATASET_REGION, mem); - if (region_space >= 0) { - region_type = H5Sget_select_type(region_space); - if(region_type == H5S_SEL_POINTS) - ret_value = render_bin_output_region_points(stream, region_space, region_id, container); - else - ret_value = render_bin_output_region_blocks(stream, region_space, region_id, container); - H5Sclose(region_space); - } /* end if (region_space >= 0) */ - H5Dclose(region_id); - } /* end if (region_id >= 0) */ - if(ret_value < 0) - break; - } + } + + H5Tclose(memb); + + break; + } + + case H5T_VLEN: + { + hsize_t nelmts; + hid_t memb; + + /* Get the VL sequences's base datatype for each element */ + if ((memb = H5Tget_super(tid)) < 0) { + ret_value = FAIL; + goto done; + } + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + + /* Get the number of sequence elements */ + nelmts = ((hvl_t *) mem)->len; + + /* dump the array element */ + if (h5str_render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) { + ret_value = FAIL; + break; + } + } + + H5Tclose(memb); + + break; + } + + case H5T_REFERENCE: + { + if (H5Tequal(tid, H5T_STD_REF_DSETREG)) { + H5S_sel_type region_type; + hid_t region_id, region_space; + + /* Region data */ + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + + if ((region_id = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, mem)) < 0) + continue; + + if ((region_space = H5Rget_region(container, H5R_DATASET_REGION, mem)) < 0) { + H5Dclose(region_id); + continue; } - else if (H5Tequal(tid, H5T_STD_REF_OBJ)) { - ; + + if ((region_type = H5Sget_select_type(region_space)) < 0) { + H5Sclose(region_space); + H5Dclose(region_id); + continue; } + + if (region_type == H5S_SEL_POINTS) + ret_value = render_bin_output_region_points(stream, region_space, region_id, container); + else + ret_value = render_bin_output_region_blocks(stream, region_space, region_id, container); + + H5Sclose(region_space); + H5Dclose(region_id); + + if (ret_value < 0) + break; } - break; - default: - for (block_index = 0; block_index < block_nelmts; block_index++) { - mem = ((unsigned char*)_mem) + block_index * size; - if (size != fwrite(mem, sizeof(char), size, stream)) { - ret_value = -1; - break; - } - } + } + else if (H5Tequal(tid, H5T_STD_REF_OBJ)) { + ; + } + + break; + } + + case H5T_NO_CLASS: + case H5T_NCLASSES: + { + ret_value = FAIL; + goto done; + break; + } + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + default: + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + if (size != fwrite(mem, sizeof(char), size, stream)) { + ret_value = FAIL; break; + } } - } /* end if((type_class = H5Tget_class(tid)) >= 0) */ - else - ret_value = -1; - } /* end if((size = H5Tget_size(tid)) > 0) */ - else - ret_value = -1; + break; + } +done: return ret_value; } /* end h5str_render_bin_output */ @@ -1930,96 +2282,107 @@ static int render_bin_output_region_data_blocks (FILE *stream, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { - hsize_t *dims1 = NULL; - hsize_t *start = NULL; - hsize_t *count = NULL; - hsize_t numelem; - hsize_t total_size[H5S_MAX_RANK]; - int jndx; - size_t type_size; - hid_t mem_space = -1; - void *region_buf = NULL; - int blkndx; - hid_t sid1 = -1; - int ret_value = SUCCEED; + hsize_t *dims1 = NULL; + hsize_t *start = NULL; + hsize_t *count = NULL; + hsize_t numelem; + hsize_t total_size[H5S_MAX_RANK]; + size_t type_size; + hid_t sid1 = H5I_INVALID_HID; + hid_t mem_space = H5I_INVALID_HID; + void *region_buf = NULL; + int blkndx; + int jndx; + int ret_value = SUCCEED; /* Get the dataspace of the dataset */ - if((sid1 = H5Dget_space(region_id)) >= 0) { - /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - /* find the dimensions of each data space from the block coordinates */ - numelem = 1; - for (jndx = 0; jndx < ndims; jndx++) { - dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1; - numelem = dims1[jndx] * numelem; - } + if ((sid1 = H5Dget_space(region_id)) < 0) { + ret_value = FAIL; + goto done; + } - /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(ndims, dims1, NULL)) >= 0) { - if((type_size = H5Tget_size(type_id)) > 0) { - if((region_buf = HDmalloc(type_size * (size_t)numelem)) != NULL) { - /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ - /* 1 2 n 1 2 n */ - if((start = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - if((count = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - for (blkndx = 0; blkndx < nblocks; blkndx++) { - for (jndx = 0; jndx < ndims; jndx++) { - start[jndx] = ptdata[jndx + blkndx * ndims * 2]; - count[jndx] = dims1[jndx]; - } - - if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) >= 0) { - if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) >= 0) { - if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) { - ret_value = h5str_render_bin_output(stream, container, type_id, (char*)region_buf, numelem); - } /* end if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) */ - else { - ret_value = -1; - break; - } - } /* end if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) >= 0) */ - else { - ret_value = -1; - break; - } - } /* end if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) >= 0) */ - else { - ret_value = -1; - break; - } - /* Render the region data element end */ - } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ - - HDfree(count); - } /* end if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - HDfree(start); - } /* end if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - HDfree(region_buf); - } /* end if((region_buf = HDmalloc(type_size * (size_t)numelem)) != NULL) */ - else - ret_value = -1; - } /* end if((type_size = H5Tget_size(type_id)) > 0) */ - else - ret_value = -1; - - if(H5Sclose(mem_space) < 0) - ret_value = -1; - } /* end if((mem_space = H5Screate_simple(ndims, dims1, NULL)) >= 0) */ - else - ret_value = -1; - HDfree(dims1); - } /* end if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - if(H5Sclose(sid1) < 0) - ret_value = -1; - } /* end if((sid1 = H5Dget_space(region_id)) >= 0) */ - else - ret_value = -1; + /* Allocate space for the dimension array */ + if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { + ret_value = FAIL; + goto done; + } + + /* Find the dimensions of each data space from the block coordinates */ + for (jndx = 0, numelem = 1; jndx < ndims; jndx++) { + dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1; + numelem = dims1[jndx] * numelem; + } + + /* Create dataspace for reading buffer */ + if ((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) { + ret_value = FAIL; + goto done; + } + + if (!(type_size = H5Tget_size(type_id))) { + ret_value = FAIL; + goto done; + } + + if (NULL == (region_buf = HDmalloc(type_size * (size_t)numelem))) { + ret_value = FAIL; + goto done; + } + + /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ + /* 1 2 n 1 2 n */ + if (NULL == (start = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { + ret_value = FAIL; + goto done; + } + + if (NULL == (count = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { + ret_value = FAIL; + goto done; + } + + for (blkndx = 0; blkndx < nblocks; blkndx++) { + for (jndx = 0; jndx < ndims; jndx++) { + start[jndx] = ptdata[jndx + blkndx * ndims * 2]; + count[jndx] = dims1[jndx]; + } + + if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) { + ret_value = FAIL; + goto done; + } + + if (H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) { + ret_value = FAIL; + goto done; + } + + if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) { + ret_value = FAIL; + goto done; + } + + if (h5str_render_bin_output(stream, container, type_id, (char *)region_buf, numelem) < 0) { + ret_value = FAIL; + goto done; + } + + /* Render the region data element end */ + } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ + +done: + if (count) + HDfree(count); + if (start) + HDfree(start); + if (region_buf) + HDfree(region_buf); + if (mem_space >= 0) + H5Sclose(mem_space); + if (dims1) + HDfree(dims1); + if (sid1 >= 0) + H5Sclose(sid1); return ret_value; } /* end render_bin_output_region_data_blocks */ @@ -2039,50 +2402,62 @@ static int render_bin_output_region_blocks (FILE *stream, hid_t region_space, hid_t region_id, hid_t container) { - int ret_value = SUCCEED; - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata = NULL; - int ndims; - hid_t dtype; - hid_t type_id; - - if((nblocks = H5Sget_select_hyper_nblocks(region_space)) > 0) { + hssize_t nblocks; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + hid_t dtype = H5I_INVALID_HID; + hid_t type_id = H5I_INVALID_HID; + int ndims; + int ret_value = SUCCEED; + + if ((nblocks = H5Sget_select_hyper_nblocks(region_space)) < 0) { + ret_value = FAIL; + goto done; + } + + if (nblocks > 0) { /* Print block information */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) >= 0) { - alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); - if((ptdata = (hsize_t*)HDmalloc((size_t)alloc_size)) != NULL) { - if(H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, (hsize_t)nblocks, ptdata) >= 0) { - if((dtype = H5Dget_type(region_id)) >= 0) { - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) { - ret_value = render_bin_output_region_data_blocks(stream, region_id, container, ndims, - type_id, nblocks, ptdata); - - if(H5Tclose(type_id) < 0) - ret_value = -1; - } /* end if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) */ - else - ret_value = -1; + if ((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) { + ret_value = FAIL; + goto done; + } - if(H5Tclose(dtype) < 0) - ret_value = -1; - } /* end if((dtype = H5Dget_type(region_id)) >= 0) */ - else - ret_value = -1; - } /* end if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) >= 0) */ - else - ret_value = -1; - - HDfree(ptdata); - } /* end if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) != NULL) */ - else - ret_value = -1; - } /* end if((ndims = H5Sget_simple_extent_ndims(region_space)) >= 0) */ - else - ret_value = -1; - } /* end if((nblocks = H5Sget_select_hyper_nblocks(region_space)) > 0) */ - else - ret_value = -1; + alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); + + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t)alloc_size))) { + ret_value = FAIL; + goto done; + } + + if (H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, (hsize_t)nblocks, ptdata) < 0) { + ret_value = FAIL; + goto done; + } + + if ((dtype = H5Dget_type(region_id)) < 0) { + ret_value = FAIL; + goto done; + } + + if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) { + ret_value = FAIL; + goto done; + } + + if (render_bin_output_region_data_blocks(stream, region_id, container, + ndims, type_id, nblocks, ptdata) < 0) { + ret_value = FAIL; + goto done; + } + } + +done: + if (type_id >= 0) + H5Tclose(type_id); + if (dtype >= 0) + H5Tclose(dtype); + if (ptdata) + HDfree(ptdata); return ret_value; } /* end render_bin_output_region_blocks */ @@ -2105,43 +2480,57 @@ render_bin_output_region_data_points { hsize_t *dims1 = NULL; size_t type_size; - hid_t mem_space = -1; + hid_t mem_space = H5I_INVALID_HID; void *region_buf = NULL; int ret_value = SUCCEED; - if((type_size = H5Tget_size(type_id)) > 0) { - if((region_buf = HDmalloc(type_size * (size_t)npoints)) != NULL) { - /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *)HDmalloc(sizeof(hsize_t) * (size_t)ndims)) != NULL) { - dims1[0] = (hsize_t)npoints; - if((mem_space = H5Screate_simple(1, dims1, NULL)) >= 0) { - if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) >= 0) { - if(H5Sget_simple_extent_dims(region_space, dims1, NULL) >= 0) { - ret_value = h5str_render_bin_output(stream, container, type_id, (char*)region_buf, (hsize_t)npoints); - } /* end if(H5Sget_simple_extent_dims(region_space, dims1, NULL) >= 0) */ - else - ret_value = -1; - } /* end if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) >= 0) */ - else - ret_value = -1; - } /* end if((mem_space = H5Screate_simple(1, dims1, NULL)) >= 0) */ - else - ret_value = -1; - - HDfree(dims1); - } /* end if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) != NULL) */ - else - ret_value = -1; - HDfree(region_buf); - } /* end if((region_buf = HDmalloc(type_size * (size_t)npoints)) != NULL) */ - else - ret_value = -1; - - if(H5Sclose(mem_space) < 0) - ret_value = -1; - } /* end if((type_size = H5Tget_size(type_id)) > 0) */ - else - ret_value = -1; + UNUSED(ptdata); + + if (!(type_size = H5Tget_size(type_id))) { + ret_value = FAIL; + goto done; + } + + if (NULL == (region_buf = HDmalloc(type_size * (size_t)npoints))) { + ret_value = FAIL; + goto done; + } + + /* Allocate space for the dimension array */ + if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { + ret_value = FAIL; + goto done; + } + + dims1[0] = (hsize_t)npoints; + + if ((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) { + ret_value = FAIL; + goto done; + } + + if (H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) { + ret_value = FAIL; + goto done; + } + + if (H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) { + ret_value = FAIL; + goto done; + } + + if (h5str_render_bin_output(stream, container, type_id, (char *)region_buf, (hsize_t)npoints) < 0) { + ret_value = FAIL; + goto done; + } + +done: + if (dims1) + HDfree(dims1); + if (mem_space >= 0) + H5Sclose(mem_space); + if (region_buf) + HDfree(region_buf); return ret_value; } /* end render_bin_output_region_data_points */ @@ -2161,248 +2550,343 @@ static int render_bin_output_region_points (FILE *stream, hid_t region_space, hid_t region_id, hid_t container) { - int ret_value = SUCCEED; - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims; - hid_t dtype; - hid_t type_id; - - if((npoints = H5Sget_select_elem_npoints(region_space)) > 0) { + hssize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + hid_t dtype = H5I_INVALID_HID; + hid_t type_id = H5I_INVALID_HID; + int ndims; + int ret_value = SUCCEED; + + if ((npoints = H5Sget_select_elem_npoints(region_space)) < 0) { + ret_value = FAIL; + goto done; + } + + if (npoints > 0) { /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) >= 0) { - alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); - if(NULL != (ptdata = (hsize_t *)HDmalloc((size_t)alloc_size))) { - if(H5Sget_select_elem_pointlist(region_space, (hsize_t)0, (hsize_t)npoints, ptdata) >= 0) { - if((dtype = H5Dget_type(region_id)) >= 0) { - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) { - ret_value = render_bin_output_region_data_points(stream, region_space, region_id, - container, ndims, type_id, npoints, ptdata); - - if(H5Tclose(type_id) < 0) - ret_value = -1; - } /* end if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) >= 0) */ - else - ret_value = -1; + if ((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) { + ret_value = FAIL; + goto done; + } - if(H5Tclose(dtype) < 0) - ret_value = -1; - } /* end if((dtype = H5Dget_type(region_id)) >= 0) */ - else - ret_value = -1; - } /* end if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) >= 0) */ - else - ret_value = -1; + alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); - HDfree(ptdata); - } /* end if(NULL != (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) */ - else - ret_value = -1; - } /* end if((ndims = H5Sget_simple_extent_ndims(region_space)) >= 0) */ - else - ret_value = -1; + if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t)alloc_size))) { + ret_value = FAIL; + goto done; + } - } /* end if((npoints = H5Sget_select_elem_npoints(region_space)) > 0) */ - else - ret_value = -1; + if (H5Sget_select_elem_pointlist(region_space, (hsize_t)0, (hsize_t)npoints, ptdata) < 0) { + ret_value = FAIL; + goto done; + } + + if ((dtype = H5Dget_type(region_id)) < 0) { + ret_value = FAIL; + goto done; + } + + if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) { + ret_value = FAIL; + goto done; + } + + if (render_bin_output_region_data_points(stream, region_space, region_id, + container, ndims, type_id, npoints, ptdata) < 0) { + ret_value = FAIL; + goto done; + } + } + +done: + if (type_id >= 0) + H5Tclose(type_id); + if (dtype >= 0) + H5Tclose(dtype); + if (ptdata) + HDfree(ptdata); return ret_value; } /* end render_bin_output_region_points */ int h5str_dump_simple_dset - (FILE *stream, hid_t dset, int binary_order) + (JNIEnv *env, FILE *stream, hid_t dset, int binary_order) { - int ret_value = SUCCEED; - hid_t f_space = -1; /* file data space */ - hsize_t elmtno; /* counter */ - size_t i; /* counter */ - int ndims; - int carry; /* counter carry value */ - hsize_t zero[8]; /* vector of zeros */ - hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/ + hsize_t elmtno; /* counter */ + hsize_t zero[8]; /* vector of zeros */ + hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/ + size_t i; /* counter */ + hid_t f_space = H5I_INVALID_HID; /* file data space */ + int ndims; + int carry; /* counter carry value */ /* Print info */ - size_t p_type_nbytes; /* size of memory type */ - hsize_t p_nelmts; /* total selected elmts */ + hsize_t p_nelmts; /* total selected elmts */ + size_t p_type_nbytes; /* size of memory type */ /* Stripmine info */ - hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ - hsize_t sm_nbytes; /* bytes per stripmine */ - hsize_t sm_nelmts; /* elements per stripmine*/ - unsigned char *sm_buf = NULL; /* buffer for raw data */ - hid_t sm_space = -1; /* stripmine data space */ + unsigned char *sm_buf = NULL; /* buffer for raw data */ + hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ + hsize_t sm_nbytes; /* bytes per stripmine */ + hsize_t sm_nelmts; /* elements per stripmine */ + hid_t sm_space = H5I_INVALID_HID; /* stripmine data space */ /* Hyperslab info */ - hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */ - hsize_t hs_size[H5S_MAX_RANK]; /* size this pass */ - hsize_t hs_nelmts; /* elements in request */ + hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */ + hsize_t hs_size[H5S_MAX_RANK]; /* size this pass */ + hsize_t hs_nelmts; /* elements in request */ /* VL data special information */ - unsigned int vl_data = 0; /* contains VL datatypes */ - hid_t p_type = -1; - hid_t f_type = -1; - - if(dset < 0) return -1; - f_type = H5Dget_type(dset); - if (binary_order == 1) - p_type = h5str_get_native_type(f_type); - else if (binary_order == 2) - p_type = h5str_get_little_endian_type(f_type); - else if (binary_order == 3) - p_type = h5str_get_big_endian_type(f_type); - else - p_type = H5Tcopy(f_type); + unsigned int vl_data = 0; /* contains VL datatypes */ + hid_t p_type = H5I_INVALID_HID; + hid_t f_type = H5I_INVALID_HID; - H5Tclose(f_type); + int ret_value = FAIL; - if (p_type >= 0) { - if((f_space = H5Dget_space(dset)) >= 0) { - ndims = H5Sget_simple_extent_ndims(f_space); + if (dset < 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_dump_simple_dset: dset ID < 0"); - if ((size_t)ndims <= (sizeof(sm_size)/sizeof(sm_size[0]))) { - H5Sget_simple_extent_dims(f_space, total_size, NULL); + if ((f_type = H5Dget_type(dset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - /* calculate the number of elements we're going to print */ - p_nelmts = 1; + switch (binary_order) { + case 1: + { + if ((p_type = h5str_get_native_type(f_type)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + case 2: + { + if ((p_type = h5str_get_little_endian_type(f_type)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + case 3: + { + if ((p_type = h5str_get_big_endian_type(f_type)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + break; + } + + default: + { + if ((p_type = H5Tcopy(f_type)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + break; + } + } - if (ndims > 0) { - for (i = 0; i < ndims; i++) - p_nelmts *= total_size[i]; - } /* end if */ + if ((f_space = H5Dget_space(dset)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (p_nelmts > 0) { - /* Check if we have VL data in the dataset's datatype */ - if (h5str_detect_vlen(p_type) != 0) - vl_data = 1; + if ((ndims = H5Sget_simple_extent_ndims(f_space)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - /* - * Determine the strip mine size and allocate a buffer. The strip mine is - * a hyperslab whose size is manageable. - */ - sm_nbytes = p_type_nbytes = H5Tget_size(p_type); + if ((size_t)ndims <= (sizeof(sm_size) / sizeof(sm_size[0]))) { + if (H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); + /* Calculate the number of elements we're going to print */ + p_nelmts = 1; + + if (ndims > 0) { + for (i = 0; i < (size_t) ndims; i++) + p_nelmts *= total_size[i]; + } /* end if */ + + if (p_nelmts > 0) { + /* Check if we have VL data in the dataset's datatype */ + if (h5str_detect_vlen(p_type) != 0) + vl_data = 1; + + /* + * Determine the strip mine size and allocate a buffer. The strip mine is + * a hyperslab whose size is manageable. + */ + if (!(sm_nbytes = p_type_nbytes = H5Tget_size(p_type))) + H5_LIBRARY_ERROR(ENVONLY); + + if (ndims > 0) { + for (i = (size_t)ndims; i > 0; --i) { + hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; + if ( size == 0 ) /* datum size > H5TOOLS_BUFSIZE */ + size = 1; + sm_size[i - 1] = (((total_size[i - 1]) < (size)) ? (total_size[i - 1]) : (size)); + sm_nbytes *= sm_size[i - 1]; + } + } + + if (sm_nbytes > 0) { + if (NULL == (sm_buf = (unsigned char *) HDmalloc((size_t)sm_nbytes))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_simple_dset: failed to allocate sm_buf"); + + sm_nelmts = sm_nbytes / p_type_nbytes; + + if ((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* The stripmine loop */ + HDmemset(hs_offset, 0, sizeof hs_offset); + HDmemset(zero, 0, sizeof zero); + + for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { + /* Calculate the hyperslab size */ if (ndims > 0) { - for (i = (size_t)ndims; i > 0; --i) { - hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; - if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */ - size = 1; - sm_size[i - 1] = (((total_size[i - 1]) < (size)) ? (total_size[i - 1]) : (size)); - sm_nbytes *= sm_size[i - 1]; + for (i = 0, hs_nelmts = 1; i < (size_t) ndims; i++) { + hs_size[i] = (((total_size[i] - hs_offset[i]) < (sm_size[i])) ? (total_size[i] - hs_offset[i]) : (sm_size[i])); + hs_nelmts *= hs_size[i]; } + + if (H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0) + H5_LIBRARY_ERROR(ENVONLY); } + else { + if (H5Sselect_all(f_space) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if(sm_nbytes > 0) { - sm_buf = (unsigned char *)HDmalloc((size_t)sm_nbytes); - - sm_nelmts = sm_nbytes / p_type_nbytes; - sm_space = H5Screate_simple(1, &sm_nelmts, NULL); - - /* The stripmine loop */ - HDmemset(hs_offset, 0, sizeof hs_offset); - HDmemset(zero, 0, sizeof zero); - - for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { - /* Calculate the hyperslab size */ - if (ndims > 0) { - for (i = 0, hs_nelmts = 1; i < ndims; i++) { - hs_size[i] = (((total_size[i] - hs_offset[i]) < (sm_size[i])) ? (total_size[i] - hs_offset[i]) : (sm_size[i])); - hs_nelmts *= hs_size[i]; - } - - H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL); - H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL); - } - else { - H5Sselect_all(f_space); - H5Sselect_all(sm_space); - hs_nelmts = 1; - } - - /* Read the data */ - if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) >= 0) { - - if (binary_order == 99) - ret_value = h5tools_dump_simple_data(stream, dset, p_type, sm_buf, hs_nelmts); - else - ret_value = h5str_render_bin_output(stream, dset, p_type, sm_buf, hs_nelmts); - - /* Reclaim any VL memory, if necessary */ - if (vl_data) - H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); - } - else { - ret_value = -1; - break; - } - - if(ret_value < 0) break; - - /* Calculate the next hyperslab offset */ - for (i = (size_t)ndims, carry = 1; i > 0 && carry; --i) { - hs_offset[i - 1] += hs_size[i - 1]; - - if (hs_offset[i - 1] == total_size[i - 1]) - hs_offset[i - 1] = 0; - else - carry = 0; - } - } + if (H5Sselect_all(sm_space) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + hs_nelmts = 1; + } - if(sm_buf) - HDfree(sm_buf); + /* Read the data */ + if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (binary_order == 99) { + if (h5tools_dump_simple_data(ENVONLY, stream, dset, p_type, sm_buf, hs_nelmts) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else { + if (h5str_render_bin_output(stream, dset, p_type, sm_buf, hs_nelmts) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + + /* Reclaim any VL memory, if necessary */ + if (vl_data) { + if (H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + + /* Calculate the next hyperslab offset */ + for (i = (size_t)ndims, carry = 1; i > 0 && carry; --i) { + hs_offset[i - 1] += hs_size[i - 1]; + + if (hs_offset[i - 1] == total_size[i - 1]) + hs_offset[i - 1] = 0; + else + carry = 0; } - if(sm_space >= 0 && H5Sclose(sm_space) < 0) - ret_value = -1; } } - if(f_space >= 0 && H5Sclose(f_space) < 0) - ret_value = -1; - } /* end if((f_space = H5Dget_space(dset)) >= 0) */ - else - ret_value = -1; - - if (p_type >= 0) - H5Tclose(p_type); + } } + + ret_value = SUCCEED; + +done: + if (sm_space >= 0) + H5Sclose(sm_space); + if (sm_buf) + HDfree(sm_buf); + if (f_space >= 0) + H5Sclose(f_space); + if (p_type >= 0) + H5Tclose(p_type); + if (f_type >= 0) + H5Tclose(f_type); + return ret_value; } /* end h5str_dump_simple_dset */ +htri_t +H5Tdetect_variable_str(hid_t tid) { + htri_t ret_val = 0; + + if (H5Tget_class(tid) == H5T_COMPOUND) { + unsigned i; + unsigned nm = (unsigned)H5Tget_nmembers(tid); + for(i = 0; i < nm; i++) { + htri_t status = 0; + hid_t mtid = 0; + if((mtid = H5Tget_member_type(tid, i)) < 0) + return FAIL; /* exit immediately on error */ + if((status = H5Tdetect_variable_str(mtid)) < 0) + return status; /* exit immediately on error */ + ret_val |= status; + H5Tclose (mtid); + } /* end for */ + } /* end if */ + else + ret_val = H5Tis_variable_str(tid); + + return ret_val; +} /* end H5Tdetect_variable_str */ + static int h5tools_dump_simple_data - (FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts) + (JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts) { - int ret_value = 0; - int line_count; - unsigned char *mem = (unsigned char*)_mem; - size_t size; /* datum size */ - hsize_t i; /*element counter */ - h5str_t buffer; /*string into which to render */ - - if((size = H5Tget_size(type)) > 0) { - for (i = 0, line_count = 0; i < nelmts; i++, line_count++) { - size_t bytes_in = 0; /* # of bytes to write */ - size_t bytes_wrote = 0; /* # of bytes written */ - void* memref = mem + i * size; - - /* Render the data element*/ - h5str_new(&buffer, 32 * size); - bytes_in = h5str_sprintf(&buffer, container, type, memref, 0, 1); - if(i > 0) { - HDfprintf(stream, ", "); - if (line_count >= H5TOOLS_TEXT_BLOCK) { - line_count = 0; - HDfprintf(stream, "\n"); - } + unsigned char *mem = (unsigned char *)_mem; + h5str_t buffer; /* string into which to render */ + hsize_t i; /* element counter */ + size_t size; /* datum size */ + int line_count; + int ret_value = 0; + + if (!(size = H5Tget_size(type))) + H5_LIBRARY_ERROR(ENVONLY); + + for (i = 0, line_count = 0; i < nelmts; i++, line_count++) { + size_t bytes_in = 0; /* # of bytes to write */ + void *memref = mem + i * size; + + /* Render the data element*/ + h5str_new(&buffer, 32 * size); + + if (!buffer.s) + H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: failed to allocate buffer"); + + if (!(bytes_in = h5str_sprintf(ENVONLY, &buffer, container, type, memref, 0, 1))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (i > 0) { + if (HDfprintf(stream, ", ") < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); + + if (line_count >= H5TOOLS_TEXT_BLOCK) { + line_count = 0; + + if (HDfprintf(stream, "\n") < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); } - HDfprintf(stream, "%s", buffer.s); - h5str_free(&buffer); - } /* end for (i = 0; i < nelmts... */ - HDfprintf(stream, "\n"); - } /* end if((size = H5Tget_size(tid)) > 0) */ - else - ret_value = -1; + } + + if (HDfprintf(stream, "%s", buffer.s) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); + + h5str_free(&buffer); + } /* end for (i = 0; i < nelmts... */ + + if (HDfprintf(stream, "\n") < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); + +done: + if (buffer.s) + h5str_free(&buffer); return ret_value; } /* end h5tools_dump_simple_data */ @@ -2421,53 +2905,68 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadComplex (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - herr_t status = -1; - int i; - int n; - char *rdata; - size_t max_len = 0; - size_t size; - h5str_t h5str; - hid_t p_type = -1; - jstring jstr; + h5str_t h5str; + jstring jstr; + size_t size; + size_t i; + hid_t p_type = H5I_INVALID_HID; + jsize n; + char *readBuf = NULL; + herr_t status = FAIL; + + UNUSED(clss); + + HDmemset(&h5str, 0, sizeof(h5str_t)); + + if ((p_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - p_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); size = (((H5Tget_size(mem_type_id))>(H5Tget_size(p_type))) ? (H5Tget_size(mem_type_id)) : (H5Tget_size(p_type))); - H5Tclose(p_type); - n = ENVPTR->GetArrayLength(ENVPAR buf); - rdata = (char *)HDmalloc((size_t)n * size); - if (rdata == NULL) { - h5JNIFatalError(env, "H5AreadComplex: failed to allocate buff for read"); - } /* end if */ - else { - status = H5Aread(attr_id, mem_type_id, rdata); - if (status < 0) { - h5JNIFatalError(env, "H5AreadComplex: failed to read data"); - } /* end if */ - else { - HDmemset(&h5str, 0, sizeof(h5str_t)); - h5str_new(&h5str, 4 * size); - if (h5str.s == NULL) { - h5JNIFatalError(env, "H5AreadComplex: failed to allocate string buf"); - } /* end if */ - else { - for (i = 0; i < n; i++) { - h5str.s[0] = '\0'; - h5str_sprintf(&h5str, attr_id, mem_type_id, rdata + ((size_t)i * size), 0, 0); - jstr = ENVPTR->NewStringUTF(ENVPAR h5str.s); - ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); - } /* end for */ - } /* end else */ - h5str_free(&h5str); - } /* end else */ - HDfree(rdata); - } /* end else */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) <= 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadComplex: read buffer length <= 0"); + } + + if (NULL == (readBuf = (char *) HDmalloc((size_t)n * size))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadComplex: failed to allocate read buffer"); + + if ((status = H5Aread(attr_id, mem_type_id, readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + h5str_new(&h5str, 4 * size); + + if (!h5str.s) + H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadComplex: failed to allocate string buffer"); + + for (i = 0; i < (size_t) n; i++) { + h5str.s[0] = '\0'; + + if (!h5str_sprintf(ENVONLY, &h5str, attr_id, mem_type_id, readBuf + (i * size), 0, 0)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, buf, (jsize) i, jstr); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, jstr); + } /* end for */ + +done: + if (h5str.s) + h5str_free(&h5str); + if (readBuf) + HDfree(readBuf); + if (p_type >= 0) + H5Tclose(p_type); + return status; } /* - * Copies the content of one dataset to another dataset + * Copies the content of one attribute to another attribute * Class: hdf_hdf5lib_H5 * Method: H5Acopy * Signature: (JJ)I @@ -2476,62 +2975,51 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Acopy (JNIEnv *env, jclass clss, jlong src_id, jlong dst_id) { - jbyte *buf; - herr_t retVal = -1; - hid_t src_did = (hid_t)src_id; - hid_t dst_did = (hid_t)dst_id; - hid_t tid = -1; - hid_t sid = -1; - hsize_t total_size = 0; - - - sid = H5Aget_space(src_did); - if (sid < 0) { - h5libraryError(env); - } /* end if */ - else { - tid = H5Aget_type(src_did); - if (tid < 0) { - H5Sclose(sid); - h5libraryError(env); - } /* end if */ - else { - total_size = (hsize_t)H5Sget_simple_extent_npoints(sid) * (hsize_t)H5Tget_size(tid); + hssize_t npoints; + hsize_t total_size = 0; + size_t type_size; + jbyte *buf = NULL; + hid_t tid = H5I_INVALID_HID; + hid_t sid = H5I_INVALID_HID; + herr_t retVal = FAIL; - H5Sclose(sid); + UNUSED(clss); - buf = (jbyte *)HDmalloc( (size_t)total_size * sizeof(jbyte)); - if (buf == NULL) { - H5Tclose(tid); - h5outOfMemory( env, "H5Acopy: malloc failed"); - } /* end if */ - else { - retVal = H5Aread(src_did, tid, buf); - H5Tclose(tid); + if ((sid = H5Aget_space((hid_t)src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retVal < 0) { - HDfree(buf); - h5libraryError(env); - } /* end if */ - else { - tid = H5Aget_type(dst_did); - if (tid < 0) { - HDfree(buf); - h5libraryError(env); - } /* end if */ - else { - retVal = H5Awrite(dst_did, tid, buf); + if ((tid = H5Aget_type((hid_t)src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - H5Tclose(tid); - HDfree(buf); + if ((npoints = H5Sget_simple_extent_npoints(sid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (!(type_size = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + total_size = (hsize_t)npoints * (hsize_t)type_size; - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + if (NULL == (buf = (jbyte *) HDmalloc((size_t)total_size * sizeof(jbyte)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Acopy: failed to allocate buffer"); + + if ((retVal = H5Aread((hid_t)src_id, tid, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (H5Tclose(tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + tid = H5I_INVALID_HID; + + if ((tid = H5Aget_type((hid_t)dst_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((retVal = H5Awrite((hid_t)dst_id, tid, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (buf) + HDfree(buf); + if (tid >= 0) + H5Tclose(tid); + if (sid >= 0) + H5Sclose(sid); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Acopy */ @@ -2546,64 +3034,54 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Dcopy (JNIEnv *env, jclass clss, jlong src_id, jlong dst_id) { - jbyte *buf; - herr_t retVal = -1; - hid_t src_did = (hid_t)src_id; - hid_t dst_did = (hid_t)dst_id; - hid_t tid = -1; - hid_t sid = -1; - hsize_t total_size = 0, total_allocated_size; - - total_allocated_size = H5Dget_storage_size(src_did); - if (total_allocated_size <=0) - return 0; // nothing to write; - - sid = H5Dget_space(src_did); - if (sid < 0) { - h5libraryError(env); - return -1; - } /* end if */ + hssize_t npoints; + hsize_t total_size = 0, total_allocated_size; + size_t type_size; + jbyte *buf = NULL; + hid_t tid = H5I_INVALID_HID; + hid_t sid = H5I_INVALID_HID; + herr_t retVal = FAIL; - tid = H5Dget_type(src_did); - if (tid < 0) { - H5Sclose(sid); - h5libraryError(env); - return -1; - } /* end if */ + UNUSED(clss); - total_size = (hsize_t)H5Sget_simple_extent_npoints(sid) * (hsize_t)H5Tget_size(tid); + if (!(total_allocated_size = H5Dget_storage_size((hid_t)src_id))) + return 0; // nothing to write - H5Sclose(sid); + if ((sid = H5Dget_space((hid_t)src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - buf = (jbyte*)HDmalloc((size_t)total_size * sizeof(jbyte)); - if (buf == NULL) { - H5Tclose(tid); - h5outOfMemory(env, "H5Dcopy: malloc failed"); - return -1; - } /* end if */ + if ((tid = H5Dget_type((hid_t)src_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - retVal = H5Dread(src_did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - H5Tclose(tid); + if ((npoints = H5Sget_simple_extent_npoints(sid)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (!(type_size = H5Tget_size(tid))) + H5_LIBRARY_ERROR(ENVONLY); + total_size = (hsize_t)npoints * (hsize_t)type_size; - if (retVal < 0) { - HDfree(buf); - h5libraryError(env); - return (jint)retVal; - } /* end if */ + if (NULL == (buf = (jbyte *) HDmalloc((size_t)total_size * sizeof(jbyte)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Dcopy: failed to allocate buffer"); - tid = H5Dget_type(dst_did); - if (tid < 0) { - HDfree(buf); - h5libraryError(env); - return -1; - } /* end if */ - retVal = H5Dwrite(dst_did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - H5Tclose(tid); - HDfree(buf); + if ((retVal = H5Dread((hid_t)src_id, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retVal < 0) { - h5libraryError(env); - } /* end if */ + if (H5Tclose(tid) < 0) + H5_LIBRARY_ERROR(ENVONLY); + tid = H5I_INVALID_HID; + + if ((tid = H5Dget_type((hid_t)dst_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((retVal = H5Dwrite((hid_t)dst_id, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (buf) + HDfree(buf); + if (tid >= 0) + H5Tclose(tid); + if (sid >= 0) + H5Sclose(sid); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Dcopy */ @@ -2613,7 +3091,7 @@ Java_hdf_hdf5lib_H5_H5Dcopy // // // Add these methods so that we don't need to call H5Gget_objtype_by_idx -// in a loop to get information for all the object in a group, which takes +// in a loop to get information for all the objects in a group, which takes // a lot of time to finish if the number of objects is more than 10,000 // ///////////////////////////////////////////////////////////////////////////////// @@ -2648,152 +3126,103 @@ typedef struct info_all * Method: H5Gget_obj_info_full * Signature: (JLjava/lang/String;[Ljava/lang/String;[I[I[J[JIII)I */ +/* + * NOTE: This is a dangerous call! The caller can supply any value they'd like + * for 'n' and if it exceeds the number of links in the group, we will most likely + * end up overwriting memory heap-tracking info. + */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1full (JNIEnv *env, jclass clss, jlong loc_id, jstring group_name, jobjectArray objName, jintArray oType, jintArray lType, jlongArray fNo, jlongArray oRef, jint n, jint indx_type, jint indx_order) { - herr_t ret_val = -1; - const char *gName = NULL; - char **oName = NULL; - jboolean isCopy; - jstring str; - jint *otarr; - jint *ltarr; - jlong *refP; - jlong *fnoP; - unsigned long *refs=NULL; - unsigned long *fnos=NULL; - hid_t gid = (hid_t)loc_id; - int i; - int indexType = indx_type; - int indexOrder = indx_order; - - if (oType == NULL) { - h5nullArgument(env, "H5Gget_obj_info_full: oType is NULL"); - } - else if (lType == NULL) { - h5nullArgument(env, "H5Gget_obj_info_full: lType is NULL"); - } - else if (oRef == NULL) { - h5nullArgument(env, "H5Gget_obj_info_full: oRef is NULL"); - } - else if (fNo == NULL) { - h5nullArgument(env, "H5Gget_obj_info_full: fNo is NULL"); + unsigned long *refs = NULL; + unsigned long *fnos = NULL; + const char *gName = NULL; + char **oName = NULL; + jboolean isCopy; + jstring str; + jint *otarr = NULL; + jint *ltarr = NULL; + jlong *refP = NULL; + jlong *fnoP = NULL; + hid_t gid = (hid_t)loc_id; + int i; + int indexType = indx_type; + int indexOrder = indx_order; + herr_t ret_val = FAIL; + + UNUSED(clss); + + if (NULL == oType) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: oType is NULL"); + if (NULL == lType) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: lType is NULL"); + if (NULL == oRef) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: oRef is NULL"); + if (NULL == fNo) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: fNo is NULL"); + + PIN_INT_ARRAY(ENVONLY, oType, otarr, &isCopy, "H5Gget_obj_info_full: oType not pinned"); + PIN_INT_ARRAY(ENVONLY, lType, ltarr, &isCopy, "H5Gget_obj_info_full: lType not pinned"); + PIN_LONG_ARRAY(ENVONLY, oRef, refP, &isCopy, "H5Gget_obj_info_full: oRef not pinned"); + PIN_LONG_ARRAY(ENVONLY, fNo, fnoP, &isCopy, "H5Gget_obj_info_full: fNo not pinned"); + + if (NULL == (oName = (char **) HDcalloc((size_t)n, sizeof(*oName)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for object name"); + + if (NULL == (refs = (unsigned long *) HDcalloc((size_t)n, sizeof(unsigned long)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for ref. info"); + + if (NULL == (fnos = (unsigned long *) HDcalloc((size_t)n, sizeof(unsigned long)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for file number info"); + + if (group_name) { + PIN_JAVA_STRING(ENVONLY, group_name, gName, &isCopy, "H5Gget_obj_info_full: group_name not pinned"); + + if ((gid = H5Gopen2((hid_t)loc_id, gName, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); } - else { - otarr = ENVPTR->GetIntArrayElements(ENVPAR oType, &isCopy); - if (otarr == NULL) { - h5JNIFatalError(env, "H5Gget_obj_info_full: otype not pinned"); - return -1; - } /* end if */ - ltarr = ENVPTR->GetIntArrayElements(ENVPAR lType, &isCopy); - if (ltarr == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_full: ltype not pinned"); - return -1; - } /* end if */ - refP = ENVPTR->GetLongArrayElements(ENVPAR oRef, &isCopy); - if (refP == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_full: oRef not pinned"); - return -1; - } /* end if */ - fnoP = ENVPTR->GetLongArrayElements(ENVPAR fNo, &isCopy); - if (fnoP == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_full: fNo not pinned"); - return -1; - } /* end if */ - oName = (char **)HDcalloc((size_t)n, sizeof(*oName)); - if (!oName) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR fNo, fnoP, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_full: oName not allocated"); - return -1; - } /* end if */ - - refs = (unsigned long *)HDcalloc((size_t)n, sizeof(unsigned long)); - fnos = (unsigned long *)HDcalloc((size_t)n, sizeof(unsigned long)); - if (!refs || !fnos) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR fNo, fnoP, JNI_ABORT); - h5str_array_free(oName, (size_t)n); - if (refs) - HDfree(refs); - if (fnos) - HDfree(fnos); - h5JNIFatalError(env, "H5Gget_obj_info_full: result arrays not allocated"); - return -1; - } /* end if */ - if (group_name != NULL) { - gid = -1; - gName = ENVPTR->GetStringUTFChars(ENVPAR group_name, &isCopy); - if (gName != NULL) { - gid = H5Gopen2((hid_t)loc_id, gName, H5P_DEFAULT); - - ENVPTR->ReleaseStringUTFChars(ENVPAR group_name, gName); - } /* end if */ - if(gid < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR fNo, fnoP, JNI_ABORT); - h5str_array_free(oName, (size_t)n); - HDfree(refs); - HDfree(fnos); - h5JNIFatalError(env, "H5Gget_obj_info_full: could not get group identifier"); - return -1; - } /* end if */ - } /* end if */ + if ((ret_val = H5Gget_obj_info_full(gid, oName, (int *)otarr, (int *)ltarr, fnos, refs, indexType, indexOrder)) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: retrieval of object info failed"); - ret_val = H5Gget_obj_info_full(gid, oName, (int *)otarr, (int *)ltarr, fnos, refs, indexType, indexOrder); + for (i = 0; i < n; i++) { + refP[i] = (jlong)refs[i]; + fnoP[i] = (jlong)fnos[i]; - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, 0); + if (oName[i]) { + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oName[i]))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (group_name != NULL) - H5Gclose(gid); + ENVPTR->SetObjectArrayElement(ENVONLY, objName, i, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (ret_val < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR fNo, fnoP, JNI_ABORT); - h5str_array_free(oName, (size_t)n); - HDfree(refs); - HDfree(fnos); - h5libraryError(env); + ENVPTR->DeleteLocalRef(ENVONLY, str); } /* end if */ - else { - for (i=0; iReleaseLongArrayElements(ENVPAR oRef, refP, 0); - - for (i=0; iReleaseLongArrayElements(ENVPAR fNo, fnoP, 0); - - for (i=0; iNewStringUTF(ENVPAR *(oName+i)); - ENVPTR->SetObjectArrayElement(ENVPAR objName, i, (jobject)str); - } /* end if */ - } /* for (i=0; iGetIntArrayElements(ENVPAR oType, &isCopy); - if (otarr == NULL) { - h5JNIFatalError(env, "H5Gget_obj_info_max: otype not pinned"); - return -1; - } /* end if */ + unsigned long *refs = NULL; + jboolean isCopy; + jstring str; + jlong *refP = NULL; + char **oName = NULL; + jint *otarr = NULL; + jint *ltarr = NULL; + int i; + herr_t ret_val = FAIL; - ltarr = ENVPTR->GetIntArrayElements(ENVPAR lType, &isCopy); - if (ltarr == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_max: ltype not pinned"); - return -1; - } /* end if */ + UNUSED(clss); - refP = ENVPTR->GetLongArrayElements(ENVPAR oRef, &isCopy); - if (refP == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_max: oRef not pinned"); - return -1; - } /* end if */ + if (NULL == oType) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: oType is NULL"); + if (NULL == lType) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: lType is NULL"); + if (NULL == oRef) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: oRef is NULL"); - oName = (char **)HDcalloc((size_t)n, sizeof(*oName)); - if (!oName) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - h5JNIFatalError(env, "H5Gget_obj_info_max: oName not allocated"); - return -1; - } /* end if */ - refs = (unsigned long *)HDcalloc((size_t)n, sizeof(unsigned long)); - if (!refs) { - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - h5str_array_free(oName, (size_t)n); - h5JNIFatalError(env, "H5Gget_obj_info_max: result array not allocated"); - return -1; - } /* end if */ + PIN_INT_ARRAY(ENVONLY, oType, otarr, &isCopy, "H5Gget_obj_info_max: oType not pinned"); + PIN_INT_ARRAY(ENVONLY, lType, ltarr, &isCopy, "H5Gget_obj_info_max: lType not pinned"); + PIN_LONG_ARRAY(ENVONLY, oRef, refP, &isCopy, "H5Gget_obj_info_max: oRef not pinned"); - ret_val = H5Gget_obj_info_max((hid_t)loc_id, oName, (int*)otarr, (int*)ltarr, refs, maxnum ); - ENVPTR->ReleaseIntArrayElements(ENVPAR lType, ltarr, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR oType, otarr, 0); + if (NULL == (oName = (char **) HDcalloc((size_t)n, sizeof(*oName)))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_max: failed to allocate buffer for object name"); - if (ret_val < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR oRef, refP, JNI_ABORT); - h5str_array_free(oName, (size_t)n); - HDfree(refs); - h5libraryError(env); - } /* end if */ - else { - for (i=0; iReleaseLongArrayElements(ENVPAR oRef, refP, 0); - - for (i=0; iNewStringUTF(ENVPAR *(oName+i)); - ENVPTR->SetObjectArrayElement(ENVPAR objName, i, (jobject)str); - } - } /* for (i=0; iNewStringUTF(ENVONLY, oName[i]))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, objName, i, (jobject)str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->DeleteLocalRef(ENVONLY, str); + } + } /* end for */ + +done: + if (refs) + HDfree(refs); + if (oName) + h5str_array_free(oName, (size_t)n); + if (refP) + UNPIN_LONG_ARRAY(ENVONLY, oRef, refP, (ret_val < 0) ? JNI_ABORT : 0); + if (ltarr) + UNPIN_INT_ARRAY(ENVONLY, lType, ltarr, (ret_val < 0) ? JNI_ABORT : 0); + if (otarr) + UNPIN_INT_ARRAY(ENVONLY, oType, otarr, (ret_val < 0) ? JNI_ABORT : 0); return ret_val; } /* end Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1max */ @@ -2902,6 +3307,7 @@ H5Gget_obj_info_full (hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *fno, unsigned long *objno, int indexType, int indexOrder) { info_all_t info; + info.objname = objname; info.otype = otype; info.ltype = ltype; @@ -2910,11 +3316,22 @@ H5Gget_obj_info_full info.objno = objno; info.count = 0; - if(H5Literate(loc_id, (H5_index_t)indexType, (H5_iter_order_t)indexOrder, NULL, obj_info_all, (void *)&info) < 0) { - /* iterate failed, try normal alphabetical order */ - if(H5Literate(loc_id, H5_INDEX_NAME, H5_ITER_INC, NULL, obj_info_all, (void *)&info) < 0) + if (H5Literate(loc_id, (H5_index_t)indexType, (H5_iter_order_t)indexOrder, NULL, obj_info_all, (void *)&info) < 0) { + /* + * Reset info stats; most importantly, reset the count. + */ + info.objname = objname; + info.otype = otype; + info.ltype = ltype; + info.idxnum = 0; + info.fno = fno; + info.objno = objno; + info.count = 0; + + /* Iteration failed, try normal alphabetical order */ + if (H5Literate(loc_id, H5_INDEX_NAME, H5_ITER_INC, NULL, obj_info_all, (void *)&info) < 0) return -1; - } /* end if */ + } return info.count; } /* end H5Gget_obj_info_full */ @@ -2924,6 +3341,7 @@ H5Gget_obj_info_max (hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *objno, long maxnum) { info_all_t info; + info.objname = objname; info.otype = otype; info.ltype = ltype; @@ -2931,7 +3349,7 @@ H5Gget_obj_info_max info.objno = objno; info.count = 0; - if(H5Lvisit(loc_id, H5_INDEX_NAME, H5_ITER_NATIVE, obj_info_max, (void *)&info) < 0) + if (H5Lvisit(loc_id, H5_INDEX_NAME, H5_ITER_NATIVE, obj_info_max, (void *)&info) < 0) return -1; return info.count; @@ -2941,75 +3359,87 @@ herr_t obj_info_all (hid_t loc_id, const char *name, const H5L_info_t *info, void *op_data) { - int type = -1; - hid_t oid = -1; - herr_t retVal = -1; - info_all_t *datainfo = (info_all_t*)op_data; + info_all_t *datainfo = (info_all_t *)op_data; H5O_info_t object_info; + htri_t object_exists; + size_t str_len; - retVal = H5Oget_info_by_name2(loc_id, name, &object_info, H5O_INFO_ALL, H5P_DEFAULT); + datainfo->otype[datainfo->count] = -1; + datainfo->ltype[datainfo->count] = -1; + datainfo->objno[datainfo->count] = (unsigned long)-1; - if (retVal < 0) { - *(datainfo->otype+datainfo->count) = -1; - *(datainfo->ltype+datainfo->count) = -1; - *(datainfo->objname+datainfo->count) = (char *)HDmalloc(HDstrlen(name)+1); - HDstrcpy(*(datainfo->objname+datainfo->count), name); - *(datainfo->objno+datainfo->count) = (unsigned long)-1; - } /* end if */ - else { - *(datainfo->otype+datainfo->count) = object_info.type; - *(datainfo->ltype+datainfo->count) = info->type; - *(datainfo->objname+datainfo->count) = (char *)HDmalloc(HDstrlen(name)+1); - HDstrcpy(*(datainfo->objname+datainfo->count), name); - - *(datainfo->fno+datainfo->count) = object_info.fileno; - *(datainfo->objno+datainfo->count) = (unsigned long)object_info.addr; - /* - if(info->type==H5L_TYPE_HARD) - *(datainfo->objno+datainfo->count) = (unsigned long)info->u.address; - else - *(datainfo->objno+datainfo->count) = info->u.val_size; - */ - } /* end else */ + str_len = HDstrlen(name); + if (NULL == (datainfo->objname[datainfo->count] = (char *) HDmalloc(str_len + 1))) + goto done; + + HDstrncpy(datainfo->objname[datainfo->count], name, str_len); + (datainfo->objname[datainfo->count])[str_len] = '\0'; + + if ((object_exists = H5Oexists_by_name(loc_id, name, H5P_DEFAULT)) < 0) + goto done; + + if (object_exists) { + if (H5Oget_info_by_name2(loc_id, name, &object_info, H5O_INFO_ALL, H5P_DEFAULT) < 0) + goto done; + + datainfo->otype[datainfo->count] = object_info.type; + datainfo->ltype[datainfo->count] = info->type; + datainfo->fno[datainfo->count] = object_info.fileno; + datainfo->objno[datainfo->count] = (unsigned long)object_info.addr; + } + + /* + if (info->type == H5L_TYPE_HARD) + datainfo->objno[datainfo->count] = (unsigned long)info->u.address; + else + datainfo->objno[datainfo->count] = info->u.val_size; + */ +done: datainfo->count++; - return 0; + return SUCCEED; } /* end obj_info_all */ herr_t obj_info_max (hid_t loc_id, const char *name, const H5L_info_t *info, void *op_data) { - int type = -1; - herr_t retVal = 0; - info_all_t *datainfo = (info_all_t*)op_data; + info_all_t *datainfo = (info_all_t *)op_data; H5O_info_t object_info; + size_t str_len; - retVal = H5Oget_info2(loc_id, &object_info, H5O_INFO_ALL); - if (retVal < 0) { - *(datainfo->otype+datainfo->count) = -1; - *(datainfo->ltype+datainfo->count) = -1; - *(datainfo->objname+datainfo->count) = NULL; - *(datainfo->objno+datainfo->count) = (unsigned long)-1; - return 1; - } /* end if */ - else { - *(datainfo->otype+datainfo->count) = object_info.type; - *(datainfo->ltype+datainfo->count) = info->type; - /* this will be freed by h5str_array_free(oName, n)*/ - *(datainfo->objname+datainfo->count) = (char *)HDmalloc(HDstrlen(name)+1); - strcpy(*(datainfo->objname+datainfo->count), name); - if(info->type==H5L_TYPE_HARD) - *(datainfo->objno+datainfo->count) = (unsigned long)info->u.address; - else - *(datainfo->objno+datainfo->count) = info->u.val_size; - } /* end else */ - datainfo->count++; - if(datainfo->count < (int)datainfo->idxnum) - return 0; + datainfo->otype[datainfo->count] = -1; + datainfo->ltype[datainfo->count] = -1; + datainfo->objname[datainfo->count] = NULL; + datainfo->objno[datainfo->count] = (unsigned long)-1; + + /* This will be freed by h5str_array_free(oName, n) */ + str_len = HDstrlen(name); + if (NULL == (datainfo->objname[datainfo->count] = (char *) HDmalloc(str_len + 1))) + goto done; + + HDstrncpy(datainfo->objname[datainfo->count], name, str_len); + (datainfo->objname[datainfo->count])[str_len] = '\0'; + + if (H5Oget_info2(loc_id, &object_info, H5O_INFO_ALL) < 0) + goto done; + + datainfo->otype[datainfo->count] = object_info.type; + datainfo->ltype[datainfo->count] = info->type; + + if (info->type == H5L_TYPE_HARD) + datainfo->objno[datainfo->count] = (unsigned long)info->u.address; else + datainfo->objno[datainfo->count] = info->u.val_size; + +done: + datainfo->count++; + + if (datainfo->count >= (int)datainfo->idxnum) return 1; + else + return SUCCEED; } /* end obj_info_max */ /* @@ -3021,68 +3451,62 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5export_1dataset (JNIEnv *env, jclass cls, jstring file_export_name, jstring file_name, jstring object_path, jint binary_order) { - herr_t status = -1; - herr_t ret_val = -1; - hid_t file_id = -1; - hid_t dataset_id = -1; + const char *file_export = NULL; + const char *object_name = NULL; + const char *fileName = NULL; + jboolean isCopy; + herr_t ret_val = FAIL; + hid_t file_id = H5I_INVALID_HID; + hid_t dataset_id = H5I_INVALID_HID; FILE *stream; - const char *file_export; - const char *object_name; - const char *fileName; - jboolean isCopy2; - if (file_export_name == NULL) { - h5nullArgument(env, "HDF5Library_export_data: file_export_name is NULL"); - } /* end if */ - else if (object_path == NULL) { - h5nullArgument(env, "HDF5Library_export_data: object_path is NULL"); - } /* end else if */ - else { - PIN_JAVA_STRING(file_name, fileName); - if (fileName != NULL) { - file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT); - - UNPIN_JAVA_STRING(file_name, fileName); - - if (file_id < 0) { - /* throw exception */ - h5libraryError(env); - } /* end if */ - else { - object_name = ENVPTR->GetStringUTFChars(ENVPAR object_path, &isCopy2); - if (object_name == NULL) { - h5JNIFatalError( env, "H5Dopen: object name not pinned"); - } /* end if */ - else { - dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT); + UNUSED(cls); - ENVPTR->ReleaseStringUTFChars(ENVPAR object_path, object_name); + if (NULL == file_export_name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_export_name is NULL"); - if (dataset_id < 0) { - H5Fclose(file_id); - h5libraryError(env); - } /* end if */ - else { - file_export = ENVPTR->GetStringUTFChars(ENVPAR file_export_name, 0); - stream = HDfopen(file_export, "w+"); - ENVPTR->ReleaseStringUTFChars(ENVPAR file_export_name, file_export); + if (NULL == file_name) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_name is NULL"); - ret_val = h5str_dump_simple_dset(stream, dataset_id, binary_order); + if (NULL == object_path) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: object_path is NULL"); - if (stream) - HDfclose(stream); + PIN_JAVA_STRING(ENVONLY, file_name, fileName, NULL, "H5export_dataset: file name not pinned"); - H5Dclose(dataset_id); + if ((file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - H5Fclose(file_id); + PIN_JAVA_STRING(ENVONLY, object_path, object_name, &isCopy, "H5export_dataset: object_path not pinned"); - if (ret_val < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ - } /* end else */ - } - } /* end else */ + if ((dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + PIN_JAVA_STRING(ENVONLY, file_export_name, file_export, NULL, "H5export_dataset: file_export name not pinned"); + + if (NULL == (stream = HDfopen(file_export, "w+"))) + H5_JNI_FATAL_ERROR(ENVONLY, "HDfopen failed"); + + if ((ret_val = h5str_dump_simple_dset(ENVONLY, stream, dataset_id, binary_order)) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_simple_dset failed"); + + if (stream) { + HDfclose(stream); + stream = NULL; + } + +done: + if (stream) + HDfclose(stream); + if (file_export) + UNPIN_JAVA_STRING(ENVONLY, file_export_name, file_export); + if (object_name) + UNPIN_JAVA_STRING(ENVONLY, object_path, object_name); + if (fileName) + UNPIN_JAVA_STRING(ENVONLY, file_name, fileName); + if (dataset_id >= 0) + H5Dclose(dataset_id); + if (file_id >= 0) + H5Fclose(file_id); } /* end Java_hdf_hdf5lib_H5_H5export_1dataset */ #ifdef __cplusplus diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index 23bc424..e5f0d0b 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -35,18 +35,29 @@ typedef struct h5str_t { size_t max; /* the allocated size of the string */ } h5str_t; -extern void h5str_new (h5str_t *str, size_t len); -extern void h5str_free (h5str_t *str); -extern void h5str_resize (h5str_t *str, size_t new_len); -extern char* h5str_append (h5str_t *str, const char* cstr); -extern size_t h5str_vlsprintf(h5str_t *str, hid_t container, hid_t tid, hvl_t *buf, int expand_data); -extern size_t h5str_sprintf(h5str_t *str, hid_t container, hid_t tid, void *buf, int ptrlen, int expand_data); -extern size_t h5str_vlsconvert(char *str, hid_t container, hid_t tid, hvl_t *buf, int expand_data); -extern size_t h5str_convert(char **str, hid_t container, hid_t tid, hvl_t *buf, int ptroffset, int expand_data); +extern void h5str_new(h5str_t *str, size_t len); +extern void h5str_free(h5str_t *str); +extern void h5str_resize(h5str_t *str, size_t new_len); +extern char* h5str_append(h5str_t *str, const char* cstr); +extern size_t h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_buf, size_t out_buf_offset); +extern size_t h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *in_buf, size_t in_buf_len, int expand_data); extern void h5str_array_free(char **strs, size_t len); -extern int h5str_dump_simple_dset(FILE *stream, hid_t dset, int binary_order); -extern int h5str_dump_region_blocks_data(h5str_t *str, hid_t region, hid_t region_obj); -extern int h5str_dump_region_points_data(h5str_t *str, hid_t region, hid_t region_obj); +extern int h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order); +extern int h5str_dump_region_blocks_data(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); +extern int h5str_dump_region_points_data(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); + +extern htri_t H5Tdetect_variable_str(hid_t tid); + +/* + * Symbols used to format the output of h5str_sprintf and + * to interpret the input to h5str_convert. + */ +#define H5_COMPOUND_BEGIN_INDICATOR "{" +#define H5_COMPOUND_END_INDICATOR "}" +#define H5_ARRAY_BEGIN_INDICATOR "[" +#define H5_ARRAY_END_INDICATOR "]" +#define H5_VLEN_BEGIN_INDICATOR "(" +#define H5_VLEN_END_INDICATOR ")" /* * Class: hdf_hdf5lib_H5 diff --git a/java/src/jni/h5vlImp.c b/java/src/jni/h5vlImp.c index 89ea703..c816abf 100644 --- a/java/src/jni/h5vlImp.c +++ b/java/src/jni/h5vlImp.c @@ -21,9 +21,9 @@ extern "C" { #endif /* __cplusplus */ -#include "hdf5.h" #include #include +#include "hdf5.h" #include "h5jni.h" #include "h5vlImp.h" @@ -36,18 +36,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5VLregister_1connector_1by_1name (JNIEnv *env, jclass clss, jobject connector_name, jlong vipl_id) { - hid_t status = -1; - const char *vlName; + const char *volName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(connector_name, vlName); - if (vlName != NULL) { - status = H5VLregister_connector_by_name(vlName, (hid_t)vipl_id); + UNUSED(clss); - UNPIN_JAVA_STRING(connector_name, vlName); + PIN_JAVA_STRING(ENVONLY, connector_name, volName, NULL, "H5VLregister_connector_by_name: VOL connector name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5VLregister_connector_by_name(volName, (hid_t)vipl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (volName) + UNPIN_JAVA_STRING(ENVONLY, connector_name, volName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5_H5VLregister_1connector_1by_1name */ @@ -61,11 +62,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5VLregister_1connector_1by_1value (JNIEnv *env, jclass clss, jint connector_value, jlong vipl_id) { - hid_t status = H5VLregister_connector_by_value((H5VL_class_value_t)connector_value, (hid_t)vipl_id); + hid_t status = H5I_INVALID_HID; + + UNUSED(clss); - if (status < 0) - h5libraryError(env); + if ((status = H5VLregister_connector_by_value((H5VL_class_value_t)connector_value, (hid_t)vipl_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jlong)status; } /* end Java_hdf_hdf5lib_H5_H5VLregister_1connector_1by_1value */ @@ -78,20 +82,21 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5VLis_1connector_1registered (JNIEnv *env, jclass clss, jobject connector_name) { + const char *volName = NULL; htri_t bval = JNI_FALSE; - const char *vlName; - PIN_JAVA_STRING(connector_name, vlName); - if (vlName != NULL) { - bval = H5VLis_connector_registered(vlName); + UNUSED(clss); - UNPIN_JAVA_STRING(connector_name, vlName); + PIN_JAVA_STRING(ENVONLY, connector_name, volName, NULL, "H5VLis_connector_registered: VOL connector name not pinned"); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); - } + if ((bval = H5VLis_connector_registered(volName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + bval = (bval > 0) ? JNI_TRUE : JNI_FALSE; + +done: + if (volName) + UNPIN_JAVA_STRING(ENVONLY, connector_name, volName); return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5VLis_1connector_1registered */ @@ -105,18 +110,19 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5VLget_1connector_1id (JNIEnv *env, jclass clss, jobject connector_name) { - hid_t status = -1; - const char *vlName; + const char *volName = NULL; + hid_t status = H5I_INVALID_HID; - PIN_JAVA_STRING(connector_name, vlName); - if (vlName != NULL) { - status = H5VLget_connector_id(vlName); + UNUSED(clss); - UNPIN_JAVA_STRING(connector_name, vlName); + PIN_JAVA_STRING(ENVONLY, connector_name, volName, NULL, "H5VLget_connector_id: VOL connector name not pinned"); - if (status < 0) - h5libraryError(env); - } + if ((status = H5VLget_connector_id(volName)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (volName) + UNPIN_JAVA_STRING(ENVONLY, connector_name, volName); return (jlong)status; } /* end Java_hdf_hdf5lib_H5_H5VLget_1connector_1id */ @@ -131,41 +137,31 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5VLget_1connector_1name (JNIEnv *env, jclass clss, jlong object_id) { - char *vlName; - ssize_t buf_size; - ssize_t status; + ssize_t buf_size, status; + char *volName = NULL; jstring str = NULL; - /* get the length of the comment */ - buf_size = H5VLget_connector_name((hid_t)object_id, NULL, 0); - if (buf_size < 0) { - H5Eprint2(H5E_DEFAULT, NULL); - - h5badArgument(env, "H5VLget_connector_name: buf_size < 0"); - } /* end if */ - else if (buf_size > 0) { - buf_size++; /* add extra space for the null terminator */ - vlName = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (vlName == NULL) { - /* exception -- out of memory */ - h5outOfMemory(env, "H5VLget_connector_name: malloc failed"); - } /* end if */ - else { - status = H5VLget_connector_name((hid_t)object_id, vlName, (size_t)buf_size); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - /* may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR vlName); - if (str == NULL) { - h5JNIFatalError(env, "H5VLget_connector_name: return string not allocated"); - } /* end if */ - } /* end else */ - HDfree(vlName); - } - } /* end else if */ + UNUSED(clss); + + /* Get the length of the comment */ + if ((buf_size = H5VLget_connector_name((hid_t)object_id, NULL, 0)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (buf_size > 0) { + if (NULL == (volName = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5VLget_connector_name: failed to allocated VOL connector name buffer"); + + if ((status = H5VLget_connector_name((hid_t)object_id, volName, (size_t)buf_size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + volName[buf_size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, volName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + +done: + if (volName) + HDfree(volName); return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5VLget_1connector_1name */ @@ -179,10 +175,15 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5VLclose (JNIEnv *env, jclass clss, jlong connector_id) { - herr_t retValue = H5VLclose((hid_t)connector_id); + herr_t retValue = FAIL; + + UNUSED(clss); + + if ((retValue = H5VLclose((hid_t)connector_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retValue < 0) - h5libraryError(env); +done: + return; } /* end Java_hdf_hdf5lib_H5_H5VLclose */ /* @@ -194,10 +195,15 @@ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5VLunregister_1connector (JNIEnv *env, jclass clss, jlong connector_id) { - herr_t retValue = H5VLunregister_connector((hid_t)connector_id); + herr_t retValue = FAIL; + + UNUSED(clss); + + if ((retValue = H5VLunregister_connector((hid_t)connector_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - if (retValue < 0) - h5libraryError(env); +done: + return; } /* end Java_hdf_hdf5lib_H5_H5VLunregister_1connector */ diff --git a/java/src/jni/h5vlImp.h b/java/src/jni/h5vlImp.h index af824a9..207efa5 100644 --- a/java/src/jni/h5vlImp.h +++ b/java/src/jni/h5vlImp.h @@ -44,7 +44,7 @@ Java_hdf_hdf5lib_H5_H5VLregister_1connector_1by_1value * Signature: (Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL -Java_hdf_hdf5lib_H5_H5VLis_connector_registered +Java_hdf_hdf5lib_H5_H5VLis_1connector_1registered (JNIEnv *, jclass, jobject); /* diff --git a/java/src/jni/h5zImp.c b/java/src/jni/h5zImp.c index a5e6cd8..a1c8517 100644 --- a/java/src/jni/h5zImp.c +++ b/java/src/jni/h5zImp.c @@ -36,12 +36,15 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Zunregister (JNIEnv *env, jclass clss, jint filter) { - herr_t retValue = H5Zunregister((H5Z_filter_t)filter); + herr_t retVal = FAIL; - if (retValue < 0) - h5libraryError(env); + UNUSED(clss); - return (jint)retValue; + if ((retVal = H5Zunregister((H5Z_filter_t)filter)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Zunregister */ /* @@ -53,12 +56,15 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Zfilter_1avail (JNIEnv *env, jclass clss, jint filter) { - herr_t retValue = H5Zfilter_avail((H5Z_filter_t)filter); + herr_t retVal = FAIL; + + UNUSED(clss); - if (retValue < 0) - h5libraryError(env); + if ((retVal = H5Zfilter_avail((H5Z_filter_t)filter)) < 0) + H5_LIBRARY_ERROR(ENVONLY); - return (jint)retValue; +done: + return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Zfilter_1avail */ /* @@ -73,9 +79,12 @@ Java_hdf_hdf5lib_H5_H5Zget_1filter_1info { unsigned int flags = 0; - if (H5Zget_filter_info ((H5Z_filter_t) filter, (unsigned *) &flags) < 0) - h5libraryError(env); + UNUSED(clss); + + if (H5Zget_filter_info((H5Z_filter_t) filter, (unsigned *) &flags) < 0) + H5_LIBRARY_ERROR(ENVONLY); +done: return (jint)flags; } /* end Java_hdf_hdf5lib_H5_H5Zget_1filter_1info */ diff --git a/java/src/jni/nativeData.c b/java/src/jni/nativeData.c index 33f4953..947f843 100644 --- a/java/src/jni/nativeData.c +++ b/java/src/jni/nativeData.c @@ -50,54 +50,49 @@ JNIEXPORT jintArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToInt___3B (JNIEnv *env, jclass clss, jbyteArray bdata) /* IN: array of bytes */ { - jbyte *barr; - jintArray rarray = NULL; - int blen; - jint *iarray; - jboolean bb; - char *bp; - jint *iap; - int ii; - int len; - - if (bdata == NULL) { - h5nullArgument( env, "byteToInt: bdata is NULL?"); - } /* end if */ - else { - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToInt: pin failed"); - } /* end if */ - else { - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - - len = blen/(int)sizeof(jint); - rarray = ENVPTR->NewIntArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToInt" ); - return NULL; - } /* end if */ - - iarray = ENVPTR->GetIntArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToInt: pin iarray failed"); - return NULL; - } /* end if */ - - bp = (char *)barr; - iap = iarray; - for (ii = 0; ii < len; ii++) { - *iap = *(jint *)bp; - iap++; - bp += sizeof(jint); - } /* end for */ - - ENVPTR->ReleaseIntArrayElements(ENVPAR rarray,iarray, 0); - } /* end else */ - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - } /* end else */ + jintArray rarray = NULL; + jboolean bb; + jbyte *barr = NULL; + jint *iarray = NULL; + jint *iap = NULL; + char *bp = NULL; + int blen; + int ii; + int len; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToInt: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToInt: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToInt: bdata length < 0"); + } + + len = blen / (int)sizeof(jint); + + if (NULL == (rarray = ENVPTR->NewIntArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_INT_ARRAY(ENVONLY, rarray, iarray, &bb, "byteToInt: int array not pinned"); + + bp = (char *)barr; + iap = iarray; + for (ii = 0; ii < len; ii++) { + *iap = *(jint *)bp; + iap++; + bp += sizeof(jint); + } /* end for */ + +done: + if (iarray) + UNPIN_INT_ARRAY(ENVONLY, rarray, iarray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); + return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToInt___3B */ @@ -106,40 +101,34 @@ JNIEXPORT jfloatArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToFloat___3B (JNIEnv *env, jclass clss, jbyteArray bdata) /* IN: array of bytes */ { - jbyte *barr; - jfloatArray rarray; - int blen; - jfloat *farray; - jboolean bb; - char *bp; - jfloat *iap; - int ii; - int len; - - if (bdata == NULL) { - h5nullArgument( env, "byteToFloat: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToFloat: pin failed"); - return NULL; - } /* end if */ - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - - len = blen/(int)sizeof(jfloat); - rarray = ENVPTR->NewFloatArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToFloat" ); - return NULL; - } /* end if */ - farray = ENVPTR->GetFloatArrayElements(ENVPAR rarray,&bb); - if (farray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToFloat: pin farray failed"); - return NULL; - } /* end if */ + jfloatArray rarray; + jboolean bb; + jfloat *farray = NULL; + jfloat *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + int len; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToFloat: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToFloat: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToFloat: bdata length < 0"); + } + + len = blen / (int)sizeof(jfloat); + + if (NULL == (rarray = ENVPTR->NewFloatArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_FLOAT_ARRAY(ENVONLY, rarray, farray, &bb, "byteToFloat: float array not pinned"); bp = (char *)barr; iap = farray; @@ -149,8 +138,11 @@ Java_hdf_hdf5lib_HDFNativeData_byteToFloat___3B bp += sizeof(jfloat); } /* end for */ - ENVPTR->ReleaseFloatArrayElements(ENVPAR rarray,farray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (farray) + UNPIN_FLOAT_ARRAY(ENVONLY, rarray, farray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToFloat___3B */ @@ -160,42 +152,34 @@ JNIEXPORT jshortArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToShort___3B (JNIEnv *env, jclass clss, jbyteArray bdata) /* IN: array of bytes */ { - jbyte *barr; - jshortArray rarray; - int blen; - jshort *sarray; - jboolean bb; - char *bp; - jshort *iap; - int ii; - int len; - - if (bdata == NULL) { - h5nullArgument( env, "byteToShort: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToShort: pin failed"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - - len = blen/(int)sizeof(jshort); - rarray = ENVPTR->NewShortArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToShort" ); - return NULL; - } /* end if */ - - sarray = ENVPTR->GetShortArrayElements(ENVPAR rarray,&bb); - if (sarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToShort: pin sarray failed"); - return NULL; - } /* end if */ + jshortArray rarray; + jboolean bb; + jshort *sarray = NULL; + jshort *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + int len; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToShort: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToShort: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToShort: bdata length < 0"); + } + + len = blen / (int)sizeof(jshort); + + if (NULL == (rarray = ENVPTR->NewShortArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_SHORT_ARRAY(ENVONLY, rarray, sarray, &bb, "byteToShort: short array not pinned"); bp = (char *)barr; iap = sarray; @@ -205,53 +189,48 @@ Java_hdf_hdf5lib_HDFNativeData_byteToShort___3B bp += sizeof(jshort); } /* end for */ - ENVPTR->ReleaseShortArrayElements(ENVPAR rarray,sarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (sarray) + UNPIN_SHORT_ARRAY(ENVONLY, rarray, sarray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToShort___3B */ - /* returns long [] */ JNIEXPORT jlongArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToLong___3B (JNIEnv *env, jclass clss, jbyteArray bdata) /* IN: array of bytes */ { - jbyte *barr; - jlongArray rarray; - int blen; - jlong *larray; - jboolean bb; - char *bp; - jlong *iap; - int ii; - int len; - - if (bdata == NULL) { - h5nullArgument( env, "byteToLong: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToLong: pin failed"); - return NULL; - } /* end if */ - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - - len = blen/(int)sizeof(jlong); - rarray = ENVPTR->NewLongArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToLong" ); - return NULL; - } /* end if */ - - larray = ENVPTR->GetLongArrayElements(ENVPAR rarray,&bb); - if (larray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToLong: pin larray failed"); - return NULL; - } /* end if */ + jlongArray rarray; + jboolean bb; + jlong *larray = NULL; + jlong *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + int len; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToLong: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToLong: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToLong: bdata length < 0"); + } + + len = blen / (int)sizeof(jlong); + + if (NULL == (rarray = ENVPTR->NewLongArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_LONG_ARRAY(ENVONLY, rarray, larray, &bb, "byteToLong: long array not pinned"); bp = (char *)barr; iap = larray; @@ -260,53 +239,49 @@ Java_hdf_hdf5lib_HDFNativeData_byteToLong___3B iap++; bp += sizeof(jlong); } /* end for */ - ENVPTR->ReleaseLongArrayElements(ENVPAR rarray,larray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); + +done: + if (larray) + UNPIN_LONG_ARRAY(ENVONLY, rarray, larray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToLong___3B */ - /* returns double [] */ JNIEXPORT jdoubleArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToDouble___3B (JNIEnv *env, jclass clss, jbyteArray bdata) /* IN: array of bytes */ { - jbyte *barr; - jdoubleArray rarray; - int blen; - jdouble *darray; - jboolean bb; - char *bp; - jdouble *iap; - int ii; - int len; - - if (bdata == NULL) { - h5nullArgument( env, "byteToDouble: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToDouble: pin failed"); - return NULL; - } /* end if */ - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - - len = blen/(int)sizeof(jdouble); - rarray = ENVPTR->NewDoubleArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToDouble" ); - return NULL; - } /* end if */ - - darray = ENVPTR->GetDoubleArrayElements(ENVPAR rarray,&bb); - if (darray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToDouble: pin darray failed"); - return NULL; - } /* end if */ + jdoubleArray rarray; + jboolean bb; + jdouble *darray = NULL; + jdouble *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + int len; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToDouble: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToDouble: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToDouble: bdata length < 0"); + } + + len = blen / (int)sizeof(jdouble); + + if (NULL == (rarray = ENVPTR->NewDoubleArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, &bb, "byteToDouble: double array not pinned"); bp = (char *)barr; iap = darray; @@ -316,59 +291,50 @@ Java_hdf_hdf5lib_HDFNativeData_byteToDouble___3B bp += sizeof(jdouble); } /* end for */ - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rarray,darray,0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (darray) + UNPIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToDouble___3B */ - /* returns int [] */ JNIEXPORT jintArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToInt__II_3B (JNIEnv *env, jclass clss, jint start, jint len, jbyteArray bdata) /* IN: array of bytes */ { - char *bp; - jbyte *barr; - jintArray rarray; - int blen; - jint *iarray; - jint *iap; - int ii; - jboolean bb; - - if (bdata == NULL) { - h5nullArgument( env, "byteToInt: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError(env, "byteToInt: pin failed"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - if ((start < 0) || ((int)(start + (len*(int)sizeof(jint))) > blen)) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToInt: getLen failed"); - return NULL; - } /* end if */ + jintArray rarray; + jboolean bb; + jint *iarray = NULL; + jint *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToInt: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToInt: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToInt: bdata length < 0"); + } + + if ((start < 0) || ((int)(start + (len * (int)sizeof(jint))) > blen)) + H5_JNI_FATAL_ERROR(ENVONLY, "byteToInt: start < 0 or len exceeded buffer length"); bp = (char *)barr + start; - rarray = ENVPTR->NewIntArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToInt" ); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewIntArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - iarray = ENVPTR->GetIntArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError(env, "byteToInt: pin iarray failed"); - return NULL; - } /* end if */ + PIN_INT_ARRAY(ENVONLY, rarray, iarray, &bb, "byteToInt: int array not pinned"); iap = iarray; for (ii = 0; ii < len; ii++) { @@ -377,8 +343,11 @@ Java_hdf_hdf5lib_HDFNativeData_byteToInt__II_3B bp += sizeof(jint); } /* end for */ - ENVPTR->ReleaseIntArrayElements(ENVPAR rarray,iarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (iarray) + UNPIN_INT_ARRAY(ENVONLY, rarray, iarray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToInt__II_3B */ @@ -388,57 +357,49 @@ JNIEXPORT jshortArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToShort__II_3B (JNIEnv *env, jclass clss, jint start, jint len, jbyteArray bdata) /* IN: array of bytes */ { - char *bp; - jbyte *barr; - jshortArray rarray; - int blen; - jshort *iarray; - jshort *iap; - int ii; - jboolean bb; - - if (bdata == NULL) { - h5nullArgument( env, "byteToShort: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError( env, "byteToShort: getByte failed?"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - if ((start < 0) || ((int)(start + (len*(int)sizeof(jshort))) > blen)) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5badArgument( env, "byteToShort: start or len is out of bounds"); - return NULL; - } /* end if */ + jshortArray rarray; + jboolean bb; + jshort *sarray = NULL; + jshort *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToShort: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToShort: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToShort: bdata length < 0"); + } + + if ((start < 0) || ((int)(start + (len * (int)sizeof(jshort))) > blen)) + H5_JNI_FATAL_ERROR(ENVONLY, "byteToShort: start < 0 or len exceeded buffer length"); bp = (char *)barr + start; - rarray = ENVPTR->NewShortArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToShort" ); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewShortArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - iarray = ENVPTR->GetShortArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError( env, "byteToShort: getShort failed?"); - return NULL; - } /* end if */ + PIN_SHORT_ARRAY(ENVONLY, rarray, sarray, &bb, "byteToShort: short array not pinned"); - iap = iarray; + iap = sarray; for (ii = 0; ii < len; ii++) { *iap = *(jshort *)bp; iap++; bp += sizeof(jshort); } /* end for */ - ENVPTR->ReleaseShortArrayElements(ENVPAR rarray,iarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (sarray) + UNPIN_SHORT_ARRAY(ENVONLY, rarray, sarray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToShort__II_3B */ @@ -448,57 +409,49 @@ JNIEXPORT jfloatArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToFloat__II_3B (JNIEnv *env, jclass clss, jint start, jint len, jbyteArray bdata) /* IN: array of bytes */ { - char *bp; - jbyte *barr; - jfloatArray rarray; - int blen; - jfloat *iarray; - jfloat *iap; - int ii; - jboolean bb; - - if (bdata == NULL) { - h5nullArgument( env, "byteToFloat: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError( env, "byteToFloat: getByte failed?"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - if ((start < 0) || ((int)(start + (len*(int)sizeof(jfloat))) > blen)) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5badArgument( env, "byteToFloat: start or len is out of bounds"); - return NULL; - } /* end if */ + jfloatArray rarray; + jboolean bb; + jfloat *farray = NULL; + jfloat *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToFloat: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToFloat: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToFloat: bdata length < 0"); + } + + if ((start < 0) || ((int)(start + (len * (int)sizeof(jfloat))) > blen)) + H5_JNI_FATAL_ERROR(ENVONLY, "byteToFloat: start < 0 or len exceeded buffer length"); bp = (char *)barr + start; - rarray = ENVPTR->NewFloatArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToFloat" ); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewFloatArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - iarray = ENVPTR->GetFloatArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError( env, "byteToFloat: getFloat failed?"); - return NULL; - } /* end if */ + PIN_FLOAT_ARRAY(ENVONLY, rarray, farray, &bb, "byteToFloat: float array not pinned"); - iap = iarray; + iap = farray; for (ii = 0; ii < len; ii++) { *iap = *(jfloat *)bp; iap++; bp += sizeof(jfloat); } /* end for */ - ENVPTR->ReleaseFloatArrayElements(ENVPAR rarray,iarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (farray) + UNPIN_FLOAT_ARRAY(ENVONLY, rarray, farray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToFloat__II_3B */ @@ -508,58 +461,49 @@ JNIEXPORT jlongArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToLong__II_3B (JNIEnv *env, jclass clss, jint start, jint len, jbyteArray bdata) /* IN: array of bytes */ { - char *bp; - jbyte *barr; - jlongArray rarray; - int blen; - jlong *iarray; - jlong *iap; - int ii; - jboolean bb; - - if (bdata == NULL) { - h5nullArgument( env, "byteToLong: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError( env, "byteToLong: getByte failed?"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - if ((start < 0) || ((int)(start + (len*(int)sizeof(jlong))) > blen)) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5badArgument( env, "byteToLong: start or len is out of bounds"); - return NULL; - } /* end if */ + jlongArray rarray; + jboolean bb; + jlong *larray = NULL; + jlong *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToLong: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToLong: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToLong: bdata length < 0"); + } + + if ((start < 0) || ((int)(start + (len * (int)sizeof(jlong))) > blen)) + H5_JNI_FATAL_ERROR(ENVONLY, "byteToLong: start < 0 or len exceeded buffer length"); bp = (char *)barr + start; - rarray = ENVPTR->NewLongArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToLong" ); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewLongArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - iarray = ENVPTR->GetLongArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError( env, "byteToLong: getLong failed?"); - return NULL; - } /* end if */ + PIN_LONG_ARRAY(ENVONLY, rarray, larray, &bb, "byteToLong: long array not pinned"); - iap = iarray; + iap = larray; for (ii = 0; ii < len; ii++) { - *iap = *(jlong *)bp; iap++; bp += sizeof(jlong); } /* end for */ - ENVPTR->ReleaseLongArrayElements(ENVPAR rarray,iarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (larray) + UNPIN_LONG_ARRAY(ENVONLY, rarray, larray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToLong__II_3B */ @@ -569,57 +513,49 @@ JNIEXPORT jdoubleArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToDouble__II_3B (JNIEnv *env, jclass clss, jint start, jint len, jbyteArray bdata) /* IN: array of bytes */ { - char *bp; - jbyte *barr; - jdoubleArray rarray; - int blen; - jdouble *iarray; - jdouble *iap; - int ii; - jboolean bb; - - if (bdata == NULL) { - h5nullArgument( env, "byteToDouble: bdata is NULL?"); - return NULL; - } /* end if */ - barr = ENVPTR->GetByteArrayElements(ENVPAR bdata,&bb); - if (barr == NULL) { - h5JNIFatalError( env, "byteToDouble: getByte failed?"); - return NULL; - } /* end if */ - - blen = ENVPTR->GetArrayLength(ENVPAR bdata); - if ((start < 0) || ((int)(start + (len*(int)sizeof(jdouble))) > blen)) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5badArgument( env, "byteToDouble: start or len is out of bounds"); - return NULL; - } /* end if */ + jdoubleArray rarray; + jboolean bb; + jdouble *darray = NULL; + jdouble *iap = NULL; + jbyte *barr = NULL; + char *bp = NULL; + int blen; + int ii; + + UNUSED(clss); + + if (NULL == bdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToDouble: byte array is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToDouble: byte array not pinned"); + + if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToDouble: bdata length < 0"); + } + + if ((start < 0) || ((int)(start + (len * (int)sizeof(jdouble))) > blen)) + H5_JNI_FATAL_ERROR(ENVONLY, "byteToDouble: start < 0 or len exceeded buffer length"); bp = (char *)barr + start; - rarray = ENVPTR->NewDoubleArray(ENVPAR len); - if (rarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5outOfMemory( env, "byteToDouble" ); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewDoubleArray(ENVONLY, len))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - iarray = ENVPTR->GetDoubleArrayElements(ENVPAR rarray,&bb); - if (iarray == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); - h5JNIFatalError( env, "byteToDouble: getDouble failed?"); - return NULL; - } /* end if */ + PIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, &bb, "byteToDouble: double array not pinned"); - iap = iarray; + iap = darray; for (ii = 0; ii < len; ii++) { *iap = *(jdouble *)bp; iap++; bp += sizeof(jdouble); } /* end for */ - ENVPTR->ReleaseDoubleArrayElements(ENVPAR rarray,iarray, 0); - ENVPTR->ReleaseByteArrayElements(ENVPAR bdata,barr,JNI_ABORT); +done: + if (darray) + UNPIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, rarray ? 0 : JNI_ABORT); + if (barr) + UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToDouble__II_3B */ @@ -629,67 +565,59 @@ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_intToByte__II_3I (JNIEnv *env, jclass clss, jint start, jint len, jintArray idata) /* IN: array of int */ { - jint *ip; - jint *iarr; - int ilen; - jbyteArray rarray; - int blen; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ii; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + jint *ip = NULL; + jint *iarr = NULL; + int ilen; + int blen; + int ii; + int ij; union things { int ival; char bytes[4]; } u; - if (idata == NULL) { - h5nullArgument( env, "intToByte: idata is NULL?"); - return NULL; - } /* end if */ + UNUSED(clss); + + if (NULL == idata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "intToByte: int array is NULL"); - iarr = ENVPTR->GetIntArrayElements(ENVPAR idata,&bb); - if (iarr == NULL) { - h5JNIFatalError( env, "intToByte: getInt failed?"); - return NULL; - } /* end if */ + PIN_INT_ARRAY(ENVONLY, idata, iarr, &bb, "intToByte: int array not pinned"); - ilen = ENVPTR->GetArrayLength(ENVPAR idata); - if ((start < 0) || (((start + len)) > ilen)) { - ENVPTR->ReleaseIntArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5badArgument( env, "intToByte: start or len is out of bounds"); - return NULL; - } /* end if */ + if ((ilen = ENVPTR->GetArrayLength(ENVONLY, idata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "intToByte: idata length < 0"); + } + + if ((start < 0) || (((start + len)) > ilen)) + H5_JNI_FATAL_ERROR(ENVONLY, "intToByte: start < 0 or len exceeded buffer length"); ip = iarr + start; blen = ilen * (int)sizeof(jint); - rarray = ENVPTR->NewByteArray(ENVPAR blen); - if (rarray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5outOfMemory( env, "intToByte" ); - return NULL; - } /* end if */ - - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5JNIFatalError( env, "intToByte: getByte failed?"); - return NULL; - } /* end if */ + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "intToByte: byte array not pinned"); bap = barray; for (ii = 0; ii < len; ii++) { u.ival = *ip++; - for (ij = 0; ij < sizeof(jint); ij++) { + for (ij = 0; (size_t) ij < sizeof(jint); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR idata,iarr,JNI_ABORT); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT); + if (iarr) + UNPIN_INT_ARRAY(ENVONLY, idata, iarr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_intToByte__II_3I */ @@ -697,68 +625,61 @@ Java_hdf_hdf5lib_HDFNativeData_intToByte__II_3I /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_shortToByte__II_3S - (JNIEnv *env, jclass clss, jint start, jint len, jshortArray idata) /* IN: array of short */ + (JNIEnv *env, jclass clss, jint start, jint len, jshortArray sdata) /* IN: array of short */ { - jshort *ip; - jshort *iarr; - int ilen; - jbyteArray rarray; - int blen; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ii; - int ij; + jbyteArray rarray; + jboolean bb; + jshort *ip = NULL; + jshort *sarr = NULL; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ilen; + int blen; + int ii; + int ij; union things { short ival; char bytes[4]; } u; - if (idata == NULL) { - h5nullArgument( env, "shortToByte: idata is NULL?"); - return NULL; - } /* end if */ - iarr = ENVPTR->GetShortArrayElements(ENVPAR idata,&bb); - if (iarr == NULL) { - h5JNIFatalError( env, "shortToByte: getShort failed?"); - return NULL; - } /* end if */ - - ilen = ENVPTR->GetArrayLength(ENVPAR idata); - if ((start < 0) || (((start + len)) > ilen)) { - ENVPTR->ReleaseShortArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5badArgument( env, "shortToByte: start or len is out of bounds"); - return NULL; - } /* end if */ + UNUSED(clss); - ip = iarr + start; + if (NULL == sdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "shortToByte: short array is NULL"); + + PIN_SHORT_ARRAY(ENVONLY, sdata, sarr, &bb, "shortToByte: short array not pinned"); + + if ((ilen = ENVPTR->GetArrayLength(ENVONLY, sdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "shortToByte: sdata length < 0"); + } + + if ((start < 0) || (((start + len)) > ilen)) + H5_JNI_FATAL_ERROR(ENVONLY, "shortToByte: start < 0 or len exceeded buffer length"); + + ip = sarr + start; blen = ilen * (int)sizeof(jshort); - rarray = ENVPTR->NewByteArray(ENVPAR blen); - if (rarray == NULL) { - ENVPTR->ReleaseShortArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5outOfMemory( env, "shortToByte" ); - return NULL; - } /* end if */ - - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - ENVPTR->ReleaseShortArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5JNIFatalError( env, "shortToByte: getByte failed?"); - return NULL; - } /* end if */ + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "shortToByte: byte array not pinned"); bap = barray; for (ii = 0; ii < len; ii++) { u.ival = *ip++; - for (ij = 0; ij < sizeof(jshort); ij++) { + for (ij = 0; (size_t) ij < sizeof(jshort); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); - ENVPTR->ReleaseShortArrayElements(ENVPAR idata,iarr,JNI_ABORT); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT); + if (sarr) + UNPIN_SHORT_ARRAY(ENVONLY, sdata, sarr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_shortToByte__II_3S */ @@ -766,68 +687,61 @@ Java_hdf_hdf5lib_HDFNativeData_shortToByte__II_3S /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_floatToByte__II_3F - (JNIEnv *env, jclass clss, jint start, jint len, jfloatArray idata) /* IN: array of float */ + (JNIEnv *env, jclass clss, jint start, jint len, jfloatArray fdata) /* IN: array of float */ { - jfloat *ip; - jfloat *iarr; - int ilen; - jbyteArray rarray; - int blen; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ii; - int ij; + jbyteArray rarray; + jboolean bb; + jfloat *ip = NULL; + jfloat *farr = NULL; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ilen; + int blen; + int ii; + int ij; union things { float ival; char bytes[4]; } u; - if (idata == NULL) { - h5nullArgument( env, "floatToByte: idata is NULL?"); - return NULL; - } /* end if */ - iarr = ENVPTR->GetFloatArrayElements(ENVPAR idata,&bb); - if (iarr == NULL) { - h5JNIFatalError( env, "floatToByte: getFloat failed?"); - return NULL; - } /* end if */ - - ilen = ENVPTR->GetArrayLength(ENVPAR idata); - if ((start < 0) || (((start + len)) > ilen)) { - ENVPTR->ReleaseFloatArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5badArgument( env, "floatToByte: start or len is out of bounds"); - return NULL; - } /* end if */ + UNUSED(clss); - ip = iarr + start; + if (NULL == fdata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "floatToByte: float array is NULL"); + + PIN_FLOAT_ARRAY(ENVONLY, fdata, farr, &bb, "floatToByte: float array not pinned"); + + if ((ilen = ENVPTR->GetArrayLength(ENVONLY, fdata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "floatToByte: fdata length < 0"); + } + + if ((start < 0) || (((start + len)) > ilen)) + H5_JNI_FATAL_ERROR(ENVONLY, "floatToByte: start < 0 or len exceeded buffer length"); + + ip = farr + start; blen = ilen * (int)sizeof(jfloat); - rarray = ENVPTR->NewByteArray(ENVPAR blen); - if (rarray == NULL) { - ENVPTR->ReleaseFloatArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5outOfMemory( env, "floatToByte" ); - return NULL; - } /* end if */ - - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - ENVPTR->ReleaseFloatArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5JNIFatalError( env, "floatToByte: getByte failed?"); - return NULL; - } /* end if */ + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "floatToByte: byte array not pinned"); bap = barray; for (ii = 0; ii < len; ii++) { u.ival = *ip++; - for (ij = 0; ij < sizeof(jfloat); ij++) { + for (ij = 0; (size_t) ij < sizeof(jfloat); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); - ENVPTR->ReleaseFloatArrayElements(ENVPAR idata,iarr,JNI_ABORT); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT); + if (farr) + UNPIN_FLOAT_ARRAY(ENVONLY, fdata, farr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_floatToByte__II_3F */ @@ -835,178 +749,159 @@ Java_hdf_hdf5lib_HDFNativeData_floatToByte__II_3F /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_doubleToByte__II_3D - (JNIEnv *env, jclass clss, jint start, jint len, jdoubleArray idata) /* IN: array of double */ + (JNIEnv *env, jclass clss, jint start, jint len, jdoubleArray ddata) /* IN: array of double */ { - jdouble *ip; - jdouble *iarr; - int ilen; - jbyteArray rarray; - int blen; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ii; - int ij; + jbyteArray rarray; + jboolean bb; + jdouble *ip = NULL; + jdouble *darr = NULL; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ilen; + int blen; + int ii; + int ij; union things { double ival; char bytes[8]; } u; - if (idata == NULL) { - h5nullArgument( env, "doubleToByte: idata is NULL?"); - return NULL; - } /* end if */ - iarr = ENVPTR->GetDoubleArrayElements(ENVPAR idata,&bb); - if (iarr == NULL) { - h5JNIFatalError( env, "doubleToByte: getDouble failed?"); - return NULL; - } /* end if */ - - ilen = ENVPTR->GetArrayLength(ENVPAR idata); - if ((start < 0) || (((start + len)) > ilen)) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5badArgument( env, "doubleToByte: start or len is out of bounds"); - return NULL; - } /* end if */ + UNUSED(clss); - ip = iarr + start; + if (NULL == ddata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "doubleToByte: double array is NULL"); + + PIN_DOUBLE_ARRAY(ENVONLY, ddata, darr, &bb, "doubleToByte: double array not pinned"); + + if ((ilen = ENVPTR->GetArrayLength(ENVONLY, ddata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "doubleToByte: ddata length < 0"); + } + + if ((start < 0) || (((start + len)) > ilen)) + H5_JNI_FATAL_ERROR(ENVONLY, "doubleToByte: start < 0 or len exceeded buffer length"); + + ip = darr + start; blen = ilen * (int)sizeof(jdouble); - rarray = ENVPTR->NewByteArray(ENVPAR blen); - if (rarray == NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5outOfMemory( env, "doubleToByte" ); - return NULL; - } /* end if */ - - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - ENVPTR->ReleaseDoubleArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5JNIFatalError( env, "doubleToByte: getByte failed?"); - return NULL; - } /* end if */ + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "doubleToByte: byte array not pinned"); bap = barray; for (ii = 0; ii < len; ii++) { u.ival = *ip++; - for (ij = 0; ij < sizeof(jdouble); ij++) { + for (ij = 0; (size_t) ij < sizeof(jdouble); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); - ENVPTR->ReleaseDoubleArrayElements(ENVPAR idata,iarr,JNI_ABORT); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT); + if (darr) + UNPIN_DOUBLE_ARRAY(ENVONLY, ddata, darr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_doubleToByte__II_3D */ - /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_longToByte__II_3J - (JNIEnv *env, jclass clss, jint start, jint len, jlongArray idata) /* IN: array of long */ + (JNIEnv *env, jclass clss, jint start, jint len, jlongArray ldata) /* IN: array of long */ { - jlong *ip; - jlong *iarr; - int ilen; - jbyteArray rarray; - int blen; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ii; - int ij; + jbyteArray rarray; + jboolean bb; + jlong *ip = NULL; + jlong *larr = NULL; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ilen; + int blen; + int ii; + int ij; union things { jlong ival; char bytes[8]; } u; - if (idata == NULL) { - h5nullArgument( env, "longToByte: idata is NULL?"); - return NULL; - } /* end if */ - iarr = ENVPTR->GetLongArrayElements(ENVPAR idata,&bb); - if (iarr == NULL) { - h5JNIFatalError( env, "longToByte: getLong failed?"); - return NULL; - } /* end if */ - - ilen = ENVPTR->GetArrayLength(ENVPAR idata); - if ((start < 0) || (((start + len)) > ilen)) { - ENVPTR->ReleaseLongArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5badArgument( env, "longToByte: start or len is out of bounds?\n"); - return NULL; - } /* end if */ + UNUSED(clss); - ip = iarr + start; + if (NULL == ldata) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "longToByte: long array is NULL"); + + PIN_LONG_ARRAY(ENVONLY, ldata, larr, &bb, "longToByte: long array not pinned"); + + if ((ilen = ENVPTR->GetArrayLength(ENVONLY, ldata)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "longToByte: ldata length < 0"); + } + + if ((start < 0) || (((start + len)) > ilen)) + H5_JNI_FATAL_ERROR(ENVONLY, "longToByte: start < 0 or len exceeded buffer length"); + + ip = larr + start; blen = ilen * (int)sizeof(jlong); - rarray = ENVPTR->NewByteArray(ENVPAR blen); - if (rarray == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5outOfMemory( env, "longToByte" ); - return NULL; - } /* end if */ - - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR idata,iarr,JNI_ABORT); - h5JNIFatalError( env, "longToByte: getByte failed?"); - return NULL; - } /* end if */ + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "longToByte: byte array not pinned"); bap = barray; for (ii = 0; ii < len; ii++) { u.ival = *ip++; - for (ij = 0; ij < sizeof(jlong); ij++) { + for (ij = 0; (size_t) ij < sizeof(jlong); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR idata,iarr,JNI_ABORT); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT); + if (larr) + UNPIN_LONG_ARRAY(ENVONLY, ldata, larr, JNI_ABORT); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_longToByte__II_3J */ - /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_intToByte__I (JNIEnv *env, jclass clss, jint idata) /* IN: int */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - int ij; - jboolean bb; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { int ival; char bytes[sizeof(int)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jint)); - if (rarray == NULL) { - h5outOfMemory( env, "intToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jint)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "intToByte: getByte failed?"); - return NULL; - } /* end if */ + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "intToByte: byte array not pinned"); bap = barray; u.ival = idata; - for (ij = 0; ij < sizeof(jint); ij++) { + for (ij = 0; (size_t) ij < sizeof(jint); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_intToByte__I */ @@ -1014,38 +909,35 @@ Java_hdf_hdf5lib_HDFNativeData_intToByte__I /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_floatToByte__F - (JNIEnv *env, jclass clss, jfloat idata) /* IN: int */ + (JNIEnv *env, jclass clss, jfloat fdata) /* IN: float */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { float ival; char bytes[sizeof(float)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jfloat)); - if (rarray == NULL) { - h5outOfMemory( env, "floatToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "floatToByte: getByte failed?"); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jfloat)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "floatToByte: byte array not pinned"); bap = barray; - u.ival = idata; - for (ij = 0; ij < sizeof(jfloat); ij++) { + u.ival = fdata; + for (ij = 0; (size_t) ij < sizeof(jfloat); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,(jbyte *)barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_floatToByte__F */ @@ -1053,118 +945,107 @@ Java_hdf_hdf5lib_HDFNativeData_floatToByte__F /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_shortToByte__S - (JNIEnv *env, jclass clss, jshort idata) /* IN: short */ + (JNIEnv *env, jclass clss, jshort sdata) /* IN: short */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { short ival; char bytes[sizeof(short)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jshort)); - if (rarray == NULL) { - h5outOfMemory( env, "shortToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "shortToByte: getShort failed?"); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jshort)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "shortToByte: byte array not pinned"); bap = barray; - u.ival = idata; - for (ij = 0; ij < sizeof(jshort); ij++) { + u.ival = sdata; + for (ij = 0; (size_t) ij < sizeof(jshort); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,(jbyte *)barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_shortToByte__S */ - /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_doubleToByte__D - (JNIEnv *env, jclass clss, jdouble idata) /* IN: double */ + (JNIEnv *env, jclass clss, jdouble ddata) /* IN: double */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { double ival; char bytes[sizeof(double)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jdouble)); - if (rarray == NULL) { - h5outOfMemory( env, "doubleToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); + + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jdouble)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "doubleToByte: getDouble failed?"); - return NULL; - } /* end if */ + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "doubleToByte: byte array not pinned"); bap = barray; - u.ival = idata; - for (ij = 0; ij < sizeof(jdouble); ij++) { + u.ival = ddata; + for (ij = 0; (size_t) ij < sizeof(jdouble); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,(jbyte *)barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_doubleToByte__D */ - /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_longToByte__J - (JNIEnv *env, jclass clss, jlong idata) /* IN: array of long */ + (JNIEnv *env, jclass clss, jlong ldata) /* IN: long */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { jlong ival; char bytes[sizeof(jlong)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jlong)); - if (rarray == NULL) { - h5outOfMemory( env, "longToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "longToByte: getLong failed?"); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jlong)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "longToByte: byte array not pinned"); bap = barray; - u.ival = idata; - for (ij = 0; ij < sizeof(jlong); ij++) { + u.ival = ldata; + for (ij = 0; (size_t) ij < sizeof(jlong); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,(jbyte *)barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_longToByte__J */ @@ -1172,38 +1053,35 @@ Java_hdf_hdf5lib_HDFNativeData_longToByte__J /* returns byte [] */ JNIEXPORT jbyteArray JNICALL Java_hdf_hdf5lib_HDFNativeData_byteToByte__B - (JNIEnv *env, jclass clss, jbyte idata) /* IN: array of long */ + (JNIEnv *env, jclass clss, jbyte bdata) /* IN: byte */ { - jbyteArray rarray; - jbyte *barray; - jbyte *bap; - jboolean bb; - int ij; + jbyteArray rarray; + jboolean bb; + jbyte *barray = NULL; + jbyte *bap = NULL; + int ij; union things { jbyte ival; char bytes[sizeof(jbyte)]; } u; - rarray = ENVPTR->NewByteArray(ENVPAR sizeof(jbyte)); - if (rarray == NULL) { - h5outOfMemory( env, "byteToByte" ); - return NULL; - } /* end if */ + UNUSED(clss); - barray = ENVPTR->GetByteArrayElements(ENVPAR rarray,&bb); - if (barray == NULL) { - h5JNIFatalError( env, "byteToByte: getByte failed?"); - return NULL; - } /* end if */ + if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jbyte)))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "byteToByte: byte array not pinned"); bap = barray; - u.ival = idata; - for (ij = 0; ij < sizeof(jbyte); ij++) { + u.ival = bdata; + for (ij = 0; (size_t) ij < sizeof(jbyte); ij++) { *bap = u.bytes[ij]; bap++; } /* end for */ - ENVPTR->ReleaseByteArrayElements(ENVPAR rarray,(jbyte *)barray, 0); +done: + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0); return rarray; } /* end Java_hdf_hdf5lib_HDFNativeData_byteToByte__B */ diff --git a/java/test/TestH5.java b/java/test/TestH5.java index 54603ca..c59101b 100644 --- a/java/test/TestH5.java +++ b/java/test/TestH5.java @@ -177,6 +177,23 @@ public class TestH5 { for (int i = 0; i < 2; i++) assertFalse(libversion[i] == 0); } + + /** + * Test method for {@link hdf.hdf5lib.H5#H5get_libversion(int[])} + * to ensure a null libversion parameter causes the function to + * fail. + */ + @Test + public void testH5get_libversion_null_param() { + try { + H5.H5get_libversion(null); + } + catch (Throwable err) { + return; + } + + fail("H5.H5get_libversion: succeeded with a null libversion parameter!"); + } /** * Test method for diff --git a/java/test/testfiles/JUnit-TestH5.txt b/java/test/testfiles/JUnit-TestH5.txt index 37c5b65..b282a91 100644 --- a/java/test/testfiles/JUnit-TestH5.txt +++ b/java/test/testfiles/JUnit-TestH5.txt @@ -1,4 +1,5 @@ JUnit version 4.11 +.testH5get_libversion_null_param .testJ2C .testIsSerializable .testH5garbage_collect @@ -11,5 +12,5 @@ JUnit version 4.11 Time: XXXX -OK (9 tests) +OK (10 tests) diff --git a/src/H5Torder.c b/src/H5Torder.c index d687d03..62662d6 100644 --- a/src/H5Torder.c +++ b/src/H5Torder.c @@ -100,11 +100,11 @@ H5Tget_order(hid_t type_id) /* Check args */ if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5T_ORDER_ERROR, "not a datatype") + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, H5T_ORDER_ERROR, "not a datatype") /* Get order */ if(H5T_ORDER_ERROR == (ret_value = H5T_get_order(dt))) - HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, H5T_ORDER_ERROR, "cant't get order for specified datatype") + HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, H5T_ORDER_ERROR, "can't get order for specified datatype") done: FUNC_LEAVE_API(ret_value) -- cgit v0.12 From d98faf57030a2843511047fa701acf379569a2d6 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 11:09:43 -0600 Subject: Rename parallel tests to start with PAR_ --- examples/CMakeTests.cmake | 4 ++-- fortran/examples/CMakeTests.cmake | 4 ++-- fortran/testpar/CMakeTests.cmake | 2 +- testpar/CMakeTests.cmake | 10 +++++----- testpar/CMakeVFDTests.cmake | 2 +- tools/test/h5diff/CMakeTests.cmake | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/CMakeTests.cmake b/examples/CMakeTests.cmake index dd1e03b..9fc12eb 100644 --- a/examples/CMakeTests.cmake +++ b/examples/CMakeTests.cmake @@ -181,9 +181,9 @@ ### Windows pops up a modal permission dialog on this test if (H5_HAVE_PARALLEL AND NOT WIN32) if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME EXAMPLES_PAR-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_EXAMPLES-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) else () - add_test (NAME EXAMPLES_PAR-ph5example COMMAND "${CMAKE_COMMAND}" + add_test (NAME PAR_EXAMPLES-ph5example COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${MPIEXEC_MAX_NUMPROCS};${MPIEXEC_PREFLAGS};$;${MPIEXEC_POSTFLAGS}" -D "TEST_ARGS:STRING=" -D "TEST_EXPECT=0" diff --git a/fortran/examples/CMakeTests.cmake b/fortran/examples/CMakeTests.cmake index 323cf91..3dd5d6a 100644 --- a/fortran/examples/CMakeTests.cmake +++ b/fortran/examples/CMakeTests.cmake @@ -151,8 +151,8 @@ foreach (example ${F2003_examples}) endforeach () if (H5_HAVE_PARALLEL AND MPI_Fortran_FOUND) - add_test (NAME f90_ex_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_f90_ex_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) if (BUILD_SHARED_LIBS) - add_test (NAME f90_ex-shared_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_f90_ex-shared_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endif () endif () diff --git a/fortran/testpar/CMakeTests.cmake b/fortran/testpar/CMakeTests.cmake index d00a6fc..12fd13b 100644 --- a/fortran/testpar/CMakeTests.cmake +++ b/fortran/testpar/CMakeTests.cmake @@ -15,4 +15,4 @@ ### T E S T I N G ### ############################################################################## ############################################################################## -add_test (NAME FORT_parallel_test COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) +add_test (NAME PAR_FORT_parallel_test COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index a0d7f59..a7c606d 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -16,16 +16,16 @@ ############################################################################## ############################################################################## -add_test (NAME TEST_PAR_testphdf5 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) +add_test (NAME PAR_TEST_testphdf5 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) foreach (testp ${H5P_TESTS}) - add_test (NAME TEST_PAR_${testp} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME PAR_TEST_${testp} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endforeach () # The t_pflush1 test is hard-coded to fail. -set_tests_properties (TEST_PAR_t_pflush1 PROPERTIES WILL_FAIL "true") -#set_property (TEST TEST_PAR_t_pflush1 PROPERTY PASS_REGULAR_EXPRESSION "PASSED") -set_tests_properties (TEST_PAR_t_pflush2 PROPERTIES DEPENDS TEST_PAR_t_pflush1) +set_tests_properties (PAR_TEST_t_pflush1 PROPERTIES WILL_FAIL "true") +#set_property (TEST PAR_TEST_t_pflush1 PROPERTY PASS_REGULAR_EXPRESSION "PASSED") +set_tests_properties (PAR_TEST_t_pflush2 PROPERTIES DEPENDS PAR_TEST_t_pflush1) ############################################################################## ############################################################################## diff --git a/testpar/CMakeVFDTests.cmake b/testpar/CMakeVFDTests.cmake index b6b065f..ed6c898 100644 --- a/testpar/CMakeVFDTests.cmake +++ b/testpar/CMakeVFDTests.cmake @@ -37,7 +37,7 @@ if (NOT HDF5_ENABLE_USING_MEMCHECKER) foreach (test ${H5P_VFD_TESTS}) add_test ( - NAME TEST_PAR_VFD-${vfdname}-${test} + NAME PAR_TEST_VFD-${vfdname}-${test} COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=$" -D "TEST_ARGS:STRING=" diff --git a/tools/test/h5diff/CMakeTests.cmake b/tools/test/h5diff/CMakeTests.cmake index 24646b0..fc0018b 100644 --- a/tools/test/h5diff/CMakeTests.cmake +++ b/tools/test/h5diff/CMakeTests.cmake @@ -394,7 +394,7 @@ macro (ADD_PH5_TEST resultfile resultcode) # If using memchecker add tests without using scripts if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME PH5DIFF-${resultfile} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} ${ARGN}) + add_test (NAME PAR_H5DIFF-${resultfile} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} ${ARGN}) set_tests_properties (PH5DIFF-${resultfile} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/PAR/testfiles") if (NOT "${resultcode}" STREQUAL "0") set_tests_properties (PH5DIFF-${resultfile} PROPERTIES WILL_FAIL "true") -- cgit v0.12 From edcbc9966f5c742970ad32eb50a7925fcf7ab677 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 12:01:25 -0600 Subject: Refactor parallel test names --- bin/batch/cori_ctestP.sl.in.cmake | 2 +- bin/batch/cori_ctestS.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestP.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestS.sl.in.cmake | 2 +- bin/batch/ctestP.sl.in.cmake | 2 +- bin/batch/ctestS.sl.in.cmake | 2 +- bin/batch/knl_ctestP.sl.in.cmake | 2 +- bin/batch/knl_ctestS.sl.in.cmake | 2 +- bin/batch/ray_ctestP.lsf.in.cmake | 2 +- bin/batch/ray_ctestS.lsf.in.cmake | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/batch/cori_ctestP.sl.in.cmake b/bin/batch/cori_ctestP.sl.in.cmake index 6aa4916..af43410 100644 --- a/bin/batch/cori_ctestP.sl.in.cmake +++ b/bin/batch/cori_ctestP.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" +CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/cori_ctestS.sl.in.cmake b/bin/batch/cori_ctestS.sl.in.cmake index cf68826..be9267a 100644 --- a/bin/batch/cori_ctestS.sl.in.cmake +++ b/bin/batch/cori_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E PAR_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/cori_knl_ctestP.sl.in.cmake b/bin/batch/cori_knl_ctestP.sl.in.cmake index 90dd52a..38fa81d 100644 --- a/bin/batch/cori_knl_ctestP.sl.in.cmake +++ b/bin/batch/cori_knl_ctestP.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" +CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/cori_knl_ctestS.sl.in.cmake b/bin/batch/cori_knl_ctestS.sl.in.cmake index 7db4483..5474672 100644 --- a/bin/batch/cori_knl_ctestS.sl.in.cmake +++ b/bin/batch/cori_knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E PAR_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ctestP.sl.in.cmake b/bin/batch/ctestP.sl.in.cmake index 9fed14d..eadf336 100644 --- a/bin/batch/ctestP.sl.in.cmake +++ b/bin/batch/ctestP.sl.in.cmake @@ -8,7 +8,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" +CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/ctestS.sl.in.cmake b/bin/batch/ctestS.sl.in.cmake index 98c1bcd..6f97d2b 100644 --- a/bin/batch/ctestS.sl.in.cmake +++ b/bin/batch/ctestS.sl.in.cmake @@ -8,7 +8,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E PAR_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/knl_ctestP.sl.in.cmake b/bin/batch/knl_ctestP.sl.in.cmake index 5c7c83f..3e5cbe5 100644 --- a/bin/batch/knl_ctestP.sl.in.cmake +++ b/bin/batch/knl_ctestP.sl.in.cmake @@ -10,7 +10,7 @@ cd @HDF5_BINARY_DIR@ #run parallel tests except t_cache_image test -CMD="ctest . -R TEST_PAR|PH5DIFF|PERFORM|ph5example -E t_cache_image -C Release -T test" +CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/knl_ctestS.sl.in.cmake b/bin/batch/knl_ctestS.sl.in.cmake index 0dae31f..d099666 100644 --- a/bin/batch/knl_ctestS.sl.in.cmake +++ b/bin/batch/knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E TEST_PAR|PH5DIFF|PERFORM|ph5example -C Release -j 32 -T test" +CMD="ctest . -E PAR_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ray_ctestP.lsf.in.cmake b/bin/batch/ray_ctestP.lsf.in.cmake index 6b5316a..8ffaf8c 100644 --- a/bin/batch/ray_ctestP.lsf.in.cmake +++ b/bin/batch/ray_ctestP.lsf.in.cmake @@ -15,6 +15,6 @@ cd @HDF5_BINARY_DIR@ echo "Run parallel test command. Test output will be in build/ctestP.out" -ctest . -R 'TEST_PAR|PH5DIFF|PERFORM|ph5example' -E t_cache_image -C Release -T test >& ctestP.out +ctest . -R 'PAR_' -E t_cache_image -C Release -T test >& ctestP.out echo "Done running ctest parallel command." diff --git a/bin/batch/ray_ctestS.lsf.in.cmake b/bin/batch/ray_ctestS.lsf.in.cmake index d23a513..5bd5c83 100644 --- a/bin/batch/ray_ctestS.lsf.in.cmake +++ b/bin/batch/ray_ctestS.lsf.in.cmake @@ -11,7 +11,7 @@ cd @HDF5_BINARY_DIR@ echo "Run command. Test output will be in build/ctestS.out" -ctest . -E 'TEST_PAR|PH5DIFF|PERFORM|ph5example' -C Release -j 32 -T test >& ctestS.out +ctest . -E 'PAR_' -C Release -j 32 -T test >& ctestS.out ##$CMD >& ctestS.out echo "Done running command." -- cgit v0.12 From 6f71b2cdcf3326b1d7bc67cf664b56d2f4056bfd Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 11 Feb 2019 12:42:19 -0600 Subject: Refactor mpi test names --- bin/batch/cori_ctestP.sl.in.cmake | 2 +- bin/batch/cori_ctestS.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestP.sl.in.cmake | 2 +- bin/batch/cori_knl_ctestS.sl.in.cmake | 2 +- bin/batch/ctestP.sl.in.cmake | 2 +- bin/batch/ctestS.sl.in.cmake | 2 +- bin/batch/knl_ctestP.sl.in.cmake | 2 +- bin/batch/knl_ctestS.sl.in.cmake | 2 +- bin/batch/ray_ctestP.lsf.in.cmake | 2 +- bin/batch/ray_ctestS.lsf.in.cmake | 2 +- examples/CMakeTests.cmake | 18 +++++++++--------- fortran/examples/CMakeTests.cmake | 4 ++-- fortran/testpar/CMakeTests.cmake | 2 +- testpar/CMakeTests.cmake | 10 +++++----- testpar/CMakeVFDTests.cmake | 2 +- tools/test/h5diff/CMakeTests.cmake | 16 ++++++++-------- tools/test/perform/CMakeTests.cmake | 4 ++-- 17 files changed, 38 insertions(+), 38 deletions(-) diff --git a/bin/batch/cori_ctestP.sl.in.cmake b/bin/batch/cori_ctestP.sl.in.cmake index af43410..287fe3c 100644 --- a/bin/batch/cori_ctestP.sl.in.cmake +++ b/bin/batch/cori_ctestP.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" +CMD="ctest . -R MPI_TEST_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/cori_ctestS.sl.in.cmake b/bin/batch/cori_ctestS.sl.in.cmake index be9267a..50bef6b 100644 --- a/bin/batch/cori_ctestS.sl.in.cmake +++ b/bin/batch/cori_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E PAR_ -C Release -j 32 -T test" +CMD="ctest . -E MPI_TEST_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/cori_knl_ctestP.sl.in.cmake b/bin/batch/cori_knl_ctestP.sl.in.cmake index 38fa81d..82378ec 100644 --- a/bin/batch/cori_knl_ctestP.sl.in.cmake +++ b/bin/batch/cori_knl_ctestP.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" +CMD="ctest . -R MPI_TEST_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/cori_knl_ctestS.sl.in.cmake b/bin/batch/cori_knl_ctestS.sl.in.cmake index 5474672..bcb4881 100644 --- a/bin/batch/cori_knl_ctestS.sl.in.cmake +++ b/bin/batch/cori_knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E PAR_ -C Release -j 32 -T test" +CMD="ctest . -E MPI_TEST_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ctestP.sl.in.cmake b/bin/batch/ctestP.sl.in.cmake index eadf336..8d216d6 100644 --- a/bin/batch/ctestP.sl.in.cmake +++ b/bin/batch/ctestP.sl.in.cmake @@ -8,7 +8,7 @@ #SBATCH --job-name=h5_ctestP cd @HDF5_BINARY_DIR@ -CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" +CMD="ctest . -R MPI_TEST_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/ctestS.sl.in.cmake b/bin/batch/ctestS.sl.in.cmake index 6f97d2b..4f96bb9 100644 --- a/bin/batch/ctestS.sl.in.cmake +++ b/bin/batch/ctestS.sl.in.cmake @@ -8,7 +8,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E PAR_ -C Release -j 32 -T test" +CMD="ctest . -E MPI_TEST_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/knl_ctestP.sl.in.cmake b/bin/batch/knl_ctestP.sl.in.cmake index 3e5cbe5..79dfb89 100644 --- a/bin/batch/knl_ctestP.sl.in.cmake +++ b/bin/batch/knl_ctestP.sl.in.cmake @@ -10,7 +10,7 @@ cd @HDF5_BINARY_DIR@ #run parallel tests except t_cache_image test -CMD="ctest . -R PAR_ -E t_cache_image -C Release -T test" +CMD="ctest . -R MPI_TEST_ -E t_cache_image -C Release -T test" echo "Run $CMD. Test output will be in build/ctestP.out" $CMD >& ctestP.out diff --git a/bin/batch/knl_ctestS.sl.in.cmake b/bin/batch/knl_ctestS.sl.in.cmake index d099666..af6353b 100644 --- a/bin/batch/knl_ctestS.sl.in.cmake +++ b/bin/batch/knl_ctestS.sl.in.cmake @@ -9,7 +9,7 @@ #SBATCH --job-name=h5_ctestS cd @HDF5_BINARY_DIR@ -CMD="ctest . -E PAR_ -C Release -j 32 -T test" +CMD="ctest . -E MPI_TEST_ -C Release -j 32 -T test" echo "Run $CMD. Test output will be in build/ctestS.out" $CMD >& ctestS.out diff --git a/bin/batch/ray_ctestP.lsf.in.cmake b/bin/batch/ray_ctestP.lsf.in.cmake index 8ffaf8c..082276a 100644 --- a/bin/batch/ray_ctestP.lsf.in.cmake +++ b/bin/batch/ray_ctestP.lsf.in.cmake @@ -15,6 +15,6 @@ cd @HDF5_BINARY_DIR@ echo "Run parallel test command. Test output will be in build/ctestP.out" -ctest . -R 'PAR_' -E t_cache_image -C Release -T test >& ctestP.out +ctest . -R 'MPI_TEST_' -E t_cache_image -C Release -T test >& ctestP.out echo "Done running ctest parallel command." diff --git a/bin/batch/ray_ctestS.lsf.in.cmake b/bin/batch/ray_ctestS.lsf.in.cmake index 5bd5c83..da20438 100644 --- a/bin/batch/ray_ctestS.lsf.in.cmake +++ b/bin/batch/ray_ctestS.lsf.in.cmake @@ -11,7 +11,7 @@ cd @HDF5_BINARY_DIR@ echo "Run command. Test output will be in build/ctestS.out" -ctest . -E 'PAR_' -C Release -j 32 -T test >& ctestS.out +ctest . -E 'MPI_TEST_' -C Release -j 32 -T test >& ctestS.out ##$CMD >& ctestS.out echo "Done running command." diff --git a/examples/CMakeTests.cmake b/examples/CMakeTests.cmake index 9fc12eb..cb47c78 100644 --- a/examples/CMakeTests.cmake +++ b/examples/CMakeTests.cmake @@ -181,9 +181,9 @@ ### Windows pops up a modal permission dialog on this test if (H5_HAVE_PARALLEL AND NOT WIN32) if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME PAR_EXAMPLES-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_EXAMPLES-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) else () - add_test (NAME PAR_EXAMPLES-ph5example COMMAND "${CMAKE_COMMAND}" + add_test (NAME MPI_TEST_EXAMPLES-ph5example COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${MPIEXEC_MAX_NUMPROCS};${MPIEXEC_PREFLAGS};$;${MPIEXEC_POSTFLAGS}" -D "TEST_ARGS:STRING=" -D "TEST_EXPECT=0" @@ -195,14 +195,14 @@ ) endif () if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES_PAR-ph5example PROPERTIES DEPENDS ${last_test}) + set_tests_properties (MPI_TEST_EXAMPLES-ph5example PROPERTIES DEPENDS ${last_test}) endif () - set (last_test "EXAMPLES_PAR-ph5example") + set (last_test "MPI_TEST_EXAMPLES-ph5example") if (BUILD_SHARED_LIBS) if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME EXAMPLES_PAR-shared-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_EXAMPLES-shared-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) else () - add_test (NAME EXAMPLES_PAR-shared-ph5example COMMAND "${CMAKE_COMMAND}" + add_test (NAME MPI_TEST_EXAMPLES-shared-ph5example COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${MPIEXEC_MAX_NUMPROCS};${MPIEXEC_PREFLAGS};$;${MPIEXEC_POSTFLAGS}" -D "TEST_ARGS:STRING=" -D "TEST_EXPECT=0" @@ -213,10 +213,10 @@ -P "${HDF_RESOURCES_EXT_DIR}/grepTest.cmake" ) endif () - set_tests_properties (EXAMPLES_PAR-shared-ph5example PROPERTIES WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/H5EX-shared) + set_tests_properties (MPI_TEST_EXAMPLES-shared-ph5example PROPERTIES WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/H5EX-shared) if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES_PAR-shared-ph5example PROPERTIES DEPENDS ${last_test}) + set_tests_properties (MPI_TEST_EXAMPLES-shared-ph5example PROPERTIES DEPENDS ${last_test}) endif () - set (last_test "EXAMPLES_PAR-shared-ph5example") + set (last_test "MPI_TEST_EXAMPLES-shared-ph5example") endif () endif () diff --git a/fortran/examples/CMakeTests.cmake b/fortran/examples/CMakeTests.cmake index 3dd5d6a..face086 100644 --- a/fortran/examples/CMakeTests.cmake +++ b/fortran/examples/CMakeTests.cmake @@ -151,8 +151,8 @@ foreach (example ${F2003_examples}) endforeach () if (H5_HAVE_PARALLEL AND MPI_Fortran_FOUND) - add_test (NAME PAR_f90_ex_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_f90_ex_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) if (BUILD_SHARED_LIBS) - add_test (NAME PAR_f90_ex-shared_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_f90_ex-shared_ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endif () endif () diff --git a/fortran/testpar/CMakeTests.cmake b/fortran/testpar/CMakeTests.cmake index 12fd13b..d0abe0e 100644 --- a/fortran/testpar/CMakeTests.cmake +++ b/fortran/testpar/CMakeTests.cmake @@ -15,4 +15,4 @@ ### T E S T I N G ### ############################################################################## ############################################################################## -add_test (NAME PAR_FORT_parallel_test COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) +add_test (NAME MPI_TEST_FORT_parallel_test COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index a7c606d..b71e7bc 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -16,16 +16,16 @@ ############################################################################## ############################################################################## -add_test (NAME PAR_TEST_testphdf5 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) +add_test (NAME MPI_TEST_testphdf5 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) foreach (testp ${H5P_TESTS}) - add_test (NAME PAR_TEST_${testp} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_${testp} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endforeach () # The t_pflush1 test is hard-coded to fail. -set_tests_properties (PAR_TEST_t_pflush1 PROPERTIES WILL_FAIL "true") -#set_property (TEST PAR_TEST_t_pflush1 PROPERTY PASS_REGULAR_EXPRESSION "PASSED") -set_tests_properties (PAR_TEST_t_pflush2 PROPERTIES DEPENDS PAR_TEST_t_pflush1) +set_tests_properties (MPI_TEST_t_pflush1 PROPERTIES WILL_FAIL "true") +#set_property (TEST MPI_TEST_t_pflush1 PROPERTY PASS_REGULAR_EXPRESSION "PASSED") +set_tests_properties (MPI_TEST_t_pflush2 PROPERTIES DEPENDS MPI_TEST_t_pflush1) ############################################################################## ############################################################################## diff --git a/testpar/CMakeVFDTests.cmake b/testpar/CMakeVFDTests.cmake index ed6c898..e2bf88a 100644 --- a/testpar/CMakeVFDTests.cmake +++ b/testpar/CMakeVFDTests.cmake @@ -37,7 +37,7 @@ if (NOT HDF5_ENABLE_USING_MEMCHECKER) foreach (test ${H5P_VFD_TESTS}) add_test ( - NAME PAR_TEST_VFD-${vfdname}-${test} + NAME MPI_TEST_VFD-${vfdname}-${test} COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=$" -D "TEST_ARGS:STRING=" diff --git a/tools/test/h5diff/CMakeTests.cmake b/tools/test/h5diff/CMakeTests.cmake index fc0018b..1376e0d 100644 --- a/tools/test/h5diff/CMakeTests.cmake +++ b/tools/test/h5diff/CMakeTests.cmake @@ -394,28 +394,28 @@ macro (ADD_PH5_TEST resultfile resultcode) # If using memchecker add tests without using scripts if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME PAR_H5DIFF-${resultfile} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} ${ARGN}) - set_tests_properties (PH5DIFF-${resultfile} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/PAR/testfiles") + add_test (NAME MPI_TEST_H5DIFF-${resultfile} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} ${ARGN}) + set_tests_properties (MPI_TEST_H5DIFF-${resultfile} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/PAR/testfiles") if (NOT "${resultcode}" STREQUAL "0") - set_tests_properties (PH5DIFF-${resultfile} PROPERTIES WILL_FAIL "true") + set_tests_properties (MPI_TEST_H5DIFF-${resultfile} PROPERTIES WILL_FAIL "true") endif () if (NOT "${last_test}" STREQUAL "") - set_tests_properties (PH5DIFF-${resultfile} PROPERTIES DEPENDS ${last_test}) + set_tests_properties (MPI_TEST_H5DIFF-${resultfile} PROPERTIES DEPENDS ${last_test}) endif () else () # Remove any output file left over from previous test run add_test ( - NAME PH5DIFF-${resultfile}-clear-objects + NAME MPI_TEST_H5DIFF-${resultfile}-clear-objects COMMAND ${CMAKE_COMMAND} -E remove PAR/testfiles/${resultfile}.out PAR/testfiles/${resultfile}.out.err ) if (NOT "${last_test}" STREQUAL "") - set_tests_properties (PH5DIFF-${resultfile}-clear-objects PROPERTIES DEPENDS ${last_test}) + set_tests_properties (MPI_TEST_H5DIFF-${resultfile}-clear-objects PROPERTIES DEPENDS ${last_test}) endif () add_test ( - NAME PH5DIFF-${resultfile} + NAME MPI_TEST_H5DIFF-${resultfile} COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${MPIEXEC_MAX_NUMPROCS};${MPIEXEC_PREFLAGS};$;${MPIEXEC_POSTFLAGS}" -D "TEST_ARGS:STRING=${ARGN}" @@ -429,7 +429,7 @@ -D "TEST_SORT_COMPARE=TRUE" -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" ) - set_tests_properties (PH5DIFF-${resultfile} PROPERTIES DEPENDS PH5DIFF-${resultfile}-clear-objects) + set_tests_properties (MPI_TEST_H5DIFF-${resultfile} PROPERTIES DEPENDS MPI_TEST_H5DIFF-${resultfile}-clear-objects) set (last_test "PH5DIFF-${resultfile}") endif () endmacro () diff --git a/tools/test/perform/CMakeTests.cmake b/tools/test/perform/CMakeTests.cmake index 02dc15d..36172d1 100644 --- a/tools/test/perform/CMakeTests.cmake +++ b/tools/test/perform/CMakeTests.cmake @@ -170,9 +170,9 @@ endif () set_tests_properties (PERFORM_zip_perf PROPERTIES DEPENDS "PERFORM_zip_perf_help;PERFORM_h5perform-clearall-objects") if (H5_HAVE_PARALLEL) - add_test (NAME PAR_PERFORM_h5perf COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_PERFORM_h5perf COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) if (HDF5_BUILD_PERFORM_STANDALONE) - add_test (NAME PAR_PERFORM_h5perf_alone COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) + add_test (NAME MPI_TEST_PERFORM_h5perf_alone COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) endif () endif () -- cgit v0.12