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

Fix h5py testing failure due to invalid datatype IDs #4321

Merged
merged 2 commits into from
Apr 4, 2024
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
27 changes: 19 additions & 8 deletions src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -3394,6 +3394,7 @@ H5T__create(H5T_class_t type, size_t size)
/* Copy the default string datatype */
if (NULL == (dt = H5T_copy(origin_dt, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy");
dt->shared->type = type;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for H5Tcreate with H5T_INTEGER, H5T_FLOAT, H5T_TIME and H5T_STRING weren't setting the new datatype's type to the given type, like the other cases below. This meant that newly-created types in any combination of these four categories could compare equal to each other if their sizes are the same.


/* Modify the datatype */
if (H5T__set_size(dt, size) < 0)
Expand Down Expand Up @@ -4578,6 +4579,8 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, bool superset)
/*
* Compound data types...
*/
if (dt1->shared->u.compnd.nmembs == 0 && dt2->shared->u.compnd.nmembs == 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortcut for comparing two compounds with 0 members. Also avoids a segfault in the debugging code below, but I added a check there to be safe.

HGOTO_DONE(0);
if (dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
HGOTO_DONE(-1);
if (dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
Expand Down Expand Up @@ -4620,11 +4623,13 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, bool superset)

#ifdef H5T_DEBUG
/* I don't quite trust the code above yet :-) --RPM */
for (u = 0; u < dt1->shared->u.compnd.nmembs - 1; u++) {
assert(strcmp(dt1->shared->u.compnd.memb[idx1[u]].name,
dt1->shared->u.compnd.memb[idx1[u + 1]].name));
assert(strcmp(dt2->shared->u.compnd.memb[idx2[u]].name,
dt2->shared->u.compnd.memb[idx2[u + 1]].name));
if (dt1->shared->u.compnd.nmembs > 0) {
for (u = 0; u < dt1->shared->u.compnd.nmembs - 1; u++) {
assert(strcmp(dt1->shared->u.compnd.memb[idx1[u]].name,
dt1->shared->u.compnd.memb[idx1[u + 1]].name));
assert(strcmp(dt2->shared->u.compnd.memb[idx2[u]].name,
dt2->shared->u.compnd.memb[idx2[u + 1]].name));
}
}
#endif

Expand Down Expand Up @@ -4660,6 +4665,8 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, bool superset)
/*
* Enumeration data types...
*/
if (dt1->shared->u.enumer.nmembs == 0 && dt2->shared->u.enumer.nmembs == 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortcut for comparing two enums with 0 members. Also avoids a segfault in the debugging code below, but I added a check there to be safe.

HGOTO_DONE(0);

/* If we are doing a "superset" comparison, dt2 is allowed to have
* more members than dt1
Expand Down Expand Up @@ -4717,9 +4724,13 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, bool superset)

#ifdef H5T_DEBUG
/* I don't quite trust the code above yet :-) --RPM */
for (u = 0; u < dt1->shared->u.enumer.nmembs - 1; u++) {
assert(strcmp(dt1->shared->u.enumer.name[idx1[u]], dt1->shared->u.enumer.name[idx1[u + 1]]));
assert(strcmp(dt2->shared->u.enumer.name[idx2[u]], dt2->shared->u.enumer.name[idx2[u + 1]]));
if (dt1->shared->u.enumer.nmembs > 0) {
for (u = 0; u < dt1->shared->u.enumer.nmembs - 1; u++) {
assert(
strcmp(dt1->shared->u.enumer.name[idx1[u]], dt1->shared->u.enumer.name[idx1[u + 1]]));
assert(
strcmp(dt2->shared->u.enumer.name[idx2[u]], dt2->shared->u.enumer.name[idx2[u + 1]]));
}
}
#endif

Expand Down
Loading
Loading