From: Stefan Behnel Date: Fri, 18 Sep 2009 06:16:51 +0000 (+0200) Subject: rolled back accidentally committed files X-Git-Tag: 0.12.alpha0~192 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5c5f07173c980b5c4b8637f320eaf8e07f9b04bc;p=cython.git rolled back accidentally committed files --- diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index 923cfc4a..53ce01b1 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -21,7 +21,7 @@ builtin_function_table = [ #('eval', "", "", ""), #('execfile', "", "", ""), #('filter', "", "", ""), - #('getattr', "OO", "O", "PyObject_GetAttr"), # optimised later on + #('getattr', "OO", "O", "PyObject_GetAttr"), # optimised later on ('getattr3', "OOO", "O", "__Pyx_GetAttr3", "getattr"), ('hasattr', "OO", "b", "PyObject_HasAttr"), ('hash', "O", "l", "PyObject_Hash"), @@ -29,7 +29,7 @@ builtin_function_table = [ #('id', "", "", ""), #('input', "", "", ""), ('intern', "s", "O", "__Pyx_InternFromString"), - #('isinstance', "OO", "b", "PyObject_IsInstance"), # optimised later on + ('isinstance', "OO", "b", "PyObject_IsInstance"), ('issubclass', "OO", "b", "PyObject_IsSubclass"), ('iter', "O", "O", "PyObject_GetIter"), ('len', "O", "Z", "PyObject_Length"), diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index fe0a7329..425c7f6e 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -712,41 +712,6 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform): "expected 2 or 3, found %d" % len(args)) return node - PyObject_TypeCheck_func_type = PyrexTypes.CFuncType( - PyrexTypes.c_bint_type, [ - PyrexTypes.CFuncTypeArg("obj", PyrexTypes.py_object_type, None), - PyrexTypes.CFuncTypeArg("type", PyrexTypes.c_py_type_object_ptr_type, None), - ]) - - PyObject_IsInstance_func_type = PyrexTypes.CFuncType( - PyrexTypes.c_bint_type, [ - PyrexTypes.CFuncTypeArg("obj", PyrexTypes.py_object_type, None), - PyrexTypes.CFuncTypeArg("type", PyrexTypes.py_object_type, None), - ]) - - def _handle_simple_function_isinstance(self, node, pos_args): - """Replace generic calls to isinstance(x, type) by a more - efficient type check. - """ - args = pos_args.args - if len(args) != 2: - error(node.pos, "isinstance(x, type) called with wrong number of args, found %d" % - len(args)) - return node - - type_arg = args[1] - if type_arg.type is Builtin.type_type: - function_name = "PyObject_TypeCheck" - function_type = self.PyObject_TypeCheck_func_type - args[1] = ExprNodes.CastNode(type_arg, PyrexTypes.c_py_type_object_ptr_type) - else: - function_name = "PyObject_IsInstance" - function_type = self.PyObject_IsInstance_func_type - - return ExprNodes.PythonCapiCallNode( - node.pos, function_name, function_type, - args = args, is_temp = node.is_temp) - Pyx_Type_func_type = PyrexTypes.CFuncType( Builtin.type_type, [ PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None) @@ -1093,8 +1058,8 @@ class FinalOptimizePhase(Visitor.CythonTransform): just before the C code generation phase. The optimizations currently implemented in this class are: - - Eliminate None assignment and refcounting for first assignment. - - Eliminate dead coercion nodes. + - Eliminate None assignment and refcounting for first assignment. + - isinstance -> typecheck for cdef types """ def visit_SingleAssignmentNode(self, node): """Avoid redundant initialisation of local variables before their @@ -1110,23 +1075,18 @@ class FinalOptimizePhase(Visitor.CythonTransform): lhs.entry.init = 0 return node - def visit_NoneCheckNode(self, node): - """Remove NoneCheckNode nodes wrapping nodes that cannot - possibly be None. - - FIXME: the list below might be better maintained as a node - class attribute... + def visit_SimpleCallNode(self, node): + """Replace generic calls to isinstance(x, type) by a more efficient + type check. """ - target = node.arg - if isinstance(target, ExprNodes.NoneNode): - return node - if not target.type.is_pyobject: - return target - if isinstance(target, (ExprNodes.ConstNode, - ExprNodes.NumBinopNode)): - return target - if isinstance(target, (ExprNodes.SequenceNode, - ExprNodes.ComprehensionNode, - ExprNodes.SetNode, ExprNodes.DictNode)): - return target + self.visitchildren(node) + if node.function.type.is_cfunction and isinstance(node.function, ExprNodes.NameNode): + if node.function.name == 'isinstance': + type_arg = node.args[1] + if type_arg.type.is_builtin_type and type_arg.type.name == 'type': + from CythonScope import utility_scope + node.function.entry = utility_scope.lookup('PyObject_TypeCheck') + node.function.type = node.function.entry.type + PyTypeObjectPtr = PyrexTypes.CPtrType(utility_scope.lookup('PyTypeObject').type) + node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr) return node diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 46f21ab6..17d886c5 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1691,9 +1691,6 @@ c_anon_enum_type = CAnonEnumType(-1, 1) c_py_buffer_type = CStructOrUnionType("Py_buffer", "struct", None, 1, "Py_buffer") c_py_buffer_ptr_type = CPtrType(c_py_buffer_type) -c_py_type_object_type = CStructOrUnionType("PyTypeObject", "struct", None, 1, "PyTypeObject") -c_py_type_object_ptr_type = CPtrType(c_py_type_object_type) - error_type = ErrorType() unspecified_type = UnspecifiedType() diff --git a/tests/bugs.txt b/tests/bugs.txt index 9de9fdf2..3c6ad215 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -8,7 +8,6 @@ unsignedbehaviour_T184 funcexc_iter_T228 bad_c_struct_T252 missing_baseclass_in_predecl_T262 -compile_time_unraisable_T370 # Not yet enabled profile_test