Commit b81646d4 authored by Brad King's avatar Brad King Committed by Code Review
Browse files

Merge topic 'byte-swap-size_t' into master

7db71e5c vtkXML(DataParser|Writer): Use size_t in PerformByteSwap
51335bc0 vtkByteSwap: Use size_t for buffer length arguments
parents 8d408a33 7db71e5c
......@@ -66,7 +66,7 @@ VTK_TEMPLATE_SPECIALIZE struct vtkByteSwapper<8>
//----------------------------------------------------------------------------
// Define range swap functions.
template <class T> inline void vtkByteSwapRange(T* first, vtkIdType num)
template <class T> inline void vtkByteSwapRange(T* first, size_t num)
{
// Swap one value at a time.
T* last = first + num;
......@@ -75,21 +75,21 @@ template <class T> inline void vtkByteSwapRange(T* first, vtkIdType num)
vtkByteSwapper<sizeof(T)>::Swap(reinterpret_cast<char*>(p));
}
}
inline bool vtkByteSwapRangeWrite(const char* first, vtkIdType num,
inline bool vtkByteSwapRangeWrite(const char* first, size_t num,
FILE* f, int)
{
// No need to swap segments of 1 byte.
size_t status=fwrite(first, sizeof(char), static_cast<size_t>(num), f);
return status==static_cast<size_t>(num);
}
inline bool vtkByteSwapRangeWrite(const signed char* first, vtkIdType num,
inline bool vtkByteSwapRangeWrite(const signed char* first, size_t num,
FILE* f, int)
{
// No need to swap segments of 1 byte.
size_t status=fwrite(first, sizeof(signed char),static_cast<size_t>(num),f);
return status==static_cast<size_t>(num);
}
inline bool vtkByteSwapRangeWrite(const unsigned char* first, vtkIdType num,
inline bool vtkByteSwapRangeWrite(const unsigned char* first, size_t num,
FILE* f, int)
{
// No need to swap segments of 1 byte.
......@@ -97,7 +97,7 @@ inline bool vtkByteSwapRangeWrite(const unsigned char* first, vtkIdType num,
return status==static_cast<size_t>(num);
}
template <class T>
inline bool vtkByteSwapRangeWrite(const T* first, vtkIdType num, FILE* f, long)
inline bool vtkByteSwapRangeWrite(const T* first, size_t num, FILE* f, long)
{
// Swap and write one value at a time. We do not need to do this in
// blocks because the file stream is already buffered.
......@@ -113,28 +113,28 @@ inline bool vtkByteSwapRangeWrite(const T* first, vtkIdType num, FILE* f, long)
}
return result;
}
inline void vtkByteSwapRangeWrite(const char* first, vtkIdType num,
inline void vtkByteSwapRangeWrite(const char* first, size_t num,
ostream* os, int)
{
// No need to swap segments of 1 byte.
os->write(first, num*static_cast<vtkIdType>(sizeof(char)));
os->write(first, num*static_cast<size_t>(sizeof(char)));
}
inline void vtkByteSwapRangeWrite(const signed char* first, vtkIdType num,
inline void vtkByteSwapRangeWrite(const signed char* first, size_t num,
ostream* os, int)
{
// No need to swap segments of 1 byte.
os->write(reinterpret_cast<const char*>(first),
num*static_cast<vtkIdType>(sizeof(signed char)));
num*static_cast<size_t>(sizeof(signed char)));
}
inline void vtkByteSwapRangeWrite(const unsigned char* first, vtkIdType num,
inline void vtkByteSwapRangeWrite(const unsigned char* first, size_t num,
ostream* os, int)
{
// No need to swap segments of 1 byte.
os->write(reinterpret_cast<const char*>(first),
num*static_cast<vtkIdType>(sizeof(unsigned char)));
num*static_cast<size_t>(sizeof(unsigned char)));
}
template <class T>
inline void vtkByteSwapRangeWrite(const T* first, vtkIdType num,
inline void vtkByteSwapRangeWrite(const T* first, size_t num,
ostream* os, long)
{
// Swap and write one value at a time. We do not need to do this in
......@@ -153,15 +153,15 @@ inline void vtkByteSwapRangeWrite(const T* first, vtkIdType num,
// Define swap functions for each endian-ness.
#if defined(VTK_WORDS_BIGENDIAN)
template <class T> inline void vtkByteSwapBE(T*) {}
template <class T> inline void vtkByteSwapBERange(T*, vtkIdType) {}
template <class T> inline void vtkByteSwapBERange(T*, size_t) {}
template <class T>
inline bool vtkByteSwapBERangeWrite(const T* p, vtkIdType num, FILE* f)
inline bool vtkByteSwapBERangeWrite(const T* p, size_t num, FILE* f)
{
size_t status=fwrite(p, sizeof(T), static_cast<size_t>(num), f);
return status==static_cast<size_t>(num);
}
template <class T>
inline void vtkByteSwapBERangeWrite(const T* p, vtkIdType num, ostream* os)
inline void vtkByteSwapBERangeWrite(const T* p, size_t num, ostream* os)
{
os->write((char*)p, sizeof(T)*num);
}
......@@ -169,17 +169,17 @@ template <class T> inline void vtkByteSwapLE(T* p)
{
vtkByteSwapper<sizeof(T)>::Swap(reinterpret_cast<char*>(p));
}
template <class T> inline void vtkByteSwapLERange(T* p, vtkIdType num)
template <class T> inline void vtkByteSwapLERange(T* p, size_t num)
{
vtkByteSwapRange(p, num);
}
template <class T>
inline bool vtkByteSwapLERangeWrite(const T* p, vtkIdType num, FILE* f)
inline bool vtkByteSwapLERangeWrite(const T* p, size_t num, FILE* f)
{
return vtkByteSwapRangeWrite(p, num, f, 1);
}
template <class T>
inline void vtkByteSwapLERangeWrite(const T* p, vtkIdType num, ostream* os)
inline void vtkByteSwapLERangeWrite(const T* p, size_t num, ostream* os)
{
vtkByteSwapRangeWrite(p, num, os, 1);
}
......@@ -188,51 +188,51 @@ template <class T> inline void vtkByteSwapBE(T* p)
{
vtkByteSwapper<sizeof(T)>::Swap(reinterpret_cast<char*>(p));
}
template <class T> inline void vtkByteSwapBERange(T* p, vtkIdType num)
template <class T> inline void vtkByteSwapBERange(T* p, size_t num)
{
vtkByteSwapRange(p, num);
}
template <class T>
inline bool vtkByteSwapBERangeWrite(const T* p, vtkIdType num, FILE* f)
inline bool vtkByteSwapBERangeWrite(const T* p, size_t num, FILE* f)
{
return vtkByteSwapRangeWrite(p, num, f, 1);
}
template <class T>
inline void vtkByteSwapBERangeWrite(const T* p, vtkIdType num, ostream* os)
inline void vtkByteSwapBERangeWrite(const T* p, size_t num, ostream* os)
{
vtkByteSwapRangeWrite(p, num, os, 1);
}
template <class T> inline void vtkByteSwapLE(T*) {}
template <class T> inline void vtkByteSwapLERange(T*, vtkIdType) {}
template <class T> inline void vtkByteSwapLERange(T*, size_t) {}
template <class T>
inline bool vtkByteSwapLERangeWrite(const T* p, vtkIdType num, FILE* f)
inline bool vtkByteSwapLERangeWrite(const T* p, size_t num, FILE* f)
{
size_t status=fwrite(p, sizeof(T), static_cast<size_t>(num), f);
return status==static_cast<size_t>(num);
}
template <class T>
inline void vtkByteSwapLERangeWrite(const T* p, vtkIdType num, ostream* os)
inline void vtkByteSwapLERangeWrite(const T* p, size_t num, ostream* os)
{
os->write(reinterpret_cast<const char*>(p),
static_cast<vtkIdType>(sizeof(T))*num);
static_cast<size_t>(sizeof(T))*num);
}
#endif
//----------------------------------------------------------------------------
#define VTK_BYTE_SWAP_IMPL(T) \
void vtkByteSwap::SwapLE(T* p) { vtkByteSwapLE(p); } \
void vtkByteSwap::SwapBE(T* p) { vtkByteSwapBE(p); } \
void vtkByteSwap::SwapLERange(T* p, vtkIdType num) \
{ vtkByteSwapLERange(p, num); } \
void vtkByteSwap::SwapBERange(T* p, vtkIdType num) \
{ vtkByteSwapBERange(p, num); } \
bool vtkByteSwap::SwapLERangeWrite(const T* p, vtkIdType num, FILE* file) \
{ return vtkByteSwapLERangeWrite(p, num, file); } \
bool vtkByteSwap::SwapBERangeWrite(const T* p, vtkIdType num, FILE* file) \
{ return vtkByteSwapBERangeWrite(p, num, file); } \
void vtkByteSwap::SwapLERangeWrite(const T* p, vtkIdType num, ostream* os) \
{ vtkByteSwapLERangeWrite(p, num, os); } \
void vtkByteSwap::SwapBERangeWrite(const T* p, vtkIdType num, ostream* os) \
#define VTK_BYTE_SWAP_IMPL(T) \
void vtkByteSwap::SwapLE(T* p) { vtkByteSwapLE(p); } \
void vtkByteSwap::SwapBE(T* p) { vtkByteSwapBE(p); } \
void vtkByteSwap::SwapLERange(T* p, size_t num) \
{ vtkByteSwapLERange(p, num); } \
void vtkByteSwap::SwapBERange(T* p, size_t num) \
{ vtkByteSwapBERange(p, num); } \
bool vtkByteSwap::SwapLERangeWrite(const T* p, size_t num, FILE* file) \
{ return vtkByteSwapLERangeWrite(p, num, file); } \
bool vtkByteSwap::SwapBERangeWrite(const T* p, size_t num, FILE* file) \
{ return vtkByteSwapBERangeWrite(p, num, file); } \
void vtkByteSwap::SwapLERangeWrite(const T* p, size_t num, ostream* os) \
{ vtkByteSwapLERangeWrite(p, num, os); } \
void vtkByteSwap::SwapBERangeWrite(const T* p, size_t num, ostream* os) \
{ vtkByteSwapBERangeWrite(p, num, os); }
VTK_BYTE_SWAP_IMPL(float)
VTK_BYTE_SWAP_IMPL(double)
......@@ -279,22 +279,22 @@ typedef double vtkByteSwapType8;
{ vtkByteSwap::SwapLE(static_cast<vtkByteSwapType##S*>(p)); } \
void vtkByteSwap::Swap##S##BE(void* p) \
{ vtkByteSwap::SwapBE(static_cast<vtkByteSwapType##S*>(p)); } \
void vtkByteSwap::Swap##S##LERange(void* p, int n) \
void vtkByteSwap::Swap##S##LERange(void* p, size_t n) \
{ vtkByteSwap::SwapLERange(static_cast<vtkByteSwapType##S*>(p), n); } \
void vtkByteSwap::Swap##S##BERange(void* p, int n) \
void vtkByteSwap::Swap##S##BERange(void* p, size_t n) \
{ vtkByteSwap::SwapBERange(static_cast<vtkByteSwapType##S*>(p), n); } \
bool vtkByteSwap::SwapWrite##S##LERange(const void* p, int n, FILE* f) \
{ return vtkByteSwap::SwapLERangeWrite(static_cast<const vtkByteSwapType##S*>(p), \
n, f); } \
bool vtkByteSwap::SwapWrite##S##BERange(const void* p, int n, FILE* f) \
{ return vtkByteSwap::SwapBERangeWrite(static_cast<const vtkByteSwapType##S*>(p), \
n, f); } \
void vtkByteSwap::SwapWrite##S##LERange(const void* p, int n, ostream* os) \
{ vtkByteSwap::SwapLERangeWrite(static_cast<const vtkByteSwapType##S*>(p), \
n, os); } \
void vtkByteSwap::SwapWrite##S##BERange(const void* p, int n, ostream* os) \
{ vtkByteSwap::SwapBERangeWrite(static_cast<const vtkByteSwapType##S*>(p), \
n, os); }
bool vtkByteSwap::SwapWrite##S##LERange(void const* p, size_t n, FILE* f) \
{ return vtkByteSwap::SwapLERangeWrite( \
static_cast<const vtkByteSwapType##S*>(p), n, f); } \
bool vtkByteSwap::SwapWrite##S##BERange(void const* p, size_t n, FILE* f) \
{ return vtkByteSwap::SwapBERangeWrite( \
static_cast<const vtkByteSwapType##S*>(p), n, f); } \
void vtkByteSwap::SwapWrite##S##LERange(void const* p, size_t n, ostream* os) \
{ vtkByteSwap::SwapLERangeWrite( \
static_cast<const vtkByteSwapType##S*>(p), n, os); } \
void vtkByteSwap::SwapWrite##S##BERange(void const* p, size_t n, ostream* os) \
{ vtkByteSwap::SwapBERangeWrite( \
static_cast<const vtkByteSwapType##S*>(p), n, os); }
VTK_BYTE_SWAP_SIZE(2)
VTK_BYTE_SWAP_SIZE(4)
VTK_BYTE_SWAP_SIZE(8)
......@@ -303,10 +303,10 @@ VTK_BYTE_SWAP_SIZE(8)
//----------------------------------------------------------------------------
// Swaps the bytes of a buffer. Uses an arbitrary word size, but
// assumes the word size is divisible by two.
void vtkByteSwap::SwapVoidRange(void *buffer, int numWords, int wordSize)
void vtkByteSwap::SwapVoidRange(void *buffer, size_t numWords, size_t wordSize)
{
unsigned char temp, *out, *buf;
int idx1, idx2, inc, half;
size_t idx1, idx2, inc, half;
half = wordSize / 2;
inc = wordSize - 1;
......
......@@ -34,15 +34,15 @@ public:
// Type-safe swap signatures to swap for storage in either Little
// Endian or Big Endian format. Swapping is performed according to
// the true size of the type given.
#define VTK_BYTE_SWAP_DECL(T) \
static void SwapLE(T* p); \
static void SwapBE(T* p); \
static void SwapLERange(T* p, vtkIdType num); \
static void SwapBERange(T* p, vtkIdType num); \
static bool SwapLERangeWrite(const T* p, vtkIdType num, FILE* file); \
static bool SwapBERangeWrite(const T* p, vtkIdType num, FILE* file); \
static void SwapLERangeWrite(const T* p, vtkIdType num, ostream* os); \
static void SwapBERangeWrite(const T* p, vtkIdType num, ostream* os)
#define VTK_BYTE_SWAP_DECL(T) \
static void SwapLE(T* p); \
static void SwapBE(T* p); \
static void SwapLERange(T* p, size_t num); \
static void SwapBERange(T* p, size_t num); \
static bool SwapLERangeWrite(const T* p, size_t num, FILE* file); \
static bool SwapBERangeWrite(const T* p, size_t num, FILE* file); \
static void SwapLERangeWrite(const T* p, size_t num, ostream* os); \
static void SwapBERangeWrite(const T* p, size_t num, ostream* os)
VTK_BYTE_SWAP_DECL(float);
VTK_BYTE_SWAP_DECL(double);
VTK_BYTE_SWAP_DECL(char);
......@@ -73,19 +73,19 @@ public:
// Description:
// Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static void Swap2LERange(void* p, int num);
static void Swap4LERange(void* p, int num);
static void Swap8LERange(void* p, int num);
static void Swap2LERange(void* p, size_t num);
static void Swap4LERange(void* p, size_t num);
static void Swap8LERange(void* p, size_t num);
// Description:
// Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
// The results are written directly to a file to avoid temporary storage.
static bool SwapWrite2LERange(const void* p, int num, FILE* f);
static bool SwapWrite4LERange(const void* p, int num, FILE* f);
static bool SwapWrite8LERange(const void* p, int num, FILE* f);
static void SwapWrite2LERange(const void* p, int num, ostream* os);
static void SwapWrite4LERange(const void* p, int num, ostream* os);
static void SwapWrite8LERange(const void* p, int num, ostream* os);
static bool SwapWrite2LERange(void const* p, size_t num, FILE* f);
static bool SwapWrite4LERange(void const* p, size_t num, FILE* f);
static bool SwapWrite8LERange(void const* p, size_t num, FILE* f);
static void SwapWrite2LERange(void const* p, size_t num, ostream* os);
static void SwapWrite4LERange(void const* p, size_t num, ostream* os);
static void SwapWrite8LERange(void const* p, size_t num, ostream* os);
// Description:
// Swap 2, 4, or 8 bytes for storage as Big Endian.
......@@ -95,24 +95,24 @@ public:
// Description:
// Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void Swap2BERange(void* p, int num);
static void Swap4BERange(void* p, int num);
static void Swap8BERange(void* p, int num);
static void Swap2BERange(void* p, size_t num);
static void Swap4BERange(void* p, size_t num);
static void Swap8BERange(void* p, size_t num);
// Description:
// Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
// The results are written directly to a file to avoid temporary storage.
static bool SwapWrite2BERange(const void* p, int num, FILE* f);
static bool SwapWrite4BERange(const void* p, int num, FILE* f);
static bool SwapWrite8BERange(const void* p, int num, FILE* f);
static void SwapWrite2BERange(const void* p, int num, ostream* os);
static void SwapWrite4BERange(const void* p, int num, ostream* os);
static void SwapWrite8BERange(const void* p, int num, ostream* os);
static bool SwapWrite2BERange(void const* p, size_t num, FILE* f);
static bool SwapWrite4BERange(void const* p, size_t num, FILE* f);
static bool SwapWrite8BERange(void const* p, size_t num, FILE* f);
static void SwapWrite2BERange(void const* p, size_t num, ostream* os);
static void SwapWrite4BERange(void const* p, size_t num, ostream* os);
static void SwapWrite8BERange(void const* p, size_t num, ostream* os);
// Description:
// Swaps the bytes of a buffer. Uses an arbitrary word size, but
// assumes the word size is divisible by two.
static void SwapVoidRange(void *buffer, int numWords, int wordSize);
static void SwapVoidRange(void *buffer, size_t numWords, size_t wordSize);
protected:
vtkByteSwap();
......
......@@ -436,8 +436,8 @@ unsigned long vtkXMLDataParser::GetWordTypeSize(int wordType)
}
//----------------------------------------------------------------------------
void vtkXMLDataParser::PerformByteSwap(void* data, OffsetType numWords,
int wordSize)
void vtkXMLDataParser::PerformByteSwap(void* data, size_t numWords,
size_t wordSize)
{
char* ptr = static_cast<char*>(data);
if(this->ByteOrder == vtkXMLDataParser::BigEndian)
......
......@@ -159,7 +159,7 @@ protected:
void PushOpenElement(vtkXMLDataElement* element);
vtkXMLDataElement* PopOpenElement();
void FreeAllElements();
void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
// Data reading methods.
void ReadCompressionHeader();
......
......@@ -1164,8 +1164,8 @@ int vtkXMLWriter::WriteBinaryDataBlock(unsigned char* in_data,
}
//----------------------------------------------------------------------------
void vtkXMLWriter::PerformByteSwap(void* data, OffsetType numWords,
int wordSize)
void vtkXMLWriter::PerformByteSwap(void* data, size_t numWords,
size_t wordSize)
{
char* ptr = static_cast<char*>(data);
if(this->ByteOrder == vtkXMLWriter::BigEndian)
......
......@@ -415,7 +415,7 @@ protected:
// Internal utility methods.
int WriteBinaryDataInternal(void* data, OffsetType numWords, int wordType);
int WriteBinaryDataBlock(unsigned char* in_data, OffsetType numWords, int wordType);
void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
int CreateCompressionHeader(OffsetType size);
int WriteCompressionBlock(unsigned char* data, OffsetType size);
int WriteCompressionHeader();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment