From fdeceae09c9611b47d4b7b031b6b602c38913e88 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 28 Jun 2009 19:19:51 +0000 Subject: Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73376 | benjamin.peterson | 2009-06-11 17:29:23 -0500 (Thu, 11 Jun 2009) | 1 line remove check for case handled in sub-function ........ r73393 | alexandre.vassalotti | 2009-06-12 13:56:57 -0500 (Fri, 12 Jun 2009) | 2 lines Clear reference to the static PyExc_RecursionErrorInst in _PyExc_Fini. ........ r73398 | alexandre.vassalotti | 2009-06-12 15:57:12 -0500 (Fri, 12 Jun 2009) | 3 lines Add const qualifier to PyErr_SetFromErrnoWithFilename and to PyErr_SetFromErrnoWithUnicodeFilename. ........ r73400 | alexandre.vassalotti | 2009-06-12 16:43:47 -0500 (Fri, 12 Jun 2009) | 2 lines Delete outdated make file for building the parser with MSVC 6. ........ r73404 | benjamin.peterson | 2009-06-12 20:40:00 -0500 (Fri, 12 Jun 2009) | 1 line keep the slice.step field as NULL if no step expression is given ........ r73405 | benjamin.peterson | 2009-06-12 22:46:30 -0500 (Fri, 12 Jun 2009) | 1 line prevent import statements from assigning to None ........ r73409 | benjamin.peterson | 2009-06-13 08:06:21 -0500 (Sat, 13 Jun 2009) | 1 line allow importing from a module named None if it has an 'as' clause ........ r73419 | benjamin.peterson | 2009-06-13 11:19:19 -0500 (Sat, 13 Jun 2009) | 1 line set Print.values to NULL if there are no values ........ r73420 | benjamin.peterson | 2009-06-13 12:08:53 -0500 (Sat, 13 Jun 2009) | 1 line give a better error message when deleting () ........ r73421 | benjamin.peterson | 2009-06-13 15:23:33 -0500 (Sat, 13 Jun 2009) | 1 line when no module is given in a 'from' relative import, make ImportFrom.module NULL ........ r73432 | amaury.forgeotdarc | 2009-06-14 16:20:40 -0500 (Sun, 14 Jun 2009) | 3 lines #6227: Because of a wrong indentation, the test was not testing what it should. Ensure that the snippet in doctest_aliases actually contains aliases. ........ r73457 | benjamin.peterson | 2009-06-16 18:13:09 -0500 (Tue, 16 Jun 2009) | 1 line add underscores ........ r73460 | benjamin.peterson | 2009-06-16 22:23:04 -0500 (Tue, 16 Jun 2009) | 1 line remove unused 'encoding' member from the compiler struct ........ r73485 | benjamin.peterson | 2009-06-19 17:07:47 -0500 (Fri, 19 Jun 2009) | 1 line remove duplicate test ........ r73486 | benjamin.peterson | 2009-06-19 17:09:17 -0500 (Fri, 19 Jun 2009) | 1 line add missing assertion #6313 ........ r73488 | benjamin.peterson | 2009-06-19 17:16:28 -0500 (Fri, 19 Jun 2009) | 1 line show that this one isn't used ........ r73489 | benjamin.peterson | 2009-06-19 17:21:12 -0500 (Fri, 19 Jun 2009) | 1 line use closures ........ r73501 | benjamin.peterson | 2009-06-21 18:01:07 -0500 (Sun, 21 Jun 2009) | 1 line don't need to add the name 'lambda' as assigned ........ r73502 | benjamin.peterson | 2009-06-21 18:03:36 -0500 (Sun, 21 Jun 2009) | 1 line remove tmpname support since it's no longer used ........ r73513 | benjamin.peterson | 2009-06-22 20:18:57 -0500 (Mon, 22 Jun 2009) | 1 line fix grammar ........ r73514 | benjamin.peterson | 2009-06-22 22:01:56 -0500 (Mon, 22 Jun 2009) | 1 line remove some unused symtable constants ........ --- Python/Python-ast.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 1e85b2fac7..e9bd849495 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1332,11 +1332,6 @@ ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int col_offset, PyArena *arena) { stmt_ty p; - if (!module) { - PyErr_SetString(PyExc_ValueError, - "field module is required for ImportFrom"); - return NULL; - } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; @@ -4465,8 +4460,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"module\" missing from ImportFrom"); - return 1; + module = NULL; } if (PyObject_HasAttrString(obj, "names")) { int res; -- cgit v1.2.1 From 1316f79d980701193356be7a5978f02c402b5b51 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 17 Jul 2009 19:11:02 +0000 Subject: update ast version --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index e9bd849495..e03dac0bb5 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 67616. + __version__ 73626. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6411,7 +6411,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "67616") < 0) + if (PyModule_AddStringConstant(m, "__version__", "73626") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From b9035d45226b0afebfeb658d3dd9cdf5871e586b Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 13 Dec 2009 01:24:58 +0000 Subject: regenerate Python-ast.c --- Python/Python-ast.c | 544 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 455 insertions(+), 89 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index e03dac0bb5..05fa5416de 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3374,13 +3374,18 @@ int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; if (obj == Py_None) { *out = NULL; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Module_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* body; if (PyObject_HasAttrString(obj, "body")) { @@ -3412,7 +3417,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Interactive_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* body; if (PyObject_HasAttrString(obj, "body")) { @@ -3444,7 +3453,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Expression_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty body; if (PyObject_HasAttrString(obj, "body")) { @@ -3463,7 +3476,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Suite_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* body; if (PyObject_HasAttrString(obj, "body")) { @@ -3508,6 +3525,7 @@ int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; int lineno; int col_offset; @@ -3540,7 +3558,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); return 1; } - if (PyObject_IsInstance(obj, (PyObject*)FunctionDef_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { identifier name; arguments_ty args; asdl_seq* body; @@ -3637,7 +3659,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)ClassDef_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { identifier name; asdl_seq* bases; asdl_seq* keywords; @@ -3785,7 +3811,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Return_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; if (PyObject_HasAttrString(obj, "value")) { @@ -3803,7 +3833,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Delete_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* targets; if (PyObject_HasAttrString(obj, "targets")) { @@ -3835,7 +3869,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Assign_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* targets; expr_ty value; @@ -3880,7 +3918,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)AugAssign_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty target; operator_ty op; expr_ty value; @@ -3925,7 +3967,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)For_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty target; expr_ty iter; asdl_seq* body; @@ -4010,7 +4056,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)While_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty test; asdl_seq* body; asdl_seq* orelse; @@ -4081,7 +4131,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)If_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty test; asdl_seq* body; asdl_seq* orelse; @@ -4152,7 +4206,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)With_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty context_expr; expr_ty optional_vars; asdl_seq* body; @@ -4210,7 +4268,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Raise_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty exc; expr_ty cause; @@ -4240,7 +4302,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)TryExcept_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* body; asdl_seq* handlers; asdl_seq* orelse; @@ -4325,7 +4391,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)TryFinally_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* body; asdl_seq* finalbody; @@ -4383,7 +4453,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Assert_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty test; expr_ty msg; @@ -4414,7 +4488,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Import_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* names; if (PyObject_HasAttrString(obj, "names")) { @@ -4446,7 +4524,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)ImportFrom_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { identifier module; asdl_seq* names; int level; @@ -4503,7 +4585,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Global_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* names; if (PyObject_HasAttrString(obj, "names")) { @@ -4535,7 +4621,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Nonlocal_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* names; if (PyObject_HasAttrString(obj, "names")) { @@ -4567,7 +4657,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Expr_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; if (PyObject_HasAttrString(obj, "value")) { @@ -4586,19 +4680,31 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Pass_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Pass(lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Break_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Break(lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Continue_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Continue(lineno, col_offset, arena); if (*out == NULL) goto failed; @@ -4617,6 +4723,7 @@ int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; int lineno; int col_offset; @@ -4649,7 +4756,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); return 1; } - if (PyObject_IsInstance(obj, (PyObject*)BoolOp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { boolop_ty op; asdl_seq* values; @@ -4694,7 +4805,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)BinOp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty left; operator_ty op; expr_ty right; @@ -4739,7 +4854,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)UnaryOp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { unaryop_ty op; expr_ty operand; @@ -4771,7 +4890,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Lambda_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { arguments_ty args; expr_ty body; @@ -4803,7 +4926,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)IfExp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty test; expr_ty body; expr_ty orelse; @@ -4848,7 +4975,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Dict_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* keys; asdl_seq* values; @@ -4906,7 +5037,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Set_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* elts; if (PyObject_HasAttrString(obj, "elts")) { @@ -4938,7 +5073,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)ListComp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty elt; asdl_seq* generators; @@ -4983,7 +5122,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)SetComp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty elt; asdl_seq* generators; @@ -5028,7 +5171,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)DictComp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty key; expr_ty value; asdl_seq* generators; @@ -5087,7 +5234,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty elt; asdl_seq* generators; @@ -5132,7 +5283,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Yield_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; if (PyObject_HasAttrString(obj, "value")) { @@ -5150,7 +5305,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Compare_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty left; asdl_int_seq* ops; asdl_seq* comparators; @@ -5222,7 +5381,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Call_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty func; asdl_seq* args; asdl_seq* keywords; @@ -5318,7 +5481,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Num_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { object n; if (PyObject_HasAttrString(obj, "n")) { @@ -5337,7 +5504,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Str_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { string s; if (PyObject_HasAttrString(obj, "s")) { @@ -5356,7 +5527,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Bytes_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { string s; if (PyObject_HasAttrString(obj, "s")) { @@ -5375,13 +5550,21 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Ellipsis_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Ellipsis(lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Attribute_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; identifier attr; expr_context_ty ctx; @@ -5426,7 +5609,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Subscript_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; slice_ty slice; expr_context_ty ctx; @@ -5471,7 +5658,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Starred_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; expr_context_ty ctx; @@ -5503,7 +5694,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Name_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { identifier id; expr_context_ty ctx; @@ -5535,7 +5730,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)List_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* elts; expr_context_ty ctx; @@ -5580,7 +5779,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Tuple_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* elts; expr_context_ty ctx; @@ -5638,28 +5841,53 @@ int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; - if (PyObject_IsInstance(obj, (PyObject*)Load_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Load; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Store_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Store; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Del_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Del; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)AugLoad_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = AugLoad; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)AugStore_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = AugStore; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Param_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Param; return 0; } @@ -5676,13 +5904,18 @@ int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; if (obj == Py_None) { *out = NULL; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Slice_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty lower; expr_ty upper; expr_ty step; @@ -5724,7 +5957,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)ExtSlice_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { asdl_seq* dims; if (PyObject_HasAttrString(obj, "dims")) { @@ -5756,7 +5993,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Index_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty value; if (PyObject_HasAttrString(obj, "value")) { @@ -5788,12 +6029,21 @@ int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; - if (PyObject_IsInstance(obj, (PyObject*)And_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = And; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Or_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Or; return 0; } @@ -5810,52 +6060,101 @@ int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; - if (PyObject_IsInstance(obj, (PyObject*)Add_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Add; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Sub_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Sub; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Mult_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Mult; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Div_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Div; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Mod_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Mod; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Pow_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Pow; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)LShift_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = LShift; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)RShift_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = RShift; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)BitOr_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = BitOr; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)BitXor_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = BitXor; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)BitAnd_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = BitAnd; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)FloorDiv_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = FloorDiv; return 0; } @@ -5872,20 +6171,37 @@ int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; - if (PyObject_IsInstance(obj, (PyObject*)Invert_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Invert; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Not_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Not; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)UAdd_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = UAdd; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)USub_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = USub; return 0; } @@ -5902,44 +6218,85 @@ int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; - if (PyObject_IsInstance(obj, (PyObject*)Eq_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Eq; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)NotEq_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = NotEq; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Lt_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Lt; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)LtE_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = LtE; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Gt_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Gt; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)GtE_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = GtE; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)Is_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = Is; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)IsNot_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = IsNot; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)In_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = In; return 0; } - if (PyObject_IsInstance(obj, (PyObject*)NotIn_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { *out = NotIn; return 0; } @@ -6020,6 +6377,7 @@ int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) { PyObject* tmp = NULL; + int isinstance; int lineno; int col_offset; @@ -6052,7 +6410,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); return 1; } - if (PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type)) { + isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { expr_ty type; identifier name; asdl_seq* body; @@ -6629,11 +6991,15 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, (PyObject*)Interactive_type}; char *req_name[] = {"Module", "Expression", "Interactive"}; + int isinstance; assert(0 <= mode && mode <= 2); init_types(); - if (!PyObject_IsInstance(ast, req_type[mode])) { + isinstance = PyObject_IsInstance(ast, req_type[mode]); + if (isinstance == -1) + return NULL; + if (!isinstance) { PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", req_name[mode], Py_TYPE(ast)->tp_name); return NULL; -- cgit v1.2.1 From 046dd2b5f082e1f3975d7cea07826db45c72c259 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Jun 2010 19:57:46 +0000 Subject: Issue #8848: U / U# formats of Py_BuildValue() are just alias to s / s# --- Python/Python-ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 05fa5416de..bedd7d7de7 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -527,7 +527,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int } PyTuple_SET_ITEM(fnames, i, field); } - result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", + result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", type, base, "_fields", fnames, "__module__", "_ast"); Py_DECREF(fnames); return (PyTypeObject*)result; -- cgit v1.2.1 From dfca49ec2ca05151f8f1bf09be0f126f8338e526 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Wed, 23 Jun 2010 21:40:15 +0000 Subject: Issue #9051: Instances of timezone class can now be pickled. --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index bedd7d7de7..54c4e0160d 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 73626. + __version__ 82163. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6773,7 +6773,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "73626") < 0) + if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From 61922f057eff2bf4e6d5e3b56645fa85b28f0fc5 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 27 Jun 2010 21:45:24 +0000 Subject: Merged revisions 81465-81466,81468,81679,81735,81760,81868,82183 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81465 | georg.brandl | 2010-05-22 06:29:19 -0500 (Sat, 22 May 2010) | 2 lines Issue #3924: Ignore cookies with invalid "version" field in cookielib. ........ r81466 | georg.brandl | 2010-05-22 06:31:16 -0500 (Sat, 22 May 2010) | 1 line Underscore the name of an internal utility function. ........ r81468 | georg.brandl | 2010-05-22 06:43:25 -0500 (Sat, 22 May 2010) | 1 line #8635: document enumerate() start parameter in docstring. ........ r81679 | benjamin.peterson | 2010-06-03 16:21:03 -0500 (Thu, 03 Jun 2010) | 1 line use a set for membership testing ........ r81735 | michael.foord | 2010-06-05 06:46:59 -0500 (Sat, 05 Jun 2010) | 1 line Extract error message truncating into a method (unittest.TestCase._truncateMessage). ........ r81760 | michael.foord | 2010-06-05 14:38:42 -0500 (Sat, 05 Jun 2010) | 1 line Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as a skip rather than an error. ........ r81868 | benjamin.peterson | 2010-06-09 14:45:04 -0500 (Wed, 09 Jun 2010) | 1 line fix code formatting ........ r82183 | benjamin.peterson | 2010-06-23 15:29:26 -0500 (Wed, 23 Jun 2010) | 1 line cpython only gc tests ........ --- Python/Python-ast.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 54c4e0160d..c37dda7f00 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -537,8 +537,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) { int i, result; PyObject *s, *l = PyTuple_New(num_fields); - if (!l) return 0; - for(i = 0; i < num_fields; i++) { + if (!l) + return 0; + for (i = 0; i < num_fields; i++) { s = PyUnicode_FromString(attrs[i]); if (!s) { Py_DECREF(l); -- cgit v1.2.1 From 0cfbd11a323bad965dd270499e13b7fa63178a64 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 20 Nov 2010 01:38:49 +0000 Subject: use %R format code; fixes invalid dereferencing #10391 --- Python/Python-ast.c | 75 ++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index c37dda7f00..7f22f7f5c3 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3375,6 +3375,7 @@ int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; @@ -3514,11 +3515,8 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); + failed: return 1; } @@ -3526,6 +3524,7 @@ int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; int lineno; @@ -4712,11 +4711,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); + failed: return 1; } @@ -4724,6 +4720,7 @@ int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; int lineno; @@ -5830,11 +5827,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); + failed: return 1; } @@ -5842,6 +5836,7 @@ int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); @@ -5893,11 +5888,7 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); return 1; } @@ -5905,6 +5896,7 @@ int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; @@ -6018,11 +6010,8 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); + failed: return 1; } @@ -6030,6 +6019,7 @@ int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); @@ -6049,11 +6039,7 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); return 1; } @@ -6061,6 +6047,7 @@ int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); @@ -6160,11 +6147,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); return 1; } @@ -6172,6 +6155,7 @@ int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); @@ -6207,11 +6191,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); return 1; } @@ -6219,6 +6199,7 @@ int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); @@ -6302,11 +6283,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); return 1; } @@ -6378,6 +6355,7 @@ int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) { PyObject* tmp = NULL; + tmp = tmp; int isinstance; int lineno; @@ -6473,11 +6451,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) return 0; } - tmp = PyObject_Repr(obj); - if (tmp == NULL) goto failed; - PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyBytes_AS_STRING(tmp)); -failed: - Py_XDECREF(tmp); + PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); + failed: return 1; } -- cgit v1.2.1 From f8f95ac0048b606c4e81d9b1f113dcde62e09d8c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 20 Nov 2010 02:01:45 +0000 Subject: c89 declarations --- Python/Python-ast.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 7f22f7f5c3..8de5314e2d 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3375,8 +3375,8 @@ int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; if (obj == Py_None) { @@ -3524,8 +3524,8 @@ int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; int lineno; int col_offset; @@ -4720,8 +4720,8 @@ int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; int lineno; int col_offset; @@ -5836,8 +5836,8 @@ int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); if (isinstance == -1) { @@ -5896,8 +5896,8 @@ int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; if (obj == Py_None) { @@ -6019,8 +6019,8 @@ int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); if (isinstance == -1) { @@ -6047,8 +6047,8 @@ int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); if (isinstance == -1) { @@ -6155,8 +6155,8 @@ int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); if (isinstance == -1) { @@ -6199,8 +6199,8 @@ int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); if (isinstance == -1) { @@ -6355,8 +6355,8 @@ int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) { PyObject* tmp = NULL; - tmp = tmp; int isinstance; + tmp = tmp; int lineno; int col_offset; -- cgit v1.2.1 From 2a0838ed90391b3fa68188d59dda4bbacbf4c812 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 20 Nov 2010 04:31:07 +0000 Subject: new plan: functions that want 'tmp' can declare it --- Python/Python-ast.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 8de5314e2d..4d26ec8de7 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3374,10 +3374,9 @@ failed: int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; + PyObject *tmp = NULL; if (obj == Py_None) { *out = NULL; @@ -3523,10 +3522,9 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; + PyObject *tmp = NULL; int lineno; int col_offset; @@ -4719,10 +4717,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; + PyObject *tmp = NULL; int lineno; int col_offset; @@ -5835,9 +5832,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); if (isinstance == -1) { @@ -5895,10 +5890,9 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; + PyObject *tmp = NULL; if (obj == Py_None) { *out = NULL; @@ -6018,9 +6012,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); if (isinstance == -1) { @@ -6046,9 +6038,7 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); if (isinstance == -1) { @@ -6154,9 +6144,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); if (isinstance == -1) { @@ -6198,9 +6186,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); if (isinstance == -1) { @@ -6354,10 +6340,9 @@ failed: int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) { - PyObject* tmp = NULL; int isinstance; - tmp = tmp; + PyObject *tmp = NULL; int lineno; int col_offset; -- cgit v1.2.1 From f93d2d0b52f1b7772092895e8a916bac0da07c6c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 21 Nov 2010 15:12:34 +0000 Subject: fix refleak --- Python/Python-ast.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 4d26ec8de7..2c09f96f0e 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3516,6 +3516,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); failed: + Py_XDECREF(tmp); return 1; } @@ -4711,6 +4712,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); failed: + Py_XDECREF(tmp); return 1; } @@ -5826,6 +5828,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); failed: + Py_XDECREF(tmp); return 1; } @@ -6006,6 +6009,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); failed: + Py_XDECREF(tmp); return 1; } @@ -6438,6 +6442,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); failed: + Py_XDECREF(tmp); return 1; } -- cgit v1.2.1 From 7848f2a4be885c95dc41d479377d063547e46fb3 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 22 Jul 2011 10:50:23 -0500 Subject: type check AST strings and identifiers This is related to a21829180423 as well as #12609 and #12610. --- Python/Python-ast.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2c09f96f0e..43dcf6a508 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 82163. + __version__ . This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -600,8 +600,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -#define obj2ast_identifier obj2ast_object -#define obj2ast_string obj2ast_object +static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, + const char *name) +{ + if (!PyUnicode_CheckExact(name)) { + PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); + return 1; + } + return obj2ast_object(obj, out, arena); +} + +static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) +{ + return obj2ast_stringlike(obj, out, arena, "identifier"); +} + +static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) +{ + return obj2ast_stringlike(obj, out, arena, "string"); +} static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { @@ -6739,7 +6756,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) + if (PyModule_AddStringConstant(m, "__version__", "") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From 4fb9e4f2e1910fdbe8932559a9b807ded60e53d1 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 22 Jul 2011 10:39:12 -0500 Subject: hardcode the old svn __version__ --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 43dcf6a508..ea6a2ecf52 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ . + __version__ 82163. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6756,7 +6756,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "") < 0) + if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From f6639c9c8201eee770b6d1a62feb772a9dbbb593 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 22 Jul 2011 11:09:07 -0500 Subject: None is ok for identifiers but not strings --- Python/Python-ast.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index ea6a2ecf52..8ba06ff39a 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -600,24 +600,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, - const char *name) +static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) { - if (!PyUnicode_CheckExact(name)) { - PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); + if (!PyUnicode_CheckExact(obj) && obj != Py_None) { + PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); return 1; } return obj2ast_object(obj, out, arena); } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) -{ - return obj2ast_stringlike(obj, out, arena, "identifier"); -} - static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) { - return obj2ast_stringlike(obj, out, arena, "string"); + if (!PyUnicode_CheckExact(obj)) { + PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); + return 1; + } + return obj2ast_object(obj, out, arena); } static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) -- cgit v1.2.1 From fceeee47d9cd9eef2f01ebd782e2a3face38be15 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 31 Aug 2011 22:13:03 -0400 Subject: accept bytes for the AST 'string' type This is a temporary kludge and all is well in 3.3. --- Python/Python-ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 8ba06ff39a..89c07cd602 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -611,7 +611,7 @@ static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) { - if (!PyUnicode_CheckExact(obj)) { + if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); return 1; } -- cgit v1.2.1 From 025a9d35b90a5c26c427462569e336c7c46c8388 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 21:52:30 +0100 Subject: Issue #13436: commit regenerated Python-ast.c --- Python/Python-ast.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 89c07cd602..a276b6cf21 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -622,11 +622,7 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { int i; if (!PyLong_Check(obj)) { - PyObject *s = PyObject_Repr(obj); - if (s == NULL) return 1; - PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", - PyBytes_AS_STRING(s)); - Py_DECREF(s); + PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); return 1; } -- cgit v1.2.1