Skip to content

Commit 17eb367

Browse files
committed
Clean up some error usage in mmap
1 parent 9035d36 commit 17eb367

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Src/IronPython.Modules/mmap.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public void resize(long newsize) {
807807
// resize on Posix platforms
808808
try {
809809
if (_handle.IsInvalid) {
810-
throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
810+
throw PythonNT.GetOsError(PythonErrno.EBADF);
811811
}
812812
_view.Flush();
813813
_view.Dispose();
@@ -1109,20 +1109,18 @@ internal Bytes GetSearchString() {
11091109
}
11101110
}
11111111

1112-
[SupportedOSPlatform("linux"), SupportedOSPlatform("macos")]
1112+
[SupportedOSPlatform("linux")]
1113+
[SupportedOSPlatform("macos")]
11131114
private static long GetFileSizeUnix(SafeFileHandle handle) {
11141115
long size;
11151116
if (handle.IsInvalid) {
1116-
throw PythonOps.OSError(PythonExceptions._OSError.ERROR_INVALID_HANDLE, "Invalid file handle");
1117+
throw PythonNT.GetOsError(PythonErrno.EBADF);
11171118
}
11181119

11191120
if (Mono.Unix.Native.Syscall.fstat((int)handle.DangerousGetHandle(), out Mono.Unix.Native.Stat status) == 0) {
11201121
size = status.st_size;
11211122
} else {
1122-
Mono.Unix.Native.Errno errno = Mono.Unix.Native.Stdlib.GetLastError();
1123-
string msg = Mono.Unix.UnixMarshal.GetErrorDescription(errno);
1124-
int error = Mono.Unix.Native.NativeConvert.FromErrno(errno);
1125-
throw PythonOps.OSError(error, msg);
1123+
throw PythonNT.GetLastUnixError();
11261124
}
11271125

11281126
return size;

Src/IronPython.Modules/nt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ private static Exception DirectoryExistsError(string? filename) {
23132313
}
23142314

23152315

2316-
private static Exception GetOsError(int error, string? filename = null, string? filename2 = null)
2316+
internal static Exception GetOsError(int error, string? filename = null, string? filename2 = null)
23172317
=> PythonOps.OSError(error, strerror(error), filename, null, filename2);
23182318

23192319
#if FEATURE_NATIVE || FEATURE_CTYPES

Src/IronPython.Modules/posix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static partial class PythonNT {
2828

2929
[SupportedOSPlatform("linux")]
3030
[SupportedOSPlatform("osx")]
31-
private static Exception GetLastUnixError(string? filename = null, string? filename2 = null)
31+
internal static Exception GetLastUnixError(string? filename = null, string? filename2 = null)
3232
// On POSIX, GetLastWin32Error returns the errno value, same as GetLastPInvokeError
3333
=> GetOsError(Marshal.GetLastWin32Error(), filename, filename2);
3434

0 commit comments

Comments
 (0)