10
node *n = (node *) PyObject_MALLOC(1 * sizeof(node));
10
node *n = (node *) PyObject_MALLOC(1 * sizeof(node));
21
21
/* See comments at XXXROUNDUP below. Returns -1 on overflow. */
23
23
fancy_roundup(int n)
25
/* Round up to the closest power of 2 >= n. */
25
/* Round up to the closest power of 2 >= n. */
36
36
/* A gimmick to make massive numbers of reallocs quicker. The result is
70
70
* Note that this would be straightforward if a node stored its current
71
71
* capacity. The code is tricky to avoid that.
73
#define XXXROUNDUP(n) ((n) <= 1 ? (n) : \
74
(n) <= 128 ? (((n) + 3) & ~3) : \
73
#define XXXROUNDUP(n) ((n) <= 1 ? (n) : \
74
(n) <= 128 ? (((n) + 3) & ~3) : \
79
79
PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset)
81
const int nch = n1->n_nchildren;
83
int required_capacity;
86
if (nch == INT_MAX || nch < 0)
89
current_capacity = XXXROUNDUP(nch);
90
required_capacity = XXXROUNDUP(nch + 1);
91
if (current_capacity < 0 || required_capacity < 0)
93
if (current_capacity < required_capacity) {
94
if (required_capacity > PY_SIZE_MAX / sizeof(node)) {
98
n = (node *) PyObject_REALLOC(n,
99
required_capacity * sizeof(node));
105
n = &n1->n_child[n1->n_nchildren++];
108
n->n_lineno = lineno;
109
n->n_col_offset = col_offset;
81
const int nch = n1->n_nchildren;
83
int required_capacity;
86
if (nch == INT_MAX || nch < 0)
89
current_capacity = XXXROUNDUP(nch);
90
required_capacity = XXXROUNDUP(nch + 1);
91
if (current_capacity < 0 || required_capacity < 0)
93
if (current_capacity < required_capacity) {
94
if (required_capacity > PY_SIZE_MAX / sizeof(node)) {
98
n = (node *) PyObject_REALLOC(n,
99
required_capacity * sizeof(node));
105
n = &n1->n_child[n1->n_nchildren++];
108
n->n_lineno = lineno;
109
n->n_col_offset = col_offset;
120
120
PyNode_Free(node *n)
129
129
freechildren(node *n)
132
for (i = NCH(n); --i >= 0; )
133
freechildren(CHILD(n, i));
134
if (n->n_child != NULL)
135
PyObject_FREE(n->n_child);
137
PyObject_FREE(STR(n));
132
for (i = NCH(n); --i >= 0; )
133
freechildren(CHILD(n, i));
134
if (n->n_child != NULL)
135
PyObject_FREE(n->n_child);
137
PyObject_FREE(STR(n));