From 25a2eb4675f8e1fcf8b990bc345aac694dba8228 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 13 Mar 2011 01:15:14 +0000 Subject: py/library api: raise an error if a requested member isn't found. --- source/blender/python/intern/bpy_library.c | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'source/blender/python') 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) -- cgit v1.2.3