[libmanette] Use assertions instead of g_return*_if_fail in static functions



commit 4eca560dcce7c3f30522cfce8ca7d0f5c0a8d28d
Author: vanadiae <vanadiae35 gmail com>
Date:   Wed Oct 14 18:22:22 2020 +0200

    Use assertions instead of g_return*_if_fail in static functions
    
    As g_return_if_fail is only for public API checking. If there need to be
    some arguments checking in static functions, it is a programmer error
    and so must assert.
    
    This commit also removes type checking for self (i.e. the type defined
    in this file), since those check should already be put for public API
    functions.

 src/manette-device.c          |  8 ++++----
 src/manette-mapping-manager.c | 13 +++----------
 src/manette-monitor.c         | 18 ++++++++----------
 3 files changed, 15 insertions(+), 24 deletions(-)
---
diff --git a/src/manette-device.c b/src/manette-device.c
index e7be34c..62d4e0d 100644
--- a/src/manette-device.c
+++ b/src/manette-device.c
@@ -156,7 +156,7 @@ is_game_controller (struct libevdev *device)
 {
   gboolean has_joystick_axes_or_buttons;
 
-  g_return_val_if_fail (device != NULL, FALSE);
+  g_assert (device != NULL);
 
   /* Same detection code as udev-builtin-input_id.c in systemd
    * joysticks don’t necessarily have buttons; e. g.
@@ -204,7 +204,7 @@ map_event (ManetteDevice *self,
 static void
 remove_event_source (ManetteDevice *self)
 {
-  g_return_if_fail (self != NULL);
+  g_assert (self != NULL);
 
   if (self->event_source_id < 0)
     return;
@@ -397,7 +397,7 @@ centered_absolute_value (struct input_absinfo *abs_info,
   gint64 value_centered;
   gint64 divisor;
 
-  g_return_val_if_fail (abs_info != NULL, 0.0);
+  g_assert (abs_info != NULL);
 
   /* Adapt the value and the maximum to a minimum of 0. */
   max_normalized = ((gint64) abs_info->maximum) - abs_info->minimum;
@@ -488,7 +488,7 @@ poll_events (GIOChannel    *source,
 {
   struct input_event evdev_event;
 
-  g_return_val_if_fail (MANETTE_IS_DEVICE (self), FALSE);
+  g_assert (MANETTE_IS_DEVICE (self));
 
   while (libevdev_has_event_pending (self->evdev_device))
     if (libevdev_next_event (self->evdev_device,
diff --git a/src/manette-mapping-manager.c b/src/manette-mapping-manager.c
index 616be3d..ac059f5 100644
--- a/src/manette-mapping-manager.c
+++ b/src/manette-mapping-manager.c
@@ -57,8 +57,7 @@ add_mapping (ManetteMappingManager *self,
   const gchar *platform;
   g_auto (GStrv) split = NULL;
 
-  g_return_if_fail (MANETTE_IS_MAPPING_MANAGER (self));
-  g_return_if_fail (mapping_string != NULL);
+  g_assert (mapping_string != NULL);
 
   if (mapping_string[0] == '\0' || mapping_string[0] == '#')
     return;
@@ -85,8 +84,7 @@ add_from_input_stream (ManetteMappingManager  *self,
   g_autoptr (GDataInputStream) data_stream = NULL;
   GError *inner_error = NULL;
 
-  g_return_if_fail (MANETTE_IS_MAPPING_MANAGER (self));
-  g_return_if_fail (input_stream != NULL);
+  g_assert (input_stream != NULL);
 
   data_stream = g_data_input_stream_new (input_stream);
   while (TRUE) {
@@ -117,8 +115,7 @@ add_from_file_uri (ManetteMappingManager  *self,
   g_autoptr (GFileInputStream) stream = NULL;
   GError *inner_error = NULL;
 
-  g_return_if_fail (MANETTE_IS_MAPPING_MANAGER (self));
-  g_return_if_fail (file_uri != NULL);
+  g_assert (file_uri != NULL);
 
   file = g_file_new_for_uri (file_uri);
   stream = g_file_read (file, NULL, &inner_error);
@@ -153,8 +150,6 @@ save_user_mappings (ManetteMappingManager  *self,
   g_autoptr (GDataOutputStream) data_stream = NULL;
   GError *inner_error = NULL;
 
-  g_return_if_fail (MANETTE_IS_MAPPING_MANAGER (self));
-
   file = g_file_new_for_uri (self->user_mappings_uri);
   directory = g_file_get_parent (file);
 
@@ -201,8 +196,6 @@ user_mappings_changed_cb (GFileMonitor          *monitor,
 {
   g_autoptr (GError) inner_error = NULL;
 
-  g_return_if_fail (MANETTE_IS_MAPPING_MANAGER (self));
-
   g_hash_table_remove_all (self->user_mappings);
 
   if (!g_file_query_exists (file, NULL)) {
diff --git a/src/manette-monitor.c b/src/manette-monitor.c
index bd6a7cd..6cd1f23 100644
--- a/src/manette-monitor.c
+++ b/src/manette-monitor.c
@@ -99,8 +99,8 @@ add_device (ManetteMonitor *self,
   g_autoptr (ManetteDevice) device = NULL;
   g_autoptr (GError) error = NULL;
 
-  g_return_if_fail (self != NULL);
-  g_return_if_fail (filename != NULL);
+  g_assert (self != NULL);
+  g_assert (filename != NULL);
 
   if (g_hash_table_contains (self->devices, filename))
     return;
@@ -146,8 +146,8 @@ add_device_for_udev_device (ManetteMonitor *self,
 {
   const gchar *filename;
 
-  g_return_if_fail (self != NULL);
-  g_return_if_fail (udev_device != NULL);
+  g_assert (self != NULL);
+  g_assert (udev_device != NULL);
 
   filename = g_udev_device_get_device_file (udev_device);
   add_device (self, filename);
@@ -175,7 +175,7 @@ udev_device_property_is (GUdevDevice *udev_device,
 static gboolean
 udev_device_is_manette (GUdevDevice *udev_device)
 {
-  g_return_val_if_fail (udev_device != NULL, FALSE);
+  g_assert (udev_device != NULL);
 
   return udev_device_property_is (udev_device, "ID_INPUT_JOYSTICK", "1") ||
          udev_device_property_is (udev_device, ".INPUT_CLASS", "joystick");
@@ -187,9 +187,9 @@ udev_client_uevent_cb (GUdevClient    *sender,
                        GUdevDevice    *udev_device,
                        ManetteMonitor *self)
 {
-  g_return_if_fail (self != NULL);
-  g_return_if_fail (action != NULL);
-  g_return_if_fail (udev_device != NULL);
+  g_assert (action != NULL);
+  g_assert (udev_device != NULL);
+  g_assert (self != NULL);
 
   if (g_udev_device_get_device_file (udev_device) == NULL)
     return;
@@ -381,8 +381,6 @@ mappings_changed_cb (ManetteMappingManager *mapping_manager,
   g_autoptr (ManetteMonitorIter) iterator = NULL;
   ManetteDevice *device = NULL;
 
-  g_return_if_fail (MANETTE_IS_MONITOR (self));
-
   iterator = manette_monitor_iterate (self);
   while (manette_monitor_iter_next (iterator, &device))
     load_mapping (self, device);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]