joes        2004/07/01 21:40:08

  Modified:    glue/perl/xsbuilder apreq_xs_postperl.h
               glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h
               glue/perl/xsbuilder/Apache/Request Apache__Request.h
               glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
  Log:
  Tag all the *2sv macros with a "parent" argument to ensure the parent object
  isn't destroyed until the child object is done with it.  Without this patch
  the following will dump core on the command line, because the underlying pool
  would be destroyed after the first statement is executed- thus the segfault
  in param().  This patch fixes that.
  
    % perl -MApache2 -MApache::Request -MAPR::Pool
      -wle '$r=Apache::Request->new(APR::Pool->new); print $r->param("foo")'
  
  Revision  Changes    Path
  1.32      +14 -13    httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h
  
  Index: apreq_xs_postperl.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- apreq_xs_postperl.h       1 Jul 2004 18:26:33 -0000       1.31
  +++ apreq_xs_postperl.h       2 Jul 2004 04:40:08 -0000       1.32
  @@ -107,7 +107,7 @@
    * @return Reference to the new Perl object in class.
    */
   APR_INLINE
  -static SV *apreq_xs_c2perl(pTHX_ void *obj, void *env, const char *class)
  +static SV *apreq_xs_c2perl(pTHX_ void *obj, void *env, const char *class, SV 
*parent)
   {
       SV *rv = sv_setref_pv(newSV(0), class, obj);
       if (env) {
  @@ -120,7 +120,7 @@
            * 5.8.x is OK with the old way as well, but in the future
            * we may have to use "#if PERL_VERSION < 8" ...
            */
  -        sv_magic(SvRV(rv), Nullsv, PERL_MAGIC_ext, Nullch, -1);
  +        sv_magic(SvRV(rv), parent, PERL_MAGIC_ext, Nullch, -1);
           SvMAGIC(SvRV(rv))->mg_ptr = env;
       }
       return rv;
  @@ -135,7 +135,7 @@
    */
   APR_INLINE
   static SV *apreq_xs_table_c2perl(pTHX_ void *obj, void *env, 
  -                                 const char *class)
  +                                 const char *class, SV *parent)
   {
       SV *sv = (SV *)newHV();
       SV *rv = sv_setref_pv(newSV(0), class, obj);
  @@ -149,7 +149,7 @@
            * 5.8.x is OK with the old way as well, but in the future
            * we may have to use "#if PERL_VERSION < 8" ...
            */
  -        sv_magic(SvRV(rv), Nullsv, PERL_MAGIC_ext, Nullch, -1);
  +        sv_magic(SvRV(rv), parent, PERL_MAGIC_ext, Nullch, -1);
           SvMAGIC(SvRV(rv))->mg_ptr = env;
       }
   
  @@ -160,7 +160,7 @@
   }
   
   
  -#define apreq_xs_2sv(t,class) apreq_xs_c2perl(aTHX_ t, env, class)
  +#define apreq_xs_2sv(t,class,parent) apreq_xs_c2perl(aTHX_ t, env, 
class,parent)
   #define apreq_xs_sv2(type,sv)((apreq_##type##_t *)apreq_xs_perl2c(aTHX_ sv, \
                                                                     #type))
   #define apreq_xs_sv2env(sv) apreq_xs_perl2env(aTHX_ sv)
  @@ -220,13 +220,13 @@
       data = (items == 3)  ?  SvPV_nolen(ST(2)) :  NULL;                  \
       obj = apreq_##type(env, data);                                      \
                                                                           \
  -    ST(0) = obj ? sv_2mortal( apreq_xs_2sv(obj, SvPV_nolen(ST(0))) ) :  \
  +    ST(0) = obj ? sv_2mortal( apreq_xs_2sv(obj, SvPV_nolen(ST(0)),ST(1)) ) : 
 \
                     &PL_sv_undef;                                         \
       XSRETURN(1);                                                        \
   }
   
   
  -/** requires definition of apreq_xs_##type##2sv(t,class) macro */
  +/** requires definition of apreq_xs_##type##2sv(t,class,parent) macro */
   
   #define APREQ_XS_DEFINE_MAKE(type)                                      \
   static XS(apreq_xs_make_##type)                                         \
  @@ -248,7 +248,7 @@
       val = SvPVbyte(ST(3), vlen);                                        \
       t = apreq_make_##type(pool, key, klen, val, vlen);                  \
                                                                           \
  -    ST(0) = sv_2mortal(apreq_xs_##type##2sv(t,class));                  \
  +    ST(0) = sv_2mortal(apreq_xs_##type##2sv(t,class,ST(1)));            \
       XSRETURN(1);                                                        \
   }  
   
  @@ -259,6 +259,7 @@
   struct apreq_xs_do_arg {
       void            *env;
       PerlInterpreter *perl;
  +    SV              *parent;
   };
   
   static int apreq_xs_table_keys(void *data, const char *key,
  @@ -281,7 +282,7 @@
   }
   
   #define apreq_xs_sv2table(sv)      ((apr_table_t *) SvIVX(SvRV(sv)))
  -#define apreq_xs_table2sv(t,class) apreq_xs_table_c2perl(aTHX_ t, env, class)
  +#define apreq_xs_table2sv(t,class) apreq_xs_table_c2perl(aTHX_ t, env, 
class,NULL)
   #define apreq_xs_do(attr)          (items == 1 ? apreq_xs_table_keys \
                                      : apreq_xs_##attr##_table_values)
   
  @@ -322,7 +323,7 @@
           apreq_##type##_t *RETVAL =                                      \
                             apreq_value_to_##type(apreq_strtoval(val));   \
           if (COND)                                                       \
  -            XPUSHs(sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass)));  \
  +            
XPUSHs(sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass,d->parent)));  \
       } else                                                              \
           XPUSHs(&PL_sv_undef);                                           \
                                                                           \
  @@ -333,7 +334,7 @@
   {                                                                       \
       dXSARGS;                                                            \
       const char *key = NULL;                                             \
  -    struct apreq_xs_do_arg d = { NULL, aTHX };                          \
  +    struct apreq_xs_do_arg d = { NULL, aTHX, NULL };                    \
       void *env;                                                          \
       SV *sv = ST(0);                                                     \
                                                                           \
  @@ -341,7 +342,7 @@
           Perl_croak(aTHX_ "Usage: $object->get($key)");                  \
                                                                           \
       env = apreq_xs_##attr##_sv2env(ST(0));                              \
  -    d.env = env;                                                        \
  +    d.env = env; d.parent=sv;                                           \
       if (items == 2)                                                     \
           key = SvPV_nolen(ST(1));                                        \
                                                                           \
  @@ -365,7 +366,7 @@
                                                                           \
           RETVAL = apreq_xs_##attr##_##type(sv, key);                     \
           if (RETVAL && (COND))                                           \
  -            XPUSHs(sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass)));  \
  +            XPUSHs(sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass,sv)));  \
                                                                           \
       default:                                                            \
           PUTBACK;                                                        \
  
  
  
  1.21      +1 -1      
httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h
  
  Index: Apache__Cookie.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Apache__Cookie.h  1 Jul 2004 04:11:24 -0000       1.20
  +++ Apache__Cookie.h  2 Jul 2004 04:40:08 -0000       1.21
  @@ -17,7 +17,7 @@
   #define apreq_xs_jar2cookie(j) j->cookies
   #define apreq_xs_jar2env(j) j->env
   
  -#define apreq_xs_cookie2sv(c,class) apreq_xs_2sv(c,class)
  +#define apreq_xs_cookie2sv(c,class,parent) apreq_xs_2sv(c,class,parent)
   #define apreq_xs_sv2cookie(sv) ((apreq_cookie_t *)SvIVX(SvRV(sv)))
   
   /** 
  
  
  
  1.33      +2 -2      
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
  
  Index: Apache__Request.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Apache__Request.h 1 Jul 2004 13:20:51 -0000       1.32
  +++ Apache__Request.h 2 Jul 2004 04:40:08 -0000       1.33
  @@ -89,9 +89,9 @@
   
   #define apreq_xs_table_error_check
   
  -#define apreq_xs_param2rv(ptr, class) apreq_xs_2sv(ptr,class)
  +#define apreq_xs_param2rv(ptr, class, parent) apreq_xs_2sv(ptr,class,parent)
   #define apreq_xs_rv2param(sv) ((apreq_param_t *)SvIVX(SvRV(sv)))
  -#define apreq_xs_param2sv(ptr,class) newSVpvn((ptr)->v.data,(ptr)->v.size)
  +#define apreq_xs_param2sv(ptr,class,parent) 
newSVpvn((ptr)->v.data,(ptr)->v.size)
   
   APREQ_XS_DEFINE_ENV(request);
   APREQ_XS_DEFINE_OBJECT(request);
  
  
  
  1.10      +1 -1      
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
  
  Index: Apache__Upload.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Apache__Upload.h  1 Jul 2004 04:11:24 -0000       1.9
  +++ Apache__Upload.h  2 Jul 2004 04:40:08 -0000       1.10
  @@ -140,7 +140,7 @@
   
   /* uploads are represented by the full apreq_param_t in C */
   #define apreq_upload_t apreq_param_t
  -#define apreq_xs_param2sv(ptr,class)  apreq_xs_2sv(ptr,class)
  +#define apreq_xs_param2sv(ptr,class,parent)  apreq_xs_2sv(ptr,class,parent)
   #define apreq_xs_sv2param(sv) ((apreq_upload_t *)SvIVX(SvRV(sv)))
   
   static int apreq_xs_upload_table_keys(void *data, const char *key,
  
  
  

Reply via email to