diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-05 14:17:27 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-05 14:17:27 -0400 |
commit | 0ab1a2e39b6f65b0f6a5879605ddbf12f9f50de4 (patch) | |
tree | 5aa82c5c13706d9df7faf787d7c8071478e33dac /src/backend/utils/mb | |
parent | ef777cb093e8cb45dd3ae9d3f1499c765147c1dd (diff) | |
download | postgresql-0ab1a2e39b6f65b0f6a5879605ddbf12f9f50de4.tar.gz |
Remove dead encoding-conversion functions.
The code for conversions SQL_ASCII <-> MULE_INTERNAL and
SQL_ASCII <-> UTF8 was unreachable, because we long ago changed
the wrapper functions pg_do_encoding_conversion() et al so that
they have hard-wired behaviors for conversions involving SQL_ASCII.
(At least some of those fast paths date back to 2002, though it
looks like we may not have been totally consistent about this until
later.) Given the lack of complaints, nobody is dissatisfied with
this state of affairs. Hence, let's just remove the unreachable code.
Also, change CREATE CONVERSION so that it rejects attempts to
define such conversions. Since we consider that SQL_ASCII represents
lack of knowledge about the encoding in use, such a conversion would
be semantically dubious even if it were reachable.
Adjust a couple of regression test cases that had randomly decided
to rely on these conversion functions rather than any other ones.
Discussion: https://postgr.es/m/41163.1559156593@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/mb')
6 files changed, 2 insertions, 195 deletions
diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c index f2b51acffe..3ecc92b0a6 100644 --- a/src/backend/utils/mb/conv.c +++ b/src/backend/utils/mb/conv.c @@ -133,51 +133,6 @@ mic2latin(const unsigned char *mic, unsigned char *p, int len, /* - * ASCII ---> MIC - * - * While ordinarily SQL_ASCII encoding is forgiving of high-bit-set - * characters, here we must take a hard line because we don't know - * the appropriate MIC equivalent. - */ -void -pg_ascii2mic(const unsigned char *l, unsigned char *p, int len) -{ - int c1; - - while (len > 0) - { - c1 = *l; - if (c1 == 0 || IS_HIGHBIT_SET(c1)) - report_invalid_encoding(PG_SQL_ASCII, (const char *) l, len); - *p++ = c1; - l++; - len--; - } - *p = '\0'; -} - -/* - * MIC ---> ASCII - */ -void -pg_mic2ascii(const unsigned char *mic, unsigned char *p, int len) -{ - int c1; - - while (len > 0) - { - c1 = *mic; - if (c1 == 0 || IS_HIGHBIT_SET(c1)) - report_untranslatable_char(PG_MULE_INTERNAL, PG_SQL_ASCII, - (const char *) mic, len); - *p++ = c1; - mic++; - len--; - } - *p = '\0'; -} - -/* * latin2mic_with_table: a generic single byte charset encoding * conversion from a local charset to the mule internal code. * diff --git a/src/backend/utils/mb/conversion_procs/Makefile b/src/backend/utils/mb/conversion_procs/Makefile index 258ffec06b..413aeb9861 100644 --- a/src/backend/utils/mb/conversion_procs/Makefile +++ b/src/backend/utils/mb/conversion_procs/Makefile @@ -14,9 +14,9 @@ top_builddir = ../../../../.. include $(top_builddir)/src/Makefile.global SUBDIRS = \ - ascii_and_mic cyrillic_and_mic euc_cn_and_mic euc_jp_and_sjis \ + cyrillic_and_mic euc_cn_and_mic euc_jp_and_sjis \ euc_kr_and_mic euc_tw_and_big5 latin2_and_win1250 latin_and_mic \ - utf8_and_ascii utf8_and_big5 utf8_and_cyrillic utf8_and_euc_cn \ + utf8_and_big5 utf8_and_cyrillic utf8_and_euc_cn \ utf8_and_euc_jp utf8_and_euc_kr utf8_and_euc_tw utf8_and_gb18030 \ utf8_and_gbk utf8_and_iso8859 utf8_and_iso8859_1 utf8_and_johab \ utf8_and_sjis utf8_and_win utf8_and_uhc \ diff --git a/src/backend/utils/mb/conversion_procs/ascii_and_mic/Makefile b/src/backend/utils/mb/conversion_procs/ascii_and_mic/Makefile deleted file mode 100644 index fa65eba9fd..0000000000 --- a/src/backend/utils/mb/conversion_procs/ascii_and_mic/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -#------------------------------------------------------------------------- -# -# src/backend/utils/mb/conversion_procs/ascii_and_mic/Makefile -# -#------------------------------------------------------------------------- -subdir = src/backend/utils/mb/conversion_procs/ascii_and_mic -top_builddir = ../../../../../.. -include $(top_builddir)/src/Makefile.global - -NAME = ascii_and_mic -PGFILEDESC = "ascii <-> mic text conversions" - -include $(srcdir)/../proc.mk diff --git a/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c b/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c deleted file mode 100644 index 95ecc94f07..0000000000 --- a/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c +++ /dev/null @@ -1,60 +0,0 @@ -/*------------------------------------------------------------------------- - * - * ASCII and MULE_INTERNAL - * - * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * IDENTIFICATION - * src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" -#include "fmgr.h" -#include "mb/pg_wchar.h" - -PG_MODULE_MAGIC; - -PG_FUNCTION_INFO_V1(ascii_to_mic); -PG_FUNCTION_INFO_V1(mic_to_ascii); - -/* ---------- - * conv_proc( - * INTEGER, -- source encoding id - * INTEGER, -- destination encoding id - * CSTRING, -- source string (null terminated C string) - * CSTRING, -- destination string (null terminated C string) - * INTEGER -- source string length - * ) returns VOID; - * ---------- - */ - -Datum -ascii_to_mic(PG_FUNCTION_ARGS) -{ - unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); - unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); - int len = PG_GETARG_INT32(4); - - CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_MULE_INTERNAL); - - pg_ascii2mic(src, dest, len); - - PG_RETURN_VOID(); -} - -Datum -mic_to_ascii(PG_FUNCTION_ARGS) -{ - unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); - unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); - int len = PG_GETARG_INT32(4); - - CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_SQL_ASCII); - - pg_mic2ascii(src, dest, len); - - PG_RETURN_VOID(); -} diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_ascii/Makefile b/src/backend/utils/mb/conversion_procs/utf8_and_ascii/Makefile deleted file mode 100644 index 7bd68e209b..0000000000 --- a/src/backend/utils/mb/conversion_procs/utf8_and_ascii/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -#------------------------------------------------------------------------- -# -# src/backend/utils/mb/conversion_procs/utf8_and_ascii/Makefile -# -#------------------------------------------------------------------------- -subdir = src/backend/utils/mb/conversion_procs/utf8_and_ascii -top_builddir = ../../../../../.. -include $(top_builddir)/src/Makefile.global - -NAME = utf8_and_ascii -PGFILEDESC = "utf8 <-> ascii text conversions" - -include $(srcdir)/../proc.mk diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c b/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c deleted file mode 100644 index 37db19345e..0000000000 --- a/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c +++ /dev/null @@ -1,62 +0,0 @@ -/*------------------------------------------------------------------------- - * - * ASCII <--> UTF8 - * - * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * IDENTIFICATION - * src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" -#include "fmgr.h" -#include "mb/pg_wchar.h" - -PG_MODULE_MAGIC; - -PG_FUNCTION_INFO_V1(ascii_to_utf8); -PG_FUNCTION_INFO_V1(utf8_to_ascii); - -/* ---------- - * conv_proc( - * INTEGER, -- source encoding id - * INTEGER, -- destination encoding id - * CSTRING, -- source string (null terminated C string) - * CSTRING, -- destination string (null terminated C string) - * INTEGER -- source string length - * ) returns VOID; - * ---------- - */ - -Datum -ascii_to_utf8(PG_FUNCTION_ARGS) -{ - unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); - unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); - int len = PG_GETARG_INT32(4); - - CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8); - - /* this looks wrong, but basically we're just rejecting high-bit-set */ - pg_ascii2mic(src, dest, len); - - PG_RETURN_VOID(); -} - -Datum -utf8_to_ascii(PG_FUNCTION_ARGS) -{ - unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2); - unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); - int len = PG_GETARG_INT32(4); - - CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII); - - /* this looks wrong, but basically we're just rejecting high-bit-set */ - pg_mic2ascii(src, dest, len); - - PG_RETURN_VOID(); -} |