Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make msvcrt Windows-only #1708

Merged
merged 1 commit into from
Jul 13, 2023
Merged
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
14 changes: 2 additions & 12 deletions Src/IronPython.Modules/msvcrt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

using Microsoft.Scripting.Runtime;

Expand All @@ -24,6 +25,7 @@
[assembly: PythonModule("msvcrt", typeof(IronPython.Modules.PythonMsvcrt), PlatformsAttribute.PlatformFamily.Windows)]
namespace IronPython.Modules {
[PythonType("msvcrt")]
[SupportedOSPlatform("windows")]
public class PythonMsvcrt {
public const string __doc__ = "Functions from the Microsoft Visual C Runtime.";

Expand Down Expand Up @@ -76,10 +78,6 @@ private static bool TryGetFileHandle(Stream stream, out object handle) {
handle = ((PipeStream)stream).SafePipeHandle.DangerousGetHandle().ToPython();
return true;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
handle = GetFileHandleUnix();
if (handle != null) return true;
}
#endif

// if all else fails try reflection
Expand All @@ -91,14 +89,6 @@ private static bool TryGetFileHandle(Stream stream, out object handle) {

handle = null;
return false;

// Isolate Mono.Unix from the rest of the method so that we don't try to load the Mono.Unix assembly on Windows.
object GetFileHandleUnix() {
if (stream is Mono.Unix.UnixStream) {
return ((Mono.Unix.UnixStream)stream).Handle;
}
return null;
}
}

[Documentation(@"get_osfhandle(fd) -> file handle
Expand Down
Loading