Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize java w/ develop #3283

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions java/src/jni/exceptionImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ typedef struct H5E_num_t {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \
\
if (NULL == (jm = ENVPTR->GetMethodID(ENVONLY, jc, "<init>", "(Ljava/lang/String;)V"))) { \
HDprintf("THROWEXCEPTION FATAL ERROR: GetMethodID failed\n"); \
printf("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)); \
printf("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)); \
printf("THROWEXCEPTION FATAL ERROR: Class %s: Throw failed\n", (className)); \
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); \
} \
}
Expand Down Expand Up @@ -168,9 +168,9 @@ Java_hdf_hdf5lib_exceptions_HDF5LibraryException_printStackTrace0(JNIEnv *env, j
else {
PIN_JAVA_STRING(ENVONLY, file_name, file, NULL, "printStackTrace0: file name not pinned");

if ((stream = HDfopen(file, "a+"))) {
if ((stream = fopen(file, "a+"))) {
H5Eprint2(H5E_DEFAULT, stream);
HDfclose(stream);
fclose(stream);
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ h5libraryError(JNIEnv *env)
goto done;

if (msg_size > 0) {
if (NULL == (msg_str = (char *)HDcalloc((size_t)msg_size + 1, sizeof(char))))
if (NULL == (msg_str = (char *)calloc((size_t)msg_size + 1, sizeof(char))))
H5_OUT_OF_MEMORY_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)
Expand All @@ -428,7 +428,7 @@ h5libraryError(JNIEnv *env)

done:
if (msg_str)
HDfree(msg_str);
free(msg_str);

return retVal;
} /* end h5libraryError() */
Expand Down
2 changes: 1 addition & 1 deletion java/src/jni/h5Constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ Java_hdf_hdf5lib_HDF5Constants_H5O_1TOKEN_1UNDEF(JNIEnv *env, jclass cls)
H5O_token_t undef_token = H5O_TOKEN_UNDEF;

/* TODO: Can be optimized by keeping a global reference to the undefined token class */
return create_H5O_token_t(env, &undef_token, FALSE);
return create_H5O_token_t(env, &undef_token, false);
}

JNIEXPORT jlong JNICALL
Expand Down
2 changes: 1 addition & 1 deletion java/src/jni/h5Imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Java_hdf_hdf5lib_H5_H5set_1free_1list_1limits(JNIEnv *env, jclass clss, jint reg
JNIEXPORT jboolean JNICALL
Java_hdf_hdf5lib_H5_H5is_1library_1threadsafe(JNIEnv *env, jclass clss)
{
hbool_t is_ts = false;
bool is_ts = false;

UNUSED(clss);

Expand Down
80 changes: 40 additions & 40 deletions java/src/jni/h5aImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (readBuf = HDcalloc((size_t)vl_array_len, typeSize)))
if (NULL == (readBuf = calloc((size_t)vl_array_len, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aread: failed to allocate raw VL read buffer");
}
else {
Expand Down Expand Up @@ -218,7 +218,7 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t
}

if (vl_data_class) {
HDfree(readBuf);
free(readBuf);
}
else {
if (isCriticalPinning) {
Expand Down Expand Up @@ -270,7 +270,7 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (writeBuf = HDcalloc((size_t)vl_array_len, typeSize)))
if (NULL == (writeBuf = calloc((size_t)vl_array_len, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Awrite: failed to allocate raw VL write buffer");
}
else {
Expand Down Expand Up @@ -304,7 +304,7 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_
}

if (vl_data_class) {
HDfree(writeBuf);
free(writeBuf);
}
else {
if (isCriticalPinning) {
Expand Down Expand Up @@ -993,17 +993,17 @@ Java_hdf_hdf5lib_H5_H5Aread_1string(JNIEnv *env, jclass clss, jlong attr_id, jlo
if (!(str_len = H5Tget_size((hid_t)mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (cstr = (char *)HDmalloc(str_len + 1)))
if (NULL == (cstr = (char *)malloc(str_len + 1)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aread_string: memory allocation failed");

if (NULL == (c_buf = (char *)HDmalloc((size_t)n * str_len)))
if (NULL == (c_buf = (char *)malloc((size_t)n * str_len)))
H5_OUT_OF_MEMORY_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);
memcpy(cstr, c_buf + pos, str_len);
cstr[str_len] = '\0';

if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, cstr))) {
Expand All @@ -1022,9 +1022,9 @@ Java_hdf_hdf5lib_H5_H5Aread_1string(JNIEnv *env, jclass clss, jlong attr_id, jlo

done:
if (c_buf)
HDfree(c_buf);
free(c_buf);
if (cstr)
HDfree(cstr);
free(cstr);

return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5Aread_1string */
Expand Down Expand Up @@ -1058,7 +1058,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1string(JNIEnv *env, jclass clss, jlong attr_id, jl
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)))
if (NULL == (c_buf = (char *)malloc((size_t)n * str_len)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Awrite_string: memory allocation failed");

for (i = 0; i < (size_t)n; i++) {
Expand All @@ -1068,7 +1068,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1string(JNIEnv *env, jclass clss, jlong attr_id, jl
/*
* If the string object was NULL, skip it.
*/
HDmemset(&c_buf[i * str_len], 0, str_len);
memset(&c_buf[i * str_len], 0, str_len);
continue;
}

Expand All @@ -1079,7 +1079,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1string(JNIEnv *env, jclass clss, jlong attr_id, jl

PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5Awrite_string: string not pinned");

HDstrncpy(&c_buf[i * str_len], utf8, str_len);
strncpy(&c_buf[i * str_len], utf8, str_len);

UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
utf8 = NULL;
Expand All @@ -1094,7 +1094,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1string(JNIEnv *env, jclass clss, jlong attr_id, jl
if (utf8)
UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
if (c_buf)
HDfree(c_buf);
free(c_buf);

return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5Awrite_1string */
Expand Down Expand Up @@ -1133,7 +1133,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (readBuf = HDcalloc((size_t)vl_array_len, typeSize)))
if (NULL == (readBuf = calloc((size_t)vl_array_len, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aread: failed to allocate raw VL read buffer");

if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0)
Expand All @@ -1157,9 +1157,9 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
}
if (is_variable) {
for (size_t i = 0; i < (size_t)vl_array_len; i++)
HDfree(((char **)readBuf)[i]);
free(((char **)readBuf)[i]);
}
HDfree(readBuf);
free(readBuf);
}

return (jint)status;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (writeBuf = HDcalloc((size_t)vl_array_len, typeSize)))
if (NULL == (writeBuf = calloc((size_t)vl_array_len, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Awrite: failed to allocate raw VL write buffer");

if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
Expand All @@ -1224,10 +1224,10 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
}
if (is_variable) {
for (size_t i = 0; i < (size_t)vl_array_len; i++)
HDfree(((char **)writeBuf)[i]);
free(((char **)writeBuf)[i]);
}

HDfree(writeBuf);
free(writeBuf);
}

return (jint)status;
Expand Down Expand Up @@ -1323,7 +1323,7 @@ H5AreadVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadVL_str: buf length < 0");
}

if (NULL == (strs = (char **)HDcalloc((size_t)n, sizeof(char *))))
if (NULL == (strs = (char **)calloc((size_t)n, sizeof(char *))))
H5_OUT_OF_MEMORY_ERROR(ENVONLY,
"H5AreadVL_str: failed to allocate variable length string read buffer");

Expand Down Expand Up @@ -1356,7 +1356,7 @@ H5AreadVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
H5free_memory(strs[i]);
}

HDfree(strs);
free(strs);
}

return status;
Expand All @@ -1381,7 +1381,7 @@ H5AreadVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
void *readBuf = NULL;
herr_t status = FAIL;

HDmemset(&h5str, 0, sizeof(h5str_t));
memset(&h5str, 0, sizeof(h5str_t));

/* Get size of string array */
if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
Expand All @@ -1396,7 +1396,7 @@ H5AreadVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
if (!(typeSize = H5Tget_size(tid)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (readBuf = HDcalloc((size_t)n, typeSize)))
if (NULL == (readBuf = calloc((size_t)n, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AreadVL_asstr: failed to allocate read buffer");

if ((status = H5Aread(aid, tid, readBuf)) < 0)
Expand Down Expand Up @@ -1429,7 +1429,7 @@ H5AreadVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
h5str_free(&h5str);
if (readBuf) {
H5Treclaim(tid, sid, H5P_DEFAULT, readBuf);
HDfree(readBuf);
free(readBuf);
}
if (sid >= 0)
H5Sclose(sid);
Expand Down Expand Up @@ -1528,7 +1528,7 @@ H5AwriteVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL_str: buf length < 0");
}

if (NULL == (writeBuf = (char **)HDcalloc((size_t)size + 1, sizeof(char *))))
if (NULL == (writeBuf = (char **)calloc((size_t)size + 1, sizeof(char *))))
H5_OUT_OF_MEMORY_ERROR(ENVONLY,
"H5AwriteVL_str: failed to allocate variable length string write buffer");

Expand All @@ -1550,10 +1550,10 @@ H5AwriteVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)

PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5AwriteVL_str: string not pinned");

if (NULL == (writeBuf[i] = (char *)HDmalloc((size_t)length + 1)))
if (NULL == (writeBuf[i] = (char *)malloc((size_t)length + 1)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate string buffer");

HDstrncpy(writeBuf[i], utf8, (size_t)length + 1);
strncpy(writeBuf[i], utf8, (size_t)length + 1);
writeBuf[i][length] = '\0';

UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
Expand All @@ -1571,10 +1571,10 @@ H5AwriteVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
if (writeBuf) {
for (i = 0; i < size; i++) {
if (writeBuf[i])
HDfree(writeBuf[i]);
free(writeBuf[i]);
}

HDfree(writeBuf);
free(writeBuf);
}

return status;
Expand Down Expand Up @@ -1610,7 +1610,7 @@ H5AwriteVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
if (!(typeSize = H5Tget_size(tid)))
H5_LIBRARY_ERROR(ENVONLY);

if (NULL == (writeBuf = HDcalloc((size_t)n, typeSize)))
if (NULL == (writeBuf = calloc((size_t)n, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL_asstr: failed to allocate write buffer");

/*
Expand All @@ -1626,7 +1626,7 @@ H5AwriteVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
/*
* If the string object was NULL, skip it.
*/
HDmemset(&(((char *)writeBuf)[i * typeSize]), 0, typeSize);
memset(&(((char *)writeBuf)[i * typeSize]), 0, typeSize);
continue;
}

Expand All @@ -1646,7 +1646,7 @@ H5AwriteVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
if (!h5str_convert(ENVONLY, &utf8_copy, aid, tid, &(((char *)writeBuf)[i * typeSize]), 0))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);

HDfree(utf8_copy);
free(utf8_copy);

UNPIN_JAVA_STRING(ENVONLY, jstr, utf8);
utf8 = NULL;
Expand All @@ -1662,7 +1662,7 @@ H5AwriteVL_asstr(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf)
UNPIN_JAVA_STRING(ENVONLY, jstr, utf8);
if (writeBuf) {
H5Treclaim(tid, sid, H5P_DEFAULT, writeBuf);
HDfree(writeBuf);
free(writeBuf);
}
if (sid >= 0)
H5Sclose(sid);
Expand All @@ -1687,14 +1687,14 @@ Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref(JNIEnv *env, jclass clss, jlong attr_id, j

UNUSED(clss);

HDmemset(&h5str, 0, sizeof(h5str_t));
memset(&h5str, 0, sizeof(h5str_t));

if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_reg_ref: buf length < 0");
}

if (NULL == (ref_data = (H5R_ref_t *)HDcalloc(1, (size_t)n * sizeof(H5R_ref_t))))
if (NULL == (ref_data = (H5R_ref_t *)calloc(1, (size_t)n * sizeof(H5R_ref_t))))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aread_reg_ref: failed to allocate read buffer");

if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, ref_data)) < 0)
Expand Down Expand Up @@ -1724,7 +1724,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref(JNIEnv *env, jclass clss, jlong attr_id, j
if (h5str.s)
h5str_free(&h5str);
if (ref_data)
HDfree(ref_data);
free(ref_data);

return (jint)status;
} /* end Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref */
Expand Down Expand Up @@ -1784,7 +1784,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1name(JNIEnv *env, jclass clss, jlong attr_id)
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)))
if (NULL == (attrName = (char *)malloc(sizeof(char) * (size_t)buf_size + 1)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Aget_name: failed to allocate attribute name buffer");

if (H5Aget_name((hid_t)attr_id, (size_t)buf_size + 1, attrName) < 0)
Expand All @@ -1796,7 +1796,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1name(JNIEnv *env, jclass clss, jlong attr_id)

done:
if (attrName)
HDfree(attrName);
free(attrName);

return str;
} /* end Java_hdf_hdf5lib_H5_H5Aget_1name */
Expand Down Expand Up @@ -2140,7 +2140,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx(JNIEnv *env, jclass clss, jlong loc_id
(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)))
if (NULL == (attrName = (char *)malloc(sizeof(char) * (size_t)status_size + 1)))
H5_OUT_OF_MEMORY_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,
Expand All @@ -2153,7 +2153,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx(JNIEnv *env, jclass clss, jlong loc_id

done:
if (attrName)
HDfree(attrName);
free(attrName);
if (objName)
UNPIN_JAVA_STRING(ENVONLY, obj_name, objName);

Expand Down
Loading