Unify src/common/'s definitions of MaxAllocSize.
authorTom Lane <[email protected]>
Mon, 28 Oct 2024 18:39:01 +0000 (14:39 -0400)
committerTom Lane <[email protected]>
Mon, 28 Oct 2024 18:39:01 +0000 (14:39 -0400)
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
src/common/saslprep.c
src/common/stringinfo.c
src/include/common/fe_memutils.h

index a063fd26d51a236a61575d8e5c48a55a64b371ae..2ebc01093f571bc348e32c3d9520a5dbb2042473 100644 (file)
@@ -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
 
 
index 0a840352802e04945202af62f5d3be20a25f569a..5d84d13c6d2d5946a0635369c911cd17bc96afa0 100644 (file)
 #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"
index eb9d6502fc89ab4c839676d75ce86773effb5461..6192e65477ec68c6f3b1fdfae9df0bc5d61d30f2 100644 (file)
@@ -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"
index 492cc97e8d19accf85a68916f75abe0b2e08f9ae..6544ebb44e5884bf80fac0e072f4b17df254feb0 100644 (file)
@@ -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.