* Perform one-time setup of PL/Python, after checking for a conflict * with other versions of Python. */
| 114 | * with other versions of Python. |
| 115 | */ |
| 116 | static void |
| 117 | PLy_initialize(void) |
| 118 | { |
| 119 | static bool inited = false; |
| 120 | |
| 121 | /* |
| 122 | * Check for multiple Python libraries before actively doing anything with |
| 123 | * libpython. This must be repeated on each entry to PL/Python, in case a |
| 124 | * conflicting library got loaded since we last looked. |
| 125 | * |
| 126 | * It is attractive to weaken this error from FATAL to ERROR, but there |
| 127 | * would be corner cases, so it seems best to be conservative. |
| 128 | */ |
| 129 | if (*plpython_version_bitmask_ptr != (1 << PY_MAJOR_VERSION)) |
| 130 | ereport(FATAL, |
| 131 | (errmsg("multiple Python libraries are present in session"), |
| 132 | errdetail("Only one Python major version can be used in one session."))); |
| 133 | |
| 134 | /* The rest should only be done once per session */ |
| 135 | if (inited) |
| 136 | return; |
| 137 | |
| 138 | #if PY_MAJOR_VERSION >= 3 |
| 139 | PyImport_AppendInittab("plpy", PyInit_plpy); |
| 140 | #endif |
| 141 | Py_Initialize(); |
| 142 | #if PY_MAJOR_VERSION >= 3 |
| 143 | PyImport_ImportModule("plpy"); |
| 144 | #endif |
| 145 | PLy_init_interp(); |
| 146 | PLy_init_plpy(); |
| 147 | if (PyErr_Occurred()) |
| 148 | PLy_elog(FATAL, "untrapped error in initialization"); |
| 149 | |
| 150 | init_procedure_caches(); |
| 151 | |
| 152 | explicit_subtransactions = NIL; |
| 153 | |
| 154 | PLy_execution_contexts = NULL; |
| 155 | |
| 156 | inited = true; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * For GPDB Use: |
no test coverage detected