Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/data-stack.c @ 4891:6ab2712f1a93 HEAD
Only imap binary was actually working.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 10 Dec 2006 14:35:02 +0200 |
parents | 65b56dd915cb |
children | 9e86dbe68663 |
rev | line source |
---|---|
1741
9df02b1533b3
Removed most of the license comments from src/lib/*.c. It's just fine to
Timo Sirainen <tss@iki.fi>
parents:
1320
diff
changeset
|
1 /* Copyright (c) 2002-2003 Timo Sirainen */ |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
798
diff
changeset
|
3 /* @UNSAFE: whole file */ |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
798
diff
changeset
|
4 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "lib.h" |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "data-stack.h" |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include <stdlib.h> |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
10 #ifdef HAVE_GC_GC_H |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
11 # include <gc/gc.h> |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
12 #elif defined (HAVE_GC_H) |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
13 # include <gc.h> |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
14 #endif |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
15 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 /* Use malloc() and free() for all memory allocations. Useful for debugging |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 memory corruption. */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 /* #define DISABLE_DATA_STACK */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 #ifndef DISABLE_DATA_STACK |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 /* Initial stack size - this should be kept in a size that doesn't exceed |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 in a normal use to avoid extra malloc()ing. */ |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
751
diff
changeset
|
24 #ifdef DEBUG |
798
1c67ec58f0a1
Use a bit larger initial data stack size when DEBUG is set - current one is
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
25 # define INITIAL_STACK_SIZE (1024*10) |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
751
diff
changeset
|
26 #else |
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
751
diff
changeset
|
27 # define INITIAL_STACK_SIZE (1024*32) |
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
751
diff
changeset
|
28 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
30 #ifdef DEBUG |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
31 # define CLEAR_CHR 0xde |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
32 #elif defined(USE_GC) |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
33 # define CLEAR_CHR 0 |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
34 #endif |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
35 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
36 struct stack_block { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
37 struct stack_block *next; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 size_t size, left; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 /* unsigned char data[]; */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 }; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
43 #define SIZEOF_MEMBLOCK MEM_ALIGN(sizeof(struct stack_block)) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 #define STACK_BLOCK_DATA(block) \ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 ((char *) (block) + SIZEOF_MEMBLOCK) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 /* current_frame_block contains last t_push()ed frames. After that new |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
49 stack_frame_block is created and it's ->prev is set to |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
50 current_frame_block. */ |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 #define BLOCK_FRAME_COUNT 32 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
53 struct stack_frame_block { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
54 struct stack_frame_block *prev; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
56 struct stack_block *block[BLOCK_FRAME_COUNT]; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 size_t block_space_used[BLOCK_FRAME_COUNT]; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 size_t last_alloc_size[BLOCK_FRAME_COUNT]; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 }; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
61 unsigned int data_stack_frame = 0; |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
62 |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
63 static int frame_pos = BLOCK_FRAME_COUNT-1; /* in current_frame_block */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
64 static struct stack_frame_block *current_frame_block; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
65 static struct stack_frame_block *unused_frame_blocks; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
67 static struct stack_block *current_block; /* block now used for allocation */ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
68 static struct stack_block *unused_block; /* largest unused block is kept here */ |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
70 static struct stack_block *last_buffer_block; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 static size_t last_buffer_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
73 unsigned int t_push(void) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
75 struct stack_frame_block *frame_block; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 frame_pos++; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 if (frame_pos == BLOCK_FRAME_COUNT) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 /* frame block full */ |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
80 if (data_stack_frame == 0) { |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
81 /* kludgy, but allow this before initialization */ |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
82 frame_pos = 0; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
83 data_stack_init(); |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
84 return t_push(); |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
85 } |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
86 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 frame_pos = 0; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 if (unused_frame_blocks == NULL) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 /* allocate new block */ |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
90 #ifndef USE_GC |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
91 frame_block = calloc(sizeof(*frame_block), 1); |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
92 #else |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
93 frame_block = GC_malloc(sizeof(*frame_block)); |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
94 #endif |
3198
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
95 if (frame_block == NULL) { |
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
96 i_fatal_status(FATAL_OUTOFMEM, |
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
97 "t_push(): Out of memory"); |
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
98 } |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 } else { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 /* use existing unused frame_block */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 frame_block = unused_frame_blocks; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 unused_frame_blocks = unused_frame_blocks->prev; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 frame_block->prev = current_frame_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 current_frame_block = frame_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 /* mark our current position */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 current_frame_block->block[frame_pos] = current_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 current_frame_block->block_space_used[frame_pos] = current_block->left; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 current_frame_block->last_alloc_size[frame_pos] = 0; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
114 return data_stack_frame++; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
117 #ifndef USE_GC |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
118 static void free_blocks(struct stack_block *block) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 { |
1320
e9e08440df77
When data stack grew larger than two blocks, t_pop()ing crashed when trying
Timo Sirainen <tss@iki.fi>
parents:
1032
diff
changeset
|
120 struct stack_block *next; |
e9e08440df77
When data stack grew larger than two blocks, t_pop()ing crashed when trying
Timo Sirainen <tss@iki.fi>
parents:
1032
diff
changeset
|
121 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 /* free all the blocks, except if any of them is bigger than |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 unused_block, replace it */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 while (block != NULL) { |
1320
e9e08440df77
When data stack grew larger than two blocks, t_pop()ing crashed when trying
Timo Sirainen <tss@iki.fi>
parents:
1032
diff
changeset
|
125 next = block->next; |
e9e08440df77
When data stack grew larger than two blocks, t_pop()ing crashed when trying
Timo Sirainen <tss@iki.fi>
parents:
1032
diff
changeset
|
126 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 if (unused_block == NULL || block->size > unused_block->size) { |
751
04e2c5774c3f
DEBUG: Don't send shrink messages, they could cause infinite loop.
Timo Sirainen <tss@iki.fi>
parents:
734
diff
changeset
|
128 free(unused_block); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 unused_block = block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 } else { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 free(block); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 |
1320
e9e08440df77
When data stack grew larger than two blocks, t_pop()ing crashed when trying
Timo Sirainen <tss@iki.fi>
parents:
1032
diff
changeset
|
134 block = next; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 } |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
137 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
139 unsigned int t_pop(void) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
141 struct stack_frame_block *frame_block; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 int popped_frame_pos; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 if (frame_pos < 0) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 i_panic("t_pop() called with empty stack"); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 /* update the current block */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 current_block = current_frame_block->block[frame_pos]; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 current_block->left = current_frame_block->block_space_used[frame_pos]; |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
150 #ifdef CLEAR_CHR |
548
797c5eb84267
DEBUG: when t_pop()ing, fill the free'd memory area with 0xde bytes.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
151 memset(STACK_BLOCK_DATA(current_block) + |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
152 (current_block->size - current_block->left), CLEAR_CHR, |
548
797c5eb84267
DEBUG: when t_pop()ing, fill the free'd memory area with 0xde bytes.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
153 current_block->left); |
797c5eb84267
DEBUG: when t_pop()ing, fill the free'd memory area with 0xde bytes.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
154 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 if (current_block->next != NULL) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 /* free unused blocks */ |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
157 #ifndef USE_GC |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 free_blocks(current_block->next); |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
159 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 current_block->next = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 popped_frame_pos = frame_pos; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 if (frame_pos > 0) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 frame_pos--; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 else { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 /* frame block is now unused, add it to unused list */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 frame_pos = BLOCK_FRAME_COUNT-1; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 frame_block = current_frame_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 current_frame_block = frame_block->prev; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 frame_block->prev = unused_frame_blocks; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 unused_frame_blocks = frame_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
177 return --data_stack_frame; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
180 static struct stack_block *mem_block_alloc(size_t min_size) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
182 struct stack_block *block; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 size_t prev_size, alloc_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 prev_size = current_block == NULL ? 0 : current_block->size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 alloc_size = nearest_power(prev_size + min_size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
188 #ifndef USE_GC |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 block = malloc(SIZEOF_MEMBLOCK + alloc_size); |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
190 #else |
4597 | 191 block = GC_malloc(SIZEOF_MEMBLOCK + alloc_size); |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
192 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 if (block == NULL) { |
3198
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
194 i_fatal_status(FATAL_OUTOFMEM, "mem_block_alloc(): " |
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
195 "Out of memory when allocating %"PRIuSIZE_T |
cb285bd5d8c9
If we run out of memory, exit with FATAL_OUTOFMEM status instead of dumping
Timo Sirainen <tss@iki.fi>
parents:
1992
diff
changeset
|
196 " bytes", alloc_size + SIZEOF_MEMBLOCK); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 block->size = alloc_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 block->next = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 return block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3232
diff
changeset
|
204 static void *t_malloc_real(size_t size, bool permanent) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
206 struct stack_block *block; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 void *ret; |
837
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
208 #ifdef DEBUG |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3232
diff
changeset
|
209 bool warn = FALSE; |
837
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
210 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
837
diff
changeset
|
212 if (size == 0 || size > SSIZE_T_MAX) |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
837
diff
changeset
|
213 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 |
1992
63e67430b580
allow using data stack without data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
1786
diff
changeset
|
215 if (data_stack_frame == 0) { |
63e67430b580
allow using data stack without data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
1786
diff
changeset
|
216 /* kludgy, but allow this before initialization */ |
63e67430b580
allow using data stack without data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
1786
diff
changeset
|
217 data_stack_init(); |
63e67430b580
allow using data stack without data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
1786
diff
changeset
|
218 } |
63e67430b580
allow using data stack without data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
1786
diff
changeset
|
219 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 /* reset t_buffer_get() mark - not really needed but makes it easier |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 to notice if t_malloc() is called between t_buffer_get() and |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 t_buffer_alloc() */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 last_buffer_block = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 /* allocate only aligned amount of memory so alignment comes |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 always properly */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 size = MEM_ALIGN(size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 |
402 | 229 /* used for t_try_realloc() */ |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 current_frame_block->last_alloc_size[frame_pos] = size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 if (current_block->left >= size) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 /* enough space in current block, use it */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 ret = STACK_BLOCK_DATA(current_block) + |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 (current_block->size - current_block->left); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 if (permanent) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 current_block->left -= size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 return ret; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 /* current block is full, see if we can use the unused_block */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 if (unused_block != NULL && unused_block->size >= size) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 block = unused_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 unused_block = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 } else { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 block = mem_block_alloc(size); |
728
883cda17d175
DEBUG: we get warnings when growing/shrinking data stack.
Timo Sirainen <tss@iki.fi>
parents:
548
diff
changeset
|
247 #ifdef DEBUG |
837
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
248 warn = TRUE; |
728
883cda17d175
DEBUG: we get warnings when growing/shrinking data stack.
Timo Sirainen <tss@iki.fi>
parents:
548
diff
changeset
|
249 #endif |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 block->left = block->size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 if (permanent) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 block->left -= size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 block->next = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 current_block->next = block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 current_block = block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
837
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
260 ret = STACK_BLOCK_DATA(current_block); |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
261 #ifdef DEBUG |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
262 if (warn) { |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
263 /* warn later, so that if i_warning() wants to allocate more |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
264 memory we don't go to infinite loop */ |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
265 i_warning("Growing data stack with: %"PRIuSIZE_T, block->size); |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
266 } |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
267 #endif |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
268 |
ec6dd72cb8e3
Use vsnprintf() always when possible, even if we went through the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
269 return ret; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 void *t_malloc(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 return t_malloc_real(size, TRUE); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 void *t_malloc0(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 void *mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 mem = t_malloc_real(size, TRUE); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 memset(mem, 0, size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 return mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3232
diff
changeset
|
286 bool t_try_realloc(void *mem, size_t size) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 size_t last_alloc_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
837
diff
changeset
|
290 if (size == 0 || size > SSIZE_T_MAX) |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
837
diff
changeset
|
291 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
837
diff
changeset
|
292 |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 last_alloc_size = current_frame_block->last_alloc_size[frame_pos]; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 /* see if we're trying to grow the memory we allocated last */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 if (STACK_BLOCK_DATA(current_block) + |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 (current_block->size - current_block->left - |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 last_alloc_size) == mem) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 /* yeah, see if we have space to grow */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 size = MEM_ALIGN(size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 if (current_block->left >= size - last_alloc_size) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 /* just shrink the available size */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 current_block->left -= size - last_alloc_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 current_frame_block->last_alloc_size[frame_pos] = size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 return TRUE; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 return FALSE; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 |
3232 | 312 size_t t_get_bytes_available(void) |
313 { | |
314 return current_block->left; | |
315 } | |
316 | |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 void *t_buffer_get(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 void *ret; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 ret = t_malloc_real(size, FALSE); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 last_buffer_size = size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 last_buffer_block = current_block; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 return ret; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 void *t_buffer_reget(void *buffer, size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 size_t old_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 void *new_buffer; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 old_size = last_buffer_size; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 if (size <= old_size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 return buffer; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 new_buffer = t_buffer_get(size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 if (new_buffer != buffer) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 memcpy(new_buffer, buffer, old_size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 return new_buffer; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 void t_buffer_alloc(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 i_assert(last_buffer_block != NULL); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 i_assert(last_buffer_size >= size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 i_assert(current_block->left >= size); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 /* we've already reserved the space, now we just mark it used */ |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 t_malloc_real(size, TRUE); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 void data_stack_init(void) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 { |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
356 if (data_stack_frame == 0) { |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
357 data_stack_frame = 1; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
358 |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
359 current_block = mem_block_alloc(INITIAL_STACK_SIZE); |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
360 current_block->left = current_block->size; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
361 current_block->next = NULL; |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
362 |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
363 current_frame_block = NULL; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
364 unused_frame_blocks = NULL; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
365 frame_pos = BLOCK_FRAME_COUNT-1; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
367 last_buffer_block = NULL; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
368 last_buffer_size = 0; |
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
369 } |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 t_push(); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 void data_stack_deinit(void) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 t_pop(); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 if (frame_pos != BLOCK_FRAME_COUNT-1) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 i_panic("Missing t_pop() call"); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
381 #ifndef USE_GC |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 while (unused_frame_blocks != NULL) { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
383 struct stack_frame_block *frame_block = unused_frame_blocks; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 unused_frame_blocks = unused_frame_blocks->prev; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
386 free(frame_block); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 free(current_block); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 free(unused_block); |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
391 #endif |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
392 unused_frame_blocks = NULL; |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
393 current_block = NULL; |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
394 unused_block = NULL; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 #else |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 |
1786
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
399 #ifdef USE_GC |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
400 # error No GC with disabled data stack |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
401 #endif |
49b6103dd2e0
Added support for Boehm GC. However it seems to be crashing for some reason
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
402 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
403 struct stack_frame { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
404 struct stack_frame *next; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
405 struct frame_alloc *allocs; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 }; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
408 struct frame_alloc { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
409 struct frame_alloc *next; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 void *mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 }; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
841
e3a979b1b55d
t_try_realloc() wasn't working right with DISABLE_DATA_STACK.
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
413 unsigned int data_stack_frame; |
e3a979b1b55d
t_try_realloc() wasn't working right with DISABLE_DATA_STACK.
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
414 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
415 static struct stack_frame *current_frame; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 static void *buffer_mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
418 unsigned int t_push(void) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
420 struct stack_frame *frame; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
422 frame = malloc(sizeof(struct stack_frame)); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
423 if (frame == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
424 i_panic("t_push(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 frame->allocs = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 |
402 | 427 frame->next = current_frame; |
428 current_frame = frame; | |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
429 return data_stack_frame++; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
432 unsigned int t_pop(void) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
434 struct stack_frame *frame; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
435 struct frame_alloc *alloc; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 |
402 | 437 frame = current_frame; |
438 current_frame = frame->next; | |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 while (frame->allocs != NULL) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 alloc = frame->allocs; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 frame->allocs = alloc->next; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 free(alloc->mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 free(alloc); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 free(frame); |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
449 return --data_stack_frame; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 static void add_alloc(void *mem) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
454 struct frame_alloc *alloc; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
456 alloc = malloc(sizeof(struct frame_alloc)); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
457 if (alloc == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
458 i_panic("add_alloc(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 alloc->mem = mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 alloc->next = current_frame->allocs; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 current_frame->allocs = alloc; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 if (buffer_mem != NULL) { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 free(buffer_mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 buffer_mem = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 void *t_malloc(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 void *mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 mem = malloc(size); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
474 if (mem == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
475 i_panic("t_malloc(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 add_alloc(mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 return mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 void *t_malloc0(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 void *mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 mem = calloc(size, 1); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
485 if (mem == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
486 i_panic("t_malloc0(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 add_alloc(mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 return mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3232
diff
changeset
|
491 bool t_try_realloc(void *mem __attr_unused__, size_t size __attr_unused__) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 return FALSE; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 void *t_buffer_get(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
497 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 buffer_mem = realloc(buffer_mem, size); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
499 if (buffer_mem == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
500 i_panic("t_buffer_get(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 return buffer_mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 void *t_buffer_reget(void *buffer, size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 i_assert(buffer == buffer_mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 buffer_mem = realloc(buffer_mem, size); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
509 if (buffer_mem == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
510 i_panic("t_buffer_reget(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 return buffer_mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 void t_buffer_alloc(size_t size) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 void *mem; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 i_assert(buffer_mem != NULL); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 |
402 | 520 mem = realloc(buffer_mem, size); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
521 if (mem == NULL) |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
402
diff
changeset
|
522 i_panic("t_buffer_alloc(): Out of memory"); |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 buffer_mem = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 add_alloc(mem); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 void data_stack_init(void) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 { |
1032
ea309e90c01a
Allow calling t_push() before data_stack_init().
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
530 data_stack_frame = 0; |
402 | 531 current_frame = NULL; |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 buffer_mem = NULL; |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
533 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
534 t_push(); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
536 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 void data_stack_deinit(void) |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 { |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 t_pop(); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
540 |
536
37893ed97492
changed t_push() and t_pop() to return unsigned int. added global
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
541 if (data_stack_frame != 0) |
399
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
542 i_panic("Missing t_pop() call"); |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 } |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
544 |
383503837741
s/temporary memory pool/data stack/ which is the correct name for it.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
545 #endif |