perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From do...@apache.org
Subject cvs commit: modperl-2.0/xs/tables/current/ModPerl FunctionTable.pm
Date Sat, 15 Sep 2001 18:17:31 GMT
dougm       01/09/15 11:17:31

  Modified:    lib/ModPerl TypeMap.pm
               t/response/TestAPR table.pm
               todo     api.txt
               xs/maps  apr_functions.map
               xs/tables/current/ModPerl FunctionTable.pm
  Added:       xs/APR/Table APR__Table.h
  Log:
  implement APR::Table->do
  Submitted by:	Philippe M . Chiasson <gozer@cpan.org>
  Reviewed by:	dougm
  
  Revision  Changes    Path
  1.10      +1 -0      modperl-2.0/lib/ModPerl/TypeMap.pm
  
  Index: TypeMap.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/ModPerl/TypeMap.pm,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TypeMap.pm	2001/09/10 05:35:10	1.9
  +++ TypeMap.pm	2001/09/15 18:17:31	1.10
  @@ -396,6 +396,7 @@
       Apache__RequestRec => 'r',
       Apache__Server => 'server',
       Apache__Connection => 'connection',
  +    APR__Table => 'table',
       APR__UUID => 'uuid',
       apr_status_t => 'status',
   );
  
  
  
  1.2       +54 -1     modperl-2.0/t/response/TestAPR/table.pm
  
  Index: table.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/table.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- table.pm	2001/09/12 16:40:27	1.1
  +++ table.pm	2001/09/15 18:17:31	1.2
  @@ -8,10 +8,13 @@
   use Apache::Const -compile => 'OK';
   use APR::Table ();
   
  +my $filter_count;
  +my $TABLE_SIZE = 20;
  +
   sub handler {
       my $r = shift;
   
  -    plan $r, tests => 5;
  +    plan $r, tests => 9;
   
       my $table = APR::Table::make($r->pool, 16);
   
  @@ -25,7 +28,57 @@
   
       ok not defined $table->get('foo');
   
  +    for (1..$TABLE_SIZE) {
  +        $table->set(chr($_+97), $_);
  +    }
  +
  +    #Simple filtering
  +    $filter_count = 0;
  +    $table->do("my_filter");
  +    ok $filter_count == $TABLE_SIZE;
  +
  +    #Filtering aborting in the middle
  +    $filter_count = 0;
  +    $table->do("my_filter_stop");
  +    ok $filter_count == int($TABLE_SIZE)/2;
  +
  +    #Filtering with anon sub
  +    $filter_count=0;
  +    $table->do(sub {
  +        my ($key,$value) = @_;
  +        $filter_count++;
  +        unless ($key eq chr($value+97)) {
  +            die "arguments I recieved are bogus($key,$value)";
  +        }
  +        return 1;
  +    });
  +
  +    ok $filter_count == $TABLE_SIZE;
  +
  +    $filter_count = 0;
  +    $table->do("my_filter", "c", "b", "e");
  +    ok $filter_count == 3;
  +
       Apache::OK;
  +}
  +
  +sub my_filter {
  +    my ($key,$value) = @_;
  +    $filter_count++;
  +    unless ($key eq chr($value+97)) {
  +        die "arguments I recieved are bogus($key,$value)";
  +    }
  +    return 1;
  +}
  +
  +sub my_filter_stop {
  +    my ($key,$value) = @_;
  +    $filter_count++;
  +    unless ($key eq chr($value+97)) {
  +        die "arguments I recieved are bogus($key,$value)";
  +    }
  +    return 0 if ($filter_count == int($TABLE_SIZE)/2);
  +    return 1;
   }
   
   1;
  
  
  
  1.4       +0 -2      modperl-2.0/todo/api.txt
  
  Index: api.txt
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/todo/api.txt,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- api.txt	2001/09/15 17:57:25	1.3
  +++ api.txt	2001/09/15 18:17:31	1.4
  @@ -9,8 +9,6 @@
   $r->headers_out->{KEY} is not currently supported
   might want to make this optional, disabled by default
   
  -missing: APR::Table->do
  -
   $r->finfo:
   need apr_finfo_t <-> struct stat conversion (might already be there,
   haven't looked close enough yet)
  
  
  
  1.1                  modperl-2.0/xs/APR/Table/APR__Table.h
  
  Index: APR__Table.h
  ===================================================================
  typedef struct {
      SV *cv;
      apr_table_t *filter; /*XXX: or maybe a mgv ? */
  } mpxs_table_do_cb_data_t;
  
  typedef int (*mpxs_apr_table_do_cb_t)(void *, const char *, const char *);
  
  static int mpxs_apr_table_do_cb(void *data,
                                  const char *key, const char *val)
  {
      dTHX; /*XXX*/
      dSP;
      int rv = 0;
      mpxs_table_do_cb_data_t *tdata = (mpxs_table_do_cb_data_t *)data;
  
      /* Skip completely if something is wrong */
      if (!(tdata && tdata->cv && key && val)) {
          return 0;
      }
  
      /* Skip entries if not in our filter list */
      if (tdata->filter) {
          if (!apr_table_get(tdata->filter, key)) {
              return 1;
          }
      }
      
      ENTER;
      SAVETMPS;
  
      PUSHMARK(sp);
      XPUSHs(sv_2mortal(newSVpv(key,0)));
      XPUSHs(sv_2mortal(newSVpv(val,0)));
      PUTBACK;
  
      rv = call_sv(tdata->cv, 0);
      SPAGAIN;
      rv = (1 == rv) ? POPi : 1;
      PUTBACK;
  
      FREETMPS;
      LEAVE;
      
      /* rv of 0 aborts the traversal */
      return rv;
  }
  
  static MP_INLINE 
  void mpxs_apr_table_do(pTHX_ I32 items, SV **MARK, SV **SP) 
  {
      apr_table_t *table;
      SV *sub;
      mpxs_table_do_cb_data_t tdata;
      
      mpxs_usage_va_2(table, sub, "$table->do(sub, [@filter])");
           
      tdata.cv = sub;
      tdata.filter = NULL;
      
      if (items > 2) {
          STRLEN len;
          tdata.filter = apr_table_make(table->a.pool, items-2);
  
          while (MARK <= SP) {
              /* XXX: can we use apr_table_setn here? */
              apr_table_set(tdata.filter, SvPV(*MARK,len), "1");
              MARK++;
          }
      }
    
      /* XXX: would be nice to be able to call apr_table_vdo directly, 
       * but I don't think it's possible to create/populate something 
       * that smells like a va_list with our list of filters specs
       */
      
      apr_table_do(mpxs_apr_table_do_cb, (void *)&tdata, table, NULL);
      
      /* Free tdata.filter or wait for the pool to go away? */
      
      return; 
  }
  
  
  
  1.19      +1 -1      modperl-2.0/xs/maps/apr_functions.map
  
  Index: apr_functions.map
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/maps/apr_functions.map,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- apr_functions.map	2001/09/10 06:42:51	1.18
  +++ apr_functions.map	2001/09/15 18:17:31	1.19
  @@ -183,7 +183,7 @@
    apr_table_overlay | | base, overlay, p
    apr_table_add
   -apr_table_addn
  - apr_table_do
  + apr_table_do | mpxs_ | ...
    apr_table_get
    apr_table_merge
   -apr_table_mergen
  
  
  
  1.26      +23 -1     modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm
  
  Index: FunctionTable.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- FunctionTable.pm	2001/09/15 17:57:25	1.25
  +++ FunctionTable.pm	2001/09/15 18:17:31	1.26
  @@ -2,7 +2,7 @@
   
   # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   # ! WARNING: generated by ModPerl::ParseSource/0.01
  -# !          Sat Sep 15 10:58:15 2001
  +# !          Sat Sep 15 11:10:02 2001
   # !          do NOT edit, any changes will be lost !
   # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   
  @@ -3984,6 +3984,28 @@
         {
           'type' => 'SV *',
           'name' => 'arg'
  +      }
  +    ]
  +  },
  +  {
  +    'return_type' => 'void',
  +    'name' => 'mpxs_apr_table_do',
  +    'args' => [
  +      {
  +        'type' => 'PerlInterpreter *',
  +        'name' => 'my_perl'
  +      },
  +      {
  +        'type' => 'I32',
  +        'name' => 'items'
  +      },
  +      {
  +        'type' => 'SV **',
  +        'name' => 'mark'
  +      },
  +      {
  +        'type' => 'SV **',
  +        'name' => 'sp'
         }
       ]
     },
  
  
  

Mime
View raw message