You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by dg...@hyperreal.org on 1998/03/28 22:35:42 UTC

cvs commit: apache-1.3/src/main alloc.c

dgaudet     98/03/28 13:35:42

  Modified:    .        STATUS
               src/include alloc.h
               src/main alloc.c
  Log:
  alloc debugging stuff works with psprintf
  
  Revision  Changes    Path
  1.231     +0 -1      apache-1.3/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/STATUS,v
  retrieving revision 1.230
  retrieving revision 1.231
  diff -u -r1.230 -r1.231
  --- STATUS	1998/03/28 12:03:44	1.230
  +++ STATUS	1998/03/28 21:35:37	1.231
  @@ -444,7 +444,6 @@
   
     * vformatter TODO:
       - double check logic in apapi_vformatter(), and especially psprintf()
  -    - fix ALLOC_USE_MALLOC, make sure ALLOC_DEBUG and POOL_DEBUG still work
       - add in and use the inaddr formatting codes that started the whole
         debate last october
       - ... so that we can finally start fixing all the log messages that
  
  
  
  1.51      +2 -0      apache-1.3/src/include/alloc.h
  
  Index: alloc.h
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/include/alloc.h,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- alloc.h	1998/03/28 11:58:16	1.50
  +++ alloc.h	1998/03/28 21:35:38	1.51
  @@ -97,6 +97,8 @@
   #define pool_join(a,b)
   #else
   API_EXPORT(void) pool_join(pool *p, pool *sub);
  +API_EXPORT(pool *) find_pool(const void *ts);
  +API_EXPORT(int) pool_is_ancestor(pool *a, pool *b);
   #endif
   
   /* Clearing out EVERYTHING in an pool... destroys any sub-pools */
  
  
  
  1.81      +48 -8     apache-1.3/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/alloc.c,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- alloc.c	1998/03/28 11:58:21	1.80
  +++ alloc.c	1998/03/28 21:35:41	1.81
  @@ -219,7 +219,7 @@
   
   
   
  -#ifdef ALLOC_DEBUG
  +#if defined(ALLOC_DEBUG) && !defined(ALLOC_USE_MALLOC)
   static void chk_on_blk_list(union block_hdr *blok, union block_hdr *free_blk)
   {
       while (free_blk) {
  @@ -535,7 +535,7 @@
   /* Find the pool that ts belongs to, return NULL if it doesn't
    * belong to any pool.
    */
  -pool *find_pool(const void *ts)
  +API_EXPORT(pool *) find_pool(const void *ts)
   {
       const char *s = ts;
       union block_hdr **pb;
  @@ -582,7 +582,7 @@
   /* return TRUE iff a is an ancestor of b
    * NULL is considered an ancestor of all pools
    */
  -int pool_is_ancestor(pool *a, pool *b)
  +API_EXPORT(int) pool_is_ancestor(pool *a, pool *b)
   {
       if (a == NULL) {
   	return 1;
  @@ -771,11 +771,6 @@
       return res;
   }
   
  -/* XXX */
  -#ifdef ALLOC_USE_MALLOC
  -#error "psprintf does not support ALLOC_USE_MALLOC yet..."
  -#endif
  -
   /* psprintf is implemented by writing directly into the current
    * block of the pool, starting right at first_avail.  If there's
    * insufficient room, then a new block is allocated and the earlier
  @@ -785,13 +780,36 @@
   
   struct psprintf_data {
       pool *p;
  +#ifdef ALLOC_USE_MALLOC
  +    char *base;
  +    size_t len;
  +#else
       union block_hdr *blok;
       char *strp;
       int got_a_new_block;
  +#endif
   };
   
   static int psprintf_write(void *vdata, const char *inp, size_t len)
   {
  +#ifdef ALLOC_USE_MALLOC
  +    struct psprintf_data *ps;
  +    int size;
  +    char *ptr;
  +
  +    ps = vdata;
  +
  +    size = ps->len + len + 1;
  +    ptr = realloc(ps->base, size);
  +    if (ptr == NULL) {
  +	fputs("Ouch!  Out of memory!\n", stderr);
  +	exit(1);
  +    }
  +    ps->base = ptr;
  +    memcpy(ptr + ps->len, inp, len);
  +    ps->len += len;
  +    return 0;
  +#else
       struct psprintf_data *ps;
       union block_hdr *blok;
       union block_hdr *nblok;
  @@ -837,10 +855,31 @@
       ps->blok = nblok;
       ps->got_a_new_block = 1;
       return 0;
  +#endif
   }
   
   API_EXPORT(char *) pvsprintf(pool *p, const char *fmt, va_list ap)
   {
  +#ifdef ALLOC_USE_MALLOC
  +    struct psprintf_data ps;
  +    void *ptr;
  +
  +    block_alarms();
  +    ps.p = p;
  +    ps.base = NULL;
  +    ps.len = CLICK_SZ;	/* need room at beginning for allocation_list */
  +    apapi_vformatter(psprintf_write, &ps, fmt, ap);
  +    ptr = ps.base;
  +    if (ptr == NULL) {
  +	unblock_alarms();
  +	return pstrdup(p, "");
  +    }
  +    *((char *)ptr + ps.len) = '\0';	/* room was saved for this */
  +    *(void **)ptr = p->allocation_list;
  +    p->allocation_list = ptr;
  +    unblock_alarms();
  +    return (char *)ptr + CLICK_SZ;
  +#else
       struct psprintf_data ps;
       char *strp;
       int size;
  @@ -870,6 +909,7 @@
       }
   
       return strp;
  +#endif
   }
   
   API_EXPORT_NONSTD(char *) psprintf(pool *p, const char *fmt, ...)