diff options
author | Yann Ylavic <ylavic@apache.org> | 2017-03-23 21:34:25 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2017-03-23 21:34:25 +0000 |
commit | b8deb32e55fd4777a50d6c667969dbc64da52e3c (patch) | |
tree | b4dde15377f8035de11b584372a53d50caac1a79 /memory | |
parent | 0e96cf8c2d256c9d5a25ac1541f1a6e9803aa093 (diff) | |
download | apr-b8deb32e55fd4777a50d6c667969dbc64da52e3c.tar.gz |
apr_allocator: Provide apr_allocator_align() to get the true size that
would be allocated for the given size (including the header and alignment).
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1788334 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'memory')
-rw-r--r-- | memory/unix/apr_pools.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c index 138180b77..784280f2c 100644 --- a/memory/unix/apr_pools.c +++ b/memory/unix/apr_pools.c @@ -236,6 +236,30 @@ APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator, } static APR_INLINE +apr_size_t allocator_align(apr_size_t in_size) +{ + apr_size_t size = in_size; + + /* Round up the block size to the next boundary, but always + * allocate at least a certain size (MIN_ALLOC). + */ + size = APR_ALIGN(size + APR_MEMNODE_T_SIZE, BOUNDARY_SIZE); + if (size < in_size) { + return 0; + } + if (size < MIN_ALLOC) { + size = MIN_ALLOC; + } + + return size; +} + +APR_DECLARE(apr_size_t) apr_allocator_align(apr_size_t size) +{ + return allocator_align(size); +} + +static APR_INLINE apr_memnode_t *allocator_alloc(apr_allocator_t *allocator, apr_size_t in_size) { apr_memnode_t *node, **ref; @@ -245,12 +269,10 @@ apr_memnode_t *allocator_alloc(apr_allocator_t *allocator, apr_size_t in_size) /* Round up the block size to the next boundary, but always * allocate at least a certain size (MIN_ALLOC). */ - size = APR_ALIGN(in_size + APR_MEMNODE_T_SIZE, BOUNDARY_SIZE); - if (size < in_size) { + size = allocator_align(in_size); + if (!size) { return NULL; } - if (size < MIN_ALLOC) - size = MIN_ALLOC; /* Find the index for this node size by * dividing its size by the boundary size |