[Bf-blender-cvs] [9350005d8b5] master: Fix T13879 new OBJ exporter not saving files with Unicode characters.

Aras Pranckevicius noreply at git.blender.org
Sat Jan 22 02:16:39 CET 2022


Commit: 9350005d8b56a831f4c592d58fdf190af64efad4
Author: Aras Pranckevicius
Date:   Fri Jan 21 20:14:01 2022 -0500
Branches: master
https://developer.blender.org/rB9350005d8b56a831f4c592d58fdf190af64efad4

Fix T13879 new OBJ exporter not saving files with Unicode characters.

Need to use BLI_fopen instead of fopen.

===================================================================

M	source/blender/io/wavefront_obj/exporter/obj_export_io.hh
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh
index e88a76fc4e8..daae8ae52c8 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh
@@ -26,6 +26,7 @@
 #include <type_traits>
 
 #include "BLI_compiler_attrs.h"
+#include "BLI_fileops.h"
 #include "BLI_string_ref.hh"
 #include "BLI_utility_mixins.hh"
 
@@ -276,7 +277,7 @@ template<eFileType filetype> class FormattedFileHandler : NonCopyable, NonMovabl
   FormattedFileHandler(std::string outfile_path) noexcept(false)
       : outfile_path_(std::move(outfile_path))
   {
-    outfile_ = std::fopen(outfile_path_.c_str(), "w");
+    outfile_ = BLI_fopen(outfile_path_.c_str(), "w");
     if (!outfile_) {
       throw std::system_error(errno, std::system_category(), "Cannot open file " + outfile_path_);
     }
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
index 5dac913c902..89e1de49511 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -1,10 +1,8 @@
 /* Apache License, Version 2.0 */
 
-#include <fstream>
 #include <gtest/gtest.h>
 #include <ios>
 #include <memory>
-#include <sstream>
 #include <string>
 #include <system_error>
 
@@ -185,15 +183,21 @@ static std::unique_ptr<OBJWriter> init_writer(const OBJExportParams &params,
   }
 }
 
-/* The following is relative to BKE_tempdir_base. */
-const char *const temp_file_path = "output.OBJ";
+/* The following is relative to BKE_tempdir_base.
+ * Use Latin Capital Letter A with Ogonek, Cyrillic Capital Letter Zhe
+ * at the end, to test I/O on non-English file names. */
+const char *const temp_file_path = "output\xc4\x84\xd0\x96.OBJ";
 
 static std::string read_temp_file_in_string(const std::string &file_path)
 {
-  std::ifstream temp_stream(file_path);
-  std::ostringstream input_ss;
-  input_ss << temp_stream.rdbuf();
-  return input_ss.str();
+  std::string res;
+  size_t buffer_len;
+  void *buffer = BLI_file_read_text_as_mem(file_path.c_str(), 0, &buffer_len);
+  if (buffer != NULL) {
+    res.assign((const char *)buffer, buffer_len);
+    MEM_freeN(buffer);
+  }
+  return res;
 }
 
 TEST(obj_exporter_writer, header)



More information about the Bf-blender-cvs mailing list