diff --git a/CHANGES b/CHANGES index 27268df662..7496960602 100644 --- a/CHANGES +++ b/CHANGES @@ -80,6 +80,9 @@ Features added Bugs fixed ---------- +* C, don't deepcopy the entire symbol table and make a mess every time an + enumerator is handled. + Testing -------- diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 0e7d88e042..6c117a558c 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -1336,6 +1336,10 @@ class ASTDeclaration(ASTBaseBase): # set by CObject._add_enumerator_to_parent self.enumeratorScopedSymbol = None # type: Symbol + def clone(self) -> "ASTDeclaration": + return ASTDeclaration(self.objectType, self.directiveType, + self.declaration.clone(), self.semicolon) + @property def name(self) -> ASTNestedName: return self.declaration.name @@ -1425,6 +1429,16 @@ class Symbol: debug_lookup = False debug_show_tree = False + def __copy__(self): + assert False # shouldn't happen + + def __deepcopy__(self, memo): + if self.parent: + assert False # shouldn't happen + else: + # the domain base class makes a copy of the initial data, which is fine + return Symbol(None, None, None, None) + @staticmethod def debug_print(*args: Any) -> None: print(Symbol.debug_indent_string * Symbol.debug_indent, end="") diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index c840423aad..38c84898be 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -3782,6 +3782,16 @@ class Symbol: debug_lookup = False # overridden by the corresponding config value debug_show_tree = False # overridden by the corresponding config value + def __copy__(self): + assert False # shouldn't happen + + def __deepcopy__(self, memo): + if self.parent: + assert False # shouldn't happen + else: + # the domain base class makes a copy of the initial data, which is fine + return Symbol(None, None, None, None, None, None) + @staticmethod def debug_print(*args: Any) -> None: print(Symbol.debug_indent_string * Symbol.debug_indent, end="") diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py index 6c2e99c842..a67b2a0add 100644 --- a/sphinx/util/cfamily.py +++ b/sphinx/util/cfamily.py @@ -110,7 +110,6 @@ class ASTBaseBase: __hash__ = None # type: Callable[[], int] def clone(self) -> Any: - """Clone a definition expression node.""" return deepcopy(self) def _stringify(self, transform: StringifyTransform) -> str: