Mercurial > cpython-lru_cache-weakref
annotate Python/pyarena.c @ 37034:fff4eecdef45 legacy-trunk
Fix a leak that would happen under error conditions (found by Coverty).
| author | Thomas Heller <theller@ctypes.org> |
|---|---|
| date | Thu, 16 Mar 2006 20:02:36 +0000 |
| parents | 54754f0d25c7 |
| children | c9a6273775b5 f731859e9b3b |
| rev | line source |
|---|---|
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
1 #include "Python.h" |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
2 #include "pyarena.h" |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
3 |
|
36813
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
4 /* A simple arena block structure. |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
5 |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
6 Measurements with standard library modules suggest the average |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
7 allocation is about 20 bytes and that most compiles use a single |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
8 block. |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
9 */ |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
10 |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
11 #define DEFAULT_BLOCK_SIZE 8192 |
|
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
12 typedef struct _block { |
|
36813
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
13 /* Total number of bytes owned by this block available to pass out. |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
14 * Read-only after initialization. The first such byte starts at |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
15 * ab_mem. |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
16 */ |
| 36720 | 17 size_t ab_size; |
|
36813
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
18 |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
19 /* Total number of bytes already passed out. The next byte available |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
20 * to pass out starts at ab_mem + ab_offset. |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
21 */ |
| 36720 | 22 size_t ab_offset; |
|
36813
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
23 |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
24 /* An arena maintains a singly-linked, NULL-terminated list of |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
25 * all blocks owned by the arena. These are linked via the |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
26 * ab_next member. |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
27 */ |
| 36720 | 28 struct _block *ab_next; |
|
36813
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
29 |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
30 /* Pointer to the first allocatable byte owned by this block. Read- |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
31 * only after initialization. |
|
54754f0d25c7
Document the purpose of the struct _block members.
Tim Peters <tim.peters@gmail.com>
parents:
36812
diff
changeset
|
32 */ |
| 36720 | 33 void *ab_mem; |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
34 } block; |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
35 |
|
36724
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
36 /* The arena manages two kinds of memory, blocks of raw memory |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
37 and a list of PyObject* pointers. PyObjects are decrefed |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
38 when the arena is freed. |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
39 */ |
|
36808
b1a3c2238f97
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
36765
diff
changeset
|
40 |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
41 struct _arena { |
| 36720 | 42 block *a_head; |
| 43 block *a_cur; | |
|
36724
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
44 PyObject *a_objects; |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
45 #if defined(Py_DEBUG) |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
46 /* Debug output */ |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
47 size_t total_allocs; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
48 size_t total_size; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
49 size_t total_blocks; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
50 size_t total_block_size; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
51 size_t total_big_blocks; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
52 #endif |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
53 }; |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
54 |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
55 static block * |
|
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
56 block_new(size_t size) |
|
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
57 { |
|
36808
b1a3c2238f97
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
36765
diff
changeset
|
58 /* Allocate header and block as one unit. |
| 36720 | 59 ab_mem points just past header. */ |
| 60 block *b = (block *)malloc(sizeof(block) + size); | |
| 61 if (!b) | |
| 62 return NULL; | |
| 63 b->ab_size = size; | |
| 64 b->ab_mem = (void *)(b + 1); | |
| 65 b->ab_next = NULL; | |
| 66 b->ab_offset = 0; | |
| 67 return b; | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
68 } |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
69 |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
70 static void |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
71 block_free(block *b) { |
| 36720 | 72 while (b) { |
| 73 block *next = b->ab_next; | |
| 74 free(b); | |
| 75 b = next; | |
| 76 } | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
77 } |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
78 |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
79 static void * |
|
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
80 block_alloc(block *b, size_t size) |
|
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
81 { |
| 36720 | 82 void *p; |
| 83 assert(b); | |
| 84 if (b->ab_offset + size > b->ab_size) { | |
| 85 /* If we need to allocate more memory than will fit in | |
| 86 the default block, allocate a one-off block that is | |
| 87 exactly the right size. */ | |
| 88 /* TODO(jhylton): Think about space waste at end of block */ | |
| 89 block *new = block_new( | |
| 90 size < DEFAULT_BLOCK_SIZE ? | |
| 91 DEFAULT_BLOCK_SIZE : size); | |
| 92 if (!new) | |
| 93 return NULL; | |
| 94 assert(!b->ab_next); | |
| 95 b->ab_next = new; | |
| 96 b = new; | |
| 97 } | |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
98 |
| 36720 | 99 assert(b->ab_offset + size <= b->ab_size); |
| 100 p = (void *)(((char *)b->ab_mem) + b->ab_offset); | |
| 101 b->ab_offset += size; | |
| 102 return p; | |
|
36716
71d873054d29
Real arena implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36084
diff
changeset
|
103 } |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
104 |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
105 PyArena * |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
106 PyArena_New() |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
107 { |
| 36720 | 108 PyArena* arena = (PyArena *)malloc(sizeof(PyArena)); |
| 109 if (!arena) | |
| 110 return NULL; | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
111 |
| 36720 | 112 arena->a_head = block_new(DEFAULT_BLOCK_SIZE); |
| 113 arena->a_cur = arena->a_head; | |
|
36724
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
114 if (!arena->a_head) { |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
115 free((void *)arena); |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
116 return NULL; |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
117 } |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
118 arena->a_objects = PyList_New(0); |
|
36724
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
119 if (!arena->a_objects) { |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
120 block_free(arena->a_head); |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
121 free((void *)arena); |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
122 return NULL; |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
123 } |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
124 #if defined(Py_DEBUG) |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
125 arena->total_allocs = 0; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
126 arena->total_size = 0; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
127 arena->total_blocks = 1; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
128 arena->total_block_size = DEFAULT_BLOCK_SIZE; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
129 arena->total_big_blocks = 0; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
130 #endif |
| 36720 | 131 return arena; |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
132 } |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
133 |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
134 void |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
135 PyArena_Free(PyArena *arena) |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
136 { |
| 36720 | 137 assert(arena); |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
138 #if defined(Py_DEBUG) |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
139 /* |
|
36808
b1a3c2238f97
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
36765
diff
changeset
|
140 fprintf(stderr, |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
141 "alloc=%d size=%d blocks=%d block_size=%d big=%d objects=%d\n", |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
142 arena->total_allocs, arena->total_size, arena->total_blocks, |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
143 arena->total_block_size, arena->total_big_blocks, |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
144 PyList_Size(arena->a_objects)); |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
145 */ |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
146 #endif |
| 36720 | 147 block_free(arena->a_head); |
|
36724
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
148 assert(arena->a_objects->ob_refcnt == 1); |
|
5f3822c2e731
Use simple PyList to implement list of PyObject pointers
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36720
diff
changeset
|
149 Py_DECREF(arena->a_objects); |
| 36720 | 150 free(arena); |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
151 } |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
152 |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
153 void * |
|
36808
b1a3c2238f97
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
36765
diff
changeset
|
154 PyArena_Malloc(PyArena *arena, size_t size) |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
155 { |
| 36720 | 156 void *p = block_alloc(arena->a_cur, size); |
| 157 if (!p) | |
| 158 return NULL; | |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
159 #if defined(Py_DEBUG) |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
160 arena->total_allocs++; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
161 arena->total_size += size; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
162 #endif |
| 36720 | 163 /* Reset cur if we allocated a new block. */ |
| 164 if (arena->a_cur->ab_next) { | |
| 165 arena->a_cur = arena->a_cur->ab_next; | |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
166 #if defined(Py_DEBUG) |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
167 arena->total_blocks++; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
168 arena->total_block_size += arena->a_cur->ab_size; |
|
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
169 if (arena->a_cur->ab_size > DEFAULT_BLOCK_SIZE) |
|
36812
1d055ebd8322
Added words about what PyArena_Malloc() does.
Tim Peters <tim.peters@gmail.com>
parents:
36808
diff
changeset
|
170 ++arena->total_big_blocks; |
|
36728
f2a895d33a5c
Add some stats collection in debugging mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
36724
diff
changeset
|
171 #endif |
| 36720 | 172 } |
| 173 return p; | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
174 } |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
175 |
|
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
176 int |
|
36808
b1a3c2238f97
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
36765
diff
changeset
|
177 PyArena_AddPyObject(PyArena *arena, PyObject *obj) |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
178 { |
| 36765 | 179 int r = PyList_Append(arena->a_objects, obj); |
| 180 if (r >= 0) { | |
| 181 Py_DECREF(obj); | |
| 182 } | |
| 183 return r; | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
184 } |
