summaryrefslogtreecommitdiff
path: root/src/include/common/fe_memutils.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-04-26 14:14:28 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-04-26 14:14:28 -0400
commit528c454b2ada89ca0f0cd9a64f939e775b55b879 (patch)
tree6cb9277a7bc417afe27c035f1bb9e8406fb85734 /src/include/common/fe_memutils.h
parent39b0c7681e465f3e486ca2a5d13fbbafbe25cb1a (diff)
Don't #include utils/palloc.h in common/fe_memutils.h.
This breaks the principle that common/ ought not depend on anything in the server, not only code-wise but in the headers. The only arguable advantage is avoidance of duplication of half a dozen extern declarations, and even that is rather dubious, considering that the previous coding was wrong about which declarations to duplicate: it exposed pnstrdup() to frontend code even though no such function is provided in fe_memutils.c. On the same principle, don't #include utils/memutils.h in the frontend build of psprintf.c. This requires duplicating the definition of MaxAllocSize, but that seems fine to me: there's no a-priori reason why frontend code should use the same size limit as the backend anyway. In passing, clean up some rather odd layout and ordering choices that were imposed on palloc.h to reduce the number of #ifdefs required by the previous approach. Per gripe from Christoph Berg. There's still more work to do to make include/common/ clean, but this part seems reasonably noncontroversial.
Diffstat (limited to 'src/include/common/fe_memutils.h')
-rw-r--r--src/include/common/fe_memutils.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/include/common/fe_memutils.h b/src/include/common/fe_memutils.h
index 96ee7b3ef66..3da1891ef2c 100644
--- a/src/include/common/fe_memutils.h
+++ b/src/include/common/fe_memutils.h
@@ -9,12 +9,24 @@
#ifndef FE_MEMUTILS_H
#define FE_MEMUTILS_H
+/* "Safe" memory allocation functions --- these exit(1) on failure */
extern char *pg_strdup(const char *in);
extern void *pg_malloc(size_t size);
extern void *pg_malloc0(size_t size);
extern void *pg_realloc(void *pointer, size_t size);
extern void pg_free(void *pointer);
-#include "utils/palloc.h"
+/* Equivalent functions, deliberately named the same as backend functions */
+extern char *pstrdup(const char *in);
+extern void *palloc(Size size);
+extern void *palloc0(Size size);
+extern void *repalloc(void *pointer, Size size);
+extern void pfree(void *pointer);
+
+/* sprintf into a palloc'd buffer --- these are in psprintf.c */
+extern char *psprintf(const char *fmt,...)
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
+extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
#endif /* FE_MEMUTILS_H */