1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

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
This commit is contained in:
Tom Lane 2021-11-29 11:00:00 -05:00
parent 11b500072e
commit e04a8059a7
6 changed files with 33 additions and 21 deletions

View 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

View File

@ -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 */

View 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);

View 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

View File

@ -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

View File

@ -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
/*