[PATCH] GKeyFile: Switch gint to gint64



This effects the get_integer, set_integer, get_integer_list, and
set_integer_list functions.
---
I ran out of bits while trying to save an integer in a GKeyFile.
Swapping gint with gint64 seemed like the easiest solution.
I'm not entirely sure how this effects portability or backwards
compatibility (could be more of a problem with the _list functions).

You could also add separate get/set functions for longlong or int64, not
sure if that would be better or worse though. Thoughts?

 glib/gkeyfile.c |   32 +++++++++++++++-----------------
 glib/gkeyfile.h |    8 ++++----
 2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 2226e70..364d791 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -156,11 +156,11 @@ static gchar                *g_key_file_parse_value_as_string  (GKeyFile
 static gchar                *g_key_file_parse_string_as_value  (GKeyFile               *key_file,
 								const gchar            *string,
 								gboolean                escape_separator);
-static gint                  g_key_file_parse_value_as_integer (GKeyFile               *key_file,
+static gint64                g_key_file_parse_value_as_integer (GKeyFile               *key_file,
 								const gchar            *value,
 								GError                **error);
 static gchar                *g_key_file_parse_integer_as_value (GKeyFile               *key_file,
-								gint                    value);
+								gint64                  value);
 static gdouble               g_key_file_parse_value_as_double  (GKeyFile               *key_file,
                                                                 const gchar            *value,
                                                                 GError                **error);
@@ -2085,7 +2085,7 @@ g_key_file_set_boolean_list (GKeyFile    *key_file,
  *
  * Since: 2.6
  **/
-gint
+gint64
 g_key_file_get_integer (GKeyFile     *key_file,
 			const gchar  *group_name,
 			const gchar  *key,
@@ -2093,7 +2093,7 @@ g_key_file_get_integer (GKeyFile     *key_file,
 {
   GError *key_file_error;
   gchar *value;
-  gint int_value;
+  gint64 int_value;
 
   g_return_val_if_fail (key_file != NULL, -1);
   g_return_val_if_fail (group_name != NULL, -1);
@@ -2149,7 +2149,7 @@ void
 g_key_file_set_integer (GKeyFile    *key_file,
 			const gchar *group_name,
 			const gchar *key,
-			gint         value)
+			gint64       value)
 {
   gchar *result;
 
@@ -2181,7 +2181,7 @@ g_key_file_set_integer (GKeyFile    *key_file,
  *
  * Since: 2.6
  **/
-gint *
+gint64 *
 g_key_file_get_integer_list (GKeyFile     *key_file,
 			     const gchar  *group_name,
 			     const gchar  *key,
@@ -2190,7 +2190,7 @@ g_key_file_get_integer_list (GKeyFile     *key_file,
 {
   GError *key_file_error = NULL;
   gchar **values;
-  gint *int_values;
+  gint64 *int_values;
   gsize i, num_ints;
 
   g_return_val_if_fail (key_file != NULL, NULL);
@@ -2209,7 +2209,7 @@ g_key_file_get_integer_list (GKeyFile     *key_file,
   if (!values)
     return NULL;
 
-  int_values = g_new (gint, num_ints);
+  int_values = g_new (gint64, num_ints);
 
   for (i = 0; i < num_ints; i++)
     {
@@ -2251,7 +2251,7 @@ void
 g_key_file_set_integer_list (GKeyFile    *key_file,
 			     const gchar *group_name,
 			     const gchar *key,
-			     gint         list[],
+			     gint64       list[],
 			     gsize        length)
 {
   GString *values;
@@ -3629,17 +3629,16 @@ g_key_file_parse_string_as_value (GKeyFile    *key_file,
   return value;
 }
 
-static gint
+static gint64
 g_key_file_parse_value_as_integer (GKeyFile     *key_file,
 				   const gchar  *value,
 				   GError      **error)
 {
   gchar *end_of_valid_int;
- glong long_value;
-  gint int_value;
+  gint64 int_value;
 
   errno = 0;
-  long_value = strtol (value, &end_of_valid_int, 10);
+  int_value = strtoll (value, &end_of_valid_int, 10);
 
   if (*value == '\0' || *end_of_valid_int != '\0')
     {
@@ -3653,8 +3652,7 @@ g_key_file_parse_value_as_integer (GKeyFile     *key_file,
       return 0;
     }
 
-  int_value = long_value;
-  if (int_value != long_value || errno == ERANGE)
+  if (errno == ERANGE)
     {
       gchar *value_utf8 = _g_utf8_make_valid (value);
       g_set_error (error,
@@ -3672,10 +3670,10 @@ g_key_file_parse_value_as_integer (GKeyFile     *key_file,
 
 static gchar *
 g_key_file_parse_integer_as_value (GKeyFile *key_file,
-				   gint      value)
+				   gint64    value)
 
 {
-  return g_strdup_printf ("%d", value);
+  return g_strdup_printf ("%lld", value);
 }
 
 static gdouble
diff --git a/glib/gkeyfile.h b/glib/gkeyfile.h
index b19124c..4e2781b 100644
--- a/glib/gkeyfile.h
+++ b/glib/gkeyfile.h
@@ -128,14 +128,14 @@ void      g_key_file_set_boolean            (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
 					     gboolean              value);
-gint      g_key_file_get_integer            (GKeyFile             *key_file,
+gint64    g_key_file_get_integer            (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
 					     GError              **error);
 void      g_key_file_set_integer            (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
-					     gint                  value);
+					     gint64                value);
 gdouble   g_key_file_get_double             (GKeyFile             *key_file,
                                              const gchar          *group_name,
                                              const gchar          *key,
@@ -176,7 +176,7 @@ void      g_key_file_set_boolean_list       (GKeyFile             *key_file,
 					     const gchar          *key,
 					     gboolean              list[],
 					     gsize                 length);
-gint     *g_key_file_get_integer_list       (GKeyFile             *key_file,
+gint64   *g_key_file_get_integer_list       (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
 					     gsize                *length,
@@ -194,7 +194,7 @@ gdouble  *g_key_file_get_double_list        (GKeyFile             *key_file,
 void      g_key_file_set_integer_list       (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
-					     gint                  list[],
+					     gint64                list[],
 					     gsize                 length);
 gboolean  g_key_file_set_comment            (GKeyFile             *key_file,
                                              const gchar          *group_name,
-- 
1.6.5.2

Attachment: pgpn9SjXXiQ6f.pgp
Description: PGP signature



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