summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-29 13:24:23 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-29 13:24:23 (GMT)
commitf2bfd54d6f2acde253ae24805edf116c372bd81e (patch)
tree30964d80bd483e0c2a18b7e80638883cc52ad565 /Parser
parentea13dc629caed2dd44b1ba5b611e1ba2ac1fd96f (diff)
downloadcpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.zip
cpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.tar.gz
cpython-f2bfd54d6f2acde253ae24805edf116c372bd81e.tar.bz2
Properly check for consistency with the third argument of
compile() when compiling an AST node.
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index fa43078..3a0bb95 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -954,13 +954,20 @@ PyObject* PyAST_mod2obj(mod_ty t)
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)
@@ -1016,7 +1023,7 @@ def main(srcfile):
)
c.visit(mod)
print >>f, "PyObject* PyAST_mod2obj(mod_ty t);"
- print >>f, "mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena);"
+ print >>f, "mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);"
print >>f, "int PyAST_Check(PyObject* obj);"
f.close()