| 142 | #endif /* PY_MAJOR_VERSION >= 3 */ |
| 143 | |
| 144 | void |
| 145 | PLy_init_plpy(void) |
| 146 | { |
| 147 | PyObject *main_mod, |
| 148 | *main_dict, |
| 149 | *plpy_mod; |
| 150 | |
| 151 | #if PY_MAJOR_VERSION < 3 |
| 152 | PyObject *plpy; |
| 153 | #endif |
| 154 | |
| 155 | /* |
| 156 | * initialize plpy module |
| 157 | */ |
| 158 | PLy_plan_init_type(); |
| 159 | PLy_result_init_type(); |
| 160 | PLy_subtransaction_init_type(); |
| 161 | PLy_cursor_init_type(); |
| 162 | |
| 163 | #if PY_MAJOR_VERSION >= 3 |
| 164 | PyModule_Create(&PLy_module); |
| 165 | /* for Python 3 we initialized the exceptions in PyInit_plpy */ |
| 166 | #else |
| 167 | plpy = Py_InitModule("plpy", PLy_methods); |
| 168 | PLy_add_exceptions(plpy); |
| 169 | #endif |
| 170 | |
| 171 | /* PyDict_SetItemString(plpy, "PlanType", (PyObject *) &PLy_PlanType); */ |
| 172 | |
| 173 | /* |
| 174 | * initialize main module, and add plpy |
| 175 | */ |
| 176 | main_mod = PyImport_AddModule("__main__"); |
| 177 | main_dict = PyModule_GetDict(main_mod); |
| 178 | plpy_mod = PyImport_AddModule("plpy"); |
| 179 | if (plpy_mod == NULL) |
| 180 | PLy_elog(ERROR, "could not import \"plpy\" module"); |
| 181 | PyDict_SetItemString(main_dict, "plpy", plpy_mod); |
| 182 | if (PyErr_Occurred()) |
| 183 | PLy_elog(ERROR, "could not import \"plpy\" module"); |
| 184 | } |
| 185 | |
| 186 | static void |
| 187 | PLy_add_exceptions(PyObject *plpy) |
no test coverage detected