From 8299373d41b74d988196b80f55f25efe43b7531c Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Sat, 9 Oct 2021 09:23:49 -0500 Subject: 1.10 Merge Add missing dataset reference text #1081 (#1083) * Merge Add missing dataset reference text #1081 * Only print name if not printing data --- java/src/jni/h5util.c | 58 ++++++++++++++++++++++++++++++++++++++----------- java/src/jni/h5util.h | 1 + tools/lib/h5tools_ref.c | 2 +- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index c05fee6..9f0bbfe 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -224,7 +224,7 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ case sizeof(float): { float tmp_float = 0.0f; - sscanf(token, "%f", &tmp_float); + HDsscanf(token, "%f", &tmp_float); HDmemcpy(cptr, &tmp_float, sizeof(float)); break; } @@ -232,7 +232,7 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ case sizeof(double): { double tmp_double = 0.0; - sscanf(token, "%lf", &tmp_double); + HDsscanf(token, "%lf", &tmp_double); HDmemcpy(cptr, &tmp_double, sizeof(double)); break; } @@ -240,7 +240,7 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ case sizeof(long double): { long double tmp_ldouble = 0.0; - sscanf(token, "%Lg", &tmp_ldouble); + HDsscanf(token, "%Lg", &tmp_ldouble); HDmemcpy(cptr, &tmp_ldouble, sizeof(long double)); break; } @@ -288,11 +288,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ signed char tmp_char = 0; if (H5T_SGN_NONE == nsign) { - sscanf(token, "%hhu", &tmp_uchar); + HDsscanf(token, "%hhu", &tmp_uchar); HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char)); } else { - sscanf(token, "%hhd", &tmp_char); + HDsscanf(token, "%hhd", &tmp_char); HDmemcpy(cptr, &tmp_char, sizeof(char)); } @@ -304,11 +304,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ short tmp_short = 0; if (H5T_SGN_NONE == nsign) { - sscanf(token, "%hu", &tmp_ushort); + HDsscanf(token, "%hu", &tmp_ushort); HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); } else { - sscanf(token, "%hd", &tmp_short); + HDsscanf(token, "%hd", &tmp_short); HDmemcpy(&tmp_short, cptr, sizeof(short)); } @@ -320,11 +320,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ int tmp_int = 0; if (H5T_SGN_NONE == nsign) { - sscanf(token, "%u", &tmp_uint); + HDsscanf(token, "%u", &tmp_uint); HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int)); } else { - sscanf(token, "%d", &tmp_int); + HDsscanf(token, "%d", &tmp_int); HDmemcpy(cptr, &tmp_int, sizeof(int)); } @@ -337,11 +337,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ long tmp_long = 0; if (H5T_SGN_NONE == nsign) { - sscanf(token, "%lu", &tmp_ulong); + HDsscanf(token, "%lu", &tmp_ulong); HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long)); } else { - sscanf(token, "%ld", &tmp_long); + HDsscanf(token, "%ld", &tmp_long); HDmemcpy(cptr, &tmp_long, sizeof(long)); } @@ -354,11 +354,11 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ long long tmp_llong = 0; if (H5T_SGN_NONE == nsign) { - sscanf(token, fmt_ullong, &tmp_ullong); + HDsscanf(token, fmt_ullong, &tmp_ullong); HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long)); } else { - sscanf(token, fmt_llong, &tmp_llong); + HDsscanf(token, fmt_llong, &tmp_llong); HDmemcpy(cptr, &tmp_llong, sizeof(long long)); } @@ -640,6 +640,34 @@ done: return retVal; } /* end h5str_convert */ +/*------------------------------------------------------------------------- + * Function: h5str_sprint_reference + * + * Purpose: Object reference -- show the name of the referenced object. + * + * Return: SUCCEED or FAIL + *------------------------------------------------------------------------- + */ +int +h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf) +{ + hid_t region = H5I_INVALID_HID; + char ref_name[1024]; + const char *path; + + int ret_value = FAIL; + + if ((H5Rget_name(region_obj, H5R_DATASET_REGION, ref_buf, (char *)ref_name, 1024)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (!h5str_append(out_str, ref_name)) + H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); + + ret_value = SUCCEED; +done: + + return ret_value; +} /* h5str_sprint_reference */ + int h5str_region_dataset(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref_buf, int expand_data) { @@ -655,6 +683,10 @@ h5str_region_dataset(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref_b if ((region_sid = H5Rget_region(container, H5R_DATASET_REGION, ref_buf)) < 0) H5_LIBRARY_ERROR(ENVONLY); + if (expand_data == 0) + if (h5str_sprint_reference(ENVONLY, out_str, region_obj, ref_buf) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if ((region_type = H5Sget_select_type(region_sid)) > H5S_SEL_ERROR) { if (H5S_SEL_POINTS == region_type) { if (h5str_dump_region_points(ENVONLY, out_str, region_sid, region_obj, expand_data) < 0) diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index 64913a7..33f1ea7 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -41,6 +41,7 @@ extern void h5str_resize(h5str_t *str, size_t new_len); extern char * h5str_append(h5str_t *str, const char *cstr); extern size_t h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_buf, size_t out_buf_offset); +extern int h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf); extern size_t h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *in_buf, int expand_data); extern void h5str_array_free(char **strs, size_t len); diff --git a/tools/lib/h5tools_ref.c b/tools/lib/h5tools_ref.c index 2adec9f..4effc34 100644 --- a/tools/lib/h5tools_ref.c +++ b/tools/lib/h5tools_ref.c @@ -280,7 +280,7 @@ ref_path_table_gen_fake(const char *path) /*------------------------------------------------------------------------- * Function: lookup_ref_path * - * Purpose: Lookup the path to the object with refernce 'ref'. + * Purpose: Lookup the path to the object with reference 'ref'. * * Return: Return a path to the object, or NULL if not found. * -- cgit v0.12