Commit 383b9284 authored by Robert Bradshaw's avatar Robert Bradshaw

Create directive for fast __getattr__.

Until the dust settles, this is better than manually patching Sage's Cython.
parent d591804e
...@@ -1238,11 +1238,13 @@ class CCodeWriter(object): ...@@ -1238,11 +1238,13 @@ class CCodeWriter(object):
def put_pymethoddef(self, entry, term, allow_skip=True): def put_pymethoddef(self, entry, term, allow_skip=True):
if entry.is_special or entry.name == '__getattribute__': 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 # Python's typeobject.c will automatically fill in our slot
# in add_operators() (called by PyType_Ready) with a value # in add_operators() (called by PyType_Ready) with a value
# that's better than ours. # that's better than ours.
if allow_skip: elif allow_skip:
return return
from TypeSlots import method_coexist from TypeSlots import method_coexist
if entry.doc: if entry.doc:
......
...@@ -2136,7 +2136,7 @@ class DefNode(FuncDefNode): ...@@ -2136,7 +2136,7 @@ class DefNode(FuncDefNode):
entry.doc_cname = \ entry.doc_cname = \
Naming.funcdoc_prefix + prefix + name Naming.funcdoc_prefix + prefix + name
if entry.is_special: 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 entry.wrapperbase_cname = None
else: else:
entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name
......
...@@ -71,6 +71,7 @@ directive_defaults = { ...@@ -71,6 +71,7 @@ directive_defaults = {
'autotestdict.cdef': False, 'autotestdict.cdef': False,
'autotestdict.all': False, 'autotestdict.all': False,
'language_level': 2, 'language_level': 2,
'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
'warn': None, 'warn': None,
'warn.undeclared': False, 'warn.undeclared': False,
......
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