diff --git a/Cargo.lock b/Cargo.lock index b4507ae3b..21bd128a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1585,6 +1585,7 @@ dependencies = [ "env_logger", "flame", "flamescope", + "libc", "log", "num-traits", "rustpython-compiler", diff --git a/Cargo.toml b/Cargo.toml index 2eaf31095..38f080585 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ pylib = { package = "rustpython-pylib", path = "vm/pylib-crate", version = "0.1. dirs = { package = "dirs-next", version = "1.0" } num-traits = "0.2.8" cfg-if = "0.1" +libc = "0.2" flame = { version = "0.2", optional = true } flamescope = { version = "0.1", optional = true } diff --git a/Lib/_codecs.py b/Lib/_codecs.py index 2c86f4932..eca7a38c2 100644 --- a/Lib/_codecs.py +++ b/Lib/_codecs.py @@ -1006,8 +1006,8 @@ def PyUnicode_DecodeUTF16Stateful(s, size, errors, byteorder='native', final=Tru # have any nested variables. def STORECHAR(CH, byteorder): - hi = chr(((CH) >> 8) & 0xff) - lo = chr((CH) & 0xff) + hi = (CH >> 8) & 0xff + lo = CH & 0xff if byteorder == 'little': return [lo, hi] else: diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index aa0dd6d87..6241d114d 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -817,18 +817,14 @@ class CommandLineTestCase(unittest.TestCase): self.assertIn(b'January', stdout) self.assertIn(b'Mo Tu We Th Fr Sa Su', stdout) - @unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows') def test_output_year(self): stdout = self.run_ok('2004') self.assertEqual(stdout, conv(result_2004_text)) - @unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows') def test_output_month(self): stdout = self.run_ok('2004', '1') self.assertEqual(stdout, conv(result_2004_01_text)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_option_encoding(self): self.assertFailure('-e') self.assertFailure('--encoding') @@ -860,7 +856,6 @@ class CommandLineTestCase(unittest.TestCase): stdout = self.run_ok('--width', '3', '2004') self.assertIn(b'Mon Tue Wed Thu Fri Sat Sun', stdout) - @unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows') def test_option_lines(self): self.assertFailure('-l') self.assertFailure('--lines') @@ -875,7 +870,6 @@ class CommandLineTestCase(unittest.TestCase): stdout = self.run_ok('--spacing', '8', '2004') self.assertIn(b'Su Mo', stdout) - @unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows') def test_option_months(self): self.assertFailure('-m') self.assertFailure('--month') @@ -883,7 +877,6 @@ class CommandLineTestCase(unittest.TestCase): stdout = self.run_ok('--months', '1', '2004') self.assertIn(conv('\nMo Tu We Th Fr Sa Su\n'), stdout) - @unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows') def test_option_type(self): self.assertFailure('-t') self.assertFailure('--type') diff --git a/src/main.rs b/src/main.rs index 9c4e075be..dda81e9e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,19 @@ fn main() { settings.initialization_parameter = InitParameter::InitializeInternal; } + // don't translate newlines (\r\n <=> \n) + #[cfg(windows)] + { + extern "C" { + fn _setmode(fd: i32, flags: i32) -> i32; + } + unsafe { + _setmode(0, libc::O_BINARY); + _setmode(1, libc::O_BINARY); + _setmode(2, libc::O_BINARY); + } + } + let vm = VirtualMachine::new(settings); let res = run_rustpython(&vm, &matches);