Skip to content

Commit 6e1b493

Browse files
authored
int: Turn on OIIO_NODISCARD_ERROR_ENABLE for internal builds (#5145)
Rearrange the automatic setting of `OIIO_NODISCARD_ERROR_ENABLE` so that for external (not OIIO itself) builds, we default to enabling for OIIO >= 3.3, and disabling for older and current versions. But now, when building OIIO itself, it is ENABLED regardless of version. So this means that as we add OIIO_NODISCARD_ERROR annotations to functions, we MUST fix any calls to those functions where we ourselves don't check their return values, and can't accidentally add new breaking code. Also, had to fix a bunch of spots that were missed in the original PR, places where we didn't patch up our sloppy uses of what was annotated in that patch. I'm not sure I understand how these could have been missed in that last PR, since that PR did fix other uses of the annotated functions. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent c6c80bc commit 6e1b493

4 files changed

Lines changed: 39 additions & 17 deletions

File tree

src/doc/Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,7 @@ PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS \
22022202
OIIO_CONST_FUNC= \
22032203
OIIO_MAYBE_UNUSED= \
22042204
OIIO_NODISCARD:= \
2205+
OIIO_NODISCARD_ERROR:= \
22052206
OIIO_DEPRECATED(x)=[[deprecated]] \
22062207
OIIO_FORMAT_DEPRECATED:= \
22072208
OIIO_FORCEINLINE=inline \

src/include/OpenImageIO/platform.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,12 @@
475475
// override the default, for example to flag discarded errors in older
476476
// versions of OIIO, or to disable the warnings in future versions of OIIO.
477477
#ifndef OIIO_NODISCARD_ERROR_ENABLE
478-
# if OIIO_VERSION_LESS(3, 3, 0)
479-
# define OIIO_NODISCARD_ERROR_ENABLE 0 /* disable for now */
478+
# if OIIO_VERSION_GREATER_EQUAL(3, 3, 0) || defined(OIIO_INTERNAL)
479+
/* enable for OIIO >= 3.3, or now for OIIO's own build */
480+
# define OIIO_NODISCARD_ERROR_ENABLE 1
480481
# else
481-
# define OIIO_NODISCARD_ERROR_ENABLE 1 /* enable for OIIO >= 3.3 */
482+
/* disable for now externally */
483+
# define OIIO_NODISCARD_ERROR_ENABLE 0
482484
# endif
483485
#endif
484486

src/libOpenImageIO/imageinout_test.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,10 @@ test_read_tricky_sizes()
483483
// Read in, make sure it's right, several different ways
484484
{
485485
auto imgin = ImageInput::open(srcfilename);
486-
imgin->read_image(0, 0, 0, 4, TypeUInt8, buf, 4 /* xstride */);
486+
OIIO_ASSERT(imgin);
487+
bool ok = imgin->read_image(0, 0, 0, 4, TypeUInt8, buf,
488+
4 /* xstride */);
489+
OIIO_ASSERT(ok);
487490
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
488491
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
489492
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
@@ -492,8 +495,9 @@ test_read_tricky_sizes()
492495
{
493496
memset(buf, 0, 4 * 4 * 4);
494497
auto imgin = ImageInput::open(srcfilename);
495-
imgin->read_scanlines(0, 0, 0, 4, 0, 0, 4, TypeUInt8, buf,
496-
/*xstride=*/4);
498+
bool ok = imgin->read_scanlines(0, 0, 0, 4, 0, 0, 4, TypeUInt8, buf,
499+
/*xstride=*/4);
500+
OIIO_ASSERT(ok);
497501
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
498502
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
499503
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
@@ -502,8 +506,11 @@ test_read_tricky_sizes()
502506
{
503507
memset(buf, 0, 4 * 4 * 4);
504508
auto imgin = ImageInput::open(srcfilename);
509+
OIIO_ASSERT(imgin);
510+
bool ok = true;
505511
for (int y = 0; y < 4; ++y)
506-
imgin->read_scanline(y, 0, TypeUInt8, buf, /*xstride=*/4);
512+
ok &= imgin->read_scanline(y, 0, TypeUInt8, buf, /*xstride=*/4);
513+
OIIO_ASSERT(ok);
507514
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
508515
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
509516
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
@@ -515,7 +522,10 @@ test_read_tricky_sizes()
515522
{
516523
memset(buf, 0, 4 * 4 * 4);
517524
auto imgin = ImageInput::open(srcfilename);
518-
imgin->read_image(0, 0, 0, 4, TypeUInt8, buf, 4 /* xstride */);
525+
OIIO_ASSERT(imgin);
526+
bool ok = imgin->read_image(0, 0, 0, 4, TypeUInt8, buf,
527+
4 /* xstride */);
528+
OIIO_ASSERT(ok);
519529
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
520530
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
521531
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
@@ -524,8 +534,11 @@ test_read_tricky_sizes()
524534
{
525535
memset(buf, 0, 4 * 4 * 4);
526536
auto imgin = ImageInput::open(srcfilename);
527-
imgin->read_tiles(0, 0, 0, 4, 0, 4, 0, 1, 0, 4, TypeUInt8, buf,
528-
/*xstride=*/4);
537+
OIIO_ASSERT(imgin);
538+
bool ok = imgin->read_tiles(0, 0, 0, 4, 0, 4, 0, 1, 0, 4, TypeUInt8,
539+
buf,
540+
/*xstride=*/4);
541+
OIIO_ASSERT(ok);
529542
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
530543
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
531544
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
@@ -534,8 +547,10 @@ test_read_tricky_sizes()
534547
{
535548
memset(buf, 0, 4 * 4 * 4);
536549
auto imgin = ImageInput::open(srcfilename);
537-
imgin->read_tile(0, 0, 0, TypeUInt8, buf, /*xstride=*/4);
550+
OIIO_ASSERT(imgin);
551+
bool ok = imgin->read_tile(0, 0, 0, TypeUInt8, buf, /*xstride=*/4);
538552
OIIO_CHECK_EQUAL(int(buf[0][0][0]), 128);
553+
OIIO_ASSERT(ok);
539554
OIIO_CHECK_EQUAL(int(buf[0][0][1]), 0);
540555
OIIO_CHECK_EQUAL(int(buf[0][0][2]), 0);
541556
OIIO_CHECK_EQUAL(int(buf[0][0][3]), 0);

src/libOpenImageIO/imagespeed_test.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ time_read_image()
8686
for (ustring filename : input_filename) {
8787
auto in = ImageInput::open(filename.c_str());
8888
OIIO_ASSERT(in);
89-
in->read_image(0, 0, 0, in->spec().nchannels, conversion, &buffer[0]);
89+
(void)in->read_image(0, 0, 0, in->spec().nchannels, conversion,
90+
&buffer[0]);
9091
in->close();
9192
}
9293
}
@@ -126,10 +127,11 @@ time_read_64_scanlines_at_a_time()
126127
pixelsize = spec.pixel_bytes(true); // UNKNOWN -> native
127128
imagesize_t scanlinesize = spec.width * pixelsize;
128129
for (int y = 0; y < spec.height; y += 64) {
129-
in->read_scanlines(/*subimage=*/0, /*miplevel=*/0, y + spec.y,
130-
std::min(y + spec.y + 64, spec.y + spec.height),
131-
0, 0, spec.nchannels, conversion,
132-
&buffer[scanlinesize * y]);
130+
bool ok = in->read_scanlines(
131+
/*subimage=*/0, /*miplevel=*/0, y + spec.y,
132+
std::min(y + spec.y + 64, spec.y + spec.height), 0, 0,
133+
spec.nchannels, conversion, &buffer[scanlinesize * y]);
134+
OIIO_ASSERT(ok);
133135
}
134136
in->close();
135137
}
@@ -548,7 +550,9 @@ main(int argc, char** argv)
548550
auto in = ImageInput::open(input_filename[0].c_str());
549551
OIIO_ASSERT(in);
550552
bufspec = in->spec(0, 0);
551-
in->read_image(0, 0, 0, bufspec.nchannels, conversion, &buffer[0]);
553+
bool ok = in->read_image(0, 0, 0, bufspec.nchannels, conversion,
554+
&buffer[0]);
555+
OIIO_ASSERT(ok);
552556
in->close();
553557
in.reset();
554558
std::cout << "Timing ways of writing images:\n";

0 commit comments

Comments
 (0)