diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-22 15:50:23 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-22 15:50:23 (GMT) |
commit | 2193d2b72bc942a0c0b489a9c2759a6aefbeecdf (patch) | |
tree | 76d553c58f5e909d09aef21e6131ec797e72c3d7 /Parser/asdl_c.py | |
parent | 996f606787a7aba177f738157acd672b5821be4c (diff) | |
download | cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.zip cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.gz cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.bz2 |
type check AST strings and identifiers
This is related to a21829180423 as well as #12609 and #12610.
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-x | Parser/asdl_c.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index d6555d6..729ded8 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -794,8 +794,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) { |