diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-22 15:39:50 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-22 15:39:50 (GMT) |
commit | 77820242dd465e12f6660ae701fb3520d784fd1f (patch) | |
tree | b86bf097b24156d9deb145310a41576da6d59951 /Parser | |
parent | 59c69512be98d887387f446a77ab39d1626dfd8a (diff) | |
download | cpython-77820242dd465e12f6660ae701fb3520d784fd1f.zip cpython-77820242dd465e12f6660ae701fb3520d784fd1f.tar.gz cpython-77820242dd465e12f6660ae701fb3520d784fd1f.tar.bz2 |
verify the types of AST strings and identifiers (closes #12609 and #12610)
Diffstat (limited to 'Parser')
-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 f6f8d0e..8aba6b3 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -800,8 +800,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_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) { |