Coverage Report

Created: 2025-07-11 07:00

/src/logging-log4cxx/src/main/cpp/pool.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/logstring.h>
19
#include <log4cxx/helpers/pool.h>
20
#include <apr_strings.h>
21
#include <log4cxx/helpers/exception.h>
22
#include <apr_pools.h>
23
#include <assert.h>
24
#if !defined(LOG4CXX)
25
  #define LOG4CXX 1
26
#endif
27
#include <log4cxx/helpers/aprinitializer.h>
28
29
using namespace LOG4CXX_NS::helpers;
30
using namespace LOG4CXX_NS;
31
32
33
2.90k
Pool::Pool() : pool(0), release(true)
34
2.90k
{
35
2.90k
}
36
37
0
Pool::Pool(apr_pool_t* p, bool release1) : pool(p), release(release1)
38
0
{
39
0
  assert(p != NULL);
40
0
}
41
42
Pool::~Pool()
43
2.90k
{
44
2.90k
  if (pool && release)
45
1
  {
46
1
    apr_pool_destroy(pool);
47
1
  }
48
2.90k
}
49
50
void Pool::setPool()
51
1
{
52
1
  apr_status_t stat = apr_pool_create(&pool, APRInitializer::getRootPool());
53
54
1
  if (stat != APR_SUCCESS)
55
0
  {
56
0
    throw PoolException(stat);
57
0
  }
58
1
}
59
60
apr_pool_t* Pool::getAPRPool()
61
1
{
62
1
  if (!pool)
63
1
    setPool();
64
1
  return pool;
65
1
}
66
67
apr_pool_t* Pool::create()
68
0
{
69
0
  if (!pool)
70
0
    setPool();
71
0
  apr_pool_t* child;
72
0
  apr_status_t stat = apr_pool_create(&child, pool);
73
74
0
  if (stat != APR_SUCCESS)
75
0
  {
76
0
    throw PoolException(stat);
77
0
  }
78
79
0
  return child;
80
0
}
81
82
void* Pool::palloc(size_t size)
83
0
{
84
0
  if (!pool)
85
0
    setPool();
86
0
  return apr_palloc(pool, size);
87
0
}
88
89
char* Pool::pstralloc(size_t size)
90
0
{
91
0
  return (char*) palloc(size);
92
0
}
93
94
char* Pool::itoa(int n)
95
0
{
96
0
  if (!pool)
97
0
    setPool();
98
0
  return apr_itoa(pool, n);
99
0
}
100
101
char* Pool::pstrndup(const char* s, size_t len)
102
0
{
103
0
  if (!pool)
104
0
    setPool();
105
0
  return apr_pstrndup(pool, s, len);
106
0
}
107
108
char* Pool::pstrdup(const char* s)
109
0
{
110
0
  if (!pool)
111
0
    setPool();
112
0
  return apr_pstrdup(pool, s);
113
0
}
114
115
char* Pool::pstrdup(const std::string& s)
116
0
{
117
0
  if (!pool)
118
0
    setPool();
119
0
  return apr_pstrndup(pool, s.data(), s.length());
120
0
}