From f7f16a29766c4df15d204015ce6d7f10df0a8833 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 18 Jul 2012 11:53:25 -0700 Subject: [PATCH] add ABI compatibility check minor revision shouldn't matter, we only check major revision number. Bumped all version numbers so that incompatibility starts *now* Change-Id: Id06c20f03039845ae4cfb3fd121807b931d67ee4 --- src/dec/vp8.c | 17 +++++++++-------- src/dec/webp.c | 4 ++-- src/mux/demux.c | 2 +- src/mux/muxedit.c | 13 ++++++++----- src/mux/muxread.c | 4 +++- src/webp/decode.h | 2 +- src/webp/encode.h | 2 +- src/webp/mux.h | 4 ++-- src/webp/types.h | 3 +++ 9 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/dec/vp8.c b/src/dec/vp8.c index 904cc70b..5db7d546 100644 --- a/src/dec/vp8.c +++ b/src/dec/vp8.c @@ -35,9 +35,10 @@ static void SetOk(VP8Decoder* const dec) { } int VP8InitIoInternal(VP8Io* const io, int version) { - if (version != WEBP_DECODER_ABI_VERSION) + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { return 0; // mismatch error - if (io) { + } + if (io != NULL) { memset(io, 0, sizeof(*io)); } return 1; @@ -45,7 +46,7 @@ int VP8InitIoInternal(VP8Io* const io, int version) { VP8Decoder* VP8New(void) { VP8Decoder* const dec = (VP8Decoder*)calloc(1, sizeof(VP8Decoder)); - if (dec) { + if (dec != NULL) { SetOk(dec); WebPWorkerInit(&dec->worker_); dec->ready_ = 0; @@ -60,13 +61,13 @@ VP8StatusCode VP8Status(VP8Decoder* const dec) { } const char* VP8StatusMessage(VP8Decoder* const dec) { - if (!dec) return "no object"; + if (dec == NULL) return "no object"; if (!dec->error_msg_) return "OK"; return dec->error_msg_; } void VP8Delete(VP8Decoder* const dec) { - if (dec) { + if (dec != NULL) { VP8Clear(dec); free(dec); } @@ -136,7 +137,7 @@ int VP8GetInfo(const uint8_t* data, size_t data_size, size_t chunk_size, // Header parsing static void ResetSegmentHeader(VP8SegmentHeader* const hdr) { - assert(hdr); + assert(hdr != NULL); hdr->use_segment_ = 0; hdr->update_map_ = 0; hdr->absolute_delta_ = 1; @@ -147,8 +148,8 @@ static void ResetSegmentHeader(VP8SegmentHeader* const hdr) { // Paragraph 9.3 static int ParseSegmentHeader(VP8BitReader* br, VP8SegmentHeader* hdr, VP8Proba* proba) { - assert(br); - assert(hdr); + assert(br != NULL); + assert(hdr != NULL); hdr->use_segment_ = VP8Get(br); if (hdr->use_segment_) { hdr->update_map_ = VP8Get(br); diff --git a/src/dec/webp.c b/src/dec/webp.c index 21744e91..edd348cb 100644 --- a/src/dec/webp.c +++ b/src/dec/webp.c @@ -651,7 +651,7 @@ int WebPGetInfo(const uint8_t* data, size_t data_size, int WebPInitDecoderConfigInternal(WebPDecoderConfig* config, int version) { - if (version != WEBP_DECODER_ABI_VERSION) { + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { return 0; // version mismatch } if (config == NULL) { @@ -667,7 +667,7 @@ VP8StatusCode WebPGetFeaturesInternal(const uint8_t* data, size_t data_size, WebPBitstreamFeatures* features, int version) { VP8StatusCode status; - if (version != WEBP_DECODER_ABI_VERSION) { + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DECODER_ABI_VERSION)) { return VP8_STATUS_INVALID_PARAM; // version mismatch } if (features == NULL) { diff --git a/src/mux/demux.c b/src/mux/demux.c index 2ce553d6..4519f7d5 100644 --- a/src/mux/demux.c +++ b/src/mux/demux.c @@ -631,7 +631,7 @@ WebPDemuxer* WebPDemuxInternal(const WebPData* data, int allow_partial, MemBuffer mem; WebPDemuxer* dmux; - if (version != WEBP_DEMUX_ABI_VERSION) return NULL; + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_DEMUX_ABI_VERSION)) return NULL; if (data == NULL || data->bytes_ == NULL || data->size_ == 0) return NULL; if (!InitMemBuffer(&mem, data->bytes_, data->size_)) return NULL; diff --git a/src/mux/muxedit.c b/src/mux/muxedit.c index 33dab625..59e08745 100644 --- a/src/mux/muxedit.c +++ b/src/mux/muxedit.c @@ -35,11 +35,14 @@ static void MuxInit(WebPMux* const mux) { } WebPMux* WebPNewInternal(int version) { - WebPMux* const mux = (version == WEBP_MUX_ABI_VERSION) ? - (WebPMux*)malloc(sizeof(WebPMux)) : NULL; - // If mux is NULL MuxInit is a noop. - MuxInit(mux); - return mux; + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_MUX_ABI_VERSION)) { + return NULL; + } else { + WebPMux* const mux = (WebPMux*)malloc(sizeof(WebPMux)); + // If mux is NULL MuxInit is a noop. + MuxInit(mux); + return mux; + } } static void DeleteAllChunks(WebPChunk** const chunk_list) { diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 8d52cc99..351d9cd9 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -89,7 +89,9 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data, ChunkInit(&chunk); // Sanity checks. - if (version != WEBP_MUX_ABI_VERSION) return NULL; // version mismatch + if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_MUX_ABI_VERSION)) { + return NULL; // version mismatch + } if (bitstream == NULL) return NULL; data = bitstream->bytes_; diff --git a/src/webp/decode.h b/src/webp/decode.h index c61849e7..74f1ee20 100644 --- a/src/webp/decode.h +++ b/src/webp/decode.h @@ -18,7 +18,7 @@ extern "C" { #endif -#define WEBP_DECODER_ABI_VERSION 0x0003 +#define WEBP_DECODER_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b) // Return the decoder's version number, packed in hexadecimal using 8bits for // each of major/minor/revision. E.g: v2.5.7 is 0x020507. diff --git a/src/webp/encode.h b/src/webp/encode.h index 1568ea65..4e34d467 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -18,7 +18,7 @@ extern "C" { #endif -#define WEBP_ENCODER_ABI_VERSION 0x0003 +#define WEBP_ENCODER_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b) // Return the encoder's version number, packed in hexadecimal using 8bits for // each of major/minor/revision. E.g: v2.5.7 is 0x020507. diff --git a/src/webp/mux.h b/src/webp/mux.h index 5c023077..ec132b35 100644 --- a/src/webp/mux.h +++ b/src/webp/mux.h @@ -51,7 +51,7 @@ extern "C" { #endif -#define WEBP_MUX_ABI_VERSION 0x0000 +#define WEBP_MUX_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b) // Error codes typedef enum { @@ -461,7 +461,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* mux, // Demux API. // Enables extraction of image and extended format data from WebP files. -#define WEBP_DEMUX_ABI_VERSION 0x0000 +#define WEBP_DEMUX_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b) typedef struct WebPDemuxer WebPDemuxer; diff --git a/src/webp/types.h b/src/webp/types.h index 25c0e708..3e27190b 100644 --- a/src/webp/types.h +++ b/src/webp/types.h @@ -39,4 +39,7 @@ typedef long long int int64_t; #define WEBP_EXTERN(type) extern type #endif /* WEBP_EXTERN */ +// Macro to check ABI compatibility (same major revision number) +#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) + #endif /* WEBP_WEBP_TYPES_H_ */