pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15032


Change subject: Get rid of osmo_str_tolower() use inside libosmocore code
......................................................................

Get rid of osmo_str_tolower() use inside libosmocore code

There's no real good reason for using that function (static buffer)
instead of osmo_str_tolower_buf(local buffer), so let's use the later.
In any case, we get rid of TLS variables in those places, which is a
performance improvement.
It will also allow later shrinking of those buffers if we decide to
define maximum logging category and level name length.

Change-Id: I2e99de1142020e4d80ef0a094e4e751f7903f5f9
---
M src/vty/logging_vty.c
1 file changed, 13 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/32/15032/1

diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 9911c6f..b785be4 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -289,14 +289,15 @@
 static void add_category_strings(char **cmd_str_p, char **doc_str_p,
                                 const struct log_info *categories)
 {
+       char buf[128];
        int i;
        for (i = 0; i < categories->num_cat; i++) {
                if (categories->cat[i].name == NULL)
                        continue;
                /* skip the leading 'D' in each category name, hence '+ 1' */
+               osmo_str_tolower_buf(buf, sizeof(buf), categories->cat[i].name 
+ 1);
                osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s",
-                                    i ? "|" : "",
-                                    osmo_str_tolower(categories->cat[i].name + 
1));
+                                    i ? "|" : "", buf);
                osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n",
                                     categories->cat[i].description);
        }
@@ -868,6 +869,7 @@

 static int config_write_log_single(struct vty *vty, struct log_target *tgt)
 {
+       char level_buf[128];
        int i;

        switch (tgt->type) {
@@ -923,26 +925,25 @@

        if (tgt->loglevel) {
                const char *level_str = get_value_string_or_null(loglevel_strs, 
tgt->loglevel);
-               level_str = osmo_str_tolower(level_str);
-               if (!level_str)
+               if (!level_str) {
                        vty_out(vty, "%% Invalid log level %u for 
'force-all'%s",
                                tgt->loglevel, VTY_NEWLINE);
-               else
-                       vty_out(vty, " logging level force-all %s%s", 
level_str, VTY_NEWLINE);
+               } else {
+                       osmo_str_tolower_buf(level_buf, sizeof(level_buf), 
level_str);
+                       vty_out(vty, " logging level force-all %s%s", 
level_buf, VTY_NEWLINE);
+               }
        }

        for (i = 0; i < osmo_log_info->num_cat; i++) {
                const struct log_category *cat = &tgt->categories[i];
-               const char *cat_name;
+               char cat_name[128];
                const char *level_str;

                /* skip empty entries in the array */
                if (!osmo_log_info->cat[i].name)
                        continue;

-               /* Note: cat_name references the static buffer returned by 
osmo_str_tolower(), will
-                * become invalid after next osmo_str_tolower() invocation. */
-               cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1);
+               osmo_str_tolower_buf(cat_name, sizeof(cat_name), 
osmo_log_info->cat[i].name + 1);

                level_str = get_value_string_or_null(loglevel_strs, 
cat->loglevel);
                if (!level_str) {
@@ -951,8 +952,9 @@
                        continue;
                }

+               osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str);
                vty_out(vty, " logging level %s", cat_name);
-               vty_out(vty, " %s%s", osmo_str_tolower(level_str), VTY_NEWLINE);
+               vty_out(vty, " %s%s", level_buf, VTY_NEWLINE);
        }

        return 1;

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15032
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I2e99de1142020e4d80ef0a094e4e751f7903f5f9
Gerrit-Change-Number: 15032
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to