Leaking the 'restrict' keyword redefinition into C++

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
hwright
Posts: 6
Joined: 2015-02-20T10:24:16-07:00
Authentication code: 6789

Leaking the 'restrict' keyword redefinition into C++

Post by hwright »

'restrict' is a keyword in C99, but not C++. ImageMagick uses 'restrict' in it's public APIs, and in order to compile with C++ compilers, macro magic ensures the 'restrict' keyword is properly defined in magick/magick-baseconfig.h.

A problem occurs when this definition is leaked outside of ImageMagick. 'restrict' is a valid identifier name in C++, so a redefinition of it can cause C++ code to fail to compile. The following patch (against the 6.9.0 branch) should fix the problem.

[[[
Index: Magick++/lib/Magick++.h
===================================================================
--- Magick++/lib/Magick++.h (revision 18234)
+++ Magick++/lib/Magick++.h (working copy)
@@ -12,5 +12,11 @@
#include <Magick++/Pixels.h>
#include <Magick++/ResourceLimits.h>
#include <Magick++/STL.h>
+
+// Don't leak our definition of the 'restrict' keyword. 'restrict' is a valid
+// identifier in C++, and leaking it could cause extraneous build failures.
+#ifdef restrict
+#undef restrict
+#endif
#define MagickPlusPlus_Header
#endif // MagickPlusPlus_Header
]]]
-Hyrum
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Leaking the 'restrict' keyword redefinition into C++

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.9.1-0 Beta, available by sometime tomorrow. Thanks.
hwright
Posts: 6
Joined: 2015-02-20T10:24:16-07:00
Authentication code: 6789

Re: Leaking the 'restrict' keyword redefinition into C++

Post by hwright »

Thanks.
-Hyrum
Post Reply