Skip to content

Commit e78a23e

Browse files
Merge pull request #396 from PeterC-DLS/master
Make check work for copied datatype IDs to fix #386
2 parents 78eecee + a5ba1d9 commit e78a23e

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/napi5.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,7 @@ NXstatus NX5getattra(NXhandle handle, char* name, void* data)
24892489
hid_t memtype_id, filespace, datatype;
24902490
H5T_class_t tclass;
24912491
hsize_t ndims, dims[H5S_MAX_RANK];
2492+
htri_t is_vlen_str = 0; /* false */
24922493
char **vstrdata = NULL;
24932494

24942495
pFile = NXI5assert(handle);
@@ -2508,7 +2509,10 @@ NXstatus NX5getattra(NXhandle handle, char* name, void* data)
25082509
NXReportError("ERROR: unable to read dims");
25092510
return NX_ERROR;
25102511
}
2511-
if (ndims == 0 && H5Tis_variable_str(datatype)) {
2512+
2513+
is_vlen_str = H5Tis_variable_str(datatype);
2514+
if (ndims == 0 && is_vlen_str) {
2515+
/* this assumes a fixed size - is this dangerous? */
25122516
char *strdata = calloc(512, sizeof(char));
25132517
status = H5Aread(pFile->iCurrentA, H5S_ALL, &strdata);
25142518
if (status >= 0)
@@ -2523,7 +2527,7 @@ NXstatus NX5getattra(NXhandle handle, char* name, void* data)
25232527
}
25242528
tclass = H5Tget_class(datatype);
25252529
/* stop gap kludge for fixed length strings */
2526-
if (tclass == H5T_C_S1) {
2530+
if (tclass == H5T_STRING && !is_vlen_str) {
25272531
char *datatmp = NULL;
25282532
status = readStringAttribute(pFile->iCurrentA, &datatmp);
25292533
if (status < 0)
@@ -2535,7 +2539,7 @@ NXstatus NX5getattra(NXhandle handle, char* name, void* data)
25352539

25362540
memset(iStart, 0, H5S_MAX_RANK * sizeof(int));
25372541
/* map datatypes of other plateforms */
2538-
if (H5Tis_variable_str(datatype)) {
2542+
if (is_vlen_str) {
25392543
vstrdata = (char **)malloc((size_t) dims[0] * sizeof(char *));
25402544
memtype_id = H5Tcopy(H5T_C_S1);
25412545
H5Tset_size(memtype_id, H5T_VARIABLE);

test/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ if(WITH_HDF5)
4545
target_link_libraries(napi_test_hdf5 NeXus_Shared_Library
4646
${NAPI_LINK_LIBS})
4747
add_test(NAME "NAPI-C-HDF5-test" COMMAND napi_test_hdf5)
48+
add_executable(napi_attra_test_hdf5 napi_attra_test.c)
49+
target_link_libraries(napi_attra_test_hdf5 NeXus_Shared_Library
50+
${NAPI_LINK_LIBS})
51+
add_test(NAME "NAPI-C-HDF5-attra-test" COMMAND napi_attra_test_hdf5)
4852
endif()
4953

5054
if(WITH_HDF4)
@@ -53,6 +57,10 @@ if(WITH_HDF4)
5357
${NAPI_LINK_LIBS})
5458
add_test(NAME "NAPI-C-HDF4-test"
5559
COMMAND napi_test_hdf4)
60+
add_executable(napi_attra_test_hdf4 napi_attra_test.c)
61+
target_link_libraries(napi_attra_test_hdf4 NeXus_Shared_Library
62+
${NAPI_LINK_LIBS})
63+
add_test(NAME "NAPI-C-HDF4-attra-test" COMMAND napi_attra_test_hdf4)
5664
endif()
5765

5866
if(WITH_MXML)
@@ -66,6 +74,10 @@ if(WITH_MXML)
6674
${NAPI_LINK_LIBS})
6775
add_test(NAME "NAPI-C-MXML-TABLE-test"
6876
COMMAND napi_test-xml-table)
77+
add_executable(napi_attra_test_xml napi_attra_test.c)
78+
target_link_libraries(napi_attra_test_xml NeXus_Shared_Library
79+
${NAPI_LINK_LIBS})
80+
add_test(NAME "NAPI-C-MXML-attra-test" COMMAND napi_attra_test_xml)
6981
endif()
7082

7183
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)