diff options
author | vvvv <vvvv@ydb.tech> | 2023-10-20 18:42:40 +0300 |
---|---|---|
committer | vvvv <vvvv@ydb.tech> | 2023-10-20 19:40:38 +0300 |
commit | 6472d9635f006ec9dd8ae0189c9c3e940885ef2d (patch) | |
tree | c7b8541e14c22f74a7641368a5facad3de36bae2 | |
parent | babd49b87ac8b28d492552a48161080fae18a250 (diff) | |
download | ydb-6472d9635f006ec9dd8ae0189c9c3e940885ef2d.tar.gz |
Try to copy port .h/.c inside pg_wrapper
81 files changed, 627 insertions, 385 deletions
diff --git a/build/sysincl/misc-win.yml b/build/sysincl/misc-win.yml index e0567f28f9..6814f85dcf 100644 --- a/build/sysincl/misc-win.yml +++ b/build/sysincl/misc-win.yml @@ -19,7 +19,7 @@ - sys/time.h: contrib/libs/libpq/src/include/port/win32_msvc/sys/time.h - unistd.h: contrib/libs/libpq/src/include/port/win32_msvc/unistd.h -- source_filter: "^contrib/libs/postgresql/src|^ydb/library/yql/parser/pg_wrapper/postgresql/src" +- source_filter: "^contrib/libs/postgresql/src" includes: - arpa/inet.h: contrib/libs/postgresql/src/include/port/win32/arpa/inet.h - dirent.h: contrib/libs/postgresql/src/include/port/win32_msvc/dirent.h @@ -35,6 +35,23 @@ - unistd.h: contrib/libs/postgresql/src/include/port/win32_msvc/unistd.h - utime.h: contrib/libs/postgresql/src/include/port/win32_msvc/utime.h +- source_filter: "^ydb/library/yql/parser/pg_wrapper/postgresql/src" + includes: + - arpa/inet.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/arpa/inet.h + - dirent.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/dirent.h + - grp.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/grp.h + - netdb.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netdb.h + - netinet/in.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netinet/in.h + - pwd.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/pwd.h + - sys/file.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/file.h + - sys/param.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/param.h + - sys/socket.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/socket.h + - sys/time.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/time.h + - sys/wait.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/wait.h + - unistd.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/unistd.h + - utime.h: ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/utime.h + - dl.h + - source_filter: "^contrib/libs/libx264" includes: - inttypes.h: contrib/libs/libx264/extras/inttypes.h diff --git a/ydb/library/yql/parser/pg_wrapper/CMakeLists.darwin-x86_64.txt b/ydb/library/yql/parser/pg_wrapper/CMakeLists.darwin-x86_64.txt index f5c23f9907..d9b0b0d0ae 100644 --- a/ydb/library/yql/parser/pg_wrapper/CMakeLists.darwin-x86_64.txt +++ b/ydb/library/yql/parser/pg_wrapper/CMakeLists.darwin-x86_64.txt @@ -932,6 +932,6 @@ target_sources(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.17.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.18.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.19.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/posix_sema.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/sysv_shmem.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/posix_sema.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/sysv_shmem.c ) diff --git a/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-aarch64.txt b/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-aarch64.txt index 9400ab57eb..21f3a2ee48 100644 --- a/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-aarch64.txt +++ b/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-aarch64.txt @@ -929,6 +929,6 @@ target_sources(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.17.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.18.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.19.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/posix_sema.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/sysv_shmem.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/posix_sema.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/sysv_shmem.c ) diff --git a/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-x86_64.txt b/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-x86_64.txt index ba44efe629..b77fdddbb4 100644 --- a/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-x86_64.txt +++ b/ydb/library/yql/parser/pg_wrapper/CMakeLists.linux-x86_64.txt @@ -933,6 +933,6 @@ target_sources(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.17.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.18.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.19.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/posix_sema.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/sysv_shmem.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/posix_sema.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/sysv_shmem.c ) diff --git a/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt b/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt index 55adf2435d..4e83ec8262 100644 --- a/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt +++ b/ydb/library/yql/parser/pg_wrapper/CMakeLists.windows-x86_64.txt @@ -135,9 +135,8 @@ target_include_directories(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/common ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/include ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/include - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/include/port/win32 - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/include/port/win32_msvc + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32 + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc ) target_link_libraries(yql-parser-pg_wrapper PUBLIC contrib-libs-cxxsupp @@ -947,31 +946,31 @@ target_sources(yql-parser-pg_wrapper PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.17.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.18.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/pg_kernels.19.cpp - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32/crashdump.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32/signal.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32/socket.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32/timer.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32_sema.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/backend/port/win32_shmem.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/dirmod.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/dlopen.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/getaddrinfo.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/getopt.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/getrusage.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/gettimeofday.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/inet_aton.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/kill.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/open.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/pread.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/pwrite.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/pwritev.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/system.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32common.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32env.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32error.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32fseek.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32ntdll.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32security.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32setlocale.c - ${CMAKE_SOURCE_DIR}/contrib/libs/postgresql/src/port/win32stat.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/crashdump.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/signal.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/socket.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/timer.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_sema.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_shmem.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dirmod.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dlopen.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getaddrinfo.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getopt.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getrusage.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/gettimeofday.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/inet_aton.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/kill.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/open.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pread.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwrite.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwritev.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/system.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32common.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32env.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32error.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32fseek.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32ntdll.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32security.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32setlocale.c + ${CMAKE_SOURCE_DIR}/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32stat.c ) diff --git a/contrib/libs/postgresql/src/backend/port/posix_sema.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/posix_sema.c index a97a3ed99e..cf343d20e3 100644 --- a/contrib/libs/postgresql/src/backend/port/posix_sema.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/posix_sema.c @@ -15,7 +15,7 @@ * forked backends, but they could not be accessed by exec'd backends. * * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION @@ -61,11 +61,11 @@ typedef struct PGSemaphoreData #ifdef USE_NAMED_POSIX_SEMAPHORES static sem_t **mySemPointers; /* keep track of created semaphores */ #else -static PGSemaphore sharedSemas; /* array of PGSemaphoreData in shared memory */ +static __thread PGSemaphore sharedSemas; /* array of PGSemaphoreData in shared memory */ #endif -static int numSems; /* number of semas acquired so far */ -static int maxSems; /* allocated size of above arrays */ -static int nextSemKey; /* next name to try */ +static __thread int numSems; /* number of semas acquired so far */ +static __thread int maxSems; /* allocated size of above arrays */ +static __thread int nextSemKey; /* next name to try */ static void ReleaseSemaphores(int status, Datum arg); diff --git a/contrib/libs/postgresql/src/backend/port/sysv_shmem.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/sysv_shmem.c index ea287c733d..713e00b280 100644 --- a/contrib/libs/postgresql/src/backend/port/sysv_shmem.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/sysv_shmem.c @@ -9,7 +9,7 @@ * exist, though, because mmap'd shmem provides no way to find out how * many processes are attached, which we need for interlocking purposes. * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION @@ -97,8 +97,8 @@ typedef enum unsigned long UsedShmemSegID = 0; void *UsedShmemSegAddr = NULL; -static Size AnonymousShmemSize; -static void *AnonymousShmem = NULL; +static __thread Size AnonymousShmemSize; +static __thread void *AnonymousShmem = NULL; static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size); static void IpcMemoryDetach(int status, Datum shmaddr); @@ -289,7 +289,7 @@ static void IpcMemoryDetach(int status, Datum shmaddr) { /* Detach System V shared memory block. */ - if (shmdt((void *) DatumGetPointer(shmaddr)) < 0) + if (shmdt(DatumGetPointer(shmaddr)) < 0) elog(LOG, "shmdt(%p) failed: %m", DatumGetPointer(shmaddr)); } @@ -323,7 +323,7 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2) IpcMemoryState state; state = PGSharedMemoryAttach((IpcMemoryId) id2, NULL, &memAddress); - if (memAddress && shmdt((void *) memAddress) < 0) + if (memAddress && shmdt(memAddress) < 0) elog(LOG, "shmdt(%p) failed: %m", memAddress); switch (state) { @@ -456,6 +456,8 @@ PGSharedMemoryAttach(IpcMemoryId shmId, return shmStat.shm_nattch == 0 ? SHMSTATE_UNATTACHED : SHMSTATE_ATTACHED; } +#ifdef MAP_HUGETLB + /* * Identify the huge page size to use, and compute the related mmap flags. * @@ -473,19 +475,13 @@ PGSharedMemoryAttach(IpcMemoryId shmId, * hugepage sizes, we might want to think about more invasive strategies, * such as increasing shared_buffers to absorb the extra space. * - * Returns the (real, assumed or config provided) page size into - * *hugepagesize, and the hugepage-related mmap flags to use into - * *mmap_flags if requested by the caller. If huge pages are not supported, - * *hugepagesize and *mmap_flags are set to 0. + * Returns the (real, assumed or config provided) page size into *hugepagesize, + * and the hugepage-related mmap flags to use into *mmap_flags. */ -void +static void GetHugePageSize(Size *hugepagesize, int *mmap_flags) { -#ifdef MAP_HUGETLB - Size default_hugepagesize = 0; - Size hugepagesize_local = 0; - int mmap_flags_local = 0; /* * System-dependent code to find out the default huge page size. @@ -523,12 +519,12 @@ GetHugePageSize(Size *hugepagesize, int *mmap_flags) if (huge_page_size != 0) { /* If huge page size is requested explicitly, use that. */ - hugepagesize_local = (Size) huge_page_size * 1024; + *hugepagesize = (Size) huge_page_size * 1024; } else if (default_hugepagesize != 0) { /* Otherwise use the system default, if we have it. */ - hugepagesize_local = default_hugepagesize; + *hugepagesize = default_hugepagesize; } else { @@ -540,39 +536,26 @@ GetHugePageSize(Size *hugepagesize, int *mmap_flags) * writing, there are no reports of any non-Linux systems being picky * about that. */ - hugepagesize_local = 2 * 1024 * 1024; + *hugepagesize = 2 * 1024 * 1024; } - mmap_flags_local = MAP_HUGETLB; + *mmap_flags = MAP_HUGETLB; /* * On recent enough Linux, also include the explicit page size, if * necessary. */ #if defined(MAP_HUGE_MASK) && defined(MAP_HUGE_SHIFT) - if (hugepagesize_local != default_hugepagesize) + if (*hugepagesize != default_hugepagesize) { - int shift = pg_ceil_log2_64(hugepagesize_local); + int shift = pg_ceil_log2_64(*hugepagesize); - mmap_flags_local |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; + *mmap_flags |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; } #endif - - /* assign the results found */ - if (mmap_flags) - *mmap_flags = mmap_flags_local; - if (hugepagesize) - *hugepagesize = hugepagesize_local; - -#else - - if (hugepagesize) - *hugepagesize = 0; - if (mmap_flags) - *mmap_flags = 0; +} #endif /* MAP_HUGETLB */ -} /* * Creates an anonymous mmap()ed shared memory segment. @@ -807,7 +790,7 @@ PGSharedMemoryCreate(Size size, break; } - if (oldhdr && shmdt((void *) oldhdr) < 0) + if (oldhdr && shmdt(oldhdr) < 0) elog(LOG, "shmdt(%p) failed: %m", oldhdr); } diff --git a/contrib/libs/postgresql/src/backend/port/win32/crashdump.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/crashdump.c index cea7be2896..45b6696ba1 100644 --- a/contrib/libs/postgresql/src/backend/port/win32/crashdump.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/crashdump.c @@ -28,7 +28,7 @@ * be added, though at the cost of a greater chance of the crash dump failing. * * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32/crashdump.c @@ -38,6 +38,8 @@ #include "postgres.h" +#define WIN32_LEAN_AND_MEAN + /* * Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS * compiler quite sanely complains about. Well done, Microsoft. diff --git a/contrib/libs/postgresql/src/backend/port/win32/signal.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/signal.c index b71164d8db..580a517f3f 100644 --- a/contrib/libs/postgresql/src/backend/port/win32/signal.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/signal.c @@ -3,7 +3,7 @@ * signal.c * Microsoft Windows Win32 Signal Emulation Functions * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32/signal.c @@ -52,17 +52,7 @@ static BOOL WINAPI pg_console_handler(DWORD dwCtrlType); void pg_usleep(long microsec) { - if (unlikely(pgwin32_signal_event == NULL)) - { - /* - * If we're reached by pgwin32_open_handle() early in startup before - * the signal event is set up, just fall back to a regular - * non-interruptible sleep. - */ - SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE); - return; - } - + Assert(pgwin32_signal_event != NULL); if (WaitForSingleObject(pgwin32_signal_event, (microsec < 500 ? 1 : (microsec + 500) / 1000)) == WAIT_OBJECT_0) diff --git a/contrib/libs/postgresql/src/backend/port/win32/socket.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/socket.c index 52944a0d33..af151e8470 100644 --- a/contrib/libs/postgresql/src/backend/port/win32/socket.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/socket.c @@ -3,7 +3,7 @@ * socket.c * Microsoft Windows Win32 Socket Functions * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32/socket.c @@ -47,8 +47,8 @@ int pgwin32_noblock = 0; * * Note: where there is a direct correspondence between a WSAxxx error code * and a Berkeley error symbol, this mapping is actually a no-op, because - * in win32_port.h we redefine the network-related Berkeley error symbols to - * have the values of their WSAxxx counterparts. The point of the switch is + * in win32.h we redefine the network-related Berkeley error symbols to have + * the values of their WSAxxx counterparts. The point of the switch is * mostly to translate near-miss error codes into something that's sensible * in the Berkeley universe. */ @@ -141,15 +141,10 @@ TranslateSocketError(void) case WSAEDISCON: errno = ENOTCONN; break; - case WSAETIMEDOUT: - errno = ETIMEDOUT; - break; default: ereport(NOTICE, - (errmsg_internal("unrecognized win32 socket error code: %d", - WSAGetLastError()))); + (errmsg_internal("unrecognized win32 socket error code: %d", WSAGetLastError()))); errno = EINVAL; - break; } } diff --git a/contrib/libs/postgresql/src/backend/port/win32/timer.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/timer.c index 3405253af3..53fdae9468 100644 --- a/contrib/libs/postgresql/src/backend/port/win32/timer.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32/timer.c @@ -8,7 +8,7 @@ * - Does not support interval timer (value->it_interval) * - Only supports ITIMER_REAL * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32/timer.c diff --git a/contrib/libs/postgresql/src/backend/port/win32_sema.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_sema.c index 8e9c0f9307..d2f334d4b1 100644 --- a/contrib/libs/postgresql/src/backend/port/win32_sema.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_sema.c @@ -3,7 +3,7 @@ * win32_sema.c * Microsoft Windows Win32 Semaphores Emulation * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32_sema.c @@ -18,8 +18,8 @@ #include "storage/pg_sema.h" static HANDLE *mySemSet; /* IDs of sema sets acquired so far */ -static int numSems; /* number of sema sets acquired so far */ -static int maxSems; /* allocated size of mySemaSet array */ +static __thread int numSems; /* number of sema sets acquired so far */ +static __thread int maxSems; /* allocated size of mySemaSet array */ static void ReleaseSemaphores(int code, Datum arg); diff --git a/contrib/libs/postgresql/src/backend/port/win32_shmem.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_shmem.c index 6cf69411db..d7a71992d8 100644 --- a/contrib/libs/postgresql/src/backend/port/win32_shmem.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/port/win32_shmem.c @@ -3,7 +3,7 @@ * win32_shmem.c * Implement shared memory using win32 facilities * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group * * IDENTIFICATION * src/backend/port/win32_shmem.c @@ -605,17 +605,3 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild) return true; } - -/* - * This function is provided for consistency with sysv_shmem.c and does not - * provide any useful information for Windows. To obtain the large page size, - * use GetLargePageMinimum() instead. - */ -void -GetHugePageSize(Size *hugepagesize, int *mmap_flags) -{ - if (hugepagesize) - *hugepagesize = 0; - if (mmap_flags) - *mmap_flags = 0; -} diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics.h index b820d4e966..e32a1c400a 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics.h @@ -28,7 +28,7 @@ * For an introduction to using memory barriers within the PostgreSQL backend, * see src/backend/storage/lmgr/README.barrier * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/atomics.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/arch-x86.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/arch-x86.h index 2cab5a327a..cef1ba724c 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/arch-x86.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/arch-x86.h @@ -7,7 +7,7 @@ * support for xadd and cmpxchg. Given that the 386 isn't supported anywhere * anymore that's not much of a restriction luckily. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * NOTES: diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/fallback.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/fallback.h index b344aae955..1cdef5f2f6 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/fallback.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/fallback.h @@ -4,7 +4,7 @@ * Fallback for platforms without spinlock and/or atomics support. Slower * than native atomics support, but not unusably slow. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/atomics/fallback.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-gcc.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-gcc.h index 99fda188c4..6c566aff96 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-gcc.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-gcc.h @@ -3,7 +3,7 @@ * generic-gcc.h * Atomic operations, implemented using gcc (or compatible) intrinsics. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * NOTES: diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-msvc.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-msvc.h index 8823b8589e..29cfc7b30c 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-msvc.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic-msvc.h @@ -3,7 +3,7 @@ * generic-msvc.h * Atomic operations support when using MSVC * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * NOTES: @@ -80,7 +80,7 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, { bool ret; uint64 current; - current = _InterlockedCompareExchange64((volatile __int64 *)&ptr->value, newval, *expected); + current = _InterlockedCompareExchange64((volatile long long*)&ptr->value, newval, *expected); ret = current == *expected; *expected = current; return ret; @@ -94,7 +94,7 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, static inline uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) { - return _InterlockedExchangeAdd64((volatile __int64 *)&ptr->value, add_); + return _InterlockedExchangeAdd64((volatile long long*)&ptr->value, add_); } #endif /* _WIN64 */ diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic.h index 6d094dc4a4..a1f245624a 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/atomics/generic.h @@ -4,7 +4,7 @@ * Implement higher level operations based on some lower level atomic * operations. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/atomics/generic.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bitutils.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bitutils.h index 086bd08132..04e58cd1c4 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bitutils.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bitutils.h @@ -4,7 +4,7 @@ * Miscellaneous functions for bit-wise operations. * * - * Copyright (c) 2019-2021, PostgreSQL Global Development Group + * Copyright (c) 2019-2022, PostgreSQL Global Development Group * * src/include/port/pg_bitutils.h * @@ -13,15 +13,9 @@ #ifndef PG_BITUTILS_H #define PG_BITUTILS_H -#ifndef FRONTEND extern PGDLLIMPORT const uint8 pg_leftmost_one_pos[256]; extern PGDLLIMPORT const uint8 pg_rightmost_one_pos[256]; extern PGDLLIMPORT const uint8 pg_number_of_ones[256]; -#else -extern const uint8 pg_leftmost_one_pos[256]; -extern const uint8 pg_rightmost_one_pos[256]; -extern const uint8 pg_number_of_ones[256]; -#endif /* * pg_leftmost_one_pos32 @@ -253,20 +247,56 @@ pg_ceil_log2_64(uint64 num) return pg_leftmost_one_pos64(num - 1) + 1; } -/* Count the number of one-bits in a uint32 or uint64 */ +/* + * With MSVC on x86_64 builds, try using native popcnt instructions via the + * __popcnt and __popcnt64 intrinsics. These don't work the same as GCC's + * __builtin_popcount* intrinsic functions as they always emit popcnt + * instructions. + */ +#if defined(_MSC_VER) && defined(_M_AMD64) +#define HAVE_X86_64_POPCNTQ +#endif + +/* + * On x86_64, we can use the hardware popcount instruction, but only if + * we can verify that the CPU supports it via the cpuid instruction. + * + * Otherwise, we fall back to a hand-rolled implementation. + */ +#ifdef HAVE_X86_64_POPCNTQ +#if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID) +#define TRY_POPCNT_FAST 1 +#endif +#endif + +#ifdef TRY_POPCNT_FAST +/* Attempt to use the POPCNT instruction, but perform a runtime check first */ extern int (*pg_popcount32) (uint32 word); extern int (*pg_popcount64) (uint64 word); +#else +/* Use a portable implementation -- no need for a function pointer. */ +extern int pg_popcount32(uint32 word); +extern int pg_popcount64(uint64 word); + +#endif /* TRY_POPCNT_FAST */ + /* Count the number of one-bits in a byte array */ extern uint64 pg_popcount(const char *buf, int bytes); /* - * Rotate the bits of "word" to the right by n bits. + * Rotate the bits of "word" to the right/left by n bits. */ static inline uint32 pg_rotate_right32(uint32 word, int n) { - return (word >> n) | (word << (sizeof(word) * BITS_PER_BYTE - n)); + return (word >> n) | (word << (32 - n)); +} + +static inline uint32 +pg_rotate_left32(uint32 word, int n) +{ + return (word << n) | (word >> (32 - n)); } #endif /* PG_BITUTILS_H */ diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bswap.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bswap.h index 6dfa7757c6..4033d2bf39 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bswap.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_bswap.h @@ -11,7 +11,7 @@ * return the same. Use caution when using these wrapper macros with signed * integers. * - * Copyright (c) 2015-2021, PostgreSQL Global Development Group + * Copyright (c) 2015-2022, PostgreSQL Global Development Group * * src/include/port/pg_bswap.h * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_crc32c.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_crc32c.h index f3c4107ff9..d7668651ba 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_crc32c.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_crc32c.h @@ -23,7 +23,7 @@ * EQ_CRC32C(c1, c2) * Check for equality of two CRCs. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/pg_crc32c.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_iovec.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_iovec.h index 88f6615dbc..f0b1a71bcb 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_iovec.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/pg_iovec.h @@ -3,7 +3,7 @@ * pg_iovec.h * Header for vectored I/O functions, to use in place of <sys/uio.h>. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/pg_iovec.h diff --git a/contrib/libs/postgresql/src/include/port/win32/arpa/inet.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/arpa/inet.h index ad1803179c..ad1803179c 100644 --- a/contrib/libs/postgresql/src/include/port/win32/arpa/inet.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/arpa/inet.h diff --git a/contrib/libs/postgresql/src/include/port/win32/grp.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/grp.h index 8b4f21310e..8b4f21310e 100644 --- a/contrib/libs/postgresql/src/include/port/win32/grp.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/grp.h diff --git a/contrib/libs/postgresql/src/include/port/win32/netdb.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netdb.h index ad0627e986..ad0627e986 100644 --- a/contrib/libs/postgresql/src/include/port/win32/netdb.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netdb.h diff --git a/contrib/libs/postgresql/src/include/port/win32/netinet/in.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netinet/in.h index a4e22f89f4..a4e22f89f4 100644 --- a/contrib/libs/postgresql/src/include/port/win32/netinet/in.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/netinet/in.h diff --git a/contrib/libs/postgresql/src/include/port/win32/pwd.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/pwd.h index b8c7178fc0..b8c7178fc0 100644 --- a/contrib/libs/postgresql/src/include/port/win32/pwd.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/pwd.h diff --git a/contrib/libs/postgresql/src/include/port/win32/sys/socket.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/socket.h index 9b2cdf3b9b..9b2cdf3b9b 100644 --- a/contrib/libs/postgresql/src/include/port/win32/sys/socket.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/socket.h diff --git a/contrib/libs/postgresql/src/include/port/win32/sys/wait.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/wait.h index eaeb5661c9..eaeb5661c9 100644 --- a/contrib/libs/postgresql/src/include/port/win32/sys/wait.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32/sys/wait.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/dirent.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/dirent.h index 62799db001..62799db001 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/dirent.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/dirent.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/file.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/file.h index 76be3e7774..76be3e7774 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/file.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/file.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/param.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/param.h index 160df3b25e..160df3b25e 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/param.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/param.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/time.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/time.h index 9d943ecc6f..9d943ecc6f 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/sys/time.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/sys/time.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/unistd.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/unistd.h index b7795ba03c..b7795ba03c 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/unistd.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/unistd.h diff --git a/contrib/libs/postgresql/src/include/port/win32_msvc/utime.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/utime.h index c78e79c33d..c78e79c33d 100644 --- a/contrib/libs/postgresql/src/include/port/win32_msvc/utime.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc/utime.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_port.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_port.h index ca7628f587..d1e89f364a 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_port.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_port.h @@ -6,7 +6,7 @@ * Note this is read in MinGW as well as native Windows builds, * but not in Cygwin builds. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/port/win32_port.h @@ -43,6 +43,14 @@ #define _WINSOCKAPI_ #endif +/* + * windows.h includes a lot of other headers, slowing down compilation + * significantly. WIN32_LEAN_AND_MEAN reduces that a bit. It'd be better to + * remove the include of windows.h (as well as indirect inclusions of it) from + * such a central place, but until then... + */ +#define WIN32_LEAN_AND_MEAN + #include <winsock2.h> #include <ws2tcpip.h> #include <windows.h> @@ -53,6 +61,8 @@ #undef near /* needed before sys/stat hacking below: */ +#define fstat microsoft_native_fstat +#define stat microsoft_native_stat #include <sys/stat.h> #undef fstat #undef stat @@ -191,15 +201,21 @@ struct itimerval int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue); +/* Convenience wrapper for GetFileType() */ +extern DWORD pgwin32_get_file_type(HANDLE hFile); + /* * WIN32 does not provide 64-bit off_t, but does provide the functions operating - * with 64-bit offsets. + * with 64-bit offsets. Also, fseek() might not give an error for unseekable + * streams, so harden that function with our version. */ #define pgoff_t __int64 #ifdef _MSC_VER -#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin) -#define ftello(stream) _ftelli64(stream) +extern int _pgfseeko64(FILE *stream, pgoff_t offset, int origin); +extern pgoff_t _pgftello64(FILE *stream); +#define fseeko(stream, offset, origin) _pgfseeko64(stream, offset, origin) +#define ftello(stream) _pgftello64(stream) #else #ifndef fseeko #define fseeko(stream, offset, origin) fseeko64(stream, offset, origin) @@ -379,6 +395,8 @@ extern int _pgstat64(const char *name, struct stat *buf); #define ENETUNREACH WSAENETUNREACH #undef ENOTCONN #define ENOTCONN WSAENOTCONN +#undef ETIMEDOUT +#define ETIMEDOUT WSAETIMEDOUT /* * Locale stuff. @@ -437,16 +455,16 @@ extern char *pgwin32_setlocale(int category, const char *locale); /* In backend/port/win32/signal.c */ extern PGDLLIMPORT volatile int pg_signal_queue; extern PGDLLIMPORT int pg_signal_mask; -extern HANDLE pgwin32_signal_event; -extern HANDLE pgwin32_initial_signal_pipe; +extern PGDLLIMPORT HANDLE pgwin32_signal_event; +extern PGDLLIMPORT HANDLE pgwin32_initial_signal_pipe; #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask) #define PG_SIGNAL_COUNT 32 -void pgwin32_signal_initialize(void); -HANDLE pgwin32_create_signal_listener(pid_t pid); -void pgwin32_dispatch_queued_signals(void); -void pg_queue_signal(int signum); +extern void pgwin32_signal_initialize(void); +extern HANDLE pgwin32_create_signal_listener(pid_t pid); +extern void pgwin32_dispatch_queued_signals(void); +extern void pg_queue_signal(int signum); /* In src/port/kill.c */ #define kill(pid,sig) pgkill(pid,sig) @@ -463,17 +481,17 @@ extern int pgkill(int pid, int sig); #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags) #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags) -SOCKET pgwin32_socket(int af, int type, int protocol); -int pgwin32_bind(SOCKET s, struct sockaddr *addr, int addrlen); -int pgwin32_listen(SOCKET s, int backlog); -SOCKET pgwin32_accept(SOCKET s, struct sockaddr *addr, int *addrlen); -int pgwin32_connect(SOCKET s, const struct sockaddr *name, int namelen); -int pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout); -int pgwin32_recv(SOCKET s, char *buf, int len, int flags); -int pgwin32_send(SOCKET s, const void *buf, int len, int flags); -int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout); +extern SOCKET pgwin32_socket(int af, int type, int protocol); +extern int pgwin32_bind(SOCKET s, struct sockaddr *addr, int addrlen); +extern int pgwin32_listen(SOCKET s, int backlog); +extern SOCKET pgwin32_accept(SOCKET s, struct sockaddr *addr, int *addrlen); +extern int pgwin32_connect(SOCKET s, const struct sockaddr *name, int namelen); +extern int pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout); +extern int pgwin32_recv(SOCKET s, char *buf, int len, int flags); +extern int pgwin32_send(SOCKET s, const void *buf, int len, int flags); +extern int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout); -extern int pgwin32_noblock; +extern PGDLLIMPORT int pgwin32_noblock; #endif /* FRONTEND */ @@ -517,9 +535,6 @@ typedef unsigned short mode_t; #define W_OK 2 #define R_OK 4 -/* Pulled from Makefile.port in MinGW */ -#define DLSUFFIX ".dll" - #endif /* _MSC_VER */ #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || \ diff --git a/contrib/libs/postgresql/src/include/port/win32ntdll.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32ntdll.h index 291b067ea4..291b067ea4 100644 --- a/contrib/libs/postgresql/src/include/port/win32ntdll.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32ntdll.h diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/bsearch_arg.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/bsearch_arg.c index 8849bdffd2..a74c5882eb 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/bsearch_arg.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/bsearch_arg.c @@ -1,7 +1,7 @@ /* * bsearch_arg.c: bsearch variant with a user-supplied pointer * - * Copyright (c) 2021, PostgreSQL Global Development Group + * Copyright (c) 2021-2022, PostgreSQL Global Development Group * Copyright (c) 1990 Regents of the University of California. * All rights reserved. * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/chklocale.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/chklocale.c index 3d47d37eae..c85d8da3c8 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/chklocale.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/chklocale.c @@ -4,7 +4,7 @@ * Functions for handling locale-related info * * - * Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Copyright (c) 1996-2022, PostgreSQL Global Development Group * * * IDENTIFICATION @@ -278,7 +278,6 @@ win32_langinfo(const char *ctype) strcpy(r, codepage); } } - } #endif diff --git a/contrib/libs/postgresql/src/port/dirmod.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dirmod.c index 62daec7af8..62daec7af8 100644 --- a/contrib/libs/postgresql/src/port/dirmod.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dirmod.c diff --git a/contrib/libs/postgresql/src/port/dlopen.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dlopen.c index d441dc8196..d441dc8196 100644 --- a/contrib/libs/postgresql/src/port/dlopen.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/dlopen.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/fls.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/fls.c index 2c622c51eb..19b4221826 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/fls.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/fls.c @@ -3,7 +3,7 @@ * fls.c * finds the last (most significant) bit that is set * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * * IDENTIFICATION diff --git a/contrib/libs/postgresql/src/port/getaddrinfo.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getaddrinfo.c index 3284c6eb52..3284c6eb52 100644 --- a/contrib/libs/postgresql/src/port/getaddrinfo.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getaddrinfo.c diff --git a/contrib/libs/postgresql/src/port/getopt.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getopt.c index 207c2836d3..207c2836d3 100644 --- a/contrib/libs/postgresql/src/port/getopt.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getopt.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getpeereid.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getpeereid.c index d6aa755d30..56ae141040 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getpeereid.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getpeereid.c @@ -3,7 +3,7 @@ * getpeereid.c * get peer userid for UNIX-domain socket connection * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * * IDENTIFICATION @@ -37,7 +37,7 @@ getpeereid(int sock, uid_t *uid, gid_t *gid) #if defined(SO_PEERCRED) /* Linux: use getsockopt(SO_PEERCRED) */ struct ucred peercred; - ACCEPT_TYPE_ARG3 so_len = sizeof(peercred); + socklen_t so_len = sizeof(peercred); if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) != 0 || so_len != sizeof(peercred)) @@ -48,7 +48,7 @@ getpeereid(int sock, uid_t *uid, gid_t *gid) #elif defined(LOCAL_PEERCRED) /* Debian with FreeBSD kernel: use getsockopt(LOCAL_PEERCRED) */ struct xucred peercred; - ACCEPT_TYPE_ARG3 so_len = sizeof(peercred); + socklen_t so_len = sizeof(peercred); if (getsockopt(sock, 0, LOCAL_PEERCRED, &peercred, &so_len) != 0 || so_len != sizeof(peercred) || diff --git a/contrib/libs/postgresql/src/port/getrusage.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getrusage.c index 8369fd2793..8369fd2793 100644 --- a/contrib/libs/postgresql/src/port/getrusage.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/getrusage.c diff --git a/contrib/libs/postgresql/src/port/gettimeofday.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/gettimeofday.c index ee8fe82337..ee8fe82337 100644 --- a/contrib/libs/postgresql/src/port/gettimeofday.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/gettimeofday.c diff --git a/contrib/libs/postgresql/src/port/inet_aton.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/inet_aton.c index adaf18adb3..adaf18adb3 100644 --- a/contrib/libs/postgresql/src/port/inet_aton.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/inet_aton.c diff --git a/contrib/libs/postgresql/src/port/kill.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/kill.c index ff0862683c..ff0862683c 100644 --- a/contrib/libs/postgresql/src/port/kill.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/kill.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/noblock.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/noblock.c index b43222c338..4c95a1fcf2 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/noblock.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/noblock.c @@ -3,7 +3,7 @@ * noblock.c * set a file descriptor as blocking or non-blocking * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION diff --git a/contrib/libs/postgresql/src/port/open.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/open.c index 8c09c7c1f7..8c09c7c1f7 100644 --- a/contrib/libs/postgresql/src/port/open.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/open.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/path.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/path.c index a695cc4e2f..99b53d15e1 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/path.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/path.c @@ -3,7 +3,7 @@ * path.c * portable path handling routines * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * @@ -46,8 +46,9 @@ static void make_relative_path(char *ret_path, const char *target_path, const char *bin_path, const char *my_exec_path); -static void trim_directory(char *path); +static char *trim_directory(char *path); static void trim_trailing_separator(char *path); +static char *append_subdir_to_path(char *path, char *subdir); /* @@ -222,13 +223,9 @@ join_path_components(char *ret_path, strlcpy(ret_path, head, MAXPGPATH); /* - * Remove any leading "." in the tail component. - * - * Note: we used to try to remove ".." as well, but that's tricky to get - * right; now we just leave it to be done by canonicalize_path() later. + * We used to try to simplify some cases involving "." and "..", but now + * we just leave that to be done by canonicalize_path() later. */ - while (tail[0] == '.' && IS_DIR_SEP(tail[1])) - tail += 2; if (*tail) { @@ -241,14 +238,27 @@ join_path_components(char *ret_path, } +/* State-machine states for canonicalize_path */ +typedef enum +{ + ABSOLUTE_PATH_INIT, /* Just past the leading '/' (and Windows + * drive name if any) of an absolute path */ + ABSOLUTE_WITH_N_DEPTH, /* We collected 'pathdepth' directories in an + * absolute path */ + RELATIVE_PATH_INIT, /* At start of a relative path */ + RELATIVE_WITH_N_DEPTH, /* We collected 'pathdepth' directories in a + * relative path */ + RELATIVE_WITH_PARENT_REF /* Relative path containing only double-dots */ +} canonicalize_state; + /* * Clean up path by: * o make Win32 path use Unix slashes * o remove trailing quote on Win32 * o remove trailing slash - * o remove duplicate adjacent separators - * o remove trailing '.' - * o process trailing '..' ourselves + * o remove duplicate (adjacent) separators + * o remove '.' (unless path reduces to only '.') + * o process '..' ourselves, removing it if possible */ void canonicalize_path(char *path) @@ -256,8 +266,11 @@ canonicalize_path(char *path) char *p, *to_p; char *spath; + char *parsed; + char *unparse; bool was_sep = false; - int pending_strips; + canonicalize_state state; + int pathdepth = 0; /* counts collected regular directory names */ #ifdef WIN32 @@ -308,87 +321,194 @@ canonicalize_path(char *path) *to_p = '\0'; /* - * Remove any trailing uses of "." and process ".." ourselves + * Remove any uses of "." and process ".." ourselves * * Note that "/../.." should reduce to just "/", while "../.." has to be - * kept as-is. In the latter case we put back mistakenly trimmed ".." - * components below. Also note that we want a Windows drive spec to be - * visible to trim_directory(), but it's not part of the logic that's - * looking at the name components; hence distinction between path and - * spath. + * kept as-is. Also note that we want a Windows drive spec to be visible + * to trim_directory(), but it's not part of the logic that's looking at + * the name components; hence distinction between path and spath. + * + * This loop overwrites the path in-place. This is safe since we'll never + * make the path longer. "unparse" points to where we are reading the + * path, "parse" to where we are writing. */ spath = skip_drive(path); - pending_strips = 0; - for (;;) + if (*spath == '\0') + return; /* empty path is returned as-is */ + + if (*spath == '/') + { + state = ABSOLUTE_PATH_INIT; + /* Skip the leading slash for absolute path */ + parsed = unparse = (spath + 1); + } + else { - int len = strlen(spath); + state = RELATIVE_PATH_INIT; + parsed = unparse = spath; + } - if (len >= 2 && strcmp(spath + len - 2, "/.") == 0) - trim_directory(path); - else if (strcmp(spath, ".") == 0) + while (*unparse != '\0') + { + char *unparse_next; + bool is_double_dot; + + /* Split off this dir name, and set unparse_next to the next one */ + unparse_next = unparse; + while (*unparse_next && *unparse_next != '/') + unparse_next++; + if (*unparse_next != '\0') + *unparse_next++ = '\0'; + + /* Identify type of this dir name */ + if (strcmp(unparse, ".") == 0) { - /* Want to leave "." alone, but "./.." has to become ".." */ - if (pending_strips > 0) - *spath = '\0'; - break; + /* We can ignore "." components in all cases */ + unparse = unparse_next; + continue; } - else if ((len >= 3 && strcmp(spath + len - 3, "/..") == 0) || - strcmp(spath, "..") == 0) + + if (strcmp(unparse, "..") == 0) + is_double_dot = true; + else { - trim_directory(path); - pending_strips++; + /* adjacent separators were eliminated above */ + Assert(*unparse != '\0'); + is_double_dot = false; } - else if (pending_strips > 0 && *spath != '\0') + + switch (state) { - /* trim a regular directory name canceled by ".." */ - trim_directory(path); - pending_strips--; - /* foo/.. should become ".", not empty */ - if (*spath == '\0') - strcpy(spath, "."); + case ABSOLUTE_PATH_INIT: + /* We can ignore ".." immediately after / */ + if (!is_double_dot) + { + /* Append first dir name (we already have leading slash) */ + parsed = append_subdir_to_path(parsed, unparse); + state = ABSOLUTE_WITH_N_DEPTH; + pathdepth++; + } + break; + case ABSOLUTE_WITH_N_DEPTH: + if (is_double_dot) + { + /* Remove last parsed dir */ + /* (trim_directory won't remove the leading slash) */ + *parsed = '\0'; + parsed = trim_directory(path); + if (--pathdepth == 0) + state = ABSOLUTE_PATH_INIT; + } + else + { + /* Append normal dir */ + *parsed++ = '/'; + parsed = append_subdir_to_path(parsed, unparse); + pathdepth++; + } + break; + case RELATIVE_PATH_INIT: + if (is_double_dot) + { + /* Append irreducible double-dot (..) */ + parsed = append_subdir_to_path(parsed, unparse); + state = RELATIVE_WITH_PARENT_REF; + } + else + { + /* Append normal dir */ + parsed = append_subdir_to_path(parsed, unparse); + state = RELATIVE_WITH_N_DEPTH; + pathdepth++; + } + break; + case RELATIVE_WITH_N_DEPTH: + if (is_double_dot) + { + /* Remove last parsed dir */ + *parsed = '\0'; + parsed = trim_directory(path); + if (--pathdepth == 0) + { + /* + * If the output path is now empty, we're back to the + * INIT state. However, we could have processed a + * path like "../dir/.." and now be down to "..", in + * which case enter the correct state for that. + */ + if (parsed == spath) + state = RELATIVE_PATH_INIT; + else + state = RELATIVE_WITH_PARENT_REF; + } + } + else + { + /* Append normal dir */ + *parsed++ = '/'; + parsed = append_subdir_to_path(parsed, unparse); + pathdepth++; + } + break; + case RELATIVE_WITH_PARENT_REF: + if (is_double_dot) + { + /* Append next irreducible double-dot (..) */ + *parsed++ = '/'; + parsed = append_subdir_to_path(parsed, unparse); + } + else + { + /* Append normal dir */ + *parsed++ = '/'; + parsed = append_subdir_to_path(parsed, unparse); + + /* + * We can now start counting normal dirs. But if later + * double-dots make us remove this dir again, we'd better + * revert to RELATIVE_WITH_PARENT_REF not INIT state. + */ + state = RELATIVE_WITH_N_DEPTH; + pathdepth = 1; + } + break; } - else - break; - } - if (pending_strips > 0) - { - /* - * We could only get here if path is now totally empty (other than a - * possible drive specifier on Windows). We have to put back one or - * more ".."'s that we took off. - */ - while (--pending_strips > 0) - strcat(path, "../"); - strcat(path, ".."); + unparse = unparse_next; } + + /* + * If our output path is empty at this point, insert ".". We don't want + * to do this any earlier because it'd result in an extra dot in corner + * cases such as "../dir/..". Since we rejected the wholly-empty-path + * case above, there is certainly room. + */ + if (parsed == spath) + *parsed++ = '.'; + + /* And finally, ensure the output path is nul-terminated. */ + *parsed = '\0'; } /* * Detect whether a path contains any parent-directory references ("..") * * The input *must* have been put through canonicalize_path previously. - * - * This is a bit tricky because we mustn't be fooled by "..a.." (legal) - * nor "C:.." (legal on Unix but not Windows). */ bool path_contains_parent_reference(const char *path) { - int path_len; - - path = skip_drive(path); /* C: shouldn't affect our conclusion */ - - path_len = strlen(path); - /* - * ".." could be the whole path; otherwise, if it's present it must be at - * the beginning, in the middle, or at the end. + * Once canonicalized, an absolute path cannot contain any ".." at all, + * while a relative path could contain ".."(s) only at the start. So it + * is sufficient to check the start of the path, after skipping any + * Windows drive/network specifier. */ - if (strcmp(path, "..") == 0 || - strncmp(path, "../", 3) == 0 || - strstr(path, "/../") != NULL || - (path_len >= 3 && strcmp(path + path_len - 3, "/..") == 0)) + path = skip_drive(path); /* C: shouldn't affect our conclusion */ + + if (path[0] == '.' && + path[1] == '.' && + (path[2] == '\0' || path[2] == '/')) return true; return false; @@ -396,10 +516,11 @@ path_contains_parent_reference(const char *path) /* * Detect whether a path is only in or below the current working directory. + * + * The input *must* have been put through canonicalize_path previously. + * * An absolute path that matches the current working directory should - * return false (we only want relative to the cwd). We don't allow - * "/../" even if that would keep us under the cwd (it is too hard to - * track that). + * return false (we only want relative to the cwd). */ bool path_is_relative_and_below_cwd(const char *path) @@ -815,14 +936,16 @@ bool get_home_path(char *ret_path) { #ifndef WIN32 - char pwdbuf[BUFSIZ]; - struct passwd pwdstr; - struct passwd *pwd = NULL; + /* + * We first consult $HOME. If that's unset, try to get the info from + * <pwd.h>. + */ + const char *home; - (void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd); - if (pwd == NULL) - return false; - strlcpy(ret_path, pwd->pw_dir, MAXPGPATH); + home = getenv("HOME"); + if (home == NULL || home[0] == '\0') + return pg_get_user_home_dir(geteuid(), ret_path, MAXPGPATH); + strlcpy(ret_path, home, MAXPGPATH); return true; #else char *tmppath; @@ -871,8 +994,11 @@ get_parent_directory(char *path) * Trim trailing directory from path, that is, remove any trailing slashes, * the last pathname component, and the slash just ahead of it --- but never * remove a leading slash. + * + * For the convenience of canonicalize_path, the path's new end location + * is returned. */ -static void +static char * trim_directory(char *path) { char *p; @@ -880,7 +1006,7 @@ trim_directory(char *path) path = skip_drive(path); if (path[0] == '\0') - return; + return path; /* back up over trailing slash(es) */ for (p = path + strlen(path) - 1; IS_DIR_SEP(*p) && p > path; p--) @@ -895,6 +1021,7 @@ trim_directory(char *path) if (p == path && IS_DIR_SEP(*p)) p++; *p = '\0'; + return p; } @@ -914,3 +1041,25 @@ trim_trailing_separator(char *path) for (p--; p > path && IS_DIR_SEP(*p); p--) *p = '\0'; } + +/* + * append_subdir_to_path + * + * Append the currently-considered subdirectory name to the output + * path in canonicalize_path. Return the new end location of the + * output path. + * + * Since canonicalize_path updates the path in-place, we must use + * memmove not memcpy, and we don't yet terminate the path with '\0'. + */ +static char * +append_subdir_to_path(char *path, char *subdir) +{ + size_t len = strlen(subdir); + + /* No need to copy data if path and subdir are the same. */ + if (path != subdir) + memmove(path, subdir, len); + + return path + len; +} diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_bitutils.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_bitutils.c index 2252021854..61d5e5d933 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_bitutils.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_bitutils.c @@ -3,7 +3,7 @@ * pg_bitutils.c * Miscellaneous functions for bit-wise operations. * - * Copyright (c) 2019-2021, PostgreSQL Global Development Group + * Copyright (c) 2019-2022, PostgreSQL Global Development Group * * IDENTIFICATION * src/port/pg_bitutils.c @@ -103,37 +103,21 @@ const uint8 pg_number_of_ones[256] = { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; -/* - * On x86_64, we can use the hardware popcount instruction, but only if - * we can verify that the CPU supports it via the cpuid instruction. - * - * Otherwise, we fall back to __builtin_popcount if the compiler has that, - * or a hand-rolled implementation if not. - */ -#ifdef HAVE_X86_64_POPCNTQ -#if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID) -#define USE_POPCNT_ASM 1 -#endif -#endif - static int pg_popcount32_slow(uint32 word); static int pg_popcount64_slow(uint64 word); -#ifdef USE_POPCNT_ASM +#ifdef TRY_POPCNT_FAST static bool pg_popcount_available(void); static int pg_popcount32_choose(uint32 word); static int pg_popcount64_choose(uint64 word); -static int pg_popcount32_asm(uint32 word); -static int pg_popcount64_asm(uint64 word); +static int pg_popcount32_fast(uint32 word); +static int pg_popcount64_fast(uint64 word); int (*pg_popcount32) (uint32 word) = pg_popcount32_choose; int (*pg_popcount64) (uint64 word) = pg_popcount64_choose; -#else -int (*pg_popcount32) (uint32 word) = pg_popcount32_slow; -int (*pg_popcount64) (uint64 word) = pg_popcount64_slow; -#endif /* USE_POPCNT_ASM */ +#endif /* TRY_POPCNT_FAST */ -#ifdef USE_POPCNT_ASM +#ifdef TRY_POPCNT_FAST /* * Return true if CPUID indicates that the POPCNT instruction is available. @@ -165,8 +149,8 @@ pg_popcount32_choose(uint32 word) { if (pg_popcount_available()) { - pg_popcount32 = pg_popcount32_asm; - pg_popcount64 = pg_popcount64_asm; + pg_popcount32 = pg_popcount32_fast; + pg_popcount64 = pg_popcount64_fast; } else { @@ -182,8 +166,8 @@ pg_popcount64_choose(uint64 word) { if (pg_popcount_available()) { - pg_popcount32 = pg_popcount32_asm; - pg_popcount64 = pg_popcount64_asm; + pg_popcount32 = pg_popcount32_fast; + pg_popcount64 = pg_popcount64_fast; } else { @@ -195,32 +179,40 @@ pg_popcount64_choose(uint64 word) } /* - * pg_popcount32_asm + * pg_popcount32_fast * Return the number of 1 bits set in word */ static int -pg_popcount32_asm(uint32 word) +pg_popcount32_fast(uint32 word) { +#ifdef _MSC_VER + return __popcnt(word); +#else uint32 res; __asm__ __volatile__(" popcntl %1,%0\n":"=q"(res):"rm"(word):"cc"); return (int) res; +#endif } /* - * pg_popcount64_asm + * pg_popcount64_fast * Return the number of 1 bits set in word */ static int -pg_popcount64_asm(uint64 word) +pg_popcount64_fast(uint64 word) { +#ifdef _MSC_VER + return __popcnt64(word); +#else uint64 res; __asm__ __volatile__(" popcntq %1,%0\n":"=q"(res):"rm"(word):"cc"); return (int) res; +#endif } -#endif /* USE_POPCNT_ASM */ +#endif /* TRY_POPCNT_FAST */ /* @@ -273,6 +265,28 @@ pg_popcount64_slow(uint64 word) #endif /* HAVE__BUILTIN_POPCOUNT */ } +#ifndef TRY_POPCNT_FAST + +/* + * When the POPCNT instruction is not available, there's no point in using + * function pointers to vary the implementation between the fast and slow + * method. We instead just make these actual external functions when + * TRY_POPCNT_FAST is not defined. The compiler should be able to inline + * the slow versions here. + */ +int +pg_popcount32(uint32 word) +{ + return pg_popcount32_slow(word); +} + +int +pg_popcount64(uint64 word) +{ + return pg_popcount64_slow(word); +} + +#endif /* !TRY_POPCNT_FAST */ /* * pg_popcount diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_config_paths.h b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_config_paths.h index d9c45851c9..16f934d0dc 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_config_paths.h +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_config_paths.h @@ -1,12 +1,12 @@ -#define PGBINDIR "/var/empty/postgresql-14.2/bin" -#define PGSHAREDIR "/var/empty/postgresql-14.2/share/postgresql" +#define PGBINDIR "/var/empty/postgresql-15.4/bin" +#define PGSHAREDIR "/var/empty/postgresql-15.4/share/postgresql" #define SYSCONFDIR "/etc/postgresql" -#define INCLUDEDIR "/var/empty/postgresql-14.2/include" -#define PKGINCLUDEDIR "/var/empty/postgresql-14.2/include" -#define INCLUDEDIRSERVER "/var/empty/postgresql-14.2/include/server" +#define INCLUDEDIR "/var/empty/postgresql-15.4/include" +#define PKGINCLUDEDIR "/var/empty/postgresql-15.4/include" +#define INCLUDEDIRSERVER "/var/empty/postgresql-15.4/include/server" #define LIBDIR "/var/empty/tmp/out/lib" #define PKGLIBDIR "/var/empty/tmp/out/lib" -#define LOCALEDIR "/var/empty/postgresql-14.2/share/locale" -#define DOCDIR "/var/empty/postgresql-14.2/share/doc//postgresql" -#define HTMLDIR "/var/empty/postgresql-14.2/share/doc//postgresql" -#define MANDIR "/var/empty/postgresql-14.2/share/man" +#define LOCALEDIR "/var/empty/postgresql-15.4/share/locale" +#define DOCDIR "/var/empty/postgresql-15.4/share/doc//postgresql" +#define HTMLDIR "/var/empty/postgresql-15.4/share/doc//postgresql" +#define MANDIR "/var/empty/postgresql-15.4/share/man" diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sb8.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sb8.c index 98da86cdd3..b3f579fcd6 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sb8.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sb8.c @@ -8,7 +8,7 @@ * Generation", IEEE Transactions on Computers, vol.57, no. 11, * pp. 1550-1560, November 2008, doi:10.1109/TC.2008.85 * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42.c index 10fc01e1f0..627ed33566 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42.c @@ -3,7 +3,7 @@ * pg_crc32c_sse42.c * Compute CRC-32C checksum using Intel SSE 4.2 instructions. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42_choose.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42_choose.c index 0608e02011..85788c30c7 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42_choose.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_crc32c_sse42_choose.c @@ -8,7 +8,7 @@ * computation. Otherwise, fall back to the pure software implementation * (slicing-by-8). * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_strong_random.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_strong_random.c index 07f24c0089..be589c9d0b 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_strong_random.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pg_strong_random.c @@ -10,7 +10,7 @@ * therefore, even when built for backend, it cannot rely on backend * infrastructure such as elog() or palloc(). * - * Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Copyright (c) 1996-2022, PostgreSQL Global Development Group * * IDENTIFICATION * src/port/pg_strong_random.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgcheckdir.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgcheckdir.c index 9fb2f23bdd..6c09cf2981 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgcheckdir.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgcheckdir.c @@ -1,13 +1,15 @@ /*------------------------------------------------------------------------- * - * src/port/pgcheckdir.c + * pgcheckdir.c * * A simple subroutine to check whether a directory exists and is empty or not. * Useful in both initdb and the backend. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * + * IDENTIFICATION + * src/port/pgcheckdir.c *------------------------------------------------------------------------- */ diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgsleep.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgsleep.c index d6d51363e7..a84e6ccb38 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgsleep.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgsleep.c @@ -4,7 +4,7 @@ * Portable delay handling. * * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * src/port/pgsleep.c * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrcasecmp.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrcasecmp.c index 98e1aedfee..fc7ee91e8f 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrcasecmp.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrcasecmp.c @@ -18,7 +18,7 @@ * C library thinks the locale is. * * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * src/port/pgstrcasecmp.c * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrsignal.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrsignal.c index 0f3b5da04f..3094e2aaab 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrsignal.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pgstrsignal.c @@ -9,7 +9,7 @@ * This file is not currently built in MSVC builds, since it's useless * on non-Unix platforms. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pqsignal.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pqsignal.c index a373b48093..6cb0320edb 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pqsignal.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pqsignal.c @@ -4,7 +4,7 @@ * reliable BSD-style signal(2) routine stolen from RWW who stole it * from Stevens... * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/contrib/libs/postgresql/src/port/pread.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pread.c index bbf12ee027..bbf12ee027 100644 --- a/contrib/libs/postgresql/src/port/pread.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pread.c diff --git a/contrib/libs/postgresql/src/port/pwrite.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwrite.c index cadecc481c..cadecc481c 100644 --- a/contrib/libs/postgresql/src/port/pwrite.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwrite.c diff --git a/contrib/libs/postgresql/src/port/pwritev.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwritev.c index bc53704ef7..bc53704ef7 100644 --- a/contrib/libs/postgresql/src/port/pwritev.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/pwritev.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/quotes.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/quotes.c index 63a219f5f4..d90a4567ae 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/quotes.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/quotes.c @@ -3,7 +3,7 @@ * quotes.c * string quoting and escaping functions * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/snprintf.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/snprintf.c index 7c21429369..b8e2b0e7f8 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/snprintf.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/snprintf.c @@ -2,7 +2,7 @@ * Copyright (c) 1983, 1995, 1996 Eric P. Allman * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -110,6 +110,16 @@ #undef printf /* + * We use the platform's native snprintf() for some machine-dependent cases. + * While that's required by C99, Microsoft Visual Studio lacks it before + * VS2015. Fortunately, we don't really need the length check in practice, + * so just fall back to native sprintf() on that platform. + */ +#if defined(_MSC_VER) && _MSC_VER < 1900 /* pre-VS2015 */ +#define snprintf(str,size,...) sprintf(str,__VA_ARGS__) +#endif + +/* * Info about where the formatted output is going. * * dopr and subroutines will not write at/past bufend, but snprintf @@ -1002,8 +1012,8 @@ fmtptr(const void *value, PrintfTarget *target) int vallen; char convert[64]; - /* we rely on regular C library's sprintf to do the basic conversion */ - vallen = sprintf(convert, "%p", value); + /* we rely on regular C library's snprintf to do the basic conversion */ + vallen = snprintf(convert, sizeof(convert), "%p", value); if (vallen < 0) target->failed = true; else @@ -1015,8 +1025,8 @@ fmtint(long long value, char type, int forcesign, int leftjust, int minlen, int zpad, int precision, int pointflag, PrintfTarget *target) { - unsigned long long base; unsigned long long uvalue; + int base; int dosign; const char *cvt = "0123456789abcdef"; int signvalue = 0; @@ -1075,12 +1085,36 @@ fmtint(long long value, char type, int forcesign, int leftjust, vallen = 0; else { - /* make integer string */ - do + /* + * Convert integer to string. We special-case each of the possible + * base values so as to avoid general-purpose divisions. On most + * machines, division by a fixed constant can be done much more + * cheaply than a general divide. + */ + if (base == 10) + { + do + { + convert[sizeof(convert) - (++vallen)] = cvt[uvalue % 10]; + uvalue = uvalue / 10; + } while (uvalue); + } + else if (base == 16) { - convert[sizeof(convert) - (++vallen)] = cvt[uvalue % base]; - uvalue = uvalue / base; - } while (uvalue); + do + { + convert[sizeof(convert) - (++vallen)] = cvt[uvalue % 16]; + uvalue = uvalue / 16; + } while (uvalue); + } + else /* base == 8 */ + { + do + { + convert[sizeof(convert) - (++vallen)] = cvt[uvalue % 8]; + uvalue = uvalue / 8; + } while (uvalue); + } } zeropad = Max(0, precision - vallen); @@ -1129,11 +1163,11 @@ fmtfloat(double value, char type, int forcesign, int leftjust, int padlen; /* amount to pad with spaces */ /* - * We rely on the regular C library's sprintf to do the basic conversion, + * We rely on the regular C library's snprintf to do the basic conversion, * then handle padding considerations here. * * The dynamic range of "double" is about 1E+-308 for IEEE math, and not - * too wildly more than that with other hardware. In "f" format, sprintf + * too wildly more than that with other hardware. In "f" format, snprintf * could therefore generate at most 308 characters to the left of the * decimal point; while we need to allow the precision to get as high as * 308+17 to ensure that we don't truncate significant digits from very @@ -1185,14 +1219,14 @@ fmtfloat(double value, char type, int forcesign, int leftjust, fmt[2] = '*'; fmt[3] = type; fmt[4] = '\0'; - vallen = sprintf(convert, fmt, prec, value); + vallen = snprintf(convert, sizeof(convert), fmt, prec, value); } else { fmt[0] = '%'; fmt[1] = type; fmt[2] = '\0'; - vallen = sprintf(convert, fmt, value); + vallen = snprintf(convert, sizeof(convert), fmt, value); } if (vallen < 0) goto fail; @@ -1321,7 +1355,7 @@ pg_strfromd(char *str, size_t count, int precision, double value) fmt[2] = '*'; fmt[3] = 'g'; fmt[4] = '\0'; - vallen = sprintf(convert, fmt, precision, value); + vallen = snprintf(convert, sizeof(convert), fmt, precision, value); if (vallen < 0) { target.failed = true; diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/strerror.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/strerror.c index 5e27a8530a..e47bbd0009 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/strerror.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/strerror.c @@ -3,7 +3,7 @@ * strerror.c * Replacements for standard strerror() and strerror_r() functions * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * @@ -34,7 +34,7 @@ static char *win32_socket_strerror(int errnum, char *buf, size_t buflen); char * pg_strerror(int errnum) { - static __thread char errorstr_buf[PG_STRERROR_R_BUFLEN]; + static char errorstr_buf[PG_STRERROR_R_BUFLEN]; return pg_strerror_r(errnum, errorstr_buf, sizeof(errorstr_buf)); } @@ -250,10 +250,8 @@ get_errno_symbol(int errnum) #endif case ESRCH: return "ESRCH"; -#ifdef ETIMEDOUT case ETIMEDOUT: return "ETIMEDOUT"; -#endif #ifdef ETXTBSY case ETXTBSY: return "ETXTBSY"; diff --git a/contrib/libs/postgresql/src/port/system.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/system.c index 20a830fd5c..20a830fd5c 100644 --- a/contrib/libs/postgresql/src/port/system.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/system.c diff --git a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/thread.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/thread.c index 1f3bcbd1c9..7f01db04f0 100644 --- a/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/thread.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/thread.c @@ -5,7 +5,7 @@ * Prototypes and macros around system calls, used to help make * threaded libraries reentrant and safe to use from threaded applications. * - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group * * src/port/thread.c * @@ -45,10 +45,9 @@ * use *_r function names if they exit * (*_THREADSAFE=yes) * use non-*_r functions if they are thread-safe - * - * One thread-safe solution for gethostbyname() might be to use getaddrinfo(). */ +#ifndef WIN32 /* * Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r() @@ -60,7 +59,6 @@ * error during lookup: returns an errno code, *result is NULL * (caller should *not* assume that the errno variable is set) */ -#ifndef WIN32 int pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer, size_t buflen, struct passwd **result) @@ -75,42 +73,74 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer, return (*result == NULL) ? errno : 0; #endif } -#endif /* - * Wrapper around gethostbyname() or gethostbyname_r() to mimic - * POSIX gethostbyname_r() behaviour, if it is not available or required. - * This function is called _only_ by our getaddrinfo() portability function. + * pg_get_user_name - get the name of the user with the given ID + * + * On success, the user name is returned into the buffer (of size buflen), + * and "true" is returned. On failure, a localized error message is + * returned into the buffer, and "false" is returned. */ -#ifndef HAVE_GETADDRINFO -int -pqGethostbyname(const char *name, - struct hostent *resultbuf, - char *buffer, size_t buflen, - struct hostent **result, - int *herrno) +bool +pg_get_user_name(uid_t user_id, char *buffer, size_t buflen) { -#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R) - - /* - * broken (well early POSIX draft) gethostbyname_r() which returns 'struct - * hostent *' - */ - *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno); - return (*result == NULL) ? -1 : 0; -#else + char pwdbuf[BUFSIZ]; + struct passwd pwdstr; + struct passwd *pw = NULL; + int pwerr; - /* no gethostbyname_r(), just use gethostbyname() */ - *result = gethostbyname(name); + pwerr = pqGetpwuid(user_id, &pwdstr, pwdbuf, sizeof(pwdbuf), &pw); + if (pw != NULL) + { + strlcpy(buffer, pw->pw_name, buflen); + return true; + } + if (pwerr != 0) + snprintf(buffer, buflen, + _("could not look up local user ID %d: %s"), + (int) user_id, + strerror_r(pwerr, pwdbuf, sizeof(pwdbuf))); + else + snprintf(buffer, buflen, + _("local user with ID %d does not exist"), + (int) user_id); + return false; +} - if (*result != NULL) - *herrno = h_errno; +/* + * pg_get_user_home_dir - get the home directory of the user with the given ID + * + * On success, the directory path is returned into the buffer (of size buflen), + * and "true" is returned. On failure, a localized error message is + * returned into the buffer, and "false" is returned. + * + * Note that this does not incorporate the common behavior of checking + * $HOME first, since it's independent of which user_id is queried. + */ +bool +pg_get_user_home_dir(uid_t user_id, char *buffer, size_t buflen) +{ + char pwdbuf[BUFSIZ]; + struct passwd pwdstr; + struct passwd *pw = NULL; + int pwerr; - if (*result != NULL) - return 0; + pwerr = pqGetpwuid(user_id, &pwdstr, pwdbuf, sizeof(pwdbuf), &pw); + if (pw != NULL) + { + strlcpy(buffer, pw->pw_dir, buflen); + return true; + } + if (pwerr != 0) + snprintf(buffer, buflen, + _("could not look up local user ID %d: %s"), + (int) user_id, + strerror_r(pwerr, pwdbuf, sizeof(pwdbuf))); else - return -1; -#endif + snprintf(buffer, buflen, + _("local user with ID %d does not exist"), + (int) user_id); + return false; } -#endif +#endif /* !WIN32 */ diff --git a/contrib/libs/postgresql/src/port/win32common.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32common.c index 2fd78f7f93..2fd78f7f93 100644 --- a/contrib/libs/postgresql/src/port/win32common.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32common.c diff --git a/contrib/libs/postgresql/src/port/win32env.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32env.c index 7aa5a3081e..7aa5a3081e 100644 --- a/contrib/libs/postgresql/src/port/win32env.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32env.c diff --git a/contrib/libs/postgresql/src/port/win32error.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32error.c index fca867ba3d..fca867ba3d 100644 --- a/contrib/libs/postgresql/src/port/win32error.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32error.c diff --git a/contrib/libs/postgresql/src/port/win32fseek.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32fseek.c index 985313c825..985313c825 100644 --- a/contrib/libs/postgresql/src/port/win32fseek.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32fseek.c diff --git a/contrib/libs/postgresql/src/port/win32ntdll.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32ntdll.c index 10c33c6a01..10c33c6a01 100644 --- a/contrib/libs/postgresql/src/port/win32ntdll.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32ntdll.c diff --git a/contrib/libs/postgresql/src/port/win32security.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32security.c index 1235199f2f..1235199f2f 100644 --- a/contrib/libs/postgresql/src/port/win32security.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32security.c diff --git a/contrib/libs/postgresql/src/port/win32setlocale.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32setlocale.c index aadd09a4e9..aadd09a4e9 100644 --- a/contrib/libs/postgresql/src/port/win32setlocale.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32setlocale.c diff --git a/contrib/libs/postgresql/src/port/win32stat.c b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32stat.c index e25811d290..e25811d290 100644 --- a/contrib/libs/postgresql/src/port/win32stat.c +++ b/ydb/library/yql/parser/pg_wrapper/postgresql/src/port/win32stat.c diff --git a/ydb/library/yql/parser/pg_wrapper/ya.make b/ydb/library/yql/parser/pg_wrapper/ya.make index 286fd0f5ea..c9acb4619e 100644 --- a/ydb/library/yql/parser/pg_wrapper/ya.make +++ b/ydb/library/yql/parser/pg_wrapper/ya.make @@ -84,44 +84,43 @@ INCLUDE(cflags.inc) IF (OS_LINUX OR OS_DARWIN) SRCS( - ../../../../../contrib/libs/postgresql/src/backend/port/posix_sema.c - ../../../../../contrib/libs/postgresql/src/backend/port/sysv_shmem.c + postgresql/src/backend/port/posix_sema.c + postgresql/src/backend/port/sysv_shmem.c ) ELSEIF (OS_WINDOWS) ADDINCL( - contrib/libs/postgresql/src/include - contrib/libs/postgresql/src/include/port/win32 - contrib/libs/postgresql/src/include/port/win32 - contrib/libs/postgresql/src/include/port/win32_msvc + ydb/library/yql/parser/pg_wrapper/postgresql/src/include + ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32 + ydb/library/yql/parser/pg_wrapper/postgresql/src/include/port/win32_msvc ) SRCS( - ../../../../../contrib/libs/postgresql/src/backend/port/win32/crashdump.c - ../../../../../contrib/libs/postgresql/src/backend/port/win32/signal.c - ../../../../../contrib/libs/postgresql/src/backend/port/win32/socket.c - ../../../../../contrib/libs/postgresql/src/backend/port/win32/timer.c - ../../../../../contrib/libs/postgresql/src/backend/port/win32_sema.c - ../../../../../contrib/libs/postgresql/src/backend/port/win32_shmem.c - ../../../../../contrib/libs/postgresql/src/port/dirmod.c - ../../../../../contrib/libs/postgresql/src/port/dlopen.c - ../../../../../contrib/libs/postgresql/src/port/getaddrinfo.c - ../../../../../contrib/libs/postgresql/src/port/getopt.c - ../../../../../contrib/libs/postgresql/src/port/getrusage.c - ../../../../../contrib/libs/postgresql/src/port/gettimeofday.c - ../../../../../contrib/libs/postgresql/src/port/inet_aton.c - ../../../../../contrib/libs/postgresql/src/port/kill.c - ../../../../../contrib/libs/postgresql/src/port/open.c - ../../../../../contrib/libs/postgresql/src/port/pread.c - ../../../../../contrib/libs/postgresql/src/port/pwrite.c - ../../../../../contrib/libs/postgresql/src/port/pwritev.c - ../../../../../contrib/libs/postgresql/src/port/system.c - ../../../../../contrib/libs/postgresql/src/port/win32common.c - ../../../../../contrib/libs/postgresql/src/port/win32env.c - ../../../../../contrib/libs/postgresql/src/port/win32error.c - ../../../../../contrib/libs/postgresql/src/port/win32fseek.c - ../../../../../contrib/libs/postgresql/src/port/win32ntdll.c - ../../../../../contrib/libs/postgresql/src/port/win32security.c - ../../../../../contrib/libs/postgresql/src/port/win32setlocale.c - ../../../../../contrib/libs/postgresql/src/port/win32stat.c + postgresql/src/backend/port/win32/crashdump.c + postgresql/src/backend/port/win32/signal.c + postgresql/src/backend/port/win32/socket.c + postgresql/src/backend/port/win32/timer.c + postgresql/src/backend/port/win32_sema.c + postgresql/src/backend/port/win32_shmem.c + postgresql/src/port/dirmod.c + postgresql/src/port/dlopen.c + postgresql/src/port/getaddrinfo.c + postgresql/src/port/getopt.c + postgresql/src/port/getrusage.c + postgresql/src/port/gettimeofday.c + postgresql/src/port/inet_aton.c + postgresql/src/port/kill.c + postgresql/src/port/open.c + postgresql/src/port/pread.c + postgresql/src/port/pwrite.c + postgresql/src/port/pwritev.c + postgresql/src/port/system.c + postgresql/src/port/win32common.c + postgresql/src/port/win32env.c + postgresql/src/port/win32error.c + postgresql/src/port/win32fseek.c + postgresql/src/port/win32ntdll.c + postgresql/src/port/win32security.c + postgresql/src/port/win32setlocale.c + postgresql/src/port/win32stat.c ) ENDIF() |