Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2019-03-18 13:32:06 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2019-03-18 13:36:50 +0300
commitd0e28721b04a0235d4f6bfbe42f43672ff923444 (patch)
treeaf52e9e2f14a7e29eb40731b88584d00e309f821 /source/blender/python
parent66932a2c814037f897af56693efb68b6993406fb (diff)
Cleanup: Main id looping: add FOREACH_MAIN_LISTBASE macro.
We don't want to use flow control like `break` statement into the basic `FOREACH_MAIN_ID` macro, as this is a nested loop. When refined behavior is needed (like breaking whole iteration, or just skipping to next ID type), FOREACH_MAIN_LISTBASE and FOREACH_MAIN_LISTBASE_ID macros should be used instead. Based on D4382 by @campbellbarton (Other potential solution, using flow control macros: D4384).
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_rna_id_collection.c87
1 files changed, 46 insertions, 41 deletions
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 31b135fe933..7a5849f818d 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -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
+ ListBase *lb;
ID *id;
PyObject *subset = NULL;
@@ -223,57 +224,61 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
data_cb.types_bitmap = key_types_bitmap;
- FOREACH_MAIN_ID_BEGIN(bmain, id)
+ FOREACH_MAIN_LISTBASE_BEGIN(bmain, lb)
{
- /* We cannot skip here in case we have some filter on key types... */
- if (key_types_bitmap == NULL && 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. */
+ FOREACH_MAIN_LISTBASE_ID_BEGIN(lb, id)
+ {
+ /* We cannot skip here in case we have some filter on key types... */
+ if (key_types_bitmap == NULL && val_types_bitmap != NULL) {
+ if (!id_check_type(id, val_types_bitmap)) {
+ break;
+ }
}
- }
- /* 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 &&
- /* We do not want to pre-add keys of flitered out types. */
- (key_types_bitmap == NULL || id_check_type(id, key_types_bitmap)) &&
- /* We do not want to pre-add keys when we have filter on value types, but not on key types. */
- (val_types_bitmap == NULL || key_types_bitmap != NULL))
- {
- 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 &&
+ /* We do not want to pre-add keys of flitered out types. */
+ (key_types_bitmap == NULL || id_check_type(id, key_types_bitmap)) &&
+ /* We do not want to pre-add keys when we have filter on value types, but not on key types. */
+ (val_types_bitmap == NULL || key_types_bitmap != NULL))
+ {
+ 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 (val_types_bitmap != NULL && !id_check_type(id, val_types_bitmap)) {
- continue;
- }
+ if (val_types_bitmap != NULL && !id_check_type(id, val_types_bitmap)) {
+ continue;
+ }
- data_cb.id_curr = id;
- BKE_library_foreach_ID_link(NULL, id, foreach_libblock_id_user_map_callback, &data_cb, IDWALK_CB_NOP);
+ 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_LISTBASE_ID_END;
}
- FOREACH_MAIN_ID_END;
+ FOREACH_MAIN_LISTBASE_ID_END;
ret = data_cb.user_map;