Skip to content

Commit 2e01d05

Browse files
committed
Fix frontend version of sh_error() in simplehash.h.
The code does not expect sh_error() to return, but the patch that made this header usable in frontend didn't get that memo. While here, plaster unlikely() on the tests that decide whether to invoke sh_error(), and add our standard copyright notice. Noted by Andres Freund. Back-patch to v13 where this frontend support came in. Discussion: https://postgr.es/m/0D54435C-1199-4361-9D74-2FBDCF8EA164@anarazel.de
1 parent 4760060 commit 2e01d05

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/include/lib/simplehash.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
* presence is relevant to determine whether a lookup needs to continue
5656
* looking or is done - buckets following a deleted element are shifted
5757
* backwards, unless they're empty or already at their optimal position.
58+
*
59+
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
60+
* Portions Copyright (c) 1994, Regents of the University of California
61+
*
62+
* src/include/lib/simplehash.h
5863
*/
5964

6065
#include "port/pg_bitutils.h"
@@ -218,7 +223,8 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
218223
#define SIMPLEHASH_H
219224

220225
#ifdef FRONTEND
221-
#define sh_error(...) pg_log_error(__VA_ARGS__)
226+
#define sh_error(...) \
227+
do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
222228
#define sh_log(...) pg_log_info(__VA_ARGS__)
223229
#else
224230
#define sh_error(...) elog(ERROR, __VA_ARGS__)
@@ -247,7 +253,7 @@ SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint64 newsize)
247253
* Verify that allocation of ->data is possible on this platform, without
248254
* overflowing Size.
249255
*/
250-
if ((((uint64) sizeof(SH_ELEMENT_TYPE)) * size) >= SIZE_MAX / 2)
256+
if (unlikely((((uint64) sizeof(SH_ELEMENT_TYPE)) * size) >= SIZE_MAX / 2))
251257
sh_error("hash table too large");
252258

253259
/* now set size */
@@ -532,10 +538,8 @@ SH_INSERT_HASH_INTERNAL(SH_TYPE * tb, SH_KEY_TYPE key, uint32 hash, bool *found)
532538
*/
533539
if (unlikely(tb->members >= tb->grow_threshold))
534540
{
535-
if (tb->size == SH_MAX_SIZE)
536-
{
541+
if (unlikely(tb->size == SH_MAX_SIZE))
537542
sh_error("hash table size exceeded");
538-
}
539543

540544
/*
541545
* When optimizing, it can be very useful to print these out.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy