Skip to content

Commit

Permalink
Refactor ADD_EXCEPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
Erlend E. Aasland committed Jun 23, 2021
1 parent 158a638 commit c79de0c
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,17 @@ do { \
} \
} while (0)

#define ADD_EXCEPTION(module, name, exc, base) \
do { \
exc = PyErr_NewException(MODULE_NAME "." name, base, NULL); \
if (!exc) { \
goto error; \
} \
int res = PyModule_AddObjectRef(module, name, exc); \
Py_DECREF(exc); \
if (res < 0) { \
goto error; \
} \
#define ADD_EXCEPTION(module, state, name, base) \
do { \
state->name = PyErr_NewException(MODULE_NAME "." #name, base, NULL); \
if (state->name == NULL) { \
goto error; \
} \
int res = PyModule_AddObjectRef(module, #name, state->name); \
Py_DECREF(state->name); \
if (res < 0) { \
goto error; \
} \
} while (0)

PyMODINIT_FUNC PyInit__sqlite3(void)
Expand Down Expand Up @@ -398,26 +398,20 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
ADD_TYPE(module, state->RowType);

/*** Create DB-API Exception hierarchy */
ADD_EXCEPTION(module, "Error", state->Error, PyExc_Exception);
ADD_EXCEPTION(module, "Warning", state->Warning, PyExc_Exception);
ADD_EXCEPTION(module, state, Error, PyExc_Exception);
ADD_EXCEPTION(module, state, Warning, PyExc_Exception);

/* Error subclasses */
ADD_EXCEPTION(module, "InterfaceError", state->InterfaceError,
state->Error);
ADD_EXCEPTION(module, "DatabaseError", state->DatabaseError, state->Error);
ADD_EXCEPTION(module, state, InterfaceError, state->Error);
ADD_EXCEPTION(module, state, DatabaseError, state->Error);

/* DatabaseError subclasses */
ADD_EXCEPTION(module, "InternalError", state->InternalError,
state->DatabaseError);
ADD_EXCEPTION(module, "OperationalError", state->OperationalError,
state->DatabaseError);
ADD_EXCEPTION(module, "ProgrammingError", state->ProgrammingError,
state->DatabaseError);
ADD_EXCEPTION(module, "IntegrityError", state->IntegrityError,
state->DatabaseError);
ADD_EXCEPTION(module, "DataError", state->DataError, state->DatabaseError);
ADD_EXCEPTION(module, "NotSupportedError", state->NotSupportedError,
state->DatabaseError);
ADD_EXCEPTION(module, state, InternalError, state->DatabaseError);
ADD_EXCEPTION(module, state, OperationalError, state->DatabaseError);
ADD_EXCEPTION(module, state, ProgrammingError, state->DatabaseError);
ADD_EXCEPTION(module, state, IntegrityError, state->DatabaseError);
ADD_EXCEPTION(module, state, DataError, state->DatabaseError);
ADD_EXCEPTION(module, state, NotSupportedError, state->DatabaseError);

/* Set integer constants */
if (add_integer_constants(module) < 0) {
Expand Down

0 comments on commit c79de0c

Please sign in to comment.