On 02/02/2018 07:03 AM, Markus Armbruster wrote:
guardname() fails to return a valid C identifier for arguments
containing anything but [A-Za-z0-9_.-'].  Fix that.

Signed-off-by: Markus Armbruster <arm...@redhat.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 7ffffc78d9..7d497b5b17 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1860,7 +1860,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()

For some choices of filename, the old code prefixes a q_ (via c_name) which gets turned into Q_ in the final guard name. The new code does not. Then again, all of the names protected by c_name() all contain lower case, while guard names are all upper case; so we aren't protecting ourselves from defining a reserved word; the main use for c_name() is to protect ourselves where we are not changing case (for example, _BOOL is no better than Q__BOOL as a guard name for a file named _Bool).

Might be worth mentioning this design consideration in the commit message, but the change itself is reasonable.

Reviewed-by: Eric Blake <ebl...@redhat.com>

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to