Skip to content

Commit

Permalink
cleanup: Coalesce redundant STRINGIZE macros -> OIIO_STRINGIZE (Acade…
Browse files Browse the repository at this point in the history
…mySoftwareFoundation#4121)

We did this separately each place we needed it. Do it just once, in a
public header, and give it a name that won't clash with other packages.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Feb 8, 2024
1 parent 46d8c82 commit fbe7b12
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
6 changes: 2 additions & 4 deletions src/gif.imageio/gifinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ OIIO_EXPORT const char* gif_input_extensions[] = { "gif", NULL };
OIIO_EXPORT const char*
gif_imageio_library_version()
{
#define STRINGIZE2(a) #a
#define STRINGIZE(a) STRINGIZE2(a)
#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && defined(GIFLIB_RELEASE)
return "gif_lib " STRINGIZE(GIFLIB_MAJOR) "." STRINGIZE(
GIFLIB_MINOR) "." STRINGIZE(GIFLIB_RELEASE);
return "gif_lib " OIIO_STRINGIZE(GIFLIB_MAJOR) "." OIIO_STRINGIZE(
GIFLIB_MINOR) "." OIIO_STRINGIZE(GIFLIB_RELEASE);
#else
return "gif_lib unknown version";
#endif
Expand Down
4 changes: 0 additions & 4 deletions src/iff.imageio/iff_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ tile_height_size(uint32_t height)
}


#define STRINGIZE2(a) #a
#define STRINGIZE(a) STRINGIZE2(a)


} // namespace iff_pvt


Expand Down
47 changes: 23 additions & 24 deletions src/iff.imageio/noproxy-iff_pvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ OIIO_PLUGIN_NAMESPACE_BEGIN

using namespace iff_pvt;

#define STRINGIZE2(a) #a
#define STRINGIZE(a) STRINGIZE2(a)



bool
Expand All @@ -30,7 +27,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
for (;;) {
// get type and length
if (!read_typesize(fd, type, size)) {
err = "could not read type/size @ L" STRINGIZE(__LINE__);
err = "could not read type/size @ L" OIIO_STRINGIZE(__LINE__);
return false;
}

Expand All @@ -40,7 +37,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
&& type[3] == '4') {
// get type
if (!fread(&type, 1, sizeof(type), fd)) {
err = "could not read FDR4 type @ L" STRINGIZE(__LINE__);
err = "could not read FDR4 type @ L" OIIO_STRINGIZE(__LINE__);
return false;
}

Expand All @@ -50,7 +47,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
// read TBHD.
for (;;) {
if (!read_typesize(fd, type, size)) {
err = "could not read CIMG length @ L" STRINGIZE(
err = "could not read CIMG length @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -63,7 +60,8 @@ IffFileHeader::read_header(FILE* fd, std::string& err)

// test if table header size is correct
if (tbhdsize != 24 && tbhdsize != 32) {
err = "bad table header @ L" STRINGIZE(__LINE__);
err = "bad table header @ L" OIIO_STRINGIZE(
__LINE__);
return false; // bad table header
}

Expand All @@ -72,14 +70,14 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
|| !read(fd, prnum) || !read(fd, prden)
|| !read(fd, flags) || !read(fd, bytes)
|| !read(fd, tiles) || !read(fd, compression)) {
err = "@ L" STRINGIZE(__LINE__);
err = "@ L" OIIO_STRINGIZE(__LINE__);
return false;
}

// get xy
if (tbhdsize == 32) {
if (!read(fd, x) || !read(fd, y)) {
err = "could not get xy @ L" STRINGIZE(
err = "could not get xy @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -90,7 +88,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)

// tiles
if (tiles == 0) {
err = "non-tiles not supported @ L" STRINGIZE(
err = "non-tiles not supported @ L" OIIO_STRINGIZE(
__LINE__);
return false;
} // non-tiles not supported
Expand All @@ -100,7 +98,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
// 2 QRL (not supported)
// 3 QR4 (not supported)
if (compression > 1) {
err = "only RLE compression is supported @ L" STRINGIZE(
err = "only RLE compression is supported @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand Down Expand Up @@ -135,7 +133,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
for (;;) {
// get type
if (!read_typesize(fd, type, size)) {
err = "could not read type/size @ L" STRINGIZE(
err = "could not read type/size @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -146,7 +144,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
&& type[2] == 'T' && type[3] == 'H') {
std::vector<char> str(chunksize);
if (!fread(&str[0], 1, chunksize, fd)) {
err = "could not read author @ L" STRINGIZE(
err = "could not read author @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -155,15 +153,15 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
&& type[2] == 'T' && type[3] == 'E') {
std::vector<char> str(chunksize);
if (!fread(&str[0], 1, chunksize, fd)) {
err = "could not read date @ L" STRINGIZE(
err = "could not read date @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
date = std::string(&str[0], size);
} else if (type[0] == 'F' && type[1] == 'O'
&& type[2] == 'R' && type[3] == '4') {
if (!fread(&type, 1, sizeof(type), fd)) {
err = "could not read FOR4 type @ L" STRINGIZE(
err = "could not read FOR4 type @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -180,7 +178,8 @@ IffFileHeader::read_header(FILE* fd, std::string& err)

for (unsigned int t = 0; t < tiles; t++) {
if (!read_typesize(fd, type, size)) {
err = "xxx @ L" STRINGIZE(__LINE__);
err = "xxx @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
chunksize = align_size(size, 4);
Expand All @@ -195,7 +194,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
|| !read(fd, ymin)
|| !read(fd, xmax)
|| !read(fd, ymax)) {
err = "xxx @ L" STRINGIZE(
err = "xxx @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -204,7 +203,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
if (xmin > xmax || ymin > ymax
|| xmax >= width
|| ymax >= height) {
err = "tile min/max nonsensical @ L" STRINGIZE(
err = "tile min/max nonsensical @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -219,23 +218,23 @@ IffFileHeader::read_header(FILE* fd, std::string& err)

// skip to the next block.
if (fseek(fd, chunksize, SEEK_CUR)) {
err = "could not fseek @ L" STRINGIZE(
err = "could not fseek @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
}
} else {
// skip to the next block.
if (fseek(fd, chunksize, SEEK_CUR)) {
err = "could not fseek @ L" STRINGIZE(
err = "could not fseek @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
}
} else {
// skip to the next block.
if (fseek(fd, chunksize, SEEK_CUR)) {
err = "could not fseek @ L" STRINGIZE(
err = "could not fseek @ L" OIIO_STRINGIZE(
__LINE__);
return false;
}
Expand All @@ -247,19 +246,19 @@ IffFileHeader::read_header(FILE* fd, std::string& err)

// skip to the next block.
if (fseek(fd, chunksize, SEEK_CUR)) {
err = "could not fseek @ L" STRINGIZE(__LINE__);
err = "could not fseek @ L" OIIO_STRINGIZE(__LINE__);
return false;
}
}
}
}
// skip to the next block.
if (fseek(fd, chunksize, SEEK_CUR)) {
err = "could not fseek @ L" STRINGIZE(__LINE__);
err = "could not fseek @ L" OIIO_STRINGIZE(__LINE__);
return false;
}
}
err = "unknown error, ended early @ L" STRINGIZE(__LINE__);
err = "unknown error, ended early @ L" OIIO_STRINGIZE(__LINE__);
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/include/OpenImageIO/oiioversion.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#define OIIO_VERSION_TWEAK @PROJECT_VERSION_TWEAK@
#define OIIO_VERSION_RELEASE_TYPE @PROJECT_VERSION_RELEASE_TYPE@

// Preprocessor utility: stringize
#define OIIO_STRINGIZE_HELPER(a) #a
#define OIIO_STRINGIZE(a) OIIO_STRINGIZE_HELPER(a)

// Construct a single integer version number from major, minor, patch.
// Example of its use:
//
Expand Down
8 changes: 3 additions & 5 deletions src/jpeg.imageio/jpeginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ OIIO_EXPORT int jpeg_imageio_version = OIIO_PLUGIN_VERSION;
OIIO_EXPORT const char*
jpeg_imageio_library_version()
{
#define STRINGIZE2(a) #a
#define STRINGIZE(a) STRINGIZE2(a)
#ifdef LIBJPEG_TURBO_VERSION
return "jpeg-turbo " STRINGIZE(LIBJPEG_TURBO_VERSION) "/jp" STRINGIZE(
JPEG_LIB_VERSION);
return "jpeg-turbo " OIIO_STRINGIZE(
LIBJPEG_TURBO_VERSION) "/jp" OIIO_STRINGIZE(JPEG_LIB_VERSION);
#else
return "jpeglib " STRINGIZE(JPEG_LIB_VERSION_MAJOR) "." STRINGIZE(
return "jpeglib " OIIO_STRINGIZE(JPEG_LIB_VERSION_MAJOR) "." OIIO_STRINGIZE(
JPEG_LIB_VERSION_MINOR);
#endif
}
Expand Down

0 comments on commit fbe7b12

Please sign in to comment.