From 2e1c8e4f059b1ae7cc06a1f45f40bbbf9d08f5d0 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Mon, 14 Oct 2019 09:16:01 +0200 Subject: Add a warning when we use in cdef() a global variable without also specifying a storage class (extern or static) --- cffi/cparser.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cffi/cparser.py') 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): -- cgit v1.2.1