]> wimlib.net Git - wimlib/blobdiff - include/wimlib/compiler.h
Don't bother with malloc function attribute
[wimlib] / include / wimlib / compiler.h
index 2b1923c263f6c054c642d0b7c9b518b4e769f736..91445b2a6ada21275e9648ff5c1cff79f7c248d0 100644 (file)
@@ -3,21 +3,28 @@
  *
  * Compiler-specific definitions.  Currently, only GCC and clang are supported.
  *
- * The following copying information applies to this specific source code file:
+ * Copyright 2022 Eric Biggers
  *
- * Written in 2013-2016 by Eric Biggers <ebiggers3@gmail.com>
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
  *
- * To the extent possible under law, the author(s) have dedicated all copyright
- * and related and neighboring rights to this software to the public domain
- * worldwide via the Creative Commons Zero 1.0 Universal Public Domain
- * Dedication (the "CC0").
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
- * This software is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the CC0 for more details.
- *
- * You should have received a copy of the CC0 along with this software; if not
- * see <http://creativecommons.org/publicdomain/zero/1.0/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #ifndef _WIMLIB_COMPILER_H
 #  define _cold_attribute
 #endif
 
-/* Hint that the annotated function is malloc-like: any non-null pointer it
- * returns will not alias any pointer previously in use by the program.  */
-#define _malloc_attribute      __attribute__((malloc))
-
 /* Hint that the annotated function takes a printf()-like format string and
  * arguments.  This is currently disabled on Windows because MinGW does not
  * support this attribute on functions taking wide-character strings.  */
  * the case if the function contains only static assertions.  */
 #define _unused_attribute      __attribute__((unused))
 
-/* Endianness definitions.  Either CPU_IS_BIG_ENDIAN or CPU_IS_LITTLE_ENDIAN is
- * set to 1.  The other is set to 0.  Note that newer gcc supports
+/* Endianness definitions.  Either CPU_IS_BIG_ENDIAN() or CPU_IS_LITTLE_ENDIAN()
+ * evaluates to 1.  The other evaluates to 0.  Note that newer gcc supports
  * __BYTE_ORDER__ for easily determining the endianness; older gcc doesn't.  In
  * the latter case we fall back to a configure-time check.  */
 #ifdef __BYTE_ORDER__
-#  define CPU_IS_BIG_ENDIAN    (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#  define CPU_IS_BIG_ENDIAN()  (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 #elif defined(HAVE_CONFIG_H)
 #  include "config.h"
 #  ifdef WORDS_BIGENDIAN
-#    define CPU_IS_BIG_ENDIAN 1
+#    define CPU_IS_BIG_ENDIAN()        1
 #  else
-#    define CPU_IS_BIG_ENDIAN 0
+#    define CPU_IS_BIG_ENDIAN()        0
 #  endif
 #endif
-#define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN)
+#define CPU_IS_LITTLE_ENDIAN() (!CPU_IS_BIG_ENDIAN())
 
 /* UNALIGNED_ACCESS_IS_FAST should be defined to 1 if unaligned memory accesses
  * can be performed efficiently on the target platform.  */
 #  define min(a, b)  ({ typeof(a) _a = (a); typeof(b) _b = (b); \
                        (_a < _b) ? _a : _b; })
 #endif
+#define MIN(a, b)      min((a), (b))
 
 /* Get the maximum of two variables, without multiple evaluation.  */
 #ifndef max
 #  define max(a, b)  ({ typeof(a) _a = (a); typeof(b) _b = (b); \
                        (_a > _b) ? _a : _b; })
 #endif
+#define MAX(a, b)      max((a), (b))
 
 /* Swap the values of two variables, without multiple evaluation.  */
 #ifndef swap
 #  define swap(a, b) ({ typeof(a) _a = (a); (a) = (b); (b) = _a; })
 #endif
+#define SWAP(a, b)     swap((a), (b))
 
 /* (Optional) Efficiently swap the bytes of a 16-bit integer.  */
 #if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
 #endif
 
 /* STATIC_ASSERT() - verify the truth of an expression at compilation time.  */
-#if __STDC_VERSION__ >= 201112L
+#ifdef __CHECKER__
+#  define STATIC_ASSERT(expr)
+#elif __STDC_VERSION__ >= 201112L
 #  define STATIC_ASSERT(expr)  _Static_assert((expr), "")
 #else
 #  define STATIC_ASSERT(expr)  ((void)sizeof(char[1 - 2 * !(expr)]))