From 207ff8aca4a74af2756c6a345286ebecd139d759 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 30 Aug 2016 12:00:00 -0400 Subject: [PATCH v2 19/23] Add C linkage to functions exported by plugins This is required so dlsym() can find them reliably. --- contrib/auth_delay/auth_delay.c | 2 +- contrib/auto_explain/auto_explain.c | 4 ++-- contrib/bloom/bloom.h | 2 +- contrib/earthdistance/earthdistance.c | 2 +- contrib/hstore/hstore.h | 8 +++++--- contrib/hstore_plperl/hstore_plperl.c | 2 +- contrib/hstore_plpython/hstore_plpython.c | 2 +- contrib/ltree/ltree.h | 2 ++ contrib/ltree_plpython/ltree_plpython.c | 2 +- contrib/passwordcheck/passwordcheck.c | 2 +- contrib/pg_stat_statements/pg_stat_statements.c | 2 ++ contrib/pg_trgm/trgm_op.c | 2 +- contrib/seg/seg.c | 6 ++++++ contrib/sepgsql/hooks.c | 2 +- contrib/test_decoding/test_decoding.c | 4 ++-- src/backend/replication/libpqwalreceiver/libpqwalreceiver.c | 2 +- src/backend/replication/pgoutput/pgoutput.c | 2 +- src/include/fmgr.h | 6 +++--- src/pl/plperl/plperl.c | 2 ++ src/pl/plpgsql/src/plpgsql.h | 2 +- src/pl/plpython/plpy_main.c | 2 ++ src/pl/plpython/plpy_typeio.h | 2 +- src/pl/tcl/pltcl.c | 2 ++ src/test/modules/dummy_seclabel/dummy_seclabel.c | 2 +- src/test/modules/test_rls_hooks/test_rls_hooks.c | 2 ++ src/test/modules/test_shm_mq/test.c | 2 +- src/test/modules/test_shm_mq/test_shm_mq.h | 2 +- src/test/modules/worker_spi/worker_spi.c | 2 +- src/test/regress/regress.c | 8 +++++--- 29 files changed, 52 insertions(+), 30 deletions(-) diff --git a/contrib/auth_delay/auth_delay.c b/contrib/auth_delay/auth_delay.c index e0604fb808..7eae401403 100644 --- a/contrib/auth_delay/auth_delay.c +++ b/contrib/auth_delay/auth_delay.c @@ -20,7 +20,7 @@ PG_MODULE_MAGIC; -void _PG_init(void); +extern "C" void _PG_init(void); /* GUC Variables */ static int auth_delay_milliseconds; diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c index 34b9f1543e..319c7a9c7b 100644 --- a/contrib/auto_explain/auto_explain.c +++ b/contrib/auto_explain/auto_explain.c @@ -55,8 +55,8 @@ static bool current_query_sampled = true; (auto_explain_log_min_duration >= 0 && \ (nesting_level == 0 || auto_explain_log_nested_statements)) -void _PG_init(void); -void _PG_fini(void); +extern "C" void _PG_init(void); +extern "C" void _PG_fini(void); static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags); static void explain_ExecutorRun(QueryDesc *queryDesc, diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h index 0cfe49aad8..d4ab749e95 100644 --- a/contrib/bloom/bloom.h +++ b/contrib/bloom/bloom.h @@ -173,7 +173,7 @@ typedef struct BloomScanOpaqueData typedef BloomScanOpaqueData *BloomScanOpaque; /* blutils.c */ -extern void _PG_init(void); +extern "C" void _PG_init(void); extern void initBloomState(BloomState *state, Relation index); extern void BloomFillMetapage(Relation index, Page metaPage); extern void BloomInitMetapage(Relation index); diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c index 861b166373..305be5d932 100644 --- a/contrib/earthdistance/earthdistance.c +++ b/contrib/earthdistance/earthdistance.c @@ -112,7 +112,7 @@ geo_distance(PG_FUNCTION_ARGS) } #else /* !USE_FLOAT8_BYVAL */ -double *geo_distance(Point *pt1, Point *pt2); +extern "C" double *geo_distance(Point *pt1, Point *pt2); double * geo_distance(Point *pt1, Point *pt2) diff --git a/contrib/hstore/hstore.h b/contrib/hstore/hstore.h index fbedc971c0..323faa4b8c 100644 --- a/contrib/hstore/hstore.h +++ b/contrib/hstore/hstore.h @@ -147,7 +147,7 @@ typedef struct } while (0) /* DatumGetHStoreP includes support for reading old-format hstore values */ -extern HStore *hstoreUpgrade(Datum orig); +extern "C" HStore *hstoreUpgrade(Datum orig); #define DatumGetHStoreP(d) hstoreUpgrade(d) @@ -168,6 +168,7 @@ typedef struct bool needfree; /* need to pfree the value? */ } Pairs; +extern "C" { extern int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen); extern HStore *hstorePairs(Pairs *pairs, int32 pcount, int32 buflen); @@ -176,6 +177,7 @@ extern size_t hstoreCheckValLen(size_t len); extern int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen); extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs); +} #define HStoreContainsStrategyNumber 7 #define HStoreExistsStrategyNumber 9 @@ -194,8 +196,8 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs); #if HSTORE_POLLUTE_NAMESPACE #define HSTORE_POLLUTE(newname_,oldname_) \ PG_FUNCTION_INFO_V1(oldname_); \ - Datum newname_(PG_FUNCTION_ARGS); \ - Datum oldname_(PG_FUNCTION_ARGS) { return newname_(fcinfo); } \ + extern "C" Datum newname_(PG_FUNCTION_ARGS); \ + extern "C" Datum oldname_(PG_FUNCTION_ARGS) { return newname_(fcinfo); } \ extern int no_such_variable #else #define HSTORE_POLLUTE(newname_,oldname_) \ diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c index 480212f341..be252e4b7e 100644 --- a/contrib/hstore_plperl/hstore_plperl.c +++ b/contrib/hstore_plperl/hstore_plperl.c @@ -9,7 +9,7 @@ PG_MODULE_MAGIC; -extern void _PG_init(void); +extern "C" void _PG_init(void); /* Linkage to functions in hstore module */ typedef HStore *(*hstoreUpgrade_t) (Datum orig); diff --git a/contrib/hstore_plpython/hstore_plpython.c b/contrib/hstore_plpython/hstore_plpython.c index b184324ebf..d9cf139a97 100644 --- a/contrib/hstore_plpython/hstore_plpython.c +++ b/contrib/hstore_plpython/hstore_plpython.c @@ -7,7 +7,7 @@ PG_MODULE_MAGIC; -extern void _PG_init(void); +extern "C" void _PG_init(void); /* Linkage to functions in plpython module */ typedef char *(*PLyObject_AsString_t) (PyObject *plrv); diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h index c604357dbf..277b9a4206 100644 --- a/contrib/ltree/ltree.h +++ b/contrib/ltree/ltree.h @@ -130,6 +130,7 @@ typedef struct /* use in array iterator */ +extern "C" { Datum ltree_isparent(PG_FUNCTION_ARGS); Datum ltree_risparent(PG_FUNCTION_ARGS); Datum ltq_regex(PG_FUNCTION_ARGS); @@ -154,6 +155,7 @@ Datum ltree_textadd(PG_FUNCTION_ARGS); /* Util function */ Datum ltree_in(PG_FUNCTION_ARGS); +} bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *val)); diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c index bdd462a91b..0bedf005ae 100644 --- a/contrib/ltree_plpython/ltree_plpython.c +++ b/contrib/ltree_plpython/ltree_plpython.c @@ -6,7 +6,7 @@ PG_MODULE_MAGIC; -extern void _PG_init(void); +extern "C" void _PG_init(void); /* Linkage to functions in plpython module */ #if PY_MAJOR_VERSION >= 3 diff --git a/contrib/passwordcheck/passwordcheck.c b/contrib/passwordcheck/passwordcheck.c index c988bf5169..7fa530284a 100644 --- a/contrib/passwordcheck/passwordcheck.c +++ b/contrib/passwordcheck/passwordcheck.c @@ -29,7 +29,7 @@ PG_MODULE_MAGIC; /* passwords shorter than this will be rejected */ #define MIN_PWD_LENGTH 8 -extern void _PG_init(void); +extern "C" void _PG_init(void); /* * check_password diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index bda5ec61ed..bbd926eb10 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -276,8 +276,10 @@ static bool pgss_save; /* whether to save stats across shutdown */ /*---- Function declarations ----*/ +extern "C" { void _PG_init(void); void _PG_fini(void); +} PG_FUNCTION_INFO_V1(pg_stat_statements_reset); PG_FUNCTION_INFO_V1(pg_stat_statements_1_2); diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c index 368e7c8941..654b5c4644 100644 --- a/contrib/pg_trgm/trgm_op.c +++ b/contrib/pg_trgm/trgm_op.c @@ -19,7 +19,7 @@ PG_MODULE_MAGIC; double similarity_threshold = 0.3f; double word_similarity_threshold = 0.6f; -void _PG_init(void); +extern "C" void _PG_init(void); PG_FUNCTION_INFO_V1(set_limit); PG_FUNCTION_INFO_V1(show_limit); diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c index 895d879498..b98de5f66c 100644 --- a/contrib/seg/seg.c +++ b/contrib/seg/seg.c @@ -47,6 +47,7 @@ PG_FUNCTION_INFO_V1(seg_center); /* ** GiST support methods */ +extern "C" { bool gseg_consistent(GISTENTRY *entry, SEG *query, StrategyNumber strategy, @@ -61,11 +62,13 @@ bool gseg_internal_consistent(SEG *key, SEG *query, StrategyNumber strategy); SEG *gseg_union(GistEntryVector *entryvec, int *sizep); SEG *gseg_binary_union(SEG *r1, SEG *r2, int *sizep); bool *gseg_same(SEG *b1, SEG *b2, bool *result); +} /* ** R-tree support functions */ +extern "C" { bool seg_same(SEG *a, SEG *b); bool seg_contains_int(SEG *a, int *b); bool seg_contains_float4(SEG *a, float4 *b); @@ -80,16 +83,19 @@ bool seg_over_right(SEG *a, SEG *b); SEG *seg_union(SEG *a, SEG *b); SEG *seg_inter(SEG *a, SEG *b); void rt_seg_size(SEG *a, float *sz); +} /* ** Various operators */ +extern "C" { int32 seg_cmp(SEG *a, SEG *b); bool seg_lt(SEG *a, SEG *b); bool seg_le(SEG *a, SEG *b); bool seg_gt(SEG *a, SEG *b); bool seg_ge(SEG *a, SEG *b); bool seg_different(SEG *a, SEG *b); +} /* ** Auxiliary funxtions diff --git a/contrib/sepgsql/hooks.c b/contrib/sepgsql/hooks.c index 93cc8debaa..f80826f23f 100644 --- a/contrib/sepgsql/hooks.c +++ b/contrib/sepgsql/hooks.c @@ -30,7 +30,7 @@ PG_MODULE_MAGIC; /* * Declarations */ -void _PG_init(void); +extern "C" void _PG_init(void); /* * Saved hook entries (if stacked) diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c index 21cfd673c6..df81fb5a54 100644 --- a/contrib/test_decoding/test_decoding.c +++ b/contrib/test_decoding/test_decoding.c @@ -35,8 +35,8 @@ PG_MODULE_MAGIC; /* These must be available to pg_dlsym() */ -extern void _PG_init(void); -extern void _PG_output_plugin_init(OutputPluginCallbacks *cb); +extern "C" void _PG_init(void); +extern "C" void _PG_output_plugin_init(OutputPluginCallbacks *cb); typedef struct { diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index daae3f70e7..239f250790 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -33,7 +33,7 @@ PG_MODULE_MAGIC; -void _PG_init(void); +extern "C" void _PG_init(void); struct WalReceiverConn { diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 0ceb4be375..b83889eb70 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -27,7 +27,7 @@ PG_MODULE_MAGIC; -extern void _PG_output_plugin_init(OutputPluginCallbacks *cb); +extern "C" void _PG_output_plugin_init(OutputPluginCallbacks *cb); static void pgoutput_startup(LogicalDecodingContext * ctx, OutputPluginOptions *opt, bool is_init); diff --git a/src/include/fmgr.h b/src/include/fmgr.h index a671480004..8f1eccfb88 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -355,8 +355,8 @@ typedef const Pg_finfo_record *(*PGFInfoFunction) (void); * info function, since authors shouldn't need to be explicitly aware of it. */ #define PG_FUNCTION_INFO_V1(funcname) \ -extern Datum funcname(PG_FUNCTION_ARGS); \ -extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \ +extern "C" Datum funcname(PG_FUNCTION_ARGS); \ +extern "C" PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \ const Pg_finfo_record * \ CppConcat(pg_finfo_,funcname) (void) \ { \ @@ -425,7 +425,7 @@ typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void); #define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func" #define PG_MODULE_MAGIC \ -extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \ +extern "C" PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \ const Pg_magic_struct * \ PG_MAGIC_FUNCTION_NAME(void) \ { \ diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 00979cba74..e07ad0d321 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -246,7 +246,9 @@ static plperl_call_data *current_call_data = NULL; /********************************************************************** * Forward declarations **********************************************************************/ +extern "C" { void _PG_init(void); +} static PerlInterpreter *plperl_init_interp(void); static void plperl_destroy_interp(PerlInterpreter **); diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h index 2193a95f71..ee5982e3c8 100644 --- a/src/pl/plpgsql/src/plpgsql.h +++ b/src/pl/plpgsql/src/plpgsql.h @@ -1085,7 +1085,7 @@ extern void plpgsql_HashTableInit(void); /* * Functions in pl_handler.c */ -extern void _PG_init(void); +extern "C" void _PG_init(void); /* * Functions in pl_exec.c diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c index 860b804e54..efd3bf0002 100644 --- a/src/pl/plpython/plpy_main.c +++ b/src/pl/plpython/plpy_main.c @@ -39,7 +39,9 @@ #define plpython_inline_handler plpython3_inline_handler #endif +extern "C" { extern void _PG_init(void); +} PG_MODULE_MAGIC; diff --git a/src/pl/plpython/plpy_typeio.h b/src/pl/plpython/plpy_typeio.h index e04722c47a..0793927fff 100644 --- a/src/pl/plpython/plpy_typeio.h +++ b/src/pl/plpython/plpy_typeio.h @@ -117,6 +117,6 @@ extern Datum PLyObject_ToCompositeDatum(PLyTypeInfo *info, TupleDesc desc, PyObj extern PyObject *PLyDict_FromTuple(PLyTypeInfo *info, HeapTuple tuple, TupleDesc desc); /* conversion from Python objects to C strings */ -extern char *PLyObject_AsString(PyObject *plrv); +extern "C" char *PLyObject_AsString(PyObject *plrv); #endif /* PLPY_TYPEIO_H */ diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 11faa6defe..c3cbd6f69f 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -251,7 +251,9 @@ static const TclExceptionNameMap exception_name_map[] = { /********************************************************************** * Forward declarations **********************************************************************/ +extern "C" { void _PG_init(void); +} static void pltcl_init_interp(pltcl_interp_desc *interp_desc, bool pltrusted); static pltcl_interp_desc *pltcl_fetch_interp(bool pltrusted); diff --git a/src/test/modules/dummy_seclabel/dummy_seclabel.c b/src/test/modules/dummy_seclabel/dummy_seclabel.c index 7fd78f05c7..fdeeb3325b 100644 --- a/src/test/modules/dummy_seclabel/dummy_seclabel.c +++ b/src/test/modules/dummy_seclabel/dummy_seclabel.c @@ -19,7 +19,7 @@ PG_MODULE_MAGIC; /* Entrypoint of the module */ -void _PG_init(void); +extern "C" void _PG_init(void); PG_FUNCTION_INFO_V1(dummy_seclabel_dummy); diff --git a/src/test/modules/test_rls_hooks/test_rls_hooks.c b/src/test/modules/test_rls_hooks/test_rls_hooks.c index 65bf3e33c9..12a782a919 100644 --- a/src/test/modules/test_rls_hooks/test_rls_hooks.c +++ b/src/test/modules/test_rls_hooks/test_rls_hooks.c @@ -35,8 +35,10 @@ PG_MODULE_MAGIC; static row_security_policy_hook_type prev_row_security_policy_hook_permissive = NULL; static row_security_policy_hook_type prev_row_security_policy_hook_restrictive = NULL; +extern "C" { void _PG_init(void); void _PG_fini(void); +} /* Install hooks */ void diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c index ea3657d5f0..167863afe9 100644 --- a/src/test/modules/test_shm_mq/test.c +++ b/src/test/modules/test_shm_mq/test.c @@ -24,7 +24,7 @@ PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(test_shm_mq); PG_FUNCTION_INFO_V1(test_shm_mq_pipelined); -void _PG_init(void); +extern "C" void _PG_init(void); static void verify_message(Size origlen, char *origdata, Size newlen, char *newdata); diff --git a/src/test/modules/test_shm_mq/test_shm_mq.h b/src/test/modules/test_shm_mq/test_shm_mq.h index e76ecab891..cb24007065 100644 --- a/src/test/modules/test_shm_mq/test_shm_mq.h +++ b/src/test/modules/test_shm_mq/test_shm_mq.h @@ -40,6 +40,6 @@ extern void test_shm_mq_setup(int64 queue_size, int32 nworkers, shm_mq_handle **input); /* Main entrypoint for a worker. */ -extern void test_shm_mq_main(Datum) pg_attribute_noreturn(); +extern "C" void test_shm_mq_main(Datum) pg_attribute_noreturn(); #endif diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c index 72ab8464e1..8506a9f621 100644 --- a/src/test/modules/worker_spi/worker_spi.c +++ b/src/test/modules/worker_spi/worker_spi.c @@ -45,7 +45,7 @@ PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(worker_spi_launch); -void _PG_init(void); +extern "C" void _PG_init(void); void worker_spi_main(Datum) pg_attribute_noreturn(); /* flags set by signal handlers */ diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 986d54ce2f..d07514ef55 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -45,8 +45,8 @@ extern PATH *poly2path(POLYGON *poly); extern void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2); -extern char *reverse_name(char *string); -extern int oldstyle_length(int n, text *t); +extern "C" char *reverse_name(char *string); +extern "C" int oldstyle_length(int n, text *t); #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; @@ -240,8 +240,10 @@ typedef struct double radius; } WIDGET; +extern "C" { WIDGET *widget_in(char *str); -char *widget_out(WIDGET *widget); +char *widget_out(WIDGET * widget); +} #define NARGS 3 -- 2.12.0