summaryrefslogtreecommitdiff
path: root/cffi
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2019-10-14 09:16:01 +0200
committerArmin Rigo <arigo@tunes.org>2019-10-14 09:16:01 +0200
commit2e1c8e4f059b1ae7cc06a1f45f40bbbf9d08f5d0 (patch)
treed4747cf3365cc6a782b226acecfebd612ad00105 /cffi
parent7fa9a5f8a80e0e460c486a7f90ae12886b22b0d9 (diff)
downloadcffi-2e1c8e4f059b1ae7cc06a1f45f40bbbf9d08f5d0.tar.gz
Add a warning when we use in cdef() a global variable without also specifying a storage class (extern or static)
Diffstat (limited to 'cffi')
-rw-r--r--cffi/cparser.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py
index 9cb3412..c275f42 100644
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -156,6 +156,13 @@ def _warn_for_string_literal(csource):
"confuse pre-parsing.")
break
+def _warn_for_non_extern_non_static_global_variable(decl):
+ if not decl.storage:
+ import warnings
+ warnings.warn("Declaration of global variable '%s' in cdef() should "
+ "be marked 'extern' for consistency (or possibly "
+ "'static' in API mode)" % (decl.name,))
+
def _preprocess(csource):
# Remove comments. NOTE: this only work because the cdef() section
# should not contain any string literal!
@@ -506,6 +513,7 @@ class Parser(object):
if (quals & model.Q_CONST) and not tp.is_array_type:
self._declare('constant ' + decl.name, tp, quals=quals)
else:
+ _warn_for_non_extern_non_static_global_variable(decl)
self._declare('variable ' + decl.name, tp, quals=quals)
def parse_type(self, cdecl):