From a8dd220effdb718950246bc9461df28d7684b542 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Sat, 27 Feb 2016 04:30:22 -0600 Subject: [PATCH 1/3] Update methodbinder.cs --- src/runtime/methodbinder.cs | 49 +++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 8760ad26f..532a52fbf 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -245,7 +245,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, else { _methods = GetMethods(); } - Type type; + Type clrtype; for (int i = 0; i < _methods.Length; i++) { MethodBase mi = _methods[i]; @@ -295,34 +295,53 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, // this logic below handles cases when multiple overloading methods // are ambiguous, hence comparison between Python and CLR types // is necessary - type = null; - - if (_methods.Length>1) { - IntPtr pyoptype = IntPtr.Zero; + clrtype = null; + IntPtr pyoptype; + if (_methods.Length > 1) { + pyoptype = IntPtr.Zero; pyoptype = Runtime.PyObject_Type(op); Exceptions.Clear(); - if (pyoptype != IntPtr.Zero) { } - type = Converter.GetTypeByAlias(pyoptype); - Runtime.Decref(pyoptype); + if (pyoptype != IntPtr.Zero) { + clrtype = Converter.GetTypeByAlias(pyoptype); } + Runtime.Decref(pyoptype); + } - if (type != null) { - if (pi[n].ParameterType != type) { - margs = null; - break; + if (clrtype != null) { + if (pi[n].ParameterType != clrtype) { + IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType); + // does pytype require Decref? + pyoptype = Runtime.PyObject_Type(op); + Exceptions.Clear(); + if (pyoptype != IntPtr.Zero) { + if (pytype != pyoptype) { + Runtime.Decref(pyoptype); + margs = null; + break; + } + else { + clrtype = pi[n].ParameterType; + } + } + else { + Runtime.Decref(pyoptype); + margs = null; + break; + } + Runtime.Decref(pyoptype); } } else { - type = pi[n].ParameterType; + clrtype = pi[n].ParameterType; } - if (pi[n].IsOut || type.IsByRef) + if (pi[n].IsOut || clrtype.IsByRef) { outs++; } - if (!Converter.ToManaged(op, type, out arg, false)) + if (!Converter.ToManaged(op, clrtype, out arg, false)) { Exceptions.Clear(); margs = null; From 70d81c2f8c218284b5846644203d274175e00a4c Mon Sep 17 00:00:00 2001 From: denfromufa Date: Sat, 27 Feb 2016 04:33:43 -0600 Subject: [PATCH 2/3] Update converter.cs --- src/runtime/converter.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index 039294d13..012b1151a 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -29,7 +29,10 @@ private Converter() {} static NumberFormatInfo nfi; static Type objectType; static Type stringType; + static Type singleType; static Type doubleType; + static Type decimalType; + static Type int16Type; static Type int32Type; static Type int64Type; static Type flagsType; @@ -40,9 +43,12 @@ static Converter () { nfi = NumberFormatInfo.InvariantInfo; objectType = typeof(Object); stringType = typeof(String); + int16Type = typeof(Int16); int32Type = typeof(Int32); int64Type = typeof(Int64); + singleType = typeof(Single); doubleType = typeof(Double); + decimalType = typeof(Decimal); flagsType = typeof(FlagsAttribute); boolType = typeof(Boolean); typeType = typeof(Type); @@ -73,6 +79,28 @@ internal static Type GetTypeByAlias(IntPtr op) { return null; } + internal static IntPtr GetPythonTypeByAlias(Type op) + { + if (op == stringType) { + return Runtime.PyUnicodeType; + } + else if ((op == int16Type) || + (op == int32Type)) { + return Runtime.PyIntType; + } + else if (op == int64Type) { + return Runtime.PyLongType; + } + else if ((op == doubleType) || + (op == singleType)) { + return Runtime.PyFloatType; + } + else if (op == boolType) { + return Runtime.PyBoolType; + } + return IntPtr.Zero; + } + //==================================================================== // Return a Python object for the given native object, converting From 688a3d4596026a88ee788ee1f1fedbfc06c06685 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Sat, 27 Feb 2016 04:36:35 -0600 Subject: [PATCH 3/3] Update wordpad.py --- demo/wordpad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/wordpad.py b/demo/wordpad.py index 32844b1d4..a67deef23 100644 --- a/demo/wordpad.py +++ b/demo/wordpad.py @@ -205,7 +205,7 @@ def InitializeComponent(self): self.richTextBox.TabIndex = 0 self.richTextBox.AutoSize = 1 self.richTextBox.ScrollBars = WinForms.RichTextBoxScrollBars.ForcedBoth - self.richTextBox.Font = System.Drawing.Font("Tahoma", 10) + self.richTextBox.Font = System.Drawing.Font("Tahoma", 10.0) self.richTextBox.AcceptsTab = 1 self.richTextBox.Location = System.Drawing.Point(0, 0)