[glib/wip/mattiasb/gdbus-codegen-safer-headerguards] gdbus-codegen: Safer header guards
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/mattiasb/gdbus-codegen-safer-headerguards] gdbus-codegen: Safer header guards
- Date: Tue, 29 Oct 2019 15:14:50 +0000 (UTC)
commit 3ce697ffef5e1f646ac5340dfcdab39af049c03d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Tue Oct 29 16:01:39 2019 +0100
gdbus-codegen: Safer header guards
Whitelist a safe set of characters for use in header guards instead of
maintaining a (growing) blacklist.
The whitelist is intentionally short since reading up on all
peculiarities of the C and C++ standard for identifiers is not my idea
of fun. :)
Fixes #1379
gio/gdbus-2.0/codegen/codegen.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py
index 55cd7bb34..119c97d68 100644
--- a/gio/gdbus-2.0/codegen/codegen.py
+++ b/gio/gdbus-2.0/codegen/codegen.py
@@ -51,6 +51,13 @@ def generate_namespace(namespace):
return (ns, ns_upper, ns_lower)
+def generate_header_guard(header_name):
+ # There might be more characters that are safe to use than these, but lets
+ # stay conservative.
+ safe_valid_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ return ''.join(map(lambda c: c if c in safe_valid_chars else '_',
+ header_name.upper()))
+
class HeaderCodeGenerator:
def __init__(self, ifaces, namespace, generate_objmanager,
generate_autocleanup, header_name, input_files_basenames,
@@ -59,7 +66,7 @@ class HeaderCodeGenerator:
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
self.generate_objmanager = generate_objmanager
self.generate_autocleanup = generate_autocleanup
- self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/',
'_').replace(':', '_')
+ self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma
self.outfile = outfile
@@ -613,7 +620,7 @@ class InterfaceInfoHeaderCodeGenerator:
def __init__(self, ifaces, namespace, header_name, input_files_basenames, use_pragma, outfile):
self.ifaces = ifaces
self.namespace, self.ns_upper, self.ns_lower = generate_namespace(namespace)
- self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/',
'_').replace(':', '_')
+ self.header_guard = generate_header_guard(header_name)
self.input_files_basenames = input_files_basenames
self.use_pragma = use_pragma
self.outfile = outfile
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]