Mercurial > cpython-lru_cache-weakref
diff Python/Python-ast.c @ 71452:a21829180423 2.7
verify the types of AST strings and identifiers (closes #12609 and #12610)
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 22 Jul 2011 10:39:50 -0500 |
| parents | 9d004a9a2ced |
| children | 7a72068d88fe |
line wrap: on
line diff
--- a/Python/Python-ast.c Fri Jul 22 10:39:12 2011 -0500 +++ b/Python/Python-ast.c Fri Jul 22 10:39:50 2011 -0500 @@ -2,7 +2,7 @@ /* - __version__ 82160. + __version__ . This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -594,8 +594,25 @@ return 0; } -#define obj2ast_identifier obj2ast_object -#define obj2ast_string obj2ast_object +static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) +{ + if (!PyString_CheckExact(obj)) { + PyErr_Format(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 (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) { + PyErr_SetString(PyExc_TypeError, + "AST string must be of type str or unicode"); + return 1; + } + return obj2ast_object(obj, out, arena); +} static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { @@ -6570,7 +6587,7 @@ if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return; - if (PyModule_AddStringConstant(m, "__version__", "82160") < 0) + if (PyModule_AddStringConstant(m, "__version__", "") < 0) return; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
