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

Commite4c1a49

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 parentc0bd128 commite4c1a49

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

‎src/include/common/fe_memutils.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
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);
1925

2026
#endif/* FE_MEMUTILS_H */

‎src/include/utils/palloc.h‎

Lines changed: 7 additions & 9 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,6 +49,11 @@ extern void *MemoryContextAlloc(MemoryContext context, Size size);
5149
externvoid*MemoryContextAllocZero(MemoryContextcontext,Sizesize);
5250
externvoid*MemoryContextAllocZeroAligned(MemoryContextcontext,Sizesize);
5351

52+
externvoid*palloc(Sizesize);
53+
externvoid*palloc0(Sizesize);
54+
externvoid*repalloc(void*pointer,Sizesize);
55+
externvoidpfree(void*pointer);
56+
5457
/*
5558
* The result of palloc() is always word-aligned, so we can skip testing
5659
* alignment of the pointer when deciding which MemSet variant to use.
@@ -89,13 +92,8 @@ MemoryContextSwitchTo(MemoryContext context)
8992
* allocated in a context, not with malloc().
9093
*/
9194
externchar*MemoryContextStrdup(MemoryContextcontext,constchar*string);
92-
#endif/* !FRONTEND */
9395

9496
externchar*pstrdup(constchar*in);
9597
externchar*pnstrdup(constchar*in,Sizelen);
96-
externvoid*palloc(Sizesize);
97-
externvoid*palloc0(Sizesize);
98-
externvoidpfree(void*pointer);
99-
externvoid*repalloc(void*pointer,Sizesize);
10098

10199
#endif/* PALLOC_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp