On Wed, 11 Apr 2001 [EMAIL PROTECTED] wrote:
> > #define apr_bucket_do_create(ap__b,do_make) \
> > do { \
> > apr_bucket *b; \
> > b = calloc(1, sizeof(*b)); \
> > ap__b = do_make; \
> > APR_RING_ELEM_INIT(ap__b, link); \
> > } while(0)
>
> +1
Upon further inspection, the also magical apr_bucket *b is also now
unnecessary since ap__b is no longer tested for NULL. So
apr_bucket_do_create() collapses even further down to just:
#define apr_bucket_do_create(ap__b,do_make) \
do { \
ap__b = calloc(1, sizeof(*ap__b)); \
ap__b = do_make; \
APR_RING_ELEM_INIT(ap__b, link); \
} while(0)
And callers do something like this:
{
apr_bucket *b;
apr_bucket_do_create(b, apr_bucket_foo_make(b, foo));
return b;
}
But this is screwy for two reasons: the double assignments to ap__b in the
macro and the seeming call to rv = apr_bucket_foo_make(b, foo) BEFORE
calling apr_bucket_do_create(b, rv) (if apr_bucket_do_create() were a
function).
It seems to me that apr_bucket_do_create() has outlived its usefulness.
It's only a few lines long at this point, which are less tricky-looking
when done inline than when done as a macro. So what I'm going to do
unless someone objects strongly is to nix it altogether and just do this:
#define APR_BUCKET_INIT(b) APR_RING_ELEM_INIT((b), link)
APU_DECLARE(apr_bucket *) apr_bucket_foo_create(apr_foo_t *foo)
{
apr_bucket *b = (apr_bucket *)calloc(1, sizeof(*b));
APR_BUCKET_INIT(b);
return apr_bucket_foo_make(b, foo);
}
Note that I've switched the effective order of APR_BUCKET_INIT() and
apr_bucket_foo_make, but it shouldn't matter since the two never touch
each other's data (and if they did, it would be better for the init to
happen first anyway).
--Cliff
--------------------------------------------------------------
Cliff Woolley
[EMAIL PROTECTED]
Charlottesville, VA