Hello,
I’ve searched the group and found a few references to writing compound data types with variable length character strings to a packet table. Taking all those into account, I think that I’ve implemented a test case correctly, but I keep getting a segfault when appending to a packet table. Below is the simple main() that fails at H5PTappend(). Hopefully someone can offer some insight as to why it is failing. I’m using the stock version of HDF5 (v1.10.5-4) that comes with CEntOS 8.x so I think this version should allow for variable length packet tables. Any help/insight would be appreciated.
Thanks,
#include "hdf5.h"
#include "hdf5_hl.h"
typedef struct v_moddata_t {
hvl_t cLogHandle;
} v_moddata_t;
//
// Test program
//
int main(int argc, char **argv) {
hid_t iErr = 0;
char cFileName[] = "Testing.hd5";
printf("Test HDF5 File: %s\n",cFileName);
//
// Open HDF5 file for export
hid_t hidFileID = H5Fcreate(cFileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
printf(" Dumping vpacket table\n");
//
// Attempt to open the revision history packet table
hid_t hidPTableID = H5PTopen(hidFileID, "VRevision History");
//
// If there is an error attempt to create a fixed length packet table
if( hidPTableID == H5I_BADID ) {
//
// Create copy of native character type
hid_t hidCharLenVarTypeID = H5Tcopy(H5T_C_S1);
//
// Set size of character type
H5Tset_size(hidCharLenVarTypeID, H5T_VARIABLE);
//
// Create memory data type for compound data
hid_t hidModDataTypeID = H5Tcreate(H5T_COMPOUND, sizeof(v_moddata_t));
H5Tinsert(hidModDataTypeID, "log", HOFFSET(v_moddata_t, cLogHandle), hidCharLenVarTypeID);
H5Tpack(hidModDataTypeID);
//
// Create packet table
hidPTableID = H5PTcreate(hidFileID, "VRevision History", hidModDataTypeID, 100, H5P_DEFAULT);
// hidPTableID = H5PTcreate_fl(hidFileID, "VRevision History", hidModDataTypeID, (hid_t) 100, -1);
//
// Free resources
H5Tclose(hidModDataTypeID);
H5Tclose(hidCharLenVarTypeID);
//
// Check for error and return
if( hidPTableID == H5I_INVALID_HID ) return 1;
// if( hidPTableID == H5I_BADID ) return 1;
}
//
// Fill data type
v_moddata_t modDat;
modDat.cLogHandle.len = 16;
modDat.cLogHandle.p = (void *) "Some stuff here\0";
printf("String %i - '%s'\n", (int) modDat.cLogHandle.len, (char *) modDat.cLogHandle.p);
//
// Append data to packet table
iErr = H5PTappend(hidPTableID, (size_t) 1, &modDat);
//
// Close packet table
iErr = H5PTclose(hidPTableID);
//
// Close file
iErr = H5Fclose(hidFileID);
return 0;
}