[Bf-blender-cvs] [4d1a109] master: Fix T35176: Python fails with blend files from non-ASCII paths
Campbell Barton
noreply at git.blender.org
Wed Apr 30 15:47:08 CEST 2014
Commit: 4d1a109ddec02ad7e527d8b65a5cdc8d4a7528a9
Author: Campbell Barton
Date: Wed Apr 30 23:43:01 2014 +1000
https://developer.blender.org/rB4d1a109ddec02ad7e527d8b65a5cdc8d4a7528a9
Fix T35176: Python fails with blend files from non-ASCII paths
Thanks to Tamito for updating the patch to support Freestyle!
===================================================================
M source/blender/python/generic/bpy_internal_import.c
M source/blender/python/intern/bpy_interface.c
===================================================================
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index a0e6204..2d19fdb 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -47,6 +47,8 @@
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h"
+#include "py_capi_utils.h"
+
#include "bpy_internal_import.h" /* own include */
static Main *bpy_import_main = NULL;
@@ -133,6 +135,7 @@ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
bool bpy_text_compile(Text *text)
{
char fn_dummy[FILE_MAX];
+ PyObject *fn_dummy_py;
char *buf;
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
@@ -140,10 +143,14 @@ bool bpy_text_compile(Text *text)
/* if previously compiled, free the object */
free_compiled_text(text);
+ fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);
+
buf = txt_to_buf(text);
- text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
+ text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
MEM_freeN(buf);
+ Py_DECREF(fn_dummy_py);
+
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 93bced3..99e741c 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -463,12 +463,17 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */
- char *buf = txt_to_buf(text);
+ char *buf;
+ PyObject *fn_dummy_py;
- text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
+ fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);
+ buf = txt_to_buf(text);
+ text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
MEM_freeN(buf);
+ Py_DECREF(fn_dummy_py);
+
if (PyErr_Occurred()) {
if (do_jump) {
python_script_error_jump_text(text);
More information about the Bf-blender-cvs
mailing list