Cleanup a bit and make things more consistent.

Don't double check for NULLs and don't initialize if not necessary.
No functional changes.
This commit is contained in:
Neal Norwitz 2005-12-18 03:16:20 +00:00
parent b04747fc50
commit 84456bdab3
2 changed files with 87 additions and 142 deletions

View file

@ -578,9 +578,8 @@ ast_for_arguments(struct compiling *c, const node *n)
/* first count the number of normal args & defaults */ /* first count the number of normal args & defaults */
for (i = 0; i < NCH(n); i++) { for (i = 0; i < NCH(n); i++) {
ch = CHILD(n, i); ch = CHILD(n, i);
if (TYPE(ch) == fpdef) { if (TYPE(ch) == fpdef)
n_args++; n_args++;
}
if (TYPE(ch) == EQUAL) if (TYPE(ch) == EQUAL)
n_defaults++; n_defaults++;
} }
@ -668,9 +667,8 @@ ast_for_arguments(struct compiling *c, const node *n)
static expr_ty static expr_ty
ast_for_dotted_name(struct compiling *c, const node *n) ast_for_dotted_name(struct compiling *c, const node *n)
{ {
expr_ty e = NULL; expr_ty e;
expr_ty attrib = NULL; identifier id;
identifier id = NULL;
int i; int i;
REQ(n, dotted_name); REQ(n, dotted_name);
@ -681,17 +679,14 @@ ast_for_dotted_name(struct compiling *c, const node *n)
e = Name(id, Load, LINENO(n), c->c_arena); e = Name(id, Load, LINENO(n), c->c_arena);
if (!e) if (!e)
return NULL; return NULL;
id = NULL;
for (i = 2; i < NCH(n); i+=2) { for (i = 2; i < NCH(n); i+=2) {
id = NEW_IDENTIFIER(CHILD(n, i)); id = NEW_IDENTIFIER(CHILD(n, i));
if (!id) if (!id)
return NULL; return NULL;
attrib = Attribute(e, id, Load, LINENO(CHILD(n, i)), c->c_arena); e = Attribute(e, id, Load, LINENO(CHILD(n, i)), c->c_arena);
if (!attrib) if (!e)
return NULL; return NULL;
e = attrib;
attrib = NULL;
} }
return e; return e;
@ -702,7 +697,7 @@ ast_for_decorator(struct compiling *c, const node *n)
{ {
/* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */ /* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */
expr_ty d = NULL; expr_ty d = NULL;
expr_ty name_expr = NULL; expr_ty name_expr;
REQ(n, decorator); REQ(n, decorator);
@ -739,7 +734,7 @@ ast_for_decorator(struct compiling *c, const node *n)
static asdl_seq* static asdl_seq*
ast_for_decorators(struct compiling *c, const node *n) ast_for_decorators(struct compiling *c, const node *n)
{ {
asdl_seq* decorator_seq = NULL; asdl_seq* decorator_seq;
expr_ty d; expr_ty d;
int i; int i;
@ -762,9 +757,9 @@ static stmt_ty
ast_for_funcdef(struct compiling *c, const node *n) ast_for_funcdef(struct compiling *c, const node *n)
{ {
/* funcdef: 'def' [decorators] NAME parameters ':' suite */ /* funcdef: 'def' [decorators] NAME parameters ':' suite */
identifier name = NULL; identifier name;
arguments_ty args = NULL; arguments_ty args;
asdl_seq *body = NULL; asdl_seq *body;
asdl_seq *decorator_seq = NULL; asdl_seq *decorator_seq = NULL;
int name_i; int name_i;
@ -855,11 +850,10 @@ count_list_fors(const node *n)
else else
return n_fors; return n_fors;
} }
else {
/* Should never be reached */ /* Should never be reached */
PyErr_SetString(PyExc_SystemError, "logic error in count_list_fors"); PyErr_SetString(PyExc_SystemError, "logic error in count_list_fors");
return -1; return -1;
}
} }
/* Count the number of 'if' statements in a list comprehension. /* Count the number of 'if' statements in a list comprehension.
@ -1004,12 +998,11 @@ count_gen_fors(const node *n)
else else
return n_fors; return n_fors;
} }
else {
/* Should never be reached */ /* Should never be reached */
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
"logic error in count_gen_fors"); "logic error in count_gen_fors");
return -1; return -1;
}
} }
/* Count the number of 'if' statements in a generator expression. /* Count the number of 'if' statements in a generator expression.
@ -1475,11 +1468,8 @@ ast_for_expr(struct compiling *c, const node *n)
} }
if (!strcmp(STR(CHILD(n, 1)), "and")) if (!strcmp(STR(CHILD(n, 1)), "and"))
return BoolOp(And, seq, LINENO(n), c->c_arena); return BoolOp(And, seq, LINENO(n), c->c_arena);
else { assert(!strcmp(STR(CHILD(n, 1)), "or"));
assert(!strcmp(STR(CHILD(n, 1)), "or")); return BoolOp(Or, seq, LINENO(n), c->c_arena);
return BoolOp(Or, seq, LINENO(n), c->c_arena);
}
break;
case not_test: case not_test:
if (NCH(n) == 1) { if (NCH(n) == 1) {
n = CHILD(n, 0); n = CHILD(n, 0);
@ -1587,7 +1577,7 @@ ast_for_expr(struct compiling *c, const node *n)
PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n)); PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n));
return NULL; return NULL;
} }
/* should never get here unless if error is set*/ /* should never get here unless if error is set */
return NULL; return NULL;
} }
@ -1601,8 +1591,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
*/ */
int i, nargs, nkeywords, ngens; int i, nargs, nkeywords, ngens;
asdl_seq *args = NULL; asdl_seq *args;
asdl_seq *keywords = NULL; asdl_seq *keywords;
expr_ty vararg = NULL, kwarg = NULL; expr_ty vararg = NULL, kwarg = NULL;
REQ(n, arglist); REQ(n, arglist);
@ -1732,11 +1722,9 @@ ast_for_testlist_gexp(struct compiling *c, const node* n)
/* testlist_gexp: test ( gen_for | (',' test)* [','] ) */ /* testlist_gexp: test ( gen_for | (',' test)* [','] ) */
/* argument: test [ gen_for ] */ /* argument: test [ gen_for ] */
assert(TYPE(n) == testlist_gexp || TYPE(n) == argument); assert(TYPE(n) == testlist_gexp || TYPE(n) == argument);
if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == gen_for) { if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == gen_for)
return ast_for_genexp(c, n); return ast_for_genexp(c, n);
} return ast_for_testlist(c, n);
else
return ast_for_testlist(c, n);
} }
/* like ast_for_testlist() but returns a sequence */ /* like ast_for_testlist() but returns a sequence */
@ -1752,15 +1740,13 @@ ast_for_class_bases(struct compiling *c, const node* n)
if (!bases) if (!bases)
return NULL; return NULL;
base = ast_for_expr(c, CHILD(n, 0)); base = ast_for_expr(c, CHILD(n, 0));
if (!base) { if (!base)
return NULL; return NULL;
}
asdl_seq_SET(bases, 0, base); asdl_seq_SET(bases, 0, base);
return bases; return bases;
} }
else {
return seq_for_testlist(c, n); return seq_for_testlist(c, n);
}
} }
static stmt_ty static stmt_ty
@ -1813,14 +1799,12 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
expr2 = ast_for_testlist(c, ch); expr2 = ast_for_testlist(c, ch);
else else
expr2 = Yield(ast_for_expr(c, ch), LINENO(ch), c->c_arena); expr2 = Yield(ast_for_expr(c, ch), LINENO(ch), c->c_arena);
if (!expr2) { if (!expr2)
return NULL; return NULL;
}
operator = ast_for_augassign(CHILD(n, 1)); operator = ast_for_augassign(CHILD(n, 1));
if (!operator) { if (!operator)
return NULL; return NULL;
}
return AugAssign(expr1, operator, expr2, LINENO(n), c->c_arena); return AugAssign(expr1, operator, expr2, LINENO(n), c->c_arena);
} }
@ -1848,9 +1832,8 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
if (!e) if (!e)
return NULL; return NULL;
if (!set_context(e, Store, CHILD(n, i))) { if (!set_context(e, Store, CHILD(n, i)))
return NULL; return NULL;
}
asdl_seq_SET(targets, i / 2, e); asdl_seq_SET(targets, i / 2, e);
} }
@ -1888,9 +1871,8 @@ ast_for_print_stmt(struct compiling *c, const node *n)
return NULL; return NULL;
for (i = start; i < NCH(n); i += 2) { for (i = start; i < NCH(n); i += 2) {
expression = ast_for_expr(c, CHILD(n, i)); expression = ast_for_expr(c, CHILD(n, i));
if (!expression) { if (!expression)
return NULL; return NULL;
}
asdl_seq_APPEND(seq, expression); asdl_seq_APPEND(seq, expression);
} }
@ -1915,10 +1897,8 @@ ast_for_exprlist(struct compiling *c, const node *n, int context)
if (!e) if (!e)
return NULL; return NULL;
asdl_seq_SET(seq, i / 2, e); asdl_seq_SET(seq, i / 2, e);
if (context) { if (context && !set_context(e, context, CHILD(n, i)))
if (!set_context(e, context, CHILD(n, i))) return NULL;
return NULL;
}
} }
return seq; return seq;
} }
@ -2015,6 +1995,9 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
"unexpected flow_stmt: %d", TYPE(ch)); "unexpected flow_stmt: %d", TYPE(ch));
return NULL; return NULL;
} }
PyErr_SetString(PyExc_SystemError, "unhandled flow statement");
return NULL;
} }
static alias_ty static alias_ty
@ -2030,13 +2013,8 @@ alias_for_import_name(struct compiling *c, const node *n)
loop: loop:
switch (TYPE(n)) { switch (TYPE(n)) {
case import_as_name: case import_as_name:
if (NCH(n) == 3) str = (NCH(n) == 3) ? NEW_IDENTIFIER(CHILD(n, 2)) : NULL;
return alias(NEW_IDENTIFIER(CHILD(n, 0)), return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena);
NEW_IDENTIFIER(CHILD(n, 2)), c->c_arena);
else
return alias(NEW_IDENTIFIER(CHILD(n, 0)),
NULL, c->c_arena);
break;
case dotted_as_name: case dotted_as_name:
if (NCH(n) == 1) { if (NCH(n) == 1) {
n = CHILD(n, 0); n = CHILD(n, 0);
@ -2090,6 +2068,8 @@ alias_for_import_name(struct compiling *c, const node *n)
"unexpected import name: %d", TYPE(n)); "unexpected import name: %d", TYPE(n));
return NULL; return NULL;
} }
PyErr_SetString(PyExc_SystemError, "unhandled import name condition");
return NULL; return NULL;
} }
@ -2116,9 +2096,8 @@ ast_for_import_stmt(struct compiling *c, const node *n)
return NULL; return NULL;
for (i = 0; i < NCH(n); i += 2) { for (i = 0; i < NCH(n); i += 2) {
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i)); alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
if (!import_alias) { if (!import_alias)
return NULL; return NULL;
}
asdl_seq_SET(aliases, i / 2, import_alias); asdl_seq_SET(aliases, i / 2, import_alias);
} }
return Import(aliases, LINENO(n), c->c_arena); return Import(aliases, LINENO(n), c->c_arena);
@ -2158,24 +2137,21 @@ ast_for_import_stmt(struct compiling *c, const node *n)
n_children = 1; n_children = 1;
aliases = asdl_seq_new((n_children + 1) / 2, c->c_arena); aliases = asdl_seq_new((n_children + 1) / 2, c->c_arena);
if (!aliases) { if (!aliases)
return NULL; return NULL;
}
/* handle "from ... import *" special b/c there's no children */ /* handle "from ... import *" special b/c there's no children */
if (from_modules && from_modules[0] == '*') { if (from_modules && from_modules[0] == '*') {
alias_ty import_alias = alias_for_import_name(c, n); alias_ty import_alias = alias_for_import_name(c, n);
if (!import_alias) { if (!import_alias)
return NULL; return NULL;
}
asdl_seq_APPEND(aliases, import_alias); asdl_seq_APPEND(aliases, import_alias);
} }
for (i = 0; i < NCH(n); i += 2) { for (i = 0; i < NCH(n); i += 2) {
alias_ty import_alias = alias_for_import_name(c, CHILD(n, i)); alias_ty import_alias = alias_for_import_name(c, CHILD(n, i));
if (!import_alias) { if (!import_alias)
return NULL; return NULL;
}
asdl_seq_APPEND(aliases, import_alias); asdl_seq_APPEND(aliases, import_alias);
} }
return ImportFrom(mod->name, aliases, lineno, c->c_arena); return ImportFrom(mod->name, aliases, lineno, c->c_arena);
@ -2200,9 +2176,8 @@ ast_for_global_stmt(struct compiling *c, const node *n)
return NULL; return NULL;
for (i = 1; i < NCH(n); i += 2) { for (i = 1; i < NCH(n); i += 2) {
name = NEW_IDENTIFIER(CHILD(n, i)); name = NEW_IDENTIFIER(CHILD(n, i));
if (!name) { if (!name)
return NULL; return NULL;
}
asdl_seq_SET(s, i / 2, name); asdl_seq_SET(s, i / 2, name);
} }
return Global(s, LINENO(n), c->c_arena); return Global(s, LINENO(n), c->c_arena);
@ -2272,7 +2247,7 @@ static asdl_seq *
ast_for_suite(struct compiling *c, const node *n) ast_for_suite(struct compiling *c, const node *n)
{ {
/* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */ /* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */
asdl_seq *seq = NULL; asdl_seq *seq;
stmt_ty s; stmt_ty s;
int i, total, num, end, pos = 0; int i, total, num, end, pos = 0;
node *ch; node *ch;
@ -2352,12 +2327,12 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!expression) if (!expression)
return NULL; return NULL;
suite_seq = ast_for_suite(c, CHILD(n, 3)); suite_seq = ast_for_suite(c, CHILD(n, 3));
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
return If(expression, suite_seq, NULL, LINENO(n), c->c_arena); return If(expression, suite_seq, NULL, LINENO(n), c->c_arena);
} }
s = STR(CHILD(n, 4)); s = STR(CHILD(n, 4));
/* s[2], the third character in the string, will be /* s[2], the third character in the string, will be
's' for el_s_e, or 's' for el_s_e, or
@ -2371,13 +2346,11 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!expression) if (!expression)
return NULL; return NULL;
seq1 = ast_for_suite(c, CHILD(n, 3)); seq1 = ast_for_suite(c, CHILD(n, 3));
if (!seq1) { if (!seq1)
return NULL; return NULL;
}
seq2 = ast_for_suite(c, CHILD(n, 6)); seq2 = ast_for_suite(c, CHILD(n, 6));
if (!seq2) { if (!seq2)
return NULL; return NULL;
}
return If(expression, seq1, seq2, LINENO(n), c->c_arena); return If(expression, seq1, seq2, LINENO(n), c->c_arena);
} }
@ -2402,17 +2375,14 @@ ast_for_if_stmt(struct compiling *c, const node *n)
if (!orelse) if (!orelse)
return NULL; return NULL;
expression = ast_for_expr(c, CHILD(n, NCH(n) - 6)); expression = ast_for_expr(c, CHILD(n, NCH(n) - 6));
if (!expression) { if (!expression)
return NULL; return NULL;
}
seq1 = ast_for_suite(c, CHILD(n, NCH(n) - 4)); seq1 = ast_for_suite(c, CHILD(n, NCH(n) - 4));
if (!seq1) { if (!seq1)
return NULL; return NULL;
}
seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1)); seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1));
if (!seq2) { if (!seq2)
return NULL; return NULL;
}
asdl_seq_SET(orelse, 0, If(expression, seq1, seq2, asdl_seq_SET(orelse, 0, If(expression, seq1, seq2,
LINENO(CHILD(n, NCH(n) - 6)), LINENO(CHILD(n, NCH(n) - 6)),
@ -2420,25 +2390,20 @@ ast_for_if_stmt(struct compiling *c, const node *n)
/* the just-created orelse handled the last elif */ /* the just-created orelse handled the last elif */
n_elif--; n_elif--;
} }
else
orelse = NULL;
for (i = 0; i < n_elif; i++) { for (i = 0; i < n_elif; i++) {
int off = 5 + (n_elif - i - 1) * 4; int off = 5 + (n_elif - i - 1) * 4;
expr_ty expression; expr_ty expression;
asdl_seq *suite_seq; asdl_seq *suite_seq;
asdl_seq *new = asdl_seq_new(1, c->c_arena); asdl_seq *new = asdl_seq_new(1, c->c_arena);
if (!new) { if (!new)
return NULL; return NULL;
}
expression = ast_for_expr(c, CHILD(n, off)); expression = ast_for_expr(c, CHILD(n, off));
if (!expression) { if (!expression)
return NULL; return NULL;
}
suite_seq = ast_for_suite(c, CHILD(n, off + 2)); suite_seq = ast_for_suite(c, CHILD(n, off + 2));
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
asdl_seq_SET(new, 0, asdl_seq_SET(new, 0,
If(expression, suite_seq, orelse, If(expression, suite_seq, orelse,
@ -2449,11 +2414,10 @@ ast_for_if_stmt(struct compiling *c, const node *n)
ast_for_suite(c, CHILD(n, 3)), ast_for_suite(c, CHILD(n, 3)),
orelse, LINENO(n), c->c_arena); orelse, LINENO(n), c->c_arena);
} }
else {
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"unexpected token in 'if' statement: %s", s); "unexpected token in 'if' statement: %s", s);
return NULL; return NULL;
}
} }
static stmt_ty static stmt_ty
@ -2470,9 +2434,8 @@ ast_for_while_stmt(struct compiling *c, const node *n)
if (!expression) if (!expression)
return NULL; return NULL;
suite_seq = ast_for_suite(c, CHILD(n, 3)); suite_seq = ast_for_suite(c, CHILD(n, 3));
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
return While(expression, suite_seq, NULL, LINENO(n), c->c_arena); return While(expression, suite_seq, NULL, LINENO(n), c->c_arena);
} }
else if (NCH(n) == 7) { else if (NCH(n) == 7) {
@ -2483,28 +2446,25 @@ ast_for_while_stmt(struct compiling *c, const node *n)
if (!expression) if (!expression)
return NULL; return NULL;
seq1 = ast_for_suite(c, CHILD(n, 3)); seq1 = ast_for_suite(c, CHILD(n, 3));
if (!seq1) { if (!seq1)
return NULL; return NULL;
}
seq2 = ast_for_suite(c, CHILD(n, 6)); seq2 = ast_for_suite(c, CHILD(n, 6));
if (!seq2) { if (!seq2)
return NULL; return NULL;
}
return While(expression, seq1, seq2, LINENO(n), c->c_arena); return While(expression, seq1, seq2, LINENO(n), c->c_arena);
} }
else {
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"wrong number of tokens for 'while' statement: %d", "wrong number of tokens for 'while' statement: %d",
NCH(n)); NCH(n));
return NULL; return NULL;
}
} }
static stmt_ty static stmt_ty
ast_for_for_stmt(struct compiling *c, const node *n) ast_for_for_stmt(struct compiling *c, const node *n)
{ {
asdl_seq *_target = NULL, *seq = NULL, *suite_seq = NULL; asdl_seq *_target, *seq = NULL, *suite_seq;
expr_ty expression; expr_ty expression;
expr_ty target; expr_ty target;
/* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */ /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */
@ -2517,23 +2477,19 @@ ast_for_for_stmt(struct compiling *c, const node *n)
} }
_target = ast_for_exprlist(c, CHILD(n, 1), Store); _target = ast_for_exprlist(c, CHILD(n, 1), Store);
if (!_target) { if (!_target)
return NULL; return NULL;
} if (asdl_seq_LEN(_target) == 1)
if (asdl_seq_LEN(_target) == 1) {
target = asdl_seq_GET(_target, 0); target = asdl_seq_GET(_target, 0);
}
else else
target = Tuple(_target, Store, LINENO(n), c->c_arena); target = Tuple(_target, Store, LINENO(n), c->c_arena);
expression = ast_for_testlist(c, CHILD(n, 3)); expression = ast_for_testlist(c, CHILD(n, 3));
if (!expression) { if (!expression)
return NULL; return NULL;
}
suite_seq = ast_for_suite(c, CHILD(n, 5)); suite_seq = ast_for_suite(c, CHILD(n, 5));
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
return For(target, expression, suite_seq, seq, LINENO(n), c->c_arena); return For(target, expression, suite_seq, seq, LINENO(n), c->c_arena);
} }
@ -2560,9 +2516,8 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
if (!expression) if (!expression)
return NULL; return NULL;
suite_seq = ast_for_suite(c, body); suite_seq = ast_for_suite(c, body);
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
return excepthandler(expression, NULL, suite_seq, c->c_arena); return excepthandler(expression, NULL, suite_seq, c->c_arena);
} }
@ -2572,26 +2527,22 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
expr_ty e = ast_for_expr(c, CHILD(exc, 3)); expr_ty e = ast_for_expr(c, CHILD(exc, 3));
if (!e) if (!e)
return NULL; return NULL;
if (!set_context(e, Store, CHILD(exc, 3))) { if (!set_context(e, Store, CHILD(exc, 3)))
return NULL; return NULL;
}
expression = ast_for_expr(c, CHILD(exc, 1)); expression = ast_for_expr(c, CHILD(exc, 1));
if (!expression) { if (!expression)
return NULL; return NULL;
}
suite_seq = ast_for_suite(c, body); suite_seq = ast_for_suite(c, body);
if (!suite_seq) { if (!suite_seq)
return NULL; return NULL;
}
return excepthandler(expression, e, suite_seq, c->c_arena); return excepthandler(expression, e, suite_seq, c->c_arena);
} }
else {
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"wrong number of children for 'except' clause: %d", "wrong number of children for 'except' clause: %d",
NCH(exc)); NCH(exc));
return NULL; return NULL;
}
} }
static stmt_ty static stmt_ty
@ -2706,9 +2657,8 @@ ast_for_classdef(struct compiling *c, const node *n)
return NULL; return NULL;
s = ast_for_suite(c, CHILD(n, 6)); s = ast_for_suite(c, CHILD(n, 6));
if (!s) { if (!s)
return NULL; return NULL;
}
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n), return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n),
c->c_arena); c->c_arena);
} }

View file

@ -40,9 +40,6 @@ PyArenaList_New(void)
static void static void
PyArenaList_FreeObject(PyArenaList *alist) PyArenaList_FreeObject(PyArenaList *alist)
{ {
if (!alist)
return;
while (alist) { while (alist) {
PyArenaList *prev; PyArenaList *prev;
Py_XDECREF((PyObject *)alist->al_pointer); Py_XDECREF((PyObject *)alist->al_pointer);
@ -56,9 +53,6 @@ PyArenaList_FreeObject(PyArenaList *alist)
static void static void
PyArenaList_FreeMalloc(PyArenaList *alist) PyArenaList_FreeMalloc(PyArenaList *alist)
{ {
if (!alist)
return;
while (alist) { while (alist) {
PyArenaList *prev; PyArenaList *prev;
if (alist->al_pointer) { if (alist->al_pointer) {
@ -105,7 +99,8 @@ PyArena_Malloc(PyArena *arena, size_t size)
void *p; void *p;
assert(size != 0); assert(size != 0);
p = malloc(size); p = malloc(size);
PyArena_AddMallocPointer(arena, p); if (p)
PyArena_AddMallocPointer(arena, p);
return p; return p;
} }