gthread: avoid locking in _get_mutex_impl
[platform/upstream/glib.git] / glib / gmacros.h
index ad52ebb..aed6d09 100644 (file)
@@ -28,7 +28,7 @@
  * not refer to variables from glibconfig.h
  */
 
-#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__G_LIB_H__) && !defined (GLIB_COMPILATION)
+#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
 #error "Only <glib.h> can be included directly."
 #endif
 
 #define G_GNUC_DEPRECATED
 #endif /* __GNUC__ */
 
+#if    __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define G_GNUC_DEPRECATED_FOR(f)                        \
+  __attribute__((deprecated("Use " #f " instead")))
+#else
+#define G_GNUC_DEPRECATED_FOR(f)        G_GNUC_DEPRECATED
+#endif /* __GNUC__ */
+
 #if     __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 #  define G_GNUC_MAY_ALIAS __attribute__((may_alias))
 #else
 #define G_STRINGIFY(macro_or_string)   G_STRINGIFY_ARG (macro_or_string)
 #define        G_STRINGIFY_ARG(contents)       #contents
 
+#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
+#define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
+#define G_STATIC_ASSERT(expr) typedef struct { char Compile_Time_Assertion[(expr) ? 1 : -1]; } G_PASTE (_GStaticAssert_, __LINE__)
+#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
+
 /* Provide a string identifying the current code position */
 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
 #  define G_STRLOC     __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
 /* Provide a string identifying the current function, non-concatenatable */
 #if defined (__GNUC__)
 #  define G_STRFUNC     ((const char*) (__PRETTY_FUNCTION__))
-#elif defined (G_HAVE_ISO_VARARGS)
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
 #  define G_STRFUNC     ((const char*) (__func__))
 #else
 #  define G_STRFUNC     ((const char*) ("???"))
 /* Provide convenience macros for handling structure
  * fields through their offsets.
  */
-#define G_STRUCT_OFFSET(struct_type, member)   \
-    ((glong) ((guint8*) &((struct_type*) 0)->member))
+
+#if defined(__GNUC__)  && __GNUC__ >= 4
+#  define G_STRUCT_OFFSET(struct_type, member) \
+      ((glong) offsetof (struct_type, member))
+#else
+#  define G_STRUCT_OFFSET(struct_type, member) \
+      ((glong) ((guint8*) &((struct_type*) 0)->member))
+#endif
+
 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
     ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
 
-/* Provide simple macro statement wrappers (adapted from Perl):
- *  G_STMT_START { statements; } G_STMT_END;
- *  can be used as a single statement, as in
- *  if (x) G_STMT_START { ... } G_STMT_END; else ...
- *
- *  When GCC is compiling C code in non-ANSI mode, it will use the
- *  compiler __extension__ to wrap the statements wihin `({' and '})' braces.
- *  When compiling on platforms where configure has defined
- *  HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
- *  For any other platforms (SunOS4 is known to have this issue), wrap the
- *  statements with `if (1)' and `else (void) 0'.
+/* Provide simple macro statement wrappers:
+ *   G_STMT_START { statements; } G_STMT_END;
+ * This can be used as a single statement, like:
+ *   if (x) G_STMT_START { ... } G_STMT_END; else ...
+ * This intentionally does not use compiler extensions like GCC's '({...})' to
+ * avoid portability issue or side effects when compiled with different compilers.
  */
 #if !(defined (G_STMT_START) && defined (G_STMT_END))
-# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
-#  define G_STMT_START (void) __extension__ (
-#  define G_STMT_END )
-# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
-#  if defined (HAVE_DOWHILE_MACROS)
-#   define G_STMT_START do
-#   define G_STMT_END while (0)
-#  else /* !HAVE_DOWHILE_MACROS */
-#   define G_STMT_START if (1)
-#   define G_STMT_END else (void) 0
-#  endif /* !HAVE_DOWHILE_MACROS */
-# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
+#  define G_STMT_START  do
+#  define G_STMT_END    while (0)
 #endif
 
 /* Allow the app programmer to select whether or not return values
  */
 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
 #define _G_BOOLEAN_EXPR(expr)                   \
__extension__ ({                               \
G_GNUC_EXTENSION ({                            \
    int _g_boolean_var_;                         \
    if (expr)                                    \
       _g_boolean_var_ = 1;                      \