[Bf-blender-cvs] [34642fe] master: PyAPI: minor cleanup with library linking

Campbell Barton noreply at git.blender.org
Thu Jul 14 17:24:02 CEST 2016


Commit: 34642fe532cbd87ce63763c03d05ab551fdf7172
Author: Campbell Barton
Date:   Thu Jul 14 21:00:05 2016 +1000
Branches: master
https://developer.blender.org/rB34642fe532cbd87ce63763c03d05ab551fdf7172

PyAPI: minor cleanup with library linking

===================================================================

M	source/blender/python/intern/bpy_library_load.c

===================================================================

diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c
index 7ceb99d..37a7e0e 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -39,7 +39,6 @@
 
 #include "BLO_readfile.h"
 
-#include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_library.h"
 #include "BKE_idcode.h"
@@ -186,6 +185,7 @@ PyDoc_STRVAR(bpy_lib_load_doc,
 static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
 {
 	static const char *kwlist[] = {"filepath", "link", "relative", NULL};
+	Main *bmain = CTX_data_main(BPy_GetContext());
 	BPy_Library *ret;
 	const char *filename = NULL;
 	bool is_rel = false, is_link = false;
@@ -204,7 +204,7 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *
 
 	BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath));
 	BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath));
-	BLI_path_abs(ret->abspath, G.main->name);
+	BLI_path_abs(ret->abspath, bmain->name);
 
 	ret->blo_handle = NULL;
 	ret->flag = ((is_link ? FILE_LINK : 0) |
@@ -222,19 +222,16 @@ static PyObject *_bpy_names(BPy_Library *self, int blocktype)
 	int totnames;
 
 	names = BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames);
+	list = PyList_New(totnames);
 
 	if (names) {
 		int counter = 0;
-		list = PyList_New(totnames);
 		for (l = names; l; l = l->next) {
 			PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
 			counter++;
 		}
 		BLI_linklist_free(names, free); /* free linklist *and* each node's data */
 	}
-	else {
-		list = PyList_New(0);
-	}
 
 	return list;
 }
@@ -354,9 +351,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 
 					for (i = 0; i < size; i++) {
 						PyObject *item_src = PyList_GET_ITEM(ls, i);
-#ifdef USE_RNA_DATABLOCKS
-						PyObject *item_dst = NULL;
-#endif
+						PyObject *item_dst;  /* must be set below */
 						const char *item_idname = _PyUnicode_AsString(item_src);
 
 						// printf("  %s\n", item_idname);
@@ -367,15 +362,16 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 #ifdef USE_RNA_DATABLOCKS
 								/* swap name for pointer to the id */
 								item_dst = PyCapsule_New((void *)id, NULL, NULL);
+#else
+								/* leave as is */
+								continue;
 #endif
 							}
 							else {
 								bpy_lib_exit_warn_idname(self, name_plural, item_idname);
 								/* just warn for now */
 								/* err = -1; */
-#ifdef USE_RNA_DATABLOCKS
 								item_dst = Py_INCREF_RET(Py_None);
-#endif
 							}
 
 							/* ID or None */
@@ -384,19 +380,12 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 							/* XXX, could complain about this */
 							bpy_lib_exit_warn_type(self, item_src);
 							PyErr_Clear();
-
-#ifdef USE_RNA_DATABLOCKS
 							item_dst = Py_INCREF_RET(Py_None);
-#endif
 						}
 
-#ifdef USE_RNA_DATABLOCKS
-						if (item_dst) {
-							/* item_dst must be new or already incref'd */
-							Py_DECREF(item_src);
-							PyList_SET_ITEM(ls, i, item_dst);
-						}
-#endif
+						/* item_dst must be new or already incref'd */
+						Py_DECREF(item_src);
+						PyList_SET_ITEM(ls, i, item_dst);
 					}
 				}
 			}
@@ -419,7 +408,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 		/* copied from wm_operator.c */
 		{
 			/* mark all library linked objects to be updated */
-			BKE_main_lib_objects_recalc_all(G.main);
+			BKE_main_lib_objects_recalc_all(bmain);
 
 			/* append, rather than linking */
 			if ((self->flag & FILE_LINK) == 0) {
@@ -431,6 +420,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 
 		/* finally swap the capsules for real bpy objects
 		 * important since BLO_library_append_end initializes NodeTree types used by srna->refine */
+#ifdef USE_RNA_DATABLOCKS
 		{
 			int idcode_step = 0, idcode;
 			while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
@@ -460,6 +450,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 				}
 			}
 		}
+#endif  /* USE_RNA_DATABLOCKS */
 
 		Py_RETURN_NONE;
 	}




More information about the Bf-blender-cvs mailing list