summaryrefslogtreecommitdiff
path: root/src/bin/scripts/common.c
diff options
context:
space:
mode:
authorAlvaro Herrera2013-02-12 13:33:40 +0000
committerAlvaro Herrera2013-02-12 14:21:05 +0000
commit8396447cdbdff0b62914748de2fec04281dc9114 (patch)
treedd95fd78c6c507ef6f3c9d9c4cd769aeda7c9fcc /src/bin/scripts/common.c
parent0cb1fac3b19f01025b63d2cdceabb8767185da28 (diff)
Create libpgcommon, and move pg_malloc et al to it
libpgcommon is a new static library to allow sharing code among the various frontend programs and backend; this lets us eliminate duplicate implementations of common routines. We avoid libpgport, because that's intended as a place for porting issues; per discussion, it seems better to keep them separate. The first use case, and the only implemented by this patch, is pg_malloc and friends, which many frontend programs were already using. At the same time, we can use this to provide palloc emulation functions for the frontend; this way, some palloc-using files in the backend can also be used by the frontend cleanly. To do this, we change palloc() in the backend to be a function instead of a macro on top of MemoryContextAlloc(). This was previously believed to cause loss of performance, but this implementation has been tweaked by Tom and Andres so that on modern compilers it provides a slight improvement over the previous one. This lets us clean up some places that were already with localized hacks. Most of the pg_malloc/palloc changes in this patch were authored by Andres Freund. Zoltán Böszörményi also independently provided a form of that. libpgcommon infrastructure was authored by Álvaro.
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r--src/bin/scripts/common.c49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index c7cc04aea4b..03193b6fcdc 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -278,55 +278,6 @@ executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
}
/*
- * "Safe" wrapper around strdup(). Pulled from psql/common.c
- */
-char *
-pg_strdup(const char *string)
-{
- char *tmp;
-
- if (!string)
- {
- fprintf(stderr, _("pg_strdup: cannot duplicate null pointer (internal error)\n"));
- exit(EXIT_FAILURE);
- }
- tmp = strdup(string);
- if (!tmp)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
- return tmp;
-}
-
-void *
-pg_malloc(size_t size)
-{
- void *tmp;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- tmp = malloc(size);
- if (!tmp)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(EXIT_FAILURE);
- }
- return tmp;
-}
-
-void *
-pg_malloc0(size_t size)
-{
- void *tmp;
-
- tmp = pg_malloc(size);
- MemSet(tmp, 0, size);
- return tmp;
-}
-
-/*
* Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
*/