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
Date Wed, 13 Jun 2001 00:31:16 GMT
dreid       01/06/12 17:31:16

  Modified:    memory/unix apr_sms.c
  Log:
  Check we have a realloc_fn before calling it.
  Add a default calloc_fn which should be more obvious than checking
  and doing it.
  
  Submitted by:	Sander Striker <striker@samba-tng.org>
  Reviewed by:	David Reid <dreid@apache.org>
  
  Revision  Changes    Path
  1.21      +31 -10    apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- apr_sms.c	2001/06/13 00:16:50	1.20
  +++ apr_sms.c	2001/06/13 00:31:14	1.21
  @@ -103,15 +103,6 @@
       if (size == 0)
           return NULL;
   
  -    if (!sms->calloc_fn) {
  -        /* Assumption - if we don't have calloc we have
  -         * malloc, might be bogus...
  -         */
  -        void *mem = sms->malloc_fn(sms, size);
  -        memset(mem, '\0', size);
  -        return mem;
  -    }
  -    
       return sms->calloc_fn(sms, size);
   }
   
  @@ -125,8 +116,12 @@
           apr_sms_free(sms, mem);
           return NULL;
       }
  +
  +    if (sms->realloc_fn)
  +        return sms->realloc_fn(sms, mem, size);
   
  -    return sms->realloc_fn(sms, mem, size);
  +    /* XXX - shoulod we free the block passed in ??? */
  +    return NULL;
   }
   
   APR_DECLARE(apr_status_t) apr_sms_free(apr_sms_t *sms,
  @@ -139,6 +134,22 @@
   }
   
   /*
  + * default allocation functions
  + */
  +
  +static void *apr_sms_default_calloc(apr_sms_t *sms,
  +                                    apr_size_t size)
  +{
  +    void *mem;
  +
  +    mem = sms->malloc_fn(sms, size);
  +    if (mem)
  +        memset(mem, '\0', size);
  +
  +    return mem;
  +}
  +
  +/*
    * memory system functions
    */
   
  @@ -200,6 +211,11 @@
           apr_lock_release(pms->sms_lock);    
       }
   
  +    /* Set default functions.  These should NOT be altered by an sms
  +     * module unless it implements them itself.
  +     */
  +    sms->calloc_fn = apr_sms_default_calloc;
  +    
       /* XXX - This should eventually be removed */
       apr_pool_create(&sms->pool, pms ? pms->pool : NULL);
   
  @@ -232,6 +248,11 @@
     
       assert(!sms->reset_fn || sms->destroy_fn);
   
  +    /* Has someone been stupid and NULL'd our default function without
  +     * providing an implementation of their own... tsch, tsch
  +     */
  +    assert(sms->calloc_fn);
  +    
       /*
        * Make sure all accounting memory dies with the memory system.
        * To be more specific, make sure the accounting memort system
  
  
  

Mime
View raw message