Visitar URL original
Merge bug fixes from ipy-2.7-maint · JayDevOps/ironpython3@a9a23aa · GitHub
Skip to content

Commit a9a23aa

Browse files
author
Alex Earl
committed
Merge bug fixes from ipy-2.7-maint
1 parent 3d2586e commit a9a23aa

43 files changed

Lines changed: 2045 additions & 365 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ Languages/IronPython/Tests/vbproptest0.*.dll
5454
Util/References
5555

5656
/NuGet.config
57+
*.bak

‎IronPython.sln‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.21005.1
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.24720.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPython", "Src\IronPython\IronPython.csproj", "{95289EA9-5778-489D-AB48-F81F2CE2DA32}"
77
EndProject
@@ -58,6 +58,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{17737ACB
5858
EndProject
5959
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPythonTestConsole", "Src\IronPythonTestConsole\IronPythonTestConsole.csproj", "{79446DDF-421C-4695-9859-5E01F0D95830}"
6060
EndProject
61+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPythonCompiler", "Src\IronPythonCompiler\IronPythonCompiler.csproj", "{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}"
62+
EndProject
6163
Global
6264
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6365
AndroidDebug|Any CPU = AndroidDebug|Any CPU
@@ -295,13 +297,39 @@ Global
295297
{79446DDF-421C-4695-9859-5E01F0D95830}.Win8Debug|Any CPU.Build.0 = Win8Debug|Any CPU
296298
{79446DDF-421C-4695-9859-5E01F0D95830}.Win8Release|Any CPU.ActiveCfg = Win8Release|Any CPU
297299
{79446DDF-421C-4695-9859-5E01F0D95830}.Win8Release|Any CPU.Build.0 = Win8Release|Any CPU
300+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.AndroidDebug|Any CPU.ActiveCfg = AndroidDebug|Any CPU
301+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.AndroidDebug|Any CPU.Build.0 = AndroidDebug|Any CPU
302+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.AndroidRelease|Any CPU.ActiveCfg = AndroidRelease|Any CPU
303+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.AndroidRelease|Any CPU.Build.0 = AndroidRelease|Any CPU
304+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
305+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
306+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU
307+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.FxCop|Any CPU.Build.0 = FxCop|Any CPU
308+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
309+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Release|Any CPU.Build.0 = Release|Any CPU
310+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Silverlight5Debug|Any CPU.ActiveCfg = Silverlight5Debug|Any CPU
311+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Silverlight5Debug|Any CPU.Build.0 = Silverlight5Debug|Any CPU
312+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Silverlight5Release|Any CPU.ActiveCfg = Silverlight5Release|Any CPU
313+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Silverlight5Release|Any CPU.Build.0 = Silverlight5Release|Any CPU
314+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v2Debug|Any CPU.ActiveCfg = v2Debug|Any CPU
315+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v2Debug|Any CPU.Build.0 = v2Debug|Any CPU
316+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v2Release|Any CPU.ActiveCfg = v2Release|Any CPU
317+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v2Release|Any CPU.Build.0 = v2Release|Any CPU
318+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v45Debug|Any CPU.ActiveCfg = v45Debug|Any CPU
319+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v45Debug|Any CPU.Build.0 = v45Debug|Any CPU
320+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v45Release|Any CPU.ActiveCfg = v45Release|Any CPU
321+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.v45Release|Any CPU.Build.0 = v45Release|Any CPU
322+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Win8Debug|Any CPU.ActiveCfg = Win8Debug|Any CPU
323+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Win8Debug|Any CPU.Build.0 = Win8Debug|Any CPU
324+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Win8Release|Any CPU.ActiveCfg = Win8Release|Any CPU
325+
{3DFB096E-AC09-4E7A-9288-7F7C33C288C7}.Win8Release|Any CPU.Build.0 = Win8Release|Any CPU
298326
EndGlobalSection
299327
GlobalSection(SolutionProperties) = preSolution
300328
HideSolutionNode = FALSE
301329
EndGlobalSection
302330
GlobalSection(NestedProjects) = preSolution
303-
{17737ACB-40C6-41A6-83DA-3203A4DCEC19} = {3A14D070-628F-44EF-92DD-47C8BE5C33CD}
304-
{CE9DF8A7-CEE3-44CB-8C17-E0E3004A8755} = {17737ACB-40C6-41A6-83DA-3203A4DCEC19}
305331
{2BA7ADB8-E6B4-4C3E-95A0-A65C98919FE2} = {17737ACB-40C6-41A6-83DA-3203A4DCEC19}
332+
{CE9DF8A7-CEE3-44CB-8C17-E0E3004A8755} = {17737ACB-40C6-41A6-83DA-3203A4DCEC19}
333+
{17737ACB-40C6-41A6-83DA-3203A4DCEC19} = {3A14D070-628F-44EF-92DD-47C8BE5C33CD}
306334
EndGlobalSection
307335
EndGlobal

‎Src/IronPython.Modules/_collections.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public PythonTuple __reduce__() {
435435
});
436436

437437
return PythonTuple.MakeTuple(
438-
DynamicHelpers.GetPythonTypeFromType(GetType()),
438+
DynamicHelpers.GetPythonType(this),
439439
PythonTuple.MakeTuple(List.FromArrayNoCopy(items)),
440440
null
441441
);

‎Src/IronPython.Modules/_csv.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public bool MoveNext()
711711
{
712712
throw PythonOps.TypeError("expected string or " +
713713
"Unicode object, {0} found",
714-
PythonType.GetPythonType(lineobj.GetType()));
714+
DynamicHelpers.GetPythonType(lineobj.GetType()));
715715
}
716716

717717
string line = lineobj as string;

‎Src/IronPython.Modules/_ssl.cs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
[assembly: PythonModule("_ssl", typeof(IronPython.Modules.PythonSsl))]
3737
namespace IronPython.Modules {
3838
public static class PythonSsl {
39-
public const string __doc__ = "Implementation module for SSL socket operations.";
39+
public const string __doc__ = "Implementation module for SSL socket operations. See the socket module\nfor documentation.";
4040
public const int OPENSSL_VERSION_NUMBER = 9437184;
4141
public static PythonTuple OPENSSL_VERSION_INFO = PythonTuple.MakeTuple(0, 0, 0, 0, 0);
4242
public const string OPENSSL_VERSION = "OpenSSL 0.0.0 (.NET SSL)";
@@ -80,7 +80,7 @@ public static PythonSocket.ssl sslwrap(
8080
[DefaultParameterValue(null)] string keyfile,
8181
[DefaultParameterValue(null)] string certfile,
8282
[DefaultParameterValue(PythonSsl.CERT_NONE)]int certs_mode,
83-
[DefaultParameterValue(-1)]int protocol,
83+
[DefaultParameterValue(PythonSsl.PROTOCOL_SSLv23 | PythonSsl.OP_NO_SSLv2 | PythonSsl.OP_NO_SSLv3)]int protocol,
8484
[DefaultParameterValue(null)]string cacertsfile,
8585
[DefaultParameterValue(null)]object ciphers) {
8686
return new PythonSocket.ssl(
@@ -418,6 +418,17 @@ private static Exception ErrorDecoding(CodeContext context, params object[] args
418418
public const int PROTOCOL_SSLv3 = 1;
419419
public const int PROTOCOL_SSLv23 = 2;
420420
public const int PROTOCOL_TLSv1 = 3;
421+
public const int PROTOCOL_TLSv1_1 = 4;
422+
public const int PROTOCOL_TLSv1_2 = 5;
423+
424+
public const int OP_NO_SSLv2 = 0x1000000;
425+
public const int OP_NO_SSLv3 = 0x2000000;
426+
public const int OP_NO_TLSv1 = 0x4000000;
427+
public const int OP_NO_TLSv1_1 = 0x10000000;
428+
public const int OP_NO_TLSv1_2 = 0x8000000;
429+
430+
internal const int OP_NO_ALL = OP_NO_SSLv2 | OP_NO_SSLv3 | OP_NO_TLSv1 | OP_NO_TLSv1_1 | OP_NO_TLSv1_2;
431+
421432

422433
#region Exported constants
423434

‎Src/IronPython.Modules/_struct.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,13 @@ internal static bool GetBoolValue(CodeContext/*!*/ context, int index, object[]
894894
}
895895

896896
internal static char GetCharValue(CodeContext/*!*/ context, int index, object[] args) {
897-
string val = GetValue(context, index, args) as string;
898-
if (val == null || val.Length != 1) throw Error(context, "char format requires string of length 1");
897+
object val = GetValue(context, index, args);
898+
string strVal = val as string;
899+
if (strVal != null && strVal.Length == 1) return strVal[0];
899900

900-
return val[0];
901+
IList<Byte> byteVal = val as IList<Byte>;
902+
if (byteVal == null || byteVal.Count != 1) throw Error(context, "char format requires string of length 1");
903+
else return (char)byteVal[0];
901904
}
902905

903906
internal static sbyte GetSByteValue(CodeContext/*!*/ context, int index, object[] args) {

‎Src/IronPython.Modules/_weakref.cs‎

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ namespace IronPython.Modules {
3232
public static partial class PythonWeakRef {
3333
public const string __doc__ = "Provides support for creating weak references and proxies to objects";
3434

35-
internal static IWeakReferenceable ConvertToWeakReferenceable(object obj) {
36-
IWeakReferenceable iwr = obj as IWeakReferenceable;
37-
if (iwr != null) return iwr;
35+
/// <summary>
36+
/// Wrapper provided for backwards compatibility.
37+
/// </summary>
38+
internal static IWeakReferenceable ConvertToWeakReferenceable(PythonContext context, object obj) {
39+
return context.ConvertToWeakReferenceable(obj);
3840

39-
throw PythonOps.TypeError("cannot create weak reference to '{0}' object", PythonOps.GetPythonTypeName(obj));
4041
}
4142

42-
public static int getweakrefcount(object @object) {
43-
return @ref.GetWeakRefCount(@object);
43+
public static int getweakrefcount(CodeContext context, object @object) {
44+
return @ref.GetWeakRefCount(PythonContext.GetContext(context), @object);
4445
}
4546

46-
public static List getweakrefs(object @object) {
47-
return @ref.GetWeakRefs(@object);
47+
public static List getweakrefs(CodeContext context, object @object) {
48+
return @ref.GetWeakRefs(PythonContext.GetContext(context), @object);
4849
}
4950

5051
public static object proxy(CodeContext context, object @object) {
@@ -75,10 +76,11 @@ public class @ref : IStructuralEquatable
7576
private WeakHandle _target;
7677
private int _hashVal;
7778
private bool _fHasHash;
79+
private CodeContext _context;
7880

7981
#region Python Constructors
8082
public static object __new__(CodeContext context, PythonType cls, object @object) {
81-
IWeakReferenceable iwr = ConvertToWeakReferenceable(@object);
83+
IWeakReferenceable iwr = ConvertToWeakReferenceable(PythonContext.GetContext(context), @object);
8284

8385
if (cls == DynamicHelpers.GetPythonTypeFromType(typeof(@ref))) {
8486
WeakRefTracker wrt = iwr.GetWeakRef();
@@ -90,7 +92,7 @@ public static object __new__(CodeContext context, PythonType cls, object @object
9092
}
9193
}
9294

93-
return new @ref(@object);
95+
return new @ref(context, @object);
9496
} else {
9597
return cls.CreateInstance(context, @object);
9698
}
@@ -99,20 +101,21 @@ public static object __new__(CodeContext context, PythonType cls, object @object
99101
public static object __new__(CodeContext context, PythonType cls, object @object, object callback) {
100102
if (callback == null) return __new__(context, cls, @object);
101103
if (cls == DynamicHelpers.GetPythonTypeFromType(typeof(@ref))) {
102-
return new @ref(@object, callback);
104+
return new @ref(context, @object, callback);
103105
} else {
104106
return cls.CreateInstance(context, @object, callback);
105107
}
106108
}
107109
#endregion
108110

109111
#region Constructors
110-
public @ref(object @object)
111-
: this(@object, null) {
112+
public @ref(CodeContext context, object @object)
113+
: this(context, @object, null) {
112114
}
113115

114-
public @ref(object @object, object callback) {
115-
WeakRefHelpers.InitializeWeakRef(this, @object, callback);
116+
public @ref(CodeContext context, object @object, object callback) {
117+
this._context = context;
118+
WeakRefHelpers.InitializeWeakRef(this._context.GetPythonContext(), this, @object, callback);
116119
this._target = new WeakHandle(@object, false);
117120
}
118121
#endregion
@@ -122,8 +125,8 @@ public @ref(object @object, object callback) {
122125
// remove our self from the chain...
123126
try {
124127
if (_target.IsAlive) {
125-
IWeakReferenceable iwr = _target.Target as IWeakReferenceable;
126-
if (iwr != null) {
128+
IWeakReferenceable iwr;
129+
if (this._context.GetPythonContext().TryConvertToWeakReferenceable(_target.Target, out iwr)) {
127130
WeakRefTracker wrt = iwr.GetWeakRef();
128131
if (wrt != null) {
129132
// weak reference being finalized before target object,
@@ -143,20 +146,20 @@ public @ref(object @object, object callback) {
143146

144147
#region Static helpers
145148

146-
internal static int GetWeakRefCount(object o) {
147-
IWeakReferenceable iwr = o as IWeakReferenceable;
148-
if (iwr != null) {
149+
internal static int GetWeakRefCount(PythonContext context, object o) {
150+
IWeakReferenceable iwr;
151+
if (context.TryConvertToWeakReferenceable(o, out iwr)) {
149152
WeakRefTracker wrt = iwr.GetWeakRef();
150153
if (wrt != null) return wrt.HandlerCount;
151154
}
152155

153156
return 0;
154157
}
155158

156-
internal static List GetWeakRefs(object o) {
159+
internal static List GetWeakRefs(PythonContext context, object o) {
157160
List l = new List();
158-
IWeakReferenceable iwr = o as IWeakReferenceable;
159-
if (iwr != null) {
161+
IWeakReferenceable iwr;
162+
if (context.TryConvertToWeakReferenceable(o, out iwr)) {
160163
WeakRefTracker wrt = iwr.GetWeakRef();
161164
if (wrt != null) {
162165
for (int i = 0; i < wrt.HandlerCount; i++) {
@@ -172,14 +175,14 @@ internal static List GetWeakRefs(object o) {
172175
[SpecialName]
173176
public object Call(CodeContext context) {
174177
if (!_target.IsAlive) {
175-
throw PythonOps.ReferenceError("weak object has gone away");
178+
return null;
176179
}
177180
try {
178181
object res = _target.Target;
179182
GC.KeepAlive(this);
180183
return res;
181184
} catch (InvalidOperationException) {
182-
throw PythonOps.ReferenceError("weak object has gone away");
185+
return null;
183186
}
184187
}
185188

@@ -311,7 +314,7 @@ public sealed partial class weakproxy : IPythonObject, ICodeFormattable, IProxyO
311314

312315
#region Python Constructors
313316
internal static object MakeNew(CodeContext/*!*/ context, object @object, object callback) {
314-
IWeakReferenceable iwr = ConvertToWeakReferenceable(@object);
317+
IWeakReferenceable iwr = ConvertToWeakReferenceable(PythonContext.GetContext(context), @object);
315318

316319
if (callback == null) {
317320
WeakRefTracker wrt = iwr.GetWeakRef();
@@ -331,7 +334,7 @@ internal static object MakeNew(CodeContext/*!*/ context, object @object, object
331334
#region Constructors
332335

333336
private weakproxy(CodeContext/*!*/ context, object target, object callback) {
334-
WeakRefHelpers.InitializeWeakRef(this, target, callback);
337+
WeakRefHelpers.InitializeWeakRef(PythonContext.GetContext(context), this, target, callback);
335338
_target = new WeakHandle(target, false);
336339
_context = context;
337340
}
@@ -341,8 +344,8 @@ private weakproxy(CodeContext/*!*/ context, object target, object callback) {
341344
~weakproxy() {
342345
// remove our self from the chain...
343346
try {
344-
IWeakReferenceable iwr = _target.Target as IWeakReferenceable;
345-
if (iwr != null) {
347+
IWeakReferenceable iwr;
348+
if (this._context.GetPythonContext().TryConvertToWeakReferenceable(_target.Target, out iwr)) {
346349
WeakRefTracker wrt = iwr.GetWeakRef();
347350
wrt.RemoveHandler(this);
348351
}
@@ -579,7 +582,7 @@ public sealed partial class weakcallableproxy :
579582
#region Python Constructors
580583

581584
internal static object MakeNew(CodeContext/*!*/ context, object @object, object callback) {
582-
IWeakReferenceable iwr = ConvertToWeakReferenceable(@object);
585+
IWeakReferenceable iwr = ConvertToWeakReferenceable(PythonContext.GetContext(context), @object);
583586

584587
if (callback == null) {
585588
WeakRefTracker wrt = iwr.GetWeakRef();
@@ -602,7 +605,7 @@ internal static object MakeNew(CodeContext/*!*/ context, object @object, object
602605
#region Constructors
603606

604607
private weakcallableproxy(CodeContext context, object target, object callback) {
605-
WeakRefHelpers.InitializeWeakRef(this, target, callback);
608+
WeakRefHelpers.InitializeWeakRef(PythonContext.GetContext(context), this, target, callback);
606609
_target = new WeakHandle(target, false);
607610
_context = context;
608611
}
@@ -614,8 +617,8 @@ private weakcallableproxy(CodeContext context, object target, object callback) {
614617
~weakcallableproxy() {
615618
// remove our self from the chain...
616619
try {
617-
IWeakReferenceable iwr = _target.Target as IWeakReferenceable;
618-
if (iwr != null) {
620+
IWeakReferenceable iwr;
621+
if (this._context.GetPythonContext().TryConvertToWeakReferenceable(_target.Target, out iwr)) {
619622
WeakRefTracker wrt = iwr.GetWeakRef();
620623
wrt.RemoveHandler(this);
621624
}
@@ -829,8 +832,8 @@ public object __nonzero__() {
829832
}
830833

831834
static class WeakRefHelpers {
832-
public static void InitializeWeakRef(object self, object target, object callback) {
833-
IWeakReferenceable iwr = ConvertToWeakReferenceable(target);
835+
public static void InitializeWeakRef(PythonContext context, object self, object target, object callback) {
836+
IWeakReferenceable iwr = ConvertToWeakReferenceable(context, target);
834837

835838
WeakRefTracker wrt = iwr.GetWeakRef();
836839
if (wrt == null) {

0 commit comments

Comments
 (0)