apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/include apr_pools.h apr_sms.h
Date Wed, 11 Jul 2001 14:20:32 GMT
dreid       01/07/11 07:20:31

  Modified:    .        configure.in
               memory/unix apr_sms.c sms_private.h
               include  apr_pools.h apr_sms.h
  Added:       memory/unix apr_sms_pools.c
  Log:
  The 'pools are sms' patch.  Think I got everything :)
  
  To use the patch you need to add --enable-sms into the configure
  line. You'll also need to do a make clean before rebuilding as
  we use defines for apr_palloc and so on...
  
  Revision  Changes    Path
  1.336     +13 -2     apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.335
  retrieving revision 1.336
  diff -u -r1.335 -r1.336
  --- configure.in	2001/07/10 02:18:52	1.335
  +++ configure.in	2001/07/11 14:19:51	1.336
  @@ -152,11 +152,22 @@
     APR_ADDTO(NOTEST_CPPFLAGS,-DAPR_ASSERT_MEMORY)
   ])dnl
   
  -AC_ARG_ENABLE(profile,[  --enable-profile        Turn on profiling for the build (GCC)],[
  +AC_ARG_ENABLE(profile,[  --enable-profile   Turn on profiling for the build (GCC)],
     if test "$GCC" = "yes"; then
       APR_ADDTO(CFLAGS, -pg)
     fi
  -])dnl
  +)dnl
  +
  +POOLS_TARGET=apr_pools.lo
  +AC_ARG_ENABLE(sms, [ --enable-sms Build APR to use sms emulating pools],
  +    echo "*************   WARNING   ***************"
  +    echo "You have switched ON using SMS to emulate pools.  This is highly"
  +    echo "experimental and so you may want to think about it!"
  +    echo "Presently this option is only advised for people working on SMS"
  +    APR_ADDTO(CFLAGS, -DAPR_POOLS_ARE_SMS)
  +    POOLS_TARGET=apr_sms_pools.lo
  +)dnl
  +AC_SUBST(POOLS_TARGET)
   
   dnl # this is the place to put specific options for platform/compiler
   dnl # combinations
  
  
  
  1.48      +6 -0      apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- apr_sms.c	2001/07/07 18:54:32	1.47
  +++ apr_sms.c	2001/07/11 14:20:02	1.48
  @@ -295,8 +295,12 @@
       sms->threads = 1;
   #endif /* APR_HAS_THREADS */
       
  +#ifndef APR_POOLS_ARE_SMS
       /* XXX - This should eventually be removed */
       apr_pool_create(&sms->pool, pms ? pms->pool : NULL);
  +#else
  +    sms->pool = sms;
  +#endif
   
       return APR_SUCCESS;
   }
  @@ -610,8 +614,10 @@
       if (sms->sms_lock)
           apr_lock_destroy(sms->sms_lock);
       
  +#ifndef APR_POOLS_ARE_SMS
       /* XXX - This should eventually be removed */
       apr_pool_destroy(sms->pool);
  +#endif
   
       /* 1 - If we have a self destruct, use it */
       if (sms->destroy_fn)
  
  
  
  1.7       +5 -0      apr/memory/unix/sms_private.h
  
  Index: sms_private.h
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/sms_private.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- sms_private.h	2001/07/07 13:03:45	1.6
  +++ sms_private.h	2001/07/11 14:20:05	1.7
  @@ -68,6 +68,7 @@
   /**
    * The memory system structure
    */
  +
   struct apr_sms_t
   {
       apr_sms_t  *parent;
  @@ -95,6 +96,10 @@
   
       apr_status_t (*apr_abort)(int retcode);
       struct apr_hash_t *prog_data;
  +
  +#ifdef APR_POOLS_ARE_SMS
  +    struct process_chain *subprocesses;
  +#endif
   
   #if APR_HAS_THREADS    
       apr_status_t (*thread_register_fn)   (apr_sms_t *sms, 
  
  
  
  1.1                  apr/memory/unix/apr_sms_pools.c
  
  Index: apr_sms_pools.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr.h"
  #include "apr_pools.h" /* includes apr_sms.h" */
  #include "apr_sms_trivial.h"
  #include "apr_errno.h"
  #include "apr_lock.h"
  #include "apr_portable.h"
  #include "apr_lib.h" /* for apr_vformatter */
  
  #include "sms_private.h"
  
  static int initialized = 0;
  static apr_pool_t *permanent_pool = NULL;
  
  APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool, apr_pool_t *p)
  {
      if (!initialized)
          /* Hmm, if we are given a parent here, is this correct?
           * It should never happen, so we're probably OK....
           */
          return apr_sms_std_create(newpool);
  
      return apr_sms_trivial_create(newpool, p ? p : permanent_pool);
  }
      
  APR_DECLARE(apr_pool_t *) apr_pool_sub_make(apr_pool_t * p,
                                             apr_abortfunc_t abort)
  {
      apr_pool_t *np;
  
      if (apr_sms_trivial_create(&np, p) != APR_SUCCESS)
          return NULL;
  
      apr_sms_set_abort(abort, np);
  
      return np;
  }
  
  APR_DECLARE(void) apr_pool_cleanup_register(apr_pool_t *pool,
                                              const void *data,
                                           apr_status_t (*plain_cleanup)(void*),
                                           apr_status_t (*child_cleanup)(void*))
  {
      if (plain_cleanup == child_cleanup) {
          /* we only need to register one as an ALL_CLEANUP */
          apr_sms_cleanup_register(pool, APR_ALL_CLEANUPS, data, plain_cleanup);
          return;
      }
      if (plain_cleanup)
          apr_sms_cleanup_register(pool, APR_GENERAL_CLEANUP, data,
                                          plain_cleanup);
  
      if (child_cleanup)
          apr_sms_cleanup_register(pool, APR_CHILD_CLEANUP, data,
                                          child_cleanup);
  }
  
  APR_DECLARE(void) apr_pool_cleanup_for_exec(void)
  {
  #if !defined(WIN32) && !defined(OS2)
      /* See note in apr_pools.c for why we do this :) */
      apr_sms_cleanup_run_type(permanent_pool, APR_CHILD_CLEANUP);
  #endif
  }
  
  APR_DECLARE(apr_status_t) apr_pool_alloc_init(apr_pool_t *gp)
  {
      initialized = 1;
      return apr_sms_trivial_create(&permanent_pool, gp);
  }
  
  APR_DECLARE(void) apr_pool_alloc_term(apr_pool_t *gp)
  {
      apr_sms_destroy(permanent_pool);
      /* so, are we still initialized after this???? */
  }
  
  APR_DECLARE(int) apr_pool_is_ancestor(apr_pool_t *a, apr_pool_t *b)
  {
      while (b && b != a)
          b = b->parent;
  
      return b == a;
  }
  
  /* This stuff needs to be reviewed, but here it is :) */
  
  struct psprintf_data {
      apr_vformatter_buff_t  vbuff;
      char *base;
      apr_sms_t *sms;
  };
  
  static int psprintf_flush(apr_vformatter_buff_t *vbuff)
  {
      struct psprintf_data *ps = (struct psprintf_data*)vbuff;
      apr_size_t size;
      char *ptr;
  
      size = (char*) ps->vbuff.curpos - ps->base;
      ptr = apr_sms_realloc(ps->sms, ps->base, 2*size);
      if (ptr == NULL) {
          fputs("[psprintf_flush] Ouch!  Out of memory!\n", stderr);
          exit(1);
      }
      ps->base = ptr;
      ps->vbuff.curpos = ptr + size;
      ps->vbuff.endpos = ptr + 2 * size - 1;
      return 0;
  }
  
  APR_DECLARE(char *) apr_pvsprintf(apr_pool_t *p, const char *fmt, va_list ap)
  {
      struct psprintf_data ps;
      void *ptr;
  
      ps.sms = (apr_sms_t*)p;
      ps.base = apr_sms_malloc(ps.sms, 512);
      if (ps.base == NULL) {
          fputs("[apr_pvsprintf] Ouch! Out of memory!\n", stderr);
          exit(1);
      }
      ps.vbuff.curpos = ps.base;
      ps.vbuff.endpos = ps.base + 511;
      apr_vformatter(psprintf_flush, &ps.vbuff, fmt, ap);
      *ps.vbuff.curpos++ = '\0';
      ptr = ps.base;
      ptr = apr_sms_realloc(ps.sms, ptr, (char*)ps.vbuff.curpos - (char*)ptr);
      if (ptr == NULL) {
          fputs("[apr_pvsprintf #2] Ouch! Out of memory!\n", stderr);
          exit(1);
      }
      return (char*)ptr;
  }
  
  APR_DECLARE_NONSTD(char*) apr_psprintf(apr_pool_t *p, const char *fmt, ...)
  {
      va_list ap;
      char *res;
  
      va_start(ap,fmt);
      res = apr_pvsprintf(p, fmt, ap);
      va_end(ap);
      return res;
  }
  
  APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *pid,
                                             enum kill_conditions how)
  {
      struct process_chain *newpc = (struct process_chain*)
          apr_sms_malloc(a, sizeof(struct process_chain));
  
      newpc->pid       = pid;
      newpc->kill_how  = how;
      newpc->next      = a -> subprocesses;
      a->subprocesses  = newpc;
  }
  
  
  
  
  1.52      +76 -17    apr/include/apr_pools.h
  
  Index: apr_pools.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_pools.h,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- apr_pools.h	2001/07/07 18:53:17	1.51
  +++ apr_pools.h	2001/07/11 14:20:19	1.52
  @@ -55,6 +55,10 @@
   #ifndef APR_POOLS_H
   #define APR_POOLS_H
   
  +#ifdef APR_POOLS_ARE_SMS
  +#include "apr_sms.h"
  +#endif
  +
   #ifdef __cplusplus
   extern "C" {
   #endif
  @@ -91,11 +95,13 @@
   #define APR_POOL_DEBUG
   */
   
  +#ifndef APR_POOLS_ARE_SMS
   /** The fundamental pool type */
   typedef struct apr_pool_t apr_pool_t;
   
   /** A function that is called when allocation fails. */
   typedef int (*apr_abortfunc_t)(int retcode);
  +#endif /* !APR_POOLS_ARE_SMS */
   
   /**
    * @defgroup PoolDebug Pool Debugging functions.
  @@ -228,6 +234,7 @@
   APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newcont,
                                             apr_pool_t *cont);
   
  +#if !defined(APR_POOLS_ARE_SMS) || defined(DOXYGEN)
   /**
    * Set the function to be called when an allocation failure occurs.
    * @tip If the program wants APR to exit on a memory allocation error,
  @@ -287,17 +294,6 @@
                                              apr_pool_t *cont);
   
   /**
  - * Make a sub pool from the current pool
  - * @param p The pool to use as a parent pool
  - * @param apr_abort A function to use if the pool cannot allocate more memory.
  - * @return The new sub-pool
  - * @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(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p,
  -                                            int (*apr_abort)(int retcode));
  -
  -/**
    * Clear all memory in the pool and run all the cleanups. This also clears all
    * subpools.
    * @param p The pool to clear
  @@ -330,6 +326,35 @@
    */
   APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
   
  +#endif /* !APR_POOLS_ARE_SMS || DOXYGEN */
  +
  +/**
  + * Make a sub pool from the current pool
  + * @param p The pool to use as a parent pool
  + * @param apr_abort A function to use if the pool cannot allocate more memory.
  + * @return The new sub-pool
  + * @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(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p,
  +                                            int (*apr_abort)(int retcode));
  +
  +#if defined(APR_POOL_DEBUG) || defined(DOXYGEN) 
  +/**
  + * Report the number of bytes currently in the pool
  + * @param p The pool to inspect
  + * @param recurse Recurse/include the subpools' sizes
  + * @return The number of bytes
  + */
  +APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);
  +
  +/**
  + * Report the number of bytes currently in the list of free blocks
  + * @return The number of bytes
  + */
  +APR_DECLARE(apr_size_t) apr_pool_free_blocks_num_bytes(void);
  +#endif
  +
   /**
    * Register a function to be called when a pool is cleared or destroyed
    * @param p The pool register the cleanup with 
  @@ -343,6 +368,7 @@
                                          apr_status_t (*plain_cleanup)(void *),
                                          apr_status_t (*child_cleanup)(void *));
   
  +#if !defined(APR_POOLS_ARE_SMS) || defined(DOXYGEN)
   /**
    * Remove a previously registered cleanup function
    * @param p The pool remove the cleanup from 
  @@ -364,6 +390,14 @@
   APR_DECLARE(apr_status_t) apr_pool_cleanup_run(apr_pool_t *p, void *data,
                                             apr_status_t (*cleanup)(void *));
   
  +/**
  + * An empty cleanup function 
  + * @param data The data to cleanup
  + */
  +APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  +
  +#endif /* !APR_POOLS_ARE_SMS || DOXYGEN */
  +
   /* Preparing for exec() --- close files, etc., but *don't* flush I/O
    * buffers, *don't* wait for subprocesses, and *don't* free any memory.
    */
  @@ -373,12 +407,6 @@
    */
   APR_DECLARE(void) apr_pool_cleanup_for_exec(void);
   
  -/**
  - * An empty cleanup function 
  - * @param data The data to cleanup
  - */
  -APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  -
   /*
    * Pool accessor functions.
    *
  @@ -418,6 +446,37 @@
   # endif /* apr_pool_join */
   # define apr_pool_join(a,b)
   #endif /* APR_POOL_DEBUG */
  +
  +
  +#ifdef APR_POOLS_ARE_SMS
  +/* Add a number of defines where the sms equivalent is 1 to 1 */
  +#define apr_pool_get_abort(p)                apr_sms_get_abort(p)
  +#define apr_pool_set_abort(fn, p)            apr_sms_set_abort(fn, p)
  +
  +#define apr_pool_get_parent(p)               apr_sms_get_parent(p)
  +
  +#define apr_pool_userdata_set(d, k, c, p) \
  +        apr_sms_userdata_set(d, k, c, p)
  +#define apr_pool_userdata_get(d, k, p) \
  +        apr_sms_userdata_get(d, k, p)
  +
  +#define apr_pool_cleanup_kill(p, d, c) \
  +        apr_sms_cleanup_unregister(p, APR_ALL_CLEANUPS, d, c)
  +#define apr_pool_cleanup_run(p, d, c) \
  +        apr_sms_cleanup_run(p, APR_GENERAL_CLEANUP, d, c)
  +
  +/* we won't even bother to register these as they'll be ignored when
  + * we call the register fucntion
  + */
  +#define apr_pool_cleanup_null                NULL
  +
  +/* The parameters match exactly for these, so just define them directly */
  +#define apr_palloc       apr_sms_malloc
  +#define apr_pcalloc      apr_sms_calloc
  +#define apr_pool_clear   apr_sms_reset
  +#define apr_pool_destroy apr_sms_destroy
  +
  +#endif /* APR_POOLS_ARE_SMS */
   
   #ifdef __cplusplus
   }
  
  
  
  1.37      +10 -3     apr/include/apr_sms.h
  
  Index: apr_sms.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_sms.h,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- apr_sms.h	2001/07/07 17:40:02	1.36
  +++ apr_sms.h	2001/07/11 14:20:23	1.37
  @@ -67,14 +67,18 @@
   
   #include "apr.h"
   #include "apr_errno.h"
  +#ifndef APR_POOLS_ARE_SMS
   #include "apr_pools.h"
  -#include "apr_lock.h"
  -#include "apr_portable.h"
  +#endif
   
   #ifdef __cplusplus
   extern "C" {
   #endif
   
  +#ifdef APR_POOLS_ARE_SMS
  +typedef struct apr_sms_t           apr_pool_t;
  +typedef int (*apr_abortfunc_t)(int retcode);
  +#endif
   
   /**********************************************************************
    ** Defines 
  @@ -150,7 +154,6 @@
   #define APR_DEBUG_ALLOCATIONS         0
   #define APR_DEBUG_ALLOC_FILE "/tmp/sms_alloc"
   
  -
   /**
    * @package APR memory system
    */
  @@ -408,6 +411,10 @@
    */
   APR_DECLARE(void) apr_sms_tag(apr_sms_t *sms, const char *tag);
   #endif /* APR_DEBUG_TAG_SMS */
  +
  +#if SMS_ALLOC_STATS
  +APR_DECLARE(void) apr_sms_dump_stats(apr_sms_t *sms);
  +#endif
   
   #ifdef __cplusplus
   }
  
  
  

Mime
View raw message