palloc unification
There was some discussion about unifying backend and frontend
code/headers for palloc et al, particularly so that programs that want
to mix both can be easily compiled; see
/messages/by-id/20130118150629.GC29501@alap2.anarazel.de
for what I believe to be the latest and greatest patch in that area.
The good news from that patch is that there is a reported (small)
performance increase from the approach suggested there, on Intel and
non-Intel platforms. So it seems we're okay on that front.
On the source code organization front, however, I'm not too happy with
that particular proposal. There would be two files named palloc.h, for
one thing, and also the changes to utils/palloc.h leave way too much of
the backend-only implementation exposed to the frontend world.
I propose to have a new subdirectory src/include/shared, and two
header files:
src/include/utils/palloc.h (same as today)
src/include/shared/fe_memutils.h
(pg_malloc, pg_free, pg_strdup decls)
utils/palloc.h would be modified so that #ifdef FRONTEND, only the basic
function declarations (palloc, pfree, pstrdup, pnstrdup) are exposed;
frontend environment would be safe from CurrentMemoryContext etc.
The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.
Opinions on having a new subdir?
We could eventually move some stuff from timestamp.c in there, so that
pg_xlogdump could get timestamp_to_str from there; we could perhaps
remove the ecpg implementation of that as well and make it use this one.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Mon, Feb 4, 2013 at 5:50 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
There was some discussion about unifying backend and frontend
code/headers for palloc et al, particularly so that programs that want
to mix both can be easily compiled; see
/messages/by-id/20130118150629.GC29501@alap2.anarazel.de
for what I believe to be the latest and greatest patch in that area.
The good news from that patch is that there is a reported (small)
performance increase from the approach suggested there, on Intel and
non-Intel platforms. So it seems we're okay on that front.On the source code organization front, however, I'm not too happy with
that particular proposal. There would be two files named palloc.h, for
one thing, and also the changes to utils/palloc.h leave way too much of
the backend-only implementation exposed to the frontend world.I propose to have a new subdirectory src/include/shared, and two
header files:src/include/utils/palloc.h (same as today)
src/include/shared/fe_memutils.h
(pg_malloc, pg_free, pg_strdup decls)utils/palloc.h would be modified so that #ifdef FRONTEND, only the basic
function declarations (palloc, pfree, pstrdup, pnstrdup) are exposed;
frontend environment would be safe from CurrentMemoryContext etc.The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.Opinions on having a new subdir?
We could eventually move some stuff from timestamp.c in there, so that
pg_xlogdump could get timestamp_to_str from there; we could perhaps
remove the ecpg implementation of that as well and make it use this one.
I like the idea of having a place for shared frontend and backend code
very much, but I don't think src/include/shared or src/shared is a
good name, because "shared" can mean a lot of things - like "shared
library", for example. I think that this should be set up in a manner
analogous to libpgport, except not for portability code, but instead
for other stuff. Maybe we could call it libpgframework or something.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Robert Haas escribió:
On Mon, Feb 4, 2013 at 5:50 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
I propose to have a new subdirectory src/include/shared, and two
header files:
The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.Opinions on having a new subdir?
I like the idea of having a place for shared frontend and backend code
very much, but I don't think src/include/shared or src/shared is a
good name, because "shared" can mean a lot of things - like "shared
library", for example. I think that this should be set up in a manner
analogous to libpgport, except not for portability code, but instead
for other stuff. Maybe we could call it libpgframework or something.
Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Feb 6, 2013 at 9:38 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
Robert Haas escribió:
On Mon, Feb 4, 2013 at 5:50 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
I propose to have a new subdirectory src/include/shared, and two
header files:The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.Opinions on having a new subdir?
I like the idea of having a place for shared frontend and backend code
very much, but I don't think src/include/shared or src/shared is a
good name, because "shared" can mean a lot of things - like "shared
library", for example. I think that this should be set up in a manner
analogous to libpgport, except not for portability code, but instead
for other stuff. Maybe we could call it libpgframework or something.Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?
That seems reasonable to me.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 6 February 2013 14:38, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
Robert Haas escribió:
On Mon, Feb 4, 2013 at 5:50 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
I propose to have a new subdirectory src/include/shared, and two
header files:The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.Opinions on having a new subdir?
I like the idea of having a place for shared frontend and backend code
very much, but I don't think src/include/shared or src/shared is a
good name, because "shared" can mean a lot of things - like "shared
library", for example. I think that this should be set up in a manner
analogous to libpgport, except not for portability code, but instead
for other stuff. Maybe we could call it libpgframework or something.Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?
"common" ?
src/backend/common
src/include/common
--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Feb 6, 2013 at 9:59 AM, Simon Riggs <simon@2ndquadrant.com> wrote:
On 6 February 2013 14:38, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
Robert Haas escribió:
On Mon, Feb 4, 2013 at 5:50 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
I propose to have a new subdirectory src/include/shared, and two
header files:The frontend (pg_malloc) function definitions would live somewhere in,
say, src/shared/fe_memutils.c. For the palloc() implementation, I think
we should create another file, so that frontend-only programs that do
not require those symbols (most of them) are not unnecessarily bloated.Opinions on having a new subdir?
I like the idea of having a place for shared frontend and backend code
very much, but I don't think src/include/shared or src/shared is a
good name, because "shared" can mean a lot of things - like "shared
library", for example. I think that this should be set up in a manner
analogous to libpgport, except not for portability code, but instead
for other stuff. Maybe we could call it libpgframework or something.Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?"common" ?
src/backend/common
src/include/common
+1
--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Simon Riggs <simon@2ndQuadrant.com> writes:
On 6 February 2013 14:38, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?
"common" ?
src/backend/common
src/include/common
To me the term "framework" carries a lot of baggage that doesn't fit
this usage. "common" seems better.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Tom Lane escribió:
Simon Riggs <simon@2ndQuadrant.com> writes:
On 6 February 2013 14:38, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
Yeah, I am doing this right now and the "shared" name doesn't seem so
good. "libpgframework" sounds decent. So since libpgport comes from
src/port, are we okay with src/framework and src/include/framework?"common" ?
src/backend/common
src/include/commonTo me the term "framework" carries a lot of baggage that doesn't fit
this usage. "common" seems better.
Okay, here's an attempt at doing it that way. Notably this creates
libpgcommon, a static library, to be used by both frontend and backend.
There's only a frontend file now (fe_memutils.c); the backend side of it
is empty. I verified that the backend makefile rules work, but there's
no attempt to link it into the backend. libpgcommon piggybacks on
libpgport: for instance there is no separate submake-pgcommon rule on
which to depend, or LDFLAGS additions and the like, I just appended it
all to existing pgport rules. Duplicating it would be much more verbose
and pointless; if we ever need to distinguish these two libs, that can
easily be done.
Some existing pg_malloc() implementations tried to do something other
than exit(EXIT_FAILURE); pg_upgrade did pg_log(FATAL) for instance. But
I don't think there is much point in that, so I've just made them all
use fprintf(stderr); exit(EXIT_FAILURE); This is the same approach
Zoltan ended up with in his patch.
MSVC is known broken (I didn't touch Andres' hunk of that. I will look
into that later.)
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:
commonalize-palloc.patchtext/x-diff; charset=us-asciiDownload
*** a/contrib/oid2name/oid2name.c
--- b/contrib/oid2name/oid2name.c
***************
*** 9,14 ****
--- 9,16 ----
*/
#include "postgres_fe.h"
+ #include "common/fe_memutils.h"
+
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
***************
*** 50,58 **** struct options
/* function prototypes */
static void help(const char *progname);
void get_opts(int, char **, struct options *);
- void *pg_malloc(size_t size);
- void *pg_realloc(void *ptr, size_t size);
- char *pg_strdup(const char *str);
void add_one_elt(char *eltname, eary *eary);
char *get_comma_elts(eary *eary);
PGconn *sql_conn(struct options *);
--- 52,57 ----
***************
*** 201,253 **** help(const char *progname)
progname, progname);
}
- void *
- pg_malloc(size_t size)
- {
- void *ptr;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- ptr = malloc(size);
- if (!ptr)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return ptr;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- result = realloc(ptr, size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- char *
- pg_strdup(const char *str)
- {
- char *result = strdup(str);
-
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
/*
* add_one_elt
*
--- 200,205 ----
*** a/contrib/pg_upgrade/check.c
--- b/contrib/pg_upgrade/check.c
***************
*** 10,15 ****
--- 10,16 ----
#include "postgres.h"
#include "pg_upgrade.h"
+ #include "common/fe_memutils.h"
static void set_locale_and_encoding(ClusterInfo *cluster);
*** a/contrib/pg_upgrade/controldata.c
--- b/contrib/pg_upgrade/controldata.c
***************
*** 10,15 ****
--- 10,16 ----
#include "postgres.h"
#include "pg_upgrade.h"
+ #include "common/fe_memutils.h"
#include <ctype.h>
*** a/contrib/pg_upgrade/file.c
--- b/contrib/pg_upgrade/file.c
***************
*** 10,15 ****
--- 10,16 ----
#include "postgres.h"
#include "pg_upgrade.h"
+ #include "common/fe_memutils.h"
#include <fcntl.h>
*** a/contrib/pg_upgrade/function.c
--- b/contrib/pg_upgrade/function.c
***************
*** 10,15 ****
--- 10,16 ----
#include "postgres.h"
#include "pg_upgrade.h"
+ #include "common/fe_memutils.h"
#include "access/transam.h"
*** a/contrib/pg_upgrade/info.c
--- b/contrib/pg_upgrade/info.c
***************
*** 10,15 ****
--- 10,16 ----
#include "postgres.h"
#include "pg_upgrade.h"
+ #include "common/fe_memutils.h"
#include "access/transam.h"
*** a/contrib/pg_upgrade/option.c
--- b/contrib/pg_upgrade/option.c
***************
*** 9,14 ****
--- 9,15 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "miscadmin.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/pg_upgrade.c
--- b/contrib/pg_upgrade/pg_upgrade.c
***************
*** 37,42 ****
--- 37,43 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "pg_upgrade.h"
#ifdef HAVE_LANGINFO_H
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
***************
*** 451,460 **** void
prep_status(const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
void check_ok(void);
- char *pg_strdup(const char *s);
- void *pg_malloc(size_t size);
- void *pg_realloc(void *ptr, size_t size);
- void pg_free(void *ptr);
const char *getErrorText(int errNum);
unsigned int str2uint(const char *str);
void pg_putenv(const char *var, const char *val);
--- 451,456 ----
*** a/contrib/pg_upgrade/relfilenode.c
--- b/contrib/pg_upgrade/relfilenode.c
***************
*** 9,14 ****
--- 9,15 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "pg_upgrade.h"
#include "catalog/pg_class.h"
*** a/contrib/pg_upgrade/tablespace.c
--- b/contrib/pg_upgrade/tablespace.c
***************
*** 9,14 ****
--- 9,15 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "pg_upgrade.h"
static void get_tablespace_paths(void);
*** a/contrib/pg_upgrade/util.c
--- b/contrib/pg_upgrade/util.c
***************
*** 9,14 ****
--- 9,15 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "pg_upgrade.h"
#include <signal.h>
***************
*** 213,267 **** get_user_info(char **user_name)
}
- void *
- pg_malloc(size_t size)
- {
- void *p;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- p = malloc(size);
- if (p == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
- return p;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *p;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- p = realloc(ptr, size);
- if (p == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
- return p;
- }
-
-
- void
- pg_free(void *ptr)
- {
- if (ptr != NULL)
- free(ptr);
- }
-
-
- char *
- pg_strdup(const char *s)
- {
- char *result = strdup(s);
-
- if (result == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
-
- return result;
- }
-
-
/*
* getErrorText()
*
--- 214,219 ----
*** a/contrib/pg_upgrade/version_old_8_3.c
--- b/contrib/pg_upgrade/version_old_8_3.c
***************
*** 9,14 ****
--- 9,15 ----
#include "postgres.h"
+ #include "common/fe_memutils.h"
#include "pg_upgrade.h"
#include "access/transam.h"
*** a/contrib/pgbench/pgbench.c
--- b/contrib/pgbench/pgbench.c
***************
*** 33,38 ****
--- 33,39 ----
#include "postgres_fe.h"
+ #include "common/fe_memutils.h"
#include "getopt_long.h"
#include "libpq-fe.h"
#include "libpq/pqsignal.h"
***************
*** 320,378 **** static char *select_only = {
static void setalarm(int seconds);
static void *threadRun(void *arg);
-
- /*
- * routines to check mem allocations and fail noisily.
- */
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- static void *
- pg_realloc(void *ptr, size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- result = realloc(ptr, size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
-
static void
usage(void)
{
--- 321,326 ----
*** a/src/Makefile
--- b/src/Makefile
***************
*** 13,18 **** top_builddir = ..
--- 13,19 ----
include Makefile.global
SUBDIRS = \
+ common \
port \
timezone \
backend \
*** a/src/Makefile.global.in
--- b/src/Makefile.global.in
***************
*** 243,256 **** LD = @LD@
with_gnu_ld = @with_gnu_ld@
ld_R_works = @ld_R_works@
! # We want -L for libpgport.a to be first in LDFLAGS. We also need LDFLAGS
! # to be a "recursively expanded" variable, else adjustments to rpathdir
! # don't work right. So we must NOT do LDFLAGS := something, meaning this has
! # to be done first and elsewhere we must only do LDFLAGS += something.
ifdef PGXS
LDFLAGS = -L$(libdir)
else
! LDFLAGS = -L$(top_builddir)/src/port
endif
LDFLAGS += @LDFLAGS@
--- 243,257 ----
with_gnu_ld = @with_gnu_ld@
ld_R_works = @ld_R_works@
! # We want -L for libpgport.a and libpgcommon.a to be first in LDFLAGS. We
! # also need LDFLAGS to be a "recursively expanded" variable, else adjustments
! # to rpathdir don't work right. So we must NOT do LDFLAGS := something,
! # meaning this has to be done first and elsewhere we must only do LDFLAGS +=
! # something.
ifdef PGXS
LDFLAGS = -L$(libdir)
else
! LDFLAGS = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
endif
LDFLAGS += @LDFLAGS@
***************
*** 400,415 **** endif
libpq = -L$(libpq_builddir) -lpq
# This macro is for use by client executables (not libraries) that use libpq.
! # We force clients to pull symbols from the non-shared library libpgport
! # rather than pulling some libpgport symbols from libpq just because
! # libpq uses those functions too. This makes applications less
# dependent on changes in libpq's usage of pgport. To do this we link to
# pgport before libpq. This does cause duplicate -lpgport's to appear
# on client link lines.
ifdef PGXS
! libpq_pgport = -L$(libdir) -lpgport $(libpq)
else
! libpq_pgport = -L$(top_builddir)/src/port -lpgport $(libpq)
endif
--- 401,417 ----
libpq = -L$(libpq_builddir) -lpq
# This macro is for use by client executables (not libraries) that use libpq.
! # We force clients to pull symbols from the non-shared libraries libpgport
! # and libpgcommon rather than pulling some libpgport symbols from libpq just
! # because libpq uses those functions too. This makes applications less
# dependent on changes in libpq's usage of pgport. To do this we link to
# pgport before libpq. This does cause duplicate -lpgport's to appear
# on client link lines.
ifdef PGXS
! libpq_pgport = -L$(libdir) -lpgport -lpgcommon $(libpq)
else
! libpq_pgport = -L$(top_builddir)/src/port -lpgport \
! -L$(top_builddir)/src/common -lpgcommon $(libpq)
endif
***************
*** 418,423 **** submake-libpq:
--- 420,426 ----
submake-libpgport:
$(MAKE) -C $(top_builddir)/src/port all
+ $(MAKE) -C $(top_builddir)/src/common all
.PHONY: submake-libpq submake-libpgport
***************
*** 496,502 **** endif
LIBOBJS = @LIBOBJS@
! LIBS := -lpgport $(LIBS)
# to make ws2_32.lib the last library, and always link with shfolder,
# so SHGetFolderName isn't picked up from shell32.dll
--- 499,505 ----
LIBOBJS = @LIBOBJS@
! LIBS := -lpgport -lpgcommon $(LIBS)
# to make ws2_32.lib the last library, and always link with shfolder,
# so SHGetFolderName isn't picked up from shell32.dll
*** a/src/backend/storage/file/copydir.c
--- b/src/backend/storage/file/copydir.c
***************
*** 26,42 ****
#include "storage/fd.h"
#include "miscadmin.h"
- /*
- * On Windows, call non-macro versions of palloc; we can't reference
- * CurrentMemoryContext in this file because of PGDLLIMPORT conflict.
- */
- #if defined(WIN32) || defined(__CYGWIN__)
- #undef palloc
- #undef pstrdup
- #define palloc(sz) pgport_palloc(sz)
- #define pstrdup(str) pgport_pstrdup(str)
- #endif
-
static void fsync_fname(char *fname, bool isdir);
--- 26,31 ----
*** a/src/backend/utils/mmgr/mcxt.c
--- b/src/backend/utils/mmgr/mcxt.c
***************
*** 634,639 **** MemoryContextAllocZeroAligned(MemoryContext context, Size size)
--- 634,675 ----
return ret;
}
+ void *
+ palloc(Size size)
+ {
+ /* duplicates MemoryContextAlloc to avoid increased overhead */
+ AssertArg(MemoryContextIsValid(CurrentMemoryContext));
+
+ if (!AllocSizeIsValid(size))
+ elog(ERROR, "invalid memory alloc request size %lu",
+ (unsigned long) size);
+
+ CurrentMemoryContext->isReset = false;
+
+ return (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size);
+ }
+
+ void *
+ palloc0(Size size)
+ {
+ /* duplicates MemoryContextAllocZero to avoid increased overhead */
+ void *ret;
+
+ AssertArg(MemoryContextIsValid(CurrentMemoryContext));
+
+ if (!AllocSizeIsValid(size))
+ elog(ERROR, "invalid memory alloc request size %lu",
+ (unsigned long) size);
+
+ CurrentMemoryContext->isReset = false;
+
+ ret = (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size);
+
+ MemSetAligned(ret, 0, size);
+
+ return ret;
+ }
+
/*
* pfree
* Release an allocated chunk.
***************
*** 715,720 **** MemoryContextStrdup(MemoryContext context, const char *string)
--- 751,762 ----
return nstr;
}
+ char *
+ pstrdup(const char *in)
+ {
+ return MemoryContextStrdup(CurrentMemoryContext, in);
+ }
+
/*
* pnstrdup
* Like pstrdup(), but append null byte to a
***************
*** 729,767 **** pnstrdup(const char *in, Size len)
out[len] = '\0';
return out;
}
-
-
- #if defined(WIN32) || defined(__CYGWIN__)
- /*
- * Memory support routines for libpgport on Win32
- *
- * Win32 can't load a library that PGDLLIMPORTs a variable
- * if the link object files also PGDLLIMPORT the same variable.
- * For this reason, libpgport can't reference CurrentMemoryContext
- * in the palloc macro calls.
- *
- * To fix this, we create several functions here that allow us to
- * manage memory without doing the inline in libpgport.
- */
- void *
- pgport_palloc(Size sz)
- {
- return palloc(sz);
- }
-
-
- char *
- pgport_pstrdup(const char *str)
- {
- return pstrdup(str);
- }
-
-
- /* Doesn't reference a PGDLLIMPORT variable, but here for completeness. */
- void
- pgport_pfree(void *pointer)
- {
- pfree(pointer);
- }
-
- #endif
--- 771,773 ----
*** a/src/bin/initdb/initdb.c
--- b/src/bin/initdb/initdb.c
***************
*** 56,61 ****
--- 56,63 ----
#include <signal.h>
#include <time.h>
+ #include "common/fe_memutils.h"
+
#include "libpq/pqsignal.h"
#include "mb/pg_wchar.h"
#include "getaddrinfo.h"
***************
*** 200,207 **** const char *subdirs[] = {
static char bin_path[MAXPGPATH];
static char backend_exec[MAXPGPATH];
- static void *pg_malloc(size_t size);
- static char *pg_strdup(const char *s);
static char **replace_token(char **lines,
const char *token, const char *replacement);
--- 202,207 ----
***************
*** 317,359 **** do { \
#define DIR_SEP "\\"
#endif
- /*
- * routines to check mem allocations and fail noisily.
- *
- * Note that we can't call exit_nicely() on a memory failure, as it calls
- * rmtree() which needs memory allocation. So we just exit with a bang.
- */
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
static char *
escape_quotes(const char *src)
{
--- 317,322 ----
*** a/src/bin/pg_basebackup/pg_basebackup.c
--- b/src/bin/pg_basebackup/pg_basebackup.c
***************
*** 12,17 ****
--- 12,19 ----
*/
#include "postgres_fe.h"
+
+ #include "common/fe_memutils.h"
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "pgtar.h"
***************
*** 32,38 ****
#include "receivelog.h"
#include "streamutil.h"
-
/* Global options */
char *basedir = NULL;
char format = 'p'; /* p(lain)/t(ar) */
--- 34,39 ----
*** a/src/bin/pg_basebackup/pg_receivexlog.c
--- b/src/bin/pg_basebackup/pg_receivexlog.c
***************
*** 13,18 ****
--- 13,19 ----
*/
#include "postgres_fe.h"
+ #include "common/fe_memutils.h"
#include "libpq-fe.h"
#include "libpq/pqsignal.h"
#include "access/xlog_internal.h"
*** a/src/bin/pg_basebackup/receivelog.c
--- b/src/bin/pg_basebackup/receivelog.c
***************
*** 23,28 ****
--- 23,29 ----
#include "libpq-fe.h"
#include "access/xlog_internal.h"
+ #include "common/fe_memutils.h"
#include "receivelog.h"
#include "streamutil.h"
*** a/src/bin/pg_basebackup/streamutil.c
--- b/src/bin/pg_basebackup/streamutil.c
***************
*** 13,18 ****
--- 13,19 ----
#include "postgres_fe.h"
#include "streamutil.h"
+ #include "common/fe_memutils.h"
#include <stdio.h>
#include <string.h>
***************
*** 26,68 **** static char *dbpassword = NULL;
PGconn *conn = NULL;
/*
- * strdup() and malloc() replacements that print an error and exit
- * if something goes wrong. Can never return NULL.
- */
- char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- void *
- pg_malloc0(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- MemSet(result, 0, size);
- return result;
- }
-
-
- /*
* Connect to the server. Returns a valid PGconn pointer if connected,
* or NULL on non-permanent error. On permanent error, the function will
* call exit(1) directly.
--- 27,32 ----
*** a/src/bin/pg_basebackup/streamutil.h
--- b/src/bin/pg_basebackup/streamutil.h
***************
*** 15,22 **** extern PGconn *conn;
exit(code); \
}
-
- extern char *pg_strdup(const char *s);
- extern void *pg_malloc0(size_t size);
-
extern PGconn *GetConnection(void);
--- 15,18 ----
*** a/src/bin/pg_ctl/pg_ctl.c
--- b/src/bin/pg_ctl/pg_ctl.c
***************
*** 33,38 ****
--- 33,39 ----
#include <sys/resource.h>
#endif
+ #include "common/fe_memutils.h"
#include "libpq/pqsignal.h"
#include "getopt_long.h"
#include "miscadmin.h"
***************
*** 118,125 **** write_stderr(const char *fmt,...)
/* This extension allows gcc to check the format string for consistency with
the supplied arguments. */
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
- static void *pg_malloc(size_t size);
- static char *pg_strdup(const char *s);
static void do_advice(void);
static void do_help(void);
static void set_mode(char *modeopt);
--- 119,124 ----
***************
*** 226,267 **** write_stderr(const char *fmt,...)
}
/*
- * routines to check memory allocations and fail noisily.
- */
-
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- write_stderr(_("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- write_stderr(_("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- /*
* Given an already-localized string, print it to stdout unless the
* user has specified that no messages should be printed.
*/
--- 225,230 ----
*** a/src/bin/pg_dump/Makefile
--- b/src/bin/pg_dump/Makefile
***************
*** 20,26 **** override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o dumpmem.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
--- 20,26 ----
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
***************
*** 35,42 **** pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
! pg_dumpall: pg_dumpall.o dumputils.o dumpmem.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dumpall.o dumputils.o dumpmem.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
--- 35,42 ----
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
! pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
*** a/src/bin/pg_dump/common.c
--- b/src/bin/pg_dump/common.c
***************
*** 18,25 ****
#include <ctype.h>
#include "catalog/pg_class.h"
! #include "dumpmem.h"
! #include "dumputils.h"
/*
--- 18,24 ----
#include <ctype.h>
#include "catalog/pg_class.h"
! #include "common/fe_memutils.h"
/*
*** a/src/bin/pg_dump/compress_io.c
--- b/src/bin/pg_dump/compress_io.c
***************
*** 53,60 ****
*/
#include "compress_io.h"
- #include "dumpmem.h"
#include "dumputils.h"
/*----------------------
* Compressor API
--- 53,60 ----
*/
#include "compress_io.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
/*----------------------
* Compressor API
*** a/src/bin/pg_dump/dumpmem.c
--- /dev/null
***************
*** 1,76 ****
- /*-------------------------------------------------------------------------
- *
- * dumpmem.c
- * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * src/bin/pg_dump/dumpmem.c
- *
- *-------------------------------------------------------------------------
- */
- #include "postgres_fe.h"
-
- #include "dumputils.h"
- #include "dumpmem.h"
-
-
- /*
- * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out via exit();
- *therefore, their return value is guaranteed to be non-NULL.
- */
-
- char *
- pg_strdup(const char *string)
- {
- char *tmp;
-
- if (!string)
- exit_horribly(NULL, "cannot duplicate null pointer\n");
- tmp = strdup(string);
- if (!tmp)
- exit_horribly(NULL, "out of memory\n");
- 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)
- exit_horribly(NULL, "out of memory\n");
- return tmp;
- }
-
- void *
- pg_malloc0(size_t size)
- {
- void *tmp;
-
- tmp = pg_malloc(size);
- MemSet(tmp, 0, size);
- return tmp;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *tmp;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- tmp = realloc(ptr, size);
- if (!tmp)
- exit_horribly(NULL, "out of memory\n");
- return tmp;
- }
--- 0 ----
*** a/src/bin/pg_dump/dumpmem.h
--- /dev/null
***************
*** 1,22 ****
- /*-------------------------------------------------------------------------
- *
- * dumpmem.h
- * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/bin/pg_dump/dumpmem.h
- *
- *-------------------------------------------------------------------------
- */
-
- #ifndef DUMPMEM_H
- #define DUMPMEM_H
-
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
- extern void *pg_realloc(void *ptr, size_t size);
-
- #endif /* DUMPMEM_H */
--- 0 ----
*** a/src/bin/pg_dump/dumputils.c
--- b/src/bin/pg_dump/dumputils.c
***************
*** 16,23 ****
#include <ctype.h>
#include "dumputils.h"
- #include "dumpmem.h"
#include "parser/keywords.h"
--- 16,24 ----
#include <ctype.h>
+ #include "common/fe_memutils.h"
+
#include "dumputils.h"
#include "parser/keywords.h"
*** a/src/bin/pg_dump/nls.mk
--- b/src/bin/pg_dump/nls.mk
***************
*** 3,9 **** CATALOG_NAME = pg_dump
AVAIL_LANGUAGES = de es fr it ja ko pt_BR sv tr zh_CN zh_TW
GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
pg_backup_null.c pg_backup_tar.c \
! pg_backup_directory.c dumpmem.c dumputils.c compress_io.c \
pg_dump.c common.c pg_dump_sort.c \
pg_restore.c pg_dumpall.c \
../../port/exec.c
--- 3,9 ----
AVAIL_LANGUAGES = de es fr it ja ko pt_BR sv tr zh_CN zh_TW
GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
pg_backup_null.c pg_backup_tar.c \
! pg_backup_directory.c dumputils.c compress_io.c \
pg_dump.c common.c pg_dump_sort.c \
pg_restore.c pg_dumpall.c \
../../port/exec.c
*** a/src/bin/pg_dump/pg_backup_archiver.c
--- b/src/bin/pg_dump/pg_backup_archiver.c
***************
*** 21,28 ****
*/
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <ctype.h>
#include <unistd.h>
--- 21,28 ----
*/
#include "pg_backup_db.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include <ctype.h>
#include <unistd.h>
*** a/src/bin/pg_dump/pg_backup_custom.c
--- b/src/bin/pg_dump/pg_backup_custom.c
***************
*** 26,32 ****
#include "compress_io.h"
#include "dumputils.h"
! #include "dumpmem.h"
/*--------
* Routines in the format interface
--- 26,32 ----
#include "compress_io.h"
#include "dumputils.h"
! #include "common/fe_memutils.h"
/*--------
* Routines in the format interface
*** a/src/bin/pg_dump/pg_backup_db.c
--- b/src/bin/pg_dump/pg_backup_db.c
***************
*** 11,18 ****
*/
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <unistd.h>
#include <ctype.h>
--- 11,18 ----
*/
#include "pg_backup_db.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include <unistd.h>
#include <ctype.h>
*** a/src/bin/pg_dump/pg_backup_directory.c
--- b/src/bin/pg_dump/pg_backup_directory.c
***************
*** 34,41 ****
*/
#include "compress_io.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <dirent.h>
#include <sys/stat.h>
--- 34,41 ----
*/
#include "compress_io.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include <dirent.h>
#include <sys/stat.h>
*** a/src/bin/pg_dump/pg_backup_null.c
--- b/src/bin/pg_dump/pg_backup_null.c
***************
*** 23,30 ****
*/
#include "pg_backup_archiver.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <unistd.h> /* for dup */
--- 23,30 ----
*/
#include "pg_backup_archiver.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include <unistd.h> /* for dup */
*** a/src/bin/pg_dump/pg_backup_tar.c
--- b/src/bin/pg_dump/pg_backup_tar.c
***************
*** 31,38 ****
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include "pgtar.h"
#include <sys/stat.h>
--- 31,38 ----
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include "pgtar.h"
#include <sys/stat.h>
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 41,46 ****
--- 41,47 ----
#include <termios.h>
#endif
+ #include "common/fe_memutils.h"
#include "getopt_long.h"
#include "access/attnum.h"
***************
*** 59,65 ****
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
extern char *optarg;
--- 60,65 ----
*** a/src/bin/pg_dump/pg_dump_sort.c
--- b/src/bin/pg_dump/pg_dump_sort.c
***************
*** 15,21 ****
*/
#include "pg_backup_archiver.h"
#include "dumputils.h"
! #include "dumpmem.h"
/* translator: this is a module name */
static const char *modulename = gettext_noop("sorter");
--- 15,21 ----
*/
#include "pg_backup_archiver.h"
#include "dumputils.h"
! #include "common/fe_memutils.h"
/* translator: this is a module name */
static const char *modulename = gettext_noop("sorter");
*** a/src/bin/pg_dump/pg_dumpall.c
--- b/src/bin/pg_dump/pg_dumpall.c
***************
*** 25,31 ****
#include "getopt_long.h"
#include "dumputils.h"
! #include "dumpmem.h"
#include "pg_backup.h"
/* version string we expect back from pg_dump */
--- 25,31 ----
#include "getopt_long.h"
#include "dumputils.h"
! #include "common/fe_memutils.h"
#include "pg_backup.h"
/* version string we expect back from pg_dump */
*** a/src/bin/pg_dump/pg_restore.c
--- b/src/bin/pg_dump/pg_restore.c
***************
*** 41,48 ****
#include "pg_backup_archiver.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <ctype.h>
--- 41,48 ----
#include "pg_backup_archiver.h"
#include "dumputils.h"
+ #include "common/fe_memutils.h"
#include <ctype.h>
*** a/src/bin/pg_resetxlog/pg_resetxlog.c
--- b/src/bin/pg_resetxlog/pg_resetxlog.c
***************
*** 54,59 ****
--- 54,60 ----
#include "access/xlog_internal.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
+ #include "common/fe_memutils.h"
extern int optind;
extern char *optarg;
***************
*** 417,423 **** ReadControlFile(void)
}
/* Use malloc to ensure we have a maxaligned buffer */
! buffer = (char *) malloc(PG_CONTROL_SIZE);
len = read(fd, buffer, PG_CONTROL_SIZE);
if (len < 0)
--- 418,424 ----
}
/* Use malloc to ensure we have a maxaligned buffer */
! buffer = (char *) pg_malloc(PG_CONTROL_SIZE);
len = read(fd, buffer, PG_CONTROL_SIZE);
if (len < 0)
***************
*** 937,943 **** WriteEmptyXLOG(void)
int nbytes;
/* Use malloc() to ensure buffer is MAXALIGNED */
! buffer = (char *) malloc(XLOG_BLCKSZ);
page = (XLogPageHeader) buffer;
memset(buffer, 0, XLOG_BLCKSZ);
--- 938,944 ----
int nbytes;
/* Use malloc() to ensure buffer is MAXALIGNED */
! buffer = (char *) pg_malloc(XLOG_BLCKSZ);
page = (XLogPageHeader) buffer;
memset(buffer, 0, XLOG_BLCKSZ);
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
***************
*** 33,38 ****
--- 33,39 ----
#include <openssl/ssl.h>
#endif
+ #include "common/fe_memutils.h"
#include "portability/instr_time.h"
#include "libpq-fe.h"
*** a/src/bin/psql/common.c
--- b/src/bin/psql/common.c
***************
*** 17,22 ****
--- 17,23 ----
#include <win32.h>
#endif
+ #include "common/fe_memutils.h"
#include "portability/instr_time.h"
#include "pqsignal.h"
***************
*** 33,88 **** static bool command_no_begin(const char *query);
static bool is_select_command(const char *query);
/*
- * "Safe" wrapper around strdup()
- */
- char *
- pg_strdup(const char *string)
- {
- char *tmp;
-
- if (!string)
- {
- psql_error("%s: pg_strdup: cannot duplicate null pointer (internal error)\n",
- pset.progname);
- exit(EXIT_FAILURE);
- }
- tmp = strdup(string);
- if (!tmp)
- {
- psql_error("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)
- {
- psql_error("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;
- }
-
- /*
* setQFout
* -- handler for -o command line option and \o command
*
--- 34,39 ----
*** a/src/bin/psql/common.h
--- b/src/bin/psql/common.h
***************
*** 14,28 ****
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
- /*
- * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out
- * safely; therefore, their return value is guaranteed to be non-NULL.
- */
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
-
extern bool setQFout(const char *fname);
extern void
--- 14,19 ----
*** a/src/bin/psql/copy.c
--- b/src/bin/psql/copy.c
***************
*** 16,21 ****
--- 16,23 ----
#include <io.h> /* I think */
#endif
+ #include "common/fe_memutils.h"
+
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "pqsignal.h"
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
***************
*** 14,19 ****
--- 14,21 ----
#include <ctype.h>
+ #include "common/fe_memutils.h"
+
#include "catalog/pg_default_acl.h"
#include "common.h"
*** a/src/bin/psql/input.c
--- b/src/bin/psql/input.c
***************
*** 12,17 ****
--- 12,19 ----
#endif
#include <fcntl.h>
+ #include "common/fe_memutils.h"
+
#include "input.h"
#include "settings.h"
#include "tab-complete.h"
*** a/src/bin/psql/mainloop.c
--- b/src/bin/psql/mainloop.c
***************
*** 8,13 ****
--- 8,14 ----
#include "postgres_fe.h"
#include "mainloop.h"
+ #include "common/fe_memutils.h"
#include "command.h"
#include "common.h"
*** a/src/bin/psql/print.c
--- b/src/bin/psql/print.c
***************
*** 22,27 ****
--- 22,29 ----
#include <locale.h>
+ #include "common/fe_memutils.h"
+
#include "catalog/pg_type.h"
#include "pqsignal.h"
*** a/src/bin/psql/prompt.c
--- b/src/bin/psql/prompt.c
***************
*** 17,22 ****
--- 17,24 ----
#include <netdb.h>
#endif
+ #include "common/fe_memutils.h"
+
#include "common.h"
#include "input.h"
#include "prompt.h"
*** a/src/bin/psql/startup.c
--- b/src/bin/psql/startup.c
***************
*** 16,21 ****
--- 16,22 ----
#include <win32.h>
#endif /* WIN32 */
+ #include "common/fe_memutils.h"
#include "getopt_long.h"
#include <locale.h>
*** a/src/bin/psql/stringutils.c
--- b/src/bin/psql/stringutils.c
***************
*** 9,14 ****
--- 9,16 ----
#include <ctype.h>
+ #include "common/fe_memutils.h"
+
#include "common.h"
#include "stringutils.h"
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
***************
*** 45,50 ****
--- 45,52 ----
#include "tab-complete.h"
#include "input.h"
+ #include "common/fe_memutils.h"
+
/* If we don't have this, we might as well forget about the whole thing: */
#ifdef USE_READLINE
*** a/src/bin/psql/variables.c
--- b/src/bin/psql/variables.c
***************
*** 7,12 ****
--- 7,14 ----
*/
#include "postgres_fe.h"
+ #include "common/fe_memutils.h"
+
#include "common.h"
#include "variables.h"
*** a/src/bin/scripts/common.c
--- b/src/bin/scripts/common.c
***************
*** 278,332 **** 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.
*/
--- 278,283 ----
*** a/src/bin/scripts/common.h
--- b/src/bin/scripts/common.h
***************
*** 12,17 ****
--- 12,18 ----
#include "libpq-fe.h"
#include "getopt_long.h" /* pgrminclude ignore */
#include "pqexpbuffer.h" /* pgrminclude ignore */
+ #include "common/fe_memutils.h"
enum trivalue
{
***************
*** 50,57 **** extern bool yesno_prompt(const char *question);
extern void setup_cancel_handler(void);
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
-
#endif /* COMMON_H */
--- 51,54 ----
*** /dev/null
--- b/src/common/Makefile
***************
*** 0 ****
--- 1,64 ----
+ #-------------------------------------------------------------------------
+ #
+ # Makefile
+ # Makefile for src/common
+ #
+ # This makefile generates two outputs:
+ #
+ # libpgcommon.a - contains object files with FRONTEND defined,
+ # for use by client application and libraries
+ #
+ # libpgcommon_srv.a - contains object files without FRONTEND defined,
+ # for use only by the backend binaries
+ #
+ # IDENTIFICATION
+ # src/common/Makefile
+ #
+ #-------------------------------------------------------------------------
+
+ subdir = src/common
+ top_builddir = ../..
+ include $(top_builddir)/src/Makefile.global
+
+ override CPPFLAGS := -DFRONTEND $(CPPFLAGS)
+ LIBS += $(PTHREAD_LIBS)
+
+ OBJS_COMMON =
+
+ OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o
+
+ OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
+
+ all: libpgcommon.a libpgcommon_srv.a
+
+ # libpgcommon is needed by some contrib
+ install: all installdirs
+ $(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
+
+ installdirs:
+ $(MKDIR_P) '$(DESTDIR)$(libdir)'
+
+ uninstall:
+ rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
+
+ libpgcommon.a: $(OBJS_FRONTEND)
+ $(AR) $(AROPT) $@ $^
+
+ #
+ # Server versions of object files
+ #
+
+ libpgcommon_srv.a: $(OBJS_SRV)
+ $(AR) $(AROPT) $@ $^
+
+ # Because this uses its own compilation rule, it doesn't use the
+ # dependency tracking logic from Makefile.global. To make sure that
+ # dependency tracking works anyway for the *_srv.o files, depend on
+ # their *.o siblings as well, which do have proper dependencies. It's
+ # a hack that might fail someday if there is a *_srv.o without a
+ # corresponding *.o, but it works for now.
+ %_srv.o: %.c %.o
+ $(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
+
+ clean distclean maintainer-clean:
+ rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND) $(OBJS_SRV)
*** /dev/null
--- b/src/common/fe_memutils.c
***************
*** 0 ****
--- 1,131 ----
+ /*-------------------------------------------------------------------------
+ *
+ * fe_memutils.c
+ * memory management support for frontend code
+ *
+ * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/common/fe_memutils.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ #ifndef FRONTEND
+ #error "This file is not expected to be compiled for backend code"
+ #endif
+
+ #include "postgres_fe.h"
+
+ #include "common/fe_memutils.h"
+ #include "utils/palloc.h"
+
+ 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;
+ }
+
+ void *
+ pg_realloc(void *ptr, size_t size)
+ {
+ void *tmp;
+
+ /* Avoid unportable behavior of realloc(NULL, 0) */
+ if (ptr == NULL && size == 0)
+ size = 1;
+ tmp = realloc(ptr, size);
+ if (!tmp)
+ {
+ fprintf(stderr, _("out of memory\n"));
+ exit(EXIT_FAILURE);
+ }
+ return tmp;
+ }
+
+ /*
+ * "Safe" wrapper around strdup().
+ */
+ char *
+ pg_strdup(const char *string)
+ {
+ char *tmp;
+
+ if (!string)
+ {
+ fprintf(stderr,
+ _("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_free(void *ptr)
+ {
+ if (ptr != NULL)
+ free(ptr);
+ }
+
+ /*
+ * Frontend emulation of backend memory management functions. Useful for
+ * programs that compile backend files.
+ */
+ void *
+ palloc(Size size)
+ {
+ return pg_malloc(size);
+ }
+
+ void *
+ palloc0(Size size)
+ {
+ return pg_malloc0(size);
+ }
+
+ void
+ pfree(void *pointer)
+ {
+ pg_free(pointer);
+ }
+
+ char *
+ pstrdup(const char *string)
+ {
+ return pg_strdup(string);
+ }
+
+ void *
+ repalloc(void *pointer, Size size)
+ {
+ return pg_realloc(pointer, size);
+ }
*** /dev/null
--- b/src/include/common/fe_memutils.h
***************
*** 0 ****
--- 1,28 ----
+ /*
+ * fe_memutils.h
+ * memory management support for frontend code
+ *
+ * Copyright (c) 2003-2013, PostgreSQL Global Development Group
+ *
+ * src/include/common/fe_memutils.h
+ */
+ #ifndef FE_MEMUTILS_H
+ #define FE_MEMUTILS_H
+
+ extern char *pg_strdup(const char *string);
+ 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);
+
+ #ifdef FRONTEND_PALLOC_EMULATION
+ #ifndef FRONTEND
+ #error FRONTEND must be defined for FRONTEND_PALLOC_EMULATION
+ #endif /* !FRONTEND */
+
+ #include "utils/palloc.h"
+
+ #endif
+
+
+ #endif /* FE_MEMUTILS_H */
*** a/src/include/utils/palloc.h
--- b/src/include/utils/palloc.h
***************
*** 28,33 ****
--- 28,35 ----
#ifndef PALLOC_H
#define PALLOC_H
+ #ifndef FRONTEND
+
/*
* Type MemoryContextData is declared in nodes/memnodes.h. Most users
* of memory allocation should just treat it as an abstract type, so we
***************
*** 49,58 **** extern void *MemoryContextAlloc(MemoryContext context, Size size);
extern void *MemoryContextAllocZero(MemoryContext context, Size size);
extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
- #define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
-
- #define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
-
/*
* The result of palloc() is always word-aligned, so we can skip testing
* alignment of the pointer when deciding which MemSet variant to use.
--- 51,56 ----
***************
*** 66,85 **** extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
MemoryContextAllocZero(CurrentMemoryContext, sz) )
- extern void pfree(void *pointer);
-
- extern void *repalloc(void *pointer, Size size);
-
/*
* MemoryContextSwitchTo can't be a macro in standard C compilers.
* But we can make it an inline function if the compiler supports it.
* See STATIC_IF_INLINE in c.h.
- *
- * This file has to be includable by some non-backend code such as
- * pg_resetxlog, so don't expose the CurrentMemoryContext reference
- * if FRONTEND is defined.
*/
- #ifndef FRONTEND
#ifndef PG_USE_INLINE
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
--- 64,74 ----
***************
*** 94,115 **** MemoryContextSwitchTo(MemoryContext context)
return old;
}
#endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */
- #endif /* !FRONTEND */
/*
* These are like standard strdup() except the copied string is
* allocated in a context, not with malloc().
*/
extern char *MemoryContextStrdup(MemoryContext context, const char *string);
! #define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
!
extern char *pnstrdup(const char *in, Size len);
!
! #if defined(WIN32) || defined(__CYGWIN__)
! extern void *pgport_palloc(Size sz);
! extern char *pgport_pstrdup(const char *str);
! extern void pgport_pfree(void *pointer);
! #endif
#endif /* PALLOC_H */
--- 83,101 ----
return old;
}
#endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */
/*
* These are like standard strdup() except the copied string is
* allocated in a context, not with malloc().
*/
extern char *MemoryContextStrdup(MemoryContext context, const char *string);
+ #endif /* !FRONTEND */
! extern char *pstrdup(const char *in);
extern char *pnstrdup(const char *in, Size len);
! extern void *palloc(Size size);
! extern void *palloc0(Size size);
! extern void pfree(void *pointer);
! extern void *repalloc(void *pointer, Size size);
#endif /* PALLOC_H */
*** a/src/port/dirmod.c
--- b/src/port/dirmod.c
***************
*** 19,24 ****
--- 19,25 ----
#include "postgres.h"
#else
#include "postgres_fe.h"
+ #include "utils/palloc.h"
#endif
/* Don't modify declarations in system headers */
***************
*** 40,119 ****
#endif
#endif
-
- #ifndef FRONTEND
-
- /*
- * On Windows, call non-macro versions of palloc; we can't reference
- * CurrentMemoryContext in this file because of PGDLLIMPORT conflict.
- */
- #if defined(WIN32) || defined(__CYGWIN__)
- #undef palloc
- #undef pstrdup
- #define palloc(sz) pgport_palloc(sz)
- #define pstrdup(str) pgport_pstrdup(str)
- #endif
- #else /* FRONTEND */
-
- /*
- * In frontend, fake palloc behavior with these
- */
- #undef palloc
- #undef pstrdup
- #define palloc(sz) fe_palloc(sz)
- #define pstrdup(str) fe_pstrdup(str)
- #define repalloc(pointer,sz) fe_repalloc(pointer,sz)
- #define pfree(pointer) free(pointer)
-
- static void *
- fe_palloc(Size size)
- {
- void *res;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- res = malloc(size);
- if (res == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
-
- static char *
- fe_pstrdup(const char *string)
- {
- char *res;
-
- if ((res = strdup(string)) == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
-
- static void *
- fe_repalloc(void *pointer, Size size)
- {
- void *res;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (pointer == NULL && size == 0)
- size = 1;
- res = realloc(pointer, size);
- if (res == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
- #endif /* FRONTEND */
-
-
#if defined(WIN32) || defined(__CYGWIN__)
/*
--- 41,46 ----
*** a/src/tools/msvc/Mkvcbuild.pm
--- b/src/tools/msvc/Mkvcbuild.pm
***************
*** 63,71 **** sub mkvcbuild
--- 63,74 ----
sprompt.c tar.c thread.c getopt.c getopt_long.c dirent.c rint.c win32env.c
win32error.c win32setlocale.c);
+ our @pgportfrontend = qw(palloc.c);
+
$libpgport = $solution->AddProject('libpgport', 'lib', 'misc');
$libpgport->AddDefine('FRONTEND');
$libpgport->AddFiles('src\port', @pgportfiles);
+ $libpgport->AddFiles('src\port', @pgportfrontend);
$postgres = $solution->AddProject('postgres', 'exe', '', 'src\backend');
$postgres->AddIncludeDir('src\backend');
***************
*** 393,399 **** sub mkvcbuild
$pgdumpall->AddIncludeDir('src\backend');
$pgdumpall->AddFile('src\bin\pg_dump\pg_dumpall.c');
$pgdumpall->AddFile('src\bin\pg_dump\dumputils.c');
- $pgdumpall->AddFile('src\bin\pg_dump\dumpmem.c');
$pgdumpall->AddFile('src\bin\pg_dump\keywords.c');
$pgdumpall->AddFile('src\backend\parser\kwlookup.c');
--- 396,401 ----
On 2013-02-06 15:51:15 -0300, Alvaro Herrera wrote:
Okay, here's an attempt at doing it that way. Notably this creates
libpgcommon, a static library, to be used by both frontend and backend.
There's only a frontend file now (fe_memutils.c); the backend side of it
is empty. I verified that the backend makefile rules work, but there's
no attempt to link it into the backend. libpgcommon piggybacks on
libpgport: for instance there is no separate submake-pgcommon rule on
which to depend, or LDFLAGS additions and the like, I just appended it
all to existing pgport rules. Duplicating it would be much more verbose
and pointless; if we ever need to distinguish these two libs, that can
easily be done.
Looks good to me.
Although I have to admit I am wondering whether there still is a point
in using pg_malloc() et al. instead of just using palloc() et al. There
doesn't seem to be too much gained by that. But thats probably better
done as another patch ontop of this if at all.
Some existing pg_malloc() implementations tried to do something other
than exit(EXIT_FAILURE); pg_upgrade did pg_log(FATAL) for instance. But
I don't think there is much point in that, so I've just made them all
use fprintf(stderr); exit(EXIT_FAILURE); This is the same approach
Zoltan ended up with in his patch.
If anything it should be plain write()s, as that wouldn't allocate
memory... But otherwise I aggree.
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Here's a more finalized version of this. There are two main interesting
changes here:
1. postgres_fe.h includes common/fe_memutils.h
This means all frontend programs get the #include without having to
do it explicitely by themselves. postgres.h includes utils/palloc.h
which I used as precendent for this.
2. fe_memutils.h includes utils/palloc.h
This means all frontend programs get the palloc() et al prototypes.
Some other things of note:
a. pg_upgrade was using postgres.h all over the place instead of
postgres_fe.h. There's no reason for this AFAICS so I changed it.
No warnings, make check passes.
b. pg_resetxlog is the only frontend place that uses pg_malloc() and
which needs to #include postgres.h instead of postgres_fe.h, so it's
the only place that needs to include fe_memutils.h directly.
(pg_controldata is the other place that includes postgres.h, but it
doesn't need the pg_malloc etc declarations).
c. I added the MSVC bits. I tested that most of it works, but the
various regress executables as well as zic failed to build due to
lack of libpgcommon at link time. I think I fixed it; I'm waiting on
new tests to run. (This patch is the fixed version).
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:
commonalize-palloc-2.patchtext/x-diff; charset=us-asciiDownload
*** a/contrib/oid2name/oid2name.c
--- b/contrib/oid2name/oid2name.c
***************
*** 50,58 **** struct options
/* function prototypes */
static void help(const char *progname);
void get_opts(int, char **, struct options *);
- void *pg_malloc(size_t size);
- void *pg_realloc(void *ptr, size_t size);
- char *pg_strdup(const char *str);
void add_one_elt(char *eltname, eary *eary);
char *get_comma_elts(eary *eary);
PGconn *sql_conn(struct options *);
--- 50,55 ----
***************
*** 201,253 **** help(const char *progname)
progname, progname);
}
- void *
- pg_malloc(size_t size)
- {
- void *ptr;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- ptr = malloc(size);
- if (!ptr)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return ptr;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- result = realloc(ptr, size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- char *
- pg_strdup(const char *str)
- {
- char *result = strdup(str);
-
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
/*
* add_one_elt
*
--- 198,203 ----
*** a/contrib/pg_upgrade/check.c
--- b/contrib/pg_upgrade/check.c
***************
*** 7,13 ****
* contrib/pg_upgrade/check.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/check.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/controldata.c
--- b/contrib/pg_upgrade/controldata.c
***************
*** 7,13 ****
* contrib/pg_upgrade/controldata.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/controldata.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/dump.c
--- b/contrib/pg_upgrade/dump.c
***************
*** 7,13 ****
* contrib/pg_upgrade/dump.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/dump.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/exec.c
--- b/contrib/pg_upgrade/exec.c
***************
*** 7,13 ****
* contrib/pg_upgrade/exec.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/exec.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/file.c
--- b/contrib/pg_upgrade/file.c
***************
*** 7,13 ****
* contrib/pg_upgrade/file.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/file.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/function.c
--- b/contrib/pg_upgrade/function.c
***************
*** 7,13 ****
* contrib/pg_upgrade/function.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/function.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/info.c
--- b/contrib/pg_upgrade/info.c
***************
*** 7,13 ****
* contrib/pg_upgrade/info.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/info.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/option.c
--- b/contrib/pg_upgrade/option.c
***************
*** 7,13 ****
* contrib/pg_upgrade/option.c
*/
! #include "postgres.h"
#include "miscadmin.h"
--- 7,13 ----
* contrib/pg_upgrade/option.c
*/
! #include "postgres_fe.h"
#include "miscadmin.h"
*** a/contrib/pg_upgrade/page.c
--- b/contrib/pg_upgrade/page.c
***************
*** 7,13 ****
* contrib/pg_upgrade/page.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/page.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/parallel.c
--- b/contrib/pg_upgrade/parallel.c
***************
*** 7,13 ****
* contrib/pg_upgrade/parallel.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/parallel.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/pg_upgrade.c
--- b/contrib/pg_upgrade/pg_upgrade.c
***************
*** 35,41 ****
! #include "postgres.h"
#include "pg_upgrade.h"
--- 35,41 ----
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
***************
*** 451,460 **** void
prep_status(const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
void check_ok(void);
- char *pg_strdup(const char *s);
- void *pg_malloc(size_t size);
- void *pg_realloc(void *ptr, size_t size);
- void pg_free(void *ptr);
const char *getErrorText(int errNum);
unsigned int str2uint(const char *str);
void pg_putenv(const char *var, const char *val);
--- 451,456 ----
*** a/contrib/pg_upgrade/relfilenode.c
--- b/contrib/pg_upgrade/relfilenode.c
***************
*** 7,13 ****
* contrib/pg_upgrade/relfilenode.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/relfilenode.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/server.c
--- b/contrib/pg_upgrade/server.c
***************
*** 7,13 ****
* contrib/pg_upgrade/server.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/server.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/tablespace.c
--- b/contrib/pg_upgrade/tablespace.c
***************
*** 7,13 ****
* contrib/pg_upgrade/tablespace.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/tablespace.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/util.c
--- b/contrib/pg_upgrade/util.c
***************
*** 7,13 ****
* contrib/pg_upgrade/util.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/util.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
***************
*** 213,267 **** get_user_info(char **user_name)
}
- void *
- pg_malloc(size_t size)
- {
- void *p;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- p = malloc(size);
- if (p == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
- return p;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *p;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- p = realloc(ptr, size);
- if (p == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
- return p;
- }
-
-
- void
- pg_free(void *ptr)
- {
- if (ptr != NULL)
- free(ptr);
- }
-
-
- char *
- pg_strdup(const char *s)
- {
- char *result = strdup(s);
-
- if (result == NULL)
- pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
-
- return result;
- }
-
-
/*
* getErrorText()
*
--- 213,218 ----
*** a/contrib/pg_upgrade/version.c
--- b/contrib/pg_upgrade/version.c
***************
*** 7,13 ****
* contrib/pg_upgrade/version.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/version.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pg_upgrade/version_old_8_3.c
--- b/contrib/pg_upgrade/version_old_8_3.c
***************
*** 7,13 ****
* contrib/pg_upgrade/version_old_8_3.c
*/
! #include "postgres.h"
#include "pg_upgrade.h"
--- 7,13 ----
* contrib/pg_upgrade/version_old_8_3.c
*/
! #include "postgres_fe.h"
#include "pg_upgrade.h"
*** a/contrib/pgbench/pgbench.c
--- b/contrib/pgbench/pgbench.c
***************
*** 320,378 **** static char *select_only = {
static void setalarm(int seconds);
static void *threadRun(void *arg);
-
- /*
- * routines to check mem allocations and fail noisily.
- */
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- static void *
- pg_realloc(void *ptr, size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- result = realloc(ptr, size);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- return result;
- }
-
-
static void
usage(void)
{
--- 320,325 ----
*** a/src/Makefile
--- b/src/Makefile
***************
*** 13,18 **** top_builddir = ..
--- 13,19 ----
include Makefile.global
SUBDIRS = \
+ common \
port \
timezone \
backend \
*** a/src/Makefile.global.in
--- b/src/Makefile.global.in
***************
*** 243,256 **** LD = @LD@
with_gnu_ld = @with_gnu_ld@
ld_R_works = @ld_R_works@
! # We want -L for libpgport.a to be first in LDFLAGS. We also need LDFLAGS
! # to be a "recursively expanded" variable, else adjustments to rpathdir
! # don't work right. So we must NOT do LDFLAGS := something, meaning this has
! # to be done first and elsewhere we must only do LDFLAGS += something.
ifdef PGXS
LDFLAGS = -L$(libdir)
else
! LDFLAGS = -L$(top_builddir)/src/port
endif
LDFLAGS += @LDFLAGS@
--- 243,257 ----
with_gnu_ld = @with_gnu_ld@
ld_R_works = @ld_R_works@
! # We want -L for libpgport.a and libpgcommon.a to be first in LDFLAGS. We
! # also need LDFLAGS to be a "recursively expanded" variable, else adjustments
! # to rpathdir don't work right. So we must NOT do LDFLAGS := something,
! # meaning this has to be done first and elsewhere we must only do LDFLAGS +=
! # something.
ifdef PGXS
LDFLAGS = -L$(libdir)
else
! LDFLAGS = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
endif
LDFLAGS += @LDFLAGS@
***************
*** 400,415 **** endif
libpq = -L$(libpq_builddir) -lpq
# This macro is for use by client executables (not libraries) that use libpq.
! # We force clients to pull symbols from the non-shared library libpgport
! # rather than pulling some libpgport symbols from libpq just because
! # libpq uses those functions too. This makes applications less
# dependent on changes in libpq's usage of pgport. To do this we link to
# pgport before libpq. This does cause duplicate -lpgport's to appear
# on client link lines.
ifdef PGXS
! libpq_pgport = -L$(libdir) -lpgport $(libpq)
else
! libpq_pgport = -L$(top_builddir)/src/port -lpgport $(libpq)
endif
--- 401,417 ----
libpq = -L$(libpq_builddir) -lpq
# This macro is for use by client executables (not libraries) that use libpq.
! # We force clients to pull symbols from the non-shared libraries libpgport
! # and libpgcommon rather than pulling some libpgport symbols from libpq just
! # because libpq uses those functions too. This makes applications less
# dependent on changes in libpq's usage of pgport. To do this we link to
# pgport before libpq. This does cause duplicate -lpgport's to appear
# on client link lines.
ifdef PGXS
! libpq_pgport = -L$(libdir) -lpgport -lpgcommon $(libpq)
else
! libpq_pgport = -L$(top_builddir)/src/port -lpgport \
! -L$(top_builddir)/src/common -lpgcommon $(libpq)
endif
***************
*** 418,423 **** submake-libpq:
--- 420,426 ----
submake-libpgport:
$(MAKE) -C $(top_builddir)/src/port all
+ $(MAKE) -C $(top_builddir)/src/common all
.PHONY: submake-libpq submake-libpgport
***************
*** 496,502 **** endif
LIBOBJS = @LIBOBJS@
! LIBS := -lpgport $(LIBS)
# to make ws2_32.lib the last library, and always link with shfolder,
# so SHGetFolderName isn't picked up from shell32.dll
--- 499,505 ----
LIBOBJS = @LIBOBJS@
! LIBS := -lpgport -lpgcommon $(LIBS)
# to make ws2_32.lib the last library, and always link with shfolder,
# so SHGetFolderName isn't picked up from shell32.dll
*** a/src/backend/storage/file/copydir.c
--- b/src/backend/storage/file/copydir.c
***************
*** 26,42 ****
#include "storage/fd.h"
#include "miscadmin.h"
- /*
- * On Windows, call non-macro versions of palloc; we can't reference
- * CurrentMemoryContext in this file because of PGDLLIMPORT conflict.
- */
- #if defined(WIN32) || defined(__CYGWIN__)
- #undef palloc
- #undef pstrdup
- #define palloc(sz) pgport_palloc(sz)
- #define pstrdup(str) pgport_pstrdup(str)
- #endif
-
static void fsync_fname(char *fname, bool isdir);
--- 26,31 ----
*** a/src/backend/utils/mmgr/mcxt.c
--- b/src/backend/utils/mmgr/mcxt.c
***************
*** 634,639 **** MemoryContextAllocZeroAligned(MemoryContext context, Size size)
--- 634,675 ----
return ret;
}
+ void *
+ palloc(Size size)
+ {
+ /* duplicates MemoryContextAlloc to avoid increased overhead */
+ AssertArg(MemoryContextIsValid(CurrentMemoryContext));
+
+ if (!AllocSizeIsValid(size))
+ elog(ERROR, "invalid memory alloc request size %lu",
+ (unsigned long) size);
+
+ CurrentMemoryContext->isReset = false;
+
+ return (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size);
+ }
+
+ void *
+ palloc0(Size size)
+ {
+ /* duplicates MemoryContextAllocZero to avoid increased overhead */
+ void *ret;
+
+ AssertArg(MemoryContextIsValid(CurrentMemoryContext));
+
+ if (!AllocSizeIsValid(size))
+ elog(ERROR, "invalid memory alloc request size %lu",
+ (unsigned long) size);
+
+ CurrentMemoryContext->isReset = false;
+
+ ret = (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size);
+
+ MemSetAligned(ret, 0, size);
+
+ return ret;
+ }
+
/*
* pfree
* Release an allocated chunk.
***************
*** 715,720 **** MemoryContextStrdup(MemoryContext context, const char *string)
--- 751,762 ----
return nstr;
}
+ char *
+ pstrdup(const char *in)
+ {
+ return MemoryContextStrdup(CurrentMemoryContext, in);
+ }
+
/*
* pnstrdup
* Like pstrdup(), but append null byte to a
***************
*** 729,767 **** pnstrdup(const char *in, Size len)
out[len] = '\0';
return out;
}
-
-
- #if defined(WIN32) || defined(__CYGWIN__)
- /*
- * Memory support routines for libpgport on Win32
- *
- * Win32 can't load a library that PGDLLIMPORTs a variable
- * if the link object files also PGDLLIMPORT the same variable.
- * For this reason, libpgport can't reference CurrentMemoryContext
- * in the palloc macro calls.
- *
- * To fix this, we create several functions here that allow us to
- * manage memory without doing the inline in libpgport.
- */
- void *
- pgport_palloc(Size sz)
- {
- return palloc(sz);
- }
-
-
- char *
- pgport_pstrdup(const char *str)
- {
- return pstrdup(str);
- }
-
-
- /* Doesn't reference a PGDLLIMPORT variable, but here for completeness. */
- void
- pgport_pfree(void *pointer)
- {
- pfree(pointer);
- }
-
- #endif
--- 771,773 ----
*** a/src/bin/initdb/initdb.c
--- b/src/bin/initdb/initdb.c
***************
*** 200,207 **** const char *subdirs[] = {
static char bin_path[MAXPGPATH];
static char backend_exec[MAXPGPATH];
- static void *pg_malloc(size_t size);
- static char *pg_strdup(const char *s);
static char **replace_token(char **lines,
const char *token, const char *replacement);
--- 200,205 ----
***************
*** 317,359 **** do { \
#define DIR_SEP "\\"
#endif
- /*
- * routines to check mem allocations and fail noisily.
- *
- * Note that we can't call exit_nicely() on a memory failure, as it calls
- * rmtree() which needs memory allocation. So we just exit with a bang.
- */
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
static char *
escape_quotes(const char *src)
{
--- 315,320 ----
*** a/src/bin/pg_basebackup/streamutil.c
--- b/src/bin/pg_basebackup/streamutil.c
***************
*** 26,68 **** static char *dbpassword = NULL;
PGconn *conn = NULL;
/*
- * strdup() and malloc() replacements that print an error and exit
- * if something goes wrong. Can never return NULL.
- */
- char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- void *
- pg_malloc0(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- fprintf(stderr, _("%s: out of memory\n"), progname);
- exit(1);
- }
- MemSet(result, 0, size);
- return result;
- }
-
-
- /*
* Connect to the server. Returns a valid PGconn pointer if connected,
* or NULL on non-permanent error. On permanent error, the function will
* call exit(1) directly.
--- 26,31 ----
*** a/src/bin/pg_basebackup/streamutil.h
--- b/src/bin/pg_basebackup/streamutil.h
***************
*** 15,22 **** extern PGconn *conn;
exit(code); \
}
-
- extern char *pg_strdup(const char *s);
- extern void *pg_malloc0(size_t size);
-
extern PGconn *GetConnection(void);
--- 15,18 ----
*** a/src/bin/pg_ctl/pg_ctl.c
--- b/src/bin/pg_ctl/pg_ctl.c
***************
*** 118,125 **** write_stderr(const char *fmt,...)
/* This extension allows gcc to check the format string for consistency with
the supplied arguments. */
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
- static void *pg_malloc(size_t size);
- static char *pg_strdup(const char *s);
static void do_advice(void);
static void do_help(void);
static void set_mode(char *modeopt);
--- 118,123 ----
***************
*** 226,267 **** write_stderr(const char *fmt,...)
}
/*
- * routines to check memory allocations and fail noisily.
- */
-
- static void *
- pg_malloc(size_t size)
- {
- void *result;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- result = malloc(size);
- if (!result)
- {
- write_stderr(_("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
-
- static char *
- pg_strdup(const char *s)
- {
- char *result;
-
- result = strdup(s);
- if (!result)
- {
- write_stderr(_("%s: out of memory\n"), progname);
- exit(1);
- }
- return result;
- }
-
- /*
* Given an already-localized string, print it to stdout unless the
* user has specified that no messages should be printed.
*/
--- 224,229 ----
*** a/src/bin/pg_dump/Makefile
--- b/src/bin/pg_dump/Makefile
***************
*** 20,26 **** override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o dumpmem.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
--- 20,26 ----
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_null.o pg_backup_tar.o \
! pg_backup_directory.o dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o
***************
*** 35,42 **** pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
! pg_dumpall: pg_dumpall.o dumputils.o dumpmem.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dumpall.o dumputils.o dumpmem.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
--- 35,42 ----
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
! pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
! $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
*** a/src/bin/pg_dump/common.c
--- b/src/bin/pg_dump/common.c
***************
*** 18,25 ****
#include <ctype.h>
#include "catalog/pg_class.h"
- #include "dumpmem.h"
- #include "dumputils.h"
/*
--- 18,23 ----
*** a/src/bin/pg_dump/compress_io.c
--- b/src/bin/pg_dump/compress_io.c
***************
*** 53,59 ****
*/
#include "compress_io.h"
- #include "dumpmem.h"
#include "dumputils.h"
/*----------------------
--- 53,58 ----
*** a/src/bin/pg_dump/dumpmem.c
--- /dev/null
***************
*** 1,76 ****
- /*-------------------------------------------------------------------------
- *
- * dumpmem.c
- * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * src/bin/pg_dump/dumpmem.c
- *
- *-------------------------------------------------------------------------
- */
- #include "postgres_fe.h"
-
- #include "dumputils.h"
- #include "dumpmem.h"
-
-
- /*
- * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out via exit();
- *therefore, their return value is guaranteed to be non-NULL.
- */
-
- char *
- pg_strdup(const char *string)
- {
- char *tmp;
-
- if (!string)
- exit_horribly(NULL, "cannot duplicate null pointer\n");
- tmp = strdup(string);
- if (!tmp)
- exit_horribly(NULL, "out of memory\n");
- 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)
- exit_horribly(NULL, "out of memory\n");
- return tmp;
- }
-
- void *
- pg_malloc0(size_t size)
- {
- void *tmp;
-
- tmp = pg_malloc(size);
- MemSet(tmp, 0, size);
- return tmp;
- }
-
- void *
- pg_realloc(void *ptr, size_t size)
- {
- void *tmp;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (ptr == NULL && size == 0)
- size = 1;
- tmp = realloc(ptr, size);
- if (!tmp)
- exit_horribly(NULL, "out of memory\n");
- return tmp;
- }
--- 0 ----
*** a/src/bin/pg_dump/dumpmem.h
--- /dev/null
***************
*** 1,22 ****
- /*-------------------------------------------------------------------------
- *
- * dumpmem.h
- * Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/bin/pg_dump/dumpmem.h
- *
- *-------------------------------------------------------------------------
- */
-
- #ifndef DUMPMEM_H
- #define DUMPMEM_H
-
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
- extern void *pg_realloc(void *ptr, size_t size);
-
- #endif /* DUMPMEM_H */
--- 0 ----
*** a/src/bin/pg_dump/dumputils.c
--- b/src/bin/pg_dump/dumputils.c
***************
*** 17,23 ****
#include <ctype.h>
#include "dumputils.h"
- #include "dumpmem.h"
#include "parser/keywords.h"
--- 17,22 ----
*** a/src/bin/pg_dump/nls.mk
--- b/src/bin/pg_dump/nls.mk
***************
*** 3,9 **** CATALOG_NAME = pg_dump
AVAIL_LANGUAGES = de es fr it ja ko pt_BR sv tr zh_CN zh_TW
GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
pg_backup_null.c pg_backup_tar.c \
! pg_backup_directory.c dumpmem.c dumputils.c compress_io.c \
pg_dump.c common.c pg_dump_sort.c \
pg_restore.c pg_dumpall.c \
../../port/exec.c
--- 3,9 ----
AVAIL_LANGUAGES = de es fr it ja ko pt_BR sv tr zh_CN zh_TW
GETTEXT_FILES = pg_backup_archiver.c pg_backup_db.c pg_backup_custom.c \
pg_backup_null.c pg_backup_tar.c \
! pg_backup_directory.c dumputils.c compress_io.c \
pg_dump.c common.c pg_dump_sort.c \
pg_restore.c pg_dumpall.c \
../../port/exec.c
*** a/src/bin/pg_dump/pg_backup_archiver.c
--- b/src/bin/pg_dump/pg_backup_archiver.c
***************
*** 21,27 ****
*/
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <ctype.h>
--- 21,26 ----
*** a/src/bin/pg_dump/pg_backup_custom.c
--- b/src/bin/pg_dump/pg_backup_custom.c
***************
*** 26,32 ****
#include "compress_io.h"
#include "dumputils.h"
- #include "dumpmem.h"
/*--------
* Routines in the format interface
--- 26,31 ----
*** a/src/bin/pg_dump/pg_backup_db.c
--- b/src/bin/pg_dump/pg_backup_db.c
***************
*** 11,17 ****
*/
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <unistd.h>
--- 11,16 ----
*** a/src/bin/pg_dump/pg_backup_directory.c
--- b/src/bin/pg_dump/pg_backup_directory.c
***************
*** 34,40 ****
*/
#include "compress_io.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <dirent.h>
--- 34,39 ----
*** a/src/bin/pg_dump/pg_backup_null.c
--- b/src/bin/pg_dump/pg_backup_null.c
***************
*** 23,29 ****
*/
#include "pg_backup_archiver.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <unistd.h> /* for dup */
--- 23,28 ----
*** a/src/bin/pg_dump/pg_backup_tar.c
--- b/src/bin/pg_dump/pg_backup_tar.c
***************
*** 31,37 ****
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include "pgtar.h"
--- 31,36 ----
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 59,65 ****
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
- #include "dumpmem.h"
#include "dumputils.h"
extern char *optarg;
--- 59,64 ----
*** a/src/bin/pg_dump/pg_dump_sort.c
--- b/src/bin/pg_dump/pg_dump_sort.c
***************
*** 15,21 ****
*/
#include "pg_backup_archiver.h"
#include "dumputils.h"
- #include "dumpmem.h"
/* translator: this is a module name */
static const char *modulename = gettext_noop("sorter");
--- 15,20 ----
*** a/src/bin/pg_dump/pg_dumpall.c
--- b/src/bin/pg_dump/pg_dumpall.c
***************
*** 25,31 ****
#include "getopt_long.h"
#include "dumputils.h"
- #include "dumpmem.h"
#include "pg_backup.h"
/* version string we expect back from pg_dump */
--- 25,30 ----
*** a/src/bin/pg_dump/pg_restore.c
--- b/src/bin/pg_dump/pg_restore.c
***************
*** 41,47 ****
#include "pg_backup_archiver.h"
- #include "dumpmem.h"
#include "dumputils.h"
#include <ctype.h>
--- 41,46 ----
*** a/src/bin/pg_resetxlog/pg_resetxlog.c
--- b/src/bin/pg_resetxlog/pg_resetxlog.c
***************
*** 54,59 ****
--- 54,60 ----
#include "access/xlog_internal.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
+ #include "common/fe_memutils.h"
extern int optind;
extern char *optarg;
***************
*** 420,426 **** ReadControlFile(void)
}
/* Use malloc to ensure we have a maxaligned buffer */
! buffer = (char *) malloc(PG_CONTROL_SIZE);
len = read(fd, buffer, PG_CONTROL_SIZE);
if (len < 0)
--- 421,427 ----
}
/* Use malloc to ensure we have a maxaligned buffer */
! buffer = (char *) pg_malloc(PG_CONTROL_SIZE);
len = read(fd, buffer, PG_CONTROL_SIZE);
if (len < 0)
***************
*** 942,948 **** WriteEmptyXLOG(void)
int nbytes;
/* Use malloc() to ensure buffer is MAXALIGNED */
! buffer = (char *) malloc(XLOG_BLCKSZ);
page = (XLogPageHeader) buffer;
memset(buffer, 0, XLOG_BLCKSZ);
--- 943,949 ----
int nbytes;
/* Use malloc() to ensure buffer is MAXALIGNED */
! buffer = (char *) pg_malloc(XLOG_BLCKSZ);
page = (XLogPageHeader) buffer;
memset(buffer, 0, XLOG_BLCKSZ);
*** a/src/bin/psql/common.c
--- b/src/bin/psql/common.c
***************
*** 33,88 **** static bool command_no_begin(const char *query);
static bool is_select_command(const char *query);
/*
- * "Safe" wrapper around strdup()
- */
- char *
- pg_strdup(const char *string)
- {
- char *tmp;
-
- if (!string)
- {
- psql_error("%s: pg_strdup: cannot duplicate null pointer (internal error)\n",
- pset.progname);
- exit(EXIT_FAILURE);
- }
- tmp = strdup(string);
- if (!tmp)
- {
- psql_error("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)
- {
- psql_error("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;
- }
-
- /*
* setQFout
* -- handler for -o command line option and \o command
*
--- 33,38 ----
*** a/src/bin/psql/common.h
--- b/src/bin/psql/common.h
***************
*** 14,28 ****
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
- /*
- * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out
- * safely; therefore, their return value is guaranteed to be non-NULL.
- */
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
-
extern bool setQFout(const char *fname);
extern void
--- 14,19 ----
*** a/src/bin/scripts/common.c
--- b/src/bin/scripts/common.c
***************
*** 278,332 **** 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.
*/
--- 278,283 ----
*** a/src/bin/scripts/common.h
--- b/src/bin/scripts/common.h
***************
*** 50,57 **** extern bool yesno_prompt(const char *question);
extern void setup_cancel_handler(void);
- extern char *pg_strdup(const char *string);
- extern void *pg_malloc(size_t size);
- extern void *pg_malloc0(size_t size);
-
#endif /* COMMON_H */
--- 50,53 ----
*** /dev/null
--- b/src/common/Makefile
***************
*** 0 ****
--- 1,64 ----
+ #-------------------------------------------------------------------------
+ #
+ # Makefile
+ # Makefile for src/common
+ #
+ # This makefile generates two outputs:
+ #
+ # libpgcommon.a - contains object files with FRONTEND defined,
+ # for use by client application and libraries
+ #
+ # libpgcommon_srv.a - contains object files without FRONTEND defined,
+ # for use only by the backend binaries
+ #
+ # IDENTIFICATION
+ # src/common/Makefile
+ #
+ #-------------------------------------------------------------------------
+
+ subdir = src/common
+ top_builddir = ../..
+ include $(top_builddir)/src/Makefile.global
+
+ override CPPFLAGS := -DFRONTEND $(CPPFLAGS)
+ LIBS += $(PTHREAD_LIBS)
+
+ OBJS_COMMON =
+
+ OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o
+
+ OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
+
+ all: libpgcommon.a libpgcommon_srv.a
+
+ # libpgcommon is needed by some contrib
+ install: all installdirs
+ $(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
+
+ installdirs:
+ $(MKDIR_P) '$(DESTDIR)$(libdir)'
+
+ uninstall:
+ rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
+
+ libpgcommon.a: $(OBJS_FRONTEND)
+ $(AR) $(AROPT) $@ $^
+
+ #
+ # Server versions of object files
+ #
+
+ libpgcommon_srv.a: $(OBJS_SRV)
+ $(AR) $(AROPT) $@ $^
+
+ # Because this uses its own compilation rule, it doesn't use the
+ # dependency tracking logic from Makefile.global. To make sure that
+ # dependency tracking works anyway for the *_srv.o files, depend on
+ # their *.o siblings as well, which do have proper dependencies. It's
+ # a hack that might fail someday if there is a *_srv.o without a
+ # corresponding *.o, but it works for now.
+ %_srv.o: %.c %.o
+ $(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
+
+ clean distclean maintainer-clean:
+ rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND) $(OBJS_SRV)
*** /dev/null
--- b/src/common/fe_memutils.c
***************
*** 0 ****
--- 1,128 ----
+ /*-------------------------------------------------------------------------
+ *
+ * fe_memutils.c
+ * memory management support for frontend code
+ *
+ * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/common/fe_memutils.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ #ifndef FRONTEND
+ #error "This file is not expected to be compiled for backend code"
+ #endif
+
+ #include "postgres_fe.h"
+
+ 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;
+ }
+
+ void *
+ pg_realloc(void *ptr, size_t size)
+ {
+ void *tmp;
+
+ /* Avoid unportable behavior of realloc(NULL, 0) */
+ if (ptr == NULL && size == 0)
+ size = 1;
+ tmp = realloc(ptr, size);
+ if (!tmp)
+ {
+ fprintf(stderr, _("out of memory\n"));
+ exit(EXIT_FAILURE);
+ }
+ return tmp;
+ }
+
+ /*
+ * "Safe" wrapper around strdup().
+ */
+ char *
+ pg_strdup(const char *string)
+ {
+ char *tmp;
+
+ if (!string)
+ {
+ fprintf(stderr,
+ _("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_free(void *ptr)
+ {
+ if (ptr != NULL)
+ free(ptr);
+ }
+
+ /*
+ * Frontend emulation of backend memory management functions. Useful for
+ * programs that compile backend files.
+ */
+ void *
+ palloc(Size size)
+ {
+ return pg_malloc(size);
+ }
+
+ void *
+ palloc0(Size size)
+ {
+ return pg_malloc0(size);
+ }
+
+ void
+ pfree(void *pointer)
+ {
+ pg_free(pointer);
+ }
+
+ char *
+ pstrdup(const char *string)
+ {
+ return pg_strdup(string);
+ }
+
+ void *
+ repalloc(void *pointer, Size size)
+ {
+ return pg_realloc(pointer, size);
+ }
*** /dev/null
--- b/src/include/common/fe_memutils.h
***************
*** 0 ****
--- 1,20 ----
+ /*
+ * fe_memutils.h
+ * memory management support for frontend code
+ *
+ * Copyright (c) 2003-2013, PostgreSQL Global Development Group
+ *
+ * src/include/common/fe_memutils.h
+ */
+ #ifndef FE_MEMUTILS_H
+ #define FE_MEMUTILS_H
+
+ extern char *pg_strdup(const char *string);
+ 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"
+
+ #endif /* FE_MEMUTILS_H */
*** a/src/include/postgres_fe.h
--- b/src/include/postgres_fe.h
***************
*** 24,27 ****
--- 24,29 ----
#include "c.h"
+ #include "common/fe_memutils.h"
+
#endif /* POSTGRES_FE_H */
*** a/src/include/utils/palloc.h
--- b/src/include/utils/palloc.h
***************
*** 28,33 ****
--- 28,35 ----
#ifndef PALLOC_H
#define PALLOC_H
+ #ifndef FRONTEND
+
/*
* Type MemoryContextData is declared in nodes/memnodes.h. Most users
* of memory allocation should just treat it as an abstract type, so we
***************
*** 49,58 **** extern void *MemoryContextAlloc(MemoryContext context, Size size);
extern void *MemoryContextAllocZero(MemoryContext context, Size size);
extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
- #define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
-
- #define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
-
/*
* The result of palloc() is always word-aligned, so we can skip testing
* alignment of the pointer when deciding which MemSet variant to use.
--- 51,56 ----
***************
*** 66,85 **** extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
MemoryContextAllocZero(CurrentMemoryContext, sz) )
- extern void pfree(void *pointer);
-
- extern void *repalloc(void *pointer, Size size);
-
/*
* MemoryContextSwitchTo can't be a macro in standard C compilers.
* But we can make it an inline function if the compiler supports it.
* See STATIC_IF_INLINE in c.h.
- *
- * This file has to be includable by some non-backend code such as
- * pg_resetxlog, so don't expose the CurrentMemoryContext reference
- * if FRONTEND is defined.
*/
- #ifndef FRONTEND
#ifndef PG_USE_INLINE
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
--- 64,74 ----
***************
*** 94,115 **** MemoryContextSwitchTo(MemoryContext context)
return old;
}
#endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */
- #endif /* !FRONTEND */
/*
* These are like standard strdup() except the copied string is
* allocated in a context, not with malloc().
*/
extern char *MemoryContextStrdup(MemoryContext context, const char *string);
! #define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
!
extern char *pnstrdup(const char *in, Size len);
!
! #if defined(WIN32) || defined(__CYGWIN__)
! extern void *pgport_palloc(Size sz);
! extern char *pgport_pstrdup(const char *str);
! extern void pgport_pfree(void *pointer);
! #endif
#endif /* PALLOC_H */
--- 83,101 ----
return old;
}
#endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */
/*
* These are like standard strdup() except the copied string is
* allocated in a context, not with malloc().
*/
extern char *MemoryContextStrdup(MemoryContext context, const char *string);
+ #endif /* !FRONTEND */
! extern char *pstrdup(const char *in);
extern char *pnstrdup(const char *in, Size len);
! extern void *palloc(Size size);
! extern void *palloc0(Size size);
! extern void pfree(void *pointer);
! extern void *repalloc(void *pointer, Size size);
#endif /* PALLOC_H */
*** a/src/port/dirmod.c
--- b/src/port/dirmod.c
***************
*** 40,119 ****
#endif
#endif
-
- #ifndef FRONTEND
-
- /*
- * On Windows, call non-macro versions of palloc; we can't reference
- * CurrentMemoryContext in this file because of PGDLLIMPORT conflict.
- */
- #if defined(WIN32) || defined(__CYGWIN__)
- #undef palloc
- #undef pstrdup
- #define palloc(sz) pgport_palloc(sz)
- #define pstrdup(str) pgport_pstrdup(str)
- #endif
- #else /* FRONTEND */
-
- /*
- * In frontend, fake palloc behavior with these
- */
- #undef palloc
- #undef pstrdup
- #define palloc(sz) fe_palloc(sz)
- #define pstrdup(str) fe_pstrdup(str)
- #define repalloc(pointer,sz) fe_repalloc(pointer,sz)
- #define pfree(pointer) free(pointer)
-
- static void *
- fe_palloc(Size size)
- {
- void *res;
-
- /* Avoid unportable behavior of malloc(0) */
- if (size == 0)
- size = 1;
- res = malloc(size);
- if (res == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
-
- static char *
- fe_pstrdup(const char *string)
- {
- char *res;
-
- if ((res = strdup(string)) == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
-
- static void *
- fe_repalloc(void *pointer, Size size)
- {
- void *res;
-
- /* Avoid unportable behavior of realloc(NULL, 0) */
- if (pointer == NULL && size == 0)
- size = 1;
- res = realloc(pointer, size);
- if (res == NULL)
- {
- fprintf(stderr, _("out of memory\n"));
- exit(1);
- }
- return res;
- }
- #endif /* FRONTEND */
-
-
#if defined(WIN32) || defined(__CYGWIN__)
/*
--- 40,45 ----
*** a/src/tools/msvc/Install.pm
--- b/src/tools/msvc/Install.pm
***************
*** 86,91 **** sub Install
--- 86,92 ----
'Import libraries', $target . '/lib/',
"$conf\\", "postgres\\postgres.lib",
"libpq\\libpq.lib", "libecpg\\libecpg.lib",
+ "libpgcommon\\libpgcommon.lib",
"libpgport\\libpgport.lib", "libpgtypes\\libpgtypes.lib",
"libecpg_compat\\libecpg_compat.lib");
CopySetOfFiles(
*** a/src/tools/msvc/Mkvcbuild.pm
--- b/src/tools/msvc/Mkvcbuild.pm
***************
*** 24,29 **** our (@ISA, @EXPORT_OK);
--- 24,30 ----
my $solution;
my $libpgport;
+ my $libpgcommon;
my $postgres;
my $libpq;
***************
*** 35,40 **** my @contrib_uselibpgport = (
--- 36,46 ----
'pg_standby', 'pg_archivecleanup',
'pg_test_fsync', 'pg_test_timing',
'pg_upgrade', 'vacuumlo');
+ my @contrib_uselibpgcommon = (
+ 'oid2name', 'pgbench',
+ 'pg_standby', 'pg_archivecleanup',
+ 'pg_test_fsync', 'pg_test_timing',
+ 'pg_upgrade', 'vacuumlo');
my $contrib_extralibs = { 'pgbench' => ['wsock32.lib'] };
my $contrib_extraincludes =
{ 'tsearch2' => ['contrib/tsearch2'], 'dblink' => ['src/backend'] };
***************
*** 63,72 **** sub mkvcbuild
--- 69,87 ----
sprompt.c tar.c thread.c getopt.c getopt_long.c dirent.c rint.c win32env.c
win32error.c win32setlocale.c);
+ our @pgcommonfiles = qw(
+ fe_memutils.c);
+
+ our @pgcommonbkndfiles = qw();
+
$libpgport = $solution->AddProject('libpgport', 'lib', 'misc');
$libpgport->AddDefine('FRONTEND');
$libpgport->AddFiles('src\port', @pgportfiles);
+ $libpgcommon = $solution->AddProject('libpgcommon', 'lib', 'misc');
+ $libpgcommon->AddDefine('FRONTEND');
+ $libpgcommon->AddFiles('src\common', @pgcommonfiles);
+
$postgres = $solution->AddProject('postgres', 'exe', '', 'src\backend');
$postgres->AddIncludeDir('src\backend');
$postgres->AddDir('src\backend\port\win32');
***************
*** 81,86 **** sub mkvcbuild
--- 96,102 ----
$postgres->ReplaceFile('src\backend\port\pg_latch.c',
'src\backend\port\win32_latch.c');
$postgres->AddFiles('src\port', @pgportfiles);
+ $postgres->AddFiles('src\common', @pgcommonbkndfiles);
$postgres->AddDir('src\timezone');
$postgres->AddFiles('src\backend\parser', 'scan.l', 'gram.y');
$postgres->AddFiles('src\backend\bootstrap', 'bootscanner.l',
***************
*** 307,313 **** sub mkvcbuild
$pgregress_ecpg->AddIncludeDir('src\test\regress');
$pgregress_ecpg->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
$pgregress_ecpg->AddDefine('FRONTEND');
! $pgregress_ecpg->AddReference($libpgport);
my $isolation_tester =
$solution->AddProject('isolationtester', 'exe', 'misc');
--- 323,329 ----
$pgregress_ecpg->AddIncludeDir('src\test\regress');
$pgregress_ecpg->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
$pgregress_ecpg->AddDefine('FRONTEND');
! $pgregress_ecpg->AddReference($libpgport, $libpgcommon);
my $isolation_tester =
$solution->AddProject('isolationtester', 'exe', 'misc');
***************
*** 332,338 **** sub mkvcbuild
$pgregress_isolation->AddIncludeDir('src\test\regress');
$pgregress_isolation->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
$pgregress_isolation->AddDefine('FRONTEND');
! $pgregress_isolation->AddReference($libpgport);
# src/bin
my $initdb = AddSimpleFrontend('initdb');
--- 348,354 ----
$pgregress_isolation->AddIncludeDir('src\test\regress');
$pgregress_isolation->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
$pgregress_isolation->AddDefine('FRONTEND');
! $pgregress_isolation->AddReference($libpgport, $libpgcommon);
# src/bin
my $initdb = AddSimpleFrontend('initdb');
***************
*** 393,399 **** sub mkvcbuild
$pgdumpall->AddIncludeDir('src\backend');
$pgdumpall->AddFile('src\bin\pg_dump\pg_dumpall.c');
$pgdumpall->AddFile('src\bin\pg_dump\dumputils.c');
- $pgdumpall->AddFile('src\bin\pg_dump\dumpmem.c');
$pgdumpall->AddFile('src\bin\pg_dump\keywords.c');
$pgdumpall->AddFile('src\backend\parser\kwlookup.c');
--- 409,414 ----
***************
*** 407,413 **** sub mkvcbuild
my $zic = $solution->AddProject('zic', 'exe', 'utils');
$zic->AddFiles('src\timezone', 'zic.c', 'ialloc.c', 'scheck.c',
'localtime.c');
! $zic->AddReference($libpgport);
if ($solution->{options}->{xml})
{
--- 422,428 ----
my $zic = $solution->AddProject('zic', 'exe', 'utils');
$zic->AddFiles('src\timezone', 'zic.c', 'ialloc.c', 'scheck.c',
'localtime.c');
! $zic->AddReference($libpgport, $libpgcommon);
if ($solution->{options}->{xml})
{
***************
*** 547,553 **** sub mkvcbuild
$proj->AddIncludeDir('src\interfaces\libpq');
$proj->AddIncludeDir('src\bin\pg_dump');
$proj->AddIncludeDir('src\bin\psql');
! $proj->AddReference($libpq, $libpgport);
$proj->AddResourceFile('src\bin\scripts', 'PostgreSQL Utility');
}
--- 562,568 ----
$proj->AddIncludeDir('src\interfaces\libpq');
$proj->AddIncludeDir('src\bin\pg_dump');
$proj->AddIncludeDir('src\bin\psql');
! $proj->AddReference($libpq, $libpgport, $libpgcommon);
$proj->AddResourceFile('src\bin\scripts', 'PostgreSQL Utility');
}
***************
*** 561,567 **** sub mkvcbuild
$pgregress->AddFile('src\test\regress\pg_regress_main.c');
$pgregress->AddIncludeDir('src\port');
$pgregress->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
! $pgregress->AddReference($libpgport);
$solution->Save();
return $solution->{vcver};
--- 576,582 ----
$pgregress->AddFile('src\test\regress\pg_regress_main.c');
$pgregress->AddIncludeDir('src\port');
$pgregress->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
! $pgregress->AddReference($libpgport, $libpgcommon);
$solution->Save();
return $solution->{vcver};
***************
*** 579,585 **** sub AddSimpleFrontend
my $p = $solution->AddProject($n, 'exe', 'bin');
$p->AddDir('src\bin\\' . $n);
! $p->AddReference($libpgport);
if ($uselibpq)
{
$p->AddIncludeDir('src\interfaces\libpq');
--- 594,600 ----
my $p = $solution->AddProject($n, 'exe', 'bin');
$p->AddDir('src\bin\\' . $n);
! $p->AddReference($libpgport, $libpgcommon);
if ($uselibpq)
{
$p->AddIncludeDir('src\interfaces\libpq');
***************
*** 730,735 **** sub AdjustContribProj
--- 745,754 ----
{
$proj->AddReference($libpgport);
}
+ if (grep { /^$n$/ } @contrib_uselibpgcommon)
+ {
+ $proj->AddReference($libpgcommon);
+ }
if ($contrib_extralibs->{$n})
{
foreach my $l (@{ $contrib_extralibs->{$n} })
*** a/src/tools/msvc/Project.pm
--- b/src/tools/msvc/Project.pm
***************
*** 225,231 **** sub AddDir
if ($filter eq "LIBOBJS")
{
! if (grep(/$p/, @main::pgportfiles) == 1)
{
$p =~ s/\.c/\.o/;
$matches .= $p . " ";
--- 225,231 ----
if ($filter eq "LIBOBJS")
{
! if (grep(/$p/, @main::pgportfiles, @main::pgcommonfiles) == 1)
{
$p =~ s/\.c/\.o/;
$matches .= $p . " ";
Alvaro Herrera escribió:
c. I added the MSVC bits. I tested that most of it works, but the
various regress executables as well as zic failed to build due to
lack of libpgcommon at link time. I think I fixed it; I'm waiting on
new tests to run. (This patch is the fixed version).
The attached is all that's necessary on top of the submitted v2 to make
it build on MSVC.
Barring objections, I will push this.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:
commonalize-palloc-2a.patchtext/x-diff; charset=us-asciiDownload
commit 486f297229c321e02b628c415d17f971ad3cd7b9
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Mon Feb 11 19:10:56 2013 -0300
ecpg needs libpgcommon, too
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 0642662..75e7e41 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -313,7 +313,7 @@ sub mkvcbuild
$ecpg->AddDefine('MINOR_VERSION=9');
$ecpg->AddDefine('PATCHLEVEL=0');
$ecpg->AddDefine('ECPG_COMPILE');
- $ecpg->AddReference($libpgport);
+ $ecpg->AddReference($libpgport, $libpgcommon);
my $pgregress_ecpg =
$solution->AddProject('pg_regress_ecpg', 'exe', 'misc');
Alvaro Herrera escribió:
Alvaro Herrera escribió:
c. I added the MSVC bits. I tested that most of it works, but the
various regress executables as well as zic failed to build due to
lack of libpgcommon at link time. I think I fixed it; I'm waiting on
new tests to run. (This patch is the fixed version).The attached is all that's necessary on top of the submitted v2 to make
it build on MSVC.Barring objections, I will push this.
Pushed.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers