apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stri...@apache.org
Subject cvs commit: apr/memory/unix apr_pools.c
Date Sat, 12 Jan 2002 16:15:08 GMT
striker     02/01/12 08:15:08

  Modified:    include  apr_pools.h
               memory/unix apr_pools.c
  Log:
  The new APR_POOL_DEBUG and APR_POOL_DEBUG_VERBOSE code.
  
  Revision  Changes    Path
  1.68      +14 -12    apr/include/apr_pools.h
  
  Index: apr_pools.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_pools.h,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- apr_pools.h	11 Jan 2002 21:01:19 -0000	1.67
  +++ apr_pools.h	12 Jan 2002 16:15:07 -0000	1.68
  @@ -94,12 +94,12 @@
    */
   /* 
   #define APR_POOL_DEBUG
  +#define APR_POOL_DEBUG_VERBOSE
   */
   
  -#define APR_POOL_STRINGIZE(x) APR_POOL__STRINGIZE(x)
  -#define APR_POOL__STRINGIZE(x) #x
  -#define APR_POOL__FILELINE__ __FILE__ ":" APR_POOL_STRINGIZE(__LINE__)
  -    
  +#if defined(APR_POOL_DEBUG_VERBOSE) && !defined(APR_POOL_DEBUG)
  +#define APR_POOL_DEBUG
  +#endif    
       
   /** The fundamental pool type */
   typedef struct apr_pool_t apr_pool_t;
  @@ -159,8 +159,8 @@
    *
    */
   #if defined(APR_POOL_DEBUG)
  -#define apr_pool_create_ex( newpool, parent, abort_fn, flag)  \
  -    apr_pool_create_ex_dbg( newpool, parent, abort_fn, flag,__FILE__,__LINE__)  
  +#define apr_pool_create_ex(newpool, parent, abort_fn, flag)  \
  +    apr_pool_create_ex_dbg(newpool, parent, abort_fn, flag, __FILE__, __LINE__)
   
   APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
                                                apr_pool_t *parent,
  @@ -189,7 +189,8 @@
   #else
   #if defined(APR_POOL_DEBUG)
   #define apr_pool_create(newpool, parent) \
  -    apr_pool_create_ex_dbg(newpool, parent, NULL, APR_POOL_FDEFAULT,__FILE__,__LINE__)
  +    apr_pool_create_ex_dbg(newpool, parent, NULL, APR_POOL_FDEFAULT, \
  +                           __FILE__, __LINE__)
   #else
   #define apr_pool_create(newpool, parent) \
       apr_pool_create_ex(newpool, parent, NULL, APR_POOL_FDEFAULT)
  @@ -212,10 +213,11 @@
   #else
   #if defined(APR_POOL_DEBUG)
   #define apr_pool_sub_make(newpool, parent, abort_fn) \
  -    (void)apr_pool_create_ex_dbg(newpool, parent, abort_fn, APR_POOL_FDEFAULT,__FILE__,__LINE__);
  +    (void)apr_pool_create_ex_dbg(newpool, parent, abort_fn, APR_POOL_FDEFAULT, \
  +                                 __FILE__, __LINE__)
   #else
   #define apr_pool_sub_make(newpool, parent, abort_fn) \
  -    (void)apr_pool_create_ex(newpool, parent, abort_fn, APR_POOL_FDEFAULT);
  +    (void)apr_pool_create_ex(newpool, parent, abort_fn, APR_POOL_FDEFAULT)
   #endif
   #endif
   
  @@ -227,7 +229,7 @@
    */
   #if defined(APR_POOL_DEBUG)
   #define apr_pool_destroy(p) \
  -    apr_pool_destroy_dbg(p, __FILE__,__LINE__)
  +    apr_pool_destroy_dbg(p, __FILE__, __LINE__)
   
   APR_DECLARE(void) apr_pool_destroy_dbg(apr_pool_t *p, const char *file, int line);
   #else
  @@ -264,9 +266,9 @@
    */
   #if defined(APR_POOL_DEBUG)
   #define apr_pool_clear(p) \
  -    apr_pool_clear_dbg(p, __FILE__,__LINE__)
  +    apr_pool_clear_dbg(p, __FILE__, __LINE__)
   
  -APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *p, const char*file, int line);
  +APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *p, const char *file, int line);
   #else
   APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
   #endif
  
  
  
  1.129     +180 -48   apr/memory/unix/apr_pools.c
  
  Index: apr_pools.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
  retrieving revision 1.128
  retrieving revision 1.129
  diff -u -r1.128 -r1.129
  --- apr_pools.c	11 Jan 2002 21:01:19 -0000	1.128
  +++ apr_pools.c	12 Jan 2002 16:15:07 -0000	1.129
  @@ -67,7 +67,7 @@
   #include "apr_want.h"
   
   #if APR_HAVE_STDLIB_H
  -#include <stdlib.h>     /* for malloc and free */
  +#include <stdlib.h>     /* for malloc, free and abort */
   #endif
   
   /*
  @@ -91,14 +91,6 @@
   
   #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
   
  -/*
  - * This option prints out the pool creation info
  - * (and info about its children)
  - * when the pool is destroyed.
  - */
  -/*
  -#define APR_POOL_DEBUG_VERBOSE
  -*/
       
   /*
    * Structures
  @@ -198,6 +190,9 @@
   };
   #endif /* !defined(APR_POOL_DEBUG) */
   
  +#if defined(APR_POOL_DEBUG_VERBOSE)
  +static apr_file_t *file_stderr = NULL;
  +#endif
   
   /*
    * Local functions
  @@ -235,7 +230,7 @@
   
       global_allocator.owner = global_pool;
       apr_pools_initialized = 1;
  -
  +    
       return APR_SUCCESS;
   }
   
  @@ -842,9 +837,20 @@
                     APR_POOL_FNEW_ALLOCATOR|APR_POOL_FLOCK)) != APR_SUCCESS) {
           return rv;
       }
  -    
  +
  +    apr_pool_tag(global_pool, "APR global pool");
  +
       apr_pools_initialized = 1;
   
  +#if APR_POOL_DEBUG_VERBOSE
  +    apr_file_open_stderr(&file_stderr, global_pool);
  +    if (file_stderr) {
  +        apr_file_printf(file_stderr,
  +            "POOL DEBUG: GLOBAL  0x%08X(%s)\n",
  +            (unsigned int)global_pool, global_pool->tag); 
  +    }
  +#endif
  +    
       return APR_SUCCESS;
   }
   
  @@ -857,8 +863,55 @@
       
       apr_pool_destroy(global_pool); /* This will also destroy the mutex */
       global_pool = NULL;
  +
  +#if APR_POOL_DEBUG_VERBOSE
  +    file_stderr = NULL;
  +#endif
   }
   
  +/*
  + * Integrity checking
  + * This basically checks to see if the pool being used is still
  + * a relative to the global pool.  If not it was previously
  + * destroyed, in which case we abort().
  + */
  +
  +static int pool_is_child_of(apr_pool_t *pool, apr_pool_t *parent)
  +{
  +    apr_pool_t *child;
  +   
  +    if (parent == NULL)
  +        return 0;
  +
  +    child = parent->child;
  +
  +    while (child) {
  +        if (pool == child || pool_is_child_of(pool, child))
  +            return 1;
  +        
  +        child = child->sibling;
  +    }
  +
  +    return 0;
  +}
  +
  +static void check_integrity(apr_pool_t *pool)
  +{
  +    if (pool == global_pool || global_pool == NULL)
  +        return;
  +
  +    if (!pool_is_child_of(pool, global_pool))
  +    {
  +#if defined(APR_POOL_DEBUG_VERBOSE)
  +        if (file_stderr) {
  +            apr_file_printf(file_stderr,
  +                "POOL DEBUG: INVALID 0x%08X, abort().\n", (unsigned int)pool);
  +        }
  +#endif         
  +
  +        abort();
  +    }
  +}
   
   /*
    * Memory allocation (debug)
  @@ -869,6 +922,8 @@
       debug_node_t *node;
       void *mem;
   
  +    check_integrity(pool);
  +    
       if ((mem = malloc(size)) == NULL) {
           if (pool->abort_fn)
               pool->abort_fn(APR_ENOMEM);
  @@ -897,13 +952,12 @@
       return mem;
   }
   
  -/*
  - * (debug)
  - */
   APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size)
   {
       void *mem;
  -   
  +
  +    check_integrity(pool);
  +    
       mem = apr_palloc(pool, size);
       memset(mem, 0, size);
   
  @@ -913,10 +967,9 @@
   
   /*
    * Pool creation/destruction (debug)
  - * TODO: printout a line if _VERBOSE is on
    */
   
  -APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *pool,const char*file, int line)
  +static void pool_clear_dbg(apr_pool_t *pool, const char *file, int line)
   {
       debug_node_t *node;
       apr_uint32_t index;
  @@ -925,7 +978,7 @@
        * this pool thus this loop is safe and easy.
        */
       while (pool->child)
  -        apr_pool_destroy_dbg(pool->child,file,line);
  +        apr_pool_destroy_dbg(pool->child, file, line);
   
       /* Run cleanups */
       run_cleanups(pool->cleanups);
  @@ -949,32 +1002,38 @@
       }
   }
   
  -/*
  - * destroy (debug)
  - */
  -APR_DECLARE(void) apr_pool_destroy_dbg(apr_pool_t *pool,const char*file, int line)
  +APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *pool, 
  +                                     const char *file, int line)
   {
  -#if defined APR_POOL_DEBUG_VERBOSE
  -    apr_file_t *stderr_log = NULL;
  -    apr_pool_t *child;
  +    check_integrity(pool);
  +    
  +#if defined(APR_POOL_DEBUG_VERBOSE)
  +    if (file_stderr) {
  +        apr_file_printf(file_stderr,
  +            "POOL DEBUG: CLEAR  0x%08X(%s) [%s:%d]\n",
  +            (unsigned int)pool, pool->tag,
  +            file, line);
  +    }
  +#endif
   
  -    apr_file_open_stderr(&stderr_log,pool); /* XXX not sure about this one */
  -    if (stderr_log) {
  -        apr_file_printf(stderr_log,
  -            "DEBUG: %s:%d destroy pool tagged %s created %s:%d\n",
  -            file, line, pool->tag, pool->file, pool->line);
  -        child= pool->child;
  -        while (child) {
  -            apr_file_printf(stderr_log,
  -                "DEBUG:\tpool child tagged %s created %s:%d\n",
  -                child->tag, child->file, child->line);
  -            child = child->sibling;
  -        }
  -        apr_file_close(stderr_log);
  +    pool_clear_dbg(pool, file, line);
  +}
  +
  +APR_DECLARE(void) apr_pool_destroy_dbg(apr_pool_t *pool, 
  +                                       const char *file, int line)
  +{
  +    check_integrity(pool);
  +    
  +#if defined(APR_POOL_DEBUG_VERBOSE)
  +    if (file_stderr) {
  +        apr_file_printf(file_stderr,
  +            "POOL DEBUG: DESTROY 0x%08X(%s) [%s:%u]\n",
  +            (unsigned int)pool, pool->tag,
  +            file, line);
       }
   #endif
   
  -    apr_pool_clear_dbg(pool,file,line);
  +    pool_clear_dbg(pool, file, line);
   
       /* Remove the pool from the parents child list */
       if (pool->parent) {
  @@ -998,10 +1057,6 @@
       free(pool);
   }
   
  -/*
  - * create (debug)
  - * there is a macro which adds the file/line #
  - */
   APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool, 
                                                apr_pool_t *parent,
                                                apr_abortfunc_t abort_fn,
  @@ -1015,6 +1070,8 @@
   
       if (!parent)
           parent = global_pool;
  +    else
  +       check_integrity(parent);
   
       if (!abort_fn && parent)
           abort_fn = parent->abort_fn;
  @@ -1029,6 +1086,9 @@
       memset(pool, 0, SIZEOF_POOL_T);
       
       pool->abort_fn = abort_fn;
  +    pool->tag = "<untagged>";
  +    pool->file = file;
  +    pool->line = line;
   
       if ((flags & APR_POOL_FNEW_ALLOCATOR) == APR_POOL_FNEW_ALLOCATOR) {
   #if APR_HAS_THREADS
  @@ -1071,14 +1131,60 @@
           pool->ref = NULL;
       }
   
  -    pool->file = file;
  -    pool->line = line;
  -
       *newpool = pool;
   
  +#if defined(APR_POOL_DEBUG_VERBOSE)
  +    if (file_stderr) {
  +        apr_file_printf(file_stderr,
  +            "POOL DEBUG: CREATE  0x%08X(%s) parent = 0x%08X(%s) [%s:%u]\n",
  +            (unsigned int)pool, pool->tag, 
  +            (unsigned int)parent, parent ? parent->tag : "<null>",
  +            file, line);
  +    }
  +#endif
  +
       return APR_SUCCESS;
   }
   
  +/*
  + * Pool creation/destruction stubs, for people who want 
  + * APR_POOL_DEBUG, but didn't recompile their entire application.
  + * The prototypes are here to keep compilers picky about
  + * prototypes happy.
  + */
  +
  +#undef apr_pool_clear
  +APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool);
  +
  +APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool)
  +{
  +    apr_pool_clear_dbg(pool, "<undefined>", 0);
  +}
  +
  +#undef apr_pool_destroy
  +APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool);
  +
  +APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool)
  +{
  +    apr_pool_destroy_dbg(pool, "<undefined>", 0);
  +}
  +
  +#undef apr_pool_create_ex
  +APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
  +                                             apr_pool_t *parent,
  +                                             apr_abortfunc_t abort_fn,
  +                                             apr_uint32_t flags);
  +
  +APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
  +                                             apr_pool_t *parent,
  +                                             apr_abortfunc_t abort_fn,
  +                                             apr_uint32_t flags)
  +{
  +    return apr_pool_create_ex_dbg(newpool, parent, 
  +                                  abort_fn, flags,
  +                                  "<undefined>", 0);
  +}
  +
   
   /*
    * "Print" functions (debug)
  @@ -1112,6 +1218,8 @@
       struct psprintf_data ps;
       debug_node_t *node;
   
  +    check_integrity(pool);
  +    
       ps.size = 64;
       ps.mem = malloc(ps.size);
       ps.vbuff.curpos  = ps.mem;
  @@ -1311,6 +1419,10 @@
                                                   apr_status_t (*cleanup) (void *),
                                                   apr_pool_t *pool)
   {
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(pool);
  +#endif
  +    
       if (pool->user_data == NULL)
           pool->user_data = apr_hash_make(pool);
   
  @@ -1332,6 +1444,10 @@
                                                    apr_status_t (*cleanup) (void *),
                                                    apr_pool_t *pool)
   {
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(pool);
  +#endif
  +    
       if (pool->user_data == NULL)
           pool->user_data = apr_hash_make(pool);
   
  @@ -1345,6 +1461,10 @@
   
   APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key, apr_pool_t
*pool)
   {
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(pool);
  +#endif
  +    
       if (pool->user_data == NULL)
           *data = NULL;
       else
  @@ -1370,9 +1490,13 @@
                         apr_status_t (*child_cleanup_fn)(void *data))
   {
       cleanup_t *c;
  -
  +    
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(p);
  +#endif
  +    
       if (p != NULL) {
  -        c = (cleanup_t *) apr_palloc(p, sizeof(cleanup_t));
  +        c = (cleanup_t *)apr_palloc(p, sizeof(cleanup_t));
           c->data = data;
           c->plain_cleanup_fn = plain_cleanup_fn;
           c->child_cleanup_fn = child_cleanup_fn;
  @@ -1386,6 +1510,10 @@
   {
       cleanup_t *c, **lastp;
   
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(p);
  +#endif
  +   
       if (p == NULL)
           return;
   
  @@ -1407,6 +1535,10 @@
                                          apr_status_t (*child_cleanup_fn) (void *))
   {
       cleanup_t *c;
  +
  +#if defined(APR_POOL_DEBUG)
  +    check_integrity(p);
  +#endif
   
       if (p == NULL)
           return;
  
  
  

Mime
View raw message