Avoid direct cross-module links in hstore_plperl and ltree_plpython, too.
authorTom Lane <[email protected]>
Tue, 4 Oct 2016 21:49:07 +0000 (17:49 -0400)
committerTom Lane <[email protected]>
Tue, 4 Oct 2016 21:49:07 +0000 (17:49 -0400)
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>

contrib/hstore_plperl/Makefile
contrib/hstore_plperl/hstore_plperl--1.0.sql
contrib/hstore_plperl/hstore_plperl.c
contrib/hstore_plperl/hstore_plperlu--1.0.sql
contrib/ltree_plpython/Makefile
contrib/ltree_plpython/ltree_plpython.c
contrib/ltree_plpython/ltree_plpython2u--1.0.sql
contrib/ltree_plpython/ltree_plpython3u--1.0.sql
contrib/ltree_plpython/ltree_plpythonu--1.0.sql
src/tools/msvc/Mkvcbuild.pm

index b3b8654bc80d068528002452a3bba66da3efc7c1..41d34357f9d9786e170739ce12814c1303a2bdfa 100644 (file)
@@ -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
index 9a64fcb18be860716be345cd30abcc3fa2a8f784..af743c873350856f60d33e9e663f16b6581f9e13 100644 (file)
@@ -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';
index d40a792730779c4b443ef0c0b356f3daf315c01f..480212f341e247ffa4010cea29e83be4f3fe1545 100644 (file)
@@ -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);
 
index f3552849075b90a02f9a14992dcc44fb2e131a90..7c3bc86eba965175776ef654f7555e68e89209ff 100644 (file)
@@ -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';
index 08186f19a139e22ad753452709898646e4edc116..c45b7c2b09789828e95fc961d200c23851478314 100644 (file)
@@ -4,7 +4,7 @@ MODULE_big = ltree_plpython$(python_majorversion)
 OBJS = ltree_plpython.o $(WIN32RES)
 PGFILEDESC = "ltree_plpython - ltree transform for plpython"
 
-PG_CPPFLAGS = -I$(top_srcdir)/src/pl/plpython $(python_includespec) -I$(top_srcdir)/contrib/ltree
+PG_CPPFLAGS = -I$(top_srcdir)/src/pl/plpython $(python_includespec) -I$(top_srcdir)/contrib/ltree -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"'
 
 EXTENSION = ltree_plpythonu ltree_plpython2u ltree_plpython3u
 DATA = ltree_plpythonu--1.0.sql ltree_plpython2u--1.0.sql ltree_plpython3u--1.0.sql
@@ -23,19 +23,18 @@ 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 libpython explicitly
 ifeq ($(PORTNAME), aix)
 rpathdir = $(pkglibdir):$(python_libdir)
-SHLIB_LINK += $(python_libspec) $(python_additional_libs) $(sort $(wildcard ../../src/pl/plpython/libplpython*.exp))
-endif
+SHLIB_LINK += $(python_libspec) $(python_additional_libs)
+else
 ifeq ($(PORTNAME), win32)
-SHLIB_LINK += $(sort $(wildcard ../../src/pl/plpython/libpython*.a)) $(sort $(wildcard ../../src/pl/plpython/libplpython*.a))
+# ... see silliness in plpython Makefile ...
+SHLIB_LINK += $(sort $(wildcard ../../src/pl/plpython/libpython*.a))
+else
+rpathdir = $(python_libdir)
+SHLIB_LINK += $(python_libspec)
 endif
-
-ifeq ($(PORTNAME), cygwin)
-SHLIB_LINK += -L../ltree -lltree -L../../src/pl/plpython \
-       -lplpython$(python_majorversion) $(python_libspec)
 endif
 
 REGRESS_OPTS += --load-extension=ltree
index 26b7b3c275d8875d9c2092bfc43f5e62510df76d..bdd462a91b9c15d160de92f001542846cdb1e860 100644 (file)
@@ -1,10 +1,39 @@
 #include "postgres.h"
+
 #include "fmgr.h"
 #include "plpython.h"
 #include "ltree.h"
 
 PG_MODULE_MAGIC;
 
+extern void _PG_init(void);
+
+/* Linkage to functions in plpython module */
+#if PY_MAJOR_VERSION >= 3
+typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
+static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
+#endif
+
+
+/*
+ * Module initialize function: fetch function pointers for cross-module calls.
+ */
+void
+_PG_init(void)
+{
+       /* Asserts verify that typedefs above match original declarations */
+#if PY_MAJOR_VERSION >= 3
+       AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
+       PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
+               load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
+                                                          true, NULL);
+#endif
+}
+
+
+/* These defines must be after the module init function */
+#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
+
 
 PG_FUNCTION_INFO_V1(ltree_to_plpython);
 
index 62531371bf9032dfa4239b3fb20af05fd8323c8d..5c4a7037013e6a3a6aba587e22fd7f2389885ab5 100644 (file)
@@ -3,11 +3,6 @@
 -- complain if script is sourced in psql, rather than via CREATE EXTENSION
 \echo Use "CREATE EXTENSION ltree_plpython2u" to load this file. \quit
 
--- make sure the prerequisite libraries are loaded
-LOAD 'plpython2';
-SELECT NULL::ltree;
-
-
 CREATE FUNCTION ltree_to_plpython2(val internal) RETURNS internal
 LANGUAGE C STRICT IMMUTABLE
 AS 'MODULE_PATHNAME', 'ltree_to_plpython';
index 3f21d1b721042e54ba32f979592de8f9fd45556d..09ada3c7e8b701393aca79123edec4f3362bdce4 100644 (file)
@@ -3,11 +3,6 @@
 -- complain if script is sourced in psql, rather than via CREATE EXTENSION
 \echo Use "CREATE EXTENSION ltree_plpython3u" to load this file. \quit
 
--- make sure the prerequisite libraries are loaded
-LOAD 'plpython3';
-SELECT NULL::ltree;
-
-
 CREATE FUNCTION ltree_to_plpython3(val internal) RETURNS internal
 LANGUAGE C STRICT IMMUTABLE
 AS 'MODULE_PATHNAME', 'ltree_to_plpython';
index e8deadc62d00ab10b4e973f00814fc3415e91e9a..ee93edf28b964be2d897f1aa7628b24f66fdf05c 100644 (file)
@@ -3,11 +3,6 @@
 -- complain if script is sourced in psql, rather than via CREATE EXTENSION
 \echo Use "CREATE EXTENSION ltree_plpythonu" to load this file. \quit
 
--- make sure the prerequisite libraries are loaded
-LOAD 'plpython2';  -- change to plpython3 if that ever becomes the default
-SELECT NULL::ltree;
-
-
 CREATE FUNCTION ltree_to_plpython(val internal) RETURNS internal
 LANGUAGE C STRICT IMMUTABLE
 AS 'MODULE_PATHNAME';
index d2ab9e466ef2f259565121463fb90246875a8bdb..de764dd4d44b28a37e18357f1ce99544a43cceff 100644 (file)
@@ -480,10 +480,11 @@ sub mkvcbuild
                        'plpython' . $pymajorver,        'src/pl/plpython',
                        'hstore',                        'contrib/hstore');
                $hstore_plpython->AddDefine('PLPYTHON_LIBNAME="plpython' . $pymajorver . '"');
-               AddTransformModule(
+               my $ltree_plpython = AddTransformModule(
                        'ltree_plpython' . $pymajorver, 'contrib/ltree_plpython',
                        'plpython' . $pymajorver,       'src/pl/plpython',
                        'ltree',                        'contrib/ltree');
+               $ltree_plpython->AddDefine('PLPYTHON_LIBNAME="plpython' . $pymajorver . '"');
        }
 
        if ($solution->{options}->{perl})