Message ID | 20180202130336.24719-19-armbru@redhat.com |
---|---|
State | New |
Headers | show |
Series | Modularize generated QAPI code | expand |
On Fri, Feb 2, 2018 at 2:03 PM, Markus Armbruster <armbru@redhat.com> 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 <armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@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() > > > def guardstart(name): > -- > 2.13.6 >
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 <armbru@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 <eblake@redhat.com>
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() def guardstart(name):
guardname() fails to return a valid C identifier for arguments containing anything but [A-Za-z0-9_.-']. Fix that. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- scripts/qapi/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)