rbb 99/11/24 14:30:20
Modified: src/lib/apr/include apr_lib.h
src/lib/apr/lib apr_pools.c
src/lib/apr/misc/unix misc.h start.c
Log:
Deal with pool function failures in a clean way. I need to look at how we
are dealing with this in APR more closely. Currently, I just passed NULL
for the initial allocation. This means we get an error back in ap_initialize.
I think this is okay, but I wanted to get this change in because of all the
discussion about it, and I am stopping work for the day. I'll look at this
more tomorrow or Friday.
Revision Changes Path
1.17 +1 -1 apache-2.0/src/lib/apr/include/apr_lib.h
Index: apr_lib.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_lib.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- apr_lib.h 1999/11/23 13:46:54 1.16
+++ apr_lib.h 1999/11/24 22:30:01 1.17
@@ -299,7 +299,7 @@
/*
* APR memory structure manipulators (pools, tables, and arrays).
*/
-API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p);
+API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p, int (*apr_abort)(int
retcode));
API_EXPORT(void) ap_clear_pool(struct context_t *p);
API_EXPORT(void) ap_destroy_pool(struct context_t *p);
API_EXPORT(long) ap_bytes_in_pool(ap_pool_t *p);
1.22 +32 -22 apache-2.0/src/lib/apr/lib/apr_pools.c
Index: apr_pools.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/lib/apr_pools.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- apr_pools.c 1999/11/23 21:22:47 1.21
+++ apr_pools.c 1999/11/24 22:30:06 1.22
@@ -201,6 +201,17 @@
} h;
};
+#define APR_ABORT(conditional, retcode, func, str) \
+ if (conditional) { \
+ if (func == NULL) { \
+ return NULL; \
+ } \
+ else { \
+ fprintf(stderr, "%s", str);
+ func(retcode); \
+ } \
+ }
+
/*
* Static cells for managing our internal synchronisation.
*/
@@ -250,7 +261,7 @@
* malloc() to provide aligned memory.
*/
-static union block_hdr *malloc_block(int size)
+static union block_hdr *malloc_block(int size, int (*apr_abort)(int retcode))
{
union block_hdr *blok;
@@ -267,9 +278,8 @@
#endif /* ALLOC_STATS */
blok = (union block_hdr *) malloc(size + sizeof(union block_hdr));
- if (blok == NULL) {
- return NULL;
- }
+ APR_ABORT(blok == NULL, APR_ENOMEM, (*apr_abort)
+ "Ouch! malloc failed in malloc_block()\n");
debug_fill(blok, size + sizeof(union block_hdr));
blok->h.next = NULL;
blok->h.first_avail = (char *) (blok + 1);
@@ -298,6 +308,7 @@
"at the end of a block!\n");
while (free_blk) {
if (free_blk == blok) {
+ fprintf(stderr, "Ouch! Freeing free block\n");
abort();
exit(1);
}
@@ -394,7 +405,7 @@
* if necessary. Must be called with alarms blocked.
*/
-static union block_hdr *new_block(int min_size)
+static union block_hdr *new_block(int min_size, int (*apr_abort)(int
retcode))
{
union block_hdr **lastptr = &block_freelist;
union block_hdr *blok = block_freelist;
@@ -422,7 +433,7 @@
min_size += BLOCK_MINFREE;
blok = malloc_block((min_size > BLOCK_MINALLOC)
- ? min_size : BLOCK_MINALLOC);
+ ? min_size : BLOCK_MINALLOC, apr_abort);
return blok;
}
@@ -468,7 +479,7 @@
#define POOL_HDR_CLICKS (1 + ((sizeof(struct ap_pool_t) - 1) / CLICK_SZ))
#define POOL_HDR_BYTES (POOL_HDR_CLICKS * CLICK_SZ)
-API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p)
+API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p, int (*apr_abort)(int
retcode))
{
union block_hdr *blok;
ap_pool_t *new_pool;
@@ -477,7 +488,7 @@
ap_lock(alloc_mutex);
- blok = new_block(POOL_HDR_BYTES);
+ blok = new_block(POOL_HDR_BYTES, apr_abort);
new_pool = (ap_pool_t *) blok->h.first_avail;
blok->h.first_avail += POOL_HDR_BYTES;
#ifdef POOL_DEBUG
@@ -545,7 +556,7 @@
ap_create_lock(&spawn_mutex, APR_MUTEX, APR_INTRAPROCESS,
NULL, NULL);
- permanent_pool = ap_make_sub_pool(NULL);
+ permanent_pool = ap_make_sub_pool(NULL, NULL);
#ifdef ALLOC_STATS
atexit(dump_stats);
#endif
@@ -658,7 +669,7 @@
/* Find the pool that ts belongs to, return NULL if it doesn't
* belong to any pool.
*/
-API_EXPORT(ap_pool_t *) ap_find_pool(const void *ts)
+API_EXPORT(ap_pool_t *) ap_find_pool(const void *ts, int (apr_abort)(int
retcode))
{
const char *s = ts;
union block_hdr **pb;
@@ -671,12 +682,11 @@
/* consider stuff on the stack to also be in the NULL pool...
* XXX: there's cases where we don't want to assume this
*/
- if ((stack_direction == -1 && is_ptr_in_range(s, &ts, known_stack_point))
- || (stack_direction == 1
- && is_ptr_in_range(s, known_stack_point, &ts))) {
- abort();
- return NULL;
- }
+ APR_ABORT((stack_direction == -1 &&
+ is_ptr_in_range(s, &ts, known_stack_point)) ||
+ (stack_direction == 1 &&
+ is_ptr_in_range(s, known_stack_point, &ts)), 1, apr_abort,
+ "Ouch! find_pool() called on pointer in a free block\n");
ap_block_alarms();
/* search the global_block_list */
for (pb = &global_block_list; *pb; pb = &b->h.global_next) {
@@ -728,14 +738,14 @@
* instead. This is a guarantee by the caller that sub will not
* be destroyed before p is.
*/
-API_EXPORT(void) ap_pool_join(ap_pool_t *p, ap_pool_t *sub)
+API_EXPORT(void) ap_pool_join(ap_pool_t *p, ap_pool_t *sub,
+ int (*apr_abort)(int retcode))
{
union block_hdr *b;
/* We could handle more general cases... but this is it for now. */
- if (sub->parent != p) {
- abort();
- }
+ APR_ABORT(sub->parent != p, 1, apr_abort,
+ "pool_join: p is not a parent of sub\n");
ap_block_alarms();
while (p->joined) {
p = p->joined;
@@ -830,7 +840,7 @@
ap_lock(alloc_mutex);
- blok = new_block(size);
+ blok = new_block(size, c->apr_abort);
a->last->h.next = blok;
a->last = blok;
#ifdef POOL_DEBUG
@@ -974,7 +984,7 @@
/* must try another blok */
ap_lock(alloc_mutex);
- nblok = new_block(2 * cur_len);
+ nblok = new_block(2 * cur_len, NULL);
ap_unlock(alloc_mutex);
memcpy(nblok->h.first_avail, blok->h.first_avail, cur_len);
ps->vbuff.curpos = nblok->h.first_avail + cur_len;
1.5 +1 -0 apache-2.0/src/lib/apr/misc/unix/misc.h
Index: misc.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/misc.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- misc.h 1999/11/20 22:05:17 1.4
+++ misc.h 1999/11/24 22:30:09 1.5
@@ -71,6 +71,7 @@
struct context_t {
struct ap_pool_t *pool;
datastruct *prog_data;
+ int (*apr_abort)(int retcode);
};
#endif /* ! MISC_H */
1.13 +12 -1 apache-2.0/src/lib/apr/misc/unix/start.c
Index: start.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/start.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- start.c 1999/11/04 07:26:21 1.12
+++ start.c 1999/11/24 22:30:09 1.13
@@ -82,7 +82,7 @@
ap_pool_t *pool;
if (cont) {
- pool = ap_make_sub_pool(cont->pool);
+ pool = ap_make_sub_pool(cont->pool, cont->apr_abort);
}
else {
pool = ap_init_alloc();;
@@ -96,6 +96,7 @@
new->pool = pool;
new->prog_data = NULL;
+ new->apr_abort = NULL;
*newcont = new;
return APR_SUCCESS;
@@ -207,5 +208,15 @@
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
#endif
return APR_SUCCESS;
+}
+
+ap_status_t ap_set_abort(int (*apr_abort)(int retcode), struct context_t
*cont)
+{
+ if (cont == NULL) {
+ return APR_ENOCONT;
+ }
+ else {
+ cont->apr_abort = apr_abort;
+ }
}