apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/memory/unix apr_sms.c apr_sms_std.c apr_sms_tracking.c
Date Fri, 01 Jun 2001 17:32:15 GMT
dreid       01/06/01 10:32:15

  Modified:    include  apr_sms.h
               memory/unix apr_sms.c apr_sms_std.c apr_sms_tracking.c
  Log:
  This changes apr_sms_create into a more appropriately named
  apr_sms_init. It also now returns an apr_status_t which is more
  inline with the rest of the code.
  
  I've changed to using calloc for the memory structures rather
  than memset in the function, but we may want to change this again.
  This patch is a modified version of one submitted by Sander Striker.
  
  Submitted by:	Sander Striker <striker@samba-tng.org>
  Reviewed by:	David Reid (applied in a modified form)
  
  Revision  Changes    Path
  1.7       +6 -8      apr/include/apr_sms.h
  
  Index: apr_sms.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_sms.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_sms.h	2001/05/30 11:03:32	1.6
  +++ apr_sms.h	2001/06/01 17:32:12	1.7
  @@ -161,20 +161,18 @@
    */
   
   /**
  - * Create a memory system (actually it initialized a memory system structure)
  + * Initialize a memory system
    * @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_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_sms_t)
  + * @param mem_sys The memory system created
    * @param parent_mem_sys The parent memory system
  - * @return The freshly initialized memory system
  - * @deffunc apr_sms_t *apr_sms_create(void *memory,
  - *				   apr_sms_t *parent_mem_sys)
  + * @deffunc apr_status_t apr_sms_init(apr_sms_t *sms,
  + *				      apr_sms_t *parent_mem_sys)
    */
  -APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, apr_sms_t *parent_mem_sys);
  +APR_DECLARE(apr_status_t) apr_sms_init(apr_sms_t *mem_sys, 
  +                                       apr_sms_t *parent_mem_sys);
   
   /**
    * Check if a memory system is obeying all rules. 
  
  
  
  1.9       +17 -14    apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_sms.c	2001/05/20 22:34:53	1.8
  +++ apr_sms.c	2001/06/01 17:32:13	1.9
  @@ -177,37 +177,40 @@
       return mem_sys->reset_fn != NULL;
   }
   
  -APR_DECLARE(apr_sms_t *) apr_sms_create(void *memory, 
  -                                        apr_sms_t *parent_mem_sys)
  +APR_DECLARE(apr_status_t) apr_sms_init(apr_sms_t *mem_sys, 
  +                                       apr_sms_t *parent_mem_sys)
   {
  -    apr_sms_t *mem_sys;
  +    /* XXX - I've assumed that memory passed in will be zeroed,
  +     * i.e. calloc'd instead of malloc'd...
  +     * This may well be a bogus assumption, and if so we either need
  +     * to memset or have a series of =NULL's at the end.
  +     * This function is only called by modules, so this isn't as crazy
  +     * an assumption to make as it sounds :)
  +     */
   
  -    if (!memory)
  -        return NULL;
  +    if (!mem_sys)
  +        return APR_EINVAL;
   
  -    /* Just typecast it, and clear it */
  -    mem_sys = (apr_sms_t *)memory;
  -    memset(mem_sys, '\0', sizeof(apr_sms_t));
  -
  -    /* Initialize the parent and accounting memory system pointers */
       mem_sys->parent_mem_sys = parent_mem_sys;
       mem_sys->accounting_mem_sys = mem_sys;
  +    mem_sys->child_mem_sys = NULL;
   
  -    if (parent_mem_sys != NULL) {
  +    if (parent_mem_sys) {
           if ((mem_sys->sibling_mem_sys = parent_mem_sys->child_mem_sys) != NULL)
               mem_sys->sibling_mem_sys->ref_mem_sys = &mem_sys->sibling_mem_sys;
   
           mem_sys->ref_mem_sys = &parent_mem_sys->child_mem_sys;
  +        /* This is probably not correct as we could have multiple children
  +         * from a single parent...  We probably need a list...
  +         */
           parent_mem_sys->child_mem_sys = mem_sys;
       }
  -    /* This seems a bit redundant, but we're not taking chances */
       else {
           mem_sys->ref_mem_sys     = NULL;
           mem_sys->sibling_mem_sys = NULL;
  -        mem_sys->child_mem_sys   = NULL;
       }
   
  -    return mem_sys;
  +    return APR_SUCCESS;
   }
   
   #ifdef APR_MEMORY_ASSERT
  
  
  
  1.5       +10 -3     apr/memory/unix/apr_sms_std.c
  
  Index: apr_sms_std.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms_std.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apr_sms_std.c	2001/05/30 11:03:34	1.4
  +++ apr_sms_std.c	2001/06/01 17:32:14	1.5
  @@ -108,22 +108,28 @@
   APR_DECLARE(apr_status_t) apr_sms_std_create(apr_sms_t **mem_sys)
   {
       apr_sms_t *new_mem_sys;
  +    apr_status_t rv;
   
       assert(mem_sys);
   
       *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);
  +    /* We don't have a parent so we allocate the memory
  +     * for the structure ourselves...
  +     */
  +    new_mem_sys = apr_sms_std_calloc(NULL, sizeof(apr_sms_t));
   
       if (!new_mem_sys)
           return APR_ENOMEM;
   
  +    if ((rv = apr_sms_init(new_mem_sys, NULL)) != APR_SUCCESS)
  +        return rv;
  +
       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;
       new_mem_sys->identity   = module_identity;
  +
       /* 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.
  @@ -134,3 +140,4 @@
       *mem_sys = new_mem_sys;
       return APR_SUCCESS;
   }
  +
  
  
  
  1.5       +12 -7     apr/memory/unix/apr_sms_tracking.c
  
  Index: apr_sms_tracking.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms_tracking.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apr_sms_tracking.c	2001/05/30 11:03:34	1.4
  +++ apr_sms_tracking.c	2001/06/01 17:32:14	1.5
  @@ -173,7 +173,7 @@
                                             void *mem)
   {
       apr_track_node_t *node;
  -
  +    
       assert(mem_sys);
       assert(mem);
   
  @@ -192,7 +192,7 @@
       apr_sms_tracking_t *tms;
       apr_track_node_t *node;
       apr_status_t rv;
  -    
  + 
       assert(mem_sys);
   
       tms = (apr_sms_tracking_t *)mem_sys;
  @@ -233,22 +233,26 @@
   APR_DECLARE(apr_status_t) apr_sms_tracking_create(apr_sms_t **mem_sys, 
                                                     apr_sms_t *pms)
   {
  -    apr_sms_t *new_mem_sys, *tmpms;
  +    apr_sms_t *new_mem_sys;
       apr_sms_tracking_t *tms;
  +    apr_status_t rv;
   
       assert(mem_sys);
       assert(pms);
       
       *mem_sys = NULL;
  -    /* changed this to 2 stages to make easier to follow...
  -     * should we be using apr_sms_calloc now we have it? 
  +    /* We're not a top level module, ie we have a parent, so
  +     * we allocate the memory for the structure from our parent.
  +     * This is safe as we shouldn't outlive our parent...
        */
  -    tmpms = apr_sms_malloc(pms, sizeof(apr_sms_tracking_t));
  -    new_mem_sys = apr_sms_create(tmpms, pms);
  +    new_mem_sys = apr_sms_calloc(pms, sizeof(apr_sms_tracking_t));
   
       if (!new_mem_sys)
           return APR_ENOMEM;
   
  +    if ((rv = apr_sms_init(new_mem_sys, pms)) != APR_SUCCESS)
  +        return rv;
  +
       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;
  @@ -265,3 +269,4 @@
       *mem_sys = new_mem_sys;
       return APR_SUCCESS;
   }
  +
  
  
  

Mime
View raw message