Skip to content

Commit 3be3328

Browse files
committed
Rename PythonErrorNumber to PythonErrno
1 parent c02f027 commit 3be3328

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

Src/IronPython.Modules/_socket.cs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void __init__(CodeContext/*!*/ context, int family = DefaultAddressFamily
154154
socket = HandleToSocket(handle);
155155
if (socket is null) {
156156
throw PythonOps.OSError(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
157-
? PythonErrorNumber.WSAENOTSOCK : PythonErrorNumber.EBADF,
157+
? PythonErrno.WSAENOTSOCK : PythonErrno.EBADF,
158158
"Bad file descriptor");
159159
}
160160
} else {
@@ -310,7 +310,7 @@ public int connect_ex([NotNone] PythonTuple address) {
310310
} catch (SocketException ex) {
311311
return !ClrModule.IsMono ? ex.NativeErrorCode : MapMonoSocketErrorToErrno(ex.SocketErrorCode);
312312
}
313-
return PythonErrorNumber.ENOERROR;
313+
return PythonErrno.ENOERROR;
314314
}
315315

316316
public long detach() {
@@ -1768,15 +1768,15 @@ internal static Exception MakeException(CodeContext/*!*/ context, Exception exce
17681768
// The following SocketErrors have no defined mapping to errno, so a generic errno is used instead
17691769
case SocketError.ProcessLimit:
17701770
return PythonExceptions.CreateThrowable(error,
1771-
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PythonErrorNumber.EPROCLIM : PythonErrorNumber.ENOTSUP,
1771+
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PythonErrno.EPROCLIM : PythonErrno.ENOTSUP,
17721772
"Too many processes");
17731773
case SocketError.NotInitialized:
17741774
case SocketError.SystemNotReady:
17751775
case SocketError.VersionNotSupported:
17761776
case SocketError.TypeNotFound:
1777-
return PythonExceptions.CreateThrowable(error, PythonErrorNumber.ENOTSUP, $"Socket error: {se.SocketErrorCode}");
1777+
return PythonExceptions.CreateThrowable(error, PythonErrno.ENOTSUP, $"Socket error: {se.SocketErrorCode}");
17781778
case SocketError.SocketError:
1779-
return PythonExceptions.CreateThrowable(error, PythonErrorNumber.EIO, $"Unknown socket error");
1779+
return PythonExceptions.CreateThrowable(error, PythonErrno.EIO, $"Unknown socket error");
17801780

17811781
// For the rest, NativeErrorCode provides the errno (except on Mono)
17821782
default:
@@ -1787,7 +1787,7 @@ internal static Exception MakeException(CodeContext/*!*/ context, Exception exce
17871787
return PythonExceptions.CreateThrowable(error, se.NativeErrorCode, se.Message);
17881788
}
17891789
} else if (exception is ObjectDisposedException) {
1790-
return PythonExceptions.CreateThrowable(error, PythonErrorNumber.EBADF, "Socket is closed");
1790+
return PythonExceptions.CreateThrowable(error, PythonErrno.EBADF, "Socket is closed");
17911791
} else if (exception is InvalidOperationException or ArgumentException) {
17921792
return MakeException(context, new SocketException((int)SocketError.InvalidArgument));
17931793
} else {
@@ -1856,56 +1856,56 @@ private static Exception MakeGaiException(CodeContext context, int eaiCode) {
18561856
private static int MapMonoSocketErrorToErrno(SocketError serror) {
18571857
monoSocketErrorToNativeError ??= new Dictionary<SocketError, int>(45)
18581858
{
1859-
{ SocketError.AccessDenied, PythonErrorNumber.EACCES}, // could also have been EPERM
1860-
{ SocketError.AddressAlreadyInUse, PythonErrorNumber.EADDRINUSE },
1861-
{ SocketError.AddressNotAvailable, PythonErrorNumber.EADDRNOTAVAIL },
1862-
{ SocketError.AddressFamilyNotSupported, PythonErrorNumber.EAFNOSUPPORT },
1863-
{ SocketError.AlreadyInProgress, PythonErrorNumber.EALREADY },
1864-
{ SocketError.ConnectionAborted, PythonErrorNumber.ECONNABORTED },
1865-
{ SocketError.ConnectionRefused, PythonErrorNumber.ECONNREFUSED },
1866-
{ SocketError.ConnectionReset, PythonErrorNumber.ECONNRESET },
1867-
{ SocketError.DestinationAddressRequired, PythonErrorNumber.EDESTADDRREQ },
1868-
{ SocketError.Disconnecting, PythonErrorNumber.ESHUTDOWN },
1869-
{ SocketError.Fault, PythonErrorNumber.EFAULT },
1870-
{ SocketError.HostDown, PythonErrorNumber.EHOSTDOWN },
1871-
{ SocketError.HostNotFound, PythonErrorNumber.ENOENT },
1872-
{ SocketError.HostUnreachable, PythonErrorNumber.EHOSTUNREACH },
1873-
{ SocketError.InProgress, PythonErrorNumber.EINPROGRESS },
1874-
{ SocketError.Interrupted, PythonErrorNumber.EINTR },
1875-
{ SocketError.InvalidArgument, PythonErrorNumber.EINVAL },
1876-
{ SocketError.IOPending, PythonErrorNumber.EINPROGRESS },
1877-
{ SocketError.IsConnected, PythonErrorNumber.EISCONN },
1878-
{ SocketError.MessageSize, PythonErrorNumber.EMSGSIZE },
1879-
{ SocketError.NetworkDown, PythonErrorNumber.ENETDOWN },
1880-
{ SocketError.NetworkReset, PythonErrorNumber.ENETRESET },
1881-
{ SocketError.NetworkUnreachable, PythonErrorNumber.ENETUNREACH },
1882-
{ SocketError.NoBufferSpaceAvailable, PythonErrorNumber.ENOBUFS },
1883-
{ SocketError.NoData, PythonErrorNumber.ENODATA },
1884-
{ SocketError.NotConnected, PythonErrorNumber.ENOTCONN },
1885-
{ SocketError.NotInitialized, PythonErrorNumber.ENOTSUP },
1886-
{ SocketError.NotSocket, PythonErrorNumber.ENOTSOCK },
1887-
{ SocketError.OperationAborted, PythonErrorNumber.ECANCELED },
1888-
{ SocketError.OperationNotSupported, PythonErrorNumber.ENOTSUP },
1889-
{ SocketError.ProcessLimit, !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PythonErrorNumber.EPROCLIM : PythonErrorNumber.ENOTSUP },
1890-
{ SocketError.ProtocolFamilyNotSupported, PythonErrorNumber.EPFNOSUPPORT },
1891-
{ SocketError.ProtocolNotSupported, PythonErrorNumber.EPROTONOSUPPORT },
1892-
{ SocketError.ProtocolOption, PythonErrorNumber.ENOPROTOOPT },
1893-
{ SocketError.ProtocolType, PythonErrorNumber.EPROTOTYPE },
1894-
{ SocketError.Shutdown, PythonErrorNumber.EPIPE },
1895-
{ SocketError.SocketNotSupported, PythonErrorNumber.ESOCKTNOSUPPORT },
1896-
{ SocketError.Success, PythonErrorNumber.ENOERROR },
1897-
{ SocketError.SystemNotReady, PythonErrorNumber.ENOTSUP }, // or EAGAIN
1898-
{ SocketError.TimedOut, PythonErrorNumber.ETIMEDOUT },
1899-
{ SocketError.TooManyOpenSockets, PythonErrorNumber.ENFILE }, // could also have been EMFILE
1900-
{ SocketError.TryAgain, PythonErrorNumber.EAGAIN }, // not a perfect mapping, but better than nothing
1901-
{ SocketError.TypeNotFound, PythonErrorNumber.ENOTSOCK },
1902-
{ SocketError.VersionNotSupported, PythonErrorNumber.EPROTONOSUPPORT },
1903-
{ SocketError.WouldBlock, PythonErrorNumber.EWOULDBLOCK }, // on Linux/OSX, same as EAGAIN
1859+
{ SocketError.AccessDenied, PythonErrno.EACCES}, // could also have been EPERM
1860+
{ SocketError.AddressAlreadyInUse, PythonErrno.EADDRINUSE },
1861+
{ SocketError.AddressNotAvailable, PythonErrno.EADDRNOTAVAIL },
1862+
{ SocketError.AddressFamilyNotSupported, PythonErrno.EAFNOSUPPORT },
1863+
{ SocketError.AlreadyInProgress, PythonErrno.EALREADY },
1864+
{ SocketError.ConnectionAborted, PythonErrno.ECONNABORTED },
1865+
{ SocketError.ConnectionRefused, PythonErrno.ECONNREFUSED },
1866+
{ SocketError.ConnectionReset, PythonErrno.ECONNRESET },
1867+
{ SocketError.DestinationAddressRequired, PythonErrno.EDESTADDRREQ },
1868+
{ SocketError.Disconnecting, PythonErrno.ESHUTDOWN },
1869+
{ SocketError.Fault, PythonErrno.EFAULT },
1870+
{ SocketError.HostDown, PythonErrno.EHOSTDOWN },
1871+
{ SocketError.HostNotFound, PythonErrno.ENOENT },
1872+
{ SocketError.HostUnreachable, PythonErrno.EHOSTUNREACH },
1873+
{ SocketError.InProgress, PythonErrno.EINPROGRESS },
1874+
{ SocketError.Interrupted, PythonErrno.EINTR },
1875+
{ SocketError.InvalidArgument, PythonErrno.EINVAL },
1876+
{ SocketError.IOPending, PythonErrno.EINPROGRESS },
1877+
{ SocketError.IsConnected, PythonErrno.EISCONN },
1878+
{ SocketError.MessageSize, PythonErrno.EMSGSIZE },
1879+
{ SocketError.NetworkDown, PythonErrno.ENETDOWN },
1880+
{ SocketError.NetworkReset, PythonErrno.ENETRESET },
1881+
{ SocketError.NetworkUnreachable, PythonErrno.ENETUNREACH },
1882+
{ SocketError.NoBufferSpaceAvailable, PythonErrno.ENOBUFS },
1883+
{ SocketError.NoData, PythonErrno.ENODATA },
1884+
{ SocketError.NotConnected, PythonErrno.ENOTCONN },
1885+
{ SocketError.NotInitialized, PythonErrno.ENOTSUP },
1886+
{ SocketError.NotSocket, PythonErrno.ENOTSOCK },
1887+
{ SocketError.OperationAborted, PythonErrno.ECANCELED },
1888+
{ SocketError.OperationNotSupported, PythonErrno.ENOTSUP },
1889+
{ SocketError.ProcessLimit, !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PythonErrno.EPROCLIM : PythonErrno.ENOTSUP },
1890+
{ SocketError.ProtocolFamilyNotSupported, PythonErrno.EPFNOSUPPORT },
1891+
{ SocketError.ProtocolNotSupported, PythonErrno.EPROTONOSUPPORT },
1892+
{ SocketError.ProtocolOption, PythonErrno.ENOPROTOOPT },
1893+
{ SocketError.ProtocolType, PythonErrno.EPROTOTYPE },
1894+
{ SocketError.Shutdown, PythonErrno.EPIPE },
1895+
{ SocketError.SocketNotSupported, PythonErrno.ESOCKTNOSUPPORT },
1896+
{ SocketError.Success, PythonErrno.ENOERROR },
1897+
{ SocketError.SystemNotReady, PythonErrno.ENOTSUP }, // or EAGAIN
1898+
{ SocketError.TimedOut, PythonErrno.ETIMEDOUT },
1899+
{ SocketError.TooManyOpenSockets, PythonErrno.ENFILE }, // could also have been EMFILE
1900+
{ SocketError.TryAgain, PythonErrno.EAGAIN }, // not a perfect mapping, but better than nothing
1901+
{ SocketError.TypeNotFound, PythonErrno.ENOTSOCK },
1902+
{ SocketError.VersionNotSupported, PythonErrno.EPROTONOSUPPORT },
1903+
{ SocketError.WouldBlock, PythonErrno.EWOULDBLOCK }, // on Linux/OSX, same as EAGAIN
19041904
};
19051905
if (monoSocketErrorToNativeError.TryGetValue(serror, out int errno)) {
19061906
return errno;
19071907
} else {
1908-
return PythonErrorNumber.EIO;
1908+
return PythonErrno.EIO;
19091909
}
19101910
}
19111911

Src/IronPython.Modules/errno.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
using IronPython.Runtime;
1010

11-
[assembly: PythonModule("errno", typeof(IronPython.Modules.PythonErrorNumber))]
11+
[assembly: PythonModule("errno", typeof(IronPython.Modules.PythonErrno))]
1212
namespace IronPython.Modules {
13-
public static class PythonErrorNumber {
13+
public static class PythonErrno {
1414
public const string __doc__ = "Provides a list of common error numbers. These numbers are frequently reported in various exceptions.";
1515

1616
internal const int ENOERROR = 0;

Src/IronPython.Modules/mmap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public MmapUnix(CodeContext/*!*/ context, int fileno, long length, int flags = M
234234
private static MemoryMappedFileAccess ToMmapFileAccess(int flags, int prot, int access) {
235235
if (access == ACCESS_DEFAULT) {
236236
if ((flags & (MAP_PRIVATE | MAP_SHARED)) == 0) {
237-
throw PythonOps.OSError(PythonErrorNumber.EINVAL, "Invalid argument");
237+
throw PythonOps.OSError(PythonErrno.EINVAL, "Invalid argument");
238238
}
239239
if ((prot & PROT_WRITE) != 0) {
240240
prot |= PROT_READ;
@@ -830,7 +830,7 @@ public void resize(long newsize) {
830830
// resize on Posix platforms
831831
try {
832832
if (_handle.IsInvalid) {
833-
throw PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor");
833+
throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
834834
}
835835
_view.Flush();
836836
_view.Dispose();

Src/IronPython.Modules/nt.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public static int dup2(CodeContext/*!*/ context, int fd, int fd2) {
397397
}
398398

399399
if (!fileManager.ValidateFdRange(fd2)) {
400-
throw PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor");
400+
throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
401401
}
402402

403403
if (fileManager.TryGetStreams(fd2, out _)) {
@@ -496,7 +496,7 @@ public static object fstat(CodeContext/*!*/ context, int fd) {
496496
if (streams.IsStandardIOStream()) return new stat_result(0x1000);
497497
if (StatStream(streams.ReadStream) is not null and var res) return res;
498498
}
499-
return LightExceptions.Throw(PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor"));
499+
return LightExceptions.Throw(PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor"));
500500

501501
static object? StatStream(Stream stream) {
502502
if (stream is FileStream fs) return lstat(fs.Name, new Dictionary<string, object>(1));
@@ -516,7 +516,7 @@ public static void fsync(CodeContext context, int fd) {
516516
try {
517517
streams.Flush();
518518
} catch (IOException) {
519-
throw PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor");
519+
throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
520520
}
521521
}
522522

@@ -1039,13 +1039,13 @@ public static void putenv([NotNone] string name, [NotNone] string value) {
10391039

10401040
public static Bytes read(CodeContext/*!*/ context, int fd, int buffersize) {
10411041
if (buffersize < 0) {
1042-
throw PythonOps.OSError(PythonErrorNumber.EINVAL, "Invalid argument");
1042+
throw PythonOps.OSError(PythonErrno.EINVAL, "Invalid argument");
10431043
}
10441044

10451045
try {
10461046
PythonContext pythonContext = context.LanguageContext;
10471047
var streams = pythonContext.FileManager.GetStreams(fd);
1048-
if (!streams.ReadStream.CanRead) throw PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor");
1048+
if (!streams.ReadStream.CanRead) throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
10491049

10501050
return Bytes.Make(streams.Read(buffersize));
10511051
} catch (Exception e) {
@@ -1942,7 +1942,7 @@ public static PythonTuple waitpid(int pid, int options) {
19421942
Process? process;
19431943
lock (_processToIdMapping) {
19441944
if (!_processToIdMapping.TryGetValue(pid, out process)) {
1945-
throw GetOsError(PythonErrorNumber.ECHILD);
1945+
throw GetOsError(PythonErrno.ECHILD);
19461946
}
19471947
}
19481948

@@ -1964,7 +1964,7 @@ public static int write(CodeContext/*!*/ context, int fd, [NotNone] IBufferProto
19641964
using var buffer = data.GetBuffer();
19651965
PythonContext pythonContext = context.LanguageContext;
19661966
var streams = pythonContext.FileManager.GetStreams(fd);
1967-
if (!streams.WriteStream.CanWrite) throw PythonOps.OSError(PythonErrorNumber.EBADF, "Bad file descriptor");
1967+
if (!streams.WriteStream.CanWrite) throw PythonOps.OSError(PythonErrno.EBADF, "Bad file descriptor");
19681968

19691969
return streams.Write(buffer);
19701970
} catch (Exception e) {
@@ -2411,7 +2411,7 @@ private static Exception DirectoryExistsError(string? filename) {
24112411
return GetWin32Error(PythonExceptions._OSError.ERROR_ALREADY_EXISTS, filename);
24122412
}
24132413
#endif
2414-
return GetOsError(PythonErrorNumber.EEXIST, filename);
2414+
return GetOsError(PythonErrno.EEXIST, filename);
24152415
}
24162416

24172417
#if FEATURE_NATIVE

0 commit comments

Comments
 (0)