postgres.git / summary / log / commit / refs
commit 11b7de4a784135d7a9bce4a29ede092797749efc
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon Oct 28 18:39:01 2024 +0000
Unify src/common/'s definitions of MaxAllocSize.
As threatened in the previous patch, define MaxAllocSize in
src/include/common/fe_memutils.h rather than having several
copies of it in different src/common/*.c files. This also
provides an opportunity to document it better.
While this would probably be safe to back-patch, I'll refrain
(for now anyway).
src/common/psprintf.c | 3 ---
src/common/saslprep.c | 4 ----
src/common/stringinfo.c | 3 ---
src/include/common/fe_memutils.h | 12 ++++++++++++
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/common/psprintf.c b/src/common/psprintf.c
index a063fd26d51..2ebc01093f5 100644
--- a/src/common/psprintf.c
+++ b/src/common/psprintf.c
@@ -24,9 +24,6 @@
#include "postgres_fe.h"
-/* It's possible we could use a different value for this in frontend code */
-#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
-
#endif
diff --git a/src/common/saslprep.c b/src/common/saslprep.c
index 0a840352802..5d84d13c6d2 100644
--- a/src/common/saslprep.c
+++ b/src/common/saslprep.c
@@ -24,10 +24,6 @@
#include "utils/memutils.h"
#else
#include "postgres_fe.h"
-
-/* It's possible we could use a different value for this in frontend code */
-#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
-
#endif
#include "common/saslprep.h"
diff --git a/src/common/stringinfo.c b/src/common/stringinfo.c
index eb9d6502fc8..6192e65477e 100644
--- a/src/common/stringinfo.c
+++ b/src/common/stringinfo.c
@@ -24,9 +24,6 @@
#include "postgres_fe.h"
-/* It's possible we could use a different value for this in frontend code */
-#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
-
#endif
#include "lib/stringinfo.h"
diff --git a/src/include/common/fe_memutils.h b/src/include/common/fe_memutils.h
index 492cc97e8d1..6544ebb44e5 100644
--- a/src/include/common/fe_memutils.h
+++ b/src/include/common/fe_memutils.h
@@ -9,6 +9,18 @@
#ifndef FE_MEMUTILS_H
#define FE_MEMUTILS_H
+/*
+ * Assumed maximum size for allocation requests.
+ *
+ * We don't enforce this, so the actual maximum is the platform's SIZE_MAX.
+ * But it's useful to have it defined in frontend builds, so that common
+ * code can check for oversized requests without having frontend-vs-backend
+ * differences. Also, some code relies on MaxAllocSize being no more than
+ * INT_MAX/2, so rather than setting this to SIZE_MAX, make it the same as
+ * the backend's value.
+ */
+#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
+
/*
* Flags for pg_malloc_extended and palloc_extended, deliberately named
* the same as the backend flags.
[parent: bd2843167200]