First off - this patch names apr_pool_t allocations (nothing to do with pipes,
sorry for my earlier misnomer.)


From: "Branko Čibej" <[EMAIL PROTECTED]>
Sent: Thursday, August 02, 2001 5:51 PM


> William A. Rowe, Jr. wrote:
>
> >2. I can't figure out how to stringize __LINE__, which sort of sucks.
> >
> The Well Known Hack is
>
>     #define STRINGIFY(S) REALLY_STRINGIFY(S)
>     #define REALLY_STRINGIFY(S) #S
>
>     char this_line_number[] = STRINGIFY(__LINE__);

Thanks, the revised patch is attached :)


One other bit of coolness for win32 developers that I like...

--- srclib/apr/include/arch/win32/apr_private.h 2001/06/06 00:07:46 1.24
+++ srclib/apr/include/arch/win32/apr_private.h 2001/08/02 23:13:00
@@ -191,5 +191,8 @@
         ptr = (type *)apr_sms_calloc(struct->mem_sys, sizeof(type)); \
     }

+#define abort() DebugBreak();
+#define assert(x) if (!(x)) DebugBreak;
+
 #endif  /*APR_PRIVATE_H*/
 #endif  /*WIN32*/


This works nicely around WIN32's bogus crtlib interceptions of abort(), which
make backtracing somewhat difficult (espessially with the BoundsChecker 
intercepts.)


Index: srclib/apr/include/apr_pools.h
===================================================================
RCS file: /home/cvs/apr/include/apr_pools.h,v
retrieving revision 1.55
diff -u -r1.55 apr_pools.h
--- srclib/apr/include/apr_pools.h      2001/08/02 05:24:42     1.55
+++ srclib/apr/include/apr_pools.h      2001/08/02 23:13:00
@@ -95,6 +95,11 @@
 #define APR_POOL_DEBUG
 */
 
+#ifdef APR_POOL_DEBUG
+#define APR_STRINGIFY(S) APR_REALLY_STRINGIFY(S)
+#define APR_REALLY_STRINGIFY(S) #S
+#endif
+
 #ifndef APR_POOLS_ARE_SMS
 /** The fundamental pool type */
 typedef struct apr_pool_t apr_pool_t;
@@ -207,8 +212,17 @@
  * @remark Programs do NOT need to call this directly.  APR will call this
  *      automatically from apr_initialize. 
  * @internal
+ * @deffunc apr_status_t apr_pool_alloc_init(apr_pool_t *globalp)
  */
-APR_DECLARE(apr_status_t) apr_pool_alloc_init(apr_pool_t *globalp);
+APR_DECLARE(apr_status_t) apr_pool_alloc_init(apr_pool_t *globalp, const char 
* created);
+
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_alloc_init(p) \
+    (apr_pool_alloc_init)(p, #p " (" STRINGIFY(__LINE__) ") " __FILE__)
+#else
+#define apr_pool_alloc_init(p) \
+    (apr_pool_alloc_init)(p, NULL)
+#endif
 
 /**
  * Tear down all of the internal structures required to use pools
@@ -230,10 +244,20 @@
  *        pool.  If it is non-NULL, the new pool will inherit all
  *        of it's parent pool's attributes, except the apr_pool_t will 
  *        be a sub-pool.
+ * @deffunc 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 *cont);
+                                          apr_pool_t *cont,
+                                          const char *created);
 
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_create(p, pp) \
+    (apr_pool_create)(p, pp, #p " (" STRINGIFY(__LINE__) ") " __FILE__)
+#else
+#define apr_pool_create(p, pp) \
+    (apr_pool_create)(p, pp, NULL)
+#endif
+
 #if !defined(APR_POOLS_ARE_SMS) || defined(DOXYGEN)
 /**
  * Set the function to be called when an allocation failure occurs.
@@ -329,6 +353,7 @@
 #endif /* !APR_POOLS_ARE_SMS || DOXYGEN */
 
 /**
+ * Make a sub pool from the current pool
  * @param p The new sub-pool
  * @param parent The pool to use as a parent pool
  * @param apr_abort A function to use if the pool cannot allocate more memory.
@@ -336,9 +361,18 @@
  * @remark The @a apr_abort function provides a way to quit the program if the
  *      machine is out of memory.  By default, APR will return on error.
  */
-APR_DECLARE(void) apr_pool_sub_make(apr_pool_t **p, 
-                                            apr_pool_t *pparent,
-                                            int (*apr_abort)(int retcode));
+APR_DECLARE(void) apr_pool_sub_make(apr_pool_t **p,
+                                    apr_pool_t *parent,
+                                    int (*apr_abort)(int retcode),
+                                    const char *created);
+
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_sub_make(p, pp, abort) \
+    (apr_pool_sub_make)(p, pp, abort, #p " (" STRINGIFY(__LINE__) ") " 
__FILE__)
+#else
+#define apr_pool_sub_make(p, pp, abort) \
+    (apr_pool_sub_make)(p, pp, abort, NULL)
+#endif
 
 #if defined(APR_POOL_DEBUG) || defined(DOXYGEN) 
 /**
Index: srclib/apr/memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.106
diff -u -r1.106 apr_pools.c
--- srclib/apr/memory/unix/apr_pools.c  2001/08/02 05:24:42     1.106
+++ srclib/apr/memory/unix/apr_pools.c  2001/08/02 23:13:01
@@ -105,6 +105,10 @@
 #include <malloc.h>
 #endif
 
+#undef apr_pool_alloc_init
+#undef apr_pool_create
+#undef apr_pool_sub_make
+
 /* Details of the debugging options can now be found in the developer
  * section of the documentaion.
  * ### gjs: where the hell is that?
@@ -199,6 +203,7 @@
 #endif
 #ifdef APR_POOL_DEBUG
     /** a list of joined pools */
+    const char *created;
     struct apr_pool_t *joined;
 #endif
     /** A function to control how pools behave when they receive ENOMEM */
@@ -281,7 +286,6 @@
        if (*ptr != FILL_BYTE) {
            fputs(error_msg, stderr);
            abort();
-           exit(1);
        }
     }
 }
@@ -582,12 +586,12 @@
 
 APR_DECLARE(void) apr_pool_sub_make(apr_pool_t **p,
                                     apr_pool_t *parent,
-                                    apr_abortfunc_t abortfunc)
+                                    apr_abortfunc_t abortfunc,
+                                    const char *created)
 {
     union block_hdr *blok;
     apr_pool_t *new_pool;
 
-
 #if APR_HAS_THREADS
     if (alloc_mutex) {
         apr_lock_acquire(alloc_mutex);
@@ -597,11 +601,14 @@
     blok = new_block(POOL_HDR_BYTES, abortfunc);
     new_pool = (apr_pool_t *) blok->h.first_avail;
     blok->h.first_avail += POOL_HDR_BYTES;
+
+    memset((char *) new_pool, '\0', sizeof(struct apr_pool_t));
+
 #ifdef APR_POOL_DEBUG
     blok->h.owning_pool = new_pool;
+    new_pool->created = created;
 #endif
 
-    memset((char *) new_pool, '\0', sizeof(struct apr_pool_t));
     new_pool->free_first_avail = blok->h.first_avail;
     new_pool->first = new_pool->last = blok;
 
@@ -655,13 +662,14 @@
 
 /* ### why do we have this, in addition to apr_pool_sub_make? */
 APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,
-                                          apr_pool_t *parent_pool)
+                                          apr_pool_t *parent_pool,
+                                          const char *created)
 {
     apr_abortfunc_t abortfunc;
 
     abortfunc = parent_pool ? parent_pool->apr_abort : NULL;
 
-    apr_pool_sub_make(newpool, parent_pool, abortfunc);
+    apr_pool_sub_make(newpool, parent_pool, abortfunc, created);
     if (*newpool == NULL) {
         return APR_ENOPOOL;
     }   
@@ -811,7 +819,8 @@
     return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) apr_pool_alloc_init(apr_pool_t *globalp)
+APR_DECLARE(apr_status_t) apr_pool_alloc_init(apr_pool_t *globalp, 
+                                              const char *created)
 {
 #if APR_HAS_THREADS
     apr_status_t status;
@@ -836,7 +845,7 @@
         return status;
     }
 #endif
-    apr_pool_sub_make(&permanent_pool, globalp, NULL);
+    apr_pool_sub_make(&permanent_pool, globalp, NULL, created);
 
 #ifdef ALLOC_STATS
     atexit(dump_stats);

Reply via email to