You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2026/10/29 10:42:29 UTC
(mynewt-newt) branch master updated: newt/syscfg: Don't add parentheses around single token values
This is an automated email from the ASF dual-hosted git repository.
kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new fcd7d412 newt/syscfg: Don't add parentheses around single token values
fcd7d412 is described below
commit fcd7d412462e95c667191b5ecc56e13c57f2e1be
Author: Jerzy Kasenberg <je...@apache.org>
AuthorDate: Tue Oct 27 18:45:07 2026 +0100
newt/syscfg: Don't add parentheses around single token values
syscfg.h wrapped every non-string value in parentheses, so
MYNEWT_VAL(X) gave (5) or (FOO). That makes values impossible to use
for token pasting (i.e. to build symbol names from a setting) without
tricks that strip the parentheses.
Values that are a single decimal or hex number (with optional integer
suffix) or a single identifier are now written as is. Negative numbers
and expressions are still wrapped in parentheses. Choice defines are
written without parentheses too, they are always 0 or 1.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jerzy Kasenberg <je...@apache.org>
---
newt/syscfg/syscfg.go | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index 337bebf2..e05389ff 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -81,6 +81,10 @@ const SYSCFG_TASK_PRIO_MAX = 0xef
var cfgRefRe = regexp.MustCompile("MYNEWT_VAL\\((\\w+)\\)")
var cfgChoiceValRe = regexp.MustCompile("^[A-Za-z0-9_]+$")
+
+// Decimal or hex number (with optional integer suffix) or identifier.
+var cfgSingleTokenRe = regexp.MustCompile(
+ "^([0-9]+|0[xX][0-9A-Fa-f]+)[uUlL]*$|^[A-Za-z_][A-Za-z0-9_]*$")
var cfgPkgRepoName = regexp.MustCompile("^@([A-Za-z0-9-_]+)/")
var cfgPkgIllegalChar = regexp.MustCompile("[^A-Za-z0-9_]")
@@ -1521,6 +1525,10 @@ func writeDefine(key string, value string, w io.Writer) {
fmt.Fprintf(w, "#ifndef %s\n", key)
if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") {
fmt.Fprintf(w, "#define %s %s\n", key, value)
+ } else if cfgSingleTokenRe.MatchString(value) {
+ // Single number or identifier does not need parentheses; this
+ // allows value to be used for token pasting.
+ fmt.Fprintf(w, "#define %s %s\n", key, value)
} else {
fmt.Fprintf(w, "#define %s (%s)\n", key, value)
}
@@ -1539,7 +1547,7 @@ func writeChoiceDefine(key string, value string, choices []string, w io.Writer)
parentVal = "1"
}
fmt.Fprintf(w, "#ifndef %s__%s\n", key, choice)
- fmt.Fprintf(w, "#define %s__%s (%d)\n", key, choice, definedVal)
+ fmt.Fprintf(w, "#define %s__%s %d\n", key, choice, definedVal)
fmt.Fprintf(w, "#endif\n")
}