fix a bogus line in dynahash.c

Поиск
Список
Период
Сортировка
От Qingqing Zhou
Тема fix a bogus line in dynahash.c
Дата
Msg-id d70n5f$1ii9$1@news.hub.org
обсуждение исходный текст
Ответы Re: fix a bogus line in dynahash.c  (Neil Conway <neilc@samurai.com>)
Re: fix a bogus line in dynahash.c  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Neil Conway
Дата:
Сообщение: Re: [PATCH] pg_autovacuum commandline password hiding.
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [PATCH] pg_autovacuum commandline password hiding.