ID management: use FOREACH_MAIN_ID in some places.

This commit is contained in:
Bastien Montagne 2019-02-18 16:39:12 +01:00
parent b36f78abf4
commit b8ec2c9559
1 changed files with 34 additions and 40 deletions

View File

@ -159,6 +159,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
#else
Main *bmain = G_MAIN; /* XXX Ugly, but should work! */
#endif
ID *id;
PyObject *subset = NULL;
@ -222,57 +223,51 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
data_cb.types_bitmap = key_types_bitmap;
ListBase *lb_array[MAX_LIBARRAY];
int lb_index;
lb_index = set_listbasepointers(bmain, lb_array);
while (lb_index--) {
if (val_types_bitmap && lb_array[lb_index]->first) {
if (!id_check_type(lb_array[lb_index]->first, val_types_bitmap)) {
continue;
FOREACH_MAIN_ID_BEGIN(bmain, id)
{
if (val_types_bitmap != NULL) {
if (!id_check_type(id, val_types_bitmap)) {
break; /* Break iter on that type of IDs, continues with next ID type. */
}
}
for (ID *id = lb_array[lb_index]->first; id; id = id->next) {
/* One-time init, ID is just used as placeholder here, we abuse this in iterator callback
* to avoid having to rebuild a complete bpyrna object each time for the key searching
* (where only ID pointer value is used). */
if (data_cb.py_id_key_lookup_only == NULL) {
data_cb.py_id_key_lookup_only = pyrna_id_CreatePyObject(id);
/* One-time init, ID is just used as placeholder here, we abuse this in iterator callback
* to avoid having to rebuild a complete bpyrna object each time for the key searching
* (where only ID pointer value is used). */
if (data_cb.py_id_key_lookup_only == NULL) {
data_cb.py_id_key_lookup_only = pyrna_id_CreatePyObject(id);
}
if (!data_cb.is_subset) {
PyObject *key = data_cb.py_id_key_lookup_only;
PyObject *set;
RNA_id_pointer_create(id, &((BPy_StructRNA *)key)->ptr);
/* We have to insert the key now, otherwise ID unused would be missing from final dict... */
if ((set = PyDict_GetItem(data_cb.user_map, key)) == NULL) {
/* Cannot use our placeholder key here! */
key = pyrna_id_CreatePyObject(id);
set = PySet_New(NULL);
PyDict_SetItem(data_cb.user_map, key, set);
Py_DECREF(set);
Py_DECREF(key);
}
}
if (!data_cb.is_subset) {
PyObject *key = data_cb.py_id_key_lookup_only;
PyObject *set;
data_cb.id_curr = id;
BKE_library_foreach_ID_link(NULL, id, foreach_libblock_id_user_map_callback, &data_cb, IDWALK_CB_NOP);
RNA_id_pointer_create(id, &((BPy_StructRNA *)key)->ptr);
/* We have to insert the key now, otherwise ID unused would be missing from final dict... */
if ((set = PyDict_GetItem(data_cb.user_map, key)) == NULL) {
/* Cannot use our placeholder key here! */
key = pyrna_id_CreatePyObject(id);
set = PySet_New(NULL);
PyDict_SetItem(data_cb.user_map, key, set);
Py_DECREF(set);
Py_DECREF(key);
}
}
data_cb.id_curr = id;
BKE_library_foreach_ID_link(NULL, id, foreach_libblock_id_user_map_callback, &data_cb, IDWALK_CB_NOP);
if (data_cb.py_id_curr) {
Py_DECREF(data_cb.py_id_curr);
data_cb.py_id_curr = NULL;
}
if (data_cb.py_id_curr) {
Py_DECREF(data_cb.py_id_curr);
data_cb.py_id_curr = NULL;
}
}
FOREACH_MAIN_ID_END;
ret = data_cb.user_map;
error:
Py_XDECREF(data_cb.py_id_key_lookup_only);
if (key_types_bitmap) {
@ -284,7 +279,6 @@ error:
}
return ret;
}
PyDoc_STRVAR(bpy_batch_remove_doc,