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

Commit8037160

Browse files
committed
Install safeguard against running PL/Python 2 and 3 in the same session
1 parentc9b142d commit8037160

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

‎doc/src/sgml/plpython.sgml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.50 2010/07/06 21:37:31 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.51 2010/07/08 18:42:12 petere Exp $ -->
22

33
<chapter id="plpython">
44
<title>PL/Python - Python Procedural Language</title>
@@ -154,12 +154,13 @@
154154
</para>
155155

156156
<para>
157-
On most (possibly all) platforms, it is not possible to use
158-
PL/Python based on Python 2 and PL/Python based on Python 3 in the
159-
same session, because the symbols in the dynamic modules will
160-
clash, which will result in crashes of the PostgreSQL server
161-
process. It is possible, however, to use both PL/Python variants
162-
in the same database, from separate sessions.
157+
It is not allowed to use PL/Python based on Python 2 and PL/Python
158+
based on Python 3 in the same session, because the symbols in the
159+
dynamic modules would clash, which could result in crashes of the
160+
PostgreSQL server process. There is a check that prevents mixing
161+
Python major versions in a session, which will abort the session if
162+
a mismatch is detected. It is possible, however, to use both
163+
PL/Python variants in the same database, from separate sessions.
163164
</para>
164165
</sect1>
165166

‎src/pl/plpython/plpython.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.146 2010/07/06 19:19:01 momjian Exp $
4+
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.147 2010/07/08 18:42:12 petere Exp $
55
*
66
*********************************************************************
77
*/
@@ -3206,6 +3206,8 @@ PyInit_plpy(void)
32063206
#endif
32073207

32083208

3209+
staticconstintplpython_python_version=PY_MAJOR_VERSION;
3210+
32093211
/*
32103212
* _PG_init()- library load-time initialization
32113213
*
@@ -3216,6 +3218,21 @@ _PG_init(void)
32163218
{
32173219
/* Be sure we do initialization only once (should be redundant now) */
32183220
staticboolinited= false;
3221+
constint**version_ptr;
3222+
3223+
/* Be sure we don't run Python 2 and 3 in the same session (might crash) */
3224+
version_ptr= (constint**)find_rendezvous_variable("plpython_python_version");
3225+
if (!(*version_ptr))
3226+
*version_ptr=&plpython_python_version;
3227+
else
3228+
{
3229+
if (**version_ptr!=plpython_python_version)
3230+
ereport(FATAL,
3231+
(errmsg("Python major version mismatch in session"),
3232+
errdetail("This session has previously used Python major version %d, and it is now attempting to use Python major version %d.",
3233+
**version_ptr,plpython_python_version),
3234+
errhint("Start a new session to use a different Python major version.")));
3235+
}
32193236

32203237
if (inited)
32213238
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp