stas        2003/11/03 15:31:19

  Modified:    src/modules/perl mod_perl.c modperl_perl.c modperl_perl.h
  Log:
  move the ever-growing hash-seed-manipulation ifdef clutter to
  modperl_perl.c, bringing mod_perl.c back to a readable form.
  
  Revision  Changes    Path
  1.203     +0 -70     modperl-2.0/src/modules/perl/mod_perl.c
  
  Index: mod_perl.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.c,v
  retrieving revision 1.202
  retrieving revision 1.203
  diff -u -u -r1.202 -r1.203
  --- mod_perl.c        3 Nov 2003 09:29:49 -0000       1.202
  +++ mod_perl.c        3 Nov 2003 23:31:19 -0000       1.203
  @@ -9,76 +9,6 @@
   #define MP_IS_STARTING    (MP_init_status == 1 ? 1 : 0)
   #define MP_IS_RUNNING     (MP_init_status == 2 ? 1 : 0)
   
  -#if !(PERL_REVISION == 5 && ( PERL_VERSION < 8 || \
  -    (PERL_VERSION == 8 && PERL_SUBVERSION == 0))) && \
  -    (defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT))
  -#define MP_NEED_HASH_SEED_FIXUP
  -#endif
  -
  -
  -#ifdef MP_NEED_HASH_SEED_FIXUP
  -static UV   MP_init_hash_seed = 0;
  -static bool MP_init_hash_seed_set = FALSE;
  -#endif
  -
  -/* see modperl_hash_seed_set() */
  -static void modperl_hash_seed_init(apr_pool_t *p) 
  -{
  -#ifdef MP_NEED_HASH_SEED_FIXUP
  -    char *s;
  -    /* check if there is a specific hash seed passed via the env var
  -     * and if that's the case -- use it */
  -    apr_status_t rv = apr_env_get(&s, "PERL_HASH_SEED", p);
  -    if (rv == APR_SUCCESS) {
  -        if (s) {
  -            while (isSPACE(*s)) s++;
  -        }
  -        if (s && isDIGIT(*s)) {
  -            MP_init_hash_seed = (UV)Atol(s); /* XXX: Atoul()? */
  -            MP_init_hash_seed_set = TRUE;
  -        }
  -    }
  -    
  -    /* calculate our own random hash seed */
  -    if (!MP_init_hash_seed_set) {
  -        apr_uuid_t *uuid = (apr_uuid_t *)apr_palloc(p, sizeof(apr_uuid_t));
  -        char buf[APR_UUID_FORMATTED_LENGTH + 1];
  -        int i;
  -
  -        apr_initialize();
  -        apr_uuid_get(uuid);
  -        apr_uuid_format(buf, uuid);
  -        /* fprintf(stderr, "UUID: %s\n", buf); */
  -
  -        /* XXX: need a better alg to convert uuid string into a seed */
  -        for (i=0; buf[i]; i++){
  -            MP_init_hash_seed += (UV)(i+1)*(buf[i]+MP_init_hash_seed);
  -        }
  -
  -        MP_init_hash_seed_set = TRUE;
  -    }
  -#endif
  -}
  -
  -/* before 5.8.1, perl was using HASH_SEED=0, starting from 5.8.1
  - * it randomizes if perl was compiled with ccflags -DUSE_HASH_SEED
  - * or -DUSE_HASH_SEED_EXPLICIT, in which case we need to tell perl
  - * to use the same seed everywhere */
  -static void modperl_hash_seed_set(pTHX) 
  -{
  -#ifdef MP_NEED_HASH_SEED_FIXUP
  -    if (MP_init_hash_seed_set) {
  -#if PERL_REVISION == 5 && PERL_VERSION == 8 && PERL_SUBVERSION == 1
  -        PL_hash_seed       = MP_init_hash_seed;
  -        PL_hash_seed_set   = MP_init_hash_seed_set;
  -#else
  -        PL_rehash_seed     = MP_init_hash_seed;
  -        PL_rehash_seed_set = MP_init_hash_seed_set;
  -#endif
  -    }
  -#endif
  -}
  -
   #ifndef USE_ITHREADS
   static apr_status_t modperl_shutdown(void *data)
   {
  
  
  
  1.20      +69 -0     modperl-2.0/src/modules/perl/modperl_perl.c
  
  Index: modperl_perl.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_perl.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -u -r1.19 -r1.20
  --- modperl_perl.c    18 Oct 2003 21:01:30 -0000      1.19
  +++ modperl_perl.c    3 Nov 2003 23:31:19 -0000       1.20
  @@ -160,3 +160,72 @@
       }
   #endif
   }
  +
  +#if !(PERL_REVISION == 5 && ( PERL_VERSION < 8 ||    \
  +    (PERL_VERSION == 8 && PERL_SUBVERSION == 0))) && \
  +    (defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT))
  +#define MP_NEED_HASH_SEED_FIXUP
  +#endif
  +
  +#ifdef MP_NEED_HASH_SEED_FIXUP
  +static UV   MP_init_hash_seed = 0;
  +static bool MP_init_hash_seed_set = FALSE;
  +#endif
  +
  +/* see modperl_hash_seed_set() */
  +void modperl_hash_seed_init(apr_pool_t *p) 
  +{
  +#ifdef MP_NEED_HASH_SEED_FIXUP
  +    char *s;
  +    /* check if there is a specific hash seed passed via the env var
  +     * and if that's the case -- use it */
  +    apr_status_t rv = apr_env_get(&s, "PERL_HASH_SEED", p);
  +    if (rv == APR_SUCCESS) {
  +        if (s) {
  +            while (isSPACE(*s)) s++;
  +        }
  +        if (s && isDIGIT(*s)) {
  +            MP_init_hash_seed = (UV)Atol(s); /* XXX: Atoul()? */
  +            MP_init_hash_seed_set = TRUE;
  +        }
  +    }
  +
  +    /* calculate our own random hash seed */
  +    if (!MP_init_hash_seed_set) {
  +        apr_uuid_t *uuid = (apr_uuid_t *)apr_palloc(p, sizeof(apr_uuid_t));
  +        char buf[APR_UUID_FORMATTED_LENGTH + 1];
  +        int i;
  +
  +        apr_initialize();
  +        apr_uuid_get(uuid);
  +        apr_uuid_format(buf, uuid);
  +        /* fprintf(stderr, "UUID: %s\n", buf); */
  +
  +        /* XXX: need a better alg to convert uuid string into a seed */
  +        for (i=0; buf[i]; i++){
  +            MP_init_hash_seed += (UV)(i+1)*(buf[i]+MP_init_hash_seed);
  +        }
  +
  +        MP_init_hash_seed_set = TRUE;
  +    }
  +#endif
  +}
  +
  +/* before 5.8.1, perl was using HASH_SEED=0, starting from 5.8.1
  + * it randomizes if perl was compiled with ccflags -DUSE_HASH_SEED
  + * or -DUSE_HASH_SEED_EXPLICIT, in which case we need to tell perl
  + * to use the same seed everywhere */
  +void modperl_hash_seed_set(pTHX) 
  +{
  +#ifdef MP_NEED_HASH_SEED_FIXUP
  +    if (MP_init_hash_seed_set) {
  +#if PERL_REVISION == 5 && PERL_VERSION == 8 && PERL_SUBVERSION == 1
  +        PL_hash_seed       = MP_init_hash_seed;
  +        PL_hash_seed_set   = MP_init_hash_seed_set;
  +#else
  +        PL_rehash_seed     = MP_init_hash_seed;
  +        PL_rehash_seed_set = MP_init_hash_seed_set;
  +#endif
  +    }
  +#endif
  +}
  
  
  
  1.12      +4 -0      modperl-2.0/src/modules/perl/modperl_perl.h
  
  Index: modperl_perl.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_perl.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -u -r1.11 -r1.12
  --- modperl_perl.h    18 Oct 2003 21:01:30 -0000      1.11
  +++ modperl_perl.h    3 Nov 2003 23:31:19 -0000       1.12
  @@ -22,4 +22,8 @@
   
   void modperl_perl_destruct(PerlInterpreter *perl);
   
  +void modperl_hash_seed_init(apr_pool_t *p);
  +
  +void modperl_hash_seed_set(pTHX);
  +
   #endif /* MODPERL_PERL_H */
  
  
  

Reply via email to