Skip to content

Commit

Permalink
Merge branch 'static_link_cleanup' into static_link_cleanup_mc
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed Aug 20, 2024
2 parents 602c2e0 + ee463a4 commit 3a1dbbc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
"--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
"--suppress=invalidPointerCast:*/GeoLib.cpp" # TIFFImage.raster is newed on 8 byte boundries, can supress this warning
"--error-exitcode=1"

"--suppress=duplInheritedMember" # Name hiding for functions with the same name

"--suppress=memleak:*/LuaEndpoint.cpp" # line: 254, 'info' is freed by requestThread but ccpcheck does not 'see it'
"--suppress=returnDanglingLifetime:*/LuaLibraryMsg.cpp" # line 198, code is OK
"--suppress=constParameterReference:*/ArrowBuilderImpl.cpp" # List [] const issue
"--suppress=constParameterReference:*/BathyRefractionCorrector.cpp" # in run() param extent cannot be const
"--suppress=constParameterPointer:*/CcsdsPayloadDispatch.cpp" # Not trivial to fix, would have to change DispachObject class as well.
"--suppress=knownConditionTrueFalse" # -1 < 0 etc
)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ BUILD = $(ROOT)/build
########################

all: ## build code
make -j4 -C $(BUILD)
make -j8 -C $(BUILD)

config: prep ## configure make for release version of sliderule
cd $(BUILD); cmake -DCMAKE_BUILD_TYPE=Release $(CFG) $(ROOT)

config-debug: prep
config-debug: prep
cd $(BUILD); cmake -DCMAKE_BUILD_TYPE=Debug -DH5CORO_MAXIMUM_NAME_SIZE=208 $(CFG) $(ROOT)

config-library: prep ## configure make for shared library libsliderule.so
cd $(BUILD); cmake -DCMAKE_BUILD_TYPE=Release -DSHARED_LIBRARY=ON $(CFG) $(ROOT)

Expand Down
28 changes: 5 additions & 23 deletions datasets/bathy/package/BathyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int BathyReader::luaCreate (lua_State* L)
const char* shared_directory = getLuaString(L, 7);
const bool read_sdp_variables = getLuaBoolean(L, 8, true, false);
const bool send_terminator = getLuaBoolean(L, 9, true, true);

/* Build Classifier List */
if(lua_istable(L, classifier_table_index))
{
Expand Down Expand Up @@ -235,10 +235,6 @@ BathyReader::BathyReader (lua_State* L,
bathyMask = new GeoLib::TIFFImage(NULL, GLOBAL_BATHYMETRY_MASK_FILE_PATH);
}

/* Initialize Stats */
memset(&stats, 0, sizeof(stats));
stats.valid = true;

/* Initialize Readers */
active = true;
numComplete = 0;
Expand Down Expand Up @@ -344,12 +340,12 @@ BathyReader::~BathyReader (void)
delete [] sharedDirectory;
delete bathyMask;
delete outQ;

for(int i = 0; i < BathyParms::NUM_CLASSIFIERS; i++)
{
if(classifiers[i]) classifiers[i]->releaseLuaObject();
}

if(parms) parms->releaseLuaObject();
if(uncertainty) uncertainty->releaseLuaObject();
if(refraction) refraction->releaseLuaObject();
Expand Down Expand Up @@ -824,15 +820,7 @@ void* BathyReader::subsettingThread (void* parm)

/* Thread Variables */
vector<BathyParms::extent_t*> extents;
stats_t local_stats = {
.valid = true,
.photon_count = 0,
.subaqueous_photons = 0,
.corrections_duration = 0.0,
.qtrees_duration = 0.0,
.coastnet_duration = 0.0,
.openoceanspp_duration = 0.0
};
stats_t local_stats;

/* Start Trace */
const uint32_t trace_id = start_trace(INFO, reader->traceId, "atl03_subsetter", "{\"asset\":\"%s\", \"resource\":\"%s\", \"track\":%d}", parms->asset->getName(), parms->resource, info->track);
Expand Down Expand Up @@ -1777,7 +1765,7 @@ int BathyReader::luaClassifierEnabled (lua_State* L)
}

/*----------------------------------------------------------------------------
* luaStats - :stats(<with_clear>) --> {<key>=<value>, ...} containing statistics
* luaStats - :stats() --> {<key>=<value>, ...} containing statistics
*----------------------------------------------------------------------------*/
int BathyReader::luaStats (lua_State* L)
{
Expand All @@ -1797,9 +1785,6 @@ int BathyReader::luaStats (lua_State* L)

try
{
/* Get Clear Parameter */
const bool with_clear = getLuaBoolean(L, 2, true, false);

/* Create Statistics Table */
lua_newtable(L);
LuaEngine::setAttrBool(L, "valid", lua_obj->stats.valid);
Expand All @@ -1810,9 +1795,6 @@ int BathyReader::luaStats (lua_State* L)
LuaEngine::setAttrNum(L, "coastnet_duration", lua_obj->stats.coastnet_duration);
LuaEngine::setAttrNum(L, "openoceanspp_duration", lua_obj->stats.openoceanspp_duration);

/* Clear if Requested */
if(with_clear) memset(&lua_obj->stats, 0, sizeof(lua_obj->stats));

/* Set Success */
status = true;
num_obj_to_return = 2;
Expand Down
17 changes: 13 additions & 4 deletions datasets/bathy/package/BathyReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,23 @@ class BathyReader: public LuaObject
*--------------------------------------------------------------------*/

/* Statitics */
typedef struct {
typedef struct Stats {
bool valid;
uint64_t photon_count;
uint64_t subaqueous_photons;
double corrections_duration;
double qtrees_duration;
double coastnet_duration;
double openoceanspp_duration;

Stats (void):
valid(true),
photon_count(0),
subaqueous_photons(0),
corrections_duration(0.0),
qtrees_duration(0.0),
coastnet_duration(0.0),
openoceanspp_duration(0.0) {}
} stats_t;

/*--------------------------------------------------------------------
Expand Down Expand Up @@ -296,10 +305,10 @@ class BathyReader: public LuaObject
static void* subsettingThread (void* parm);

static double calculateBackground (int32_t current_segment, int32_t& bckgrd_in, const Atl03Data& atl03);
static void parseResource (const char* resource, TimeLib::date_t& date,
uint16_t& rgt, uint8_t& cycle, uint8_t& region,
static void parseResource (const char* resource, TimeLib::date_t& date,
uint16_t& rgt, uint8_t& cycle, uint8_t& region,
uint8_t& version);

void findSeaSurface (BathyParms::extent_t& extent);
void writeCSV (const vector<BathyParms::extent_t*>& extents, int spot, const stats_t& local_stats);

Expand Down
4 changes: 2 additions & 2 deletions datasets/bathy/package/BathyRefractionCorrector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ BathyRefractionCorrector::~BathyRefractionCorrector (void)
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
uint64_t BathyRefractionCorrector::run( BathyParms::extent_t& extent,
uint64_t BathyRefractionCorrector::run( BathyParms::extent_t& extent,
const H5Array<float>& ref_el,
const H5Array<float>& ref_az ) const
{
Expand Down Expand Up @@ -200,7 +200,7 @@ uint64_t BathyRefractionCorrector::run( BathyParms::extent_t& extent,
const double dZ = p * sin(beta); // vertical offset
const double dY = p * cos(beta); // cross-track offset
const double dE = dY * sin(static_cast<double>(ref_az[seg])); // UTM offsets
const double dN = dY * cos(static_cast<double>(ref_az[seg]));
const double dN = dY * cos(static_cast<double>(ref_az[seg]));

/* Save Refraction Height Correction */
photons[i].delta_h = dZ;
Expand Down
31 changes: 15 additions & 16 deletions packages/geo/GeoLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ GeoLib::TIFFImage::TIFFImage(lua_State* L, const char* filename, long driver):
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
typesize = 4; // tiff driver only supports uint32_t (RGB)

mlog(INFO, "Reading image %s which is %u x %u pixels", filename, width, height);

size = width * height * typesize;
raster = new uint8_t[size];
raster = new (std::align_val_t(RASTER_DATA_ALIGNMENT)) uint8_t[size];
type = RecordObject::UINT32;

uint32_t* _raster = reinterpret_cast<uint32_t*>(raster);
if(!TIFFReadRGBAImage(tif, width, height, _raster, 0))
{
delete [] raster;
operator delete[](raster, std::align_val_t(RASTER_DATA_ALIGNMENT));
throw RunTimeException(CRITICAL, RTE_ERROR, "failed to read tiff file: %s", filename);
}

Expand All @@ -212,7 +212,7 @@ GeoLib::TIFFImage::TIFFImage(lua_State* L, const char* filename, long driver):
mlog(INFO, "Reading image %s which is %u x %u pixels", filename, width, height);

size = width * height * typesize;
raster = new uint8_t [size];
raster = new (std::align_val_t(RASTER_DATA_ALIGNMENT)) uint8_t[size];
void* _data = const_cast<void*>(reinterpret_cast<const void*>(raster));
const OGRErr err = band->RasterIO(GF_Read, 0, 0, width, height, _data, width, height, dtype, 0, 0);
GDALClose((GDALDatasetH)dataset);
Expand All @@ -232,9 +232,9 @@ GeoLib::TIFFImage::TIFFImage(lua_State* L, const char* filename, long driver):
default: type = RecordObject::INVALID_FIELD; break;
}

if(err != CE_None)
if(err != CE_None)
{
delete [] raster;
operator delete[](raster, std::align_val_t(RASTER_DATA_ALIGNMENT));
throw RunTimeException(CRITICAL, RTE_ERROR, "failed to read tiff file: %s", filename);
}
}
Expand All @@ -249,7 +249,7 @@ GeoLib::TIFFImage::TIFFImage(lua_State* L, const char* filename, long driver):
*----------------------------------------------------------------------------*/
GeoLib::TIFFImage::~TIFFImage(void)
{
delete [] raster;
operator delete[](raster, std::align_val_t(RASTER_DATA_ALIGNMENT));
}

/*----------------------------------------------------------------------------
Expand All @@ -259,32 +259,31 @@ GeoLib::TIFFImage::val_t GeoLib::TIFFImage::getPixel(uint32_t x, uint32_t y)
{
val_t val = {.u64 = INVALID_PIXEL};
const uint32_t offset = ((y * width) + x) * typesize;

if(offset < size)
{
switch(typesize)
{
case 1:
{
uint8_t* valptr = reinterpret_cast<uint8_t*>(&raster[offset]);
val.u8 = *valptr;
val.u8 = raster[offset];
break;
}
case 2:
{
uint16_t* valptr = reinterpret_cast<uint16_t*>(&raster[offset]);
const uint16_t* valptr = reinterpret_cast<uint16_t*>(&raster[offset]);
val.u16 = *valptr;
break;
}
case 4:
{
uint32_t* valptr = reinterpret_cast<uint32_t*>(&raster[offset]);
const uint32_t* valptr = reinterpret_cast<uint32_t*>(&raster[offset]);
val.u32 = *valptr;
break;
}
case 8:
{
uint64_t* valptr = reinterpret_cast<uint64_t*>(&raster[offset]);
const uint64_t* valptr = reinterpret_cast<uint64_t*>(&raster[offset]);
val.u64 = *valptr;
break;
}
Expand Down Expand Up @@ -361,7 +360,7 @@ int GeoLib::TIFFImage::luaPixel (lua_State* L)
case RecordObject::DOUBLE: lua_pushnumber(L, val.f64); break;
default: throw RunTimeException(CRITICAL, RTE_ERROR, "invalid type: %d", type);
}

status = true;
}
catch(const RunTimeException& e)
Expand All @@ -386,7 +385,7 @@ int GeoLib::TIFFImage::luaConvertToBMP (lua_State* L)
{
/* special case conversion of 64-bit floats to scaled 32-bit unsigned ints */
const uint32_t num_elements = lua_obj->width * lua_obj->height;
double* _raster = reinterpret_cast<double*>(lua_obj->raster);
const double* _raster = reinterpret_cast<double*>(lua_obj->raster);
uint32_t* data = new uint32_t [num_elements];
double minval = std::numeric_limits<double>::max();
double maxval = std::numeric_limits<double>::min();
Expand Down Expand Up @@ -423,7 +422,7 @@ int GeoLib::TIFFImage::luaConvertToBMP (lua_State* L)
else
{
/* just use the value as-is if it is 32 bits */
uint32_t* _raster = reinterpret_cast<uint32_t*>(lua_obj->raster);
const uint32_t* _raster = reinterpret_cast<uint32_t*>(lua_obj->raster);
status = GeoLib::writeBMP(_raster, lua_obj->width, lua_obj->height, bmp_filename);
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/geo/GeoLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class GeoLib: public MathLib

class TIFFImage: public LuaObject
{
static const int RASTER_DATA_ALIGNMENT = 8;

public:
static const char* OBJECT_TYPE;
static const char* LUA_META_NAME;
Expand Down
12 changes: 6 additions & 6 deletions packages/geo/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ void initgeo (void)
GeoLib::init();

/* Register GDAL custom error handler */
// #ifdef GDAL_ERROR_REPORTING
void (*fptrGdalErrorHandler)(CPLErr, int, const char *) = GdalErrHandler;
CPLSetErrorHandler(fptrGdalErrorHandler);
// #else
// CPLSetErrorHandler(NULL);
// #endif
#ifdef GDAL_ERROR_REPORTING
void (*fptrGdalErrorHandler)(CPLErr, int, const char*) = GdalErrHandler;
CPLSetErrorHandler(fptrGdalErrorHandler);
#else
CPLSetErrorHandler(NULL);
#endif

/* Extend Lua */
LuaEngine::extend(LUA_GEO_LIBNAME, geo_open);
Expand Down

0 comments on commit 3a1dbbc

Please sign in to comment.