aboutsummaryrefslogtreecommitdiff
path: root/contrib/hstore_plperl
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-10-04 17:49:07 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-10-04 17:49:07 -0400
commiteda04886c1e048d695728206504ab4198462168e (patch)
tree30501f4583bd1b5ecf7dd990dd15d16a9f889b9c /contrib/hstore_plperl
parentfc76259f5b8473dbd3d2009b0e4a267cf3a7e704 (diff)
downloadpostgresql-eda04886c1e048d695728206504ab4198462168e.tar.gz
postgresql-eda04886c1e048d695728206504ab4198462168e.zip
Avoid direct cross-module links in hstore_plperl and ltree_plpython, too.
Just turning the crank on the project started in commit d51924be8. These cases turn out to be exact subsets of the boilerplate needed for hstore_plpython. Discussion: <2652.1475512158@sss.pgh.pa.us>
Diffstat (limited to 'contrib/hstore_plperl')
-rw-r--r--contrib/hstore_plperl/Makefile16
-rw-r--r--contrib/hstore_plperl/hstore_plperl--1.0.sql5
-rw-r--r--contrib/hstore_plperl/hstore_plperl.c54
-rw-r--r--contrib/hstore_plperl/hstore_plperlu--1.0.sql5
4 files changed, 62 insertions, 18 deletions
diff --git a/contrib/hstore_plperl/Makefile b/contrib/hstore_plperl/Makefile
index b3b8654bc80..41d34357f9d 100644
--- a/contrib/hstore_plperl/Makefile
+++ b/contrib/hstore_plperl/Makefile
@@ -23,20 +23,20 @@ include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
-# In configurations that forbid undefined symbols in libraries, link with each
-# dependency. This does preclude pgxs builds.
+# We must link libperl explicitly
ifeq ($(PORTNAME), aix)
rpathdir = $(pkglibdir):$(perl_archlibexp)/CORE
-SHLIB_LINK += ../hstore/libhstore.exp $(perl_embed_ldflags)
-endif
+SHLIB_LINK += $(perl_embed_ldflags)
+else
ifeq ($(PORTNAME), win32)
# these settings are the same as for plperl
override CPPFLAGS += -DPLPERL_HAVE_UID_GID -Wno-comment
-SHLIB_LINK += ../hstore/libhstore.a $(sort $(wildcard ../../src/pl/plperl/libperl*.a))
+# ... see silliness in plperl Makefile ...
+SHLIB_LINK += $(sort $(wildcard ../../src/pl/plperl/libperl*.a))
+else
+rpathdir = $(perl_archlibexp)/CORE
+SHLIB_LINK += $(perl_embed_ldflags)
endif
-
-ifeq ($(PORTNAME), cygwin)
-SHLIB_LINK += -L../hstore -l hstore $(perl_embed_ldflags)
endif
# As with plperl we need to make sure that the CORE directory is included
diff --git a/contrib/hstore_plperl/hstore_plperl--1.0.sql b/contrib/hstore_plperl/hstore_plperl--1.0.sql
index 9a64fcb18be..af743c87335 100644
--- a/contrib/hstore_plperl/hstore_plperl--1.0.sql
+++ b/contrib/hstore_plperl/hstore_plperl--1.0.sql
@@ -3,11 +3,6 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hstore_plperl" to load this file. \quit
--- make sure the prerequisite libraries are loaded
-LOAD 'plperl';
-SELECT NULL::hstore;
-
-
CREATE FUNCTION hstore_to_plperl(val internal) RETURNS internal
LANGUAGE C STRICT IMMUTABLE
AS 'MODULE_PATHNAME';
diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c
index d40a7927307..480212f341e 100644
--- a/contrib/hstore_plperl/hstore_plperl.c
+++ b/contrib/hstore_plperl/hstore_plperl.c
@@ -1,5 +1,7 @@
#include "postgres.h"
+
#undef _
+
#include "fmgr.h"
#include "plperl.h"
#include "plperl_helpers.h"
@@ -7,6 +9,58 @@
PG_MODULE_MAGIC;
+extern void _PG_init(void);
+
+/* Linkage to functions in hstore module */
+typedef HStore *(*hstoreUpgrade_t) (Datum orig);
+static hstoreUpgrade_t hstoreUpgrade_p;
+typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, int32 *buflen);
+static hstoreUniquePairs_t hstoreUniquePairs_p;
+typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, int32 buflen);
+static hstorePairs_t hstorePairs_p;
+typedef size_t (*hstoreCheckKeyLen_t) (size_t len);
+static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
+typedef size_t (*hstoreCheckValLen_t) (size_t len);
+static hstoreCheckValLen_t hstoreCheckValLen_p;
+
+
+/*
+ * Module initialize function: fetch function pointers for cross-module calls.
+ */
+void
+_PG_init(void)
+{
+ /* Asserts verify that typedefs above match original declarations */
+ AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
+ hstoreUpgrade_p = (hstoreUpgrade_t)
+ load_external_function("$libdir/hstore", "hstoreUpgrade",
+ true, NULL);
+ AssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
+ hstoreUniquePairs_p = (hstoreUniquePairs_t)
+ load_external_function("$libdir/hstore", "hstoreUniquePairs",
+ true, NULL);
+ AssertVariableIsOfType(&hstorePairs, hstorePairs_t);
+ hstorePairs_p = (hstorePairs_t)
+ load_external_function("$libdir/hstore", "hstorePairs",
+ true, NULL);
+ AssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
+ hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
+ load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
+ true, NULL);
+ AssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
+ hstoreCheckValLen_p = (hstoreCheckValLen_t)
+ load_external_function("$libdir/hstore", "hstoreCheckValLen",
+ true, NULL);
+}
+
+
+/* These defines must be after the module init function */
+#define hstoreUpgrade hstoreUpgrade_p
+#define hstoreUniquePairs hstoreUniquePairs_p
+#define hstorePairs hstorePairs_p
+#define hstoreCheckKeyLen hstoreCheckKeyLen_p
+#define hstoreCheckValLen hstoreCheckValLen_p
+
PG_FUNCTION_INFO_V1(hstore_to_plperl);
diff --git a/contrib/hstore_plperl/hstore_plperlu--1.0.sql b/contrib/hstore_plperl/hstore_plperlu--1.0.sql
index f3552849075..7c3bc86eba9 100644
--- a/contrib/hstore_plperl/hstore_plperlu--1.0.sql
+++ b/contrib/hstore_plperl/hstore_plperlu--1.0.sql
@@ -3,11 +3,6 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hstore_plperlu" to load this file. \quit
--- make sure the prerequisite libraries are loaded
-LOAD 'plperl';
-SELECT NULL::hstore;
-
-
CREATE FUNCTION hstore_to_plperlu(val internal) RETURNS internal
LANGUAGE C STRICT IMMUTABLE
AS 'MODULE_PATHNAME', 'hstore_to_plperl';