[Spice-devel] [spice-common 1/5] codegen: Improve header guard generation
Frediano Ziglio
fziglio at redhat.com
Fri Jun 24 06:46:29 UTC 2016
>
> From: Frediano Ziglio <fziglio at redhat.com>
>
> Until now, the same header guard was used for all generated .h files.
> Now the header guard name is based on the name of the file being
> generated so that it's different for each .h file.
> ---
> Frediano, I left you as the author of this patch but I squashed the changes I
> suggested, I can take ownership and mention you in the commit log if you
> prefer.
>
> Christophe
>
You could just add two Signed-off-by lines.
Beside that I would say ack.
Frediano
>
> python_modules/marshal.py | 13 +++++++++++--
> spice_codegen.py | 1 +
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/python_modules/marshal.py b/python_modules/marshal.py
> index cc6cbdf..dc36e18 100644
> --- a/python_modules/marshal.py
> +++ b/python_modules/marshal.py
> @@ -1,13 +1,22 @@
>
> from . import ptypes
> from . import codegen
> +import re
>
> def write_includes(writer):
> writer.header.writeln("#include <spice/protocol.h>")
> writer.header.writeln('#include "common/marshaller.h"')
> writer.header.newline()
> - writer.header.writeln("#ifndef _GENERATED_HEADERS_H")
> - writer.header.writeln("#define _GENERATED_HEADERS_H")
> + if writer.header.has_option("dest_file"):
> + src = writer.header.options["dest_file"]
> + else:
> + src = "generated_headers.h"
> + src = re.sub(r'[^a-z0-9]+', '_', src, flags=re.IGNORECASE)
> + src = src.upper()
> + if src.endswith("_H"):
> + src = "_H_"+src[:-2]
> + writer.header.writeln("#ifndef %s" % src)
> + writer.header.writeln("#define %s" % src)
>
> writer.writeln("#include <string.h>")
> writer.writeln("#include <assert.h>")
> diff --git a/spice_codegen.py b/spice_codegen.py
> index 569cccc..53c7be3 100755
> --- a/spice_codegen.py
> +++ b/spice_codegen.py
> @@ -170,6 +170,7 @@ if proto == None:
> codegen.set_prefix(proto.name)
> writer = codegen.CodeWriter()
> writer.header = codegen.CodeWriter()
> +writer.header.set_option("dest_file", dest_file)
> writer.set_option("source", os.path.basename(proto_file))
>
> license = """/*
> --
> 2.7.4
>
>
More information about the Spice-devel
mailing list