From e04a8059a74c125a8af94acdcb7b15b92188470a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Nov 2021 11:00:00 -0500 Subject: [PATCH] Simplify declaring variables exported from libpgcommon and libpgport. This reverts commits c2d1eea9e and 11b500072, as well as similar hacks elsewhere, in favor of setting up the PGDLLIMPORT macro so that it can just be used unconditionally. That can work because in frontend code, we need no marking in either the defining or consuming files for a variable exported from these libraries; and frontend code has no need to access variables exported from the core backend, either. While at it, write some actual documentation about the PGDLLIMPORT and PGDLLEXPORT macros. Patch by me, based on a suggestion from Robert Haas. Discussion: https://postgr.es/m/1160385.1638165449@sss.pgh.pa.us --- src/include/c.h | 14 +++++++++++++- src/include/common/keywords.h | 6 ------ src/include/common/pg_prng.h | 4 ---- src/include/port/cygwin.h | 10 ++++++++-- src/include/port/pg_bitutils.h | 6 ------ src/include/port/win32.h | 14 ++++++++++++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index c8ede082739..7e591171a84 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1312,10 +1312,22 @@ extern long long strtoll(const char *str, char **endptr, int base); extern unsigned long long strtoull(const char *str, char **endptr, int base); #endif -/* no special DLL markers on most ports */ +/* + * Use "extern PGDLLIMPORT ..." to declare variables that are defined + * in the core backend and need to be accessible by loadable modules. + * No special marking is required on most ports. + */ #ifndef PGDLLIMPORT #define PGDLLIMPORT #endif + +/* + * Use "extern PGDLLEXPORT ..." to declare functions that are defined in + * loadable modules and need to be callable by the core backend. (Usually, + * this is not necessary because our build process automatically exports + * such symbols, but sometimes manual marking is required.) + * No special marking is required on most ports. + */ #ifndef PGDLLEXPORT #define PGDLLEXPORT #endif diff --git a/src/include/common/keywords.h b/src/include/common/keywords.h index 19e4eda8f9e..d2e94e13d29 100644 --- a/src/include/common/keywords.h +++ b/src/include/common/keywords.h @@ -22,14 +22,8 @@ #define TYPE_FUNC_NAME_KEYWORD 2 #define RESERVED_KEYWORD 3 -#ifndef FRONTEND extern PGDLLIMPORT const ScanKeywordList ScanKeywords; extern PGDLLIMPORT const uint8 ScanKeywordCategories[]; extern PGDLLIMPORT const bool ScanKeywordBareLabel[]; -#else -extern const ScanKeywordList ScanKeywords; -extern const uint8 ScanKeywordCategories[]; -extern const bool ScanKeywordBareLabel[]; -#endif #endif /* KEYWORDS_H */ diff --git a/src/include/common/pg_prng.h b/src/include/common/pg_prng.h index e4df5165d7e..623c65ae731 100644 --- a/src/include/common/pg_prng.h +++ b/src/include/common/pg_prng.h @@ -26,11 +26,7 @@ typedef struct pg_prng_state * Callers not needing local PRNG series may use this global state vector, * after initializing it with one of the pg_prng_...seed functions. */ -#ifndef FRONTEND extern PGDLLIMPORT pg_prng_state pg_global_prng_state; -#else -extern pg_prng_state pg_global_prng_state; -#endif extern void pg_prng_seed(pg_prng_state *state, uint64 seed); extern void pg_prng_fseed(pg_prng_state *state, double fseed); diff --git a/src/include/port/cygwin.h b/src/include/port/cygwin.h index 64d69936e5e..44bf8533729 100644 --- a/src/include/port/cygwin.h +++ b/src/include/port/cygwin.h @@ -1,12 +1,18 @@ /* src/include/port/cygwin.h */ +/* + * Variables declared in the core backend and referenced by loadable + * modules need to be marked "dllimport" in the core build, but + * "dllexport" when the declaration is read in a loadable module. + * No special markings should be used when compiling frontend code. + */ +#ifndef FRONTEND #ifdef BUILDING_DLL #define PGDLLIMPORT __declspec (dllexport) #else #define PGDLLIMPORT __declspec (dllimport) #endif - -#define PGDLLEXPORT +#endif /* * Cygwin has a strtof() which is literally just (float)strtod(), which means diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h index 7dd7fef4f74..d5078b54b30 100644 --- a/src/include/port/pg_bitutils.h +++ b/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 diff --git a/src/include/port/win32.h b/src/include/port/win32.h index d8ae49e22d1..c6213c77c3a 100644 --- a/src/include/port/win32.h +++ b/src/include/port/win32.h @@ -45,16 +45,26 @@ * defines for dynamic linking on Win32 platform */ +/* + * Variables declared in the core backend and referenced by loadable + * modules need to be marked "dllimport" in the core build, but + * "dllexport" when the declaration is read in a loadable module. + * No special markings should be used when compiling frontend code. + */ +#ifndef FRONTEND #ifdef BUILDING_DLL #define PGDLLIMPORT __declspec (dllexport) #else #define PGDLLIMPORT __declspec (dllimport) #endif +#endif +/* + * Under MSVC, functions exported by a loadable module must be marked + * "dllexport". Other compilers don't need that. + */ #ifdef _MSC_VER #define PGDLLEXPORT __declspec (dllexport) -#else -#define PGDLLEXPORT #endif /*