Commit 25612694 authored by Robert Bradshaw's avatar Robert Bradshaw

Dissallow non-extern redeclarations.

parent f0d5ffd7
3.0a6-cypclass 3.0a5-cypclass_pyobject_virtual 3.0a5-cypclass_virtual 3.0a6-cypclass-remove-logging 3.0a6-cypclass_attribute_lock 3.0a6-cypclass_attribute_lock_nonrecursive_rw 3.0a6-cypclass_consume 3.0a6-cypclass_frozen 3.0a6-cypclass_lock 3.0a6-cypclass_recover_consume cypclass_pyobject cypclass_pyobject_virtual cypclass_virtual master nogil_cypclass_acthon_on_rc8v3 3.0a6 3.0a5 3.0a4 3.0a3 3.0a2 3.0a1 0.29.21 0.29.20 0.29.19 0.29.18 0.29.17 0.29.16 0.29.15 0.29.14 0.29.13 0.29.12 0.29.11 0.29.10 0.29.9 0.29.8 0.29.7 0.29.6 0.29.5 0.29.4 0.29.3 0.29.2 0.29.1 0.29 0.29rc2 0.29rc1 0.29b1 0.28.6 0.28.5 0.28.4 0.28.3 0.28.2 0.28.1 0.28 0.28rc1 0.28b2 0.28b1 0.27.3 0.27.2 0.27.1 0.27.1b1 0.27 0.27rc1 0.27b1 0.27a1 0.26.1 0.26.1rc1 0.26 0.26rc2 0.26rc1 0.26rc0 0.26b2 0.26b1 0.26b0 0.26.alpha0 0.25.2 0.25.2rc0 0.25.2b1 0.25.1 0.25.1b1 0.25.1b0 0.25 0.25b2 0.25b1 0.25b0 0.25a0 0.24.1 0.24 0.24b0 0.24a0 0.23.5 0.23.4 0.23.3 0.23.2 0.23.1 0.23 0.23.beta1 0.23b2 0.22.1 0.22.1rc1 0.22 0.22.beta0 0.22.alpha0 0.21.2 0.21.1 0.21 0.21rc1 0.21b2 0.21b1 0.21a1 0.20.2 0.20.2b1 0.20.1 0.20.1rc1 0.20 0.20rc1 0.20b2 0.20b1 0.19.2 0.19.1 0.19 0.19rc1 0.19b2 0.19b1 0.18 0.18rc1 0.18b1 0.17.4 0.17.3 0.17.2 0.17.1 0.17 0.17.beta1 0.17b4 0.17b3 0.17b2 0.16 0.16rc2 0.16rc1 0.16rc0 0.16.beta0 0.15.1 0.15 0.15rc2 0.15rc1 0.15rc0 0.14.1 0.14.1rc3 0.14.1rc2 0.14.1rc1 0.14.1rc0 0.14 0.14.rc0 0.14.beta2 0.14.beta1 0.14.beta0 0.14.alpha0 0.13 0.13.beta1 0.13.beta0 0.12.1 0.12 0.12.rc0 0.12.alpha0 0.11.3 0.11.3.rc0 0.11.2 0.11.2.rc1 0.11.1 0.11.1.beta 0.11.1.alpha 0.11.rc 0.11-beta 0.10.3 0.10.2 0.10.1 0.10 0.9.9.2.beta 0.9.8.1 snippets_article nogil_cypclass_rc8 nogil_cypclass_lock_on_rc8v3 cythonplus-0.3 cythonplus-0.2 cythonplus-0.1 cypclass_pyobject_before_mro_rebase_12_06_2020
No related merge requests found
......@@ -261,7 +261,7 @@ class Scope:
# Return the module-level scope containing this scope.
return self.outer_scope.builtin_scope()
def declare(self, name, cname, type, pos):
def declare(self, name, cname, type, pos, visibility):
# Create new entry, and add to dictionary if
# name is not None. Reports a warning if already
# declared.
......@@ -270,13 +270,17 @@ class Scope:
warning(pos, "'%s' is a reserved name in C." % cname, -1)
dict = self.entries
if name and dict.has_key(name):
if visibility == 'extern':
warning(pos, "'%s' redeclared " % name, 0)
else:
error(pos, "'%s' redeclared " % name)
entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude
if name:
entry.qualified_name = self.qualify_name(name)
dict[name] = entry
entry.scope = self
entry.visibility = visibility
return entry
def qualify_name(self, name):
......@@ -289,7 +293,7 @@ class Scope:
cname = name
else:
cname = self.mangle(Naming.enum_prefix, name)
entry = self.declare(name, cname, type, pos)
entry = self.declare(name, cname, type, pos, 'private')
entry.is_const = 1
entry.value = value
return entry
......@@ -299,8 +303,7 @@ class Scope:
# Add an entry for a type definition.
if not cname:
cname = name
entry = self.declare(name, cname, type, pos)
entry.visibility = visibility
entry = self.declare(name, cname, type, pos, visibility)
entry.is_type = 1
if defining:
self.type_entries.append(entry)
......@@ -384,9 +387,8 @@ class Scope:
cname = name
else:
cname = self.mangle(Naming.var_prefix, name)
entry = self.declare(name, cname, type, pos)
entry = self.declare(name, cname, type, pos, visibility)
entry.is_variable = 1
entry.visibility = visibility
self.control_flow.set_state((), (name, 'initalized'), False)
return entry
......@@ -415,8 +417,11 @@ class Scope:
if visibility != 'private' and visibility != entry.visibility:
warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
if not entry.type.same_as(type):
if visibility == 'extern' and entry.visibility == 'extern':
warning(pos, "Function signature does not match previous declaration", 1)
entry.type = type
else:
error(pos, "Function signature does not match previous declaration")
else:
if not cname:
if api or visibility != 'private':
......@@ -435,9 +440,8 @@ class Scope:
def add_cfunction(self, name, type, pos, cname, visibility):
# Add a C function entry without giving it a func_cname.
entry = self.declare(name, cname, type, pos)
entry = self.declare(name, cname, type, pos, visibility)
entry.is_cfunction = 1
entry.visibility = visibility
self.cfunc_entries.append(entry)
return entry
......@@ -648,7 +652,7 @@ class PreImportScope(Scope):
Scope.__init__(self, Options.pre_import, None, None)
def declare_builtin(self, name, pos):
entry = self.declare(name, name, py_object_type, pos)
entry = self.declare(name, name, py_object_type, pos, 'private')
entry.is_variable = True
entry.is_pyglobal = True
return entry
......@@ -819,7 +823,7 @@ class ModuleScope(Scope):
for entry in self.cached_builtins:
if entry.name == name:
return entry
entry = self.declare(None, None, py_object_type, pos)
entry = self.declare(None, None, py_object_type, pos, 'private')
if Options.cache_builtins:
entry.is_builtin = 1
entry.is_const = 1
......@@ -1135,7 +1139,7 @@ class LocalScope(Scope):
def declare_arg(self, name, type, pos):
# Add an entry for an argument of a function.
cname = self.mangle(Naming.var_prefix, name)
entry = self.declare(name, cname, type, pos)
entry = self.declare(name, cname, type, pos, 'private')
entry.is_variable = 1
if type.is_pyobject:
entry.init = "0"
......@@ -1208,7 +1212,7 @@ class StructOrUnionScope(Scope):
cname = name
if type.is_cfunction:
type = PyrexTypes.CPtrType(type)
entry = self.declare(name, cname, type, pos)
entry = self.declare(name, cname, type, pos, visibility)
entry.is_variable = 1
self.var_entries.append(entry)
if type.is_pyobject and not allow_pyobject:
......@@ -1340,8 +1344,7 @@ class CClassScope(ClassScope):
% name)
if not cname:
cname = name
entry = self.declare(name, cname, type, pos)
entry.visibility = visibility
entry = self.declare(name, cname, type, pos, visibility)
entry.is_variable = 1
self.var_entries.append(entry)
if type.is_pyobject:
......@@ -1382,7 +1385,7 @@ class CClassScope(ClassScope):
warning(pos, "__new__ method of extension type will change semantics "
"in a future version of Pyrex and Cython. Use __cinit__ instead.")
name = Utils.EncodedString("__cinit__")
entry = self.declare_var(name, py_object_type, pos)
entry = self.declare_var(name, py_object_type, pos, visibility='extern')
special_sig = get_special_method_signature(name)
if special_sig:
# Special methods get put in the method table with a particular
......@@ -1459,7 +1462,7 @@ class CClassScope(ClassScope):
def declare_property(self, name, doc, pos):
entry = self.lookup_here(name)
if entry is None:
entry = self.declare(name, name, py_object_type, pos)
entry = self.declare(name, name, py_object_type, pos, 'private')
entry.is_property = 1
entry.doc = doc
entry.scope = PropertyScope(name,
......@@ -1477,7 +1480,7 @@ class CClassScope(ClassScope):
for base_entry in \
base_scope.inherited_var_entries + base_scope.var_entries:
entry = self.declare(base_entry.name, adapt(base_entry.cname),
base_entry.type, None)
base_entry.type, None, 'private')
entry.is_variable = 1
self.inherited_var_entries.append(entry)
for base_entry in base_scope.cfunc_entries:
......@@ -1502,7 +1505,7 @@ class PropertyScope(Scope):
# Add an entry for a method.
signature = get_property_accessor_signature(name)
if signature:
entry = self.declare(name, name, py_object_type, pos)
entry = self.declare(name, name, py_object_type, pos, 'private')
entry.is_special = 1
entry.signature = signature
return entry
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment