Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 11b7de4

Browse files
committed
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).
1 parent bd28431 commit 11b7de4

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/common/psprintf.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
#include "postgres_fe.h"
2626

27-
/* It's possible we could use a different value for this in frontend code */
28-
#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
29-
3027
#endif
3128

3229

src/common/saslprep.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
#include "utils/memutils.h"
2525
#else
2626
#include "postgres_fe.h"
27-
28-
/* It's possible we could use a different value for this in frontend code */
29-
#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
30-
3127
#endif
3228

3329
#include "common/saslprep.h"

src/common/stringinfo.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
#include "postgres_fe.h"
2626

27-
/* It's possible we could use a different value for this in frontend code */
28-
#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
29-
3027
#endif
3128

3229
#include "lib/stringinfo.h"

src/include/common/fe_memutils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
#ifndef FE_MEMUTILS_H
1010
#define FE_MEMUTILS_H
1111

12+
/*
13+
* Assumed maximum size for allocation requests.
14+
*
15+
* We don't enforce this, so the actual maximum is the platform's SIZE_MAX.
16+
* But it's useful to have it defined in frontend builds, so that common
17+
* code can check for oversized requests without having frontend-vs-backend
18+
* differences. Also, some code relies on MaxAllocSize being no more than
19+
* INT_MAX/2, so rather than setting this to SIZE_MAX, make it the same as
20+
* the backend's value.
21+
*/
22+
#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
23+
1224
/*
1325
* Flags for pg_malloc_extended and palloc_extended, deliberately named
1426
* the same as the backend flags.

0 commit comments

Comments
 (0)