stas        2004/08/18 15:05:16

  Modified:    .        Changes
               src/modules/perl modperl_filter.c modperl_types.h
  Log:
  replace the memory allocation for modperl filter handlers to use a
  temporary subpool of the ap_filter_t object. previously using perl's
  safemalloc had problems on win32 (randonly my_perl == NULL)
  
  Revision  Changes    Path
  1.455     +4 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.454
  retrieving revision 1.455
  diff -u -u -r1.454 -r1.455
  --- Changes   18 Aug 2004 18:05:29 -0000      1.454
  +++ Changes   18 Aug 2004 22:05:16 -0000      1.455
  @@ -12,6 +12,10 @@
   
   =item 1.99_15-dev
   
  +replace the memory allocation for modperl filter handlers to use a
  +temporary subpool of the ap_filter_t object. previously using perl's
  +safemalloc had problems on win32 (randonly my_perl == NULL) [Stas]
  +
   Apache::Module remove_loaded_module re-added [Gozer]
   
   Disable Apache::HookRun::run_create_request -- it's already run
  
  
  
  1.95      +27 -17    modperl-2.0/src/modules/perl/modperl_filter.c
  
  Index: modperl_filter.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -u -r1.94 -r1.95
  --- modperl_filter.c  10 Aug 2004 00:38:35 -0000      1.94
  +++ modperl_filter.c  18 Aug 2004 22:05:16 -0000      1.95
  @@ -38,21 +38,21 @@
   /* allocate wbucket memory using malloc and not request pools, since
    * we may need many of these if the filter is invoked multiple
    * times */
  -#define WBUCKET_INIT(wb, p, next_filter)                   \
  -    if (!wb) {                                             \
  -        wb = (modperl_wbucket_t *)safemalloc(sizeof(*wb)); \
  -        wb->pool    = p;                                   \
  -        wb->filters = &next_filter;                        \
  -        wb->outcnt  = 0;                                   \
  -        wb->r       = NULL;                                \
  -        wb->header_parse = 0;                              \
  +#define WBUCKET_INIT(filter)                                     \
  +    if (!filter->wbucket) {                                      \
  +        modperl_wbucket_t *wb =                                  \
  +            (modperl_wbucket_t *)apr_pcalloc(filter->temp_pool,  \
  +                                             sizeof(*wb));       \
  +        wb->pool         = filter->pool;                         \
  +        wb->filters      = &(filter->f->next);                   \
  +        wb->outcnt       = 0;                                    \
  +        wb->r            = NULL;                                 \
  +        wb->header_parse = 0;                                    \
  +        filter->wbucket  = wb;                                   \
       }
   
   #define FILTER_FREE(filter)        \
  -    if (filter->wbucket) {         \
  -        safefree(filter->wbucket); \
  -    }                              \
  -    safefree(filter);
  +    apr_pool_destroy(filter->temp_pool);
   
   /* Save the value of $@ if it was set */
   #define MP_FILTER_SAVE_ERRSV(tmpsv)                 \
  @@ -306,17 +306,26 @@
                                        apr_off_t readbytes)
   {
       apr_pool_t *p = MP_FILTER_POOL(f);
  +    apr_pool_t *temp_pool;
       modperl_filter_t *filter;
   
       /* we can't allocate memory from the pool here, since potentially
        * a filter can be called hundreds of times during the same
        * request/connection resulting in enormous memory demands
  -     * (sizeof(*filter)*number of invocations)
  +     * (sizeof(*filter)*number of invocations). so we use a sub-pool
  +     * which will get destroyed at the end of each modperl_filter
  +     * invocation.
        */
  -    Newz(0, filter, 1, modperl_filter_t);
  -
  +    apr_status_t rv = apr_pool_create(&temp_pool, p);
  +    if (rv != APR_SUCCESS) {
  +        /* XXX: how do we handle the error? assert? */
  +        return NULL;
  +    }
  +    filter = (modperl_filter_t *)apr_pcalloc(temp_pool, sizeof(*filter));
  +                
       filter->mode = mode;
       filter->f = f;
  +    filter->temp_pool = temp_pool;
       filter->pool = p;
       filter->wbucket = NULL;
   
  @@ -808,7 +817,7 @@
           filter->flush = 0;
       }
   
  -    WBUCKET_INIT(filter->wbucket, filter->pool, filter->f->next);
  +    WBUCKET_INIT(filter);
       filter->rc = modperl_wbucket_flush(filter->wbucket, add_flush_bucket);
       if (filter->rc != APR_SUCCESS) {
           return filter->rc;
  @@ -848,7 +857,8 @@
                                                      const char *buf,
                                                      apr_size_t *len)
   {
  -    WBUCKET_INIT(filter->wbucket, filter->pool, filter->f->next);
  +    WBUCKET_INIT(filter);
  +
       return modperl_wbucket_write(aTHX_ filter->wbucket, buf, len);
   }
   
  
  
  
  1.76      +1 -0      modperl-2.0/src/modules/perl/modperl_types.h
  
  Index: modperl_types.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_types.h,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -u -r1.75 -r1.76
  --- modperl_types.h   22 Jun 2004 22:34:10 -0000      1.75
  +++ modperl_types.h   18 Aug 2004 22:05:16 -0000      1.76
  @@ -228,6 +228,7 @@
       apr_status_t rc;
       modperl_filter_mode_e mode;
       apr_pool_t *pool;
  +    apr_pool_t *temp_pool;
   } modperl_filter_t;
   
   typedef struct {
  
  
  

Reply via email to