httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Re: cvs commit: apache-2.0/src/lib/apr/lib apr_hash.c
Date Sat, 15 Jul 2000 13:09:22 GMT
Greg Stein wrote:
> 
> On Tue, Jul 11, 2000 at 10:38:12PM +0100, Ben Laurie wrote:
> > Greg Stein wrote:
> > >
> > > On Mon, Jul 10, 2000 at 09:57:38AM +0100, Ben Laurie wrote:
> > > > gstein@locus.apache.org wrote:
> > > > >   -=head1 void *ap_hash_get(ap_hash_t *ht, void *key, size_t klen)
> > > > >   +=head1 void *ap_hash_get(ap_hash_t *ht, const void *key, size_t
klen)
> > > >
> > > > Surely ap_hash_get() should return a const void *???
> > >
> > > Nah. You might store a modifiable buffer into the hash table:
> > >
> > >   buf = ap_pcalloc(p, BUFSIZE);
> > >   ap_hash_set(ht, "hello", 0, buf);
> > >   ...
> > >
> > >   buf = ap_hash_get(ht, "hello", 0);
> > >   sprintf(buf, "%d/%d", foo, bar);
> > >
> > > The get() function treats it as "const", and we store into the internal
> > > tables that way. But we drop the const right as we return it, since the
> > > notion of "const" is really up to the person who shoved the value in there.
> >
> > In which case you should be honest about that and not mark the value you
> 
> We would need to do ap_hash_set_c() and ap_hash_set(). But of course, we
> don't track const-ness in the ADT, so the ap_hash_get() could switch it.
> 
> [ and no, tracking const-ness would not be a good thing to add ]

Why not?

> Adding the "const" on the ap_hash_set() allows you to actually place const
> data in there. Without the const, you get errors on the set() if you have
> const data. But if the get() is non-const, then you can place it into const
> or non-const pointers.

Which means you can deconstify a const, accidentally. Which is why
tracking constness _is_ a good thing. IMO.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

Coming to ApacheCon Europe 2000? http://apachecon.com/

Mime
View raw message