Subject: Re: Patch: New Hashtable
From: Joaquin Cuenca Abela (cuenca@celium.net)
Date: Mon May 21 2001 - 08:28:42 CDT
On 20 May 2001 18:00:28 -0400, Dom Lachowicz wrote:
> Hi guys,
>
> This is my work to date on the hashtable. It also contains work by Pat
> Lam and Mike Nordell. It applies to the tree before all of these recent
> importer/exporter updates.
I don't have the time to take a serious look, but the new UT_Pair is
const-broken.
First,
void * car() const { return _car; }
void * cdr() const { return _cdr; }
that's the same error that we had with vector a few days ago. If we try
to be friendlier with STL programmers (or should I just say C++
programmers?), avoid possible collisions with compiler internal names,
and prepare the code to a possible templated version (maybe one day...),
we end with something like:
typedef void* pair_type;
inline const pair_type& first() const { return car_; }
inline const pair_type& second() const { return cdr_; }
inline pair_type& first() { return car_; }
inline pair_type& second() { return cdr_; }
The UT_Pair of this patch contains also indefined behaviour under
certain circunstances (for instance:
UT_Pair p("Hallo", "good bye");
(static_cast<char *> (p.car()))[1] = 'e';
has undefined consecuences).
That's due to the lines:
UT_Pair::UT_Pair(const void * car, const void * cdr)
{
_car = (void *)car;
_cdr = (void *)cdr;
}
the innocent (void *) is a dangerous const_cast<void*> () (in addition,
a minor detail is that it's better to initialize the two variables
through ": _car(car), _cdr(cdr)" and not through the assignement
operator.)
Cheers,
-- Joaquín Cuenca Abela cuenca@celium.net
This archive was generated by hypermail 2b25 : Sat May 26 2001 - 03:51:05 CDT