glib: add _g_assert() macro

For example, if a static function has only one caller, then the reviewer
can maybe trivially confirm invariants about the parameters. On the
other hand, if the function is called at many places and form other
files, that may be less trivial.

Assertions are always supposed to hold. But in some cases
they more obviously hold than in others.

But such assertions can still be useful, because they help catching
errors during refactoring and they act as executed comments about the
invariants.

But if they are always present even in release mode, there is an
argument to avoid the overhead of checking the condition.

Also, some assertions conditions may be more expensive to evaluate, and
be avoided for that in release mode.

The usual solution was:

  #ifdef G_ENABLE_DEBUG
     g_assert (condition);
  #endif

but that is cumbersome. It also hides the condition from the compiler in
certain modes, which can lead to unused variables warnings.

The solution now is

    _g_assert (condition);
diff --git a/glib/glib-private.h b/glib/glib-private.h
index 4dd0c20..f196429 100644
--- a/glib/glib-private.h
+++ b/glib/glib-private.h
@@ -75,6 +75,47 @@
 
 #endif
 
+#ifdef G_ENABLE_DEBUG
+/**
+ * _G_ENABLE_DEBUG:
+ *
+ * A preprocessor define that is always either 0 or 1,
+ * depending on defined(G_ENABLE_DEBUG). It can be used
+ * with #if or in C code (where the compiler recognizes
+ * this as a constant).
+ */
+#define _G_ENABLE_DEBUG 1
+#else
+#define _G_ENABLE_DEBUG 0
+#endif
+
+/**
+ * _g_assert():
+ * @condition: the condition that must evaluate to a true value.
+ *
+ * If %G_ENABLE_DEBUG is defined, this expands to a g_assert().
+ * Otherwise, it expands to (effectively) no operation.
+ *
+ * Note that the comiler will always see the condition, to avoid
+ * warnings about unused variables. But usually, the condition will
+ * not be evaluated and must have no side effects.
+ */
+#define _g_assert(condition)  \
+  G_STMT_START                \
+  {                           \
+    if (_G_ENABLE_DEBUG)      \
+      {                       \
+        g_assert (condition); \
+      }                       \
+    if (0)                    \
+      {                       \
+        if (condition)        \
+          {                   \
+          }                   \
+      }                       \
+  }                           \
+  G_STMT_END
+
 /**
  * G_CONTAINER_OF:
  * @ptr: a pointer to a member @field of type @type.