diff options
author | Matthias Klose <doko@ubuntu.com> | 2012-03-14 23:26:07 +0100 |
---|---|---|
committer | Matthias Klose <doko@ubuntu.com> | 2012-03-14 23:26:07 +0100 |
commit | 22cde52f7629ca850ecd68687d0685142f7a8e5d (patch) | |
tree | 42025ba50d9f1605750333c5adc114d9083cdab3 /Python/Python-ast.c | |
parent | 31ba1cc7e03400c4a4ab2f0eea8c67e23d22418d (diff) | |
parent | 749f2a613f5bd6a723078b8ccb9af0c3dbb7d767 (diff) | |
download | cpython-22cde52f7629ca850ecd68687d0685142f7a8e5d.tar.gz |
merge 3.1
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r-- | Python/Python-ast.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index efc69dcfec..a276b6cf21 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 67616. + __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 @@ -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; @@ -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); @@ -599,18 +600,29 @@ 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_identifier(PyObject* obj, PyObject** out, PyArena* arena) +{ + 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_string(PyObject* obj, PyObject** out, PyArena* arena) +{ + if (!PyUnicode_CheckExact(obj) && !PyBytes_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) { 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; } @@ -1332,11 +1344,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; @@ -3520,6 +3527,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; } @@ -4544,8 +4552,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; @@ -4716,6 +4723,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; } @@ -5831,6 +5839,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; } @@ -6011,6 +6020,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; } @@ -6443,6 +6453,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; } @@ -6739,7 +6750,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__", "82163") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |