Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit528c454

Browse files
committed
Don't #include utils/palloc.h in common/fe_memutils.h.
This breaks the principle that common/ ought not depend on anything in theserver, not only code-wise but in the headers. The only arguable advantageis avoidance of duplication of half a dozen extern declarations, and eventhat is rather dubious, considering that the previous coding was wrongabout which declarations to duplicate: it exposed pnstrdup() to frontendcode even though no such function is provided in fe_memutils.c.On the same principle, don't #include utils/memutils.h in the frontendbuild of psprintf.c. This requires duplicating the definition ofMaxAllocSize, but that seems fine to me: there's no a-priori reason whyfrontend code should use the same size limit as the backend anyway.In passing, clean up some rather odd layout and ordering choices thatwere imposed on palloc.h to reduce the number of #ifdefs required bythe previous approach.Per gripe from Christoph Berg. There's still more work to do to makeinclude/common/ clean, but this part seems reasonably noncontroversial.
1 parent39b0c76 commit528c454

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

‎src/common/psprintf.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@
1515
*/
1616

1717
#ifndefFRONTEND
18+
1819
#include"postgres.h"
20+
21+
#include"utils/memutils.h"
22+
1923
#else
24+
2025
#include"postgres_fe.h"
21-
#endif
2226

23-
#include"utils/memutils.h"
27+
/* It's possible we could use a different value for this in frontend code */
28+
#defineMaxAllocSize((Size) 0x3fffffff)/* 1 gigabyte - 1 */
29+
30+
#endif
2431

2532

2633
/*

‎src/include/common/fe_memutils.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@
99
#ifndefFE_MEMUTILS_H
1010
#defineFE_MEMUTILS_H
1111

12+
/* "Safe" memory allocation functions --- these exit(1) on failure */
1213
externchar*pg_strdup(constchar*in);
1314
externvoid*pg_malloc(size_tsize);
1415
externvoid*pg_malloc0(size_tsize);
1516
externvoid*pg_realloc(void*pointer,size_tsize);
1617
externvoidpg_free(void*pointer);
1718

18-
#include"utils/palloc.h"
19+
/* Equivalent functions, deliberately named the same as backend functions */
20+
externchar*pstrdup(constchar*in);
21+
externvoid*palloc(Sizesize);
22+
externvoid*palloc0(Sizesize);
23+
externvoid*repalloc(void*pointer,Sizesize);
24+
externvoidpfree(void*pointer);
25+
26+
/* sprintf into a palloc'd buffer --- these are in psprintf.c */
27+
externchar*psprintf(constchar*fmt,...)
28+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
29+
externsize_tpvsnprintf(char*buf,size_tlen,constchar*fmt,va_listargs)
30+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,0)));
1931

2032
#endif/* FE_MEMUTILS_H */

‎src/include/utils/palloc.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
*/
3636
typedefstructMemoryContextData*MemoryContext;
3737

38-
#ifndefFRONTEND
39-
4038
/*
4139
* CurrentMemoryContext is the default allocation context for palloc().
42-
*We declare ithere so that palloc() can be a macro.Avoid accessing it
43-
*directly! Instead, use MemoryContextSwitchTo()to change the setting.
40+
*Avoid accessing itdirectly! Instead, use MemoryContextSwitchTo()
41+
* to change the setting.
4442
*/
4543
externPGDLLIMPORTMemoryContextCurrentMemoryContext;
4644

@@ -51,9 +49,10 @@ extern void *MemoryContextAlloc(MemoryContext context, Size size);
5149
externvoid*MemoryContextAllocZero(MemoryContextcontext,Sizesize);
5250
externvoid*MemoryContextAllocZeroAligned(MemoryContextcontext,Sizesize);
5351

54-
/* Higher-limit allocators. */
55-
externvoid*MemoryContextAllocHuge(MemoryContextcontext,Sizesize);
56-
externvoid*repalloc_huge(void*pointer,Sizesize);
52+
externvoid*palloc(Sizesize);
53+
externvoid*palloc0(Sizesize);
54+
externvoid*repalloc(void*pointer,Sizesize);
55+
externvoidpfree(void*pointer);
5756

5857
/*
5958
* The result of palloc() is always word-aligned, so we can skip testing
@@ -68,6 +67,10 @@ extern void *repalloc_huge(void *pointer, Size size);
6867
MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
6968
MemoryContextAllocZero(CurrentMemoryContext, sz) )
7069

70+
/* Higher-limit allocators. */
71+
externvoid*MemoryContextAllocHuge(MemoryContextcontext,Sizesize);
72+
externvoid*repalloc_huge(void*pointer,Sizesize);
73+
7174
/*
7275
* MemoryContextSwitchTo can't be a macro in standard C compilers.
7376
* But we can make it an inline function if the compiler supports it.
@@ -93,17 +96,9 @@ MemoryContextSwitchTo(MemoryContext context)
9396
* allocated in a context, not with malloc().
9497
*/
9598
externchar*MemoryContextStrdup(MemoryContextcontext,constchar*string);
96-
#endif/* !FRONTEND */
97-
9899
externchar*pstrdup(constchar*in);
99100
externchar*pnstrdup(constchar*in,Sizelen);
100101

101-
/* basic memory allocation functions */
102-
externvoid*palloc(Sizesize);
103-
externvoid*palloc0(Sizesize);
104-
externvoidpfree(void*pointer);
105-
externvoid*repalloc(void*pointer,Sizesize);
106-
107102
/* sprintf into a palloc'd buffer --- these are in psprintf.c */
108103
externchar*psprintf(constchar*fmt,...)
109104
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp