diff rust/hg-cpython/src/filepatterns.rs @ 42634:0247601869ba

rust-filepatterns: fix type of warnings tuple to (bytes, bytes) Otherwise warn() in match.py would fail if the warning contains non-ASCII character. We might want to add a thin ByteString wrapper around Vec<u8> to implement ToPyObject<ObjectType = PyBytes>, but I'm not sure.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 21 Jul 2019 12:46:57 +0900
parents 326fdce22fb2
children ce6797ef6eab
line wrap: on
line diff
--- a/rust/hg-cpython/src/filepatterns.rs	Sun Jul 21 13:48:29 2019 +0900
+++ b/rust/hg-cpython/src/filepatterns.rs	Sun Jul 21 12:46:57 2019 +0900
@@ -40,17 +40,31 @@
                 };
                 let results: Vec<(PyBytes, LineNumber, PyBytes)> =
                     patterns.iter().map(itemgetter).collect();
-                return Ok((results, warnings).to_py_object(py));
+                return Ok((results, warnings_to_py_bytes(py, &warnings))
+                    .to_py_object(py));
             }
             let itemgetter = |x: &PatternTuple| PyBytes::new(py, &x.0);
             let results: Vec<PyBytes> =
                 patterns.iter().map(itemgetter).collect();
-            Ok((results, warnings).to_py_object(py))
+            Ok(
+                (results, warnings_to_py_bytes(py, &warnings))
+                    .to_py_object(py),
+            )
         }
         Err(e) => Err(PatternFileError::pynew(py, e)),
     }
 }
 
+fn warnings_to_py_bytes(
+    py: Python,
+    warnings: &[(Vec<u8>, Vec<u8>)],
+) -> Vec<(PyBytes, PyBytes)> {
+    warnings
+        .iter()
+        .map(|(path, syn)| (PyBytes::new(py, path), PyBytes::new(py, syn)))
+        .collect()
+}
+
 fn build_single_regex_wrapper(
     py: Python,
     kind: PyObject,