Commit fe4c5c0c authored by Stefan Behnel's avatar Stefan Behnel

try a potentially safer way to find out if we know the tp_new slot function of a type

parent 84c076b2
from Cython.Compiler import TypeSlots
from Cython.Compiler.ExprNodes import not_a_constant
import cython
cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object,
......@@ -2182,6 +2183,9 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
if type_arg.type_entry:
ext_type = type_arg.type_entry.type
if ext_type.is_extension_type and not ext_type.is_external:
tp_slot = TypeSlots.ConstructorSlot("tp_new", '__new__')
slot_func_cname = TypeSlots.get_slot_function(ext_type.scope, tp_slot)
if slot_func_cname:
cython_scope = self.context.cython_scope
PyTypeObjectPtr = PyrexTypes.CPtrType(
cython_scope.lookup('PyTypeObject').type)
......@@ -2193,7 +2197,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
])
type_arg = ExprNodes.CastNode(type_arg, PyTypeObjectPtr)
slot_func_cname = ext_type.scope.mangle_internal("tp_new")
if not kwargs:
kwargs = ExprNodes.NullNode(node.pos, type=PyrexTypes.py_object_type) # hack?
return ExprNodes.PythonCapiCallNode(
......
......@@ -493,11 +493,13 @@ def get_special_method_signature(name):
else:
return None
def get_property_accessor_signature(name):
# Return signature of accessor for an extension type
# property, else None.
return property_accessor_signatures.get(name)
def get_base_slot_function(scope, slot):
# Returns the function implementing this slot in the baseclass.
# This is useful for enabling the compiler to optimize calls
......@@ -511,6 +513,18 @@ def get_base_slot_function(scope, slot):
return parent_slot
return None
def get_slot_function(scope, slot):
# Returns the function implementing this slot in the baseclass.
# This is useful for enabling the compiler to optimize calls
# that recursively climb the class hierarchy.
slot_code = slot.slot_code(scope)
if slot_code != '0':
entry = scope.parent_scope.lookup_here(scope.parent_type.name)
if entry.visibility != 'extern':
return slot_code
return None
#------------------------------------------------------------------------------------------
#
# Signatures for generic Python functions and methods.
......
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