From 8ac2e6a86b65121d8c2d8f5cf0fd43fcf225abfe Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Wed, 17 Aug 2022 11:40:28 +0400 Subject: [PATCH] Move all inlined compatible wrappers into header file Previous implementation segregated compatible inline function wrappers into separate .c file that prevented inlining of these functions into caller points in other modules. In current patch all these fuctions with `static inline` specification have been moved to header file compat.h. This emulates behavior of macro expanding in case when compiler performs inlining. Resolve https://github.com/postgrespro/pg_wait_sampling/issues/45 --- Makefile | 2 +- collector.c | 1 + compat.c => compat.h | 41 +++++++++++++++++++++++++++-------------- pg_wait_sampling.c | 1 + pg_wait_sampling.h | 11 ----------- 5 files changed, 30 insertions(+), 26 deletions(-) rename compat.c => compat.h (76%) diff --git a/Makefile b/Makefile index ab90e59..9869ec9 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # contrib/pg_wait_sampling/Makefile MODULE_big = pg_wait_sampling -OBJS = pg_wait_sampling.o collector.o compat.o +OBJS = pg_wait_sampling.o collector.o EXTENSION = pg_wait_sampling EXTVERSION = 1.1 diff --git a/collector.c b/collector.c index 9bb8cfb..2bfe534 100644 --- a/collector.c +++ b/collector.c @@ -26,6 +26,7 @@ #include "utils/resowner.h" #include "pgstat.h" +#include "compat.h" #include "pg_wait_sampling.h" static volatile sig_atomic_t shutdown_requested = false; diff --git a/compat.c b/compat.h similarity index 76% rename from compat.c rename to compat.h index f2a57ae..3f471ce 100644 --- a/compat.c +++ b/compat.h @@ -1,11 +1,32 @@ +/* + * compat.h + * Definitions for function wrappers compatible between PG versions. + * + * Copyright (c) 2015-2022, Postgres Professional + * + * IDENTIFICATION + * contrib/pg_wait_sampling/compat.h + */ +#ifndef __COMPAT_H__ +#define __COMPAT_H__ + #include "postgres.h" #include "access/tupdesc.h" #include "miscadmin.h" +#include "storage/shm_mq.h" -#include "pg_wait_sampling.h" +static inline TupleDesc +CreateTemplateTupleDescCompat(int nattrs, bool hasoid) +{ +#if PG_VERSION_NUM >= 120000 + return CreateTemplateTupleDesc(nattrs); +#else + return CreateTemplateTupleDesc(nattrs, hasoid); +#endif +} -inline void +static inline void shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq) { #if PG_VERSION_NUM >= 100000 @@ -15,7 +36,7 @@ shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq) #endif } -inline shm_mq_result +static inline shm_mq_result shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data, bool nowait, bool force_flush) { @@ -26,17 +47,7 @@ shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data, #endif } -inline TupleDesc -CreateTemplateTupleDescCompat(int nattrs, bool hasoid) -{ -#if PG_VERSION_NUM >= 120000 - return CreateTemplateTupleDesc(nattrs); -#else - return CreateTemplateTupleDesc(nattrs, hasoid); -#endif -} - -inline void +static inline void InitPostgresCompat(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bool load_session_libraries, @@ -53,3 +64,5 @@ InitPostgresCompat(const char *in_dbname, Oid dboid, InitPostgres(in_dbname, dboid, username, useroid, out_dbname); #endif } + +#endif diff --git a/pg_wait_sampling.c b/pg_wait_sampling.c index 8c45f10..deda26c 100644 --- a/pg_wait_sampling.c +++ b/pg_wait_sampling.c @@ -34,6 +34,7 @@ #include "utils/memutils.h" /* TopMemoryContext. Actually for PG 9.6 only, * but there should be no harm for others. */ +#include "compat.h" #include "pg_wait_sampling.h" PG_MODULE_MAGIC; diff --git a/pg_wait_sampling.h b/pg_wait_sampling.h index 0de8d7b..a33d707 100644 --- a/pg_wait_sampling.h +++ b/pg_wait_sampling.h @@ -83,15 +83,4 @@ extern void register_wait_collector(void); extern void alloc_history(History *, int); extern PGDLLEXPORT void collector_main(Datum main_arg); -extern void shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq); -extern shm_mq_result shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, - const void *data, bool nowait, - bool force_flush); -extern TupleDesc CreateTemplateTupleDescCompat(int nattrs, bool hasoid); -extern void InitPostgresCompat(const char *in_dbname, Oid dboid, - const char *username, Oid useroid, - bool load_session_libraries, - bool override_allow_connections, - char *out_dbname); - #endif