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 <campbell@blender.org>2022-03-28 08:37:09 +0300
committerCampbell Barton <campbell@blender.org>2022-03-28 08:44:25 +0300
commit3ea90de9e65154a150f2150473d297d85ff09815 (patch)
treeba387fbda09755d7dd4e57807eb6e38e06702643 /source/blender/python/intern/bpy_interface_run.c
parente8fd2d846926a9ee1a934e68e7dd69ced10080f5 (diff)
Fix text editor failure to move the cursor for syntax errors
This broke between 3.0 and 3.1, upgrading to Python 3.10 seems the likely cause as this code didn't change.
Diffstat (limited to 'source/blender/python/intern/bpy_interface_run.c')
-rw-r--r--source/blender/python/intern/bpy_interface_run.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_interface_run.c b/source/blender/python/intern/bpy_interface_run.c
index 8db122470b8..37abf930cff 100644
--- a/source/blender/python/intern/bpy_interface_run.c
+++ b/source/blender/python/intern/bpy_interface_run.c
@@ -35,11 +35,11 @@
/** \name Private Utilities
* \{ */
-static void python_script_error_jump_text(Text *text)
+static void python_script_error_jump_text(Text *text, const char *filepath)
{
int lineno;
int offset;
- python_script_error_jump(text->id.name + 2, &lineno, &offset);
+ python_script_error_jump(filepath, &lineno, &offset);
if (lineno != -1) {
/* select the line with the error */
txt_move_to(text, lineno - 1, INT_MAX, false);
@@ -82,6 +82,10 @@ static bool python_script_exec(
PyObject *py_dict = NULL, *py_result = NULL;
PyGILState_STATE gilstate;
+ char fn_dummy[FILE_MAX];
+ /** The `__file__` added into the name-space. */
+ const char *fn_namespace = NULL;
+
BLI_assert(fn || text);
if (fn == NULL && text == NULL) {
@@ -93,8 +97,8 @@ static bool python_script_exec(
PyC_MainModule_Backup(&main_mod);
if (text) {
- char fn_dummy[FILE_MAXDIR];
bpy_text_filename_get(fn_dummy, bmain_old, sizeof(fn_dummy), text);
+ fn_namespace = fn_dummy;
if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */
char *buf;
@@ -111,7 +115,7 @@ static bool python_script_exec(
if (PyErr_Occurred()) {
if (do_jump) {
- python_script_error_jump_text(text);
+ python_script_error_jump_text(text, fn_namespace);
}
BPY_text_free_code(text);
}
@@ -124,6 +128,7 @@ static bool python_script_exec(
}
else {
FILE *fp = BLI_fopen(fn, "r");
+ fn_namespace = fn;
if (fp) {
py_dict = PyC_DefaultNameSpace(fn);
@@ -170,7 +175,7 @@ static bool python_script_exec(
/* ensure text is valid before use, the script may have freed itself */
Main *bmain_new = CTX_data_main(C);
if ((bmain_old == bmain_new) && (BLI_findindex(&bmain_new->texts, text) != -1)) {
- python_script_error_jump_text(text);
+ python_script_error_jump_text(text, fn_namespace);
}
}
}