Skip to content

Move all inlined compatible wrappers into header file #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 27 additions & 14 deletions compat.c → compat.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
{
Expand All @@ -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,
Expand All @@ -53,3 +64,5 @@ InitPostgresCompat(const char *in_dbname, Oid dboid,
InitPostgres(in_dbname, dboid, username, useroid, out_dbname);
#endif
}

#endif
1 change: 1 addition & 0 deletions pg_wait_sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions pg_wait_sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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