Page 1 of 1

Leaking the 'restrict' keyword redefinition into C++

Posted: 2015-03-19T10:27:29-07:00
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
]]]

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

Posted: 2015-03-19T11:08:53-07:00
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.

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

Posted: 2015-03-19T11:27:49-07:00
by hwright
Thanks.