Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/core/IronPython.Modules/fcntl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ a file object.
""";


// supporting fcntl.ioctl(fileno, termios.TIOCGWINSZ, buf)
// where buf = array.array('h', [0, 0, 0, 0])
public static object ioctl(CodeContext context, int fd, int cmd, [NotNone] IBufferProtocol arg, int mutate_flag = 1) {
if (cmd == PythonTermios.TIOCGWINSZ) {
using IPythonBuffer buf = arg.GetBuffer();

Span<short> winsize = stackalloc short[4];
winsize[0] = (short)Console.WindowHeight;
winsize[1] = (short)Console.WindowWidth;
winsize[2] = (short)Console.BufferHeight; // buffer height and width are not accurate on macOS
winsize[3] = (short)Console.BufferWidth;
Span<byte> payload = MemoryMarshal.Cast<short, byte>(winsize);

if (buf.IsReadOnly || mutate_flag == 0) {
byte[] res = buf.ToArray();
payload.Slice(0, Math.Min(payload.Length, res.Length)).CopyTo(res);
return Bytes.Make(res);
} else {
var res = buf.AsSpan();
payload.Slice(0, Math.Min(payload.Length, res.Length)).CopyTo(res);
return 0;
}
}
throw new NotImplementedException($"ioctl: unsupported command {cmd}");
}


// FD Flags
public static int FD_CLOEXEC = 1;
public static int FASYNC => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x0040 : 0x2000;
Expand Down
8 changes: 5 additions & 3 deletions tests/suite/test_builtin_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ def load_tests(loader, standard_tests, pattern):
test.test_builtin.BuiltinTest('test_input'),
test.test_builtin.BuiltinTest('test_len'),
test.test_builtin.BuiltinTest('test_open_non_inheritable'), # https://github.com/IronLanguages/ironpython3/issues/1225
]

skip_tests = [
# module `pty` is importable but not functional on .NET Core
test.test_builtin.PtyTests('test_input_no_stdout_fileno'),
test.test_builtin.PtyTests('test_input_tty'),
test.test_builtin.PtyTests('test_input_tty_non_ascii'),
test.test_builtin.PtyTests('test_input_tty_non_ascii_unicode_errors'),
test.test_builtin.ShutdownTest('test_cleanup'),
]

skip_tests = []
if is_netcoreapp:
skip_tests += [
test.test_builtin.ShutdownTest('test_cleanup'),
]

return generate_suite(tests, failing_tests, skip_tests)
Expand Down