Simplify declaring variables exported from libpgcommon and libpgport.
authorTom Lane <[email protected]>
Mon, 29 Nov 2021 16:00:00 +0000 (11:00 -0500)
committerTom Lane <[email protected]>
Mon, 29 Nov 2021 16:00:00 +0000 (11:00 -0500)
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
src/include/common/keywords.h
src/include/common/pg_prng.h
src/include/port/cygwin.h
src/include/port/pg_bitutils.h
src/include/port/win32.h

index c8ede0827396dd8e4e91d2e0a9bf28d62919014f..7e591171a84c27d1299da97e56b10a5acf8064c6 100644 (file)
@@ -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
index 19e4eda8f9e57350d633675c4130e58cea580c47..d2e94e13d29421c957532a95e07405f0f9bf086e 100644 (file)
 #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 */
index e4df5165d7e3858cc74fbfc5d5e3fe990f057105..623c65ae731dc02874ec71ff718b7561ee65fc2e 100644 (file)
@@ -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);
index 64d69936e5e02b25c8227031510afab035fba43f..44bf8533729cc6c4d214a8c637c2f1e6d5b171ed 100644 (file)
@@ -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
index 7dd7fef4f7447b93d082e277f64682a89c270e3f..d5078b54b3019635371a203814b0ea2df043464c 100644 (file)
 #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
index d8ae49e22d1042e182146fd4d93d84affef75fad..c6213c77c3aee8e239de6a7c2ec0fed5140ef9ae 100644 (file)
  * 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
 
 /*