Fix a bug in Python/ast.c, where a particular syntaxerror in an 'if' with one or more 'elif's would be ignored or mishandled: timberwolf:~/python/python/trunk > cat test2.py def bug(): if w: dir()=1 elif v: pass timberwolf:~/python/python/trunk > python2.4 test2.py File "test2.py", line 3 dir()=1 SyntaxError: can't assign to function call timberwolf:~/python/python/trunk > python2.5 test2.py Exception exceptions.SyntaxError: ("can't assign to function call", 3) in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection Aborted The actual problem is the lack of error checks on the return values of ast_for_expr() and ast_for_suite, in ast_for_if_stmt. Attached patch fixes.
The patch looks fine to me, please apply (or let me know if you want me to apply it). I think there are a few other places where return values of ast_for_ aren't checked: - ast_for_listcomp, not checking ast_for_expr results - ast_for_withexpr, not checking context_expr
Updated to apply against SVN HEAD and incorporated the additional error checking Martin pointed out. Checked in as r54404 (trunk), r54405 (release25-maint). Any objection to cleaning up ast.c's indentation? It's an ungodly mess.
It would be great to clean up the indentation in ast.c. I think I fixed it (at least made it consistent) in compile.c. Probably symtable.c could use it too. All the files that were new from the AST branch should be cleaned up and use the proper formatting we are using for 3k. I don't remember exactly what it is, but I think it's 4 space indents, but possibly still using tabs.
I don't object to reformatting, if it's a single commit. It would be good if you could add Emacs magic at the end so the file keeps its formatting when edited with Emacs.