Skip to content

Commit c54a17a

Browse files
committed
Support dynamical loading of LZF filter plugin
1 parent 9bd0310 commit c54a17a

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

lzf/README.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ is released under the BSD license (see LICENSE.txt for details).
1515
Using the filter from HDF5
1616
--------------------------
1717

18-
There is exactly one new public function declared in lzf_filter.h, with
19-
the following signature:
18+
With HDF5 version 1.8.11 or later the filter can be loaded dynamically by the
19+
HDF5 library. The filter needs to be compiled as a plugin as described below
20+
that is placed in the default plugin path /usr/local/hdf5/lib/plugin/. The
21+
plugin path can be overridden with the environment variable HDF5_PLUGIN_PATH.
22+
23+
With older HDF5 versions, or when statically linking the filter to your program,
24+
the filter must be registered manually. There is exactly one new public function
25+
declared in lzf_filter.h, with the following signature:
2026

2127
int register_lzf(void)
2228

@@ -38,17 +44,23 @@ version of the LZF compression library. Since the filter is stateless, it's
3844
recommended to statically link the entire thing into your program; for
3945
example:
4046

41-
$ gcc -O2 -lhdf5 lzf/*.c lzf_filter.c myprog.c -o myprog
47+
$ gcc -O2 lzf/*.c lzf_filter.c myprog.c -lhdf5 -o myprog
4248

4349
It can also be built as a shared library, although you will have to install
4450
the resulting library somewhere the runtime linker can find it:
4551

46-
$ gcc -O2 -lhdf5 -fPIC -shared lzf/*.c lzf_filter.c -o liblzf_filter.so
52+
$ gcc -O2 -fPIC -shared lzf/*.c lzf_filter.c -lhdf5 -o liblzf_filter.so
4753

4854
A similar procedure should be used for building C++ code. As in these
4955
examples, using option -O1 or higher is strongly recommended for increased
5056
performance.
5157

58+
With HDF5 version 1.8.11 or later the filter can be dynamically loaded as a
59+
plugin. The filter is built as a shared library that is *not* linked against
60+
the HDF5 library:
61+
62+
$ gcc -O2 -fPIC -shared lzf/*.c lzf_filter.c -o liblzf_filter.so
63+
5264

5365
Contact
5466
-------

lzf/lzf_filter.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,44 @@ size_t lzf_filter(unsigned flags, size_t cd_nelmts,
6363

6464
herr_t lzf_set_local(hid_t dcpl, hid_t type, hid_t space);
6565

66+
#if H5PY_H5Z_NEWCLS
67+
static const H5Z_class_t filter_class = {
68+
H5Z_CLASS_T_VERS,
69+
(H5Z_filter_t)(H5PY_FILTER_LZF),
70+
1, 1,
71+
"lzf",
72+
NULL,
73+
(H5Z_set_local_func_t)(lzf_set_local),
74+
(H5Z_func_t)(lzf_filter)
75+
};
76+
#else
77+
static const H5Z_class_t filter_class = {
78+
(H5Z_filter_t)(H5PY_FILTER_LZF),
79+
"lzf",
80+
NULL,
81+
(H5Z_set_local_func_t)(lzf_set_local),
82+
(H5Z_func_t)(lzf_filter)
83+
};
84+
#endif
85+
86+
/* Support dynamical loading of LZF filter plugin */
87+
#if defined(H5_VERSION_GE)
88+
#if H5_VERSION_GE(1, 8, 11)
89+
90+
#include "H5PLextern.h"
91+
92+
H5PL_type_t H5PLget_plugin_type(void){ return H5PL_TYPE_FILTER; }
93+
94+
const void *H5PLget_plugin_info(void){ return &filter_class; }
95+
96+
#endif
97+
#endif
6698

6799
/* Try to register the filter, passing on the HDF5 return value */
68100
int register_lzf(void){
69101

70102
int retval;
71103

72-
#if H5PY_H5Z_NEWCLS
73-
H5Z_class_t filter_class = {
74-
H5Z_CLASS_T_VERS,
75-
(H5Z_filter_t)(H5PY_FILTER_LZF),
76-
1, 1,
77-
"lzf",
78-
NULL,
79-
(H5Z_set_local_func_t)(lzf_set_local),
80-
(H5Z_func_t)(lzf_filter)
81-
};
82-
#else
83-
H5Z_class_t filter_class = {
84-
(H5Z_filter_t)(H5PY_FILTER_LZF),
85-
"lzf",
86-
NULL,
87-
(H5Z_set_local_func_t)(lzf_set_local),
88-
(H5Z_func_t)(lzf_filter)
89-
};
90-
#endif
91-
92104
retval = H5Zregister(&filter_class);
93105
if(retval<0){
94106
PUSH_ERR("register_lzf", H5E_CANTREGISTER, "Can't register LZF filter");

0 commit comments

Comments
 (0)