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


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 :




Assigning to myself,

Note, theres an api for this.



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,