V2: Use a single definition of MIN and MAX in sources
authorCristian Rodríguez <crrodriguez@opensuse.org>
Thu, 5 Apr 2012 22:39:37 +0000 (19:39 -0300)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 5 Apr 2012 23:52:06 +0000 (09:52 +1000)
configure.ac
src/libFLAC/bitreader.c
src/libFLAC/bitwriter.c
src/libFLAC/fixed.c
src/libFLAC/format.c
src/libFLAC/include/private/macros.h [new file with mode: 0644]
src/libFLAC/metadata_iterators.c
src/libFLAC/ogg_decoder_aspect.c
src/libFLAC/stream_decoder.c
src/libFLAC/stream_encoder.c
src/libFLAC/stream_encoder_framing.c

index d2501bb..7627fb7 100644 (file)
@@ -22,6 +22,10 @@ AC_INIT(src/flac/main.c)
 AM_INIT_AUTOMAKE(flac, 1.2.1)
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 AM_INIT_AUTOMAKE(flac, 1.2.1)
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
+
+#Prefer whatever the current ISO standard is.
+AC_PROG_CC_STDC
+AC_USE_SYSTEM_EXTENSIONS
 # Enable the generation of shared libraries under Win32
 AC_LIBTOOL_WIN32_DLL
 
 # Enable the generation of shared libraries under Win32
 AC_LIBTOOL_WIN32_DLL
 
@@ -60,6 +64,7 @@ AC_HEADER_STDC
 AM_PROG_CC_C_O
 AC_C_INLINE
 AC_C_VARARRAYS
 AM_PROG_CC_C_O
 AC_C_INLINE
 AC_C_VARARRAYS
+AC_C_TYPEOF
 
 AC_CHECK_HEADERS(stdint.h)
 AC_SUBST(HAVE_STDINT_H)
 
 AC_CHECK_HEADERS(stdint.h)
 AC_SUBST(HAVE_STDINT_H)
@@ -68,6 +73,8 @@ AC_SUBST(HAVE_INTTYPES_H)
 AC_CHECK_HEADERS(byteswap.h)
 AC_SUBST(HAVE_BYTESWAP_H)
 
 AC_CHECK_HEADERS(byteswap.h)
 AC_SUBST(HAVE_BYTESWAP_H)
 
+AC_CHECK_HEADERS([sys/param.h])
+
 XIPH_C_BSWAP32
 
 XIPH_C_FIND_ENDIAN
 XIPH_C_BSWAP32
 
 XIPH_C_FIND_ENDIAN
index cd05a62..7e17fd8 100644 (file)
@@ -38,6 +38,7 @@
 #include "private/bitmath.h"
 #include "private/bitreader.h"
 #include "private/crc.h"
 #include "private/bitmath.h"
 #include "private/bitreader.h"
 #include "private/crc.h"
+#include "private/macros.h"
 #include "FLAC/assert.h"
 #include "share/endswap.h"
 
 #include "FLAC/assert.h"
 #include "share/endswap.h"
 
@@ -109,15 +110,6 @@ static const unsigned char byte_to_unary_table[] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
-#ifdef min
-#undef min
-#endif
-#define min(x,y) ((x)<(y)?(x):(y))
-#ifdef max
-#undef max
-#endif
-#define max(x,y) ((x)>(y)?(x):(y))
-
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 #define FLAC__U64L(x) x
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 #define FLAC__U64L(x) x
@@ -547,7 +539,7 @@ FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
                FLAC__uint32 x;
 
                if(n != 0) {
                FLAC__uint32 x;
 
                if(n != 0) {
-                       m = min(8-n, bits);
+                       m = flac_min(8-n, bits);
                        if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
                                return false;
                        bits -= m;
                        if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
                                return false;
                        bits -= m;
index 7da4b15..44914d1 100644 (file)
@@ -37,6 +37,7 @@
 #include <string.h>
 #include "private/bitwriter.h"
 #include "private/crc.h"
 #include <string.h>
 #include "private/bitwriter.h"
 #include "private/crc.h"
+#include "private/macros.h"
 #include "FLAC/assert.h"
 #include "share/alloc.h"
 #include "share/endswap.h"
 #include "FLAC/assert.h"
 #include "share/alloc.h"
 #include "share/endswap.h"
@@ -67,11 +68,6 @@ static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(uint32_
 #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
 #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
 
 #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
 #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
 
-#ifdef min
-#undef min
-#endif
-#define min(x,y) ((x)<(y)?(x):(y))
-
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 #define FLAC__U64L(x) x
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 #define FLAC__U64L(x) x
@@ -288,7 +284,7 @@ FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsign
                return false;
        /* first part gets to word alignment */
        if(bw->bits) {
                return false;
        /* first part gets to word alignment */
        if(bw->bits) {
-               n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
+               n = flac_min(FLAC__BITS_PER_WORD - bw->bits, bits);
                bw->accum <<= n;
                bits -= n;
                bw->bits += n;
                bw->accum <<= n;
                bits -= n;
                bw->bits += n;
index 1a57cf4..05b289a 100644 (file)
@@ -37,6 +37,7 @@
 #include <string.h>
 #include "private/bitmath.h"
 #include "private/fixed.h"
 #include <string.h>
 #include "private/bitmath.h"
 #include "private/fixed.h"
+#include "private/macros.h"
 #include "FLAC/assert.h"
 
 #ifndef M_LN2
 #include "FLAC/assert.h"
 
 #ifndef M_LN2
 #define M_LN2 0.69314718055994530942
 #endif
 
 #define M_LN2 0.69314718055994530942
 #endif
 
-#ifdef min
-#undef min
-#endif
-#define min(x,y) ((x) < (y)? (x) : (y))
-
 #ifdef local_abs
 #undef local_abs
 #endif
 #ifdef local_abs
 #undef local_abs
 #endif
@@ -242,11 +238,11 @@ unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned d
                error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
        }
 
                error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
        }
 
-       if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
+       if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4))
                order = 0;
                order = 0;
-       else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
+       else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4))
                order = 1;
                order = 1;
-       else if(total_error_2 < min(total_error_3, total_error_4))
+       else if(total_error_2 < flac_min(total_error_3, total_error_4))
                order = 2;
        else if(total_error_3 < total_error_4)
                order = 3;
                order = 2;
        else if(total_error_3 < total_error_4)
                order = 3;
@@ -304,11 +300,11 @@ unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsig
                error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
        }
 
                error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
        }
 
-       if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
+       if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4))
                order = 0;
                order = 0;
-       else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
+       else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4))
                order = 1;
                order = 1;
-       else if(total_error_2 < min(total_error_3, total_error_4))
+       else if(total_error_2 < flac_min(total_error_3, total_error_4))
                order = 2;
        else if(total_error_3 < total_error_4)
                order = 3;
                order = 2;
        else if(total_error_3 < total_error_4)
                order = 3;
index c7454f8..d796547 100644 (file)
 #include "FLAC/assert.h"
 #include "FLAC/format.h"
 #include "private/format.h"
 #include "FLAC/assert.h"
 #include "FLAC/format.h"
 #include "private/format.h"
-
-#ifdef min
-#undef min
-#endif
-#define min(a,b) ((a)<(b)?(a):(b))
+#include "private/macros.h"
 
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
@@ -542,7 +538,7 @@ unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned block
                max_rice_partition_order++;
                blocksize >>= 1;
        }
                max_rice_partition_order++;
                blocksize >>= 1;
        }
-       return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
+       return flac_min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
 }
 
 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
 }
 
 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
diff --git a/src/libFLAC/include/private/macros.h b/src/libFLAC/include/private/macros.h
new file mode 100644 (file)
index 0000000..1718005
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef FLAC__PRIVATE__MACROS_H
+#define FLAC__PRIVATE__MACROS_H
+
+#if defined(__GNUC__)
+
+#define flac_max(a,b) \
+    ({ __typeof__ (a) _a = (a); \
+    __typeof__ (b) _b = (b); \
+    _a > _b ? _a : _b; })
+
+#define flac_min(a,b) \
+    ({ __typeof__ (a) _a = (a); \
+    __typeof__ (b) _b = (b); \
+    _a < _b ? _a : _b; })
+
+/* Whatever other unix that has sys/param.h */
+#elif defined(HAVE_SYS_PARAM_H)
+#include <sys/param.h>
+#define flac_max(a,b) MAX(a,b)
+#define flac_min(a,b) MIN(a,b)
+
+/* Windows VS has them in stdlib.h.. XXX:Untested */
+#elif defined(_MSC_VER)
+#include <stdlib.h>
+#define flac_max(a,b) __max(a,b)
+#define flac_min(a,b) __min(a,b)
+#endif
+
+#endif
\ No newline at end of file
index 0ba0d20..4fbe678 100644 (file)
 #include "FLAC/stream_decoder.h"
 #include "share/alloc.h"
 #include "share/compat.h"
 #include "FLAC/stream_decoder.h"
 #include "share/alloc.h"
 #include "share/compat.h"
-
-#ifdef max
-#undef max
-#endif
-#define max(a,b) ((a)>(b)?(a):(b))
-#ifdef min
-#undef min
-#endif
-#define min(a,b) ((a)<(b)?(a):(b))
-
+#include "private/macros.h"
 
 /****************************************************************************
  *
 
 /****************************************************************************
  *
@@ -2634,7 +2625,7 @@ FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, F
        const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
        FLAC__byte buffer[4]; /* magic number is asserted below */
 
        const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
        FLAC__byte buffer[4]; /* magic number is asserted below */
 
-       FLAC__ASSERT(max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer));
+       FLAC__ASSERT(flac_max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer));
 
        pack_uint32_little_endian_(block->vendor_string.length, buffer, entry_length_len);
        if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len)
 
        pack_uint32_little_endian_(block->vendor_string.length, buffer, entry_length_len);
        if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len)
@@ -3134,7 +3125,7 @@ FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, off_t bytes, FLAC
 
        FLAC__ASSERT(bytes >= 0);
        while(bytes > 0) {
 
        FLAC__ASSERT(bytes >= 0);
        while(bytes > 0) {
-               n = min(sizeof(buffer), (size_t)bytes);
+               n = flac_min(sizeof(buffer), (size_t)bytes);
                if(fread(buffer, 1, n, file) != n) {
                        *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
                        return false;
                if(fread(buffer, 1, n, file) != n) {
                        *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
                        return false;
@@ -3156,7 +3147,7 @@ FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Re
 
        FLAC__ASSERT(bytes >= 0);
        while(bytes > 0) {
 
        FLAC__ASSERT(bytes >= 0);
        while(bytes > 0) {
-               n = min(sizeof(buffer), (size_t)bytes);
+               n = flac_min(sizeof(buffer), (size_t)bytes);
                if(read_cb(buffer, 1, n, handle) != n) {
                        *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
                        return false;
                if(read_cb(buffer, 1, n, handle) != n) {
                        *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
                        return false;
index 0e8519c..f67fb40 100644 (file)
 #include "FLAC/assert.h"
 #include "private/ogg_decoder_aspect.h"
 #include "private/ogg_mapping.h"
 #include "FLAC/assert.h"
 #include "private/ogg_decoder_aspect.h"
 #include "private/ogg_mapping.h"
+#include "private/macros.h"
 
 
-#ifdef max
-#undef max
-#endif
-#define max(x,y) ((x)>(y)?(x):(y))
 
 /***********************************************************************
  *
 
 /***********************************************************************
  *
@@ -210,7 +207,7 @@ FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(
                        }
                        else if (ret == 0) {
                                /* need more data */
                        }
                        else if (ret == 0) {
                                /* need more data */
-                               const size_t ogg_bytes_to_read = max(bytes_requested - *bytes, OGG_BYTES_CHUNK);
+                               const size_t ogg_bytes_to_read = flac_max(bytes_requested - *bytes, OGG_BYTES_CHUNK);
                                char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read);
 
                                if(0 == oggbuf) {
                                char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read);
 
                                if(0 == oggbuf) {
index 6f96023..5b3c3cd 100644 (file)
 #include "private/lpc.h"
 #include "private/md5.h"
 #include "private/memory.h"
 #include "private/lpc.h"
 #include "private/md5.h"
 #include "private/memory.h"
-
-#ifdef max
-#undef max
-#endif
-#define max(a,b) ((a)>(b)?(a):(b))
+#include "private/macros.h"
 
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
 
 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
 #ifdef _MSC_VER
@@ -2732,7 +2728,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigne
                }
        }
 
                }
        }
 
-       if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
+       if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order))) {
                decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
                decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
index dd36b70..ce0c8da 100644 (file)
@@ -60,6 +60,7 @@
 #include "private/lpc.h"
 #include "private/md5.h"
 #include "private/memory.h"
 #include "private/lpc.h"
 #include "private/md5.h"
 #include "private/memory.h"
+#include "private/macros.h"
 #if FLAC__HAS_OGG
 #include "private/ogg_helper.h"
 #include "private/ogg_mapping.h"
 #if FLAC__HAS_OGG
 #include "private/ogg_helper.h"
 #include "private/ogg_mapping.h"
 #define FLaC__INLINE
 #endif
 
 #define FLaC__INLINE
 #endif
 
-#ifdef min
-#undef min
-#endif
-#define min(x,y) ((x)<(y)?(x):(y))
-
-#ifdef max
-#undef max
-#endif
-#define max(x,y) ((x)>(y)?(x):(y))
-
 /* Exact Rice codeword length calculation is off by default.  The simple
  * (and fast) estimation (of how many bits a residual value will be
  * encoded with) in this encoder is very good, almost always yielding
 /* Exact Rice codeword length calculation is off by default.  The simple
  * (and fast) estimation (of how many bits a residual value will be
  * encoded with) in this encoder is very good, almost always yielding
@@ -691,7 +682,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
                if(encoder->protected_->bits_per_sample < 16) {
                        /* @@@ need some data about how to set this here w.r.t. blocksize and sample rate */
                        /* @@@ until then we'll make a guess */
                if(encoder->protected_->bits_per_sample < 16) {
                        /* @@@ need some data about how to set this here w.r.t. blocksize and sample rate */
                        /* @@@ until then we'll make a guess */
-                       encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
+                       encoder->protected_->qlp_coeff_precision = flac_max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
                }
                else if(encoder->protected_->bits_per_sample == 16) {
                        if(encoder->protected_->blocksize <= 192)
                }
                else if(encoder->protected_->bits_per_sample == 16) {
                        if(encoder->protected_->blocksize <= 192)
@@ -880,7 +871,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
        encoder->private_->current_frame_number = 0;
 
        encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
        encoder->private_->current_frame_number = 0;
 
        encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
-       encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
+       encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(flac_max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
        encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
 
        /*
        encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
 
        /*
@@ -1971,7 +1962,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
        FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
 
        do {
        FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
 
        do {
-               const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
+               const unsigned n = flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
 
                if(encoder->protected_->verify)
                        append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
 
                if(encoder->protected_->verify)
                        append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
@@ -2034,7 +2025,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
                 */
                do {
                        if(encoder->protected_->verify)
                 */
                do {
                        if(encoder->protected_->verify)
-                               append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
+                               append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
 
                        /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
                        for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
 
                        /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
                        for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
@@ -2069,7 +2060,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
                 */
                do {
                        if(encoder->protected_->verify)
                 */
                do {
                        if(encoder->protected_->verify)
-                               append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
+                               append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
 
                        /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
                        for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
 
                        /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
                        for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
@@ -2411,8 +2402,8 @@ FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC
        FLAC__bitwriter_clear(encoder->private_->frame);
 
        if(samples > 0) {
        FLAC__bitwriter_clear(encoder->private_->frame);
 
        if(samples > 0) {
-               encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
-               encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
+               encoder->private_->streaminfo.data.stream_info.min_framesize = flac_min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
+               encoder->private_->streaminfo.data.stream_info.max_framesize = flac_max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
        }
 
        return true;
        }
 
        return true;
@@ -2499,7 +2490,7 @@ FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
                 * when the encoder goes back to write metadata, 'current_frame'
                 * will drop back to 0.
                 */
                 * when the encoder goes back to write metadata, 'current_frame'
                 * will drop back to 0.
                 */
-               encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
+               encoder->private_->frames_written = flac_max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
        }
        else
                encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
        }
        else
                encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
@@ -2510,7 +2501,7 @@ FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
 /* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks.  */
 void update_metadata_(const FLAC__StreamEncoder *encoder)
 {
 /* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks.  */
 void update_metadata_(const FLAC__StreamEncoder *encoder)
 {
-       FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
+       FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
        const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
        const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
        const unsigned min_framesize = metadata->data.stream_info.min_framesize;
        const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
        const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
        const unsigned min_framesize = metadata->data.stream_info.min_framesize;
@@ -2675,7 +2666,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
                FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
                FLAC__STREAM_SYNC_LENGTH
        ;
                FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
                FLAC__STREAM_SYNC_LENGTH
        ;
-       FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
+       FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
        const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
        const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
        const unsigned min_framesize = metadata->data.stream_info.min_framesize;
        const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
        const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
        const unsigned min_framesize = metadata->data.stream_info.min_framesize;
@@ -2926,9 +2917,9 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fracti
        }
        else {
                max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
        }
        else {
                max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
-               max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
+               max_partition_order = flac_min(max_partition_order, encoder->protected_->max_residual_partition_order);
        }
        }
-       min_partition_order = min(min_partition_order, max_partition_order);
+       min_partition_order = flac_min(min_partition_order, max_partition_order);
 
        /*
         * Setup the frame
 
        /*
         * Setup the frame
@@ -3332,8 +3323,8 @@ FLAC__bool process_subframe_(
                                                                        min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
                                                                        /* try to ensure a 32-bit datapath throughout for 16bps(+1bps for side channel) or less */
                                                                        if(subframe_bps <= 17) {
                                                                        min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
                                                                        /* try to ensure a 32-bit datapath throughout for 16bps(+1bps for side channel) or less */
                                                                        if(subframe_bps <= 17) {
-                                                                               max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
-                                                                               max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
+                                                                               max_qlp_coeff_precision = flac_min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
+                                                                               max_qlp_coeff_precision = flac_max(max_qlp_coeff_precision, min_qlp_coeff_precision);
                                                                        }
                                                                        else
                                                                                max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
                                                                        }
                                                                        else
                                                                                max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
@@ -3577,7 +3568,7 @@ unsigned evaluate_lpc_subframe_(
        if(subframe_bps <= 16) {
                FLAC__ASSERT(order > 0);
                FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
        if(subframe_bps <= 16) {
                FLAC__ASSERT(order > 0);
                FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
-               qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
+               qlp_coeff_precision = flac_min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
        }
 
        ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
        }
 
        ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
@@ -3681,7 +3672,7 @@ unsigned find_best_partition_order_(
        const unsigned blocksize = residual_samples + predictor_order;
 
        max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
        const unsigned blocksize = residual_samples + predictor_order;
 
        max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
-       min_partition_order = min(min_partition_order, max_partition_order);
+       min_partition_order = flac_min(min_partition_order, max_partition_order);
 
        precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
 
 
        precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
 
@@ -3735,7 +3726,7 @@ unsigned find_best_partition_order_(
                unsigned partition;
 
                /* save best parameters and raw_bits */
                unsigned partition;
 
                /* save best parameters and raw_bits */
-               FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
+               FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, flac_max(6u, best_partition_order));
                memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
                if(do_escape_coding)
                        memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
                memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
                if(do_escape_coding)
                        memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
@@ -3887,7 +3878,7 @@ void precompute_partition_info_escapes_(
                for(i = 0; i < partitions; i++) {
                        m = raw_bits_per_partition[from_partition];
                        from_partition++;
                for(i = 0; i < partitions; i++) {
                        m = raw_bits_per_partition[from_partition];
                        from_partition++;
-                       raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
+                       raw_bits_per_partition[to_partition] = flac_max(m, raw_bits_per_partition[from_partition]);
                        from_partition++;
                        to_partition++;
                }
                        from_partition++;
                        to_partition++;
                }
@@ -3965,7 +3956,7 @@ FLAC__bool set_partitioned_rice_(
        FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
        FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
 
        FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
        FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
 
-       FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
+       FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order));
        parameters = partitioned_rice_contents->parameters;
        raw_bits = partitioned_rice_contents->raw_bits;
 
        parameters = partitioned_rice_contents->parameters;
        raw_bits = partitioned_rice_contents->raw_bits;
 
index c883429..a415ad6 100644 (file)
 #include "private/crc.h"
 #include "FLAC/assert.h"
 
 #include "private/crc.h"
 #include "FLAC/assert.h"
 
-#ifdef max
-#undef max
-#endif
-#define max(x,y) ((x)>(y)?(x):(y))
-
 static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
 static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);
 
 static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
 static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);