Commit 5b19736e authored by Stefan Behnel's avatar Stefan Behnel

simplify code for directly calling module internal tp_new() slot function

parent 9fd5c96d
...@@ -2153,21 +2153,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -2153,21 +2153,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
PyrexTypes.CFuncTypeArg("kwargs", Builtin.dict_type, None), PyrexTypes.CFuncTypeArg("kwargs", Builtin.dict_type, None),
]) ])
Pyx_call_tp_new_func_type = PyrexTypes.CFuncType(
PyrexTypes.py_object_type, [
PyrexTypes.CFuncTypeArg("tpnew_func", PyrexTypes.c_void_ptr_type, None),
PyrexTypes.CFuncTypeArg("type", PyrexTypes.py_object_type, None),
PyrexTypes.CFuncTypeArg("args", Builtin.tuple_type, None),
])
Pyx_call_tp_new_kwargs_func_type = PyrexTypes.CFuncType(
PyrexTypes.py_object_type, [
PyrexTypes.CFuncTypeArg("tpnew_func", PyrexTypes.c_void_ptr_type, None),
PyrexTypes.CFuncTypeArg("type", PyrexTypes.py_object_type, None),
PyrexTypes.CFuncTypeArg("args", Builtin.tuple_type, None),
PyrexTypes.CFuncTypeArg("kwargs", Builtin.dict_type, None),
])
def _handle_any_slot__new__(self, node, args, is_unbound_method, kwargs=None): def _handle_any_slot__new__(self, node, args, is_unbound_method, kwargs=None):
"""Replace 'exttype.__new__(exttype, ...)' by a call to exttype->tp_new() """Replace 'exttype.__new__(exttype, ...)' by a call to exttype->tp_new()
""" """
...@@ -2197,29 +2182,25 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -2197,29 +2182,25 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
if type_arg.type_entry: if type_arg.type_entry:
ext_type = type_arg.type_entry.type ext_type = type_arg.type_entry.type
if ext_type.is_extension_type and not ext_type.is_external: if ext_type.is_extension_type and not ext_type.is_external:
utility_code = UtilityCode.load_cached( cython_scope = self.context.cython_scope
'call_tp_new', 'ObjectHandling.c') PyTypeObjectPtr = PyrexTypes.CPtrType(
slot_func_cname = ext_type.scope.mangle_internal("tp_new") cython_scope.lookup('PyTypeObject').type)
slot_func = ExprNodes.RawCNameExprNode( pyx_tp_new_kwargs_func_type = PyrexTypes.CFuncType(
node.pos, cname=slot_func_cname, PyrexTypes.py_object_type, [
type=PyrexTypes.c_void_ptr_type) PyrexTypes.CFuncTypeArg("type", PyTypeObjectPtr, None),
PyrexTypes.CFuncTypeArg("args", PyrexTypes.py_object_type, None),
PyrexTypes.CFuncTypeArg("kwargs", PyrexTypes.py_object_type, None),
])
if kwargs: type_arg = ExprNodes.CastNode(type_arg, PyTypeObjectPtr)
return ExprNodes.PythonCapiCallNode( slot_func_cname = ext_type.scope.mangle_internal("tp_new")
node.pos, "__Pyx_call_tp_new_kwargs", if not kwargs:
self.Pyx_call_tp_new_kwargs_func_type, kwargs = ExprNodes.NullNode(node.pos, type=PyrexTypes.py_object_type) # hack?
args=[slot_func, type_arg, args_tuple, kwargs], return ExprNodes.PythonCapiCallNode(
utility_code=utility_code, node.pos, slot_func_cname,
is_temp=node.is_temp pyx_tp_new_kwargs_func_type,
) args=[type_arg, args_tuple, kwargs],
else: is_temp=True)
return ExprNodes.PythonCapiCallNode(
node.pos, "__Pyx_call_tp_new",
self.Pyx_call_tp_new_func_type,
args=[slot_func, type_arg, args_tuple],
utility_code=utility_code,
is_temp=node.is_temp
)
else: else:
# arbitrary variable, needs a None check for safety # arbitrary variable, needs a None check for safety
type_arg = type_arg.as_none_safe_node( type_arg = type_arg.as_none_safe_node(
......
...@@ -658,9 +658,3 @@ bad: ...@@ -658,9 +658,3 @@ bad:
static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) { static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs)); return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs));
} }
/////////////// call_tp_new.proto ///////////////
#define __Pyx_call_tp_new(tp_new_func, type_obj, args) __Pyx_call_tp_new_kwargs(tp_new_func, type_obj, args, NULL)
#define __Pyx_call_tp_new_kwargs(tp_new_func, type_obj, args, kwargs) tp_new_func((PyTypeObject*)type_obj, args, kwargs)
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