]> granicus.if.org Git - python/commitdiff
Use union to discriminate pointer types from enum/int types.
authorSkip Montanaro <skip@pobox.com>
Thu, 13 Apr 2006 09:37:01 +0000 (09:37 +0000)
committerSkip Montanaro <skip@pobox.com>
Thu, 13 Apr 2006 09:37:01 +0000 (09:37 +0000)
Include/asdl.h
Python/compile.c

index d709d42c76d452c8ca53718f1e183353e2937235..6a9adea99e5ccf977b66001c89acb172947ca49d 100644 (file)
@@ -19,18 +19,22 @@ typedef enum {false, true} bool;
 
 typedef struct {
     int size;
-    void *elements[1];
+    union {
+        void *elements[1];
+       unsigned int enum_type[1];
+    } elt;
 } asdl_seq;
 
 asdl_seq *asdl_seq_new(int size, PyArena *arena);
 
-#define asdl_seq_GET(S, I) (S)->elements[(I)]
+#define asdl_seq_GET(S, I) (S)->elt.elements[(I)]
+#define asdl_seq_GET_ENUM(S, I) (S)->elt.enum_type[(I)]
 #define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
 #ifdef Py_DEBUG
 #define asdl_seq_SET(S, I, V) { \
         int _asdl_i = (I); \
         assert((S) && _asdl_i < (S)->size); \
-        (S)->elements[_asdl_i] = (V); \
+        (S)->elt.elements[_asdl_i] = (V); \
 }
 #else
 #define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
index 1bbe73a07968bec8f8cfd7d9e3734bbceb9ae119..0fc0200989d2abeffb1449faa7f04637bcbd1455 100644 (file)
@@ -3066,10 +3066,8 @@ compiler_compare(struct compiler *c, expr_ty e)
        for (i = 1; i < n; i++) {
                ADDOP(c, DUP_TOP);
                ADDOP(c, ROT_THREE);
-               /* XXX We're casting a void* to cmpop_ty in the next stmt. */
                ADDOP_I(c, COMPARE_OP,
-                       cmpop((cmpop_ty)( CMPCAST asdl_seq_GET(
-                                                  e->v.Compare.ops, i - 1))));
+                       cmpop((cmpop_ty)asdl_seq_GET_ENUM(e->v.Compare.ops, i - 1)));
                ADDOP_JREL(c, JUMP_IF_FALSE, cleanup);
                NEXT_BLOCK(c);
                ADDOP(c, POP_TOP);
@@ -3080,8 +3078,7 @@ compiler_compare(struct compiler *c, expr_ty e)
        VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1));
        ADDOP_I(c, COMPARE_OP,
                /* XXX We're casting a void* to cmpop_ty in the next stmt. */
-              cmpop((cmpop_ty)( CMPCAST asdl_seq_GET(e->v.Compare.ops, 
-                                                       n - 1))));
+              cmpop((cmpop_ty)asdl_seq_GET_ENUM(e->v.Compare.ops, n - 1)));
        if (n > 1) {
                basicblock *end = compiler_new_block(c);
                if (end == NULL)