Skip to content

Commit

Permalink
refactor: consol '_get_conflict_error' w/ '_from_module' variant
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Jun 5, 2024
1 parent 6ba3f38 commit 9396f92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/BTrees/BTreeModuleTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ intern_strings()
}

static inline PyObject* _get_module(PyTypeObject* typeobj);
static inline PyObject* _get_conflict_error( PyObject* bt_obj);
static inline PyObject* _get_conflict_error_from_module(PyObject* module);
static inline PyObject* _get_conflict_error( PyObject* bt_obj_or_module);
static inline PyObject* _get_btreetype_setattro_allowed_names(
PyTypeObject* type);
static inline PerCAPI* _get_per_capi(PyObject* bt_obj_or_module);
Expand Down Expand Up @@ -790,23 +789,23 @@ _get_module(PyTypeObject* typeobj)
}

static inline PyObject*
_get_conflict_error(PyObject* bucket_or_btree)
_get_conflict_error(PyObject* bt_obj_or_module)
{
PyObject* module = _get_module(Py_TYPE(bucket_or_btree));
PyObject* module;

if (PyModule_Check(bt_obj_or_module))
module = bt_obj_or_module;
else
module = _get_module(Py_TYPE(bt_obj_or_module));

if (module == NULL)
/* Probably occurs during shutdown. Just bail.*/
return NULL;

module_state* state = PyModule_GetState(module);
return state->conflict_error;
}

static inline PyObject*
_get_conflict_error_from_module(PyObject* module)
{
module_state* state = PyModule_GetState(module);
return state->conflict_error;
}

static inline PyObject*
_get_btreetype_setattro_allowed_names(PyTypeObject* type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BTrees/MergeTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ merge_output(Bucket *r, SetIteration *i, int mapping) {
static PyObject *
merge_error(PyObject* module, int p1, int p2, int p3, int reason) {
PyObject *r;
PyObject * conflict_error = _get_conflict_error_from_module(module);
PyObject * conflict_error = _get_conflict_error(module);

UNLESS(r = Py_BuildValue("iiii", p1, p2, p3, reason)) r = Py_None;
if (conflict_error == NULL) {
Expand Down

0 comments on commit 9396f92

Please sign in to comment.