I now understand the wisdom of moving the remaining hex functions to /common. I know someone already suggested that, and the attached patch does this.
I will add the attached patch to the commitfest so I can get cfbot testing. -- Bruce Momjian <br...@momjian.us> https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee
diff --git a/src/backend/replication/backup_manifest.c b/src/backend/replication/backup_manifest.c new file mode 100644 index c3f339c..716f114 *** a/src/backend/replication/backup_manifest.c --- b/src/backend/replication/backup_manifest.c *************** *** 17,23 **** #include "libpq/pqformat.h" #include "mb/pg_wchar.h" #include "replication/backup_manifest.h" ! #include "utils/builtins.h" #include "utils/json.h" static void AppendStringToManifest(backup_manifest_info *manifest, char *s); --- 17,23 ---- #include "libpq/pqformat.h" #include "mb/pg_wchar.h" #include "replication/backup_manifest.h" ! #include "common/hex.h" #include "utils/json.h" static void AppendStringToManifest(backup_manifest_info *manifest, char *s); diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c new file mode 100644 index a6c65b1..bca941a *** a/src/backend/utils/adt/encode.c --- b/src/backend/utils/adt/encode.c *************** *** 15,21 **** #include <ctype.h> ! #include "common/hex_decode.h" #include "mb/pg_wchar.h" #include "utils/builtins.h" #include "utils/memutils.h" --- 15,21 ---- #include <ctype.h> ! #include "common/hex.h" #include "mb/pg_wchar.h" #include "utils/builtins.h" #include "utils/memutils.h" *************** binary_decode(PG_FUNCTION_ARGS) *** 142,179 **** /* - * HEX - */ - - static const char hextbl[] = "0123456789abcdef"; - - uint64 - hex_encode(const char *src, size_t len, char *dst) - { - const char *end = src + len; - - while (src < end) - { - *dst++ = hextbl[(*src >> 4) & 0xF]; - *dst++ = hextbl[*src & 0xF]; - src++; - } - return (uint64) len * 2; - } - - static uint64 - hex_enc_len(const char *src, size_t srclen) - { - return (uint64) srclen << 1; - } - - static uint64 - hex_dec_len(const char *src, size_t srclen) - { - return (uint64) srclen >> 1; - } - - /* * BASE64 */ --- 142,147 ---- diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c new file mode 100644 index 9300d19..79fcdcd *** a/src/backend/utils/adt/varlena.c --- b/src/backend/utils/adt/varlena.c *************** *** 22,28 **** #include "catalog/pg_type.h" #include "common/hashfn.h" #include "common/int.h" ! #include "common/hex_decode.h" #include "common/unicode_norm.h" #include "lib/hyperloglog.h" #include "libpq/pqformat.h" --- 22,28 ---- #include "catalog/pg_type.h" #include "common/hashfn.h" #include "common/int.h" ! #include "common/hex.h" #include "common/unicode_norm.h" #include "lib/hyperloglog.h" #include "libpq/pqformat.h" diff --git a/src/common/Makefile b/src/common/Makefile new file mode 100644 index f624977..93eb27a *** a/src/common/Makefile --- b/src/common/Makefile *************** OBJS_COMMON = \ *** 58,64 **** file_perm.o \ file_utils.o \ hashfn.o \ ! hex_decode.o \ ip.o \ jsonapi.o \ keywords.o \ --- 58,64 ---- file_perm.o \ file_utils.o \ hashfn.o \ ! hex.o \ ip.o \ jsonapi.o \ keywords.o \ diff --git a/src/common/hex_decode.c b/src/common/hex_decode.c new file mode 100644 index 3ecdc73..97f57bc *** a/src/common/hex_decode.c --- b/src/common/hex_decode.c *************** *** 1,7 **** /*------------------------------------------------------------------------- * ! * hex_decode.c ! * hex decoding * * * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group --- 1,7 ---- /*------------------------------------------------------------------------- * ! * hex.c ! * hex processing * * * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group *************** *** 9,15 **** * * * IDENTIFICATION ! * src/common/hex_decode.c * *------------------------------------------------------------------------- */ --- 9,15 ---- * * * IDENTIFICATION ! * src/common/hex.c * *------------------------------------------------------------------------- */ *************** *** 26,32 **** #else #include "mb/pg_wchar.h" #endif ! #include "common/hex_decode.h" static const int8 hexlookup[128] = { --- 26,32 ---- #else #include "mb/pg_wchar.h" #endif ! #include "common/hex.h" static const int8 hexlookup[128] = { *************** static const int8 hexlookup[128] = { *** 40,45 **** --- 40,65 ---- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; + /* + * HEX + */ + + static const char hextbl[] = "0123456789abcdef"; + + uint64 + hex_encode(const char *src, size_t len, char *dst) + { + const char *end = src + len; + + while (src < end) + { + *dst++ = hextbl[(*src >> 4) & 0xF]; + *dst++ = hextbl[*src & 0xF]; + src++; + } + return (uint64) len * 2; + } + static inline char get_hex(const char *cp) { *************** hex_decode(const char *src, size_t len, *** 104,106 **** --- 124,138 ---- return p - dst; } + + uint64 + hex_enc_len(const char *src, size_t srclen) + { + return (uint64) srclen << 1; + } + + uint64 + hex_dec_len(const char *src, size_t srclen) + { + return (uint64) srclen >> 1; + } diff --git a/src/include/common/hex.h b/src/include/common/hex.h new file mode 100644 index ...76154b6 *** a/src/include/common/hex.h --- b/src/include/common/hex.h *************** *** 0 **** --- 1,18 ---- + /* + * hex.h + * hex processing + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/common/hex.h + */ + #ifndef COMMON_HEX_H + #define COMMON_HEX_H + + extern uint64 hex_decode(const char *src, size_t len, char *dst); + extern uint64 hex_encode(const char *src, size_t len, char *dst); + extern uint64 hex_enc_len(const char *src, size_t srclen); + extern uint64 hex_dec_len(const char *src, size_t srclen); + + #endif /* COMMON_HEX_H */ diff --git a/src/include/common/hex_decode.h b/src/include/common/hex_decode.h new file mode . index 1f99f06..e69de29 *** a/src/include/common/hex_decode.h --- b/src/include/common/hex_decode.h *************** *** 1,16 **** - /* - * hex_decode.h - * hex decoding - * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * src/include/common/hex_decode.h - */ - #ifndef COMMON_HEX_DECODE_H - #define COMMON_HEX_DECODE_H - - extern uint64 hex_decode(const char *src, size_t len, char *dst); - - - #endif /* COMMON_HEX_DECODE_H */ --- 0 ---- diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h new file mode 100644 index 19271e0..11ba6ae *** a/src/include/utils/builtins.h --- b/src/include/utils/builtins.h *************** extern void domain_check(Datum value, bo *** 31,39 **** extern int errdatatype(Oid datatypeOid); extern int errdomainconstraint(Oid datatypeOid, const char *conname); - /* encode.c */ - extern uint64 hex_encode(const char *src, size_t len, char *dst); - /* int.c */ extern int2vector *buildint2vector(const int16 *int2s, int n); --- 31,36 ---- diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm new file mode 100644 index 7f014a1..60b216c *** a/src/tools/msvc/Mkvcbuild.pm --- b/src/tools/msvc/Mkvcbuild.pm *************** sub mkvcbuild *** 121,127 **** our @pgcommonallfiles = qw( archive.c base64.c checksum_helper.c config_info.c controldata_utils.c d2s.c encnames.c exec.c ! f2s.c file_perm.c file_utils.c hashfn.c hex_decode.c ip.c jsonapi.c keywords.c kwlookup.c link-canary.c md5_common.c pg_get_line.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 --- 121,127 ---- our @pgcommonallfiles = qw( archive.c base64.c checksum_helper.c config_info.c controldata_utils.c d2s.c encnames.c exec.c ! f2s.c file_perm.c file_utils.c hashfn.c hex.c ip.c jsonapi.c keywords.c kwlookup.c link-canary.c md5_common.c pg_get_line.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