diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-02-26 20:51:25 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-02-26 20:51:25 (GMT) |
commit | ce1d5d2527810961f7fe8f7a64d9e54075da482e (patch) | |
tree | 2d5b7e63cef263265d17bf9163d8ca58751ad45b /Parser/asdl_c.py | |
parent | bd260da900b5c5f16e5c61f6795d08171b33e0f8 (diff) | |
download | cpython-ce1d5d2527810961f7fe8f7a64d9e54075da482e.zip cpython-ce1d5d2527810961f7fe8f7a64d9e54075da482e.tar.gz cpython-ce1d5d2527810961f7fe8f7a64d9e54075da482e.tar.bz2 |
Fix iterating over cmpop_ty lists.
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-x | Parser/asdl_c.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 9fba049..acaa99b 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -609,13 +609,21 @@ class ObjVisitor(PickleVisitor): def set(self, field, value, depth): if field.seq: + # XXX should really check for is_simple, but that requires a symbol table if field.type.value == "cmpop": - # XXX check that this cast is safe, i.e. works independent on whether - # sizeof(cmpop_ty) != sizeof(void*) - cast = "(PyObject*(*)(void*))" + # While the sequence elements are stored as void*, + # ast2obj_cmpop expects an enum + self.emit("{", depth) + self.emit("int i, n = asdl_seq_LEN(%s);" % value, depth+1) + self.emit("value = PyList_New(n);", depth+1) + self.emit("if (!value) goto failed;", depth+1) + self.emit("for(i = 0; i < n; i++)", depth+1) + # This cannot fail, so no need for error handling + self.emit("PyList_SET_ITEM(value, i, ast2obj_%s((%s_ty)asdl_seq_GET(%s, i)));" % + (field.type, field.type, value), depth+2, reflow=False) + self.emit("}", depth) else: - cast = "" - self.emit("value = ast2obj_list(%s, %sast2obj_%s);" % (value, cast, field.type), depth) + self.emit("value = ast2obj_list(%s, ast2obj_%s);" % (value, field.type), depth) else: ctype = get_c_type(field.type) self.emit("value = ast2obj_%s(%s);" % (field.type, value), depth, reflow=False) |