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
This commit is contained in:
Tom Lane 2020-01-16 15:56:32 -05:00
parent 2eb34ac369
commit e6afa8918c
12 changed files with 23 additions and 51 deletions

View 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

View 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

View File

@ -1,4 +1,3 @@
/encnames.c
/localtime.c
/initdb

View 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

View 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

View File

@ -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"
/*

View 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.

View File

@ -1,4 +1 @@
/exports.list
# .c files that are symlinked in from elsewhere
/encnames.c
/wchar.c

View 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 $@

View 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})
{