From 9396f921581dc5dead465d2f873b7301d472387f Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 5 Jun 2024 13:23:18 -0400 Subject: [PATCH] refactor: consol '_get_conflict_error' w/ '_from_module' variant --- src/BTrees/BTreeModuleTemplate.c | 21 ++++++++++----------- src/BTrees/MergeTemplate.c | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/BTrees/BTreeModuleTemplate.c b/src/BTrees/BTreeModuleTemplate.c index cfff7f1..b2d42d6 100644 --- a/src/BTrees/BTreeModuleTemplate.c +++ b/src/BTrees/BTreeModuleTemplate.c @@ -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); @@ -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) { diff --git a/src/BTrees/MergeTemplate.c b/src/BTrees/MergeTemplate.c index e787b5e..3329940 100644 --- a/src/BTrees/MergeTemplate.c +++ b/src/BTrees/MergeTemplate.c @@ -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) {