| 184 | } |
| 185 | |
| 186 | static void |
| 187 | PLy_add_exceptions(PyObject *plpy) |
| 188 | { |
| 189 | PyObject *excmod; |
| 190 | HASHCTL hash_ctl; |
| 191 | |
| 192 | #if PY_MAJOR_VERSION < 3 |
| 193 | excmod = Py_InitModule("spiexceptions", PLy_exc_methods); |
| 194 | #else |
| 195 | excmod = PyModule_Create(&PLy_exc_module); |
| 196 | #endif |
| 197 | if (excmod == NULL) |
| 198 | PLy_elog(ERROR, "could not create the spiexceptions module"); |
| 199 | |
| 200 | /* |
| 201 | * PyModule_AddObject does not add a refcount to the object, for some odd |
| 202 | * reason; we must do that. |
| 203 | */ |
| 204 | Py_INCREF(excmod); |
| 205 | if (PyModule_AddObject(plpy, "spiexceptions", excmod) < 0) |
| 206 | PLy_elog(ERROR, "could not add the spiexceptions module"); |
| 207 | |
| 208 | PLy_exc_error = PLy_create_exception("plpy.Error", NULL, NULL, |
| 209 | "Error", plpy); |
| 210 | PLy_exc_fatal = PLy_create_exception("plpy.Fatal", NULL, NULL, |
| 211 | "Fatal", plpy); |
| 212 | PLy_exc_spi_error = PLy_create_exception("plpy.SPIError", NULL, NULL, |
| 213 | "SPIError", plpy); |
| 214 | |
| 215 | hash_ctl.keysize = sizeof(int); |
| 216 | hash_ctl.entrysize = sizeof(PLyExceptionEntry); |
| 217 | PLy_spi_exceptions = hash_create("PL/Python SPI exceptions", 256, |
| 218 | &hash_ctl, HASH_ELEM | HASH_BLOBS); |
| 219 | |
| 220 | PLy_generate_spi_exceptions(excmod, PLy_exc_spi_error); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Create an exception object and add it to the module |
no test coverage detected