[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated (2dbc55882 -> d095ae856)
From: |
gnunet |
Subject: |
[gnunet] branch master updated (2dbc55882 -> d095ae856) |
Date: |
Mon, 09 Dec 2024 13:29:24 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a change to branch master
in repository gnunet.
from 2dbc55882 meson: fix build with new submodules
new e14699ed8 util: Fix #9369
new d095ae856 -fix comment
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/include/gnunet_configuration_lib.h | 14 ++++++++++++++
src/lib/util/configuration.c | 27 +++++++++++++++++++++++++++
src/lib/util/test_configuration.c | 27 +++++++++++++++++++++++++++
3 files changed, 68 insertions(+)
diff --git a/src/include/gnunet_configuration_lib.h
b/src/include/gnunet_configuration_lib.h
index d856658b3..d8e688e32 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -376,6 +376,20 @@ GNUNET_CONFIGURATION_get_value_number (
const char *option,
unsigned long long *number);
+/**
+ * Set a configuration value that should be a float.
+ * Note that this possibly truncates your float value.
+ *
+ * @param cfg configuration to update
+ * @param section section of interest
+ * @param option option of interest
+ * @param number value to set
+ */
+void
+GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ float number);
/**
* Get a configuration value that should be a floating point number.
diff --git a/src/lib/util/configuration.c b/src/lib/util/configuration.c
index 9c4e120a4..0eaea6a88 100644
--- a/src/lib/util/configuration.c
+++ b/src/lib/util/configuration.c
@@ -1711,6 +1711,29 @@ GNUNET_CONFIGURATION_get_value_number (
return GNUNET_OK;
}
+void
+GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ float number)
+{
+ char s[64];
+
+ // TODO FIXME note that this truncates the float
+ // #9369
+ const locale_t cl = newlocale(0, "C", (locale_t)0);
+ locale_t old_locale = uselocale(cl);
+ GNUNET_snprintf (s,
+ 64,
+ "%f",
+ number);
+ uselocale(old_locale);
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ section,
+ option,
+ s);
+}
+
enum GNUNET_GenericReturnValue
GNUNET_CONFIGURATION_get_value_float (
@@ -1728,11 +1751,15 @@ GNUNET_CONFIGURATION_get_value_float (
return GNUNET_NO;
if (NULL == e->val)
return GNUNET_NO;
+ // #9369
+ const locale_t cl = newlocale(0, "C", (locale_t)0);
+ locale_t old_locale = uselocale(cl);
if (1 != sscanf (e->val,
"%f%1s",
number,
dummy))
return GNUNET_SYSERR;
+ uselocale(old_locale);
return GNUNET_OK;
}
diff --git a/src/lib/util/test_configuration.c
b/src/lib/util/test_configuration.c
index 68f907b03..2d1e3d1b8 100644
--- a/src/lib/util/test_configuration.c
+++ b/src/lib/util/test_configuration.c
@@ -305,6 +305,7 @@ testConfig ()
{
char *c;
unsigned long long l;
+ float f;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b",
&c))
return 1;
@@ -347,6 +348,32 @@ testConfig ()
}
GNUNET_free (c);
+ // This only works if we have this locale.
+ setlocale(LC_NUMERIC, "de_DE");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "NUMBERS", "FLOAT_TEST_INVALID",
"1,23");
+ if (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_float (cfg, "NUMBERS",
"FLOAT_TEST_INVALID", &f))
+ {
+ printf ("Parsed: %f\n", f);
+ GNUNET_break (0);
+ return 6;
+ }
+ GNUNET_CONFIGURATION_set_value_float (cfg, "NUMBERS", "FLOAT_TEST", 1.23);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "FLOAT_TEST", &c))
+ {
+ GNUNET_break (0);
+ return 6;
+ }
+ if (0 != strncmp (c, "1.23", 4))
+ {
+ printf ("%s\n", c);
+ GNUNET_free (c);
+ GNUNET_break (0);
+ return 7;
+ }
+ GNUNET_free (c);
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] branch master updated (2dbc55882 -> d095ae856),
gnunet <=