Merge branch '1708-build-with-g-disable-assert' into 'master'

Fix build with G_DISABLE_ASSERT defined

Closes #1708

See merge request GNOME/glib!705
This commit is contained in:
Philip Withnall 2019-03-08 19:59:36 +00:00
commit 3e7baaae23
35 changed files with 299 additions and 228 deletions

View File

@ -51,6 +51,30 @@ fedora-x86_64:
- "_build/meson-logs"
- "_coverage"
G_DISABLE_ASSERT:
stage: build
except:
- tags
variables:
CPPFLAGS: "-DG_DISABLE_ASSERT"
script:
- meson ${MESON_COMMON_OPTIONS}
--werror
-Dsystemtap=true
-Ddtrace=true
-Dfam=true
-Dinstalled_tests=true
_build
- ninja -C _build
- meson test -C _build --timeout-multiplier ${MESON_TEST_TIMEOUT_MULTIPLIER} --no-suite flaky
artifacts:
name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}"
when: always
paths:
- "_build/config.h"
- "_build/glib/glibconfig.h"
- "_build/meson-logs"
.cross-template: &cross-template
stage: build
except:

View File

@ -774,7 +774,7 @@ g_application_impl_command_line (GApplicationImpl *impl,
const gchar *object_path = "/org/gtk/Application/CommandLine";
GMainContext *context;
CommandLineData data;
guint object_id;
guint object_id G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
context = g_main_context_new ();
data.loop = g_main_loop_new (context, FALSE);

View File

@ -936,7 +936,7 @@ g_data_input_stream_read_until (GDataInputStream *stream,
/* If we're not at end of stream then we have a stop_char to consume. */
if (result != NULL && g_buffered_input_stream_get_available (bstream) > 0)
{
gsize res;
gsize res G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
gchar b;
res = g_input_stream_read (G_INPUT_STREAM (stream), &b, 1, NULL, NULL);

View File

@ -1714,7 +1714,7 @@ parse_value_from_blob (GMemoryBuffer *buf,
if (array_len == 0)
{
GVariant *item;
GVariant *item G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
item = parse_value_from_blob (buf,
element_type,
TRUE,
@ -2345,7 +2345,10 @@ append_value_to_blob (GVariant *value,
{
gsize len;
const gchar *v;
#ifndef G_DISABLE_ASSERT
const gchar *end;
#endif
v = g_variant_get_string (value, &len);
g_assert (g_utf8_validate (v, -1, &end) && (end == v + len));
g_memory_buffer_put_uint32 (mbuf, len);

View File

@ -179,7 +179,8 @@ ensure_attribute_hash (void)
attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
#define REGISTER_ATTRIBUTE(name) G_STMT_START{\
guint _u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \
guint _u G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */; \
_u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \
/* use for generating the ID: g_print ("#define G_FILE_ATTRIBUTE_ID_%s (%u + %u)\n", #name + 17, _u & ~ID_MASK, _u & ID_MASK); */ \
g_assert (_u == G_FILE_ATTRIBUTE_ID_ ## name); \
}G_STMT_END

View File

@ -334,7 +334,7 @@ g_keyfile_settings_backend_write_one (gpointer key,
gpointer user_data)
{
WriteManyData *data = user_data;
gboolean success;
gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
success = set_to_keyfile (data->kfsb, key, value);
g_assert (success);

View File

@ -648,8 +648,10 @@ key_state_serialise (KeyState *state)
else
{
GVariantBuilder builder;
gboolean checked G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
g_assert (key_state_check (state, NULL));
checked = key_state_check (state, NULL);
g_assert (checked);
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);

View File

@ -328,6 +328,7 @@ g_file_monitor_source_send_synthetic_created (GFileMonitorSource *fms,
g_file_monitor_source_queue_event (fms, G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT, child, NULL);
}
#ifndef G_DISABLE_ASSERT
static gboolean
is_basename (const gchar *name)
{
@ -336,6 +337,7 @@ is_basename (const gchar *name)
return !strchr (name, '/');
}
#endif /* !G_DISABLE_ASSERT */
gboolean
g_file_monitor_source_handle_event (GFileMonitorSource *fms,

View File

@ -1455,7 +1455,7 @@ gint
g_settings_schema_key_to_enum (GSettingsSchemaKey *key,
GVariant *value)
{
gboolean it_worked;
gboolean it_worked G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
guint result;
it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length,
@ -1499,7 +1499,7 @@ g_settings_schema_key_to_flags (GSettingsSchemaKey *key,
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "&s", &flag))
{
gboolean it_worked;
gboolean it_worked G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
guint flag_value;
it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length, flag, &flag_value);

View File

@ -389,7 +389,9 @@ g_socket_connection_set_property (GObject *object,
static void
g_socket_connection_constructed (GObject *object)
{
#ifndef G_DISABLE_ASSERT
GSocketConnection *connection = G_SOCKET_CONNECTION (object);
#endif
g_assert (connection->priv->socket != NULL);
}

View File

@ -575,7 +575,7 @@ initable_init (GInitable *initable,
{
guint64 identifier;
gint s;
gint s G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
#ifdef G_OS_WIN32
identifier = (guint64) GetProcessId (self->pid);

View File

@ -55,7 +55,7 @@ g_inotify_file_monitor_start (GLocalFileMonitor *local_monitor,
GFileMonitorSource *source)
{
GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (local_monitor);
gboolean success;
gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
/* should already have been called, from is_supported() */
success = _ih_startup ();
@ -83,7 +83,9 @@ g_inotify_file_monitor_cancel (GFileMonitor *monitor)
static void
g_inotify_file_monitor_finalize (GObject *object)
{
#ifndef G_DISABLE_ASSERT
GInotifyFileMonitor *inotify_monitor = G_INOTIFY_FILE_MONITOR (object);
#endif
/* must surely have been cancelled already */
g_assert (!inotify_monitor->sub);

View File

@ -36,11 +36,11 @@ test_basic (void)
GVariant *state;
action = g_simple_action_new ("foo", NULL);
g_assert (g_action_get_enabled (G_ACTION (action)));
g_assert (g_action_get_parameter_type (G_ACTION (action)) == NULL);
g_assert (g_action_get_state_type (G_ACTION (action)) == NULL);
g_assert (g_action_get_state_hint (G_ACTION (action)) == NULL);
g_assert (g_action_get_state (G_ACTION (action)) == NULL);
g_assert_true (g_action_get_enabled (G_ACTION (action)));
g_assert_null (g_action_get_parameter_type (G_ACTION (action)));
g_assert_null (g_action_get_state_type (G_ACTION (action)));
g_assert_null (g_action_get_state_hint (G_ACTION (action)));
g_assert_null (g_action_get_state (G_ACTION (action)));
g_object_get (action,
"name", &name,
"parameter-type", &parameter_type,
@ -49,21 +49,21 @@ test_basic (void)
"state", &state,
NULL);
g_assert_cmpstr (name, ==, "foo");
g_assert (parameter_type == NULL);
g_assert (enabled);
g_assert (state_type == NULL);
g_assert (state == NULL);
g_assert_null (parameter_type);
g_assert_true (enabled);
g_assert_null (state_type);
g_assert_null (state);
g_free (name);
g_signal_connect (action, "activate", G_CALLBACK (activate), &a);
g_assert (!a.did_run);
g_assert_false (a.did_run);
g_action_activate (G_ACTION (action), NULL);
g_assert (a.did_run);
g_assert_true (a.did_run);
a.did_run = FALSE;
g_simple_action_set_enabled (action, FALSE);
g_action_activate (G_ACTION (action), NULL);
g_assert (!a.did_run);
g_assert_false (a.did_run);
if (g_test_undefined ())
{
@ -74,19 +74,19 @@ test_basic (void)
}
g_object_unref (action);
g_assert (!a.did_run);
g_assert_false (a.did_run);
action = g_simple_action_new ("foo", G_VARIANT_TYPE_STRING);
g_assert (g_action_get_enabled (G_ACTION (action)));
g_assert (g_variant_type_equal (g_action_get_parameter_type (G_ACTION (action)), G_VARIANT_TYPE_STRING));
g_assert (g_action_get_state_type (G_ACTION (action)) == NULL);
g_assert (g_action_get_state_hint (G_ACTION (action)) == NULL);
g_assert (g_action_get_state (G_ACTION (action)) == NULL);
g_assert_true (g_action_get_enabled (G_ACTION (action)));
g_assert_true (g_variant_type_equal (g_action_get_parameter_type (G_ACTION (action)), G_VARIANT_TYPE_STRING));
g_assert_null (g_action_get_state_type (G_ACTION (action)));
g_assert_null (g_action_get_state_hint (G_ACTION (action)));
g_assert_null (g_action_get_state (G_ACTION (action)));
g_signal_connect (action, "activate", G_CALLBACK (activate), &a);
g_assert (!a.did_run);
g_assert_false (a.did_run);
g_action_activate (G_ACTION (action), g_variant_new_string ("Hello world"));
g_assert (a.did_run);
g_assert_true (a.did_run);
g_assert_cmpstr (g_variant_get_string (a.params, NULL), ==, "Hello world");
g_variant_unref (a.params);
a.did_run = FALSE;
@ -100,18 +100,18 @@ test_basic (void)
}
g_object_unref (action);
g_assert (!a.did_run);
g_assert_false (a.did_run);
}
static void
test_name (void)
{
g_assert (!g_action_name_is_valid (""));
g_assert (!g_action_name_is_valid ("("));
g_assert (!g_action_name_is_valid ("%abc"));
g_assert (!g_action_name_is_valid ("$x1"));
g_assert (g_action_name_is_valid ("abc.def"));
g_assert (g_action_name_is_valid ("ABC-DEF"));
g_assert_false (g_action_name_is_valid (""));
g_assert_false (g_action_name_is_valid ("("));
g_assert_false (g_action_name_is_valid ("%abc"));
g_assert_false (g_action_name_is_valid ("$x1"));
g_assert_true (g_action_name_is_valid ("abc.def"));
g_assert_true (g_action_name_is_valid ("ABC-DEF"));
}
static gboolean
@ -193,41 +193,41 @@ test_simple_group (void)
simple = g_simple_action_new ("foo", NULL);
g_signal_connect (simple, "activate", G_CALLBACK (activate), &a);
g_assert (!a.did_run);
g_assert_false (a.did_run);
g_action_activate (G_ACTION (simple), NULL);
g_assert (a.did_run);
g_assert_true (a.did_run);
a.did_run = FALSE;
group = g_simple_action_group_new ();
g_simple_action_group_insert (group, G_ACTION (simple));
g_object_unref (simple);
g_assert (!a.did_run);
g_assert_false (a.did_run);
g_action_group_activate_action (G_ACTION_GROUP (group), "foo", NULL);
g_assert (a.did_run);
g_assert_true (a.did_run);
simple = g_simple_action_new_stateful ("bar", G_VARIANT_TYPE_STRING, g_variant_new_string ("hihi"));
g_simple_action_group_insert (group, G_ACTION (simple));
g_object_unref (simple);
g_assert (g_action_group_has_action (G_ACTION_GROUP (group), "foo"));
g_assert (g_action_group_has_action (G_ACTION_GROUP (group), "bar"));
g_assert (!g_action_group_has_action (G_ACTION_GROUP (group), "baz"));
g_assert_true (g_action_group_has_action (G_ACTION_GROUP (group), "foo"));
g_assert_true (g_action_group_has_action (G_ACTION_GROUP (group), "bar"));
g_assert_false (g_action_group_has_action (G_ACTION_GROUP (group), "baz"));
actions = g_action_group_list_actions (G_ACTION_GROUP (group));
g_assert_cmpint (g_strv_length (actions), ==, 2);
g_assert (strv_set_equal (actions, "foo", "bar", NULL));
g_assert_true (strv_set_equal (actions, "foo", "bar", NULL));
g_strfreev (actions);
g_assert (g_action_group_get_action_enabled (G_ACTION_GROUP (group), "foo"));
g_assert (g_action_group_get_action_enabled (G_ACTION_GROUP (group), "bar"));
g_assert (g_action_group_get_action_parameter_type (G_ACTION_GROUP (group), "foo") == NULL);
g_assert (g_variant_type_equal (g_action_group_get_action_parameter_type (G_ACTION_GROUP (group), "bar"), G_VARIANT_TYPE_STRING));
g_assert (g_action_group_get_action_state_type (G_ACTION_GROUP (group), "foo") == NULL);
g_assert (g_variant_type_equal (g_action_group_get_action_state_type (G_ACTION_GROUP (group), "bar"), G_VARIANT_TYPE_STRING));
g_assert (g_action_group_get_action_state_hint (G_ACTION_GROUP (group), "foo") == NULL);
g_assert (g_action_group_get_action_state_hint (G_ACTION_GROUP (group), "bar") == NULL);
g_assert (g_action_group_get_action_state (G_ACTION_GROUP (group), "foo") == NULL);
g_assert_true (g_action_group_get_action_enabled (G_ACTION_GROUP (group), "foo"));
g_assert_true (g_action_group_get_action_enabled (G_ACTION_GROUP (group), "bar"));
g_assert_null (g_action_group_get_action_parameter_type (G_ACTION_GROUP (group), "foo"));
g_assert_true (g_variant_type_equal (g_action_group_get_action_parameter_type (G_ACTION_GROUP (group), "bar"), G_VARIANT_TYPE_STRING));
g_assert_null (g_action_group_get_action_state_type (G_ACTION_GROUP (group), "foo"));
g_assert_true (g_variant_type_equal (g_action_group_get_action_state_type (G_ACTION_GROUP (group), "bar"), G_VARIANT_TYPE_STRING));
g_assert_null (g_action_group_get_action_state_hint (G_ACTION_GROUP (group), "foo"));
g_assert_null (g_action_group_get_action_state_hint (G_ACTION_GROUP (group), "bar"));
g_assert_null (g_action_group_get_action_state (G_ACTION_GROUP (group), "foo"));
state = g_action_group_get_action_state (G_ACTION_GROUP (group), "bar");
g_assert (g_variant_type_equal (g_variant_get_type (state), G_VARIANT_TYPE_STRING));
g_assert_true (g_variant_type_equal (g_variant_get_type (state), G_VARIANT_TYPE_STRING));
g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "hihi");
g_variant_unref (state);
@ -238,13 +238,13 @@ test_simple_group (void)
action = g_simple_action_group_lookup (group, "bar");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
g_assert (!g_action_group_get_action_enabled (G_ACTION_GROUP (group), "bar"));
g_assert_false (g_action_group_get_action_enabled (G_ACTION_GROUP (group), "bar"));
g_simple_action_group_remove (group, "bar");
action = g_simple_action_group_lookup (group, "foo");
g_assert_cmpstr (g_action_get_name (action), ==, "foo");
action = g_simple_action_group_lookup (group, "bar");
g_assert (action == NULL);
g_assert_null (action);
simple = g_simple_action_new ("foo", NULL);
g_simple_action_group_insert (group, G_ACTION (simple));
@ -252,7 +252,7 @@ test_simple_group (void)
a.did_run = FALSE;
g_object_unref (group);
g_assert (!a.did_run);
g_assert_false (a.did_run);
}
G_GNUC_END_IGNORE_DEPRECATIONS
@ -264,11 +264,11 @@ test_stateful (void)
GVariant *state;
action = g_simple_action_new_stateful ("foo", NULL, g_variant_new_string ("hihi"));
g_assert (g_action_get_enabled (G_ACTION (action)));
g_assert (g_action_get_parameter_type (G_ACTION (action)) == NULL);
g_assert (g_action_get_state_hint (G_ACTION (action)) == NULL);
g_assert (g_variant_type_equal (g_action_get_state_type (G_ACTION (action)),
G_VARIANT_TYPE_STRING));
g_assert_true (g_action_get_enabled (G_ACTION (action)));
g_assert_null (g_action_get_parameter_type (G_ACTION (action)));
g_assert_null (g_action_get_state_hint (G_ACTION (action)));
g_assert_true (g_variant_type_equal (g_action_get_state_type (G_ACTION (action)),
G_VARIANT_TYPE_STRING));
state = g_action_get_state (G_ACTION (action));
g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "hihi");
g_variant_unref (state);
@ -319,12 +319,12 @@ test_default_activate (void)
action = g_simple_action_new_stateful ("foo", NULL, g_variant_new_boolean (FALSE));
g_action_activate (G_ACTION (action), NULL);
state = g_action_get_state (G_ACTION (action));
g_assert (g_variant_get_boolean (state));
g_assert_true (g_variant_get_boolean (state));
g_variant_unref (state);
/* and back again */
g_action_activate (G_ACTION (action), NULL);
state = g_action_get_state (G_ACTION (action));
g_assert (!g_variant_get_boolean (state));
g_assert_false (g_variant_get_boolean (state));
g_variant_unref (state);
g_object_unref (action);
}
@ -337,8 +337,8 @@ activate_foo (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
g_assert (user_data == GINT_TO_POINTER (123));
g_assert (parameter == NULL);
g_assert_true (user_data == GINT_TO_POINTER (123));
g_assert_null (parameter);
foo_activated = TRUE;
}
@ -347,7 +347,7 @@ activate_bar (GSimpleAction *simple,
GVariant *parameter,
gpointer user_data)
{
g_assert (user_data == GINT_TO_POINTER (123));
g_assert_true (user_data == GINT_TO_POINTER (123));
g_assert_cmpstr (g_variant_get_string (parameter, NULL), ==, "param");
bar_activated = TRUE;
}
@ -385,16 +385,16 @@ test_entries (void)
G_N_ELEMENTS (entries),
GINT_TO_POINTER (123));
g_assert (!foo_activated);
g_assert_false (foo_activated);
g_action_group_activate_action (G_ACTION_GROUP (actions), "foo", NULL);
g_assert (foo_activated);
g_assert_true (foo_activated);
foo_activated = FALSE;
g_assert (!bar_activated);
g_assert_false (bar_activated);
g_action_group_activate_action (G_ACTION_GROUP (actions), "bar",
g_variant_new_string ("param"));
g_assert (bar_activated);
g_assert (!foo_activated);
g_assert_true (bar_activated);
g_assert_false (foo_activated);
if (g_test_undefined ())
{
@ -478,7 +478,7 @@ test_parse_detailed (void)
gchar *name;
success = g_action_parse_detailed_name (testcases[i].detailed, &name, &target, &error);
g_assert (success == (error == NULL));
g_assert_true (success == (error == NULL));
if (success && testcases[i].expected_error)
g_error ("Unexpected success on '%s'. Expected error containing '%s'",
testcases[i].detailed, testcases[i].expected_error);
@ -497,7 +497,7 @@ test_parse_detailed (void)
}
g_assert_cmpstr (name, ==, testcases[i].expected_name);
g_assert ((target == NULL) == (testcases[i].expected_target == NULL));
g_assert_true ((target == NULL) == (testcases[i].expected_target == NULL));
if (success)
{
@ -513,7 +513,7 @@ test_parse_detailed (void)
GVariant *expected;
expected = g_variant_parse (NULL, testcases[i].expected_target, NULL, NULL, NULL);
g_assert (expected);
g_assert_true (expected);
g_assert_cmpvariant (expected, target);
g_variant_unref (expected);
@ -659,7 +659,7 @@ list_cb (GObject *source,
gchar **actions;
v = g_dbus_connection_call_finish (bus, res, &error);
g_assert (v);
g_assert_nonnull (v);
g_variant_get (v, "(^a&s)", &actions);
g_assert_cmpint (g_strv_length (actions), ==, G_N_ELEMENTS (exported_entries));
g_free (actions);
@ -704,10 +704,10 @@ describe_cb (GObject *source,
GVariantIter *iter;
v = g_dbus_connection_call_finish (bus, res, &error);
g_assert (v);
g_assert_nonnull (v);
/* FIXME: there's an extra level of tuplelization in here */
g_variant_get (v, "((bgav))", &enabled, &param, &iter);
g_assert (enabled == TRUE);
g_assert_true (enabled);
g_assert_cmpstr (param, ==, "");
g_assert_cmpint (g_variant_iter_n_children (iter), ==, 0);
g_free (param);
@ -791,8 +791,8 @@ test_dbus_export (void)
g_main_loop_run (loop);
/* test that the initial transfer works */
g_assert (G_IS_DBUS_ACTION_GROUP (proxy));
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (G_IS_DBUS_ACTION_GROUP (proxy));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
/* test that various changes get propagated from group to proxy */
action = g_simple_action_new_stateful ("italic", NULL, g_variant_new_boolean (FALSE));
@ -802,7 +802,7 @@ test_dbus_export (void)
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
action = G_SIMPLE_ACTION (g_simple_action_group_lookup (group, "cut"));
g_simple_action_set_enabled (action, FALSE);
@ -810,7 +810,7 @@ test_dbus_export (void)
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
action = G_SIMPLE_ACTION (g_simple_action_group_lookup (group, "bold"));
g_simple_action_set_state (action, g_variant_new_boolean (FALSE));
@ -818,14 +818,14 @@ test_dbus_export (void)
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_simple_action_group_remove (group, "italic");
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
/* test that activations and state changes propagate the other way */
@ -836,7 +836,7 @@ test_dbus_export (void)
g_main_loop_run (loop);
g_assert_cmpint (activation_count ("copy"), ==, 1);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_cmpint (activation_count ("bold"), ==, 0);
g_action_group_activate_action (G_ACTION_GROUP (proxy), "bold", NULL);
@ -845,9 +845,9 @@ test_dbus_export (void)
g_main_loop_run (loop);
g_assert_cmpint (activation_count ("bold"), ==, 1);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
v = g_action_group_get_action_state (G_ACTION_GROUP (group), "bold");
g_assert (g_variant_get_boolean (v));
g_assert_true (g_variant_get_boolean (v));
g_variant_unref (v);
g_action_group_change_action_state (G_ACTION_GROUP (proxy), "bold", g_variant_new_boolean (FALSE));
@ -856,9 +856,9 @@ test_dbus_export (void)
g_main_loop_run (loop);
g_assert_cmpint (activation_count ("bold"), ==, 1);
g_assert (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
g_assert_true (compare_action_groups (G_ACTION_GROUP (group), G_ACTION_GROUP (proxy)));
v = g_action_group_get_action_state (G_ACTION_GROUP (group), "bold");
g_assert (!g_variant_get_boolean (v));
g_assert_false (g_variant_get_boolean (v));
g_variant_unref (v);
g_dbus_connection_unexport_action_group (bus, id);
@ -980,7 +980,7 @@ state_changed (GActionGroup *group,
{
GString *string;
g_assert (!state_change_log);
g_assert_false (state_change_log);
string = g_string_new (action_name);
g_string_append_c (string, ':');
@ -1038,7 +1038,7 @@ test_property_actions (void)
action = g_property_action_new ("keepalive", app, "inactivity-timeout");
g_object_get (action, "name", &name, "parameter-type", &ptype, "enabled", &enabled, "state-type", &stype, "state", &state, NULL);
g_assert_cmpstr (name, ==, "keepalive");
g_assert (enabled);
g_assert_true (enabled);
g_free (name);
g_variant_type_free (ptype);
g_variant_type_free (stype);
@ -1112,24 +1112,24 @@ test_property_actions (void)
/* bool tests */
g_action_group_change_action_state (G_ACTION_GROUP (group), "tls", g_variant_new ("b", TRUE));
verify_changed ("tls:true");
g_assert (g_socket_client_get_tls (client));
g_assert_true (g_socket_client_get_tls (client));
ensure_state (group, "tls", "true");
g_action_group_change_action_state (G_ACTION_GROUP (group), "disable-proxy", g_variant_new ("b", TRUE));
verify_changed ("disable-proxy:true");
ensure_state (group, "disable-proxy", "true");
g_assert (!g_socket_client_get_enable_proxy (client));
g_assert_false (g_socket_client_get_enable_proxy (client));
/* test toggle true->false */
g_action_group_activate_action (G_ACTION_GROUP (group), "tls", NULL);
verify_changed ("tls:false");
g_assert (!g_socket_client_get_tls (client));
g_assert_false (g_socket_client_get_tls (client));
ensure_state (group, "tls", "false");
/* and now back false->true */
g_action_group_activate_action (G_ACTION_GROUP (group), "tls", NULL);
verify_changed ("tls:true");
g_assert (g_socket_client_get_tls (client));
g_assert_true (g_socket_client_get_tls (client));
ensure_state (group, "tls", "true");
g_socket_client_set_tls (client, FALSE);
@ -1139,12 +1139,12 @@ test_property_actions (void)
/* now do the same for the inverted action */
g_action_group_activate_action (G_ACTION_GROUP (group), "disable-proxy", NULL);
verify_changed ("disable-proxy:false");
g_assert (g_socket_client_get_enable_proxy (client));
g_assert_true (g_socket_client_get_enable_proxy (client));
ensure_state (group, "disable-proxy", "false");
g_action_group_activate_action (G_ACTION_GROUP (group), "disable-proxy", NULL);
verify_changed ("disable-proxy:true");
g_assert (!g_socket_client_get_enable_proxy (client));
g_assert_false (g_socket_client_get_enable_proxy (client));
ensure_state (group, "disable-proxy", "true");
g_socket_client_set_enable_proxy (client, TRUE);

View File

@ -73,11 +73,11 @@ test_noop (void)
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
id = g_subprocess_get_identifier (proc);
g_assert (id != NULL);
g_assert_nonnull (id);
g_subprocess_wait_check (proc, NULL, error);
g_assert_no_error (local_error);
g_assert (g_subprocess_get_successful (proc));
g_assert_true (g_subprocess_get_successful (proc));
g_object_unref (proc);
}
@ -93,7 +93,7 @@ check_ready (GObject *source,
ret = g_subprocess_wait_check_finish (G_SUBPROCESS (source),
res,
&error);
g_assert (ret);
g_assert_true (ret);
g_assert_no_error (error);
g_object_unref (source);
@ -218,7 +218,7 @@ test_exit1_cancel_wait_check_cb (GObject *source,
data->cb_called = TRUE;
ret = g_subprocess_wait_check_finish (subprocess, result, &error);
g_assert (!ret);
g_assert_false (ret);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
g_clear_error (&error);
@ -271,7 +271,7 @@ test_exit1_cancel_in_cb_wait_check_cb (GObject *source,
data->cb_called = TRUE;
ret = g_subprocess_wait_check_finish (subprocess, result, &error);
g_assert (!ret);
g_assert_false (ret);
g_assert_error (error, G_SPAWN_EXIT_ERROR, 1);
g_clear_error (&error);
@ -501,7 +501,7 @@ test_cat_eof (void)
/* Spawn 'cat' */
cat = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error, "cat", NULL);
g_assert_no_error (error);
g_assert (cat);
g_assert_nonnull (cat);
/* Make sure that reading stdout blocks (until we cancel) */
cancellable = g_cancellable_new ();
@ -515,19 +515,19 @@ test_cat_eof (void)
/* Close the stream (EOF on cat's stdin) */
result = g_output_stream_close (g_subprocess_get_stdin_pipe (cat), NULL, &error);
g_assert_no_error (error);
g_assert (result);
g_assert_true (result);
/* Now check that reading cat's stdout gets us an EOF (since it quit) */
s = g_input_stream_read (g_subprocess_get_stdout_pipe (cat), &buffer, sizeof buffer, NULL, &error);
g_assert_no_error (error);
g_assert (!s);
g_assert_false (s);
/* Check that the process has exited as a result of the EOF */
result = g_subprocess_wait (cat, NULL, &error);
g_assert_no_error (error);
g_assert (g_subprocess_get_if_exited (cat));
g_assert_true (g_subprocess_get_if_exited (cat));
g_assert_cmpint (g_subprocess_get_exit_status (cat), ==, 0);
g_assert (result);
g_assert_true (result);
g_object_unref (cat);
}
@ -686,7 +686,7 @@ test_multi_1 (void)
g_main_loop_run (data.loop);
g_assert (!data.caught_error);
g_assert_false (data.caught_error);
g_assert_no_error (data.error);
g_assert_cmpint (g_memory_output_stream_get_data_size ((GMemoryOutputStream*)membuf), ==, SPLICELEN);
@ -1279,11 +1279,11 @@ on_request_quit_exited (GObject *object,
g_subprocess_wait_finish (subprocess, result, &error);
g_assert_no_error (error);
#ifdef G_OS_UNIX
g_assert (g_subprocess_get_if_signaled (subprocess));
g_assert (g_subprocess_get_term_sig (subprocess) == 9);
g_assert_true (g_subprocess_get_if_signaled (subprocess));
g_assert_cmpint (g_subprocess_get_term_sig (subprocess), ==, 9);
#endif
g_spawn_check_exit_status (g_subprocess_get_status (subprocess), &error);
g_assert (error != NULL);
g_assert_nonnull (error);
g_clear_error (&error);
g_main_loop_quit ((GMainLoop*)user_data);
@ -1473,7 +1473,7 @@ test_cwd (void)
result = splice_to_string (stdout_stream, error);
basename = g_strrstr (result, G_DIR_SEPARATOR_S);
g_assert (basename != NULL);
g_assert_nonnull (basename);
g_assert_cmpstr (basename, ==, tmp_lineend_basename);
g_free (tmp_lineend);
@ -1726,7 +1726,7 @@ test_launcher_environment (void)
args = get_test_subprocess_args ("printenv", "A", "C", "E", NULL);
proc = g_subprocess_launcher_spawnv (launcher, (const gchar **) args->pdata, &error);
g_assert_no_error (error);
g_assert (proc);
g_assert_nonnull (proc);
g_subprocess_communicate_utf8 (proc, NULL, NULL, &out, NULL, &error);
g_assert_no_error (error);

View File

@ -10,6 +10,7 @@ test_c_args = [
'-DTEST_SERVICES="@0@/gio/tests/services"'.format(meson.build_root()),
'-DGLIB_MKENUMS="@0@"'.format(glib_mkenums),
'-DGLIB_COMPILE_SCHEMAS="@0@"'.format(glib_compile_schemas.full_path()),
'-UG_DISABLE_ASSERT',
]
if host_machine.system() == 'windows'

View File

@ -1304,7 +1304,10 @@ parse_iso8601_date (const gchar *text, gsize length,
static GTimeZone *
parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset)
{
gint i, tz_length, offset_sign = 1, offset_hours, offset_minutes;
gint i, tz_length, offset_hours, offset_minutes;
#ifndef G_DISABLE_ASSERT
gint offset_sign = 1;
#endif
GTimeZone *tz;
/* UTC uses Z suffix */
@ -1318,7 +1321,9 @@ parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset)
for (i = length - 1; i >= 0; i--)
if (text[i] == '+' || text[i] == '-')
{
#ifndef G_DISABLE_ASSERT
offset_sign = text[i] == '-' ? -1 : 1;
#endif
break;
}
if (i < 0)

View File

@ -1311,7 +1311,9 @@ g_io_channel_set_encoding (GIOChannel *channel,
GError **error)
{
GIConv read_cd, write_cd;
#ifndef G_DISABLE_ASSERT
gboolean did_encode;
#endif
g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);
@ -1335,7 +1337,9 @@ g_io_channel_set_encoding (GIOChannel *channel,
channel->partial_write_buf[0] = '\0';
}
#ifndef G_DISABLE_ASSERT
did_encode = channel->do_encode;
#endif
if (!encoding || strcmp (encoding, "UTF8") == 0 || strcmp (encoding, "UTF-8") == 0)
{

View File

@ -149,7 +149,14 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
#endif
#ifdef G_DISABLE_ASSERT
/* https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable
* GCC 5 is not a strict lower bound for versions of GCC which provide __builtin_unreachable(). */
#if __GNUC__ >= 5 || g_macro__has_builtin(__builtin_unreachable)
#define g_assert_not_reached() G_STMT_START { (void) 0; __builtin_unreachable (); } G_STMT_END
#else /* if __builtin_unreachable() is not supported: */
#define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
#endif
#define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
#else /* !G_DISABLE_ASSERT */
#define g_assert_not_reached() G_STMT_START { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } G_STMT_END

View File

@ -362,7 +362,7 @@ static void
token_stream_assert (TokenStream *stream,
const gchar *token)
{
gboolean correct_token;
gboolean correct_token G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
correct_token = token_stream_consume (stream, token);
g_assert (correct_token);

View File

@ -1084,12 +1084,16 @@ g_variant_type_key (const GVariantType *type)
const GVariantType *
g_variant_type_value (const GVariantType *type)
{
#ifndef G_DISABLE_ASSERT
const gchar *type_string;
#endif
g_return_val_if_fail (g_variant_type_check (type), NULL);
#ifndef G_DISABLE_ASSERT
type_string = g_variant_type_peek_string (type);
g_assert (type_string[0] == '{');
#endif
return g_variant_type_next (g_variant_type_key (type));
}

View File

@ -157,6 +157,7 @@ static void
g_variant_type_info_check (const GVariantTypeInfo *info,
char container_class)
{
#ifndef G_DISABLE_ASSERT
g_assert (!container_class || info->container_class == container_class);
/* alignment can only be one of these */
@ -185,6 +186,7 @@ g_variant_type_info_check (const GVariantTypeInfo *info,
g_assert (0 <= index && index < 24);
g_assert (g_variant_type_info_basic_chars[index][0] != ' ');
}
#endif /* !G_DISABLE_ASSERT */
}
/* < private >

View File

@ -327,6 +327,7 @@ if host_system == 'windows'
else
gtester = executable('gtester', 'gtester.c',
install : true,
c_args : ['-UG_DISABLE_ASSERT'],
include_directories : configinc,
dependencies : [libglib_dep])
endif

View File

@ -58,7 +58,7 @@ void test_async_queue_sort (void)
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 8);
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 10);
g_assert (g_async_queue_try_pop (q) == NULL);
g_assert_null (g_async_queue_try_pop (q));
g_async_queue_unref (q);
}
@ -78,18 +78,18 @@ test_async_queue_destroy (void)
q = g_async_queue_new_full (destroy_notify);
g_assert (destroy_count == 0);
g_assert_cmpint (destroy_count, ==, 0);
g_async_queue_push (q, GINT_TO_POINTER (1));
g_async_queue_push (q, GINT_TO_POINTER (1));
g_async_queue_push (q, GINT_TO_POINTER (1));
g_async_queue_push (q, GINT_TO_POINTER (1));
g_assert (g_async_queue_length (q) == 4);
g_assert_cmpint (g_async_queue_length (q), ==, 4);
g_async_queue_unref (q);
g_assert (destroy_count == 4);
g_assert_cmpint (destroy_count, ==, 4);
}
static GAsyncQueue *q;
@ -183,7 +183,7 @@ test_async_queue_timed (void)
start = g_get_monotonic_time ();
val = g_async_queue_timeout_pop (q, G_USEC_PER_SEC / 10);
g_assert (val == NULL);
g_assert_null (val);
end = g_get_monotonic_time ();
diff = end - start;
@ -197,7 +197,7 @@ test_async_queue_timed (void)
g_get_current_time (&tv);
g_time_val_add (&tv, G_USEC_PER_SEC / 10);
val = g_async_queue_timed_pop (q, &tv);
g_assert (val == NULL);
g_assert_null (val);
end = g_get_monotonic_time ();
diff = end - start;
@ -210,7 +210,7 @@ test_async_queue_timed (void)
g_async_queue_lock (q);
val = g_async_queue_timed_pop_unlocked (q, &tv);
g_async_queue_unlock (q);
g_assert (val == NULL);
g_assert_null (val);
end = g_get_monotonic_time ();
diff = end - start;
@ -238,7 +238,7 @@ test_async_queue_remove (void)
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 2);
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 1);
g_assert (g_async_queue_try_pop (q) == NULL);
g_assert_null (g_async_queue_try_pop (q));
g_async_queue_unref (q);
}
@ -261,7 +261,7 @@ test_async_queue_push_front (void)
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 2);
g_assert_cmpint (GPOINTER_TO_INT (g_async_queue_pop (q)), ==, 7);
g_assert (g_async_queue_try_pop (q) == NULL);
g_assert_null (g_async_queue_try_pop (q));
g_async_queue_unref (q);
}

View File

@ -60,35 +60,35 @@ test_maincontext_basic (void)
ctx = g_main_context_new ();
g_assert (!g_main_context_pending (ctx));
g_assert (!g_main_context_iteration (ctx, FALSE));
g_assert_false (g_main_context_pending (ctx));
g_assert_false (g_main_context_iteration (ctx, FALSE));
source = g_source_new (&funcs, sizeof (GSource));
g_assert_cmpint (g_source_get_priority (source), ==, G_PRIORITY_DEFAULT);
g_assert (!g_source_is_destroyed (source));
g_assert_false (g_source_is_destroyed (source));
g_assert (!g_source_get_can_recurse (source));
g_assert (g_source_get_name (source) == NULL);
g_assert_false (g_source_get_can_recurse (source));
g_assert_null (g_source_get_name (source));
g_source_set_can_recurse (source, TRUE);
g_source_set_name (source, "d");
g_assert (g_source_get_can_recurse (source));
g_assert_true (g_source_get_can_recurse (source));
g_assert_cmpstr (g_source_get_name (source), ==, "d");
g_assert (g_main_context_find_source_by_user_data (ctx, NULL) == NULL);
g_assert (g_main_context_find_source_by_funcs_user_data (ctx, &funcs, NULL) == NULL);
g_assert_null (g_main_context_find_source_by_user_data (ctx, NULL));
g_assert_null (g_main_context_find_source_by_funcs_user_data (ctx, &funcs, NULL));
id = g_source_attach (source, ctx);
g_assert_cmpint (g_source_get_id (source), ==, id);
g_assert (g_main_context_find_source_by_id (ctx, id) == source);
g_assert_true (g_main_context_find_source_by_id (ctx, id) == source);
g_source_set_priority (source, G_PRIORITY_HIGH);
g_assert_cmpint (g_source_get_priority (source), ==, G_PRIORITY_HIGH);
g_source_destroy (source);
g_assert (g_source_get_context (source) == ctx);
g_assert (g_main_context_find_source_by_id (ctx, id) == NULL);
g_assert_true (g_source_get_context (source) == ctx);
g_assert_null (g_main_context_find_source_by_id (ctx, id));
g_main_context_unref (ctx);
@ -96,7 +96,7 @@ test_maincontext_basic (void)
{
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*assertion*source->context != NULL*failed*");
g_assert (g_source_get_context (source) == NULL);
g_assert_null (g_source_get_context (source));
g_test_assert_expected_messages ();
}
@ -110,19 +110,19 @@ test_maincontext_basic (void)
g_source_unref (source);
g_source_set_name_by_id (id, "e");
g_assert_cmpstr (g_source_get_name (source), ==, "e");
g_assert (g_source_get_context (source) == ctx);
g_assert (g_source_remove_by_funcs_user_data (&funcs, data));
g_assert_true (g_source_get_context (source) == ctx);
g_assert_true (g_source_remove_by_funcs_user_data (&funcs, data));
source = g_source_new (&funcs, sizeof (GSource));
g_source_set_funcs (source, &funcs);
g_source_set_callback (source, cb, data, NULL);
id = g_source_attach (source, ctx);
g_source_unref (source);
g_assert (g_source_remove_by_user_data (data));
g_assert (!g_source_remove_by_user_data ((gpointer)0x1234));
g_assert_true (g_source_remove_by_user_data (data));
g_assert_false (g_source_remove_by_user_data ((gpointer)0x1234));
g_idle_add (cb, data);
g_assert (g_idle_remove_by_data (data));
g_assert_true (g_idle_remove_by_data (data));
}
static void
@ -133,12 +133,12 @@ test_mainloop_basic (void)
loop = g_main_loop_new (NULL, FALSE);
g_assert (!g_main_loop_is_running (loop));
g_assert_false (g_main_loop_is_running (loop));
g_main_loop_ref (loop);
ctx = g_main_loop_get_context (loop);
g_assert (ctx == g_main_context_default ());
g_assert_true (ctx == g_main_context_default ());
g_main_loop_unref (loop);
@ -233,24 +233,24 @@ test_priorities (void)
g_source_attach (sourceb, ctx);
g_source_unref (sourceb);
g_assert (g_main_context_pending (ctx));
g_assert (g_main_context_iteration (ctx, FALSE));
g_assert_true (g_main_context_pending (ctx));
g_assert_true (g_main_context_iteration (ctx, FALSE));
g_assert_cmpint (a, ==, 0);
g_assert_cmpint (b, ==, 1);
g_assert (g_main_context_iteration (ctx, FALSE));
g_assert_true (g_main_context_iteration (ctx, FALSE));
g_assert_cmpint (a, ==, 0);
g_assert_cmpint (b, ==, 2);
g_source_destroy (sourceb);
g_assert (g_main_context_iteration (ctx, FALSE));
g_assert_true (g_main_context_iteration (ctx, FALSE));
g_assert_cmpint (a, ==, 1);
g_assert_cmpint (b, ==, 2);
g_assert (g_main_context_pending (ctx));
g_assert_true (g_main_context_pending (ctx));
g_source_destroy (sourcea);
g_assert (!g_main_context_pending (ctx));
g_assert_false (g_main_context_pending (ctx));
g_main_context_unref (ctx);
}
@ -271,7 +271,7 @@ static gboolean
func (gpointer data)
{
if (data != NULL)
g_assert (data == g_thread_self ());
g_assert_true (data == g_thread_self ());
count++;
@ -706,12 +706,12 @@ timeout1_callback (gpointer user_data)
gint64 mtime1, mtime2, time2;
source = g_main_current_source ();
g_assert (source == data->timeout1);
g_assert_true (source == data->timeout1);
if (data->time1 == -1)
{
/* First iteration */
g_assert (!g_source_is_destroyed (data->timeout2));
g_assert_false (g_source_is_destroyed (data->timeout2));
mtime1 = g_get_monotonic_time ();
data->time1 = g_source_get_time (source);
@ -733,7 +733,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
GTimeVal tv;
/* Second iteration */
g_assert (g_source_is_destroyed (data->timeout2));
g_assert_true (g_source_is_destroyed (data->timeout2));
/* g_source_get_time() MAY change between iterations; in this
* case we know for sure that it did because of the g_usleep()
@ -746,9 +746,9 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_source_get_current_time (source, &tv);
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert (tv.tv_sec > data->tv.tv_sec ||
(tv.tv_sec == data->tv.tv_sec &&
tv.tv_usec > data->tv.tv_usec));
g_assert_true (tv.tv_sec > data->tv.tv_sec ||
(tv.tv_sec == data->tv.tv_sec &&
tv.tv_usec > data->tv.tv_usec));
g_main_loop_quit (data->loop);
}
@ -764,9 +764,9 @@ timeout2_callback (gpointer user_data)
gint64 time2, time3;
source = g_main_current_source ();
g_assert (source == data->timeout2);
g_assert_true (source == data->timeout2);
g_assert (!g_source_is_destroyed (data->timeout1));
g_assert_false (g_source_is_destroyed (data->timeout1));
/* g_source_get_time() does not change between different sources in
* a single iteration of the mainloop.
@ -804,8 +804,8 @@ test_source_time (void)
g_main_loop_run (data.loop);
g_assert (!g_source_is_destroyed (data.timeout1));
g_assert (g_source_is_destroyed (data.timeout2));
g_assert_false (g_source_is_destroyed (data.timeout1));
g_assert_true (g_source_is_destroyed (data.timeout2));
g_source_destroy (data.timeout1);
g_source_unref (data.timeout1);
@ -833,9 +833,9 @@ on_source_fired_cb (gpointer user_data)
current_source = g_main_current_source ();
current_context = g_source_get_context (current_source);
source_id = g_source_get_id (current_source);
g_assert (g_main_context_find_source_by_id (current_context, source_id) != NULL);
g_assert_nonnull (g_main_context_find_source_by_id (current_context, source_id));
g_source_destroy (current_source);
g_assert (g_main_context_find_source_by_id (current_context, source_id) == NULL);
g_assert_null (g_main_context_find_source_by_id (current_context, source_id));
if (data->outstanding_ops == 0)
g_main_loop_quit (data->loop);
@ -945,7 +945,7 @@ test_ready_time (void)
/* A source with no ready time set should not fire */
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
while (g_main_context_iteration (NULL, FALSE));
g_assert (!ready_time_dispatched);
g_assert_false (ready_time_dispatched);
/* The ready time should not have been changed */
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
@ -959,21 +959,21 @@ test_ready_time (void)
*/
g_source_set_ready_time (source, g_get_monotonic_time () + G_TIME_SPAN_DAY);
while (g_main_context_iteration (NULL, FALSE));
g_assert (!ready_time_dispatched);
g_assert_false (ready_time_dispatched);
/* Make sure it didn't get reset */
g_assert_cmpint (g_source_get_ready_time (source), !=, -1);
/* Ready time of -1 -> don't fire */
g_source_set_ready_time (source, -1);
while (g_main_context_iteration (NULL, FALSE));
g_assert (!ready_time_dispatched);
g_assert_false (ready_time_dispatched);
/* Not reset, but should still be -1 from above */
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
/* A ready time of the current time should fire immediately */
g_source_set_ready_time (source, g_get_monotonic_time ());
while (g_main_context_iteration (NULL, FALSE));
g_assert (ready_time_dispatched);
g_assert_true (ready_time_dispatched);
ready_time_dispatched = FALSE;
/* Should have gotten reset by the handler function */
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
@ -981,14 +981,14 @@ test_ready_time (void)
/* As well as one in the recent past... */
g_source_set_ready_time (source, g_get_monotonic_time () - G_TIME_SPAN_SECOND);
while (g_main_context_iteration (NULL, FALSE));
g_assert (ready_time_dispatched);
g_assert_true (ready_time_dispatched);
ready_time_dispatched = FALSE;
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
/* Zero is the 'official' way to get a source to fire immediately */
g_source_set_ready_time (source, 0);
while (g_main_context_iteration (NULL, FALSE));
g_assert (ready_time_dispatched);
g_assert_true (ready_time_dispatched);
ready_time_dispatched = FALSE;
g_assert_cmpint (g_source_get_ready_time (source), ==, -1);
@ -1126,7 +1126,7 @@ write_bytes (gint fd,
return FALSE;
/* Detect if we run before we should */
g_assert (*to_write >= 0);
g_assert_cmpint (*to_write, >=, 0);
limit = MIN (*to_write, sizeof zeros);
*to_write -= write (fd, zeros, limit);
@ -1163,7 +1163,7 @@ test_unix_fd (void)
GSource *source_b;
s = pipe (fds);
g_assert (s == 0);
g_assert_cmpint (s, ==, 0);
to_read = fill_a_pipe (fds[1]);
/* write at higher priority to keep the pipe full... */
@ -1192,17 +1192,17 @@ test_unix_fd (void)
/* Since the sources are at different priority, only one of them
* should possibly have run.
*/
g_assert (to_write == to_write_was || to_read == to_read_was);
g_assert_true (to_write == to_write_was || to_read == to_read_was);
}
g_assert (to_write == 0);
g_assert (to_read == 0);
g_assert_cmpint (to_write, ==, 0);
g_assert_cmpint (to_read, ==, 0);
/* 'a' is already removed by itself */
g_assert (g_source_is_destroyed (source_a));
g_assert_true (g_source_is_destroyed (source_a));
g_source_unref (source_a);
g_source_remove (b);
g_assert (g_source_is_destroyed (source_b));
g_assert_true (g_source_is_destroyed (source_b));
g_source_unref (source_b);
close (fds[1]);
close (fds[0]);
@ -1227,10 +1227,10 @@ assert_main_context_state (gint n_to_poll,
context = g_main_context_default ();
acquired = g_main_context_acquire (context);
g_assert (acquired);
g_assert_true (acquired);
immediate = g_main_context_prepare (context, &max_priority);
g_assert (!immediate);
g_assert_false (immediate);
n = g_main_context_query (context, max_priority, &timeout, poll_fds, 10);
g_assert_cmpint (n, ==, n_to_poll + 1); /* one will be the gwakeup */
@ -1290,7 +1290,7 @@ test_unix_fd_source (void)
assert_main_context_state (0);
s = pipe (fds);
g_assert (s == 0);
g_assert_cmpint (s, ==, 0);
source = g_unix_fd_source_new (fds[1], G_IO_OUT);
g_source_attach (source, NULL);
@ -1301,7 +1301,7 @@ test_unix_fd_source (void)
g_test_expect_message ("GLib", G_LOG_LEVEL_WARNING, "*GUnixFDSource dispatched without callback*");
while (g_main_context_iteration (NULL, FALSE));
g_test_assert_expected_messages ();
g_assert (g_source_is_destroyed (source));
g_assert_true (g_source_is_destroyed (source));
g_source_unref (source);
out = in = FALSE;
@ -1324,7 +1324,7 @@ test_unix_fd_source (void)
g_source_attach (out_source, NULL);
assert_main_context_state (1,
fds[1], G_IO_OUT, 0);
g_assert (!in && !out);
g_assert_true (!in && !out);
in_source = g_unix_fd_source_new (fds[0], G_IO_IN);
g_source_set_callback (in_source, (GSourceFunc) flag_bool, &in, NULL);
@ -1334,7 +1334,7 @@ test_unix_fd_source (void)
fds[0], G_IO_IN, G_IO_IN,
fds[1], G_IO_OUT, G_IO_OUT);
/* out is higher priority so only it should fire */
g_assert (!in && out);
g_assert_true (!in && out);
/* raise the priority of the in source to higher than out*/
in = out = FALSE;
@ -1342,7 +1342,7 @@ test_unix_fd_source (void)
assert_main_context_state (2,
fds[0], G_IO_IN, G_IO_IN,
fds[1], G_IO_OUT, G_IO_OUT);
g_assert (in && !out);
g_assert_true (in && !out);
/* now, let them be equal */
in = out = FALSE;
@ -1350,7 +1350,7 @@ test_unix_fd_source (void)
assert_main_context_state (2,
fds[0], G_IO_IN, G_IO_IN,
fds[1], G_IO_OUT, G_IO_OUT);
g_assert (in && out);
g_assert_true (in && out);
g_source_destroy (out_source);
g_source_unref (out_source);
@ -1376,8 +1376,8 @@ return_true (GSource *source, GSourceFunc callback, gpointer user_data)
return TRUE;
}
#define assert_flagged(s) g_assert (((FlagSource *) (s))->flagged);
#define assert_not_flagged(s) g_assert (!((FlagSource *) (s))->flagged);
#define assert_flagged(s) g_assert_true (((FlagSource *) (s))->flagged);
#define assert_not_flagged(s) g_assert_true (!((FlagSource *) (s))->flagged);
#define clear_flag(s) ((FlagSource *) (s))->flagged = 0
static void
@ -1505,7 +1505,7 @@ test_unix_file_poll (void)
GMainLoop *loop;
fd = open ("/dev/null", O_RDONLY);
g_assert (fd >= 0);
g_assert_cmpint (fd, >=, 0);
loop = g_main_loop_new (NULL, FALSE);
@ -1537,8 +1537,8 @@ timeout_cb (gpointer data)
GMainContext *context;
context = g_main_loop_get_context (loop);
g_assert (g_main_loop_is_running (loop));
g_assert (g_main_context_is_owner (context));
g_assert_true (g_main_loop_is_running (loop));
g_assert_true (g_main_context_is_owner (context));
g_main_loop_quit (loop);
@ -1723,9 +1723,9 @@ test_nfds (void)
*/
g_main_context_iteration (ctx, FALSE);
g_assert (source1_ran);
g_assert_true (source1_ran);
#ifndef G_OS_WIN32
g_assert (source3_ran);
g_assert_true (source3_ran);
#endif
g_source_destroy (source1);

View File

@ -40,7 +40,7 @@ test_empty (void)
file = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
g_assert (g_mapped_file_get_contents (file) == NULL);
g_assert_null (g_mapped_file_get_contents (file));
g_mapped_file_free (file);
}
@ -53,10 +53,10 @@ test_device (void)
GMappedFile *file;
file = g_mapped_file_new ("/dev/null", FALSE, &error);
g_assert (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_INVAL) ||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NODEV) ||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM));
g_assert (file == NULL);
g_assert_true (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_INVAL) ||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NODEV) ||
g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM));
g_assert_null (file);
g_error_free (error);
}
#endif
@ -71,7 +71,7 @@ test_nonexisting (void)
file = g_mapped_file_new ("no-such-file", FALSE, &error);
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
g_clear_error (&error);
g_assert (file == NULL);
g_assert_null (file);
}
static void
@ -98,10 +98,10 @@ test_writable (void)
g_assert_no_error (error);
contents = g_mapped_file_get_contents (file);
g_assert (strncmp (contents, old, strlen (old)) == 0);
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
memcpy (contents, new, strlen (new));
g_assert (strncmp (contents, new, strlen (new)) == 0);
g_assert_cmpuint (strncmp (contents, new, strlen (new)), ==, 0);
g_mapped_file_free (file);
@ -110,7 +110,7 @@ test_writable (void)
g_assert_no_error (error);
contents = g_mapped_file_get_contents (file);
g_assert (strncmp (contents, old, strlen (old)) == 0);
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
g_mapped_file_free (file);
@ -139,27 +139,27 @@ test_writable_fd (void)
g_free (contents);
fd = g_open (tmp_copy_path, O_RDWR, 0);
g_assert (fd != -1);
g_assert_cmpint (fd, !=, -1);
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
g_assert_no_error (error);
contents = g_mapped_file_get_contents (file);
g_assert (strncmp (contents, old, strlen (old)) == 0);
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
memcpy (contents, new, strlen (new));
g_assert (strncmp (contents, new, strlen (new)) == 0);
g_assert_cmpuint (strncmp (contents, new, strlen (new)), ==, 0);
g_mapped_file_free (file);
close (fd);
error = NULL;
fd = g_open (tmp_copy_path, O_RDWR, 0);
g_assert (fd != -1);
g_assert_cmpint (fd, !=, -1);
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
g_assert_no_error (error);
contents = g_mapped_file_get_contents (file);
g_assert (strncmp (contents, old, strlen (old)) == 0);
g_assert_cmpuint (strncmp (contents, old, strlen (old)), ==, 0);
g_mapped_file_free (file);

View File

@ -176,7 +176,7 @@ test_env.set('MALLOC_CHECK_', '2')
test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
test_deps = [libm, thread_dep, libglib_dep]
test_cargs = ['-DG_LOG_DOMAIN="GLib"']
test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
foreach test_name, extra_args : glib_tests
source = extra_args.get('source', test_name + '.c')

View File

@ -87,17 +87,17 @@ test_rand (void)
rand = g_rand_new_with_seed (first_numbers[0]);
for (n = 1; n < G_N_ELEMENTS (first_numbers); n++)
g_assert (first_numbers[n] == g_rand_int (rand));
g_assert_cmpuint (first_numbers[n], ==, g_rand_int (rand));
g_rand_set_seed (rand, 2);
g_rand_set_seed_array (rand, seed_array, G_N_ELEMENTS (seed_array));
for (n = 0; n < G_N_ELEMENTS (array_outputs); n++)
g_assert (array_outputs[n] == g_rand_int (rand));
g_assert_cmpuint (array_outputs[n], ==, g_rand_int (rand));
copy = g_rand_copy (rand);
for (n = 0; n < 100; n++)
g_assert (g_rand_int (copy) == g_rand_int (rand));
g_assert_cmpuint (g_rand_int (copy), ==, g_rand_int (rand));
for (n = 1; n < 100000; n++)
{
@ -106,28 +106,34 @@ test_rand (void)
gboolean b;
i = g_rand_int_range (rand, 8,16);
g_assert (i >= 8 && i < 16);
g_assert_cmpint (i, >=, 8);
g_assert_cmpint (i, <, 16);
i = g_random_int_range (8,16);
g_assert (i >= 8 && i < 16);
g_assert_cmpint (i, >=, 8);
g_assert_cmpint (i, <, 16);
d = g_rand_double (rand);
g_assert (d >= 0 && d < 1);
g_assert_cmpfloat (d, >=, 0.0);
g_assert_cmpfloat (d, <, 1.0);
d = g_random_double ();
g_assert (d >= 0 && d < 1);
g_assert_cmpfloat (d, >=, 0.0);
g_assert_cmpfloat (d, <, 1.0);
d = g_rand_double_range (rand, -8, 32);
g_assert (d >= -8 && d < 32);
g_assert_cmpfloat (d, >=, -8.0);
g_assert_cmpfloat (d, <, 32.0);
d = g_random_double_range (-8, 32);
g_assert (d >= -8 && d < 32);
g_assert_cmpfloat (d, >=, -8.0);
g_assert_cmpfloat (d, <, 32.0);
b = g_random_boolean ();
g_assert (b == TRUE || b == FALSE);
g_assert_true (b == TRUE || b == FALSE);
b = g_rand_boolean (rand);
g_assert (b == TRUE || b == FALSE);
g_assert_true (b == TRUE || b == FALSE);
}
/* Statistical sanity check, count the number of ones
@ -143,7 +149,7 @@ test_rand (void)
proportion = (double)ones / (double)100000;
/* 0.025 is overkill, but should suffice to test for some unreasonability */
g_assert (ABS (proportion - 0.25) < 0.025);
g_assert_cmpfloat (ABS (proportion - 0.25), <, 0.025);
g_rand_free (rand);
g_rand_free (copy);
@ -158,8 +164,8 @@ test_double_range (void)
d = g_random_double_range (-G_MAXDOUBLE, G_MAXDOUBLE);
g_assert (-G_MAXDOUBLE <= d);
g_assert (d < G_MAXDOUBLE);
g_assert_cmpfloat (-G_MAXDOUBLE, <=, d);
g_assert_cmpfloat (d, <, G_MAXDOUBLE);
}
int

View File

@ -100,7 +100,7 @@ _g_boxed_type_init (void)
NULL, /* value_table */
};
const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
GType type;
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
/* G_TYPE_BOXED
*/

View File

@ -113,7 +113,7 @@ _g_enum_types_init (void)
static const GTypeFundamentalInfo finfo = {
G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE,
};
GType type;
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
g_return_if_fail (initialized == FALSE);
initialized = TRUE;

View File

@ -381,7 +381,7 @@ _g_object_type_init (void)
"p", /* lcopy_format */
g_value_object_lcopy_value, /* lcopy_value */
};
GType type;
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
g_return_if_fail (initialized == FALSE);
initialized = TRUE;

View File

@ -1191,11 +1191,16 @@ void
_g_param_spec_types_init (void)
{
const guint n_types = 23;
GType type, *spec_types, *spec_types_bound;
GType type, *spec_types;
#ifndef G_DISABLE_ASSERT
GType *spec_types_bound;
#endif
g_param_spec_types = g_new0 (GType, n_types);
spec_types = g_param_spec_types;
#ifndef G_DISABLE_ASSERT
spec_types_bound = g_param_spec_types + n_types;
#endif
/* G_TYPE_PARAM_CHAR
*/

View File

@ -4362,7 +4362,7 @@ gobject_init (void)
const gchar *env_string;
GTypeInfo info;
TypeNode *node;
GType type;
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
/* Ensure GLib is initialized first, see
* https://bugzilla.gnome.org/show_bug.cgi?id=756139

View File

@ -435,7 +435,7 @@ _g_value_types_init (void)
NULL, /* value_table */
};
const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
GType type;
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
/* G_TYPE_CHAR / G_TYPE_UCHAR
*/

View File

@ -68,7 +68,7 @@ test_env.set('MALLOC_CHECK_', '2')
test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
test_deps = [libm, thread_dep, libglib_dep, libgobject_dep]
test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"']
test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT']
foreach test_name, extra_args : gobject_tests
source = extra_args.get('source', test_name + '.c')

View File

@ -10,7 +10,7 @@ test_env.set('G_DEBUG', 'gc-friendly')
test_env.set('MALLOC_CHECK_', '2')
test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
test_cargs = ['-DG_LOG_DOMAIN="GLib"']
test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
subdir('gobject')
subdir('refcount')