Mercurial > dovecot > original-hg > dovecot-1.2
view src/lib/mempool-unsafe-datastack.c @ 3749:194295062e5e HEAD
Added kqueue support. Patch by Vaclav Haisman.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 14 Dec 2005 20:51:52 +0200 |
parents | 6396b4c0a721 |
children | bf0a03691989 |
line wrap: on
line source
/* Copyright (c) 2002-2003 Timo Sirainen */ #include "lib.h" #include "mempool.h" #include <stdlib.h> static const char *pool_unsafe_data_stack_get_name(pool_t pool); static void pool_unsafe_data_stack_ref(pool_t pool); static void pool_unsafe_data_stack_unref(pool_t pool); static void *pool_unsafe_data_stack_malloc(pool_t pool, size_t size); static void pool_unsafe_data_stack_free(pool_t pool, void *mem); static void *pool_unsafe_data_stack_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size); static void pool_unsafe_data_stack_clear(pool_t pool); static size_t pool_unsafe_data_stack_get_max_easy_alloc_size(pool_t pool); static struct pool static_unsafe_data_stack_pool = { pool_unsafe_data_stack_get_name, pool_unsafe_data_stack_ref, pool_unsafe_data_stack_unref, pool_unsafe_data_stack_malloc, pool_unsafe_data_stack_free, pool_unsafe_data_stack_realloc, pool_unsafe_data_stack_clear, pool_unsafe_data_stack_get_max_easy_alloc_size, TRUE, TRUE }; pool_t unsafe_data_stack_pool = &static_unsafe_data_stack_pool; static const char *pool_unsafe_data_stack_get_name(pool_t pool __attr_unused__) { return "unsafe data stack"; } static void pool_unsafe_data_stack_ref(pool_t pool __attr_unused__) { } static void pool_unsafe_data_stack_unref(pool_t pool __attr_unused__) { } static void *pool_unsafe_data_stack_malloc(pool_t pool __attr_unused__, size_t size) { if (size == 0 || size > SSIZE_T_MAX) i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); return t_malloc0(size); } static void pool_unsafe_data_stack_free(pool_t pool __attr_unused__, void *mem __attr_unused__) { } static void *pool_unsafe_data_stack_realloc(pool_t pool __attr_unused__, void *mem, size_t old_size, size_t new_size) { void *new_mem; /* @UNSAFE */ if (new_size == 0 || new_size > SSIZE_T_MAX) i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size); if (mem == NULL) return pool_unsafe_data_stack_malloc(pool, new_size); if (old_size >= new_size) return mem; if (!t_try_realloc(mem, new_size)) { new_mem = t_malloc(new_size); memcpy(new_mem, mem, old_size); mem = new_mem; } memset((char *) mem + old_size, 0, new_size - old_size); return mem; } static void pool_unsafe_data_stack_clear(pool_t pool __attr_unused__) { } static size_t pool_unsafe_data_stack_get_max_easy_alloc_size(pool_t pool __attr_unused__) { return t_get_bytes_available(); }