Commit e92a8827 authored by Tom Lane's avatar Tom Lane

Modify hash_search() API to prevent future occurrences of the error

spotted by Qingqing Zhou.  The HASH_ENTER action now automatically
fails with elog(ERROR) on out-of-memory --- which incidentally lets
us eliminate duplicate error checks in quite a bunch of places.  If
you really need the old return-NULL-on-out-of-memory behavior, you
can ask for HASH_ENTER_NULL.  But there is now an Assert in that path
checking that you aren't hoping to get that behavior in a palloc-based
hash table.
Along the way, remove the old HASH_FIND_SAVE/HASH_REMOVE_SAVED actions,
which were not being used anywhere anymore, and were surely too ugly
and unsafe to want to see revived again.
parent ecd70d75
...@@ -2061,11 +2061,6 @@ createNewConnection(const char *name, remoteConn * con) ...@@ -2061,11 +2061,6 @@ createNewConnection(const char *name, remoteConn * con)
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key, hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key,
HASH_ENTER, &found); HASH_ENTER, &found);
if (!hentry)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found) if (found)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT), (errcode(ERRCODE_DUPLICATE_OBJECT),
......
...@@ -144,10 +144,6 @@ do { \ ...@@ -144,10 +144,6 @@ do { \
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \ snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \ hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \
key, HASH_ENTER, &found); \ key, HASH_ENTER, &found); \
if (hentry == NULL) \
ereport(ERROR, \
(errcode(ERRCODE_OUT_OF_MEMORY), \
errmsg("out of memory"))); \
if (found) \ if (found) \
ereport(ERROR, \ ereport(ERROR, \
(errcode(ERRCODE_DUPLICATE_OBJECT), \ (errcode(ERRCODE_DUPLICATE_OBJECT), \
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.36 2005/01/10 20:02:19 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.37 2005/05/29 04:23:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -223,9 +223,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode) ...@@ -223,9 +223,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
hentry = (XLogRelCacheEntry *) hentry = (XLogRelCacheEntry *)
hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found); hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found);
if (hentry == NULL)
elog(PANIC, "XLogOpenRelation: out of memory for cache");
if (found) if (found)
elog(PANIC, "XLogOpenRelation: file found on insert into cache"); elog(PANIC, "XLogOpenRelation: file found on insert into cache");
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Copyright (c) 2002-2005, PostgreSQL Global Development Group * Copyright (c) 2002-2005, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.37 2005/05/24 04:18:04 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.38 2005/05/29 04:23:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -346,9 +346,9 @@ StorePreparedStatement(const char *stmt_name, ...@@ -346,9 +346,9 @@ StorePreparedStatement(const char *stmt_name,
HASH_ENTER, HASH_ENTER,
&found); &found);
/* Shouldn't get a failure, nor a duplicate entry */ /* Shouldn't get a duplicate entry */
if (!entry || found) if (found)
elog(ERROR, "could not store prepared statement \"%s\"", elog(ERROR, "duplicate prepared statement \"%s\"",
stmt_name); stmt_name);
/* Fill in the hash table entry with copied data */ /* Fill in the hash table entry with copied data */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.14 2005/03/16 21:38:06 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.15 2005/05/29 04:23:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -379,13 +379,9 @@ LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot, ...@@ -379,13 +379,9 @@ LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
} }
else else
{ {
/* created new entry ... we hope */
if (entry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* /*
* created new entry
*
* Zero any caller-requested space in the entry. (This zaps * Zero any caller-requested space in the entry. (This zaps
* the "key data" dynahash.c copied into the new entry, but we * the "key data" dynahash.c copied into the new entry, but we
* don't care since we're about to overwrite it anyway.) * don't care since we're about to overwrite it anyway.)
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Copyright (c) 2003-2005, PostgreSQL Global Development Group * Copyright (c) 2003-2005, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.3 2005/05/17 00:43:47 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.4 2005/05/29 04:23:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -220,10 +220,6 @@ tbm_create_pagetable(TIDBitmap *tbm) ...@@ -220,10 +220,6 @@ tbm_create_pagetable(TIDBitmap *tbm)
page = (PagetableEntry *) hash_search(tbm->pagetable, page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &tbm->entry1.blockno, (void *) &tbm->entry1.blockno,
HASH_ENTER, &found); HASH_ENTER, &found);
if (page == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
Assert(!found); Assert(!found);
memcpy(page, &tbm->entry1, sizeof(PagetableEntry)); memcpy(page, &tbm->entry1, sizeof(PagetableEntry));
} }
...@@ -726,10 +722,6 @@ tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno) ...@@ -726,10 +722,6 @@ tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno)
page = (PagetableEntry *) hash_search(tbm->pagetable, page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &pageno, (void *) &pageno,
HASH_ENTER, &found); HASH_ENTER, &found);
if (page == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
} }
/* Initialize it if not present before */ /* Initialize it if not present before */
...@@ -820,10 +812,6 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno) ...@@ -820,10 +812,6 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
page = (PagetableEntry *) hash_search(tbm->pagetable, page = (PagetableEntry *) hash_search(tbm->pagetable,
(void *) &chunk_pageno, (void *) &chunk_pageno,
HASH_ENTER, &found); HASH_ENTER, &found);
if (page == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* Initialize it if not present before */ /* Initialize it if not present before */
if (!found) if (!found)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2005, PostgreSQL Global Development Group * Copyright (c) 2001-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.94 2005/05/11 01:41:40 neilc Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.95 2005/05/29 04:23:03 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -2061,10 +2061,6 @@ pgstat_get_db_entry(int databaseid) ...@@ -2061,10 +2061,6 @@ pgstat_get_db_entry(int databaseid)
result = (PgStat_StatDBEntry *) hash_search(pgStatDBHash, result = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
&databaseid, &databaseid,
HASH_ENTER, &found); HASH_ENTER, &found);
if (result == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
/* If not found, initialize the new one. */ /* If not found, initialize the new one. */
if (!found) if (!found)
...@@ -2126,10 +2122,6 @@ pgstat_sub_backend(int procpid) ...@@ -2126,10 +2122,6 @@ pgstat_sub_backend(int procpid)
(void *) &procpid, (void *) &procpid,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (deadbe == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
if (!found) if (!found)
{ {
...@@ -2435,12 +2427,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2435,12 +2427,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
(void *) &dbbuf.databaseid, (void *) &dbbuf.databaseid,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (dbentry == NULL)
{
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
if (found) if (found)
{ {
ereport(pgStatRunningInCollector ? LOG : WARNING, ereport(pgStatRunningInCollector ? LOG : WARNING,
...@@ -2503,10 +2489,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb, ...@@ -2503,10 +2489,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
tabentry = (PgStat_StatTabEntry *) hash_search(tabhash, tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
(void *) &tabbuf.tableid, (void *) &tabbuf.tableid,
HASH_ENTER, &found); HASH_ENTER, &found);
if (tabentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found) if (found)
{ {
...@@ -2730,10 +2712,6 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len) ...@@ -2730,10 +2712,6 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables, tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(void *) &(tabmsg[i].t_id), (void *) &(tabmsg[i].t_id),
HASH_ENTER, &found); HASH_ENTER, &found);
if (tabentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
if (!found) if (!found)
{ {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.40 2005/03/04 20:21:06 tgl Exp $ * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.41 2005/05/29 04:23:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -110,11 +110,6 @@ BufTableInsert(BufferTag *tagPtr, int buf_id) ...@@ -110,11 +110,6 @@ BufTableInsert(BufferTag *tagPtr, int buf_id)
result = (BufferLookupEnt *) result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) tagPtr, HASH_ENTER, &found); hash_search(SharedBufHash, (void *) tagPtr, HASH_ENTER, &found);
if (!result)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
if (found) /* found something already in the table */ if (found) /* found something already in the table */
return result->id; return result->id;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.66 2005/03/19 23:27:05 tgl Exp $ * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.67 2005/05/29 04:23:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -192,10 +192,6 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -192,10 +192,6 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
hresult = (LocalBufferLookupEnt *) hresult = (LocalBufferLookupEnt *)
hash_search(LocalBufHash, (void *) &newTag, HASH_ENTER, &found); hash_search(LocalBufHash, (void *) &newTag, HASH_ENTER, &found);
if (!hresult)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found) /* shouldn't happen */ if (found) /* shouldn't happen */
elog(ERROR, "local buffer hash table corrupted"); elog(ERROR, "local buffer hash table corrupted");
hresult->id = b; hresult->id = b;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.44 2005/04/24 03:51:49 momjian Exp $ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005/05/29 04:23:04 tgl Exp $
* *
* *
* NOTES: * NOTES:
...@@ -1036,10 +1036,6 @@ create_fsm_rel(RelFileNode *rel) ...@@ -1036,10 +1036,6 @@ create_fsm_rel(RelFileNode *rel)
(void *) rel, (void *) rel,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (!fsmrel)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
if (!found) if (!found)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.83 2005/04/04 04:34:41 neilc Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005/05/29 04:23:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -235,10 +235,6 @@ InitShmemIndex(void) ...@@ -235,10 +235,6 @@ InitShmemIndex(void)
result = (ShmemIndexEnt *) result = (ShmemIndexEnt *)
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found); hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
if (!result)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
Assert(!found); Assert(!found);
...@@ -367,7 +363,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr) ...@@ -367,7 +363,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
/* look it up in the shmem index */ /* look it up in the shmem index */
result = (ShmemIndexEnt *) result = (ShmemIndexEnt *)
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, foundPtr); hash_search(ShmemIndex, (void *) &item, HASH_ENTER_NULL, foundPtr);
if (!result) if (!result)
{ {
...@@ -375,7 +371,6 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr) ...@@ -375,7 +371,6 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory"))); errmsg("out of shared memory")));
return NULL;
} }
if (*foundPtr) if (*foundPtr)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.152 2005/05/19 23:30:18 tgl Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.153 2005/05/29 04:23:04 tgl Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -470,10 +470,6 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, ...@@ -470,10 +470,6 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
locallock = (LOCALLOCK *) hash_search(LockMethodLocalHash[lockmethodid], locallock = (LOCALLOCK *) hash_search(LockMethodLocalHash[lockmethodid],
(void *) &localtag, (void *) &localtag,
HASH_ENTER, &found); HASH_ENTER, &found);
if (!locallock)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* /*
* if it's a new locallock object, initialize it * if it's a new locallock object, initialize it
...@@ -531,7 +527,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, ...@@ -531,7 +527,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
*/ */
lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid], lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
(void *) locktag, (void *) locktag,
HASH_ENTER, &found); HASH_ENTER_NULL, &found);
if (!lock) if (!lock)
{ {
LWLockRelease(masterLock); LWLockRelease(masterLock);
...@@ -578,7 +574,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, ...@@ -578,7 +574,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
*/ */
proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid], proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid],
(void *) &proclocktag, (void *) &proclocktag,
HASH_ENTER, &found); HASH_ENTER_NULL, &found);
if (!proclock) if (!proclock)
{ {
/* Ooops, not enough shmem for the proclock */ /* Ooops, not enough shmem for the proclock */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.114 2004/12/31 22:01:13 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.115 2005/05/29 04:23:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -805,9 +805,8 @@ register_dirty_segment(SMgrRelation reln, MdfdVec *seg) ...@@ -805,9 +805,8 @@ register_dirty_segment(SMgrRelation reln, MdfdVec *seg)
entry.rnode = reln->smgr_rnode; entry.rnode = reln->smgr_rnode;
entry.segno = seg->mdfd_segno; entry.segno = seg->mdfd_segno;
if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) != NULL) (void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
return true; return true;
/* out of memory: fall through to do it locally */
} }
else else
{ {
...@@ -838,10 +837,7 @@ RememberFsyncRequest(RelFileNode rnode, BlockNumber segno) ...@@ -838,10 +837,7 @@ RememberFsyncRequest(RelFileNode rnode, BlockNumber segno)
entry.rnode = rnode; entry.rnode = rnode;
entry.segno = segno; entry.segno = segno;
if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) == NULL) (void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
} }
/* /*
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.86 2005/03/20 22:00:53 tgl Exp $ * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.87 2005/05/29 04:23:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -207,10 +207,6 @@ smgropen(RelFileNode rnode) ...@@ -207,10 +207,6 @@ smgropen(RelFileNode rnode)
reln = (SMgrRelation) hash_search(SMgrRelationHash, reln = (SMgrRelation) hash_search(SMgrRelationHash,
(void *) &rnode, (void *) &rnode,
HASH_ENTER, &found); HASH_ENTER, &found);
if (reln == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* Initialize it if not present before */ /* Initialize it if not present before */
if (!found) if (!found)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.77 2005/04/28 21:47:15 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.78 2005/05/29 04:23:05 tgl Exp $
* *
* ---------- * ----------
*/ */
...@@ -3466,10 +3466,6 @@ ri_HashPreparedPlan(RI_QueryKey *key, void *plan) ...@@ -3466,10 +3466,6 @@ ri_HashPreparedPlan(RI_QueryKey *key, void *plan)
entry = (RI_QueryHashEntry *) hash_search(ri_query_cache, entry = (RI_QueryHashEntry *) hash_search(ri_query_cache,
(void *) key, (void *) key,
HASH_ENTER, &found); HASH_ENTER, &found);
if (entry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
entry->plan = plan; entry->plan = plan;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.224 2005/05/27 23:31:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.225 2005/05/29 04:23:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -137,10 +137,6 @@ do { \ ...@@ -137,10 +137,6 @@ do { \
(void *) &(RELATION->rd_id), \ (void *) &(RELATION->rd_id), \
HASH_ENTER, \ HASH_ENTER, \
&found); \ &found); \
if (idhentry == NULL) \
ereport(ERROR, \
(errcode(ERRCODE_OUT_OF_MEMORY), \
errmsg("out of memory"))); \
/* used to give notice if found -- now just keep quiet */ \ /* used to give notice if found -- now just keep quiet */ \
idhentry->reldesc = RELATION; \ idhentry->reldesc = RELATION; \
} while(0) } while(0)
...@@ -1044,10 +1040,6 @@ LookupOpclassInfo(Oid operatorClassOid, ...@@ -1044,10 +1040,6 @@ LookupOpclassInfo(Oid operatorClassOid,
opcentry = (OpClassCacheEnt *) hash_search(OpClassCache, opcentry = (OpClassCacheEnt *) hash_search(OpClassCache,
(void *) &operatorClassOid, (void *) &operatorClassOid,
HASH_ENTER, &found); HASH_ENTER, &found);
if (opcentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found && opcentry->valid) if (found && opcentry->valid)
{ {
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.13 2005/04/14 20:32:43 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.14 2005/05/29 04:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -158,10 +158,6 @@ lookup_type_cache(Oid type_id, int flags) ...@@ -158,10 +158,6 @@ lookup_type_cache(Oid type_id, int flags)
typentry = (TypeCacheEntry *) hash_search(TypeCacheHash, typentry = (TypeCacheEntry *) hash_search(TypeCacheHash,
(void *) &type_id, (void *) &type_id,
HASH_ENTER, &found); HASH_ENTER, &found);
if (typentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
Assert(!found); /* it wasn't there a moment ago */ Assert(!found); /* it wasn't there a moment ago */
MemSet(typentry, 0, sizeof(TypeCacheEntry)); MemSet(typentry, 0, sizeof(TypeCacheEntry));
...@@ -480,10 +476,6 @@ assign_record_type_typmod(TupleDesc tupDesc) ...@@ -480,10 +476,6 @@ assign_record_type_typmod(TupleDesc tupDesc)
recentry = (RecordCacheEntry *) hash_search(RecordCacheHash, recentry = (RecordCacheEntry *) hash_search(RecordCacheHash,
(void *) hashkey, (void *) hashkey,
HASH_ENTER, &found); HASH_ENTER, &found);
if (recentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (!found) if (!found)
{ {
/* New entry ... hash_search initialized only the hash key */ /* New entry ... hash_search initialized only the hash key */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.94 2005/04/14 20:32:43 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.95 2005/05/29 04:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -521,10 +521,6 @@ record_C_func(HeapTuple procedureTuple, ...@@ -521,10 +521,6 @@ record_C_func(HeapTuple procedureTuple,
&fn_oid, &fn_oid,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (entry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
/* OID is already filled in */ /* OID is already filled in */
entry->fn_xmin = HeapTupleHeaderGetXmin(procedureTuple->t_data); entry->fn_xmin = HeapTupleHeaderGetXmin(procedureTuple->t_data);
entry->fn_cmin = HeapTupleHeaderGetCmin(procedureTuple->t_data); entry->fn_cmin = HeapTupleHeaderGetCmin(procedureTuple->t_data);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.60 2005/05/16 00:19:04 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.61 2005/05/29 04:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -498,22 +498,22 @@ calc_bucket(HASHHDR *hctl, uint32 hash_val) ...@@ -498,22 +498,22 @@ calc_bucket(HASHHDR *hctl, uint32 hash_val)
* action is one of: * action is one of:
* HASH_FIND: look up key in table * HASH_FIND: look up key in table
* HASH_ENTER: look up key in table, creating entry if not present * HASH_ENTER: look up key in table, creating entry if not present
* HASH_ENTER_NULL: same, but return NULL if out of memory
* HASH_REMOVE: look up key in table, remove entry if present * HASH_REMOVE: look up key in table, remove entry if present
* HASH_FIND_SAVE: look up key in table, also save in static var
* HASH_REMOVE_SAVED: remove entry saved by HASH_FIND_SAVE
* *
* Return value is a pointer to the element found/entered/removed if any, * Return value is a pointer to the element found/entered/removed if any,
* or NULL if no match was found. (NB: in the case of the REMOVE actions, * or NULL if no match was found. (NB: in the case of the REMOVE action,
* the result is a dangling pointer that shouldn't be dereferenced!) * the result is a dangling pointer that shouldn't be dereferenced!)
* A NULL result for HASH_ENTER implies we ran out of memory. *
* HASH_ENTER will normally ereport a generic "out of memory" error if
* it is unable to create a new entry. The HASH_ENTER_NULL operation is
* the same except it will return NULL if out of memory. Note that
* HASH_ENTER_NULL cannot be used with the default palloc-based allocator,
* since palloc internally ereports on out-of-memory.
* *
* If foundPtr isn't NULL, then *foundPtr is set TRUE if we found an * If foundPtr isn't NULL, then *foundPtr is set TRUE if we found an
* existing entry in the table, FALSE otherwise. This is needed in the * existing entry in the table, FALSE otherwise. This is needed in the
* HASH_ENTER case, but is redundant with the return value otherwise. * HASH_ENTER case, but is redundant with the return value otherwise.
*
* The HASH_FIND_SAVE/HASH_REMOVE_SAVED interface is a hack to save one
* table lookup in a find/process/remove scenario. Note that no other
* addition or removal in the table can safely happen in between.
*---------- *----------
*/ */
void * void *
...@@ -523,19 +523,15 @@ hash_search(HTAB *hashp, ...@@ -523,19 +523,15 @@ hash_search(HTAB *hashp,
bool *foundPtr) bool *foundPtr)
{ {
HASHHDR *hctl = hashp->hctl; HASHHDR *hctl = hashp->hctl;
uint32 hashvalue = 0; Size keysize = hctl->keysize;
uint32 hashvalue;
uint32 bucket; uint32 bucket;
long segment_num; long segment_num;
long segment_ndx; long segment_ndx;
HASHSEGMENT segp; HASHSEGMENT segp;
HASHBUCKET currBucket; HASHBUCKET currBucket;
HASHBUCKET *prevBucketPtr; HASHBUCKET *prevBucketPtr;
HashCompareFunc match;
static struct State
{
HASHBUCKET currBucket;
HASHBUCKET *prevBucketPtr;
} saveState;
#if HASH_STATISTICS #if HASH_STATISTICS
hash_accesses++; hash_accesses++;
...@@ -543,24 +539,8 @@ hash_search(HTAB *hashp, ...@@ -543,24 +539,8 @@ hash_search(HTAB *hashp,
#endif #endif
/* /*
* Do the initial lookup (or recall result of prior lookup) * Do the initial lookup
*/ */
if (action == HASH_REMOVE_SAVED)
{
currBucket = saveState.currBucket;
prevBucketPtr = saveState.prevBucketPtr;
/*
* Try to catch subsequent errors
*/
Assert(currBucket);
saveState.currBucket = NULL;
}
else
{
HashCompareFunc match;
Size keysize = hctl->keysize;
hashvalue = hashp->hash(keyPtr, keysize); hashvalue = hashp->hash(keyPtr, keysize);
bucket = calc_bucket(hctl, hashvalue); bucket = calc_bucket(hctl, hashvalue);
...@@ -579,6 +559,7 @@ hash_search(HTAB *hashp, ...@@ -579,6 +559,7 @@ hash_search(HTAB *hashp,
* Follow collision chain looking for matching key * Follow collision chain looking for matching key
*/ */
match = hashp->match; /* save one fetch in inner loop */ match = hashp->match; /* save one fetch in inner loop */
while (currBucket != NULL) while (currBucket != NULL)
{ {
if (currBucket->hashvalue == hashvalue && if (currBucket->hashvalue == hashvalue &&
...@@ -591,7 +572,6 @@ hash_search(HTAB *hashp, ...@@ -591,7 +572,6 @@ hash_search(HTAB *hashp,
hctl->collisions++; hctl->collisions++;
#endif #endif
} }
}
if (foundPtr) if (foundPtr)
*foundPtr = (bool) (currBucket != NULL); *foundPtr = (bool) (currBucket != NULL);
...@@ -606,17 +586,7 @@ hash_search(HTAB *hashp, ...@@ -606,17 +586,7 @@ hash_search(HTAB *hashp,
return (void *) ELEMENTKEY(currBucket); return (void *) ELEMENTKEY(currBucket);
return NULL; return NULL;
case HASH_FIND_SAVE:
if (currBucket != NULL)
{
saveState.currBucket = currBucket;
saveState.prevBucketPtr = prevBucketPtr;
return (void *) ELEMENTKEY(currBucket);
}
return NULL;
case HASH_REMOVE: case HASH_REMOVE:
case HASH_REMOVE_SAVED:
if (currBucket != NULL) if (currBucket != NULL)
{ {
Assert(hctl->nentries > 0); Assert(hctl->nentries > 0);
...@@ -638,6 +608,11 @@ hash_search(HTAB *hashp, ...@@ -638,6 +608,11 @@ hash_search(HTAB *hashp,
} }
return NULL; return NULL;
case HASH_ENTER_NULL:
/* ENTER_NULL does not work with palloc-based allocator */
Assert(hashp->alloc != DynaHashAlloc);
/* FALL THRU */
case HASH_ENTER: case HASH_ENTER:
/* Return existing element if found, else create one */ /* Return existing element if found, else create one */
if (currBucket != NULL) if (currBucket != NULL)
...@@ -649,7 +624,20 @@ hash_search(HTAB *hashp, ...@@ -649,7 +624,20 @@ hash_search(HTAB *hashp,
{ {
/* no free elements. allocate another chunk of buckets */ /* no free elements. allocate another chunk of buckets */
if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR)) if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
return NULL; /* out of memory */ {
/* out of memory */
if (action == HASH_ENTER_NULL)
return NULL;
/* report a generic message */
if (hashp->isshared)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
else
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
currBucket = hctl->freeList; currBucket = hctl->freeList;
Assert(currBucket != NULL); Assert(currBucket != NULL);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.79 2005/05/11 18:05:37 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.80 2005/05/29 04:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,10 +72,6 @@ do { \ ...@@ -72,10 +72,6 @@ do { \
StrNCpy(key, NAME, MAX_PORTALNAME_LEN); \ StrNCpy(key, NAME, MAX_PORTALNAME_LEN); \
hentry = (PortalHashEnt*)hash_search(PortalHashTable, \ hentry = (PortalHashEnt*)hash_search(PortalHashTable, \
key, HASH_ENTER, &found); \ key, HASH_ENTER, &found); \
if (hentry == NULL) \
ereport(ERROR, \
(errcode(ERRCODE_OUT_OF_MEMORY), \
errmsg("out of memory"))); \
if (found) \ if (found) \
elog(ERROR, "duplicate portal name"); \ elog(ERROR, "duplicate portal name"); \
hentry->portal = PORTAL; \ hentry->portal = PORTAL; \
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.35 2005/04/14 20:32:43 tgl Exp $ * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.36 2005/05/29 04:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -153,8 +153,7 @@ typedef enum ...@@ -153,8 +153,7 @@ typedef enum
HASH_FIND, HASH_FIND,
HASH_ENTER, HASH_ENTER,
HASH_REMOVE, HASH_REMOVE,
HASH_FIND_SAVE, HASH_ENTER_NULL
HASH_REMOVE_SAVED
} HASHACTION; } HASHACTION;
/* hash_seq status (should be considered an opaque type by callers) */ /* hash_seq status (should be considered an opaque type by callers) */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.89 2005/05/06 17:24:55 tgl Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.90 2005/05/29 04:23:06 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -2157,10 +2157,6 @@ plpgsql_HashTableInsert(PLpgSQL_function *function, ...@@ -2157,10 +2157,6 @@ plpgsql_HashTableInsert(PLpgSQL_function *function,
(void *) func_key, (void *) func_key,
HASH_ENTER, HASH_ENTER,
&found); &found);
if (hentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found) if (found)
elog(WARNING, "trying to insert a function that already exists"); elog(WARNING, "trying to insert a function that already exists");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.31 2005/05/23 21:54:02 momjian Exp $ * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.32 2005/05/29 04:23:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -971,6 +971,7 @@ identify_system_timezone(void) ...@@ -971,6 +971,7 @@ identify_system_timezone(void)
* load and parse the TZ definition file every time it is selected. * load and parse the TZ definition file every time it is selected.
*/ */
static HTAB *timezone_cache = NULL; static HTAB *timezone_cache = NULL;
static bool static bool
init_timezone_hashtable(void) init_timezone_hashtable(void)
{ {
...@@ -1013,15 +1014,19 @@ pg_tzset(const char *name) ...@@ -1013,15 +1014,19 @@ pg_tzset(const char *name)
HASH_FIND, HASH_FIND,
NULL); NULL);
if (tzp) if (tzp)
{
/* Timezone found in cache, nothing more to do */ /* Timezone found in cache, nothing more to do */
return tzp; return tzp;
}
if (tzload(name, &tz.state) != 0) if (tzload(name, &tz.state) != 0)
{ {
if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0) if (name[0] == ':' || tzparse(name, &tz.state, FALSE) != 0)
{
/* Unknown timezone. Fail our call instead of loading GMT! */ /* Unknown timezone. Fail our call instead of loading GMT! */
return NULL; return NULL;
} }
}
strcpy(tz.TZname, name); strcpy(tz.TZname, name);
...@@ -1031,9 +1036,6 @@ pg_tzset(const char *name) ...@@ -1031,9 +1036,6 @@ pg_tzset(const char *name)
HASH_ENTER, HASH_ENTER,
NULL); NULL);
if (!tzp)
return NULL;
strcpy(tzp->TZname, tz.TZname); strcpy(tzp->TZname, tz.TZname);
memcpy(&tzp->state, &tz.state, sizeof(tz.state)); memcpy(&tzp->state, &tz.state, sizeof(tz.state));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment