From: Victor Stinner Date: Fri, 26 Jul 2013 22:04:42 +0000 (+0200) Subject: (Merge 3.3) Parser/asdl_c.py: use Py_CLEAR() X-Git-Tag: v3.4.0a1~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b318990cacb02b6f59f0b529cb3e6014f4b1c9fd;p=python (Merge 3.3) Parser/asdl_c.py: use Py_CLEAR() --- b318990cacb02b6f59f0b529cb3e6014f4b1c9fd diff --cc Python/Python-ast.c index 776055fa34,d78657ce07..49d19dacd6 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@@ -5738,29 -5584,6 +5647,28 @@@ obj2ast_expr(PyObject* obj, expr_ty* ou if (*out == NULL) goto failed; return 0; } + isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + singleton value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_singleton(tmp, &value, arena); + if (res != 0) goto failed; - Py_XDECREF(tmp); - tmp = NULL; ++ Py_CLEAR(tmp); + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); + return 1; + } + *out = NameConstant(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); if (isinstance == -1) { return 1; @@@ -6699,10 -6496,9 +6579,9 @@@ obj2ast_arguments(PyObject* obj, argume int res; tmp = _PyObject_GetAttrId(obj, &PyId_vararg); if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &vararg, arena); + res = obj2ast_arg(tmp, &vararg, arena); if (res != 0) goto failed; - Py_XDECREF(tmp); - tmp = NULL; + Py_CLEAR(tmp); } else { vararg = NULL; } @@@ -6731,41 -6536,25 +6609,39 @@@ PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); return 1; } - if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { + if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { int res; - tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); + Py_ssize_t len; + Py_ssize_t i; + tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); if (tmp == NULL) goto failed; - res = obj2ast_identifier(tmp, &kwarg, arena); - if (res != 0) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + kw_defaults = asdl_seq_new(len, arena); + if (kw_defaults == NULL) goto failed; + for (i = 0; i < len; i++) { + expr_ty value; + res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(kw_defaults, i, value); + } - Py_XDECREF(tmp); - tmp = NULL; + Py_CLEAR(tmp); } else { - kwarg = NULL; + PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); + return 1; } - if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { + if (exists_not_none(obj, &PyId_kwarg)) { int res; - tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); + tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &kwargannotation, arena); + res = obj2ast_arg(tmp, &kwarg, arena); if (res != 0) goto failed; - Py_XDECREF(tmp); - tmp = NULL; + Py_CLEAR(tmp); } else { - kwargannotation = NULL; + kwarg = NULL; } if (_PyObject_HasAttrId(obj, &PyId_defaults)) { int res;