#include #include #include #include #include #include /* Older versions of the hdf library may define H5PL_type_t here */ #include #ifndef DLL_EXPORT #define DLL_EXPORT #endif /* WARNING: Starting with HDF5 version 1.10.x, the plugin code MUST be careful when using the standard *malloc()*, *realloc()*, and *free()* function. In the event that the code is allocating, reallocating, for free'ing memory that either came from or will be exported to the calling HDF5 library, then one MUST use the corresponding HDF5 functions *H5allocate_memory()*, *H5resize_memory()*, *H5free_memory()* [5] to avoid memory failures. Additionally, if your filter code leaks memory, then the HDF5 library will generate an error. */ #include "h5misc.h" #undef DEBUG /* The C standard apparently defines all floating point constants as double; we rely on that in this code. */ #define DBLVAL 12345678.12345678 static int paramcheck(size_t nparams, const unsigned int* params); static void byteswap8(unsigned char* mem); static void mismatch(size_t i, const char* which); const H5Z_class2_t H5Z_TEST[1] = {{ H5Z_CLASS_T_VERS, /* H5Z_class_t version */ (H5Z_filter_t)(H5Z_FILTER_TEST), /* Filter id number */ 1, /* encoder_present flag (set to true) */ 1, /* decoder_present flag (set to true) */ "test", /* Filter name for debugging */ (H5Z_can_apply_func_t)H5Z_test_can_apply, /* The "can apply" callback */ NULL, /* The "set local" callback */ (H5Z_func_t)H5Z_filter_test, /* The actual filter function */ }}; /* External Discovery Functions */ H5PL_type_t H5PLget_plugin_type(void) { return H5PL_TYPE_FILTER; } const void* H5PLget_plugin_info(void) { return H5Z_TEST; } /* Make this explicit */ /* * The "can_apply" callback returns positive a valid combination, zero for an * invalid combination and negative for an error. */ htri_t H5Z_test_can_apply(hid_t dcpl_id, hid_t type_id, hid_t space_id) { return 1; /* Assume it can always apply */ } /* This filter does some verification that the parameters passed to the filter are correct. Specifically, that endian-ness is correct. As a filter, it is the identify function, passing input to output unchanged. Test cases format: 1.The first param is the test index i.e. which test to execute. 2. The remaining parameters are those for the test chosen in #1 */ size_t H5Z_filter_test(unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[], size_t nbytes, size_t *buf_size, void **buf) { void* newbuf; unsigned int testcase = 0; if(cd_nelmts == 0) goto fail; testcase = cd_values[0]; if(testcase == TC_ENDIAN) { if(!paramcheck(cd_nelmts,cd_values)) goto fail; } if (flags & H5Z_FLAG_REVERSE) { /* Replace buffer */ newbuf = H5allocate_memory(*buf_size,0); if(newbuf == NULL) abort(); memcpy(newbuf,*buf,*buf_size); /* reclaim old buffer */ H5free_memory(*buf); *buf = newbuf; } else { /* Replace buffer */ newbuf = H5allocate_memory(*buf_size,0); if(newbuf == NULL) abort(); memcpy(newbuf,*buf,*buf_size); /* reclaim old buffer */ H5free_memory(*buf); *buf = newbuf; } return *buf_size; fail: return 0; } static int paramcheck(size_t nparams, const unsigned int* params) { size_t i; /* Test endianness of this machine */ const unsigned char b[4] = {0x0,0x0,0x0,0x1}; /* value 1 in big-endian*/ int bigendian = (1 == *(unsigned int*)b); /* 1=>big 0=>little*/ if(nparams != 14) { fprintf(stderr,"Too few parameters: need=16 sent=%ld\n",(unsigned long)nparams); goto fail; } for(i=0;i