OSDN Git Service

* changed feature.
[modchxj/mod_chxj.git] / src / qs_malloc.c
1 /*
2  * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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 #include <stdio.h>
18 #include "apr_pools.h"
19 #include "qs_log.h"
20 #include "qs_malloc.h"
21
22 /**
23  * Init
24  */
25 void
26 qs_init_malloc(Doc *doc) 
27 {
28   apr_status_t rtn;
29
30   rtn = apr_allocator_create(&(doc->allocator));
31   if (rtn != APR_SUCCESS) {
32     QX_LOGGER_FATAL("Out Of Memory");
33   }
34   rtn = apr_pool_create_ex(&(doc->pool), NULL, NULL, doc->allocator);
35   if (rtn != APR_SUCCESS) {
36     QX_LOGGER_FATAL("Out Of Memory");
37   }
38
39   doc->do_init_flag = 1;
40 }
41
42
43
44
45
46 void
47 qs_all_free(Doc *doc, const char *UNUSED(fname), int UNUSED(line)) 
48 {
49   if (doc->do_init_flag) {
50     apr_pool_destroy(doc->pool);
51
52     apr_allocator_destroy(doc->allocator);
53     doc->do_init_flag = 0;
54   }
55 }
56
57
58 #if HAVE_MALLOC == 0
59 #undef malloc
60
61 #include <sys/types.h>
62
63 void *malloc ();
64
65 void *rpl_malloc(size_t n) { if (n == 0) n = 1; return malloc (n); }
66 #endif
67 /*
68  * vim:ts=2 et
69  */