[gnome-keyring] gcr: Cleanup GcrRecord after review.



commit 89efa77a605078c501eff393f201911d24604565
Author: Stef Walter <stefw collabora co uk>
Date:   Mon May 16 07:23:12 2011 +0200

    gcr: Cleanup GcrRecord after review.
    
     * Use G_DEFINE_BOXED_TYPE
     * Fix some test corner cases.
     * Locale independent integer parsing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650255

 gcr/gcr-record.c        |   22 +++-------------------
 gcr/gcr-record.h        |    4 ++--
 gcr/tests/test-record.c |    4 ++++
 3 files changed, 9 insertions(+), 21 deletions(-)
---
diff --git a/gcr/gcr-record.c b/gcr/gcr-record.c
index b0a3924..cd33b2d 100644
--- a/gcr/gcr-record.c
+++ b/gcr/gcr-record.c
@@ -39,21 +39,7 @@ struct _GcrRecord {
 	guint n_columns;
 };
 
-GType
-_gcr_record_get_boxed_type (void)
-{
-	static gsize initialization_value = 0;
-	static GType type = 0;
-
-	if (g_once_init_enter (&initialization_value)) {
-		type = g_boxed_type_register_static ("GcrRecord",
-		                                     (GBoxedCopyFunc)_gcr_record_copy,
-		                                     (GBoxedFreeFunc)_gcr_record_free);
-		g_once_init_leave (&initialization_value, 1);
-	}
-
-	return type;
-}
+G_DEFINE_BOXED_TYPE (GcrRecord, _gcr_record, _gcr_record_copy, _gcr_record_free);
 
 GcrRecord*
 _gcr_record_copy (GcrRecord *record)
@@ -205,7 +191,7 @@ gboolean
 _gcr_record_get_uint (GcrRecord *record, guint column, guint *value)
 {
 	const gchar *raw;
-	glong result;
+	gint64 result;
 	gchar *end = NULL;
 
 	g_return_val_if_fail (record, FALSE);
@@ -214,7 +200,7 @@ _gcr_record_get_uint (GcrRecord *record, guint column, guint *value)
 	if (raw == NULL)
 		return FALSE;
 
-	result = strtol (raw, &end, 10);
+	result = g_ascii_strtoll (raw, &end, 10);
 	if (!end || end[0]) {
 		_gcr_debug ("invalid unsigned integer value: %s", raw);
 		return FALSE;
@@ -230,8 +216,6 @@ _gcr_record_get_uint (GcrRecord *record, guint column, guint *value)
 	return TRUE;
 }
 
-
-
 const gchar*
 _gcr_record_get_raw (GcrRecord *record, guint column)
 {
diff --git a/gcr/gcr-record.h b/gcr/gcr-record.h
index 268d5a8..3cc6d8d 100644
--- a/gcr/gcr-record.h
+++ b/gcr/gcr-record.h
@@ -86,9 +86,9 @@ typedef enum {
 
 typedef struct _GcrRecord GcrRecord;
 
-#define        GCR_TYPE_RECORD                  (_gcr_record_get_boxed_type ())
+#define        GCR_TYPE_RECORD                  (_gcr_record_get_type ())
 
-GType          _gcr_record_get_boxed_type       (void) G_GNUC_CONST;
+GType          _gcr_record_get_type             (void) G_GNUC_CONST;
 
 GcrRecord*     _gcr_record_copy                 (GcrRecord *record);
 
diff --git a/gcr/tests/test-record.c b/gcr/tests/test-record.c
index 7d7073f..265d677 100644
--- a/gcr/tests/test-record.c
+++ b/gcr/tests/test-record.c
@@ -248,6 +248,9 @@ test_copy (Test *test, gconstpointer unused)
 		g_assert_cmpstr (_gcr_record_get_raw (copy, i), ==,
 		                 _gcr_record_get_raw (test->record, i));
 	}
+
+	g_assert (_gcr_record_get_raw (copy, count) == NULL);
+	_gcr_record_free (copy);
 }
 
 static void
@@ -265,6 +268,7 @@ test_boxed (Test *test, gconstpointer unused)
 		                 _gcr_record_get_raw (test->record, i));
 	}
 
+	g_assert (_gcr_record_get_raw (copy, count) == NULL);
 	g_boxed_free (GCR_TYPE_RECORD, copy);
 }
 



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