Skip to content

Commit e04a805

Browse files
committed
Simplify declaring variables exported from libpgcommon and libpgport.
This reverts commits c2d1eea and 11b5000, 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/[email protected]
1 parent 11b5000 commit e04a805

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

src/include/c.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -1312,10 +1312,22 @@ extern long long strtoll(const char *str, char **endptr, int base);
13121312
extern unsigned long long strtoull(const char *str, char **endptr, int base);
13131313
#endif
13141314

1315-
/* no special DLL markers on most ports */
1315+
/*
1316+
* Use "extern PGDLLIMPORT ..." to declare variables that are defined
1317+
* in the core backend and need to be accessible by loadable modules.
1318+
* No special marking is required on most ports.
1319+
*/
13161320
#ifndef PGDLLIMPORT
13171321
#define PGDLLIMPORT
13181322
#endif
1323+
1324+
/*
1325+
* Use "extern PGDLLEXPORT ..." to declare functions that are defined in
1326+
* loadable modules and need to be callable by the core backend. (Usually,
1327+
* this is not necessary because our build process automatically exports
1328+
* such symbols, but sometimes manual marking is required.)
1329+
* No special marking is required on most ports.
1330+
*/
13191331
#ifndef PGDLLEXPORT
13201332
#define PGDLLEXPORT
13211333
#endif

src/include/common/keywords.h

-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@
2222
#define TYPE_FUNC_NAME_KEYWORD 2
2323
#define RESERVED_KEYWORD 3
2424

25-
#ifndef FRONTEND
2625
extern PGDLLIMPORT const ScanKeywordList ScanKeywords;
2726
extern PGDLLIMPORT const uint8 ScanKeywordCategories[];
2827
extern PGDLLIMPORT const bool ScanKeywordBareLabel[];
29-
#else
30-
extern const ScanKeywordList ScanKeywords;
31-
extern const uint8 ScanKeywordCategories[];
32-
extern const bool ScanKeywordBareLabel[];
33-
#endif
3428

3529
#endif /* KEYWORDS_H */

src/include/common/pg_prng.h

-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ typedef struct pg_prng_state
2626
* Callers not needing local PRNG series may use this global state vector,
2727
* after initializing it with one of the pg_prng_...seed functions.
2828
*/
29-
#ifndef FRONTEND
3029
extern PGDLLIMPORT pg_prng_state pg_global_prng_state;
31-
#else
32-
extern pg_prng_state pg_global_prng_state;
33-
#endif
3430

3531
extern void pg_prng_seed(pg_prng_state *state, uint64 seed);
3632
extern void pg_prng_fseed(pg_prng_state *state, double fseed);

src/include/port/cygwin.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
/* src/include/port/cygwin.h */
22

3+
/*
4+
* Variables declared in the core backend and referenced by loadable
5+
* modules need to be marked "dllimport" in the core build, but
6+
* "dllexport" when the declaration is read in a loadable module.
7+
* No special markings should be used when compiling frontend code.
8+
*/
9+
#ifndef FRONTEND
310
#ifdef BUILDING_DLL
411
#define PGDLLIMPORT __declspec (dllexport)
512
#else
613
#define PGDLLIMPORT __declspec (dllimport)
714
#endif
8-
9-
#define PGDLLEXPORT
15+
#endif
1016

1117
/*
1218
* Cygwin has a strtof() which is literally just (float)strtod(), which means

src/include/port/pg_bitutils.h

-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313
#ifndef PG_BITUTILS_H
1414
#define PG_BITUTILS_H
1515

16-
#ifndef FRONTEND
1716
extern PGDLLIMPORT const uint8 pg_leftmost_one_pos[256];
1817
extern PGDLLIMPORT const uint8 pg_rightmost_one_pos[256];
1918
extern PGDLLIMPORT const uint8 pg_number_of_ones[256];
20-
#else
21-
extern const uint8 pg_leftmost_one_pos[256];
22-
extern const uint8 pg_rightmost_one_pos[256];
23-
extern const uint8 pg_number_of_ones[256];
24-
#endif
2519

2620
/*
2721
* pg_leftmost_one_pos32

src/include/port/win32.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,26 @@
4545
* defines for dynamic linking on Win32 platform
4646
*/
4747

48+
/*
49+
* Variables declared in the core backend and referenced by loadable
50+
* modules need to be marked "dllimport" in the core build, but
51+
* "dllexport" when the declaration is read in a loadable module.
52+
* No special markings should be used when compiling frontend code.
53+
*/
54+
#ifndef FRONTEND
4855
#ifdef BUILDING_DLL
4956
#define PGDLLIMPORT __declspec (dllexport)
5057
#else
5158
#define PGDLLIMPORT __declspec (dllimport)
5259
#endif
60+
#endif
5361

62+
/*
63+
* Under MSVC, functions exported by a loadable module must be marked
64+
* "dllexport". Other compilers don't need that.
65+
*/
5466
#ifdef _MSC_VER
5567
#define PGDLLEXPORT __declspec (dllexport)
56-
#else
57-
#define PGDLLEXPORT
5868
#endif
5969

6070
/*

0 commit comments

Comments
 (0)