plpython-version-check.patch
text/x-patch
Filename: plpython-version-check.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/pl/plpython/plpython.c | 17 | 0 |
Index: src/pl/plpython/plpython.c
===================================================================
RCS file: /cvsroot/pgsql/src/pl/plpython/plpython.c,v
retrieving revision 1.145
diff -u -3 -p -r1.145 plpython.c
--- src/pl/plpython/plpython.c 29 Jun 2010 00:18:11 -0000 1.145
+++ src/pl/plpython/plpython.c 7 Jul 2010 21:04:33 -0000
@@ -3206,6 +3206,8 @@ PyInit_plpy(void)
#endif
+static const int plpython_python_version = PY_MAJOR_VERSION;
+
/*
* _PG_init() - library load-time initialization
*
@@ -3216,6 +3218,21 @@ _PG_init(void)
{
/* Be sure we do initialization only once (should be redundant now) */
static bool inited = false;
+ const int **version_ptr;
+
+ /* Be sure we don't run Python 2 and 3 in the same session (might crash) */
+ version_ptr = (const int **) find_rendezvous_variable("plpython_python_version");
+ if (!(*version_ptr))
+ *version_ptr = &plpython_python_version;
+ else
+ {
+ if (**version_ptr != plpython_python_version)
+ ereport(ERROR,
+ (errmsg("Python major version mismatch in session"),
+ errdetail("This session had previously used Python major version %d, and it is now attempting to use Python major version %d.",
+ **version_ptr, plpython_python_version),
+ errhint("Start a new session to use a different Python major version.")));
+ }
if (inited)
return;