From 383b92844784298d6f83de8a2256dd6f37a3f0ca Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 13 Nov 2010 14:29:34 -0800 Subject: [PATCH] Create directive for fast __getattr__. Until the dust settles, this is better than manually patching Sage's Cython. --- Cython/Compiler/Code.py | 6 ++++-- Cython/Compiler/Nodes.py | 2 +- Cython/Compiler/Options.py | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index fde29429..a3225f0e 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1238,11 +1238,13 @@ class CCodeWriter(object): def put_pymethoddef(self, entry, term, allow_skip=True): if entry.is_special or entry.name == '__getattribute__': - if entry.name not in ['__cinit__', '__dealloc__', '__richcmp__', '__next__', '__getreadbuffer__', '__getwritebuffer__', '__getsegcount__', '__getcharbuffer__', '__getbuffer__', '__releasebuffer__', '__getattr__']: + if entry.name not in ['__cinit__', '__dealloc__', '__richcmp__', '__next__', '__getreadbuffer__', '__getwritebuffer__', '__getsegcount__', '__getcharbuffer__', '__getbuffer__', '__releasebuffer__']: + if entry.name == '__getattr__' and not self.globalstate.directives['fast_getattr']: + pass # Python's typeobject.c will automatically fill in our slot # in add_operators() (called by PyType_Ready) with a value # that's better than ours. - if allow_skip: + elif allow_skip: return from TypeSlots import method_coexist if entry.doc: diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 3cfc336b..878ad29a 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2136,7 +2136,7 @@ class DefNode(FuncDefNode): entry.doc_cname = \ Naming.funcdoc_prefix + prefix + name if entry.is_special: - if entry.name in TypeSlots.invisible or not entry.doc: + if entry.name in TypeSlots.invisible or not entry.doc or (entry.name in '__getattr__' and env.directives['fast_getattr']): entry.wrapperbase_cname = None else: entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index a21fd8df..a1f77717 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -71,6 +71,7 @@ directive_defaults = { 'autotestdict.cdef': False, 'autotestdict.all': False, 'language_level': 2, + 'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere. 'warn': None, 'warn.undeclared': False, -- 2.26.2