#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <apr.h>
#include <apr_version.h>
#include <apr_general.h>
#include <apr_pools.h>
#include "svn_pools.h"
#include "pools.h"
#if APR_POOL_DEBUG
static const char SVN_FILE_LINE_UNDEFINED[] = "svn:<undefined>";
#endif
static int
abort_on_pool_failure(int retcode)
{
printf("libsvn: Out of memory - terminating application.\n");
#ifdef WIN32
if (retcode == APR_ENOMEM)
RaiseException(STATUS_NO_MEMORY, EXCEPTION_NONCONTINUABLE, 0, NULL);
#endif
abort();
return 0;
}
#if APR_POOL_DEBUG
#undef svn_pool_create_ex
#endif
#if !APR_POOL_DEBUG
apr_pool_t *
svn_pool_create_ex(apr_pool_t *parent_pool, apr_allocator_t *allocator)
{
apr_pool_t *pool;
apr_pool_create_ex(&pool, parent_pool, abort_on_pool_failure, allocator);
return pool;
}
apr_pool_t *
svn_pool_create_ex_debug(apr_pool_t *pool, apr_allocator_t *allocator,
const char *file_line)
{
return svn_pool_create_ex(pool, allocator);
}
#else
apr_pool_t *
svn_pool_create_ex_debug(apr_pool_t *parent_pool, apr_allocator_t *allocator,
const char *file_line)
{
apr_pool_t *pool;
apr_pool_create_ex_debug(&pool, parent_pool, abort_on_pool_failure,
allocator, file_line);
return pool;
}
apr_pool_t *
svn_pool_create_ex(apr_pool_t *pool, apr_allocator_t *allocator)
{
return svn_pool_create_ex_debug(pool, allocator, SVN_FILE_LINE_UNDEFINED);
}
#endif
apr_allocator_t *
svn_pool_create_allocator(svn_boolean_t thread_safe)
{
apr_allocator_t *allocator;
apr_pool_t *pool;
if (apr_allocator_create(&allocator))
abort_on_pool_failure(EXIT_FAILURE);
apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
pool = svn_pool_create_ex(NULL, allocator);
apr_allocator_owner_set(allocator, pool);
#if APR_POOL_DEBUG
apr_pool_tag (pool, "svn root pool");
#endif
#if APR_HAS_THREADS
if (thread_safe)
{
apr_thread_mutex_t *mutex;
apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool);
apr_allocator_mutex_set(allocator, mutex);
}
#endif
SVN_ERR_ASSERT_NO_RETURN(allocator != NULL);
return allocator;
}
#if !APR_VERSION_AT_LEAST(1,3,3)
#define apr_pool_create_unmanaged_ex apr_pool_create_core_ex
#endif
apr_pool_t *
svn_pool__create_unmanaged(svn_boolean_t thread_safe)
{
apr_pool_t *pool;
apr_pool_create_unmanaged_ex(&pool, abort_on_pool_failure,
svn_pool_create_allocator(thread_safe));
return pool;
}