diff Python/Python-ast.c @ 46193:b0bf06d49647 legacy-trunk

Properly check for consistency with the third argument of compile() when compiling an AST node.
author Georg Brandl <georg@python.org>
date Sat, 29 Mar 2008 13:24:23 +0000
parents 1b5b6abb1f2e
children 2ff88ae9850c
line wrap: on
line diff
--- a/Python/Python-ast.c	Sat Mar 29 13:14:52 2008 +0000
+++ b/Python/Python-ast.c	Sat Mar 29 13:24:23 2008 +0000
@@ -5944,13 +5944,20 @@
     return ast2obj_mod(t);
 }
 
-mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena)
+/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
+mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
 {
     mod_ty res;
+    PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
+                            (PyObject*)Interactive_type};
+    char *req_name[] = {"Module", "Expression", "Interactive"};
+    assert(0 <= mode && mode <= 2);
+
     init_types();
-    if (!PyObject_IsInstance(ast, (PyObject*)mod_type)) {
-        PyErr_SetString(PyExc_TypeError, "expected either Module, Interactive "
-                        "or Expression node");
+
+    if (!PyObject_IsInstance(ast, req_type[mode])) {
+        PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
+                     req_name[mode], Py_TYPE(ast)->tp_name);
         return NULL;
     }
     if (obj2ast_mod(ast, &res, arena) != 0)