~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

« back to all changes in this revision

Viewing changes to src/lib/mempool-alloconly.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-28 08:45:43 UTC
  • mfrom: (1.10.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060628084543-pc6v7oikzlvnlnu3
Tags: 1.0.beta9-1ubuntu1
* Merge from debian unstable, resolved minor conflicts.
* debian/control: Removed unnecessary build dependency ssl-cert, add it as
  dovecot-common dependency.
* Remove debian/patches/prohibit_.._mbox_mask.dpatch, upstream now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
        struct pool pool;
19
19
        int refcount;
20
20
 
 
21
        struct pool_block *block;
 
22
#ifdef DEBUG
 
23
        const char *name;
21
24
        size_t base_size;
22
 
        struct pool_block *block;
23
 
#ifdef DEBUG
24
 
        const char *name;
25
25
#endif
26
26
};
27
27
 
39
39
#define POOL_BLOCK_DATA(block) \
40
40
        ((char *) (block) + SIZEOF_POOLBLOCK)
41
41
 
 
42
#define DEFAULT_BASE_SIZE MEM_ALIGN(sizeof(struct alloconly_pool))
 
43
 
42
44
static const char *pool_alloconly_get_name(pool_t pool);
43
45
static void pool_alloconly_ref(pool_t pool);
44
46
static void pool_alloconly_unref(pool_t *pool);
69
71
        FALSE
70
72
};
71
73
 
 
74
#ifdef DEBUG
 
75
static void check_nuls(struct pool_block *block)
 
76
{
 
77
        const char *data = POOL_BLOCK_DATA(block);
 
78
        size_t i;
 
79
 
 
80
        for (i = block->size - block->left; i < block->size; i++) {
 
81
                if (data[i] != '\0')
 
82
                        i_unreached();
 
83
        }
 
84
        if (block->prev != NULL)
 
85
                check_nuls(block->prev);
 
86
}
 
87
#endif
 
88
 
72
89
pool_t pool_alloconly_create(const char *name __attr_unused__, size_t size)
73
90
{
74
91
        struct alloconly_pool apool, *new_apool;
92
109
        *new_apool = apool;
93
110
#ifdef DEBUG
94
111
        new_apool->name = p_strdup(&new_apool->pool, name);
95
 
#endif
96
112
 
97
113
        /* set base_size so p_clear() doesn't trash alloconly_pool structure. */
98
114
        new_apool->base_size = new_apool->block->size - new_apool->block->left;
99
115
        new_apool->block->last_alloc_size = 0;
 
116
#endif
100
117
 
101
118
        return &new_apool->pool;
102
119
}
270
287
{
271
288
        struct alloconly_pool *apool = (struct alloconly_pool *) pool;
272
289
        struct pool_block *block;
273
 
        size_t avail_size;
 
290
        size_t base_size, avail_size;
 
291
 
 
292
#ifdef DEBUG
 
293
        check_nuls(apool->block);
 
294
#endif
274
295
 
275
296
        /* destroy all blocks but the oldest, which contains the
276
297
           struct alloconly_pool allocation. */
287
308
        }
288
309
 
289
310
        /* clear the first block */
290
 
        avail_size = apool->block->size - apool->base_size;
291
 
        memset(PTR_OFFSET(POOL_BLOCK_DATA(apool->block), apool->base_size), 0,
 
311
#ifdef DEBUG
 
312
        base_size = apool->base_size;
 
313
#else
 
314
        base_size = DEFAULT_BASE_SIZE;
 
315
#endif
 
316
        avail_size = apool->block->size - base_size;
 
317
        memset(PTR_OFFSET(POOL_BLOCK_DATA(apool->block), base_size), 0,
292
318
               avail_size - apool->block->left);
293
319
        apool->block->left = avail_size;
294
320
        apool->block->last_alloc_size = 0;