Skip to content

Commit

Permalink
Fix building for FreeBSD
Browse files Browse the repository at this point in the history
On FreeBSD, _assert() is a macro in <assert.h>.  The macro expansion
causes build errors like this:

	/build/source/src/LercLib/fpl_Lerc2Ext.cpp:34:6: error: expected unqualified-id
	   34 | void _assert(bool v)
	      |      ^
	/nix/store/zgvh12biq5svwz3m0s6dbcvkyrm2fbz4-libc-x86_64-unknown-freebsd-14.1.0/include/assert.h:51:22: note: expanded from macro '_assert'
	   51 | #define _assert(e)      ((void)0)
	      |                           ^
	/build/source/src/LercLib/fpl_Lerc2Ext.cpp:34:6: error: expected ')'
	/nix/store/zgvh12biq5svwz3m0s6dbcvkyrm2fbz4-libc-x86_64-unknown-freebsd-14.1.0/include/assert.h:51:22: note: expanded from macro '_assert'
	   51 | #define _assert(e)      ((void)0)
	      |                           ^
	/build/source/src/LercLib/fpl_Lerc2Ext.cpp:34:6: note: to match this '('
	/nix/store/zgvh12biq5svwz3m0s6dbcvkyrm2fbz4-libc-x86_64-unknown-freebsd-14.1.0/include/assert.h:51:21: note: expanded from macro '_assert'
	   51 | #define _assert(e)      ((void)0)
	      |                          ^
	/build/source/src/LercLib/fpl_Lerc2Ext.cpp:34:6: error: expected ')'
	   34 | void _assert(bool v)
	      |      ^
	/nix/store/zgvh12biq5svwz3m0s6dbcvkyrm2fbz4-libc-x86_64-unknown-freebsd-14.1.0/include/assert.h:51:27: note: expanded from macro '_assert'
	   51 | #define _assert(e)      ((void)0)
	      |                                ^
	/build/source/src/LercLib/fpl_Lerc2Ext.cpp:34:6: note: to match this '('
	/nix/store/zgvh12biq5svwz3m0s6dbcvkyrm2fbz4-libc-x86_64-unknown-freebsd-14.1.0/include/assert.h:51:20: note: expanded from macro '_assert'
	   51 | #define _assert(e)      ((void)0)
	      |                         ^
  • Loading branch information
alyssais committed Oct 10, 2024
1 parent 4177b33 commit 215c195
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/LercLib/fpl_EsriHuffman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Original coding 2021 Yuriy Yakimenko

USING_NAMESPACE_LERC

void _assert(bool v);
void lerc_assert(bool v);

bool decodePackBits (const unsigned char *ptr, const size_t size, size_t expected, unsigned char **output)
{
Expand Down Expand Up @@ -332,7 +332,7 @@ int fpl_EsriHuffman::EncodeHuffman (const char *input, size_t input_len, unsigne
ptr[0] = HUFFMAN_RLE; // RLE flag
ptr[1] = input[0];

_assert(input_len <= 0xffffffff);
lerc_assert(input_len <= 0xffffffff);

uint32_t len = (uint32_t)input_len;

Expand Down Expand Up @@ -498,7 +498,7 @@ bool fpl_EsriHuffman::DecodeHuffman(const unsigned char* inBytes, const size_t i
{
unsigned char *unpacked = NULL;

_assert (true == decodePackBits (ppByte + 1, inCount - 1, nBytesRemainingInOut, &unpacked));
lerc_assert (true == decodePackBits (ppByte + 1, inCount - 1, nBytesRemainingInOut, &unpacked));

*output = unpacked;

Expand Down
14 changes: 7 additions & 7 deletions src/LercLib/fpl_Lerc2Ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Original coding 2021 Yuriy Yakimenko

USING_NAMESPACE_LERC

void _assert(bool v)
void lerc_assert(bool v)
{
if (v == false)
throw "Assertion failed";
Expand Down Expand Up @@ -65,7 +65,7 @@ static void generateListOfTestBlocks(const int width, const int height, std::vec
{
size_t size = (size_t)width * height;

_assert(size > 0);
lerc_assert(size > 0);

const int block_target_size = 8 * 1024;

Expand Down Expand Up @@ -614,11 +614,11 @@ bool restoreCrossBytes(std::vector<std::pair<int, char*> >& output_buffers, cons
//FILE* output,
const UnitType unit_type, uint8_t** output_block)
{
_assert(predictor == PREDICTOR_NONE || predictor == PREDICTOR_ROWS_COLS);
lerc_assert(predictor == PREDICTOR_NONE || predictor == PREDICTOR_ROWS_COLS);

size_t unit_size = output_buffers.size();

_assert(unit_size == UnitTypes::size(unit_type));
lerc_assert(unit_size == UnitTypes::size(unit_type));

const int delta = Predictor::getIntDelta(predictor);

Expand Down Expand Up @@ -670,11 +670,11 @@ bool restoreByteOrder(std::vector<std::pair<int, char*> >& output_buffers,
const size_t cols, const size_t rows, const PredictorType predictor, //FILE* output,
const UnitType unit_type, uint8_t** output_block)
{
_assert(predictor == PREDICTOR_NONE || predictor == PREDICTOR_DELTA1);
lerc_assert(predictor == PREDICTOR_NONE || predictor == PREDICTOR_DELTA1);

size_t unit_size = output_buffers.size();

_assert(unit_size == UnitTypes::size(unit_type));
lerc_assert(unit_size == UnitTypes::size(unit_type));

const int delta = Predictor::getIntDelta(predictor);

Expand Down Expand Up @@ -807,7 +807,7 @@ bool LosslessFPCompression::DecodeHuffmanFltSlice (const unsigned char** ppByte,

size_t extracted_size = fpl_Compression::extract_buffer((const char *)compressed, compressed_size, expected_size, &uncompressed);

_assert(expected_size == extracted_size);
lerc_assert(expected_size == extracted_size);

free(compressed);
compressed = NULL;
Expand Down

0 comments on commit 215c195

Please sign in to comment.