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
23 changes: 5 additions & 18 deletions Src/IronPython.Modules/select.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if FEATURE_SYNC_SOCKETS

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Scripting;
using System.Net.Sockets;

using IronPython.Runtime;
using IronPython.Runtime.Exceptions;
using IronPython.Runtime.Operations;
using IronPython.Runtime.Types;

using Microsoft.Scripting.Runtime;
using System.Runtime.CompilerServices;
using Microsoft.Scripting.Utils;

using System.Net.Sockets;

[assembly: PythonModule("select", typeof(IronPython.Modules.PythonSelect))]
namespace IronPython.Modules {
Expand Down Expand Up @@ -67,9 +63,9 @@ public static PythonTuple select(CodeContext/*!*/ context, object iwtd, object o
try {
Socket.Select(readerList, writerList, errorList, timeoutMicroseconds);
} catch (ArgumentNullException) {
throw MakeException(context, SocketExceptionToTuple(new SocketException((int)SocketError.InvalidArgument)));
throw PythonSocket.MakeException(context, new SocketException((int)SocketError.InvalidArgument));
} catch (SocketException e) {
throw MakeException(context, SocketExceptionToTuple(e));
throw PythonSocket.MakeException(context, e);
}

// Convert back to what the user originally passed in
Expand All @@ -80,14 +76,6 @@ public static PythonTuple select(CodeContext/*!*/ context, object iwtd, object o
return PythonTuple.MakeTuple(readerList, writerList, errorList);
}

private static PythonTuple SocketExceptionToTuple(SocketException e) {
return PythonTuple.MakeTuple(e.ErrorCode, e.Message);
}

private static Exception MakeException(CodeContext/*!*/ context, object value) {
return PythonExceptions.CreateThrowable((PythonType)context.LanguageContext.GetModuleState("selecterror"), value);
}

/// <summary>
/// Process a sequence of objects that are compatible with ObjectToSocket(). Return two
/// things as out params: an in-order List of sockets that correspond to the original
Expand Down Expand Up @@ -137,8 +125,7 @@ private static Socket ObjectToSocket(CodeContext context, object obj) {
}
socket = PythonSocket.socket.HandleToSocket(handle);
if (socket == null) {
SocketException e = new SocketException((int)SocketError.NotSocket);
throw PythonExceptions.CreateThrowable((PythonType)context.LanguageContext.GetModuleState("selecterror"), PythonTuple.MakeTuple(e.ErrorCode, e.Message));
throw PythonSocket.MakeException(context, new SocketException((int)SocketError.NotSocket));
}
return socket;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Runtime/Operations/IntOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static string __format__(CodeContext/*!*/ context, int self, [NotNone] st
throw PythonOps.ValueError("Unknown format code '{0}' for object of type 'int'", spec.TypeRepr);
}

Debug.Assert(digits[0] != '-');
Debug.Assert(spec.Type == 'c' || digits[0] != '-');

return spec.AlignNumericText(digits, self == 0, self > 0);
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,4 +1683,18 @@ def d01(a=1): pass
exec('def f(' + ','.join('a{0}'.format(i) for i in range(size)) + '): pass', d)
d["f"](*range(size)) # just make sure this runs successfully

def test_ipy3_gh1614(self):
# https://github.com/IronLanguages/ironpython3/issues/1614

# this was causing an assertion error in DEBUG builds
self.assertEqual('{:c}'.format(0x2d), '-')

def test_ipy3_gh1615(self):
# https://github.com/IronLanguages/ironpython3/issues/1615

# this was causing an assertion error in DEBUG builds
import select
with self.assertRaises(OSError):
select.select([], [], [])

run_test(__name__)