@@ -609,13 +609,21 @@ def emitSeq(self, field, value, depth, emit):
609609
610610 def set (self , field , value , depth ):
611611 if field .seq :
612+ # XXX should really check for is_simple, but that requires a symbol table
612613 if field .type .value == "cmpop" :
613- # XXX check that this cast is safe, i.e. works independent on whether
614- # sizeof(cmpop_ty) != sizeof(void*)
615- cast = "(PyObject*(*)(void*))"
614+ # While the sequence elements are stored as void*,
615+ # ast2obj_cmpop expects an enum
616+ self .emit ("{" , depth )
617+ self .emit ("int i, n = asdl_seq_LEN(%s);" % value , depth + 1 )
618+ self .emit ("value = PyList_New(n);" , depth + 1 )
619+ self .emit ("if (!value) goto failed;" , depth + 1 )
620+ self .emit ("for(i = 0; i < n; i++)" , depth + 1 )
621+ # This cannot fail, so no need for error handling
622+ self .emit ("PyList_SET_ITEM(value, i, ast2obj_%s((%s_ty)asdl_seq_GET(%s, i)));" %
623+ (field .type , field .type , value ), depth + 2 , reflow = False )
624+ self .emit ("}" , depth )
616625 else :
617- cast = ""
618- self .emit ("value = ast2obj_list(%s, %sast2obj_%s);" % (value , cast , field .type ), depth )
626+ self .emit ("value = ast2obj_list(%s, ast2obj_%s);" % (value , field .type ), depth )
619627 else :
620628 ctype = get_c_type (field .type )
621629 self .emit ("value = ast2obj_%s(%s);" % (field .type , value ), depth , reflow = False )
0 commit comments