From 57e5fe8ccb86dbb88c96549ac69d3f3f16c8a91d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 4 May 2012 12:19:19 +0100 Subject: [PATCH 1/7] Add multiple-inclusion guards to generated client-side code --- telepathy-glib/codegen.am | 1 + tools/glib-client-gen.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/telepathy-glib/codegen.am b/telepathy-glib/codegen.am index 02fe35d..cd9a2ae 100644 --- a/telepathy-glib/codegen.am +++ b/telepathy-glib/codegen.am @@ -298,6 +298,7 @@ _gen/tp-cli-%-body.h: _gen/tp-spec-%.xml \ $(PYTHON) $(tools_dir)/glib-client-gen.py \ $$subclass $$subclass_assert \ --group `echo $* | tr - _` \ + --guard "TP_GEN_TP_CLI_`echo $* | tr a-z- A-Z_`_H_INCLUDED" \ --iface-quark-prefix=TP_IFACE_QUARK \ --tp-proxy-api=0.7.6 \ --deprecation-attribute=_TP_GNUC_DEPRECATED \ diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py index c94bd2c..6b2b97f 100644 --- a/tools/glib-client-gen.py +++ b/tools/glib-client-gen.py @@ -71,6 +71,8 @@ class Generator(object): self.deprecation_attribute = opts.get('--deprecation-attribute', 'G_GNUC_DEPRECATED') + self.guard = opts.get('--guard', None) + def h(self, s): if isinstance(s, unicode): s = s.encode('utf-8') @@ -1171,6 +1173,11 @@ class Generator(object): def __call__(self): + if self.guard is not None: + self.h('#ifndef %s' % self.guard) + self.h('#define %s' % self.guard) + self.h('') + self.h('G_BEGIN_DECLS') self.h('') @@ -1229,6 +1236,10 @@ class Generator(object): self.h('G_END_DECLS') self.h('') + if self.guard is not None: + self.h('#endif /* defined (%s) */' % self.guard) + self.h('') + file_set_contents(self.basename + '.h', '\n'.join(self.__header)) file_set_contents(self.basename + '-body.h', '\n'.join(self.__body)) file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) @@ -1242,7 +1253,7 @@ if __name__ == '__main__': ['group=', 'subclass=', 'subclass-assert=', 'iface-quark-prefix=', 'tp-proxy-api=', 'generate-reentrant=', 'deprecate-reentrant=', - 'deprecation-attribute=']) + 'deprecation-attribute=', 'guard=']) opts = {} -- 1.7.10