* This should be called only once, from PLy_initialize. Initialize the Python * interpreter and global data. */
| 197 | * interpreter and global data. |
| 198 | */ |
| 199 | static void |
| 200 | PLy_init_interp(void) |
| 201 | { |
| 202 | static PyObject *PLy_interp_safe_globals = NULL; |
| 203 | PyObject *mainmod; |
| 204 | |
| 205 | mainmod = PyImport_AddModule("__main__"); |
| 206 | if (mainmod == NULL || PyErr_Occurred()) |
| 207 | PLy_elog(ERROR, "could not import \"__main__\" module"); |
| 208 | Py_INCREF(mainmod); |
| 209 | PLy_interp_globals = PyModule_GetDict(mainmod); |
| 210 | PLy_interp_safe_globals = PyDict_New(); |
| 211 | if (PLy_interp_safe_globals == NULL) |
| 212 | PLy_elog(ERROR, NULL); |
| 213 | PyDict_SetItemString(PLy_interp_globals, "GD", PLy_interp_safe_globals); |
| 214 | Py_DECREF(mainmod); |
| 215 | if (PLy_interp_globals == NULL || PyErr_Occurred()) |
| 216 | PLy_elog(ERROR, "could not initialize globals"); |
| 217 | } |
| 218 | |
| 219 | Datum |
| 220 | plpython_validator(PG_FUNCTION_ARGS) |