diff mbox

[v2,21/29] qapi/common: Fix guardname() for funny filenames

Message ID 20180211093607.27351-22-armbru@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Markus Armbruster Feb. 11, 2018, 9:35 a.m. UTC
guardname() fails to return a valid C identifier for arguments
containing anything but [A-Za-z0-9_.-'].  Fix that.  Don't bother
protecting ticklish identifiers; header guards are all-caps, and no
ticklish identifiers are.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Roth Feb. 19, 2018, 6:18 p.m. UTC | #1
Quoting Markus Armbruster (2018-02-11 03:35:59)
> guardname() fails to return a valid C identifier for arguments
> containing anything but [A-Za-z0-9_.-'].  Fix that.  Don't bother
> protecting ticklish identifiers; header guards are all-caps, and no
> ticklish identifiers are.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  scripts/qapi/common.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index de12f8469a..6e5152b173 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -1867,7 +1867,7 @@ def mcgen(code, **kwds):
> 
> 
>  def guardname(filename):
> -    return c_name(filename, protect=False).upper()
> +    return re.sub(r'[^A-Za-z0-9_]', '_', filename).upper()
> 
> 
>  def guardstart(name):
> -- 
> 2.13.6
>
diff mbox

Patch

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index de12f8469a..6e5152b173 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1867,7 +1867,7 @@  def mcgen(code, **kwds):
 
 
 def guardname(filename):
-    return c_name(filename, protect=False).upper()
+    return re.sub(r'[^A-Za-z0-9_]', '_', filename).upper()
 
 
 def guardstart(name):