httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Weilt <>
Subject a strange problem of gcc -O2 optimization flag in a output filter
Date Wed, 31 Jan 2007 10:01:18 GMT

I have wrote a module, which has an output filter. The filter collects all
the buckets of a request and does some processing, then it produces a new
brigade containing the new output data and pass it to the next filter in the
filter chains.

The output filter code is like this:

static apr_status_t TestOutFilter(ap_filter_t *f,
                                        apr_bucket_brigade *pbbIn)
    request_rec *r = f->r;
    conn_rec *c = r->connection;
    OutContext *pCtx;

    if(!(pCtx = f->ctx)){
      f->ctx = pCtx=apr_palloc(r->pool,sizeof *pCtx);
      pCtx->pbbTmp = apr_brigade_create(r->pool,c->bucket_alloc);
    apr_bucket_brigade *pbbOut = pCtx->pbbTmp;
      apr_bucket *pbktIn,*tmpbucket;

      APR_BRIGADE_INSERT_TAIL(pbbOut, pbktIn);


      if(APR_BUCKET_IS_EOS(pbktIn)) {
/*       we have all the buckets in pbbTmp;
         do  some processing and  create a new  bucket
         outputbuffer contains the new data to pass to next filter
           APR_BRIGADE_INSERT_TAIL(pbbOut, tmpbucket);
        APR_BRIGADE_INSERT_TAIL(pbbOut, pbktIn);
        return ap_pass_brigade(f->next,pbbOut);

    return APR_SUCCESS;

The strange thing is when I use "/usr/local/apache2/bin/apxs -i -a -c -Wc,O0
-Wc,-ggdb testmodule.c" to compile the module, it works well, but if I
"/usr/local/apache2/bin/apxs -i -a -c  -Wc,O2 -Wc,-ggdb testmodule.c", it
has death cycle in the function. Here '-Wc' means add gcc flag, '-Wc,O0'
means 'gcc -O0' ,which is no optimization. '-Wc,O2' is the default value if
it's not specified.

I use gdb to debug this, and find that in "-Wc,O2" case, the function  has
death loop in the while loop. The pbbIn and pbbOut values are not changed
after a loop, which means:
      APR_BRIGADE_INSERT_TAIL(pbbOut, pbktIn);"
aren't executed correctly or even optimized out.

By the way, even "-Wc,O1" flat works correctly.

I can't figure out the reason and how to solve it.
Any one knows something about this?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message