Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd51924b

Browse files
committed
Convert contrib/hstore_plpython to not use direct linking to other modules.
Previously, on most platforms, we allowed hstore_plpython's referencesto hstore and plpython to be unresolved symbols at link time, trustingthe dynamic linker to resolve them when the module is loaded. Thishas a number of problems, the worst being that the dynamic linkerdoes not know where the references come from and can do nothing butfail if those other modules haven't been loaded. We've more or lessgotten away with that for the limited use-case of datatype transformmodules, but even there, it requires some awkward hacks, most recentlycommit83c2492.Instead, let's not treat these references as linker-resolvable at all,but use function pointers that are manually filled in by the module's_PG_init function. There are few enough contact points that thisdoesn't seem unmaintainable, at least for these use-cases. (Note thatthe same technique wouldn't work at all for decoupling from libpythonitself, but fortunately that's just a standard shared library and canbe linked to normally.)This is an initial patch that just converts hstore_plpython. If thebuildfarm doesn't find any fatal problems, I'll work on the othertransform modules soon.Tom Lane, per an idea of Andres Freund's.Discussion: <2652.1475512158@sss.pgh.pa.us>
1 parent6bc811c commitd51924b

File tree

6 files changed

+76
-26
lines changed

6 files changed

+76
-26
lines changed

‎contrib/hstore_plpython/Makefile

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

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

99
EXTENSION = hstore_plpythonu hstore_plpython2u hstore_plpython3u
1010
DATA = hstore_plpythonu--1.0.sql hstore_plpython2u--1.0.sql hstore_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 +=../hstore/libhstore.exp$(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 += ../hstore/libhstore.a$(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../hstore -lhstore -L../../src/pl/plpython\
38-
-lplpython$(python_majorversion)$(python_libspec)
3938
endif
4039

4140
REGRESS_OPTS += --load-extension=hstore

‎contrib/hstore_plpython/hstore_plpython.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,76 @@
11
#include"postgres.h"
2+
23
#include"fmgr.h"
34
#include"plpython.h"
45
#include"plpy_typeio.h"
56
#include"hstore.h"
67

78
PG_MODULE_MAGIC;
89

10+
externvoid_PG_init(void);
11+
12+
/* Linkage to functions in plpython module */
13+
typedefchar*(*PLyObject_AsString_t) (PyObject*plrv);
14+
15+
staticPLyObject_AsString_tPLyObject_AsString_p;
16+
17+
/* Linkage to functions in hstore module */
18+
typedefHStore*(*hstoreUpgrade_t) (Datumorig);
19+
typedefint (*hstoreUniquePairs_t) (Pairs*a,int32l,int32*buflen);
20+
typedefHStore*(*hstorePairs_t) (Pairs*pairs,int32pcount,int32buflen);
21+
typedefsize_t (*hstoreCheckKeyLen_t) (size_tlen);
22+
typedefsize_t (*hstoreCheckValLen_t) (size_tlen);
23+
24+
statichstoreUpgrade_thstoreUpgrade_p;
25+
statichstoreUniquePairs_thstoreUniquePairs_p;
26+
statichstorePairs_thstorePairs_p;
27+
statichstoreCheckKeyLen_thstoreCheckKeyLen_p;
28+
statichstoreCheckValLen_thstoreCheckValLen_p;
29+
30+
31+
/*
32+
* Module initialize function: fetch function pointers for cross-module calls.
33+
*/
34+
void
35+
_PG_init(void)
36+
{
37+
/* These asserts verify that typedefs above match original declarations */
38+
AssertVariableIsOfType(&PLyObject_AsString,PLyObject_AsString_t);
39+
AssertVariableIsOfType(&hstoreUpgrade,hstoreUpgrade_t);
40+
AssertVariableIsOfType(&hstoreUniquePairs,hstoreUniquePairs_t);
41+
AssertVariableIsOfType(&hstorePairs,hstorePairs_t);
42+
AssertVariableIsOfType(&hstoreCheckKeyLen,hstoreCheckKeyLen_t);
43+
AssertVariableIsOfType(&hstoreCheckValLen,hstoreCheckValLen_t);
44+
45+
PLyObject_AsString_p= (PLyObject_AsString_t)
46+
load_external_function("$libdir/"PLPYTHON_LIBNAME,"PLyObject_AsString",
47+
true,NULL);
48+
hstoreUpgrade_p= (hstoreUpgrade_t)
49+
load_external_function("$libdir/hstore","hstoreUpgrade",
50+
true,NULL);
51+
hstoreUniquePairs_p= (hstoreUniquePairs_t)
52+
load_external_function("$libdir/hstore","hstoreUniquePairs",
53+
true,NULL);
54+
hstorePairs_p= (hstorePairs_t)
55+
load_external_function("$libdir/hstore","hstorePairs",
56+
true,NULL);
57+
hstoreCheckKeyLen_p= (hstoreCheckKeyLen_t)
58+
load_external_function("$libdir/hstore","hstoreCheckKeyLen",
59+
true,NULL);
60+
hstoreCheckValLen_p= (hstoreCheckValLen_t)
61+
load_external_function("$libdir/hstore","hstoreCheckValLen",
62+
true,NULL);
63+
}
64+
65+
66+
/* These defines must be after the module init function */
67+
#definePLyObject_AsString PLyObject_AsString_p
68+
#definehstoreUpgrade hstoreUpgrade_p
69+
#definehstoreUniquePairs hstoreUniquePairs_p
70+
#definehstorePairs hstorePairs_p
71+
#definehstoreCheckKeyLen hstoreCheckKeyLen_p
72+
#definehstoreCheckValLen hstoreCheckValLen_p
73+
974

1075
PG_FUNCTION_INFO_V1(hstore_to_plpython);
1176

‎contrib/hstore_plpython/hstore_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 hstore_plpython2u" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD'plpython2';
8-
SELECTNULL::hstore;
9-
10-
116
CREATEFUNCTIONhstore_to_plpython2(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS'MODULE_PATHNAME','hstore_to_plpython';

‎contrib/hstore_plpython/hstore_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 hstore_plpython3u" to load this file. \quit
55

6-
-- make sure the prerequisite libraries are loaded
7-
LOAD'plpython3';
8-
SELECTNULL::hstore;
9-
10-
116
CREATEFUNCTIONhstore_to_plpython3(val internal) RETURNS internal
127
LANGUAGE C STRICT IMMUTABLE
138
AS'MODULE_PATHNAME','hstore_to_plpython';

‎contrib/hstore_plpython/hstore_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 hstore_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-
SELECTNULL::hstore;
9-
10-
116
CREATEFUNCTIONhstore_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
@@ -475,10 +475,11 @@ sub mkvcbuild
475475
$plpython->AddReference($postgres);
476476

477477
# Add transform modules dependent on plpython
478-
AddTransformModule(
478+
my$hstore_plpython =AddTransformModule(
479479
'hstore_plpython' .$pymajorver,'contrib/hstore_plpython',
480480
'plpython' .$pymajorver,'src/pl/plpython',
481481
'hstore','contrib/hstore');
482+
$hstore_plpython->AddDefine('PLPYTHON_LIBNAME="plpython' .$pymajorver .'"');
482483
AddTransformModule(
483484
'ltree_plpython' .$pymajorver,'contrib/ltree_plpython',
484485
'plpython' .$pymajorver,'src/pl/plpython',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp