[libgweather/wip/hadess/serialisation-fix: 1/18] GWeatherLocation: Add private function to reset the world



commit 96d1ac23977d422a5e2eb1f42b51f2e20793348f
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 9 13:17:15 2018 +0200

    GWeatherLocation: Add private function to reset the world
    
    So that we can test easily the different envvars.

 libgweather/gweather-location.c | 41 +++++++++++++++++++++++++++--------------
 libgweather/test_libgweather.c  |  2 ++
 2 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 5e37f2f..d122e0e 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -377,7 +377,15 @@ error_out:
     return NULL;
 }
 
-static GWeatherLocation *global_world;
+static GWeatherLocation *global_world = NULL;
+
+static void _gweather_location_unref_no_check (GWeatherLocation *loc);
+
+GWEATHER_EXTERN void
+_gweather_location_reset_world (void)
+{
+       g_clear_pointer (&global_world, _gweather_location_unref_no_check);
+}
 
 /**
  * gweather_location_get_world:
@@ -438,25 +446,14 @@ gweather_location_ref (GWeatherLocation *loc)
     return loc;
 }
 
-/**
- * gweather_location_unref:
- * @loc: a #GWeatherLocation
- *
- * Subtracts 1 from @loc's reference count, and frees it if the
- * reference count reaches 0.
- **/
-void
-gweather_location_unref (GWeatherLocation *loc)
+static void
+_gweather_location_unref_no_check (GWeatherLocation *loc)
 {
     int i;
 
-    g_return_if_fail (loc != NULL);
-
     if (--loc->ref_count)
        return;
 
-    g_return_if_fail (loc->level != GWEATHER_LOCATION_WORLD);
-
     g_free (loc->english_name);
     g_free (loc->local_name);
     g_free (loc->msgctxt);
@@ -492,6 +489,22 @@ gweather_location_unref (GWeatherLocation *loc)
     g_slice_free (GWeatherLocation, loc);
 }
 
+/**
+ * gweather_location_unref:
+ * @loc: a #GWeatherLocation
+ *
+ * Subtracts 1 from @loc's reference count, and frees it if the
+ * reference count reaches 0.
+ **/
+void
+gweather_location_unref (GWeatherLocation *loc)
+{
+    g_return_if_fail (loc != NULL);
+    g_return_if_fail (loc->level != GWEATHER_LOCATION_WORLD);
+
+    _gweather_location_unref_no_check (loc);
+}
+
 GType
 gweather_location_get_type (void)
 {
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index 8c96969..1eddf52 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -27,6 +27,8 @@
 #include "gweather-location.h"
 #include "gweather-weather.h"
 
+extern void _gweather_location_reset_world (void);
+
 /* For test_metar_weather_stations */
 #define METAR_SOURCES "https://www.aviationweather.gov/docs/metar/stations.txt";
 


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