-
-
Notifications
You must be signed in to change notification settings - Fork 266
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) Segmentation fault when using a compound type. #143
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bdf9ae1
(fix) Segmentation fault when using a compound type.
b502f35
(fix) Removed undesired comment lines.
913bf9b
(fix) Segmentation fault when using a compound type: added test.
d99f20a
(fix) Added the missing cmpd_transform.c file to MANIFEST.
022c7ce
(fix) cmpd_dtransform test: autotools and source header.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,7 @@ set (H5_TESTS | |
thread_id # special link | ||
vol | ||
timer | ||
cmpd_dtransform | ||
) | ||
|
||
macro (ADD_H5_EXE file) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* Copyright by The HDF Group. * | ||
* Copyright by the Board of Trustees of the University of Illinois. * | ||
* All rights reserved. * | ||
* * | ||
* This file is part of HDF5. The full HDF5 copyright notice, including * | ||
* terms governing use, modification, and redistribution, is contained in * | ||
* the files COPYING and Copyright.html. COPYING can be found at the root * | ||
* of the source code distribution tree; Copyright.html can be found at the * | ||
* root level of an installed copy of the electronic HDF5 document set and * | ||
* is linked from the top-level documents page. It can also be found at * | ||
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * | ||
* access to either file, you may request a copy from help@hdfgroup.org. * | ||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
|
||
/* | ||
* Programmer: Jan-Willem Blokland | ||
* December 1, 2020 | ||
* | ||
* Purpose: Test writing compounded attribute followed by | ||
* writing data with a data transform functiun. | ||
*/ | ||
|
||
#include "h5test.h" | ||
|
||
#define FILENAME "cmpd_dtransform.h5" | ||
#define LENGTH 11 | ||
|
||
typedef struct { | ||
char name[64]; | ||
char unit[64]; | ||
} att_t; | ||
|
||
int | ||
main(void) | ||
{ | ||
hsize_t dima[] = { 1 }; | ||
hsize_t dims[] = { LENGTH }; | ||
hid_t str_dtyp_id, att_dtyp_id, file_id, fspace_id, dset_id, att_dspc_id, att_attr_id, dxpl_id; | ||
|
||
/* Compound datatype */ | ||
att_t *atts = HDmalloc(sizeof(att_t)); | ||
HDstrcpy(atts[0].name, "Name"); | ||
HDstrcpy(atts[0].unit, "Unit"); | ||
|
||
/* String type */ | ||
if ((str_dtyp_id = H5Tcopy(H5T_C_S1)) < 0) | ||
TEST_ERROR; | ||
H5Tset_size(str_dtyp_id, 64); | ||
|
||
/* Attribute type */ | ||
if ((att_dtyp_id = H5Tcreate(H5T_COMPOUND, sizeof(att_t))) < 0) | ||
TEST_ERROR; | ||
H5Tinsert(att_dtyp_id, "NAME", HOFFSET(att_t, name), str_dtyp_id); | ||
H5Tinsert(att_dtyp_id, "UNIT", HOFFSET(att_t, unit), str_dtyp_id); | ||
|
||
/* Create file. */ | ||
if ((file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) | ||
TEST_ERROR; | ||
|
||
/* Create file dataspace. */ | ||
if ((fspace_id = H5Screate_simple(1, dims, NULL)) < 0) | ||
TEST_ERROR; | ||
|
||
/* Create dataset. */ | ||
if ((dset_id = H5Dcreate2(file_id, "test_dset", H5T_NATIVE_INT, fspace_id, | ||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) | ||
TEST_ERROR; | ||
|
||
/* Write the attribute (compound) to the dataset */ | ||
if ((att_dspc_id = H5Screate_simple(1, dima, NULL)) < 0) | ||
TEST_ERROR; | ||
if ((att_attr_id = H5Acreate2(dset_id, "ATTRIBUTES", att_dtyp_id, att_dspc_id, | ||
H5P_DEFAULT, H5P_DEFAULT)) < 0) | ||
TEST_ERROR; | ||
if (H5Awrite(att_attr_id, att_dtyp_id, atts) < 0) | ||
TEST_ERROR; | ||
|
||
/* Create dataset transfer property list */ | ||
const char *expr = "2*x"; | ||
if ((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) | ||
TEST_ERROR; | ||
if (H5Pset_data_transform(dxpl_id, expr) < 0) { | ||
HDprintf("**** ERROR: H5Pset_data_transform (expression: %s) ****\n", expr); | ||
TEST_ERROR; | ||
} | ||
|
||
int *data = HDmalloc(LENGTH * sizeof(int)); | ||
int *data_res = HDmalloc(LENGTH * sizeof(int)); | ||
for (unsigned i = 0; i < LENGTH; i++) { | ||
data[i] = 10; | ||
data_res[i] = 2 * data[i]; | ||
} | ||
|
||
/* Write the data */ | ||
if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id, data) < 0) | ||
TEST_ERROR; | ||
|
||
/* Read attribute */ | ||
att_t *atts_res =HDmalloc(sizeof(att_t)); | ||
if (H5Aread(att_attr_id, att_dtyp_id, atts_res) < 0) | ||
TEST_ERROR; | ||
|
||
/* Verify attribute */ | ||
if (HDstrcmp(atts_res[0].name, atts[0].name) != 0) | ||
TEST_ERROR; | ||
if (HDstrcmp(atts_res[0].unit, atts[0].unit) != 0) | ||
TEST_ERROR; | ||
|
||
/* Read the data */ | ||
if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) | ||
TEST_ERROR; | ||
|
||
/* Verify data */ | ||
for (unsigned idx = 0; idx < LENGTH; idx++) { | ||
if (data[idx] != data_res[idx]) | ||
TEST_ERROR; | ||
} | ||
|
||
HDfree(atts); | ||
HDfree(atts_res); | ||
HDfree(data); | ||
HDfree(data_res); | ||
|
||
/* Close all identifiers. */ | ||
H5Pclose(dxpl_id); | ||
H5Aclose(att_attr_id); | ||
H5Sclose(att_dspc_id); | ||
H5Dclose(dset_id); | ||
H5Sclose(fspace_id); | ||
H5Fclose(file_id); | ||
H5Tclose(att_dtyp_id); | ||
H5Tclose(str_dtyp_id); | ||
|
||
return 0; | ||
|
||
error: | ||
return 1; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HDF Group copyright header has changed, and the line "* Copyright by the Board of Trustees of the University of Illinois." applies only to files created before 2007.
The text in the paragraph has changed and the link that is now for the COPYING file also needs updating in all of the HDF5 source files, which will be happening within a few days, so it isn't necessary to make changes for this pull request, especiallly since pasting it here made format changes. Once that update is done, this header will be replaced with the following:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright by The HDF Group. *
All rights reserved. *
This file is part of HDF5. The full HDF5 copyright notice, including *
terms governing use, modification, and redistribution, is contained in *
the COPYING file, which can be found at the root of the source code *
distribution tree, or in https://www.hdfgroup.org/licenses. *
If you do not have access to either file, you may request a copy from *
help@hdfgroup.org. *
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the source header to the latest version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!