gstdoc-scangobj: serialise doubles and floats always with a decimal dot
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 23 Jul 2010 15:46:10 +0000 (16:46 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 23 Jul 2010 15:46:10 +0000 (16:46 +0100)
Make sure floats and double property values are output with a decimal dot
(and not e.g. a comma) irrespective of the current locale. g_ascii_formatd() is
used here instead of g_ascii_dtostr() because we want nice human-readable
numbers and do not need the exact same bit representation when deserialising.

Other parts of gtk-doc may need fixing as well to make sure to always
deserialise floats and doubles in C locale.

gstdoc-scangobj

index f1d031b..cc1e294 100755 (executable)
@@ -1216,8 +1216,13 @@ describe_double_constant (gdouble value)
     desc = g_strdup ("G_MINFLOAT");
   else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
     desc = g_strdup ("-G_MAXFLOAT");
-  else
-    desc = g_strdup_printf ("%lg", value);
+  else {
+    /* make sure floats are output with a decimal dot irrespective of
+     * current locale. Use formatd since we want human-readable numbers
+     * and do not need the exact same bit representation when deserialising */
+    desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+    g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
+  }
 
   return desc;
 }
@@ -1583,13 +1588,23 @@ describe_default (GParamSpec *spec)
     {
       GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
 
-      desc = g_strdup_printf ("%g", pspec->default_value);
+      /* make sure floats are output with a decimal dot irrespective of
+       * current locale. Use formatd since we want human-readable numbers
+       * and do not need the exact same bit representation when deserialising */
+      desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+      g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+          pspec->default_value);
     }
   else if (G_IS_PARAM_SPEC_DOUBLE (spec))
     {
       GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
 
-      desc = g_strdup_printf ("%lg", pspec->default_value);
+      /* make sure floats are output with a decimal dot irrespective of
+       * current locale. Use formatd since we want human-readable numbers
+       * and do not need the exact same bit representation when deserialising */
+      desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+      g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+          pspec->default_value);
     }
   else if (G_IS_PARAM_SPEC_STRING (spec))
     {