Skip to contentSkip to conversation

cmdline: treat hyphens and underscores the same

PATCH In review Jan Beulich 3 participants 4 messages Jan 23, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cmdline: treat hyphens and underscores the same

In order to avoid permanently having to ask that no new command line options using underscores be introduced (albeit I'm likely to still make remarks), and in order to also allow extending the use of hyphens to pre-existing ones, introduce custom comparison functions treating both characters as matching.

---
v2: Rename to opt_str{,n}cmp(). Don't use the new function for comapring
against "no-" in parse_params(). Add comment to cdiff().

docs/misc/xen-command-line.pandoc +5 -0
@@ -72,6 +72,11 @@ Some options take a comma separated list
 Some parameters act as combinations of the above, most commonly a mix
 of Boolean and String.  These are noted in the relevant sections.
 
+### Spelling
+
+Parameter names may include hyphens or underscores.  These are
+generally being treated as matching one another by the parsing logic.
+
 ## Parameter details
 
 ### acpi
xen/common/kernel.c +52 -5

90 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw
Quoted 49 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Jan Beulich
Sent: 23 January 2020 11:43
To: [email protected]
Cc: Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Konrad Wilk <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>
Subject: [Xen-devel] [PATCH v2] cmdline: treat hyphens and underscores the same

In order to avoid permanently having to ask that no new command line options using underscores be introduced (albeit I'm likely to still make remarks), and in order to also allow extending the use of hyphens to pre-existing ones, introduce custom comparison functions treating both characters as matching.

---
v2: Rename to opt_str{,n}cmp(). Don't use the new function for comapring
against "no-" in parse_params(). Add comment to cdiff().

docs/misc/xen-command-line.pandoc +5 -0
@@ -72,6 +72,11 @@ Some options take a comma separated list
 Some parameters act as combinations of the above, most commonly a mix
 of Boolean and String.  These are noted in the relevant sections.
 
+### Spelling
+
+Parameter names may include hyphens or underscores.  These are
+generally being treated as matching one another by the parsing logic.
+
 ## Parameter details
 
 ### acpi
xen/common/kernel.c +2 -0
@@ -23,6 +23,53 @@ enum system_state system_state = SYS_STA
 xen_commandline_t saved_cmdline;
 static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 
+/*
+ * Calculate the difference between two characters for command line

parsing
+ * purposes, i.e. treating '-' and '_' the same.
+ */

xen/common/kernel.c enum system_state system_state = SYS_STA · line 37

Quoted 8 lines
xen/common/kernel.c +8 -0
+static int cdiff(unsigned char c1, unsigned char c2)
+{
+    int res = c1 - c2;
+
+    if ( res && (c1 ^ c2) == ('-' ^ '_') &&
+         (c1 == '-' || c1 == '_') )
+        res = 0;
+

Wow! That makes my head hurt. How about:

static int cdiff(unsigned char c1, unsigned char c2)

{
    if ( c1 == '-' )
        c1 = '_';

    if ( c2 == '-' )
        c2 = '_';

    return c1 - c2;
}

?

Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 71 lines · Paul
Quoted 49 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Jan Beulich
Sent: 23 January 2020 11:43
To: [email protected]
Cc: Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Konrad Wilk <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>
Subject: [Xen-devel] [PATCH v2] cmdline: treat hyphens and underscores the same

In order to avoid permanently having to ask that no new command line options using underscores be introduced (albeit I'm likely to still make remarks), and in order to also allow extending the use of hyphens to pre-existing ones, introduce custom comparison functions treating both characters as matching.

---
v2: Rename to opt_str{,n}cmp(). Don't use the new function for comapring
against "no-" in parse_params(). Add comment to cdiff().

docs/misc/xen-command-line.pandoc +5 -0
@@ -72,6 +72,11 @@ Some options take a comma separated list
 Some parameters act as combinations of the above, most commonly a mix
 of Boolean and String.  These are noted in the relevant sections.
 
+### Spelling
+
+Parameter names may include hyphens or underscores.  These are
+generally being treated as matching one another by the parsing logic.
+
 ## Parameter details
 
 ### acpi
xen/common/kernel.c +2 -0
@@ -23,6 +23,53 @@ enum system_state system_state = SYS_STA
 xen_commandline_t saved_cmdline;
 static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 
+/*
+ * Calculate the difference between two characters for command line

parsing
+ * purposes, i.e. treating '-' and '_' the same.
+ */

xen/common/kernel.c enum system_state system_state = SYS_STA · line 37

Quoted 8 lines
xen/common/kernel.c +8 -0
+static int cdiff(unsigned char c1, unsigned char c2)
+{
+    int res = c1 - c2;
+
+    if ( res && (c1 ^ c2) == ('-' ^ '_') &&
+         (c1 == '-' || c1 == '_') )
+        res = 0;
+

Wow! That makes my head hurt. How about:

static int cdiff(unsigned char c1, unsigned char c2)

{
    if ( c1 == '-' )
        c1 = '_';

    if ( c2 == '-' )
        c2 = '_';

    return c1 - c2;
}
Quoted 1 line

?

This would work for the current uses where ultimately the result is only evaluated for being (non-)zero, but wouldn't be correct when used for actual collation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

In order to avoid permanently having to ask that no new command line options using underscores be introduced (albeit I'm likely to still make remarks), and in order to also allow extending the use of hyphens to pre-existing ones, introduce custom comparison functions treating both characters as matching.

---
v2: Rename to opt_str{,n}cmp(). Don't use the new function for comapring
against "no-" in parse_params(). Add comment to cdiff().

Personally, I think this is a bad idea and should not be continued.

Yes - it is irritating needing to remember whether an option is spelled with hyphen or underscore, but that is nothing compared to the pain for users, who will have less bleeding edge version of Xen where the different really matters.

Having one consistent behaviour across all versions of Xen is of far more value to people than trying to fix a few wonky corner cases for developers benefit.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel