Skip to content

Commit

Permalink
refactor: rename state attr / accessor for settable BTree attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Jun 5, 2024
1 parent 9396f92 commit ba7c000
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/BTrees/BTreeModuleTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ intern_strings()

static inline PyObject* _get_module(PyTypeObject* typeobj);
static inline PyObject* _get_conflict_error( PyObject* bt_obj_or_module);
static inline PyObject* _get_btreetype_setattro_allowed_names(
PyTypeObject* type);
static inline PyObject* _get_btreetype_allowed_attrs(PyTypeObject* type);
static inline PerCAPI* _get_per_capi(PyObject* bt_obj_or_module);
static inline PyTypeObject* _get_btree_type(PyObject* module);
static inline PyTypeObject* _get_bucket_type(PyObject* module);
Expand Down Expand Up @@ -726,7 +725,7 @@ static struct PyMethodDef module_methods[] = {
typedef struct {
PyObject* conflict_error;
PerCAPI* per_capi;
PyObject* btreetype_setattro_allowed_names;
PyObject* btreetype_allowed_attrs;
PyTypeObject* btree_type_type;
PyTypeObject* btree_type;
PyTypeObject* bucket_type;
Expand All @@ -743,7 +742,7 @@ module_traverse(PyObject* module, visitproc visit, void *arg)
Py_VISIT(state->conflict_error);
if (state->per_capi)
Py_VISIT(state->per_capi->pertype);
Py_VISIT(state->btreetype_setattro_allowed_names);
Py_VISIT(state->btreetype_allowed_attrs);
Py_VISIT(state->btree_type_type);
Py_VISIT(state->btree_type);
Py_VISIT(state->bucket_type);
Expand All @@ -761,7 +760,7 @@ module_clear(PyObject* module)
Py_CLEAR(state->conflict_error);
if (state->per_capi)
Py_CLEAR(state->per_capi->pertype);
Py_CLEAR(state->btreetype_setattro_allowed_names);
Py_CLEAR(state->btreetype_allowed_attrs);
Py_CLEAR(state->btree_type_type);
Py_CLEAR(state->btree_type);
Py_CLEAR(state->bucket_type);
Expand Down Expand Up @@ -807,14 +806,14 @@ _get_conflict_error(PyObject* bt_obj_or_module)
}

static inline PyObject*
_get_btreetype_setattro_allowed_names(PyTypeObject* type)
_get_btreetype_allowed_attrs(PyTypeObject* type)
{
PyObject* module = _get_module(type);
if (module == NULL)
return NULL;

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

static inline PerCAPI*
Expand Down Expand Up @@ -1038,7 +1037,7 @@ module_exec(PyObject* module)
PyObject *mod_dict;
PyObject *interfaces;

state->btreetype_setattro_allowed_names = PyTuple_Pack(
state->btreetype_allowed_attrs = PyTuple_Pack(
5,
/* BTree attributes */
str_max_internal_size,
Expand All @@ -1049,7 +1048,7 @@ module_exec(PyObject* module)
str___provides__
);

if (state->btreetype_setattro_allowed_names == NULL)
if (state->btreetype_allowed_attrs == NULL)
return -1;

/* Grab the ConflictError class */
Expand Down
4 changes: 2 additions & 2 deletions src/BTrees/BTreeTemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
static int
BTreeType_setattro(PyTypeObject* type, PyObject* name, PyObject* value)
{
PyObject* allowed_names = _get_btreetype_setattro_allowed_names(type);
PyObject* allowed_attrs = _get_btreetype_allowed_attrs(type);
/*
type.tp_setattro prohibits setting any attributes on a built-in type,
so we need to use our own (metaclass) type to handle it. The set of
Expand All @@ -34,7 +34,7 @@ BTreeType_setattro(PyTypeObject* type, PyObject* name, PyObject* value)
attributes.
*/
int allowed;
allowed = PySequence_Contains(allowed_names, name);
allowed = PySequence_Contains(allowed_attrs, name);
if (allowed < 0) {
return -1;
}
Expand Down

0 comments on commit ba7c000

Please sign in to comment.