bus error with python with link_append and {}
Closed, ResolvedPublic

Description

While I was experimenting with python (i am a newbie) and trying to link_append some materials, I wrote some lines (certainly wrong) and get a bus error.
bpy.ops.wm.link_append(directory="/Users/o/Dropbox/blender/blendmine/matlib.blend/Material", link=False, filename={'lib_red','lib_green'} ,relative_path=True)

please see the attached file, and execute the script. it should crash
crashing on mac, windows and linux.

It doesn't matter if the lib file in directory is found or not, it always crashes whenever I use {} or [] in filename. (it is certainly not the way to append a collection of items, but it should not make a bus error)
It works when I append just one file.

here is the crashlog :

http://www.pasteall.org/26541

Details

Type
Bug

Assigning to myself,

Note, theres an api for this.

http://www.blender.org/documentation/blender_python_api_2_60_4/bpy.types.BlendDataLibraries.html#bpy.types.BlendDataLibraries

Hi!

Here's a patch which I believe fixes this:

diff --git a/blender/source/blender/python/generic/py_capi_utils.c b/blender/source/blender/python/generic/py_capi_utils.c
index 7fbd8ba..f711fb9 100644
--- a/blender/source/blender/python/generic/py_capi_utils.c
+++ b/blender/source/blender/python/generic/py_capi_utils.c
@@ -386,7 +386,10 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
return PyBytes_AS_STRING(py_str);
}
else {
- return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(py_str)));
+ if (*coerce= PyUnicode_EncodeFSDefault(py_str)) {
+ return PyBytes_AS_STRING(*coerce);
+ }
+ return NULL;
}
}
}

This was diffed in a git mirror of the Subversion repo, but the filenames should be the same so that should be safe to apply.

The root cause is that the code is ... strange, it's passing a set literal where a string is expected. Then (I think, haven't analyzed this very deeply) an attempt is made to coerce the set into being a string, which fails, but there's no handling of the failure so instead we get a crash.

With this patch, it fails "properly", with a message like this:

TypeError: Converting py args to operator properties: WM_OT_link_append.filename expected a string type, not set

I hope this helps!

I've tried attaching a patch with the code, since the formatting got a bit messed up in my response.

fixed r42064. thx for the patch,