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 <ideasman42@gmail.com>2021-01-28 01:27:08 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-01-28 01:47:05 +0300
commitdf135b74fc938ec5ff08bc912ece18917165319d (patch)
tree6f8de2de860d761438aa66db8f925c8f7fb42bc6
parente285765a6bce68f664f37965e7bd5429d330bffc (diff)
PyAPI: use PYTHONUTF8/Py_UTF8Mode on all platforms
System encoding issues have been a paint-point for us with Python 3, since Blender always uses UTF-8 which might not be the case for the OS. While the Py_SetStandardStreamEncoding was already set to utf-8, the file-system could still have an incompatible encoding. See PEP-540 for details.
-rw-r--r--source/blender/python/intern/bpy_interface.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index c54c78ae389..830a809408b 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -341,12 +341,20 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
}
}
- /* Without this the `sys.stdout` may be set to 'ascii'
- * (it is on my system at least), where printing unicode values will raise
- * an error, this is highly annoying, another stumbling block for developers,
- * so use a more relaxed error handler and enforce utf-8 since the rest of
- * Blender is utf-8 too - campbell */
- Py_SetStandardStreamEncoding("utf-8", "surrogateescape");
+ /* Force `utf-8` on all platforms, since this is what's used for Blender's internal strings,
+ * providing consistent encoding behavior across all Blender installations.
+ *
+ * This also uses the `surrogateescape` error handler ensures any unexpected bytes are escaped
+ * instead of raising an error.
+ *
+ * Without this `sys.getfilesystemencoding()` and `sys.stdout` for example may be set to ASCII
+ * or some other encoding - where printing some `utf-8` values will raise an error.
+ *
+ * This can cause scripts to fail entirely on some systems.
+ *
+ * This assignment is the equivalent of enabling the `PYTHONUTF8` environment variable.
+ * See `PEP-540` for details on exactly what this changes. */
+ Py_UTF8Mode = 1;
/* Suppress error messages when calculating the module search path.
* While harmless, it's noisy. */