return long long, not int, so gint64 deserialization actually works. Is there any...
authorThomas Vander Stichele <thomas@apestaart.org>
Wed, 22 Jun 2005 10:52:18 +0000 (10:52 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Wed, 22 Jun 2005 10:52:18 +0000 (10:52 +0000)
Original commit message from CVS:

* check/gst/gstvalue.c: (START_TEST):
* gst/gstvalue.c: (gst_value_deserialize):
return long long, not int, so gint64 deserialization actually
works.  Is there any flag that makes the compiler check this ?
Fixes #308559

ChangeLog
check/gst/gstvalue.c
gst/gstvalue.c
tests/check/gst/gstvalue.c

index 7ff0f7d2a699059f3c9c8657249bffef1aeac68a..85c4739331262f6b02f9f870403da498186237e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-06-22  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+       * check/gst/gstvalue.c: (START_TEST):
+       * gst/gstvalue.c: (gst_value_deserialize):
+         return long long, not int, so gint64 deserialization actually
+         works.  Is there any flag that makes the compiler check this ?
+         Fixes #308559
+
 2005-06-22  Wim Taymans  <wim@fluendo.com>
 
        * gst/gstbuffer.h:
index 81247846d79e642407ac2d920274a7dbcc83e789..f0a9b4c83ce32f63bd1058553fd82f596f4d75c4 100644 (file)
@@ -36,14 +36,13 @@ END_TEST;
 START_TEST (test_deserialize_gint64)
 {
   GValue value = { 0 };
+  const char *string = "12345678901";
+
 
   g_value_init (&value, G_TYPE_INT64);
-  fail_unless (gst_value_deserialize (&value, "12345678901"));
-  /* FIXME:
-   * this test actually fails, gasp.
-   fail_unless (g_value_get_int64 (&value) == 12345678901LL,
-   "resulting value is %" G_GINT64_FORMAT ", not 12345678901");
-   */
+  fail_unless (gst_value_deserialize (&value, string));
+  fail_unless (g_value_get_int64 (&value) == 12345678901LL,
+      "resulting value is %" G_GINT64_FORMAT ", not %s", value, string);
 }
 
 END_TEST;
index 4e4a3142fc5526500310e1de36087f7d3032520b..ca73b04314d018adc4ff9567f93cf3663027b3ec 100644 (file)
@@ -984,7 +984,7 @@ gst_value_deserialize_boolean (GValue * dest, const char *s)
  * int *
  *******/
 
-static int
+static long long
 gst_strtoll (const char *s, char **end, int base)
 {
   long long i;
@@ -1058,72 +1058,74 @@ gst_value_deserialize_int_helper (long long *to, const char *s, long long min,
   return ret;
 }
 
-#define CREATE_SERIALIZATION(_type,_macro) \
-CREATE_SERIALIZATION_START(_type,_macro) \
-\
-static gboolean \
-gst_value_deserialize_ ## _type (GValue * dest, const char *s) \
-{ \
-  long long x; \
-\
-  if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, G_MAX ## _macro)) { \
-    g_value_set_ ## _type (dest, x); \
-    return TRUE; \
-  } else { \
-    return FALSE; \
-  } \
-}
-
-#define CREATE_USERIALIZATION(_type,_macro) \
-CREATE_SERIALIZATION_START(_type,_macro) \
-\
-static gboolean \
-gst_value_deserialize_ ## _type (GValue * dest, const char *s) \
-{ \
-  unsigned long long x; \
-  char *end; \
-  gboolean ret = FALSE; \
-\
-  x = g_ascii_strtoull (s, &end, 0); \
-  if (*end == 0) { \
-    ret = TRUE; \
-  } else { \
-    if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
-      x = G_LITTLE_ENDIAN; \
-      ret = TRUE; \
-    } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
-      x = G_BIG_ENDIAN; \
-      ret = TRUE; \
-    } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
-      x = G_BYTE_ORDER; \
-      ret = TRUE; \
-    } else if (g_ascii_strcasecmp (s, "min") == 0) { \
-      x = 0; \
-      ret = TRUE; \
-    } else if (g_ascii_strcasecmp (s, "max") == 0) { \
-      x = G_MAX ## _macro; \
-      ret = TRUE; \
-    } \
-  } \
-  if (ret) { \
-    if (x > G_MAX ## _macro) {\
-      ret = FALSE; \
-    } else { \
-      g_value_set_ ## _type (dest, x); \
-    } \
-  } \
-  return ret; \
-}
-
-#define REGISTER_SERIALIZATION(_gtype, _type) G_STMT_START{ \
-  static const GstValueTable gst_value = { \
-    _gtype, \
-    gst_value_compare_ ## _type, \
-    gst_value_serialize_ ## _type, \
-    gst_value_deserialize_ ## _type, \
-  }; \
-\
-  gst_value_register (&gst_value); \
+#define CREATE_SERIALIZATION(_type,_macro)                             \
+CREATE_SERIALIZATION_START(_type,_macro)                               \
+                                                                       \
+static gboolean                                                                \
+gst_value_deserialize_ ## _type (GValue * dest, const char *s)         \
+{                                                                      \
+  long long x;                                                         \
+                                                                       \
+  if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro,                \
+      G_MAX ## _macro)) {                                              \
+    g_value_set_ ## _type (dest, x);                                   \
+    return TRUE;                                                       \
+  } else {                                                             \
+    return FALSE;                                                      \
+  }                                                                    \
+}
+
+#define CREATE_USERIALIZATION(_type,_macro)                            \
+CREATE_SERIALIZATION_START(_type,_macro)                               \
+                                                                       \
+static gboolean                                                                \
+gst_value_deserialize_ ## _type (GValue * dest, const char *s)         \
+{                                                                      \
+  unsigned long long x;                                                        \
+  char *end;                                                           \
+  gboolean ret = FALSE;                                                        \
+                                                                       \
+  x = g_ascii_strtoull (s, &end, 0);                                   \
+  if (*end == 0) {                                                     \
+    ret = TRUE;                                                                \
+  } else {                                                             \
+    if (g_ascii_strcasecmp (s, "little_endian") == 0) {                        \
+      x = G_LITTLE_ENDIAN;                                             \
+      ret = TRUE;                                                      \
+    } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {            \
+      x = G_BIG_ENDIAN;                                                        \
+      ret = TRUE;                                                      \
+    } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {            \
+      x = G_BYTE_ORDER;                                                        \
+      ret = TRUE;                                                      \
+    } else if (g_ascii_strcasecmp (s, "min") == 0) {                   \
+      x = 0;                                                           \
+      ret = TRUE;                                                      \
+    } else if (g_ascii_strcasecmp (s, "max") == 0) {                   \
+      x = G_MAX ## _macro;                                             \
+      ret = TRUE;                                                      \
+    }                                                                  \
+  }                                                                    \
+  if (ret) {                                                           \
+    if (x > G_MAX ## _macro) {                                         \
+      ret = FALSE;                                                     \
+    } else {                                                           \
+      g_value_set_ ## _type (dest, x);                                 \
+    }                                                                  \
+  }                                                                    \
+  return ret;                                                          \
+}
+
+#define REGISTER_SERIALIZATION(_gtype, _type)                          \
+G_STMT_START {                                                         \
+  static const GstValueTable gst_value = {                             \
+    _gtype,                                                            \
+    gst_value_compare_ ## _type,                                       \
+    gst_value_serialize_ ## _type,                                     \
+    gst_value_deserialize_ ## _type,                                   \
+  };                                                                   \
+                                                                       \
+  gst_value_register (&gst_value);                                     \
 } G_STMT_END
 
 CREATE_SERIALIZATION (int, INT)
@@ -2478,7 +2480,7 @@ gst_value_serialize (const GValue * value)
  *
  * Tries to deserialize a string into the type specified by the given GValue.
  * If the operation succeeds, TRUE is returned, FALSE otherwise.
- * 
+ *
  * Returns: TRUE on success
  */
 gboolean
@@ -2494,17 +2496,20 @@ gst_value_deserialize (GValue * dest, const gchar * src)
     table = &g_array_index (gst_value_table, GstValueTable, i);
     if (table->serialize == NULL)
       continue;
+
     if (table->type == G_VALUE_TYPE (dest)) {
       best = table;
       break;
     }
+
     if (g_type_is_a (G_VALUE_TYPE (dest), table->type)) {
       if (!best || g_type_is_a (table->type, best->type))
         best = table;
     }
   }
-  if (best)
+  if (best) {
     return best->deserialize (dest, src);
+  }
 
   return FALSE;
 }
index 81247846d79e642407ac2d920274a7dbcc83e789..f0a9b4c83ce32f63bd1058553fd82f596f4d75c4 100644 (file)
@@ -36,14 +36,13 @@ END_TEST;
 START_TEST (test_deserialize_gint64)
 {
   GValue value = { 0 };
+  const char *string = "12345678901";
+
 
   g_value_init (&value, G_TYPE_INT64);
-  fail_unless (gst_value_deserialize (&value, "12345678901"));
-  /* FIXME:
-   * this test actually fails, gasp.
-   fail_unless (g_value_get_int64 (&value) == 12345678901LL,
-   "resulting value is %" G_GINT64_FORMAT ", not 12345678901");
-   */
+  fail_unless (gst_value_deserialize (&value, string));
+  fail_unless (g_value_get_int64 (&value) == 12345678901LL,
+      "resulting value is %" G_GINT64_FORMAT ", not %s", value, string);
 }
 
 END_TEST;