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:
authorCampbell Barton <ideasman42@gmail.com>2011-03-13 04:15:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-03-13 04:15:14 +0300
commit25a2eb4675f8e1fcf8b990bc345aac694dba8228 (patch)
tree3570f9494687a37e874339f215f69e34fefc3528 /source/blender/python
parent60a299443588f38a9d0a22a5bb45d6142e5afd43 (diff)
py/library api: raise an error if a requested member isn't found.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_library.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c
index f6bbd259df2..977bcabe694 100644
--- a/source/blender/python/intern/bpy_library.c
+++ b/source/blender/python/intern/bpy_library.c
@@ -258,6 +258,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
{
Main *mainl= NULL;
+ int err= 0;
flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
@@ -285,7 +286,11 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
// printf(" %s\n", item_str);
if(item_str) {
- BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, self->flag);
+ if(!BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, self->flag)) {
+ PyErr_Format(PyExc_KeyError, "load: %s does not contain %s[\"%s\"]", self->abspath, name_plural, item_str);
+ err= -1;
+ break;
+ }
}
else {
/* XXX, could complain about this */
@@ -297,26 +302,33 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
}
}
- BLO_library_append_end(NULL, mainl, &(self->blo_handle), 0, self->flag);
- BLO_blendhandle_close(self->blo_handle);
-
- { /* copied from wm_operator.c */
- /* mark all library linked objects to be updated */
- recalc_all_library_objects(G.main);
-
- /* append, rather than linking */
- if((self->flag & FILE_LINK)==0) {
- Library *lib= BLI_findstring(&G.main->library, self->abspath, offsetof(Library, name));
- if(lib) all_local(lib, 1);
- else BLI_assert(!"cant find name of just added library!");
- }
+ if(err == -1) {
+ /* exception raised above, XXX, this leaks some memory */
+ BLO_blendhandle_close(self->blo_handle);
+ self->blo_handle= NULL;
+ return NULL;
}
+ else {
+ BLO_library_append_end(NULL, mainl, &(self->blo_handle), 0, self->flag);
+ BLO_blendhandle_close(self->blo_handle);
+ self->blo_handle= NULL;
+
+ { /* copied from wm_operator.c */
+ /* mark all library linked objects to be updated */
+ recalc_all_library_objects(G.main);
+
+ /* append, rather than linking */
+ if((self->flag & FILE_LINK)==0) {
+ Library *lib= BLI_findstring(&G.main->library, self->abspath, offsetof(Library, name));
+ if(lib) all_local(lib, 1);
+ else BLI_assert(!"cant find name of just added library!");
+ }
+ }
- flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
-
- self->blo_handle= NULL;
+ flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
+ }
}
int bpy_lib_init(PyObject *mod_par)