Merge 2.57.3 into tizen
[platform/upstream/glib.git] / glib / gvariant-parser.c
index 233a19f..f813a1b 100644 (file)
@@ -465,7 +465,13 @@ pattern_coalesce (const gchar *left,
               (*one)++;
             }
 
-          else if (**one == 'N' && strchr ("ynqiuxthd", **the_other))
+          else if (**one == 'N' && strchr ("ynqiuxthfd", **the_other))
+            {
+              *out++ = *(*the_other)++;
+              (*one)++;
+            }
+
+          else if (**one == 'D' && (**the_other == 'f' || **the_other == 'd'))
             {
               *out++ = *(*the_other)++;
               (*one)++;
@@ -626,6 +632,10 @@ ast_resolve (AST     *ast,
         pattern[j++] = 'i';
         break;
 
+      case 'D':
+        pattern[j++] = 'd';
+        break;
+
       default:
         pattern[j++] = pattern[i];
         break;
@@ -1256,7 +1266,7 @@ dictionary_get_pattern (AST     *ast,
   /* the basic types,
    * plus undetermined number type and undetermined string type.
    */
-  if (!strchr ("bynqiuxthdsogNS", key_char))
+  if (!strchr ("bynqiuxthfdsogNDS", key_char))
     {
       ast_set_error (ast, error, NULL,
                      G_VARIANT_PARSE_ERROR_BASIC_TYPE_EXPECTED,
@@ -1804,7 +1814,7 @@ number_get_pattern (AST     *ast,
       (!g_str_has_prefix (number->token, "0x") && strchr (number->token, 'e')) ||
       strstr (number->token, "inf") ||
       strstr (number->token, "nan"))
-    return g_strdup ("Md");
+    return g_strdup ("MD");
 
   return g_strdup ("MN");
 }
@@ -1829,17 +1839,16 @@ number_get_value (AST                 *ast,
   Number *number = (Number *) ast;
   const gchar *token;
   gboolean negative;
-  gboolean floating;
   guint64 abs_val;
   gdouble dbl_val;
+  gchar typechar;
   gchar *end;
 
+  typechar = *g_variant_type_peek_string (type);
   token = number->token;
 
-  if (g_variant_type_equal (type, G_VARIANT_TYPE_DOUBLE))
+  if (typechar == 'f' || typechar == 'd')
     {
-      floating = TRUE;
-
       errno = 0;
       dbl_val = g_ascii_strtod (token, &end);
       if (dbl_val != 0.0 && errno == ERANGE)
@@ -1856,7 +1865,6 @@ number_get_value (AST                 *ast,
     }
   else
     {
-      floating = FALSE;
       negative = token[0] == '-';
       if (token[0] == '-')
         token++;
@@ -1892,10 +1900,7 @@ number_get_value (AST                 *ast,
       return NULL;
      }
 
-  if (floating)
-    return g_variant_new_double (dbl_val);
-
-  switch (*g_variant_type_peek_string (type))
+  switch (typechar)
     {
     case 'y':
       if (negative || abs_val > G_MAXUINT8)
@@ -1937,6 +1942,12 @@ number_get_value (AST                 *ast,
         return number_overflow (ast, type, error);
       return g_variant_new_handle (negative ? -abs_val : abs_val);
 
+    case 'f':
+      return g_variant_new_float (dbl_val);
+
+    case 'd':
+      return g_variant_new_double (dbl_val);
+
     default:
       return ast_type_error (ast, type, error);
     }
@@ -2222,6 +2233,9 @@ typedecl_parse (TokenStream  *stream,
       else if (token_stream_consume (stream, "uint64"))
         type = g_variant_type_copy (G_VARIANT_TYPE_UINT64);
 
+      else if (token_stream_consume (stream, "float"))
+        type = g_variant_type_copy (G_VARIANT_TYPE_FLOAT);
+
       else if (token_stream_consume (stream, "double"))
         type = g_variant_type_copy (G_VARIANT_TYPE_DOUBLE);