Skip to content

Commit

Permalink
memset removed, info.data newed with 8 byte alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
elidwa committed Jul 22, 2024
1 parent 33b11e8 commit 1694afd
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/h5/H5Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ bool H5Array<T>::join(int timeout, bool throw_exception)
/*
* There is no way to do this in a portable "safe" way. The code
* below works because our target architectures are x86_64 and aarch64.
* The data pointed to by info.data is new'ed and therefore guaranteed
* to be aligned to a 16 byte boundary. The calling code is responsible
* for knowing what the data being read out of the h5 file is and
* The data pointed to by info.data is new'ed with H5CORO_DATA_ALIGNMENT alignment.
* The calling code is responsible for knowing
* what the data being read out of the h5 file is and
* providing the correct type to the template.
*/
data = reinterpret_cast<T*>(h5f->info.data);
Expand Down
17 changes: 7 additions & 10 deletions packages/h5/H5Coro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ H5Coro::Future::Future (void)
H5Coro::Future::~Future (void)
{
wait(IO_PEND);
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
}

/*----------------------------------------------------------------------------
Expand Down Expand Up @@ -456,9 +456,6 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
{
info_t info;

memset(&info, 0, sizeof(info_t));
info.datatype = RecordObject::INVALID_FIELD;

/* Start Trace */
const uint32_t trace_id = start_trace(INFO, parent_trace_id, "h5coro_read", "{\"context\":\"%s\", \"dataset\":\"%s\"}", context->name, datasetname);

Expand All @@ -472,7 +469,7 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
if(valtype == RecordObject::INTEGER)
{
/* Allocate Buffer of Integers */
long* tbuf = new long [info.elements];
long* tbuf = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) long [info.elements];

/* Float to Long */
if(info.datatype == RecordObject::FLOAT)
Expand Down Expand Up @@ -585,15 +582,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
}

/* Switch Buffers */
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = reinterpret_cast<uint8_t*>(tbuf);
info.datasize = sizeof(long) * info.elements;
}
/* Perform Integer Type Transaltion */
else if(valtype == RecordObject::REAL)
{
/* Allocate Buffer of Integers */
double* tbuf = new double [info.elements];
/* Allocate Buffer of doubles */
double* tbuf = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) double [info.elements];

/* Float to Double */
if(info.datatype == RecordObject::FLOAT)
Expand Down Expand Up @@ -688,15 +685,15 @@ H5Coro::info_t H5Coro::read (Context* context, const char* datasetname, RecordOb
}

/* Switch Buffers */
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = reinterpret_cast<uint8_t*>(tbuf);
info.datasize = sizeof(double) * info.elements;
}

/* Check Data Valid */
if(!data_valid)
{
delete [] info.data;
operator delete[](info.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info.data = NULL;
info.datasize = 0;
throw RunTimeException(CRITICAL, RTE_ERROR, "data translation failed for %s: [%d] %d --> %d", datasetname, info.typesize, (int)info.datatype, (int)valtype);
Expand Down
6 changes: 5 additions & 1 deletion packages/h5/H5Coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
#define H5CORO_ENABLE_FILL false
#endif

#ifndef H5CORO_DATA_ALIGNMENT
#define H5CORO_DATA_ALIGNMENT 8
#endif

/******************************************************************************
* MACRO
******************************************************************************/
Expand Down Expand Up @@ -99,7 +103,7 @@ namespace H5Coro
uint32_t elements; // number of elements in dataset
uint32_t typesize; // number of bytes per element
uint64_t datasize; // total number of bytes in dataset
uint8_t* data; // point to allocated data buffer
uint8_t* data; // point to allocated data buffer - must be H5CORO_DATA_ALIGNMENT aligned
RecordObject::fieldType_t datatype; // data type of elements
int64_t shape[MAX_NDIMS]; // dimensions of the data
} info_t;
Expand Down
4 changes: 2 additions & 2 deletions packages/h5/H5Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ H5Dataset::H5Dataset (info_t* info, Context* context,
catch(const RunTimeException& e)
{
/* Clean Up Data Allocations */
delete [] info->data;
operator delete [] (info->data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
info->data= NULL;
info->datasize = 0;

Expand Down Expand Up @@ -319,7 +319,7 @@ void H5Dataset::readDataset (info_t* info)
const int64_t extra_space_for_terminator = (metaData.type == STRING_TYPE);

/* Allocate */
buffer = new uint8_t [buffer_size + extra_space_for_terminator];
buffer = new (std::align_val_t(H5CORO_DATA_ALIGNMENT)) uint8_t [buffer_size + extra_space_for_terminator];

/* Gaurantee Termination of String */
if(metaData.type == STRING_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion packages/h5/H5DatasetDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool H5DatasetDevice::isConnected (int num_open)
void H5DatasetDevice::closeConnection (void)
{
connected = false;
delete [] dataBuffer;
operator delete[](dataBuffer, std::align_val_t(H5CORO_DATA_ALIGNMENT));
dataBuffer = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/h5/H5File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void* H5File::readThread (void* parm)
}

/* Clean Up Result Data */
delete [] results.data;
operator delete[](results.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
}

/* Clean Up Thread Info */
Expand Down
4 changes: 2 additions & 2 deletions plugins/icesat2/plugin/MeritRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RasterObject* MeritRaster::create(lua_State* L, GeoParms* _parms)
*----------------------------------------------------------------------------*/
MeritRaster::~MeritRaster(void)
{
delete [] cache;
operator delete[](cache, std::align_val_t(H5CORO_DATA_ALIGNMENT));
if(asset) asset->releaseLuaObject();
}

Expand Down Expand Up @@ -180,7 +180,7 @@ uint32_t MeritRaster::getSamples (const MathLib::point_3d_t& point, int64_t gps,
/* Update Cache */
cacheMut.lock();
{
delete [] cache;
operator delete[](cache, std::align_val_t(H5CORO_DATA_ALIGNMENT));
cache = tile;
cacheLon = left_lon;
cacheLat = upper_lat;
Expand Down
2 changes: 1 addition & 1 deletion plugins/swot/plugin/SwotL2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void* SwotL2Reader::varThread (void* parm)
reader->checkComplete();

/* Clean Up */
delete [] results.data;
operator delete[](results.data, std::align_val_t(H5CORO_DATA_ALIGNMENT));
delete [] info->variable_name;
delete info;

Expand Down
3 changes: 2 additions & 1 deletion project-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
"--suppress=unreadVariable:*/TimeLib.cpp" # line: 471, terminating '\0' detected as 'unused' but it is used/needed
"--suppress=invalidPointerCast:*/H5Array.h" # line: 166, documented in code
"--suppress=invalidPointerCast:*/H5Element.h" # line: 141, documented in code
"--suppress=invalidPointerCast:*/H5Coro.cpp" # info.data (uint8_t* being cast to float/double ptrs. Allignments issues)
"--suppress=invalidPointerCast:*/H5Coro.cpp" # info.data is newed on 8 byte boundries, can supress this warning
"--suppress=uninitvar:*/H5Coro.cpp" # info
"--suppress=copyCtorPointerCopying:*/MsgQ.cpp" # line: 120, shallow copy which is fine in code
"--error-exitcode=1"

Expand Down

0 comments on commit 1694afd

Please sign in to comment.