fix a bogus line in dynahash.c

From: "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu>
To: pgsql-patches(at)postgresql(dot)org
Subject: fix a bogus line in dynahash.c
Date: 2005-05-25 02:14:16
Message-ID: d70n5f$1ii9$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


Change elog(ERROR) to Assert(false) for two reasons:

(1) "unrecognized hash action code" could hardly really happen;
(2) even if it could happen, elog(ERROR) won't save us since in many places
we have to check the return code of hash_search() and decide the error
level.

On a separate matter, can anyone please explain me how this piece of code
works:

/* no free elements. allocate another chunk of buckets */
if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
return NULL; /* out of memory */

element_alloc() in fact uses MemoryContextAlloc() stuff. So if
element_alloc() fails, it actually elog(ERROR) itself and jump out of our
control, and we could never get a chance to check its returned value. So
many places like this:

if (!hash_search(... HASH_ENTER ...))
elog( ...)

could never happen?

Regards,
Qingqing

Index: dynahash.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v
retrieving revision 1.60
diff -c -r1.60 dynahash.c
*** dynahash.c 16 May 2005 00:19:04 -0000 1.60
--- dynahash.c 25 May 2005 01:57:42 -0000
***************
*** 680,687 ****
return (void *) ELEMENTKEY(currBucket);
}

! elog(ERROR, "unrecognized hash action code: %d", (int) action);
!
return NULL; /* keep compiler quiet */
}

--- 680,688 ----
return (void *) ELEMENTKEY(currBucket);
}

! /* Should never be here */
! Assert(false);
!
return NULL; /* keep compiler quiet */
}

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-05-25 02:44:13 Re: [PATCH] pg_autovacuum commandline password hiding.
Previous Message Neil Conway 2005-05-25 01:46:43 Re: [PATCH] pg_autovacuum commandline password hiding.