apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject cvs commit: apr-util/xml apr_xml.c
Date Thu, 26 Apr 2001 21:29:02 GMT
gstein      01/04/26 14:29:02

  Modified:    include  apr_general.h apr_pools.h
               lib      apr_pools.c
               misc/unix start.c
               xml      apr_xml.c
  Log:
  *) Make the apr_pool_t structure private.
  *) rename apr_set_abort (in apr_general.h) to apr_pool_set_abort (in
     apr_pools.h)
  *) add apr_pool_get_abort (used in apr-util/xml/apr_xml.c)
  *) add apr_abortfunc_t type and use throughout
  *) some simplifications within apr_pools.c
  
  Revision  Changes    Path
  1.57      +0 -13     apr/include/apr_general.h
  
  Index: apr_general.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_general.h,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -u -r1.56 -r1.57
  --- apr_general.h	2001/02/26 04:38:22	1.56
  +++ apr_general.h	2001/04/26 21:28:56	1.57
  @@ -174,19 +174,6 @@
    */
   APR_DECLARE(void) apr_terminate(void);
   
  -/**
  - * Set the APR_ABORT function.
  - * @tip This is in for backwards compatability.  If the program using
  - *      APR wants APR to exit on a memory allocation error, then this
  - *      function should be called to set the function to use in order
  - *      to actually exit the program.  If this function is not called,
  - *      then APR will return an error and expect the calling program to
  - *      deal with the error accordingly.
  - * @deffunc apr_status_t apr_set_abort(int (*apr_abort)(int retcode), apr_pool_t *cont)
  - */
  -APR_DECLARE(apr_status_t) apr_set_abort(int (*apr_abort)(int retcode),
  -                                        apr_pool_t *cont);
  -
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.47      +21 -35    apr/include/apr_pools.h
  
  Index: apr_pools.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_pools.h,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -u -r1.46 -r1.47
  --- apr_pools.h	2001/04/17 10:48:55	1.46
  +++ apr_pools.h	2001/04/26 21:28:56	1.47
  @@ -89,46 +89,13 @@
    
   /*
   #define APR_POOL_DEBUG
  -#define ALLOC_USE_MALLOC
   */
   
   /** The fundamental pool type */
   typedef struct apr_pool_t apr_pool_t;
   
  -/** The memory allocation structure
  - */
  -struct apr_pool_t {
  -    /** The first block in this pool. */
  -    union block_hdr *first;
  -    /** The last block in this pool. */
  -    union block_hdr *last;
  -    /** The list of cleanups to run on pool cleanup. */
  -    struct cleanup *cleanups;
  -    /** A list of processes to kill when this pool is cleared */
  -    struct process_chain *subprocesses;
  -    /** The first sub_pool of this pool */
  -    struct apr_pool_t *sub_pools;
  -    /** The next sibling pool */
  -    struct apr_pool_t *sub_next;
  -    /** The previous sibling pool */
  -    struct apr_pool_t *sub_prev;
  -    /** The parent pool of this pool */
  -    struct apr_pool_t *parent;
  -    /** The first free byte in this pool */
  -    char *free_first_avail;
  -#ifdef ALLOC_USE_MALLOC
  -    /** The allocation list if using malloc */
  -    void *allocation_list;
  -#endif
  -#ifdef APR_POOL_DEBUG
  -    /** a list of joined pools */
  -    struct apr_pool_t *joined;
  -#endif
  -    /** A function to control how pools behave when they receive ENOMEM */
  -    int (*apr_abort)(int retcode);
  -    /** A place to hold user data associated with this pool */
  -    struct apr_hash_t *prog_data;
  -};
  +/** A function that is called when allocation fails. */
  +typedef int (*apr_abortfunc_t)(int retcode);
   
   /* pools have nested lifetimes -- sub_pools are destroyed when the
    * parent pool is cleared.  We allow certain liberties with operations
  @@ -224,6 +191,25 @@
    */
   APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newcont,
                                             apr_pool_t *cont);
  +
  +/**
  + * Set the function to be called when an allocation failure occurs.
  + * @tip If the program wants APR to exit on a memory allocation error,
  + *      then this function can be called to set the callback to use (for
  + *      performing cleanup and then exiting). If this function is not called,
  + *      then APR will return an error and expect the calling program to
  + *      deal with the error accordingly.
  + * @deffunc apr_status_t apr_pool_set_abort(apr_abortfunc_t abortfunc, apr_pool_t *pool)
  + */
  +APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
  +                                     apr_pool_t *pool);
  +
  +/**
  + * Get the abort function associated with the specified pool.
  + * @param pool The pool for retrieving the abort function.
  + * @deffunc apr_abortfunc_t apr_pool_get_abort(apr_pool_t *pool)
  + */
  +APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
   
   /**
    * Set the data associated with the current pool
  
  
  
  1.95      +71 -31    apr/lib/apr_pools.c
  
  Index: apr_pools.c
  ===================================================================
  RCS file: /home/cvs/apr/lib/apr_pools.c,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -u -r1.94 -r1.95
  --- apr_pools.c	2001/04/26 15:30:52	1.94
  +++ apr_pools.c	2001/04/26 21:28:58	1.95
  @@ -131,6 +131,7 @@
   /*
   #define ALLOC_DEBUG
   #define ALLOC_STATS
  +#define ALLOC_USE_MALLOC
   #define DEBUG_WITH_MPROTECT
   */
   
  @@ -171,6 +172,42 @@
   #endif
   
   
  +/** The memory allocation structure
  + */
  +struct apr_pool_t {
  +    /** The first block in this pool. */
  +    union block_hdr *first;
  +    /** The last block in this pool. */
  +    union block_hdr *last;
  +    /** The list of cleanups to run on pool cleanup. */
  +    struct cleanup *cleanups;
  +    /** A list of processes to kill when this pool is cleared */
  +    struct process_chain *subprocesses;
  +    /** The first sub_pool of this pool */
  +    struct apr_pool_t *sub_pools;
  +    /** The next sibling pool */
  +    struct apr_pool_t *sub_next;
  +    /** The previous sibling pool */
  +    struct apr_pool_t *sub_prev;
  +    /** The parent pool of this pool */
  +    struct apr_pool_t *parent;
  +    /** The first free byte in this pool */
  +    char *free_first_avail;
  +#ifdef ALLOC_USE_MALLOC
  +    /** The allocation list if using malloc */
  +    void *allocation_list;
  +#endif
  +#ifdef APR_POOL_DEBUG
  +    /** a list of joined pools */
  +    struct apr_pool_t *joined;
  +#endif
  +    /** A function to control how pools behave when they receive ENOMEM */
  +    int (*apr_abort)(int retcode);
  +    /** A place to hold user data associated with this pool */
  +    struct apr_hash_t *prog_data;
  +};
  +
  +
   /*****************************************************************
    *
    * Managing free storage blocks...
  @@ -207,16 +244,6 @@
       } 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.
  @@ -320,7 +347,7 @@
    * Get a completely new block from the system pool. Note that we rely on
    * malloc() to provide aligned memory.
    */
  -static union block_hdr *malloc_block(int size, int (*apr_abort)(int retcode))
  +static union block_hdr *malloc_block(int size, apr_abortfunc_t abortfunc)
   {
       union block_hdr *blok;
   
  @@ -337,8 +364,15 @@
   #endif /* ALLOC_STATS */
   
       blok = (union block_hdr *) DO_MALLOC(size + sizeof(union block_hdr));
  -    APR_ABORT(blok == NULL, APR_ENOMEM, apr_abort,
  -              "Ouch!  malloc failed in malloc_block()\n");
  +    if (blok == NULL) {
  +        /* ### keep this fprintf here? */
  +        fprintf(stderr, "Ouch!  malloc failed in malloc_block()\n");
  +        if (abortfunc != NULL) {
  +            (void) (*abortfunc)(APR_ENOMEM);
  +        }
  +        return NULL;
  +    }
  +
       debug_fill(blok, size + sizeof(union block_hdr));
   
       blok->h.next = NULL;
  @@ -472,7 +506,7 @@
    * Get a new block, from our own free list if possible, from the system
    * if necessary.  Must be called with alarms blocked.
    */
  -static union block_hdr *new_block(int min_size, int (*apr_abort)(int retcode))
  +static union block_hdr *new_block(int min_size, apr_abortfunc_t abortfunc)
   {
       union block_hdr **lastptr = &block_freelist;
       union block_hdr *blok = block_freelist;
  @@ -500,7 +534,7 @@
   
       min_size += BLOCK_MINFREE;
       blok = malloc_block((min_size > BLOCK_MINALLOC)
  -			? min_size : BLOCK_MINALLOC, apr_abort);
  +			? min_size : BLOCK_MINALLOC, abortfunc);
       return blok;
   }
   
  @@ -546,7 +580,8 @@
   #define POOL_HDR_CLICKS (1 + ((sizeof(struct apr_pool_t) - 1) / CLICK_SZ))
   #define POOL_HDR_BYTES (POOL_HDR_CLICKS * CLICK_SZ)
   
  -APR_DECLARE(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p, int (*apr_abort)(int retcode))
  +APR_DECLARE(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p,
  +                                            apr_abortfunc_t abortfunc)
   {
       union block_hdr *blok;
       apr_pool_t *new_pool;
  @@ -558,7 +593,7 @@
       }
   #endif
   
  -    blok = new_block(POOL_HDR_BYTES, apr_abort);
  +    blok = new_block(POOL_HDR_BYTES, abortfunc);
       new_pool = (apr_pool_t *) blok->h.first_avail;
       blok->h.first_avail += POOL_HDR_BYTES;
   #ifdef APR_POOL_DEBUG
  @@ -618,30 +653,35 @@
   #endif
   
   /* ### why do we have this, in addition to apr_pool_sub_make? */
  -APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newcont, apr_pool_t *cont)
  +APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newcont,
  +                                          apr_pool_t *parent_pool)
   {
       apr_pool_t *newpool;
  +    apr_abortfunc_t abortfunc;
   
  -    if (cont) {
  -        newpool = apr_pool_sub_make(cont, cont->apr_abort);
  -    }
  -    else {
  -        newpool = apr_pool_sub_make(NULL, NULL);
  -    }
  -        
  +    abortfunc = parent_pool ? parent_pool->apr_abort : NULL;
  +
  +    newpool = apr_pool_sub_make(parent_pool, abortfunc);
       if (newpool == NULL) {
           return APR_ENOPOOL;
       }   
   
       newpool->prog_data = NULL;
  -    if (cont) {
  -        newpool->apr_abort = cont->apr_abort;
  -    }
  -    else {
  -        newpool->apr_abort = NULL;
  -    }
  +    newpool->apr_abort = abortfunc;
  +
       *newcont = newpool;
       return APR_SUCCESS;
  +}
  +
  +APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
  +                                     apr_pool_t *pool)
  +{
  +    pool->apr_abort = abortfunc;
  +}
  +
  +APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool)
  +{
  +    return pool->apr_abort;
   }
   
   /*****************************************************************
  
  
  
  1.50      +0 -6      apr/misc/unix/start.c
  
  Index: start.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/start.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -u -r1.49 -r1.50
  --- start.c	2001/02/16 04:15:56	1.49
  +++ start.c	2001/04/26 21:29:00	1.50
  @@ -112,9 +112,3 @@
       }
       apr_pool_alloc_term(global_apr_pool);
   }
  -
  -APR_DECLARE(apr_status_t) apr_set_abort(int (*apr_abort)(int retcode), apr_pool_t *cont)
  -{
  -    cont->apr_abort = apr_abort;
  -    return APR_SUCCESS;
  -}
  
  
  
  1.21      +1 -1      apr-util/xml/apr_xml.c
  
  Index: apr_xml.c
  ===================================================================
  RCS file: /home/cvs/apr-util/xml/apr_xml.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -u -r1.20 -r1.21
  --- apr_xml.c	2001/03/08 18:43:39	1.20
  +++ apr_xml.c	2001/04/26 21:29:00	1.21
  @@ -383,7 +383,7 @@
   
       parser->xp = XML_ParserCreate(NULL);
       if (parser->xp == NULL) {
  -        (void) (*pool->apr_abort)(APR_ENOMEM);
  +        (*apr_pool_get_abort(pool))(APR_ENOMEM);
           return NULL;
       }
   
  
  
  

Mime
View raw message