Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eda0488

Browse files
committed
Avoid direct cross-module links in hstore_plperl and ltree_plpython, too.
Just turning the crank on the project started in commit d51924b. These cases turn out to be exact subsets of the boilerplate needed for hstore_plpython. Discussion: <2652.1475512158@sss.pgh.pa.us>
1 parent fc76259 commit eda0488

10 files changed

+102
-44
lines changed

contrib/hstore_plperl/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ include $(top_builddir)/src/Makefile.global
2323
include $(top_srcdir)/contrib/contrib-global.mk
2424
endif
2525

26-
# In configurations that forbid undefined symbols in libraries, link with each
27-
# dependency. This does preclude pgxs builds.
26+
# We must link libperl explicitly
2827
ifeq ($(PORTNAME), aix)
2928
rpathdir = $(pkglibdir):$(perl_archlibexp)/CORE
30-
SHLIB_LINK += ../hstore/libhstore.exp $(perl_embed_ldflags)
31-
endif
29+
SHLIB_LINK += $(perl_embed_ldflags)
30+
else
3231
ifeq ($(PORTNAME), win32)
3332
# these settings are the same as for plperl
3433
override CPPFLAGS += -DPLPERL_HAVE_UID_GID -Wno-comment
35-
SHLIB_LINK += ../hstore/libhstore.a $(sort $(wildcard ../../src/pl/plperl/libperl*.a))
34+
# ... see silliness in plperl Makefile ...
35+
SHLIB_LINK += $(sort $(wildcard ../../src/pl/plperl/libperl*.a))
36+
else
37+
rpathdir = $(perl_archlibexp)/CORE
38+
SHLIB_LINK += $(perl_embed_ldflags)
3639
endif
37-
38-
ifeq ($(PORTNAME), cygwin)
39-
SHLIB_LINK += -L../hstore -l hstore $(perl_embed_ldflags)
4040
endif
4141

4242
# As with plperl we need to make sure that the CORE directory is included

contrib/hstore_plperl/hstore_plperl--1.0.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION hstore_plperl" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD 'plperl';
8-
SELECT NULL::hstore;
9-
10-
116
CREATE FUNCTION hstore_to_plperl(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS 'MODULE_PATHNAME';

contrib/hstore_plperl/hstore_plperl.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,66 @@
11
#include "postgres.h"
2+
23
#undef _
4+
35
#include "fmgr.h"
46
#include "plperl.h"
57
#include "plperl_helpers.h"
68
#include "hstore.h"
79

810
PG_MODULE_MAGIC;
911

12+
extern void _PG_init(void);
13+
14+
/* Linkage to functions in hstore module */
15+
typedef HStore *(*hstoreUpgrade_t) (Datum orig);
16+
static hstoreUpgrade_t hstoreUpgrade_p;
17+
typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, int32 *buflen);
18+
static hstoreUniquePairs_t hstoreUniquePairs_p;
19+
typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, int32 buflen);
20+
static hstorePairs_t hstorePairs_p;
21+
typedef size_t (*hstoreCheckKeyLen_t) (size_t len);
22+
static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
23+
typedef size_t (*hstoreCheckValLen_t) (size_t len);
24+
static hstoreCheckValLen_t hstoreCheckValLen_p;
25+
26+
27+
/*
28+
* Module initialize function: fetch function pointers for cross-module calls.
29+
*/
30+
void
31+
_PG_init(void)
32+
{
33+
/* Asserts verify that typedefs above match original declarations */
34+
AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
35+
hstoreUpgrade_p = (hstoreUpgrade_t)
36+
load_external_function("$libdir/hstore", "hstoreUpgrade",
37+
true, NULL);
38+
AssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
39+
hstoreUniquePairs_p = (hstoreUniquePairs_t)
40+
load_external_function("$libdir/hstore", "hstoreUniquePairs",
41+
true, NULL);
42+
AssertVariableIsOfType(&hstorePairs, hstorePairs_t);
43+
hstorePairs_p = (hstorePairs_t)
44+
load_external_function("$libdir/hstore", "hstorePairs",
45+
true, NULL);
46+
AssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
47+
hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
48+
load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
49+
true, NULL);
50+
AssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
51+
hstoreCheckValLen_p = (hstoreCheckValLen_t)
52+
load_external_function("$libdir/hstore", "hstoreCheckValLen",
53+
true, NULL);
54+
}
55+
56+
57+
/* These defines must be after the module init function */
58+
#define hstoreUpgrade hstoreUpgrade_p
59+
#define hstoreUniquePairs hstoreUniquePairs_p
60+
#define hstorePairs hstorePairs_p
61+
#define hstoreCheckKeyLen hstoreCheckKeyLen_p
62+
#define hstoreCheckValLen hstoreCheckValLen_p
63+
1064

1165
PG_FUNCTION_INFO_V1(hstore_to_plperl);
1266

contrib/hstore_plperl/hstore_plperlu--1.0.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION hstore_plperlu" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD 'plperl';
8-
SELECT NULL::hstore;
9-
10-
116
CREATE FUNCTION hstore_to_plperlu(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS 'MODULE_PATHNAME', 'hstore_to_plperl';

contrib/ltree_plpython/Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MODULE_big = ltree_plpython$(python_majorversion)
44
OBJS = ltree_plpython.o $(WIN32RES)
55
PGFILEDESC = "ltree_plpython - ltree transform for plpython"
66

7-
PG_CPPFLAGS = -I$(top_srcdir)/src/pl/plpython $(python_includespec) -I$(top_srcdir)/contrib/ltree
7+
PG_CPPFLAGS = -I$(top_srcdir)/src/pl/plpython $(python_includespec) -I$(top_srcdir)/contrib/ltree -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"'
88

99
EXTENSION = ltree_plpythonu ltree_plpython2u ltree_plpython3u
1010
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
2323
include $(top_srcdir)/contrib/contrib-global.mk
2424
endif
2525

26-
# In configurations that forbid undefined symbols in libraries, link with each
27-
# dependency. This does preclude pgxs builds.
26+
# We must link libpython explicitly
2827
ifeq ($(PORTNAME), aix)
2928
rpathdir = $(pkglibdir):$(python_libdir)
30-
SHLIB_LINK += $(python_libspec) $(python_additional_libs) $(sort $(wildcard ../../src/pl/plpython/libplpython*.exp))
31-
endif
29+
SHLIB_LINK += $(python_libspec) $(python_additional_libs)
30+
else
3231
ifeq ($(PORTNAME), win32)
33-
SHLIB_LINK += $(sort $(wildcard ../../src/pl/plpython/libpython*.a)) $(sort $(wildcard ../../src/pl/plpython/libplpython*.a))
32+
# ... see silliness in plpython Makefile ...
33+
SHLIB_LINK += $(sort $(wildcard ../../src/pl/plpython/libpython*.a))
34+
else
35+
rpathdir = $(python_libdir)
36+
SHLIB_LINK += $(python_libspec)
3437
endif
35-
36-
ifeq ($(PORTNAME), cygwin)
37-
SHLIB_LINK += -L../ltree -lltree -L../../src/pl/plpython \
38-
-lplpython$(python_majorversion) $(python_libspec)
3938
endif
4039

4140
REGRESS_OPTS += --load-extension=ltree

contrib/ltree_plpython/ltree_plpython.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
#include "postgres.h"
2+
23
#include "fmgr.h"
34
#include "plpython.h"
45
#include "ltree.h"
56

67
PG_MODULE_MAGIC;
78

9+
extern void _PG_init(void);
10+
11+
/* Linkage to functions in plpython module */
12+
#if PY_MAJOR_VERSION >= 3
13+
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
14+
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
15+
#endif
16+
17+
18+
/*
19+
* Module initialize function: fetch function pointers for cross-module calls.
20+
*/
21+
void
22+
_PG_init(void)
23+
{
24+
/* Asserts verify that typedefs above match original declarations */
25+
#if PY_MAJOR_VERSION >= 3
26+
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
27+
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
28+
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
29+
true, NULL);
30+
#endif
31+
}
32+
33+
34+
/* These defines must be after the module init function */
35+
#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
36+
837

938
PG_FUNCTION_INFO_V1(ltree_to_plpython);
1039

contrib/ltree_plpython/ltree_plpython2u--1.0.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION ltree_plpython2u" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD 'plpython2';
8-
SELECT NULL::ltree;
9-
10-
116
CREATE FUNCTION ltree_to_plpython2(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS 'MODULE_PATHNAME', 'ltree_to_plpython';

contrib/ltree_plpython/ltree_plpython3u--1.0.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION ltree_plpython3u" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD 'plpython3';
8-
SELECT NULL::ltree;
9-
10-
116
CREATE FUNCTION ltree_to_plpython3(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS 'MODULE_PATHNAME', 'ltree_to_plpython';

contrib/ltree_plpython/ltree_plpythonu--1.0.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION ltree_plpythonu" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD 'plpython2'; -- change to plpython3 if that ever becomes the default
8-
SELECT NULL::ltree;
9-
10-
116
CREATE FUNCTION ltree_to_plpython(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS 'MODULE_PATHNAME';

src/tools/msvc/Mkvcbuild.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,11 @@ sub mkvcbuild
480480
'plpython' . $pymajorver, 'src/pl/plpython',
481481
'hstore', 'contrib/hstore');
482482
$hstore_plpython->AddDefine('PLPYTHON_LIBNAME="plpython' . $pymajorver . '"');
483-
AddTransformModule(
483+
my $ltree_plpython = AddTransformModule(
484484
'ltree_plpython' . $pymajorver, 'contrib/ltree_plpython',
485485
'plpython' . $pymajorver, 'src/pl/plpython',
486486
'ltree', 'contrib/ltree');
487+
$ltree_plpython->AddDefine('PLPYTHON_LIBNAME="plpython' . $pymajorver . '"');
487488
}
488489

489490
if ($solution->{options}->{perl})

0 commit comments

Comments
 (0)