Skip to content

Commit 72f0e96

Browse files
authored
Merge pull request #57 from arenadata/inline_compat_functions
Move all inlined compatible wrappers into header file
2 parents 4c1ae7a + 8ac2e6a commit 72f0e96

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# contrib/pg_wait_sampling/Makefile
22

33
MODULE_big = pg_wait_sampling
4-
OBJS = pg_wait_sampling.o collector.o compat.o
4+
OBJS = pg_wait_sampling.o collector.o
55

66
EXTENSION = pg_wait_sampling
77
EXTVERSION = 1.1

collector.c

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "utils/resowner.h"
2727
#include "pgstat.h"
2828

29+
#include "compat.h"
2930
#include "pg_wait_sampling.h"
3031

3132
static volatile sig_atomic_t shutdown_requested = false;

compat.c renamed to compat.h

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
/*
2+
* compat.h
3+
* Definitions for function wrappers compatible between PG versions.
4+
*
5+
* Copyright (c) 2015-2022, Postgres Professional
6+
*
7+
* IDENTIFICATION
8+
* contrib/pg_wait_sampling/compat.h
9+
*/
10+
#ifndef __COMPAT_H__
11+
#define __COMPAT_H__
12+
113
#include "postgres.h"
214

315
#include "access/tupdesc.h"
416
#include "miscadmin.h"
17+
#include "storage/shm_mq.h"
518

6-
#include "pg_wait_sampling.h"
19+
static inline TupleDesc
20+
CreateTemplateTupleDescCompat(int nattrs, bool hasoid)
21+
{
22+
#if PG_VERSION_NUM >= 120000
23+
return CreateTemplateTupleDesc(nattrs);
24+
#else
25+
return CreateTemplateTupleDesc(nattrs, hasoid);
26+
#endif
27+
}
728

8-
inline void
29+
static inline void
930
shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq)
1031
{
1132
#if PG_VERSION_NUM >= 100000
@@ -15,7 +36,7 @@ shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq)
1536
#endif
1637
}
1738

18-
inline shm_mq_result
39+
static inline shm_mq_result
1940
shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data,
2041
bool nowait, bool force_flush)
2142
{
@@ -26,17 +47,7 @@ shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data,
2647
#endif
2748
}
2849

29-
inline TupleDesc
30-
CreateTemplateTupleDescCompat(int nattrs, bool hasoid)
31-
{
32-
#if PG_VERSION_NUM >= 120000
33-
return CreateTemplateTupleDesc(nattrs);
34-
#else
35-
return CreateTemplateTupleDesc(nattrs, hasoid);
36-
#endif
37-
}
38-
39-
inline void
50+
static inline void
4051
InitPostgresCompat(const char *in_dbname, Oid dboid,
4152
const char *username, Oid useroid,
4253
bool load_session_libraries,
@@ -53,3 +64,5 @@ InitPostgresCompat(const char *in_dbname, Oid dboid,
5364
InitPostgres(in_dbname, dboid, username, useroid, out_dbname);
5465
#endif
5566
}
67+
68+
#endif

pg_wait_sampling.c

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "utils/memutils.h" /* TopMemoryContext. Actually for PG 9.6 only,
3535
* but there should be no harm for others. */
3636

37+
#include "compat.h"
3738
#include "pg_wait_sampling.h"
3839

3940
PG_MODULE_MAGIC;

pg_wait_sampling.h

-11
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,4 @@ extern void register_wait_collector(void);
8383
extern void alloc_history(History *, int);
8484
extern PGDLLEXPORT void collector_main(Datum main_arg);
8585

86-
extern void shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq);
87-
extern shm_mq_result shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes,
88-
const void *data, bool nowait,
89-
bool force_flush);
90-
extern TupleDesc CreateTemplateTupleDescCompat(int nattrs, bool hasoid);
91-
extern void InitPostgresCompat(const char *in_dbname, Oid dboid,
92-
const char *username, Oid useroid,
93-
bool load_session_libraries,
94-
bool override_allow_connections,
95-
char *out_dbname);
96-
9786
#endif

0 commit comments

Comments
 (0)