[libgweather/wip/hadess/serialisation-fix-stable: 4/13] GWeatherLocation: Add private function to reset the world



commit e64216f67fd52e421b9677edd2a15704a4d3612c
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 fd2439d..1a53d82 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -381,7 +381,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:
@@ -441,25 +449,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);
@@ -495,6 +492,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 82a5c9b..d8f6586 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -26,6 +26,8 @@
 #include <gweather-version.h>
 #include "gweather-location.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]