Skip to content

Commit

Permalink
Fix 32-bit build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney committed Feb 25, 2023
1 parent 0d3e964 commit db2e0a8
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 12 deletions.
4 changes: 3 additions & 1 deletion include/E57SimpleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ namespace e57
PointStandardizedFieldsAvailable pointFields;

/// The number of points in the Data3D.
int64_t pointCount = 0;
/// On 32-bit systems size_t will allow for 4,294,967,295 points per scan which seems
/// reasonable...
size_t pointCount = 0;
};

/// @brief Stores pointers to user-provided buffers
Expand Down
2 changes: 1 addition & 1 deletion include/E57SimpleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace e57
/// "points" data vector for the groups
/// @param [out] pointCount pointer to the buffer holding size of the groups given
/// @return Return true if successful, false otherwise
bool ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
bool ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
int64_t *startPointIndex, int64_t *pointCount ) const;

/// @brief Use this to read the actual 3D data
Expand Down
2 changes: 1 addition & 1 deletion include/E57SimpleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace e57
/// for the groups
/// @param [in] pointCount buffer with sizes of the groups given
/// @return Return true if successful, false otherwise
bool WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
bool WriteData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
int64_t *startPointIndex, int64_t *pointCount );

///@}
Expand Down
7 changes: 7 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
#define VALIDATE_BASIC ( E57_VALIDATION_LEVEL > VALIDATION_OFF )
#define VALIDATE_DEEP ( E57_VALIDATION_LEVEL > VALIDATION_BASIC )

// Determine if we are building 32 or 64 bit
#if SIZE_MAX == UINT32_MAX
#define E57_32_BIT
#elif SIZE_MAX == UINT64_MAX
#define E57_64_BIT
#endif

namespace e57
{
#define E57_EXCEPTION1( ecode ) \
Expand Down
5 changes: 2 additions & 3 deletions src/E57SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ namespace e57
bColumnIndex );
}

bool Reader::ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount,
int64_t *idElementValue, int64_t *startPointIndex,
int64_t *pointCount ) const
bool Reader::ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
int64_t *startPointIndex, int64_t *pointCount ) const
{
return impl_->ReadData3DGroupsData( dataIndex, groupCount, idElementValue, startPointIndex,
pointCount );
Expand Down
4 changes: 2 additions & 2 deletions src/E57SimpleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace
( pointFields.timeMinimum == cMin ) && ( pointFields.timeMaximum == cMax );

// Now run through the points and set the things we need to
for ( int64_t i = 0; i < ioData3DHeader.pointCount; ++i )
for ( size_t i = 0; i < ioData3DHeader.pointCount; ++i )
{
if ( writePointRange && pointFields.cartesianXField )
{
Expand Down Expand Up @@ -267,7 +267,7 @@ namespace e57
return impl_->SetUpData3DPointsData( dataIndex, pointCount, buffers );
}

bool Writer::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount,
bool Writer::WriteData3DGroupsData( int64_t dataIndex, size_t groupCount,
int64_t *idElementValue, int64_t *startPointIndex,
int64_t *pointCount )
{
Expand Down
20 changes: 19 additions & 1 deletion src/ReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,25 @@ namespace e57
const StructureNode proto( points.prototype() );

data3DHeader.guid = StringNode( scan.get( "guid" ) ).value();

#ifdef E57_32_BIT
// If we exceed the size_t max, only process the max (4,294,967,295 points).
if ( points.childCount() > static_cast<int64_t>( std::numeric_limits<size_t>::max() ) )
{
data3DHeader.pointCount = std::numeric_limits<size_t>::max();

std::cout << "Warning (32-bit): Point count (" << points.childCount()
<< ") exceeds storage capacity (" << std::numeric_limits<size_t>::max()
<< "). Dropping " << points.childCount() - std::numeric_limits<size_t>::max()
<< " points from scan." << std::endl;
}
else
{
data3DHeader.pointCount = static_cast<size_t>( points.childCount() );
}
#else
data3DHeader.pointCount = points.childCount();
#endif

if ( scan.isDefined( "name" ) )
{
Expand Down Expand Up @@ -1478,7 +1496,7 @@ namespace e57
}

// Reads the group data
bool ReaderImpl::ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount,
bool ReaderImpl::ReadData3DGroupsData( int64_t dataIndex, size_t groupCount,
int64_t *idElementValue, int64_t *startPointIndex,
int64_t *pointCount ) const
{
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace e57
int64_t &pointsSize, int64_t &groupsSize, int64_t &countSize,
bool &bColumnIndex ) const;

bool ReadData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
bool ReadData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
int64_t *startPointIndex, int64_t *pointCount ) const;

template <typename COORDTYPE>
Expand Down
2 changes: 1 addition & 1 deletion src/WriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ namespace e57
int64_t dataIndex, size_t pointCount, const Data3DPointsData_t<double> &buffers );

// This function writes out the group data
bool WriterImpl::WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount,
bool WriterImpl::WriteData3DGroupsData( int64_t dataIndex, size_t groupCount,
int64_t *idElementValue, int64_t *startPointIndex,
int64_t *pointCount )
{
Expand Down
2 changes: 1 addition & 1 deletion src/WriterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace e57
CompressedVectorWriter SetUpData3DPointsData( int64_t dataIndex, size_t pointCount,
const Data3DPointsData_t<COORDTYPE> &buffers );

bool WriteData3DGroupsData( int64_t dataIndex, int64_t groupCount, int64_t *idElementValue,
bool WriteData3DGroupsData( int64_t dataIndex, size_t groupCount, int64_t *idElementValue,
int64_t *startPointIndex, int64_t *pointCount );

StructureNode GetRawE57Root();
Expand Down

0 comments on commit db2e0a8

Please sign in to comment.