diff options
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 22ef3d0..c38a853 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -795,8 +795,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) { |