Skip to content

Commit b63a913

Browse files
authored
Have AVIF_FALSE and AVIF_TRUE be enums in the CI (AOMediaCodec#2712)
1 parent d9c9002 commit b63a913

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/ci-c-warnings.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
# Generate the configurations:
19-
# case 0: nodiscard
19+
# case 0: nodiscard, case 1: use stdbool, case 2: use enums
2020
matrix:
2121
os: [ubuntu-latest, windows-latest]
22-
case: [0]
22+
case: [0, 1, 2]
2323

2424
runs-on: ${{ matrix.os }}
2525

@@ -54,6 +54,18 @@ jobs:
5454
- name: Enable nodiscard
5555
if: ${{ matrix.case == 0}}
5656
run: echo "CMAKE_AVIF_FLAGS=\"-DAVIF_ENABLE_NODISCARD=ON\"" >> $GITHUB_ENV
57+
- name: Use stdbool for AVIF_TRUE/AVIF_FALSE
58+
if: ${{ matrix.case == 1}}
59+
run: |
60+
sed -i 's/#include <stdint.h>/#include <stdint.h>\n#include <stdbool.h>/' include/avif/avif.h
61+
sed -i 's/typedef int avifBool;/typedef bool avifBool;/' include/avif/avif.h
62+
sed -i 's/#define AVIF_TRUE 1/#define AVIF_TRUE true/' include/avif/avif.h
63+
sed -i 's/#define AVIF_FALSE 0/#define AVIF_FALSE false/' include/avif/avif.h
64+
- name: Use enums for AVIF_TRUE/AVIF_FALSE
65+
if: ${{ matrix.case == 2}}
66+
run: |
67+
sed -i 's/#define AVIF_TRUE 1/enum avifTrueFalse_{ AVIF_TRUE = 1,/' include/avif/avif.h
68+
sed -i 's/#define AVIF_FALSE 0/AVIF_FALSE = 0};/' include/avif/avif.h
5769
5870
- name: Prepare libavif (cmake)
5971
run: >

apps/avifdec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ int main(int argc, char * argv[])
359359

360360
const avifBool decodeAllFrames = frameIndex == DECODE_ALL_FRAMES;
361361
int currIndex = decodeAllFrames ? 0 : frameIndex;
362-
while (AVIF_TRUE) {
362+
for (;;) {
363363
result = decodeAllFrames ? avifDecoderNextImage(decoder) : avifDecoderNthImage(decoder, frameIndex);
364364
if (result != AVIF_RESULT_OK) {
365365
break;

include/avif/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ static inline void avifBreakOnError()
6262
// AVIF_ASSERT_OR_RETURN() can be used instead of assert() for extra security in release builds.
6363
#ifdef NDEBUG
6464
#define AVIF_ASSERT_OR_RETURN(A) AVIF_CHECKERR((A), AVIF_RESULT_INTERNAL_ERROR)
65+
#define AVIF_ASSERT_NOT_REACHED_OR_RETURN \
66+
do { \
67+
avifBreakOnError(); \
68+
return AVIF_RESULT_INTERNAL_ERROR; \
69+
} while (0)
6570
#else
6671
#define AVIF_ASSERT_OR_RETURN(A) assert(A)
72+
#define AVIF_ASSERT_NOT_REACHED_OR_RETURN assert(0);
6773
#endif
6874

6975
// ---------------------------------------------------------------------------

src/read.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,15 +4001,15 @@ static avifResult avifParseMovieBox(avifDecoderData * data,
40014001
static avifProperty * avifMetaCreateProperty(avifMeta * meta, const char * propertyType)
40024002
{
40034003
avifProperty * metaProperty = avifArrayPush(&meta->properties);
4004-
AVIF_CHECK(metaProperty);
4004+
AVIF_CHECKERR(metaProperty, NULL);
40054005
memcpy(metaProperty->type, propertyType, 4);
40064006
return metaProperty;
40074007
}
40084008

40094009
static avifProperty * avifDecoderItemAddProperty(avifDecoderItem * item, const avifProperty * metaProperty)
40104010
{
40114011
avifProperty * itemProperty = avifArrayPush(&item->properties);
4012-
AVIF_CHECK(itemProperty);
4012+
AVIF_CHECKERR(itemProperty, NULL);
40134013
*itemProperty = *metaProperty;
40144014
return itemProperty;
40154015
}
@@ -5536,7 +5536,7 @@ static avifResult avifMetaFindAlphaItem(avifMeta * meta,
55365536
for (uint32_t dimgIdx = 0; dimgIdx < tileCount; ++dimgIdx) {
55375537
if (dimgIdxToAlphaItemIdx[dimgIdx] >= meta->items.count) {
55385538
avifFree(dimgIdxToAlphaItemIdx);
5539-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
5539+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
55405540
}
55415541
avifDecoderItem * alphaTileItem = meta->items.item[dimgIdxToAlphaItemIdx[dimgIdx]];
55425542
alphaTileItem->dimgForID = (*alphaItem)->id;

src/write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream *
26422642

26432643
if (floatFlag) {
26442644
// bit(2) bit_depth_log2_minus4;
2645-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
2645+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
26462646
} else {
26472647
AVIF_CHECKRES(avifRWStreamWriteBits(s, image->depth > 8, 1)); // bit(1) high_bit_depth_flag;
26482648
if (image->depth > 8) {
@@ -2710,7 +2710,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream *
27102710
AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmapFloatFlag, 1)); // bit(1) gainmap_float_flag;
27112711
if (gainmapFloatFlag) {
27122712
// bit(2) gainmap_bit_depth_log2_minus4;
2713-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
2713+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
27142714
} else {
27152715
AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmap->depth > 8, 1)); // bit(1) gainmap_high_bit_depth_flag;
27162716
if (gainmap->depth > 8) {

0 commit comments

Comments
 (0)