Skip to content

Commit 0785d1b

Browse files
peteremichaelpqdanielgustafsson
committed
common/jsonapi: support libpq as a client
Based on a patch by Michael Paquier. For libpq, use PQExpBuffer instead of StringInfo. This requires us to track allocation failures so that we can return JSON_OUT_OF_MEMORY as needed rather than exit()ing. Author: Jacob Champion <jacob.champion@enterprisedb.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Co-authored-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/d1b467a78e0e36ed85a09adf979d04cf124a9d4b.camel@vmware.com
1 parent 3beb945 commit 0785d1b

File tree

9 files changed

+558
-243
lines changed

9 files changed

+558
-243
lines changed

src/common/Makefile

+19-4
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ endif
103103
# a matter of policy, because it is not appropriate for general purpose
104104
# libraries such as libpq to report errors directly. fe_memutils.c is
105105
# excluded because libpq must not exit() on allocation failure.
106+
#
107+
# The excluded files for _shlib builds are pulled into their own static
108+
# library, for the benefit of test programs that need not follow the
109+
# shlib rules.
106110
OBJS_FRONTEND_SHLIB = \
107111
$(OBJS_COMMON) \
108112
restricted_token.o \
109113
sprompt.o
110-
OBJS_FRONTEND = \
111-
$(OBJS_FRONTEND_SHLIB) \
114+
OBJS_EXCLUDED_SHLIB = \
112115
fe_memutils.o \
113116
logging.o
117+
OBJS_FRONTEND = \
118+
$(OBJS_FRONTEND_SHLIB) \
119+
$(OBJS_EXCLUDED_SHLIB)
114120

115121
# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
116122
OBJS_SHLIB = $(OBJS_FRONTEND_SHLIB:%.o=%_shlib.o)
@@ -121,7 +127,7 @@ TOOLSDIR = $(top_srcdir)/src/tools
121127
GEN_KEYWORDLIST = $(PERL) -I $(TOOLSDIR) $(TOOLSDIR)/gen_keywordlist.pl
122128
GEN_KEYWORDLIST_DEPS = $(TOOLSDIR)/gen_keywordlist.pl $(TOOLSDIR)/PerfectHash.pm
123129

124-
all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
130+
all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a libpgcommon_excluded_shlib.a
125131

126132
# libpgcommon is needed by some contrib
127133
install: all installdirs
@@ -154,6 +160,11 @@ libpgcommon_shlib.a: $(OBJS_SHLIB)
154160
rm -f $@
155161
$(AR) $(AROPT) $@ $^
156162

163+
# The JSON API normally exits on out-of-memory; disable that behavior for shared
164+
# library builds. This requires libpq's pqexpbuffer.h.
165+
jsonapi_shlib.o: override CPPFLAGS += -DJSONAPI_USE_PQEXPBUFFER
166+
jsonapi_shlib.o: override CPPFLAGS += -I$(libpq_srcdir)
167+
157168
# Because this uses its own compilation rule, it doesn't use the
158169
# dependency tracking logic from Makefile.global. To make sure that
159170
# dependency tracking works anyway for the *_shlib.o files, depend on
@@ -163,6 +174,10 @@ libpgcommon_shlib.a: $(OBJS_SHLIB)
163174
%_shlib.o: %.c %.o
164175
$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
165176

177+
libpgcommon_excluded_shlib.a: $(OBJS_EXCLUDED_SHLIB)
178+
rm -f $@
179+
$(AR) $(AROPT) $@ $^
180+
166181
#
167182
# Server versions of object files
168183
#
@@ -196,6 +211,6 @@ RYU_OBJS = $(RYU_FILES) $(RYU_FILES:%.o=%_shlib.o) $(RYU_FILES:%.o=%_srv.o)
196211
$(RYU_OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
197212

198213
clean distclean:
199-
rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
214+
rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a libpgcommon_excluded_shlib.a
200215
rm -f $(OBJS_FRONTEND) $(OBJS_SHLIB) $(OBJS_SRV)
201216
rm -f kwlist_d.h

0 commit comments

Comments
 (0)