Skip to content

Commit 1b5c20c

Browse files
lgritz1div0
authored andcommitted
cleanup: Coalesce redundant STRINGIZE macros -> OIIO_STRINGIZE (AcademySoftwareFoundation#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 <[email protected]> Signed-off-by: Peter Kovář <[email protected]>
1 parent ca95735 commit 1b5c20c

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

src/gif.imageio/gifinput.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ OIIO_EXPORT const char* gif_input_extensions[] = { "gif", NULL };
132132
OIIO_EXPORT const char*
133133
gif_imageio_library_version()
134134
{
135-
#define STRINGIZE2(a) #a
136-
#define STRINGIZE(a) STRINGIZE2(a)
137135
#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && defined(GIFLIB_RELEASE)
138-
return "gif_lib " STRINGIZE(GIFLIB_MAJOR) "." STRINGIZE(
139-
GIFLIB_MINOR) "." STRINGIZE(GIFLIB_RELEASE);
136+
return "gif_lib " OIIO_STRINGIZE(GIFLIB_MAJOR) "." OIIO_STRINGIZE(
137+
GIFLIB_MINOR) "." OIIO_STRINGIZE(GIFLIB_RELEASE);
140138
#else
141139
return "gif_lib unknown version";
142140
#endif

src/iff.imageio/iff_pvt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ tile_height_size(uint32_t height)
107107
}
108108

109109

110-
#define STRINGIZE2(a) #a
111-
#define STRINGIZE(a) STRINGIZE2(a)
112-
113-
114110
} // namespace iff_pvt
115111

116112

src/iff.imageio/noproxy-iff_pvt.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ OIIO_PLUGIN_NAMESPACE_BEGIN
88

99
using namespace iff_pvt;
1010

11-
#define STRINGIZE2(a) #a
12-
#define STRINGIZE(a) STRINGIZE2(a)
13-
1411

1512

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

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

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

6461
// test if table header size is correct
6562
if (tbhdsize != 24 && tbhdsize != 32) {
66-
err = "bad table header @ L" STRINGIZE(__LINE__);
63+
err = "bad table header @ L" OIIO_STRINGIZE(
64+
__LINE__);
6765
return false; // bad table header
6866
}
6967

@@ -72,14 +70,14 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
7270
|| !read(fd, prnum) || !read(fd, prden)
7371
|| !read(fd, flags) || !read(fd, bytes)
7472
|| !read(fd, tiles) || !read(fd, compression)) {
75-
err = "@ L" STRINGIZE(__LINE__);
73+
err = "@ L" OIIO_STRINGIZE(__LINE__);
7674
return false;
7775
}
7876

7977
// get xy
8078
if (tbhdsize == 32) {
8179
if (!read(fd, x) || !read(fd, y)) {
82-
err = "could not get xy @ L" STRINGIZE(
80+
err = "could not get xy @ L" OIIO_STRINGIZE(
8381
__LINE__);
8482
return false;
8583
}
@@ -90,7 +88,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
9088

9189
// tiles
9290
if (tiles == 0) {
93-
err = "non-tiles not supported @ L" STRINGIZE(
91+
err = "non-tiles not supported @ L" OIIO_STRINGIZE(
9492
__LINE__);
9593
return false;
9694
} // non-tiles not supported
@@ -100,7 +98,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
10098
// 2 QRL (not supported)
10199
// 3 QR4 (not supported)
102100
if (compression > 1) {
103-
err = "only RLE compression is supported @ L" STRINGIZE(
101+
err = "only RLE compression is supported @ L" OIIO_STRINGIZE(
104102
__LINE__);
105103
return false;
106104
}
@@ -135,7 +133,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
135133
for (;;) {
136134
// get type
137135
if (!read_typesize(fd, type, size)) {
138-
err = "could not read type/size @ L" STRINGIZE(
136+
err = "could not read type/size @ L" OIIO_STRINGIZE(
139137
__LINE__);
140138
return false;
141139
}
@@ -146,7 +144,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
146144
&& type[2] == 'T' && type[3] == 'H') {
147145
std::vector<char> str(chunksize);
148146
if (!fread(&str[0], 1, chunksize, fd)) {
149-
err = "could not read author @ L" STRINGIZE(
147+
err = "could not read author @ L" OIIO_STRINGIZE(
150148
__LINE__);
151149
return false;
152150
}
@@ -155,15 +153,15 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
155153
&& type[2] == 'T' && type[3] == 'E') {
156154
std::vector<char> str(chunksize);
157155
if (!fread(&str[0], 1, chunksize, fd)) {
158-
err = "could not read date @ L" STRINGIZE(
156+
err = "could not read date @ L" OIIO_STRINGIZE(
159157
__LINE__);
160158
return false;
161159
}
162160
date = std::string(&str[0], size);
163161
} else if (type[0] == 'F' && type[1] == 'O'
164162
&& type[2] == 'R' && type[3] == '4') {
165163
if (!fread(&type, 1, sizeof(type), fd)) {
166-
err = "could not read FOR4 type @ L" STRINGIZE(
164+
err = "could not read FOR4 type @ L" OIIO_STRINGIZE(
167165
__LINE__);
168166
return false;
169167
}
@@ -180,7 +178,8 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
180178

181179
for (unsigned int t = 0; t < tiles; t++) {
182180
if (!read_typesize(fd, type, size)) {
183-
err = "xxx @ L" STRINGIZE(__LINE__);
181+
err = "xxx @ L" OIIO_STRINGIZE(
182+
__LINE__);
184183
return false;
185184
}
186185
chunksize = align_size(size, 4);
@@ -195,7 +194,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
195194
|| !read(fd, ymin)
196195
|| !read(fd, xmax)
197196
|| !read(fd, ymax)) {
198-
err = "xxx @ L" STRINGIZE(
197+
err = "xxx @ L" OIIO_STRINGIZE(
199198
__LINE__);
200199
return false;
201200
}
@@ -204,7 +203,7 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
204203
if (xmin > xmax || ymin > ymax
205204
|| xmax >= width
206205
|| ymax >= height) {
207-
err = "tile min/max nonsensical @ L" STRINGIZE(
206+
err = "tile min/max nonsensical @ L" OIIO_STRINGIZE(
208207
__LINE__);
209208
return false;
210209
}
@@ -219,23 +218,23 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
219218

220219
// skip to the next block.
221220
if (fseek(fd, chunksize, SEEK_CUR)) {
222-
err = "could not fseek @ L" STRINGIZE(
221+
err = "could not fseek @ L" OIIO_STRINGIZE(
223222
__LINE__);
224223
return false;
225224
}
226225
}
227226
} else {
228227
// skip to the next block.
229228
if (fseek(fd, chunksize, SEEK_CUR)) {
230-
err = "could not fseek @ L" STRINGIZE(
229+
err = "could not fseek @ L" OIIO_STRINGIZE(
231230
__LINE__);
232231
return false;
233232
}
234233
}
235234
} else {
236235
// skip to the next block.
237236
if (fseek(fd, chunksize, SEEK_CUR)) {
238-
err = "could not fseek @ L" STRINGIZE(
237+
err = "could not fseek @ L" OIIO_STRINGIZE(
239238
__LINE__);
240239
return false;
241240
}
@@ -247,19 +246,19 @@ IffFileHeader::read_header(FILE* fd, std::string& err)
247246

248247
// skip to the next block.
249248
if (fseek(fd, chunksize, SEEK_CUR)) {
250-
err = "could not fseek @ L" STRINGIZE(__LINE__);
249+
err = "could not fseek @ L" OIIO_STRINGIZE(__LINE__);
251250
return false;
252251
}
253252
}
254253
}
255254
}
256255
// skip to the next block.
257256
if (fseek(fd, chunksize, SEEK_CUR)) {
258-
err = "could not fseek @ L" STRINGIZE(__LINE__);
257+
err = "could not fseek @ L" OIIO_STRINGIZE(__LINE__);
259258
return false;
260259
}
261260
}
262-
err = "unknown error, ended early @ L" STRINGIZE(__LINE__);
261+
err = "unknown error, ended early @ L" OIIO_STRINGIZE(__LINE__);
263262
return false;
264263
}
265264

src/include/OpenImageIO/oiioversion.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#define OIIO_VERSION_TWEAK @PROJECT_VERSION_TWEAK@
4949
#define OIIO_VERSION_RELEASE_TYPE @PROJECT_VERSION_RELEASE_TYPE@
5050

51+
// Preprocessor utility: stringize
52+
#define OIIO_STRINGIZE_HELPER(a) #a
53+
#define OIIO_STRINGIZE(a) OIIO_STRINGIZE_HELPER(a)
54+
5155
// Construct a single integer version number from major, minor, patch.
5256
// Example of its use:
5357
//

src/jpeg.imageio/jpeginput.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ OIIO_EXPORT int jpeg_imageio_version = OIIO_PLUGIN_VERSION;
2727
OIIO_EXPORT const char*
2828
jpeg_imageio_library_version()
2929
{
30-
#define STRINGIZE2(a) #a
31-
#define STRINGIZE(a) STRINGIZE2(a)
3230
#ifdef LIBJPEG_TURBO_VERSION
33-
return "jpeg-turbo " STRINGIZE(LIBJPEG_TURBO_VERSION) "/jp" STRINGIZE(
34-
JPEG_LIB_VERSION);
31+
return "jpeg-turbo " OIIO_STRINGIZE(
32+
LIBJPEG_TURBO_VERSION) "/jp" OIIO_STRINGIZE(JPEG_LIB_VERSION);
3533
#else
36-
return "jpeglib " STRINGIZE(JPEG_LIB_VERSION_MAJOR) "." STRINGIZE(
34+
return "jpeglib " OIIO_STRINGIZE(JPEG_LIB_VERSION_MAJOR) "." OIIO_STRINGIZE(
3735
JPEG_LIB_VERSION_MINOR);
3836
#endif
3937
}

0 commit comments

Comments
 (0)