summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-04-13 12:29:43 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-04-13 12:29:43 (GMT)
commit0cc56e5c59bbc9d839d1468f8b51ea9391e8852a (patch)
treeb01b94983a324fdc0e660fdd194a9f67060a6e6a /Python
parent0f1955daeea82b6d8765d2b7642a9f082faddc74 (diff)
downloadcpython-0cc56e5c59bbc9d839d1468f8b51ea9391e8852a.zip
cpython-0cc56e5c59bbc9d839d1468f8b51ea9391e8852a.tar.gz
cpython-0cc56e5c59bbc9d839d1468f8b51ea9391e8852a.tar.bz2
Introduce asdl_int_seq, to hold cmpop_ty.
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-ast.c6
-rw-r--r--Python/asdl.c19
-rw-r--r--Python/ast.c8
-rw-r--r--Python/compile.c12
4 files changed, 27 insertions, 18 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index af9deed..7a0f528 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -1503,8 +1503,8 @@ Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
}
expr_ty
-Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, int
- col_offset, PyArena *arena)
+Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
+ int col_offset, PyArena *arena)
{
expr_ty p;
if (!left) {
@@ -2503,7 +2503,7 @@ ast2obj_expr(void* _o)
value = PyList_New(n);
if (!value) goto failed;
for(i = 0; i < n; i++)
- PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)(int)asdl_seq_GET(o->v.Compare.ops, i)));
+ PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
}
if (!value) goto failed;
if (PyObject_SetAttrString(result, "ops", value) == -1)
diff --git a/Python/asdl.c b/Python/asdl.c
index 225df6e..416b293 100644
--- a/Python/asdl.c
+++ b/Python/asdl.c
@@ -8,7 +8,24 @@ asdl_seq_new(int size, PyArena *arena)
size_t n = sizeof(asdl_seq) +
(size ? (sizeof(void *) * (size - 1)) : 0);
- seq = (asdl_seq *)PyArena_Malloc(arena, n);
+ seq = (asdl_seq *)PyArena_Malloc(arena, n);
+ if (!seq) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memset(seq, 0, n);
+ seq->size = size;
+ return seq;
+}
+
+asdl_int_seq *
+asdl_int_seq_new(int size, PyArena *arena)
+{
+ asdl_seq *seq = NULL;
+ size_t n = sizeof(asdl_seq) +
+ (size ? (sizeof(int) * (size - 1)) : 0);
+
+ seq = (asdl_seq *)PyArena_Malloc(arena, n);
if (!seq) {
PyErr_NoMemory();
return NULL;
diff --git a/Python/ast.c b/Python/ast.c
index e825042..0b3b485 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1600,8 +1600,9 @@ ast_for_expr(struct compiling *c, const node *n)
}
else {
expr_ty expression;
- asdl_seq *ops, *cmps;
- ops = asdl_seq_new(NCH(n) / 2, c->c_arena);
+ asdl_int_seq *ops;
+ asdl_seq *cmps;
+ ops = asdl_int_seq_new(NCH(n) / 2, c->c_arena);
if (!ops)
return NULL;
cmps = asdl_seq_new(NCH(n) / 2, c->c_arena);
@@ -1609,7 +1610,6 @@ ast_for_expr(struct compiling *c, const node *n)
return NULL;
}
for (i = 1; i < NCH(n); i += 2) {
- /* XXX cmpop_ty is just an enum */
cmpop_ty newoperator;
newoperator = ast_for_comp_op(CHILD(n, i));
@@ -1622,7 +1622,7 @@ ast_for_expr(struct compiling *c, const node *n)
return NULL;
}
- asdl_seq_SET(ops, i / 2, (void *)(Py_uintptr_t)newoperator);
+ asdl_seq_SET(ops, i / 2, newoperator);
asdl_seq_SET(cmps, i / 2, expression);
}
expression = ast_for_expr(c, CHILD(n, 0));
diff --git a/Python/compile.c b/Python/compile.c
index 1bbe73a..8b6f2f1 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3058,17 +3058,11 @@ compiler_compare(struct compiler *c, expr_ty e)
VISIT(c, expr,
(expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0));
}
-#ifdef __cplusplus
-#define CMPCAST (intptr_t)
-#else
-#define CMPCAST
-#endif
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(
+ cmpop((cmpop_ty)(asdl_seq_GET(
e->v.Compare.ops, i - 1))));
ADDOP_JREL(c, JUMP_IF_FALSE, cleanup);
NEXT_BLOCK(c);
@@ -3079,9 +3073,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(e->v.Compare.ops, n - 1))));
if (n > 1) {
basicblock *end = compiler_new_block(c);
if (end == NULL)