On Sep 23, 2008, at 9:20 AM, Lisandro Dalcin wrote:
> Latests Robert's commit optimizing 'isinstance' call breaked the call
> to cdef methods. The one line patch below seems to fix the problem,
> but anyway this need to be reviewed more carefully. Perhaps an
> unimportant gotcha: the generated code for, let say
> 'insinstance(None, list)' has two superfluous casts:
>
> /* "/tmp/qq.pyx":1
> * isinstance(None, list) # <<<<<<<<<<<<<<
> */
> __pyx_1 = PyObject_TypeCheck(Py_None, ((PyTypeObject
> *)((PyObject*)&PyList_Type)));
Yep, I was looking at this last night. There's not a clean way to
"undo" the first cast, so I've just left it in as it doesn't hurt.
> diff -r 30b7a6c2c7c1 Cython/Compiler/Optimize.py
> --- a/Cython/Compiler/Optimize.py Mon Sep 22 23:45:08 2008 -0700
> +++ b/Cython/Compiler/Optimize.py Tue Sep 23 13:09:36 2008 -0300
> @@ -163,7 +163,7 @@ class FinalOptimizePhase(Visitor.CythonT
> def visit_SimpleCallNode(self, node):
> self.visitchildren(node)
> if node.function.type.is_cfunction:
> - if node.function.name == 'isinstance':
> + if getattr(node.function, 'name', None) == 'isinstance':
> type_arg = node.args[1]
> if type_arg.type.is_builtin_type and
> type_arg.type.name == 'type':
> object_module = self.context.find_module
> ('python_object')
Ah, I see what the issue was. I've committed a fix. All tests pass now.
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev