Fix mostly java warnings, and cpp cast (#2134)

This commit is contained in:
Allen Byrne 2022-10-03 13:31:32 -05:00 committed by GitHub
parent 1fb83da215
commit c114bd64b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 209 additions and 190 deletions

View File

@ -190,13 +190,15 @@ test_szip_filter(H5File &file1)
hsize_t i, j, n;
for (i = n = 0; i < size[0]; i++) {
for (j = 0; j < size[1]; j++) {
points[i][j] = (int)n++;
points[i][j] = static_cast<int> n++;
}
}
// Write to the dataset then read back the values
dataset.write((void *)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
dataset.read((void *)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
dataset.write(static_cast<void *> points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL,
xfer);
dataset.read(static_cast<void *> check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL,
xfer);
// Check that the values read are the same as the values written
for (i = 0; i < size[0]; i++)

View File

@ -1084,7 +1084,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
/* Get size of data array */
if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0");
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: readBuf length < 0");
}
dims[0] = (hsize_t)n;
@ -1100,7 +1100,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
H5T_class_t vlClass;
size_t vlSize;
void *rawBuf = NULL;
jobject *jList = NULL;
jobjectArray jList = NULL;
size_t i, j, x;
@ -1234,7 +1234,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
floatValue);
(double)floatValue);
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
break;
}
@ -1321,7 +1321,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
htri_t vl_data_class;
herr_t status = FAIL;
jboolean writeBufIsCopy;
jbyteArray *writeBuf = NULL;
jbyteArray writeBuf = NULL;
UNUSED(clss);
@ -1349,7 +1349,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
H5T_class_t vlClass;
size_t vlSize;
void *rawBuf = NULL;
jobject *jList = NULL;
jobjectArray jList = NULL;
size_t i, j, x;

View File

@ -1115,7 +1115,7 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t vlClass;
size_t vlSize;
void *rawBuf = NULL;
jobject *jList = NULL;
jobjectArray jList = NULL;
size_t i, j, x;
@ -1250,7 +1250,7 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
}
jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
floatValue);
(double)floatValue);
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
break;
}
@ -1334,7 +1334,7 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
htri_t vl_data_class;
herr_t status = FAIL;
jboolean writeBufIsCopy;
jbyteArray *writeBuf = NULL;
jbyteArray writeBuf = NULL;
UNUSED(clss);
@ -1358,7 +1358,7 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t vlClass;
size_t vlSize;
void *rawBuf = NULL;
jobject *jList = NULL;
jobjectArray jList = NULL;
size_t i, j, x;

View File

@ -257,6 +257,23 @@
do { \
(*envptr)->ReleaseStringUTFChars(envptr, pinnedString, stringToRelease); \
} while (0)
/*
* Above String macros may be incorrect, suggested code for getting a cstr from java
* int jstr_to_cstr(JNIEnv *jenv, jstring j_str, char *c_str, size_t cstr_len)
* {
* int32_t j_len, c_len;
*
* c_len = (*jenv)->GetStringUTFLength(jenv, j_str);
* if (c_len > (int32_t)cstr_len)
* return -ENAMETOOLONG;
* j_len = (*jenv)->GetStringLength(jenv, j_str);
* (*jenv)->GetStringUTFRegion(jenv, j_str, 0, j_len, c_str);
* if ((*jenv)->ExceptionCheck(jenv))
* return -EIO;
* return 0;
* }
*
*/
#ifdef __cplusplus
extern "C" {

View File

@ -436,7 +436,7 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
break;
case H5T_ENUM: {
void *value;
void *value = NULL;
token = HDstrtok(this_str, delimiter);
@ -865,7 +865,7 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i
if (NULL == (this_str = (char *)HDmalloc(this_len)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer");
if (HDsnprintf(this_str, this_len, "%g", tmp_float) < 0)
if (HDsnprintf(this_str, this_len, "%g", (double)tmp_float) < 0)
H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure");
break;
@ -2273,10 +2273,10 @@ h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hs
}
case H5T_STRING: {
unsigned char tempuchar;
unsigned int i;
H5T_str_t pad;
char *s;
char *s = NULL;
unsigned char tempuchar;
if ((pad = H5Tget_strpad(tid)) < 0) {
ret_value = FAIL;
@ -2287,7 +2287,7 @@ h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hs
mem = ((unsigned char *)_mem) + block_index * size;
if (H5Tis_variable_str(tid)) {
s = *(char **)mem;
s = *(char **)((void *)mem);
if (s != NULL)
size = HDstrlen(s);
}
@ -2919,23 +2919,19 @@ done:
int
h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
{
hid_t f_space = H5I_INVALID_HID; /* file data space */
hsize_t elmtno; /* counter */
size_t i = 0; /* counter */
int sndims; /* rank of dataspace */
int carry; /* counter carry value */
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 */
hssize_t p_nelmts; /* total selected elmts */
size_t p_type_nbytes; /* size of memory type */
/* Stripmine info */
void *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 */
unsigned char *sm_buf = NULL; /* buffer for raw data */
hid_t sm_space = H5I_INVALID_HID; /* stripmine data space */
/* Hyperslab info */
@ -2945,11 +2941,11 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
/* VL data special information */
unsigned int vl_data = 0; /* contains VL datatypes */
int ret_value = FAIL;
hid_t p_type = H5I_INVALID_HID;
hid_t f_type = H5I_INVALID_HID;
int ret_value = FAIL;
if (dset < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_dump_simple_dset: dset ID < 0");
@ -2959,18 +2955,21 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
if ((f_space = H5Dget_space(dset)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if ((ndims = H5Sget_simple_extent_ndims(f_space)) < 0)
if ((sndims = H5Sget_simple_extent_ndims(f_space)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
/* Assume entire data space to be printed */
if (H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (H5Tequal(f_type, H5T_STD_REF_DSETREG)) {
hssize_t p_nelmts; /* total selected elmts */
if ((p_nelmts = H5Sget_simple_extent_npoints(f_space)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (NULL ==
(sm_buf = (H5R_ref_t *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), (size_t)p_nelmts)))
(sm_buf = (unsigned char *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), (size_t)p_nelmts)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_dump_simple_mem: failed to allocate sm_buf");
/* Read the data */
@ -2987,6 +2986,10 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
}
}
else {
/* Print info */
size_t p_type_nbytes; /* size of memory type */
hsize_t p_nelmts; /* total selected elmts */
switch (binary_order) {
case 1: {
if ((p_type = h5str_get_native_type(f_type)) < 0)
@ -3017,15 +3020,11 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
}
}
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++)
if (sndims > 0) {
for (i = 0; i < (size_t)sndims; i++)
p_nelmts *= total_size[i];
} /* end if */
@ -3041,8 +3040,8 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
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) {
if (sndims > 0) {
for (i = (size_t)sndims; i > 0; --i) {
hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
if (size == 0) /* datum size > H5TOOLS_BUFSIZE */
size = 1;
@ -3066,20 +3065,18 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
for (elmtno = 0; elmtno < (hsize_t)p_nelmts; elmtno += hs_nelmts) {
/* Calculate the hyperslab size */
if (ndims > 0) {
for (i = 0, hs_nelmts = 1; i < (size_t)ndims; i++) {
if (sndims > 0) {
for (i = 0, hs_nelmts = 1; i < (size_t)sndims; 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)
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)
if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
H5_LIBRARY_ERROR(ENVONLY);
}
else {
@ -3112,7 +3109,7 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
}
/* Calculate the next hyperslab offset */
for (i = (size_t)ndims, carry = 1; i > 0 && carry; --i) {
for (i = (size_t)sndims, carry = 1; i > 0 && carry; --i) {
hs_offset[i - 1] += hs_size[i - 1];
if (hs_offset[i - 1] == total_size[i - 1])
@ -3124,7 +3121,6 @@ h5str_dump_simple_dset(JNIEnv *env, FILE *stream, hid_t dset, int binary_order)
}
}
}
}
ret_value = SUCCEED;
@ -3148,16 +3144,13 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
{
hid_t f_space = H5I_INVALID_HID; /* file data space */
hsize_t alloc_size;
int ndims; /* rank of dataspace */
int sndims; /* rank of dataspace */
unsigned i; /* counters */
hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset */
hssize_t p_nelmts; /* total selected elmts */
void *sm_buf = NULL; /* buffer for raw data */
hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */
int ret_value = 0;
unsigned char *sm_buf = NULL; /* buffer for raw data */
/* VL data special information */
unsigned int vl_data = 0; /* contains VL datatypes */
hid_t p_type = H5I_INVALID_HID;
@ -3172,18 +3165,20 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
if (H5I_INVALID_HID == (f_space = H5Aget_space(attr_id)))
H5_LIBRARY_ERROR(ENVONLY);
if ((ndims = H5Sget_simple_extent_ndims(f_space)) < 0)
if ((sndims = H5Sget_simple_extent_ndims(f_space)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (H5Tequal(f_type, H5T_STD_REF_DSETREG)) {
hssize_t p_nelmts; /* total selected elmts */
if ((p_nelmts = H5Sget_simple_extent_npoints(f_space)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (NULL ==
(sm_buf = (H5R_ref_t *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), (size_t)p_nelmts)))
(sm_buf = (unsigned char *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), (size_t)p_nelmts)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_dump_simple_mem: failed to allocate sm_buf");
/* Read the data */
@ -3200,6 +3195,8 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
}
}
else {
hsize_t p_nelmts; /* total selected elmts */
switch (binary_order) {
case 1: {
if ((p_type = h5str_get_native_type(f_type)) < 0)
@ -3230,14 +3227,11 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
}
}
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++)
if (sndims > 0) {
for (i = 0; i < (size_t)sndims; i++)
p_nelmts *= total_size[i];
} /* end if */
@ -3255,8 +3249,7 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
H5_LIBRARY_ERROR(ENVONLY);
if (binary_order == 99) {
if (h5str_dump_simple_data(ENVONLY, stream, attr_id, p_type, sm_buf, (size_t)p_nelmts) <
0)
if (h5str_dump_simple_data(ENVONLY, stream, attr_id, p_type, sm_buf, (size_t)p_nelmts) < 0)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
}
else {
@ -3271,7 +3264,6 @@ h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr_id, int binary_order
}
}
}
}
ret_value = SUCCEED;

View File

@ -77,6 +77,7 @@ public class TestH5Fparams {
H5.H5Funmount(-1, null);
}
@SuppressWarnings("deprecation")
@Ignore
public void testH5Fis_hdf5_text()
{

View File

@ -449,6 +449,7 @@ public class TestH5Ocreate {
((idata)((H5O_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("G1/DS2") == 0);
}
@SuppressWarnings("deprecation")
@Test
public void testH5Ocomment()
{
@ -479,6 +480,7 @@ public class TestH5Ocreate {
assertTrue("H5Oget_comment: ", obj_comment.compareTo("Test Comment") == 0);
}
@SuppressWarnings("deprecation")
@Test
public void testH5Ocomment_clear()
{
@ -525,6 +527,7 @@ public class TestH5Ocreate {
assertTrue("H5Oget_comment: ", obj_comment == null);
}
@SuppressWarnings("deprecation")
@Test
public void testH5Ocomment_by_name()
{
@ -548,6 +551,7 @@ public class TestH5Ocreate {
assertTrue("H5Oget_comment_by_name: ", obj_comment.compareTo("Test Comment") == 0);
}
@SuppressWarnings("deprecation")
@Test
public void testH5Ocomment_by_name_clear()
{

View File

@ -168,6 +168,7 @@ public class TestH5Oparams {
H5.H5Ovisit_by_name(-1, "Bogus", -1, -1, null, null, 0, -1);
}
@SuppressWarnings("deprecation")
@Test(expected = HDF5LibraryException.class)
public void testH5Oset_comment_invalid() throws Throwable
{
@ -180,12 +181,14 @@ public class TestH5Oparams {
H5.H5Oget_comment(-1);
}
@SuppressWarnings("deprecation")
@Test(expected = HDF5LibraryException.class)
public void testH5Oset_comment_by_name_invalid() throws Throwable
{
H5.H5Oset_comment_by_name(-1, "Bogus", null, -1);
}
@SuppressWarnings("deprecation")
@Test(expected = NullPointerException.class)
public void testH5Oset_comment_by_name_null() throws Throwable
{

View File

@ -3978,7 +3978,7 @@ test_misc22(void)
if ((prec[j] + offsets[k]) > (H5Tget_size(idts[i]) * 8))
continue;
MESSAGE(5, (" Testing datatypes size=%d precision=%u offset=%d\n", H5Tget_size(idts[i]),
MESSAGE(5, (" Testing datatypes size=%zu precision=%u offset=%d\n", H5Tget_size(idts[i]),
(unsigned)prec[j], (unsigned)offsets[k]));
/* Create the DCPL */