Create directive for fast __getattr__.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 13 Nov 2010 22:29:34 +0000 (14:29 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 13 Nov 2010 22:29:34 +0000 (14:29 -0800)
Until the dust settles, this is better than manually patching Sage's Cython.

Cython/Compiler/Code.py
Cython/Compiler/Nodes.py
Cython/Compiler/Options.py

index fde29429fe52b8de536168801f5e1df8029ab6b0..a3225f0e25889e9ed915af88e0d08e7fa3c364f6 100644 (file)
@@ -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:
index 3cfc336b35f17a0174ca61e0e837866c8621cfeb..878ad29ab1fc2d62686b7e414b916cf7f7867d0c 100644 (file)
@@ -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
index a21fd8dfaaefdc1e8e9276a0c38608682d746db1..a1f777173cea2a28e63359c421da71a645016005 100644 (file)
@@ -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,