From e6afa8918c461c1dd80c5063a950518fa4e950cd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Jan 2020 15:56:32 -0500 Subject: [PATCH] Move wchar.c and encnames.c to src/common/. Formerly, various frontend directories symlinked these two sources and then built them locally. That's an ancient, ugly hack, and we now have a much better way: put them into libpgcommon. So do that. (The immediate motivation for this is the prospect of having to introduce still more symlinking if we don't.) This commit moves these two files absolutely verbatim, for ease of reviewing the git history. There's some follow-on work to be done that will modify them a bit. Robert Haas, Tom Lane Discussion: https://postgr.es/m/CA+TgmoYO8oq-iy8E02rD8eX25T-9SmyxKWqqks5OMHxKvGXpXQ@mail.gmail.com --- src/backend/utils/mb/Makefile | 2 -- src/backend/utils/mb/README | 10 ++++++---- src/bin/initdb/.gitignore | 1 - src/bin/initdb/Makefile | 20 ++++++++------------ src/common/Makefile | 4 +++- src/{backend/utils/mb => common}/encnames.c | 0 src/common/saslprep.c | 6 ------ src/{backend/utils/mb => common}/wchar.c | 0 src/include/mb/pg_wchar.h | 4 ++-- src/interfaces/libpq/.gitignore | 3 --- src/interfaces/libpq/Makefile | 19 +------------------ src/tools/msvc/Mkvcbuild.pm | 5 +++-- 12 files changed, 23 insertions(+), 51 deletions(-) rename src/{backend/utils/mb => common}/encnames.c (100%) rename src/{backend/utils/mb => common}/wchar.c (100%) diff --git a/src/backend/utils/mb/Makefile b/src/backend/utils/mb/Makefile index cd4a016449e..b19a125fa2f 100644 --- a/src/backend/utils/mb/Makefile +++ b/src/backend/utils/mb/Makefile @@ -14,10 +14,8 @@ include $(top_builddir)/src/Makefile.global OBJS = \ conv.o \ - encnames.o \ mbutils.o \ stringinfo_mb.o \ - wchar.o \ wstrcmp.o \ wstrncmp.o diff --git a/src/backend/utils/mb/README b/src/backend/utils/mb/README index 7495ca5db23..ef366268913 100644 --- a/src/backend/utils/mb/README +++ b/src/backend/utils/mb/README @@ -3,12 +3,8 @@ src/backend/utils/mb/README Encodings ========= -encnames.c: public functions for both the backend and the frontend. conv.c: static functions and a public table for code conversion -wchar.c: mostly static functions and a public table for mb string and - multibyte conversion mbutils.c: public functions for the backend only. - requires conv.c and wchar.c stringinfo_mb.c: public backend-only multibyte-aware stringinfo functions wstrcmp.c: strcmp for mb wstrncmp.c: strncmp for mb @@ -16,6 +12,12 @@ win866.c: a tool to generate KOI8 <--> CP866 conversion table iso.c: a tool to generate KOI8 <--> ISO8859-5 conversion table win1251.c: a tool to generate KOI8 <--> CP1251 conversion table +See also in src/common/: + +encnames.c: public functions for encoding names +wchar.c: mostly static functions and a public table for mb string and + multibyte conversion + Introduction ------------ http://www.cprogramming.com/tutorial/unicode.html diff --git a/src/bin/initdb/.gitignore b/src/bin/initdb/.gitignore index 71a899ffb8a..b3167c46e20 100644 --- a/src/bin/initdb/.gitignore +++ b/src/bin/initdb/.gitignore @@ -1,4 +1,3 @@ -/encnames.c /localtime.c /initdb diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile index f587a8675db..7e237547808 100644 --- a/src/bin/initdb/Makefile +++ b/src/bin/initdb/Makefile @@ -18,7 +18,12 @@ include $(top_builddir)/src/Makefile.global override CPPFLAGS := -DFRONTEND -I$(libpq_srcdir) -I$(top_srcdir)/src/timezone $(CPPFLAGS) -# note: we need libpq only because fe_utils does +# Note: it's important that we link to encnames.o from libpgcommon, not +# from libpq, else we have risks of version skew if we run with a libpq +# shared library from a different PG version. The libpq_pgport macro +# should ensure that that happens. +# +# We need libpq only because fe_utils does. LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) # use system timezone data? @@ -28,7 +33,6 @@ endif OBJS = \ $(WIN32RES) \ - encnames.o \ findtimezone.o \ initdb.o \ localtime.o @@ -38,15 +42,7 @@ all: initdb initdb: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) -# We used to pull in all of libpq to get encnames.c, but that -# exposes us to risks of version skew if we link to a shared library. -# Do it the hard way, instead, so that we're statically linked. - -encnames.c: % : $(top_srcdir)/src/backend/utils/mb/% - rm -f $@ && $(LN_S) $< . - -# Likewise, pull in localtime.c from src/timezones - +# We must pull in localtime.c from src/timezones localtime.c: % : $(top_srcdir)/src/timezone/% rm -f $@ && $(LN_S) $< . @@ -60,7 +56,7 @@ uninstall: rm -f '$(DESTDIR)$(bindir)/initdb$(X)' clean distclean maintainer-clean: - rm -f initdb$(X) $(OBJS) encnames.c localtime.c + rm -f initdb$(X) $(OBJS) localtime.c rm -rf tmp_check # ensure that changes in datadir propagate into object file diff --git a/src/common/Makefile b/src/common/Makefile index ffb0f6edffa..5b44340afdd 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -51,6 +51,7 @@ OBJS_COMMON = \ config_info.o \ controldata_utils.o \ d2s.o \ + encnames.o \ exec.o \ f2s.o \ file_perm.o \ @@ -70,7 +71,8 @@ OBJS_COMMON = \ stringinfo.o \ unicode_norm.o \ username.o \ - wait_error.o + wait_error.o \ + wchar.o ifeq ($(with_openssl),yes) OBJS_COMMON += sha2_openssl.o diff --git a/src/backend/utils/mb/encnames.c b/src/common/encnames.c similarity index 100% rename from src/backend/utils/mb/encnames.c rename to src/common/encnames.c diff --git a/src/common/saslprep.c b/src/common/saslprep.c index 2a2449e97b4..7739b81807e 100644 --- a/src/common/saslprep.c +++ b/src/common/saslprep.c @@ -27,12 +27,6 @@ #include "common/saslprep.h" #include "common/unicode_norm.h" - -/* - * Note: The functions in this file depend on functions from - * src/backend/utils/mb/wchar.c, so in order to use this in frontend - * code, you will need to link that in, too. - */ #include "mb/pg_wchar.h" /* diff --git a/src/backend/utils/mb/wchar.c b/src/common/wchar.c similarity index 100% rename from src/backend/utils/mb/wchar.c rename to src/common/wchar.c diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h index 7fb5fa41117..026f64f90be 100644 --- a/src/include/mb/pg_wchar.h +++ b/src/include/mb/pg_wchar.h @@ -222,8 +222,8 @@ typedef unsigned int pg_wchar; * PostgreSQL encoding identifiers * * WARNING: the order of this enum must be same as order of entries - * in the pg_enc2name_tbl[] array (in mb/encnames.c), and - * in the pg_wchar_table[] array (in mb/wchar.c)! + * in the pg_enc2name_tbl[] array (in src/common/encnames.c), and + * in the pg_wchar_table[] array (in src/common/wchar.c)! * * If you add some encoding don't forget to check * PG_ENCODING_BE_LAST macro. diff --git a/src/interfaces/libpq/.gitignore b/src/interfaces/libpq/.gitignore index 7b438f37650..a4afe7c1c68 100644 --- a/src/interfaces/libpq/.gitignore +++ b/src/interfaces/libpq/.gitignore @@ -1,4 +1 @@ /exports.list -# .c files that are symlinked in from elsewhere -/encnames.c -/wchar.c diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index f5f1c0c08da..a06882651f1 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -45,11 +45,6 @@ OBJS = \ pqexpbuffer.o \ fe-auth.o -# src/backend/utils/mb -OBJS += \ - encnames.o \ - wchar.o - ifeq ($(with_openssl),yes) OBJS += \ fe-secure-common.o \ @@ -102,17 +97,7 @@ include $(top_srcdir)/src/Makefile.shlib backend_src = $(top_srcdir)/src/backend -# We use a few backend modules verbatim, but since we need -# to compile with appropriate options to build a shared lib, we can't -# use the same object files built for the backend. -# Instead, symlink the source files in here and build our own object files. -# When you add a file here, remember to add it in the "clean" target below. - -encnames.c wchar.c: % : $(backend_src)/utils/mb/% - rm -f $@ && $(LN_S) $< . - - -# Make dependencies on pg_config_paths.h visible, too. +# Make dependencies on pg_config_paths.h visible in all builds. fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h fe-misc.o: fe-misc.c $(top_builddir)/src/port/pg_config_paths.h @@ -144,8 +129,6 @@ clean distclean: clean-lib rm -f $(OBJS) pthread.h # Might be left over from a Win32 client-only build rm -f pg_config_paths.h -# Remove files we (may have) symlinked in from other places - rm -f encnames.c wchar.c maintainer-clean: distclean $(MAKE) -C test $@ diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index f6ab0d528b1..67b9f238b21 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -120,11 +120,12 @@ sub mkvcbuild } our @pgcommonallfiles = qw( - base64.c config_info.c controldata_utils.c d2s.c exec.c f2s.c file_perm.c ip.c + base64.c config_info.c controldata_utils.c d2s.c encnames.c exec.c + f2s.c file_perm.c ip.c keywords.c kwlookup.c link-canary.c md5.c pg_lzcompress.c pgfnames.c psprintf.c relpath.c rmtree.c saslprep.c scram-common.c string.c stringinfo.c unicode_norm.c username.c - wait_error.c); + wait_error.c wchar.c); if ($solution->{options}->{openssl}) {