apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/test testmem.c
Date Sun, 13 May 2001 11:11:48 GMT
dreid       01/05/13 04:11:48

  Modified:    include  apr_memory_system.h apr_tracking_memory_system.h
               memory/unix apr_memory_system.c apr_standard_memory_system.c
                        apr_tracking_memory_system.c
               test     testmem.c
  Log:
  The big name change for the memory code.  Names used follow the outline I
  posted yesterday.  Please review at our leisure.
  
  Also adds a calloc function that uses calloc if available or does malloc
  /memset.
  Test program updated to new names.
  Shorter variable names as well.
  
  The next step is the asserts & checks...
  
  Revision  Changes    Path
  1.5       +91 -93    apr/include/apr_memory_system.h
  
  Index: apr_memory_system.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_memory_system.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apr_memory_system.h	2001/05/10 10:33:09	1.4
  +++ apr_memory_system.h	2001/05/13 11:11:42	1.5
  @@ -51,6 +51,14 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
  +/* This code kindly donated to APR by 
  + *    Elrond  <elrond@samba-tng.org>
  + *    Luke Kenneth Casson Leighton <lkcl@samba-tng.org>
  + *    Sander Striker <striker@samba-tng.org>
  + *
  + * May 2001
  + */
    
   #ifndef APR_MEMORY_SYSTEM_H
   #define APR_MEMORY_SYSTEM_H
  @@ -66,32 +74,33 @@
    * @package APR memory system
    */
   
  -typedef struct apr_memory_system_t apr_memory_system_t;
  +typedef struct apr_sms_t apr_sms_t;
   
  -struct apr_memory_system_cleanup;
  +struct apr_sms_cleanup;
   
   /**
    * The memory system structure
    */
  -struct apr_memory_system_t
  +struct apr_sms_t
   {
  -  apr_memory_system_t  *parent_memory_system;
  -  apr_memory_system_t  *child_memory_system;
  -  apr_memory_system_t  *sibling_memory_system;
  -  apr_memory_system_t **ref_memory_system;
  -  apr_memory_system_t  *accounting_memory_system;
  -
  -  struct apr_memory_system_cleanup *cleanups;
  -
  -  void * (*malloc_fn)(apr_memory_system_t *memory_system, apr_size_t size);
  -  void * (*realloc_fn)(apr_memory_system_t *memory_system, void *memory, 
  -		       apr_size_t size);
  -  apr_status_t (*free_fn)(apr_memory_system_t *memory_system, void *memory);
  -  apr_status_t (*reset_fn)(apr_memory_system_t *memory_system);
  -  void (*pre_destroy_fn)(apr_memory_system_t *memory_system);
  -  void (*destroy_fn)(apr_memory_system_t *memory_system);
  -  void (*threadsafe_lock_fn)(apr_memory_system_t *memory_system);
  -  void (*threadsafe_unlock_fn)(apr_memory_system_t *memory_system);
  +  apr_sms_t  *parent_mem_sys;
  +  apr_sms_t  *child_mem_sys;
  +  apr_sms_t  *sibling_mem_sys;
  +  apr_sms_t **ref_mem_sys;
  +  apr_sms_t  *accounting_mem_sys;
  +
  +  struct apr_sms_cleanup *cleanups;
  +
  +  void * (*malloc_fn)(apr_sms_t *mem_sys, apr_size_t size);
  +  void * (*calloc_fn)(apr_sms_t *mem_sys, apr_size_t size);
  +  void * (*realloc_fn)(apr_sms_t *mem_sys, void *memory, 
  +                       apr_size_t size);
  +  apr_status_t (*free_fn)(apr_sms_t *mem_sys, void *memory);
  +  apr_status_t (*reset_fn)(apr_sms_t *mem_sys);
  +  void (*pre_destroy_fn)(apr_sms_t *mem_sys);
  +  void (*destroy_fn)(apr_sms_t *mem_sys);
  +  void (*threadsafe_lock_fn)(apr_sms_t *mem_sys);
  +  void (*threadsafe_unlock_fn)(apr_sms_t *mem_sys);
   };
   
   /*
  @@ -100,45 +109,46 @@
   
   /**
    * Allocate a block of memory using a certain memory system
  - * @param memory_system The memory system to use
  + * @param mem_sys The memory system to use
  + * @param size The (minimal required) size of the block to be allocated
  + * @return pointer to a newly allocated block of memory, NULL if insufficient
  + *         memory available
  + * @deffunc void *apr_sms_malloc(apr_sms_t *mem_sys, apr_size_t size)
  + */
  +APR_DECLARE(void *) apr_sms_malloc(apr_sms_t *mem_sys, apr_size_t size);
  +
  +/**
  + * Allocate a block of zeroed memory using a certain memory system
  + * @param mem_sys The memory system to use
    * @param size The (minimal required) size of the block to be allocated
    * @return pointer to a newly allocated block of memory, NULL if insufficient
    *         memory available
  - * @deffunc void *apr_memory_system_malloc(apr_memory_system_t *memory_system,
  - *					   apr_size_t size)
  + * @deffunc void *apr_sms_calloc(apr_sms_t *mem_sys, apr_size_t size)
    */
  -APR_DECLARE(void *) 
  -apr_memory_system_malloc(apr_memory_system_t *memory_system, 
  -                         apr_size_t size);
  +APR_DECLARE(void *) apr_sms_calloc(apr_sms_t *mem_sys, apr_size_t size);
   
   /**
    * Change the size of a previously allocated block of memory
  - * @param memory_system The memory system to use (should be the same as the
  + * @param mem_sys The memory system to use (should be the same as the
    *        one that returned the block)
    * @param mem Pointer to the previously allocated block. If NULL, this
  - *        function acts like apr_memory_system_malloc.
  + *        function acts like apr_sms_malloc.
    * @param size The (minimal required) size of the block to be allocated
    * @return pointer to a newly allocated block of memory, NULL if insufficient
    *         memory available
  - * @deffunc void *apr_memory_system_realloc(apr_memory_system_t *memory_system,
  - *					    void *mem, apr_size_t size)
  + * @deffunc void *apr_sms_realloc(apr_sms_t *mem_sys, void *mem, apr_size_t size)
    */
  -APR_DECLARE(void *) 
  -apr_memory_system_realloc(apr_memory_system_t *memory_system, 
  -                          void *mem,
  -                          apr_size_t size);
  +APR_DECLARE(void *) apr_sms_realloc(apr_sms_t *mem_sys, void *mem, apr_size_t size);
   
   /**
    * Free a block of memory
  - * @param memory_system The memory system to use (should be the same as the
  + * @param mem_sys The memory system to use (should be the same as the
    *        one that returned the block)
    * @param mem The block of memory to be freed
  - * @deffunc void apr_memory_system_free(apr_memory_system_t *memory_system,
  + * @deffunc void apr_sms_free(apr_sms_t *mem_sys,
    *					void *mem)
    */
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_free(apr_memory_system_t *memory_system,
  -                       void *mem);
  +APR_DECLARE(apr_status_t) apr_sms_free(apr_sms_t *mem_sys, void *mem);
   
   /*
    * memory system functions
  @@ -148,34 +158,32 @@
    * Create a memory system (actually it initialized a memory system structure)
    * @caution Call this function as soon as you have obtained a block of memory
    *          to serve as a memory system structure from your 
  - *          apr_xxx_memory_system_create. Only use this function when you are
  + *          apr_xxx_sms_create. Only use this function when you are
    *          implementing a memory system.
    * @param memory The memory to turn into a memory system
    * @warning The memory passed in should be at least of size 
  - *          sizeof(apr_memory_system_t)
  - * @param parent_memory_system The parent memory system
  + *          sizeof(apr_sms_t)
  + * @param parent_mem_sys The parent memory system
    * @return The freshly initialized memory system
  - * @deffunc apr_memory_system_t *apr_memory_system_create(void *memory,
  - *				   apr_memory_system_t *parent_memory_system)
  + * @deffunc apr_sms_t *apr_sms_create(void *memory,
  + *				   apr_sms_t *parent_mem_sys)
    */
  -APR_DECLARE(apr_memory_system_t *)
  -apr_memory_system_create(void *memory, 
  -                         apr_memory_system_t *parent_memory_system);
  +APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, apr_sms_t *parent_mem_sys);
   
   /**
    * Check if a memory system is obeying all rules. 
    * @caution Call this function as the last statement before returning a new
  - *          memory system from your apr_xxx_memory_system_create.
  - * @deffunc void apr_memory_system_validate(apr_memory_system_t *memory_system)
  + *          memory system from your apr_xxx_sms_create.
  + * @deffunc void apr_sms_validate(apr_sms_t *mem_sys)
    */
   #ifdef APR_MEMORY_SYSTEM_DEBUG
   APR_DECLARE(void) 
  -apr_memory_system_assert(apr_memory_system_t *memory_system);
  +apr_sms_assert(apr_sms_t *mem_sys);
   #else
  -#ifdef apr_memory_system_assert
  -#undef apr_memory_system_assert
  +#ifdef apr_sms_assert
  +#undef apr_sms_assert
   #endif
  -#define apr_memory_system_assert(memory_system)
  +#define apr_sms_assert(mem_sys)
   #endif /* APR_MEMORY_SYSTEM_DEBUG */
   
   /**
  @@ -184,50 +192,45 @@
    * @warning This function will fail if there is no reset function available
    *          for the given memory system (i.e. the memory system is non-
    *          tracking).
  - * @param memory_system The memory system to be reset
  - * @deffunc apr_status_t apr_memory_system_reset(apr_memory_system_t *memory_system)
  + * @param mem_sys The memory system to be reset
  + * @deffunc apr_status_t apr_sms_reset(apr_sms_t *mem_sys)
    */
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_reset(apr_memory_system_t *memory_system);
  +APR_DECLARE(apr_status_t) apr_sms_reset(apr_sms_t *mem_sys);
   
   /**
    * Destroy a memory system, effectively freeing all of its memory, and itself. 
    * This will also run all cleanup functions associated with the memory system.
    * @caution Be carefull when using this function with a non-tracking memory
    *          system
  - * @param memory_system The memory system to be destroyed
  - * @deffunc apr_status_t apr_memory_system_destroy(apr_memory_system_t *memory_system)
  + * @param mem_sys The memory system to be destroyed
  + * @deffunc apr_status_t apr_sms_destroy(apr_sms_t *mem_sys)
    */
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_destroy(apr_memory_system_t *memory_system);
  +APR_DECLARE(apr_status_t) apr_sms_destroy(apr_sms_t *mem_sys);
   
   /**
    * Perform thread-safe locking required whilst this memory system is modified
  - * @param memory_system The memory system to be locked for thread-safety
  - * @deffunc void apr_memory_system_threadsafe_lock(apr_memory_system_t *memory_system)
  + * @param mem_sys The memory system to be locked for thread-safety
  + * @deffunc void apr_sms_threadsafe_lock(apr_sms_t *mem_sys)
    */
  -APR_DECLARE(void)
  -apr_memory_system_threadsafe_lock(apr_memory_system_t *memory_system);
  +APR_DECLARE(void) apr_sms_threadsafe_lock(apr_sms_t *mem_sys);
   
   /**
    * Release thread-safe locking required whilst this memory system was
    * being modified
  - * @param memory_system The memory system to be released from thread-safety
  - * @deffunc void apr_memory_system_threadsafe_unlock(apr_memory_system_t *memory_system)
  + * @param mem_sys The memory system to be released from thread-safety
  + * @deffunc void apr_sms_threadsafe_unlock(apr_sms_t *mem_sys)
    */
  -APR_DECLARE(void)
  -apr_memory_system_threadsafe_unlock(apr_memory_system_t *memory_system);
  +APR_DECLARE(void) apr_sms_threadsafe_unlock(apr_sms_t *mem_sys);
   
   /**
    * Determine if memory system a is an ancestor of memory system b
    * @param a The memory system to search
    * @param b The memory system to search for
    * @return APR_SUCCESS if a is an ancestor of b, 1 if it isn't
  - * @deffunc apr_status_t apr_memory_system_is_ancestor(apr_memory_system_t *a,
  - *						     apr_memory_system_t *b)
  + * @deffunc apr_status_t apr_sms_is_ancestor(apr_sms_t *a,
  + *						     apr_sms_t *b)
    */
  -APR_DECLARE(apr_status_t) 
  -apr_memory_system_is_ancestor(apr_memory_system_t *a, apr_memory_system_t *b);
  +APR_DECLARE(apr_status_t) apr_sms_is_ancestor(apr_sms_t *a, apr_sms_t *b);
   
   /*
    * memory system cleanup management functions
  @@ -235,51 +238,46 @@
   
   /**
    * Register a function to be called when a memory system is reset or destroyed
  - * @param memory_system The memory system to register the cleanup function with
  + * @param mem_sys The memory system to register the cleanup function with
    * @param data The data to pass to the cleanup function
    * @param cleanup_fn The function to call when the memory system is reset or
    *        destroyed
  - * @deffunc void apr_memory_system_cleanup_register(apr_memory_system_t *memory_system,
  + * @deffunc void apr_sms_cleanup_register(apr_sms_t *mem_sys,
    *		   void *data, apr_status_t (*cleanup_fn)(void *));
    */
  -APR_DECLARE(apr_status_t) 
  -apr_memory_system_cleanup_register(apr_memory_system_t *memory_system, 
  -                                   void *data, 
  -                                   apr_status_t (*cleanup_fn)(void *));
  +APR_DECLARE(apr_status_t) apr_sms_cleanup_register(apr_sms_t *mem_sys, void *data, 
  +                                                   apr_status_t (*cleanup_fn)(void *));
   
   /**
    * Unregister a previously registered cleanup function
  - * @param memory_system The memory system the cleanup function is registered
  + * @param mem_sys The memory system the cleanup function is registered
    *        with
    * @param data The data associated with the cleanup function
    * @param cleanup_fn The registered cleanup function
  - * @deffunc void apr_memory_system_cleanup_unregister(apr_memory_system_t *memory_system,
  + * @deffunc void apr_sms_cleanup_unregister(apr_sms_t *mem_sys,
    *		   void *data, apr_status_t (*cleanup_fn)(void *));
    */
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_cleanup_unregister(apr_memory_system_t *memory_system,
  -                                     void *data,
  -                                     apr_status_t (*cleanup)(void *));
  +APR_DECLARE(apr_status_t) apr_sms_cleanup_unregister(apr_sms_t *mem_sys, void *data,
  +                                                     apr_status_t (*cleanup)(void *));
   
   /**
    * Run the specified cleanup function immediately and unregister it
  - * @param memory_system The memory system the cleanup function is registered
  + * @param mem_sys The memory system the cleanup function is registered
    *        with
    * @param data The data associated with the cleanup function
    * @param cleanup The registered cleanup function
  - * @deffunc apr_status_t apr_memory_system_cleanup_run(apr_memory_system_t *memory_system,
  + * @deffunc apr_status_t apr_sms_cleanup_run(apr_sms_t *mem_sys,
    *			   void *data, apr_status_t (*cleanup)(void *));
    */
  -APR_DECLARE(apr_status_t) 
  -apr_memory_system_cleanup_run(apr_memory_system_t *memory_system,
  -                              void *data,
  -                              apr_status_t (*cleanup)(void *));
  +APR_DECLARE(apr_status_t) apr_sms_cleanup_run(apr_sms_t *mem_sys, void *data,
  +                                              apr_status_t (*cleanup)(void *));
   
   /**
    * Create a standard malloc/realloc/free memory system
  + * @param mem_sys A pointer to the created apr_sms_t*
  + * @deffunc apr_status_t apr_sms_std_create(apr_sms_t **mem_sys);
    */
  -APR_DECLARE(apr_status_t)
  -apr_standard_memory_system_create(apr_memory_system_t **memory_system);
  +APR_DECLARE(apr_status_t) apr_sms_std_create(apr_sms_t **mem_sys);
   
   
   #ifdef __cplusplus
  
  
  
  1.4       +15 -3     apr/include/apr_tracking_memory_system.h
  
  Index: apr_tracking_memory_system.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_tracking_memory_system.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_tracking_memory_system.h	2001/05/10 10:33:10	1.3
  +++ apr_tracking_memory_system.h	2001/05/13 11:11:42	1.4
  @@ -52,6 +52,14 @@
    * <http://www.apache.org/>.
    */
   
  +/* This code kindly donated to APR by 
  + *    Elrond  <elrond@samba-tng.org>
  + *    Luke Kenneth Casson Leighton <lkcl@samba-tng.org>
  + *    Sander Striker <striker@samba-tng.org>
  + *
  + * May 2001
  + */
  +
   #ifndef APR_TRACKING_MEMORY_SYSTEM_H
   #define APR_TRACKING_MEMORY_SYSTEM_H
   
  @@ -68,10 +76,14 @@
   
   /**
    * Create a standard malloc/realloc/free memory system
  + * @param mem_sys A pointer to the returned apr_sms_t*
  + * @param pms The parent memory system, used to allocate the memory
  + *            that we will be tracking.
  + * @deffunc apr_status_t apr_sms_tracking_create(apr_sms_t **mem_sys,
  + *                                               apr_sms_t *pms);
    */
  -APR_DECLARE(apr_status_t)
  -apr_tracking_memory_system_create(apr_memory_system_t **memory_system,
  -				  apr_memory_system_t *parent_memory_system);
  +APR_DECLARE(apr_status_t) apr_sms_tracking_create(apr_sms_t **mem_sys,
  +                                                  apr_sms_t *pms);
   
   
   
  
  
  
  1.4       +192 -196  apr/memory/unix/apr_memory_system.c
  
  Index: apr_memory_system.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_memory_system.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_memory_system.c	2001/05/10 10:33:13	1.3
  +++ apr_memory_system.c	2001/05/13 11:11:45	1.4
  @@ -52,10 +52,12 @@
    * <http://www.apache.org/>.
    */
   
  -/* This code donated to APR by 
  +/* This code kindly donated to APR by 
    *    Elrond  <elrond@samba-tng.org>
    *    Luke Kenneth Casson Leighton <lkcl@samba-tng.org>
    *    Sander Striker <striker@samba-tng.org>
  + *
  + * May 2001
    */
    
   #include "apr.h"
  @@ -71,9 +73,9 @@
   /*
    * private structure defenitions
    */
  -struct apr_memory_system_cleanup
  +struct apr_sms_cleanup
   {
  -    struct apr_memory_system_cleanup *next;
  +    struct apr_sms_cleanup *next;
       void *data;
       apr_status_t (*cleanup_fn)(void *);
   };
  @@ -82,59 +84,66 @@
    * memory allocation functions
    */
   
  -APR_DECLARE(void *)
  -apr_memory_system_malloc(apr_memory_system_t *memory_system,
  -                         apr_size_t size)
  +APR_DECLARE(void *) apr_sms_malloc(apr_sms_t *mem_sys,
  +                                   apr_size_t size)
   {
  -    assert(memory_system != NULL);
  -    assert(memory_system->malloc_fn != NULL);
  +    assert(mem_sys != NULL);
  +    assert(mem_sys->malloc_fn != NULL);
    
       if (size == 0)
           return NULL;
   
  -    return memory_system->malloc_fn(memory_system, size);
  +    return mem_sys->malloc_fn(mem_sys, size);
   }
   
  -APR_DECLARE(void *)
  -apr_memory_system_realloc(apr_memory_system_t *memory_system,
  -                          void *mem,
  -                          apr_size_t size)
  +APR_DECLARE(void *) apr_sms_calloc(apr_sms_t *mem_sys,
  +                                   apr_size_t size)
   {
  -    assert(memory_system != NULL);
  -    assert(memory_system->realloc_fn != NULL);
  +    assert(mem_sys != NULL);
  +
  +    if (size == 0)
  +        return NULL;
   
  +    if (mem_sys->calloc_fn == NULL){
  +        /* Assumption - if we don't have calloc we have
  +         * malloc, might be bogus...
  +         */
  +        void *mem = mem_sys->malloc_fn(mem_sys, size);
  +        memset(mem, '\0', size);
  +        return mem;
  +    } else
  +        return mem_sys->calloc_fn(mem_sys, size);
  +}
  +
  +APR_DECLARE(void *) apr_sms_realloc(apr_sms_t *mem_sys, void *mem,
  +                                    apr_size_t size)
  +{
  +    assert(mem_sys != NULL);
  +    assert(mem_sys->realloc_fn != NULL);
  +
       if (mem == NULL)
  -        return apr_memory_system_malloc(memory_system, size);
  +        return apr_sms_malloc(mem_sys, size);
   
       if (size == 0)
       {
  -        apr_memory_system_free(memory_system, mem);
  +        apr_sms_free(mem_sys, mem);
           return NULL;
       }
   
  -    return memory_system->realloc_fn(memory_system, mem, size);
  +    return mem_sys->realloc_fn(mem_sys, mem, size);
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_free(apr_memory_system_t *memory_system,
  -                       void *mem)
  +APR_DECLARE(apr_status_t) apr_sms_free(apr_sms_t *mem_sys,
  +                                       void *mem)
   {
  -    assert(memory_system != NULL);
  +    assert(mem_sys != NULL);
     
       if (mem == NULL)
  -        return APR_EINVAL; /* Hmm, is this an error??? */
  +        return APR_EINVAL;
   
  -    if (memory_system->free_fn != NULL)
  -        return memory_system->free_fn(memory_system, mem);  
  +    if (mem_sys->free_fn != NULL)
  +        return mem_sys->free_fn(mem_sys, mem);  
   
  -#ifdef APR_MEMORY_SYSTEM_DEBUG
  -    else /* assume this is a tracking memory system */
  -    {
  -        /* issue a warning: 
  -         * WARNING: Called apr_memory_system_free() on a tracking memory system
  -         */
  -    }
  -#endif /* APR_MEMORY_SYSTEM_DEBUG */
       return APR_SUCCESS;
   }
   
  @@ -142,65 +151,63 @@
    * memory system functions
    */
   
  -static int apr_memory_system_is_tracking(apr_memory_system_t *memory_system)
  +static int apr_sms_is_tracking(apr_sms_t *mem_sys)
   {
       /*
        * The presense of a reset function gives us the clue that this is a 
        * tracking memory system.
        */
  -    return memory_system->reset_fn != NULL;
  +    return mem_sys->reset_fn != NULL;
   }
   
  -APR_DECLARE(apr_memory_system_t *)
  -apr_memory_system_create(void *memory, 
  -                         apr_memory_system_t *parent_memory_system)
  +APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, 
  +                                        apr_sms_t *parent_mem_sys)
   {
  -    apr_memory_system_t *memory_system;
  +    apr_sms_t *mem_sys;
   
       if (memory == NULL)
           return NULL;
   
       /* Just typecast it, and clear it */
  -    memory_system = (apr_memory_system_t *)memory;
  -    memset(memory_system, '\0', sizeof(apr_memory_system_t));
  +    mem_sys = (apr_sms_t *)memory;
  +    memset(mem_sys, '\0', sizeof(apr_sms_t));
   
       /* Initialize the parent and accounting memory system pointers */
  -    memory_system->parent_memory_system = parent_memory_system;
  -    memory_system->accounting_memory_system = memory_system;
  +    mem_sys->parent_mem_sys = parent_mem_sys;
  +    mem_sys->accounting_mem_sys = mem_sys;
   
  -    if (parent_memory_system != NULL)
  +    if (parent_mem_sys != NULL)
       {
  -        if ((memory_system->sibling_memory_system = 
  -           parent_memory_system->child_memory_system) != NULL)
  +        if ((mem_sys->sibling_mem_sys = 
  +           parent_mem_sys->child_mem_sys) != NULL)
           {
  -            memory_system->sibling_memory_system->ref_memory_system = 
  -              &memory_system->sibling_memory_system;
  +            mem_sys->sibling_mem_sys->ref_mem_sys = 
  +              &mem_sys->sibling_mem_sys;
           }
  -        memory_system->ref_memory_system = 
  -          &parent_memory_system->child_memory_system;
  -        parent_memory_system->child_memory_system = memory_system;
  +        mem_sys->ref_mem_sys = 
  +          &parent_mem_sys->child_mem_sys;
  +        parent_mem_sys->child_mem_sys = mem_sys;
       }
       /* This seems a bit redundant, but we're not taking chances */
       else
       {
  -        memory_system->ref_memory_system = NULL;
  -        memory_system->sibling_memory_system = NULL;
  -        memory_system->child_memory_system = NULL;
  +        mem_sys->ref_mem_sys = NULL;
  +        mem_sys->sibling_mem_sys = NULL;
  +        mem_sys->child_mem_sys = NULL;
       }
   
  -    return memory_system;
  +    return mem_sys;
   }
   
   #ifdef APR_MEMORY_SYSTEM_DEBUG
  -APR_DECLARE(void) 
  -apr_memory_system_assert(apr_memory_system_t *memory_system)
  +APR_DECLARE(void) apr_sms_assert(apr_sms_t *mem_sys)
   {
  -    apr_memory_system_t *parent;
  +    apr_sms_t *parent;
   
       /*
        * A memory system without a malloc won't do us much good
        */
  -    assert(memory_system->malloc_fn != NULL);
  +    assert(mem_sys->malloc_fn != NULL);
   
       /* 
        * Check to see if this is either a non-tracking or
  @@ -208,24 +215,24 @@
        * or destroy function. And to avoid half implementations
        * we require reset to be present when destroy is.
        */
  -    assert(memory_system->free_fn != NULL ||
  -         (memory_system->destroy_fn != NULL &&
  -          memory_system->reset_fn != NULL));
  +    assert(mem_sys->free_fn != NULL ||
  +         (mem_sys->destroy_fn != NULL &&
  +          mem_sys->reset_fn != NULL));
   
  -    assert(memory_system->destroy_fn == NULL ||
  -         memory_system->reset_fn != NULL);
  +    assert(mem_sys->destroy_fn == NULL ||
  +         mem_sys->reset_fn != NULL);
     
  -    assert(memory_system->reset_fn == NULL ||
  -         memory_system->destroy_fn != NULL);
  +    assert(mem_sys->reset_fn == NULL ||
  +         mem_sys->destroy_fn != NULL);
   
       /*
        * Make sure all accounting memory dies with the memory system.
        * To be more specific, make sure the accounting memort system
        * is either the memory system itself or a direct child.
        */
  -    assert(memory_system->accounting_memory_system == memory_system ||
  -	 memory_system->accounting_memory_system->parent_memory_system == 
  -	   memory_system);
  +    assert(mem_sys->accounting_mem_sys == mem_sys ||
  +	 mem_sys->accounting_mem_sys->parent_mem_sys == 
  +	   mem_sys);
   
       /*
        * A non-tracking memory system can be the child of
  @@ -233,16 +240,16 @@
        * tracking ancestors, but in that specific case we issue a
        * warning.
        */
  -    if (memory_system->parent_memory_system == NULL)
  +    if (mem_sys->parent_mem_sys == NULL)
           return;
   
  -    parent = memory_system
  +    parent = mem_sys
       while (parent)
       {
  -        if (apr_memory_system_is_tracking(parent))
  +        if (apr_sms_is_tracking(parent))
               return; /* Tracking memory system found, return satisfied ;-) */
   
  -        parent = parent->parent_memory_system;
  +        parent = parent->parent_mem_sys;
       }
   
       /* issue a warning: 
  @@ -254,19 +261,17 @@
   
   /*
    * LOCAL FUNCTION used in:
  - *  - apr_memory_system_do_child_cleanups
  - *  - apr_memory_system_reset
  - *  - apr_memory_system_destroy
  + *  - apr_sms_do_child_cleanups
  + *  - apr_sms_reset
  + *  - apr_sms_destroy
    *
    * Call all the cleanup routines registered with a memory system.
    */
  -static
  -void
  -apr_memory_system_do_cleanups(apr_memory_system_t *memory_system)
  +static void apr_sms_do_cleanups(apr_sms_t *mem_sys)
   {
  -    struct apr_memory_system_cleanup *cleanup;
  +    struct apr_sms_cleanup *cleanup;
   
  -    cleanup = memory_system->cleanups;
  +    cleanup = mem_sys->cleanups;
       while (cleanup)
       {
           cleanup->cleanup_fn(cleanup->data);
  @@ -276,50 +281,47 @@
   
   /*
    * LOCAL FUNCTION used in:
  - *  - apr_memory_system_reset
  - *  - apr_memory_system_destroy
  + *  - apr_sms_reset
  + *  - apr_sms_destroy
    *
    * This not only calls do_cleanups, but also calls the pre_destroy(!)
    */
  -static 
  -void 
  -apr_memory_system_do_child_cleanups(apr_memory_system_t *memory_system)
  +static void apr_sms_do_child_cleanups(apr_sms_t *mem_sys)
   {
  -    if (memory_system == NULL)
  +    if (mem_sys == NULL)
           return;
   
  -    memory_system = memory_system->child_memory_system;
  -    while (memory_system)
  +    mem_sys = mem_sys->child_mem_sys;
  +    while (mem_sys)
       {
  -        apr_memory_system_do_child_cleanups(memory_system);
  -        apr_memory_system_do_cleanups(memory_system);
  +        apr_sms_do_child_cleanups(mem_sys);
  +        apr_sms_do_cleanups(mem_sys);
   
  -        if (memory_system->pre_destroy_fn != NULL)
  -            memory_system->pre_destroy_fn(memory_system);
  +        if (mem_sys->pre_destroy_fn != NULL)
  +            mem_sys->pre_destroy_fn(mem_sys);
   
  -        memory_system = memory_system->sibling_memory_system;
  +        mem_sys = mem_sys->sibling_mem_sys;
       }
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_reset(apr_memory_system_t *memory_system)
  +APR_DECLARE(apr_status_t) apr_sms_reset(apr_sms_t *mem_sys)
   {
  -    assert(memory_system != NULL);
  +    assert(mem_sys != NULL);
       /* Assert when called on a non-tracking memory system */
  -    assert(memory_system->reset_fn != NULL);
  +    assert(mem_sys->reset_fn != NULL);
   
       /* 
        * Run the cleanups of all child memory systems _including_
        * the accounting memory system.
        */
  -    apr_memory_system_do_child_cleanups(memory_system);
  +    apr_sms_do_child_cleanups(mem_sys);
   
       /* Run all cleanups, the memory will be freed by the reset */
  -    apr_memory_system_do_cleanups(memory_system);
  -    memory_system->cleanups = NULL;
  +    apr_sms_do_cleanups(mem_sys);
  +    mem_sys->cleanups = NULL;
   
       /* We don't have any child memory systems after the reset */
  -    memory_system->child_memory_system = NULL;
  +    mem_sys->child_mem_sys = NULL;
   
       /* Reset the accounting memory system to ourselves, any
        * child memory system _including_ the accounting memory
  @@ -327,143 +329,142 @@
        * strikerXXX: Maybe this should be the responsibility of
        *             the reset function(?).
        */
  -    memory_system->accounting_memory_system = memory_system;
  +    mem_sys->accounting_mem_sys = mem_sys;
   
       /* Let the memory system handle the actual reset */
  -    return memory_system->reset_fn(memory_system);
  +    return mem_sys->reset_fn(mem_sys);
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_destroy(apr_memory_system_t *memory_system)
  +APR_DECLARE(apr_status_t) apr_sms_destroy(apr_sms_t *mem_sys)
   {
  -    apr_memory_system_t *child_memory_system;
  -    apr_memory_system_t *sibling_memory_system;
  -    struct apr_memory_system_cleanup *cleanup;
  -    struct apr_memory_system_cleanup *next_cleanup;
  +    apr_sms_t *child_mem_sys;
  +    apr_sms_t *sibling_mem_sys;
  +    struct apr_sms_cleanup *cleanup;
  +    struct apr_sms_cleanup *next_cleanup;
   
  -    assert(memory_system != NULL);
  +    assert(mem_sys != NULL);
   
  -    if (apr_memory_system_is_tracking(memory_system))
  +    if (apr_sms_is_tracking(mem_sys))
       {
           /* 
            * Run the cleanups of all child memory systems _including_
            * the accounting memory system.
            */
  -        apr_memory_system_do_child_cleanups(memory_system);
  +        apr_sms_do_child_cleanups(mem_sys);
   
           /* Run all cleanups, the memory will be freed by the destroy */
  -        apr_memory_system_do_cleanups(memory_system);
  +        apr_sms_do_cleanups(mem_sys);
       }
       else
       {
  -        if (memory_system->accounting_memory_system != memory_system)
  +        if (mem_sys->accounting_mem_sys != mem_sys)
           {
  -            child_memory_system = memory_system->accounting_memory_system;
  +            child_mem_sys = mem_sys->accounting_mem_sys;
   		    
               /* 
                * Remove the accounting memory system from the memory systems 
                * child list (we will explicitly destroy it later in this block).
                */
  -            if (child_memory_system->sibling_memory_system != NULL)
  -	            child_memory_system->sibling_memory_system->ref_memory_system =
  -	              child_memory_system->ref_memory_system;
  +            if (child_mem_sys->sibling_mem_sys != NULL)
  +	            child_mem_sys->sibling_mem_sys->ref_mem_sys =
  +	              child_mem_sys->ref_mem_sys;
   
  -            *child_memory_system->ref_memory_system = 
  -            child_memory_system->sibling_memory_system;
  +            *child_mem_sys->ref_mem_sys = 
  +            child_mem_sys->sibling_mem_sys;
   
               /* Set this fields so destroy will work */
  -            child_memory_system->ref_memory_system = NULL;
  -            child_memory_system->sibling_memory_system = NULL;
  +            child_mem_sys->ref_mem_sys = NULL;
  +            child_mem_sys->sibling_mem_sys = NULL;
           }
   
           /* Visit all children and destroy them */
  -        child_memory_system = memory_system->child_memory_system;
  -        while (child_memory_system != NULL)
  +        child_mem_sys = mem_sys->child_mem_sys;
  +        while (child_mem_sys != NULL)
           {
  -            sibling_memory_system = child_memory_system->sibling_memory_system;
  -            apr_memory_system_destroy(child_memory_system);
  -            child_memory_system = sibling_memory_system;
  +            sibling_mem_sys = child_mem_sys->sibling_mem_sys;
  +            apr_sms_destroy(child_mem_sys);
  +            child_mem_sys = sibling_mem_sys;
           }
   
           /*
            * If the accounting memory system _is_ tracking, we also know that it is
            * not the memory system itself.
            */
  -        if (apr_memory_system_is_tracking(memory_system->accounting_memory_system))
  +        if (apr_sms_is_tracking(mem_sys->accounting_mem_sys))
           {
               /* 
                * Run all cleanups, the memory will be freed by the destroying of the
                * accounting memory system.
                */
  -            apr_memory_system_do_cleanups(memory_system);
  +            apr_sms_do_cleanups(mem_sys);
   
               /* Destroy the accounting memory system */
  -            apr_memory_system_destroy(memory_system->accounting_memory_system);
  +            apr_sms_destroy(mem_sys->accounting_mem_sys);
   
               /* 
                * Set the accounting memory system back to the parent memory system
                * just in case...
                */
  -            memory_system->accounting_memory_system = memory_system;
  +            mem_sys->accounting_mem_sys = mem_sys;
           }
           else
           {
               /* Run all cleanups, free'ing memory as we go */
  -            cleanup = memory_system->cleanups;
  +            cleanup = mem_sys->cleanups;
               while (cleanup)
               {
                   cleanup->cleanup_fn(cleanup->data);
                   next_cleanup = cleanup->next;
  -                apr_memory_system_free(memory_system->accounting_memory_system, 
  +                apr_sms_free(mem_sys->accounting_mem_sys, 
   			       cleanup);
                   cleanup = next_cleanup;
               }
   
  -            if (memory_system->accounting_memory_system != memory_system)
  +            if (mem_sys->accounting_mem_sys != mem_sys)
               {
                   /* Destroy the accounting memory system */
  -                apr_memory_system_destroy(memory_system->accounting_memory_system);
  +                apr_sms_destroy(mem_sys->accounting_mem_sys);
                   /* 
                    * Set the accounting memory system back to the parent memory system
                    * just in case...
                    */
  -                memory_system->accounting_memory_system = memory_system;
  +                mem_sys->accounting_mem_sys = mem_sys;
               }
          }
     }
   
     /* Remove the memory system from the parent memory systems child list */
  -  if (memory_system->sibling_memory_system != NULL)
  -      memory_system->sibling_memory_system->ref_memory_system =
  -        memory_system->ref_memory_system;
  -  if (memory_system->ref_memory_system != NULL)
  -      *memory_system->ref_memory_system = memory_system->sibling_memory_system;
  +  if (mem_sys->sibling_mem_sys != NULL)
  +      mem_sys->sibling_mem_sys->ref_mem_sys =
  +        mem_sys->ref_mem_sys;
  +  if (mem_sys->ref_mem_sys != NULL)
  +      *mem_sys->ref_mem_sys = mem_sys->sibling_mem_sys;
   
     /* Call the pre-destroy if present */
  -  if (memory_system->pre_destroy_fn != NULL)
  -      memory_system->pre_destroy_fn(memory_system);
  +  if (mem_sys->pre_destroy_fn != NULL)
  +      mem_sys->pre_destroy_fn(mem_sys);
   
     /* 1 - If we have a self destruct, use it */
  -  if (memory_system->destroy_fn != NULL)
  -      memory_system->destroy_fn(memory_system);
  +  if (mem_sys->destroy_fn != NULL)
  +      mem_sys->destroy_fn(mem_sys);
   
     /* 2 - If we don't have a parent, free using ourselves */
  -  else if (memory_system->parent_memory_system == NULL)
  -      memory_system->free_fn(memory_system, memory_system);
  +  else if (mem_sys->parent_mem_sys == NULL)
  +      mem_sys->free_fn(mem_sys, mem_sys);
   
     /* 3 - If we do have a parent and it has a free function, use it */
  -  else if (memory_system->parent_memory_system->free_fn != NULL)
  -      apr_memory_system_free(memory_system->parent_memory_system, memory_system);
  +  else if (mem_sys->parent_mem_sys->free_fn != NULL)
  +      apr_sms_free(mem_sys->parent_mem_sys, mem_sys);
   
     /* 4 - Assume we are the child of a tracking memory system, and do nothing */
   #ifdef APR_MEMORY_SYSTEM_DEBUG
  -    memory_system = memory_system->parent_memory_system;
  -    while (memory_system)
  +    mem_sys = mem_sys->parent_mem_sys;
  +    while (mem_sys)
       {
  -        if (apr_memory_system_is_tracking(memory_system))
  +        if (apr_sms_is_tracking(mem_sys))
               return APR_SUCCESS;
   
  -        memory_system = memory_system->parent_memory_system;
  +        mem_sys = mem_sys->parent_mem_sys;
       }
   
       assert(0); /* Made the wrong assumption, so we assert */
  @@ -471,91 +472,87 @@
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_is_ancestor(apr_memory_system_t *a,
  -                              apr_memory_system_t *b)
  +APR_DECLARE(apr_status_t) apr_sms_is_ancestor(apr_sms_t *a,
  +                                              apr_sms_t *b)
   {
       assert(b != NULL);
   
       while (b && b != a)
  -        b = b->parent_memory_system;
  +        b = b->parent_mem_sys;
   
  -    /* strikerXXX: should this be: return b == a ? APR_TRUE : APR_FALSE; */
       /* APR_SUCCESS = 0, so if they agree we should return that... */
       return !(b == a); 
   }
   
   APR_DECLARE(void)
  -apr_memory_system_threadsafe_lock(apr_memory_system_t *memory_system)
  +apr_sms_threadsafe_lock(apr_sms_t *mem_sys)
   {
  -    assert(memory_system != NULL);
  -    if (memory_system->threadsafe_lock_fn != NULL)
  -        memory_system->threadsafe_lock_fn(memory_system);
  +    assert(mem_sys != NULL);
  +    if (mem_sys->threadsafe_lock_fn != NULL)
  +        mem_sys->threadsafe_lock_fn(mem_sys);
   }
   
   APR_DECLARE(void)
  -apr_memory_system_threadsafe_unlock(apr_memory_system_t *memory_system)
  +apr_sms_threadsafe_unlock(apr_sms_t *mem_sys)
   {
  -    assert(memory_system != NULL);
  -    if (memory_system->threadsafe_unlock_fn != NULL)
  -        memory_system->threadsafe_unlock_fn(memory_system);
  +    assert(mem_sys != NULL);
  +    if (mem_sys->threadsafe_unlock_fn != NULL)
  +        mem_sys->threadsafe_unlock_fn(mem_sys);
   }
   
   /*
    * memory system cleanup management functions
    */
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_cleanup_register(apr_memory_system_t *memory_system,
  -                                   void *data,
  -                                   apr_status_t (*cleanup_fn)(void *))
  +APR_DECLARE(apr_status_t) 
  +apr_sms_cleanup_register(apr_sms_t *mem_sys, void *data,
  +                         apr_status_t (*cleanup_fn)(void *))
   {
  -    struct apr_memory_system_cleanup *cleanup;
  +    struct apr_sms_cleanup *cleanup;
   
  -    assert(memory_system != NULL);
  -    assert(memory_system->accounting_memory_system != NULL);
  +    assert(mem_sys != NULL);
  +    assert(mem_sys->accounting_mem_sys != NULL);
   
       if (cleanup_fn == NULL)
           return APR_EINVAL;
   
  -    cleanup = (struct apr_memory_system_cleanup *)
  -	    apr_memory_system_malloc(memory_system->accounting_memory_system,
  -				     sizeof(struct apr_memory_system_cleanup));
  +    cleanup = (struct apr_sms_cleanup *)
  +	    apr_sms_malloc(mem_sys->accounting_mem_sys,
  +				     sizeof(struct apr_sms_cleanup));
   
       if (cleanup == NULL)
           return APR_ENOMEM;
   
       cleanup->data = data;
       cleanup->cleanup_fn = cleanup_fn;
  -    cleanup->next = memory_system->cleanups;
  -    memory_system->cleanups = cleanup;
  +    cleanup->next = mem_sys->cleanups;
  +    mem_sys->cleanups = cleanup;
   
       return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t)
  -apr_memory_system_cleanup_unregister(apr_memory_system_t *memory_system,
  -                                     void *data,
  -                                     apr_status_t (*cleanup_fn)(void *))
  +apr_sms_cleanup_unregister(apr_sms_t *mem_sys, void *data,
  +                           apr_status_t (*cleanup_fn)(void *))
   {
  -    struct apr_memory_system_cleanup *cleanup;
  -    struct apr_memory_system_cleanup **cleanup_ref;
  +    struct apr_sms_cleanup *cleanup;
  +    struct apr_sms_cleanup **cleanup_ref;
   
  -    assert(memory_system != NULL);
  -    assert(memory_system->accounting_memory_system != NULL);
  +    assert(mem_sys != NULL);
  +    assert(mem_sys->accounting_mem_sys != NULL);
   
  -    cleanup = memory_system->cleanups;
  -    cleanup_ref = &memory_system->cleanups;
  +    cleanup = mem_sys->cleanups;
  +    cleanup_ref = &mem_sys->cleanups;
       while (cleanup)
       {
           if (cleanup->data == data && cleanup->cleanup_fn == cleanup_fn)
           {
               *cleanup_ref = cleanup->next;
   
  -            memory_system = memory_system->accounting_memory_system;
  +            mem_sys = mem_sys->accounting_mem_sys;
   
  -            if (memory_system->free_fn != NULL)
  -                apr_memory_system_free(memory_system, cleanup);
  +            if (mem_sys->free_fn != NULL)
  +                apr_sms_free(mem_sys, cleanup);
   
               return APR_SUCCESS;
           }
  @@ -568,11 +565,10 @@
       return APR_ENOCLEANUP;
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_memory_system_cleanup_run(apr_memory_system_t *memory_system, 
  -			      void *data, 
  -			      apr_status_t (*cleanup_fn)(void *))
  +APR_DECLARE(apr_status_t) 
  +apr_sms_cleanup_run(apr_sms_t *mem_sys, void *data, 
  +			        apr_status_t (*cleanup_fn)(void *))
   {
  -    apr_memory_system_cleanup_unregister(memory_system, data, cleanup_fn);
  +    apr_sms_cleanup_unregister(mem_sys, data, cleanup_fn);
       return cleanup_fn(data);
   }
  
  
  
  1.4       +41 -28    apr/memory/unix/apr_standard_memory_system.c
  
  Index: apr_standard_memory_system.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_standard_memory_system.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_standard_memory_system.c	2001/05/11 00:29:23	1.3
  +++ apr_standard_memory_system.c	2001/05/13 11:11:45	1.4
  @@ -52,15 +52,16 @@
    * <http://www.apache.org/>.
    */
   
  -/* This code donated to APR by 
  +/* This code kindly donated to APR by 
    *    Elrond  <elrond@samba-tng.org>
    *    Luke Kenneth Casson Leighton <lkcl@samba-tng.org>
    *    Sander Striker <striker@samba-tng.org>
  + *
  + * May 2001
    */
   
   #include "apr.h"
   #include "apr_private.h"
  -#include "apr_general.h"
   #include "apr_memory_system.h"
   #include <stdlib.h>
   #include <assert.h>
  @@ -69,51 +70,63 @@
    * standard memory system
    */
   
  -static 
  -void *
  -apr_standard_memory_system_malloc(apr_memory_system_t *memory_system,
  -                                  apr_size_t size)
  +static void * apr_sms_std_malloc(apr_sms_t *mem_sys,
  +                                 apr_size_t size)
   {
       return malloc(size);
   }
   
  -static 
  -void *
  -apr_standard_memory_system_realloc(apr_memory_system_t *memory_system,
  -                                   void *mem, apr_size_t size)
  +static void * apr_sms_std_calloc(apr_sms_t *mem_sys,
  +                                 apr_size_t size)
   {
  +#if HAVE_CALLOC
  +    return calloc(1, size);
  +#else
  +    void *mem;
  +    mem = malloc(size);
  +    memset(mem, '\0', size);
  +    return mem;
  +#endif
  +}
  +
  +
  +static void * apr_sms_std_realloc(apr_sms_t *mem_sys,
  +                                  void *mem, apr_size_t size)
  +{
       return realloc(mem, size);
   }
   
  -static 
  -apr_status_t
  -apr_standard_memory_system_free(apr_memory_system_t *memory_system,
  -                                void *mem)
  +static apr_status_t apr_sms_std_free(apr_sms_t *mem_sys,
  +                                     void *mem)
   {
       free(mem);
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_standard_memory_system_create(apr_memory_system_t **memory_system)
  +APR_DECLARE(apr_status_t) apr_sms_std_create(apr_sms_t **mem_sys)
   {
  -    apr_memory_system_t *new_memory_system;
  +    apr_sms_t *new_mem_sys;
   
  -    assert(memory_system != NULL);
  +    assert(mem_sys != NULL);
   
  -    *memory_system = NULL;
  -    new_memory_system = apr_memory_system_create(
  -        malloc(sizeof(apr_memory_system_t)), NULL);
  +    *mem_sys = NULL;
  +    /* should we be using apr_sms_calloc now we have it??? */
  +    new_mem_sys = apr_sms_create(malloc(sizeof(apr_sms_t)),
  +                                 NULL);
   
  -    if (new_memory_system == NULL)
  +    if (new_mem_sys == NULL)
           return APR_ENOMEM;
  -
  -    new_memory_system->malloc_fn = apr_standard_memory_system_malloc;
  -    new_memory_system->realloc_fn = apr_standard_memory_system_realloc;
  -    new_memory_system->free_fn = apr_standard_memory_system_free;
   
  -    apr_memory_system_assert(new_memory_system);
  +    new_mem_sys->malloc_fn  = apr_sms_std_malloc;
  +    new_mem_sys->calloc_fn  = apr_sms_std_calloc;
  +    new_mem_sys->realloc_fn = apr_sms_std_realloc;
  +    new_mem_sys->free_fn    = apr_sms_std_free;
  +    /* as we're not a tracking memory module, i.e. we don't keep
  +     * track of our allocations, we don't have apr_sms_reset or
  +     * apr_sms_destroy functions.
  +     */
  +    apr_sms_assert(new_mem_sys);
   
  -    *memory_system = new_memory_system;
  +    *mem_sys = new_mem_sys;
       return APR_SUCCESS;
   }
  
  
  
  1.4       +92 -75    apr/memory/unix/apr_tracking_memory_system.c
  
  Index: apr_tracking_memory_system.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_tracking_memory_system.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_tracking_memory_system.c	2001/05/11 00:29:23	1.3
  +++ apr_tracking_memory_system.c	2001/05/13 11:11:46	1.4
  @@ -52,10 +52,12 @@
    * <http://www.apache.org/>.
    */
   
  -/* This code donated to APR by 
  +/* This code kindly donated to APR by 
    *    Elrond  <elrond@samba-tng.org>
    *    Luke Kenneth Casson Leighton <lkcl@samba-tng.org>
    *    Sander Striker <striker@samba-tng.org>
  + *
  + * May 2001
    */
   
   #include "apr.h"
  @@ -66,41 +68,39 @@
   #include <assert.h>
   
   /*
  - * tracking memory system
  + * Simple tracking memory system
    */
   
   /* INTERNALLY USED STRUCTURES */
   typedef struct apr_track_node_t
   {
  -    struct apr_track_node_t *next;
  +    struct apr_track_node_t  *next;
       struct apr_track_node_t **ref;
   } apr_track_node_t;
   
  -typedef struct apr_tracking_memory_system_t
  +typedef struct apr_sms_tracking_t
   {
  -    apr_memory_system_t  header;
  +    apr_sms_t            header;
       apr_track_node_t    *nodes;
  -} apr_tracking_memory_system_t;
  +} apr_sms_tracking_t;
   
  -static 
  -void *
  -apr_tracking_memory_system_malloc(apr_memory_system_t *memory_system,
  -                                  apr_size_t size)
  +static void * apr_sms_tracking_malloc(apr_sms_t *mem_sys,
  +                                      apr_size_t size)
   {
  -    apr_tracking_memory_system_t *tracking_memory_system;
  +    apr_sms_tracking_t *tms;
       apr_track_node_t *node;
     
  -    assert (memory_system != NULL);
  +    assert (mem_sys != NULL);
   
  -    tracking_memory_system = (apr_tracking_memory_system_t *)memory_system;
  -    node = apr_memory_system_malloc(memory_system->parent_memory_system,
  -				  size + sizeof(apr_track_node_t));
  +    tms = (apr_sms_tracking_t *)mem_sys;
  +    node = apr_sms_malloc(mem_sys->parent_mem_sys,
  +                          size + sizeof(apr_track_node_t));
       if (node == NULL)
           return NULL;
   
  -    node->next = tracking_memory_system->nodes;
  -    tracking_memory_system->nodes = node;
  -    node->ref = &tracking_memory_system->nodes;
  +    node->next = tms->nodes;
  +    tms->nodes = node;
  +    node->ref = &tms->nodes;
       if (node->next != NULL)
           node->next->ref = &node->next;
   
  @@ -109,17 +109,40 @@
       return (void *)node;
   }
   
  -static 
  -void *
  -apr_tracking_memory_system_realloc(apr_memory_system_t *memory_system,
  -                                   void *mem, apr_size_t size)
  +static  void * apr_sms_tracking_calloc(apr_sms_t *mem_sys, 
  +                                       apr_size_t size)
   {
  -    apr_tracking_memory_system_t *tracking_memory_system;
  +    apr_sms_tracking_t *tms;
       apr_track_node_t *node;
  +  
  +    assert (mem_sys != NULL);
  +
  +    tms = (apr_sms_tracking_t *)mem_sys;
  +    node = apr_sms_calloc(mem_sys->parent_mem_sys,
  +                          size + sizeof(apr_track_node_t));
  +    if (node == NULL)
  +        return NULL;
  +
  +    node->next = tms->nodes;
  +    tms->nodes = node;
  +    node->ref = &tms->nodes;
  +    if (node->next != NULL)
  +        node->next->ref = &node->next;
  +
  +    node++;
  +
  +    return (void *)node;
  +}
   
  -    assert (memory_system != NULL);
  +static  void * apr_sms_tracking_realloc(apr_sms_t *mem_sys,
  +                                        void *mem, apr_size_t size)
  +{
  +    apr_sms_tracking_t *tms;
  +    apr_track_node_t *node;
   
  -    tracking_memory_system = (apr_tracking_memory_system_t *)memory_system;
  +    assert (mem_sys != NULL);
  +
  +    tms = (apr_sms_tracking_t *)mem_sys;
       node = (apr_track_node_t *)mem;
   
       if (node != NULL)
  @@ -128,14 +151,14 @@
           *(node->ref) = node->next;
       }
   
  -    node = apr_memory_system_realloc(memory_system->parent_memory_system,
  -				   node, size + sizeof(apr_track_node_t));
  +    node = apr_sms_realloc(mem_sys->parent_mem_sys,
  +                           node, size + sizeof(apr_track_node_t));
       if (node == NULL)
           return NULL;
   
  -    node->next = tracking_memory_system->nodes;
  -    tracking_memory_system->nodes = node;
  -    node->ref = &tracking_memory_system->nodes;
  +    node->next = tms->nodes;
  +    tms->nodes = node;
  +    node->ref = &tms->nodes;
       if (node->next != NULL)
           node->next->ref = &node->next;
   
  @@ -144,14 +167,12 @@
       return (void *)node;
   }
   
  -static 
  -apr_status_t
  -apr_tracking_memory_system_free(apr_memory_system_t *memory_system,
  -                                void *mem)
  +static  apr_status_t apr_sms_tracking_free(apr_sms_t *mem_sys,
  +                                           void *mem)
   {
       apr_track_node_t *node;
   
  -    assert (memory_system != NULL);
  +    assert (mem_sys != NULL);
       assert (mem != NULL);
   
       node = (apr_track_node_t *)mem;
  @@ -161,74 +182,70 @@
       if (node->next != NULL)
           node->next->ref = node->ref;
             
  -    return apr_memory_system_free(memory_system->parent_memory_system, node);
  +    return apr_sms_free(mem_sys->parent_mem_sys, node);
   }
   
  -static
  -apr_status_t
  -apr_tracking_memory_system_reset(apr_memory_system_t *memory_system)
  +static apr_status_t apr_sms_tracking_reset(apr_sms_t *mem_sys)
   {
  -    apr_tracking_memory_system_t *tracking_memory_system;
  +    apr_sms_tracking_t *tms;
       apr_track_node_t *node;
       apr_status_t rv;
       
  -    assert (memory_system != NULL);
  +    assert (mem_sys != NULL);
   
  -    tracking_memory_system = (apr_tracking_memory_system_t *)memory_system;
  +    tms = (apr_sms_tracking_t *)mem_sys;
   
  -    while (tracking_memory_system->nodes != NULL)
  +    while (tms->nodes != NULL)
       {
  -        node = tracking_memory_system->nodes;
  +        node = tms->nodes;
           *(node->ref) = node->next;
           if (node->next != NULL)
               node->next->ref = node->ref;
  -        if ((rv = apr_memory_system_free(memory_system->parent_memory_system,
  -                                         node)) != APR_SUCCESS)
  +        if ((rv = apr_sms_free(mem_sys->parent_mem_sys, 
  +                               node)) != APR_SUCCESS)
               return rv;
       }
       return APR_SUCCESS;
   }
   
  -static
  -void
  -apr_tracking_memory_system_destroy(apr_memory_system_t *memory_system)
  +static void apr_sms_tracking_destroy(apr_sms_t *mem_sys)
   {
  -    assert (memory_system != NULL);
  +    assert (mem_sys != NULL);
   
  -    apr_tracking_memory_system_reset(memory_system);
  -    apr_memory_system_free(memory_system->parent_memory_system, memory_system);
  +    apr_sms_tracking_reset(mem_sys);
  +    apr_sms_free(mem_sys->parent_mem_sys, mem_sys);
   }
   
  -APR_DECLARE(apr_status_t)
  -apr_tracking_memory_system_create(apr_memory_system_t **memory_system,
  -				  apr_memory_system_t *parent_memory_system)
  +APR_DECLARE(apr_status_t) apr_sms_tracking_create(apr_sms_t **mem_sys, 
  +                                                  apr_sms_t *pms)
   {
  -    apr_memory_system_t *new_memory_system;
  -    apr_tracking_memory_system_t *tracking_memory_system;
  -
  -    assert (memory_system != NULL);
  -    assert (parent_memory_system != NULL);
  +    apr_sms_t *new_mem_sys, *tmpms;
  +    apr_sms_tracking_t *tms;
   
  -    new_memory_system = apr_memory_system_create(
  -        apr_memory_system_malloc(parent_memory_system, 
  -                                 sizeof(apr_tracking_memory_system_t)), 
  -		parent_memory_system);
  +    assert (mem_sys != NULL);
  +    assert (pms != NULL);
  +    *mem_sys = NULL;
  +    /* changed this to 2 stages to make easier to follow...
  +     * should we be using apr_sms_calloc now we have it? 
  +     */
  +    tmpms = apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));
  +    new_mem_sys = apr_sms_create(tmpms, pms);
   
  -    *memory_system = NULL;
  -    if (new_memory_system == NULL)
  +    if (new_mem_sys == NULL)
           return APR_ENOMEM;
   
  -    new_memory_system->malloc_fn = apr_tracking_memory_system_malloc;
  -    new_memory_system->realloc_fn = apr_tracking_memory_system_realloc;
  -    new_memory_system->free_fn = apr_tracking_memory_system_free;
  -    new_memory_system->reset_fn = apr_tracking_memory_system_reset;
  -    new_memory_system->destroy_fn = apr_tracking_memory_system_destroy;
  +    new_mem_sys->malloc_fn  = apr_sms_tracking_malloc;
  +    new_mem_sys->calloc_fn  = apr_sms_tracking_calloc;
  +    new_mem_sys->realloc_fn = apr_sms_tracking_realloc;
  +    new_mem_sys->free_fn    = apr_sms_tracking_free;
  +    new_mem_sys->reset_fn   = apr_sms_tracking_reset;
  +    new_mem_sys->destroy_fn = apr_sms_tracking_destroy;
   
  -    tracking_memory_system = (apr_tracking_memory_system_t *)new_memory_system;
  -    tracking_memory_system->nodes = NULL;
  +    tms = (apr_sms_tracking_t *)new_mem_sys;
  +    tms->nodes = NULL;
   
  -    apr_memory_system_assert(new_memory_system);
  +    apr_sms_assert(new_mem_sys);
   
  -    *memory_system = new_memory_system;
  +    *mem_sys = new_mem_sys;
       return APR_SUCCESS;
   }
  
  
  
  1.4       +55 -16    apr/test/testmem.c
  
  Index: testmem.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testmem.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testmem.c	2001/05/11 00:29:24	1.3
  +++ testmem.c	2001/05/13 11:11:48	1.4
  @@ -69,22 +69,55 @@
   #define LUMPS 10
   #define LUMP_SIZE 1024
   char *ptrs[LUMPS];
  +int cntr;
   
  -static void do_test(apr_memory_system_t *ams)
  +static void malloc_mem(apr_sms_t *ams)
   {
  -    int cntr,cntr2;
  +    int cntr;
       
  -    printf("\tCreating %d lumps of memory, each %d bytes........", 
  +    printf("\tMalloc'ing %d lumps of memory, each %d bytes......", 
              LUMPS, LUMP_SIZE);
       for (cntr = 0;cntr < LUMPS;cntr ++){
  -        ptrs[cntr] = apr_memory_system_malloc(ams, LUMP_SIZE);
  +        ptrs[cntr] = apr_sms_malloc(ams, LUMP_SIZE);
           if (!ptrs[cntr]){
               printf("Failed @ lump %d of %d\n", cntr + 1, LUMPS);
               exit (-1);
           }
       }
       printf ("OK\n");
  +}
   
  +static void calloc_mem(apr_sms_t *ams)
  +{
  +    int cntr, cntr2;
  +    
  +    printf("\tCalloc'ing %d lumps of memory, each %d bytes......", 
  +           LUMPS, LUMP_SIZE);
  +    for (cntr = 0;cntr < LUMPS;cntr ++){
  +        ptrs[cntr] = apr_sms_calloc(ams, LUMP_SIZE);
  +        if (!ptrs[cntr]){
  +            printf("Failed @ lump %d of %d\n", cntr + 1, LUMPS);
  +            exit (-1);
  +        }
  +    }
  +    printf ("OK\n");
  +    printf("\t (checking that memory is zeroed..................");
  +    for (cntr = 0;cntr < LUMPS;cntr++){
  +        for (cntr2 = 0;cntr2 < LUMP_SIZE; cntr2 ++){
  +            if (*(ptrs[cntr] + cntr2) != 0){
  +                printf("Failed!\nGot %d instead of 0 at byte %d\n",
  +                       *(ptrs[cntr] + cntr2), cntr2 + 1);
  +                exit (-1);
  +            }
  +        }
  +    } 
  +    printf("OK)\n");
  +}
  +
  +static void do_test(apr_sms_t *ams)
  +{
  +    int cntr,cntr2;
  +    
       printf("\tWriting to the lumps of memory......................");
       for (cntr = 0;cntr < LUMPS;cntr ++){
           if (memset(ptrs[cntr], cntr, LUMP_SIZE) != ptrs[cntr]){
  @@ -107,13 +140,13 @@
       printf("OK\n");   
   }
   
  -static void do_free(apr_memory_system_t *ams)
  +static void do_free(apr_sms_t *ams)
   {
       int cntr;
       
       printf("\tFreeing the memory we created.......................");
       for (cntr = 0;cntr < LUMPS;cntr ++){
  -        if (apr_memory_system_free(ams, ptrs[cntr]) != APR_SUCCESS){
  +        if (apr_sms_free(ams, ptrs[cntr]) != APR_SUCCESS){
               printf("Failed to free block %d\n", cntr + 1);
               exit (-1);
           }
  @@ -123,7 +156,7 @@
   
   int main(void)
   {
  -    apr_memory_system_t *ams, *ams2;
  +    apr_sms_t *ams, *tms;
       apr_initialize();
       
       printf("APR Memory Test\n");
  @@ -131,47 +164,53 @@
   
       printf("Standard Memory\n");
       printf("\tCreating the memory area............................");
  -    if (apr_standard_memory_system_create(&ams) != APR_SUCCESS){
  +    if (apr_sms_std_create(&ams) != APR_SUCCESS){
           printf("Failed.\n");
           exit(-1);
       }
       printf("OK\n");
   
  +    malloc_mem(ams);
       do_test(ams);
       do_free(ams);
  +    calloc_mem(ams);
  +    do_test(ams);    
  +    do_free(ams);
       
       printf("Tracking Memory\n");
       printf("\tCreating the memory area............................");
  -    if (apr_tracking_memory_system_create(&ams2, ams) != APR_SUCCESS){
  +    if (apr_sms_tracking_create(&tms, ams) != APR_SUCCESS){
           printf("Failed.\n");
           exit(-1);
       }
       printf("OK\n");
   
  -    do_test(ams2);
  +    malloc_mem(tms);
  +    do_test(tms);
       printf("\tAbout to reset the tracking memory..................");
  -    if (apr_memory_system_reset(ams2) != APR_SUCCESS){
  +    if (apr_sms_reset(tms) != APR_SUCCESS){
           printf("Failed.\n");
           exit(-1);
       }
       printf("OK\n");
  -    do_test(ams2);
  -    do_free(ams2);
  +    calloc_mem(tms);
  +    do_test(tms);
  +    do_free(tms);
       
       printf("Trying to destroy the tracking memory segment...............");
  -    if (apr_memory_system_destroy(ams2) != APR_SUCCESS){
  +    if (apr_sms_destroy(tms) != APR_SUCCESS){
           printf("Failed.\n");
           exit (-1);
       }
       printf("OK\n");
   
       printf("Trying to destroy the standard memory segment...............");
  -    if (apr_memory_system_destroy(ams) != APR_SUCCESS){
  +    if (apr_sms_destroy(ams) != APR_SUCCESS){
           printf("Failed.\n");
           exit (-1);
       }
       printf("OK\n\n");
   
  -    printf("Memory test complete.\n");
  +    printf("Memory test passed.\n");
       return (0);          
   }
  
  
  

Mime
View raw message