From e4b10281cdbbf2c3eff3d3a5ee35e2ad98235130 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Sun, 7 Feb 2016 23:08:03 -0600 Subject: [PATCH 1/5] Update methodbinder.cs --- src/runtime/methodbinder.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index d63f53f1e..825cca239 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -50,7 +50,10 @@ internal void AddMethod(MethodBase m) { //==================================================================== internal static MethodInfo MatchSignature(MethodInfo[] mi, Type[] tp) { - int count = tp.Length; + if (tp == null) { + return null; + } + int count = tp.Length; for (int i = 0; i < mi.Length; i++) { ParameterInfo[] pi = mi[i].GetParameters(); if (pi.Length != count) { @@ -99,7 +102,10 @@ internal static MethodInfo MatchParameters(MethodInfo[] mi, Type[] tp) { internal static MethodInfo MatchSignatureAndParameters(MethodInfo[] mi, Type[] genericTp, Type[] sigTp) { - int genericCount = genericTp.Length; + if ((genericTp == null) || (sigTp == null)) { + return null; + } + int genericCount = genericTp.Length; int signatureCount = sigTp.Length; for (int i = 0; i < mi.Length; i++) { @@ -239,9 +245,10 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, else { _methods = GetMethods(); } - + Type type; for (int i = 0; i < _methods.Length; i++) { MethodBase mi = _methods[i]; + if (mi.IsGenericMethod) { isGeneric = true; } ParameterInfo[] pi = mi.GetParameters(); int clrnargs = pi.Length; @@ -287,7 +294,20 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, { op = Runtime.PyTuple_GetItem(args, n); } - Type type = pi[n].ParameterType; + + type = Converter.GetTypeByAlias(Runtime.PyObject_Type(op)); + + if (type != null) { + if (pi[n].ParameterType != type) { + Exceptions.Clear(); + margs = null; + break; + } + } + else { + type = pi[n].ParameterType; + } + if (pi[n].IsOut || type.IsByRef) { outs++; From e17d9bc5e134923ca8ec0e3425ba70871cb85631 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Mon, 8 Feb 2016 23:18:24 -0600 Subject: [PATCH 2/5] Update methodbinder.cs --- src/runtime/methodbinder.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 825cca239..712dd3284 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -282,24 +282,32 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, for (int n = 0; n < clrnargs; n++) { IntPtr op; - if (n < pynargs) - { - if (arrayStart == n) - { + if (n < pynargs) { + if (arrayStart == n) { // map remaining Python arguments to a tuple since // the managed function accepts it - hopefully :] op = Runtime.PyTuple_GetSlice(args, arrayStart, pynargs); } - else - { + else { op = Runtime.PyTuple_GetItem(args, n); } - - type = Converter.GetTypeByAlias(Runtime.PyObject_Type(op)); + type = null; + if (_methods.Length>1) { + IntPtr pyoptype = IntPtr.Zero; + try { + pyoptype = Runtime.PyObject_Type(op); + } + catch (System.Exception e) { + + } + if (pyoptype != IntPtr.Zero) { } + type = Converter.GetTypeByAlias(pyoptype); + } + //Runtime.Decref(pyoptype); if (type != null) { if (pi[n].ParameterType != type) { - Exceptions.Clear(); + //Exceptions.Clear(); margs = null; break; } From 64e0b4c6094c5af3ad675a1ac95de907e22e9d52 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Tue, 9 Feb 2016 08:30:09 -0600 Subject: [PATCH 3/5] Update methodbinder.cs --- src/runtime/methodbinder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 712dd3284..0ee2d5ef2 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -302,8 +302,9 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, } if (pyoptype != IntPtr.Zero) { } type = Converter.GetTypeByAlias(pyoptype); + Runtime.Decref(pyoptype); } - //Runtime.Decref(pyoptype); + if (type != null) { if (pi[n].ParameterType != type) { From 1c80917c505e4eb7f24429c89f53b78bb3bed783 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Tue, 9 Feb 2016 11:52:25 -0600 Subject: [PATCH 4/5] Update methodbinder.cs --- src/runtime/methodbinder.cs | 99 +++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 0ee2d5ef2..0c7ae7576 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -95,54 +95,54 @@ internal static MethodInfo MatchParameters(MethodInfo[] mi, Type[] tp) { } - //==================================================================== - // Given a sequence of MethodInfo and two sequences of type parameters, - // return the MethodInfo that matches the signature and the closed generic. - //==================================================================== + //==================================================================== + // Given a sequence of MethodInfo and two sequences of type parameters, + // return the MethodInfo that matches the signature and the closed generic. + //==================================================================== - internal static MethodInfo MatchSignatureAndParameters(MethodInfo[] mi, Type[] genericTp, Type[] sigTp) - { + internal static MethodInfo MatchSignatureAndParameters(MethodInfo[] mi, Type[] genericTp, Type[] sigTp) + { if ((genericTp == null) || (sigTp == null)) { return null; } int genericCount = genericTp.Length; - int signatureCount = sigTp.Length; - for (int i = 0; i < mi.Length; i++) - { - if (!mi[i].IsGenericMethodDefinition) - { - continue; - } - Type[] genericArgs = mi[i].GetGenericArguments(); - if (genericArgs.Length != genericCount) - { - continue; - } - ParameterInfo[] pi = mi[i].GetParameters(); - if (pi.Length != signatureCount) - { - continue; - } - for (int n = 0; n < pi.Length; n++) - { - if (sigTp[n] != pi[n].ParameterType) - { - break; - } - if (n == (pi.Length - 1)) - { - MethodInfo match = mi[i]; - if (match.IsGenericMethodDefinition) - { - Type[] typeArgs = match.GetGenericArguments(); - return match.MakeGenericMethod(genericTp); - } - return match; - } - } - } - return null; - } + int signatureCount = sigTp.Length; + for (int i = 0; i < mi.Length; i++) + { + if (!mi[i].IsGenericMethodDefinition) + { + continue; + } + Type[] genericArgs = mi[i].GetGenericArguments(); + if (genericArgs.Length != genericCount) + { + continue; + } + ParameterInfo[] pi = mi[i].GetParameters(); + if (pi.Length != signatureCount) + { + continue; + } + for (int n = 0; n < pi.Length; n++) + { + if (sigTp[n] != pi[n].ParameterType) + { + break; + } + if (n == (pi.Length - 1)) + { + MethodInfo match = mi[i]; + if (match.IsGenericMethodDefinition) + { + Type[] typeArgs = match.GetGenericArguments(); + return match.MakeGenericMethod(genericTp); + } + return match; + } + } + } + return null; + } //==================================================================== @@ -294,17 +294,18 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, type = null; if (_methods.Length>1) { IntPtr pyoptype = IntPtr.Zero; - try { + //try { pyoptype = Runtime.PyObject_Type(op); - } - catch (System.Exception e) { + /*} + catch (System.Exception) { - } + }*/ + Exceptions.Clear(); if (pyoptype != IntPtr.Zero) { } type = Converter.GetTypeByAlias(pyoptype); Runtime.Decref(pyoptype); } - + if (type != null) { if (pi[n].ParameterType != type) { @@ -377,7 +378,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodInfo mi = MethodBinder.MatchParameters(methodinfo, types); return Bind(inst, args, kw, mi, null); } - return null; + return null; } internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw) { From 44702a87a639ffe3d8ada7994c6c7624ae958c87 Mon Sep 17 00:00:00 2001 From: denfromufa Date: Tue, 9 Feb 2016 13:31:39 -0600 Subject: [PATCH 5/5] Update methodbinder.cs --- src/runtime/methodbinder.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 0c7ae7576..8760ad26f 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -291,15 +291,15 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, else { op = Runtime.PyTuple_GetItem(args, n); } + + // 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; - //try { - pyoptype = Runtime.PyObject_Type(op); - /*} - catch (System.Exception) { - }*/ + if (_methods.Length>1) { + IntPtr pyoptype = IntPtr.Zero; + pyoptype = Runtime.PyObject_Type(op); Exceptions.Clear(); if (pyoptype != IntPtr.Zero) { } type = Converter.GetTypeByAlias(pyoptype); @@ -309,7 +309,6 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, if (type != null) { if (pi[n].ParameterType != type) { - //Exceptions.Clear(); margs = null; break; }