fix a bogus line in dynahash.c - Mailing list pgsql-patches

From Qingqing Zhou
Subject fix a bogus line in dynahash.c
Date
Msg-id d70n5f$1ii9$1@news.hub.org
Whole thread Raw
Responses Re: fix a bogus line in dynahash.c
Re: fix a bogus line in dynahash.c
List 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 */
  }



pgsql-patches by date:

Previous
From: Neil Conway
Date:
Subject: Re: [PATCH] pg_autovacuum commandline password hiding.
Next
From: Tom Lane
Date:
Subject: Re: [PATCH] pg_autovacuum commandline password hiding.