Move wchar.c and encnames.c to src/common/.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Jan 2020 20:56:32 +0000 (15:56 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Jan 2020 20:58:55 +0000 (15:58 -0500)
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

12 files changed:
src/backend/utils/mb/Makefile
src/backend/utils/mb/README
src/bin/initdb/.gitignore
src/bin/initdb/Makefile
src/common/Makefile
src/common/encnames.c [moved from src/backend/utils/mb/encnames.c with 100% similarity]
src/common/saslprep.c
src/common/wchar.c [moved from src/backend/utils/mb/wchar.c with 100% similarity]
src/include/mb/pg_wchar.h
src/interfaces/libpq/.gitignore
src/interfaces/libpq/Makefile
src/tools/msvc/Mkvcbuild.pm

index cd4a016449e8e38ce7e8ca2815d30e36bb381917..b19a125fa2f32d9124a58bf7ae5b9857d34a8430 100644 (file)
@@ -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
 
index 7495ca5db2382e451fbba73de5ee8a203e2e881c..ef3662689135bf736d68f62125442b849123cfaa 100644 (file)
@@ -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
index 71a899ffb8a68eb2a710286dc62e7e41468370c4..b3167c46e20ba618bb1397605d89318c0f3f1680 100644 (file)
@@ -1,4 +1,3 @@
-/encnames.c
 /localtime.c
 
 /initdb
index f587a8675db9877ba17a87ad441dd032d14a6bca..7e2375478081c0c718dcf5fe113dea098e301d0f 100644 (file)
@@ -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
index ffb0f6edffa11ec94bdc18c112ea34a462f3ccd8..5b44340afdd5c2fa35fbc0d2b9a7c4fb6aea00f3 100644 (file)
@@ -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
index 2a2449e97b4b3293608a9673757609f369c99e96..7739b81807e7477a433a712909fe3c4d9be44741 100644 (file)
 
 #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"
 
 /*
index 7fb5fa4111752eb56b23c993f3caef1942888cc8..026f64f90be40456365e9fc20fe50f26823e2460 100644 (file)
@@ -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.
index 7b438f37650cf2f24a4cbb521afb6985f88af1b3..a4afe7c1c6858aefac75b6ac62c2ee972bae447f 100644 (file)
@@ -1,4 +1 @@
 /exports.list
-# .c files that are symlinked in from elsewhere
-/encnames.c
-/wchar.c
index f5f1c0c08dac82dedca73c95b8fb10d270b8059f..a06882651f1cbe43974e1673cb69473dc9553a7e 100644 (file)
@@ -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 $@
index f6ab0d528b19b3ddfc0f3051ef6f2720bce7b561..67b9f238b212201824d261e55ffea17d21291734 100644 (file)
@@ -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})
    {