diff --git a/lzf/LICENSE.txt b/lzf/LICENSE.txt index 3787a007..41cf84d3 100644 --- a/lzf/LICENSE.txt +++ b/lzf/LICENSE.txt @@ -1,7 +1,7 @@ Copyright Notice and Statement for LZF filter Copyright (c) 2008-2009 Andrew Collette -http://h5py.alfven.org +http://h5py.org All rights reserved. Redistribution and use in source and binary forms, with or without @@ -16,8 +16,8 @@ b. Redistributions in binary form must reproduce the above copyright documentation and/or other materials provided with the distribution. -c. Neither the name of the author nor the names of contributors may - be used to endorse or promote products derived from this software +c. Neither the name of the author nor the names of contributors may + be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -31,4 +31,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/lzf/README.txt b/lzf/README.txt index c6ad62c3..15dfc918 100644 --- a/lzf/README.txt +++ b/lzf/README.txt @@ -15,8 +15,14 @@ is released under the BSD license (see LICENSE.txt for details). Using the filter from HDF5 -------------------------- -There is exactly one new public function declared in lzf_filter.h, with -the following signature: +With HDF5 version 1.8.11 or later the filter can be loaded dynamically by the +HDF5 library. The filter needs to be compiled as a plugin as described below +that is placed in the default plugin path /usr/local/hdf5/lib/plugin/. The +plugin path can be overridden with the environment variable HDF5_PLUGIN_PATH. + +With older HDF5 versions, or when statically linking the filter to your program, +the filter must be registered manually. There is exactly one new public function +declared in lzf_filter.h, with the following signature: int register_lzf(void) @@ -38,17 +44,23 @@ version of the LZF compression library. Since the filter is stateless, it's recommended to statically link the entire thing into your program; for example: - $ gcc -O2 -lhdf5 lzf/*.c lzf_filter.c myprog.c -o myprog + $ gcc -O2 lzf/*.c lzf_filter.c myprog.c -lhdf5 -o myprog It can also be built as a shared library, although you will have to install the resulting library somewhere the runtime linker can find it: - $ gcc -O2 -lhdf5 -fPIC -shared lzf/*.c lzf_filter.c -o liblzf_filter.so + $ gcc -O2 -fPIC -shared lzf/*.c lzf_filter.c -lhdf5 -o liblzf_filter.so A similar procedure should be used for building C++ code. As in these examples, using option -O1 or higher is strongly recommended for increased performance. +With HDF5 version 1.8.11 or later the filter can be dynamically loaded as a +plugin. The filter is built as a shared library that is *not* linked against +the HDF5 library: + + $ gcc -O2 -fPIC -shared lzf/*.c lzf_filter.c -o liblzf_filter.so + Contact ------- @@ -58,11 +70,13 @@ goal of h5py is to provide access to the majority of the HDF5 C API and feature set from Python. The most recent version of h5py (1.1) includes the LZF filter by default. -* Downloads and bug tracker: http://h5py.googlecode.com +* Downloads: https://pypi.org/project/h5py/ -* Main web site and documentation: http://h5py.alfven.org +* Issue tracker: https://github.com/h5py/h5py -* Contact email: h5py at alfven dot org +* Main web site and documentation: http://h5py.org + +* Discussion forum: https://forum.hdfgroup.org/c/hdf5/h5py History of changes @@ -76,9 +90,3 @@ Revision 2 Revision 1 Initial release. - - - - - - diff --git a/lzf/example.c b/lzf/example.c index 23dd776c..c154702e 100644 --- a/lzf/example.c +++ b/lzf/example.c @@ -1,6 +1,6 @@ /* Copyright (C) 2009 Andrew Collette - http://h5py.alfven.org + http://h5py.org License: BSD (see LICENSE.txt) Example program demonstrating use of the LZF filter from C code. @@ -13,7 +13,7 @@ $ ./example Success! - $ h5ls -v test_lzf.hdf5 + $ h5ls -v test_lzf.hdf5 Opened "test_lzf.hdf5" with sec2 driver. dset Dataset {100/100, 100/100, 100/100} Location: 0:1:0:976 @@ -79,7 +79,7 @@ int main(){ dset = H5Dcreate(fid, "dset", H5T_NATIVE_FLOAT, sid, plist); if(dset<0) goto failed; - + r = H5Dwrite(dset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data); if(r<0) goto failed; @@ -103,4 +103,3 @@ int main(){ return return_code; } - diff --git a/lzf/lzf/lzf.h b/lzf/lzf/lzf.h index 919b6e6b..061d4cea 100644 --- a/lzf/lzf/lzf.h +++ b/lzf/lzf/lzf.h @@ -1,16 +1,16 @@ /* * Copyright (c) 2000-2008 Marc Alexander Lehmann - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -73,7 +73,7 @@ * and lzf_c.c. * */ -unsigned int +unsigned int lzf_compress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len); @@ -92,9 +92,8 @@ lzf_compress (const void *const in_data, unsigned int in_len, * * This function is very fast, about as fast as a copying loop. */ -unsigned int +unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len); #endif - diff --git a/lzf/lzf/lzfP.h b/lzf/lzf/lzfP.h index 8414da4d..ff5310dc 100644 --- a/lzf/lzf/lzfP.h +++ b/lzf/lzf/lzfP.h @@ -1,16 +1,16 @@ /* * Copyright (c) 2000-2007 Marc Alexander Lehmann - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -99,7 +99,7 @@ /* * Avoid assigning values to errno variable? for some embedding purposes - * (linux kernel for example), this is neccessary. NOTE: this breaks + * (linux kernel for example), this is necessary. NOTE: this breaks * the documentation in lzf.h. */ #ifndef AVOID_ERRNO @@ -107,7 +107,7 @@ #endif /* - * Wether to pass the LZF_STATE variable as argument, or allocate it + * Whether to pass the LZF_STATE variable as argument, or allocate it * on the stack. For small-stack environments, define this to 1. * NOTE: this breaks the prototype in lzf.h. */ @@ -116,11 +116,11 @@ #endif /* - * Wether to add extra checks for input validity in lzf_decompress + * Whether to add extra checks for input validity in lzf_decompress * and return EINVAL if the input stream has been corrupted. This * only shields against overflowing the input buffer and will not * detect most corrupted streams. - * This check is not normally noticable on modern hardware + * This check is not normally noticeable on modern hardware * (<1% slowdown), but might slow down older cpus considerably. */ @@ -163,4 +163,3 @@ typedef const u8 *LZF_STATE[1 << (HLOG)]; #endif #endif - diff --git a/lzf/lzf/lzf_c.c b/lzf/lzf/lzf_c.c index fbfd4cce..e021a247 100644 --- a/lzf/lzf/lzf_c.c +++ b/lzf/lzf/lzf_c.c @@ -1,16 +1,16 @@ /* * Copyright (c) 2000-2008 Marc Alexander Lehmann - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -293,4 +293,3 @@ lzf_compress (const void *const in_data, unsigned int in_len, return op - (u8 *)out_data; } - diff --git a/lzf/lzf/lzf_d.c b/lzf/lzf/lzf_d.c index 2e2eedaa..cc665259 100644 --- a/lzf/lzf/lzf_d.c +++ b/lzf/lzf/lzf_d.c @@ -1,16 +1,16 @@ /* * Copyright (c) 2000-2007 Marc Alexander Lehmann - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -56,7 +56,7 @@ #endif */ -unsigned int +unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len) { @@ -151,4 +151,3 @@ lzf_decompress (const void *const in_data, unsigned int in_len, return op - (u8 *)out_data; } - diff --git a/lzf/lzf_filter.c b/lzf/lzf_filter.c index 1da12e94..67c2b95a 100644 --- a/lzf/lzf_filter.c +++ b/lzf/lzf_filter.c @@ -1,13 +1,13 @@ /***** Preamble block ********************************************************* -* +* * This file is part of h5py, a low-level Python interface to the HDF5 library. -* +* * Copyright (C) 2008 Andrew Collette -* http://h5py.alfven.org +* http://h5py.org * License: BSD (See LICENSE.txt for full license) -* +* * $Date$ -* +* ****** End preamble block ****************************************************/ /* @@ -26,7 +26,7 @@ #include #include #include "hdf5.h" -#include "lzf/lzf.h" +#include "lzf.h" #include "lzf_filter.h" /* Our own versions of H5Epush_sim, as it changed in 1.8 */ @@ -42,10 +42,8 @@ #endif -/* Deal with the mutiple definitions for H5Z_class_t. - Note: HDF5 1.6 and >= 1.8 are supported. - See https://hdfgroup.github.io/hdf5/develop/group___h5_z.html#ga93145acc38c2c60d832b7a9b0123706b - for version history. +/* Deal with the multiple definitions for H5Z_class_t. + Note: HDF5 >=1.6 are supported. (1) The old class should always be used for HDF5 1.6 (2) The new class should always be used for HDF5 1.8 < 1.8.3 @@ -53,11 +51,13 @@ macro H5_USE_16_API is set */ -#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8 +#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 6 #define H5PY_H5Z_NEWCLS 0 -#elif H5_VERS_MAJOR == 1 && H5_VERS_MINOR >= 8 && H5_VERS_RELEASE >= 3 && H5_USE_16_API +#elif H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 8 && H5_VERS_RELEASE < 3 +#define H5PY_H5Z_NEWCLS 1 +#elif H5_USE_16_API #define H5PY_H5Z_NEWCLS 0 -#else +#else /* Default: use new class */ #define H5PY_H5Z_NEWCLS 1 #endif @@ -67,32 +67,44 @@ size_t lzf_filter(unsigned flags, size_t cd_nelmts, herr_t lzf_set_local(hid_t dcpl, hid_t type, hid_t space); +#if H5PY_H5Z_NEWCLS +static const H5Z_class_t filter_class = { + H5Z_CLASS_T_VERS, + (H5Z_filter_t)(H5PY_FILTER_LZF), + 1, 1, + "lzf", + NULL, + (H5Z_set_local_func_t)(lzf_set_local), + (H5Z_func_t)(lzf_filter) +}; +#else +static const H5Z_class_t filter_class = { + (H5Z_filter_t)(H5PY_FILTER_LZF), + "lzf", + NULL, + (H5Z_set_local_func_t)(lzf_set_local), + (H5Z_func_t)(lzf_filter) +}; +#endif + +/* Support dynamical loading of LZF filter plugin */ +#if defined(H5_VERSION_GE) +#if H5_VERSION_GE(1, 8, 11) + +#include "H5PLextern.h" + +H5PL_type_t H5PLget_plugin_type(void){ return H5PL_TYPE_FILTER; } + +const void *H5PLget_plugin_info(void){ return &filter_class; } + +#endif +#endif /* Try to register the filter, passing on the HDF5 return value */ int register_lzf(void){ int retval; -#if H5PY_H5Z_NEWCLS - H5Z_class_t filter_class = { - H5Z_CLASS_T_VERS, - (H5Z_filter_t)(H5PY_FILTER_LZF), - 1, 1, - "lzf", - NULL, - (H5Z_set_local_func_t)(lzf_set_local), - (H5Z_func_t)(lzf_filter) - }; -#else - H5Z_class_t filter_class = { - (H5Z_filter_t)(H5PY_FILTER_LZF), - "lzf", - NULL, - (H5Z_set_local_func_t)(lzf_set_local), - (H5Z_func_t)(lzf_filter) - }; -#endif - retval = H5Zregister(&filter_class); if(retval<0){ PUSH_ERR("register_lzf", H5E_CANTREGISTER, "Can't register LZF filter"); @@ -201,7 +213,7 @@ size_t lzf_filter(unsigned flags, size_t cd_nelmts, #endif while(!status){ - + free(outbuf); outbuf = malloc(outbuf_size); @@ -242,7 +254,7 @@ size_t lzf_filter(unsigned flags, size_t cd_nelmts, *buf_size = outbuf_size; return status; /* Size of compressed/decompressed data */ - } + } failed: @@ -250,16 +262,3 @@ size_t lzf_filter(unsigned flags, size_t cd_nelmts, return 0; } /* End filter function */ - - - - - - - - - - - - - diff --git a/lzf/lzf_filter.h b/lzf/lzf_filter.h index 27dff83a..77da0dcb 100644 --- a/lzf/lzf_filter.h +++ b/lzf/lzf_filter.h @@ -1,13 +1,13 @@ /***** Preamble block ********************************************************* -* +* * This file is part of h5py, a low-level Python interface to the HDF5 library. -* +* * Copyright (C) 2008 Andrew Collette -* http://h5py.alfven.org +* http://h5py.org * License: BSD (See LICENSE.txt for full license) -* +* * $Date$ -* +* ****** End preamble block ****************************************************/ @@ -25,7 +25,7 @@ extern "C" { requests, contact the filter author directly. */ #define H5PY_FILTER_LZF 32000 -/* Register the filter with the library. Returns a negative value on failure, +/* Register the filter with the library. Returns a negative value on failure, and a non-negative value on success. */ int register_lzf(void); @@ -35,4 +35,3 @@ int register_lzf(void); #endif #endif - diff --git a/pyproject.toml b/pyproject.toml index a44bcd3d..d80d6667 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "setuptools", "Cython>=0.19", "numpy>=2.0.0rc1", - "h5py>=2.4.0", + "h5py>=2.5.0", ] build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 67294ff3..725a84b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ setuptools>=0.7 Cython>=0.19 numpy>=1.24 -h5py>=2.4.0 +h5py>=2.5.0 diff --git a/src/lzf_h5plugin.c b/src/lzf_h5plugin.c index 49117858..14b2cabd 100644 --- a/src/lzf_h5plugin.c +++ b/src/lzf_h5plugin.c @@ -35,7 +35,3 @@ H5Z_class_t lzf_H5Filter[1] = {{ (H5Z_set_local_func_t)(lzf_set_local), (H5Z_func_t)(lzf_filter) }}; - - -H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;} -const void* H5PLget_plugin_info(void) {return lzf_H5Filter;}