diff options
Diffstat (limited to 'src/regex/tre-mem.c')
-rw-r--r-- | src/regex/tre-mem.c | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/src/regex/tre-mem.c b/src/regex/tre-mem.c index d7bdd3db..86f809d4 100644 --- a/src/regex/tre-mem.c +++ b/src/regex/tre-mem.c @@ -1,21 +1,31 @@ /* tre-mem.c - TRE memory allocator - Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -31,6 +41,12 @@ #include "tre.h" +/* + This memory allocator is for allocating small memory blocks efficiently + in terms of memory overhead and execution speed. The allocated blocks + cannot be freed individually, only all at once. There can be multiple + allocators, though. +*/ /* Returns a new memory allocator or NULL if out of memory. */ tre_mem_t @@ -77,24 +93,9 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, if (mem->failed) { - DPRINT(("tre_mem_alloc: oops, called after failure?!\n")); return NULL; } -#ifdef MALLOC_DEBUGGING - if (!provided) - { - ptr = xmalloc(1); - if (ptr == NULL) - { - DPRINT(("tre_mem_alloc: xmalloc forced failure\n")); - mem->failed = 1; - return NULL; - } - xfree(ptr); - } -#endif /* MALLOC_DEBUGGING */ - if (mem->n < size) { /* We need more memory than is available in the current block. @@ -102,10 +103,8 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, tre_list_t *l; if (provided) { - DPRINT(("tre_mem_alloc: using provided block\n")); if (provided_block == NULL) { - DPRINT(("tre_mem_alloc: provided block was NULL\n")); mem->failed = 1; return NULL; } @@ -119,8 +118,6 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, block_size = size * 8; else block_size = TRE_MEM_BLOCK_SIZE; - DPRINT(("tre_mem_alloc: allocating new %d byte block\n", - block_size)); l = xmalloc(sizeof(*l)); if (l == NULL) { @@ -159,5 +156,3 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, return ptr; } - -/* EOF */ |